Skip to contentSkip to conversation

Bug#669314: NFS: kernel forces trailing slash for export in /proc/self/mounts

PATCH In review Chris Hiestand 7 participants 12 messages Jun 19, 2012 – Oct 31, 2012 7 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Alexander Viro et al,

This is an escalation of Debian Bug #669314 http://bugs.debian.org/669314, which I will re-elaborate in this email for your convenience.

You committed a change to the way the linux kernel reports NFS mounts - now with a trailing slash for the remote export (among other changes). The change happened here:

Quoted 6 lines

commit c7f404b40a3665d9f4e9a927cc5c1ee0479ed8f9

Author: Al Viro <[email protected]>
Date:   Wed Mar 16 06:59:40 2011 -0400

vfs: new superblock methods to override /proc/*/mount{s,info}

Quoted 8 lines

a) ->show_devname(m, mnt) - what to put into devname columns in mounts, mountinfo and mountstats
b) ->show_path(m, mnt) - what to put into relative path column in mountinfo

Leaving those NULL gives old behaviour. NFS switched to using those.

The "problematic" behavior is that NFS exports now have a trailing slash in /proc/self/mounts.

This still seems to be the case in newer kernels, for example in Debian's 3.3.2-1~experimental.1.

and HEAD in Linus Torvalds' master branch, presently commit:
02edf6abe01610a5fb379df442de3c837ad99467

I believe it is/was convention to leave a trailing slash off of the nfs export
in /etc/fstab, e.g.:
nfsserver:/srv/ubuntu-32 /mnt/ubuntu-32 nfs ro,nfsvers=3,soft,intr,tcp,nodev,noatime,nosuid,rsize=32768,wsize=32768

and I'd also expect the same in /proc/self/mounts

Expected Result:
I expect /proc/self/mounts to show (notice no trailing slash on the export):
nfsserver:/srv/ubuntu-32 /mnt/ubuntu-32 nfs ro,nosuid,nodev,noatime,vers=3,rsize=32768,wsize=32768,namlen=255,soft,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=198.202.1.1,mountvers=3,mountport=41576,mountproto=tcp,local_lock=none,addr=198.202.1.1 0 0

Actual Result:
But instead in /proc/self/mounts I get (notice the trailing slash):
nfsserver:/srv/ubuntu-32/ /mnt/ubuntu-32 nfs ro,nosuid,nodev,noatime,vers=3,rsize=32768,wsize=32768,namlen=255,soft,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=198.202.1.1,mountvers=3,mountport=41576,mountproto=tcp,local_lock=none,addr=198.202.1.1 0 0

Rammifications:
This simple change has a lot of implications because lots of things parse /etc/fstab and /proc/self/mounts, for example system configuration tools and mount.nfs and umount.nfs.

If you use the former convention and try to umount an export on a newer kernel it will fail:

user@hostname:/proc/self$ sudo umount.nfs nfsserver:/srv/ubuntu-32
umount.nfs: nfsserver:/srv/ubuntu-32: not found

And if you run "sudo mount -va", mount will not recognize that the fstab mounts have already been mounted; mounting all mounts twice on the same mount point. This quickly gets messy.

If there is a new convention to display the trailing slash, we need to update our tools to handle this change. If there is not a new convention, I'd argue this is a bug.

So is this a new convention or not? What is the appropriate way for Debian to move forward?

Thanks,
Chris Hiestand

#1 lore raw

Re: NFS: kernel forces trailing slash for export in /proc/self/mounts

Quoted 24 lines · Chris Hiestand

Hi Alexander Viro et al,

This is an escalation of Debian Bug #669314 http://bugs.debian.org/669314, which I will re-elaborate in this email for your convenience.

You committed a change to the way the linux kernel reports NFS mounts - now with a trailing slash for the remote export (among other changes). The change happened here:

Quoted 6 lines

commit c7f404b40a3665d9f4e9a927cc5c1ee0479ed8f9

Author: Al Viro <[email protected]>
Date:   Wed Mar 16 06:59:40 2011 -0400

vfs: new superblock methods to override /proc/*/mount{s,info}

Quoted 8 lines

a) ->show_devname(m, mnt) - what to put into devname columns in mounts, mountinfo and mountstats
b) ->show_path(m, mnt) - what to put into relative path column in mountinfo

