Skip to contentSkip to conversation

scsi_dh_rdac: avoid crash during rescan

PATCH In review Hannes Reinecke 4 participants 6 messages Nov 11, 2019 – Nov 14, 2019 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi_dh_rdac: avoid crash during rescan

During rescanning the device might already have been removed, so we should drop the BUG_ON and just ignore the non-existing device.

---
 drivers/scsi/device_handler/scsi_dh_rdac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/device_handler/scsi_dh_rdac.c +2 -2
index 5efc959493ec..33a71df5ee59 100644
@@ -424,8 +424,8 @@ static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
 		rcu_read_lock();
 		list_for_each_entry_rcu(tmp, &h->ctlr->dh_list, node) {
 			/* h->sdev should always be valid */
-			BUG_ON(!tmp->sdev);
-			tmp->sdev->access_state = access_state;
+			if (tmp->sdev) {
+				tmp->sdev->access_state = access_state;
 		}
 		rcu_read_unlock();
 		err = SCSI_DH_OK;
Signature · 1 line
2.16.4
#1 lore raw
Quoted 13 lines · Hannes Reinecke

During rescanning the device might already have been removed, so we should drop the BUG_ON and just ignore the non-existing device.

---
  drivers/scsi/device_handler/scsi_dh_rdac.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/device_handler/scsi_dh_rdac.c +0 -0
index 5efc959493ec..33a71df5ee59 100644

drivers/scsi/device_handler/scsi_dh_rdac.c static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h) · line 431

