Add -p switch to "zpool get"
[zfs.git] / module / zfs / sa.c
index 91d4074..581cf4b 100644 (file)
@@ -136,7 +136,7 @@ static int sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr,
     sa_data_op_t action, sa_data_locator_t *locator, void *datastart,
     uint16_t buflen, dmu_tx_t *tx);
 
-arc_byteswap_func_t *sa_bswap_table[] = {
+arc_byteswap_func_t sa_bswap_table[] = {
        byteswap_uint64_array,
        byteswap_uint32_array,
        byteswap_uint16_array,
@@ -572,6 +572,7 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
 {
        int var_size = 0;
        int i;
+       int j = -1;
        int full_space;
        int hdrsize;
        boolean_t done = B_FALSE;
@@ -611,7 +612,14 @@ sa_find_sizes(sa_os_t *sa, sa_bulk_attr_t *attr_desc, int attr_count,
                if (is_var_sz && var_size > 1) {
                        if (P2ROUNDUP(hdrsize + sizeof (uint16_t), 8) +
                            *total < full_space) {
+                               /*
+                                * Account for header space used by array of
+                                * optional sizes of variable-length attributes.
+                                * Record the index in case this increase needs
+                                * to be reversed due to spill-over.
+                                */
                                hdrsize += sizeof (uint16_t);
+                               j = i;
                        } else {
                                done = B_TRUE;
                                *index = i;
@@ -640,6 +648,14 @@ next:
                        *will_spill = B_TRUE;
        }
 
+       /*
+        * j holds the index of the last variable-sized attribute for
+        * which hdrsize was increased.  Reverse the increase if that
+        * attribute will be relocated to the spill block.
+        */
+       if (*will_spill && j == *index)
+               hdrsize -= sizeof (uint16_t);
+
        hdrsize = P2ROUNDUP(hdrsize, 8);
        return (hdrsize);
 }