Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1826719

Summary: mount -a tries to mount already mounted cifs shares when we cannot query up to root dir
Product: Red Hat Enterprise Linux 7 Reporter: Roberto Bergantinos <rbergant>
Component: util-linuxAssignee: Karel Zak <kzak>
Status: CLOSED ERRATA QA Contact: Radka Brychtova <rskvaril>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.7CC: kdsouza
Target Milestone: rcKeywords: Patch, Reproducer
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: util-linux-2.23.2-65.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1829245 (view as bug list) Environment:
Last Closed: 2020-09-29 20:09:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1829245    

Description Roberto Bergantinos 2020-04-22 12:12:11 UTC
Description of problem:

 This is an issue exposed after introducing commit 597807396a00e6f31aa03805ddca27875b81440b.

util-linux-2.23.2-61.el7.x86_64 on RHEL7.

 To reproduce :

=====================================================
[root@rhel76-2 ~]# rpm -qa util-linux
util-linux-2.23.2-61.el7.x86_64
[root@rhel76-2 ~]# stap -gve 'probe module("cifs").function("smb2_is_path_accessible").return{if (kernel_string(@entry($full_path)) == "") $return = 1}' &
[1] 17722
[root@rhel76-2 ~]# Pass 1: parsed user script and 473 library scripts using 271748virt/69120res/3484shr/65780data kb, in 780usr/60sys/856real ms.
Pass 2: analyzed script: 2 probes, 4 functions, 3 embeds, 2 globals using 396980virt/195636res/4824shr/191012data kb, in 1010usr/650sys/1659real ms.
Pass 3: translated to C into "/tmp/stapqm3al5/stap_3c10a53c53d36460ed73aac03fc2c4a6_3953_src.c" using 396980virt/195964res/5152shr/191012data kb, in 470usr/130sys/599real ms.
Pass 4: compiled C into "stap_3c10a53c53d36460ed73aac03fc2c4a6_3953.ko" in 1790usr/500sys/2082real ms.
Pass 5: starting run.

[root@rhel76-2 ~]# umount /mnt
[root@rhel76-2 ~]# grep cifs /etc/fstab 
//rhel73/myshare/sub/path  /mnt   cifs    vers=3.0,username=roberto,password=Armt002!,uid=1000,gid=1000,dir_mode=0777,file_mode=0666 0       0
[root@rhel76-2 ~]# mount -vvv -a
/                        : ignored
/boot                    : already mounted
swap                     : ignored
mount.cifs kernel mount options: ip=172.23.1.225,unc=\\rhel73\myshare,vers=3.0,dir_mode=0777,file_mode=0666,uid=1000,gid=1000,user=roberto,prefixpath=sub/path,pass=********
/mnt                     : successfully mounted

[root@rhel76-2 ~]# grep cifs /proc/self/mountinfo 
47 39 0:40 / /mnt rw,relatime shared:60 - cifs //rhel73/myshare/sub/path rw,vers=3.0,cache=strict,username=roberto,domain=RHEL73,uid=1000,forceuid,gid=1000,forcegid,addr=172.23.1.225,file_mode=0666,dir_mode=0777,soft,nounix,serverino,mapposix,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1

[root@rhel76-2 ~]# mount -vvv -a
/                        : ignored
/boot                    : already mounted
swap                     : ignored
mount.cifs kernel mount options: ip=172.23.1.225,unc=\\rhel73\myshare,vers=3.0,dir_mode=0777,file_mode=0666,uid=1000,gid=1000,user=roberto,prefixpath=sub/path,pass=********
mount error(16): Device or resource busy
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)  <<<==== we still try the mount
[root@rhel76-2 ~]# fg
stap -gve 'probe module("cifs").function("smb2_is_path_accessible").return{if (kernel_string(@entry($full_path)) == "") $return = 1}'
^CPass 5: run completed in 30usr/180sys/45603real ms.

[root@rhel76-2 ~]# dmesg | tail -1
[91858.915331] CIFS VFS: cannot query dirs between root and final path, enabling CIFS_MOUNT_USE_PREFIX_PATH [1]
=====================================================

The underlying problem is that with the new code from 1633657 we introduce this on mnt_table_is_fs_mounted :

+			if (strcmp(mnt_fs_get_fstype(fs), "cifs") == 0) {
+				const char *unc_subdir = get_cifs_unc_subdir_path(src);
+				const char *path_on_fs = mnt_fs_get_root(fs);
+				if (!unc_subdir || !path_on_fs || !streq_paths(unc_subdir, path_on_fs))
+					continue;

But path_on_fs will be set to "/" on mountinfo if we cannot query root dirs [1]  :

[root@rhel76-2 /]# grep cifs /proc/self/mountinfo
47 39 0:40 / /mnt rw,relatime shared:60 - cifs //rhel73/myshare/sub/path ...
           ^
For good case when we can query up until root :

[root@rhel76-2 /]#  grep cifs /proc/self/mountinfo
47 39 0:40 /sub/path /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.

As as consequence streq_paths will return 0 and we'll skip this entry on mnt_table_is_fs_mounted

This can be reproduce on RHEL8 and probably on upstream. 

I think this commit may help :

From: Roberto Bergantinos Corpas <rbergant>
Date: Wed, 22 Apr 2020 12:27:04 +0200
Subject: [PATCH] fix for EBUSY on cifs mounts

---
 libmount/src/tab.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 3ee9c00..bc11e6a 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -1169,7 +1169,8 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
 			if (strcmp(mnt_fs_get_fstype(fs), "cifs") == 0) {
 				const char *unc_subdir = get_cifs_unc_subdir_path(src);
 				const char *path_on_fs = mnt_fs_get_root(fs);
-				if (!unc_subdir || !path_on_fs || !streq_paths(unc_subdir, path_on_fs))
+				if (!unc_subdir || !path_on_fs || (!streq_paths(unc_subdir, path_on_fs) && 
+							!(streq_paths("/", path_on_fs))))
 					continue;
 			} else {
 				const char *r = mnt_fs_get_root(fs);
-- 
2.21.0


I've tested on RHEL7 for either this issue and 1633657 and neither are reproduced. Not sure if this may trigger
any "false positive" since mount source is already checked here, but im not sure so opening this for review and reporting

Version-Release number of selected component (if applicable):


How reproducible: 100%


Steps to Reproduce: See above
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 3 Karel Zak 2020-04-27 14:04:57 UTC
Thanks Roberto! 

Ported to the upstream repository as http://github.com/karelzak/util-linux/commit/31b3a523eca2fc7e5876ec5fd89094208fed0899

Comment 12 errata-xmlrpc 2020-09-29 20:09:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (util-linux bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:3963