mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: Paul Clements <paul.clements@us.sios.com>
Cc: "nbd-general@lists.sourceforge.net" 
	<nbd-general@lists.sourceforge.net>,
	kernel list <linux-kernel@vger.kernel.org>,
	kernel@pengutronix.de
Subject: Re: [RFC 3/4] nbd: Create helper functions for ioctls
Date: Fri, 30 Jan 2015 08:54:15 +0100	[thread overview]
Message-ID: <20150130075415.GC16879@pengutronix.de> (raw)
In-Reply-To: <CAECXXi5P_K3SMey6=wWZd6t4TgCSFkA7r_Kg_r70=rC=99+Nzw@mail.gmail.com>

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

Hi Paul,

On Wed, Jan 28, 2015 at 04:04:28PM -0500, Paul Clements wrote:
> Markus,
> 
> Comments below...
> 
> On Tue, Jan 13, 2015 at 8:44 AM, Markus Pargmann <mpa@pengutronix.de> wrote:
> > This patch prepares the nbd code for the nbd-root device patch. It
> > moves the ioctl code into separate functions so they can be called
> > directly. The patch creates nbd_set_total_size(), nbd_set_blksize(),
> > nbd_set_sock() and nbd_set_timeout().
> >
> > Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> > ---
> >  drivers/block/nbd.c | 79 ++++++++++++++++++++++++++++++++++++++---------------
> >  1 file changed, 57 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> > index 0ff6ebbec252..11f7644be111 100644
> > --- a/drivers/block/nbd.c
> > +++ b/drivers/block/nbd.c
> > @@ -596,6 +596,55 @@ static void do_nbd_request(struct request_queue *q)
> >         }
> >  }
> >
> > +/*
> > + * Call with tx_lock held
> > + */
> > +static void nbd_set_total_size(struct block_device *bdev,
> > +                              struct nbd_device *nbd, size_t size)
> > +{
> > +       nbd->bytesize = size;
> > +       bdev->bd_inode->i_size = size;
> > +       set_blocksize(bdev, nbd->blksize);
> > +       set_capacity(nbd->disk, size >> 9);
> > +}
> > +
> > +/*
> > + * Call with tx_lock held
> > + */
> > +static void nbd_set_blksize(struct block_device *bdev, struct nbd_device *nbd,
> > +                           size_t blksize)
> > +{
> > +       u64 new_bytesize;
> > +
> > +       nbd->blksize = blksize;
> > +       bdev->bd_inode->i_size = nbd->bytesize;
> > +       set_blocksize(bdev, nbd->blksize);
> > +
> > +       new_bytesize = nbd->bytesize & ~(nbd->blksize-1);
> > +       if (new_bytesize != nbd->bytesize)
> > +               nbd_set_total_size(bdev, nbd, new_bytesize);
> 
> could just do set_capacity here to save a few cycles, but not a big
> deal either way...

Yes, however I will rework this again because set_blocksize returns
error values. So these functions should make error handling.

> 
> 
> > +}
> > +
> > +/*
> > + * Call with tx_lock held
> > + */
> > +static void nbd_set_sock(struct block_device *bdev, struct nbd_device *nbd,
> > +                        struct socket *sock)
> > +{
> > +       nbd->sock = sock;
> > +       if (max_part > 0)
> > +               bdev->bd_invalidated = 1;
> > +       nbd->disconnect = 0; /* we're connected now */
> > +}
> > +
> > +/*
> > + * Call with tx_lock held
> > + */
> > +static void nbd_set_timeout(struct nbd_device *nbd, int timeout)
> > +{
> > +       nbd->xmit_timeout = timeout * HZ;
> > +}
> > +
> >  static int nbd_connection_start(struct block_device *bdev,
> >                                 struct nbd_device *nbd)
> >  {
> > @@ -733,33 +782,22 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
> >                 if (nbd->sock)
> >                         return -EBUSY;
> >                 sock = sockfd_lookup(arg, &err);
> > -               if (sock) {
> > -                       nbd->sock = sock;
> > -                       if (max_part > 0)
> > -                               bdev->bd_invalidated = 1;
> > -                       nbd->disconnect = 0; /* we're connected now */
> > -                       return 0;
> > -               }
> > -               return -EINVAL;
> > +               if (!sock)
> > +                       return -EINVAL;
> > +
> > +               nbd_set_sock(bdev, nbd, sock);
> 
> need a return 0 here

Yes, fixed.

> 
> 
> >         }
> >
> >         case NBD_SET_BLKSIZE:
> > -               nbd->blksize = arg;
> > -               nbd->bytesize &= ~(nbd->blksize-1);
> > -               bdev->bd_inode->i_size = nbd->bytesize;
> > -               set_blocksize(bdev, nbd->blksize);
> > -               set_capacity(nbd->disk, nbd->bytesize >> 9);
> > +               nbd_set_blksize(bdev, nbd, arg);
> >                 return 0;
> >
> >         case NBD_SET_SIZE:
> > -               nbd->bytesize = arg & ~(nbd->blksize-1);
> > -               bdev->bd_inode->i_size = nbd->bytesize;
> > -               set_blocksize(bdev, nbd->blksize);
> > -               set_capacity(nbd->disk, nbd->bytesize >> 9);
> > +               nbd_set_total_size(bdev, nbd, arg & ~(nbd->blksize-1));
> >                 return 0;
> 
> Might consider deprecating this one...it's pretty useless these days,
> as it has the same function as NBD_SET_SIZE_BLOCKS, but has a smaller
> device size limit (at least on some platforms)... nbd-client does not
> use it anymore...

Yes I will consider this. I am not sure yet as it isn't much overhead to
have this additional ioctl.

Thanks,

Markus

-- 
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: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-01-30  7:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13 13:44 [RFC 0/4] nbd: root device support Markus Pargmann
2015-01-13 13:44 ` [RFC 1/4] nbd: Replace kthread_create with kthread_run Markus Pargmann
2015-01-13 13:44 ` [RFC 2/4] nbd: Split 'DO_IT' into three functions Markus Pargmann
2015-01-26 16:16   ` Paul Clements
2015-01-26 16:23     ` Markus Pargmann
2015-01-13 13:44 ` [RFC 3/4] nbd: Create helper functions for ioctls Markus Pargmann
2015-01-28 21:04   ` Paul Clements
2015-01-30  7:54     ` Markus Pargmann [this message]
2015-01-13 13:44 ` [RFC 4/4] nbd: Add support for nbd as root device Markus Pargmann
2015-01-20 11:51   ` Markus Pargmann
2015-01-29 23:42   ` [Nbd] " Wouter Verhelst
2015-01-30  8:04     ` Markus Pargmann
2015-01-30 17:30       ` Wouter Verhelst
2015-01-31 12:38         ` Markus Pargmann
     [not found]           ` <CAECXXi5+VhBeZwZ5aosc+Oc+0bCZbJZTjzYA-QTRrJCjs2NFOw@mail.gmail.com>
2015-01-31 14:43             ` Andreas Klauer
2015-01-31 15:45               ` Markus Pargmann
2015-01-31 15:00             ` Markus Pargmann
2015-01-30 18:10       ` [Nbd] " H. Peter Anvin
2015-01-31 12:08         ` Markus Pargmann

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=20150130075415.GC16879@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nbd-general@lists.sourceforge.net \
    --cc=paul.clements@us.sios.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