Bug 216637

Summary: kafs breaks west
Product: File System Reporter: Markus Suvanto (markus.suvanto)
Component: OtherAssignee: fs_other
Status: RESOLVED CODE_FIX    
Severity: normal CC: dhowells, jaltman, marc.c.dionne
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 6.1.0-rc2 Subsystem:
Regression: No Bisected commit-id:
Attachments: Reproducer of the bug
Output of command "west &> /tmp/log.txt"
Update reproducer
Python script that show kafs and openafs difference

Description Markus Suvanto 2022-10-29 11:21:01 UTC
Created attachment 303104 [details]
Reproducer of the bug

Kernel version 6.1.0-rc2 


1) Using kafs:
The Zephyr RTOS meta-tool west doesn't work if it is installed under /afs/...
InterruptedError: [Errno 4] Interrupted system call: '/afs/.west'

2) Using openafs or local filesystem:
west works OK

reproducer.sh scrip is in attachment

Usage:
mkdir /afs/chell.com/tmp/foo
cd /afs/chell.com/tmp/foo
cp reproducer.sh .
./reproducer.sh
Comment 1 Markus Suvanto 2023-05-31 15:17:44 UTC
Created attachment 304360 [details]
Output of command "west &> /tmp/log.txt"
Comment 2 Markus Suvanto 2023-05-31 15:41:13 UTC
I tested this again using kernel:
uname -r
6.4.0-rc4-00031-g8b817fded42d
and the problem still exist, see attachment /tmp/log.txt

I think the root cause is this:
Openafs and kafs "stat" behaves differently when path
component is /afs

Openafs client:

   masu@htpc ~ % stat /afs/station.com/.west 
   stat: cannot statx '/afs/station.com/.west': No such file or directory

   masu@htpc ~ % stat /afs/.west            
   stat: cannot statx '/afs/.west': No such file or directory

Note that both path /afs/station.com/.west and /afs/.west
gives the same "No such file or directory"

But using kafs client:

   masu@t470 ~ % stat /afs/station.com/.west 
   stat: cannot statx '/afs/station.com/.west': No such file or directory

   masu@t470 ~ % stat /afs/.west            
   stat: cannot statx '/afs/.west': Required key not available

The second paht gives "Required key not available" and this will break
west 

Fortunately there is easy workaroud of this problem:
Just hard code you path

