zfs: fix sa_modify_attrs handling of variable-sized attributes
- skip length_idx index for a replaced variable-sized attribute - skip length_idx index for a removed variable-sized attribute - also re-arranged code to make sure that length_idx is always incremented for variable-sized attributes - additionally add an assertion that the number of actually produced attributes is the same as the expected number of resulting attributes In cooperation with: Matthew Ahrens <mahrens@delphix.com> Tested by: Trent Nelson <trent@snakebite.org> Reviewed by: Matthew Ahrens <mahrens@delphix.com> (for upstream) To do: get this upstreamed MFC after: 2 weeks
This commit is contained in:
parent
ccb92b3c78
commit
9c5c3cafbd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=240345
@ -1604,8 +1604,11 @@ sa_replace_all_by_template(sa_handle_t *hdl, sa_bulk_attr_t *attr_desc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* add/remove/replace a single attribute and then rewrite the entire set
|
* Add/remove a single attribute or replace a variable-sized attribute value
|
||||||
|
* with a value of a different size, and then rewrite the entire set
|
||||||
* of attributes.
|
* of attributes.
|
||||||
|
* Same-length attribute value replacement (including fixed-length attributes)
|
||||||
|
* is handled more efficiently by the upper layers.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
|
sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
|
||||||
@ -1687,18 +1690,19 @@ sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
|
|||||||
|
|
||||||
attr = idx_tab->sa_layout->lot_attrs[i];
|
attr = idx_tab->sa_layout->lot_attrs[i];
|
||||||
if (attr == newattr) {
|
if (attr == newattr) {
|
||||||
if (action == SA_REMOVE) {
|
/* duplicate attributes are not allowed */
|
||||||
j++;
|
ASSERT(action == SA_REPLACE ||
|
||||||
continue;
|
action == SA_REMOVE);
|
||||||
|
/* must be variable-sized to be replaced here */
|
||||||
|
if (action == SA_REPLACE) {
|
||||||
|
ASSERT(SA_REGISTERED_LEN(sa, attr) == 0);
|
||||||
|
SA_ADD_BULK_ATTR(attr_desc, j, attr,
|
||||||
|
locator, datastart, buflen);
|
||||||
}
|
}
|
||||||
ASSERT(SA_REGISTERED_LEN(sa, attr) == 0);
|
|
||||||
ASSERT(action == SA_REPLACE);
|
|
||||||
SA_ADD_BULK_ATTR(attr_desc, j, attr,
|
|
||||||
locator, datastart, buflen);
|
|
||||||
} else {
|
} else {
|
||||||
length = SA_REGISTERED_LEN(sa, attr);
|
length = SA_REGISTERED_LEN(sa, attr);
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
length = hdr->sa_lengths[length_idx++];
|
length = hdr->sa_lengths[length_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
SA_ADD_BULK_ATTR(attr_desc, j, attr,
|
SA_ADD_BULK_ATTR(attr_desc, j, attr,
|
||||||
@ -1706,6 +1710,8 @@ sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
|
|||||||
(TOC_OFF(idx_tab->sa_idx_tab[attr]) +
|
(TOC_OFF(idx_tab->sa_idx_tab[attr]) +
|
||||||
(uintptr_t)old_data[k]), length);
|
(uintptr_t)old_data[k]), length);
|
||||||
}
|
}
|
||||||
|
if (SA_REGISTERED_LEN(sa, attr) == 0)
|
||||||
|
length_idx++;
|
||||||
}
|
}
|
||||||
if (k == 0 && hdl->sa_spill) {
|
if (k == 0 && hdl->sa_spill) {
|
||||||
hdr = SA_GET_HDR(hdl, SA_SPILL);
|
hdr = SA_GET_HDR(hdl, SA_SPILL);
|
||||||
@ -1723,6 +1729,7 @@ sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
|
|||||||
SA_ADD_BULK_ATTR(attr_desc, j, newattr, locator,
|
SA_ADD_BULK_ATTR(attr_desc, j, newattr, locator,
|
||||||
datastart, buflen);
|
datastart, buflen);
|
||||||
}
|
}
|
||||||
|
ASSERT3U(j, ==, attr_count);
|
||||||
|
|
||||||
error = sa_build_layouts(hdl, attr_desc, attr_count, tx);
|
error = sa_build_layouts(hdl, attr_desc, attr_count, tx);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user