ZFS file in a snapshot with a link count of 0

Dave Baukus daveb at spectralogic.com
Thu Jun 21 23:26:11 UTC 2018


On a ZFS running something very close to 11.0-STABLE FreeBSD, I am able to get a
file with a link count of 0 into a snapshot. If this file also has an extattr attached to it then
this file appears to break zfs diff.

The main question is: should a file with a link count of 0 get into the snap shot ?
Here's how I created this scenario:

  1.  Create a file with an extended attr
  2.  Open this file (keep it open - in my example the executable "x" opens the file and sleeps(10000000000))
  3.  delete the file
  4.  snap shot the vol
  5.  close the file (in my example below, kill "x")
  6.  snap shot the vol
  7.  zfs diff snap0 snap1

The gory details:

# Set an extattr and hold the file open:
#
# setextattr user DOGMEAT DogMeatGood  FOO_FILE

# ./x &
[1] 10496
Holding FOO_FILE open until killed fd = 3

# ls -ali
total 206887
 886 drwxr-xr-x   2 root  wheel          7 Jun 21 22:42 .
   4 drwxr-xr-x  31 root  wheel         31 Jun 20 23:07 ..
1029 -rw-r--r--   1 root  wheel         63 Jun 21 22:42 FOO_FILE
 946 -rw-r--r--   1 root  wheel  201326592 Jun 19 21:01 fileX_6452.40
 977 -rw-r--r--   1 root  wheel   10485760 Jun 19 21:01 fileX_6452.71
1028 -rwxr-xr-x   1 root  wheel       7702 Jun 21 22:37 x
1027 -rw-r--r--   1 root  wheel        222 Jun 21 22:37 x.c

# Look at FOO_FILE, its extended attribute directory, and the extended attribute file:
#
# zdb -ddddd pool0/vol0 1029
Dataset pool0/vol0 [ZPL], ID 53, cr_txg 14, 626G, 979 objects, rootbp DVA[0]=<0:3800514800:200> DVA[1]=<1:3200577800:200> [L0 DMU objset] fletcher4 lz4 LE contiguous unique double size=800L/200P birth=22643L/22643P fill=979 cksum=10b45c1a81:5cc3254bb73:1103a2ef78457:22ea3f2c722d9e

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
      1029    1   128K    512    512    512  100.00  ZFS plain file
                                        176   bonus  System attributes
        dnode flags: USED_BYTES USERUSED_ACCOUNTED
        dnode maxblkid: 0
        SA hdrsize 8
        SA layout 3
        path    /D9_0/FOO_FILE
        uid     0
        gid     0
        atime   Thu Jun 21 22:42:09 2018
        mtime   Thu Jun 21 22:42:09 2018
        ctime   Thu Jun 21 22:42:09 2018
        crtime  Thu Jun 21 22:42:09 2018
        gen     22625
        mode    100644
        size    63
        parent  886
        links   1
        pflags  40800000004
        ndacl   3
        xattr   1030
Indirect blocks:
               0 L0 0:3800509400:200 200L/200P F=1 B=22625/22625

                segment [0000000000000000, 0000000000000200) size   512

# zdb -ddddd pool0/vol0 1030
Dataset pool0/vol0 [ZPL], ID 53, cr_txg 14, 626G, 979 objects, rootbp DVA[0]=<0:3800514800:200> DVA[1]=<1:3200577800:200> [L0 DMU objset] fletcher4 lz4 LE contiguous unique double size=800L/200P birth=22643L/22643P fill=979 cksum=10b45c1a81:5cc3254bb73:1103a2ef78457:22ea3f2c722d9e

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
      1030    1   128K    512      0    512  100.00  ZFS directory
                                        168   bonus  System attributes
        dnode flags: USED_BYTES USERUSED_ACCOUNTED
        dnode maxblkid: 0
        SA hdrsize 8
        SA layout 2
        path    /D9_0/FOO_FILE/<xattrdir>
        uid     0
        gid     0
        atime   Thu Jun 21 22:43:41 2018
        mtime   Thu Jun 21 22:43:41 2018
        ctime   Thu Jun 21 22:43:41 2018
        crtime  Thu Jun 21 22:43:41 2018
        gen     22643
        mode    41777
        size    3
        parent  1029
        links   2
        pflags  40800000145
        ndacl   3
        microzap: 512 bytes, 1 entries

                DOGMEAT = 1031 (type: Regular File)
Indirect blocks:
               0 L0 EMBEDDED et=0 200L/34P B=22643

                segment [0000000000000000, 0000000000000200) size   512

