1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2014, 2016 by Delphix. All rights reserved.
19# Copyright (c) 2019 by Datto Inc. All rights reserved.
20#
21
22. $STF_SUITE/include/libtest.shlib
23. $STF_SUITE/tests/functional/no_space/enospc.cfg
24
25#
26# DESCRIPTION:
27# After filling a filesystem, the df command produces the
28# expected result against the pool root filesystem.
29#
30# STRATEGY:
31# 1. Write a file until the child file system is full.
32# 2. Ensure that ENOSPC is returned.
33# 3. Unmount the child file system.
34# 4. Issue df -h command.
35# 5. Ensure pool root filesystem is included (issue #8253).
36# 6. Issue df -h <filesystem>.
37# 7. Ensure size and used are non-zero.
38#
39
40verify_runnable "both"
41
42log_onexit default_cleanup_noexit
43
44log_assert "Correct df output is returned when file system is full."
45
46default_setup_noexit $DISK_SMALL
47log_must zfs set compression=off $TESTPOOL/$TESTFS
48
49log_note "Writing file: $TESTFILE0 until ENOSPC."
50file_write -o create -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \
51    -c $NUM_WRITES -d $DATA
52ret=$?
53
54(( $ret != $ENOSPC )) && \
55    log_fail "$TESTFILE0 returned: $ret rather than ENOSPC."
56
57log_must zfs umount $TESTPOOL/$TESTFS
58
59# Ensure the pool root filesystem shows in df output.
60# If the pool was full (available == 0) and the pool
61# root filesystem had very little in it (used < 1 block),
62# the size reported to df was zero (issue #8253) and
63# df skipped the filesystem in its output.
64log_must eval "df -h | grep $TESTPOOL"
65
66# Confirm df size and used are non-zero.
67size=$(df -h /$TESTPOOL | awk -v p=$TESTPOOL '$0 ~ p {print $2}')
68used=$(df -h /$TESTPOOL | awk -v p=$TESTPOOL '$0 ~ p {print $3}')
69if [[ "$size" = "0" ]] || [[ "$used" = "0" ]]
70then
71	log_fail "df failed with size $size and used $used."
72fi
73log_pass "df after ENOSPC works as expected."
74