ia64/linux-2.6.18-xen.hg

changeset 596:132bae41625f

pvSCSI: Fix some aspects of attach/detach functionality

Signed-off-by: Tomonari Horikoshi <t.horikoshi@jp.fujitsu.com>
Signed-off-by: Jun Kamada <kama@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jul 08 09:30:34 2008 +0100 (2008-07-08)
parents 92247f7e5d8a
children db4f08203b8a
files drivers/xen/scsiback/xenbus.c drivers/xen/scsifront/xenbus.c
line diff
     1.1 --- a/drivers/xen/scsiback/xenbus.c	Tue Jul 08 09:29:42 2008 +0100
     1.2 +++ b/drivers/xen/scsiback/xenbus.c	Tue Jul 08 09:30:34 2008 +0100
     1.3 @@ -104,51 +104,23 @@ struct scsi_device *scsiback_get_scsi_de
     1.4  	if (IS_ERR(shost)) {
     1.5  		printk(KERN_ERR "scsiback: host%d doesn't exist.\n",
     1.6  			phy->hst);
     1.7 -		goto invald_value;
     1.8 +		return NULL;
     1.9  	}
    1.10  	sdev   = scsi_device_lookup(shost, phy->chn, phy->tgt, phy->lun);
    1.11  	if (!sdev) {
    1.12  		printk(KERN_ERR "scsiback: %d:%d:%d:%d doesn't exist.\n",
    1.13  			phy->hst, phy->chn, phy->tgt, phy->lun);
    1.14 -		goto invald_value;
    1.15 +		scsi_host_put(shost);
    1.16 +		return NULL;
    1.17  	}
    1.18  
    1.19  	scsi_host_put(shost);
    1.20 -invald_value:
    1.21  	return (sdev);
    1.22  }
    1.23  
    1.24  #define VSCSIBACK_OP_ADD_OR_DEL_LUN	1
    1.25  #define VSCSIBACK_OP_UPDATEDEV_STATE	2
    1.26  
    1.27 -static int scsiback_change_device_state(struct xenbus_device *dev,
    1.28 -			char *state_path, enum xenbus_state set_state)
    1.29 -{
    1.30 -	struct xenbus_transaction tr;
    1.31 -	int err;
    1.32 -	
    1.33 -	do {
    1.34 -		err = xenbus_transaction_start(&tr);
    1.35 -		if (err != 0) { 
    1.36 -			printk(KERN_ERR "scsiback: transaction start failed\n");
    1.37 -			return err;
    1.38 -		}
    1.39 -		err = xenbus_printf(tr, dev->nodename, state_path, 
    1.40 -				    "%d", set_state);
    1.41 -		if (err != 0) {
    1.42 -			printk(KERN_ERR "scsiback: xenbus_printf failed\n");
    1.43 -			xenbus_transaction_end(tr, 1);
    1.44 -			return err;
    1.45 -		}
    1.46 -		err = xenbus_transaction_end(tr, 0);
    1.47 -	} while (err == -EAGAIN);
    1.48 -	
    1.49 -	if (err != 0) {
    1.50 -		printk(KERN_ERR "scsiback: failed to end %s.\n", __FUNCTION__);
    1.51 -		return err;
    1.52 -	}
    1.53 -	return 0;	
    1.54 -}
    1.55  
    1.56  static void scsiback_do_lun_hotplug(struct backend_info *be, int op)
    1.57  {
    1.58 @@ -160,8 +132,6 @@ static void scsiback_do_lun_hotplug(stru
    1.59  	unsigned int dir_n = 0;
    1.60  	struct xenbus_device *dev = be->dev;
    1.61  	struct scsi_device *sdev;
    1.62 -	struct xenbus_transaction xbt;
    1.63 -
    1.64  
    1.65  	dir = xenbus_directory(XBT_NIL, dev->nodename, "vscsi-devs", &dir_n);
    1.66  	if (IS_ERR(dir))
    1.67 @@ -181,8 +151,8 @@ static void scsiback_do_lun_hotplug(stru
    1.68  		err = xenbus_scanf(XBT_NIL, dev->nodename, str,
    1.69  			"%u:%u:%u:%u", &phy.hst, &phy.chn, &phy.tgt, &phy.lun);
    1.70  		if (XENBUS_EXIST_ERR(err)) {
    1.71 -			xenbus_printf(xbt, dev->nodename, state_str,
    1.72 -					"%d", XenbusStateClosing);
    1.73 +			xenbus_printf(XBT_NIL, dev->nodename, state_str,
    1.74 +					"%d", XenbusStateClosed);
    1.75  			continue;
    1.76  		}
    1.77  
    1.78 @@ -191,8 +161,8 @@ static void scsiback_do_lun_hotplug(stru
    1.79  		err = xenbus_scanf(XBT_NIL, dev->nodename, str,
    1.80  			"%u:%u:%u:%u", &vir.hst, &vir.chn, &vir.tgt, &vir.lun);
    1.81  		if (XENBUS_EXIST_ERR(err)) {
    1.82 -			xenbus_printf(xbt, dev->nodename, state_str,
    1.83 -					"%d", XenbusStateClosing);
    1.84 +			xenbus_printf(XBT_NIL, dev->nodename, state_str,
    1.85 +					"%d", XenbusStateClosed);
    1.86  			continue;
    1.87  		}
    1.88  
    1.89 @@ -200,36 +170,30 @@ static void scsiback_do_lun_hotplug(stru
    1.90  		case VSCSIBACK_OP_ADD_OR_DEL_LUN:
    1.91  			if (device_state == XenbusStateInitialising) {
    1.92  				sdev = scsiback_get_scsi_device(&phy);
    1.93 -				if (!sdev) {
    1.94 -					err = scsiback_change_device_state(dev,
    1.95 -						state_str, XenbusStateClosing);
    1.96 -					if (err)
    1.97 -						goto fail;
    1.98 -				} else {
    1.99 +				if (!sdev)
   1.100 +					xenbus_printf(XBT_NIL, dev->nodename, state_str, 
   1.101 +							    "%d", XenbusStateClosed);
   1.102 +				else {
   1.103  					err = scsiback_add_translation_entry(be->info, sdev, &vir);
   1.104  					if (!err) {
   1.105 -						err = scsiback_change_device_state(dev,
   1.106 -							state_str, XenbusStateInitialised);
   1.107 -						if (err)
   1.108 -							goto fail;
   1.109 +						if (xenbus_printf(XBT_NIL, dev->nodename, state_str, 
   1.110 +								    "%d", XenbusStateInitialised)) {
   1.111 +							printk(KERN_ERR "scsiback: xenbus_printf error %s\n", state_str);
   1.112 +							scsiback_del_translation_entry(be->info, &vir);
   1.113 +						}
   1.114  					} else {
   1.115 -						err = scsiback_change_device_state(dev,
   1.116 -							state_str, XenbusStateClosing);
   1.117 -						if (err)
   1.118 -							goto fail;
   1.119 +						scsi_device_put(sdev);
   1.120 +						xenbus_printf(XBT_NIL, dev->nodename, state_str, 
   1.121 +								    "%d", XenbusStateClosed);
   1.122  					}
   1.123  				}
   1.124  			}
   1.125  
   1.126  			if (device_state == XenbusStateClosing) {
   1.127 -				err = scsiback_del_translation_entry(be->info, &vir);
   1.128 -				if (err)
   1.129 -					goto fail;
   1.130 -				else {
   1.131 -					err = scsiback_change_device_state(dev,
   1.132 -						state_str, XenbusStateClosed);
   1.133 -					if (err)
   1.134 -						goto fail;
   1.135 +				if (!scsiback_del_translation_entry(be->info, &vir)) {
   1.136 +					if (xenbus_printf(XBT_NIL, dev->nodename, state_str, 
   1.137 +							    "%d", XenbusStateClosed))
   1.138 +						printk(KERN_ERR "scsiback: xenbus_printf error %s\n", state_str);
   1.139  				}
   1.140  			}
   1.141  			break;
   1.142 @@ -237,10 +201,13 @@ static void scsiback_do_lun_hotplug(stru
   1.143  		case VSCSIBACK_OP_UPDATEDEV_STATE:
   1.144  			if (device_state == XenbusStateInitialised) {
   1.145  				/* modify vscsi-devs/dev-x/state */
   1.146 -				err = scsiback_change_device_state(dev,
   1.147 -					state_str, XenbusStateConnected);
   1.148 -				if (err)
   1.149 -					goto fail;
   1.150 +				if (xenbus_printf(XBT_NIL, dev->nodename, state_str, 
   1.151 +						    "%d", XenbusStateConnected)) {
   1.152 +					printk(KERN_ERR "scsiback: xenbus_printf error %s\n", state_str);
   1.153 +					scsiback_del_translation_entry(be->info, &vir);
   1.154 +					xenbus_printf(XBT_NIL, dev->nodename, state_str, 
   1.155 +							    "%d", XenbusStateClosed);
   1.156 +				}
   1.157  			}
   1.158  			break;
   1.159  		/*When it is necessary, processing is added here.*/
   1.160 @@ -251,10 +218,6 @@ static void scsiback_do_lun_hotplug(stru
   1.161  
   1.162  	kfree(dir);
   1.163  	return ;
   1.164 -fail :
   1.165 -	kfree(dir);
   1.166 -	xenbus_dev_fatal(dev, err, "read or write %s ", str);
   1.167 -	return;
   1.168  }
   1.169  
   1.170  
     2.1 --- a/drivers/xen/scsifront/xenbus.c	Tue Jul 08 09:29:42 2008 +0100
     2.2 +++ b/drivers/xen/scsifront/xenbus.c	Tue Jul 08 09:30:34 2008 +0100
     2.3 @@ -100,13 +100,13 @@ static int scsifront_alloc_ring(struct v
     2.4  
     2.5  	if (err <= 0) {
     2.6  		xenbus_dev_fatal(dev, err, "bind_listening_port_to_irqhandler");
     2.7 -		goto fail;
     2.8 +		goto free_sring;
     2.9  	}
    2.10  	info->irq = err;
    2.11  
    2.12  	return 0;
    2.13 -fail:
    2.14 -	/* free resource */
    2.15 +
    2.16 +/* free resource */
    2.17  free_sring:
    2.18  	scsifront_free(info);
    2.19  
    2.20 @@ -298,14 +298,14 @@ static void scsifront_do_lun_hotplug(str
    2.21  		err = xenbus_scanf(XBT_NIL, dev->otherend, str, "%u",
    2.22  			&device_state);
    2.23  		if (XENBUS_EXIST_ERR(err))
    2.24 -			goto fail;
    2.25 +			continue;
    2.26  		
    2.27  		/* virtual SCSI device */
    2.28  		snprintf(str, sizeof(str), "vscsi-devs/%s/v-dev", dir[i]);
    2.29  		err = xenbus_scanf(XBT_NIL, dev->otherend, str,
    2.30  			"%u:%u:%u:%u", &hst, &chn, &tgt, &lun);
    2.31  		if (XENBUS_EXIST_ERR(err))
    2.32 -			goto fail;
    2.33 +			continue;
    2.34  
    2.35  		/* front device state path */
    2.36  		snprintf(state_str, sizeof(state_str), "vscsi-devs/%s/state", dir[i]);
    2.37 @@ -338,18 +338,12 @@ static void scsifront_do_lun_hotplug(str
    2.38  			}
    2.39  			break;
    2.40  		default:
    2.41 -			goto fail;
    2.42  			break;
    2.43  		}
    2.44  	}
    2.45  	
    2.46  	kfree(dir);
    2.47  	return;
    2.48 -
    2.49 -fail:
    2.50 -	kfree(dir);
    2.51 -	xenbus_dev_fatal(dev, err, "read or write %s ", str);
    2.52 -	return;
    2.53  }
    2.54  
    2.55