Fix __d_path for lazy unmounts
PATCH 1/1 Fix __d_path for lazy unmounts
From: John Johansen <[email protected]>
When __d_path() hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.
--- fs/dcache.c | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-)
fs/dcache.c +23 -4
@@ -1922,11 +1922,9 @@ char *__d_path(const struct path *path, struct path *root, retval = end-1 ; *retval ='/' ; -for (;;) { +while (dentry != root->dentry || vfsmnt != root->mnt) {struct dentry * parent; -if (dentry == root->dentry && vfsmnt == root->mnt) -break ;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) {/* Global root? */ if (vfsmnt->mnt_parent == vfsmnt) {
@@ -1950,9 +1948,30 @@ out:return retval; global_root: - retval +=1 ;/* hit the slash */ +/* +* We went past the (vfsmount, dentry) we were looking for and have +* either hit a root dentry, a lazily unmounted dentry, an +* unconnected dentry, or the file is on a pseudo filesystem. +*/ +if ((dentry->d_sb->s_flags &MS_NOUSER ) || + (dentry->d_name.len =1 && *dentry->d_name.name =='/' )) { +/* +* Historically, we also glue together the root dentry and +* remaining name for pseudo filesystems like pipefs, which +* have the MS_NOUSER flag set. This results in pathnames +* like "pipe:[439336]". +*/ + retval +=1 ;/* overwrite the slash */ + buflen++; + }if (prepend_name (&retval, &buflen, &dentry->d_name) !=0 ) goto Elong; + +/* connect lazily unmounted mount point */ +if (*retval !='/' && !(dentry->d_sb->s_flags &MS_NOUSER ) && +prepend (&retval, &buflen,"/" ,1 ) !=0 ) + goto Elong; + root->mnt = vfsmnt; root->dentry = dentry; goto out;
Signature · 1 line
1.6.6.1
Quoted 9 lines · [email protected] wrote:
From: John Johansen <[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.
It seems I left out the basic test for this. From a shell you can do
Quoted 4 lines
mkdir
/tmp/foo
sudo mount --bind/home/jj/tmp/foo#substitute/home/jjas you wish
cd/tmp/foo/bar# assumes/home/jj/barexists/bin/pwd
/tmp/foo/bar
Quoted 2 lines
sudo umount -l
/tmp/foo/bin/pwd
jjbar
Quoted 2 lines
Quoted 2 lines
cd ..
/bin/pwd
jj
Quoted 10 lines · Quoting [email protected] ([email protected]):
From: John Johansen <[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.Signed-off-by John Johansen <[email protected]>
In particular, I tested for closed pipes and lazily umounted mounts and binds - lazily umounted binds are fixed, and no apparent regression in the others.
Thanks, John.
-serge
Quoted 60 lines
--- fs/dcache.c | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-)fs/dcache.c +23
-4@@ -1922,11 +1922,9 @@ char *__d_path(const struct path *path, struct path *root, retval = end-1 ; *retval ='/' ; -for (;;) { +while (dentry != root->dentry || vfsmnt != root->mnt) {struct dentry * parent; -if (dentry == root->dentry && vfsmnt == root->mnt) -break ;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) {/* Global root? */ if (vfsmnt->mnt_parent == vfsmnt) {@@ -1950,9 +1948,30 @@ out:return retval; global_root: - retval +=1 ;/* hit the slash */ +/* +* We went past the (vfsmount, dentry) we were looking for and have +* either hit a root dentry, a lazily unmounted dentry, an +* unconnected dentry, or the file is on a pseudo filesystem. +*/ +if ((dentry->d_sb->s_flags &MS_NOUSER ) || + (dentry->d_name.len =1 && *dentry->d_name.name =='/' )) { +/* +* Historically, we also glue together the root dentry and +* remaining name for pseudo filesystems like pipefs, which +* have the MS_NOUSER flag set. This results in pathnames +* like "pipe:[439336]". +*/ + retval +=1 ;/* overwrite the slash */ + buflen++; + }if (prepend_name (&retval, &buflen, &dentry->d_name) !=0 ) goto Elong; + +/* connect lazily unmounted mount point */ +if (*retval !='/' && !(dentry->d_sb->s_flags &MS_NOUSER ) && +prepend (&retval, &buflen,"/" ,1 ) !=0 ) + goto Elong; + root->mnt = vfsmnt; root->dentry = dentry; goto out;Signature · 6 lines
1.6.6.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 19 lines · On Sat, 20 Feb 2010 04:27:38 -0800 [email protected] wrote:
From: John Johansen <[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.Signed-off-by John Johansen <[email protected]>--- fs/dcache.c | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-)fs/dcache.c +0
-0
fs/dcache.c char *__d_path(const struct path *path, struct path *root, · line 1925
Quoted 5 lines
fs/dcache.c +1
-1@@ -1922,11 +1922,9 @@ char *__d_path(const struct path *path, struct path *root, retval = end-1 ; *retval ='/' ; -for (;;) { +while (dentry != root->dentry || vfsmnt != root->mnt) {
Please put a space between the while' and the ('.
Quoted 9 lines
fs/dcache.c +0
-2struct dentry * parent; -if (dentry == root->dentry && vfsmnt == root->mnt) -break ;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) {/* Global root? */ if (vfsmnt->mnt_parent == vfsmnt) {@@ -1950,9 +1948,30 @@ out:return retval;
fs/dcache.c out: · line 1957
Quoted 10 lines
fs/dcache.c +7
-1global_root: - retval +=1 ;/* hit the slash */ +/* +* We went past the (vfsmount, dentry) we were looking for and have +* either hit a root dentry, a lazily unmounted dentry, an +* unconnected dentry, or the file is on a pseudo filesystem. +*/ +if ((dentry->d_sb->s_flags &MS_NOUSER ) || + (dentry->d_name.len =1 && *dentry->d_name.name =='/' )) {
Did you really mean to assign 1 to dentry->d_name.len here? Was `==' intended? I hope so, because modifying the dentry in d_path() would be odd.
If this was a mistake then why did the patch pass testing?
Quoted 20 lines
fs/dcache.c +15
-0+/* +* Historically, we also glue together the root dentry and +* remaining name for pseudo filesystems like pipefs, which +* have the MS_NOUSER flag set. This results in pathnames +* like "pipe:[439336]". +*/ + retval +=1 ;/* overwrite the slash */ + buflen++; + }if (prepend_name (&retval, &buflen, &dentry->d_name) !=0 ) goto Elong; + +/* connect lazily unmounted mount point */ +if (*retval !='/' && !(dentry->d_sb->s_flags &MS_NOUSER ) && +prepend (&retval, &buflen,"/" ,1 ) !=0 ) + goto Elong; + root->mnt = vfsmnt; root->dentry = dentry; goto out;
Quoted 52 lines · Andrew Morton
Quoted 19 lines · On Sat, 20 Feb 2010 04:27:38 -0800 [email protected] wrote:
From: John Johansen <[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.Signed-off-by John Johansen <[email protected]>--- fs/dcache.c | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-)fs/dcache.c +0
-0fs/dcache.c char *__d_path(const struct path *path, struct path *root, · line 1925
Quoted 5 lines
fs/dcache.c +1
-1@@ -1922,11 +1922,9 @@ char *__d_path(const struct path *path, struct path *root, retval = end-1 ; *retval ='/' ; -for (;;) { +while (dentry != root->dentry || vfsmnt != root->mnt) {Please put a space between the
while' and the('.Quoted 9 lines
fs/dcache.c +0
-2struct dentry * parent; -if (dentry == root->dentry && vfsmnt == root->mnt) -break ;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) {/* Global root? */ if (vfsmnt->mnt_parent == vfsmnt) {@@ -1950,9 +1948,30 @@ out:return retval;fs/dcache.c out: · line 1957
Quoted 10 lines
fs/dcache.c +7
-1global_root: - retval +=1 ;/* hit the slash */ +/* +* We went past the (vfsmount, dentry) we were looking for and have +* either hit a root dentry, a lazily unmounted dentry, an +* unconnected dentry, or the file is on a pseudo filesystem. +*/ +if ((dentry->d_sb->s_flags &MS_NOUSER ) || + (dentry->d_name.len =1 && *dentry->d_name.name =='/' )) {Did you really mean to assign 1 to
dentry->d_name.lenhere? Was `==' intended? I hope so, because modifying the dentry ind_path()would be odd.
Quoted 1 line
If this was a mistake then why did the patch pass testing?
Jinkeys! Well I guess it must've passed testing bc that will only be done for MS_NOUSER filesystems, and we won't later be doing any 'ls' so the d_name.len isn't really used?
Quoted 25 lines
Quoted 10 lines
fs/dcache.c +9
-0+/* +* Historically, we also glue together the root dentry and +* remaining name for pseudo filesystems like pipefs, which +* have the MS_NOUSER flag set. This results in pathnames +* like "pipe:[439336]". +*/ + retval +=1 ;/* overwrite the slash */ + buflen++; + }if (prepend_name (&retval, &buflen, &dentry->d_name) !=0 )fs/dcache.c out: · line 1977
Quoted 10 lines
fs/dcache.c +6
-0goto Elong; + +/* connect lazily unmounted mount point */ +if (*retval !='/' && !(dentry->d_sb->s_flags &MS_NOUSER ) && +prepend (&retval, &buflen,"/" ,1 ) !=0 ) + goto Elong; + root->mnt = vfsmnt; root->dentry = dentry; goto out;--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
cover Fix __d_path for lazy unmounts v2
Second iteration of the __d_path patch
Fixes
* formating problem - while(dentry
* the assignment where comparison should be used
Tests to exercise the behavior and test for regressions follows
---
#!/bin/bash
#simple script to test behavior of lazily unmounted bind mount
DIR1=mktemp -d /tmp/foo.XXXXXXXXXX
DIR2=mktemp -d /tmp/test.XXXXXXXXXX
mkdir "$DIR2/bar"
mount --bind "$DIR2" "$DIR1"
cd "$DIR1/bar"
echo "Before umount -l"/bin/pwd
umount -l "$DIR1"
echo "After umount -l"/bin/pwd
echo "After cd .."
cd ../bin/pwd
rm -rf "$DIR1" "$DIR2"
PATCH 1/1 Fix __d_path for lazy unmounts
In reply to Serge E. HallynFrom: John Johansen <[email protected]>
When __d_path() hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.
--- fs/dcache.c | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-)
fs/dcache.c +23 -4
@@ -1922,11 +1922,9 @@ char *__d_path(const struct path *path, struct path *root, retval = end-1 ; *retval ='/' ; -for (;;) { +while (dentry != root->dentry || vfsmnt != root->mnt) {struct dentry * parent; -if (dentry == root->dentry && vfsmnt == root->mnt) -break ;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) {/* Global root? */ if (vfsmnt->mnt_parent == vfsmnt) {
@@ -1950,9 +1948,30 @@ out:return retval; global_root: - retval +=1 ;/* hit the slash */ +/* +* We went past the (vfsmount, dentry) we were looking for and have +* either hit a root dentry, a lazily unmounted dentry, an +* unconnected dentry, or the file is on a pseudo filesystem. +*/ +if ((dentry->d_sb->s_flags &MS_NOUSER ) || + (dentry->d_name.len ==1 && *dentry->d_name.name =='/' )) { +/* +* Historically, we also glue together the root dentry and +* remaining name for pseudo filesystems like pipefs, which +* have the MS_NOUSER flag set. This results in pathnames +* like "pipe:[439336]". +*/ + retval +=1 ;/* overwrite the slash */ + buflen++; + }if (prepend_name (&retval, &buflen, &dentry->d_name) !=0 ) goto Elong; + +/* connect lazily unmounted mount point */ +if (*retval !='/' && !(dentry->d_sb->s_flags &MS_NOUSER ) && +prepend (&retval, &buflen,"/" ,1 ) !=0 ) + goto Elong; + root->mnt = vfsmnt; root->dentry = dentry; goto out;
Signature · 1 line
1.6.6.1
Quoted 24 lines · Andrew Morton
Quoted 22 lines · On Sat, 20 Feb 2010 04:27:38 -0800 [email protected] wrote:
From: John Johansen <[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.Signed-off-by John Johansen <[email protected]>--- fs/dcache.c | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-)fs/dcache.c +0
-0@@ -1922,11 +1922,9 @@ char *__d_path(const struct path *path, struct path *root, retval = end-1 ; *retval ='/' ;
Quoted 3 lines
fs/dcache.c char *__d_path(const struct path *path, struct path *root, · line 1925
Quoted 2 lines
fs/dcache.c +1
-1-for (;;) { +while (dentry != root->dentry || vfsmnt != root->mnt) {
thanks, forgot to refresh after checkpatch
Quoted 25 lines
Please put a space between the
while' and the('.Quoted 9 lines
fs/dcache.c +0
-2struct dentry * parent; -if (dentry == root->dentry && vfsmnt == root->mnt) -break ;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) {/* Global root? */ if (vfsmnt->mnt_parent == vfsmnt) {@@ -1950,9 +1948,30 @@ out:return retval;fs/dcache.c out: · line 1957
Quoted 10 lines
fs/dcache.c +7
-1global_root: - retval +=1 ;/* hit the slash */ +/* +* We went past the (vfsmount, dentry) we were looking for and have +* either hit a root dentry, a lazily unmounted dentry, an +* unconnected dentry, or the file is on a pseudo filesystem. +*/ +if ((dentry->d_sb->s_flags &MS_NOUSER ) || + (dentry->d_name.len =1 && *dentry->d_name.name =='/' )) {Did you really mean to assign 1 to
dentry->d_name.lenhere? Was `==' intended? I hope so, because modifying the dentry ind_path()would be odd.
Quoted 2 lines
If this was a mistake then why did the patch pass testing?
Nope, definite bug, missed that case in testing. In this case every test that had a leading '/' had a d_name.len == 1 as well.
I haven't seen the case of where a root dentry has a leading / and doesn't have a d_name.len == 1 and if that case never happens the test wouldn't be needed.
I will respin the patch, and include testing this time
thanks
john
Quoted 8 lines · On Sat, 20 Feb 2010, [email protected] wrote:
From: John Johansen <[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.
Example:
# mkdir -p /tmp/foo/bar # mkdir /tmp/mnt # mount --bind /tmp/foo /tmp/mnt # cd /tmp/mnt/bar # /bin/pwd /tmp/mnt/bar # umount -l /tmp/mnt # /bin/pwd foobar
After the patch it will be /foo/bar.
Why is the path starting with "/foo"? Does that make any sense?
Last time this was discussed the proposals which are halfway sane were:
a) "(unreachable)/bar" or something along those lines
b) ENOENT
And with either one care needs to be taken to limit this change to interfaces (both internal and userspace) where it's not likely to cause breakage.
Thanks,
Miklos
Quoted 22 lines · Miklos Szeredi
Quoted 8 lines · On Sat, 20 Feb 2010, [email protected] wrote:
From: John Johansen<[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.Example:
# mkdir -p /tmp/foo/bar # mkdir /tmp/mnt # mount --bind /tmp/foo /tmp/mnt # cd /tmp/mnt/bar # /bin/pwd /tmp/mnt/bar # umount -l /tmp/mnt # /bin/pwd foobar
Quoted 4 lines
After the patch it will be /foo/bar.
Why is the path starting with "/foo"? Does that make any sense?
not a lot except, connecting disconnected paths to root is what is currently done for paths that aren't reachable but have an fs as their root (ie the last dentry is / so it looks connected to root).
I would be happy in this case to leave bind mounts disconnected (no leading /) and just fix the overwriting of the internal /.
I'll make the change.
Quoted 6 lines
Last time this was discussed the proposals which are halfway sane were:
a) "(unreachable)/bar" or something along those lines
b) ENOENT
right, I actually have another couple of __d_path patches I need to kick out for discussion. Last time we rolled 3 different changes into a single patch. This time I wanted to isolate the changes per patch. I'll kick them all out today.
Quoted 4 lines
And with either one care needs to be taken to limit this change to interfaces (both internal and userspace) where it's not likely to cause breakage.
agreed.
Quoted 23 lines · John Johansen
Quoted 22 lines · Miklos Szeredi
Quoted 8 lines · On Sat, 20 Feb 2010, [email protected] wrote:
From: John Johansen<[email protected]>
When
__d_path()hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``/foo/bar''.Example:
# mkdir -p /tmp/foo/bar # mkdir /tmp/mnt # mount --bind /tmp/foo /tmp/mnt # cd /tmp/mnt/bar # /bin/pwd /tmp/mnt/bar # umount -l /tmp/mnt # /bin/pwd foobar
Quoted 8 lines
Quoted 4 lines
After the patch it will be /foo/bar.
Why is the path starting with "/foo"? Does that make any sense?
not a lot except, connecting disconnected paths to root is what is currently done for paths that aren't reachable but have an fs as their root (ie the last dentry is / so it looks connected to root).
/tmp (which contains /foo/bar) is not a root of anything. So even that logic doesn't hold for your current patch.
/tmp/foo *was* the root of the mount, so "/bar" would make a tiny little more sense. But "/bar" looks like a normal connected patch, which it is not, so it's not really a good solution either.
Thanks,
Miklos