Home » Mailing lists » Devel » [PATCH 0/25] Sysfs cleanups & tagged directory support
[PATCH 16/25] sysfs: Support for preventing unmounts. [message #19578 is a reply to message #19577] |
Tue, 07 August 2007 21:26 |
ebiederm
Messages: 1354 Registered: February 2006
|
Senior Member |
|
|
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>
---
fs/sysfs/mount.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++-----
fs/sysfs/sysfs.h | 10 +++++++
2 files changed, 81 insertions(+), 8 deletions(-)
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 4968d31..b2bfa45 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -33,47 +33,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",__FUNCTION__);
- 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 error;
}
static int sysfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
- return get_sb_single(fs_type, flags, data, sysfs_fill_super, mnt);
+ int rc;
+ mutex_lock(&sysfs_rename_mutex);
+ rc = get_sb_single(fs_type, flags, data, sysfs_fill_super, mnt);
+ mutex_unlock(&sysfs_rename_mutex);
+ return rc;
}
-static struct file_system_type sysfs_fs_type = {
+struct file_system_type sysfs_fs_type = {
.name = "sysfs",
.get_sb = sysfs_get_sb,
.kill_sb = kill_anon_super,
};
+void sysfs_grab_supers(void)
+{
+ /* must hold sysfs_rename_mutex */
+ struct super_block *sb;
+ /* Loop until I have taken s_umount on all sysfs superblocks */
+restart:
+ spin_lock(&sb_lock);
+ list_for_each_entry(sb, &sysfs_fs_type.fs_supers, s_instances) {
+ if (sysfs_info(sb)->grabbed)
+ continue;
+ /* Wait for unmount activity to complete. */
+ if (sb->s_count < S_BIAS) {
+ sb->s_count += 1;
+ spin_unlock(&sb_lock);
+ down_read(&sb->s_umount);
+ drop_super(sb);
+ goto restart;
+ }
+ atomic_inc(&sb->s_active);
+ sysfs_info(sb)->grabbed = 1;
+ }
+ spin_unlock(&sb_lock);
+}
+
+void sysfs_release_supers(void)
+{
+ /* must hold sysfs_rename_mutex */
+ struct super_block *sb;
+restart:
+ spin_lock(&sb_lock);
+ list_for_each_entry(sb, &sysfs_fs_type.fs_supers, s_instances) {
+ if (!sysfs_info(sb)->grabbed)
+ continue;
+ sysfs_info(sb)->grabbed = 0;
+ spin_unlock(&sb_lock);
+ deactivate_super(sb);
+ goto restart;
+ }
+ spin_unlock(&sb_lock);
+}
+
int __init sysfs_init(void)
{
int err = -ENOMEM;
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 791b3ed..8156ccb 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -50,8 +50,18 @@ struct sysfs_addrm_cxt {
int cnt;
};
+struct sysfs_super_info {
+ int grabbed;
+};
+
+#define sysfs_info(SB) ((struct sysfs_super_info *)(SB)->s_fs_info)
+
extern struct sysfs_dirent sysfs_root;
extern struct kmem_cache *sysfs_dir_cachep;
+extern struct file_system_type sysfs_fs_type;
+
+void sysfs_grab_supers(void);
+void sysfs_release_supers(void);
extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
--
1.5.1.1.181.g2de0
_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
|
|
|
|
|
[PATCH 0/25] Sysfs cleanups & tagged directory support
By: ebiederm on Tue, 07 August 2007 21:06
|
|
|
[PATCH 01/25] sysfs: Move all of inode initialization into sysfs_init_inode
By: ebiederm on Tue, 07 August 2007 21:08
|
|
|
[PATCH 02/25] sysfs: Remove sysfs_instantiate
By: ebiederm on Tue, 07 August 2007 21:08
|
|
|
[PATCH 03/25] sysfs: Use kill_anon_super
By: ebiederm on Tue, 07 August 2007 21:10
|
|
|
[PATCH 04/25] sysfs: Make sysfs_mount static
By: ebiederm on Tue, 07 August 2007 21:11
|
|
|
[PATCH 05/25] sysfs: In sysfs_lookup don't open code sysfs_find_dirent
By: ebiederm on Tue, 07 August 2007 21:12
|
|
|
[PATCH 06/25] sysfs: Simplify readdir.
By: ebiederm on Tue, 07 August 2007 21:13
|
|
|
[PATCH 07/25] sysfs: Rewrite sysfs_drop_dentry.
By: ebiederm on Tue, 07 August 2007 21:14
|
|
|
[PATCH 08/25] sysfs: Implement __sysfs_get_dentry
By: ebiederm on Tue, 07 August 2007 21:16
|
|
|
[PATCH 09/25] sysfs: Move sysfs_get_dentry below __sysfs_get_dentry
By: ebiederm on Tue, 07 August 2007 21:17
|
|
|
[PATCH 10/25] sysfs: Rewrite sysfs_get_dentry in terms of __sysfs_get_dentry
By: ebiederm on Tue, 07 August 2007 21:18
|
|
|
[PATCH 11/25] sysfs: Remove s_dentry
By: ebiederm on Tue, 07 August 2007 21:19
|
|
|
[PATCH 12/25] sysfs: Introduce sysfs_rename_mutex
By: ebiederm on Tue, 07 August 2007 21:21
|
|
|
[PATCH 13/25] sysfs: Simply sysfs_get_dentry
By: ebiederm on Tue, 07 August 2007 21:22
|
|
|
[PATCH 14/25] sysfs: Don't use lookup_one_len_kern
By: ebiederm on Tue, 07 August 2007 21:23
|
|
|
[PATCH 15/25] vfs: Remove lookup_one_len_kern
By: ebiederm on Tue, 07 August 2007 21:25
|
|
|
[PATCH 16/25] sysfs: Support for preventing unmounts.
By: ebiederm on Tue, 07 August 2007 21:26
|
|
|
[PATCH 17/25] sysfs: Rewrite rename in terms of sysfs dirents
By: ebiederm on Tue, 07 August 2007 21:27
|
|
|
[PATCH 18/25] sysfs: Rewrite sysfs_move_dir in terms of sysfs dirents
By: ebiederm on Tue, 07 August 2007 21:28
|
|
|
[PATCH 19/25] sysfs: sysfs_get_dentry add a sb parameter
By: ebiederm on Tue, 07 August 2007 21:29
|
|
|
[PATCH 20/25] sysfs: Rename Support multiple superblocks
By: ebiederm on Tue, 07 August 2007 21:31
|
|
|
[PATCH 21/25] sysfs: sysfs_chmod_file handle multiple superblocks
By: ebiederm on Tue, 07 August 2007 21:32
|
|
|
[PATCH 22/25] sysfs: sysfs_uptdate_file handle multiple superblocks
By: ebiederm on Tue, 07 August 2007 21:34
|
|
|
[PATCH 23/25] sysfs: Implement sysfs tagged directory support.
By: ebiederm on Tue, 07 August 2007 21:35
|
|
|
[PATCH 24/25] sysfs: Implement sysfs_delete_link and sysfs_rename_link
By: ebiederm on Tue, 07 August 2007 21:36
|
|
|
[PATCH 25/25] driver core: Implement tagged directory support for device classes.
By: ebiederm on Tue, 07 August 2007 21:36
|
|
|
Re: alternative approached at tagged nodes
|
|
|
Re: [PATCH 22/25] sysfs: sysfs_uptdate_file handle multiple superblocks
|
|
|
Re: [PATCH 21/25] sysfs: sysfs_chmod_file handle multiple superblocks
|
|
|
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks
By: ebiederm on Wed, 08 August 2007 15:45
|
|
|
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks
|
|
|
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks
By: ebiederm on Wed, 08 August 2007 16:35
|
|
|
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks
|
|
|
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks
By: ebiederm on Wed, 08 August 2007 16:55
|
|
|
Re: [PATCH 20/25] sysfs: Rename Support multiple superblocks
|
|
|
Re: [PATCH 19/25] sysfs: sysfs_get_dentry add a sb parameter
By: ebiederm on Wed, 08 August 2007 15:34
|
|
|
Re: [PATCH 19/25] sysfs: sysfs_get_dentry add a sb parameter
|
|
|
Re: [PATCH 18/25] sysfs: Rewrite sysfs_move_dir in terms of sysfs dirents
|
|
|
Re: [PATCH 17/25] sysfs: Rewrite rename in terms of sysfs dirents
By: ebiederm on Wed, 08 August 2007 15:32
|
|
|
Re: [PATCH 17/25] sysfs: Rewrite rename in terms of sysfs dirents
|
|
|
Re: [PATCH 15/25] vfs: Remove lookup_one_len_kern
|
|
|
Re: [PATCH 14/25] sysfs: Don't use lookup_one_len_kern
By: ebiederm on Wed, 08 August 2007 15:26
|
|
|
Re: [PATCH 14/25] sysfs: Don't use lookup_one_len_kern
|
|
|
Re: [PATCH 14/25] sysfs: Don't use lookup_one_len_kern
|
|
|
Re: [PATCH 13/25] sysfs: Simply sysfs_get_dentry
|
|
|
Re: [PATCH 12/25] sysfs: Introduce sysfs_rename_mutex
By: ebiederm on Wed, 08 August 2007 08:28
|
|
|
Re: [PATCH 12/25] sysfs: Introduce sysfs_rename_mutex
|
|
|
Re: [PATCH 12/25] sysfs: Introduce sysfs_rename_mutex
|
|
|
Re: [PATCH 11/25] sysfs: Remove s_dentry
|
|
|
Re: [PATCH 10/25] sysfs: Rewrite sysfs_get_dentry in terms of __sysfs_get_dentry
|
|
|
Re: [PATCH 09/25] sysfs: Move sysfs_get_dentry below __sysfs_get_dentry
|
|
|
Re: [PATCH 08/25] sysfs: Implement __sysfs_get_dentry
|
|
|
Re: [PATCH 07/25] sysfs: Rewrite sysfs_drop_dentry.
|
|
|
Re: [PATCH 06/25] sysfs: Simplify readdir.
|
|
|
Re: [PATCH 05/25] sysfs: In sysfs_lookup don't open code sysfs_find_dirent
|
|
|
Re: [PATCH 04/25] sysfs: Make sysfs_mount static
|
|
|
Re: [PATCH 03/25] sysfs: Use kill_anon_super
|
|
|
Re: [PATCH 02/25] sysfs: Remove sysfs_instantiate
|
|
|
Re: [PATCH 01/25] sysfs: Move all of inode initialization into sysfs_init_inode
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
By: ebiederm on Wed, 08 August 2007 07:47
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
By: ebiederm on Wed, 08 August 2007 07:57
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
By: ebiederm on Wed, 08 August 2007 15:08
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
By: ebiederm on Wed, 08 August 2007 15:53
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
By: ebiederm on Wed, 08 August 2007 16:37
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
|
|
Re: [PATCH 0/25] Sysfs cleanups & tagged directory support
|
Goto Forum:
Current Time: Tue Oct 15 13:14:44 GMT 2024
Total time taken to generate the page: 0.04935 seconds
|