From: Steven Smith Subject: Re: [PATCH 2/4] pvSCSI : Fix many points of backend/frontend driver Date: Fri, 4 Jul 2008 17:21:59 +0100 Message-ID: <20080704162159.GB21118@weybridge.uk.xensource.com> References: <20080703203710.8586.EB2C8575@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0807198009==" Return-path: In-Reply-To: <20080703203710.8586.EB2C8575@jp.fujitsu.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jun Kamada Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============0807198009== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="mxv5cy4qt+RJ9ypb" Content-Disposition: inline --mxv5cy4qt+RJ9ypb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > diff -r 3132ef07eecf -r e235e0bc18ab drivers/xen/scsiback/xenbus.c > --- a/drivers/xen/scsiback/xenbus.c Thu Jul 03 09:05:45 2008 +0900 > +++ b/drivers/xen/scsiback/xenbus.c Thu Jul 03 13:46:31 2008 +0900 > @@ -113,11 +113,42 @@ struct scsi_device *scsiback_get_scsi_de > goto invald_value; > } > =20 > + scsi_host_put(shost); > invald_value: > return (sdev); > } > =20 > #define VSCSIBACK_OP_ADD_OR_DEL_LUN 1 > +#define VSCSIBACK_OP_UPDATEDEV_STATE 2 > + > +static int scsiback_change_device_state(struct xenbus_device *dev, > + char *state_path, enum xenbus_state set_state) > +{ > + struct xenbus_transaction tr; > + int err; > +=09 > + do { > + err =3D xenbus_transaction_start(&tr); > + if (err !=3D 0) {=20 > + printk(KERN_ERR "scsiback: transaction start failed\n"); > + return err; > + } > + err =3D xenbus_printf(tr, dev->nodename, state_path,=20 > + "%d", set_state); > + if (err !=3D 0) { > + printk(KERN_ERR "scsiback: xenbus_printf failed\n"); > + xenbus_transaction_end(tr, 1); > + return err; > + } > + err =3D xenbus_transaction_end(tr, 0); > + } while (err =3D=3D -EAGAIN); You only do one write in this transaction. That's kind of pointless; you could achieve the same effect more easily and more efficiently by just going + err =3D xenbus_printf(XBT_NIL, dev->nodename, state_path,=20 + "%d", set_state); We have a lot of pointless transactions in other places, so I can understand why you were confused, but we don't really want to introduce any more. > +=09 > + if (err !=3D 0) { > + printk(KERN_ERR "scsiback: failed to end %s.\n", __FUNCTION__); > + return err; > + } > + return 0;=09 > +} > =20 > static void scsiback_do_lun_hotplug(struct backend_info *be, int op) > { > @@ -175,16 +201,22 @@ static void scsiback_do_lun_hotplug(stru > if (device_state =3D=3D XenbusStateInitialising) { > sdev =3D scsiback_get_scsi_device(&phy); > if (!sdev) { > - xenbus_printf(xbt, dev->nodename, state_str, > - "%d", XenbusStateClosing); > + err =3D scsiback_change_device_state(dev, > + state_str, XenbusStateClosing); > + if (err) > + goto fail; > } else { > err =3D scsiback_add_translation_entry(be->info, sdev, &vir); > if (!err) { > - xenbus_printf(xbt, dev->nodename, state_str, > - "%d", XenbusStateInitialised); > + err =3D scsiback_change_device_state(dev, > + state_str, XenbusStateInitialised); > + if (err) > + goto fail; > } else { > - xenbus_printf(xbt, dev->nodename, state_str, > - "%d", XenbusStateClosing); =09 > + err =3D scsiback_change_device_state(dev, > + state_str, XenbusStateClosing); > + if (err) > + goto fail; > } > } > } I think you're leaking a reference to sdev when scsiback_add_translation_entry() fails, aren't you? In the success case scsiback_add_translation_entry() transfers it to the translation list, so you don't have to do anything, but in the failure case you do. Steven. --mxv5cy4qt+RJ9ypb Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIbk4nSSW8CTLdF2kRAmACAJ9xXexRXs2JKniPo/0CgdVqhGTbVQCdFP8K KxrsXigF7MjMNkhUlkfNDLA= =nq40 -----END PGP SIGNATURE----- --mxv5cy4qt+RJ9ypb-- --===============0807198009== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0807198009==--