aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2010-03-30 14:31:26 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-21 12:37:31 -0400
commit3ff195b011d7decf501a4d55aeed312731094796 (patch)
tree8cfdc330abbf82893955f2d7d6e96efee81bfd7c /drivers
parentbc451f2058238013e1cdf4acd443c01734d332f0 (diff)
sysfs: Implement sysfs tagged directory support.
The problem. When implementing a network namespace I need to be able to have multiple network devices with the same name. Currently this is a problem for /sys/class/net/*, /sys/devices/virtual/net/*, and potentially a few other directories of the form /sys/ ... /net/*. What this patch does is to add an additional tag field to the sysfs dirent structure. For directories that should show different contents depending on the context such as /sys/class/net/, and /sys/devices/virtual/net/ this tag field is used to specify the context in which those directories should be visible. Effectively this is the same as creating multiple distinct directories with the same name but internally to sysfs the result is nicer. I am calling the concept of a single directory that looks like multiple directories all at the same path in the filesystem tagged directories. For the networking namespace the set of directories whose contents I need to filter with tags can depend on the presence or absence of hotplug hardware or which modules are currently loaded. Which means I need a simple race free way to setup those directories as tagged. To achieve a reace free design all tagged directories are created and managed by sysfs itself. Users of this interface: - define a type in the sysfs_tag_type enumeration. - call sysfs_register_ns_types with the type and it's operations - sysfs_exit_ns when an individual tag is no longer valid - Implement mount_ns() which returns the ns of the calling process so we can attach it to a sysfs superblock. - Implement ktype.namespace() which returns the ns of a syfs kobject. Everything else is left up to sysfs and the driver layer. For the network namespace mount_ns and namespace() are essentially one line functions, and look to remain that. Tags are currently represented a const void * pointers as that is both generic, prevides enough information for equality comparisons, and is trivial to create for current users, as it is just the existing namespace pointer. The work needed in sysfs is more extensive. At each directory or symlink creating I need to check if the directory it is being created in is a tagged directory and if so generate the appropriate tag to place on the sysfs_dirent. Likewise at each symlink or directory removal I need to check if the sysfs directory it is being removed from is a tagged directory and if so figure out which tag goes along with the name I am deleting. Currently only directories which hold kobjects, and symlinks are supported. There is not enough information in the current file attribute interfaces to give us anything to discriminate on which makes it useless, and there are no potential users which makes it an uninteresting problem to solve. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/gpiolib.c2
-rw-r--r--drivers/md/bitmap.c4
-rw-r--r--drivers/md/md.c6
3 files changed, 6 insertions, 6 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index eb0c3fe44b29..cae1b8c5b08c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -399,7 +399,7 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
399 goto free_id; 399 goto free_id;
400 } 400 }
401 401
402 pdesc->value_sd = sysfs_get_dirent(dev->kobj.sd, "value"); 402 pdesc->value_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "value");
403 if (!pdesc->value_sd) { 403 if (!pdesc->value_sd) {
404 ret = -ENODEV; 404 ret = -ENODEV;
405 goto free_id; 405 goto free_id;
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 26ac8aad0b19..f084249295d9 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1678,9 +1678,9 @@ int bitmap_create(mddev_t *mddev)
1678 1678
1679 bitmap->mddev = mddev; 1679 bitmap->mddev = mddev;
1680 1680
1681 bm = sysfs_get_dirent(mddev->kobj.sd, "bitmap"); 1681 bm = sysfs_get_dirent(mddev->kobj.sd, NULL, "bitmap");
1682 if (bm) { 1682 if (bm) {
1683 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear"); 1683 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, NULL, "can_clear");
1684 sysfs_put(bm); 1684 sysfs_put(bm);
1685 } else 1685 } else
1686 bitmap->sysfs_can_clear = NULL; 1686 bitmap->sysfs_can_clear = NULL;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index cefd63daff31..a9fd491796ac 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1766,7 +1766,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1766 kobject_del(&rdev->kobj); 1766 kobject_del(&rdev->kobj);
1767 goto fail; 1767 goto fail;
1768 } 1768 }
1769 rdev->sysfs_state = sysfs_get_dirent(rdev->kobj.sd, "state"); 1769 rdev->sysfs_state = sysfs_get_dirent(rdev->kobj.sd, NULL, "state");
1770 1770
1771 list_add_rcu(&rdev->same_set, &mddev->disks); 1771 list_add_rcu(&rdev->same_set, &mddev->disks);
1772 bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); 1772 bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk);
@@ -4189,7 +4189,7 @@ static int md_alloc(dev_t dev, char *name)
4189 mutex_unlock(&disks_mutex); 4189 mutex_unlock(&disks_mutex);
4190 if (!error) { 4190 if (!error) {
4191 kobject_uevent(&mddev->kobj, KOBJ_ADD); 4191 kobject_uevent(&mddev->kobj, KOBJ_ADD);
4192 mddev->sysfs_state = sysfs_get_dirent(mddev->kobj.sd, "array_state"); 4192 mddev->sysfs_state = sysfs_get_dirent(mddev->kobj.sd, NULL, "array_state");
4193 } 4193 }
4194 mddev_put(mddev); 4194 mddev_put(mddev);
4195 return error; 4195 return error;
@@ -4398,7 +4398,7 @@ static int do_md_run(mddev_t * mddev)
4398 printk(KERN_WARNING 4398 printk(KERN_WARNING
4399 "md: cannot register extra attributes for %s\n", 4399 "md: cannot register extra attributes for %s\n",
4400 mdname(mddev)); 4400 mdname(mddev));
4401 mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, "sync_action"); 4401 mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, NULL, "sync_action");
4402 } else if (mddev->ro == 2) /* auto-readonly not meaningful */ 4402 } else if (mddev->ro == 2) /* auto-readonly not meaningful */
4403 mddev->ro = 0; 4403 mddev->ro = 0;
4404 4404