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

Caculate header size correctly in sa_find_sizes() #2321

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 8 additions & 6 deletions module/zfs/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
ASSERT(IS_P2ALIGNED(full_space, 8));

for (i = 0; i != attr_count; i++) {
boolean_t is_var_sz;
boolean_t is_var_sz, might_spill_here;

*total = P2ROUNDUP(*total, 8);
*total += attr_desc[i].sa_length;
Expand All @@ -606,6 +606,11 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
var_size++;
}

might_spill_here =
buftype == SA_BONUS && *index == -1 &&
(*total + P2ROUNDUP(hdrsize, 8)) >
(full_space - sizeof (blkptr_t));

if (is_var_sz && var_size > 1) {
/*
* Don't worry that the spill block might overflow.
Expand All @@ -622,7 +627,7 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
* spill-over.
*/
hdrsize += sizeof (uint16_t);
if (*index != -1)
if (*index != -1 || might_spill_here)
extra_hdrsize += sizeof (uint16_t);
} else {
ASSERT(buftype == SA_BONUS);
Expand All @@ -639,11 +644,8 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
* space. The sum is used later for sizing bonus
* and spill buffer.
*/
if (buftype == SA_BONUS && *index == -1 &&
(*total + P2ROUNDUP(hdrsize, 8)) >
(full_space - sizeof (blkptr_t))) {
if (might_spill_here)
*index = i;
}

if ((*total + P2ROUNDUP(hdrsize, 8)) > full_space &&
buftype == SA_BONUS)
Expand Down