aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Clements <paul.clements@steeleye.com>2012-10-04 20:16:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-05 14:05:23 -0400
commit2f012508880f8037590372c24ca6e8b6af8fffb6 (patch)
tree3921d2b8d00cf47503d30455e2b4df180cc13d11
parentde74e00a965177e8a0d44af0ba31971b80f2bf3f (diff)
nbd: add set flags ioctl
Add a set-flags ioctl, allowing various option flags to be set on an nbd device. This allows the nbd-client to set the device flags (to enable read-only mode, or enable discard support, etc.). Flags are typically specified by the nbd-server. During the negotiation phase of the nbd connection, the server sends its flags to the client. The client then uses NBD_SET_FLAGS to inform the kernel of the options. Also included is a one-line fix to debug output for the set-timeout ioctl. Signed-off-by: Paul Clements <paul.clements@steeleye.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/block/nbd.c8
-rw-r--r--include/linux/nbd.h9
2 files changed, 12 insertions, 5 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 0c03411c59eb..68fe7514413d 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -78,6 +78,8 @@ static const char *ioctl_cmd_to_ascii(int cmd)
78 case NBD_SET_SOCK: return "set-sock"; 78 case NBD_SET_SOCK: return "set-sock";
79 case NBD_SET_BLKSIZE: return "set-blksize"; 79 case NBD_SET_BLKSIZE: return "set-blksize";
80 case NBD_SET_SIZE: return "set-size"; 80 case NBD_SET_SIZE: return "set-size";
81 case NBD_SET_TIMEOUT: return "set-timeout";
82 case NBD_SET_FLAGS: return "set-flags";
81 case NBD_DO_IT: return "do-it"; 83 case NBD_DO_IT: return "do-it";
82 case NBD_CLEAR_SOCK: return "clear-sock"; 84 case NBD_CLEAR_SOCK: return "clear-sock";
83 case NBD_CLEAR_QUE: return "clear-que"; 85 case NBD_CLEAR_QUE: return "clear-que";
@@ -468,7 +470,7 @@ static void nbd_handle_req(struct nbd_device *nbd, struct request *req)
468 nbd_cmd(req) = NBD_CMD_READ; 470 nbd_cmd(req) = NBD_CMD_READ;
469 if (rq_data_dir(req) == WRITE) { 471 if (rq_data_dir(req) == WRITE) {
470 nbd_cmd(req) = NBD_CMD_WRITE; 472 nbd_cmd(req) = NBD_CMD_WRITE;
471 if (nbd->flags & NBD_READ_ONLY) { 473 if (nbd->flags & NBD_FLAG_READ_ONLY) {
472 dev_err(disk_to_dev(nbd->disk), 474 dev_err(disk_to_dev(nbd->disk),
473 "Write on read-only\n"); 475 "Write on read-only\n");
474 goto error_out; 476 goto error_out;
@@ -651,6 +653,10 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
651 nbd->xmit_timeout = arg * HZ; 653 nbd->xmit_timeout = arg * HZ;
652 return 0; 654 return 0;
653 655
656 case NBD_SET_FLAGS:
657 nbd->flags = arg;
658 return 0;
659
654 case NBD_SET_SIZE_BLOCKS: 660 case NBD_SET_SIZE_BLOCKS:
655 nbd->bytesize = ((u64) arg) * nbd->blksize; 661 nbd->bytesize = ((u64) arg) * nbd->blksize;
656 bdev->bd_inode->i_size = nbd->bytesize; 662 bdev->bd_inode->i_size = nbd->bytesize;
diff --git a/include/linux/nbd.h b/include/linux/nbd.h
index d146ca10c0f5..4b8ed5a1cfb0 100644
--- a/include/linux/nbd.h
+++ b/include/linux/nbd.h
@@ -27,6 +27,7 @@
27#define NBD_SET_SIZE_BLOCKS _IO( 0xab, 7 ) 27#define NBD_SET_SIZE_BLOCKS _IO( 0xab, 7 )
28#define NBD_DISCONNECT _IO( 0xab, 8 ) 28#define NBD_DISCONNECT _IO( 0xab, 8 )
29#define NBD_SET_TIMEOUT _IO( 0xab, 9 ) 29#define NBD_SET_TIMEOUT _IO( 0xab, 9 )
30#define NBD_SET_FLAGS _IO( 0xab, 10)
30 31
31enum { 32enum {
32 NBD_CMD_READ = 0, 33 NBD_CMD_READ = 0,
@@ -34,6 +35,10 @@ enum {
34 NBD_CMD_DISC = 2 35 NBD_CMD_DISC = 2
35}; 36};
36 37
38/* values for flags field */
39#define NBD_FLAG_HAS_FLAGS (1 << 0) /* nbd-server supports flags */
40#define NBD_FLAG_READ_ONLY (1 << 1) /* device is read-only */
41
37#define nbd_cmd(req) ((req)->cmd[0]) 42#define nbd_cmd(req) ((req)->cmd[0])
38 43
39/* userspace doesn't need the nbd_device structure */ 44/* userspace doesn't need the nbd_device structure */
@@ -42,10 +47,6 @@ enum {
42#include <linux/wait.h> 47#include <linux/wait.h>
43#include <linux/mutex.h> 48#include <linux/mutex.h>
44 49
45/* values for flags field */
46#define NBD_READ_ONLY 0x0001
47#define NBD_WRITE_NOCHK 0x0002
48
49struct request; 50struct request;
50 51
51struct nbd_device { 52struct nbd_device {