Leaving those NULL gives old behaviour. NFS switched to using those.

The "problematic" behavior is that NFS exports now have a trailing slash in /proc/self/mounts.

[...]

Quoted 6 lines

If there is a new convention to display the trailing slash, we need to update our tools to handle this change. If there is not a new convention, I'd argue this is a bug.

So is this a new convention or not? What is the appropriate way for Debian to move forward?

Al, Trond, what's going on here? This sure looks like it broke userland, in which case we need to revert the change in behaviour.

How about the following (untested) change?

Ben.
---
Subject: nfs: Show original device name verbatim in /proc/*/mount{s,info}

Since commit c7f404b ('vfs: new superblock methods to override /proc/*/mount{s,info}'), nfs_path() is used to generate the mounted device name reported back to userland.

nfs_path() always generates a trailing slash when the given dentry is the root of an NFS mount, but userland may expect the original device name to be returned verbatim (as it used to be). Make this canonicalisation optional and change the callers accordingly.

---
 fs/nfs/internal.h      |    4 ++--
 fs/nfs/namespace.c     |   15 ++++++++++-----
 fs/nfs/nfs4namespace.c |    2 +-
 fs/nfs/super.c         |    2 +-
 4 files changed, 14 insertions(+), 9 deletions(-)
fs/nfs/internal.h +2 -2
index d554438..c38224a 100644
@@ -354,7 +354,7 @@ extern void nfs_sb_deactive(struct super_block *sb);
 
 /* namespace.c */
 extern char *nfs_path(char **p, struct dentry *dentry,
-		      char *buffer, ssize_t buflen);
+		      char *buffer, ssize_t buflen, bool canonical);
 extern struct vfsmount *nfs_d_automount(struct path *path);
 struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
 			      struct nfs_fh *, struct nfs_fattr *);
@@ -491,7 +491,7 @@ static inline char *nfs_devname(struct dentry *dentry,
 				char *buffer, ssize_t buflen)
 {
 	char *dummy;
-	return nfs_path(&dummy, dentry, buffer, buflen);
+	return nfs_path(&dummy, dentry, buffer, buflen, true);
 }
 
 /*
fs/nfs/namespace.c +10 -5
index 6559253..059975e 100644
@@ -33,6 +33,8 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * @dentry - pointer to dentry
  * @buffer - result buffer
  * @buflen - length of buffer
+ * @canonical - ensure there is exactly one slash after the original
+ *		device (export) name; if false, return it verbatim
  *
  * Helper function for constructing the server pathname
  * by arbitrary hashed dentry.
@@ -41,7 +43,8 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * server side when automounting on top of an existing partition
  * and in generating /proc/mounts and friends.
  */
-char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen)
+char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen,
+	       bool canonical)
 {
 	char *end;
 	int namelen;
@@ -74,7 +77,7 @@ rename_retry:
 		rcu_read_unlock();
 		goto rename_retry;
 	}
