Page MenuHomeFreeBSD

makefs: zfs dataset mountpoints are considered non-empty
ClosedPublic

Authored by tsoome on Mon, Jul 28, 12:23 PM.
Tags
None
Referenced Files
F125932622: D51593.id159280.diff
Wed, Aug 13, 11:10 AM
Unknown Object (File)
Sun, Aug 10, 3:13 PM
Unknown Object (File)
Sat, Aug 9, 6:07 AM
Unknown Object (File)
Sun, Aug 3, 3:28 AM
Unknown Object (File)
Sat, Aug 2, 9:46 AM
Unknown Object (File)
Tue, Jul 29, 9:02 PM
Unknown Object (File)
Tue, Jul 29, 7:54 PM
Unknown Object (File)
Tue, Jul 29, 5:59 AM
Subscribers

Details

Summary

The dataset mountpoints get link count and size calculated by
content of dataset root directory, but this will break libzfs
dir_is_empty_stat() test.

For fix, we need to check if the directory is mountpoint for
dataset, and calculate the link count and size accordingly.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

tsoome retitled this revision from makefs: zfs dataset mountpoints are considered not empty to makefs: zfs dataset mountpoints are considered non-empty.Mon, Jul 28, 12:55 PM

Could you please describe the problematic scenario? I'd like to add a regression test for it.

Could you please describe the problematic scenario? I'd like to add a regression test for it.

this one is tricky;) because it is not revealed in FreeBSD. With illumos:

root@balrog:/home/tsoome# lofiadm -a proto.zpool 
/dev/lofi/1
root@balrog:/home/tsoome# zpool import -d /dev/rlofi -R /mnt zroot
cannot mount '/mnt/usr': directory is not empty
root@balrog:/home/tsoome# ls -la /mnt/usr
total 26
drwxr-xr-x  34 pynfs    1001          45 juuli 16 11:02 .
drwxr-xr-x  23 pynfs    1001          26 juuli 28 20:06 ..
root@balrog:/home/tsoome# ls -lid /mnt/usr
      7347 drwxr-xr-x  34 pynfs    1001          45 juuli 16 11:02 /mnt/usr
root@balrog:/home/tsoome# 
root@balrog:/home/tsoome# zdb -bbbb -dddd -vvvvv -e -p /dev/rlofi/  zroot/ROOT/default 7347
Dataset zroot/ROOT/default [ZPL], ID 30, cr_txg 3, 392M, 50 objects, rootbp DVA[0]=<0:5809b000:1000> DVA[1]=<0:5809c000:1000> [L0 DMU objset] fletcher4 uncompressed unencrypted LE contiguous unique double size=1000L/1000P birth=14L/14P fill=50 cksum=8e1880a04:1c68d9c87576:2f362835924373:36157f932b07e846

    Object  lvl   iblk   dblk  dsize  dnsize  lsize   %full  type
      7347    1   128K     4K     4K    512     4K  100.00  ZFS directory (K=fletcher4) (Z=inherit)
                                               168   bonus  System attributes
        dnode flags: USED_BYTES 
        dnode maxblkid: 0
        path    /usr
        uid     1001
        gid     1001
        atime   Wed Jul 16 11:02:42 2025
        mtime   Wed Jul 16 11:02:42 2025
        ctime   Fri Jul 25 20:04:55 2025
        crtime  Wed Jul 16 11:02:42 2025
        gen     1
        mode    40755
        size    45
        parent  5
        links   34
        pflags  40800000044
        microzap: 4096 bytes, 0 entries

Indirect blocks:
               0 L0 DVA[0]=<0:831f000:1000> [L0 ZFS directory] fletcher4 uncompressed unencrypted LE contiguous unique single size=1000L/1000P birth=4L/4P fill=1 cksum=c7270b7e:31b709091f0:63618b63465af:849282bb35ff4e6

                segment [0000000000000000, 0000000000001000) size    4K

So, indeed, it is created with nlinks 34 and size 45 ("normal" empty directory should have 2 links and size 2). Using overlay mount:

root@balrog:/home/tsoome# zfs mount -O zroot/ROOT/default/usr
root@balrog:/home/tsoome# ls -lid /mnt/usr
         5 drwxr-xr-x  33 pynfs    1001          44 juuli 16 11:02 /mnt/usr

And with fix applied:

root@balrog:/home/tsoome# lofiadm -a proto.zpool 
/dev/lofi/1
root@balrog:/home/tsoome# zpool import -d /dev/rlofi -R /mnt zroot
root@balrog:/home/tsoome# ls -ld /mnt/usr
drwxr-xr-x  33 1000     staff         44 juuli 16 11:02 /mnt/usr
root@balrog:/home/tsoome# ls -ldi /mnt/usr
         5 drwxr-xr-x  33 1000     staff         44 juuli 16 11:02 /mnt/usr
root@balrog:/home/tsoome# zfs umount zroot/ROOT/default/usr
root@balrog:/home/tsoome# ls -ldi /mnt/usr
     10617 drwxr-xr-x   2 1000     staff          2 juuli 16 11:02 /mnt/usr
root@balrog:/home/tsoome# 
root@balrog:/home/tsoome# zdb -bbbb -dddd -vvvvv -e -p /dev/rlofi/  zroot/ROOT/default 10617
Dataset zroot/ROOT/default [ZPL], ID 30, cr_txg 3, 392M, 50 objects, rootbp DVA[0]=<0:5337d000:1000> DVA[1]=<0:5809e000:1000> [L0 DMU objset] fletcher4 uncompressed unencrypted LE contiguous unique double size=1000L/1000P birth=14L/14P fill=50 cksum=a7a65b7d2:1f9e00393b50:31f3613496a5d8:36ebe93c4db0e7f3

    Object  lvl   iblk   dblk  dsize  dnsize  lsize   %full  type
     10617    1   128K     4K     4K    512     4K  100.00  ZFS directory (K=fletcher4) (Z=inherit)
                                               168   bonus  System attributes
        dnode flags: USED_BYTES 
        dnode maxblkid: 0
        path    /usr
        uid     1000
        gid     10
        atime   Wed Jul 16 11:02:42 2025
        mtime   Wed Jul 16 11:02:42 2025
        ctime   Wed Jul 16 11:02:42 2025
        crtime  Wed Jul 16 11:02:42 2025
        gen     1
        mode    40755
        size    2
        parent  5
        links   2
        pflags  40800000044
        microzap: 4096 bytes, 0 entries

Indirect blocks:
               0 L0 DVA[0]=<0:18272000:1000> [L0 ZFS directory] fletcher4 uncompressed unencrypted LE contiguous unique single size=1000L/1000P birth=4L/4P fill=1 cksum=f5f5456f:3d60b8ccda7:7aa71237b866e:a38f36b4dc3367f

                segment [0000000000000000, 0000000000001000) size    4K

root@balrog:/home/tsoome#

I understand now, thank you.

usr.sbin/makefs/zfs/fs.c
409
This revision is now accepted and ready to land.Tue, Jul 29, 7:59 PM

Hmm, I see a couple of test failures with this change. Please hold off on pushing until I report back.

Hmm, I see a couple of test failures with this change. Please hold off on pushing until I report back.

It's unrelated. There is a race which arises when tests are run in parallel and zfs.ko is not loaded initially. Please go ahead.