Skip to content

Commit

Permalink
sysfs, kernfs: introduce sysfs_root_sd
Browse files Browse the repository at this point in the history
Currently, it's assumed that there's a single kernfs hierarchy in the
system anchored at sysfs_root which is defined as a global struct.  To
allow other users of kernfs, this will be made dynamic.  Introduce a
new global variable sysfs_root_sd which points to &sysfs_root and
convert all &sysfs_root users.

This patch doesn't introduce any behavior difference.

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
htejun authored and gregkh committed Nov 30, 2013
1 parent 9e30cc9 commit 061447a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions fs/sysfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
if (kobj->parent)
parent_sd = kobj->parent->sd;
else
parent_sd = &sysfs_root;
parent_sd = sysfs_root_sd;

if (!parent_sd)
return -ENOENT;
Expand Down Expand Up @@ -134,7 +134,7 @@ int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,

BUG_ON(!sd->s_parent);
new_parent_sd = new_parent_kobj && new_parent_kobj->sd ?
new_parent_kobj->sd : &sysfs_root;
new_parent_kobj->sd : sysfs_root_sd;

return kernfs_rename_ns(sd, new_parent_sd, sd->s_name, new_ns);
}
8 changes: 5 additions & 3 deletions fs/sysfs/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ static const struct super_operations sysfs_ops = {
.evict_inode = sysfs_evict_inode,
};

struct sysfs_dirent sysfs_root = {
static struct sysfs_dirent sysfs_root = {
.s_name = "",
.s_count = ATOMIC_INIT(1),
.s_flags = SYSFS_DIR,
.s_mode = S_IFDIR | S_IRUGO | S_IXUGO,
.s_ino = 1,
};

struct sysfs_dirent *sysfs_root_sd = &sysfs_root;

static int sysfs_fill_super(struct super_block *sb)
{
struct inode *inode;
Expand All @@ -53,7 +55,7 @@ static int sysfs_fill_super(struct super_block *sb)

/* get root inode, initialize and unlock it */
mutex_lock(&sysfs_mutex);
inode = sysfs_get_inode(sb, &sysfs_root);
inode = sysfs_get_inode(sb, sysfs_root_sd);
mutex_unlock(&sysfs_mutex);
if (!inode) {
pr_debug("sysfs: could not get root inode\n");
Expand All @@ -66,7 +68,7 @@ static int sysfs_fill_super(struct super_block *sb)
pr_debug("%s: could not get root dentry!\n", __func__);
return -ENOMEM;
}
root->d_fsdata = &sysfs_root;
root->d_fsdata = sysfs_root_sd;
sb->s_root = root;
sb->s_d_op = &sysfs_dentry_ops;
return 0;
Expand Down
6 changes: 3 additions & 3 deletions fs/sysfs/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
struct sysfs_dirent *parent_sd = NULL;

if (!kobj)
parent_sd = &sysfs_root;
parent_sd = sysfs_root_sd;
else
parent_sd = kobj->sd;

Expand Down Expand Up @@ -144,7 +144,7 @@ void sysfs_remove_link(struct kobject *kobj, const char *name)
struct sysfs_dirent *parent_sd = NULL;

if (!kobj)
parent_sd = &sysfs_root;
parent_sd = sysfs_root_sd;
else
parent_sd = kobj->sd;

Expand All @@ -170,7 +170,7 @@ int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
int result;

if (!kobj)
parent_sd = &sysfs_root;
parent_sd = sysfs_root_sd;
else
parent_sd = kobj->sd;

Expand Down
2 changes: 1 addition & 1 deletion fs/sysfs/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct sysfs_super_info {
const void *ns;
};
#define sysfs_info(SB) ((struct sysfs_super_info *)(SB->s_fs_info))
extern struct sysfs_dirent sysfs_root;
extern struct sysfs_dirent *sysfs_root_sd;
extern struct kmem_cache *sysfs_dir_cachep;

/*
Expand Down

0 comments on commit 061447a

Please sign in to comment.