Commit 517c2220 authored by Dave Chinner's avatar Dave Chinner Committed by Ben Myers

xfs: add CRCs to attr leaf blocks

Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBen Myers <bpm@sgi.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent f5ea1100
...@@ -819,7 +819,7 @@ xfs_attr_inactive(xfs_inode_t *dp) ...@@ -819,7 +819,7 @@ xfs_attr_inactive(xfs_inode_t *dp)
error = 0; error = 0;
goto out; goto out;
} }
error = xfs_attr_root_inactive(&trans, dp); error = xfs_attr3_root_inactive(&trans, dp);
if (error) if (error)
goto out; goto out;
...@@ -905,7 +905,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -905,7 +905,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
*/ */
dp = args->dp; dp = args->dp;
args->blkno = 0; args->blkno = 0;
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
if (error) if (error)
return error; return error;
...@@ -913,14 +913,14 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -913,14 +913,14 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
* Look up the given attribute in the leaf block. Figure out if * Look up the given attribute in the leaf block. Figure out if
* the given flags produce an error or call for an atomic rename. * the given flags produce an error or call for an atomic rename.
*/ */
retval = xfs_attr_leaf_lookup_int(bp, args); retval = xfs_attr3_leaf_lookup_int(bp, args);
if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) { if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
xfs_trans_brelse(args->trans, bp); xfs_trans_brelse(args->trans, bp);
return(retval); return retval;
} else if (retval == EEXIST) { } else if (retval == EEXIST) {
if (args->flags & ATTR_CREATE) { /* pure create op */ if (args->flags & ATTR_CREATE) { /* pure create op */
xfs_trans_brelse(args->trans, bp); xfs_trans_brelse(args->trans, bp);
return(retval); return retval;
} }
trace_xfs_attr_leaf_replace(args); trace_xfs_attr_leaf_replace(args);
...@@ -936,7 +936,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -936,7 +936,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
* Add the attribute to the leaf block, transitioning to a Btree * Add the attribute to the leaf block, transitioning to a Btree
* if required. * if required.
*/ */
retval = xfs_attr_leaf_add(bp, args); retval = xfs_attr3_leaf_add(bp, args);
if (retval == ENOSPC) { if (retval == ENOSPC) {
/* /*
* Promote the attribute list to the Btree format, then * Promote the attribute list to the Btree format, then
...@@ -944,7 +944,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -944,7 +944,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
* can manage its own transactions. * can manage its own transactions.
*/ */
xfs_bmap_init(args->flist, args->firstblock); xfs_bmap_init(args->flist, args->firstblock);
error = xfs_attr_leaf_to_node(args); error = xfs_attr3_leaf_to_node(args);
if (!error) { if (!error) {
error = xfs_bmap_finish(&args->trans, args->flist, error = xfs_bmap_finish(&args->trans, args->flist,
&committed); &committed);
...@@ -1009,7 +1009,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -1009,7 +1009,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
* In a separate transaction, set the incomplete flag on the * In a separate transaction, set the incomplete flag on the
* "old" attr and clear the incomplete flag on the "new" attr. * "old" attr and clear the incomplete flag on the "new" attr.
*/ */
error = xfs_attr_leaf_flipflags(args); error = xfs_attr3_leaf_flipflags(args);
if (error) if (error)
return(error); return(error);
...@@ -1031,19 +1031,19 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -1031,19 +1031,19 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
* Read in the block containing the "old" attr, then * Read in the block containing the "old" attr, then
* remove the "old" attr from that block (neat, huh!) * remove the "old" attr from that block (neat, huh!)
*/ */
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
-1, &bp); -1, &bp);
if (error) if (error)
return error; return error;
xfs_attr_leaf_remove(bp, args); xfs_attr3_leaf_remove(bp, args);
/* /*
* If the result is small enough, shrink it all into the inode. * If the result is small enough, shrink it all into the inode.
*/ */
if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
xfs_bmap_init(args->flist, args->firstblock); xfs_bmap_init(args->flist, args->firstblock);
error = xfs_attr_leaf_to_shortform(bp, args, forkoff); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
/* bp is gone due to xfs_da_shrink_inode */ /* bp is gone due to xfs_da_shrink_inode */
if (!error) { if (!error) {
error = xfs_bmap_finish(&args->trans, error = xfs_bmap_finish(&args->trans,
...@@ -1075,9 +1075,9 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) ...@@ -1075,9 +1075,9 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
/* /*
* Added a "remote" value, just clear the incomplete flag. * Added a "remote" value, just clear the incomplete flag.
*/ */
error = xfs_attr_leaf_clearflag(args); error = xfs_attr3_leaf_clearflag(args);
} }
return(error); return error;
} }
/* /*
...@@ -1100,24 +1100,24 @@ xfs_attr_leaf_removename(xfs_da_args_t *args) ...@@ -1100,24 +1100,24 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
*/ */
dp = args->dp; dp = args->dp;
args->blkno = 0; args->blkno = 0;
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
if (error) if (error)
return error; return error;
error = xfs_attr_leaf_lookup_int(bp, args); error = xfs_attr3_leaf_lookup_int(bp, args);
if (error == ENOATTR) { if (error == ENOATTR) {
xfs_trans_brelse(args->trans, bp); xfs_trans_brelse(args->trans, bp);
return(error); return error;
} }
xfs_attr_leaf_remove(bp, args); xfs_attr3_leaf_remove(bp, args);
/* /*
* If the result is small enough, shrink it all into the inode. * If the result is small enough, shrink it all into the inode.
*/ */
if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
xfs_bmap_init(args->flist, args->firstblock); xfs_bmap_init(args->flist, args->firstblock);
error = xfs_attr_leaf_to_shortform(bp, args, forkoff); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
/* bp is gone due to xfs_da_shrink_inode */ /* bp is gone due to xfs_da_shrink_inode */
if (!error) { if (!error) {
error = xfs_bmap_finish(&args->trans, args->flist, error = xfs_bmap_finish(&args->trans, args->flist,
...@@ -1127,7 +1127,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args) ...@@ -1127,7 +1127,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
ASSERT(committed); ASSERT(committed);
args->trans = NULL; args->trans = NULL;
xfs_bmap_cancel(args->flist); xfs_bmap_cancel(args->flist);
return(error); return error;
} }
/* /*
...@@ -1137,7 +1137,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args) ...@@ -1137,7 +1137,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
if (committed) if (committed)
xfs_trans_ijoin(args->trans, dp, 0); xfs_trans_ijoin(args->trans, dp, 0);
} }
return(0); return 0;
} }
/* /*
...@@ -1155,21 +1155,21 @@ xfs_attr_leaf_get(xfs_da_args_t *args) ...@@ -1155,21 +1155,21 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
trace_xfs_attr_leaf_get(args); trace_xfs_attr_leaf_get(args);
args->blkno = 0; args->blkno = 0;
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
if (error) if (error)
return error; return error;
error = xfs_attr_leaf_lookup_int(bp, args); error = xfs_attr3_leaf_lookup_int(bp, args);
if (error != EEXIST) { if (error != EEXIST) {
xfs_trans_brelse(args->trans, bp); xfs_trans_brelse(args->trans, bp);
return(error); return error;
} }
error = xfs_attr_leaf_getvalue(bp, args); error = xfs_attr3_leaf_getvalue(bp, args);
xfs_trans_brelse(args->trans, bp); xfs_trans_brelse(args->trans, bp);
if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) { if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
error = xfs_attr_rmtval_get(args); error = xfs_attr_rmtval_get(args);
} }
return(error); return error;
} }
/* /*
...@@ -1184,11 +1184,11 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context) ...@@ -1184,11 +1184,11 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)
trace_xfs_attr_leaf_list(context); trace_xfs_attr_leaf_list(context);
context->cursor->blkno = 0; context->cursor->blkno = 0;
error = xfs_attr_leaf_read(NULL, context->dp, 0, -1, &bp); error = xfs_attr3_leaf_read(NULL, context->dp, 0, -1, &bp);
if (error) if (error)
return XFS_ERROR(error); return XFS_ERROR(error);
error = xfs_attr_leaf_list_int(bp, context); error = xfs_attr3_leaf_list_int(bp, context);
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
return XFS_ERROR(error); return XFS_ERROR(error);
} }
...@@ -1257,7 +1257,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -1257,7 +1257,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
args->rmtblkcnt = 0; args->rmtblkcnt = 0;
} }
retval = xfs_attr_leaf_add(blk->bp, state->args); retval = xfs_attr3_leaf_add(blk->bp, state->args);
if (retval == ENOSPC) { if (retval == ENOSPC) {
if (state->path.active == 1) { if (state->path.active == 1) {
/* /*
...@@ -1267,7 +1267,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -1267,7 +1267,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
*/ */
xfs_da_state_free(state); xfs_da_state_free(state);
xfs_bmap_init(args->flist, args->firstblock); xfs_bmap_init(args->flist, args->firstblock);
error = xfs_attr_leaf_to_node(args); error = xfs_attr3_leaf_to_node(args);
if (!error) { if (!error) {
error = xfs_bmap_finish(&args->trans, error = xfs_bmap_finish(&args->trans,
args->flist, args->flist,
...@@ -1369,7 +1369,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -1369,7 +1369,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
* In a separate transaction, set the incomplete flag on the * In a separate transaction, set the incomplete flag on the
* "old" attr and clear the incomplete flag on the "new" attr. * "old" attr and clear the incomplete flag on the "new" attr.
*/ */
error = xfs_attr_leaf_flipflags(args); error = xfs_attr3_leaf_flipflags(args);
if (error) if (error)
goto out; goto out;
...@@ -1408,7 +1408,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -1408,7 +1408,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
*/ */
blk = &state->path.blk[ state->path.active-1 ]; blk = &state->path.blk[ state->path.active-1 ];
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
error = xfs_attr_leaf_remove(blk->bp, args); error = xfs_attr3_leaf_remove(blk->bp, args);
xfs_da3_fixhashpath(state, &state->path); xfs_da3_fixhashpath(state, &state->path);
/* /*
...@@ -1449,7 +1449,7 @@ xfs_attr_node_addname(xfs_da_args_t *args) ...@@ -1449,7 +1449,7 @@ xfs_attr_node_addname(xfs_da_args_t *args)
/* /*
* Added a "remote" value, just clear the incomplete flag. * Added a "remote" value, just clear the incomplete flag.
*/ */
error = xfs_attr_leaf_clearflag(args); error = xfs_attr3_leaf_clearflag(args);
if (error) if (error)
goto out; goto out;
} }
...@@ -1523,7 +1523,7 @@ xfs_attr_node_removename(xfs_da_args_t *args) ...@@ -1523,7 +1523,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)
* Mark the attribute as INCOMPLETE, then bunmapi() the * Mark the attribute as INCOMPLETE, then bunmapi() the
* remote value. * remote value.
*/ */
error = xfs_attr_leaf_setflag(args); error = xfs_attr3_leaf_setflag(args);
if (error) if (error)
goto out; goto out;
error = xfs_attr_rmtval_remove(args); error = xfs_attr_rmtval_remove(args);
...@@ -1544,7 +1544,7 @@ xfs_attr_node_removename(xfs_da_args_t *args) ...@@ -1544,7 +1544,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)
*/ */
blk = &state->path.blk[ state->path.active-1 ]; blk = &state->path.blk[ state->path.active-1 ];
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
retval = xfs_attr_leaf_remove(blk->bp, args); retval = xfs_attr3_leaf_remove(blk->bp, args);
xfs_da3_fixhashpath(state, &state->path); xfs_da3_fixhashpath(state, &state->path);
/* /*
...@@ -1590,13 +1590,13 @@ xfs_attr_node_removename(xfs_da_args_t *args) ...@@ -1590,13 +1590,13 @@ xfs_attr_node_removename(xfs_da_args_t *args)
ASSERT(state->path.blk[0].bp); ASSERT(state->path.blk[0].bp);
state->path.blk[0].bp = NULL; state->path.blk[0].bp = NULL;
error = xfs_attr_leaf_read(args->trans, args->dp, 0, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
if (error) if (error)
goto out; goto out;
if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
xfs_bmap_init(args->flist, args->firstblock); xfs_bmap_init(args->flist, args->firstblock);
error = xfs_attr_leaf_to_shortform(bp, args, forkoff); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
/* bp is gone due to xfs_da_shrink_inode */ /* bp is gone due to xfs_da_shrink_inode */
if (!error) { if (!error) {
error = xfs_bmap_finish(&args->trans, error = xfs_bmap_finish(&args->trans,
...@@ -1768,7 +1768,7 @@ xfs_attr_node_get(xfs_da_args_t *args) ...@@ -1768,7 +1768,7 @@ xfs_attr_node_get(xfs_da_args_t *args)
/* /*
* Get the value, local or "remote" * Get the value, local or "remote"
*/ */
retval = xfs_attr_leaf_getvalue(blk->bp, args); retval = xfs_attr3_leaf_getvalue(blk->bp, args);
if (!retval && (args->rmtblkno > 0) if (!retval && (args->rmtblkno > 0)
&& !(args->flags & ATTR_KERNOVAL)) { && !(args->flags & ATTR_KERNOVAL)) {
retval = xfs_attr_rmtval_get(args); retval = xfs_attr_rmtval_get(args);
...@@ -1793,7 +1793,9 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) ...@@ -1793,7 +1793,9 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
attrlist_cursor_kern_t *cursor; attrlist_cursor_kern_t *cursor;
xfs_attr_leafblock_t *leaf; xfs_attr_leafblock_t *leaf;
xfs_da_intnode_t *node; xfs_da_intnode_t *node;
xfs_da_node_entry_t *btree; struct xfs_attr3_icleaf_hdr leafhdr;
struct xfs_da3_icnode_hdr nodehdr;
struct xfs_da_node_entry *btree;
int error, i; int error, i;
struct xfs_buf *bp; struct xfs_buf *bp;
...@@ -1814,22 +1816,28 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) ...@@ -1814,22 +1816,28 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
if ((error != 0) && (error != EFSCORRUPTED)) if ((error != 0) && (error != EFSCORRUPTED))
return(error); return(error);
if (bp) { if (bp) {
struct xfs_attr_leaf_entry *entries;
node = bp->b_addr; node = bp->b_addr;
switch (be16_to_cpu(node->hdr.info.magic)) { switch (be16_to_cpu(node->hdr.info.magic)) {
case XFS_DA_NODE_MAGIC: case XFS_DA_NODE_MAGIC:
case XFS_DA3_NODE_MAGIC:
trace_xfs_attr_list_wrong_blk(context); trace_xfs_attr_list_wrong_blk(context);
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
bp = NULL; bp = NULL;
break; break;
case XFS_ATTR_LEAF_MAGIC: case XFS_ATTR_LEAF_MAGIC:
case XFS_ATTR3_LEAF_MAGIC:
leaf = bp->b_addr; leaf = bp->b_addr;
if (cursor->hashval > be32_to_cpu(leaf->entries[ xfs_attr3_leaf_hdr_from_disk(&leafhdr, leaf);
be16_to_cpu(leaf->hdr.count)-1].hashval)) { entries = xfs_attr3_leaf_entryp(leaf);
if (cursor->hashval > be32_to_cpu(
entries[leafhdr.count - 1].hashval)) {
trace_xfs_attr_list_wrong_blk(context); trace_xfs_attr_list_wrong_blk(context);
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
bp = NULL; bp = NULL;
} else if (cursor->hashval <= } else if (cursor->hashval <= be32_to_cpu(
be32_to_cpu(leaf->entries[0].hashval)) { entries[0].hashval)) {
trace_xfs_attr_list_wrong_blk(context); trace_xfs_attr_list_wrong_blk(context);
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
bp = NULL; bp = NULL;
...@@ -1851,27 +1859,31 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) ...@@ -1851,27 +1859,31 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
if (bp == NULL) { if (bp == NULL) {
cursor->blkno = 0; cursor->blkno = 0;
for (;;) { for (;;) {
__uint16_t magic;
error = xfs_da3_node_read(NULL, context->dp, error = xfs_da3_node_read(NULL, context->dp,
cursor->blkno, -1, &bp, cursor->blkno, -1, &bp,
XFS_ATTR_FORK); XFS_ATTR_FORK);
if (error) if (error)
return(error); return(error);
node = bp->b_addr; node = bp->b_addr;
if (node->hdr.info.magic == magic = be16_to_cpu(node->hdr.info.magic);
cpu_to_be16(XFS_ATTR_LEAF_MAGIC)) if (magic == XFS_ATTR_LEAF_MAGIC ||
magic == XFS_ATTR3_LEAF_MAGIC)
break; break;
if (unlikely(node->hdr.info.magic != if (magic != XFS_DA_NODE_MAGIC &&
cpu_to_be16(XFS_DA_NODE_MAGIC))) { magic != XFS_DA3_NODE_MAGIC) {
XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)", XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
XFS_ERRLEVEL_LOW, XFS_ERRLEVEL_LOW,
context->dp->i_mount, context->dp->i_mount,
node); node);
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
return(XFS_ERROR(EFSCORRUPTED)); return XFS_ERROR(EFSCORRUPTED);
} }
xfs_da3_node_hdr_from_disk(&nodehdr, node);
btree = xfs_da3_node_tree_p(node); btree = xfs_da3_node_tree_p(node);
for (i = 0; i < be16_to_cpu(node->hdr.count); for (i = 0; i < nodehdr.count; btree++, i++) {
btree++, i++) {
if (cursor->hashval if (cursor->hashval
<= be32_to_cpu(btree->hashval)) { <= be32_to_cpu(btree->hashval)) {
cursor->blkno = be32_to_cpu(btree->before); cursor->blkno = be32_to_cpu(btree->before);
...@@ -1880,9 +1892,9 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) ...@@ -1880,9 +1892,9 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
break; break;
} }
} }
if (i == be16_to_cpu(node->hdr.count)) { if (i == nodehdr.count) {
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
return(0); return 0;
} }
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
} }
...@@ -1896,22 +1908,23 @@ xfs_attr_node_list(xfs_attr_list_context_t *context) ...@@ -1896,22 +1908,23 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
*/ */
for (;;) { for (;;) {
leaf = bp->b_addr; leaf = bp->b_addr;
error = xfs_attr_leaf_list_int(bp, context); error = xfs_attr3_leaf_list_int(bp, context);
if (error) { if (error) {
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
return error; return error;
} }
if (context->seen_enough || leaf->hdr.info.forw == 0) xfs_attr3_leaf_hdr_from_disk(&leafhdr, leaf);
if (context->seen_enough || leafhdr.forw == 0)
break; break;
cursor->blkno = be32_to_cpu(leaf->hdr.info.forw); cursor->blkno = leafhdr.forw;
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
error = xfs_attr_leaf_read(NULL, context->dp, cursor->blkno, -1, error = xfs_attr3_leaf_read(NULL, context->dp, cursor->blkno, -1,
&bp); &bp);
if (error) if (error)
return error; return error;
} }
xfs_trans_brelse(NULL, bp); xfs_trans_brelse(NULL, bp);
return(0); return 0;
} }
......
/* /*
* Copyright (c) 2000-2005 Silicon Graphics, Inc. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
* Copyright (c) 2013 Red Hat, Inc.
* All Rights Reserved. * All Rights Reserved.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -39,6 +40,9 @@ ...@@ -39,6 +40,9 @@
#include "xfs_attr_leaf.h" #include "xfs_attr_leaf.h"
#include "xfs_error.h" #include "xfs_error.h"
#include "xfs_trace.h" #include "xfs_trace.h"
#include "xfs_buf_item.h"
#include "xfs_cksum.h"
/* /*
* xfs_attr_leaf.c * xfs_attr_leaf.c
...@@ -53,77 +57,213 @@ ...@@ -53,77 +57,213 @@
/* /*
* Routines used for growing the Btree. * Routines used for growing the Btree.
*/ */
STATIC int xfs_attr_leaf_create(xfs_da_args_t *args, xfs_dablk_t which_block, STATIC int xfs_attr3_leaf_create(struct xfs_da_args *args,
struct xfs_buf **bpp); xfs_dablk_t which_block, struct xfs_buf **bpp);
STATIC int xfs_attr_leaf_add_work(struct xfs_buf *leaf_buffer, STATIC int xfs_attr3_leaf_add_work(struct xfs_buf *leaf_buffer,
xfs_da_args_t *args, int freemap_index); struct xfs_attr3_icleaf_hdr *ichdr,
STATIC void xfs_attr_leaf_compact(struct xfs_da_args *args, struct xfs_da_args *args, int freemap_index);
struct xfs_buf *leaf_buffer); STATIC void xfs_attr3_leaf_compact(struct xfs_da_args *args,
STATIC void xfs_attr_leaf_rebalance(xfs_da_state_t *state, struct xfs_attr3_icleaf_hdr *ichdr,
struct xfs_buf *leaf_buffer);
STATIC void xfs_attr3_leaf_rebalance(xfs_da_state_t *state,
xfs_da_state_blk_t *blk1, xfs_da_state_blk_t *blk1,
xfs_da_state_blk_t *blk2); xfs_da_state_blk_t *blk2);
STATIC int xfs_attr_leaf_figure_balance(xfs_da_state_t *state, STATIC int xfs_attr3_leaf_figure_balance(xfs_da_state_t *state,
xfs_da_state_blk_t *leaf_blk_1, xfs_da_state_blk_t *leaf_blk_1,
xfs_da_state_blk_t *leaf_blk_2, struct xfs_attr3_icleaf_hdr *ichdr1,
int *number_entries_in_blk1, xfs_da_state_blk_t *leaf_blk_2,
int *number_usedbytes_in_blk1); struct xfs_attr3_icleaf_hdr *ichdr2,
int *number_entries_in_blk1,
int *number_usedbytes_in_blk1);
/* /*
* Routines used for shrinking the Btree. * Routines used for shrinking the Btree.
*/ */
STATIC int xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, STATIC int xfs_attr3_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp,
struct xfs_buf *bp, int level); struct xfs_buf *bp, int level);
STATIC int xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, STATIC int xfs_attr3_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp,
struct xfs_buf *bp); struct xfs_buf *bp);
STATIC int xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp, STATIC int xfs_attr3_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp,
xfs_dablk_t blkno, int blkcnt); xfs_dablk_t blkno, int blkcnt);
/* /*
* Utility routines. * Utility routines.
*/ */
STATIC void xfs_attr_leaf_moveents(xfs_attr_leafblock_t *src_leaf, STATIC void xfs_attr3_leaf_moveents(struct xfs_attr_leafblock *src_leaf,
int src_start, struct xfs_attr3_icleaf_hdr *src_ichdr, int src_start,
xfs_attr_leafblock_t *dst_leaf, struct xfs_attr_leafblock *dst_leaf,
int dst_start, int move_count, struct xfs_attr3_icleaf_hdr *dst_ichdr, int dst_start,
xfs_mount_t *mp); int move_count, struct xfs_mount *mp);
STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index); STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
static void void
xfs_attr_leaf_verify( xfs_attr3_leaf_hdr_from_disk(
struct xfs_attr3_icleaf_hdr *to,
struct xfs_attr_leafblock *from)
{
int i;
ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC) ||
from->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC));
if (from->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC)) {
struct xfs_attr3_leaf_hdr *hdr3 = (struct xfs_attr3_leaf_hdr *)from;
to->forw = be32_to_cpu(hdr3->info.hdr.forw);
to->back = be32_to_cpu(hdr3->info.hdr.back);
to->magic = be16_to_cpu(hdr3->info.hdr.magic);
to->count = be16_to_cpu(hdr3->count);
to->usedbytes = be16_to_cpu(hdr3->usedbytes);
to->firstused = be16_to_cpu(hdr3->firstused);
to->holes = hdr3->holes;
for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
to->freemap[i].base = be16_to_cpu(hdr3->freemap[i].base);
to->freemap[i].size = be16_to_cpu(hdr3->freemap[i].size);
}
return;
}
to->forw = be32_to_cpu(from->hdr.info.forw);
to->back = be32_to_cpu(from->hdr.info.back);
to->magic = be16_to_cpu(from->hdr.info.magic);
to->count = be16_to_cpu(from->hdr.count);
to->usedbytes = be16_to_cpu(from->hdr.usedbytes);
to->firstused = be16_to_cpu(from->hdr.firstused);
to->holes = from->hdr.holes;
for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
to->freemap[i].base = be16_to_cpu(from->hdr.freemap[i].base);
to->freemap[i].size = be16_to_cpu(from->hdr.freemap[i].size);
}
}
void
xfs_attr3_leaf_hdr_to_disk(
struct xfs_attr_leafblock *to,
struct xfs_attr3_icleaf_hdr *from)
{
int i;
ASSERT(from->magic == XFS_ATTR_LEAF_MAGIC ||
from->magic == XFS_ATTR3_LEAF_MAGIC);
if (from->magic == XFS_ATTR3_LEAF_MAGIC) {
struct xfs_attr3_leaf_hdr *hdr3 = (struct xfs_attr3_leaf_hdr *)to;
hdr3->info.hdr.forw = cpu_to_be32(from->forw);
hdr3->info.hdr.back = cpu_to_be32(from->back);
hdr3->info.hdr.magic = cpu_to_be16(from->magic);
hdr3->count = cpu_to_be16(from->count);
hdr3->usedbytes = cpu_to_be16(from->usedbytes);
hdr3->firstused = cpu_to_be16(from->firstused);
hdr3->holes = from->holes;
hdr3->pad1 = 0;
for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
hdr3->freemap[i].base = cpu_to_be16(from->freemap[i].base);
hdr3->freemap[i].size = cpu_to_be16(from->freemap[i].size);
}
return;
}
to->hdr.info.forw = cpu_to_be32(from->forw);
to->hdr.info.back = cpu_to_be32(from->back);
to->hdr.info.magic = cpu_to_be16(from->magic);
to->hdr.count = cpu_to_be16(from->count);
to->hdr.usedbytes = cpu_to_be16(from->usedbytes);
to->hdr.firstused = cpu_to_be16(from->firstused);
to->hdr.holes = from->holes;
to->hdr.pad1 = 0;
for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
to->hdr.freemap[i].base = cpu_to_be16(from->freemap[i].base);
to->hdr.freemap[i].size = cpu_to_be16(from->freemap[i].size);
}
}
static bool
xfs_attr3_leaf_verify(
struct xfs_buf *bp) struct xfs_buf *bp)
{ {
struct xfs_mount *mp = bp->b_target->bt_mount; struct xfs_mount *mp = bp->b_target->bt_mount;
struct xfs_attr_leaf_hdr *hdr = bp->b_addr; struct xfs_attr_leafblock *leaf = bp->b_addr;
int block_ok = 0; struct xfs_attr3_icleaf_hdr ichdr;
block_ok = hdr->info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
if (!block_ok) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr); if (xfs_sb_version_hascrc(&mp->m_sb)) {
xfs_buf_ioerror(bp, EFSCORRUPTED); struct xfs_da3_node_hdr *hdr3 = bp->b_addr;
if (ichdr.magic != XFS_ATTR3_LEAF_MAGIC)
return false;
if (!uuid_equal(&hdr3->info.uuid, &mp->m_sb.sb_uuid))
return false;
if (be64_to_cpu(hdr3->info.blkno) != bp->b_bn)
return false;
} else {
if (ichdr.magic != XFS_ATTR_LEAF_MAGIC)
return false;
} }
if (ichdr.count == 0)
return false;
/* XXX: need to range check rest of attr header values */
/* XXX: hash order check? */
return true;
} }
static void static void
xfs_attr_leaf_read_verify( xfs_attr3_leaf_write_verify(
struct xfs_buf *bp) struct xfs_buf *bp)
{ {
xfs_attr_leaf_verify(bp); struct xfs_mount *mp = bp->b_target->bt_mount;
struct xfs_buf_log_item *bip = bp->b_fspriv;
struct xfs_attr3_leaf_hdr *hdr3 = bp->b_addr;
if (!xfs_attr3_leaf_verify(bp)) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr);
xfs_buf_ioerror(bp, EFSCORRUPTED);
return;
}
if (!xfs_sb_version_hascrc(&mp->m_sb))
return;
if (bip)
hdr3->info.lsn = cpu_to_be64(bip->bli_item.li_lsn);
xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), XFS_ATTR3_LEAF_CRC_OFF);
} }
/*
* leaf/node format detection on trees is sketchy, so a node read can be done on
* leaf level blocks when detection identifies the tree as a node format tree
* incorrectly. In this case, we need to swap the verifier to match the correct
* format of the block being read.
*/
static void static void
xfs_attr_leaf_write_verify( xfs_attr3_leaf_read_verify(
struct xfs_buf *bp) struct xfs_buf *bp)
{ {
xfs_attr_leaf_verify(bp); struct xfs_mount *mp = bp->b_target->bt_mount;
if ((xfs_sb_version_hascrc(&mp->m_sb) &&
!xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length),
XFS_ATTR3_LEAF_CRC_OFF)) ||
!xfs_attr3_leaf_verify(bp)) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr);
xfs_buf_ioerror(bp, EFSCORRUPTED);
}
} }
const struct xfs_buf_ops xfs_attr_leaf_buf_ops = { const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = {
.verify_read = xfs_attr_leaf_read_verify, .verify_read = xfs_attr3_leaf_read_verify,
.verify_write = xfs_attr_leaf_write_verify, .verify_write = xfs_attr3_leaf_write_verify,
}; };
int int
xfs_attr_leaf_read( xfs_attr3_leaf_read(
struct xfs_trans *tp, struct xfs_trans *tp,
struct xfs_inode *dp, struct xfs_inode *dp,
xfs_dablk_t bno, xfs_dablk_t bno,
...@@ -131,7 +271,7 @@ xfs_attr_leaf_read( ...@@ -131,7 +271,7 @@ xfs_attr_leaf_read(
struct xfs_buf **bpp) struct xfs_buf **bpp)
{ {
return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp, return xfs_da_read_buf(tp, dp, bno, mappedbno, bpp,
XFS_ATTR_FORK, &xfs_attr_leaf_buf_ops); XFS_ATTR_FORK, &xfs_attr3_leaf_buf_ops);
} }
/*======================================================================== /*========================================================================
...@@ -559,7 +699,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args) ...@@ -559,7 +699,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
} }
ASSERT(blkno == 0); ASSERT(blkno == 0);
error = xfs_attr_leaf_create(args, blkno, &bp); error = xfs_attr3_leaf_create(args, blkno, &bp);
if (error) { if (error) {
error = xfs_da_shrink_inode(args, 0, bp); error = xfs_da_shrink_inode(args, 0, bp);
bp = NULL; bp = NULL;
...@@ -588,9 +728,9 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args) ...@@ -588,9 +728,9 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
nargs.hashval = xfs_da_hashname(sfe->nameval, nargs.hashval = xfs_da_hashname(sfe->nameval,
sfe->namelen); sfe->namelen);
nargs.flags = XFS_ATTR_NSP_ONDISK_TO_ARGS(sfe->flags); nargs.flags = XFS_ATTR_NSP_ONDISK_TO_ARGS(sfe->flags);
error = xfs_attr_leaf_lookup_int(bp, &nargs); /* set a->index */ error = xfs_attr3_leaf_lookup_int(bp, &nargs); /* set a->index */
ASSERT(error == ENOATTR); ASSERT(error == ENOATTR);
error = xfs_attr_leaf_add(bp, &nargs); error = xfs_attr3_leaf_add(bp, &nargs);
ASSERT(error != ENOSPC); ASSERT(error != ENOSPC);
if (error) if (error)
goto out; goto out;
...@@ -803,7 +943,7 @@ xfs_attr_shortform_allfit( ...@@ -803,7 +943,7 @@ xfs_attr_shortform_allfit(
continue; /* don't copy partial entries */ continue; /* don't copy partial entries */
if (!(entry->flags & XFS_ATTR_LOCAL)) if (!(entry->flags & XFS_ATTR_LOCAL))
return(0); return(0);
name_loc = xfs_attr_leaf_name_local(leaf, i); name_loc = xfs_attr3_leaf_name_local(leaf, i);
if (name_loc->namelen >= XFS_ATTR_SF_ENTSIZE_MAX) if (name_loc->namelen >= XFS_ATTR_SF_ENTSIZE_MAX)
return(0); return(0);
if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX) if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX)
...@@ -823,29 +963,34 @@ xfs_attr_shortform_allfit( ...@@ -823,29 +963,34 @@ xfs_attr_shortform_allfit(
* Convert a leaf attribute list to shortform attribute list * Convert a leaf attribute list to shortform attribute list
*/ */
int int
xfs_attr_leaf_to_shortform( xfs_attr3_leaf_to_shortform(
struct xfs_buf *bp, struct xfs_buf *bp,
xfs_da_args_t *args, struct xfs_da_args *args,
int forkoff) int forkoff)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_entry_t *entry; struct xfs_attr3_icleaf_hdr ichdr;
xfs_attr_leaf_name_local_t *name_loc; struct xfs_attr_leaf_entry *entry;
xfs_da_args_t nargs; struct xfs_attr_leaf_name_local *name_loc;
xfs_inode_t *dp; struct xfs_da_args nargs;
char *tmpbuffer; struct xfs_inode *dp = args->dp;
int error, i; char *tmpbuffer;
int error;
int i;
trace_xfs_attr_leaf_to_sf(args); trace_xfs_attr_leaf_to_sf(args);
dp = args->dp;
tmpbuffer = kmem_alloc(XFS_LBSIZE(dp->i_mount), KM_SLEEP); tmpbuffer = kmem_alloc(XFS_LBSIZE(dp->i_mount), KM_SLEEP);
ASSERT(tmpbuffer != NULL); if (!tmpbuffer)
return ENOMEM;
ASSERT(bp != NULL);
memcpy(tmpbuffer, bp->b_addr, XFS_LBSIZE(dp->i_mount)); memcpy(tmpbuffer, bp->b_addr, XFS_LBSIZE(dp->i_mount));
leaf = (xfs_attr_leafblock_t *)tmpbuffer; leaf = (xfs_attr_leafblock_t *)tmpbuffer;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
entry = xfs_attr3_leaf_entryp(leaf);
/* XXX (dgc): buffer is about to be marked stale - why zero it? */
memset(bp->b_addr, 0, XFS_LBSIZE(dp->i_mount)); memset(bp->b_addr, 0, XFS_LBSIZE(dp->i_mount));
/* /*
...@@ -875,14 +1020,14 @@ xfs_attr_leaf_to_shortform( ...@@ -875,14 +1020,14 @@ xfs_attr_leaf_to_shortform(
nargs.whichfork = XFS_ATTR_FORK; nargs.whichfork = XFS_ATTR_FORK;
nargs.trans = args->trans; nargs.trans = args->trans;
nargs.op_flags = XFS_DA_OP_OKNOENT; nargs.op_flags = XFS_DA_OP_OKNOENT;
entry = &leaf->entries[0];
for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) { for (i = 0; i < ichdr.count; entry++, i++) {
if (entry->flags & XFS_ATTR_INCOMPLETE) if (entry->flags & XFS_ATTR_INCOMPLETE)
continue; /* don't copy partial entries */ continue; /* don't copy partial entries */
if (!entry->nameidx) if (!entry->nameidx)
continue; continue;
ASSERT(entry->flags & XFS_ATTR_LOCAL); ASSERT(entry->flags & XFS_ATTR_LOCAL);
name_loc = xfs_attr_leaf_name_local(leaf, i); name_loc = xfs_attr3_leaf_name_local(leaf, i);
nargs.name = name_loc->nameval; nargs.name = name_loc->nameval;
nargs.namelen = name_loc->namelen; nargs.namelen = name_loc->namelen;
nargs.value = &name_loc->nameval[nargs.namelen]; nargs.value = &name_loc->nameval[nargs.namelen];
...@@ -895,43 +1040,50 @@ xfs_attr_leaf_to_shortform( ...@@ -895,43 +1040,50 @@ xfs_attr_leaf_to_shortform(
out: out:
kmem_free(tmpbuffer); kmem_free(tmpbuffer);
return(error); return error;
} }
/* /*
* Convert from using a single leaf to a root node and a leaf. * Convert from using a single leaf to a root node and a leaf.
*/ */
int int
xfs_attr_leaf_to_node(xfs_da_args_t *args) xfs_attr3_leaf_to_node(
struct xfs_da_args *args)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_da_intnode_t *node; struct xfs_attr3_icleaf_hdr icleafhdr;
xfs_inode_t *dp; struct xfs_attr_leaf_entry *entries;
struct xfs_buf *bp1, *bp2;
xfs_dablk_t blkno;
int error;
struct xfs_da_node_entry *btree; struct xfs_da_node_entry *btree;
struct xfs_da3_icnode_hdr icnodehdr;
struct xfs_da_intnode *node;
struct xfs_inode *dp = args->dp;
struct xfs_mount *mp = dp->i_mount;
struct xfs_buf *bp1 = NULL;
struct xfs_buf *bp2 = NULL;
xfs_dablk_t blkno;
int error;
trace_xfs_attr_leaf_to_node(args); trace_xfs_attr_leaf_to_node(args);
dp = args->dp;
bp1 = bp2 = NULL;
error = xfs_da_grow_inode(args, &blkno); error = xfs_da_grow_inode(args, &blkno);
if (error) if (error)
goto out; goto out;
error = xfs_attr_leaf_read(args->trans, args->dp, 0, -1, &bp1); error = xfs_attr3_leaf_read(args->trans, dp, 0, -1, &bp1);
if (error) if (error)
goto out; goto out;
bp2 = NULL; error = xfs_da_get_buf(args->trans, dp, blkno, -1, &bp2, XFS_ATTR_FORK);
error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp2,
XFS_ATTR_FORK);
if (error) if (error)
goto out; goto out;
/* copy leaf to new buffer, update identifiers */
bp2->b_ops = bp1->b_ops; bp2->b_ops = bp1->b_ops;
memcpy(bp2->b_addr, bp1->b_addr, XFS_LBSIZE(dp->i_mount)); memcpy(bp2->b_addr, bp1->b_addr, XFS_LBSIZE(mp));
bp1 = NULL; if (xfs_sb_version_hascrc(&mp->m_sb)) {
xfs_trans_log_buf(args->trans, bp2, 0, XFS_LBSIZE(dp->i_mount) - 1); struct xfs_da3_blkinfo *hdr3 = bp2->b_addr;
hdr3->blkno = cpu_to_be64(bp2->b_bn);
}
xfs_trans_log_buf(args->trans, bp2, 0, XFS_LBSIZE(mp) - 1);
/* /*
* Set up the new root node. * Set up the new root node.
...@@ -940,17 +1092,22 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args) ...@@ -940,17 +1092,22 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)
if (error) if (error)
goto out; goto out;
node = bp1->b_addr; node = bp1->b_addr;
xfs_da3_node_hdr_from_disk(&icnodehdr, node);
btree = xfs_da3_node_tree_p(node);
leaf = bp2->b_addr; leaf = bp2->b_addr;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&icleafhdr, leaf);
entries = xfs_attr3_leaf_entryp(leaf);
/* both on-disk, don't endian-flip twice */ /* both on-disk, don't endian-flip twice */
btree = xfs_da3_node_tree_p(node); btree[0].hashval = entries[icleafhdr.count - 1].hashval;
btree[0].hashval = leaf->entries[be16_to_cpu(leaf->hdr.count)-1 ].hashval;
btree[0].before = cpu_to_be32(blkno); btree[0].before = cpu_to_be32(blkno);
node->hdr.count = cpu_to_be16(1); icnodehdr.count = 1;
xfs_trans_log_buf(args->trans, bp1, 0, XFS_LBSIZE(dp->i_mount) - 1); xfs_da3_node_hdr_to_disk(node, &icnodehdr);
xfs_trans_log_buf(args->trans, bp1, 0, XFS_LBSIZE(mp) - 1);
error = 0; error = 0;
out: out:
return(error); return error;
} }
...@@ -963,52 +1120,62 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args) ...@@ -963,52 +1120,62 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)
* or a leaf in a node attribute list. * or a leaf in a node attribute list.
*/ */
STATIC int STATIC int
xfs_attr_leaf_create( xfs_attr3_leaf_create(
xfs_da_args_t *args, struct xfs_da_args *args,
xfs_dablk_t blkno, xfs_dablk_t blkno,
struct xfs_buf **bpp) struct xfs_buf **bpp)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_hdr_t *hdr; struct xfs_attr3_icleaf_hdr ichdr;
xfs_inode_t *dp; struct xfs_inode *dp = args->dp;
struct xfs_buf *bp; struct xfs_mount *mp = dp->i_mount;
int error; struct xfs_buf *bp;
int error;
trace_xfs_attr_leaf_create(args); trace_xfs_attr_leaf_create(args);
dp = args->dp;
ASSERT(dp != NULL);
error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp, error = xfs_da_get_buf(args->trans, args->dp, blkno, -1, &bp,
XFS_ATTR_FORK); XFS_ATTR_FORK);
if (error) if (error)
return(error); return error;
bp->b_ops = &xfs_attr_leaf_buf_ops; bp->b_ops = &xfs_attr3_leaf_buf_ops;
leaf = bp->b_addr; leaf = bp->b_addr;
memset((char *)leaf, 0, XFS_LBSIZE(dp->i_mount)); memset(leaf, 0, XFS_LBSIZE(mp));
hdr = &leaf->hdr;
hdr->info.magic = cpu_to_be16(XFS_ATTR_LEAF_MAGIC); memset(&ichdr, 0, sizeof(ichdr));
hdr->firstused = cpu_to_be16(XFS_LBSIZE(dp->i_mount)); ichdr.firstused = XFS_LBSIZE(mp);
if (!hdr->firstused) {
hdr->firstused = cpu_to_be16( if (xfs_sb_version_hascrc(&mp->m_sb)) {
XFS_LBSIZE(dp->i_mount) - XFS_ATTR_LEAF_NAME_ALIGN); struct xfs_da3_blkinfo *hdr3 = bp->b_addr;
}
ichdr.magic = XFS_ATTR3_LEAF_MAGIC;
hdr3->blkno = cpu_to_be64(bp->b_bn);
hdr3->owner = cpu_to_be64(dp->i_ino);
uuid_copy(&hdr3->uuid, &mp->m_sb.sb_uuid);
hdr->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t)); ichdr.freemap[0].base = sizeof(struct xfs_attr3_leaf_hdr);
hdr->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr->firstused) - } else {
sizeof(xfs_attr_leaf_hdr_t)); ichdr.magic = XFS_ATTR_LEAF_MAGIC;
ichdr.freemap[0].base = sizeof(struct xfs_attr_leaf_hdr);
}
ichdr.freemap[0].size = ichdr.firstused - ichdr.freemap[0].base;
xfs_trans_log_buf(args->trans, bp, 0, XFS_LBSIZE(dp->i_mount) - 1); xfs_attr3_leaf_hdr_to_disk(leaf, &ichdr);
xfs_trans_log_buf(args->trans, bp, 0, XFS_LBSIZE(mp) - 1);
*bpp = bp; *bpp = bp;
return(0); return 0;
} }
/* /*
* Split the leaf node, rebalance, then add the new entry. * Split the leaf node, rebalance, then add the new entry.
*/ */
int int
xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, xfs_attr3_leaf_split(
xfs_da_state_blk_t *newblk) struct xfs_da_state *state,
struct xfs_da_state_blk *oldblk,
struct xfs_da_state_blk *newblk)
{ {
xfs_dablk_t blkno; xfs_dablk_t blkno;
int error; int error;
...@@ -1022,7 +1189,7 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, ...@@ -1022,7 +1189,7 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk,
error = xfs_da_grow_inode(state->args, &blkno); error = xfs_da_grow_inode(state->args, &blkno);
if (error) if (error)
return(error); return(error);
error = xfs_attr_leaf_create(state->args, blkno, &newblk->bp); error = xfs_attr3_leaf_create(state->args, blkno, &newblk->bp);
if (error) if (error)
return(error); return(error);
newblk->blkno = blkno; newblk->blkno = blkno;
...@@ -1032,7 +1199,7 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, ...@@ -1032,7 +1199,7 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk,
* Rebalance the entries across the two leaves. * Rebalance the entries across the two leaves.
* NOTE: rebalance() currently depends on the 2nd block being empty. * NOTE: rebalance() currently depends on the 2nd block being empty.
*/ */
xfs_attr_leaf_rebalance(state, oldblk, newblk); xfs_attr3_leaf_rebalance(state, oldblk, newblk);
error = xfs_da3_blk_link(state, oldblk, newblk); error = xfs_da3_blk_link(state, oldblk, newblk);
if (error) if (error)
return(error); return(error);
...@@ -1046,10 +1213,10 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, ...@@ -1046,10 +1213,10 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk,
*/ */
if (state->inleaf) { if (state->inleaf) {
trace_xfs_attr_leaf_add_old(state->args); trace_xfs_attr_leaf_add_old(state->args);
error = xfs_attr_leaf_add(oldblk->bp, state->args); error = xfs_attr3_leaf_add(oldblk->bp, state->args);
} else { } else {
trace_xfs_attr_leaf_add_new(state->args); trace_xfs_attr_leaf_add_new(state->args);
error = xfs_attr_leaf_add(newblk->bp, state->args); error = xfs_attr3_leaf_add(newblk->bp, state->args);
} }
/* /*
...@@ -1064,22 +1231,23 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, ...@@ -1064,22 +1231,23 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk,
* Add a name to the leaf attribute list structure. * Add a name to the leaf attribute list structure.
*/ */
int int
xfs_attr_leaf_add( xfs_attr3_leaf_add(
struct xfs_buf *bp, struct xfs_buf *bp,
struct xfs_da_args *args) struct xfs_da_args *args)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_hdr_t *hdr; struct xfs_attr3_icleaf_hdr ichdr;
xfs_attr_leaf_map_t *map; int tablesize;
int tablesize, entsize, sum, tmp, i; int entsize;
int sum;
int tmp;
int i;
trace_xfs_attr_leaf_add(args); trace_xfs_attr_leaf_add(args);
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
ASSERT((args->index >= 0) ASSERT(args->index >= 0 && args->index <= ichdr.count);
&& (args->index <= be16_to_cpu(leaf->hdr.count)));
hdr = &leaf->hdr;
entsize = xfs_attr_leaf_newentsize(args->namelen, args->valuelen, entsize = xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
args->trans->t_mountp->m_sb.sb_blocksize, NULL); args->trans->t_mountp->m_sb.sb_blocksize, NULL);
...@@ -1087,25 +1255,23 @@ xfs_attr_leaf_add( ...@@ -1087,25 +1255,23 @@ xfs_attr_leaf_add(
* Search through freemap for first-fit on new name length. * Search through freemap for first-fit on new name length.
* (may need to figure in size of entry struct too) * (may need to figure in size of entry struct too)
*/ */
tablesize = (be16_to_cpu(hdr->count) + 1) tablesize = (ichdr.count + 1) * sizeof(xfs_attr_leaf_entry_t)
* sizeof(xfs_attr_leaf_entry_t) + xfs_attr3_leaf_hdr_size(leaf);
+ sizeof(xfs_attr_leaf_hdr_t); for (sum = 0, i = XFS_ATTR_LEAF_MAPSIZE - 1; i >= 0; i--) {
map = &hdr->freemap[XFS_ATTR_LEAF_MAPSIZE-1]; if (tablesize > ichdr.firstused) {
for (sum = 0, i = XFS_ATTR_LEAF_MAPSIZE-1; i >= 0; map--, i--) { sum += ichdr.freemap[i].size;
if (tablesize > be16_to_cpu(hdr->firstused)) {
sum += be16_to_cpu(map->size);
continue; continue;
} }
if (!map->size) if (!ichdr.freemap[i].size)
continue; /* no space in this map */ continue; /* no space in this map */
tmp = entsize; tmp = entsize;
if (be16_to_cpu(map->base) < be16_to_cpu(hdr->firstused)) if (ichdr.freemap[i].base < ichdr.firstused)
tmp += sizeof(xfs_attr_leaf_entry_t); tmp += sizeof(xfs_attr_leaf_entry_t);
if (be16_to_cpu(map->size) >= tmp) { if (ichdr.freemap[i].size >= tmp) {
tmp = xfs_attr_leaf_add_work(bp, args, i); tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, i);
return(tmp); goto out_log_hdr;
} }
sum += be16_to_cpu(map->size); sum += ichdr.freemap[i].size;
} }
/* /*
...@@ -1113,82 +1279,89 @@ xfs_attr_leaf_add( ...@@ -1113,82 +1279,89 @@ xfs_attr_leaf_add(
* and we don't have enough freespace, then compaction will do us * and we don't have enough freespace, then compaction will do us
* no good and we should just give up. * no good and we should just give up.
*/ */
if (!hdr->holes && (sum < entsize)) if (!ichdr.holes && sum < entsize)
return(XFS_ERROR(ENOSPC)); return XFS_ERROR(ENOSPC);
/* /*
* Compact the entries to coalesce free space. * Compact the entries to coalesce free space.
* This may change the hdr->count via dropping INCOMPLETE entries. * This may change the hdr->count via dropping INCOMPLETE entries.
*/ */
xfs_attr_leaf_compact(args, bp); xfs_attr3_leaf_compact(args, &ichdr, bp);
/* /*
* After compaction, the block is guaranteed to have only one * After compaction, the block is guaranteed to have only one
* free region, in freemap[0]. If it is not big enough, give up. * free region, in freemap[0]. If it is not big enough, give up.
*/ */
if (be16_to_cpu(hdr->freemap[0].size) if (ichdr.freemap[0].size < (entsize + sizeof(xfs_attr_leaf_entry_t))) {
< (entsize + sizeof(xfs_attr_leaf_entry_t))) tmp = ENOSPC;
return(XFS_ERROR(ENOSPC)); goto out_log_hdr;
}
tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, 0);
return(xfs_attr_leaf_add_work(bp, args, 0)); out_log_hdr:
xfs_attr3_leaf_hdr_to_disk(leaf, &ichdr);
xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, &leaf->hdr,
xfs_attr3_leaf_hdr_size(leaf)));
return tmp;
} }
/* /*
* Add a name to a leaf attribute list structure. * Add a name to a leaf attribute list structure.
*/ */
STATIC int STATIC int
xfs_attr_leaf_add_work( xfs_attr3_leaf_add_work(
struct xfs_buf *bp, struct xfs_buf *bp,
xfs_da_args_t *args, struct xfs_attr3_icleaf_hdr *ichdr,
int mapindex) struct xfs_da_args *args,
int mapindex)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_hdr_t *hdr; struct xfs_attr_leaf_entry *entry;
xfs_attr_leaf_entry_t *entry; struct xfs_attr_leaf_name_local *name_loc;
xfs_attr_leaf_name_local_t *name_loc; struct xfs_attr_leaf_name_remote *name_rmt;
xfs_attr_leaf_name_remote_t *name_rmt; struct xfs_mount *mp;
xfs_attr_leaf_map_t *map; int tmp;
xfs_mount_t *mp; int i;
int tmp, i;
trace_xfs_attr_leaf_add_work(args); trace_xfs_attr_leaf_add_work(args);
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); ASSERT(mapindex >= 0 && mapindex < XFS_ATTR_LEAF_MAPSIZE);
hdr = &leaf->hdr; ASSERT(args->index >= 0 && args->index <= ichdr->count);
ASSERT((mapindex >= 0) && (mapindex < XFS_ATTR_LEAF_MAPSIZE));
ASSERT((args->index >= 0) && (args->index <= be16_to_cpu(hdr->count)));
/* /*
* Force open some space in the entry array and fill it in. * Force open some space in the entry array and fill it in.
*/ */
entry = &leaf->entries[args->index]; entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
if (args->index < be16_to_cpu(hdr->count)) { if (args->index < ichdr->count) {
tmp = be16_to_cpu(hdr->count) - args->index; tmp = ichdr->count - args->index;
tmp *= sizeof(xfs_attr_leaf_entry_t); tmp *= sizeof(xfs_attr_leaf_entry_t);
memmove((char *)(entry+1), (char *)entry, tmp); memmove(entry + 1, entry, tmp);
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry))); XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry)));
} }
be16_add_cpu(&hdr->count, 1); ichdr->count++;
/* /*
* Allocate space for the new string (at the end of the run). * Allocate space for the new string (at the end of the run).
*/ */
map = &hdr->freemap[mapindex];
mp = args->trans->t_mountp; mp = args->trans->t_mountp;
ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp)); ASSERT(ichdr->freemap[mapindex].base < XFS_LBSIZE(mp));
ASSERT((be16_to_cpu(map->base) & 0x3) == 0); ASSERT((ichdr->freemap[mapindex].base & 0x3) == 0);
ASSERT(be16_to_cpu(map->size) >= ASSERT(ichdr->freemap[mapindex].size >=
xfs_attr_leaf_newentsize(args->namelen, args->valuelen, xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
mp->m_sb.sb_blocksize, NULL)); mp->m_sb.sb_blocksize, NULL));
ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp)); ASSERT(ichdr->freemap[mapindex].size < XFS_LBSIZE(mp));
ASSERT((be16_to_cpu(map->size) & 0x3) == 0); ASSERT((ichdr->freemap[mapindex].size & 0x3) == 0);
be16_add_cpu(&map->size,
-xfs_attr_leaf_newentsize(args->namelen, args->valuelen, ichdr->freemap[mapindex].size -=
mp->m_sb.sb_blocksize, &tmp)); xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
entry->nameidx = cpu_to_be16(be16_to_cpu(map->base) + mp->m_sb.sb_blocksize, &tmp);
be16_to_cpu(map->size));
entry->nameidx = cpu_to_be16(ichdr->freemap[mapindex].base +
ichdr->freemap[mapindex].size);
entry->hashval = cpu_to_be32(args->hashval); entry->hashval = cpu_to_be32(args->hashval);
entry->flags = tmp ? XFS_ATTR_LOCAL : 0; entry->flags = tmp ? XFS_ATTR_LOCAL : 0;
entry->flags |= XFS_ATTR_NSP_ARGS_TO_ONDISK(args->flags); entry->flags |= XFS_ATTR_NSP_ARGS_TO_ONDISK(args->flags);
...@@ -1203,7 +1376,7 @@ xfs_attr_leaf_add_work( ...@@ -1203,7 +1376,7 @@ xfs_attr_leaf_add_work(
XFS_DA_LOGRANGE(leaf, entry, sizeof(*entry))); XFS_DA_LOGRANGE(leaf, entry, sizeof(*entry)));
ASSERT((args->index == 0) || ASSERT((args->index == 0) ||
(be32_to_cpu(entry->hashval) >= be32_to_cpu((entry-1)->hashval))); (be32_to_cpu(entry->hashval) >= be32_to_cpu((entry-1)->hashval)));
ASSERT((args->index == be16_to_cpu(hdr->count)-1) || ASSERT((args->index == ichdr->count - 1) ||
(be32_to_cpu(entry->hashval) <= be32_to_cpu((entry+1)->hashval))); (be32_to_cpu(entry->hashval) <= be32_to_cpu((entry+1)->hashval)));
/* /*
...@@ -1214,14 +1387,14 @@ xfs_attr_leaf_add_work( ...@@ -1214,14 +1387,14 @@ xfs_attr_leaf_add_work(
* as part of this transaction (a split operation for example). * as part of this transaction (a split operation for example).
*/ */
if (entry->flags & XFS_ATTR_LOCAL) { if (entry->flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr_leaf_name_local(leaf, args->index); name_loc = xfs_attr3_leaf_name_local(leaf, args->index);
name_loc->namelen = args->namelen; name_loc->namelen = args->namelen;
name_loc->valuelen = cpu_to_be16(args->valuelen); name_loc->valuelen = cpu_to_be16(args->valuelen);
memcpy((char *)name_loc->nameval, args->name, args->namelen); memcpy((char *)name_loc->nameval, args->name, args->namelen);
memcpy((char *)&name_loc->nameval[args->namelen], args->value, memcpy((char *)&name_loc->nameval[args->namelen], args->value,
be16_to_cpu(name_loc->valuelen)); be16_to_cpu(name_loc->valuelen));
} else { } else {
name_rmt = xfs_attr_leaf_name_remote(leaf, args->index); name_rmt = xfs_attr3_leaf_name_remote(leaf, args->index);
name_rmt->namelen = args->namelen; name_rmt->namelen = args->namelen;
memcpy((char *)name_rmt->name, args->name, args->namelen); memcpy((char *)name_rmt->name, args->name, args->namelen);
entry->flags |= XFS_ATTR_INCOMPLETE; entry->flags |= XFS_ATTR_INCOMPLETE;
...@@ -1232,44 +1405,41 @@ xfs_attr_leaf_add_work( ...@@ -1232,44 +1405,41 @@ xfs_attr_leaf_add_work(
args->rmtblkcnt = XFS_B_TO_FSB(mp, args->valuelen); args->rmtblkcnt = XFS_B_TO_FSB(mp, args->valuelen);
} }
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, xfs_attr_leaf_name(leaf, args->index), XFS_DA_LOGRANGE(leaf, xfs_attr3_leaf_name(leaf, args->index),
xfs_attr_leaf_entsize(leaf, args->index))); xfs_attr_leaf_entsize(leaf, args->index)));
/* /*
* Update the control info for this leaf node * Update the control info for this leaf node
*/ */
if (be16_to_cpu(entry->nameidx) < be16_to_cpu(hdr->firstused)) { if (be16_to_cpu(entry->nameidx) < ichdr->firstused)
/* both on-disk, don't endian-flip twice */ ichdr->firstused = be16_to_cpu(entry->nameidx);
hdr->firstused = entry->nameidx;
} ASSERT(ichdr->firstused >= ichdr->count * sizeof(xfs_attr_leaf_entry_t)
ASSERT(be16_to_cpu(hdr->firstused) >= + xfs_attr3_leaf_hdr_size(leaf));
((be16_to_cpu(hdr->count) * sizeof(*entry)) + sizeof(*hdr))); tmp = (ichdr->count - 1) * sizeof(xfs_attr_leaf_entry_t)
tmp = (be16_to_cpu(hdr->count)-1) * sizeof(xfs_attr_leaf_entry_t) + xfs_attr3_leaf_hdr_size(leaf);
+ sizeof(xfs_attr_leaf_hdr_t);
map = &hdr->freemap[0]; for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) { if (ichdr->freemap[i].base == tmp) {
if (be16_to_cpu(map->base) == tmp) { ichdr->freemap[i].base += sizeof(xfs_attr_leaf_entry_t);
be16_add_cpu(&map->base, sizeof(xfs_attr_leaf_entry_t)); ichdr->freemap[i].size -= sizeof(xfs_attr_leaf_entry_t);
be16_add_cpu(&map->size,
-((int)sizeof(xfs_attr_leaf_entry_t)));
} }
} }
be16_add_cpu(&hdr->usedbytes, xfs_attr_leaf_entsize(leaf, args->index)); ichdr->usedbytes += xfs_attr_leaf_entsize(leaf, args->index);
xfs_trans_log_buf(args->trans, bp, return 0;
XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr)));
return(0);
} }
/* /*
* Garbage collect a leaf attribute list block by copying it to a new buffer. * Garbage collect a leaf attribute list block by copying it to a new buffer.
*/ */
STATIC void STATIC void
xfs_attr_leaf_compact( xfs_attr3_leaf_compact(
struct xfs_da_args *args, struct xfs_da_args *args,
struct xfs_attr3_icleaf_hdr *ichdr_d,
struct xfs_buf *bp) struct xfs_buf *bp)
{ {
xfs_attr_leafblock_t *leaf_s, *leaf_d; xfs_attr_leafblock_t *leaf_s, *leaf_d;
xfs_attr_leaf_hdr_t *hdr_s, *hdr_d; struct xfs_attr3_icleaf_hdr ichdr_s;
struct xfs_trans *trans = args->trans; struct xfs_trans *trans = args->trans;
struct xfs_mount *mp = trans->t_mountp; struct xfs_mount *mp = trans->t_mountp;
char *tmpbuffer; char *tmpbuffer;
...@@ -1286,33 +1456,68 @@ xfs_attr_leaf_compact( ...@@ -1286,33 +1456,68 @@ xfs_attr_leaf_compact(
*/ */
leaf_s = (xfs_attr_leafblock_t *)tmpbuffer; leaf_s = (xfs_attr_leafblock_t *)tmpbuffer;
leaf_d = bp->b_addr; leaf_d = bp->b_addr;
hdr_s = &leaf_s->hdr; ichdr_s = *ichdr_d; /* struct copy */
hdr_d = &leaf_d->hdr; ichdr_d->firstused = XFS_LBSIZE(mp);
hdr_d->info = hdr_s->info; /* struct copy */ ichdr_d->usedbytes = 0;
hdr_d->firstused = cpu_to_be16(XFS_LBSIZE(mp)); ichdr_d->count = 0;
/* handle truncation gracefully */ ichdr_d->holes = 0;
if (!hdr_d->firstused) { ichdr_d->freemap[0].base = xfs_attr3_leaf_hdr_size(leaf_s);
hdr_d->firstused = cpu_to_be16( ichdr_d->freemap[0].size = ichdr_d->firstused - ichdr_d->freemap[0].base;
XFS_LBSIZE(mp) - XFS_ATTR_LEAF_NAME_ALIGN);
}
hdr_d->usedbytes = 0;
hdr_d->count = 0;
hdr_d->holes = 0;
hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused) -
sizeof(xfs_attr_leaf_hdr_t));
/* /*
* Copy all entry's in the same (sorted) order, * Copy all entry's in the same (sorted) order,
* but allocate name/value pairs packed and in sequence. * but allocate name/value pairs packed and in sequence.
*/ */
xfs_attr_leaf_moveents(leaf_s, 0, leaf_d, 0, xfs_attr3_leaf_moveents(leaf_s, &ichdr_s, 0, leaf_d, ichdr_d, 0,
be16_to_cpu(hdr_s->count), mp); ichdr_s.count, mp);
/*
* this logs the entire buffer, but the caller must write the header
* back to the buffer when it is finished modifying it.
*/
xfs_trans_log_buf(trans, bp, 0, XFS_LBSIZE(mp) - 1); xfs_trans_log_buf(trans, bp, 0, XFS_LBSIZE(mp) - 1);
kmem_free(tmpbuffer); kmem_free(tmpbuffer);
} }
/*
* Compare two leaf blocks "order".
* Return 0 unless leaf2 should go before leaf1.
*/
static int
xfs_attr3_leaf_order(
struct xfs_buf *leaf1_bp,
struct xfs_attr3_icleaf_hdr *leaf1hdr,
struct xfs_buf *leaf2_bp,
struct xfs_attr3_icleaf_hdr *leaf2hdr)
{
struct xfs_attr_leaf_entry *entries1;
struct xfs_attr_leaf_entry *entries2;
entries1 = xfs_attr3_leaf_entryp(leaf1_bp->b_addr);
entries2 = xfs_attr3_leaf_entryp(leaf2_bp->b_addr);
if (leaf1hdr->count > 0 && leaf2hdr->count > 0 &&
((be32_to_cpu(entries2[0].hashval) <
be32_to_cpu(entries1[0].hashval)) ||
(be32_to_cpu(entries2[leaf2hdr->count - 1].hashval) <
be32_to_cpu(entries1[leaf1hdr->count - 1].hashval)))) {
return 1;
}
return 0;
}
int
xfs_attr_leaf_order(
struct xfs_buf *leaf1_bp,
struct xfs_buf *leaf2_bp)
{
struct xfs_attr3_icleaf_hdr ichdr1;
struct xfs_attr3_icleaf_hdr ichdr2;
xfs_attr3_leaf_hdr_from_disk(&ichdr1, leaf1_bp->b_addr);
xfs_attr3_leaf_hdr_from_disk(&ichdr2, leaf2_bp->b_addr);
return xfs_attr3_leaf_order(leaf1_bp, &ichdr1, leaf2_bp, &ichdr2);
}
/* /*
* Redistribute the attribute list entries between two leaf nodes, * Redistribute the attribute list entries between two leaf nodes,
* taking into account the size of the new entry. * taking into account the size of the new entry.
...@@ -1326,14 +1531,23 @@ xfs_attr_leaf_compact( ...@@ -1326,14 +1531,23 @@ xfs_attr_leaf_compact(
* the "new" and "old" values can end up in different blocks. * the "new" and "old" values can end up in different blocks.
*/ */
STATIC void STATIC void
xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, xfs_attr3_leaf_rebalance(
xfs_da_state_blk_t *blk2) struct xfs_da_state *state,
struct xfs_da_state_blk *blk1,
struct xfs_da_state_blk *blk2)
{ {
xfs_da_args_t *args; struct xfs_da_args *args;
xfs_da_state_blk_t *tmp_blk; struct xfs_attr_leafblock *leaf1;
xfs_attr_leafblock_t *leaf1, *leaf2; struct xfs_attr_leafblock *leaf2;
xfs_attr_leaf_hdr_t *hdr1, *hdr2; struct xfs_attr3_icleaf_hdr ichdr1;
int count, totallen, max, space, swap; struct xfs_attr3_icleaf_hdr ichdr2;
struct xfs_attr_leaf_entry *entries1;
struct xfs_attr_leaf_entry *entries2;
int count;
int totallen;
int max;
int space;
int swap;
/* /*
* Set up environment. * Set up environment.
...@@ -1342,9 +1556,9 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, ...@@ -1342,9 +1556,9 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
ASSERT(blk2->magic == XFS_ATTR_LEAF_MAGIC); ASSERT(blk2->magic == XFS_ATTR_LEAF_MAGIC);
leaf1 = blk1->bp->b_addr; leaf1 = blk1->bp->b_addr;
leaf2 = blk2->bp->b_addr; leaf2 = blk2->bp->b_addr;
ASSERT(leaf1->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr1, leaf1);
ASSERT(leaf2->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr2, leaf2);
ASSERT(leaf2->hdr.count == 0); ASSERT(ichdr2.count == 0);
args = state->args; args = state->args;
trace_xfs_attr_leaf_rebalance(args); trace_xfs_attr_leaf_rebalance(args);
...@@ -1356,16 +1570,23 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, ...@@ -1356,16 +1570,23 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
* second block, this code should never set "swap". * second block, this code should never set "swap".
*/ */
swap = 0; swap = 0;
if (xfs_attr_leaf_order(blk1->bp, blk2->bp)) { if (xfs_attr3_leaf_order(blk1->bp, &ichdr1, blk2->bp, &ichdr2)) {
struct xfs_da_state_blk *tmp_blk;
struct xfs_attr3_icleaf_hdr tmp_ichdr;
tmp_blk = blk1; tmp_blk = blk1;
blk1 = blk2; blk1 = blk2;
blk2 = tmp_blk; blk2 = tmp_blk;
/* struct copies to swap them rather than reconverting */
tmp_ichdr = ichdr1;
ichdr1 = ichdr2;
ichdr2 = tmp_ichdr;
leaf1 = blk1->bp->b_addr; leaf1 = blk1->bp->b_addr;
leaf2 = blk2->bp->b_addr; leaf2 = blk2->bp->b_addr;
swap = 1; swap = 1;
} }
hdr1 = &leaf1->hdr;
hdr2 = &leaf2->hdr;
/* /*
* Examine entries until we reduce the absolute difference in * Examine entries until we reduce the absolute difference in
...@@ -1375,41 +1596,39 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, ...@@ -1375,41 +1596,39 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
* "inleaf" is true if the new entry should be inserted into blk1. * "inleaf" is true if the new entry should be inserted into blk1.
* If "swap" is also true, then reverse the sense of "inleaf". * If "swap" is also true, then reverse the sense of "inleaf".
*/ */
state->inleaf = xfs_attr_leaf_figure_balance(state, blk1, blk2, state->inleaf = xfs_attr3_leaf_figure_balance(state, blk1, &ichdr1,
&count, &totallen); blk2, &ichdr2,
&count, &totallen);
if (swap) if (swap)
state->inleaf = !state->inleaf; state->inleaf = !state->inleaf;
/* /*
* Move any entries required from leaf to leaf: * Move any entries required from leaf to leaf:
*/ */
if (count < be16_to_cpu(hdr1->count)) { if (count < ichdr1.count) {
/* /*
* Figure the total bytes to be added to the destination leaf. * Figure the total bytes to be added to the destination leaf.
*/ */
/* number entries being moved */ /* number entries being moved */
count = be16_to_cpu(hdr1->count) - count; count = ichdr1.count - count;
space = be16_to_cpu(hdr1->usedbytes) - totallen; space = ichdr1.usedbytes - totallen;
space += count * sizeof(xfs_attr_leaf_entry_t); space += count * sizeof(xfs_attr_leaf_entry_t);
/* /*
* leaf2 is the destination, compact it if it looks tight. * leaf2 is the destination, compact it if it looks tight.
*/ */
max = be16_to_cpu(hdr2->firstused) max = ichdr2.firstused - xfs_attr3_leaf_hdr_size(leaf1);
- sizeof(xfs_attr_leaf_hdr_t); max -= ichdr2.count * sizeof(xfs_attr_leaf_entry_t);
max -= be16_to_cpu(hdr2->count) * sizeof(xfs_attr_leaf_entry_t);
if (space > max) if (space > max)
xfs_attr_leaf_compact(args, blk2->bp); xfs_attr3_leaf_compact(args, &ichdr2, blk2->bp);
/* /*
* Move high entries from leaf1 to low end of leaf2. * Move high entries from leaf1 to low end of leaf2.
*/ */
xfs_attr_leaf_moveents(leaf1, be16_to_cpu(hdr1->count) - count, xfs_attr3_leaf_moveents(leaf1, &ichdr1, ichdr1.count - count,
leaf2, 0, count, state->mp); leaf2, &ichdr2, 0, count, state->mp);
xfs_trans_log_buf(args->trans, blk1->bp, 0, state->blocksize-1); } else if (count > ichdr1.count) {
xfs_trans_log_buf(args->trans, blk2->bp, 0, state->blocksize-1);
} else if (count > be16_to_cpu(hdr1->count)) {
/* /*
* I assert that since all callers pass in an empty * I assert that since all callers pass in an empty
* second buffer, this code should never execute. * second buffer, this code should never execute.
...@@ -1420,36 +1639,37 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, ...@@ -1420,36 +1639,37 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
* Figure the total bytes to be added to the destination leaf. * Figure the total bytes to be added to the destination leaf.
*/ */
/* number entries being moved */ /* number entries being moved */
count -= be16_to_cpu(hdr1->count); count -= ichdr1.count;
space = totallen - be16_to_cpu(hdr1->usedbytes); space = totallen - ichdr1.usedbytes;
space += count * sizeof(xfs_attr_leaf_entry_t); space += count * sizeof(xfs_attr_leaf_entry_t);
/* /*
* leaf1 is the destination, compact it if it looks tight. * leaf1 is the destination, compact it if it looks tight.
*/ */
max = be16_to_cpu(hdr1->firstused) max = ichdr1.firstused - xfs_attr3_leaf_hdr_size(leaf1);
- sizeof(xfs_attr_leaf_hdr_t); max -= ichdr1.count * sizeof(xfs_attr_leaf_entry_t);
max -= be16_to_cpu(hdr1->count) * sizeof(xfs_attr_leaf_entry_t);
if (space > max) if (space > max)
xfs_attr_leaf_compact(args, blk1->bp); xfs_attr3_leaf_compact(args, &ichdr1, blk1->bp);
/* /*
* Move low entries from leaf2 to high end of leaf1. * Move low entries from leaf2 to high end of leaf1.
*/ */
xfs_attr_leaf_moveents(leaf2, 0, leaf1, xfs_attr3_leaf_moveents(leaf2, &ichdr2, 0, leaf1, &ichdr1,
be16_to_cpu(hdr1->count), count, state->mp); ichdr1.count, count, state->mp);
xfs_trans_log_buf(args->trans, blk1->bp, 0, state->blocksize-1);
xfs_trans_log_buf(args->trans, blk2->bp, 0, state->blocksize-1);
} }
xfs_attr3_leaf_hdr_to_disk(leaf1, &ichdr1);
xfs_attr3_leaf_hdr_to_disk(leaf2, &ichdr2);
xfs_trans_log_buf(args->trans, blk1->bp, 0, state->blocksize-1);
xfs_trans_log_buf(args->trans, blk2->bp, 0, state->blocksize-1);
/* /*
* Copy out last hashval in each block for B-tree code. * Copy out last hashval in each block for B-tree code.
*/ */
blk1->hashval = be32_to_cpu( entries1 = xfs_attr3_leaf_entryp(leaf1);
leaf1->entries[be16_to_cpu(leaf1->hdr.count)-1].hashval); entries2 = xfs_attr3_leaf_entryp(leaf2);
blk2->hashval = be32_to_cpu( blk1->hashval = be32_to_cpu(entries1[ichdr1.count - 1].hashval);
leaf2->entries[be16_to_cpu(leaf2->hdr.count)-1].hashval); blk2->hashval = be32_to_cpu(entries2[ichdr2.count - 1].hashval);
/* /*
* Adjust the expected index for insertion. * Adjust the expected index for insertion.
...@@ -1463,12 +1683,12 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, ...@@ -1463,12 +1683,12 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
* inserting. The index/blkno fields refer to the "old" entry, * inserting. The index/blkno fields refer to the "old" entry,
* while the index2/blkno2 fields refer to the "new" entry. * while the index2/blkno2 fields refer to the "new" entry.
*/ */
if (blk1->index > be16_to_cpu(leaf1->hdr.count)) { if (blk1->index > ichdr1.count) {
ASSERT(state->inleaf == 0); ASSERT(state->inleaf == 0);
blk2->index = blk1->index - be16_to_cpu(leaf1->hdr.count); blk2->index = blk1->index - ichdr1.count;
args->index = args->index2 = blk2->index; args->index = args->index2 = blk2->index;
args->blkno = args->blkno2 = blk2->blkno; args->blkno = args->blkno2 = blk2->blkno;
} else if (blk1->index == be16_to_cpu(leaf1->hdr.count)) { } else if (blk1->index == ichdr1.count) {
if (state->inleaf) { if (state->inleaf) {
args->index = blk1->index; args->index = blk1->index;
args->blkno = blk1->blkno; args->blkno = blk1->blkno;
...@@ -1480,8 +1700,7 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, ...@@ -1480,8 +1700,7 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
* is already stored in blkno2/index2, so don't * is already stored in blkno2/index2, so don't
* overwrite it overwise we corrupt the tree. * overwrite it overwise we corrupt the tree.
*/ */
blk2->index = blk1->index blk2->index = blk1->index - ichdr1.count;
- be16_to_cpu(leaf1->hdr.count);
args->index = blk2->index; args->index = blk2->index;
args->blkno = blk2->blkno; args->blkno = blk2->blkno;
if (!state->extravalid) { if (!state->extravalid) {
...@@ -1509,42 +1728,40 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, ...@@ -1509,42 +1728,40 @@ xfs_attr_leaf_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1,
* GROT: Do a double-split for this case? * GROT: Do a double-split for this case?
*/ */
STATIC int STATIC int
xfs_attr_leaf_figure_balance(xfs_da_state_t *state, xfs_attr3_leaf_figure_balance(
xfs_da_state_blk_t *blk1, struct xfs_da_state *state,
xfs_da_state_blk_t *blk2, struct xfs_da_state_blk *blk1,
int *countarg, int *usedbytesarg) struct xfs_attr3_icleaf_hdr *ichdr1,
struct xfs_da_state_blk *blk2,
struct xfs_attr3_icleaf_hdr *ichdr2,
int *countarg,
int *usedbytesarg)
{ {
xfs_attr_leafblock_t *leaf1, *leaf2; struct xfs_attr_leafblock *leaf1 = blk1->bp->b_addr;
xfs_attr_leaf_hdr_t *hdr1, *hdr2; struct xfs_attr_leafblock *leaf2 = blk2->bp->b_addr;
xfs_attr_leaf_entry_t *entry; struct xfs_attr_leaf_entry *entry;
int count, max, index, totallen, half; int count;
int lastdelta, foundit, tmp; int max;
int index;
/* int totallen = 0;
* Set up environment. int half;
*/ int lastdelta;
leaf1 = blk1->bp->b_addr; int foundit = 0;
leaf2 = blk2->bp->b_addr; int tmp;
hdr1 = &leaf1->hdr;
hdr2 = &leaf2->hdr;
foundit = 0;
totallen = 0;
/* /*
* Examine entries until we reduce the absolute difference in * Examine entries until we reduce the absolute difference in
* byte usage between the two blocks to a minimum. * byte usage between the two blocks to a minimum.
*/ */
max = be16_to_cpu(hdr1->count) + be16_to_cpu(hdr2->count); max = ichdr1->count + ichdr2->count;
half = (max+1) * sizeof(*entry); half = (max + 1) * sizeof(*entry);
half += be16_to_cpu(hdr1->usedbytes) + half += ichdr1->usedbytes + ichdr2->usedbytes +
be16_to_cpu(hdr2->usedbytes) + xfs_attr_leaf_newentsize(state->args->namelen,
xfs_attr_leaf_newentsize( state->args->valuelen,
state->args->namelen, state->blocksize, NULL);
state->args->valuelen,
state->blocksize, NULL);
half /= 2; half /= 2;
lastdelta = state->blocksize; lastdelta = state->blocksize;
entry = &leaf1->entries[0]; entry = xfs_attr3_leaf_entryp(leaf1);
for (count = index = 0; count < max; entry++, index++, count++) { for (count = index = 0; count < max; entry++, index++, count++) {
#define XFS_ATTR_ABS(A) (((A) < 0) ? -(A) : (A)) #define XFS_ATTR_ABS(A) (((A) < 0) ? -(A) : (A))
...@@ -1567,9 +1784,9 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state, ...@@ -1567,9 +1784,9 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
/* /*
* Wrap around into the second block if necessary. * Wrap around into the second block if necessary.
*/ */
if (count == be16_to_cpu(hdr1->count)) { if (count == ichdr1->count) {
leaf1 = leaf2; leaf1 = leaf2;
entry = &leaf1->entries[0]; entry = xfs_attr3_leaf_entryp(leaf1);
index = 0; index = 0;
} }
...@@ -1600,7 +1817,7 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state, ...@@ -1600,7 +1817,7 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
*countarg = count; *countarg = count;
*usedbytesarg = totallen; *usedbytesarg = totallen;
return(foundit); return foundit;
} }
/*======================================================================== /*========================================================================
...@@ -1619,14 +1836,20 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state, ...@@ -1619,14 +1836,20 @@ xfs_attr_leaf_figure_balance(xfs_da_state_t *state,
* GROT: allow for INCOMPLETE entries in calculation. * GROT: allow for INCOMPLETE entries in calculation.
*/ */
int int
xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) xfs_attr3_leaf_toosmall(
struct xfs_da_state *state,
int *action)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_da_state_blk_t *blk; struct xfs_da_state_blk *blk;
xfs_da_blkinfo_t *info; struct xfs_attr3_icleaf_hdr ichdr;
int count, bytes, forward, error, retval, i; struct xfs_buf *bp;
xfs_dablk_t blkno; xfs_dablk_t blkno;
struct xfs_buf *bp; int bytes;
int forward;
int error;
int retval;
int i;
trace_xfs_attr_leaf_toosmall(state->args); trace_xfs_attr_leaf_toosmall(state->args);
...@@ -1636,13 +1859,11 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) ...@@ -1636,13 +1859,11 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
* to coalesce with a sibling. * to coalesce with a sibling.
*/ */
blk = &state->path.blk[ state->path.active-1 ]; blk = &state->path.blk[ state->path.active-1 ];
info = blk->bp->b_addr; leaf = blk->bp->b_addr;
ASSERT(info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
leaf = (xfs_attr_leafblock_t *)info; bytes = xfs_attr3_leaf_hdr_size(leaf) +
count = be16_to_cpu(leaf->hdr.count); ichdr.count * sizeof(xfs_attr_leaf_entry_t) +
bytes = sizeof(xfs_attr_leaf_hdr_t) + ichdr.usedbytes;
count * sizeof(xfs_attr_leaf_entry_t) +
be16_to_cpu(leaf->hdr.usedbytes);
if (bytes > (state->blocksize >> 1)) { if (bytes > (state->blocksize >> 1)) {
*action = 0; /* blk over 50%, don't try to join */ *action = 0; /* blk over 50%, don't try to join */
return(0); return(0);
...@@ -1654,12 +1875,12 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) ...@@ -1654,12 +1875,12 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
* coalesce it with a sibling block. We choose (arbitrarily) * coalesce it with a sibling block. We choose (arbitrarily)
* to merge with the forward block unless it is NULL. * to merge with the forward block unless it is NULL.
*/ */
if (count == 0) { if (ichdr.count == 0) {
/* /*
* Make altpath point to the block we want to keep and * Make altpath point to the block we want to keep and
* path point to the block we want to drop (this one). * path point to the block we want to drop (this one).
*/ */
forward = (info->forw != 0); forward = (ichdr.forw != 0);
memcpy(&state->altpath, &state->path, sizeof(state->path)); memcpy(&state->altpath, &state->path, sizeof(state->path));
error = xfs_da3_path_shift(state, &state->altpath, forward, error = xfs_da3_path_shift(state, &state->altpath, forward,
0, &retval); 0, &retval);
...@@ -1670,7 +1891,7 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) ...@@ -1670,7 +1891,7 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
} else { } else {
*action = 2; *action = 2;
} }
return(0); return 0;
} }
/* /*
...@@ -1681,28 +1902,28 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) ...@@ -1681,28 +1902,28 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
* to shrink an attribute list over time. * to shrink an attribute list over time.
*/ */
/* start with smaller blk num */ /* start with smaller blk num */
forward = (be32_to_cpu(info->forw) < be32_to_cpu(info->back)); forward = ichdr.forw < ichdr.back;
for (i = 0; i < 2; forward = !forward, i++) { for (i = 0; i < 2; forward = !forward, i++) {
struct xfs_attr3_icleaf_hdr ichdr2;
if (forward) if (forward)
blkno = be32_to_cpu(info->forw); blkno = ichdr.forw;
else else
blkno = be32_to_cpu(info->back); blkno = ichdr.back;
if (blkno == 0) if (blkno == 0)
continue; continue;
error = xfs_attr_leaf_read(state->args->trans, state->args->dp, error = xfs_attr3_leaf_read(state->args->trans, state->args->dp,
blkno, -1, &bp); blkno, -1, &bp);
if (error) if (error)
return(error); return(error);
leaf = (xfs_attr_leafblock_t *)info; xfs_attr3_leaf_hdr_from_disk(&ichdr2, bp->b_addr);
count = be16_to_cpu(leaf->hdr.count);
bytes = state->blocksize - (state->blocksize>>2); bytes = state->blocksize - (state->blocksize >> 2) -
bytes -= be16_to_cpu(leaf->hdr.usedbytes); ichdr.usedbytes - ichdr2.usedbytes -
leaf = bp->b_addr; ((ichdr.count + ichdr2.count) *
count += be16_to_cpu(leaf->hdr.count); sizeof(xfs_attr_leaf_entry_t)) -
bytes -= be16_to_cpu(leaf->hdr.usedbytes); xfs_attr3_leaf_hdr_size(leaf);
bytes -= count * sizeof(xfs_attr_leaf_entry_t);
bytes -= sizeof(xfs_attr_leaf_hdr_t);
xfs_trans_brelse(state->args->trans, bp); xfs_trans_brelse(state->args->trans, bp);
if (bytes >= 0) if (bytes >= 0)
break; /* fits with at least 25% to spare */ break; /* fits with at least 25% to spare */
...@@ -1741,32 +1962,35 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action) ...@@ -1741,32 +1962,35 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
* If two leaves are 37% full, when combined they will leave 25% free. * If two leaves are 37% full, when combined they will leave 25% free.
*/ */
int int
xfs_attr_leaf_remove( xfs_attr3_leaf_remove(
struct xfs_buf *bp, struct xfs_buf *bp,
xfs_da_args_t *args) struct xfs_da_args *args)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_hdr_t *hdr; struct xfs_attr3_icleaf_hdr ichdr;
xfs_attr_leaf_map_t *map; struct xfs_attr_leaf_entry *entry;
xfs_attr_leaf_entry_t *entry; struct xfs_mount *mp = args->trans->t_mountp;
int before, after, smallest, entsize; int before;
int tablesize, tmp, i; int after;
xfs_mount_t *mp; int smallest;
int entsize;
int tablesize;
int tmp;
int i;
trace_xfs_attr_leaf_remove(args); trace_xfs_attr_leaf_remove(args);
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
hdr = &leaf->hdr;
mp = args->trans->t_mountp; ASSERT(ichdr.count > 0 && ichdr.count < XFS_LBSIZE(mp) / 8);
ASSERT((be16_to_cpu(hdr->count) > 0) ASSERT(args->index >= 0 && args->index < ichdr.count);
&& (be16_to_cpu(hdr->count) < (XFS_LBSIZE(mp)/8))); ASSERT(ichdr.firstused >= ichdr.count * sizeof(*entry) +
ASSERT((args->index >= 0) xfs_attr3_leaf_hdr_size(leaf));
&& (args->index < be16_to_cpu(hdr->count)));
ASSERT(be16_to_cpu(hdr->firstused) >= entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
((be16_to_cpu(hdr->count) * sizeof(*entry)) + sizeof(*hdr)));
entry = &leaf->entries[args->index]; ASSERT(be16_to_cpu(entry->nameidx) >= ichdr.firstused);
ASSERT(be16_to_cpu(entry->nameidx) >= be16_to_cpu(hdr->firstused));
ASSERT(be16_to_cpu(entry->nameidx) < XFS_LBSIZE(mp)); ASSERT(be16_to_cpu(entry->nameidx) < XFS_LBSIZE(mp));
/* /*
...@@ -1775,30 +1999,28 @@ xfs_attr_leaf_remove( ...@@ -1775,30 +1999,28 @@ xfs_attr_leaf_remove(
* find smallest free region in case we need to replace it, * find smallest free region in case we need to replace it,
* adjust any map that borders the entry table, * adjust any map that borders the entry table,
*/ */
tablesize = be16_to_cpu(hdr->count) * sizeof(xfs_attr_leaf_entry_t) tablesize = ichdr.count * sizeof(xfs_attr_leaf_entry_t)
+ sizeof(xfs_attr_leaf_hdr_t); + xfs_attr3_leaf_hdr_size(leaf);
map = &hdr->freemap[0]; tmp = ichdr.freemap[0].size;
tmp = be16_to_cpu(map->size);
before = after = -1; before = after = -1;
smallest = XFS_ATTR_LEAF_MAPSIZE - 1; smallest = XFS_ATTR_LEAF_MAPSIZE - 1;
entsize = xfs_attr_leaf_entsize(leaf, args->index); entsize = xfs_attr_leaf_entsize(leaf, args->index);
for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) { for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp)); ASSERT(ichdr.freemap[i].base < XFS_LBSIZE(mp));
ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp)); ASSERT(ichdr.freemap[i].size < XFS_LBSIZE(mp));
if (be16_to_cpu(map->base) == tablesize) { if (ichdr.freemap[i].base == tablesize) {
be16_add_cpu(&map->base, ichdr.freemap[i].base -= sizeof(xfs_attr_leaf_entry_t);
-((int)sizeof(xfs_attr_leaf_entry_t))); ichdr.freemap[i].size += sizeof(xfs_attr_leaf_entry_t);
be16_add_cpu(&map->size, sizeof(xfs_attr_leaf_entry_t));
} }
if ((be16_to_cpu(map->base) + be16_to_cpu(map->size)) if (ichdr.freemap[i].base + ichdr.freemap[i].size ==
== be16_to_cpu(entry->nameidx)) { be16_to_cpu(entry->nameidx)) {
before = i; before = i;
} else if (be16_to_cpu(map->base) } else if (ichdr.freemap[i].base ==
== (be16_to_cpu(entry->nameidx) + entsize)) { (be16_to_cpu(entry->nameidx) + entsize)) {
after = i; after = i;
} else if (be16_to_cpu(map->size) < tmp) { } else if (ichdr.freemap[i].size < tmp) {
tmp = be16_to_cpu(map->size); tmp = ichdr.freemap[i].size;
smallest = i; smallest = i;
} }
} }
...@@ -1809,36 +2031,30 @@ xfs_attr_leaf_remove( ...@@ -1809,36 +2031,30 @@ xfs_attr_leaf_remove(
*/ */
if ((before >= 0) || (after >= 0)) { if ((before >= 0) || (after >= 0)) {
if ((before >= 0) && (after >= 0)) { if ((before >= 0) && (after >= 0)) {
map = &hdr->freemap[before]; ichdr.freemap[before].size += entsize;
be16_add_cpu(&map->size, entsize); ichdr.freemap[before].size += ichdr.freemap[after].size;
be16_add_cpu(&map->size, ichdr.freemap[after].base = 0;
be16_to_cpu(hdr->freemap[after].size)); ichdr.freemap[after].size = 0;
hdr->freemap[after].base = 0;
hdr->freemap[after].size = 0;
} else if (before >= 0) { } else if (before >= 0) {
map = &hdr->freemap[before]; ichdr.freemap[before].size += entsize;
be16_add_cpu(&map->size, entsize);
} else { } else {
map = &hdr->freemap[after]; ichdr.freemap[after].base = be16_to_cpu(entry->nameidx);
/* both on-disk, don't endian flip twice */ ichdr.freemap[after].size += entsize;
map->base = entry->nameidx;
be16_add_cpu(&map->size, entsize);
} }
} else { } else {
/* /*
* Replace smallest region (if it is smaller than free'd entry) * Replace smallest region (if it is smaller than free'd entry)
*/ */
map = &hdr->freemap[smallest]; if (ichdr.freemap[smallest].size < entsize) {
if (be16_to_cpu(map->size) < entsize) { ichdr.freemap[smallest].base = be16_to_cpu(entry->nameidx);
map->base = cpu_to_be16(be16_to_cpu(entry->nameidx)); ichdr.freemap[smallest].size = entsize;
map->size = cpu_to_be16(entsize);
} }
} }
/* /*
* Did we remove the first entry? * Did we remove the first entry?
*/ */
if (be16_to_cpu(entry->nameidx) == be16_to_cpu(hdr->firstused)) if (be16_to_cpu(entry->nameidx) == ichdr.firstused)
smallest = 1; smallest = 1;
else else
smallest = 0; smallest = 0;
...@@ -1846,20 +2062,20 @@ xfs_attr_leaf_remove( ...@@ -1846,20 +2062,20 @@ xfs_attr_leaf_remove(
/* /*
* Compress the remaining entries and zero out the removed stuff. * Compress the remaining entries and zero out the removed stuff.
*/ */
memset(xfs_attr_leaf_name(leaf, args->index), 0, entsize); memset(xfs_attr3_leaf_name(leaf, args->index), 0, entsize);
be16_add_cpu(&hdr->usedbytes, -entsize); ichdr.usedbytes -= entsize;
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, xfs_attr_leaf_name(leaf, args->index), XFS_DA_LOGRANGE(leaf, xfs_attr3_leaf_name(leaf, args->index),
entsize)); entsize));
tmp = (be16_to_cpu(hdr->count) - args->index) tmp = (ichdr.count - args->index) * sizeof(xfs_attr_leaf_entry_t);
* sizeof(xfs_attr_leaf_entry_t); memmove(entry, entry + 1, tmp);
memmove((char *)entry, (char *)(entry+1), tmp); ichdr.count--;
be16_add_cpu(&hdr->count, -1);
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry))); XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(xfs_attr_leaf_entry_t)));
entry = &leaf->entries[be16_to_cpu(hdr->count)];
memset((char *)entry, 0, sizeof(xfs_attr_leaf_entry_t)); entry = &xfs_attr3_leaf_entryp(leaf)[ichdr.count];
memset(entry, 0, sizeof(xfs_attr_leaf_entry_t));
/* /*
* If we removed the first entry, re-find the first used byte * If we removed the first entry, re-find the first used byte
...@@ -1869,130 +2085,130 @@ xfs_attr_leaf_remove( ...@@ -1869,130 +2085,130 @@ xfs_attr_leaf_remove(
*/ */
if (smallest) { if (smallest) {
tmp = XFS_LBSIZE(mp); tmp = XFS_LBSIZE(mp);
entry = &leaf->entries[0]; entry = xfs_attr3_leaf_entryp(leaf);
for (i = be16_to_cpu(hdr->count)-1; i >= 0; entry++, i--) { for (i = ichdr.count - 1; i >= 0; entry++, i--) {
ASSERT(be16_to_cpu(entry->nameidx) >= ASSERT(be16_to_cpu(entry->nameidx) >= ichdr.firstused);
be16_to_cpu(hdr->firstused));
ASSERT(be16_to_cpu(entry->nameidx) < XFS_LBSIZE(mp)); ASSERT(be16_to_cpu(entry->nameidx) < XFS_LBSIZE(mp));
if (be16_to_cpu(entry->nameidx) < tmp) if (be16_to_cpu(entry->nameidx) < tmp)
tmp = be16_to_cpu(entry->nameidx); tmp = be16_to_cpu(entry->nameidx);
} }
hdr->firstused = cpu_to_be16(tmp); ichdr.firstused = tmp;
if (!hdr->firstused) { if (!ichdr.firstused)
hdr->firstused = cpu_to_be16( ichdr.firstused = tmp - XFS_ATTR_LEAF_NAME_ALIGN;
tmp - XFS_ATTR_LEAF_NAME_ALIGN);
}
} else { } else {
hdr->holes = 1; /* mark as needing compaction */ ichdr.holes = 1; /* mark as needing compaction */
} }
xfs_attr3_leaf_hdr_to_disk(leaf, &ichdr);
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr))); XFS_DA_LOGRANGE(leaf, &leaf->hdr,
xfs_attr3_leaf_hdr_size(leaf)));
/* /*
* Check if leaf is less than 50% full, caller may want to * Check if leaf is less than 50% full, caller may want to
* "join" the leaf with a sibling if so. * "join" the leaf with a sibling if so.
*/ */
tmp = sizeof(xfs_attr_leaf_hdr_t); tmp = ichdr.usedbytes + xfs_attr3_leaf_hdr_size(leaf) +
tmp += be16_to_cpu(leaf->hdr.count) * sizeof(xfs_attr_leaf_entry_t); ichdr.count * sizeof(xfs_attr_leaf_entry_t);
tmp += be16_to_cpu(leaf->hdr.usedbytes);
return(tmp < mp->m_attr_magicpct); /* leaf is < 37% full */ return tmp < mp->m_attr_magicpct; /* leaf is < 37% full */
} }
/* /*
* Move all the attribute list entries from drop_leaf into save_leaf. * Move all the attribute list entries from drop_leaf into save_leaf.
*/ */
void void
xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, xfs_attr3_leaf_unbalance(
xfs_da_state_blk_t *save_blk) struct xfs_da_state *state,
struct xfs_da_state_blk *drop_blk,
struct xfs_da_state_blk *save_blk)
{ {
xfs_attr_leafblock_t *drop_leaf, *save_leaf, *tmp_leaf; struct xfs_attr_leafblock *drop_leaf = drop_blk->bp->b_addr;
xfs_attr_leaf_hdr_t *drop_hdr, *save_hdr, *tmp_hdr; struct xfs_attr_leafblock *save_leaf = save_blk->bp->b_addr;
xfs_mount_t *mp; struct xfs_attr3_icleaf_hdr drophdr;
char *tmpbuffer; struct xfs_attr3_icleaf_hdr savehdr;
struct xfs_attr_leaf_entry *entry;
struct xfs_mount *mp = state->mp;
trace_xfs_attr_leaf_unbalance(state->args); trace_xfs_attr_leaf_unbalance(state->args);
/*
* Set up environment.
*/
mp = state->mp;
ASSERT(drop_blk->magic == XFS_ATTR_LEAF_MAGIC);
ASSERT(save_blk->magic == XFS_ATTR_LEAF_MAGIC);
drop_leaf = drop_blk->bp->b_addr; drop_leaf = drop_blk->bp->b_addr;
save_leaf = save_blk->bp->b_addr; save_leaf = save_blk->bp->b_addr;
ASSERT(drop_leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&drophdr, drop_leaf);
ASSERT(save_leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&savehdr, save_leaf);
drop_hdr = &drop_leaf->hdr; entry = xfs_attr3_leaf_entryp(drop_leaf);
save_hdr = &save_leaf->hdr;
/* /*
* Save last hashval from dying block for later Btree fixup. * Save last hashval from dying block for later Btree fixup.
*/ */
drop_blk->hashval = be32_to_cpu( drop_blk->hashval = be32_to_cpu(entry[drophdr.count - 1].hashval);
drop_leaf->entries[be16_to_cpu(drop_leaf->hdr.count)-1].hashval);
/* /*
* Check if we need a temp buffer, or can we do it in place. * Check if we need a temp buffer, or can we do it in place.
* Note that we don't check "leaf" for holes because we will * Note that we don't check "leaf" for holes because we will
* always be dropping it, toosmall() decided that for us already. * always be dropping it, toosmall() decided that for us already.
*/ */
if (save_hdr->holes == 0) { if (savehdr.holes == 0) {
/* /*
* dest leaf has no holes, so we add there. May need * dest leaf has no holes, so we add there. May need
* to make some room in the entry array. * to make some room in the entry array.
*/ */
if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) { if (xfs_attr3_leaf_order(save_blk->bp, &savehdr,
xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf, 0, drop_blk->bp, &drophdr)) {
be16_to_cpu(drop_hdr->count), mp); xfs_attr3_leaf_moveents(drop_leaf, &drophdr, 0,
save_leaf, &savehdr, 0,
drophdr.count, mp);
} else { } else {
xfs_attr_leaf_moveents(drop_leaf, 0, save_leaf, xfs_attr3_leaf_moveents(drop_leaf, &drophdr, 0,
be16_to_cpu(save_hdr->count), save_leaf, &savehdr,
be16_to_cpu(drop_hdr->count), mp); savehdr.count, drophdr.count, mp);
} }
} else { } else {
/* /*
* Destination has holes, so we make a temporary copy * Destination has holes, so we make a temporary copy
* of the leaf and add them both to that. * of the leaf and add them both to that.
*/ */
tmpbuffer = kmem_alloc(state->blocksize, KM_SLEEP); struct xfs_attr_leafblock *tmp_leaf;
ASSERT(tmpbuffer != NULL); struct xfs_attr3_icleaf_hdr tmphdr;
memset(tmpbuffer, 0, state->blocksize);
tmp_leaf = (xfs_attr_leafblock_t *)tmpbuffer; tmp_leaf = kmem_alloc(state->blocksize, KM_SLEEP);
tmp_hdr = &tmp_leaf->hdr; memset(tmp_leaf, 0, state->blocksize);
tmp_hdr->info = save_hdr->info; /* struct copy */ memset(&tmphdr, 0, sizeof(tmphdr));
tmp_hdr->count = 0;
tmp_hdr->firstused = cpu_to_be16(state->blocksize); tmphdr.magic = savehdr.magic;
if (!tmp_hdr->firstused) { tmphdr.forw = savehdr.forw;
tmp_hdr->firstused = cpu_to_be16( tmphdr.back = savehdr.back;
state->blocksize - XFS_ATTR_LEAF_NAME_ALIGN); tmphdr.firstused = state->blocksize;
} if (xfs_attr3_leaf_order(save_blk->bp, &savehdr,
tmp_hdr->usedbytes = 0; drop_blk->bp, &drophdr)) {
if (xfs_attr_leaf_order(save_blk->bp, drop_blk->bp)) { xfs_attr3_leaf_moveents(drop_leaf, &drophdr, 0,
xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf, 0, tmp_leaf, &tmphdr, 0,
be16_to_cpu(drop_hdr->count), mp); drophdr.count, mp);
xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf, xfs_attr3_leaf_moveents(save_leaf, &savehdr, 0,
be16_to_cpu(tmp_leaf->hdr.count), tmp_leaf, &tmphdr, tmphdr.count,
be16_to_cpu(save_hdr->count), mp); savehdr.count, mp);
} else { } else {
xfs_attr_leaf_moveents(save_leaf, 0, tmp_leaf, 0, xfs_attr3_leaf_moveents(save_leaf, &savehdr, 0,
be16_to_cpu(save_hdr->count), mp); tmp_leaf, &tmphdr, 0,
xfs_attr_leaf_moveents(drop_leaf, 0, tmp_leaf, savehdr.count, mp);
be16_to_cpu(tmp_leaf->hdr.count), xfs_attr3_leaf_moveents(drop_leaf, &drophdr, 0,
be16_to_cpu(drop_hdr->count), mp); tmp_leaf, &tmphdr, tmphdr.count,
drophdr.count, mp);
} }
memcpy((char *)save_leaf, (char *)tmp_leaf, state->blocksize); memcpy(save_leaf, tmp_leaf, state->blocksize);
kmem_free(tmpbuffer); savehdr = tmphdr; /* struct copy */
kmem_free(tmp_leaf);
} }
xfs_attr3_leaf_hdr_to_disk(save_leaf, &savehdr);
xfs_trans_log_buf(state->args->trans, save_blk->bp, 0, xfs_trans_log_buf(state->args->trans, save_blk->bp, 0,
state->blocksize - 1); state->blocksize - 1);
/* /*
* Copy out last hashval in each block for B-tree code. * Copy out last hashval in each block for B-tree code.
*/ */
save_blk->hashval = be32_to_cpu( entry = xfs_attr3_leaf_entryp(save_leaf);
save_leaf->entries[be16_to_cpu(save_leaf->hdr.count)-1].hashval); save_blk->hashval = be32_to_cpu(entry[savehdr.count - 1].hashval);
} }
/*======================================================================== /*========================================================================
...@@ -2013,31 +2229,33 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, ...@@ -2013,31 +2229,33 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
* Don't change the args->value unless we find the attribute. * Don't change the args->value unless we find the attribute.
*/ */
int int
xfs_attr_leaf_lookup_int( xfs_attr3_leaf_lookup_int(
struct xfs_buf *bp, struct xfs_buf *bp,
xfs_da_args_t *args) struct xfs_da_args *args)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_entry_t *entry; struct xfs_attr3_icleaf_hdr ichdr;
xfs_attr_leaf_name_local_t *name_loc; struct xfs_attr_leaf_entry *entry;
xfs_attr_leaf_name_remote_t *name_rmt; struct xfs_attr_leaf_entry *entries;
int probe, span; struct xfs_attr_leaf_name_local *name_loc;
xfs_dahash_t hashval; struct xfs_attr_leaf_name_remote *name_rmt;
xfs_dahash_t hashval;
int probe;
int span;
trace_xfs_attr_leaf_lookup(args); trace_xfs_attr_leaf_lookup(args);
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
ASSERT(be16_to_cpu(leaf->hdr.count) entries = xfs_attr3_leaf_entryp(leaf);
< (XFS_LBSIZE(args->dp->i_mount)/8)); ASSERT(ichdr.count < XFS_LBSIZE(args->dp->i_mount) / 8);
/* /*
* Binary search. (note: small blocks will skip this loop) * Binary search. (note: small blocks will skip this loop)
*/ */
hashval = args->hashval; hashval = args->hashval;
probe = span = be16_to_cpu(leaf->hdr.count) / 2; probe = span = ichdr.count / 2;
for (entry = &leaf->entries[probe]; span > 4; for (entry = &entries[probe]; span > 4; entry = &entries[probe]) {
entry = &leaf->entries[probe]) {
span /= 2; span /= 2;
if (be32_to_cpu(entry->hashval) < hashval) if (be32_to_cpu(entry->hashval) < hashval)
probe += span; probe += span;
...@@ -2046,35 +2264,31 @@ xfs_attr_leaf_lookup_int( ...@@ -2046,35 +2264,31 @@ xfs_attr_leaf_lookup_int(
else else
break; break;
} }
ASSERT((probe >= 0) && ASSERT(probe >= 0 && (!ichdr.count || probe < ichdr.count));
(!leaf->hdr.count ASSERT(span <= 4 || be32_to_cpu(entry->hashval) == hashval);
|| (probe < be16_to_cpu(leaf->hdr.count))));
ASSERT((span <= 4) || (be32_to_cpu(entry->hashval) == hashval));
/* /*
* Since we may have duplicate hashval's, find the first matching * Since we may have duplicate hashval's, find the first matching
* hashval in the leaf. * hashval in the leaf.
*/ */
while ((probe > 0) && (be32_to_cpu(entry->hashval) >= hashval)) { while (probe > 0 && be32_to_cpu(entry->hashval) >= hashval) {
entry--; entry--;
probe--; probe--;
} }
while ((probe < be16_to_cpu(leaf->hdr.count)) && while (probe < ichdr.count &&
(be32_to_cpu(entry->hashval) < hashval)) { be32_to_cpu(entry->hashval) < hashval) {
entry++; entry++;
probe++; probe++;
} }
if ((probe == be16_to_cpu(leaf->hdr.count)) || if (probe == ichdr.count || be32_to_cpu(entry->hashval) != hashval) {
(be32_to_cpu(entry->hashval) != hashval)) {
args->index = probe; args->index = probe;
return(XFS_ERROR(ENOATTR)); return XFS_ERROR(ENOATTR);
} }
/* /*
* Duplicate keys may be present, so search all of them for a match. * Duplicate keys may be present, so search all of them for a match.
*/ */
for ( ; (probe < be16_to_cpu(leaf->hdr.count)) && for (; probe < ichdr.count && (be32_to_cpu(entry->hashval) == hashval);
(be32_to_cpu(entry->hashval) == hashval);
entry++, probe++) { entry++, probe++) {
/* /*
* GROT: Add code to remove incomplete entries. * GROT: Add code to remove incomplete entries.
...@@ -2088,21 +2302,22 @@ xfs_attr_leaf_lookup_int( ...@@ -2088,21 +2302,22 @@ xfs_attr_leaf_lookup_int(
continue; continue;
} }
if (entry->flags & XFS_ATTR_LOCAL) { if (entry->flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr_leaf_name_local(leaf, probe); name_loc = xfs_attr3_leaf_name_local(leaf, probe);
if (name_loc->namelen != args->namelen) if (name_loc->namelen != args->namelen)
continue; continue;
if (memcmp(args->name, (char *)name_loc->nameval, args->namelen) != 0) if (memcmp(args->name, name_loc->nameval,
args->namelen) != 0)
continue; continue;
if (!xfs_attr_namesp_match(args->flags, entry->flags)) if (!xfs_attr_namesp_match(args->flags, entry->flags))
continue; continue;
args->index = probe; args->index = probe;
return(XFS_ERROR(EEXIST)); return XFS_ERROR(EEXIST);
} else { } else {
name_rmt = xfs_attr_leaf_name_remote(leaf, probe); name_rmt = xfs_attr3_leaf_name_remote(leaf, probe);
if (name_rmt->namelen != args->namelen) if (name_rmt->namelen != args->namelen)
continue; continue;
if (memcmp(args->name, (char *)name_rmt->name, if (memcmp(args->name, name_rmt->name,
args->namelen) != 0) args->namelen) != 0)
continue; continue;
if (!xfs_attr_namesp_match(args->flags, entry->flags)) if (!xfs_attr_namesp_match(args->flags, entry->flags))
continue; continue;
...@@ -2110,11 +2325,11 @@ xfs_attr_leaf_lookup_int( ...@@ -2110,11 +2325,11 @@ xfs_attr_leaf_lookup_int(
args->rmtblkno = be32_to_cpu(name_rmt->valueblk); args->rmtblkno = be32_to_cpu(name_rmt->valueblk);
args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount, args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount,
be32_to_cpu(name_rmt->valuelen)); be32_to_cpu(name_rmt->valuelen));
return(XFS_ERROR(EEXIST)); return XFS_ERROR(EEXIST);
} }
} }
args->index = probe; args->index = probe;
return(XFS_ERROR(ENOATTR)); return XFS_ERROR(ENOATTR);
} }
/* /*
...@@ -2122,40 +2337,40 @@ xfs_attr_leaf_lookup_int( ...@@ -2122,40 +2337,40 @@ xfs_attr_leaf_lookup_int(
* list structure. * list structure.
*/ */
int int
xfs_attr_leaf_getvalue( xfs_attr3_leaf_getvalue(
struct xfs_buf *bp, struct xfs_buf *bp,
xfs_da_args_t *args) struct xfs_da_args *args)
{ {
int valuelen; struct xfs_attr_leafblock *leaf;
xfs_attr_leafblock_t *leaf; struct xfs_attr3_icleaf_hdr ichdr;
xfs_attr_leaf_entry_t *entry; struct xfs_attr_leaf_entry *entry;
xfs_attr_leaf_name_local_t *name_loc; struct xfs_attr_leaf_name_local *name_loc;
xfs_attr_leaf_name_remote_t *name_rmt; struct xfs_attr_leaf_name_remote *name_rmt;
int valuelen;
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
ASSERT(be16_to_cpu(leaf->hdr.count) ASSERT(ichdr.count < XFS_LBSIZE(args->dp->i_mount) / 8);
< (XFS_LBSIZE(args->dp->i_mount)/8)); ASSERT(args->index < ichdr.count);
ASSERT(args->index < be16_to_cpu(leaf->hdr.count));
entry = &leaf->entries[args->index]; entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
if (entry->flags & XFS_ATTR_LOCAL) { if (entry->flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr_leaf_name_local(leaf, args->index); name_loc = xfs_attr3_leaf_name_local(leaf, args->index);
ASSERT(name_loc->namelen == args->namelen); ASSERT(name_loc->namelen == args->namelen);
ASSERT(memcmp(args->name, name_loc->nameval, args->namelen) == 0); ASSERT(memcmp(args->name, name_loc->nameval, args->namelen) == 0);
valuelen = be16_to_cpu(name_loc->valuelen); valuelen = be16_to_cpu(name_loc->valuelen);
if (args->flags & ATTR_KERNOVAL) { if (args->flags & ATTR_KERNOVAL) {
args->valuelen = valuelen; args->valuelen = valuelen;
return(0); return 0;
} }
if (args->valuelen < valuelen) { if (args->valuelen < valuelen) {
args->valuelen = valuelen; args->valuelen = valuelen;
return(XFS_ERROR(ERANGE)); return XFS_ERROR(ERANGE);
} }
args->valuelen = valuelen; args->valuelen = valuelen;
memcpy(args->value, &name_loc->nameval[args->namelen], valuelen); memcpy(args->value, &name_loc->nameval[args->namelen], valuelen);
} else { } else {
name_rmt = xfs_attr_leaf_name_remote(leaf, args->index); name_rmt = xfs_attr3_leaf_name_remote(leaf, args->index);
ASSERT(name_rmt->namelen == args->namelen); ASSERT(name_rmt->namelen == args->namelen);
ASSERT(memcmp(args->name, name_rmt->name, args->namelen) == 0); ASSERT(memcmp(args->name, name_rmt->name, args->namelen) == 0);
valuelen = be32_to_cpu(name_rmt->valuelen); valuelen = be32_to_cpu(name_rmt->valuelen);
...@@ -2163,15 +2378,15 @@ xfs_attr_leaf_getvalue( ...@@ -2163,15 +2378,15 @@ xfs_attr_leaf_getvalue(
args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount, valuelen); args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount, valuelen);
if (args->flags & ATTR_KERNOVAL) { if (args->flags & ATTR_KERNOVAL) {
args->valuelen = valuelen; args->valuelen = valuelen;
return(0); return 0;
} }
if (args->valuelen < valuelen) { if (args->valuelen < valuelen) {
args->valuelen = valuelen; args->valuelen = valuelen;
return(XFS_ERROR(ERANGE)); return XFS_ERROR(ERANGE);
} }
args->valuelen = valuelen; args->valuelen = valuelen;
} }
return(0); return 0;
} }
/*======================================================================== /*========================================================================
...@@ -2184,13 +2399,21 @@ xfs_attr_leaf_getvalue( ...@@ -2184,13 +2399,21 @@ xfs_attr_leaf_getvalue(
*/ */
/*ARGSUSED*/ /*ARGSUSED*/
STATIC void STATIC void
xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s, xfs_attr3_leaf_moveents(
xfs_attr_leafblock_t *leaf_d, int start_d, struct xfs_attr_leafblock *leaf_s,
int count, xfs_mount_t *mp) struct xfs_attr3_icleaf_hdr *ichdr_s,
int start_s,
struct xfs_attr_leafblock *leaf_d,
struct xfs_attr3_icleaf_hdr *ichdr_d,
int start_d,
int count,
struct xfs_mount *mp)
{ {
xfs_attr_leaf_hdr_t *hdr_s, *hdr_d; struct xfs_attr_leaf_entry *entry_s;
xfs_attr_leaf_entry_t *entry_s, *entry_d; struct xfs_attr_leaf_entry *entry_d;
int desti, tmp, i; int desti;
int tmp;
int i;
/* /*
* Check for nothing to do. * Check for nothing to do.
...@@ -2201,45 +2424,41 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s, ...@@ -2201,45 +2424,41 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
/* /*
* Set up environment. * Set up environment.
*/ */
ASSERT(leaf_s->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); ASSERT(ichdr_s->magic == XFS_ATTR_LEAF_MAGIC ||
ASSERT(leaf_d->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); ichdr_s->magic == XFS_ATTR3_LEAF_MAGIC);
hdr_s = &leaf_s->hdr; ASSERT(ichdr_s->magic == ichdr_d->magic);
hdr_d = &leaf_d->hdr; ASSERT(ichdr_s->count > 0 && ichdr_s->count < XFS_LBSIZE(mp) / 8);
ASSERT((be16_to_cpu(hdr_s->count) > 0) && ASSERT(ichdr_s->firstused >= (ichdr_s->count * sizeof(*entry_s))
(be16_to_cpu(hdr_s->count) < (XFS_LBSIZE(mp)/8))); + xfs_attr3_leaf_hdr_size(leaf_s));
ASSERT(be16_to_cpu(hdr_s->firstused) >= ASSERT(ichdr_d->count < XFS_LBSIZE(mp) / 8);
((be16_to_cpu(hdr_s->count) ASSERT(ichdr_d->firstused >= (ichdr_d->count * sizeof(*entry_d))
* sizeof(*entry_s))+sizeof(*hdr_s))); + xfs_attr3_leaf_hdr_size(leaf_d));
ASSERT(be16_to_cpu(hdr_d->count) < (XFS_LBSIZE(mp)/8));
ASSERT(be16_to_cpu(hdr_d->firstused) >= ASSERT(start_s < ichdr_s->count);
((be16_to_cpu(hdr_d->count) ASSERT(start_d <= ichdr_d->count);
* sizeof(*entry_d))+sizeof(*hdr_d))); ASSERT(count <= ichdr_s->count);
ASSERT(start_s < be16_to_cpu(hdr_s->count));
ASSERT(start_d <= be16_to_cpu(hdr_d->count));
ASSERT(count <= be16_to_cpu(hdr_s->count));
/* /*
* Move the entries in the destination leaf up to make a hole? * Move the entries in the destination leaf up to make a hole?
*/ */
if (start_d < be16_to_cpu(hdr_d->count)) { if (start_d < ichdr_d->count) {
tmp = be16_to_cpu(hdr_d->count) - start_d; tmp = ichdr_d->count - start_d;
tmp *= sizeof(xfs_attr_leaf_entry_t); tmp *= sizeof(xfs_attr_leaf_entry_t);
entry_s = &leaf_d->entries[start_d]; entry_s = &xfs_attr3_leaf_entryp(leaf_d)[start_d];
entry_d = &leaf_d->entries[start_d + count]; entry_d = &xfs_attr3_leaf_entryp(leaf_d)[start_d + count];
memmove((char *)entry_d, (char *)entry_s, tmp); memmove(entry_d, entry_s, tmp);
} }
/* /*
* Copy all entry's in the same (sorted) order, * Copy all entry's in the same (sorted) order,
* but allocate attribute info packed and in sequence. * but allocate attribute info packed and in sequence.
*/ */
entry_s = &leaf_s->entries[start_s]; entry_s = &xfs_attr3_leaf_entryp(leaf_s)[start_s];
entry_d = &leaf_d->entries[start_d]; entry_d = &xfs_attr3_leaf_entryp(leaf_d)[start_d];
desti = start_d; desti = start_d;
for (i = 0; i < count; entry_s++, entry_d++, desti++, i++) { for (i = 0; i < count; entry_s++, entry_d++, desti++, i++) {
ASSERT(be16_to_cpu(entry_s->nameidx) ASSERT(be16_to_cpu(entry_s->nameidx) >= ichdr_s->firstused);
>= be16_to_cpu(hdr_s->firstused));
tmp = xfs_attr_leaf_entsize(leaf_s, start_s + i); tmp = xfs_attr_leaf_entsize(leaf_s, start_s + i);
#ifdef GROT #ifdef GROT
/* /*
...@@ -2248,36 +2467,34 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s, ...@@ -2248,36 +2467,34 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
* off for 6.2, should be revisited later. * off for 6.2, should be revisited later.
*/ */
if (entry_s->flags & XFS_ATTR_INCOMPLETE) { /* skip partials? */ if (entry_s->flags & XFS_ATTR_INCOMPLETE) { /* skip partials? */
memset(xfs_attr_leaf_name(leaf_s, start_s + i), 0, tmp); memset(xfs_attr3_leaf_name(leaf_s, start_s + i), 0, tmp);
be16_add_cpu(&hdr_s->usedbytes, -tmp); ichdr_s->usedbytes -= tmp;
be16_add_cpu(&hdr_s->count, -1); ichdr_s->count -= 1;
entry_d--; /* to compensate for ++ in loop hdr */ entry_d--; /* to compensate for ++ in loop hdr */
desti--; desti--;
if ((start_s + i) < offset) if ((start_s + i) < offset)
result++; /* insertion index adjustment */ result++; /* insertion index adjustment */
} else { } else {
#endif /* GROT */ #endif /* GROT */
be16_add_cpu(&hdr_d->firstused, -tmp); ichdr_d->firstused -= tmp;
/* both on-disk, don't endian flip twice */ /* both on-disk, don't endian flip twice */
entry_d->hashval = entry_s->hashval; entry_d->hashval = entry_s->hashval;
/* both on-disk, don't endian flip twice */ entry_d->nameidx = cpu_to_be16(ichdr_d->firstused);
entry_d->nameidx = hdr_d->firstused;
entry_d->flags = entry_s->flags; entry_d->flags = entry_s->flags;
ASSERT(be16_to_cpu(entry_d->nameidx) + tmp ASSERT(be16_to_cpu(entry_d->nameidx) + tmp
<= XFS_LBSIZE(mp)); <= XFS_LBSIZE(mp));
memmove(xfs_attr_leaf_name(leaf_d, desti), memmove(xfs_attr3_leaf_name(leaf_d, desti),
xfs_attr_leaf_name(leaf_s, start_s + i), tmp); xfs_attr3_leaf_name(leaf_s, start_s + i), tmp);
ASSERT(be16_to_cpu(entry_s->nameidx) + tmp ASSERT(be16_to_cpu(entry_s->nameidx) + tmp
<= XFS_LBSIZE(mp)); <= XFS_LBSIZE(mp));
memset(xfs_attr_leaf_name(leaf_s, start_s + i), 0, tmp); memset(xfs_attr3_leaf_name(leaf_s, start_s + i), 0, tmp);
be16_add_cpu(&hdr_s->usedbytes, -tmp); ichdr_s->usedbytes -= tmp;
be16_add_cpu(&hdr_d->usedbytes, tmp); ichdr_d->usedbytes += tmp;
be16_add_cpu(&hdr_s->count, -1); ichdr_s->count -= 1;
be16_add_cpu(&hdr_d->count, 1); ichdr_d->count += 1;
tmp = be16_to_cpu(hdr_d->count) tmp = ichdr_d->count * sizeof(xfs_attr_leaf_entry_t)
* sizeof(xfs_attr_leaf_entry_t) + xfs_attr3_leaf_hdr_size(leaf_d);
+ sizeof(xfs_attr_leaf_hdr_t); ASSERT(ichdr_d->firstused >= tmp);
ASSERT(be16_to_cpu(hdr_d->firstused) >= tmp);
#ifdef GROT #ifdef GROT
} }
#endif /* GROT */ #endif /* GROT */
...@@ -2286,71 +2503,40 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s, ...@@ -2286,71 +2503,40 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
/* /*
* Zero out the entries we just copied. * Zero out the entries we just copied.
*/ */
if (start_s == be16_to_cpu(hdr_s->count)) { if (start_s == ichdr_s->count) {
tmp = count * sizeof(xfs_attr_leaf_entry_t); tmp = count * sizeof(xfs_attr_leaf_entry_t);
entry_s = &leaf_s->entries[start_s]; entry_s = &xfs_attr3_leaf_entryp(leaf_s)[start_s];
ASSERT(((char *)entry_s + tmp) <= ASSERT(((char *)entry_s + tmp) <=
((char *)leaf_s + XFS_LBSIZE(mp))); ((char *)leaf_s + XFS_LBSIZE(mp)));
memset((char *)entry_s, 0, tmp); memset(entry_s, 0, tmp);
} else { } else {
/* /*
* Move the remaining entries down to fill the hole, * Move the remaining entries down to fill the hole,
* then zero the entries at the top. * then zero the entries at the top.
*/ */
tmp = be16_to_cpu(hdr_s->count) - count; tmp = (ichdr_s->count - count) * sizeof(xfs_attr_leaf_entry_t);
tmp *= sizeof(xfs_attr_leaf_entry_t); entry_s = &xfs_attr3_leaf_entryp(leaf_s)[start_s + count];
entry_s = &leaf_s->entries[start_s + count]; entry_d = &xfs_attr3_leaf_entryp(leaf_s)[start_s];
entry_d = &leaf_s->entries[start_s]; memmove(entry_d, entry_s, tmp);
memmove((char *)entry_d, (char *)entry_s, tmp);
tmp = count * sizeof(xfs_attr_leaf_entry_t); tmp = count * sizeof(xfs_attr_leaf_entry_t);
entry_s = &leaf_s->entries[be16_to_cpu(hdr_s->count)]; entry_s = &xfs_attr3_leaf_entryp(leaf_s)[ichdr_s->count];
ASSERT(((char *)entry_s + tmp) <= ASSERT(((char *)entry_s + tmp) <=
((char *)leaf_s + XFS_LBSIZE(mp))); ((char *)leaf_s + XFS_LBSIZE(mp)));
memset((char *)entry_s, 0, tmp); memset(entry_s, 0, tmp);
} }
/* /*
* Fill in the freemap information * Fill in the freemap information
*/ */
hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t)); ichdr_d->freemap[0].base = xfs_attr3_leaf_hdr_size(leaf_d);
be16_add_cpu(&hdr_d->freemap[0].base, be16_to_cpu(hdr_d->count) * ichdr_d->freemap[0].base += ichdr_d->count * sizeof(xfs_attr_leaf_entry_t);
sizeof(xfs_attr_leaf_entry_t)); ichdr_d->freemap[0].size = ichdr_d->firstused - ichdr_d->freemap[0].base;
hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused) ichdr_d->freemap[1].base = 0;
- be16_to_cpu(hdr_d->freemap[0].base)); ichdr_d->freemap[2].base = 0;
hdr_d->freemap[1].base = 0; ichdr_d->freemap[1].size = 0;
hdr_d->freemap[2].base = 0; ichdr_d->freemap[2].size = 0;
hdr_d->freemap[1].size = 0; ichdr_s->holes = 1; /* leaf may not be compact */
hdr_d->freemap[2].size = 0;
hdr_s->holes = 1; /* leaf may not be compact */
}
/*
* Compare two leaf blocks "order".
* Return 0 unless leaf2 should go before leaf1.
*/
int
xfs_attr_leaf_order(
struct xfs_buf *leaf1_bp,
struct xfs_buf *leaf2_bp)
{
xfs_attr_leafblock_t *leaf1, *leaf2;
leaf1 = leaf1_bp->b_addr;
leaf2 = leaf2_bp->b_addr;
ASSERT((leaf1->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)) &&
(leaf2->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)));
if ((be16_to_cpu(leaf1->hdr.count) > 0) &&
(be16_to_cpu(leaf2->hdr.count) > 0) &&
((be32_to_cpu(leaf2->entries[0].hashval) <
be32_to_cpu(leaf1->entries[0].hashval)) ||
(be32_to_cpu(leaf2->entries[
be16_to_cpu(leaf2->hdr.count)-1].hashval) <
be32_to_cpu(leaf1->entries[
be16_to_cpu(leaf1->hdr.count)-1].hashval)))) {
return(1);
}
return(0);
} }
/* /*
...@@ -2361,15 +2547,16 @@ xfs_attr_leaf_lasthash( ...@@ -2361,15 +2547,16 @@ xfs_attr_leaf_lasthash(
struct xfs_buf *bp, struct xfs_buf *bp,
int *count) int *count)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr3_icleaf_hdr ichdr;
struct xfs_attr_leaf_entry *entries;
leaf = bp->b_addr; xfs_attr3_leaf_hdr_from_disk(&ichdr, bp->b_addr);
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); entries = xfs_attr3_leaf_entryp(bp->b_addr);
if (count) if (count)
*count = be16_to_cpu(leaf->hdr.count); *count = ichdr.count;
if (!leaf->hdr.count) if (!ichdr.count)
return(0); return 0;
return be32_to_cpu(leaf->entries[be16_to_cpu(leaf->hdr.count)-1].hashval); return be32_to_cpu(entries[ichdr.count - 1].hashval);
} }
/* /*
...@@ -2379,20 +2566,21 @@ xfs_attr_leaf_lasthash( ...@@ -2379,20 +2566,21 @@ xfs_attr_leaf_lasthash(
STATIC int STATIC int
xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index) xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index)
{ {
struct xfs_attr_leaf_entry *entries;
xfs_attr_leaf_name_local_t *name_loc; xfs_attr_leaf_name_local_t *name_loc;
xfs_attr_leaf_name_remote_t *name_rmt; xfs_attr_leaf_name_remote_t *name_rmt;
int size; int size;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); entries = xfs_attr3_leaf_entryp(leaf);
if (leaf->entries[index].flags & XFS_ATTR_LOCAL) { if (entries[index].flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr_leaf_name_local(leaf, index); name_loc = xfs_attr3_leaf_name_local(leaf, index);
size = xfs_attr_leaf_entsize_local(name_loc->namelen, size = xfs_attr_leaf_entsize_local(name_loc->namelen,
be16_to_cpu(name_loc->valuelen)); be16_to_cpu(name_loc->valuelen));
} else { } else {
name_rmt = xfs_attr_leaf_name_remote(leaf, index); name_rmt = xfs_attr3_leaf_name_remote(leaf, index);
size = xfs_attr_leaf_entsize_remote(name_rmt->namelen); size = xfs_attr_leaf_entsize_remote(name_rmt->namelen);
} }
return(size); return size;
} }
/* /*
...@@ -2417,35 +2605,40 @@ xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize, int *local) ...@@ -2417,35 +2605,40 @@ xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize, int *local)
*local = 0; *local = 0;
} }
} }
return(size); return size;
} }
/* /*
* Copy out attribute list entries for attr_list(), for leaf attribute lists. * Copy out attribute list entries for attr_list(), for leaf attribute lists.
*/ */
int int
xfs_attr_leaf_list_int( xfs_attr3_leaf_list_int(
struct xfs_buf *bp, struct xfs_buf *bp,
xfs_attr_list_context_t *context) struct xfs_attr_list_context *context)
{ {
attrlist_cursor_kern_t *cursor; struct attrlist_cursor_kern *cursor;
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_entry_t *entry; struct xfs_attr3_icleaf_hdr ichdr;
int retval, i; struct xfs_attr_leaf_entry *entries;
struct xfs_attr_leaf_entry *entry;
int retval;
int i;
trace_xfs_attr_list_leaf(context);
ASSERT(bp != NULL);
leaf = bp->b_addr; leaf = bp->b_addr;
xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
entries = xfs_attr3_leaf_entryp(leaf);
cursor = context->cursor; cursor = context->cursor;
cursor->initted = 1; cursor->initted = 1;
trace_xfs_attr_list_leaf(context);
/* /*
* Re-find our place in the leaf block if this is a new syscall. * Re-find our place in the leaf block if this is a new syscall.
*/ */
if (context->resynch) { if (context->resynch) {
entry = &leaf->entries[0]; entry = &entries[0];
for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) { for (i = 0; i < ichdr.count; entry++, i++) {
if (be32_to_cpu(entry->hashval) == cursor->hashval) { if (be32_to_cpu(entry->hashval) == cursor->hashval) {
if (cursor->offset == context->dupcnt) { if (cursor->offset == context->dupcnt) {
context->dupcnt = 0; context->dupcnt = 0;
...@@ -2458,12 +2651,12 @@ xfs_attr_leaf_list_int( ...@@ -2458,12 +2651,12 @@ xfs_attr_leaf_list_int(
break; break;
} }
} }
if (i == be16_to_cpu(leaf->hdr.count)) { if (i == ichdr.count) {
trace_xfs_attr_list_notfound(context); trace_xfs_attr_list_notfound(context);
return(0); return 0;
} }
} else { } else {
entry = &leaf->entries[0]; entry = &entries[0];
i = 0; i = 0;
} }
context->resynch = 0; context->resynch = 0;
...@@ -2472,7 +2665,7 @@ xfs_attr_leaf_list_int( ...@@ -2472,7 +2665,7 @@ xfs_attr_leaf_list_int(
* We have found our place, start copying out the new attributes. * We have found our place, start copying out the new attributes.
*/ */
retval = 0; retval = 0;
for ( ; (i < be16_to_cpu(leaf->hdr.count)); entry++, i++) { for (; i < ichdr.count; entry++, i++) {
if (be32_to_cpu(entry->hashval) != cursor->hashval) { if (be32_to_cpu(entry->hashval) != cursor->hashval) {
cursor->hashval = be32_to_cpu(entry->hashval); cursor->hashval = be32_to_cpu(entry->hashval);
cursor->offset = 0; cursor->offset = 0;
...@@ -2483,7 +2676,7 @@ xfs_attr_leaf_list_int( ...@@ -2483,7 +2676,7 @@ xfs_attr_leaf_list_int(
if (entry->flags & XFS_ATTR_LOCAL) { if (entry->flags & XFS_ATTR_LOCAL) {
xfs_attr_leaf_name_local_t *name_loc = xfs_attr_leaf_name_local_t *name_loc =
xfs_attr_leaf_name_local(leaf, i); xfs_attr3_leaf_name_local(leaf, i);
retval = context->put_listent(context, retval = context->put_listent(context,
entry->flags, entry->flags,
...@@ -2495,7 +2688,7 @@ xfs_attr_leaf_list_int( ...@@ -2495,7 +2688,7 @@ xfs_attr_leaf_list_int(
return retval; return retval;
} else { } else {
xfs_attr_leaf_name_remote_t *name_rmt = xfs_attr_leaf_name_remote_t *name_rmt =
xfs_attr_leaf_name_remote(leaf, i); xfs_attr3_leaf_name_remote(leaf, i);
int valuelen = be32_to_cpu(name_rmt->valuelen); int valuelen = be32_to_cpu(name_rmt->valuelen);
...@@ -2535,7 +2728,7 @@ xfs_attr_leaf_list_int( ...@@ -2535,7 +2728,7 @@ xfs_attr_leaf_list_int(
cursor->offset++; cursor->offset++;
} }
trace_xfs_attr_list_leaf_end(context); trace_xfs_attr_list_leaf_end(context);
return(retval); return retval;
} }
...@@ -2547,14 +2740,16 @@ xfs_attr_leaf_list_int( ...@@ -2547,14 +2740,16 @@ xfs_attr_leaf_list_int(
* Clear the INCOMPLETE flag on an entry in a leaf block. * Clear the INCOMPLETE flag on an entry in a leaf block.
*/ */
int int
xfs_attr_leaf_clearflag(xfs_da_args_t *args) xfs_attr3_leaf_clearflag(
struct xfs_da_args *args)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_entry_t *entry; struct xfs_attr_leaf_entry *entry;
xfs_attr_leaf_name_remote_t *name_rmt; struct xfs_attr_leaf_name_remote *name_rmt;
struct xfs_buf *bp; struct xfs_buf *bp;
int error; int error;
#ifdef DEBUG #ifdef DEBUG
struct xfs_attr3_icleaf_hdr ichdr;
xfs_attr_leaf_name_local_t *name_loc; xfs_attr_leaf_name_local_t *name_loc;
int namelen; int namelen;
char *name; char *name;
...@@ -2564,23 +2759,25 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args) ...@@ -2564,23 +2759,25 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
/* /*
* Set up the operation. * Set up the operation.
*/ */
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
if (error) if (error)
return(error); return(error);
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(args->index < be16_to_cpu(leaf->hdr.count)); entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
ASSERT(args->index >= 0);
entry = &leaf->entries[ args->index ];
ASSERT(entry->flags & XFS_ATTR_INCOMPLETE); ASSERT(entry->flags & XFS_ATTR_INCOMPLETE);
#ifdef DEBUG #ifdef DEBUG
xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
ASSERT(args->index < ichdr.count);
ASSERT(args->index >= 0);
if (entry->flags & XFS_ATTR_LOCAL) { if (entry->flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr_leaf_name_local(leaf, args->index); name_loc = xfs_attr3_leaf_name_local(leaf, args->index);
namelen = name_loc->namelen; namelen = name_loc->namelen;
name = (char *)name_loc->nameval; name = (char *)name_loc->nameval;
} else { } else {
name_rmt = xfs_attr_leaf_name_remote(leaf, args->index); name_rmt = xfs_attr3_leaf_name_remote(leaf, args->index);
namelen = name_rmt->namelen; namelen = name_rmt->namelen;
name = (char *)name_rmt->name; name = (char *)name_rmt->name;
} }
...@@ -2595,7 +2792,7 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args) ...@@ -2595,7 +2792,7 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
if (args->rmtblkno) { if (args->rmtblkno) {
ASSERT((entry->flags & XFS_ATTR_LOCAL) == 0); ASSERT((entry->flags & XFS_ATTR_LOCAL) == 0);
name_rmt = xfs_attr_leaf_name_remote(leaf, args->index); name_rmt = xfs_attr3_leaf_name_remote(leaf, args->index);
name_rmt->valueblk = cpu_to_be32(args->rmtblkno); name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
name_rmt->valuelen = cpu_to_be32(args->valuelen); name_rmt->valuelen = cpu_to_be32(args->valuelen);
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
...@@ -2612,34 +2809,41 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args) ...@@ -2612,34 +2809,41 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
* Set the INCOMPLETE flag on an entry in a leaf block. * Set the INCOMPLETE flag on an entry in a leaf block.
*/ */
int int
xfs_attr_leaf_setflag(xfs_da_args_t *args) xfs_attr3_leaf_setflag(
struct xfs_da_args *args)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_entry_t *entry; struct xfs_attr_leaf_entry *entry;
xfs_attr_leaf_name_remote_t *name_rmt; struct xfs_attr_leaf_name_remote *name_rmt;
struct xfs_buf *bp; struct xfs_buf *bp;
int error; int error;
#ifdef DEBUG
struct xfs_attr3_icleaf_hdr ichdr;
#endif
trace_xfs_attr_leaf_setflag(args); trace_xfs_attr_leaf_setflag(args);
/* /*
* Set up the operation. * Set up the operation.
*/ */
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
if (error) if (error)
return(error); return(error);
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(args->index < be16_to_cpu(leaf->hdr.count)); #ifdef DEBUG
xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
ASSERT(args->index < ichdr.count);
ASSERT(args->index >= 0); ASSERT(args->index >= 0);
entry = &leaf->entries[ args->index ]; #endif
entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
ASSERT((entry->flags & XFS_ATTR_INCOMPLETE) == 0); ASSERT((entry->flags & XFS_ATTR_INCOMPLETE) == 0);
entry->flags |= XFS_ATTR_INCOMPLETE; entry->flags |= XFS_ATTR_INCOMPLETE;
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
XFS_DA_LOGRANGE(leaf, entry, sizeof(*entry))); XFS_DA_LOGRANGE(leaf, entry, sizeof(*entry)));
if ((entry->flags & XFS_ATTR_LOCAL) == 0) { if ((entry->flags & XFS_ATTR_LOCAL) == 0) {
name_rmt = xfs_attr_leaf_name_remote(leaf, args->index); name_rmt = xfs_attr3_leaf_name_remote(leaf, args->index);
name_rmt->valueblk = 0; name_rmt->valueblk = 0;
name_rmt->valuelen = 0; name_rmt->valuelen = 0;
xfs_trans_log_buf(args->trans, bp, xfs_trans_log_buf(args->trans, bp,
...@@ -2660,14 +2864,20 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args) ...@@ -2660,14 +2864,20 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args)
* Note that they could be in different blocks, or in the same block. * Note that they could be in different blocks, or in the same block.
*/ */
int int
xfs_attr_leaf_flipflags(xfs_da_args_t *args) xfs_attr3_leaf_flipflags(
struct xfs_da_args *args)
{ {
xfs_attr_leafblock_t *leaf1, *leaf2; struct xfs_attr_leafblock *leaf1;
xfs_attr_leaf_entry_t *entry1, *entry2; struct xfs_attr_leafblock *leaf2;
xfs_attr_leaf_name_remote_t *name_rmt; struct xfs_attr_leaf_entry *entry1;
struct xfs_buf *bp1, *bp2; struct xfs_attr_leaf_entry *entry2;
struct xfs_attr_leaf_name_remote *name_rmt;
struct xfs_buf *bp1;
struct xfs_buf *bp2;
int error; int error;
#ifdef DEBUG #ifdef DEBUG
struct xfs_attr3_icleaf_hdr ichdr1;
struct xfs_attr3_icleaf_hdr ichdr2;
xfs_attr_leaf_name_local_t *name_loc; xfs_attr_leaf_name_local_t *name_loc;
int namelen1, namelen2; int namelen1, namelen2;
char *name1, *name2; char *name1, *name2;
...@@ -2678,7 +2888,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) ...@@ -2678,7 +2888,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
/* /*
* Read the block containing the "old" attr * Read the block containing the "old" attr
*/ */
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp1); error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp1);
if (error) if (error)
return error; return error;
...@@ -2686,7 +2896,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) ...@@ -2686,7 +2896,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
* Read the block containing the "new" attr, if it is different * Read the block containing the "new" attr, if it is different
*/ */
if (args->blkno2 != args->blkno) { if (args->blkno2 != args->blkno) {
error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno2, error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno2,
-1, &bp2); -1, &bp2);
if (error) if (error)
return error; return error;
...@@ -2695,31 +2905,35 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) ...@@ -2695,31 +2905,35 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
} }
leaf1 = bp1->b_addr; leaf1 = bp1->b_addr;
ASSERT(args->index < be16_to_cpu(leaf1->hdr.count)); entry1 = &xfs_attr3_leaf_entryp(leaf1)[args->index];
ASSERT(args->index >= 0);
entry1 = &leaf1->entries[ args->index ];
leaf2 = bp2->b_addr; leaf2 = bp2->b_addr;
ASSERT(args->index2 < be16_to_cpu(leaf2->hdr.count)); entry2 = &xfs_attr3_leaf_entryp(leaf2)[args->index2];
ASSERT(args->index2 >= 0);
entry2 = &leaf2->entries[ args->index2 ];
#ifdef DEBUG #ifdef DEBUG
xfs_attr3_leaf_hdr_from_disk(&ichdr1, leaf1);
ASSERT(args->index < ichdr1.count);
ASSERT(args->index >= 0);
xfs_attr3_leaf_hdr_from_disk(&ichdr2, leaf2);
ASSERT(args->index2 < ichdr2.count);
ASSERT(args->index2 >= 0);
if (entry1->flags & XFS_ATTR_LOCAL) { if (entry1->flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr_leaf_name_local(leaf1, args->index); name_loc = xfs_attr3_leaf_name_local(leaf1, args->index);
namelen1 = name_loc->namelen; namelen1 = name_loc->namelen;
name1 = (char *)name_loc->nameval; name1 = (char *)name_loc->nameval;
} else { } else {
name_rmt = xfs_attr_leaf_name_remote(leaf1, args->index); name_rmt = xfs_attr3_leaf_name_remote(leaf1, args->index);
namelen1 = name_rmt->namelen; namelen1 = name_rmt->namelen;
name1 = (char *)name_rmt->name; name1 = (char *)name_rmt->name;
} }
if (entry2->flags & XFS_ATTR_LOCAL) { if (entry2->flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr_leaf_name_local(leaf2, args->index2); name_loc = xfs_attr3_leaf_name_local(leaf2, args->index2);
namelen2 = name_loc->namelen; namelen2 = name_loc->namelen;
name2 = (char *)name_loc->nameval; name2 = (char *)name_loc->nameval;
} else { } else {
name_rmt = xfs_attr_leaf_name_remote(leaf2, args->index2); name_rmt = xfs_attr3_leaf_name_remote(leaf2, args->index2);
namelen2 = name_rmt->namelen; namelen2 = name_rmt->namelen;
name2 = (char *)name_rmt->name; name2 = (char *)name_rmt->name;
} }
...@@ -2736,7 +2950,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) ...@@ -2736,7 +2950,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
XFS_DA_LOGRANGE(leaf1, entry1, sizeof(*entry1))); XFS_DA_LOGRANGE(leaf1, entry1, sizeof(*entry1)));
if (args->rmtblkno) { if (args->rmtblkno) {
ASSERT((entry1->flags & XFS_ATTR_LOCAL) == 0); ASSERT((entry1->flags & XFS_ATTR_LOCAL) == 0);
name_rmt = xfs_attr_leaf_name_remote(leaf1, args->index); name_rmt = xfs_attr3_leaf_name_remote(leaf1, args->index);
name_rmt->valueblk = cpu_to_be32(args->rmtblkno); name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
name_rmt->valuelen = cpu_to_be32(args->valuelen); name_rmt->valuelen = cpu_to_be32(args->valuelen);
xfs_trans_log_buf(args->trans, bp1, xfs_trans_log_buf(args->trans, bp1,
...@@ -2747,7 +2961,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) ...@@ -2747,7 +2961,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
xfs_trans_log_buf(args->trans, bp2, xfs_trans_log_buf(args->trans, bp2,
XFS_DA_LOGRANGE(leaf2, entry2, sizeof(*entry2))); XFS_DA_LOGRANGE(leaf2, entry2, sizeof(*entry2)));
if ((entry2->flags & XFS_ATTR_LOCAL) == 0) { if ((entry2->flags & XFS_ATTR_LOCAL) == 0) {
name_rmt = xfs_attr_leaf_name_remote(leaf2, args->index2); name_rmt = xfs_attr3_leaf_name_remote(leaf2, args->index2);
name_rmt->valueblk = 0; name_rmt->valueblk = 0;
name_rmt->valuelen = 0; name_rmt->valuelen = 0;
xfs_trans_log_buf(args->trans, bp2, xfs_trans_log_buf(args->trans, bp2,
...@@ -2759,7 +2973,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) ...@@ -2759,7 +2973,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
*/ */
error = xfs_trans_roll(&args->trans, args->dp); error = xfs_trans_roll(&args->trans, args->dp);
return(error); return error;
} }
/*======================================================================== /*========================================================================
...@@ -2771,12 +2985,14 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args) ...@@ -2771,12 +2985,14 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
* We're doing a depth-first traversal in order to invalidate everything. * We're doing a depth-first traversal in order to invalidate everything.
*/ */
int int
xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp) xfs_attr3_root_inactive(
struct xfs_trans **trans,
struct xfs_inode *dp)
{ {
xfs_da_blkinfo_t *info; struct xfs_da_blkinfo *info;
xfs_daddr_t blkno; struct xfs_buf *bp;
struct xfs_buf *bp; xfs_daddr_t blkno;
int error; int error;
/* /*
* Read block 0 to see what we have to work with. * Read block 0 to see what we have to work with.
...@@ -2786,38 +3002,44 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp) ...@@ -2786,38 +3002,44 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp)
*/ */
error = xfs_da3_node_read(*trans, dp, 0, -1, &bp, XFS_ATTR_FORK); error = xfs_da3_node_read(*trans, dp, 0, -1, &bp, XFS_ATTR_FORK);
if (error) if (error)
return(error); return error;
blkno = XFS_BUF_ADDR(bp); blkno = bp->b_bn;
/* /*
* Invalidate the tree, even if the "tree" is only a single leaf block. * Invalidate the tree, even if the "tree" is only a single leaf block.
* This is a depth-first traversal! * This is a depth-first traversal!
*/ */
info = bp->b_addr; info = bp->b_addr;
if (info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC)) { switch (info->magic) {
error = xfs_attr_node_inactive(trans, dp, bp, 1); case cpu_to_be16(XFS_DA_NODE_MAGIC):
} else if (info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)) { case cpu_to_be16(XFS_DA3_NODE_MAGIC):
error = xfs_attr_leaf_inactive(trans, dp, bp); error = xfs_attr3_node_inactive(trans, dp, bp, 1);
} else { break;
case cpu_to_be16(XFS_ATTR_LEAF_MAGIC):
case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
error = xfs_attr3_leaf_inactive(trans, dp, bp);
break;
default:
error = XFS_ERROR(EIO); error = XFS_ERROR(EIO);
xfs_trans_brelse(*trans, bp); xfs_trans_brelse(*trans, bp);
break;
} }
if (error) if (error)
return(error); return error;
/* /*
* Invalidate the incore copy of the root block. * Invalidate the incore copy of the root block.
*/ */
error = xfs_da_get_buf(*trans, dp, 0, blkno, &bp, XFS_ATTR_FORK); error = xfs_da_get_buf(*trans, dp, 0, blkno, &bp, XFS_ATTR_FORK);
if (error) if (error)
return(error); return error;
xfs_trans_binval(*trans, bp); /* remove from cache */ xfs_trans_binval(*trans, bp); /* remove from cache */
/* /*
* Commit the invalidate and start the next transaction. * Commit the invalidate and start the next transaction.
*/ */
error = xfs_trans_roll(trans, dp); error = xfs_trans_roll(trans, dp);
return (error); return error;
} }
/* /*
...@@ -2825,7 +3047,7 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp) ...@@ -2825,7 +3047,7 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp)
* We're doing a depth-first traversal in order to invalidate everything. * We're doing a depth-first traversal in order to invalidate everything.
*/ */
STATIC int STATIC int
xfs_attr_node_inactive( xfs_attr3_node_inactive(
struct xfs_trans **trans, struct xfs_trans **trans,
struct xfs_inode *dp, struct xfs_inode *dp,
struct xfs_buf *bp, struct xfs_buf *bp,
...@@ -2835,25 +3057,25 @@ xfs_attr_node_inactive( ...@@ -2835,25 +3057,25 @@ xfs_attr_node_inactive(
xfs_da_intnode_t *node; xfs_da_intnode_t *node;
xfs_dablk_t child_fsb; xfs_dablk_t child_fsb;
xfs_daddr_t parent_blkno, child_blkno; xfs_daddr_t parent_blkno, child_blkno;
int error, count, i; int error, i;
struct xfs_buf *child_bp; struct xfs_buf *child_bp;
struct xfs_da_node_entry *btree; struct xfs_da_node_entry *btree;
struct xfs_da3_icnode_hdr ichdr;
/* /*
* Since this code is recursive (gasp!) we must protect ourselves. * Since this code is recursive (gasp!) we must protect ourselves.
*/ */
if (level > XFS_DA_NODE_MAXDEPTH) { if (level > XFS_DA_NODE_MAXDEPTH) {
xfs_trans_brelse(*trans, bp); /* no locks for later trans */ xfs_trans_brelse(*trans, bp); /* no locks for later trans */
return(XFS_ERROR(EIO)); return XFS_ERROR(EIO);
} }
node = bp->b_addr; node = bp->b_addr;
ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); xfs_da3_node_hdr_from_disk(&ichdr, node);
parent_blkno = XFS_BUF_ADDR(bp); /* save for re-read later */ parent_blkno = bp->b_bn;
count = be16_to_cpu(node->hdr.count); if (!ichdr.count) {
if (!count) {
xfs_trans_brelse(*trans, bp); xfs_trans_brelse(*trans, bp);
return(0); return 0;
} }
btree = xfs_da3_node_tree_p(node); btree = xfs_da3_node_tree_p(node);
child_fsb = be32_to_cpu(btree[0].before); child_fsb = be32_to_cpu(btree[0].before);
...@@ -2864,7 +3086,7 @@ xfs_attr_node_inactive( ...@@ -2864,7 +3086,7 @@ xfs_attr_node_inactive(
* over the leaves removing all of them. If this is higher up * over the leaves removing all of them. If this is higher up
* in the tree, recurse downward. * in the tree, recurse downward.
*/ */
for (i = 0; i < count; i++) { for (i = 0; i < ichdr.count; i++) {
/* /*
* Read the subsidiary block to see what we have to work with. * Read the subsidiary block to see what we have to work with.
* Don't do this in a transaction. This is a depth-first * Don't do this in a transaction. This is a depth-first
...@@ -2883,18 +3105,24 @@ xfs_attr_node_inactive( ...@@ -2883,18 +3105,24 @@ xfs_attr_node_inactive(
* Invalidate the subtree, however we have to. * Invalidate the subtree, however we have to.
*/ */
info = child_bp->b_addr; info = child_bp->b_addr;
if (info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC)) { switch (info->magic) {
error = xfs_attr_node_inactive(trans, dp, case cpu_to_be16(XFS_DA_NODE_MAGIC):
child_bp, level+1); case cpu_to_be16(XFS_DA3_NODE_MAGIC):
} else if (info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)) { error = xfs_attr3_node_inactive(trans, dp,
error = xfs_attr_leaf_inactive(trans, dp, child_bp, level + 1);
child_bp); break;
} else { case cpu_to_be16(XFS_ATTR_LEAF_MAGIC):
case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
error = xfs_attr3_leaf_inactive(trans, dp,
child_bp);
break;
default:
error = XFS_ERROR(EIO); error = XFS_ERROR(EIO);
xfs_trans_brelse(*trans, child_bp); xfs_trans_brelse(*trans, child_bp);
break;
} }
if (error) if (error)
return(error); return error;
/* /*
* Remove the subsidiary block from the cache * Remove the subsidiary block from the cache
...@@ -2903,7 +3131,7 @@ xfs_attr_node_inactive( ...@@ -2903,7 +3131,7 @@ xfs_attr_node_inactive(
error = xfs_da_get_buf(*trans, dp, 0, child_blkno, error = xfs_da_get_buf(*trans, dp, 0, child_blkno,
&child_bp, XFS_ATTR_FORK); &child_bp, XFS_ATTR_FORK);
if (error) if (error)
return(error); return error;
xfs_trans_binval(*trans, child_bp); xfs_trans_binval(*trans, child_bp);
} }
...@@ -2911,12 +3139,12 @@ xfs_attr_node_inactive( ...@@ -2911,12 +3139,12 @@ xfs_attr_node_inactive(
* If we're not done, re-read the parent to get the next * If we're not done, re-read the parent to get the next
* child block number. * child block number.
*/ */
if ((i+1) < count) { if (i + 1 < ichdr.count) {
error = xfs_da3_node_read(*trans, dp, 0, parent_blkno, error = xfs_da3_node_read(*trans, dp, 0, parent_blkno,
&bp, XFS_ATTR_FORK); &bp, XFS_ATTR_FORK);
if (error) if (error)
return(error); return error;
child_fsb = be32_to_cpu(btree[i+1].before); child_fsb = be32_to_cpu(btree[i + 1].before);
xfs_trans_brelse(*trans, bp); xfs_trans_brelse(*trans, bp);
} }
/* /*
...@@ -2924,10 +3152,10 @@ xfs_attr_node_inactive( ...@@ -2924,10 +3152,10 @@ xfs_attr_node_inactive(
*/ */
error = xfs_trans_roll(trans, dp); error = xfs_trans_roll(trans, dp);
if (error) if (error)
return (error); return error;
} }
return(0); return 0;
} }
/* /*
...@@ -2937,29 +3165,35 @@ xfs_attr_node_inactive( ...@@ -2937,29 +3165,35 @@ xfs_attr_node_inactive(
* caught holding something that the logging code wants to flush to disk. * caught holding something that the logging code wants to flush to disk.
*/ */
STATIC int STATIC int
xfs_attr_leaf_inactive( xfs_attr3_leaf_inactive(
struct xfs_trans **trans, struct xfs_trans **trans,
struct xfs_inode *dp, struct xfs_inode *dp,
struct xfs_buf *bp) struct xfs_buf *bp)
{ {
xfs_attr_leafblock_t *leaf; struct xfs_attr_leafblock *leaf;
xfs_attr_leaf_entry_t *entry; struct xfs_attr3_icleaf_hdr ichdr;
xfs_attr_leaf_name_remote_t *name_rmt; struct xfs_attr_leaf_entry *entry;
xfs_attr_inactive_list_t *list, *lp; struct xfs_attr_leaf_name_remote *name_rmt;
int error, count, size, tmp, i; struct xfs_attr_inactive_list *list;
struct xfs_attr_inactive_list *lp;
int error;
int count;
int size;
int tmp;
int i;
leaf = bp->b_addr; leaf = bp->b_addr;
ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
/* /*
* Count the number of "remote" value extents. * Count the number of "remote" value extents.
*/ */
count = 0; count = 0;
entry = &leaf->entries[0]; entry = xfs_attr3_leaf_entryp(leaf);
for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) { for (i = 0; i < ichdr.count; entry++, i++) {
if (be16_to_cpu(entry->nameidx) && if (be16_to_cpu(entry->nameidx) &&
((entry->flags & XFS_ATTR_LOCAL) == 0)) { ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
name_rmt = xfs_attr_leaf_name_remote(leaf, i); name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
if (name_rmt->valueblk) if (name_rmt->valueblk)
count++; count++;
} }
...@@ -2970,24 +3204,24 @@ xfs_attr_leaf_inactive( ...@@ -2970,24 +3204,24 @@ xfs_attr_leaf_inactive(
*/ */
if (count == 0) { if (count == 0) {
xfs_trans_brelse(*trans, bp); xfs_trans_brelse(*trans, bp);
return(0); return 0;
} }
/* /*
* Allocate storage for a list of all the "remote" value extents. * Allocate storage for a list of all the "remote" value extents.
*/ */
size = count * sizeof(xfs_attr_inactive_list_t); size = count * sizeof(xfs_attr_inactive_list_t);
list = (xfs_attr_inactive_list_t *)kmem_alloc(size, KM_SLEEP); list = kmem_alloc(size, KM_SLEEP);
/* /*
* Identify each of the "remote" value extents. * Identify each of the "remote" value extents.
*/ */
lp = list; lp = list;
entry = &leaf->entries[0]; entry = xfs_attr3_leaf_entryp(leaf);
for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) { for (i = 0; i < ichdr.count; entry++, i++) {
if (be16_to_cpu(entry->nameidx) && if (be16_to_cpu(entry->nameidx) &&
((entry->flags & XFS_ATTR_LOCAL) == 0)) { ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
name_rmt = xfs_attr_leaf_name_remote(leaf, i); name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
if (name_rmt->valueblk) { if (name_rmt->valueblk) {
lp->valueblk = be32_to_cpu(name_rmt->valueblk); lp->valueblk = be32_to_cpu(name_rmt->valueblk);
lp->valuelen = XFS_B_TO_FSB(dp->i_mount, lp->valuelen = XFS_B_TO_FSB(dp->i_mount,
...@@ -3003,15 +3237,15 @@ xfs_attr_leaf_inactive( ...@@ -3003,15 +3237,15 @@ xfs_attr_leaf_inactive(
*/ */
error = 0; error = 0;
for (lp = list, i = 0; i < count; i++, lp++) { for (lp = list, i = 0; i < count; i++, lp++) {
tmp = xfs_attr_leaf_freextent(trans, dp, tmp = xfs_attr3_leaf_freextent(trans, dp,
lp->valueblk, lp->valuelen); lp->valueblk, lp->valuelen);
if (error == 0) if (error == 0)
error = tmp; /* save only the 1st errno */ error = tmp; /* save only the 1st errno */
} }
kmem_free((xfs_caddr_t)list); kmem_free(list);
return(error); return error;
} }
/* /*
...@@ -3019,14 +3253,20 @@ xfs_attr_leaf_inactive( ...@@ -3019,14 +3253,20 @@ xfs_attr_leaf_inactive(
* invalidate any buffers that are incore/in transactions. * invalidate any buffers that are incore/in transactions.
*/ */
STATIC int STATIC int
xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp, xfs_attr3_leaf_freextent(
xfs_dablk_t blkno, int blkcnt) struct xfs_trans **trans,
struct xfs_inode *dp,
xfs_dablk_t blkno,
int blkcnt)
{ {
xfs_bmbt_irec_t map; struct xfs_bmbt_irec map;
xfs_dablk_t tblkno; struct xfs_buf *bp;
int tblkcnt, dblkcnt, nmap, error; xfs_dablk_t tblkno;
xfs_daddr_t dblkno; xfs_daddr_t dblkno;
xfs_buf_t *bp; int tblkcnt;
int dblkcnt;
int nmap;
int error;
/* /*
* Roll through the "value", invalidating the attribute value's * Roll through the "value", invalidating the attribute value's
......
/* /*
* Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc. * Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc.
* Copyright (c) 2013 Red Hat, Inc.
* All Rights Reserved. * All Rights Reserved.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -89,7 +90,7 @@ typedef struct xfs_attr_leaf_hdr { /* constant-structure header block */ ...@@ -89,7 +90,7 @@ typedef struct xfs_attr_leaf_hdr { /* constant-structure header block */
typedef struct xfs_attr_leaf_entry { /* sorted on key, not name */ typedef struct xfs_attr_leaf_entry { /* sorted on key, not name */
__be32 hashval; /* hash value of name */ __be32 hashval; /* hash value of name */
__be16 nameidx; /* index into buffer of name/value */ __be16 nameidx; /* index into buffer of name/value */
__u8 flags; /* LOCAL/ROOT/SECURE/INCOMPLETE flag */ __u8 flags; /* LOCAL/ROOT/SECURE/INCOMPLETE flag */
__u8 pad2; /* unused pad byte */ __u8 pad2; /* unused pad byte */
} xfs_attr_leaf_entry_t; } xfs_attr_leaf_entry_t;
...@@ -114,6 +115,54 @@ typedef struct xfs_attr_leafblock { ...@@ -114,6 +115,54 @@ typedef struct xfs_attr_leafblock {
xfs_attr_leaf_name_remote_t valuelist; /* grows from bottom of buf */ xfs_attr_leaf_name_remote_t valuelist; /* grows from bottom of buf */
} xfs_attr_leafblock_t; } xfs_attr_leafblock_t;
/*
* CRC enabled leaf structures. Called "version 3" structures to match the
* version number of the directory and dablk structures for this feature, and
* attr2 is already taken by the variable inode attribute fork size feature.
*/
struct xfs_attr3_leaf_hdr {
struct xfs_da3_blkinfo info;
__be16 count;
__be16 usedbytes;
__be16 firstused;
__u8 holes;
__u8 pad1;
struct xfs_attr_leaf_map freemap[XFS_ATTR_LEAF_MAPSIZE];
};
#define XFS_ATTR3_LEAF_CRC_OFF (offsetof(struct xfs_attr3_leaf_hdr, info.crc))
struct xfs_attr3_leafblock {
struct xfs_attr3_leaf_hdr hdr;
struct xfs_attr_leaf_entry entries[1];
/*
* The rest of the block contains the following structures after the
* leaf entries, growing from the bottom up. The variables are never
* referenced, the locations accessed purely from helper functions.
*
* struct xfs_attr_leaf_name_local
* struct xfs_attr_leaf_name_remote
*/
};
/*
* incore, neutral version of the attribute leaf header
*/
struct xfs_attr3_icleaf_hdr {
__uint32_t forw;
__uint32_t back;
__uint16_t magic;
__uint16_t count;
__uint16_t usedbytes;
__uint16_t firstused;
__u8 holes;
struct {
__uint16_t base;
__uint16_t size;
} freemap[XFS_ATTR_LEAF_MAPSIZE];
};
/* /*
* Flags used in the leaf_entry[i].flags field. * Flags used in the leaf_entry[i].flags field.
* NOTE: the INCOMPLETE bit must not collide with the flags bits specified * NOTE: the INCOMPLETE bit must not collide with the flags bits specified
...@@ -147,26 +196,43 @@ typedef struct xfs_attr_leafblock { ...@@ -147,26 +196,43 @@ typedef struct xfs_attr_leafblock {
*/ */
#define XFS_ATTR_LEAF_NAME_ALIGN ((uint)sizeof(xfs_dablk_t)) #define XFS_ATTR_LEAF_NAME_ALIGN ((uint)sizeof(xfs_dablk_t))
static inline int
xfs_attr3_leaf_hdr_size(struct xfs_attr_leafblock *leafp)
{
if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
return sizeof(struct xfs_attr3_leaf_hdr);
return sizeof(struct xfs_attr_leaf_hdr);
}
static inline struct xfs_attr_leaf_entry *
xfs_attr3_leaf_entryp(xfs_attr_leafblock_t *leafp)
{
if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
return &((struct xfs_attr3_leafblock *)leafp)->entries[0];
return &leafp->entries[0];
}
/* /*
* Cast typed pointers for "local" and "remote" name/value structs. * Cast typed pointers for "local" and "remote" name/value structs.
*/ */
static inline xfs_attr_leaf_name_remote_t * static inline char *
xfs_attr_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx) xfs_attr3_leaf_name(xfs_attr_leafblock_t *leafp, int idx)
{ {
return (xfs_attr_leaf_name_remote_t *) struct xfs_attr_leaf_entry *entries = xfs_attr3_leaf_entryp(leafp);
&((char *)leafp)[be16_to_cpu(leafp->entries[idx].nameidx)];
return &((char *)leafp)[be16_to_cpu(entries[idx].nameidx)];
} }
static inline xfs_attr_leaf_name_local_t * static inline xfs_attr_leaf_name_remote_t *
xfs_attr_leaf_name_local(xfs_attr_leafblock_t *leafp, int idx) xfs_attr3_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx)
{ {
return (xfs_attr_leaf_name_local_t *) return (xfs_attr_leaf_name_remote_t *)xfs_attr3_leaf_name(leafp, idx);
&((char *)leafp)[be16_to_cpu(leafp->entries[idx].nameidx)];
} }
static inline char *xfs_attr_leaf_name(xfs_attr_leafblock_t *leafp, int idx) static inline xfs_attr_leaf_name_local_t *
xfs_attr3_leaf_name_local(xfs_attr_leafblock_t *leafp, int idx)
{ {
return &((char *)leafp)[be16_to_cpu(leafp->entries[idx].nameidx)]; return (xfs_attr_leaf_name_local_t *)xfs_attr3_leaf_name(leafp, idx);
} }
/* /*
...@@ -221,37 +287,37 @@ int xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes); ...@@ -221,37 +287,37 @@ int xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes);
/* /*
* Internal routines when attribute fork size == XFS_LBSIZE(mp). * Internal routines when attribute fork size == XFS_LBSIZE(mp).
*/ */
int xfs_attr_leaf_to_node(struct xfs_da_args *args); int xfs_attr3_leaf_to_node(struct xfs_da_args *args);
int xfs_attr_leaf_to_shortform(struct xfs_buf *bp, int xfs_attr3_leaf_to_shortform(struct xfs_buf *bp,
struct xfs_da_args *args, int forkoff); struct xfs_da_args *args, int forkoff);
int xfs_attr_leaf_clearflag(struct xfs_da_args *args); int xfs_attr3_leaf_clearflag(struct xfs_da_args *args);
int xfs_attr_leaf_setflag(struct xfs_da_args *args); int xfs_attr3_leaf_setflag(struct xfs_da_args *args);
int xfs_attr_leaf_flipflags(xfs_da_args_t *args); int xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
/* /*
* Routines used for growing the Btree. * Routines used for growing the Btree.
*/ */
int xfs_attr_leaf_split(struct xfs_da_state *state, int xfs_attr3_leaf_split(struct xfs_da_state *state,
struct xfs_da_state_blk *oldblk, struct xfs_da_state_blk *oldblk,
struct xfs_da_state_blk *newblk); struct xfs_da_state_blk *newblk);
int xfs_attr_leaf_lookup_int(struct xfs_buf *leaf, int xfs_attr3_leaf_lookup_int(struct xfs_buf *leaf,
struct xfs_da_args *args); struct xfs_da_args *args);
int xfs_attr_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args); int xfs_attr3_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args);
int xfs_attr_leaf_add(struct xfs_buf *leaf_buffer, int xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
struct xfs_da_args *args); struct xfs_da_args *args);
int xfs_attr_leaf_remove(struct xfs_buf *leaf_buffer, int xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer,
struct xfs_da_args *args); struct xfs_da_args *args);
int xfs_attr_leaf_list_int(struct xfs_buf *bp, int xfs_attr3_leaf_list_int(struct xfs_buf *bp,
struct xfs_attr_list_context *context); struct xfs_attr_list_context *context);
/* /*
* Routines used for shrinking the Btree. * Routines used for shrinking the Btree.
*/ */
int xfs_attr_leaf_toosmall(struct xfs_da_state *state, int *retval); int xfs_attr3_leaf_toosmall(struct xfs_da_state *state, int *retval);
void xfs_attr_leaf_unbalance(struct xfs_da_state *state, void xfs_attr3_leaf_unbalance(struct xfs_da_state *state,
struct xfs_da_state_blk *drop_blk, struct xfs_da_state_blk *drop_blk,
struct xfs_da_state_blk *save_blk); struct xfs_da_state_blk *save_blk);
int xfs_attr_root_inactive(struct xfs_trans **trans, struct xfs_inode *dp); int xfs_attr3_root_inactive(struct xfs_trans **trans, struct xfs_inode *dp);
/* /*
* Utility routines. * Utility routines.
...@@ -261,10 +327,12 @@ int xfs_attr_leaf_order(struct xfs_buf *leaf1_bp, ...@@ -261,10 +327,12 @@ int xfs_attr_leaf_order(struct xfs_buf *leaf1_bp,
struct xfs_buf *leaf2_bp); struct xfs_buf *leaf2_bp);
int xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize, int xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize,
int *local); int *local);
int xfs_attr_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp, int xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
xfs_dablk_t bno, xfs_daddr_t mappedbno, xfs_dablk_t bno, xfs_daddr_t mappedbno,
struct xfs_buf **bpp); struct xfs_buf **bpp);
void xfs_attr3_leaf_hdr_from_disk(struct xfs_attr3_icleaf_hdr *to,
struct xfs_attr_leafblock *from);
extern const struct xfs_buf_ops xfs_attr_leaf_buf_ops; extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;
#endif /* __XFS_ATTR_LEAF_H__ */ #endif /* __XFS_ATTR_LEAF_H__ */
...@@ -143,14 +143,14 @@ xfs_da3_node_hdr_from_disk( ...@@ -143,14 +143,14 @@ xfs_da3_node_hdr_from_disk(
to->forw = be32_to_cpu(hdr3->info.hdr.forw); to->forw = be32_to_cpu(hdr3->info.hdr.forw);
to->back = be32_to_cpu(hdr3->info.hdr.back); to->back = be32_to_cpu(hdr3->info.hdr.back);
to->magic = be16_to_cpu(hdr3->info.hdr.magic); to->magic = be16_to_cpu(hdr3->info.hdr.magic);
to->count = be16_to_cpu(hdr3->count); to->count = be16_to_cpu(hdr3->__count);
to->level = be16_to_cpu(hdr3->__level); to->level = be16_to_cpu(hdr3->__level);
return; return;
} }
to->forw = be32_to_cpu(from->hdr.info.forw); to->forw = be32_to_cpu(from->hdr.info.forw);
to->back = be32_to_cpu(from->hdr.info.back); to->back = be32_to_cpu(from->hdr.info.back);
to->magic = be16_to_cpu(from->hdr.info.magic); to->magic = be16_to_cpu(from->hdr.info.magic);
to->count = be16_to_cpu(from->hdr.count); to->count = be16_to_cpu(from->hdr.__count);
to->level = be16_to_cpu(from->hdr.__level); to->level = be16_to_cpu(from->hdr.__level);
} }
...@@ -168,14 +168,14 @@ xfs_da3_node_hdr_to_disk( ...@@ -168,14 +168,14 @@ xfs_da3_node_hdr_to_disk(
hdr3->info.hdr.forw = cpu_to_be32(from->forw); hdr3->info.hdr.forw = cpu_to_be32(from->forw);
hdr3->info.hdr.back = cpu_to_be32(from->back); hdr3->info.hdr.back = cpu_to_be32(from->back);
hdr3->info.hdr.magic = cpu_to_be16(from->magic); hdr3->info.hdr.magic = cpu_to_be16(from->magic);
hdr3->count = cpu_to_be16(from->count); hdr3->__count = cpu_to_be16(from->count);
hdr3->__level = cpu_to_be16(from->level); hdr3->__level = cpu_to_be16(from->level);
return; return;
} }
to->hdr.info.forw = cpu_to_be32(from->forw); to->hdr.info.forw = cpu_to_be32(from->forw);
to->hdr.info.back = cpu_to_be32(from->back); to->hdr.info.back = cpu_to_be32(from->back);
to->hdr.info.magic = cpu_to_be16(from->magic); to->hdr.info.magic = cpu_to_be16(from->magic);
to->hdr.count = cpu_to_be16(from->count); to->hdr.__count = cpu_to_be16(from->count);
to->hdr.__level = cpu_to_be16(from->level); to->hdr.__level = cpu_to_be16(from->level);
} }
...@@ -270,7 +270,7 @@ xfs_da3_node_read_verify( ...@@ -270,7 +270,7 @@ xfs_da3_node_read_verify(
break; break;
return; return;
case XFS_ATTR_LEAF_MAGIC: case XFS_ATTR_LEAF_MAGIC:
bp->b_ops = &xfs_attr_leaf_buf_ops; bp->b_ops = &xfs_attr3_leaf_buf_ops;
bp->b_ops->verify_read(bp); bp->b_ops->verify_read(bp);
return; return;
case XFS_DIR2_LEAFN_MAGIC: case XFS_DIR2_LEAFN_MAGIC:
...@@ -401,7 +401,7 @@ xfs_da3_split( ...@@ -401,7 +401,7 @@ xfs_da3_split(
*/ */
switch (oldblk->magic) { switch (oldblk->magic) {
case XFS_ATTR_LEAF_MAGIC: case XFS_ATTR_LEAF_MAGIC:
error = xfs_attr_leaf_split(state, oldblk, newblk); error = xfs_attr3_leaf_split(state, oldblk, newblk);
if ((error != 0) && (error != ENOSPC)) { if ((error != 0) && (error != ENOSPC)) {
return(error); /* GROT: attr is inconsistent */ return(error); /* GROT: attr is inconsistent */
} }
...@@ -416,12 +416,12 @@ xfs_da3_split( ...@@ -416,12 +416,12 @@ xfs_da3_split(
if (state->inleaf) { if (state->inleaf) {
state->extraafter = 0; /* before newblk */ state->extraafter = 0; /* before newblk */
trace_xfs_attr_leaf_split_before(state->args); trace_xfs_attr_leaf_split_before(state->args);
error = xfs_attr_leaf_split(state, oldblk, error = xfs_attr3_leaf_split(state, oldblk,
&state->extrablk); &state->extrablk);
} else { } else {
state->extraafter = 1; /* after newblk */ state->extraafter = 1; /* after newblk */
trace_xfs_attr_leaf_split_after(state->args); trace_xfs_attr_leaf_split_after(state->args);
error = xfs_attr_leaf_split(state, newblk, error = xfs_attr3_leaf_split(state, newblk,
&state->extrablk); &state->extrablk);
} }
if (error) if (error)
...@@ -963,12 +963,12 @@ xfs_da3_join( ...@@ -963,12 +963,12 @@ xfs_da3_join(
*/ */
switch (drop_blk->magic) { switch (drop_blk->magic) {
case XFS_ATTR_LEAF_MAGIC: case XFS_ATTR_LEAF_MAGIC:
error = xfs_attr_leaf_toosmall(state, &action); error = xfs_attr3_leaf_toosmall(state, &action);
if (error) if (error)
return(error); return(error);
if (action == 0) if (action == 0)
return(0); return(0);
xfs_attr_leaf_unbalance(state, drop_blk, save_blk); xfs_attr3_leaf_unbalance(state, drop_blk, save_blk);
break; break;
case XFS_DIR2_LEAFN_MAGIC: case XFS_DIR2_LEAFN_MAGIC:
error = xfs_dir2_leafn_toosmall(state, &action); error = xfs_dir2_leafn_toosmall(state, &action);
...@@ -1024,7 +1024,8 @@ xfs_da_blkinfo_onlychild_validate(struct xfs_da_blkinfo *blkinfo, __u16 level) ...@@ -1024,7 +1024,8 @@ xfs_da_blkinfo_onlychild_validate(struct xfs_da_blkinfo *blkinfo, __u16 level)
if (level == 1) { if (level == 1) {
ASSERT(magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || ASSERT(magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) ||
magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) || magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) ||
magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC) ||
magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC));
} else { } else {
ASSERT(magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || ASSERT(magic == cpu_to_be16(XFS_DA_NODE_MAGIC) ||
magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)); magic == cpu_to_be16(XFS_DA3_NODE_MAGIC));
...@@ -1482,7 +1483,9 @@ xfs_da3_node_lookup_int( ...@@ -1482,7 +1483,9 @@ xfs_da3_node_lookup_int(
curr = blk->bp->b_addr; curr = blk->bp->b_addr;
blk->magic = be16_to_cpu(curr->magic); blk->magic = be16_to_cpu(curr->magic);
if (blk->magic == XFS_ATTR_LEAF_MAGIC) { if (blk->magic == XFS_ATTR_LEAF_MAGIC ||
blk->magic == XFS_ATTR3_LEAF_MAGIC) {
blk->magic = XFS_ATTR_LEAF_MAGIC;
blk->hashval = xfs_attr_leaf_lasthash(blk->bp, NULL); blk->hashval = xfs_attr_leaf_lasthash(blk->bp, NULL);
break; break;
} }
...@@ -1562,7 +1565,7 @@ xfs_da3_node_lookup_int( ...@@ -1562,7 +1565,7 @@ xfs_da3_node_lookup_int(
retval = xfs_dir2_leafn_lookup_int(blk->bp, args, retval = xfs_dir2_leafn_lookup_int(blk->bp, args,
&blk->index, state); &blk->index, state);
} else if (blk->magic == XFS_ATTR_LEAF_MAGIC) { } else if (blk->magic == XFS_ATTR_LEAF_MAGIC) {
retval = xfs_attr_leaf_lookup_int(blk->bp, args); retval = xfs_attr3_leaf_lookup_int(blk->bp, args);
blk->index = args->index; blk->index = args->index;
args->blkno = blk->blkno; args->blkno = blk->blkno;
} else { } else {
...@@ -1874,7 +1877,8 @@ xfs_da3_path_shift( ...@@ -1874,7 +1877,8 @@ xfs_da3_path_shift(
info->magic == cpu_to_be16(XFS_DA3_NODE_MAGIC) || info->magic == cpu_to_be16(XFS_DA3_NODE_MAGIC) ||
info->magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || info->magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) ||
info->magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) || info->magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) ||
info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC) ||
info->magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC));
/* /*
...@@ -1896,6 +1900,7 @@ xfs_da3_path_shift( ...@@ -1896,6 +1900,7 @@ xfs_da3_path_shift(
blkno = be32_to_cpu(btree[blk->index].before); blkno = be32_to_cpu(btree[blk->index].before);
break; break;
case XFS_ATTR_LEAF_MAGIC: case XFS_ATTR_LEAF_MAGIC:
case XFS_ATTR3_LEAF_MAGIC:
blk->magic = XFS_ATTR_LEAF_MAGIC; blk->magic = XFS_ATTR_LEAF_MAGIC;
ASSERT(level == path->active-1); ASSERT(level == path->active-1);
blk->index = 0; blk->index = 0;
...@@ -2626,6 +2631,7 @@ xfs_da_read_buf( ...@@ -2626,6 +2631,7 @@ xfs_da_read_buf(
XFS_TEST_ERROR((magic != XFS_DA_NODE_MAGIC) && XFS_TEST_ERROR((magic != XFS_DA_NODE_MAGIC) &&
(magic != XFS_DA3_NODE_MAGIC) && (magic != XFS_DA3_NODE_MAGIC) &&
(magic != XFS_ATTR_LEAF_MAGIC) && (magic != XFS_ATTR_LEAF_MAGIC) &&
(magic != XFS_ATTR3_LEAF_MAGIC) &&
(magic != XFS_DIR2_LEAF1_MAGIC) && (magic != XFS_DIR2_LEAF1_MAGIC) &&
(magic != XFS_DIR3_LEAF1_MAGIC) && (magic != XFS_DIR3_LEAF1_MAGIC) &&
(magic != XFS_DIR2_LEAFN_MAGIC) && (magic != XFS_DIR2_LEAFN_MAGIC) &&
......
...@@ -55,6 +55,7 @@ typedef struct xfs_da_blkinfo { ...@@ -55,6 +55,7 @@ typedef struct xfs_da_blkinfo {
* magic numbers without modification for both v2 and v3 nodes. * magic numbers without modification for both v2 and v3 nodes.
*/ */
#define XFS_DA3_NODE_MAGIC 0x3ebe /* magic number: non-leaf blocks */ #define XFS_DA3_NODE_MAGIC 0x3ebe /* magic number: non-leaf blocks */
#define XFS_ATTR3_LEAF_MAGIC 0x3bee /* magic number: attribute leaf blks */
#define XFS_DIR3_LEAF1_MAGIC 0x3df1 /* magic number: v2 dirlf single blks */ #define XFS_DIR3_LEAF1_MAGIC 0x3df1 /* magic number: v2 dirlf single blks */
#define XFS_DIR3_LEAFN_MAGIC 0x3dff /* magic number: v2 dirlf multi blks */ #define XFS_DIR3_LEAFN_MAGIC 0x3dff /* magic number: v2 dirlf multi blks */
...@@ -85,13 +86,13 @@ struct xfs_da3_blkinfo { ...@@ -85,13 +86,13 @@ struct xfs_da3_blkinfo {
typedef struct xfs_da_node_hdr { typedef struct xfs_da_node_hdr {
struct xfs_da_blkinfo info; /* block type, links, etc. */ struct xfs_da_blkinfo info; /* block type, links, etc. */
__be16 count; /* count of active entries */ __be16 __count; /* count of active entries */
__be16 __level; /* level above leaves (leaf == 0) */ __be16 __level; /* level above leaves (leaf == 0) */
} xfs_da_node_hdr_t; } xfs_da_node_hdr_t;
struct xfs_da3_node_hdr { struct xfs_da3_node_hdr {
struct xfs_da3_blkinfo info; /* block type, links, etc. */ struct xfs_da3_blkinfo info; /* block type, links, etc. */
__be16 count; /* count of active entries */ __be16 __count; /* count of active entries */
__be16 __level; /* level above leaves (leaf == 0) */ __be16 __level; /* level above leaves (leaf == 0) */
__be32 __pad32; __be32 __pad32;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment