openzfs / zfs

OpenZFS on Linux and FreeBSD
https://openzfs.github.io/openzfs-docs
Other
10.68k stars 1.76k forks source link

zfs filesystem skipped by df -h #8253

Closed PaulZ-98 closed 5 years ago

PaulZ-98 commented 5 years ago

Linux Distribution Name | Ubuntu Distribution Version | 16.04 Linux Kernel | 4.10.0-28 Architecture | x86 ZFS Version | 0.8.0-rc2_61_g0f5f238

df -h skips root mount point of pool when pool is full

Create small pool with one child filesystem. Fill the pool by writing to the child filesystem. All the bytes consumed are in the child, so "referenced" statistic of pool root filesystem is very small (< 128k). In zfs_statvfs(), f_blocks becomes zero because the small refdbytes + availbytes (0) gets shifted away.

statp->f_blocks = (refdbytes + availbytes) >> bshift;

And because f_blocks is zero, it is skipped by df -h, unless specified as df -h <filesystem>, in which case it shows all zeroes.

# df -h /datto/array1
Filesystem      Size  Used Avail Use% Mounted on
dattoArray         0     0     0    - /datto/array1
PaulZ-98 commented 5 years ago

Use the MAX macro to ensure f_blocks is at least 1.

-       statp->f_blocks = (refdbytes + availbytes) >> bshift;
+       statp->f_blocks = MAX(1, (refdbytes + availbytes) >> bshift);
PaulZ-98 commented 5 years ago

Actually we decided it is slightly better to round refdbytes up to the filesystem recordsize.