zfs: correctly calculate dn_bonuslen for saving SAs to disk

Since all attribute values start at 8-byte aligned boundary, we would
previously incorrectly calculate dn_bonuslen if any attribute but the
last had a variable-length value with length not multiple of 8.

Reported by:	Nicolas Rachinsky <fbsd-mas-0@ml.turing-complete.org>
Tested by:	Nicolas Rachinsky <fbsd-mas-0@ml.turing-complete.org>
Reviewed by:	Matthew Ahrens <mahrens@delphix.com> (for upstream)
MFC after:	2 weeks
This commit is contained in:
Andriy Gapon 2012-09-18 08:02:54 +00:00
parent ea559fb573
commit 6ed9e9f32f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=240632

View File

@ -578,7 +578,7 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
for (i = 0; i != attr_count; i++) {
boolean_t is_var_sz;
*total += attr_desc[i].sa_length;
*total += P2ROUNDUP(attr_desc[i].sa_length, 8);
if (done)
goto next;
@ -713,6 +713,8 @@ sa_build_layouts(sa_handle_t *hdl, sa_bulk_attr_t *attr_desc, int attr_count,
length = SA_REGISTERED_LEN(sa, attrs[i]);
if (length == 0)
length = attr_desc[i].sa_length;
else
VERIFY(length == attr_desc[i].sa_length);
if (buf_space < length) { /* switch to spill buffer */
VERIFY(bonustype == DMU_OT_SA);
@ -742,6 +744,7 @@ sa_build_layouts(sa_handle_t *hdl, sa_bulk_attr_t *attr_desc, int attr_count,
if (sa->sa_attr_table[attrs[i]].sa_length == 0) {
sahdr->sa_lengths[len_idx++] = length;
}
VERIFY((uintptr_t)data_start % 8 == 0);
data_start = (void *)P2ROUNDUP(((uintptr_t)data_start +
length), 8);
buf_space -= P2ROUNDUP(length, 8);