Find out in-depth information about a file in ZFS

When working with ZFS, you probably know that you can change many parameters of a filesystem at runtime, for example the record size. But how do you find out, what record size was used when you created a file. So, how do you find out for example the blocksize of the file? For example if you created those database files before you’ve set the record size of the filesystem to the same as the database or afterwards … as this has an performance impact this an useful information to obtain. Just looking at the recordsize property of zfs doesn’t help you here, as you see the recordsize currently set, not the one set at file creation time.
At first find out the inode number of the object:

jmoekamp@hivemind:/datapool/bibliothek/isos# ls -i sol-11-1111-text-x86.iso<br />
<b><font color="green">1614570</font></b> sol-11-1111-text-x86.iso

Now take the number in front of the filename and gather in-depth information with zdb -dddd <dataset name> <inode number>

# zdb -dddd datapool/bibliothek <b><font color="green">1614570</font></b>
Dataset datapool/bibliothek [ZPL], ID 72, cr_txg 45, 290G,
 701819 objects, rootbp DVA[0]=<0:8200183e00:200> 
 DVA[1]=<0:c600022600:200> [L0 DMU objset] fletcher4 lzjb
 LE contiguous unique double size=800L/200P 
 birth=26695605L/26695605P fill=701819 
 cksum=1ba679a565:8fe1c27eed6:19759bef3e3c4:33579b07e80a94

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
   1614570    3    16K   <font color="red"><b>128K</b></font>   425M   430M   99.97  ZFS plain file
                                        264   bonus  ZFS znode
        dnode flags: USED_BYTES USERUSED_ACCOUNTED
        dnode maxblkid: 3436
        path    /isos/sol-11-1111-text-x86.iso
        uid     101
        gid     10
        atime   Fri Apr 27 16:25:02 2012
        mtime   Tue Dec 20 18:58:43 2011
        ctime   Wed Apr 25 15:00:01 2012
        crtime  Wed Apr 25 14:59:12 2012
        gen     26605871
        mode    100000
        size    450799616
        parent  168872
        links   1
        xattr   1614571
        rdev    0x0000000000000000

As you see, the file has been written with 128k block size. Now we change the recordsize to 8k and copy the file to create an object with the new size.

# zfs recordsize=8k datapool/bibliothek
# cp sol-11-1111-text-x86.iso sol-11-1111-text-x86.iso.8kcopy

Find out the inode number …

# ls -i sol-11-1111-text-x86.iso.8kcopy
<font color="green"><b>508011</b></font> sol-11-1111-text-x86.iso.8kcopy

… and put it into the zdb command line …

# zdb -dd datapool/bibliothek <font color="green"><b>508011</b></font>
Dataset datapool/bibliothek [ZPL], ID 72, cr_txg 45, 291G, 701820 objects

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
    508011    4    16K     <font color="red"><b>8K</b></font>   429M   430M   99.90  ZFS plain file

Voila … this file has been created with 8k.