OpenVZ Forum - RDF feed
type: channel
items: [PATCH 00/11] sysfs tagged directories V5
items: [PATCH 01/11] sysfs: Support for preventing unmounts.
items: [PATCH 02/11] sysfs: sysfs_get_dentry add a sb parameter
items: [PATCH 03/11] sysfs: Implement __sysfs_get_dentry
items: [PATCH 04/11] sysfs: Rename Support multiple superblocks
items: [PATCH 05/11] sysfs: sysfs_chmod_file handle multiple superblocks
items: [PATCH 06/11] sysfs: Implement sysfs tagged directory support.
items: [PATCH 07/11] sysfs: Implement sysfs_delete_link and sysfs_rename_link
items: [PATCH 08/11] driver core: Implement tagged directory support for device classes.
items: [PATCH 09/11] sysfs: add sysfs_ns_exit routine
items: [PATCH 10/11] netns: Enable tagging for net_class directories in sysfs
items: [PATCH 11/11] sysfs: user namespaces: fix bug with clone(CLONE_NEWUSER) with fairsched
items: Re: [PATCH 11/11] sysfs: user namespaces: fix bug with clone(CLONE_NEWUSER) with fairsched
items: Re: [PATCH 00/11] sysfs tagged directories V5
items: Re: [PATCH 05/11] sysfs: sysfs_chmod_file handle multiple superblocks

[PATCH 00/11] sysfs tagged directories V5
type: item
description: Greg, Here is an updated version of the sysfs tagged directories that improves a bit the situation over the previous one. I've modified the patch 09 ("Enable tagging for net_class directories in sysfs") to be a bit less intrusive in sysfs core. I removed the #ifdef'd parts you didn't like in fs/sysfs/mount.c, and replaced it by a generic routine sysfs_ns_exit() that is called, if needed, by the namespace when it exits. This routine goes through every sysfs super blocks and calls the callback passed by the namespace to clean its tag. The patch is now splitted in two: * 09/11: the generic routine, * 10/11: the remaining network parts. The generic part can be merge with patch 05 ("sysfs: Implement sysfs tagged directory support.") but I left it separate for now to ease reviews. Serge's patch for user namespace is modified to use this new service too. No more #ifdef CONFIG_NET or #ifdef CONFIG_USER_NS in fs/sysfs/mount.c now. But, currently, a new namespace that wants to add its tag to sysfs dirs still need to modify fs/sysfs/mount.c in a few routines to manage the new tag member added in struct sysfs_tag_info: sysfs_fill_super(), sysfs_test_super(), sysfs_kill_sb() (see the last two patches). These changes are only the initialization and a bunch of comparisons. If we really want to go further, to get rid of these, I've thought about: * Extending sysfs_tagged_dir_operations with super blocks operations: - fill_sb_tag, test_sb_tag, kill_sb_tag * Add routines in sysfs to allow registration/unregistration of these operations structs in a list: - sysfs_register_tagged_dir_ops()... * Each subsystem concerned implements and registers its operations at boot. * In sysfs_fill_super(), sysfs_test_super() and sysfs_kill_sb(), add loops to go through all registered operations structs and calls the corresponding operations if it's present. But... I thought it was a bit overkill for the few namespaces that will actually need sysfs tagged directories. (Below you'll find the traditiona…
creator: Benjamin Thery
date: 2008-06-06T15:46:54-00:00

