mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: Pranay Srivastava <pranjas@gmail.com>
Cc: nbd-general@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	Greg KH <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v4 18/18] make nbd device wait for its users in case of timeout
Date: Thu, 19 May 2016 08:36:27 +0200	[thread overview]
Message-ID: <20160519063627.GF19642@pengutronix.de> (raw)
In-Reply-To: <CA+aCy1HivWnFHUWM_mMOBe6OSEJK0GF-ZPy6kUHgpy2pWTYtUQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6247 bytes --]

Hi,

On Thu, May 12, 2016 at 08:49:00PM +0530, Pranay Srivastava wrote:
> On Thu, May 12, 2016 at 2:49 PM, Markus Pargmann <mpa@pengutronix.de> wrote:
> > Hi,
> >
> > On Wednesday 11 May 2016 11:18:46 Pranay Kr. Srivastava wrote:
> >> When a timeout occurs or a recv fails, then
> >> instead of abruplty killing nbd block device
> >> wait for it's users to finish.
> >>
> >> This is more required when filesystem(s) like
> >> ext2 or ext3 don't expect their buffer heads to
> >> disappear while the filesystem is mounted.
> >>
> >> The change is described below:
> >> a) Add a users count to nbd_device structure.
> >> b) Add a bit flag to nbd_device structure of unsigned long.
> >>
> >> If the current user count is not 1 then make nbd-client wait
> >> for the in_use bit to be cleared.
> >
> > Thanks, I like this approach much more.
> >
> >>
> >> Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
> >> ---
> >>  drivers/block/nbd.c      | 40 ++++++++++++++++++++++++++++++++++++++++
> >>  include/uapi/linux/nbd.h |  1 +
> >>  2 files changed, 41 insertions(+)
> >>
> >> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> >> index 482a3c0..9b024d8 100644
> >> --- a/drivers/block/nbd.c
> >> +++ b/drivers/block/nbd.c
> >> @@ -59,6 +59,7 @@ struct nbd_device {
> >>       int xmit_timeout;
> >>       atomic_t timedout;
> >>       bool disconnect; /* a disconnect has been requested by user */
> >> +     u32 users;
> >
> > Perhaps it is better to use kref for this?
> 
> Yup will do.
> 
> >
> >>
> >>       struct timer_list timeout_timer;
> >>       /* protects initialization and shutdown of the socket */
> >> @@ -69,6 +70,7 @@ struct nbd_device {
> >>  #if IS_ENABLED(CONFIG_DEBUG_FS)
> >>       struct dentry *dbg_dir;
> >>  #endif
> >> +     unsigned long bflags;   /* word size bit flags for use. */
> >
> > Maybe it is better to use a completion instead of a bitfield.
> 
> Ok.
> 
> >
> >>  };
> >>
> >>  #if IS_ENABLED(CONFIG_DEBUG_FS)
> >> @@ -822,6 +824,15 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
> >>               sock_shutdown(nbd);
> >>               mutex_lock(&nbd->tx_lock);
> >>               nbd_clear_que(nbd);
> >> +             /*
> >> +              * Wait for any users currently using
> >> +              * this block device.
> >> +              */
> >> +             mutex_unlock(&nbd->tx_lock);
> >> +             pr_info("Waiting for users to release device %s ...\n",
> >> +                                             bdev->bd_disk->disk_name);
> >> +             wait_on_bit(&nbd->bflags, NBD_BFLAG_INUSE_BIT, TASK_INTERRUPTIBLE);
> >> +             mutex_lock(&nbd->tx_lock);
> >>               kill_bdev(bdev);
> >>               nbd_bdev_reset(bdev);
> >>
> >> @@ -870,10 +881,39 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
> >>       return error;
> >>  }
> >>
> >> +static int nbd_open(struct block_device *bdev, fmode_t mode)
> >> +{
> >> +     struct nbd_device *nbd_dev = bdev->bd_disk->private_data;
> >
> > Here is a new line missing otherwise checkpatch will probably warn about
> > this?
> >
> > Should we check here if we are connected here? And check whether the
> > connection is about to be closed?
> 
> I don't think it should matter if we are connected or not. We already
> handle that case
> correctly. Requests would fail and those failures will be reported to
> userland. The idea
> here is not to enforce "harsh measures" on the user on failure but to
> report them instead.

I see. Yes that's fine.

Thanks,

Markus

> 
> >
> > Best Regards,
> >
> > Markus
> 
> I'll send in a new patch after making changes as per your review.
> 
> Thanks alot!.
> 
> >
> >> +     nbd_dev->users++;
> >> +     pr_debug("Opening nbd_dev %s. Active users = %u\n",
> >> +                     bdev->bd_disk->disk_name, nbd_dev->users);
> >> +     if (nbd_dev->users > 1)
> >> +     {
> >> +             set_bit(NBD_BFLAG_INUSE_BIT, &nbd_dev->bflags);
> >> +     }
> >> +     return 0;
> >> +}
> >> +
> >> +static void nbd_release(struct gendisk *disk, fmode_t mode)
> >> +{
> >> +     struct nbd_device *nbd_dev = disk->private_data;
> >> +     nbd_dev->users--;
> >> +     pr_debug("Closing nbd_dev %s. Active users = %u\n",
> >> +                     disk->disk_name, nbd_dev->users);
> >> +     if (nbd_dev->users == 1)
> >> +     {
> >> +             clear_bit(NBD_BFLAG_INUSE_BIT, &nbd_dev->bflags);
> >> +             smp_mb();
> >> +             wake_up_bit(&nbd_dev->bflags, NBD_BFLAG_INUSE_BIT);
> >> +     }
> >> +}
> >> +
> >>  static const struct block_device_operations nbd_fops = {
> >>       .owner =        THIS_MODULE,
> >>       .ioctl =        nbd_ioctl,
> >>       .compat_ioctl = nbd_ioctl,
> >> +     .open =         nbd_open,
> >> +     .release =      nbd_release
> >>  };
> >>
> >>  #if IS_ENABLED(CONFIG_DEBUG_FS)
> >> diff --git a/include/uapi/linux/nbd.h b/include/uapi/linux/nbd.h
> >> index e08e413..8f3d3f0 100644
> >> --- a/include/uapi/linux/nbd.h
> >> +++ b/include/uapi/linux/nbd.h
> >> @@ -44,6 +44,7 @@ enum {
> >>  /* there is a gap here to match userspace */
> >>  #define NBD_FLAG_SEND_TRIM    (1 << 5) /* send trim/discard */
> >>
> >> +#define NBD_BFLAG_INUSE_BIT  (1) /* bit number for bflags */
> >>  /* userspace doesn't need the nbd_device structure */
> >>
> >>  /* These are sent over the network in the request/reply magic fields */
> >>
> >
> > --
> > 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-5555 |
> 
> 
> 
> -- 
>         ---P.K.S
> 

-- 
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-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

      reply	other threads:[~2016-05-19  6:36 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11  8:18 [PATCH v4 00/18] nbd: fixes for might_sleep warning, checkpatch warning and device wait Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 01/18] nbd: Fix might_sleep warning on xmit timeout Pranay Kr. Srivastava
2016-05-12  9:40   ` Markus Pargmann
2016-05-12  9:43     ` [PATCH] nbd: Move socket shutdown out of spinlock Markus Pargmann
2016-05-12 11:12       ` Pranay Srivastava
2016-05-12 12:43         ` Markus Pargmann
2016-05-12 15:08           ` Pranay Srivastava
2016-05-19  6:22   ` [PATCH v4 01/18] nbd: Fix might_sleep warning on xmit timeout Markus Pargmann
2016-05-19 20:35     ` Pranay Srivastava
2016-05-20  8:22       ` Markus Pargmann
2016-05-23 10:32         ` Pranay Srivastava
2016-05-25 17:15           ` Pranay Srivastava
2016-05-11  8:18 ` [PATCH v4 02/18] nbd: fix checkpatch trailing space warning Pranay Kr. Srivastava
2016-05-11  8:33   ` Greg KH
     [not found]     ` <CA+aCy1GKfNd+VXi6f9Nrz63wx4tOafPp4j8_vScPF+T=+YR41Q@mail.gmail.com>
2016-05-11  9:38       ` Fwd: " Pranay Srivastava
2016-05-11 13:46         ` [Nbd] " Eric Blake
2016-05-12  9:25           ` Markus Pargmann
2016-06-03 16:50           ` Pavel Machek
2016-05-11  8:18 ` [PATCH v4 03/18] nbd: fix checkpatch warning use linux/uaccess.h Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 04/18] nbd : fix checkpatch pointer declaration warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 05/18] nbd: fix checkpatch warning no newline after decleration Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 06/18] " Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 07/18] nbd: fix checkpatch split string warning Pranay Kr. Srivastava
2016-05-12  8:39   ` Markus Pargmann
2016-05-11  8:18 ` [PATCH v4 08/18] nbd : fix checkpatch line over 80 char warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 09/18] nbd: fix checkpatch trailing whitespace warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 10/18] " Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 11/18] nbd : fix checkpatch structure declaration braces on next line warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 12/18] nbd : fix checkpatch trailing whitespace warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 13/18] nbd : fix checkpatch printk warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 14/18] nbd: fix checkpatch no extra line after decleration warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 15/18] nbd: fix checkpatch printk warning to pr_info Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 16/18] nbd: fix checkpatch no new line after decleration warning Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 17/18] nbd: fix checkpatch printk warning to pr_info Pranay Kr. Srivastava
2016-05-11  8:18 ` [PATCH v4 18/18] make nbd device wait for its users in case of timeout Pranay Kr. Srivastava
2016-05-12  9:19   ` Markus Pargmann
2016-05-12 15:19     ` Pranay Srivastava
2016-05-19  6:36       ` Markus Pargmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160519063627.GF19642@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nbd-general@lists.sourceforge.net \
    --cc=pranjas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome