nbd: use our own workqueue for recv threads
Subsystems (3)
PATCH 1/4 nbd: use our own workqueue for recv threads
Since we are in the memory reclaim path we need our recv work to be on a workqueue that has WQ_MEM_RECLAIM set so we can avoid deadlocks. Also set WQ_HIGHPRI since we are in the completion path for IO.
--- drivers/block/nbd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/block/nbd.c +11 -2
@@ -91,6 +91,7 @@ static struct dentry *nbd_dbg_dir;static unsigned int nbds_max =16 ;static struct nbd_device *nbd_dev;static int max_part; +static struct workqueue_struct *recv_workqueue;static inline struct device *nbd_to_dev (struct nbd_device *nbd) {
@@ -785,7 +786,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,INIT_WORK (&args[i].work, recv_work); args[i].nbd = nbd; args[i].index = i; -queue_work (system_long_wq, &args[i].work); +queue_work (recv_workqueue, &args[i].work); }wait_event_interruptible (nbd->recv_wq,atomic_read (&nbd->recv_threads) ==0 );
@@ -1034,10 +1035,16 @@ static int __init nbd_init(void)if (nbds_max >1UL << (MINORBITS - part_shift))return -EINVAL ; + recv_workqueue =alloc_workqueue ("knbd-recv" , +WQ_MEM_RECLAIM |WQ_HIGHPRI ,0 ); +if (!recv_workqueue) +return -ENOMEM ; nbd_dev =kcalloc (nbds_max,sizeof (*nbd_dev),GFP_KERNEL ); -if (!nbd_dev) +if (!nbd_dev) { +destroy_workqueue (recv_workqueue);return -ENOMEM ; + }for (i =0 ; i < nbds_max; i++) {struct request_queue *q;
@@ -1117,6 +1124,7 @@ static int __init nbd_init(void)put_disk (nbd_dev[i].disk); }kfree (nbd_dev); +destroy_workqueue (recv_workqueue);return err; }
@@ -1136,6 +1144,7 @@ static void __exit nbd_cleanup(void)put_disk (disk); } } +destroy_workqueue (recv_workqueue);unregister_blkdev (NBD_MAJOR ,"nbd" );kfree (nbd_dev);printk (KERN_INFO "nbd: unregistered device at major %d\n" ,NBD_MAJOR );
Signature · 1 line
2.7.4
PATCH 2/4 miscdevice: add a minor number for nbd-control
NBD is moving to a loop-control esque way of managing it's device creation and deletion. Reserver a minor number for the new device.
--- include/linux/miscdevice.h | 1 + 1 file changed, 1 insertion(+)
include/linux/miscdevice.h +1 -0
@@ -44,6 +44,7 @@#define MISC_MCELOG_MINOR 227#define HPET_MINOR 228#define FUSE_MINOR 229 +#define NBD_CTRL_MINOR 230#define KVM_MINOR 232#define BTRFS_MINOR 234#define AUTOFS_MINOR 235
Signature · 1 line
2.7.4
PATCH 3/4 nbd: use an idr to keep track of nbd devices
In reply to Josef BacikTo prepare for dynamically adding new nbd devices to the system switch from using an array for the nbd devices and instead use an idr. This copies what loop does for keeping track of its devices.
--- drivers/block/nbd.c | 213 ++++++++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 98 deletions(-)
drivers/block/nbd.c +115 -98
@@ -41,6 +41,9 @@#include <linux/nbd.h> +static DEFINE_IDR (nbd_index_idr); +static DEFINE_MUTEX (nbd_index_mutex); +struct nbd_sock {struct socket *sock;struct mutex tx_lock;
@@ -89,9 +92,9 @@ static struct dentry *nbd_dbg_dir;#define NBD_MAGIC 0x68797548static unsigned int nbds_max =16 ; -static struct nbd_device *nbd_dev;static int max_part;static struct workqueue_struct *recv_workqueue; +static int part_shift;static inline struct device *nbd_to_dev (struct nbd_device *nbd) {
@@ -997,6 +1000,103 @@ static struct blk_mq_ops nbd_mq_ops = { .timeout = nbd_xmit_timeout, }; +static void nbd_dev_remove (struct nbd_device *nbd) +{ +struct gendisk *disk = nbd->disk; + nbd->magic =0 ; +if (disk) { +del_gendisk (disk); +blk_cleanup_queue (disk->queue); +blk_mq_free_tag_set (&nbd->tag_set); +put_disk (disk); + } +kfree (nbd); +} + +static int nbd_dev_add (int index) +{ +struct nbd_device *nbd; +struct gendisk *disk; +struct request_queue *q; +int err = -ENOMEM ; + + nbd =kzalloc (sizeof (struct nbd_device ),GFP_KERNEL ); +if (!nbd) + goto out; + + disk =alloc_disk (1 << part_shift); +if (!disk) + goto out_free_nbd; + +if (index >=0 ) { + err =idr_alloc (&nbd_index_idr, nbd, index, index +1 , +GFP_KERNEL ); +if (err == -ENOSPC ) + err = -EEXIST ; + }else { + err =idr_alloc (&nbd_index_idr, nbd,0 ,0 ,GFP_KERNEL ); +if (err >=0 ) + index = err; + } +if (err <0 ) + goto out_free_disk; + + nbd->disk = disk; + nbd->tag_set.ops = &nbd_mq_ops; + nbd->tag_set.nr_hw_queues =1 ; + nbd->tag_set.queue_depth =128 ; + nbd->tag_set.numa_node =NUMA_NO_NODE ; + nbd->tag_set.cmd_size =sizeof (struct nbd_cmd ); + nbd->tag_set.flags =BLK_MQ_F_SHOULD_MERGE | +BLK_MQ_F_SG_MERGE |BLK_MQ_F_BLOCKING ; + nbd->tag_set.driver_data = nbd; + + err =blk_mq_alloc_tag_set (&nbd->tag_set); +if (err) + goto out_free_idr; + + q =blk_mq_init_queue (&nbd->tag_set); +if (IS_ERR (q)) { + err =PTR_ERR (q); + goto out_free_tags; + } + disk->queue = q; + +/* +* Tell the block layer that we are not a rotational device +*/ +queue_flag_set_unlocked (QUEUE_FLAG_NONROT , disk->queue); +queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , disk->queue); + disk->queue->limits.discard_granularity =512 ; +blk_queue_max_discard_sectors (disk->queue,UINT_MAX ); + disk->queue->limits.discard_zeroes_data =0 ; +blk_queue_max_hw_sectors (disk->queue,65536 ); + disk->queue->limits.max_sectors =256 ; + + nbd->magic =NBD_MAGIC ; +mutex_init (&nbd->config_lock); + disk->major =NBD_MAJOR ; + disk->first_minor = index << part_shift; + disk->fops = &nbd_fops; + disk->private_data = nbd; +sprintf (disk->disk_name,"nbd%d" , index); +init_waitqueue_head (&nbd->recv_wq); +nbd_reset (nbd); +add_disk (disk); +return index; + +out_free_tags: +blk_mq_free_tag_set (&nbd->tag_set); +out_free_idr: +idr_remove (&nbd_index_idr, index); +out_free_disk: +put_disk (disk); +out_free_nbd: +kfree (nbd); +out: +return err; +} +/* * And here should be modules and kernel interface * (Just smiley confuses emacs :-)
@@ -1004,9 +1104,7 @@ static struct blk_mq_ops nbd_mq_ops = {static int __init nbd_init (void ) { -int err = -ENOMEM ;int i; -int part_shift;BUILD_BUG_ON (sizeof (struct nbd_request ) !=28 );
@@ -1040,114 +1138,33 @@ static int __init nbd_init(void)if (!recv_workqueue)return -ENOMEM ; - nbd_dev =kcalloc (nbds_max,sizeof (*nbd_dev),GFP_KERNEL ); -if (!nbd_dev) { -destroy_workqueue (recv_workqueue); -return -ENOMEM ; - } - -for (i =0 ; i < nbds_max; i++) { -struct request_queue *q; -struct gendisk *disk =alloc_disk (1 << part_shift); -if (!disk) - goto out; - nbd_dev[i].disk = disk; - - nbd_dev[i].tag_set.ops = &nbd_mq_ops; - nbd_dev[i].tag_set.nr_hw_queues =1 ; - nbd_dev[i].tag_set.queue_depth =128 ; - nbd_dev[i].tag_set.numa_node =NUMA_NO_NODE ; - nbd_dev[i].tag_set.cmd_size =sizeof (struct nbd_cmd ); - nbd_dev[i].tag_set.flags =BLK_MQ_F_SHOULD_MERGE | -BLK_MQ_F_SG_MERGE |BLK_MQ_F_BLOCKING ; - nbd_dev[i].tag_set.driver_data = &nbd_dev[i]; - - err =blk_mq_alloc_tag_set (&nbd_dev[i].tag_set); -if (err) { -put_disk (disk); - goto out; - } - -/* -* The new linux 2.5 block layer implementation requires -* every gendisk to have its very own request_queue struct. -* These structs are big so we dynamically allocate them. -*/ - q =blk_mq_init_queue (&nbd_dev[i].tag_set); -if (IS_ERR (q)) { -blk_mq_free_tag_set (&nbd_dev[i].tag_set); -put_disk (disk); - goto out; - } - disk->queue = q; - -/* -* Tell the block layer that we are not a rotational device -*/ -queue_flag_set_unlocked (QUEUE_FLAG_NONROT , disk->queue); -queue_flag_clear_unlocked (QUEUE_FLAG_ADD_RANDOM , disk->queue); - disk->queue->limits.discard_granularity =512 ; -blk_queue_max_discard_sectors (disk->queue,UINT_MAX ); - disk->queue->limits.discard_zeroes_data =0 ; -blk_queue_max_hw_sectors (disk->queue,65536 ); - disk->queue->limits.max_sectors =256 ; - } - -if (register_blkdev (NBD_MAJOR ,"nbd" )) { - err = -EIO ; - goto out; - } - -printk (KERN_INFO "nbd: registered device at major %d\n" ,NBD_MAJOR ); +if (register_blkdev (NBD_MAJOR ,"nbd" )) +return -EIO ;nbd_dbg_init (); -for (i =0 ; i < nbds_max; i++) { -struct gendisk *disk = nbd_dev[i].disk; - nbd_dev[i].magic =NBD_MAGIC ; -mutex_init (&nbd_dev[i].config_lock); - disk->major =NBD_MAJOR ; - disk->first_minor = i << part_shift; - disk->fops = &nbd_fops; - disk->private_data = &nbd_dev[i]; -sprintf (disk->disk_name,"nbd%d" , i); -init_waitqueue_head (&nbd_dev[i].recv_wq); -nbd_reset (&nbd_dev[i]); -add_disk (disk); - } +mutex_lock (&nbd_index_mutex); +for (i =0 ; i < nbds_max; i++) +nbd_dev_add (i); +mutex_unlock (&nbd_index_mutex); +return 0 ; +} +static int nbd_exit_cb (int id,void *ptr,void *data) +{ +struct nbd_device *nbd = ptr; +nbd_dev_remove (nbd);return 0 ; -out: -while (i--) { -blk_mq_free_tag_set (&nbd_dev[i].tag_set); -blk_cleanup_queue (nbd_dev[i].disk->queue); -put_disk (nbd_dev[i].disk); - } -kfree (nbd_dev); -destroy_workqueue (recv_workqueue); -return err; } static void __exit nbd_cleanup(void) { -int i; -nbd_dbg_close (); -for (i =0 ; i < nbds_max; i++) { -struct gendisk *disk = nbd_dev[i].disk; - nbd_dev[i].magic =0 ; -if (disk) { -del_gendisk (disk); -blk_cleanup_queue (disk->queue); -blk_mq_free_tag_set (&nbd_dev[i].tag_set); -put_disk (disk); - } - } +idr_for_each (&nbd_index_idr, &nbd_exit_cb,NULL ); +idr_destroy (&nbd_index_idr);destroy_workqueue (recv_workqueue);unregister_blkdev (NBD_MAJOR ,"nbd" ); -kfree (nbd_dev); -printk (KERN_INFO "nbd: unregistered device at major %d\n" ,NBD_MAJOR ); }module_init (nbd_init);
Signature · 1 line
2.7.4
PATCH 4/4 nbd: add a nbd-control interface
In reply to Josef BacikThis patch mirrors the loop back device behavior with a few changes. First there is no DEL operation as NBD doesn't get as much churn as loop devices do. Secondly the GET_NEXT operation can optionally create a new NBD device or not. Our infrastructure people want to not allow NBD to create new devices as it causes problems for them in containers. However allow this to be optional as things like the OSS NBD client probably doesn't care and would like to just be given a device to use.
--- drivers/block/nbd.c | 129 ++++++++++++++++++++++++++++++++++++++++++----- include/uapi/linux/nbd.h | 10 ++++ 2 files changed, 125 insertions(+), 14 deletions(-)
drivers/block/nbd.c +115 -14
@@ -35,6 +35,7 @@#include <linux/types.h> #include <linux/debugfs.h> #include <linux/blk-mq.h> +#include <linux/miscdevice.h> #include <linux/uaccess.h> #include <asm/types.h>
@@ -59,6 +60,7 @@ struct nbd_device {unsigned long runtime_flags;struct nbd_sock **socks;int magic; +int index;struct blk_mq_tag_set tag_set;
@@ -1041,6 +1043,7 @@ static int nbd_dev_add(int index)if (err <0 ) goto out_free_disk; + nbd->index = index; nbd->disk = disk; nbd->tag_set.ops = &nbd_mq_ops; nbd->tag_set.nr_hw_queues =1 ;
@@ -1097,20 +1100,109 @@ static int nbd_dev_add(int index)return err; } -/* -* And here should be modules and kernel interface -* (Just smiley confuses emacs :-) -*/ +static int find_free_cb (int id,void *ptr,void *data) +{ +struct nbd_device *nbd = ptr; +struct nbd_device **ret = data; + +if (nbd->num_connections ==0 ) { + *ret = nbd; +return 1 ; + } +if (*ret ==NULL || (*ret)->index < nbd->index) + *ret = nbd; +return 0 ; +} + +static int nbd_dev_lookup (struct nbd_device **ret,int index) +{ +struct nbd_device *nbd =NULL ; + +if (index <0 ) { +int err =idr_for_each (&nbd_index_idr, &find_free_cb, &nbd); +if (err !=1 ) { +if (nbd !=NULL ) { + *ret =NULL ; +return nbd->index +1 ; + }else { +return 0 ; + } + } + }else + nbd =idr_find (&nbd_index_idr, index); +if (nbd) { + *ret = nbd; +return nbd->index; + } +return -ENODEV ; +} + +static long nbd_control_ioctl (struct file *file,unsigned int cmd, +unsigned long parm) +{ +struct nbd_device *nbd =NULL ; +int ret = -ENOSYS ; + +mutex_lock (&nbd_index_mutex); +switch (cmd) { +case NBD_CTL_ADD : + ret =nbd_dev_lookup (&nbd, parm); +if (ret >=0 ) { + ret = -EEXIST ; +break ; + } + ret =nbd_dev_add (parm); +break ; +case NBD_CTL_GET_FREE : + ret =nbd_dev_lookup (&nbd,-1 ); +if (ret <0 ) +break ; +if (parm && !nbd) { +int index = ret; + + ret =nbd_dev_add (ret); +if (ret <0 ) +break ; + ret = index; + } +break ; +default : +break ; + } +mutex_unlock (&nbd_index_mutex); +return ret; +} + +static const struct file_operations nbd_ctl_fops = { + .open = nonseekable_open, + .unlocked_ioctl = nbd_control_ioctl, + .compat_ioctl = nbd_control_ioctl, + .owner =THIS_MODULE , + .llseek = noop_llseek, +}; + +static struct miscdevice nbd_misc = { + .minor =NBD_CTRL_MINOR , + .name ="nbd-control" , + .fops = &nbd_ctl_fops, +}; + +MODULE_ALIAS_MISCDEV (NBD_CTRL_MINOR ); +MODULE_ALIAS ("devname:nbd-control" );static int __init nbd_init (void ) { -int i; +int i, ret;BUILD_BUG_ON (sizeof (struct nbd_request ) !=28 ); + ret =misc_register (&nbd_misc); +if (ret <0 ) +return ret; + ret = -EINVAL ;if (max_part <0 ) {printk (KERN_ERR "nbd: max_part must be >= 0\n" ); -return -EINVAL ; + goto out_misc; } part_shift =0 ;
@@ -1129,17 +1221,20 @@ static int __init nbd_init(void) }if ((1UL << part_shift) >DISK_MAX_PARTS ) -return -EINVAL ; - + goto out_misc;if (nbds_max >1UL << (MINORBITS - part_shift)) -return -EINVAL ; + goto out_misc; + recv_workqueue =alloc_workqueue ("knbd-recv" ,WQ_MEM_RECLAIM |WQ_HIGHPRI ,0 ); -if (!recv_workqueue) -return -ENOMEM ; - -if (register_blkdev (NBD_MAJOR ,"nbd" )) -return -EIO ; +if (!recv_workqueue) { + ret = -ENOMEM ; + goto out_misc; + } +if (register_blkdev (NBD_MAJOR ,"nbd" )) { + ret = -EIO ; + goto out_workqueue; + }nbd_dbg_init ();
@@ -1148,6 +1243,11 @@ static int __init nbd_init(void)nbd_dev_add (i);mutex_unlock (&nbd_index_mutex);return 0 ; +out_workqueue: +destroy_workqueue (recv_workqueue); +out_misc: +misc_deregister (&nbd_misc); +return ret; }static int nbd_exit_cb (int id,void *ptr,void *data)
@@ -1164,6 +1264,7 @@ static void __exit nbd_cleanup(void)idr_for_each (&nbd_index_idr, &nbd_exit_cb,NULL );idr_destroy (&nbd_index_idr);destroy_workqueue (recv_workqueue); +misc_deregister (&nbd_misc);unregister_blkdev (NBD_MAJOR ,"nbd" ); }
include/uapi/linux/nbd.h +10 -0
@@ -29,6 +29,16 @@#define NBD_SET_TIMEOUT _IO( 0xab, 9 )#define NBD_SET_FLAGS _IO( 0xab, 10) +/* Use the last 8 values of our allocation for CTRL ioctls. */ +#define NBD_CTL_ADD _IO( 0xab, 23) +#define NBD_CTL_GET_FREE _IO( 0xab, 24) + +enum { +NBD_CTL_GET_FREE_SCAN =0 ,/* Get the next free available device. */ +NBD_CTL_GET_FREE_ADD =1 ,/* Get the next free available device, but +create one if one does not exist. */ +}; +enum {NBD_CMD_READ =0 ,NBD_CMD_WRITE =1 ,
Signature · 1 line
2.7.4
Greg KH
maintainerRe: [PATCH 2/4] miscdevice: add a minor number for nbd-control
In reply to Josef BacikQuoted 13 lines · Josef Bacik
NBD is moving to a loop-control esque way of managing it's device creation and deletion. Reserver a minor number for the new device.
Signed-off-by Josef Bacik <[email protected]>--- include/linux/miscdevice.h | 1 + 1 file changed, 1 insertion(+)include/linux/miscdevice.h +0
-0
include/linux/miscdevice.h line 47
Quoted 4 lines
include/linux/miscdevice.h +1
-0@@ -44,6 +44,7 @@#define MISC_MCELOG_MINOR 227#define HPET_MINOR 228#define FUSE_MINOR 229 +#define NBD_CTRL_MINOR 230
Ick, really? Why not just use a dynamic one? What 1990's-based systems are you running that you would need a static misc device number for?
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH 4/4] nbd: add a nbd-control interface
In reply to Josef BacikQuoted 9 lines · Josef Bacik
This patch mirrors the loop back device behavior with a few changes. First there is no DEL operation as NBD doesn't get as much churn as loop devices do. Secondly the
GET_NEXToperation can optionally create a new NBD device or not. Our infrastructure people want to not allow NBD to create new devices as it causes problems for them in containers. However allow this to be optional as things like the OSS NBD client probably doesn't care and would like to just be given a device to use.Signed-off-by Josef Bacik <[email protected]>
A random char device with odd ioctls? Why? There's no other configuration choice you could possibly use? Where is the userspace tool that uses this new kernel api?
You aren't passing in structures to the ioctl, so why does this HAVE to be an ioctl?
thanks,
greg k-h
Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
In reply to Josef BacikQuoted 7 lines · Josef Bacik
This patch mirrors the loop back device behavior with a few changes. First there is no DEL operation as NBD doesn't get as much churn as loop devices do. Secondly the
GET_NEXToperation can optionally create a new NBD device or not. Our infrastructure people want to not allow NBD to create new devices as it causes problems for them in containers. However allow this to be optional as things like the OSS NBD client probably doesn't care and would like to just be given a device to use.
Don't be so sure :-)
I agree that having a control device for NBD is useful and would make certain things much easier. If that's added, then I'll move to using that as a way to control the device rather than opening a device and dealing with it that way. In fact, at some point in the past I did suggest something along those ways myself; it's just not happened yet.
Obviously though this would require an intermediate situation in which the control master would be available as well as (optionally perhaps) the old way where you open a specific device node, so that we don't break existing implementations before they've had a chance to follow suit.
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 5 lines · Wouter Verhelst
=20
Quoted 2 lines · Josef Bacik
This patch mirrors the loop back device behavior with a few changes. Fi=
rst
Quoted 1 line
Quoted 1 line
there is no DEL operation as NBD doesn't get as much churn as loop devic=
es do.
Quoted 1 line
Quoted 1 line
Secondly the
GET_NEXToperation can optionally create a new NBD device o=
r not.
Quoted 1 line
Quoted 1 line
Our infrastructure people want to not allow NBD to create new devices as=
it
Quoted 1 line
Quoted 1 line
causes problems for them in containers. However allow this to be option=
al as
Quoted 1 line
Quoted 1 line
things like the OSS NBD client probably doesn't care and would like to j=
ust be
Quoted 15 lines
Quoted 1 line
given a device to use.
=20
Don't be so sure :-)
=20
I agree that having a control device for NBD is useful and would make certain things much easier. If that's added, then I'll move to using that as a way to control the device rather than opening a device and dealing with it that way. In fact, at some point in the past I did suggest something along those ways myself; it's just not happened yet. =20
Obviously though this would require an intermediate situation in which the control master would be available as well as (optionally perhaps) the old way where you open a specific device node, so that we don't break existing implementations before they've had a chance to follow suit.
Sorry I wasn't super clear. This doesn't change anything about how the dev= ices are setup, it just means if you do max_nbds=3D0 you can dynamically ad= d more as you need them, and you can find unused nbd devices easily instead=
of making the user specify them. When I get home tonight I'll push my nbd=
-client patch so you can see how I use it. Thanks,
Josef=
Re: [PATCH 2/4] miscdevice: add a minor number for nbd-control
In reply to Greg KHQuoted 17 lines · Greg KH
=20
Quoted 14 lines · Josef Bacik
NBD is moving to a loop-control esque way of managing it's device creation and deletion. Reserver a minor number for the new device. =20
Signed-off-by Josef Bacik <[email protected]>---
include/linux/miscdevice.h| 1 +1 file changed, 1 insertion(+)=20
include/linux/miscdevice.h +0
-0@@ -44,6 +44,7 @@
Quoted 8 lines
include/linux/miscdevice.h line 47
Quoted 4 lines
include/linux/miscdevice.h +1
-0#define MISC_MCELOG_MINOR 227#define HPET_MINOR 228#define FUSE_MINOR 229 +#define NBD_CTRL_MINOR 230=20
Ick, really? Why not just use a dynamic one? What 1990's-based systems are you running that you would need a static misc device number for? =20
Honestly I was just doing what loop did, I wasn't sure if there was some ad= ministration reason for needing a static minor number. If nobody cares the= n I can just use a dynamic one. Thanks,
Josef=
Greg KH
maintainerRe: [PATCH 2/4] miscdevice: add a minor number for nbd-control
Quoted 26 lines · Josef Bacik
Quoted 12 lines · Greg KH
Quoted 10 lines · Josef Bacik
NBD is moving to a loop-control esque way of managing it's device creation and deletion. Reserver a minor number for the new device.
Signed-off-by Josef Bacik <[email protected]>---
include/linux/miscdevice.h| 1 +1 file changed, 1 insertion(+)Quoted 13 lines
include/linux/miscdevice.h line 47
Quoted 9 lines
include/linux/miscdevice.h +1
-0@@ -44,6 +44,7 @@#define MISC_MCELOG_MINOR 227#define HPET_MINOR 228#define FUSE_MINOR 229 +#define NBD_CTRL_MINOR 230Ick, really? Why not just use a dynamic one? What 1990's-based systems are you running that you would need a static misc device number for?
Quoted 3 lines
Honestly I was just doing what loop did, I wasn't sure if there was some administration reason for needing a static minor number. If nobody cares then I can just use a dynamic one. Thanks,
Loop is very legacy, that's why it is that way, please don't duplicate it...
thanks,
greg k-h
Re: [PATCH 4/4] nbd: add a nbd-control interface
In reply to Greg KHQuoted 15 lines · Greg KH
Quoted 14 lines · Josef Bacik
This patch mirrors the loop back device behavior with a few
changes. First
there is no DEL operation as NBD doesn't get as much churn as loop
devices do.
Secondly theGET_NEXToperation can optionally create a new NBD
device or not.
Our infrastructure people want to not allow NBD to create new
devices as it
causes problems for them in containers. However allow this to be
optional as
things like the OSS NBD client probably doesn't care and would like
to just be
given a device to use.
Quoted 8 lines
Quoted 1 line
Signed-off-by Josef Bacik <[email protected]>A random char device with odd ioctls? Why? There's no other configuration choice you could possibly use? Where is the userspace tool that uses this new kernel api?
You aren't passing in structures to the ioctl, so why does this HAVE to be an ioctl?
Again, this is how loop does it so I assumed a known, regularly used API was the best bet. I can do literally anything, but these interfaces have to be used by other people, including internal people. The /dev/whatever-control is a well established way for interacting with dynamic device drivers (loop, DM, btrfs), so that's what I went with. Thanks,
Josef
Greg KH
maintainerRe: [PATCH 4/4] nbd: add a nbd-control interface
Quoted 24 lines · Josef Bacik
Quoted 21 lines · Greg KH
Quoted 14 lines · Josef Bacik
This patch mirrors the loop back device behavior with a few
changes. First
there is no DEL operation as NBD doesn't get as much churn as loop
devices do.
Secondly theGET_NEXToperation can optionally create a new NBD
device or not.
Our infrastructure people want to not allow NBD to create new
devices as it
causes problems for them in containers. However allow this to be
optional as
things like the OSS NBD client probably doesn't care and would like
to just be
given a device to use.Quoted 1 line
Signed-off-by Josef Bacik <[email protected]>A random char device with odd ioctls? Why? There's no other configuration choice you could possibly use? Where is the userspace tool that uses this new kernel api?
Quoted 8 lines
Quoted 2 lines
You aren't passing in structures to the ioctl, so why does this HAVE to be an ioctl?
Again, this is how loop does it so I assumed a known, regularly used API was the best bet. I can do literally anything, but these interfaces have to be used by other people, including internal people. The
/dev/whatever-controlis a well established way for interacting with dynamic device drivers (loop, DM, btrfs), so that's what I went with. Thanks,
Again, please don't duplicate what loop did, we must _learn_ from history, not repeat it :(
Re: [PATCH 4/4] nbd: add a nbd-control interface
Quoted 44 lines · Greg KH
Quoted 33 lines · Josef Bacik
Quoted 4 lines · Greg KH
Quoted 3 lines · Josef Bacik
This patch mirrors the loop back device behavior with a few
changes. First
there is no DEL operation as NBD doesn't get as much churn asloop
Quoted 6 lines
Quoted 6 lines
devices do.
Secondly theGET_NEXToperation can optionally create a new NBD
device or not.
Our infrastructure people want to not allow NBD to create new
devices as it
causes problems for them in containers. However allow this tobe
Quoted 2 lines
Quoted 2 lines
optional as
things like the OSS NBD client probably doesn't care and wouldlike
Quoted 7 lines
Quoted 4 lines
to just be
given a device to use.Signed-off-by Josef Bacik <[email protected]>A random char device with odd ioctls? Why? There's no other configuration choice you could possibly use? Where is the
userspace
Quoted 3 lines
tool that uses this new kernel api?
You aren't passing in structures to the ioctl, so why does this
HAVE to
Quoted 1 line
be an ioctl?
Quoted 9 lines
Again, this is how loop does it so I assumed a known, regularly
used API was
the best bet. I can do literally anything, but these interfaces
have to be
used by other people, including internal people. The/dev/whatever-control
is a well established way for interacting with dynamic device
drivers (loop,
DM, btrfs), so that's what I went with. Thanks,
Quoted 2 lines
Again, please don't duplicate what loop did, we must _learn_ from history, not repeat it :(
Sure but what am I supposed to do? Have some random sysfs knobs? Thanks,
Josef
Greg KH
maintainerRe: [PATCH 4/4] nbd: add a nbd-control interface
Quoted 45 lines · Josef Bacik
Quoted 44 lines · Greg KH
Quoted 42 lines · Josef Bacik
Quoted 4 lines · Greg KH
Quoted 3 lines · Josef Bacik
This patch mirrors the loop back device behavior with a few
changes. First
there is no DEL operation as NBD doesn't get as much churn asloop
Quoted 6 lines
Quoted 6 lines
devices do.
Secondly theGET_NEXToperation can optionally create a new NBD
device or not.
Our infrastructure people want to not allow NBD to create new
devices as it
causes problems for them in containers. However allow this tobe
Quoted 2 lines
Quoted 2 lines
optional as
things like the OSS NBD client probably doesn't care and wouldlike
Quoted 7 lines
Quoted 4 lines
to just be
given a device to use.Signed-off-by Josef Bacik <[email protected]>A random char device with odd ioctls? Why? There's no other configuration choice you could possibly use? Where is the
userspace
Quoted 3 lines
tool that uses this new kernel api?
You aren't passing in structures to the ioctl, so why does this
HAVE to
Quoted 1 line
be an ioctl?
Again, this is how loop does it so I assumed a known, regularly
used API was
the best bet. I can do literally anything, but these interfaces
have to be
used by other people, including internal people. The/dev/whatever-control
is a well established way for interacting with dynamic device
drivers (loop,
DM, btrfs), so that's what I went with. Thanks,
Quoted 4 lines
Quoted 2 lines
Again, please don't duplicate what loop did, we must _learn_ from history, not repeat it :(
Sure but what am I supposed to do? Have some random sysfs knobs? Thanks,
It all depends on what you are trying to do. I have yet to figure that out at all here :(
Re: [PATCH 4/4] nbd: add a nbd-control interface
Quoted 55 lines · Greg KH
Quoted 54 lines · Josef Bacik
Quoted 7 lines · Greg KH
Quoted 6 lines · Josef Bacik
Quoted 2 lines · Greg KH
Quoted 1 line · Josef Bacik
This patch mirrors the loop back device behavior with a
few
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
changes. First
there is no DEL operation as NBD doesn't get as muchchurn as
Quoted 3 lines
Quoted 3 lines
loop
Quoted 2 lines
Quoted 2 lines
devices do.
Secondly theGET_NEXToperation can optionally create anew NBD
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
device or not.
Our infrastructure people want to not allow NBD to createnew
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
devices as it
causes problems for them in containers. However allowthis to
Quoted 3 lines
Quoted 3 lines
be
Quoted 2 lines
Quoted 2 lines
optional as
things like the OSS NBD client probably doesn't care andwould
Quoted 4 lines
Quoted 4 lines
like
Quoted 3 lines
Quoted 3 lines
to just be
given a device to use.Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Josef Bacik <[email protected]>A random char device with odd ioctls? Why? There's no other configuration choice you could possibly use? Where is the
userspace
Quoted 3 lines
tool that uses this new kernel api?
You aren't passing in structures to the ioctl, so why does
this
Quoted 6 lines
Quoted 6 lines
HAVE to
Quoted 1 line
be an ioctl?
Again, this is how loop does it so I assumed a known, regularly
used API was
the best bet. I can do literally anything, but theseinterfaces
Quoted 7 lines
Quoted 6 lines
have to be
used by other people, including internal people. The/dev/whatever-control
is a well established way for interacting with dynamic device
drivers (loop,
DM, btrfs), so that's what I went with. Thanks,
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Again, please don't duplicate what loop did, we must _learn_ from history, not repeat it :(
Sure but what am I supposed to do? Have some random sysfs knobs?
Thanks,It all depends on what you are trying to do. I have yet to figure that out at all here :(
I explained it in the changelog and my response to Wouter. NBD preallocates all of its /dev/nbd# devices at modprobe time, so there's no way to add new devices as we need them. Loop accomplishes this with the /dev/loop-control and an ioctl. Then we also need a way to figure out what is the first /dev/nbd# device that isn't currently in use in order to pick the next one to configure. Keep in mind that all of the configuration for /dev/nbd# devices is done through ioctls to those devices, so having a ioctl interface for the control device is consistent with the rest of how NBD works. Thanks,
Josef
Greg KH
maintainerRe: [PATCH 4/4] nbd: add a nbd-control interface
Quoted 63 lines · Josef Bacik
Quoted 61 lines · Greg KH
Quoted 59 lines · Josef Bacik
Quoted 7 lines · Greg KH
Quoted 6 lines · Josef Bacik
Quoted 2 lines · Greg KH
Quoted 1 line · Josef Bacik
This patch mirrors the loop back device behavior with a
few
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
changes. First
there is no DEL operation as NBD doesn't get as muchchurn as
Quoted 3 lines
Quoted 3 lines
loop
Quoted 2 lines
Quoted 2 lines
devices do.
Secondly theGET_NEXToperation can optionally create anew NBD
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
device or not.
Our infrastructure people want to not allow NBD to createnew
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
devices as it
causes problems for them in containers. However allowthis to
Quoted 3 lines
Quoted 3 lines
be
Quoted 2 lines
Quoted 2 lines
optional as
things like the OSS NBD client probably doesn't care andwould
Quoted 4 lines
Quoted 4 lines
like
Quoted 3 lines
Quoted 3 lines
to just be
given a device to use.Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Josef Bacik <[email protected]>A random char device with odd ioctls? Why? There's no other configuration choice you could possibly use? Where is the
userspace
Quoted 3 lines
tool that uses this new kernel api?
You aren't passing in structures to the ioctl, so why does
this
Quoted 6 lines
Quoted 6 lines
HAVE to
Quoted 1 line
be an ioctl?
Again, this is how loop does it so I assumed a known, regularly
used API was
the best bet. I can do literally anything, but theseinterfaces
Quoted 9 lines
Quoted 6 lines
have to be
used by other people, including internal people. The/dev/whatever-control
is a well established way for interacting with dynamic device
drivers (loop,
DM, btrfs), so that's what I went with. Thanks,Again, please don't duplicate what loop did, we must _learn_ from history, not repeat it :(
Sure but what am I supposed to do? Have some random sysfs knobs?
Thanks,
Quoted 6 lines
Quoted 2 lines
It all depends on what you are trying to do. I have yet to figure that out at all here :(
I explained it in the changelog and my response to Wouter. NBD preallocates all of its /dev/nbd# devices at modprobe time, so there's no way to add new devices as we need them.
Why not fix that odd restriction?
Quoted 6 lines
Loop accomplishes this with the
/dev/loop-control
and an ioctl. Then we also need a way to figure out what is the first /dev/nbd# device that isn't currently in use in order to pick the next one to configure. Keep in mind that all of the configuration for /dev/nbd# devices is done through ioctls to those devices, so having a ioctl interface for the control device is consistent with the rest of how NBD works.
But adding a random char device node and using ioctls on it is different than using an ioctl on an existing block device node that is already there.
So what _exactly_ do you need to do with this interface? What data do you need sent/received to/from the kernel? Specifics please.
thanks,
greg k-h
Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 6 lines · Greg KH
Quoted 3 lines · Josef Bacik
I explained it in the changelog and my response to Wouter. NBD preallocates all of its /dev/nbd# devices at modprobe time, so there's no way to add new devices as we need them.
Why not fix that odd restriction?
Isn't that what this patch is trying to do?
Quoted 7 lines
Quoted 6 lines
Loop accomplishes this with the
/dev/loop-control
and an ioctl. Then we also need a way to figure out what is the first /dev/nbd# device that isn't currently in use in order to pick the next one to configure. Keep in mind that all of the configuration for /dev/nbd# devices is done through ioctls to those devices, so having a ioctl interface for the control device is consistent with the rest of how NBD works.
Quoted 6 lines
But adding a random char device node and using ioctls on it is different than using an ioctl on an existing block device node that is already there.
So what _exactly_ do you need to do with this interface? What data do you need sent/received to/from the kernel? Specifics please.
AIUI: Create new devices, and figure out which device is the next one free so we can find one without having to check the pid attribute for every device (as is needed today, and which is racy).
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Re: [PATCH 4/4] nbd: add a nbd-control interface
In reply to Greg KHQuoted 82 lines · Greg KH
Quoted 81 lines · Josef Bacik
Quoted 9 lines · Greg KH
Quoted 8 lines · Josef Bacik
Quoted 6 lines · Greg KH
Quoted 5 lines · Josef Bacik
Quoted 1 line · Greg KH
On Fri, Jan 20, 2017 at 04:56:52PM -0500, Josef Bacik
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch mirrors the loop back device behavior
with a
Quoted 7 lines
Quoted 7 lines
few
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
changes. First
there is no DEL operation as NBD doesn't get as muchchurn as
Quoted 3 lines
Quoted 3 lines
loop
Quoted 2 lines
Quoted 2 lines
devices do.
Secondly theGET_NEXToperation can optionallycreate a
Quoted 3 lines
Quoted 3 lines
new NBD
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
device or not.
Our infrastructure people want to not allow NBD tocreate
Quoted 3 lines
Quoted 3 lines
new
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
devices as it
causes problems for them in containers. Howeverallow
Quoted 4 lines
Quoted 4 lines
this to
Quoted 3 lines
Quoted 3 lines
be
Quoted 2 lines
Quoted 2 lines
optional as
things like the OSS NBD client probably doesn't careand
Quoted 8 lines
Quoted 8 lines
would
Quoted 7 lines
Quoted 7 lines
like
Quoted 6 lines
Quoted 4 lines
to just be
given a device to use.Signed-off-by Josef Bacik <[email protected]>A random char device with odd ioctls? Why? There's no
other
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
configuration choice you could possibly use? Where is
the
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
userspace
Quoted 3 lines
tool that uses this new kernel api?
You aren't passing in structures to the ioctl, so why
does
Quoted 5 lines
Quoted 5 lines
this
Quoted 4 lines
Quoted 4 lines
HAVE to
Quoted 1 line
be an ioctl?
Again, this is how loop does it so I assumed a known,
regularly
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
used API was
the best bet. I can do literally anything, but theseinterfaces
Quoted 4 lines
Quoted 4 lines
have to be
used by other people, including internal people. The/dev/whatever-control
is a well established way for interacting with dynamicdevice
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
drivers (loop,
DM, btrfs), so that's what I went with. Thanks,Again, please don't duplicate what loop did, we must _learn_
from
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
history, not repeat it :(
Sure but what am I supposed to do? Have some random sysfs
knobs?
Quoted 3 lines
Quoted 1 line
Thanks,
It all depends on what you are trying to do. I have yet to
figure that
Quoted 1 line
out at all here :(
Quoted 7 lines
Quoted 5 lines
I explained it in the changelog and my response to Wouter. NBD
preallocates
all of its /dev/nbd# devices at modprobe time, so there's no way to
add new
devices as we need them.Why not fix that odd restriction?
That's the entire point of this patchset, adding the ability to create new devices on the fly as needed.
Quoted 13 lines
Quoted 12 lines
Loop accomplishes this with the
/dev/loop-control
and an ioctl. Then we also need a way to figure out what is the
first
/dev/nbd# device that isn't currently in use in order to pick the
next one
to configure. Keep in mind that all of the configuration for
/dev/nbd#
devices is done through ioctls to those devices, so having a ioctl
interface
for the control device is consistent with the rest of how NBD works.
Quoted 6 lines
But adding a random char device node and using ioctls on it is different than using an ioctl on an existing block device node that is already there.
So what _exactly_ do you need to do with this interface? What data do you need sent/received to/from the kernel? Specifics please.
I need to say "Hey kernel, can you setup some new nbd devices for me?" and "Hey kernel, what is the first free nbd device I can use for this new connection and (optionally) create a new device for me if one does not exist?" Loop accomplished this (in 2011 btw, not some far off date) with /dev/loop-control. Btrfs has it's scanning stuff controlled by /dev/btrfs-control. Device mapper has /dev/mapper/control. This is a well established and widely used way for control block based device drivers. Thanks,
Josef
Arnd Bergmann
maintainerRe: [PATCH 4/4] nbd: add a nbd-control interface
Quoted 21 lines · Josef Bacik
Quoted 12 lines · Greg KH
Quoted 9 lines · Josef Bacik
On Mon, Jan 23, 2017 at 10:03 AM, Greg KH <[email protected]> Loop accomplishes this with the
/dev/loop-control
and an ioctl. Then we also need a way to figure out what is the first /dev/nbd# device that isn't currently in use in order to pick the next
one
to configure. Keep in mind that all of the configuration for /dev/nbd# devices is done through ioctls to those devices, so having a ioctl
interface
for the control device is consistent with the rest of how NBD works.Quoted 6 lines
But adding a random char device node and using ioctls on it is different than using an ioctl on an existing block device node that is already there.
So what _exactly_ do you need to do with this interface? What data do you need sent/received to/from the kernel? Specifics please.
Quoted 7 lines
I need to say "Hey kernel, can you setup some new nbd devices for me?" and "Hey kernel, what is the first free nbd device I can use for this new connection and (optionally) create a new device for me if one does not exist?" Loop accomplished this (in 2011 btw, not some far off date) with
/dev/loop-control. Btrfs has it's scanning stuff controlled by/dev/btrfs-control. Device mapper has/dev/mapper/control. This is a well established and widely used way for control block based device drivers.
We have multiple established ways to deal with this kind of problem, the most common ones being a separate chardev as you propose, a sysfs interface and netlink.
They all have their own set of problems, but the needs of nbd as a network storage interface seem most closely resemble what we have for other network related interfaces, where we typically use netlink to do the setup, see e.g. macvtap as an example for a network chardev interface.
Can you have a look if that would solve your problem more nicely?
Arnd
Re: [PATCH 4/4] nbd: add a nbd-control interface
T24gMS8yNS8xNywgNjoyMyBBTSwgImFybmRiZXJnbWFubkBnbWFpbC5jb20gb24gYmVoYWxmIG9m IEFybmQgQmVyZ21hbm4iIDxhcm5kYmVyZ21hbm5AZ21haWwuY29tIG9uIGJlaGFsZiBvZiBhcm5k QGFybmRiLmRlPiB3cm90ZToNCj4gT24gV2VkLCBKYW4gMjUsIDIwMTcgYXQgMjo0NyBQTSwgSm9z ZWYgQmFjaWsgPGpiYWNpa0BmYi5jb20+IHdyb3RlOg0KPiA+IE9uIFR1ZSwgSmFuIDI0LCAyMDE3 IGF0IDI6MTEgQU0sIEdyZWcgS0ggPGdyZWdraEBsaW51eGZvdW5kYXRpb24ub3JnPiB3cm90ZToN Cj4gPj4gT24gTW9uLCBKYW4gMjMsIDIwMTcgYXQgMTA6NTI6NDJBTSAtMDUwMCwgSm9zZWYgQmFj aWsgd3JvdGU6DQo+ID4+PiAgT24gTW9uLCBKYW4gMjMsIDIwMTcgYXQgMTA6MDMgQU0sIEdyZWcg S0ggPGdyZWdraEBsaW51eGZvdW5kYXRpb24ub3JnPg0KPiA+Pj4gIExvb3AgYWNjb21wbGlzaGVz IHRoaXMgd2l0aCB0aGUgL2Rldi9sb29wLWNvbnRyb2wNCj4gPj4+ICBhbmQgYW4gaW9jdGwuICBU aGVuIHdlIGFsc28gbmVlZCBhIHdheSB0byBmaWd1cmUgb3V0IHdoYXQgaXMgdGhlIGZpcnN0DQo+ ID4+PiAgL2Rldi9uYmQjIGRldmljZSB0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biBpbiB0aGF0IGZh c2hpb24uICBTbyBJJ2QNCnJhdGhlciBzdGljayB0byB0aGUgY2hhciBkZXZpY2UgaW9jdGwgdGhp bmcgYmVjYXVzZSBpdCdzIG1vcmUNCmNvbnNpc3RlbnQgd2l0aCB0aGUgb2xkIE5CRCBzdHVmZiBh cyB3ZWxsIGFzIHRoZSBsb29wIGRldmljZSBzdHVmZi4NCg0KLS0gDQpBbGV4IEdhcnRyZWxsIDxh Z2FydHJlbGxAZmIuY29tPg0KDQo=
Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 10 lines · Alex Gartrell
Quoted 9 lines · On 1/25/17, 6:23 AM, "[email protected] on behalf of Arnd Bergmann"…
We have multiple established ways to deal with this kind of problem, the most common ones being a separate chardev as you propose, a sysfs interface and netlink.
They all have their own set of problems, but the needs of nbd as a network storage interface seem most closely resemble what we have for other network related interfaces, where we typically use netlink to do the setup, see e.g. macvtap as an example for a network chardev interface.
Quoted 6 lines
Quoted 1 line
Can you have a look if that would solve your problem more nicely?
FWIW, I'm the one consuming this nbd stuff at Facebook and bringing netlink into this would be a huge pain for me. It's very weird to need to pull sockets in and then drop back to ioctls from a design perspective, and future consumers of this API would be sad as well.
As who's been maintaining the official userspace nbd client for 15 years now, I have to concur. NBD has had an API that deals with /dev/nbdX since forever, adding other APIs to that just feels wrong.
Quoted 4 lines
This is compounded, I think, by the fact that the breadth of functionality here doesn't really merit a shared library for everyone to use -- could you imagine libnbdcontrol, which exposes a single "
get_next_device" function?
Please no :)
Quoted 4 lines
If nbd were *all* netlink I think that that'd be fine, but you'd have problems implementing the
NBD_DOITfunction in that fashion. So I'd rather stick to the char device ioctl thing because it's more consistent with the old NBD stuff as well as the loop device stuff.
Indeed.
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
In reply to Arnd BergmannQuoted 5 lines · Arnd Bergmann
They all have their own set of problems, but the needs of nbd as a network storage interface seem most closely resemble what we have for other network related interfaces, where we typically use netlink to do the setup, see e.g. macvtap as an example for a network chardev interface.
But nbd is a virtual block device, first and foremost. That means it is very similar to both loop (Pavel began nbd as a copy of loop, I believe) and device mapper.
Also, it uses ioctls for all configuration and administration currently.
--
Paul
Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
In reply to Alex GartrellQuoted 8 lines · Alex Gartrell
If nbd were *all* netlink I think that that'd be fine, but you'd have problems implementing the
NBD_DOITfunction in that fashion. So I'd rather stick to the char device ioctl thing because it's more consistent with the old NBD stuff as well as the loop device stuff.
I spend most of my time looking at the userspace side of NBD so apologies if this is off base.
Given (because of NBD_DO_IT) we need an ioctl anyway, and we have an ioctl that isn't going to go away, it would seem better if possible to stick with ioctls, and not introduce either a dependency on netlink (which would presumably bloat static binaries that are used early in the boot process). Personally I'd have thought adding a new NBD ioctl (or extending an existing one) would be less entropy than adding a new char device.
Signature · 1 line
Alex Bligh
Greg KH
maintainerRe: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 12 lines · Alex Bligh
Quoted 8 lines · Alex Gartrell
If nbd were *all* netlink I think that that'd be fine, but you'd have problems implementing the
NBD_DOITfunction in that fashion. So I'd rather stick to the char device ioctl thing because it's more consistent with the old NBD stuff as well as the loop device stuff.I spend most of my time looking at the userspace side of NBD so apologies if this is off base.
Quoted 7 lines
Given (because of
NBD_DO_IT) we need an ioctl anyway, and we have an ioctl that isn't going to go away, it would seem better if possible to stick with ioctls, and not introduce either a dependency on netlink (which would presumably bloat static binaries that are used early in the boot process). Personally I'd have thought adding a new NBD ioctl (or extending an existing one) would be less entropy than adding a new char device.
Why can't you just do this on any existing nbd block device with an ioctl to it? No need to have to do it on an out-of-band char device node, right?
thanks,
greg k-h
Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 11 lines · Greg KH
Quoted 7 lines
Given (because of
NBD_DO_IT) we need an ioctl anyway, and we have an ioctl that isn't going to go away, it would seem better if possible to stick with ioctls, and not introduce either a dependency on netlink (which would presumably bloat static binaries that are used early in the boot process). Personally I'd have thought adding a new NBD ioctl (or extending an existing one) would be less entropy than adding a new char device.Why can't you just do this on any existing nbd block device with an ioctl to it? No need to have to do it on an out-of-band char device node, right?
How do you get an fd to existing nbd block device? Your intent is to use an ioctl to request creating/opening a new nbd device that no one else is using; opening an existing device in order to send that ioctl may have negative ramifications to the actual user of that existing device, if not permissions issues that prevent the open from even happening. Having a separate control fd makes it obvious that you are asking for a new nbd device, and don't want to stomp on any existing devices.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 8 lines · Eric Blake
How do you get an fd to existing nbd block device? Your intent is to use an ioctl to request creating/opening a new nbd device that no one else is using; opening an existing device in order to send that ioctl may have negative ramifications to the actual user of that existing device, if not permissions issues that prevent the open from even happening. Having a separate control fd makes it obvious that you are asking for a new nbd device, and don't want to stomp on any existing devices.
Yes, - this whole concept of needing a device first to then associate it with a backing store is something we had a in a lot of drivers, and it's always been a major problem. Thus we've been slowly moving all the drivers off it.
Greg KH
maintainerRe: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Eric Blake
How do you get an fd to existing nbd block device? Your intent is to use an ioctl to request creating/opening a new nbd device that no one else is using; opening an existing device in order to send that ioctl may have negative ramifications to the actual user of that existing device, if not permissions issues that prevent the open from even happening. Having a separate control fd makes it obvious that you are asking for a new nbd device, and don't want to stomp on any existing devices.
Quoted 4 lines
Yes, - this whole concept of needing a device first to then associate it with a backing store is something we had a in a lot of drivers, and it's always been a major problem. Thus we've been slowly moving all the drivers off it.
Ok, but do you feel the "loop method" of using a char device node to create/control these devices is a good model to follow for new devices like ndb?
thanks,
greg k-h
Re: [Nbd] [PATCH 4/4] nbd: add a nbd-control interface
Quoted 3 lines · Greg KH
Ok, but do you feel the "loop method" of using a char device node to create/control these devices is a good model to follow for new devices like ndb?
Yes. We've done the same for NVMe over fabrics.