Commit bde1e5400a1b21ef47932ab00446c7361ff3c139

Authored by Joel Becker
1 parent 11179f2c92

ocfs2: Remove xattrs via ocfs2_xa_loc

Add ocfs2_xa_remove_entry(), which will remove an xattr entry from its
storage via the ocfs2_xa_loc descriptor.

Signed-off-by: Joel Becker <joel.becker@oracle.com>

Showing 1 changed file with 29 additions and 33 deletions Side-by-side Diff

... ... @@ -1573,7 +1573,29 @@
1573 1573  
1574 1574 static void ocfs2_xa_remove_entry(struct ocfs2_xa_loc *loc)
1575 1575 {
  1576 + int index, count;
  1577 + struct ocfs2_xattr_header *xh = loc->xl_header;
  1578 + struct ocfs2_xattr_entry *entry = loc->xl_entry;
  1579 +
1576 1580 ocfs2_xa_wipe_namevalue(loc);
  1581 + loc->xl_entry = NULL;
  1582 +
  1583 + le16_add_cpu(&xh->xh_count, -1);
  1584 + count = le16_to_cpu(xh->xh_count);
  1585 +
  1586 + /*
  1587 + * Only zero out the entry if there are more remaining. This is
  1588 + * important for an empty bucket, as it keeps track of the
  1589 + * bucket's hash value. It doesn't hurt empty block storage.
  1590 + */
  1591 + if (count) {
  1592 + index = ((char *)entry - (char *)&xh->xh_entries) /
  1593 + sizeof(struct ocfs2_xattr_entry);
  1594 + memmove(&xh->xh_entries[index], &xh->xh_entries[index + 1],
  1595 + (count - index) * sizeof(struct ocfs2_xattr_entry));
  1596 + memset(&xh->xh_entries[count], 0,
  1597 + sizeof(struct ocfs2_xattr_entry));
  1598 + }
1577 1599 }
1578 1600  
1579 1601 static void ocfs2_init_dinode_xa_loc(struct ocfs2_xa_loc *loc,
... ... @@ -1638,7 +1660,6 @@
1638 1660 size_t min_offs)
1639 1661 {
1640 1662 size_t name_len = strlen(xi->name);
1641   - int i;
1642 1663 struct ocfs2_xa_loc loc;
1643 1664  
1644 1665 if (xs->xattr_bh == xs->inode_bh)
1645 1666  
... ... @@ -1686,25 +1707,12 @@
1686 1707 return;
1687 1708 }
1688 1709  
1689   - /* Remove the old name+value. */
1690   - ocfs2_xa_wipe_namevalue(&loc);
1691   - xs->here->xe_name_hash = 0;
1692   - xs->here->xe_name_offset = 0;
1693   - ocfs2_xattr_set_local(xs->here, 1);
1694   - xs->here->xe_value_size = 0;
  1710 + if (!xi->value)
  1711 + ocfs2_xa_remove_entry(&loc);
  1712 + else
  1713 + ocfs2_xa_wipe_namevalue(&loc);
1695 1714  
1696 1715 min_offs += size;
1697   -
1698   - if (!xi->value) {
1699   - /* Remove the old entry. */
1700   - i = le16_to_cpu(xs->header->xh_count) - 1;
1701   - last = &xs->header->xh_entries[i];
1702   - xs->header->xh_count = cpu_to_le16(i);
1703   -
1704   - memmove(xs->here, xs->here + 1,
1705   - (void *)last - (void *)xs->here);
1706   - memset(last, 0, sizeof(struct ocfs2_xattr_entry));
1707   - }
1708 1716 }
1709 1717 if (xi->value) {
1710 1718 /* Insert the new name+value. */
1711 1719  
... ... @@ -5001,8 +5009,8 @@
5001 5009 new_size = OCFS2_XATTR_SIZE(name_len) +
5002 5010 OCFS2_XATTR_SIZE(xi->value_len);
5003 5011  
5004   - ocfs2_xa_wipe_namevalue(&loc);
5005 5012 if (xi->value) {
  5013 + ocfs2_xa_wipe_namevalue(&loc);
5006 5014 if (new_size > size)
5007 5015 goto set_new_name_value;
5008 5016  
... ... @@ -5024,20 +5032,8 @@
5024 5032 ocfs2_xattr_set_local(xe, local);
5025 5033 return;
5026 5034 } else {
5027   - /*
5028   - * Remove the old entry if there is more than one.
5029   - * We don't remove the last entry so that we can
5030   - * use it to indicate the hash value of the empty
5031   - * bucket.
5032   - */
5033   - last -= 1;
5034   - le16_add_cpu(&xh->xh_count, -1);
5035   - if (xh->xh_count) {
5036   - memmove(xe, xe + 1,
5037   - (void *)last - (void *)xe);
5038   - memset(last, 0,
5039   - sizeof(struct ocfs2_xattr_entry));
5040   - } else
  5035 + ocfs2_xa_remove_entry(&loc);
  5036 + if (!xh->xh_count)
5041 5037 xh->xh_free_start =
5042 5038 cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE);
5043 5039