Subject: Re: bug#54286: [PATCH] Fix ls -l triggering automounts.

From: Pádraig Brady <[email-masked]>
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@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@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