mirror of
				git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
				synced 2025-10-31 16:54:21 +00:00 
			
		
		
		
	scsi: scsi_dh: Return SCSI_DH_XX error code from ->attach()
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>
This commit is contained in:
		
							parent
							
								
									b7af62a945
								
							
						
					
					
						commit
						2a8f7a0344
					
				
					 5 changed files with 32 additions and 19 deletions
				
			
		|  | @ -1085,11 +1085,11 @@ static void alua_rescan(struct scsi_device *sdev) | ||||||
| static int alua_bus_attach(struct scsi_device *sdev) | static int alua_bus_attach(struct scsi_device *sdev) | ||||||
| { | { | ||||||
| 	struct alua_dh_data *h; | 	struct alua_dh_data *h; | ||||||
| 	int err, ret = -EINVAL; | 	int err; | ||||||
| 
 | 
 | ||||||
| 	h = kzalloc(sizeof(*h) , GFP_KERNEL); | 	h = kzalloc(sizeof(*h) , GFP_KERNEL); | ||||||
| 	if (!h) | 	if (!h) | ||||||
| 		return -ENOMEM; | 		return SCSI_DH_NOMEM; | ||||||
| 	spin_lock_init(&h->pg_lock); | 	spin_lock_init(&h->pg_lock); | ||||||
| 	rcu_assign_pointer(h->pg, NULL); | 	rcu_assign_pointer(h->pg, NULL); | ||||||
| 	h->init_error = SCSI_DH_OK; | 	h->init_error = SCSI_DH_OK; | ||||||
|  | @ -1098,16 +1098,14 @@ static int alua_bus_attach(struct scsi_device *sdev) | ||||||
| 
 | 
 | ||||||
| 	mutex_init(&h->init_mutex); | 	mutex_init(&h->init_mutex); | ||||||
| 	err = alua_initialize(sdev, h); | 	err = alua_initialize(sdev, h); | ||||||
| 	if (err == SCSI_DH_NOMEM) |  | ||||||
| 		ret = -ENOMEM; |  | ||||||
| 	if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED) | 	if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED) | ||||||
| 		goto failed; | 		goto failed; | ||||||
| 
 | 
 | ||||||
| 	sdev->handler_data = h; | 	sdev->handler_data = h; | ||||||
| 	return 0; | 	return SCSI_DH_OK; | ||||||
| failed: | failed: | ||||||
| 	kfree(h); | 	kfree(h); | ||||||
| 	return ret; | 	return err; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  |  | ||||||
|  | @ -490,7 +490,7 @@ static int clariion_bus_attach(struct scsi_device *sdev) | ||||||
| 
 | 
 | ||||||
| 	h = kzalloc(sizeof(*h) , GFP_KERNEL); | 	h = kzalloc(sizeof(*h) , GFP_KERNEL); | ||||||
| 	if (!h) | 	if (!h) | ||||||
| 		return -ENOMEM; | 		return SCSI_DH_NOMEM; | ||||||
| 	h->lun_state = CLARIION_LUN_UNINITIALIZED; | 	h->lun_state = CLARIION_LUN_UNINITIALIZED; | ||||||
| 	h->default_sp = CLARIION_UNBOUND_LU; | 	h->default_sp = CLARIION_UNBOUND_LU; | ||||||
| 	h->current_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'); | 		    h->default_sp + 'A'); | ||||||
| 
 | 
 | ||||||
| 	sdev->handler_data = h; | 	sdev->handler_data = h; | ||||||
| 	return 0; | 	return SCSI_DH_OK; | ||||||
| 
 | 
 | ||||||
| failed: | failed: | ||||||
| 	kfree(h); | 	kfree(h); | ||||||
| 	return -EINVAL; | 	return err; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void clariion_bus_detach(struct scsi_device *sdev) | static void clariion_bus_detach(struct scsi_device *sdev) | ||||||
|  |  | ||||||
|  | @ -218,24 +218,28 @@ static int hp_sw_bus_attach(struct scsi_device *sdev) | ||||||
| 
 | 
 | ||||||
