From: Sukadev Bhattiprolu <sukadev@xxxxxxxxxx> Subject: [RFC][PATCH 2/6] Remove 'devpts_root' global Remove the 'devpts_root' global variable and find the root dentry using the super_block. The super-block itself is found from the device inode, using a new wrapper, pts_sb_from_inode(). --- fs/devpts/inode.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) Index: linux-2.6.26-rc8-mm1/fs/devpts/inode.c =================================================================== --- linux-2.6.26-rc8-mm1.orig/fs/devpts/inode.c 2008-08-04 02:08:15.000000000 -0700 +++ linux-2.6.26-rc8-mm1/fs/devpts/inode.c 2008-08-04 02:08:43.000000000 -0700 @@ -33,7 +33,14 @@ static DEFINE_IDR(allocated_ptys); static DEFINE_MUTEX(allocated_ptys_lock); static struct vfsmount *devpts_mnt; -static struct dentry *devpts_root; + +static inline struct super_block *pts_sb_from_inode(struct inode *inode) +{ + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) + return inode->i_sb; + + return devpts_mnt->mnt_sb; +} static struct { int setuid; @@ -141,7 +148,7 @@ devpts_fill_super(struct super_block *s, inode->i_fop = &simple_dir_operations; inode->i_nlink = 2; - devpts_root = s->s_root = d_alloc_root(inode); + s->s_root = d_alloc_root(inode); if (s->s_root) return 0; @@ -169,10 +176,9 @@ static struct file_system_type devpts_fs * to the System V naming convention */ -static struct dentry *get_node(int num) +static struct dentry *get_node(struct dentry *root, int num) { char s[12]; - struct dentry *root = devpts_root; mutex_lock(&root->d_inode->i_mutex); return lookup_one_len(s, root, sprintf(s, "%d", num)); } @@ -218,7 +224,9 @@ int devpts_pty_new(struct inode *ptmx_in struct tty_driver *driver = tty->driver; dev_t device = MKDEV(driver->major, driver->minor_start+number); struct dentry *dentry; - struct inode *inode = new_inode(devpts_mnt->mnt_sb); + struct super_block *sb = pts_sb_from_inode(ptmx_inode); + struct inode *inode = new_inode(sb); + struct dentry *root = sb->s_root; /* We're supposed to be given the slave end of a pty */ BUG_ON(driver->type != TTY_DRIVER_TYPE_PTY); @@ -234,20 +242,22 @@ int devpts_pty_new(struct inode *ptmx_in init_special_inode(inode, S_IFCHR|config.mode, device); inode->i_private = tty; - dentry = get_node(number); + dentry = get_node(root, number); if (!IS_ERR(dentry) && !dentry->d_inode) { d_instantiate(dentry, inode); - fsnotify_create(devpts_root->d_inode, dentry); + fsnotify_create(root->d_inode, dentry); } - mutex_unlock(&devpts_root->d_inode->i_mutex); + mutex_unlock(&root->d_inode->i_mutex); return 0; } struct tty_struct *devpts_get_tty(struct inode *inode, int number) { - struct dentry *dentry = get_node(number); + struct super_block *sb = pts_sb_from_inode(inode); + struct dentry *root = sb->s_root; + struct dentry *dentry = get_node(root, number); struct tty_struct *tty; tty = NULL; @@ -257,14 +267,16 @@ struct tty_struct *devpts_get_tty(struct dput(dentry); } - mutex_unlock(&devpts_root->d_inode->i_mutex); + mutex_unlock(&root->d_inode->i_mutex); return tty; } void devpts_pty_kill(struct inode *inode, int number) { - struct dentry *dentry = get_node(number); + struct super_block *sb = pts_sb_from_inode(inode); + struct dentry *root = sb->s_root; + struct dentry *dentry = get_node(root, number); if (!IS_ERR(dentry)) { struct inode *inode = dentry->d_inode; @@ -275,7 +287,7 @@ void devpts_pty_kill(struct inode *inode } dput(dentry); } - mutex_unlock(&devpts_root->d_inode->i_mutex); + mutex_unlock(&root->d_inode->i_mutex); } static int __init init_devpts_fs(void) _______________________________________________ Containers mailing list Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linux-foundation.org/mailman/listinfo/containers