By adding the a module alias, programs (or users) won't have to explicitly call modprobe. Vhost-net will always be available if built into the kernel. It does require assigning a permanent minor number for depmod to work. Choose one next to TUN since this driver is related to it. Also, use C99 style initialization. Signed-off-by: Stephen Hemminger <shemminger at vyatta.com> --- drivers/vhost/net.c | 8 +++++--- include/linux/miscdevice.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) --- a/drivers/vhost/net.c 2012-01-10 10:56:58.883179194 -0800 +++ b/drivers/vhost/net.c 2012-01-10 19:48:23.650225892 -0800 @@ -856,9 +856,9 @@ static const struct file_operations vhos }; static struct miscdevice vhost_net_misc = { - MISC_DYNAMIC_MINOR, - "vhost-net", - &vhost_net_fops, + .minor = VHOST_NET_MINOR, + .name = "vhost-net", + .fops = &vhost_net_fops, }; static int vhost_net_init(void) @@ -879,3 +879,5 @@ MODULE_VERSION("0.0.1"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Michael S. Tsirkin"); MODULE_DESCRIPTION("Host kernel accelerator for virtio net"); +MODULE_ALIAS_MISCDEV(VHOST_NET_MINOR); +MODULE_ALIAS("devname:vhost-net"); --- a/include/linux/miscdevice.h 2012-01-10 10:56:59.779189436 -0800 +++ b/include/linux/miscdevice.h 2012-01-10 19:49:56.091748210 -0800 @@ -31,6 +31,7 @@ #define I2O_MINOR 166 #define MICROCODE_MINOR 184 #define TUN_MINOR 200 +#define VHOST_NET_MINOR 201 #define MWAVE_MINOR 219 /* ACP/Mwave Modem */ #define MPT_MINOR 220 #define MPT2SAS_MINOR 221
On 11.01.2012 08:54, Stephen Hemminger wrote:> By adding the a module alias, programs (or users) won't have to explicitly > call modprobe. Vhost-net will always be available if built into the kernel. > It does require assigning a permanent minor number for depmod to work. > Choose one next to TUN since this driver is related to it.Why do you think a statically-allocated device number will do any good at all? Static /dev is gone almost completely, at least on the systems where whole virt stuff makes any sense, so you don't have pre-created vhost-net device anymore, and hence this allocation makes no sense. Just IMHO anyway. Thanks, /mjt
On Wed, Jan 11, 2012 at 12:54 PM, Stephen Hemminger <shemminger at vyatta.com>wrote:> By adding the a module alias, programs (or users) won't have to explicitly > call modprobe. Vhost-net will always be available if built into the kernel. > It does require assigning a permanent minor number for depmod to work. > Choose one next to TUN since this driver is related to it. > > Also, use C99 style initialization. > > Signed-off-by: Stephen Hemminger <shemminger at vyatta.com> > > --- > drivers/vhost/net.c | 8 +++++--- > include/linux/miscdevice.h | 1 + > 2 files changed, 6 insertions(+), 3 deletions(-) > > --- a/drivers/vhost/net.c 2012-01-10 10:56:58.883179194 -0800 > +++ b/drivers/vhost/net.c 2012-01-10 19:48:23.650225892 -0800 > @@ -856,9 +856,9 @@ static const struct file_operations vhos > }; > > static struct miscdevice vhost_net_misc = { > - MISC_DYNAMIC_MINOR, > - "vhost-net", > - &vhost_net_fops, > + .minor = VHOST_NET_MINOR, > + .name = "vhost-net", > + .fops = &vhost_net_fops, > }; > > static int vhost_net_init(void) > @@ -879,3 +879,5 @@ MODULE_VERSION("0.0.1"); > MODULE_LICENSE("GPL v2"); > MODULE_AUTHOR("Michael S. Tsirkin"); > MODULE_DESCRIPTION("Host kernel accelerator for virtio net"); > +MODULE_ALIAS_MISCDEV(VHOST_NET_MINOR); > +MODULE_ALIAS("devname:vhost-net"); > --- a/include/linux/miscdevice.h 2012-01-10 10:56:59.779189436 > -0800 > +++ b/include/linux/miscdevice.h 2012-01-10 19:49:56.091748210 > -0800 > @@ -31,6 +31,7 @@ > #define I2O_MINOR 166 > #define MICROCODE_MINOR 184 > #define TUN_MINOR 200 > +#define VHOST_NET_MINOR 201 >CC: alan at linux.intel.com CC: device at lanana.org include/linux/miscdevice.h: /* * These allocations are managed by device at lanana.org. If you use an * entry that is not in assigned your entry may well be moved and * reassigned, or set dynamic if a fixed value is not justified. */ #define MWAVE_MINOR 219 /* ACP/Mwave Modem */> #define MPT_MINOR 220 > #define MPT2SAS_MINOR 221 > > _______________________________________________ > Virtualization mailing list > Virtualization at lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/virtualization >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linuxfoundation.org/pipermail/virtualization/attachments/20120111/6d7c5b63/attachment-0001.html>
On Wed, 11 Jan 2012 11:07:47 +0400 Michael Tokarev <mjt at tls.msk.ru> wrote:> On 11.01.2012 08:54, Stephen Hemminger wrote: > > By adding the a module alias, programs (or users) won't have to explicitly > > call modprobe. Vhost-net will always be available if built into the kernel. > > It does require assigning a permanent minor number for depmod to work. > > Choose one next to TUN since this driver is related to it. > > Why do you think a statically-allocated device number will do any good > at all? Static /dev is gone almost completely, at least on the systems > where whole virt stuff makes any sense, so you don't have pre-created > vhost-net device anymore, and hence this allocation makes no sense. > Just IMHO anyway.The statically allocated device number is required for the udev/module autoloading to work. Probably the udev infrastructure needs a consistent number to hang off of. It looks like: * driver adds MODULE_ALIAS() for devname and character device * depmod scans modules and creates modules.devname (in /lib/modules) * udev uses modules.devname to autoload the module $ /sbin/modinfo vhost_net filename: /lib/modules/3.2.0-net+/kernel/drivers/vhost/vhost_net.ko alias: devname:vhost-net alias: char-major-10-201 description: Host kernel accelerator for virtio net ... See also: https://lkml.org/lkml/2010/5/21/134
By adding the correct module alias, programs won't have to explicitly call modprobe. Vhost-net will always be available if built into the kernel. It does require assigning a permanent minor number for depmod to work. Choose one next to TUN since this driver is related to it. Also, use C99 style initialization. Signed-off-by: Stephen Hemminger <shemminger at vyatta.com> --- v2 - document minor number and make sure to not overlap Documentation/devices.txt | 2 ++ drivers/vhost/net.c | 8 +++++--- include/linux/miscdevice.h | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) --- a/drivers/vhost/net.c 2012-01-10 10:56:58.883179194 -0800 +++ b/drivers/vhost/net.c 2012-01-10 19:48:23.650225892 -0800 @@ -856,9 +856,9 @@ static const struct file_operations vhos }; static struct miscdevice vhost_net_misc = { - MISC_DYNAMIC_MINOR, - "vhost-net", - &vhost_net_fops, + .minor = VHOST_NET_MINOR, + .name = "vhost-net", + .fops = &vhost_net_fops, }; static int vhost_net_init(void) @@ -879,3 +879,5 @@ MODULE_VERSION("0.0.1"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Michael S. Tsirkin"); MODULE_DESCRIPTION("Host kernel accelerator for virtio net"); +MODULE_ALIAS_MISCDEV(VHOST_NET_MINOR); +MODULE_ALIAS("devname:vhost-net"); --- a/include/linux/miscdevice.h 2012-01-10 10:56:59.779189436 -0800 +++ b/include/linux/miscdevice.h 2012-01-11 09:13:20.803694316 -0800 @@ -42,6 +42,7 @@ #define AUTOFS_MINOR 235 #define MAPPER_CTRL_MINOR 236 #define LOOP_CTRL_MINOR 237 +#define VHOST_NET_MINOR 238 #define MISC_DYNAMIC_MINOR 255 struct device; --- a/Documentation/devices.txt 2012-01-10 10:56:53.399116518 -0800 +++ b/Documentation/devices.txt 2012-01-11 09:12:49.251197653 -0800 @@ -447,6 +447,8 @@ Your cooperation is appreciated. 234 = /dev/btrfs-control Btrfs control device 235 = /dev/autofs Autofs control device 236 = /dev/mapper/control Device-Mapper control device + 237 = /dev/vhost-net Host kernel accelerator for virtio net + 240-254 Reserved for local use 255 Reserved for MISC_DYNAMIC_MINOR
On 01/11/2012 06:54 AM, Stephen Hemminger wrote:> By adding the a module alias, programs (or users) won't have to explicitly > call modprobe. Vhost-net will always be available if built into the kernel. > It does require assigning a permanent minor number for depmod to work. > Choose one next to TUN since this driver is related to it.Statically allocated numbers have to go through lanana, no? This increases the security exposure and the kernel footprint for hosts that don't want vhost-net. -- error compiling committee.c: too many arguments to function