Quoted 10 lines
drivers/scsi/device_handler/scsi_dh_rdac.c +2 -2
@@ -424,8 +424,8 @@ static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
  		rcu_read_lock();
  		list_for_each_entry_rcu(tmp, &h->ctlr->dh_list, node) {
  			/* h->sdev should always be valid */
-			BUG_ON(!tmp->sdev);
-			tmp->sdev->access_state = access_state;
+			if (tmp->sdev) {
+				tmp->sdev->access_state = access_state;
  		}
  		rcu_read_unlock();
  		err = SCSI_DH_OK;

Since rdac_bus_detach() may clear h->sdev concurrently with the above code I think READ_ONCE() is needed to make the above code safe.

Has it been considered to change the kfree() call in rdac_bus_detach() into a kfree_rcu() call? I think otherwise the above list_for_each_entry_rcu() loop may trigger a use-after-free.

Thanks,

Bart.

#2 lore raw
Quoted 30 lines · Bart Van Assche
Quoted 24 lines · Hannes Reinecke

During rescanning the device might already have been removed, so we should drop the BUG_ON and just ignore the non-existing device.

---
  drivers/scsi/device_handler/scsi_dh_rdac.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/device_handler/scsi_dh_rdac.c +2 -2
index 5efc959493ec..33a71df5ee59 100644
@@ -424,8 +424,8 @@ static int check_ownership(struct scsi_device
 *sdev, struct rdac_dh_data *h)
           rcu_read_lock();
           list_for_each_entry_rcu(tmp, &h->ctlr->dh_list, node) {
               /* h->sdev should always be valid */
-            BUG_ON(!tmp->sdev);
-            tmp->sdev->access_state = access_state;
+            if (tmp->sdev) {
+                tmp->sdev->access_state = access_state;
           }
           rcu_read_unlock();
Quoted 1 line

          err = SCSI_DH_OK;

Since rdac_bus_detach() may clear h->sdev concurrently with the above code I think READ_ONCE() is needed to make the above code safe.

Quoted 4 lines

Has it been considered to change the kfree() call in rdac_bus_detach() into a kfree_rcu() call? I think otherwise the above list_for_each_entry_rcu() loop may trigger a use-after-free.

Good point. I'll have a look.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      Teamlead Storage & Networking
[email protected]			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer
#3 lore raw
In reply to Hannes Reinecke
I love your patch! Yet something to improve:

Hi Hannes,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on v5.4-rc7 next-20191112]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi_dh_rdac-avoid-crash-during-rescan/20191113-021538
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

drivers/scsi/device_handler/scsi_dh_rdac.c: In function 'check_ownership':
drivers/scsi/device_handler/scsi_dh_rdac.c:437:12: error: invalid storage class for function 'initialize_controller'
static int initialize_controller(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:437:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
static int initialize_controller(struct scsi_device *sdev,
^~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:465:12: error: invalid storage class for function 'set_mode_select'
static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
^~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:485:12: error: invalid storage class for function 'mode_select_handle_sense'
static int mode_select_handle_sense(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:527:13: error: invalid storage class for function 'send_mode_select'
static void send_mode_select(struct work_struct *work)
^~~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:585:12: error: invalid storage class for function 'queue_mode_select'
static int queue_mode_select(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:611:12: error: invalid storage class for function 'rdac_activate'
static int rdac_activate(struct scsi_device *sdev,
^~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:647:21: error: invalid storage class for function 'rdac_prep_fn'
static blk_status_t rdac_prep_fn(struct scsi_device *sdev, struct request *req)
^~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:659:12: error: invalid storage class for function 'rdac_check_sense'
static int rdac_check_sense(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:724:12: error: invalid storage class for function 'rdac_bus_attach'
static int rdac_bus_attach(struct scsi_device *sdev)
^~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:771:13: error: invalid storage class for function 'rdac_bus_detach'
static void rdac_bus_detach( struct scsi_device *sdev )
^~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:792:13: error: initializer element is not constant
.prep_fn = rdac_prep_fn,
^~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:792:13: note: (near initialization for 'rdac_dh.prep_fn') drivers/scsi/device_handler/scsi_dh_rdac.c:793:17: error: initializer element is not constant
.check_sense = rdac_check_sense,
^~~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:793:17: note: (near initialization for 'rdac_dh.check_sense') drivers/scsi/device_handler/scsi_dh_rdac.c:794:12: error: initializer element is not constant
.attach = rdac_bus_attach,
^~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:794:12: note: (near initialization for 'rdac_dh.attach') drivers/scsi/device_handler/scsi_dh_rdac.c:795:12: error: initializer element is not constant
.detach = rdac_bus_detach,
^~~~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:795:12: note: (near initialization for 'rdac_dh.detach') drivers/scsi/device_handler/scsi_dh_rdac.c:796:14: error: initializer element is not constant
.activate = rdac_activate,
^~~~~~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:796:14: note: (near initialization for 'rdac_dh.activate') drivers/scsi/device_handler/scsi_dh_rdac.c:799:19: error: invalid storage class for function 'rdac_init'
static int __init rdac_init(void)
^~~~~~~~~
drivers/scsi/device_handler/scsi_dh_rdac.c:823:20: error: invalid storage class for function 'rdac_exit'
static void __exit rdac_exit(void)
^~~~~~~~~
In file included from drivers/scsi/device_handler/scsi_dh_rdac.c:27:0:

>> include/linux/module.h:128:42: error: invalid storage class for function '__inittest'
     static inline initcall_t __maybe_unused __inittest(void)  \
                                             ^
   drivers/scsi/device_handler/scsi_dh_rdac.c:829:1: note: in expansion of macro 'module_init'
    module_init(rdac_init);
    ^~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:829:1: warning: 'alias' attribute ignored [-Wattributes]
   In file included from drivers/scsi/device_handler/scsi_dh_rdac.c:27:0:
>> include/linux/module.h:134:42: error: invalid storage class for function '__exittest'
     static inline exitcall_t __maybe_unused __exittest(void)  \
                                             ^
   drivers/scsi/device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
>> include/linux/module.h:134:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     static inline exitcall_t __maybe_unused __exittest(void)  \
     ^
   drivers/scsi/device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:830:1: warning: 'alias' attribute ignored [-Wattributes]
   In file included from include/linux/module.h:18:0,
                    from drivers/scsi/device_handler/scsi_dh_rdac.c:27:
   include/linux/moduleparam.h:24:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    static const char __UNIQUE_ID(name)[]       \
    ^
   include/linux/module.h:159:32: note: in expansion of macro '__MODULE_INFO'
    #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
                                   ^~~~~~~~~~~~~
   include/linux/module.h:222:42: note: in expansion of macro 'MODULE_INFO'
    #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
                                             ^~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:832:1: note: in expansion of macro 'MODULE_DESCRIPTION'
    MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
    ^~~~~~~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:835:1: error: expected declaration or statement at end of input
    MODULE_LICENSE("GPL");
    ^~~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c: At top level:
   drivers/scsi/device_handler/scsi_dh_rdac.c:237:13: warning: 'send_mode_select' used but never defined
    static void send_mode_select(struct work_struct *work);
                ^~~~~~~~~~~~~~~~

drivers/scsi/device_handler/scsi_dh_rdac.c:527:13: warning: 'send_mode_select' defined but not used [-Wunused-function]
static void send_mode_select(struct work_struct *work)
^~~~~~~~~~~~~~~~
--
drivers/scsi//device_handler/scsi_dh_rdac.c: In function 'check_ownership':
drivers/scsi//device_handler/scsi_dh_rdac.c:437:12: error: invalid storage class for function 'initialize_controller'
static int initialize_controller(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:437:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
static int initialize_controller(struct scsi_device *sdev,
^~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:465:12: error: invalid storage class for function 'set_mode_select'
static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:485:12: error: invalid storage class for function 'mode_select_handle_sense'
static int mode_select_handle_sense(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:527:13: error: invalid storage class for function 'send_mode_select'
static void send_mode_select(struct work_struct *work)
^~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:585:12: error: invalid storage class for function 'queue_mode_select'
static int queue_mode_select(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:611:12: error: invalid storage class for function 'rdac_activate'
static int rdac_activate(struct scsi_device *sdev,
^~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:647:21: error: invalid storage class for function 'rdac_prep_fn'
static blk_status_t rdac_prep_fn(struct scsi_device *sdev, struct request *req)
^~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:659:12: error: invalid storage class for function 'rdac_check_sense'
static int rdac_check_sense(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:724:12: error: invalid storage class for function 'rdac_bus_attach'
static int rdac_bus_attach(struct scsi_device *sdev)
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:771:13: error: invalid storage class for function 'rdac_bus_detach'
static void rdac_bus_detach( struct scsi_device *sdev )
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:792:13: error: initializer element is not constant
.prep_fn = rdac_prep_fn,
^~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:792:13: note: (near initialization for 'rdac_dh.prep_fn') drivers/scsi//device_handler/scsi_dh_rdac.c:793:17: error: initializer element is not constant
.check_sense = rdac_check_sense,
^~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:793:17: note: (near initialization for 'rdac_dh.check_sense') drivers/scsi//device_handler/scsi_dh_rdac.c:794:12: error: initializer element is not constant
.attach = rdac_bus_attach,
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:794:12: note: (near initialization for 'rdac_dh.attach') drivers/scsi//device_handler/scsi_dh_rdac.c:795:12: error: initializer element is not constant
.detach = rdac_bus_detach,
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:795:12: note: (near initialization for 'rdac_dh.detach') drivers/scsi//device_handler/scsi_dh_rdac.c:796:14: error: initializer element is not constant
.activate = rdac_activate,
^~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:796:14: note: (near initialization for 'rdac_dh.activate') drivers/scsi//device_handler/scsi_dh_rdac.c:799:19: error: invalid storage class for function 'rdac_init'
static int __init rdac_init(void)
^~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:823:20: error: invalid storage class for function 'rdac_exit'
static void __exit rdac_exit(void)
^~~~~~~~~
In file included from drivers/scsi//device_handler/scsi_dh_rdac.c:27:0:

>> include/linux/module.h:128:42: error: invalid storage class for function '__inittest'
     static inline initcall_t __maybe_unused __inittest(void)  \
                                             ^
   drivers/scsi//device_handler/scsi_dh_rdac.c:829:1: note: in expansion of macro 'module_init'
    module_init(rdac_init);
    ^~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:829:1: warning: 'alias' attribute ignored [-Wattributes]
   In file included from drivers/scsi//device_handler/scsi_dh_rdac.c:27:0:
>> include/linux/module.h:134:42: error: invalid storage class for function '__exittest'
     static inline exitcall_t __maybe_unused __exittest(void)  \
                                             ^
   drivers/scsi//device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
>> include/linux/module.h:134:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     static inline exitcall_t __maybe_unused __exittest(void)  \
     ^
   drivers/scsi//device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:830:1: warning: 'alias' attribute ignored [-Wattributes]
   In file included from include/linux/module.h:18:0,
                    from drivers/scsi//device_handler/scsi_dh_rdac.c:27:
   include/linux/moduleparam.h:24:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    static const char __UNIQUE_ID(name)[]       \
    ^
   include/linux/module.h:159:32: note: in expansion of macro '__MODULE_INFO'
    #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
                                   ^~~~~~~~~~~~~
   include/linux/module.h:222:42: note: in expansion of macro 'MODULE_INFO'
    #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
                                             ^~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:832:1: note: in expansion of macro 'MODULE_DESCRIPTION'
    MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
    ^~~~~~~~~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:835:1: error: expected declaration or statement at end of input
    MODULE_LICENSE("GPL");
    ^~~~~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c: At top level:
   drivers/scsi//device_handler/scsi_dh_rdac.c:237:13: warning: 'send_mode_select' used but never defined
    static void send_mode_select(struct work_struct *work);
                ^~~~~~~~~~~~~~~~

drivers/scsi//device_handler/scsi_dh_rdac.c:527:13: warning: 'send_mode_select' defined but not used [-Wunused-function]
static void send_mode_select(struct work_struct *work)
^~~~~~~~~~~~~~~~

vim +/alias +829 drivers/scsi/device_handler/scsi_dh_rdac.c

fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01 828 fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01 @829 module_init(rdac_init); fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01 830 module_exit(rdac_exit); fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01 831

:::::: The code at line 829 was first introduced by commit
:::::: fbd7ab3eb53a3b88fefa7873139a62e439860155 [SCSI] scsi_dh: add lsi rdac device handler

:::::: TO: Chandra Seetharaman <[email protected]> :::::: CC: James Bottomley <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation

#4 lore raw
In reply to Hannes Reinecke
I love your patch! Yet something to improve:

Hi Hannes,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on v5.4-rc7 next-20191112]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi_dh_rdac-avoid-crash-during-rescan/20191113-021538
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: x86_64-rhel-7.6-kasan (attached as .config)
compiler: gcc-7 (Debian 7.4.0-14) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/scsi/device_handler/scsi_dh_rdac.c: In function 'check_ownership':

>> drivers/scsi/device_handler/scsi_dh_rdac.c:437:12: error: invalid storage class for function 'initialize_controller'
    static int initialize_controller(struct scsi_device *sdev,
               ^~~~~~~~~~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:437:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    static int initialize_controller(struct scsi_device *sdev,
    ^~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:465:12: error: invalid storage class for function 'set_mode_select'
    static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
               ^~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:485:12: error: invalid storage class for function 'mode_select_handle_sense'
    static int mode_select_handle_sense(struct scsi_device *sdev,
               ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:527:13: error: invalid storage class for function 'send_mode_select'
    static void send_mode_select(struct work_struct *work)
                ^~~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:585:12: error: invalid storage class for function 'queue_mode_select'
    static int queue_mode_select(struct scsi_device *sdev,
               ^~~~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:611:12: error: invalid storage class for function 'rdac_activate'
    static int rdac_activate(struct scsi_device *sdev,
               ^~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:647:21: error: invalid storage class for function 'rdac_prep_fn'
    static blk_status_t rdac_prep_fn(struct scsi_device *sdev, struct request *req)
                        ^~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:659:12: error: invalid storage class for function 'rdac_check_sense'
    static int rdac_check_sense(struct scsi_device *sdev,
               ^~~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:724:12: error: invalid storage class for function 'rdac_bus_attach'
    static int rdac_bus_attach(struct scsi_device *sdev)
               ^~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:771:13: error: invalid storage class for function 'rdac_bus_detach'
    static void rdac_bus_detach( struct scsi_device *sdev )
                ^~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:792:13: error: initializer element is not constant
     .prep_fn = rdac_prep_fn,
                ^~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:792:13: note: (near initialization for 'rdac_dh.prep_fn')
   drivers/scsi/device_handler/scsi_dh_rdac.c:793:17: error: initializer element is not constant
     .check_sense = rdac_check_sense,
                    ^~~~~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:793:17: note: (near initialization for 'rdac_dh.check_sense')
   drivers/scsi/device_handler/scsi_dh_rdac.c:794:12: error: initializer element is not constant
     .attach = rdac_bus_attach,
               ^~~~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:794:12: note: (near initialization for 'rdac_dh.attach')
   drivers/scsi/device_handler/scsi_dh_rdac.c:795:12: error: initializer element is not constant
     .detach = rdac_bus_detach,
               ^~~~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:795:12: note: (near initialization for 'rdac_dh.detach')
   drivers/scsi/device_handler/scsi_dh_rdac.c:796:14: error: initializer element is not constant
     .activate = rdac_activate,
                 ^~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:796:14: note: (near initialization for 'rdac_dh.activate')
>> drivers/scsi/device_handler/scsi_dh_rdac.c:799:19: error: invalid storage class for function 'rdac_init'
    static int __init rdac_init(void)
                      ^~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:823:20: error: invalid storage class for function 'rdac_exit'
    static void __exit rdac_exit(void)
                       ^~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from include/linux/scatterlist.h:5,
                    from include/scsi/scsi.h:10,
                    from drivers/scsi/device_handler/scsi_dh_rdac.c:22:
>> include/linux/compiler.h:302:44: error: initializer element is not constant
      __PASTE(__addressable_##sym, __LINE__) = (void *)&sym;
                                               ^
   include/linux/init.h:189:2: note: in expansion of macro '__ADDRESSABLE'
     __ADDRESSABLE(fn)     \
     ^~~~~~~~~~~~~
   include/linux/init.h:200:35: note: in expansion of macro '___define_initcall'
    #define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id)
                                      ^~~~~~~~~~~~~~~~~~
   include/linux/init.h:229:30: note: in expansion of macro '__define_initcall'
    #define device_initcall(fn)  __define_initcall(fn, 6)
                                 ^~~~~~~~~~~~~~~~~
   include/linux/init.h:234:24: note: in expansion of macro 'device_initcall'
    #define __initcall(fn) device_initcall(fn)
                           ^~~~~~~~~~~~~~~
   include/linux/module.h:85:24: note: in expansion of macro '__initcall'
    #define module_init(x) __initcall(x);
                           ^~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:829:1: note: in expansion of macro 'module_init'
    module_init(rdac_init);
    ^~~~~~~~~~~
   In file included from include/linux/printk.h:6:0,
                    from include/linux/kernel.h:15,
                    from include/asm-generic/bug.h:19,
                    from arch/x86/include/asm/bug.h:83,
                    from include/linux/bug.h:5,
                    from include/linux/scatterlist.h:7,
                    from include/scsi/scsi.h:10,
                    from drivers/scsi/device_handler/scsi_dh_rdac.c:22:
   drivers/scsi/device_handler/scsi_dh_rdac.c:830:13: error: initializer element is not constant
    module_exit(rdac_exit);
                ^
   include/linux/init.h:237:50: note: in definition of macro '__exitcall'
     static exitcall_t __exitcall_##fn __exit_call = fn
                                                     ^~
   drivers/scsi/device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
   include/linux/init.h:237:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     static exitcall_t __exitcall_##fn __exit_call = fn
     ^
   include/linux/module.h:97:24: note: in expansion of macro '__exitcall'
    #define module_exit(x) __exitcall(x);
                           ^~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
   In file included from include/linux/module.h:18:0,
                    from drivers/scsi/device_handler/scsi_dh_rdac.c:27:
   include/linux/moduleparam.h:24:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    static const char __UNIQUE_ID(name)[]       \
    ^
   include/linux/module.h:159:32: note: in expansion of macro '__MODULE_INFO'
    #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
                                   ^~~~~~~~~~~~~
   include/linux/module.h:222:42: note: in expansion of macro 'MODULE_INFO'
    #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
                                             ^~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c:832:1: note: in expansion of macro 'MODULE_DESCRIPTION'
    MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
    ^~~~~~~~~~~~~~~~~~
>> drivers/scsi/device_handler/scsi_dh_rdac.c:835:1: error: expected declaration or statement at end of input
    MODULE_LICENSE("GPL");
    ^~~~~~~~~~~~~~
   drivers/scsi/device_handler/scsi_dh_rdac.c: At top level:
   drivers/scsi/device_handler/scsi_dh_rdac.c:237:13: warning: 'send_mode_select' used but never defined
    static void send_mode_select(struct work_struct *work);
                ^~~~~~~~~~~~~~~~

drivers/scsi/device_handler/scsi_dh_rdac.c:527:13: warning: 'send_mode_select' defined but not used [-Wunused-function]
static void send_mode_select(struct work_struct *work)
^~~~~~~~~~~~~~~~
--
drivers/scsi//device_handler/scsi_dh_rdac.c: In function 'check_ownership':
drivers/scsi//device_handler/scsi_dh_rdac.c:437:12: error: invalid storage class for function 'initialize_controller'
static int initialize_controller(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:437:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
static int initialize_controller(struct scsi_device *sdev,
^~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:465:12: error: invalid storage class for function 'set_mode_select'
static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:485:12: error: invalid storage class for function 'mode_select_handle_sense'
static int mode_select_handle_sense(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:527:13: error: invalid storage class for function 'send_mode_select'
static void send_mode_select(struct work_struct *work)
^~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:585:12: error: invalid storage class for function 'queue_mode_select'
static int queue_mode_select(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:611:12: error: invalid storage class for function 'rdac_activate'
static int rdac_activate(struct scsi_device *sdev,
^~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:647:21: error: invalid storage class for function 'rdac_prep_fn'
static blk_status_t rdac_prep_fn(struct scsi_device *sdev, struct request *req)
^~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:659:12: error: invalid storage class for function 'rdac_check_sense'
static int rdac_check_sense(struct scsi_device *sdev,
^~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:724:12: error: invalid storage class for function 'rdac_bus_attach'
static int rdac_bus_attach(struct scsi_device *sdev)
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:771:13: error: invalid storage class for function 'rdac_bus_detach'
static void rdac_bus_detach( struct scsi_device *sdev )
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:792:13: error: initializer element is not constant
.prep_fn = rdac_prep_fn,
^~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:792:13: note: (near initialization for 'rdac_dh.prep_fn') drivers/scsi//device_handler/scsi_dh_rdac.c:793:17: error: initializer element is not constant
.check_sense = rdac_check_sense,
^~~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:793:17: note: (near initialization for 'rdac_dh.check_sense') drivers/scsi//device_handler/scsi_dh_rdac.c:794:12: error: initializer element is not constant
.attach = rdac_bus_attach,
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:794:12: note: (near initialization for 'rdac_dh.attach') drivers/scsi//device_handler/scsi_dh_rdac.c:795:12: error: initializer element is not constant
.detach = rdac_bus_detach,
^~~~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:795:12: note: (near initialization for 'rdac_dh.detach') drivers/scsi//device_handler/scsi_dh_rdac.c:796:14: error: initializer element is not constant
.activate = rdac_activate,
^~~~~~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:796:14: note: (near initialization for 'rdac_dh.activate') drivers/scsi//device_handler/scsi_dh_rdac.c:799:19: error: invalid storage class for function 'rdac_init'
static int __init rdac_init(void)
^~~~~~~~~
drivers/scsi//device_handler/scsi_dh_rdac.c:823:20: error: invalid storage class for function 'rdac_exit'
static void __exit rdac_exit(void)
^~~~~~~~~
In file included from include/linux/string.h:6:0,
from include/linux/scatterlist.h:5,
from include/scsi/scsi.h:10,
from drivers/scsi//device_handler/scsi_dh_rdac.c:22:

>> include/linux/compiler.h:302:44: error: initializer element is not constant
      __PASTE(__addressable_##sym, __LINE__) = (void *)&sym;
                                               ^
   include/linux/init.h:189:2: note: in expansion of macro '__ADDRESSABLE'
     __ADDRESSABLE(fn)     \
     ^~~~~~~~~~~~~
   include/linux/init.h:200:35: note: in expansion of macro '___define_initcall'
    #define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id)
                                      ^~~~~~~~~~~~~~~~~~
   include/linux/init.h:229:30: note: in expansion of macro '__define_initcall'
    #define device_initcall(fn)  __define_initcall(fn, 6)
                                 ^~~~~~~~~~~~~~~~~
   include/linux/init.h:234:24: note: in expansion of macro 'device_initcall'
    #define __initcall(fn) device_initcall(fn)
                           ^~~~~~~~~~~~~~~
   include/linux/module.h:85:24: note: in expansion of macro '__initcall'
    #define module_init(x) __initcall(x);
                           ^~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:829:1: note: in expansion of macro 'module_init'
    module_init(rdac_init);
    ^~~~~~~~~~~
   In file included from include/linux/printk.h:6:0,
                    from include/linux/kernel.h:15,
                    from include/asm-generic/bug.h:19,
                    from arch/x86/include/asm/bug.h:83,
                    from include/linux/bug.h:5,
                    from include/linux/scatterlist.h:7,
                    from include/scsi/scsi.h:10,
                    from drivers/scsi//device_handler/scsi_dh_rdac.c:22:
   drivers/scsi//device_handler/scsi_dh_rdac.c:830:13: error: initializer element is not constant
    module_exit(rdac_exit);
                ^
   include/linux/init.h:237:50: note: in definition of macro '__exitcall'
     static exitcall_t __exitcall_##fn __exit_call = fn
                                                     ^~
   drivers/scsi//device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
   include/linux/init.h:237:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     static exitcall_t __exitcall_##fn __exit_call = fn
     ^
   include/linux/module.h:97:24: note: in expansion of macro '__exitcall'
    #define module_exit(x) __exitcall(x);
                           ^~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:830:1: note: in expansion of macro 'module_exit'
    module_exit(rdac_exit);
    ^~~~~~~~~~~
   In file included from include/linux/module.h:18:0,
                    from drivers/scsi//device_handler/scsi_dh_rdac.c:27:
   include/linux/moduleparam.h:24:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    static const char __UNIQUE_ID(name)[]       \
    ^
   include/linux/module.h:159:32: note: in expansion of macro '__MODULE_INFO'
    #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
                                   ^~~~~~~~~~~~~
   include/linux/module.h:222:42: note: in expansion of macro 'MODULE_INFO'
    #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
                                             ^~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:832:1: note: in expansion of macro 'MODULE_DESCRIPTION'
    MODULE_DESCRIPTION("Multipath LSI/Engenio/NetApp E-Series RDAC driver");
    ^~~~~~~~~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c:835:1: error: expected declaration or statement at end of input
    MODULE_LICENSE("GPL");
    ^~~~~~~~~~~~~~
   drivers/scsi//device_handler/scsi_dh_rdac.c: At top level:
   drivers/scsi//device_handler/scsi_dh_rdac.c:237:13: warning: 'send_mode_select' used but never defined
    static void send_mode_select(struct work_struct *work);
                ^~~~~~~~~~~~~~~~

drivers/scsi//device_handler/scsi_dh_rdac.c:527:13: warning: 'send_mode_select' defined but not used [-Wunused-function]
static void send_mode_select(struct work_struct *work)
^~~~~~~~~~~~~~~~

vim +/initialize_controller +437 drivers/scsi/device_handler/scsi_dh_rdac.c

fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01 436

ca9f0089867c9e Hannes Reinecke     2008-07-17 @437  static int initialize_controller(struct scsi_device *sdev,
a53becc9a9dbe4 Chandra Seetharaman 2011-07-20  438  		struct rdac_dh_data *h, char *array_name, u8 *array_id)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  439  {
3278255741326b Hannes Reinecke     2016-11-03  440  	int err = SCSI_DH_IO, index;
3278255741326b Hannes Reinecke     2016-11-03  441  	struct c4_inquiry *inqp = &h->inq.c4;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  442  
3278255741326b Hannes Reinecke     2016-11-03  443  	if (!scsi_get_vpd_page(sdev, 0xC4, (unsigned char *)inqp,
3278255741326b Hannes Reinecke     2016-11-03  444  			       sizeof(struct c4_inquiry))) {
a53becc9a9dbe4 Chandra Seetharaman 2011-07-20  445  		/* get the controller index */
a53becc9a9dbe4 Chandra Seetharaman 2011-07-20  446  		if (inqp->slot_id[1] == 0x31)
a53becc9a9dbe4 Chandra Seetharaman 2011-07-20  447  			index = 0;
a53becc9a9dbe4 Chandra Seetharaman 2011-07-20  448  		else
a53becc9a9dbe4 Chandra Seetharaman 2011-07-20  449  			index = 1;
3569e5374df66a Moger, Babu         2012-02-02  450  
3569e5374df66a Moger, Babu         2012-02-02  451  		spin_lock(&list_lock);
d6857595394f1f Chandra Seetharaman 2011-07-27  452  		h->ctlr = get_controller(index, array_name, array_id, sdev);
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  453  		if (!h->ctlr)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  454  			err = SCSI_DH_RES_TEMP_UNAVAIL;
1a5dc166cd8843 Hannes Reinecke     2016-03-03  455  		else {
1a5dc166cd8843 Hannes Reinecke     2016-03-03  456  			list_add_rcu(&h->node, &h->ctlr->dh_list);
1a5dc166cd8843 Hannes Reinecke     2016-03-03  457  			h->sdev = sdev;
1a5dc166cd8843 Hannes Reinecke     2016-03-03  458  		}
3569e5374df66a Moger, Babu         2012-02-02  459  		spin_unlock(&list_lock);
3278255741326b Hannes Reinecke     2016-11-03  460  		err = SCSI_DH_OK;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  461  	}
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  462  	return err;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  463  }
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  464  
ca9f0089867c9e Hannes Reinecke     2008-07-17 @465  static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  466  {
3278255741326b Hannes Reinecke     2016-11-03  467  	int err = SCSI_DH_IO;
3278255741326b Hannes Reinecke     2016-11-03  468  	struct c2_inquiry *inqp = &h->inq.c2;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  469  
3278255741326b Hannes Reinecke     2016-11-03  470  	if (!scsi_get_vpd_page(sdev, 0xC2, (unsigned char *)inqp,
3278255741326b Hannes Reinecke     2016-11-03  471  			       sizeof(struct c2_inquiry))) {
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  472  		/*
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  473  		 * If more than MODE6_MAX_LUN luns are supported, use
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  474  		 * mode select 10
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  475  		 */
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  476  		if (inqp->max_lun_supported >= MODE6_MAX_LUN)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  477  			h->ctlr->use_ms10 = 1;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  478  		else
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  479  			h->ctlr->use_ms10 = 0;
3278255741326b Hannes Reinecke     2016-11-03  480  		err = SCSI_DH_OK;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  481  	}
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  482  	return err;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  483  }
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  484  
ca9f0089867c9e Hannes Reinecke     2008-07-17 @485  static int mode_select_handle_sense(struct scsi_device *sdev,
3278255741326b Hannes Reinecke     2016-11-03  486  				    struct scsi_sense_hdr *sense_hdr)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  487  {
3278255741326b Hannes Reinecke     2016-11-03  488  	int err = SCSI_DH_IO;
ee14c674e8fc57 Christoph Hellwig   2015-08-27  489  	struct rdac_dh_data *h = sdev->handler_data;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  490  
3278255741326b Hannes Reinecke     2016-11-03  491  	if (!scsi_sense_valid(sense_hdr))
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  492  		goto done;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  493  
3278255741326b Hannes Reinecke     2016-11-03  494  	switch (sense_hdr->sense_key) {
7687fb9209422d Chauhan, Vijay      2009-03-04  495  	case NO_SENSE:
7687fb9209422d Chauhan, Vijay      2009-03-04  496  	case ABORTED_COMMAND:
7687fb9209422d Chauhan, Vijay      2009-03-04  497  	case UNIT_ATTENTION:
7687fb9209422d Chauhan, Vijay      2009-03-04  498  		err = SCSI_DH_RETRY;
7687fb9209422d Chauhan, Vijay      2009-03-04  499  		break;
7687fb9209422d Chauhan, Vijay      2009-03-04  500  	case NOT_READY:
3278255741326b Hannes Reinecke     2016-11-03  501  		if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x01)
7687fb9209422d Chauhan, Vijay      2009-03-04  502  			/* LUN Not Ready and is in the Process of Becoming
7687fb9209422d Chauhan, Vijay      2009-03-04  503  			 * Ready
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  504  			 */
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  505  			err = SCSI_DH_RETRY;
7687fb9209422d Chauhan, Vijay      2009-03-04  506  		break;
7687fb9209422d Chauhan, Vijay      2009-03-04  507  	case ILLEGAL_REQUEST:
3278255741326b Hannes Reinecke     2016-11-03  508  		if (sense_hdr->asc == 0x91 && sense_hdr->ascq == 0x36)
7687fb9209422d Chauhan, Vijay      2009-03-04  509  			/*
7687fb9209422d Chauhan, Vijay      2009-03-04  510  			 * Command Lock contention
7687fb9209422d Chauhan, Vijay      2009-03-04  511  			 */
d2d06d4fe0f2cc Hannes Reinecke     2016-01-22  512  			err = SCSI_DH_IMM_RETRY;
7687fb9209422d Chauhan, Vijay      2009-03-04  513  		break;
7687fb9209422d Chauhan, Vijay      2009-03-04  514  	default:
dd784edcfc080f Moger, Babu         2009-09-03  515  		break;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  516  	}
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  517  
dd784edcfc080f Moger, Babu         2009-09-03  518  	RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
dd784edcfc080f Moger, Babu         2009-09-03  519  		"MODE_SELECT returned with sense %02x/%02x/%02x",
dd784edcfc080f Moger, Babu         2009-09-03  520  		(char *) h->ctlr->array_name, h->ctlr->index,
3278255741326b Hannes Reinecke     2016-11-03  521  		sense_hdr->sense_key, sense_hdr->asc, sense_hdr->ascq);
dd784edcfc080f Moger, Babu         2009-09-03  522  
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  523  done:
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  524  	return err;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  525  }
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  526  
970f3f47e7c97c Chandra Seetharaman 2009-10-21 @527  static void send_mode_select(struct work_struct *work)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  528  {
970f3f47e7c97c Chandra Seetharaman 2009-10-21  529  	struct rdac_controller *ctlr =
970f3f47e7c97c Chandra Seetharaman 2009-10-21  530  		container_of(work, struct rdac_controller, ms_work);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  531  	struct scsi_device *sdev = ctlr->ms_sdev;
ee14c674e8fc57 Christoph Hellwig   2015-08-27  532  	struct rdac_dh_data *h = sdev->handler_data;
3278255741326b Hannes Reinecke     2016-11-03  533  	int err = SCSI_DH_OK, retry_cnt = RDAC_RETRY_COUNT;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  534  	struct rdac_queue_data *tmp, *qdata;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  535  	LIST_HEAD(list);
92eb506262a2a3 Stephen Kitt        2018-03-09  536  	unsigned char cdb[MAX_COMMAND_SIZE];
3278255741326b Hannes Reinecke     2016-11-03  537  	struct scsi_sense_hdr sshdr;
3278255741326b Hannes Reinecke     2016-11-03  538  	unsigned int data_size;
3278255741326b Hannes Reinecke     2016-11-03  539  	u64 req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
3278255741326b Hannes Reinecke     2016-11-03  540  		REQ_FAILFAST_DRIVER;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  541  
970f3f47e7c97c Chandra Seetharaman 2009-10-21  542  	spin_lock(&ctlr->ms_lock);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  543  	list_splice_init(&ctlr->ms_head, &list);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  544  	ctlr->ms_queued = 0;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  545  	ctlr->ms_sdev = NULL;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  546  	spin_unlock(&ctlr->ms_lock);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  547  
c85f8cb9254e60 Chandra Seetharaman 2008-11-05  548   retry:
57adf5d4cfd319 Martin Wilck        2019-09-04  549  	memset(cdb, 0, sizeof(cdb));
57adf5d4cfd319 Martin Wilck        2019-09-04  550  
3278255741326b Hannes Reinecke     2016-11-03  551  	data_size = rdac_failover_get(ctlr, &list, cdb);
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  552  
dd784edcfc080f Moger, Babu         2009-09-03  553  	RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
dd784edcfc080f Moger, Babu         2009-09-03  554  		"%s MODE_SELECT command",
dd784edcfc080f Moger, Babu         2009-09-03  555  		(char *) h->ctlr->array_name, h->ctlr->index,
c85f8cb9254e60 Chandra Seetharaman 2008-11-05  556  		(retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying");
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  557  
fcbfffe2c5cbec Christoph Hellwig   2017-02-23  558  	if (scsi_execute(sdev, cdb, DMA_TO_DEVICE, &h->ctlr->mode_select,
fcbfffe2c5cbec Christoph Hellwig   2017-02-23  559  			data_size, NULL, &sshdr, RDAC_TIMEOUT * HZ,
fcbfffe2c5cbec Christoph Hellwig   2017-02-23  560  			RDAC_RETRIES, req_flags, 0, NULL)) {
3278255741326b Hannes Reinecke     2016-11-03  561  		err = mode_select_handle_sense(sdev, &sshdr);
c85f8cb9254e60 Chandra Seetharaman 2008-11-05  562  		if (err == SCSI_DH_RETRY && retry_cnt--)
c85f8cb9254e60 Chandra Seetharaman 2008-11-05  563  			goto retry;
d2d06d4fe0f2cc Hannes Reinecke     2016-01-22  564  		if (err == SCSI_DH_IMM_RETRY)
d2d06d4fe0f2cc Hannes Reinecke     2016-01-22  565  			goto retry;
c85f8cb9254e60 Chandra Seetharaman 2008-11-05  566  	}
dd784edcfc080f Moger, Babu         2009-09-03  567  	if (err == SCSI_DH_OK) {
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  568  		h->state = RDAC_STATE_ACTIVE;
dd784edcfc080f Moger, Babu         2009-09-03  569  		RDAC_LOG(RDAC_LOG_FAILOVER, sdev, "array %s, ctlr %d, "
dd784edcfc080f Moger, Babu         2009-09-03  570  				"MODE_SELECT completed",
dd784edcfc080f Moger, Babu         2009-09-03  571  				(char *) h->ctlr->array_name, h->ctlr->index);
dd784edcfc080f Moger, Babu         2009-09-03  572  	}
ca9f0089867c9e Hannes Reinecke     2008-07-17  573  
970f3f47e7c97c Chandra Seetharaman 2009-10-21  574  	list_for_each_entry_safe(qdata, tmp, &list, entry) {
970f3f47e7c97c Chandra Seetharaman 2009-10-21  575  		list_del(&qdata->entry);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  576  		if (err == SCSI_DH_OK)
970f3f47e7c97c Chandra Seetharaman 2009-10-21  577  			qdata->h->state = RDAC_STATE_ACTIVE;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  578  		if (qdata->callback_fn)
970f3f47e7c97c Chandra Seetharaman 2009-10-21  579  			qdata->callback_fn(qdata->callback_data, err);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  580  		kfree(qdata);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  581  	}
970f3f47e7c97c Chandra Seetharaman 2009-10-21  582  	return;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  583  }
970f3f47e7c97c Chandra Seetharaman 2009-10-21  584  
970f3f47e7c97c Chandra Seetharaman 2009-10-21 @585  static int queue_mode_select(struct scsi_device *sdev,
970f3f47e7c97c Chandra Seetharaman 2009-10-21  586  				activate_complete fn, void *data)
970f3f47e7c97c Chandra Seetharaman 2009-10-21  587  {
970f3f47e7c97c Chandra Seetharaman 2009-10-21  588  	struct rdac_queue_data *qdata;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  589  	struct rdac_controller *ctlr;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  590  
970f3f47e7c97c Chandra Seetharaman 2009-10-21  591  	qdata = kzalloc(sizeof(*qdata), GFP_KERNEL);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  592  	if (!qdata)
970f3f47e7c97c Chandra Seetharaman 2009-10-21  593  		return SCSI_DH_RETRY;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  594  
ee14c674e8fc57 Christoph Hellwig   2015-08-27  595  	qdata->h = sdev->handler_data;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  596  	qdata->callback_fn = fn;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  597  	qdata->callback_data = data;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  598  
970f3f47e7c97c Chandra Seetharaman 2009-10-21  599  	ctlr = qdata->h->ctlr;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  600  	spin_lock(&ctlr->ms_lock);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  601  	list_add_tail(&qdata->entry, &ctlr->ms_head);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  602  	if (!ctlr->ms_queued) {
970f3f47e7c97c Chandra Seetharaman 2009-10-21  603  		ctlr->ms_queued = 1;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  604  		ctlr->ms_sdev = sdev;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  605  		queue_work(kmpath_rdacd, &ctlr->ms_work);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  606  	}
970f3f47e7c97c Chandra Seetharaman 2009-10-21  607  	spin_unlock(&ctlr->ms_lock);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  608  	return SCSI_DH_OK;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  609  }
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  610  
3ae31f6a7b6e44 Chandra Seetharaman 2009-10-21 @611  static int rdac_activate(struct scsi_device *sdev,
3ae31f6a7b6e44 Chandra Seetharaman 2009-10-21  612  			activate_complete fn, void *data)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  613  {
ee14c674e8fc57 Christoph Hellwig   2015-08-27  614  	struct rdac_dh_data *h = sdev->handler_data;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  615  	int err = SCSI_DH_OK;
3425fbfe229324 Moger, Babu         2011-04-08  616  	int act = 0;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  617  
ca9f0089867c9e Hannes Reinecke     2008-07-17  618  	err = check_ownership(sdev, h);
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  619  	if (err != SCSI_DH_OK)
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  620  		goto done;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  621  
3425fbfe229324 Moger, Babu         2011-04-08  622  	switch (h->mode) {
3425fbfe229324 Moger, Babu         2011-04-08  623  	case RDAC_MODE:
3425fbfe229324 Moger, Babu         2011-04-08  624  		if (h->lun_state == RDAC_LUN_UNOWNED)
3425fbfe229324 Moger, Babu         2011-04-08  625  			act = 1;
3425fbfe229324 Moger, Babu         2011-04-08  626  		break;
3425fbfe229324 Moger, Babu         2011-04-08  627  	case RDAC_MODE_IOSHIP:
3425fbfe229324 Moger, Babu         2011-04-08  628  		if ((h->lun_state == RDAC_LUN_UNOWNED) &&
3425fbfe229324 Moger, Babu         2011-04-08  629  		    (h->preferred == RDAC_PREFERRED))
3425fbfe229324 Moger, Babu         2011-04-08  630  			act = 1;
3425fbfe229324 Moger, Babu         2011-04-08  631  		break;
3425fbfe229324 Moger, Babu         2011-04-08  632  	default:
3425fbfe229324 Moger, Babu         2011-04-08  633  		break;
3425fbfe229324 Moger, Babu         2011-04-08  634  	}
3425fbfe229324 Moger, Babu         2011-04-08  635  
3425fbfe229324 Moger, Babu         2011-04-08  636  	if (act) {
970f3f47e7c97c Chandra Seetharaman 2009-10-21  637  		err = queue_mode_select(sdev, fn, data);
970f3f47e7c97c Chandra Seetharaman 2009-10-21  638  		if (err == SCSI_DH_OK)
970f3f47e7c97c Chandra Seetharaman 2009-10-21  639  			return 0;
970f3f47e7c97c Chandra Seetharaman 2009-10-21  640  	}
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  641  done:
3ae31f6a7b6e44 Chandra Seetharaman 2009-10-21  642  	if (fn)
3ae31f6a7b6e44 Chandra Seetharaman 2009-10-21  643  		fn(data, err);
3ae31f6a7b6e44 Chandra Seetharaman 2009-10-21  644  	return 0;
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  645  }
fbd7ab3eb53a3b Chandra Seetharaman 2008-05-01  646  

:::::: The code at line 437 was first introduced by commit
:::::: ca9f0089867c9e476cf2e6d4615d2aae887171b2 [SCSI] scsi_dh: Update RDAC device handler

:::::: TO: Hannes Reinecke <[email protected]>
:::::: CC: James Bottomley <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation

#5 lore raw
In reply to Hannes Reinecke
Quoted 2 lines · Hannes Reinecke

During rescanning the device might already have been removed, so we should drop the BUG_ON and just ignore the non-existing device.

The device is also added to the list before sdev is set, which is rather silly, so that might be worth fixing as well.