diff --git a/lib/python3.11/site-packages/west-1.0.99-py3.11.egg/west/util.py b/lib/python3.11/site-packages/west-1.0.99-py3.11.egg/west/util.py
index fd577d3..48e7efe 100644
--- a/lib/python3.11/site-packages/west-1.0.99-py3.11.egg/west/util.py
+++ b/lib/python3.11/site-packages/west-1.0.99-py3.11.egg/west/util.py
@@ -66,19 +66,5 @@ def west_topdir(start: Optional[PathType] = None,
     Like west_dir(), but returns the path to the parent directory of the .west/
     directory instead, where project repositories are stored
     '''
-    cur_dir = pathlib.Path(start or os.getcwd())
+    return "/afs/movesole.com/my_zepry_sdk_path/ncs"
 
-    while True:
-        if (cur_dir / '.west').is_dir():
-            return os.fspath(cur_dir)
-
-        parent_dir = cur_dir.parent
-        if cur_dir == parent_dir:
-            # At the root. Should we fall back?
-            if fall_back and os.environ.get('ZEPHYR_BASE'):
-                return west_topdir(os.environ['ZEPHYR_BASE'],
-                                   fall_back=False)
-            else:
-                raise WestNotFound('Could not find a west workspace '
-                                   'in this or any parent directory')
-        cur_dir = parent_dir
Comment 3 Jeffrey Altman 2023-05-31 17:22:39 UTC
The behavior of openafs and kafs is different in that kafs is attempting to resolve 

  /afs/.west

as a cell named "west" so that it can automount the "root.cell" volume from "west".

On a 6.2.15-200.fc37.x86_64 system in my local environment this is the output I receive:

  [jaltman@host /]$ ls /afs/.west
  ls: cannot open directory '/afs/.west': Destination address required
  [jaltman@host /]$ stat /afs/.west
    File: /afs/.west
    Size: 0               Blocks: 0          IO Block: 4096   directory
  Device: 0,63    Inode: 156         Links: 2
  Access: (0555/dr-xr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
  Context: system_u:object_r:nfs_t:s0
  Access: 2023-05-31 13:11:16.000000000 -0400
  Modify: 2023-05-31 13:11:16.000000000 -0400
  Change: 2023-05-31 13:11:16.000000000 -0400
   Birth: -
  [jaltman@host /]$ stat /afs/kth.se/.west
  stat: cannot statx '/afs/kth.se/.west': No such file or directory

The "ls /afs/.west" is failing with the "Destination address required" because the lookup of the "west" cell returned no endpoints for the cell's location service.  Whereas the "No such file or directory" is returned for `/afs/kth.se/.west` because the kth.se "root.cell" was automounted and there is no directory entry for ".west" in the volume's root directory.

The relevant difference between OpenAFS and kafs is that for OpenAFS /afs is a single device for all cells and AFS volumes in the world.  Whereas with kafs each AFS volume is a unique device.  We can look to see if it is reasonable to map the "Destination address required" or "Required key not available" error to ENOENT when the automount fails.
Comment 4 David Howells 2023-05-31 20:18:31 UTC
What distro are you using?  Do you have the keyutils package installed?  And kafs-client?
Comment 5 Markus Suvanto 2023-05-31 20:58:35 UTC
ke, 2023-05-31 kello 20:18 +0000, bugzilla-daemon@kernel.org kirjoitti:
> https://bugzilla.kernel.org/show_bug.cgi?id=216637
> 
> --- Comment #4 from David Howells (dhowells@redhat.com) ---
> What distro are you using?  Do you have the keyutils package installed?  And
> kafs-client?
> 

Gentoo linux, keyutils is installed from portage

  sys-apps/keyutils
      Latest version available: 1.6.3
      Latest version installed: 1.6.3
      Size of files: 134 KiB
      Homepage:      https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/keyutils.git
      Description:   Linux Key Management Utilities
      License:       GPL-2 LGPL-2.1

Unfortunately gentoo don't offer kafs-client ebuild yet, so I have compiled it from source
git://git.infradead.org/users/dhowells/kafs-client.git
Current version is
commit c7d868e8b343ff04b8fa9ab7cb00e80375002d32 (HEAD -> master, tag: v0.5, origin/master, origin/HEAD)
Comment 6 Markus Suvanto 2023-06-01 08:35:05 UTC
Created attachment 304363 [details]
Update reproducer
Comment 7 Markus Suvanto 2023-06-01 08:47:29 UTC
I updated reproducer.sh to support Fedora 38
I seems that it requires ruamem-yaml python module

dnf install python3-ruamel-yaml.x86_64
Comment 8 Markus Suvanto 2023-12-04 10:03:02 UTC
Created attachment 305535 [details]
Python script that show kafs and openafs difference
Comment 9 Markus Suvanto 2023-12-04 10:16:43 UTC
Unfortunately linux stable 6.6.4
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v6.6.4&id=844a4272a462fb02a5245315258ba5a6808db840

didn't solve entirely my proble.
If tested directory is /afs/.west test
if (cur_dir / '.west').is_dir():
returns true

Attached file util.py show differences between kafs and openafs
cp util.py /afs/movesole.com/tmp/ 
cd /afs/movesole.com/tmp/

openafs:
masu@lab4 tmp % python util.py 
/afs/movesole.com/tmp
/afs/movesole.com/tmp/.west
/afs/movesole.com/tmp
/afs/movesole.com
/afs/movesole.com/.west
/afs/movesole.com
/afs
/afs/.west
/afs
/
/.west
/
/
Use my environment variable


kafs:
masu@t470 tmp % python util.py
/afs/movesole.com/tmp
/afs/movesole.com/tmp/.west
/afs/movesole.com/tmp
/afs/movesole.com
/afs/movesole.com/.west
/afs/movesole.com
/afs
/afs/.west
isdir is true
/afs
Comment 10 Markus Suvanto 2023-12-05 08:25:48 UTC
Reproducer using bash

Openafs:
[ -d "/afs/.west" ] && echo "Directory exists."


kafs:
[ -d "/afs/.west" ] && echo "Directory exists."
Directory exists.
Comment 11 Markus Suvanto 2024-02-15 11:18:10 UTC
Fixed in 6.7

commit 74cef6872ceaefb5b6c5c60641371ea28702d358