Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZAP: Fix leaf references on zap_expand_leaf() errors #16159

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions module/zfs/zap.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
uint64_t object = zap->zap_object;

zap_put_leaf(l);
*lp = l = NULL;
zap_unlockdir(zap, tag);
err = zap_lockdir(os, object, tx, RW_WRITER,
FALSE, FALSE, tag, &zn->zn_zap);
Expand Down Expand Up @@ -920,21 +921,17 @@ fzap_add_cd(zap_name_t *zn,
} else if (err == EAGAIN) {
err = zap_expand_leaf(zn, l, tag, tx, &l);
zap = zn->zn_zap; /* zap_expand_leaf() may change zap */
if (err == 0) {
if (err == 0)
goto retry;
} else if (err == ENOSPC) {
/*
* If we failed to expand the leaf, then bailout
* as there is no point trying
* zap_put_leaf_maybe_grow_ptrtbl().
*/
return (err);
}
}

out:
if (zap != NULL)
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
if (l != NULL) {
if (err == ENOSPC)
zap_put_leaf(l);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not a review, I'm trying to understand this)

it gets here because it was zap_grow_ptrtbl which returned ENOSPC; when can that happen? a) the ZAP is way too large (2^46 entries, right?) and b) on transition from 2^28 to 2^48 zap_hashbits, that is when upgrading from micro to fat zap? Is there any other case that I'm missing why ENOSPC can happen here?

I mean, I'm trying to understand which separate two leaves does the zap_put_leaf get called for and whether that could cause additional trouble - this is the second occasion, the first is on line 713.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've primarily just refactored already present code. I was actually thinking about actual out of space, but it seems not checked at this point, and you seem right that hash size limit may be the primary (and pretty unlikely) factor.

zap_expand_leaf() puts one leaf inside, while another (where the entry is going to be inserted) returns to the caller. So it is the leaf that gets new entry is checked for coming overflow and possible hash table grow. I.e. I see no problems, unless you specify better.

else
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
}
return (err);
}

Expand Down Expand Up @@ -991,8 +988,12 @@ fzap_update(zap_name_t *zn,
goto retry;
}

if (zap != NULL)
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
if (l != NULL) {
if (err == ENOSPC)
zap_put_leaf(l);
else
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
}
return (err);
}

Expand Down
Loading