summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab.c
diff options
context:
space:
mode:
authorNeilBrown2018-04-18 05:31:38 +0200
committerKarel Zak2018-04-18 10:17:26 +0200
commit7966cbba53890e1010861b75bd9923e793bbc975 (patch)
tree4aedad970bf15d00a0b46d265cd13769579d42c8 /libmount/src/tab.c
parentbugfix: fix possible segfault during umount -a (diff)
downloadkernel-qcow2-util-linux-7966cbba53890e1010861b75bd9923e793bbc975.tar.gz
kernel-qcow2-util-linux-7966cbba53890e1010861b75bd9923e793bbc975.tar.xz
kernel-qcow2-util-linux-7966cbba53890e1010861b75bd9923e793bbc975.zip
libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts.
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. [kzak@redhat.com: - use strappend() rather than asprintf()] Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab.c')
-rw-r--r--libmount/src/tab.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 968057e42..eb61dd33e 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,17 @@ 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 */
+ src = src2 = strappend(src, root);
+ free(root);
+ root = NULL;
+ }
+ }
}
if (!src)
@@ -1667,6 +1677,7 @@ done:
free(root);
DBG(TAB, ul_debugobj(tb, "mnt_table_is_fs_mounted: %s [rc=%d]", src, rc));
+ free(src2);
return rc;
}