[PATCH 01/11] sysfs: Support for preventing unmounts.
type: item
description: sysfs: Support for preventing unmounts. To support mounting multiple instances of sysfs occassionally I need to walk through all of the currently present sysfs super blocks. To allow this iteration this patch adds sysfs_grab_supers and sysfs_release_supers. While a piece of code is in a section surrounded by these no more sysfs super blocks will be either created or destroyed. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/mount.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++------ fs/sysfs/sysfs.h | 10 ++++++ 2 files changed, 81 insertions(+), 8 deletions(-) Index: linux-mm/fs/sysfs/mount.c =================================================================== --- linux-mm.orig/fs/sysfs/mount.c +++ linux-mm/fs/sysfs/mount.c @@ -41,47 +41,110 @@ struct sysfs_dirent sysfs_root = { static int sysfs_fill_super(struct super_block *sb, void *data, int silent) { - struct inode *inode; - struct dentry *root; + struct sysfs_super_info *info = NULL; + struct inode *inode = NULL; + struct dentry *root = NULL; + int error; sb->s_blocksize = PAGE_CACHE_SIZE; sb->s_blocksize_bits = PAGE_CACHE_SHIFT; sb->s_magic = SYSFS_MAGIC; sb->s_op = &sysfs_ops; sb->s_time_gran = 1; - sysfs_sb = sb; + if (!sysfs_sb) + sysfs_sb = sb; + + error = -ENOMEM; + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + goto out_err; /* get root inode, initialize and unlock it */ + error = -ENOMEM; inode = sysfs_get_inode(&sysfs_root); if (!inode) { pr_debug("sysfs: could not get root inode\n"); - return -ENOMEM; + goto out_err; } /* instantiate and link root dentry */ + error = -ENOMEM; root = d_alloc_root(inode); if (!root) { pr_debug("%s: could not get root dentry!\n",__func__); - iput(inode); - return -ENOMEM; + goto out_err; } root->d_fsdata = &sysfs_root; sb->s_root = root; + sb->s_fs_info = info; return 0; + +out_err: + dput(root); + iput(inode); + kfree(info); + if (sysfs_sb == sb) + sysfs_sb = NULL; + return…
creator: Benjamin Thery
date: 2008-06-06T15:47:04-00:00

[PATCH 02/11] sysfs: sysfs_get_dentry add a sb parameter
type: item
description: sysfs: sysfs_get_dentry add a sb parameter In preparation for multiple mounts of sysfs add a superblock parameter to sysfs_get_dentry. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/dir.c | 12 +++++++----- fs/sysfs/file.c | 2 +- fs/sysfs/sysfs.h | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) Index: linux-mm/fs/sysfs/dir.c =================================================================== --- linux-mm.orig/fs/sysfs/dir.c +++ linux-mm/fs/sysfs/dir.c @@ -87,6 +87,7 @@ static void sysfs_unlink_sibling(struct /** * sysfs_get_dentry - get dentry for the given sysfs_dirent + * @sb: superblock of the dentry to return * @sd: sysfs_dirent of interest * * Get dentry for @sd. Dentry is looked up if currently not @@ -99,9 +100,10 @@ static void sysfs_unlink_sibling(struct * RETURNS: * Pointer to found dentry on success, ERR_PTR() value on error. */ -struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd) +struct dentry *sysfs_get_dentry(struct super_block *sb, + struct sysfs_dirent *sd) { - struct dentry *dentry = dget(sysfs_sb->s_root); + struct dentry *dentry = dget(sb->s_root); while (dentry->d_fsdata != sd) { struct sysfs_dirent *cur; @@ -790,7 +792,7 @@ int sysfs_rename_dir(struct kobject * ko goto out; /* nothing to rename */ /* get the original dentry */ - old_dentry = sysfs_get_dentry(sd); + old_dentry = sysfs_get_dentry(sysfs_sb, sd); if (IS_ERR(old_dentry)) { error = PTR_ERR(old_dentry); old_dentry = NULL; @@ -858,7 +860,7 @@ int sysfs_move_dir(struct kobject *kobj, goto out; /* nothing to move */ /* get dentries */ - old_dentry = sysfs_get_dentry(sd); + old_dentry = sysfs_get_dentry(sysfs_sb, sd); if (IS_ERR(old_dentry)) { error = PTR_ERR(old_dentry); old_dentry = NULL; @@ -866,7 +868,7 @@ int sysfs_move_dir(struct kobject *kobj, } old_parent = old_dentry->d_parent; - new_parent = sysfs_get_dentry(new_parent_sd); + new_parent = sysfs_get_dentry(sysfs_sb, new_parent_sd); if (IS_…
creator: Benjamin Thery
date: 2008-06-06T15:47:14-00:00

[PATCH 03/11] sysfs: Implement __sysfs_get_dentry
type: item
description: sysfs: Implement __sysfs_get_dentry This function is similar but much simpler to sysfs_get_dentry returns a sysfs dentry if one curently exists. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/dir.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) Index: linux-mm/fs/sysfs/dir.c =================================================================== --- linux-mm.orig/fs/sysfs/dir.c +++ linux-mm/fs/sysfs/dir.c @@ -777,6 +777,45 @@ void sysfs_remove_dir(struct kobject * k __sysfs_remove_dir(sd); } +/** + * __sysfs_get_dentry - get dentry for the given sysfs_dirent + * @sb: superblock of the dentry to return + * @sd: sysfs_dirent of interest + * + * Get dentry for @sd. Only return a dentry if one currently + * exists. + * + * LOCKING: + * Kernel thread context (may sleep) + * + * RETURNS: + * Pointer to found dentry on success, NULL on failure. + */ +static struct dentry *__sysfs_get_dentry(struct super_block *sb, + struct sysfs_dirent *sd) +{ + struct inode *inode; + struct dentry *dentry = NULL; + + inode = ilookup5_nowait(sysfs_sb, sd->s_ino, sysfs_ilookup_test, sd); + if (inode && !(inode->i_state & I_NEW)) { + struct dentry *alias; + spin_lock(&dcache_lock); + list_for_each_entry(alias, &inode->i_dentry, d_alias) { + if (!IS_ROOT(alias) && d_unhashed(alias)) + continue; + if (alias->d_sb != sb) + continue; + dentry = alias; + dget_locked(dentry); + break; + } + spin_unlock(&dcache_lock); + } + iput(inode); + return dentry; +} + int sysfs_rename_dir(struct kobject * kobj, const char *new_name) { struct sysfs_dirent *sd = kobj->sd; -- _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Benjamin Thery
date: 2008-06-06T15:47:24-00:00

[PATCH 04/11] sysfs: Rename Support multiple superblocks
type: item
description: sysfs: Rename Support multiple superblocks This patch modifies the sysfs_rename_dir and sysfs_move_dir routines to support multiple sysfs dentry tries rooted in different sysfs superblocks. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/dir.c | 195 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 137 insertions(+), 58 deletions(-) Index: linux-mm/fs/sysfs/dir.c =================================================================== --- linux-mm.orig/fs/sysfs/dir.c +++ linux-mm/fs/sysfs/dir.c @@ -816,43 +816,113 @@ static struct dentry *__sysfs_get_dentry return dentry; } +struct sysfs_rename_struct { + struct list_head list; + struct dentry *old_dentry; + struct dentry *new_dentry; + struct dentry *old_parent; + struct dentry *new_parent; +}; + +static void post_rename(struct list_head *head) +{ + struct sysfs_rename_struct *srs; + while (!list_empty(head)) { + srs = list_entry(head->next, struct sysfs_rename_struct, list); + dput(srs->old_dentry); + dput(srs->new_dentry); + dput(srs->old_parent); + dput(srs->new_parent); + list_del(&srs->list); + kfree(srs); + } +} + +static int prep_rename(struct list_head *head, + struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd, + const char *name) +{ + struct sysfs_rename_struct *srs; + struct super_block *sb; + struct dentry *dentry; + int error; + + list_for_each_entry(sb, &sysfs_fs_type.fs_supers, s_instances) { + dentry = sysfs_get_dentry(sb, sd); + if (dentry == ERR_PTR(-EXDEV)) + continue; + if (IS_ERR(dentry)) { + error = PTR_ERR(dentry); + goto err_out; + } + + srs = kzalloc(sizeof(*srs), GFP_KERNEL); + if (!srs) { + error = -ENOMEM; + dput(dentry); + goto err_out; + } + + INIT_LIST_HEAD(&srs->list); + list_add(head, &srs->list); + srs->old_dentry = dentry; + srs->old_parent = dget(dentry->d_parent); + + dentry = sysfs_get_dentry(sb, new_parent_sd); + if (IS_ERR(dentry)) { + error = PTR_ERR(dentry); + goto err_…
creator: Benjamin Thery
date: 2008-06-06T15:47:34-00:00

[PATCH 05/11] sysfs: sysfs_chmod_file handle multiple superblocks
type: item
description: sysfs: sysfs_chmod_file handle multiple superblocks Teach sysfs_chmod_file how to handle multiple sysfs superblocks. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/file.c | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) Index: linux-mm/fs/sysfs/file.c =================================================================== --- linux-mm.orig/fs/sysfs/file.c +++ linux-mm/fs/sysfs/file.c @@ -573,7 +573,8 @@ EXPORT_SYMBOL_GPL(sysfs_add_file_to_grou int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode) { struct sysfs_dirent *victim_sd = NULL; - struct dentry *victim = NULL; + struct super_block *sb; + struct dentry *victim; struct inode * inode; struct iattr newattrs; int rc; @@ -584,31 +585,36 @@ int sysfs_chmod_file(struct kobject *kob goto out; mutex_lock(&sysfs_rename_mutex); - victim = sysfs_get_dentry(sysfs_sb, victim_sd); - mutex_unlock(&sysfs_rename_mutex); - if (IS_ERR(victim)) { - rc = PTR_ERR(victim); - victim = NULL; - goto out; - } - - inode = victim->d_inode; + sysfs_grab_supers(); + list_for_each_entry(sb, &sysfs_fs_type.fs_supers, s_instances) { + victim = sysfs_get_dentry(sb, victim_sd); + if (victim == ERR_PTR(-EXDEV)) + continue; + if (IS_ERR(victim)) { + rc = PTR_ERR(victim); + victim = NULL; + goto out_unlock; + } + + inode = victim->d_inode; + mutex_lock(&inode->i_mutex); + newattrs.ia_mode = (mode & S_IALLUGO) | + (inode->i_mode & ~S_IALLUGO); + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; + rc = notify_change(victim, &newattrs); + if (rc == 0) { + mutex_lock(&sysfs_mutex); + victim_sd->s_mode = newattrs.ia_mode; + mutex_unlock(&sysfs_mutex); + } + mutex_unlock(&inode->i_mutex); - mutex_lock(&inode->i_mutex); - - newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); - newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; - rc = notify_change(victim, &newattrs); - - if (rc == 0) { - mut…
creator: Benjamin Thery
date: 2008-06-06T15:47:44-00:00

[PATCH 06/11] sysfs: Implement sysfs tagged directory support.
type: item
description: 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 race free design all tagged directories are created and managed by sysfs itself. The upper level code that knows what tagged directories we need provides just two methods that enable this: sb_tag() - that returns a "void *" tag that identifies the context of the process that mounted sysfs. kobject_tag(kobj) - that returns a "void *" tag that identifies the context a kobject should be in. Everything else is left up to sysfs. For the network namespace sb_tag and kobject_tag are essentially one line functions, and look to remain that. 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 remo…
creator: Benjamin Thery
date: 2008-06-06T15:47:54-00:00

[PATCH 07/11] sysfs: Implement sysfs_delete_link and sysfs_rename_link
type: item
description: sysfs: Implement sysfs_delete_link and sysfs_rename_link When removing a symlink sysfs_remove_link does not provide enough information to figure out which tagged directory the symlink falls in. So I need sysfs_delete_link which is passed the target of the symlink to delete. Further half the time when we are removing a symlink the code is actually renaming the symlink but not doing so explicitly because we don't have a symlink rename method. So I have added sysfs_rename_link as well. Both of these functions now have enough information to find a symlink in a tagged directory. The only restriction is that they must be called before the target kobject is renamed or deleted. If they are called later I loose track of which tag the target kobject was marked with and can no longer find the old symlink to remove it. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/symlink.c | 31 +++++++++++++++++++++++++++++++ include/linux/sysfs.h | 17 +++++++++++++++++ 2 files changed, 48 insertions(+) Index: linux-mm/fs/sysfs/symlink.c =================================================================== --- linux-mm.orig/fs/sysfs/symlink.c +++ linux-mm/fs/sysfs/symlink.c @@ -80,6 +80,21 @@ int sysfs_create_link(struct kobject * k } /** + * sysfs_delete_link - remove symlink in object's directory. + * @kobj: object we're acting for. + * @targ: object we're pointing to. + * @name: name of the symlink to remove. + * + * Unlike sysfs_remove_link sysfs_delete_link has enough information + * to successfully delete symlinks in tagged directories. + */ +void sysfs_delete_link(struct kobject *kobj, struct kobject *targ, + const char *name) +{ + sysfs_hash_and_remove(targ, kobj->sd, name); +} + +/** * sysfs_remove_link - remove symlink in object's directory. * @kobj: object we're acting for. * @name: name of the symlink to remove. @@ -97,6 +112,22 @@ void sysfs_remove_link(struct kobject * sysfs_hash_and_remove(kobj, parent…
creator: Benjamin Thery
date: 2008-06-06T15:48:04-00:00

[PATCH 08/11] driver core: Implement tagged directory support for device classes.
type: item
description: driver core: Implement tagged directory support for device classes. This patch enables tagging on every class directory if struct class has tag_ops. In addition device_del and device_rename were modified to use sysfs_delete_link and sysfs_rename_link respectively to ensure when these operations happen on devices whose classes have tag_ops that they work properly. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- drivers/base/class.c | 30 ++++++++++++++++++++++++++---- drivers/base/core.c | 41 ++++++++++++++++++++++------------------- include/linux/device.h | 2 ++ 3 files changed, 50 insertions(+), 23 deletions(-) Index: linux-mm/drivers/base/class.c =================================================================== --- linux-mm.orig/drivers/base/class.c +++ linux-mm/drivers/base/class.c @@ -134,6 +134,17 @@ static void remove_class_attrs(struct cl } } +static int class_setup_tagging(struct class *cls) +{ + const struct sysfs_tagged_dir_operations *tag_ops; + + tag_ops = cls->tag_ops; + if (!tag_ops) + return 0; + + return sysfs_enable_tagging(&cls->subsys.kobj, tag_ops); +} + int class_register(struct class *cls) { int error; @@ -162,11 +173,22 @@ int class_register(struct class *cls) cls->subsys.kobj.ktype = &class_ktype; error = kset_register(&cls->subsys); - if (!error) { - error = add_class_attrs(class_get(cls)); - class_put(cls); - } + if (error) + goto out; + + error = class_setup_tagging(cls); + if (error) + goto out_unregister; + + error = add_class_attrs(cls); + if (error) + goto out_unregister; + +out: return error; +out_unregister: + kset_unregister(&cls->subsys); + goto out; } void class_unregister(struct class *cls) Index: linux-mm/drivers/base/core.c =================================================================== --- linux-mm.orig/drivers/base/core.c +++ linux-mm/drivers/base/core.c @@ -617,6 +617,10 @@ static struct kobject *get_device_parent kobject_put(k); return NULL; } + /* If…
creator: Benjamin Thery
date: 2008-06-06T15:48:14-00:00

[PATCH 09/11] sysfs: add sysfs_ns_exit routine
type: item
description: Add sysfs routine sysfs_ns_exit() to allow a namespace to go away while sysfs is still mounted. The exiting namespace calls this routine and pass it a callback to be called for every sysfs superblocks present. The callback contains the necessary code to clean the superblock tag data associated with this namespace. Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/mount.c | 21 +++++++++++++++++++++ include/linux/sysfs.h | 8 ++++++++ 2 files changed, 29 insertions(+) Index: linux-mm/fs/sysfs/mount.c =================================================================== --- linux-mm.orig/fs/sysfs/mount.c +++ linux-mm/fs/sysfs/mount.c @@ -181,6 +181,27 @@ restart: spin_unlock(&sb_lock); } +/* Clean sysfs tags related to a given namespace when it exits */ +void sysfs_ns_exit(void (*func)(struct sysfs_tag_info *, void *), void *data) +{ + /* Allow the namespace to go away while sysfs is still mounted. */ + struct super_block *sb; + mutex_lock(&sysfs_rename_mutex); + sysfs_grab_supers(); + mutex_lock(&sysfs_mutex); + list_for_each_entry(sb, &sysfs_fs_type.fs_supers, s_instances) { + + struct sysfs_super_info *info = sysfs_info(sb); + /* Call the cleaning routine provided by the namespace. + * data is the current namespace id passed by the namespace. + */ + func(&info->tag, data); + } + mutex_unlock(&sysfs_mutex); + sysfs_release_supers(); + mutex_unlock(&sysfs_rename_mutex); +} + int __init sysfs_init(void) { int err = -ENOMEM; Index: linux-mm/include/linux/sysfs.h =================================================================== --- linux-mm.orig/include/linux/sysfs.h +++ linux-mm/include/linux/sysfs.h @@ -134,6 +134,9 @@ void sysfs_printk_last_file(void); int sysfs_enable_tagging(struct kobject *kobj, const struct sysfs_tagged_dir_operations *tag_ops); +void sysfs_ns_exit(void (*func)(struct sysfs_tag_info *, void *), + void *data); + extern int __must_check sysfs_init(void); #else /* CONFIG_SYSFS */ @@ -247,6 +250,11 @@ static inline int sysfs_enable_t…
creator: Benjamin Thery
date: 2008-06-06T15:48:24-00:00

[PATCH 10/11] netns: Enable tagging for net_class directories in sysfs
type: item
description: net: Enable tagging for net_class directories in sysfs The problem. Network devices show up in sysfs and with the network namespace active multiple devices with the same name can show up in the same directory, ouch! To avoid that problem and allow existing applications in network namespaces to see the same interface that is currently presented in sysfs, this patch enables the tagging directory support in sysfs. By using the network namespace pointers as tags to separate out the the sysfs directory entries we ensure that we don't have conflicts in the directories and applications only see a limited set of the network devices. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/mount.c | 8 ++++++++ include/linux/sysfs.h | 2 ++ net/Kconfig | 2 +- net/core/net-sysfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) Index: linux-mm/fs/sysfs/mount.c =================================================================== --- linux-mm.orig/fs/sysfs/mount.c +++ linux-mm/fs/sysfs/mount.c @@ -16,6 +16,8 @@ #include <linux/mount.h> #include <linux/pagemap.h> #include <linux/init.h> +#include <linux/nsproxy.h> +#include <net/net_namespace.h> #include "sysfs.h" @@ -78,6 +80,7 @@ static int sysfs_fill_super(struct super root->d_sb = sb; sb->s_root = root; sb->s_fs_info = info; + info->tag.net_ns = hold_net(current->nsproxy->net_ns); return 0; out_err: @@ -95,6 +98,9 @@ static int sysfs_test_super(struct super struct sysfs_super_info *info = sysfs_info(sb); int found = 1; + if (task->nsproxy->net_ns != info->tag.net_ns) + found = 0; + return found; } @@ -131,6 +137,8 @@ static void sysfs_kill_sb(struct super_b struct sysfs_super_info *info = sysfs_info(sb); kill_anon_super(sb); + if (info->tag.net_ns) + release_net(info->tag.net_ns); kfree(info); } Index: linux-mm/include/linux/sysfs.h =================================================================== --- linux…
creator: Benjamin Thery
date: 2008-06-06T15:48:34-00:00

[PATCH 11/11] sysfs: user namespaces: fix bug with clone(CLONE_NEWUSER) with fairsched
type: item
description: Mark the /sys/kernel/uids directory to be tagged so that processes in different user namespaces can remount /sys and see their own uid listings. Without this patch, having CONFIG_FAIR_SCHED=y makes user namespaces unusable, because when you clone(CLONE_NEWUSER) it will auto-create the root userid and try to create /sys/kernel/uids/0. Since that already exists from the parent user namespace, the create fails, and the clone misleadingly ends up returning -ENOMEM. This patch fixes the issue by allowing each user namespace to remount /sys, and having /sys filter the /sys/kernel/uid/ entries by user namespace. Signed-off-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> --- fs/sysfs/mount.c | 3 +++ include/linux/sched.h | 1 + include/linux/sysfs.h | 2 ++ include/linux/user_namespace.h | 1 + kernel/user.c | 21 +++++++++++++++++++++ kernel/user_namespace.c | 13 ++++++++++++- 6 files changed, 40 insertions(+), 1 deletion(-) Index: linux-mm/fs/sysfs/mount.c =================================================================== --- linux-mm.orig/fs/sysfs/mount.c +++ linux-mm/fs/sysfs/mount.c @@ -81,6 +81,7 @@ static int sysfs_fill_super(struct super sb->s_root = root; sb->s_fs_info = info; info->tag.net_ns = hold_net(current->nsproxy->net_ns); + info->tag.user_ns = current->nsproxy->user_ns; return 0; out_err: @@ -100,6 +101,8 @@ static int sysfs_test_super(struct super if (task->nsproxy->net_ns != info->tag.net_ns) found = 0; + if (task->nsproxy->user_ns != info->tag.user_ns) + found = 0; return found; } Index: linux-mm/include/linux/sched.h =================================================================== --- linux-mm.orig/include/linux/sched.h +++ linux-mm/include/linux/sched.h @@ -600,6 +600,7 @@ struct user_struct { /* Hash table maintenance information */ struct hlist_node uidhash_node; uid_t uid; + struct user_namespace *user_ns; #ifdef CONFIG_USER_SCHED struct task_group *tg; Index: linux-mm/include/linux/sysfs.h ==============…
creator: Benjamin Thery
date: 2008-06-06T15:48:44-00:00

Re: [PATCH 11/11] sysfs: user namespaces: fix bug with clone(CLONE_NEWUSER) with fairsched
type: item
description: Quoting Benjamin Thery (benjamin.thery@bull.net): > Mark the /sys/kernel/uids directory to be tagged so that processes in > different user namespaces can remount /sys and see their own uid > listings. > > Without this patch, having CONFIG_FAIR_SCHED=y makes user namespaces > unusable, because when you > clone(CLONE_NEWUSER) > it will auto-create the root userid and try to create > /sys/kernel/uids/0. Since that already exists from the parent user > namespace, the create fails, and the clone misleadingly ends up > returning -ENOMEM. > > This patch fixes the issue by allowing each user namespace to remount > /sys, and having /sys filter the /sys/kernel/uid/ entries by user > namespace. > > Signed-off-by: Serge Hallyn <serue@us.ibm.com> > Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> > --- > fs/sysfs/mount.c | 3 +++ > include/linux/sched.h | 1 + > include/linux/sysfs.h | 2 ++ > include/linux/user_namespace.h | 1 + > kernel/user.c | 21 +++++++++++++++++++++ > kernel/user_namespace.c | 13 ++++++++++++- > 6 files changed, 40 insertions(+), 1 deletion(-) > > Index: linux-mm/fs/sysfs/mount.c > =================================================================== > --- linux-mm.orig/fs/sysfs/mount.c > +++ linux-mm/fs/sysfs/mount.c > @@ -81,6 +81,7 @@ static int sysfs_fill_super(struct super > sb->s_root = root; > sb->s_fs_info = info; > info->tag.net_ns = hold_net(current->nsproxy->net_ns); > + info->tag.user_ns = current->nsproxy->user_ns; > return 0; > > out_err: > @@ -100,6 +101,8 @@ static int sysfs_test_super(struct super > > if (task->nsproxy->net_ns != info->tag.net_ns) > found = 0; > + if (task->nsproxy->user_ns != info->tag.user_ns) > + found = 0; > > return found; > } > Index: linux-mm/include/linux/sched.h > =================================================================== > --- linux-mm.orig/include/linux/sched.h > +++ linux-mm/include/linux/sched.h > @@ -600,6 +600,7 @@ struct user_struct { > /* Hash table maintenance information */ > struct hlist_node…
creator: serue
date: 2008-06-10T22:41:12-00:00

Re: [PATCH 00/11] sysfs tagged directories V5
type: item
description: Quoting Benjamin Thery (benjamin.thery@bull.net): > Greg, > > Here is an updated version of the sysfs tagged directories that improves > a bit the situation over the previous one. > > I've modified the patch 09 ("Enable tagging for net_class directories in > sysfs") to be a bit less intrusive in sysfs core. I removed the #ifdef'd > parts you didn't like in fs/sysfs/mount.c, and replaced it by a generic > routine sysfs_ns_exit() that is called, if needed, by the namespace when > it exits. This routine goes through every sysfs super blocks and calls > the callback passed by the namespace to clean its tag. > > The patch is now splitted in two: > * 09/11: the generic routine, > * 10/11: the remaining network parts. > > The generic part can be merge with patch 05 ("sysfs: Implement sysfs > tagged directory support.") but I left it separate for now to ease > reviews. Thanks. Not nearly as radical as I'd feared. Greg, does this address your concern? It stops the need to put any non-braindead code (i.e. the _exit notifier stuff) in fs/sysfs/mount.c for any new namespaces needing sysfs tagging, leaving only simple comparison/assignments. > Serge's patch for user namespace is modified to use this new service too. > No more #ifdef CONFIG_NET or #ifdef CONFIG_USER_NS in fs/sysfs/mount.c > now. > > > But, currently, a new namespace that wants to add its tag to sysfs dirs > still need to modify fs/sysfs/mount.c in a few routines to manage the > new tag member added in struct sysfs_tag_info: sysfs_fill_super(), > sysfs_test_super(), sysfs_kill_sb() (see the last two patches). > These changes are only the initialization and a bunch of comparisons. > > If we really want to go further, to get rid of these, I've thought > about: > > * Extending sysfs_tagged_dir_operations with super blocks operations: > - fill_sb_tag, test_sb_tag, kill_sb_tag > > * Add routines in sysfs to allow registration/unregistration of these > operations structs in a list: > - sysfs_register_tagged_dir_ops()...…
creator: serue
date: 2008-06-10T22:50:24-00:00

Re: [PATCH 00/11] sysfs tagged directories V5
type: item
description: On Tue, Jun 10, 2008 at 05:50:24PM -0500, Serge E. Hallyn wrote: > Quoting Benjamin Thery (benjamin.thery@bull.net): > > Greg, > > > > Here is an updated version of the sysfs tagged directories that improves > > a bit the situation over the previous one. > > > > I've modified the patch 09 ("Enable tagging for net_class directories in > > sysfs") to be a bit less intrusive in sysfs core. I removed the #ifdef'd > > parts you didn't like in fs/sysfs/mount.c, and replaced it by a generic > > routine sysfs_ns_exit() that is called, if needed, by the namespace when > > it exits. This routine goes through every sysfs super blocks and calls > > the callback passed by the namespace to clean its tag. > > > > The patch is now splitted in two: > > * 09/11: the generic routine, > > * 10/11: the remaining network parts. > > > > The generic part can be merge with patch 05 ("sysfs: Implement sysfs > > tagged directory support.") but I left it separate for now to ease > > reviews. > > Thanks. Not nearly as radical as I'd feared. > > Greg, does this address your concern? It stops the need to put any > non-braindead code (i.e. the _exit notifier stuff) in fs/sysfs/mount.c for > any new namespaces needing sysfs tagging, leaving only simple > comparison/assignments. Sorry, I've been swamped with other things this week and haven't gotten a chance to look this over. Hopefully by the end of the week... It's in my queue though, don't worry it will not get lost. thanks, greg k-h _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: gregkh
date: 2008-06-10T23:00:58-00:00

Re: [PATCH 05/11] sysfs: sysfs_chmod_file handle multiple superblocks
type: item
description: Daniel Lezcano wrote: > Tejun Heo wrote: >> Hello, >> >> Daniel Lezcano wrote: >>>> I think it would be great if sysfs_chmod_file can do all-or-nothing >>>> instead of failing half way through but given the interface of >>>> notify_change(), it could be difficult to implement. Any ideas? >>> Is it acceptable to queue the notifications in a list until we are in >>> the loop and loop again to notify when exiting the first loop without >>> error ? >> >> Can you please take a look at the following patch? >> >> http://article.gmane.org/gmane.linux.file-systems/24484 >> >> Which replaces notify_change() call to two calls to sysfs_setattr() and >> fsnotify_change(). The latter never fails and the former should always >> succeed if inode_change_ok() succeeds (inode_setattr() never fails >> unless the size is changing), so I think the correct thing to do is... >> >> * Separate out sysfs_do_setattr() which doesn't do inode_change_ok() and >> just sets the attributes. Making it a void function which triggers >> WARN_ON() when inode_setattr() fails would be a good idea. >> >> * Implement sysfs_chmod_file() in similar way rename/move are >> implemented - allocate all resources and check conditions and then iff >> everything looks okay commit the operation by calling sysfs_do_setattr(). >> >> How does that sound? > > Does this patch looks like what you are describing ? Yeah, something like that. With looping for all the inodes added, it looks like it will work fine. Thanks. -- tejun _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Tejun Heo
date: 2008-06-25T12:31:49-00:00