-	if (*end != '/') {
+	if (canonical && *end != '/') {
 		if (--buflen < 0) {
 			spin_unlock(&dentry->d_lock);
 			rcu_read_unlock();
@@ -91,9 +94,11 @@ rename_retry:
 		return end;
 	}
 	namelen = strlen(base);
-	/* Strip off excess slashes in base string */
-	while (namelen > 0 && base[namelen - 1] == '/')
-		namelen--;
+	if (canonical) {
+		/* Strip off excess slashes in base string */
+		while (namelen > 0 && base[namelen - 1] == '/')
+			namelen--;
+	}
 	buflen -= namelen;
 	if (buflen < 0) {
 		spin_unlock(&dentry->d_lock);
fs/nfs/nfs4namespace.c +1 -1
index 017b4b0..94e8652 100644
@@ -81,7 +81,7 @@ static char *nfs_path_component(const char *nfspath, const char *end)
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 {
 	char *limit;
-	char *path = nfs_path(&limit, dentry, buffer, buflen);
+	char *path = nfs_path(&limit, dentry, buffer, buflen, true);
 	if (!IS_ERR(path)) {
 		char *path_component = nfs_path_component(path, limit);
 		if (path_component)
fs/nfs/super.c +1 -1
index d2c7f5d..630a1e2 100644
@@ -765,7 +765,7 @@ int nfs_show_devname(struct seq_file *m, struct dentry *root)
 	int err = 0;
 	if (!page)
 		return -ENOMEM;
-	devname = nfs_path(&dummy, root, page, PAGE_SIZE);
+	devname = nfs_path(&dummy, root, page, PAGE_SIZE, false);
 	if (IS_ERR(devname))
 		err = PTR_ERR(devname);
 	else
Signature · 2 lines
Ben Hutchings
Experience is what causes a person to make new mistakes instead of old ones.
#2 lore raw

I had a couple friends over today and we made a trivial patch to remove trailing slashes. We do not know C and have never created a patch for the kernel before, so there is undoubtedly a better way to do it. However we hope this helps in your efforts.

From 81baa04c07107f81c56c4f163da2178b01294717 Mon Sep 17 00:00:00 2001
From: Chris Hiestand <[email protected]>
Date: Sat, 15 Sep 2012 18:40:45 -0700
Subject: [PATCH] Fixes trailing slash in nfs devname

---
 fs/nfs/super.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfs/super.c +5 -1
index 79bc61f..e300a84 100644
@@ -742,8 +742,12 @@ static int nfs_show_devname(struct seq_file *m, struct vfsmount *mnt)
 	devname = nfs_path(&dummy, mnt->mnt_root, page, PAGE_SIZE);
 	if (IS_ERR(devname))
 		err = PTR_ERR(devname);
-	else
+	else {
+		size_t len = strlen(devname);
+		if (devname[len-1] == '/')
+			devname[len-1] = '\0';
 		seq_escape(m, devname, " \t\n\\");
+	}
 	free_page((unsigned long)page);
 	return err;
 }
Signature · 1 line
1.7.10.4

This patch was created from the offending commit (c7f404b40a366). But I've also applied it to to Linus Torvalds' master HEAD (3f0c3c8fe30c7) with success.

-Chris

A message that is not in the archive (sent off-list or not yet received): 254E1AAA-BDE2-41A8-94D8-6E677860AD72-xrR1t/[email protected]

#4 lore raw
Quoted 8 lines · Chris Hiestand

I had a couple friends over today and we made a trivial patch to remove trailing slashes. We do not know C and have never created a patch for the kernel before, so there is undoubtedly a better way to do it. However we hope this helps in your efforts.

This patch was created from the offending commit (c7f404b40a366). But I've also applied it to to Linus Torvalds' master HEAD (3f0c3c8fe30c7) with success.

This was my first thought - but what if userland provides a device name with a slash on the end? I think we have to report it back with the slash in that case.

Ben.

Signature · 2 lines
Ben Hutchings
Experience is what causes a person to make new mistakes instead of old ones.

A message that is not in the archive (sent off-list or not yet received): 1347804028.13258.267.camel-nDn/Rdv9kqW9Jme8/[email protected]

#6 lore raw
Quoted 3 lines · Ben Hutchings

This was my first thought - but what if userland provides a device name with a slash on the end? I think we have to report it back with the slash in that case.

That is a great point. We could not find any standard as to whether or not there should be a trailing slash. And from all the examples I could find, there seems to be a convention of omitting a trailing slash. However, if userland provides a trailing slash, it would seem appropriate to retain it.

As a point of comparison, matching the given input is the behavior of 2.6.32-5 in Debian Squeeze. So I think your approach is better.

-Chris

A message that is not in the archive (sent off-list or not yet received): FB3CAE84-FDFE-4345-9F54-3295BDE2AD81-xrR1t/[email protected]

#8 lore raw

Re: NFS: kernel forces trailing slash for export in /proc/self/mounts

Hi Chris,

Quoted 5 lines · Chris Hiestand
Quoted 3 lines · Ben Hutchings

This was my first thought - but what if userland provides a device name with a slash on the end? I think we have to report it back with the slash in that case.

[...]

Quoted 2 lines

As a point of comparison, matching the given input is the behavior of 2.6.32-5 in Debian Squeeze. So I think your approach is better.

Thanks for looking it over. Did you get a chance to test Ben's patch?

Curious,
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Re: NFS: kernel forces trailing slash for export in /proc/self/mounts

I haven't had a chance to test it yet thanks. I'll be too busy until at least mid-next week, but I will test it then if nobody beats me to it.

-Chris

Quoted 4 lines · Jonathan Nieder

Thanks for looking it over. Did you get a chance to test Ben's patch?

Curious,
Jonathan

A message that is not in the archive (sent off-list or not yet received): B259EBD8-0ED1-405F-A3E5-DF488FCE402F-xrR1t/[email protected]

#12 lore raw

Re: NFS: kernel forces trailing slash for export in /proc/self/mounts

I've applied the patch to Linus' master HEAD (43c422eda99b894f18d1cca17bcd2401efaf7bd0, at the time) and the patch seems to work fine.

/proc/self/mounts correctly reflects whether or not the user specified to use a trailing slash - and nothing is obviously broken.

If the patch looks fine to others, I propose we move this patch into wherever is the next step for testing it more broadly:
e.g. Debian experimental, and wherever it needs to go to end up in Linus' master branch.

Thanks,
Chris

A message that is not in the archive (sent off-list or not yet received): 7941E5E1-488D-4D0B-A21A-4E389EF6EBBA-xrR1t/[email protected]

#14 lore raw

PATCH 1/1 nfs: Show original device name verbatim in /proc/*/mount{s,info}

Since commit c7f404b ('vfs: new superblock methods to override /proc/*/mount{s,info}'), nfs_path() is used to generate the mounted device name reported back to userland.

nfs_path() always generates a trailing slash when the given dentry is the root of an NFS mount, but userland may expect the original device name to be returned verbatim (as it used to be). Make this canonicalisation optional and change the callers accordingly.

Reference: http://bugs.debian.org/669314

---
 fs/nfs/internal.h      |    4 ++--
 fs/nfs/namespace.c     |   15 ++++++++++-----
 fs/nfs/nfs4namespace.c |    2 +-
 fs/nfs/super.c         |    2 +-
 4 files changed, 14 insertions(+), 9 deletions(-)
fs/nfs/internal.h +2 -2
index 31fdb03..5eaf902 100644
@@ -354,7 +354,7 @@ extern void nfs_sb_deactive(struct super_block *sb);
 
 /* namespace.c */
 extern char *nfs_path(char **p, struct dentry *dentry,
-		      char *buffer, ssize_t buflen);
+		      char *buffer, ssize_t buflen, bool canonical);
 extern struct vfsmount *nfs_d_automount(struct path *path);
 struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
 			      struct nfs_fh *, struct nfs_fattr *);
@@ -491,7 +491,7 @@ static inline char *nfs_devname(struct dentry *dentry,
 				char *buffer, ssize_t buflen)
 {
 	char *dummy;
-	return nfs_path(&dummy, dentry, buffer, buflen);
+	return nfs_path(&dummy, dentry, buffer, buflen, true);
 }
 
 /*
fs/nfs/namespace.c +10 -5
index 6559253..059975e 100644
@@ -33,6 +33,8 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * @dentry - pointer to dentry
  * @buffer - result buffer
  * @buflen - length of buffer
+ * @canonical - ensure there is exactly one slash after the original
+ *		device (export) name; if false, return it verbatim
  *
  * Helper function for constructing the server pathname
  * by arbitrary hashed dentry.
@@ -41,7 +43,8 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * server side when automounting on top of an existing partition
  * and in generating /proc/mounts and friends.
  */
-char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen)
+char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen,
+	       bool canonical)
 {
 	char *end;
 	int namelen;
@@ -74,7 +77,7 @@ rename_retry:
 		rcu_read_unlock();
 		goto rename_retry;
 	}
