Bug 273858

Summary: zfs: a directory can't be removed and nothing can be created in it, but it can be moved
Product: Base System Reporter: Piotr Kubaj <pkubaj>
Component: kernAssignee: freebsd-fs (Nobody) <fs>
Status: Open ---    
Severity: Affects Only Me CC: jfc
Priority: ---    
Version: 13.2-RELEASE   
Hardware: Any   
OS: Any   

Description Piotr Kubaj freebsd_committer freebsd_triage 2023-09-16 15:02:49 UTC
I'm on 13.2-RELEASE. By accident, I had removed /usr/local. I restored it from a backup. However, I discovered that /usr/local/etc/openvpn didn't get restored. I'm not sure whether it was at first even removed.
Now, manually restoring it from .zfs/snapshots doesn't work. cp, rsync etc. don't return error, but the files are not created. Even creating empty files in openvpn directory doesn't cause error, but the files are not created (with touch).
Removing the directory also doesn't return error, but the directory is not removed.
However, it can be moved (also to another directory, but only in the same filesystem) and renamed.
I renamed it to openvpn2.

root@serwer:$/usr/local/etc$ find openvpn2
openvpn2
find: openvpn2: No such file or directory
root@serwer:$/usr/local/etc$ rmdir openvpn2
rmdir: openvpn2: Directory not empty
root@serwer:$/usr/local/etc$ rm -rf openvpn2
root@serwer:$/usr/local/etc$ ls openvpn2
root@serwer:$/usr/local/etc$ touch openvpn2/test
root@serwer:$/usr/local/etc$ ls openvpn2
root@serwer:$/usr/local/etc$ mv openvpn2 /tmp
mv: openvpn2: No such file or directory
mv: /bin/cp openvpn2 /tmp/openvpn2: terminated with 1 (non-zero) status
Comment 1 Piotr Kubaj freebsd_committer freebsd_triage 2023-09-16 21:30:05 UTC
I also tried moving openvpn2 to a newly created directory and removing that directory along with openvpn2. Here's what happened:
root@serwer:$/usr/local/etc$ mkdir tmp
root@serwer:$/usr/local/etc$ mv openvpn2 tmp/
root@serwer:$/usr/local/etc$ ls -l tmp
total 5
drwxr-xr-x  5 root  wheel  11 Sep 16 17:02 openvpn2
root@serwer:$/usr/local/etc$ find tmp
tmp
tmp/openvpn2
find: tmp/openvpn2: No such file or directory
root@serwer:$/usr/local/etc$ rm -rf tmp
rm: tmp: Directory not empty
root@serwer:$/usr/local/etc$ ls -l tmp
total 5
drwxr-xr-x  5 root  wheel  11 Sep 16 17:02 openvpn2
Comment 2 John F. Carr 2023-09-16 23:34:47 UTC
Can you run

stat . openvpn2

so we can see if there are any unusual flags on openvpn2, and whether it is considered to be on the same filesystem as its parent directory?
Comment 3 Piotr Kubaj freebsd_committer freebsd_triage 2023-09-17 05:40:00 UTC
The output is:
9613343378317154166 3880 drwxr-xr-x 22 root wheel 18446744073709551615 55 "Nov 13 19:40:46 2015" "Sep 16 22:08:34 2023" "Sep 16 22:08:34 2023" "Nov 13 19:40:46 2015" 4608 11 0x800 .
9613343378317154166 1783842 drwxr-xr-x 5 root wheel 18446744073709551615 11 "Nov 26 13:26:37 2015" "Sep 16 17:02:01 2023" "Sep 16 22:08:31 2023" "Nov 26 13:26:37 2015" 4096 10 0x800 openvpn2
Comment 4 Piotr Kubaj freebsd_committer freebsd_triage 2023-09-19 11:33:12 UTC
I'm not sure why, but today I managed to remove the openvpn2 directory on the first attempt after not trying since reporting this bug. I'm 100% positive there was an issue, but it seems to be no more.