Skip to content

Commit ba769ea

Browse files
authored
Fix ENOSPC for extended quota
When unlinking multiple files from a pool at 100% capacity, it was possible for ENOSPC to be returned after the first few unlinks. This issue was fixed previously by PR #13172 but then this was again introduced by PR #13839. This is resolved using the existing mechanism of returning ERESTART when over quota as long as we know enough space will shortly be available after processing the pending deferred frees. Also, updated the existing testcase which reliably reproduced the issue without this patch. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Dipak Ghosh <[email protected]> Signed-off-by: Akash B <[email protected]> Closes #15312
1 parent 5551dcd commit ba769ea

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

module/zfs/dsl_dir.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
2727
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
2828
* Copyright (c) 2018, loli10K <[email protected]>. All rights reserved.
29+
* Copyright (c) 2023 Hewlett Packard Enterprise Development LP.
2930
*/
3031

3132
#include <sys/dmu.h>
@@ -1358,30 +1359,23 @@ dsl_dir_tempreserve_impl(dsl_dir_t *dd, uint64_t asize, boolean_t netfree,
13581359
ext_quota = 0;
13591360

13601361
if (used_on_disk >= quota) {
1362+
if (retval == ENOSPC && (used_on_disk - quota) <
1363+
dsl_pool_deferred_space(dd->dd_pool)) {
1364+
retval = SET_ERROR(ERESTART);
1365+
}
13611366
/* Quota exceeded */
13621367
mutex_exit(&dd->dd_lock);
13631368
DMU_TX_STAT_BUMP(dmu_tx_quota);
13641369
return (retval);
13651370
} else if (used_on_disk + est_inflight >= quota + ext_quota) {
1366-
if (est_inflight > 0 || used_on_disk < quota) {
1367-
retval = SET_ERROR(ERESTART);
1368-
} else {
1369-
ASSERT3U(used_on_disk, >=, quota);
1370-
1371-
if (retval == ENOSPC && (used_on_disk - quota) <
1372-
dsl_pool_deferred_space(dd->dd_pool)) {
1373-
retval = SET_ERROR(ERESTART);
1374-
}
1375-
}
1376-
13771371
dprintf_dd(dd, "failing: used=%lluK inflight = %lluK "
1378-
"quota=%lluK tr=%lluK err=%d\n",
1372+
"quota=%lluK tr=%lluK\n",
13791373
(u_longlong_t)used_on_disk>>10,
13801374
(u_longlong_t)est_inflight>>10,
1381-
(u_longlong_t)quota>>10, (u_longlong_t)asize>>10, retval);
1375+
(u_longlong_t)quota>>10, (u_longlong_t)asize>>10);
13821376
mutex_exit(&dd->dd_lock);
13831377
DMU_TX_STAT_BUMP(dmu_tx_quota);
1384-
return (retval);
1378+
return (SET_ERROR(ERESTART));
13851379
}
13861380

13871381
/* We need to up our estimated delta before dropping dd_lock */

tests/zfs-tests/tests/functional/no_space/enospc_rm.ksh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#
1818
# Copyright (c) 2014, 2016 by Delphix. All rights reserved.
1919
# Copyright (c) 2022 by Lawrence Livermore National Security, LLC.
20+
# Copyright (c) 2023 Hewlett Packard Enterprise Development LP.
2021
#
2122

2223
. $STF_SUITE/include/libtest.shlib
@@ -51,11 +52,20 @@ log_must zfs create $TESTPOOL/$TESTFS
5152
log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
5253
log_must zfs set compression=off $TESTPOOL/$TESTFS
5354

54-
log_note "Writing files until ENOSPC."
55+
log_note "Writing Big(1G) files until ENOSPC."
5556
log_mustnot_expect "No space left on device" fio --name=test \
5657
--fallocate=none --rw=write --bs=1M --size=1G --numjobs=4 \
5758
--sync=1 --directory=$TESTDIR/ --group_reporting
5859

60+
log_must rm $TESTDIR/test.*
61+
log_must test -z "$(ls -A $TESTDIR)"
62+
sync_pool $TESTPOOL true
63+
64+
log_note "Writing small(10M) files until ENOSPC."
65+
log_mustnot_expect "No space left on device" fio --name=test \
66+
--fallocate=none --rw=write --bs=1M --size=10M --numjobs=200 \
67+
--sync=1 --directory=$TESTDIR/ --group_reporting
68+
5969
log_must rm $TESTDIR/test.*
6070
log_must test -z "$(ls -A $TESTDIR)"
6171

0 commit comments

Comments
 (0)