GNU bug report logs - #54286
[PATCH] Fix ls -l triggering automounts.

Previous Next

Package: coreutils;

Reported by: Rohan Sable <rsable <at> redhat.com>

Date: Mon, 7 Mar 2022 07:57:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 54286 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#54286; Package coreutils. (Mon, 07 Mar 2022 07:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Rohan Sable <rsable <at> redhat.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 07 Mar 2022 07:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rohan Sable <rsable <at> redhat.com>
To: bug-coreutils <at> gnu.org
Cc: ikent <at> redhat.com, rohanjsable <at> gmail.com, kdudka <at> redhat.com
Subject: [PATCH] Fix ls -l triggering automounts.
Date: Mon, 7 Mar 2022 13:24:02 +0530
Running ls -l on a path that has autofs mounts,
triggers a mount or in case of unmountable shares,
triggers errors :
~~~
[root <at> rsablerhel85 mnt2]# ll
ls: cannot access 'testshare2': No such file or directory     <<<<< Error
total 0
drwxrwxrwx. 3 1000 1000 15 Jan 17 12:08 testshare             <<<<< mount is triggerd for testshare
d?????????? ? ?    ?     ?            ? testshare2            <<<<< Path we know that is inaccessible throws an error

[root <at> rsablerhel85 mnt2]# mount | grep -i test
rsable76server:/testshare on /mnt2/testshare type nfs (rw,relatime,vers=3,rsize=32768,wsize=32768,namlen=255,hard,proto=tcp,timeo=600,retrans=6,sec=sys,mountaddr=192.168.122.58,mountvers=3,mountport=20048,mountproto=tcp,local_lock=none,addr=192.168.122.58)
~~~

Added AT_NO_AUTOMOUNT flag to do_lstat to fix this behavior.

Signed-off-by: Rohan Sable <rsable <at> redhat.com>
---
 src/ls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ls.c b/src/ls.c
index 1930e4abb..bf79ef8b9 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1204,7 +1204,7 @@ do_stat (char const *name, struct stat *st)
 static int
 do_lstat (char const *name, struct stat *st)
 {
-  return do_statx (AT_FDCWD, name, st, AT_SYMLINK_NOFOLLOW, calc_req_mask ());
+  return do_statx (AT_FDCWD, name, st, AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, calc_req_mask ());
 }
 
 static int
-- 
2.34.1





Information forwarded to bug-coreutils <at> gnu.org:
bug#54286; Package coreutils. (Mon, 07 Mar 2022 13:34:02 GMT) Full text and rfc822 format available.

Message #8 received at 54286 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Rohan Sable <rsable <at> redhat.com>, 54286 <at> debbugs.gnu.org
Cc: ikent <at> redhat.com, rohanjsable <at> gmail.com, kdudka <at> redhat.com
Subject: Re: bug#54286: [PATCH] Fix ls -l triggering automounts.
Date: Mon, 7 Mar 2022 13:33:43 +0000
On 07/03/2022 07:54, Rohan Sable wrote:
> Running ls -l on a path that has autofs mounts,
> triggers a mount or in case of unmountable shares,
> triggers errors :
> ~~~
> [root <at> rsablerhel85 mnt2]# ll
> ls: cannot access 'testshare2': No such file or directory     <<<<< Error
> total 0
> drwxrwxrwx. 3 1000 1000 15 Jan 17 12:08 testshare             <<<<< mount is triggerd for testshare
> d?????????? ? ?    ?     ?            ? testshare2            <<<<< Path we know that is inaccessible throws an error
> 
> [root <at> rsablerhel85 mnt2]# mount | grep -i test
> rsable76server:/testshare on /mnt2/testshare type nfs (rw,relatime,vers=3,rsize=32768,wsize=32768,namlen=255,hard,proto=tcp,timeo=600,retrans=6,sec=sys,mountaddr=192.168.122.58,mountvers=3,mountport=20048,mountproto=tcp,local_lock=none,addr=192.168.122.58)
> ~~~
> 
> Added AT_NO_AUTOMOUNT flag to do_lstat to fix this behavior.

Yes we should handle this, but a bit differently I think.

In this and the stat(1) patch you're only doing the adjustment for lstat().
I'd be more inclined to do this for all statx() uses because:
 - stat() and lstat() behave as if AT_NO_AUTOMOUNT is set
   - stat can be significant here for ondemand dirs, bind mounted entries, or network contexts etc.
 - ls(1) and stat(1) are operating on meta-data so should avoid mounts by default

