[Devel] [PATCH 1/4] procfs: proc_get_sb: consolidate/cleanup root_inode->pid logic

Oleg Nesterov oleg at redhat.com
Sat Jun 19 12:09:26 PDT 2010


Depending on whether it is called by the init_pid_ns or not, proc_get_sb()
does different things to initialize PROC_I(s_root->d_inode)->pid, and both
look ugly, imho.

- init_pid_ns tries to initialize ->pid every time proc_get_sb() is
  called, and we check the global proc_mnt != NULL to ensure proc_get_sb()
  was already called in the past and thus it is safe to use sb->s_root.

- sub-namespaces set ->pid at MS_KERNMOUNT stage and thus proc_get_sb()
  can'be called before the first alloc_pid() in copy_process(), ugly.

Consolidate this code, and initialize PROC_I(s_root->d_inode)->pid when
the proc fs is actually mounted (MS_KERNMOUNT is not set). This also
allows us to do more cleanups.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---

 fs/proc/root.c |   23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

--- 35-rc3/fs/proc/root.c~PNS_1_PROC_GET_SB_ROOT_PID	2010-06-19 19:20:23.000000000 +0200
+++ 35-rc3/fs/proc/root.c	2010-06-19 19:21:38.000000000 +0200
@@ -41,18 +41,6 @@ static int proc_get_sb(struct file_syste
 	int err;
 	struct super_block *sb;
 	struct pid_namespace *ns;
-	struct proc_inode *ei;
-
-	if (proc_mnt) {
-		/* Seed the root directory with a pid so it doesn't need
-		 * to be special in base.c.  I would do this earlier but
-		 * the only task alive when /proc is mounted the first time
-		 * is the init_task and it doesn't have any pids.
-		 */
-		ei = PROC_I(proc_mnt->mnt_sb->s_root->d_inode);
-		if (!ei->pid)
-			ei->pid = find_get_pid(1);
-	}
 
 	if (flags & MS_KERNMOUNT)
 		ns = (struct pid_namespace *)data;
@@ -71,15 +59,18 @@ static int proc_get_sb(struct file_syste
 			return err;
 		}
 
-		ei = PROC_I(sb->s_root->d_inode);
+		sb->s_flags |= MS_ACTIVE;
+		ns->proc_mnt = mnt;
+	}
+
+	/* MS_KERNMOUNT is called before ns has any pids */
+	if (!(flags & MS_KERNMOUNT)) {
+		struct proc_inode *ei = PROC_I(sb->s_root->d_inode);
 		if (!ei->pid) {
 			rcu_read_lock();
 			ei->pid = get_pid(find_pid_ns(1, ns));
 			rcu_read_unlock();
 		}
-
-		sb->s_flags |= MS_ACTIVE;
-		ns->proc_mnt = mnt;
 	}
 
 	simple_set_mnt(mnt, sb);

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list