Browse files

Fix dnode_hold() freeing dnode behavior

Commit 4c5b89f refactored dnode_hold() and in the process
accidentally introduced a slight change in behavior which was
not intended.  The required behavior is that once the ZPL,
or other consumer, declares its intent to free a dnode then
dnode_hold() should immediately start failing.  This updated
code wouldn't return the failure until after it was freed.

When DNODE_MUST_BE_ALLOCATED is set it must return ENOENT, and
when DNODE_MUST_BE_FREE is set it must return EEXIST;

This issue was uncovered by ztest_remap() which attempted
to remap a freeing object which should have been skipped as
described by the comment in dmu_objset_remap_indirects_impl().

Reviewed-by: George Melikov <>
Reviewed-by: Tom Caputi <>
Reviewed-by: Olaf Faaland <>
Signed-off-by: Brian Behlendorf <>
Closes #8172
  • Loading branch information...
behlendorf committed Dec 5, 2018
1 parent c5eea0a commit 78e21394679ed7435f9b0d10a56ce4f679c680fe
Showing with 4 additions and 2 deletions.
  1. +4 −2 module/zfs/dnode.c
@@ -1253,8 +1253,10 @@ dnode_buf_evict_async(void *dbu)
* EINVAL - Invalid object number or flags.
* ENOSPC - Hole too small to fulfill "slots" request (DNODE_MUST_BE_FREE)
* EEXIST - Refers to an allocated dnode (DNODE_MUST_BE_FREE)
* - Refers to a freeing dnode (DNODE_MUST_BE_FREE)
* - Refers to an interior dnode slot (DNODE_MUST_BE_ALLOCATED)
* ENOENT - The requested dnode is not allocated (DNODE_MUST_BE_ALLOCATED)
* - The requested dnode is being freed (DNODE_MUST_BE_ALLOCATED)
* EIO - I/O error when reading the meta dnode dbuf.
* succeeds even for free dnodes.
@@ -1443,7 +1445,7 @@ dnode_hold_impl(objset_t *os, uint64_t object, int flag, int slots,
if (dn->dn_type == DMU_OT_NONE) {
if (dn->dn_type == DMU_OT_NONE || dn->dn_free_txg != 0) {
dnode_slots_rele(dnc, idx, slots);
@@ -1502,7 +1504,7 @@ dnode_hold_impl(objset_t *os, uint64_t object, int flag, int slots,
if (!zfs_refcount_is_zero(&dn->dn_holds)) {
if (!zfs_refcount_is_zero(&dn->dn_holds) || dn->dn_free_txg) {
dnode_slots_rele(dnc, idx, slots);

0 comments on commit 78e2139

Please sign in to comment.