Also we have to provide some ifdef protection around AT_NO_AUTOMOUNT use.
That's best done in gnulib in fcntl.in.h

Also we have related control in the --cached=never option in stat(1),
which is meant to ensure we go the whole way to the source file system,
which maps well with _not_ setting AT_NO_AUTOMOUNT for that case only.

I'll follow up with some patches along those lines.

thanks,
Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#54286; Package coreutils. (Mon, 07 Mar 2022 14:10:02 GMT) Full text and rfc822 format available.

Message #11 received at 54286 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: bug-gnulib <at> gnu.org
Cc: 54286 <at> debbugs.gnu.org, Pádraig Brady <P <at> draigBrady.com>
Subject: [PATCH] fcntl-h: add AT_NO_AUTOMOUNT
Date: Mon,  7 Mar 2022 14:08:51 +0000
* lib/fcntl.in.h: Define AT_NO_AUTOMOUNT to 0 where not defined.
This is available on Linux since 2.6.38.
---
 ChangeLog      | 6 ++++++
 lib/fcntl.in.h | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index c5a80fd3f3..e3f0ed216c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2022-03-07  Pádraig Brady  <P <at> draigBrady.com>
+
+	fcntl-h: add AT_NO_AUTOMOUNT
+	* lib/fcntl.in.h: Define AT_NO_AUTOMOUNT to 0 where not defined.
+	This is available on Linux since 2.6.38.
+
 2022-03-01  Paul Eggert  <eggert <at> cs.ucla.edu>
 
 	Create lib/Makefile.am after gnulib-comp.m4
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index 3e0c302af3..9270ced897 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -435,6 +435,10 @@ _GL_WARN_ON_USE (openat, "openat is not portable - "
 # define AT_EACCESS 4
 #endif
 
+/* Ignore this flag if not supported.  */
+#ifndef AT_NO_AUTOMOUNT
+# define AT_NO_AUTOMOUNT 0
+#endif
 
 #endif /* _ <at> GUARD_PREFIX <at> _FCNTL_H */
 #endif /* _ <at> GUARD_PREFIX <at> _FCNTL_H */
-- 
2.26.2





Information forwarded to bug-coreutils <at> gnu.org:
bug#54286; Package coreutils. (Mon, 07 Mar 2022 14:27:02 GMT) Full text and rfc822 format available.

Message #14 received at 54286 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Rohan Sable <rsable <at> redhat.com>, 54286 <at> debbugs.gnu.org
Cc: ikent <at> redhat.com, rohanjsable <at> gmail.com, kdudka <at> redhat.com
Subject: Re: bug#54286: [PATCH] Fix ls -l triggering automounts.
Date: Mon, 7 Mar 2022 14:26:27 +0000
[Message part 1 (text/plain, inline)]
Updated patch for ls attached as per discussion.
Added a NEWS entry.
[ls-no-automount.patch (text/x-patch, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#54286; Package coreutils. (Mon, 07 Mar 2022 15:52:01 GMT) Full text and rfc822 format available.

Message #17 received at 54286 <at> debbugs.gnu.org (full text, mbox):

From: Kamil Dudka <kdudka <at> redhat.com>
To: Rohan Sable <rsable <at> redhat.com>, 54286 <at> debbugs.gnu.org,
 Pádraig Brady <P <at> draigbrady.com>
Cc: ikent <at> redhat.com, rohanjsable <at> gmail.com
Subject: Re: bug#54286: [PATCH] Fix ls -l triggering automounts.
Date: Mon, 07 Mar 2022 16:51:18 +0100
On Monday, March 7, 2022 3:26:27 PM CET Pádraig Brady wrote:
> Updated patch for ls attached as per discussion.
> Added a NEWS entry.

Works as expected.  Thank you both!

Kamil






Information forwarded to bug-coreutils <at> gnu.org:
bug#54286; Package coreutils. (Mon, 07 Mar 2022 17:16:01 GMT) Full text and rfc822 format available.

Message #20 received at 54286 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 54286 <at> debbugs.gnu.org, bug-gnulib <at> gnu.org
Subject: Re: [PATCH] fcntl-h: add AT_NO_AUTOMOUNT
Date: Mon, 7 Mar 2022 09:14:49 -0800
On 3/7/22 06:08, Pádraig Brady wrote:
> * lib/fcntl.in.h: Define AT_NO_AUTOMOUNT to 0 where not defined.
> This is available on Linux since 2.6.38.

Looks good.

Please feel free to install this sort of thing without waiting for review.




This bug report was last modified 2 years and 72 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.