]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix mount -a EBUSY for cifs
authorRoberto Bergantinos Corpas <rbergant@redhat.com>
Mon, 27 Apr 2020 13:46:02 +0000 (15:46 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Apr 2020 13:46:02 +0000 (15:46 +0200)
fstab:

 //rhel73/myshare/sub/path  /mnt   cifs

after mount in mountinfo:

 #  grep cifs /proc/self/mountinfo
 47 39 0:40 /sub/path /mnt rw,relatime shared:60 - cifs //rhel73/myshare/sub/path ...
            ^^^^^^^^^
or:

 # grep cifs /proc/self/mountinfo
 47 39 0:40 / /mnt rw,relatime shared:60 - cifs //rhel73/myshare/sub/path ...
            ^

That is so since on kernel cifs code, cifs_get_root (which returns the
entry associated with mnt_root) return s_root if
CIFS_MOUNT_USE_PREFIX_PATH is set, no questions asked.

This situation can occurr often on CIFS mounts, as CIFS servers limit
frequently scope of access to the root path.

[kzak@redhat.com: - add more info to the commit message,
                  - clean up variable names]

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1826719
Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/tab.c

index 1633d423105c38e169e7d0295ff54a373c94a19d..cac7fd3c125c4f7d63d84e5aa7830801349bacb3 100644 (file)
@@ -1763,13 +1763,14 @@ int __mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_f
                if (root) {
                        const char *fstype = mnt_fs_get_fstype(fs);
 
-                       if (fstype && (strcmp(fstype, "cifs") == 0
-                                      || strcmp(fstype, "smb3") == 0)) {
+                       if (fstype && (strcmp(fstype, "cifs") == 0 ||
+                                      strcmp(fstype, "smb3") == 0)) {
 
-                               const char *unc_subdir = get_cifs_unc_subdir_path(src);
-                               const char *path_on_fs = mnt_fs_get_root(fs);
+                               const char *sub = get_cifs_unc_subdir_path(src);
+                               const char *r = mnt_fs_get_root(fs);
 
-                               if (!unc_subdir || !path_on_fs || !streq_paths(unc_subdir, path_on_fs))
+                               if (!sub || !r || (!streq_paths(sub, r) &&
+                                                  !streq_paths("/", r)))
                                        continue;
                        } else {
                                const char *r = mnt_fs_get_root(fs);