linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ram <linuxram@us.ibm.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Andrew Morton <akpm@osdl.org>,
	viro@parcelfarce.linux.theplanet.co.uk, jamie@shareable.org
Subject: Re: [RFC][PATCH] rbind across namespaces
Date: Sun, 22 May 2005 13:25:54 -0700	[thread overview]
Message-ID: <1116793554.4397.102.camel@localhost> (raw)
In-Reply-To: <E1DZTmi-0006up-00@dorka.pomaz.szeredi.hu>

[-- Attachment #1: Type: text/plain, Size: 1184 bytes --]

On Sat, 2005-05-21 at 06:12, Miklos Szeredi wrote:
> > Ok. look at the enclosed patch. Does it look any better? The special
> > casing for detached mounts ate up some brain cells and made the code
> > less simpler.
> 
> Yes, this isn't trivial stuff.
> 
> I realized one more thing: nd->mnt (the destination vfsmount) might be
> detached while waiting for the semaphore.  So that needs to be
> rechecked after taking the semaphores.

Ok. fixed that. that was surprisingly trivial though initially it looked
like some complex locking.

> 
> And the same for old_nd->mnt in case of rbind.  Though I'm
> not sure what the semantics should be in this case:
> 
>   1) rbind always fails if the source is detached
>   2) rbind always succeeds, and if the source is detached it just
>      copies that single mount

> I like 2) better.  Is there anything against it?

sure. as much functionality as we can get. I have incorporated (2).

Take a look at the enclosed patch,
RP
> 
> Miklos
> -
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[-- Attachment #2: rbind_across_namespace3.patch --]
[-- Type: text/x-patch, Size: 2589 bytes --]

--- /home/linux/views/linux-2.6.12-rc4/fs/namespace.c	2005-05-06 23:22:29.000000000 -0700
+++ linux-2.6.12-rc4/fs/namespace.c	2005-05-22 13:22:46.000000000 -0700
@@ -616,11 +616,14 @@ out_unlock:
 }
 
 /*
- * do loopback mount.
+ * do loopback mount.  The loopback mount can be done from any namespace
+ * to any other namespace including the current namespace, as long as
+ * the task acquired rights to manipulate them.
  */
 static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
 {
 	struct nameidata old_nd;
+	struct namespace *mntpt_ns, *old_ns;
 	struct vfsmount *mnt = NULL;
 	int err = mount_is_safe(nd);
 	if (err)
@@ -631,15 +634,54 @@ static int do_loopback(struct nameidata 
 	if (err)
 		return err;
 
-	down_write(&current->namespace->sem);
 	err = -EINVAL;
-	if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) {
-		err = -ENOMEM;
-		if (recurse)
-			mnt = copy_tree(old_nd.mnt, old_nd.dentry);
-		else
-			mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
+	spin_lock(&vfsmount_lock);
+
+	/* 
+	 * Allow all kinds of binds and rbinds except
+	 * recursive bind to a detached mount
+	 */
+	mntpt_ns = nd->mnt->mnt_namespace;
+	old_ns = old_nd.mnt->mnt_namespace;
+	if (!mntpt_ns || !mntpt_ns->root || 
+		(recurse && (!old_ns || !old_ns->root))) {
+		spin_unlock(&vfsmount_lock);
+		goto out;
 	}
+	get_namespace(mntpt_ns);
+	if (recurse && old_ns != mntpt_ns)
+		get_namespace(old_ns);
+
+	spin_unlock(&vfsmount_lock);
+
+	/* 
+	 * make sure we don't race with some other thread manipulating the
+	 * namespaces.
+	 */
+	if (recurse && (old_ns < mntpt_ns))
+		down_write(&old_ns->sem);
+	down_write(&mntpt_ns->sem);
+	if (recurse && (old_ns > mntpt_ns))
+		down_write(&old_ns->sem);
+
+
+	/* 
+	 * well... mounts might have detached while we acquired
+	 * the semaphores. Revalidate that the destination mount 
+	 * is still attached. 
+	 */
+	if (!nd->mnt->mnt_namespace)
+		goto error_out;
+
+	/* 
+	 * and if the source mount is detached, than just do
+	 * a bind, instead of a rbind
+	 */
+	err = -ENOMEM;
+	if (recurse && old_nd.mnt->mnt_namespace)
+		mnt = copy_tree(old_nd.mnt, old_nd.dentry);
+	else
+		mnt = clone_mnt(old_nd.mnt, old_nd.dentry);
 
 	if (mnt) {
 		/* stop bind mounts from expiring */
@@ -656,7 +698,15 @@ static int do_loopback(struct nameidata 
 			mntput(mnt);
 	}
 
-	up_write(&current->namespace->sem);
+error_out:
+	up_write(&mntpt_ns->sem);
+	if (recurse && (old_ns != mntpt_ns)) {
+		up_write(&old_ns->sem);
+		put_namespace(old_ns);
+	}
+	put_namespace(mntpt_ns);
+
+out:
 	path_release(&old_nd);
 	return err;
 }

  reply	other threads:[~2005-05-22 20:26 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-20 22:11 [RFC][PATCH] rbind across namespaces Ram
2005-05-21  6:27 ` Miklos Szeredi
2005-05-21  7:26   ` Ram
2005-05-21  8:09     ` Miklos Szeredi
2005-05-21  8:45       ` Ram
2005-05-21  9:09         ` Miklos Szeredi
2005-05-21 10:07           ` Ram
2005-05-21 13:12             ` Miklos Szeredi
2005-05-22 20:25               ` Ram [this message]
2005-05-22 20:51                 ` Ram
2005-05-23  5:08                   ` Miklos Szeredi
2005-05-23  7:24                     ` Ram
2005-05-23  8:24                       ` Miklos Szeredi
2005-05-21  9:48         ` Miklos Szeredi
2005-05-21 13:46       ` Jamie Lokier
2005-05-22  8:08         ` Miklos Szeredi
2005-05-22 17:04           ` [RFC][PATCH] /proc/dead_mounts support (Was: [RFC][PATCH] rbind across ...) Miklos Szeredi
2005-05-22 21:10           ` [RFC][PATCH] rbind across namespaces Ram
2005-05-23  5:07             ` Miklos Szeredi
2005-05-24  0:39           ` Mike Waychison
2005-05-24  5:43             ` Miklos Szeredi
2005-05-24  7:13               ` Mike Waychison
2005-05-24  8:25                 ` Miklos Szeredi
2005-05-24 17:09                   ` Mike Waychison
2005-05-24 17:31                     ` Miklos Szeredi
2005-05-24 17:44                       ` Mike Waychison
2005-05-24 17:56                         ` Miklos Szeredi
2005-05-24 18:04                           ` Mike Waychison
2005-05-30 19:06                             ` Ram
2005-05-24  9:18                 ` Miklos Szeredi
2005-05-24 17:15                   ` Mike Waychison
2005-05-24 17:46                     ` Miklos Szeredi
2005-05-24 18:15                     ` Jamie Lokier
2005-05-24 18:33                       ` Mike Waychison
2005-05-24 21:51                         ` Jamie Lokier
2005-05-21 13:43     ` Jamie Lokier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1116793554.4397.102.camel@localhost \
    --to=linuxram@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=jamie@shareable.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).