| 	h = kzalloc(sizeof(*h), GFP_KERNEL); | 	h = kzalloc(sizeof(*h), GFP_KERNEL); | ||||||
| 	if (!h) | 	if (!h) | ||||||
| 		return -ENOMEM; | 		return SCSI_DH_NOMEM; | ||||||
| 	h->path_state = HP_SW_PATH_UNINITIALIZED; | 	h->path_state = HP_SW_PATH_UNINITIALIZED; | ||||||
| 	h->retries = HP_SW_RETRIES; | 	h->retries = HP_SW_RETRIES; | ||||||
| 	h->sdev = sdev; | 	h->sdev = sdev; | ||||||
| 
 | 
 | ||||||
| 	ret = hp_sw_tur(sdev, h); | 	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; | 		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", | 	sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n", | ||||||
| 		    HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE? | 		    HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE? | ||||||
| 		    "active":"passive"); | 		    "active":"passive"); | ||||||
| 
 | 
 | ||||||
| 	sdev->handler_data = h; | 	sdev->handler_data = h; | ||||||
| 	return 0; | 	return SCSI_DH_OK; | ||||||
| failed: | failed: | ||||||
| 	kfree(h); | 	kfree(h); | ||||||
| 	return -EINVAL; | 	return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void hp_sw_bus_detach( struct scsi_device *sdev ) | static void hp_sw_bus_detach( struct scsi_device *sdev ) | ||||||
|  |  | ||||||
|  | @ -729,7 +729,7 @@ static int rdac_bus_attach(struct scsi_device *sdev) | ||||||
| 
 | 
 | ||||||
| 	h = kzalloc(sizeof(*h) , GFP_KERNEL); | 	h = kzalloc(sizeof(*h) , GFP_KERNEL); | ||||||
| 	if (!h) | 	if (!h) | ||||||
| 		return -ENOMEM; | 		return SCSI_DH_NOMEM; | ||||||
| 	h->lun = UNINITIALIZED_LUN; | 	h->lun = UNINITIALIZED_LUN; | ||||||
| 	h->state = RDAC_STATE_ACTIVE; | 	h->state = RDAC_STATE_ACTIVE; | ||||||
| 
 | 
 | ||||||
|  | @ -755,7 +755,7 @@ static int rdac_bus_attach(struct scsi_device *sdev) | ||||||
| 		    lun_state[(int)h->lun_state]); | 		    lun_state[(int)h->lun_state]); | ||||||
| 
 | 
 | ||||||
| 	sdev->handler_data = h; | 	sdev->handler_data = h; | ||||||
| 	return 0; | 	return SCSI_DH_OK; | ||||||
| 
 | 
 | ||||||
| clean_ctlr: | clean_ctlr: | ||||||
| 	spin_lock(&list_lock); | 	spin_lock(&list_lock); | ||||||
|  | @ -764,7 +764,7 @@ clean_ctlr: | ||||||
| 
 | 
 | ||||||
| failed: | failed: | ||||||
| 	kfree(h); | 	kfree(h); | ||||||
| 	return -EINVAL; | 	return err; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void rdac_bus_detach( struct scsi_device *sdev ) | static void rdac_bus_detach( struct scsi_device *sdev ) | ||||||
|  |  | ||||||
|  | @ -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, | static int scsi_dh_handler_attach(struct scsi_device *sdev, | ||||||
| 				  struct scsi_device_handler *scsi_dh) | 				  struct scsi_device_handler *scsi_dh) | ||||||
| { | { | ||||||
| 	int error; | 	int error, ret = 0; | ||||||
| 
 | 
 | ||||||
| 	if (!try_module_get(scsi_dh->module)) | 	if (!try_module_get(scsi_dh->module)) | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
| 
 | 
 | ||||||
| 	error = scsi_dh->attach(sdev); | 	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", | 		sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n", | ||||||
| 			    scsi_dh->name, error); | 			    scsi_dh->name, error); | ||||||
| 		module_put(scsi_dh->module); | 		module_put(scsi_dh->module); | ||||||
| 	} else | 	} else | ||||||
| 		sdev->handler = scsi_dh; | 		sdev->handler = scsi_dh; | ||||||
| 
 | 
 | ||||||
| 	return error; | 	return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Hannes Reinecke
						Hannes Reinecke