From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752431AbcGTHrZ (ORCPT ); Wed, 20 Jul 2016 03:47:25 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:44655 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752142AbcGTHrW (ORCPT ); Wed, 20 Jul 2016 03:47:22 -0400 From: Markus Pargmann To: Pranay Kr Srivastava Cc: nbd-general@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 3/4] make nbd device wait for its users Date: Wed, 20 Jul 2016 09:47:13 +0200 Message-ID: <4254944.oUJx8MA6Ff@adelgunde> User-Agent: KMail/4.14.1 (Linux/4.6.0-0.bpo.1-amd64; KDE/4.14.2; x86_64; ; ) In-Reply-To: <1468665396-12149-1-git-send-email-pranjas@gmail.com> References: <1468665396-12149-1-git-send-email-pranjas@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2290334.plF3lP21og"; micalg="pgp-sha256"; protocol="application/pgp-signature" X-SA-Exim-Connect-IP: 2001:67c:670:100:a61f:72ff:fe68:75ba X-SA-Exim-Mail-From: mpa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --nextPart2290334.plF3lP21og Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="us-ascii" Hi, On Saturday 16 July 2016 16:06:36 Pranay Kr Srivastava wrote: > =09When a timeout occurs or a recv fails, then > =09instead of abruptly killing nbd block device > =09wait for its users to finish. >=20 > =09This is more required when filesystem(s) like > =09ext2 or ext3 don't expect their buffer heads to > =09disappear while the filesystem is mounted. >=20 > =09Each open is now refcounted with the device being released > =09for re-use only when there are no "other users". >=20 > =09A timedout or a disconnected device, if in use, can't > =09be used until it has been resetted. The reset happens > =09when all tasks having this bdev open closes this bdev. >=20 > Behavioral Change: >=20 > 1)=09NBD_DO_IT will not wait for the device to be reset. Hence > =09the nbd-client "may exit" while some other process is using > =09this device without actually doing the reset on this device > =09, hence thus making it unusable until all such user space > =09processes have stopped using this device. >=20 > 2)=09There's a window where the nbd-client will not be able to > =09change / issue ioctls to the nbd device. This is when there's > =09been a disconnect issued or a timeout has occured, however > =09there are "other" user processes which currently have this > =09nbd device opened. Thanks for the updated patches. I applied all of your patches with some= smaller changes. I will test them later and push them to the git repo then. Best Regards, Markus >=20 > Signed-off-by: Pranay Kr Srivastava > --- > drivers/block/nbd.c | 37 ++++++++++++++++++++++++++++++++----- > 1 file changed, 32 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c > index 4919760..fe36280 100644 > --- a/drivers/block/nbd.c > +++ b/drivers/block/nbd.c > @@ -74,6 +74,7 @@ struct nbd_device { > =09 *This is specifically for calling sock_shutdown, for now. > =09 */ > =09struct work_struct ws_shutdown; > +=09atomic_t users; /* Users that opened the block device */ > }; > =20 > #if IS_ENABLED(CONFIG_DEBUG_FS) > @@ -699,6 +700,9 @@ static void nbd_dev_dbg_close(struct nbd_device *= nbd); > static int __nbd_ioctl(struct block_device *bdev, struct nbd_device = *nbd, > =09=09 unsigned int cmd, unsigned long arg) > { > +=09if (nbd->disconnect || nbd->timedout) > +=09=09return -EBUSY; > + > =09switch (cmd) { > =09case NBD_DISCONNECT: { > =09=09struct request sreq; > @@ -728,7 +732,6 @@ static int __nbd_ioctl(struct block_device *bdev,= struct nbd_device *nbd, > =09=09nbd_clear_que(nbd); > =09=09BUG_ON(!list_empty(&nbd->queue_head)); > =09=09BUG_ON(!list_empty(&nbd->waiting_queue)); > -=09=09kill_bdev(bdev); > =09=09return 0; > =20 > =09case NBD_SET_SOCK: { > @@ -804,16 +807,12 @@ static int __nbd_ioctl(struct block_device *bde= v, struct nbd_device *nbd, > =09=09mutex_lock(&nbd->tx_lock); > =09=09nbd->task_recv =3D NULL; > =09=09nbd_clear_que(nbd); > -=09=09kill_bdev(bdev); > -=09=09nbd_bdev_reset(bdev); > =20 > =09=09if (nbd->disconnect) /* user requested, ignore socket errors *= / > =09=09=09error =3D 0; > =09=09if (nbd->timedout) > =09=09=09error =3D -ETIMEDOUT; > =20 > -=09=09nbd_reset(nbd); > - > =09=09return error; > =09} > =20 > @@ -852,10 +851,38 @@ static int nbd_ioctl(struct block_device *bdev,= fmode_t mode, > =09return error; > } > =20 > +static int nbd_open(struct block_device *bdev, fmode_t mode) > +{ > +=09struct nbd_device *nbd =3D bdev->bd_disk->private_data; > + > +=09atomic_inc(&nbd->users); > + > +=09return 0; > +} > + > +static void nbd_release(struct gendisk *disk, fmode_t mode) > +{ > +=09struct nbd_device *nbd =3D disk->private_data; > +=09struct block_device *bdev =3D bdget (part_devt( > +=09=09=09=09=09=09dev_to_part(nbd_to_dev(nbd)))); > + > +=09WARN_ON(!bdev); > +=09if (atomic_dec_and_test(&nbd->users)) { > +=09=09if (bdev) { > +=09=09=09nbd_bdev_reset(bdev); > +=09=09=09kill_bdev(bdev); > +=09=09=09bdput(bdev); > +=09=09} > +=09=09nbd_reset(nbd); > +=09} > +} > + > static const struct block_device_operations nbd_fops =3D { > =09.owner =3D=09THIS_MODULE, > =09.ioctl =3D=09nbd_ioctl, > =09.compat_ioctl =3D=09nbd_ioctl, > +=09.open =3D nbd_open, > +=09.release =3D nbd_release, > }; > =20 > static void nbd_ws_func_shutdown(struct work_struct *ws_nbd) >=20 =2D-=20 Pengutronix e.K. | = | Industrial Linux Solutions | http://www.pengutronix.de/= | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 = | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-555= 5 | --nextPart2290334.plF3lP21og Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCAAGBQJXjyyGAAoJENnm3voMNZul+l0P/iMjepYr+MI7gV4whjGf9w+2 EZevzmKZTT/Fv9cZPO63P/dDH136wwhR/kqXMlGryQq2Z+FDFQnK9jcDyJcAgPhd P/mE3FM+gI1PIDLE0iR+ot+Xil9Ov3ft23zScz3EA7zlnujycCsgMepzYITPT5vt HreaT7qlQqx0Wnwpm+JV61UTpfmRlCA/gCf12Dvet2aMHROlcss1EsIzOgPEMmd8 FocWsTbnFNkI4OdC0zBRfj+9Q2it/kGK/vVSMYeQFbITNWxupLSoZ03JS51eWYeV pm0GJj6K+EY7x8tlnt6PscNapqyNsDEIUmjAmdq9RKkOaWKEdEnmfhyM5c9T0QkH VPmnzVZeFQo+51yr+dx/mKDwmYEZA27FDpQB3RbW2c0Ym7KZTOp90YbD5ZbD6zop uNkX9W6yFeFBzkfA904Sq0cQPI64nudufVgi/vma463pAOBijRqnkebYxTrwvTT1 6oqetnagQ3MT9TOcvFxeIaDAepndzK+ab3ldoP0kQriwOmcjfw5t8tPOBYOId8wF /LkRLeSBeDUr1gHdAiGuSX1zgs4XNOd1gyMHIabBCXuW0QQhE1h7zO5hhtB6cB7V kfy5GDLjKQuHH31m7r8YFR8HFIgFd6302pkyXLsz1m/xv7GuZVcEDktlWrdoTeNS az+vKsj2w37qmnNqRgSF =2NNa -----END PGP SIGNATURE----- --nextPart2290334.plF3lP21og--