From owner-svn-src-head@FreeBSD.ORG Tue Sep 11 07:07:53 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 011A1106564A; Tue, 11 Sep 2012 07:07:53 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D596A8FC0A; Tue, 11 Sep 2012 07:07:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q8B77qKR098065; Tue, 11 Sep 2012 07:07:52 GMT (envelope-from avg@svn.freebsd.org) Received: (from avg@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q8B77qBh098063; Tue, 11 Sep 2012 07:07:52 GMT (envelope-from avg@svn.freebsd.org) Message-Id: <201209110707.q8B77qBh098063@svn.freebsd.org> From: Andriy Gapon Date: Tue, 11 Sep 2012 07:07:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r240345 - head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Sep 2012 07:07:53 -0000 Author: avg Date: Tue Sep 11 07:07:52 2012 New Revision: 240345 URL: http://svn.freebsd.org/changeset/base/240345 Log: 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 Tested by: Trent Nelson Reviewed by: Matthew Ahrens (for upstream) To do: get this upstreamed MFC after: 2 weeks Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sa.c Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sa.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sa.c Tue Sep 11 06:26:20 2012 (r240344) +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sa.c Tue Sep 11 07:07:52 2012 (r240345) @@ -1604,8 +1604,11 @@ sa_replace_all_by_template(sa_handle_t * } /* - * 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. + * Same-length attribute value replacement (including fixed-length attributes) + * is handled more efficiently by the upper layers. */ static int sa_modify_attrs(sa_handle_t *hdl, sa_attr_type_t newattr, @@ -1687,18 +1690,19 @@ sa_modify_attrs(sa_handle_t *hdl, sa_att attr = idx_tab->sa_layout->lot_attrs[i]; if (attr == newattr) { - if (action == SA_REMOVE) { - j++; - continue; + /* duplicate attributes are not allowed */ + ASSERT(action == SA_REPLACE || + 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 { length = SA_REGISTERED_LEN(sa, attr); if (length == 0) { - length = hdr->sa_lengths[length_idx++]; + length = hdr->sa_lengths[length_idx]; } SA_ADD_BULK_ATTR(attr_desc, j, attr, @@ -1706,6 +1710,8 @@ sa_modify_attrs(sa_handle_t *hdl, sa_att (TOC_OFF(idx_tab->sa_idx_tab[attr]) + (uintptr_t)old_data[k]), length); } + if (SA_REGISTERED_LEN(sa, attr) == 0) + length_idx++; } if (k == 0 && hdl->sa_spill) { hdr = SA_GET_HDR(hdl, SA_SPILL); @@ -1723,6 +1729,7 @@ sa_modify_attrs(sa_handle_t *hdl, sa_att SA_ADD_BULK_ATTR(attr_desc, j, newattr, locator, datastart, buflen); } + ASSERT3U(j, ==, attr_count); error = sa_build_layouts(hdl, attr_desc, attr_count, tx);