cifsd-team / ksmbd

ksmbd kernel server(SMB/CIFS server)
154 stars 23 forks source link

btrfs: Directories in subvolumes appear as files on SMB client #596

Open riobard opened 1 year ago

riobard commented 1 year ago

Symptom

Some (not all) directories in btrfs subvolumes on ksmbd servers appear as files when mounted over SMB on Windows and macOS clients.

On ksmbd server

# cat /etc/ksmbd/ksmbd.conf
[global]
    guest account = nobody
    map to guest = never
    server min protocol = SMB3
    smb3 encryption = mandatory

[Public]
    path = /mnt/raid/shares/Public
    guest ok = yes

[root]
    path = /
    read only = yes
# ls -lh /mnt/raid/shares/Public
drwxr-sr-x 1 smbuser  smbuser 1.3K Jul 22 01:21  Dir1
drwxr-sr-x 1 smbuser  smbuser 1.1K Jan 30  2022  Dir2

Note that the leading d indicates both Dir1 and Dir2 are (real) directories, however their parent /mnt/raid/shares/Public and grandparent /mnt/raid/shares are both btrfs subvolumes. The root of the btrfs filesystem is mounted at /mnt/raid.

# btrfs subvolume list /mnt/raid
ID 32501 gen 3395407 top level 5 path shares
ID 52405 gen 3483274 top level 32501 path shares/Public

On Windows/macOS client after mounting the share over SMB3, Dir2 somehow becomes a file, e.g. on macOS

% ls -lh /Volumes/Public
drwx------  1 test  staff    16K Jul 22 01:21 Dir1
-rwx------  1 test  staff     0B Jan 30  2022 Dir2

Note the missing leading d for Dir2. Additionally on macOS, attempting to list /Volumes/root/mnt/raid causes Terminal.app to stuck and Finder.app to beachball (application not responding).

None of the above happens with Samba server.

Environment

Related

https://github.com/cifsd-team/ksmbd/issues/556 looks related and also involves btrfs subvolumes, but its symptom is different from this one.

https://lwn.net/Articles/866582/ might give some clues but I don't really understand the underlying mechanisms.

Please let me know how I could further investigate and provide additional information to pinpoint the root cause.

Thanks very much!

namjaejeon commented 1 year ago

If you could simply tell me how to configure the btrfs subvolume, it would be very helpful for me to quickly reproduce this problem.

riobard commented 1 year ago

You could find many tutorials online to setup btrfs filesystem and subvolumes, e.g. https://linuxhint.com/create-mount-btrfs-subvolumes/

The difficult part is that I'm unable to reliably reproduce the behavior. The directory-shown-as-file symptom seems a result of interaction between btrfs subvolumes with snapshots and ksmbd (recall that samba does not have this problem), but I cannot just create new directories to reproduce the symptom (though existing problematic directories can reliably be shown as files on clients). It might have something to do with non-unique inode numbers as the article (https://lwn.net/Articles/866582/) suggests, or it might be some other problems.

I was hoping you could provide me some directions or tools to further investigate, as the issue seems pretty intricate to trigger.

namjaejeon commented 1 year ago

Okay. Let me check it.