-	if (*end != '/') {
+	if (canonical && *end != '/') {
 		if (--buflen < 0) {
 			spin_unlock(&dentry->d_lock);
 			rcu_read_unlock();
@@ -91,9 +94,11 @@ rename_retry:
 		return end;
 	}
 	namelen = strlen(base);
-	/* Strip off excess slashes in base string */
-	while (namelen > 0 && base[namelen - 1] == '/')
-		namelen--;
+	if (canonical) {
+		/* Strip off excess slashes in base string */
+		while (namelen > 0 && base[namelen - 1] == '/')
+			namelen--;
+	}
 	buflen -= namelen;
 	if (buflen < 0) {
 		spin_unlock(&dentry->d_lock);
fs/nfs/nfs4namespace.c +1 -1
index 017b4b0..94e8652 100644
@@ -81,7 +81,7 @@ static char *nfs_path_component(const char *nfspath, const char *end)
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 {
 	char *limit;
-	char *path = nfs_path(&limit, dentry, buffer, buflen);
+	char *path = nfs_path(&limit, dentry, buffer, buflen, true);
 	if (!IS_ERR(path)) {
 		char *path_component = nfs_path_component(path, limit);
 		if (path_component)
fs/nfs/super.c +1 -1
index ac6a3c5..6087ed0 100644
@@ -730,7 +730,7 @@ int nfs_show_devname(struct seq_file *m, struct dentry *root)
 	int err = 0;
 	if (!page)
 		return -ENOMEM;
-	devname = nfs_path(&dummy, root, page, PAGE_SIZE);
+	devname = nfs_path(&dummy, root, page, PAGE_SIZE, false);
 	if (IS_ERR(devname))
 		err = PTR_ERR(devname);
 	else
Reviewed-by on v1 1/1
#15 lore raw

Re: [PATCH] nfs: Show original device name verbatim in /proc/*/mount{s,info}

(cc-ing Laurent in case he wants to test. Laurent, a "git am"-ready
patch is at [1])

Quoted 9 lines · Ben Hutchings

Since commit c7f404b ('vfs: new superblock methods to override /proc/*/mount{s,info}'), nfs_path() is used to generate the mounted device name reported back to userland.

nfs_path() always generates a trailing slash when the given dentry is the root of an NFS mount, but userland may expect the original device name to be returned verbatim (as it used to be). Make this canonicalisation optional and change the callers accordingly.

Quoted 4 lines

Reference: http://bugs.debian.org/669314

Changing the content of /proc/mounts broke

 user@hostname:/proc/self$ sudo umount.nfs nfsserver:/srv/ubuntu-32
 umount.nfs: nfsserver:/srv/ubuntu-32: not found

with nfs2 and nfs3 and this looks like the minimal change to get it working again, so for what it's worth,

How about something like the following on top?

-- >8 --
Subject: nfs: convert boolean nfs_path() argument to a flag word

If nfs_path() gains any other boolean settings, they can share the flag argument, and this way call sites look like "nfs_path(&limit, dentry, buffer, buflen, NFS_PATH_CANONICAL);" so the reader does not need to guess the sense of true and false. No functional change intended.

---
[1] http://download.gmane.org/gmane.linux.nfs/52755/52756

 fs/nfs/internal.h      |  5 +++--
 fs/nfs/namespace.c     | 14 +++++++++-----
 fs/nfs/nfs4namespace.c |  3 ++-
 fs/nfs/super.c         |  2 +-
 4 files changed, 15 insertions(+), 9 deletions(-)
fs/nfs/internal.h +3 -2
index 9c9603373d64..a54fe51c1dfb 100644
@@ -353,8 +353,9 @@ extern void nfs_sb_active(struct super_block *sb);
 extern void nfs_sb_deactive(struct super_block *sb);
 
 /* namespace.c */
+#define NFS_PATH_CANONICAL 1
 extern char *nfs_path(char **p, struct dentry *dentry,
-		      char *buffer, ssize_t buflen, bool canonical);
+		      char *buffer, ssize_t buflen, unsigned flags);
 extern struct vfsmount *nfs_d_automount(struct path *path);
 struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
 			      struct nfs_fh *, struct nfs_fattr *);
@@ -498,7 +499,7 @@ static inline char *nfs_devname(struct dentry *dentry,
 				char *buffer, ssize_t buflen)
 {
 	char *dummy;
-	return nfs_path(&dummy, dentry, buffer, buflen, true);
+	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
 }
 
 /*
fs/nfs/namespace.c +9 -5
index 059975e492e1..dd057bc6b65b 100644
@@ -33,8 +33,7 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * @dentry - pointer to dentry
  * @buffer - result buffer
  * @buflen - length of buffer
- * @canonical - ensure there is exactly one slash after the original
- *		device (export) name; if false, return it verbatim
+ * @flags - options (see below)
  *
  * Helper function for constructing the server pathname
  * by arbitrary hashed dentry.
@@ -42,9 +41,14 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * This is mainly for use in figuring out the path on the
  * server side when automounting on top of an existing partition
  * and in generating /proc/mounts and friends.
+ *
+ * Supported flags:
+ * NFS_PATH_CANONICAL: ensure there is exactly one slash after
+ *		       the original device (export) name
+ *		       (if unset, the original name is returned verbatim)
  */
 char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen,
-	       bool canonical)
+	       unsigned flags)
 {
 	char *end;
 	int namelen;
@@ -77,7 +81,7 @@ rename_retry:
 		rcu_read_unlock();
 		goto rename_retry;
 	}
-	if (canonical && *end != '/') {
+	if ((flags & NFS_PATH_CANONICAL) && *end != '/') {
 		if (--buflen < 0) {
 			spin_unlock(&dentry->d_lock);
 			rcu_read_unlock();
@@ -94,7 +98,7 @@ rename_retry:
 		return end;
 	}
 	namelen = strlen(base);
-	if (canonical) {
+	if (flags & NFS_PATH_CANONICAL) {
 		/* Strip off excess slashes in base string */
 		while (namelen > 0 && base[namelen - 1] == '/')
 			namelen--;
fs/nfs/nfs4namespace.c +2 -1
index 2f6f16331769..1e09eb78543b 100644
@@ -81,7 +81,8 @@ static char *nfs_path_component(const char *nfspath, const char *end)
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 {
 	char *limit;
-	char *path = nfs_path(&limit, dentry, buffer, buflen, true);
+	char *path = nfs_path(&limit, dentry, buffer, buflen,
+			      NFS_PATH_CANONICAL);
 	if (!IS_ERR(path)) {
 		char *path_component = nfs_path_component(path, limit);
 		if (path_component)
fs/nfs/super.c +1 -1
index c89a73da13d9..13c2a5be4765 100644
@@ -771,7 +771,7 @@ int nfs_show_devname(struct seq_file *m, struct dentry *root)
 	int err = 0;
 	if (!page)
 		return -ENOMEM;
-	devname = nfs_path(&dummy, root, page, PAGE_SIZE, false);
+	devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
 	if (IS_ERR(devname))
 		err = PTR_ERR(devname);
 	else
Signature · 1 line
1.8.0.rc3
#16 lore raw

Re: [PATCH] nfs: Show original device name verbatim in /proc/*/mount{s,info}

Quoted 17 lines · Jonathan Nieder

(cc-ing Laurent in case he wants to test. Laurent, a "git am"-ready
patch is at [1])

Quoted 13 lines · Ben Hutchings

Since commit c7f404b ('vfs: new superblock methods to override /proc/*/mount{s,info}'), nfs_path() is used to generate the mounted device name reported back to userland.

nfs_path() always generates a trailing slash when the given dentry is the root of an NFS mount, but userland may expect the original device name to be returned verbatim (as it used to be). Make this canonicalisation optional and change the callers accordingly.

Reference: http://bugs.debian.org/669314

This patch will not apply to the upstream kernel; it seems rather to have been generated incrementally against an older patch attempt.

Please regenerate and resend if you want this merged...

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

A message that is not in the archive (sent off-list or not yet received): 4FA345DA4F4AE44899BD2B03EEEC2FA90929FA9E-VGJ86jkg8PeBTCzCEi1xmXOR4cbS7gtM96Bgd4bDwmQ@public.gmane.org

#18 lore raw

PATCH v3 1/1 nfs: Show original device name verbatim in /proc/*/mount{s,info}

From: Ben Hutchings <ben-/[email protected]>
Date: Sun, 21 Oct 2012 19:23:52 +0100

Since commit c7f404b ('vfs: new superblock methods to override /proc/*/mount{s,info}'), nfs_path() is used to generate the mounted device name reported back to userland.

nfs_path() always generates a trailing slash when the given dentry is the root of an NFS mount, but userland may expect the original device name to be returned verbatim (as it used to be). Make this canonicalisation optional and change the callers accordingly.

[[email protected]: use flag instead of bool argument]

Reference: http://bugs.debian.org/669314

---

Quoted 2 lines · Trond

This patch will not apply to the upstream kernel; it seems rather to have been generated incrementally against an older patch attempt.

I assume you mean the patch

nfs: convert boolean nfs_path() argument to a flag word

does not apply against master. It is just an optional code style improvement on top of Ben's

nfs: Show original device name verbatim in /proc/*/mount{s,info}

Here are the two squashed together for convenience.

Thanks,
Jonathan

 fs/nfs/internal.h      |  5 +++--
 fs/nfs/namespace.c     | 19 ++++++++++++++-----
 fs/nfs/nfs4namespace.c |  3 ++-
 fs/nfs/super.c         |  2 +-
 4 files changed, 20 insertions(+), 9 deletions(-)
fs/nfs/internal.h +3 -2
index 59b133c5d652..a54fe51c1dfb 100644
@@ -353,8 +353,9 @@ extern void nfs_sb_active(struct super_block *sb);
 extern void nfs_sb_deactive(struct super_block *sb);
 
 /* namespace.c */
+#define NFS_PATH_CANONICAL 1
 extern char *nfs_path(char **p, struct dentry *dentry,
-		      char *buffer, ssize_t buflen);
+		      char *buffer, ssize_t buflen, unsigned flags);
 extern struct vfsmount *nfs_d_automount(struct path *path);
 struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
 			      struct nfs_fh *, struct nfs_fattr *);
@@ -498,7 +499,7 @@ static inline char *nfs_devname(struct dentry *dentry,
 				char *buffer, ssize_t buflen)
 {
 	char *dummy;
-	return nfs_path(&dummy, dentry, buffer, buflen);
+	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
 }
 
 /*
fs/nfs/namespace.c +14 -5
index 655925373b91..dd057bc6b65b 100644
@@ -33,6 +33,7 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * @dentry - pointer to dentry
  * @buffer - result buffer
  * @buflen - length of buffer
+ * @flags - options (see below)
  *
  * Helper function for constructing the server pathname
  * by arbitrary hashed dentry.
@@ -40,8 +41,14 @@ int nfs_mountpoint_expiry_timeout = 500 * HZ;
  * This is mainly for use in figuring out the path on the
  * server side when automounting on top of an existing partition
  * and in generating /proc/mounts and friends.
+ *
+ * Supported flags:
+ * NFS_PATH_CANONICAL: ensure there is exactly one slash after
+ *		       the original device (export) name
+ *		       (if unset, the original name is returned verbatim)
  */
-char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen)
+char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen,
+	       unsigned flags)
 {
 	char *end;
 	int namelen;
@@ -74,7 +81,7 @@ rename_retry:
 		rcu_read_unlock();
 		goto rename_retry;
 	}
-	if (*end != '/') {
+	if ((flags & NFS_PATH_CANONICAL) && *end != '/') {
 		if (--buflen < 0) {
 			spin_unlock(&dentry->d_lock);
 			rcu_read_unlock();
@@ -91,9 +98,11 @@ rename_retry:
 		return end;
 	}
 	namelen = strlen(base);
-	/* Strip off excess slashes in base string */
-	while (namelen > 0 && base[namelen - 1] == '/')
-		namelen--;
+	if (flags & NFS_PATH_CANONICAL) {
+		/* Strip off excess slashes in base string */
+		while (namelen > 0 && base[namelen - 1] == '/')
+			namelen--;
+	}
 	buflen -= namelen;
 	if (buflen < 0) {
 		spin_unlock(&dentry->d_lock);
fs/nfs/nfs4namespace.c +2 -1
index 79fbb61ce202..1e09eb78543b 100644
@@ -81,7 +81,8 @@ static char *nfs_path_component(const char *nfspath, const char *end)
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 {
 	char *limit;
-	char *path = nfs_path(&limit, dentry, buffer, buflen);
+	char *path = nfs_path(&limit, dentry, buffer, buflen,
+			      NFS_PATH_CANONICAL);
 	if (!IS_ERR(path)) {
 		char *path_component = nfs_path_component(path, limit);
 		if (path_component)
fs/nfs/super.c +1 -1
index e831bce49766..13c2a5be4765 100644
@@ -771,7 +771,7 @@ int nfs_show_devname(struct seq_file *m, struct dentry *root)
 	int err = 0;
 	if (!page)
 		return -ENOMEM;
-	devname = nfs_path(&dummy, root, page, PAGE_SIZE);
+	devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
 	if (IS_ERR(devname))
 		err = PTR_ERR(devname);
 	else
Signature · 6 lines
1.8.0

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html