# zdb -ddddd pool0/vol0 1031
Dataset pool0/vol0 [ZPL], ID 53, cr_txg 14, 626G, 979 objects, rootbp DVA[0]=<0:3800514800:200> DVA[1]=<1:3200577800:200> [L0 DMU objset] fletcher4 lz4 LE contiguous unique double size=800L/200P birth=22643L/22643P fill=979 cksum=10b45c1a81:5cc3254bb73:1103a2ef78457:22ea3f2c722d9e

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
      1031    1   128K    512    512    512  100.00  ZFS plain file
                                        168   bonus  System attributes
        dnode flags: USED_BYTES USERUSED_ACCOUNTED
        dnode maxblkid: 0
        SA hdrsize 8
        SA layout 2
        path    /D9_0/FOO_FILE/<xattrdir>/DOGMEAT
        uid     0
        gid     0
        atime   Thu Jun 21 22:43:41 2018
        mtime   Thu Jun 21 22:43:41 2018
        ctime   Thu Jun 21 22:43:41 2018
        crtime  Thu Jun 21 22:43:41 2018
        gen     22643
        mode    100600
        size    11
        parent  1030
        links   1
        pflags  40800000005
        ndacl   3
Indirect blocks:
               0 L0 0:3800512600:200 200L/200P F=1 B=22643/22643

                segment [0000000000000000, 0000000000000200) size   512

# Remove the the file and see its link count == 0
# rm FOO_FILE
# zdb -ddddd pool0/vol0 1029
Dataset pool0/vol0 [ZPL], ID 53, cr_txg 14, 626G, 979 objects, rootbp DVA[0]=<0:38005aa600:200> DVA[1]=<1:320060d600:200> [L0 DMU objset] fletcher4 lz4 LE contiguous unique double size=800L/200P birth=22676L/22676P fill=979 cksum=125b37bf6d:64afd9a3daa:121b3638e2986:2445488d0ab9d4

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
      1029    1   128K    512    512    512  100.00  ZFS plain file
                                        176   bonus  System attributes
        dnode flags: USED_BYTES USERUSED_ACCOUNTED
        dnode maxblkid: 0
        SA hdrsize 8
        SA layout 3
        path    ???<object#1029>
        uid     0
        gid     0
        atime   Thu Jun 21 22:42:09 2018
        mtime   Thu Jun 21 22:42:09 2018
        ctime   Thu Jun 21 22:42:09 2018
        crtime  Thu Jun 21 22:42:09 2018
        gen     22625
        mode    100644
        size    63
        parent  886
        links   0
        pflags  40800000004
        ndacl   3
        xattr   1030
Indirect blocks:
               0 L0 0:3800509400:200 200L/200P F=1 B=22625/22625

                segment [0000000000000000, 0000000000000200) size   512

# Snap shot and kill the open
# zfs snap pool0/vol0 at snapF1
# kill %1
[1]+  Terminated              ./x

# See that FOO_FILE is gone from the main data set:
# zdb -ddddd pool0/vol0 1029
Dataset pool0/vol0 [ZPL], ID 53, cr_txg 14, 626G, 976 objects, rootbp DVA[0]=<0:38006c1000:200> DVA[1]=<1:3200724000:200> [L0 DMU objset] fletcher4 lz4 LE contiguous unique double size=800L/200P birth=22682L/22682P fill=976 cksum=1063454a83:5a4275153f9:10626364a67cd:2135ef6bbca8b6

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
zdb: dmu_bonus_hold(1029) failed, errno 2

# See FOO_FILE is in the snapshot with a link count of 0 and that its pathname can not be constructed:
#
# zdb -ddddd pool0/vol0 at snapF1 1029
Dataset pool0/vol0 at snapF1 [ZPL], ID 187, cr_txg 22680, 626G, 979 objects, rootbp DVA[0]=<0:38005aa600:200> DVA[1]=<1:320060d600:200> [L0 DMU objset] fletcher4 lz4 LE contiguous unique double size=800L/200P birth=22676L/22676P fill=979 cksum=125b37bf6d:64afd9a3daa:121b3638e2986:2445488d0ab9d4

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
      1029    1   128K    512    512    512  100.00  ZFS plain file
                                        176   bonus  System attributes
        dnode flags: USED_BYTES USERUSED_ACCOUNTED
        dnode maxblkid: 0
        SA hdrsize 8
        SA layout 3
        path    ???<object#1029>
        uid     0
        gid     0
        atime   Thu Jun 21 22:42:09 2018
        mtime   Thu Jun 21 22:42:09 2018
        ctime   Thu Jun 21 22:42:09 2018
        crtime  Thu Jun 21 22:42:09 2018
        gen     22625
        mode    100644
        size    63
        parent  886
        links   0
        pflags  40800000004
        ndacl   3
        xattr   1030
Indirect blocks:
               0 L0 0:3800509400:200 200L/200P F=1 B=22625/22625

                segment [0000000000000000, 0000000000000200) size   512

# zfs snap pool0/vol0 at snapF2

# See zfs diff fail on the extattr dir associated with FOO_FILE
#
zfs diff pool0/vol0 at snapF1 pool0/vol0 at snapF2
Unable to determine path or stats for object 1030 in pool0/vol0 at snapF1: No such file or directory

--
Dave Baukus



More information about the freebsd-fs mailing list