Skip to content

Commit

Permalink
zfs filesystem skipped by df -h
Browse files Browse the repository at this point in the history
On full pool when pool root filesystem references very few bytes,
the f_blocks returned to statvfs is 0 but should be at least 1.

Signed-off-by: Paul Zuchowski <pzuchowski@datto.com>
Fixes #8253
  • Loading branch information
PaulZ-98 committed Jan 9, 2019
1 parent 0f5f238 commit 07d9944
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion module/zfs/zfs_vfsops.c
Expand Up @@ -1448,7 +1448,7 @@ zfs_statvfs(struct dentry *dentry, struct kstatfs *statp)
* the file system, but reported in terms of f_bsize - the
* "preferred" size.
*/

refdbytes = P2ROUNDUP(refdbytes, statp->f_bsize);
statp->f_blocks = (refdbytes + availbytes) >> bshift;
statp->f_bfree = availbytes >> bshift;
statp->f_bavail = statp->f_bfree; /* no root reservation */
Expand Down
3 changes: 2 additions & 1 deletion tests/runfiles/linux.run
Expand Up @@ -656,7 +656,8 @@ tests = ['nestedfs_001_pos']
tags = ['functional', 'nestedfs']

[tests/functional/no_space]
tests = ['enospc_001_pos', 'enospc_002_pos', 'enospc_003_pos']
tests = ['enospc_001_pos', 'enospc_002_pos', 'enospc_003_pos',
'enospc_df']
tags = ['functional', 'no_space']

[tests/functional/nopwrite]
Expand Down
3 changes: 2 additions & 1 deletion tests/zfs-tests/tests/functional/no_space/Makefile.am
Expand Up @@ -4,7 +4,8 @@ dist_pkgdata_SCRIPTS = \
cleanup.ksh \
enospc_001_pos.ksh \
enospc_002_pos.ksh \
enospc_003_pos.ksh
enospc_003_pos.ksh \
enospc_df.ksh

dist_pkgdata_DATA = \
enospc.cfg
72 changes: 72 additions & 0 deletions tests/zfs-tests/tests/functional/no_space/enospc_df.ksh
@@ -0,0 +1,72 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#

#
# Copyright (c) 2014, 2016 by Delphix. All rights reserved.
# Copyright (c) 2019 by Datto Inc. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/no_space/enospc.cfg

#
# DESCRIPTION:
# After filling a filesystem, the df command produces the
# expected result against the pool root filesystem.
#

verify_runnable "both"

function cleanup
{
log_must_busy zpool destroy -f $TESTPOOL
}

log_onexit cleanup

log_assert "ENOSPC is returned when file system is full."

default_setup_noexit $DISK_SMALL
log_must zfs set compression=off $TESTPOOL/$TESTFS
log_must zfs snapshot $TESTPOOL/$TESTFS@snap

#
# Completely fill the pool in order to ensure the commands below will more
# reliably succeed or fail as a result of lack of space. Care is taken to
# force multiple transaction groups to ensure as many recently freed blocks
# as possible are reallocated.
#
log_note "Writing files until ENOSPC."

for i in $(seq 30); do
file_write -o create -f $TESTDIR/file.$i -b $BLOCKSZ \
-c $NUM_WRITES -d $DATA
ret=$?
(( $ret != $ENOSPC )) && \
log_fail "file.$i returned: $ret rather than ENOSPC."

log_must zpool sync -f
done

log_must zfs umount $TESTPOOL/$TESTFS
log_must eval "df -h |grep $TESTPOOL"
size=$(df -h /$TESTPOOL |grep $TESTPOOL | awk '{print $2}')
used=$(df -h /$TESTPOOL |grep $TESTPOOL | awk '{print $3}')
if [[ $size = "0" ]] || [[ $used = "0" ]]
then
log_fail "df failed with zero filesystem bytes used"
fi
log_pass "df after ENOSPC works as expected."

0 comments on commit 07d9944

Please sign in to comment.