scsi: scsi_dh: Return SCSI_DH_XX error code from ->attach()
authorHannes Reinecke <hare@suse.de>
Wed, 20 Sep 2017 07:18:51 +0000 (09:18 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Mon, 25 Sep 2017 23:03:14 +0000 (19:03 -0400)
Rather than having each device handler implementing their own error
mapping, have the ->attach() call return a SCSI_DH_XXX error code and
implement the mapping in scsi_dh_handler_attach().

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/device_handler/scsi_dh_alua.c
drivers/scsi/device_handler/scsi_dh_emc.c
drivers/scsi/device_handler/scsi_dh_hp_sw.c
drivers/scsi/device_handler/scsi_dh_rdac.c
drivers/scsi/scsi_dh.c

index 0962fd5444016d8526ec03c99a9cad9fe61d2105..fd22dc6ab5d986f92a509c311d1d9faffeb3ce6d 100644 (file)
@@ -1085,11 +1085,11 @@ static void alua_rescan(struct scsi_device *sdev)
 static int alua_bus_attach(struct scsi_device *sdev)
 {
        struct alua_dh_data *h;
-       int err, ret = -EINVAL;
+       int err;
 
        h = kzalloc(sizeof(*h) , GFP_KERNEL);
        if (!h)
-               return -ENOMEM;
+               return SCSI_DH_NOMEM;
        spin_lock_init(&h->pg_lock);
        rcu_assign_pointer(h->pg, NULL);
        h->init_error = SCSI_DH_OK;
@@ -1098,16 +1098,14 @@ static int alua_bus_attach(struct scsi_device *sdev)
 
        mutex_init(&h->init_mutex);
        err = alua_initialize(sdev, h);
-       if (err == SCSI_DH_NOMEM)
-               ret = -ENOMEM;
        if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
                goto failed;
 
        sdev->handler_data = h;
-       return 0;
+       return SCSI_DH_OK;
 failed:
        kfree(h);
-       return ret;
+       return err;
 }
 
 /*
index 8654e940e1a809ff7304232bcc4d2209fdd4349b..6a2792f3a37eeb10a0d010707b88f099e327b394 100644 (file)
@@ -490,7 +490,7 @@ static int clariion_bus_attach(struct scsi_device *sdev)
 
        h = kzalloc(sizeof(*h) , GFP_KERNEL);
        if (!h)
-               return -ENOMEM;
+               return SCSI_DH_NOMEM;
        h->lun_state = CLARIION_LUN_UNINITIALIZED;
        h->default_sp = CLARIION_UNBOUND_LU;
        h->current_sp = CLARIION_UNBOUND_LU;
@@ -510,11 +510,11 @@ static int clariion_bus_attach(struct scsi_device *sdev)
                    h->default_sp + 'A');
 
        sdev->handler_data = h;
-       return 0;
+       return SCSI_DH_OK;
 
 failed:
        kfree(h);
-       return -EINVAL;
+       return err;
 }
 
 static void clariion_bus_detach(struct scsi_device *sdev)
index 62d314e07d11251352cfdd22379927c1edad016f..e65a0ebb4b5419c25e96aff01d028fd532adb170 100644 (file)
@@ -218,24 +218,28 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
 
        h = kzalloc(sizeof(*h), GFP_KERNEL);
        if (!h)
-               return -ENOMEM;
+               return SCSI_DH_NOMEM;
        h->path_state = HP_SW_PATH_UNINITIALIZED;
        h->retries = HP_SW_RETRIES;
        h->sdev = sdev;
 
        ret = hp_sw_tur(sdev, h);
-       if (ret != SCSI_DH_OK || h->path_state == HP_SW_PATH_UNINITIALIZED)
+       if (ret != SCSI_DH_OK)
                goto failed;
+       if (h->path_state == HP_SW_PATH_UNINITIALIZED) {
+               ret = SCSI_DH_NOSYS;
+               goto failed;
+       }
 
        sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n",
                    HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE?
                    "active":"passive");
 
        sdev->handler_data = h;
-       return 0;
+       return SCSI_DH_OK;
 failed:
        kfree(h);
-       return -EINVAL;
+       return ret;
 }
 
 static void hp_sw_bus_detach( struct scsi_device *sdev )
index 2ceff585f1896d9762fd288a93f4bcfde0bf2623..7af31a1247eee5ba020d3d3b1fea7e418d6277e8 100644 (file)
@@ -729,7 +729,7 @@ static int rdac_bus_attach(struct scsi_device *sdev)
 
        h = kzalloc(sizeof(*h) , GFP_KERNEL);
        if (!h)
-               return -ENOMEM;
+               return SCSI_DH_NOMEM;
        h->lun = UNINITIALIZED_LUN;
        h->state = RDAC_STATE_ACTIVE;
 
@@ -755,7 +755,7 @@ static int rdac_bus_attach(struct scsi_device *sdev)
                    lun_state[(int)h->lun_state]);
 
        sdev->handler_data = h;
-       return 0;
+       return SCSI_DH_OK;
 
 clean_ctlr:
        spin_lock(&list_lock);
@@ -764,7 +764,7 @@ clean_ctlr:
 
 failed:
        kfree(h);
-       return -EINVAL;
+       return err;
 }
 
 static void rdac_bus_detach( struct scsi_device *sdev )
index 84addee05be67a93fdc6a5445ec7618fa449b371..ac798d284a7e8131d3240fb01180fe93677779dd 100644 (file)
@@ -126,20 +126,31 @@ static struct scsi_device_handler *scsi_dh_lookup(const char *name)
 static int scsi_dh_handler_attach(struct scsi_device *sdev,
                                  struct scsi_device_handler *scsi_dh)
 {
-       int error;
+       int error, ret = 0;
 
        if (!try_module_get(scsi_dh->module))
                return -EINVAL;
 
        error = scsi_dh->attach(sdev);
-       if (error) {
+       if (error != SCSI_DH_OK) {
+               switch (error) {
+               case SCSI_DH_NOMEM:
+                       ret = -ENOMEM;
+                       break;
+               case SCSI_DH_RES_TEMP_UNAVAIL:
+                       ret = -EAGAIN;
+                       break;
+               default:
+                       ret = -EINVAL;
+                       break;
+               }
                sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
                            scsi_dh->name, error);
                module_put(scsi_dh->module);
        } else
                sdev->handler = scsi_dh;
 
-       return error;
+       return ret;
 }
 
 /*