[lxc-devel] [RFC PATCH 09/11] misc: Make loop-control available to all user namespaces

Seth Forshee seth.forshee at canonical.com
Wed May 14 21:34:57 UTC 2014


Add a ns_global field to struct miscdevice to allow indicating
that the created struct device should be global to all user
namespaces, and set this flag for loop-control.

Signed-off-by: Seth Forshee <seth.forshee at canonical.com>
---
 drivers/block/loop.c       |  1 +
 drivers/char/misc.c        | 11 +++++++++--
 include/linux/miscdevice.h |  1 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index f70a230a2945..f0e41a372c24 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1813,6 +1813,7 @@ static struct miscdevice loop_misc = {
 	.minor		= LOOP_CTRL_MINOR,
 	.name		= "loop-control",
 	.fops		= &loop_ctl_fops,
+	.ns_global	= true,
 };
 
 MODULE_ALIAS_MISCDEV(LOOP_CTRL_MINOR);
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index ffa97d261cf3..5940ebd98023 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -205,8 +205,15 @@ int misc_register(struct miscdevice * misc)
 
 	dev = MKDEV(MISC_MAJOR, misc->minor);
 
-	misc->this_device = device_create(misc_class, misc->parent, dev,
-					  misc, "%s", misc->name);
+	if (misc->ns_global)
+		misc->this_device = device_create_global(misc_class,
+							 misc->parent, dev,
+							 misc, "%s",
+							 misc->name);
+	else
+		misc->this_device = device_create(misc_class, misc->parent, dev,
+						  misc, "%s", misc->name);
+
 	if (IS_ERR(misc->this_device)) {
 		int i = DYNAMIC_MINORS - misc->minor - 1;
 		if (i < DYNAMIC_MINORS && i >= 0)
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 51e26f3cd3b3..a85782339fe2 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -62,6 +62,7 @@ struct miscdevice  {
 	struct device *this_device;
 	const char *nodename;
 	umode_t mode;
+	bool ns_global;
 };
 
 extern int misc_register(struct miscdevice * misc);
-- 
1.9.1



More information about the lxc-devel mailing list