linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH 6/8] namespace: use mnt_base for proc
@ 2005-05-30 13:32 Miklos Szeredi
  2005-05-30 19:54 ` Mike Waychison
  0 siblings, 1 reply; 3+ messages in thread
From: Miklos Szeredi @ 2005-05-30 13:32 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: mike, jamie, viro

This patch makes /proc/PID/mounts use fs->rootmnt->mnt_base instead of
namespace->root.  This means, that if a process changes it's root to a
different namespace, or a detached subtree, the base of that tree will
be used, instead of the process's namespace.

Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>

Index: linux/fs/namespace.c
===================================================================
--- linux.orig/fs/namespace.c	2005-05-29 17:15:56.000000000 +0200
+++ linux/fs/namespace.c	2005-05-29 17:20:32.000000000 +0200
@@ -242,8 +242,7 @@ static void destroy_vfsmnt(struct vfsmou
 /* iterator */
 static void *m_start(struct seq_file *m, loff_t *pos)
 {
-	struct namespace *n = m->private;
-	struct vfsmount *mnt = n->root;
+	struct vfsmount *mnt = m->private;
 	struct vfsmount *p;
 	loff_t l = *pos;
 
@@ -256,8 +255,7 @@ static void *m_start(struct seq_file *m,
 
 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
 {
-	struct namespace *n = m->private;
-	struct vfsmount *mnt = n->root;
+	struct vfsmount *mnt = m->private;
 	struct vfsmount *p = v;
 	(*pos)++;
 	return next_mnt(p, mnt);
Index: linux/include/linux/mount.h
===================================================================
--- linux.orig/include/linux/mount.h	2005-05-29 16:55:56.000000000 +0200
+++ linux/include/linux/mount.h	2005-05-29 17:25:53.000000000 +0200
@@ -51,6 +51,18 @@ static inline struct vfsmount *mntget(st
 	return mnt;
 }
 
+static inline struct vfsmount *mntget_base(struct vfsmount *mnt)
+{
+	if (mnt) {
+		read_lock(&vfsmountref_lock);
+		mnt = mnt->mnt_base;
+		atomic_inc(&mnt->mnt_count);
+		atomic_inc(&mnt->mnt_group_count);
+		read_unlock(&vfsmountref_lock);
+	}
+	return mnt;
+}
+
 extern void destroy_mount_group(struct vfsmount *mnt);
 
 static inline void mntput_no_expire(struct vfsmount *mnt)
Index: linux/fs/proc/base.c
===================================================================
--- linux.orig/fs/proc/base.c	2005-05-29 17:18:40.000000000 +0200
+++ linux/fs/proc/base.c	2005-05-29 17:27:14.000000000 +0200
@@ -581,16 +581,13 @@ static int mounts_open(struct inode *ino
 
 	if (!ret) {
 		struct seq_file *m = file->private_data;
-		struct namespace *namespace;
-		task_lock(task);
-		namespace = task->namespace;
-		if (namespace)
-			get_namespace(namespace);
-		task_unlock(task);
-
-		if (namespace)
-			m->private = namespace;
-		else {
+		struct fs_struct *fs = get_fs_struct(task);
+		if (fs) {
+			read_lock(&fs->lock);
+			m->private = mntget_base(fs->rootmnt);
+			read_unlock(&fs->lock);
+			put_fs_struct(fs);
+		} else {
 			seq_release(inode, file);
 			ret = -EINVAL;
 		}
@@ -601,8 +598,8 @@ static int mounts_open(struct inode *ino
 static int mounts_release(struct inode *inode, struct file *file)
 {
 	struct seq_file *m = file->private_data;
-	struct namespace *namespace = m->private;
-	put_namespace(namespace);
+	struct vfsmount *mnt = m->private;
+	mntput(mnt);
 	return seq_release(inode, file);
 }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH 6/8] namespace: use mnt_base for proc
  2005-05-30 13:32 [RFC][PATCH 6/8] namespace: use mnt_base for proc Miklos Szeredi
@ 2005-05-30 19:54 ` Mike Waychison
  2005-05-31  5:58   ` Miklos Szeredi
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Waychison @ 2005-05-30 19:54 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-fsdevel, jamie, viro

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Miklos Szeredi wrote:
> This patch makes /proc/PID/mounts use fs->rootmnt->mnt_base instead of
> namespace->root.  This means, that if a process changes it's root to a
> different namespace, or a detached subtree, the base of that tree will
> be used, instead of the process's namespace.
> 

We are going to want to block out any modifications of the tree between
start and stop.  This should be possible by grabbing a read lock on
vfsmountref_lock IIRC.

> Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
> 
> Index: linux/fs/namespace.c
> ===================================================================
> --- linux.orig/fs/namespace.c	2005-05-29 17:15:56.000000000 +0200
> +++ linux/fs/namespace.c	2005-05-29 17:20:32.000000000 +0200
> @@ -242,8 +242,7 @@ static void destroy_vfsmnt(struct vfsmou
>  /* iterator */
>  static void *m_start(struct seq_file *m, loff_t *pos)
>  {
> -	struct namespace *n = m->private;
> -	struct vfsmount *mnt = n->root;
> +	struct vfsmount *mnt = m->private;
>  	struct vfsmount *p;
>  	loff_t l = *pos;
>  
> @@ -256,8 +255,7 @@ static void *m_start(struct seq_file *m,
>  
>  static void *m_next(struct seq_file *m, void *v, loff_t *pos)
>  {
> -	struct namespace *n = m->private;
> -	struct vfsmount *mnt = n->root;
> +	struct vfsmount *mnt = m->private;
>  	struct vfsmount *p = v;
>  	(*pos)++;
>  	return next_mnt(p, mnt);
> Index: linux/include/linux/mount.h
> ===================================================================
> --- linux.orig/include/linux/mount.h	2005-05-29 16:55:56.000000000 +0200
> +++ linux/include/linux/mount.h	2005-05-29 17:25:53.000000000 +0200
> @@ -51,6 +51,18 @@ static inline struct vfsmount *mntget(st
>  	return mnt;
>  }
>  
> +static inline struct vfsmount *mntget_base(struct vfsmount *mnt)
> +{
> +	if (mnt) {
> +		read_lock(&vfsmountref_lock);
> +		mnt = mnt->mnt_base;
> +		atomic_inc(&mnt->mnt_count);
> +		atomic_inc(&mnt->mnt_group_count);
> +		read_unlock(&vfsmountref_lock);
> +	}
> +	return mnt;
> +}
> +
>  extern void destroy_mount_group(struct vfsmount *mnt);
>  
>  static inline void mntput_no_expire(struct vfsmount *mnt)
> Index: linux/fs/proc/base.c
> ===================================================================
> --- linux.orig/fs/proc/base.c	2005-05-29 17:18:40.000000000 +0200
> +++ linux/fs/proc/base.c	2005-05-29 17:27:14.000000000 +0200
> @@ -581,16 +581,13 @@ static int mounts_open(struct inode *ino
>  
>  	if (!ret) {
>  		struct seq_file *m = file->private_data;
> -		struct namespace *namespace;
> -		task_lock(task);
> -		namespace = task->namespace;
> -		if (namespace)
> -			get_namespace(namespace);
> -		task_unlock(task);
> -
> -		if (namespace)
> -			m->private = namespace;
> -		else {
> +		struct fs_struct *fs = get_fs_struct(task);
> +		if (fs) {
> +			read_lock(&fs->lock);
> +			m->private = mntget_base(fs->rootmnt);
> +			read_unlock(&fs->lock);
> +			put_fs_struct(fs);
> +		} else {
>  			seq_release(inode, file);
>  			ret = -EINVAL;
>  		}
> @@ -601,8 +598,8 @@ static int mounts_open(struct inode *ino
>  static int mounts_release(struct inode *inode, struct file *file)
>  {
>  	struct seq_file *m = file->private_data;
> -	struct namespace *namespace = m->private;
> -	put_namespace(namespace);
> +	struct vfsmount *mnt = m->private;
> +	mntput(mnt);
>  	return seq_release(inode, file);
>  }
>  

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCm29jdQs4kOxk3/MRAh82AJ9KkQ1ZSaXBXICKVmwXIqybmOvlNACfdkc1
BhAJt+HydEmWeYHQkt1Uc3Y=
=+YA1
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH 6/8] namespace: use mnt_base for proc
  2005-05-30 19:54 ` Mike Waychison
@ 2005-05-31  5:58   ` Miklos Szeredi
  0 siblings, 0 replies; 3+ messages in thread
From: Miklos Szeredi @ 2005-05-31  5:58 UTC (permalink / raw)
  To: mike; +Cc: linux-fsdevel, jamie, viro

> We are going to want to block out any modifications of the tree between
> start and stop.  This should be possible by grabbing a read lock on
> vfsmountref_lock IIRC.

It's now protected by namespace_sem.  There's some overlap between
vfsmount_lock, vfsmountref_lock and namespace_sem.  All of them are
held when modifying the tree.

Do you have an idea on how to consolidate the three locks?

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-05-31  5:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-30 13:32 [RFC][PATCH 6/8] namespace: use mnt_base for proc Miklos Szeredi
2005-05-30 19:54 ` Mike Waychison
2005-05-31  5:58   ` Miklos Szeredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).