All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts.
@ 2018-04-18  3:31 NeilBrown
  2018-04-18  8:22 ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: NeilBrown @ 2018-04-18  3:31 UTC (permalink / raw)
  To: util-linux

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


When you bind-mount a subdirectory of a local filesystem, the
path to that subdirectory appears as the fourth field in mountinfo.

For nfs mounts, the fourth field is always "/", and the subdirectory
part is appended to the "special" (aka "device") field.  This is
consistent with historical NFS usage which always includes a path in
the fs_spec field.

libmount needs to know about this when "mount -a" checks to see if
a filesystem is already mounted.

Without this fix, fstab lines like:

 server::/path /dir nfs defaults 0 0
 /dir/subdir /mnt/test none bind 0 0

result in a new mount at /mnt/test every time "mount -a" is run.


Signed-off-by: NeilBrown <neilb@suse.com>
---
 libmount/src/tab.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 968057e429f5..21e37aea7f5d 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -1542,6 +1542,7 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
 	struct libmnt_fs *fs;
 
 	char *root = NULL;
+	char *src2 = NULL;
 	const char *src = NULL, *tgt = NULL;
 	char *xtgt = NULL;
 	int rc = 0;
@@ -1566,8 +1567,18 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
 			flags = MS_BIND;
 
 		rootfs = mnt_table_get_fs_root(tb, fstab_fs, flags, &root);
-		if (rootfs)
+		if (rootfs) {
+			const char *fstype = mnt_fs_get_fstype(rootfs);
+
 			src = mnt_fs_get_srcpath(rootfs);
+			if (fstype && strncmp(fstype, "nfs", 3) == 0 && root) {
+				/* NFS stores the root at the end of the source */
+				asprintf(&src2, "%s%s", src, root);
+				src = src2;
+				free(root);
+				root = NULL;
+			}
+		}
 	}
 
 	if (!src)
@@ -1667,6 +1678,7 @@ done:
 	free(root);
 
 	DBG(TAB, ul_debugobj(tb, "mnt_table_is_fs_mounted: %s [rc=%d]", src, rc));
+	free(src2);
 	return rc;
 }
 
-- 
2.14.0.rc0.dirty


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts.
  2018-04-18  3:31 [PATCH] libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts NeilBrown
@ 2018-04-18  8:22 ` Karel Zak
  2018-04-18 23:37   ` NeilBrown
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2018-04-18  8:22 UTC (permalink / raw)
  To: NeilBrown; +Cc: util-linux

On Wed, Apr 18, 2018 at 01:31:38PM +1000, NeilBrown wrote:
> For nfs mounts, the fourth field is always "/", and the subdirectory
> part is appended to the "special" (aka "device") field.  This is
> consistent with historical NFS usage which always includes a path in
> the fs_spec field.

Interesting.

>  libmount/src/tab.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

Applied with a minor change, thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

* Re: [PATCH] libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts.
  2018-04-18  8:22 ` Karel Zak
@ 2018-04-18 23:37   ` NeilBrown
  0 siblings, 0 replies; 3+ messages in thread
From: NeilBrown @ 2018-04-18 23:37 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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

On Wed, Apr 18 2018, Karel Zak wrote:

> On Wed, Apr 18, 2018 at 01:31:38PM +1000, NeilBrown wrote:
>> For nfs mounts, the fourth field is always "/", and the subdirectory
>> part is appended to the "special" (aka "device") field.  This is
>> consistent with historical NFS usage which always includes a path in
>> the fs_spec field.
>
> Interesting.
>
>>  libmount/src/tab.c | 14 +++++++++++++-
>>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> Applied with a minor change, thanks!

Thanks.  I like the minor change!

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

end of thread, other threads:[~2018-04-18 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18  3:31 [PATCH] libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts NeilBrown
2018-04-18  8:22 ` Karel Zak
2018-04-18 23:37   ` NeilBrown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.