From: Markus Pargmann <mpa@pengutronix.de>
To: Paul Clements <Paul.Clements@steeleye.com>
Cc: nbd-general@lists.sourceforge.net, linux-kernel@vger.kernel.org,
kernel@pengutronix.de, Markus Pargmann <mpa@pengutronix.de>
Subject: [RFC 3/4] nbd: Create helper functions for ioctls
Date: Tue, 13 Jan 2015 14:44:24 +0100 [thread overview]
Message-ID: <1421156665-27318-4-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1421156665-27318-1-git-send-email-mpa@pengutronix.de>
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);
+}
+
+/*
+ * 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);
}
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;
case NBD_SET_TIMEOUT:
- nbd->xmit_timeout = arg * HZ;
+ nbd_set_timeout(nbd, arg);
return 0;
case NBD_SET_FLAGS:
@@ -767,10 +805,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
return 0;
case NBD_SET_SIZE_BLOCKS:
- nbd->bytesize = ((u64) arg) * nbd->blksize;
- 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, ((u64)arg) * nbd->blksize);
return 0;
case NBD_DO_IT:
--
2.1.4
next prev parent reply other threads:[~2015-01-13 13:45 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 ` Markus Pargmann [this message]
2015-01-28 21:04 ` [RFC 3/4] nbd: Create helper functions for ioctls Paul Clements
2015-01-30 7:54 ` Markus Pargmann
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=1421156665-27318-4-git-send-email-mpa@pengutronix.de \
--to=mpa@pengutronix.de \
--cc=Paul.Clements@steeleye.com \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=nbd-general@lists.sourceforge.net \
/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
all inboxes | Powered by JetHome®