Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[safe/jmp/linux-2.6] / fs / xfs / xfs_attr_leaf.c
index 7176827..afdc891 100644 (file)
@@ -24,7 +24,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir.h"
 #include "xfs_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
@@ -34,7 +33,6 @@
 #include "xfs_ialloc_btree.h"
 #include "xfs_alloc.h"
 #include "xfs_btree.h"
-#include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
@@ -91,9 +89,20 @@ STATIC void xfs_attr_leaf_moveents(xfs_attr_leafblock_t *src_leaf,
                                         int dst_start, int move_count,
                                         xfs_mount_t *mp);
 STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
-STATIC int xfs_attr_put_listent(xfs_attr_list_context_t *context,
-                            attrnames_t *, char *name, int namelen,
-                            int valuelen);
+
+/*========================================================================
+ * Namespace helper routines
+ *========================================================================*/
+
+/*
+ * If namespace bits don't match return 0.
+ * If all match then return 1.
+ */
+STATIC_INLINE int
+xfs_attr_namesp_match(int arg_flags, int ondisk_flags)
+{
+       return XFS_ATTR_NSP_ONDISK(ondisk_flags) == XFS_ATTR_NSP_ARGS_TO_ONDISK(arg_flags);
+}
 
 
 /*========================================================================
@@ -115,6 +124,7 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)
        int offset;
        int minforkoff; /* lower limit on valid forkoff locations */
        int maxforkoff; /* upper limit on valid forkoff locations */
+       int dsize;      
        xfs_mount_t *mp = dp->i_mount;
 
        offset = (XFS_LITINO(mp) - bytes) >> 3; /* rounded down */
@@ -130,12 +140,48 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)
 
        if (!(mp->m_flags & XFS_MOUNT_ATTR2)) {
                if (bytes <= XFS_IFORK_ASIZE(dp))
-                       return mp->m_attroffset >> 3;
+                       return dp->i_d.di_forkoff;
                return 0;
        }
 
-       /* data fork btree root can have at least this many key/ptr pairs */
-       minforkoff = MAX(dp->i_df.if_bytes, XFS_BMDR_SPACE_CALC(MINDBTPTRS));
+       dsize = dp->i_df.if_bytes;
+       
+       switch (dp->i_d.di_format) {
+       case XFS_DINODE_FMT_EXTENTS:
+               /* 
+                * If there is no attr fork and the data fork is extents, 
+                * determine if creating the default attr fork will result 
+                * in the extents form migrating to btree. If so, the 
+                * minimum offset only needs to be the space required for 
+                * the btree root.
+                */ 
+               if (!dp->i_d.di_forkoff && dp->i_df.if_bytes >
+                   xfs_default_attroffset(dp))
+                       dsize = XFS_BMDR_SPACE_CALC(MINDBTPTRS);
+               break;
+               
+       case XFS_DINODE_FMT_BTREE:
+               /*
+                * If have data btree then keep forkoff if we have one,
+                * otherwise we are adding a new attr, so then we set 
+                * minforkoff to where the btree root can finish so we have 
+                * plenty of room for attrs
+                */
+               if (dp->i_d.di_forkoff) {
+                       if (offset < dp->i_d.di_forkoff) 
+                               return 0;
+                       else 
+                               return dp->i_d.di_forkoff;
+               } else
+                       dsize = XFS_BMAP_BROOT_SPACE(dp->i_df.if_broot);
+               break;
+       }
+       
+       /* 
+        * A data fork btree root must have space for at least 
+        * MINDBTPTRS key/ptr pairs if the data fork is small or empty.
+        */
+       minforkoff = MAX(dsize, XFS_BMDR_SPACE_CALC(MINDBTPTRS));
        minforkoff = roundup(minforkoff, 8) >> 3;
 
        /* attr fork btree root can have at least this many key/ptr pairs */
@@ -155,17 +201,15 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)
 STATIC void
 xfs_sbversion_add_attr2(xfs_mount_t *mp, xfs_trans_t *tp)
 {
-       unsigned long s;
-
        if ((mp->m_flags & XFS_MOUNT_ATTR2) &&
-           !(XFS_SB_VERSION_HASATTR2(&mp->m_sb))) {
-               s = XFS_SB_LOCK(mp);
-               if (!XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
-                       XFS_SB_VERSION_ADDATTR2(&mp->m_sb);
-                       XFS_SB_UNLOCK(mp, s);
+           !(xfs_sb_version_hasattr2(&mp->m_sb))) {
+               spin_lock(&mp->m_sb_lock);
+               if (!xfs_sb_version_hasattr2(&mp->m_sb)) {
+                       xfs_sb_version_addattr2(&mp->m_sb);
+                       spin_unlock(&mp->m_sb_lock);
                        xfs_mod_sb(tp, XFS_SB_VERSIONNUM | XFS_SB_FEATURES2);
                } else
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
        }
 }
 
@@ -230,11 +274,7 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
                        continue;
                if (memcmp(args->name, sfe->nameval, args->namelen) != 0)
                        continue;
-               if (((args->flags & ATTR_SECURE) != 0) !=
-                   ((sfe->flags & XFS_ATTR_SECURE) != 0))
-                       continue;
-               if (((args->flags & ATTR_ROOT) != 0) !=
-                   ((sfe->flags & XFS_ATTR_ROOT) != 0))
+               if (!xfs_attr_namesp_match(args->flags, sfe->flags))
                        continue;
                ASSERT(0);
 #endif
@@ -248,18 +288,37 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
 
        sfe->namelen = args->namelen;
        sfe->valuelen = args->valuelen;
-       sfe->flags = (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE :
-                       ((args->flags & ATTR_ROOT) ? XFS_ATTR_ROOT : 0);
+       sfe->flags = XFS_ATTR_NSP_ARGS_TO_ONDISK(args->flags);
        memcpy(sfe->nameval, args->name, args->namelen);
        memcpy(&sfe->nameval[args->namelen], args->value, args->valuelen);
        sf->hdr.count++;
-       be16_add(&sf->hdr.totsize, size);
+       be16_add_cpu(&sf->hdr.totsize, size);
        xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
 
        xfs_sbversion_add_attr2(mp, args->trans);
 }
 
 /*
+ * After the last attribute is removed revert to original inode format,
+ * making all literal area available to the data fork once more.
+ */
+STATIC void
+xfs_attr_fork_reset(
+       struct xfs_inode        *ip,
+       struct xfs_trans        *tp)
+{
+       xfs_idestroy_fork(ip, XFS_ATTR_FORK);
+       ip->i_d.di_forkoff = 0;
+       ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
+
+       ASSERT(ip->i_d.di_anextents == 0);
+       ASSERT(ip->i_afp == NULL);
+
+       ip->i_df.if_ext_max = XFS_IFORK_DSIZE(ip) / sizeof(xfs_bmbt_rec_t);
+       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+}
+
+/*
  * Remove an attribute from the shortform attribute list structure.
  */
 int
@@ -284,11 +343,7 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
                        continue;
                if (memcmp(sfe->nameval, args->name, args->namelen) != 0)
                        continue;
-               if (((args->flags & ATTR_SECURE) != 0) !=
-                   ((sfe->flags & XFS_ATTR_SECURE) != 0))
-                       continue;
-               if (((args->flags & ATTR_ROOT) != 0) !=
-                   ((sfe->flags & XFS_ATTR_ROOT) != 0))
+               if (!xfs_attr_namesp_match(args->flags, sfe->flags))
                        continue;
                break;
        }
@@ -303,33 +358,25 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
        if (end != totsize)
                memmove(&((char *)sf)[base], &((char *)sf)[end], totsize - end);
        sf->hdr.count--;
-       be16_add(&sf->hdr.totsize, -size);
+       be16_add_cpu(&sf->hdr.totsize, -size);
 
        /*
         * Fix up the start offset of the attribute fork
         */
        totsize -= size;
-       if (totsize == sizeof(xfs_attr_sf_hdr_t) && !args->addname &&
-           (mp->m_flags & XFS_MOUNT_ATTR2)) {
-               /*
-                * Last attribute now removed, revert to original
-                * inode format making all literal area available
-                * to the data fork once more.
-                */
-               xfs_idestroy_fork(dp, XFS_ATTR_FORK);
-               dp->i_d.di_forkoff = 0;
-               dp->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
-               ASSERT(dp->i_d.di_anextents == 0);
-               ASSERT(dp->i_afp == NULL);
-               dp->i_df.if_ext_max =
-                       XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
-               xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
+       if (totsize == sizeof(xfs_attr_sf_hdr_t) &&
+           (mp->m_flags & XFS_MOUNT_ATTR2) &&
+           (dp->i_d.di_format != XFS_DINODE_FMT_BTREE) &&
+           !(args->op_flags & XFS_DA_OP_ADDNAME)) {
+               xfs_attr_fork_reset(dp, args->trans);
        } else {
                xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
                dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize);
                ASSERT(dp->i_d.di_forkoff);
-               ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) || args->addname ||
-                       !(mp->m_flags & XFS_MOUNT_ATTR2));
+               ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) ||
+                               (args->op_flags & XFS_DA_OP_ADDNAME) ||
+                               !(mp->m_flags & XFS_MOUNT_ATTR2) ||
+                               dp->i_d.di_format == XFS_DINODE_FMT_BTREE);
                dp->i_afp->if_ext_max =
                        XFS_IFORK_ASIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
                dp->i_df.if_ext_max =
@@ -365,11 +412,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
                        continue;
                if (memcmp(args->name, sfe->nameval, args->namelen) != 0)
                        continue;
-               if (((args->flags & ATTR_SECURE) != 0) !=
-                   ((sfe->flags & XFS_ATTR_SECURE) != 0))
-                       continue;
-               if (((args->flags & ATTR_ROOT) != 0) !=
-                   ((sfe->flags & XFS_ATTR_ROOT) != 0))
+               if (!xfs_attr_namesp_match(args->flags, sfe->flags))
                        continue;
                return(XFS_ERROR(EEXIST));
        }
@@ -396,11 +439,7 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
                        continue;
                if (memcmp(args->name, sfe->nameval, args->namelen) != 0)
                        continue;
-               if (((args->flags & ATTR_SECURE) != 0) !=
-                   ((sfe->flags & XFS_ATTR_SECURE) != 0))
-                       continue;
-               if (((args->flags & ATTR_ROOT) != 0) !=
-                   ((sfe->flags & XFS_ATTR_ROOT) != 0))
+               if (!xfs_attr_namesp_match(args->flags, sfe->flags))
                        continue;
                if (args->flags & ATTR_KERNOVAL) {
                        args->valuelen = sfe->valuelen;
@@ -477,7 +516,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
        nargs.total = args->total;
        nargs.whichfork = XFS_ATTR_FORK;
        nargs.trans = args->trans;
-       nargs.oknoent = 1;
+       nargs.op_flags = XFS_DA_OP_OKNOENT;
 
        sfe = &sf->list[0];
        for (i = 0; i < sf->hdr.count; i++) {
@@ -487,8 +526,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
                nargs.valuelen = sfe->valuelen;
                nargs.hashval = xfs_da_hashname((char *)sfe->nameval,
                                                sfe->namelen);
-               nargs.flags = (sfe->flags & XFS_ATTR_SECURE) ? ATTR_SECURE :
-                               ((sfe->flags & XFS_ATTR_ROOT) ? ATTR_ROOT : 0);
+               nargs.flags = XFS_ATTR_NSP_ONDISK_TO_ARGS(sfe->flags);
                error = xfs_attr_leaf_lookup_int(bp, &nargs); /* set a->index */
                ASSERT(error == ENOATTR);
                error = xfs_attr_leaf_add(bp, &nargs);
@@ -502,7 +540,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
 out:
        if(bp)
                xfs_da_buf_done(bp);
-       kmem_free(tmpbuffer, size);
+       kmem_free(tmpbuffer);
        return(error);
 }
 
@@ -522,9 +560,13 @@ xfs_attr_shortform_compare(const void *a, const void *b)
        }
 }
 
+
+#define XFS_ISRESET_CURSOR(cursor) \
+       (!((cursor)->initted) && !((cursor)->hashval) && \
+        !((cursor)->blkno) && !((cursor)->offset))
 /*
  * Copy out entries of shortform attribute lists for attr_list().
- * Shortform atrtribute lists are not stored in hashval sorted order.
+ * Shortform attribute lists are not stored in hashval sorted order.
  * If the output buffer is not large enough to hold them all, then we
  * we have to calculate each entries' hashvalue and sort them before
  * we can begin returning them to the user.
@@ -539,6 +581,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
        xfs_attr_sf_entry_t *sfe;
        xfs_inode_t *dp;
        int sbsize, nsbuf, count, i;
+       int error;
 
        ASSERT(context != NULL);
        dp = context->dp;
@@ -554,46 +597,44 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
        xfs_attr_trace_l_c("sf start", context);
 
        /*
-        * If the buffer is large enough, do not bother with sorting.
+        * If the buffer is large enough and the cursor is at the start,
+        * do not bother with sorting since we will return everything in
+        * one buffer and another call using the cursor won't need to be
+        * made.
         * Note the generous fudge factor of 16 overhead bytes per entry.
+        * If bufsize is zero then put_listent must be a search function
+        * and can just scan through what we have.
         */
-       if ((dp->i_afp->if_bytes + sf->hdr.count * 16) < context->bufsize) {
+       if (context->bufsize == 0 ||
+           (XFS_ISRESET_CURSOR(cursor) &&
+             (dp->i_afp->if_bytes + sf->hdr.count * 16) < context->bufsize)) {
                for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
-                       attrnames_t     *namesp;
+                       error = context->put_listent(context,
+                                          sfe->flags,
+                                          (char *)sfe->nameval,
+                                          (int)sfe->namelen,
+                                          (int)sfe->valuelen,
+                                          (char*)&sfe->nameval[sfe->namelen]);
 
-                       if (((context->flags & ATTR_SECURE) != 0) !=
-                           ((sfe->flags & XFS_ATTR_SECURE) != 0) &&
-                           !(context->flags & ATTR_KERNORMALS)) {
-                               sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
-                               continue;
-                       }
-                       if (((context->flags & ATTR_ROOT) != 0) !=
-                           ((sfe->flags & XFS_ATTR_ROOT) != 0) &&
-                           !(context->flags & ATTR_KERNROOTLS)) {
-                               sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
-                               continue;
-                       }
-                       namesp = (sfe->flags & XFS_ATTR_SECURE) ? &attr_secure:
-                               ((sfe->flags & XFS_ATTR_ROOT) ? &attr_trusted :
-                                 &attr_user);
-                       if (context->flags & ATTR_KERNOVAL) {
-                               ASSERT(context->flags & ATTR_KERNAMELS);
-                               context->count += namesp->attr_namelen +
-                                       sfe->namelen + 1;
-                       }
-                       else {
-                               if (xfs_attr_put_listent(context, namesp,
-                                                  (char *)sfe->nameval,
-                                                  (int)sfe->namelen,
-                                                  (int)sfe->valuelen))
-                                       break;
-                       }
+                       /*
+                        * Either search callback finished early or
+                        * didn't fit it all in the buffer after all.
+                        */
+                       if (context->seen_enough)
+                               break;
+
+                       if (error)
+                               return error;
                        sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
                }
                xfs_attr_trace_l_c("sf big-gulp", context);
                return(0);
        }
 
+       /* do no more for a search callback */
+       if (context->bufsize == 0)
+               return 0;
+
        /*
         * It didn't all fit, so we have to sort everything on hashval.
         */
@@ -613,21 +654,10 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                                             XFS_ERRLEVEL_LOW,
                                             context->dp->i_mount, sfe);
                        xfs_attr_trace_l_c("sf corrupted", context);
-                       kmem_free(sbuf, sbsize);
+                       kmem_free(sbuf);
                        return XFS_ERROR(EFSCORRUPTED);
                }
-               if (((context->flags & ATTR_SECURE) != 0) !=
-                   ((sfe->flags & XFS_ATTR_SECURE) != 0) &&
-                   !(context->flags & ATTR_KERNORMALS)) {
-                       sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
-                       continue;
-               }
-               if (((context->flags & ATTR_ROOT) != 0) !=
-                   ((sfe->flags & XFS_ATTR_ROOT) != 0) &&
-                   !(context->flags & ATTR_KERNROOTLS)) {
-                       sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
-                       continue;
-               }
+
                sbp->entno = i;
                sbp->hash = xfs_da_hashname((char *)sfe->nameval, sfe->namelen);
                sbp->name = (char *)sfe->nameval;
@@ -662,7 +692,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                }
        }
        if (i == nsbuf) {
-               kmem_free(sbuf, sbsize);
+               kmem_free(sbuf);
                xfs_attr_trace_l_c("blk end", context);
                return(0);
        }
@@ -671,30 +701,24 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
         * Loop putting entries into the user buffer.
         */
        for ( ; i < nsbuf; i++, sbp++) {
-               attrnames_t     *namesp;
-
-               namesp = (sbp->flags & XFS_ATTR_SECURE) ? &attr_secure :
-                       ((sbp->flags & XFS_ATTR_ROOT) ? &attr_trusted :
-                         &attr_user);
-
                if (cursor->hashval != sbp->hash) {
                        cursor->hashval = sbp->hash;
                        cursor->offset = 0;
                }
-               if (context->flags & ATTR_KERNOVAL) {
-                       ASSERT(context->flags & ATTR_KERNAMELS);
-                       context->count += namesp->attr_namelen +
-                                               sbp->namelen + 1;
-               } else {
-                       if (xfs_attr_put_listent(context, namesp,
-                                       sbp->name, sbp->namelen,
-                                       sbp->valuelen))
-                               break;
-               }
+               error = context->put_listent(context,
+                                       sbp->flags,
+                                       sbp->name,
+                                       sbp->namelen,
+                                       sbp->valuelen,
+                                       &sbp->name[sbp->namelen]);
+               if (error)
+                       return error;
+               if (context->seen_enough)
+                       break;
                cursor->offset++;
        }
 
-       kmem_free(sbuf, sbsize);
+       kmem_free(sbuf);
        xfs_attr_trace_l_c("sf E-O-F", context);
        return(0);
 }
@@ -721,7 +745,7 @@ xfs_attr_shortform_allfit(xfs_dabuf_t *bp, xfs_inode_t *dp)
                        continue;               /* don't copy partial entries */
                if (!(entry->flags & XFS_ATTR_LOCAL))
                        return(0);
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, i);
+               name_loc = xfs_attr_leaf_name_local(leaf, i);
                if (name_loc->namelen >= XFS_ATTR_SF_ENTSIZE_MAX)
                        return(0);
                if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX)
@@ -731,6 +755,7 @@ xfs_attr_shortform_allfit(xfs_dabuf_t *bp, xfs_inode_t *dp)
                                + be16_to_cpu(name_loc->valuelen);
        }
        if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) &&
+           (dp->i_d.di_format != XFS_DINODE_FMT_BTREE) &&
            (bytes == sizeof(struct xfs_attr_sf_hdr)))
                return(-1);
        return(xfs_attr_shortform_bytesfit(dp, bytes));
@@ -769,20 +794,8 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args, int forkoff)
 
        if (forkoff == -1) {
                ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2);
-
-               /*
-                * Last attribute was removed, revert to original
-                * inode format making all literal area available
-                * to the data fork once more.
-                */
-               xfs_idestroy_fork(dp, XFS_ATTR_FORK);
-               dp->i_d.di_forkoff = 0;
-               dp->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
-               ASSERT(dp->i_d.di_anextents == 0);
-               ASSERT(dp->i_afp == NULL);
-               dp->i_df.if_ext_max =
-                       XFS_IFORK_DSIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
-               xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
+               ASSERT(dp->i_d.di_format != XFS_DINODE_FMT_BTREE);
+               xfs_attr_fork_reset(dp, args->trans);
                goto out;
        }
 
@@ -798,7 +811,7 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args, int forkoff)
        nargs.total = args->total;
        nargs.whichfork = XFS_ATTR_FORK;
        nargs.trans = args->trans;
-       nargs.oknoent = 1;
+       nargs.op_flags = XFS_DA_OP_OKNOENT;
        entry = &leaf->entries[0];
        for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
                if (entry->flags & XFS_ATTR_INCOMPLETE)
@@ -806,20 +819,19 @@ xfs_attr_leaf_to_shortform(xfs_dabuf_t *bp, xfs_da_args_t *args, int forkoff)
                if (!entry->nameidx)
                        continue;
                ASSERT(entry->flags & XFS_ATTR_LOCAL);
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, i);
+               name_loc = xfs_attr_leaf_name_local(leaf, i);
                nargs.name = (char *)name_loc->nameval;
                nargs.namelen = name_loc->namelen;
                nargs.value = (char *)&name_loc->nameval[nargs.namelen];
                nargs.valuelen = be16_to_cpu(name_loc->valuelen);
                nargs.hashval = be32_to_cpu(entry->hashval);
-               nargs.flags = (entry->flags & XFS_ATTR_SECURE) ? ATTR_SECURE :
-                             ((entry->flags & XFS_ATTR_ROOT) ? ATTR_ROOT : 0);
+               nargs.flags = XFS_ATTR_NSP_ONDISK_TO_ARGS(entry->flags);
                xfs_attr_shortform_add(&nargs, forkoff);
        }
        error = 0;
 
 out:
-       kmem_free(tmpbuffer, XFS_LBSIZE(dp->i_mount));
+       kmem_free(tmpbuffer);
        return(error);
 }
 
@@ -1079,7 +1091,7 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
                xfs_da_log_buf(args->trans, bp,
                    XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry)));
        }
-       be16_add(&hdr->count, 1);
+       be16_add_cpu(&hdr->count, 1);
 
        /*
         * Allocate space for the new string (at the end of the run).
@@ -1093,16 +1105,15 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
                                         mp->m_sb.sb_blocksize, NULL));
        ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
        ASSERT((be16_to_cpu(map->size) & 0x3) == 0);
-       be16_add(&map->size,
+       be16_add_cpu(&map->size,
                -xfs_attr_leaf_newentsize(args->namelen, args->valuelen,
                                          mp->m_sb.sb_blocksize, &tmp));
        entry->nameidx = cpu_to_be16(be16_to_cpu(map->base) +
                                     be16_to_cpu(map->size));
        entry->hashval = cpu_to_be32(args->hashval);
        entry->flags = tmp ? XFS_ATTR_LOCAL : 0;
-       entry->flags |= (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE :
-                       ((args->flags & ATTR_ROOT) ? XFS_ATTR_ROOT : 0);
-       if (args->rename) {
+       entry->flags |= XFS_ATTR_NSP_ARGS_TO_ONDISK(args->flags);
+       if (args->op_flags & XFS_DA_OP_RENAME) {
                entry->flags |= XFS_ATTR_INCOMPLETE;
                if ((args->blkno2 == args->blkno) &&
                    (args->index2 <= args->index)) {
@@ -1126,14 +1137,14 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
         * as part of this transaction (a split operation for example).
         */
        if (entry->flags & XFS_ATTR_LOCAL) {
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, args->index);
+               name_loc = xfs_attr_leaf_name_local(leaf, args->index);
                name_loc->namelen = args->namelen;
                name_loc->valuelen = cpu_to_be16(args->valuelen);
                memcpy((char *)name_loc->nameval, args->name, args->namelen);
                memcpy((char *)&name_loc->nameval[args->namelen], args->value,
                                   be16_to_cpu(name_loc->valuelen));
        } else {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
+               name_rmt = xfs_attr_leaf_name_remote(leaf, args->index);
                name_rmt->namelen = args->namelen;
                memcpy((char *)name_rmt->name, args->name, args->namelen);
                entry->flags |= XFS_ATTR_INCOMPLETE;
@@ -1144,7 +1155,7 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
                args->rmtblkcnt = XFS_B_TO_FSB(mp, args->valuelen);
        }
        xfs_da_log_buf(args->trans, bp,
-            XFS_DA_LOGRANGE(leaf, XFS_ATTR_LEAF_NAME(leaf, args->index),
+            XFS_DA_LOGRANGE(leaf, xfs_attr_leaf_name(leaf, args->index),
                                   xfs_attr_leaf_entsize(leaf, args->index)));
 
        /*
@@ -1161,12 +1172,12 @@ xfs_attr_leaf_add_work(xfs_dabuf_t *bp, xfs_da_args_t *args, int mapindex)
        map = &hdr->freemap[0];
        for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; map++, i++) {
                if (be16_to_cpu(map->base) == tmp) {
-                       be16_add(&map->base, sizeof(xfs_attr_leaf_entry_t));
-                       be16_add(&map->size,
+                       be16_add_cpu(&map->base, sizeof(xfs_attr_leaf_entry_t));
+                       be16_add_cpu(&map->size,
                                 -((int)sizeof(xfs_attr_leaf_entry_t)));
                }
        }
-       be16_add(&hdr->usedbytes, xfs_attr_leaf_entsize(leaf, args->index));
+       be16_add_cpu(&hdr->usedbytes, xfs_attr_leaf_entsize(leaf, args->index));
        xfs_da_log_buf(args->trans, bp,
                XFS_DA_LOGRANGE(leaf, hdr, sizeof(*hdr)));
        return(0);
@@ -1218,7 +1229,7 @@ xfs_attr_leaf_compact(xfs_trans_t *trans, xfs_dabuf_t *bp)
                                be16_to_cpu(hdr_s->count), mp);
        xfs_da_log_buf(trans, bp, 0, XFS_LBSIZE(mp) - 1);
 
-       kmem_free(tmpbuffer, XFS_LBSIZE(mp));
+       kmem_free(tmpbuffer);
 }
 
 /*
@@ -1541,7 +1552,7 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)
        /*
         * Check for the degenerate case of the block being empty.
         * If the block is empty, we'll simply delete it, no need to
-        * coalesce it with a sibling block.  We choose (aribtrarily)
+        * coalesce it with a sibling block.  We choose (arbitrarily)
         * to merge with the forward block unless it is NULL.
         */
        if (count == 0) {
@@ -1674,9 +1685,9 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
                ASSERT(be16_to_cpu(map->base) < XFS_LBSIZE(mp));
                ASSERT(be16_to_cpu(map->size) < XFS_LBSIZE(mp));
                if (be16_to_cpu(map->base) == tablesize) {
-                       be16_add(&map->base,
+                       be16_add_cpu(&map->base,
                                 -((int)sizeof(xfs_attr_leaf_entry_t)));
-                       be16_add(&map->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))
@@ -1698,19 +1709,19 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
        if ((before >= 0) || (after >= 0)) {
                if ((before >= 0) && (after >= 0)) {
                        map = &hdr->freemap[before];
-                       be16_add(&map->size, entsize);
-                       be16_add(&map->size,
+                       be16_add_cpu(&map->size, entsize);
+                       be16_add_cpu(&map->size,
                                 be16_to_cpu(hdr->freemap[after].size));
                        hdr->freemap[after].base = 0;
                        hdr->freemap[after].size = 0;
                } else if (before >= 0) {
                        map = &hdr->freemap[before];
-                       be16_add(&map->size, entsize);
+                       be16_add_cpu(&map->size, entsize);
                } else {
                        map = &hdr->freemap[after];
                        /* both on-disk, don't endian flip twice */
                        map->base = entry->nameidx;
-                       be16_add(&map->size, entsize);
+                       be16_add_cpu(&map->size, entsize);
                }
        } else {
                /*
@@ -1734,16 +1745,16 @@ xfs_attr_leaf_remove(xfs_dabuf_t *bp, xfs_da_args_t *args)
        /*
         * Compress the remaining entries and zero out the removed stuff.
         */
-       memset(XFS_ATTR_LEAF_NAME(leaf, args->index), 0, entsize);
-       be16_add(&hdr->usedbytes, -entsize);
+       memset(xfs_attr_leaf_name(leaf, args->index), 0, entsize);
+       be16_add_cpu(&hdr->usedbytes, -entsize);
        xfs_da_log_buf(args->trans, bp,
-            XFS_DA_LOGRANGE(leaf, XFS_ATTR_LEAF_NAME(leaf, args->index),
+            XFS_DA_LOGRANGE(leaf, xfs_attr_leaf_name(leaf, args->index),
                                   entsize));
 
        tmp = (be16_to_cpu(hdr->count) - args->index)
                                        * sizeof(xfs_attr_leaf_entry_t);
        memmove((char *)entry, (char *)(entry+1), tmp);
-       be16_add(&hdr->count, -1);
+       be16_add_cpu(&hdr->count, -1);
        xfs_da_log_buf(args->trans, bp,
            XFS_DA_LOGRANGE(leaf, entry, tmp + sizeof(*entry)));
        entry = &leaf->entries[be16_to_cpu(hdr->count)];
@@ -1868,7 +1879,7 @@ xfs_attr_leaf_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk,
                                be16_to_cpu(drop_hdr->count), mp);
                }
                memcpy((char *)save_leaf, (char *)tmp_leaf, state->blocksize);
-               kmem_free(tmpbuffer, state->blocksize);
+               kmem_free(tmpbuffer);
        }
 
        xfs_da_log_buf(state->args->trans, save_blk->bp, 0,
@@ -1928,7 +1939,7 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
                else
                        break;
        }
-       ASSERT((probe >= 0) && 
+       ASSERT((probe >= 0) &&
               (!leaf->hdr.count
               || (probe < be16_to_cpu(leaf->hdr.count))));
        ASSERT((span <= 4) || (be32_to_cpu(entry->hashval) == hashval));
@@ -1970,32 +1981,23 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
                        continue;
                }
                if (entry->flags & XFS_ATTR_LOCAL) {
-                       name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, probe);
+                       name_loc = xfs_attr_leaf_name_local(leaf, probe);
                        if (name_loc->namelen != args->namelen)
                                continue;
-                       if (memcmp(args->name, (char *)name_loc->nameval,
-                                            args->namelen) != 0)
-                               continue;
-                       if (((args->flags & ATTR_SECURE) != 0) !=
-                           ((entry->flags & XFS_ATTR_SECURE) != 0))
+                       if (memcmp(args->name, (char *)name_loc->nameval, args->namelen) != 0)
                                continue;
-                       if (((args->flags & ATTR_ROOT) != 0) !=
-                           ((entry->flags & XFS_ATTR_ROOT) != 0))
+                       if (!xfs_attr_namesp_match(args->flags, entry->flags))
                                continue;
                        args->index = probe;
                        return(XFS_ERROR(EEXIST));
                } else {
-                       name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, probe);
+                       name_rmt = xfs_attr_leaf_name_remote(leaf, probe);
                        if (name_rmt->namelen != args->namelen)
                                continue;
                        if (memcmp(args->name, (char *)name_rmt->name,
                                             args->namelen) != 0)
                                continue;
-                       if (((args->flags & ATTR_SECURE) != 0) !=
-                           ((entry->flags & XFS_ATTR_SECURE) != 0))
-                               continue;
-                       if (((args->flags & ATTR_ROOT) != 0) !=
-                           ((entry->flags & XFS_ATTR_ROOT) != 0))
+                       if (!xfs_attr_namesp_match(args->flags, entry->flags))
                                continue;
                        args->index = probe;
                        args->rmtblkno = be32_to_cpu(name_rmt->valueblk);
@@ -2029,7 +2031,7 @@ xfs_attr_leaf_getvalue(xfs_dabuf_t *bp, xfs_da_args_t *args)
 
        entry = &leaf->entries[args->index];
        if (entry->flags & XFS_ATTR_LOCAL) {
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, args->index);
+               name_loc = xfs_attr_leaf_name_local(leaf, args->index);
                ASSERT(name_loc->namelen == args->namelen);
                ASSERT(memcmp(args->name, name_loc->nameval, args->namelen) == 0);
                valuelen = be16_to_cpu(name_loc->valuelen);
@@ -2044,7 +2046,7 @@ xfs_attr_leaf_getvalue(xfs_dabuf_t *bp, xfs_da_args_t *args)
                args->valuelen = valuelen;
                memcpy(args->value, &name_loc->nameval[args->namelen], valuelen);
        } else {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
+               name_rmt = xfs_attr_leaf_name_remote(leaf, args->index);
                ASSERT(name_rmt->namelen == args->namelen);
                ASSERT(memcmp(args->name, name_rmt->name, args->namelen) == 0);
                valuelen = be32_to_cpu(name_rmt->valuelen);
@@ -2137,16 +2139,16 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
                 * off for 6.2, should be revisited later.
                 */
                if (entry_s->flags & XFS_ATTR_INCOMPLETE) { /* skip partials? */
-                       memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp);
-                       be16_add(&hdr_s->usedbytes, -tmp);
-                       be16_add(&hdr_s->count, -1);
+                       memset(xfs_attr_leaf_name(leaf_s, start_s + i), 0, tmp);
+                       be16_add_cpu(&hdr_s->usedbytes, -tmp);
+                       be16_add_cpu(&hdr_s->count, -1);
                        entry_d--;      /* to compensate for ++ in loop hdr */
                        desti--;
                        if ((start_s + i) < offset)
                                result++;       /* insertion index adjustment */
                } else {
 #endif /* GROT */
-                       be16_add(&hdr_d->firstused, -tmp);
+                       be16_add_cpu(&hdr_d->firstused, -tmp);
                        /* both on-disk, don't endian flip twice */
                        entry_d->hashval = entry_s->hashval;
                        /* both on-disk, don't endian flip twice */
@@ -2154,15 +2156,15 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
                        entry_d->flags = entry_s->flags;
                        ASSERT(be16_to_cpu(entry_d->nameidx) + tmp
                                                        <= XFS_LBSIZE(mp));
-                       memmove(XFS_ATTR_LEAF_NAME(leaf_d, desti),
-                               XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), tmp);
+                       memmove(xfs_attr_leaf_name(leaf_d, desti),
+                               xfs_attr_leaf_name(leaf_s, start_s + i), tmp);
                        ASSERT(be16_to_cpu(entry_s->nameidx) + tmp
                                                        <= XFS_LBSIZE(mp));
-                       memset(XFS_ATTR_LEAF_NAME(leaf_s, start_s + i), 0, tmp);
-                       be16_add(&hdr_s->usedbytes, -tmp);
-                       be16_add(&hdr_d->usedbytes, tmp);
-                       be16_add(&hdr_s->count, -1);
-                       be16_add(&hdr_d->count, 1);
+                       memset(xfs_attr_leaf_name(leaf_s, start_s + i), 0, tmp);
+                       be16_add_cpu(&hdr_s->usedbytes, -tmp);
+                       be16_add_cpu(&hdr_d->usedbytes, tmp);
+                       be16_add_cpu(&hdr_s->count, -1);
+                       be16_add_cpu(&hdr_d->count, 1);
                        tmp = be16_to_cpu(hdr_d->count)
                                                * sizeof(xfs_attr_leaf_entry_t)
                                                + sizeof(xfs_attr_leaf_hdr_t);
@@ -2203,7 +2205,7 @@ xfs_attr_leaf_moveents(xfs_attr_leafblock_t *leaf_s, int start_s,
         * Fill in the freemap information
         */
        hdr_d->freemap[0].base = cpu_to_be16(sizeof(xfs_attr_leaf_hdr_t));
-       be16_add(&hdr_d->freemap[0].base, be16_to_cpu(hdr_d->count) *
+       be16_add_cpu(&hdr_d->freemap[0].base, be16_to_cpu(hdr_d->count) *
                        sizeof(xfs_attr_leaf_entry_t));
        hdr_d->freemap[0].size = cpu_to_be16(be16_to_cpu(hdr_d->firstused)
                              - be16_to_cpu(hdr_d->freemap[0].base));
@@ -2270,12 +2272,12 @@ xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index)
 
        ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC);
        if (leaf->entries[index].flags & XFS_ATTR_LOCAL) {
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, index);
-               size = XFS_ATTR_LEAF_ENTSIZE_LOCAL(name_loc->namelen,
+               name_loc = xfs_attr_leaf_name_local(leaf, index);
+               size = xfs_attr_leaf_entsize_local(name_loc->namelen,
                                                   be16_to_cpu(name_loc->valuelen));
        } else {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, index);
-               size = XFS_ATTR_LEAF_ENTSIZE_REMOTE(name_rmt->namelen);
+               name_rmt = xfs_attr_leaf_name_remote(leaf, index);
+               size = xfs_attr_leaf_entsize_remote(name_rmt->namelen);
        }
        return(size);
 }
@@ -2291,13 +2293,13 @@ xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize, int *local)
 {
        int size;
 
-       size = XFS_ATTR_LEAF_ENTSIZE_LOCAL(namelen, valuelen);
-       if (size < XFS_ATTR_LEAF_ENTSIZE_LOCAL_MAX(blocksize)) {
+       size = xfs_attr_leaf_entsize_local(namelen, valuelen);
+       if (size < xfs_attr_leaf_entsize_local_max(blocksize)) {
                if (local) {
                        *local = 1;
                }
        } else {
-               size = XFS_ATTR_LEAF_ENTSIZE_REMOTE(namelen);
+               size = xfs_attr_leaf_entsize_remote(namelen);
                if (local) {
                        *local = 0;
                }
@@ -2314,8 +2316,6 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
        attrlist_cursor_kern_t *cursor;
        xfs_attr_leafblock_t *leaf;
        xfs_attr_leaf_entry_t *entry;
-       xfs_attr_leaf_name_local_t *name_loc;
-       xfs_attr_leaf_name_remote_t *name_rmt;
        int retval, i;
 
        ASSERT(bp != NULL);
@@ -2357,10 +2357,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
         * We have found our place, start copying out the new attributes.
         */
        retval = 0;
-       for (  ; (i < be16_to_cpu(leaf->hdr.count))
-            && (retval == 0); entry++, i++) {
-               attrnames_t     *namesp;
-
+       for (  ; (i < be16_to_cpu(leaf->hdr.count)); entry++, i++) {
                if (be32_to_cpu(entry->hashval) != cursor->hashval) {
                        cursor->hashval = be32_to_cpu(entry->hashval);
                        cursor->offset = 0;
@@ -2368,115 +2365,64 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
 
                if (entry->flags & XFS_ATTR_INCOMPLETE)
                        continue;               /* skip incomplete entries */
-               if (((context->flags & ATTR_SECURE) != 0) !=
-                   ((entry->flags & XFS_ATTR_SECURE) != 0) &&
-                   !(context->flags & ATTR_KERNORMALS))
-                       continue;               /* skip non-matching entries */
-               if (((context->flags & ATTR_ROOT) != 0) !=
-                   ((entry->flags & XFS_ATTR_ROOT) != 0) &&
-                   !(context->flags & ATTR_KERNROOTLS))
-                       continue;               /* skip non-matching entries */
-
-               namesp = (entry->flags & XFS_ATTR_SECURE) ? &attr_secure :
-                       ((entry->flags & XFS_ATTR_ROOT) ? &attr_trusted :
-                         &attr_user);
 
                if (entry->flags & XFS_ATTR_LOCAL) {
-                       name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, i);
-                       if (context->flags & ATTR_KERNOVAL) {
-                               ASSERT(context->flags & ATTR_KERNAMELS);
-                               context->count += namesp->attr_namelen +
-                                               (int)name_loc->namelen + 1;
-                       } else {
-                               retval = xfs_attr_put_listent(context, namesp,
-                                       (char *)name_loc->nameval,
-                                       (int)name_loc->namelen,
-                                       be16_to_cpu(name_loc->valuelen));
-                       }
+                       xfs_attr_leaf_name_local_t *name_loc =
+                               xfs_attr_leaf_name_local(leaf, i);
+
+                       retval = context->put_listent(context,
+                                               entry->flags,
+                                               (char *)name_loc->nameval,
+                                               (int)name_loc->namelen,
+                                               be16_to_cpu(name_loc->valuelen),
+                                               (char *)&name_loc->nameval[name_loc->namelen]);
+                       if (retval)
+                               return retval;
                } else {
-                       name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
-                       if (context->flags & ATTR_KERNOVAL) {
-                               ASSERT(context->flags & ATTR_KERNAMELS);
-                               context->count += namesp->attr_namelen +
-                                               (int)name_rmt->namelen + 1;
+                       xfs_attr_leaf_name_remote_t *name_rmt =
+                               xfs_attr_leaf_name_remote(leaf, i);
+
+                       int valuelen = be32_to_cpu(name_rmt->valuelen);
+
+                       if (context->put_value) {
+                               xfs_da_args_t args;
+
+                               memset((char *)&args, 0, sizeof(args));
+                               args.dp = context->dp;
+                               args.whichfork = XFS_ATTR_FORK;
+                               args.valuelen = valuelen;
+                               args.value = kmem_alloc(valuelen, KM_SLEEP);
+                               args.rmtblkno = be32_to_cpu(name_rmt->valueblk);
+                               args.rmtblkcnt = XFS_B_TO_FSB(args.dp->i_mount, valuelen);
+                               retval = xfs_attr_rmtval_get(&args);
+                               if (retval)
+                                       return retval;
+                               retval = context->put_listent(context,
+                                               entry->flags,
+                                               (char *)name_rmt->name,
+                                               (int)name_rmt->namelen,
+                                               valuelen,
+                                               (char*)args.value);
+                               kmem_free(args.value);
                        } else {
-                               retval = xfs_attr_put_listent(context, namesp,
-                                       (char *)name_rmt->name,
-                                       (int)name_rmt->namelen,
-                                       be32_to_cpu(name_rmt->valuelen));
+                               retval = context->put_listent(context,
+                                               entry->flags,
+                                               (char *)name_rmt->name,
+                                               (int)name_rmt->namelen,
+                                               valuelen,
+                                               NULL);
                        }
+                       if (retval)
+                               return retval;
                }
-               if (retval == 0) {
-                       cursor->offset++;
-               }
+               if (context->seen_enough)
+                       break;
+               cursor->offset++;
        }
        xfs_attr_trace_l_cl("blk end", context, leaf);
        return(retval);
 }
 
-#define        ATTR_ENTBASESIZE                /* minimum bytes used by an attr */ \
-       (((struct attrlist_ent *) 0)->a_name - (char *) 0)
-#define        ATTR_ENTSIZE(namelen)           /* actual bytes used by an attr */ \
-       ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
-        & ~(sizeof(u_int32_t)-1))
-
-/*
- * Format an attribute and copy it out to the user's buffer.
- * Take care to check values and protect against them changing later,
- * we may be reading them directly out of a user buffer.
- */
-/*ARGSUSED*/
-STATIC int
-xfs_attr_put_listent(xfs_attr_list_context_t *context,
-                    attrnames_t *namesp, char *name, int namelen, int valuelen)
-{
-       attrlist_ent_t *aep;
-       int arraytop;
-
-       ASSERT(!(context->flags & ATTR_KERNOVAL));
-       if (context->flags & ATTR_KERNAMELS) {
-               char *offset;
-
-               ASSERT(context->count >= 0);
-
-               arraytop = context->count + namesp->attr_namelen + namelen + 1;
-               if (arraytop > context->firstu) {
-                       context->count = -1;    /* insufficient space */
-                       return(1);
-               }
-               offset = (char *)context->alist + context->count;
-               strncpy(offset, namesp->attr_name, namesp->attr_namelen);
-               offset += namesp->attr_namelen;
-               strncpy(offset, name, namelen);                 /* real name */
-               offset += namelen;
-               *offset = '\0';
-               context->count += namesp->attr_namelen + namelen + 1;
-               return(0);
-       }
-
-       ASSERT(context->count >= 0);
-       ASSERT(context->count < (ATTR_MAX_VALUELEN/8));
-       ASSERT(context->firstu >= sizeof(*context->alist));
-       ASSERT(context->firstu <= context->bufsize);
-
-       arraytop = sizeof(*context->alist) +
-                       context->count * sizeof(context->alist->al_offset[0]);
-       context->firstu -= ATTR_ENTSIZE(namelen);
-       if (context->firstu < arraytop) {
-               xfs_attr_trace_l_c("buffer full", context);
-               context->alist->al_more = 1;
-               return(1);
-       }
-
-       aep = (attrlist_ent_t *)&(((char *)context->alist)[ context->firstu ]);
-       aep->a_valuelen = valuelen;
-       memcpy(aep->a_name, name, namelen);
-       aep->a_name[ namelen ] = 0;
-       context->alist->al_offset[ context->count++ ] = context->firstu;
-       context->alist->al_count = context->count;
-       xfs_attr_trace_l_c("add", context);
-       return(0);
-}
 
 /*========================================================================
  * Manage the INCOMPLETE flag in a leaf entry
@@ -2518,11 +2464,11 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
 
 #ifdef DEBUG
        if (entry->flags & XFS_ATTR_LOCAL) {
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf, args->index);
+               name_loc = xfs_attr_leaf_name_local(leaf, args->index);
                namelen = name_loc->namelen;
                name = (char *)name_loc->nameval;
        } else {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
+               name_rmt = xfs_attr_leaf_name_remote(leaf, args->index);
                namelen = name_rmt->namelen;
                name = (char *)name_rmt->name;
        }
@@ -2537,7 +2483,7 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
 
        if (args->rmtblkno) {
                ASSERT((entry->flags & XFS_ATTR_LOCAL) == 0);
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
+               name_rmt = xfs_attr_leaf_name_remote(leaf, args->index);
                name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
                name_rmt->valuelen = cpu_to_be32(args->valuelen);
                xfs_da_log_buf(args->trans, bp,
@@ -2548,9 +2494,7 @@ xfs_attr_leaf_clearflag(xfs_da_args_t *args)
        /*
         * Commit the flag value change and start the next trans in series.
         */
-       error = xfs_attr_rolltrans(&args->trans, args->dp);
-
-       return(error);
+       return xfs_trans_roll(&args->trans, args->dp);
 }
 
 /*
@@ -2586,7 +2530,7 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args)
        xfs_da_log_buf(args->trans, bp,
                        XFS_DA_LOGRANGE(leaf, entry, sizeof(*entry)));
        if ((entry->flags & XFS_ATTR_LOCAL) == 0) {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, args->index);
+               name_rmt = xfs_attr_leaf_name_remote(leaf, args->index);
                name_rmt->valueblk = 0;
                name_rmt->valuelen = 0;
                xfs_da_log_buf(args->trans, bp,
@@ -2597,9 +2541,7 @@ xfs_attr_leaf_setflag(xfs_da_args_t *args)
        /*
         * Commit the flag value change and start the next trans in series.
         */
-       error = xfs_attr_rolltrans(&args->trans, args->dp);
-
-       return(error);
+       return xfs_trans_roll(&args->trans, args->dp);
 }
 
 /*
@@ -2661,20 +2603,20 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
 
 #ifdef DEBUG
        if (entry1->flags & XFS_ATTR_LOCAL) {
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf1, args->index);
+               name_loc = xfs_attr_leaf_name_local(leaf1, args->index);
                namelen1 = name_loc->namelen;
                name1 = (char *)name_loc->nameval;
        } else {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf1, args->index);
+               name_rmt = xfs_attr_leaf_name_remote(leaf1, args->index);
                namelen1 = name_rmt->namelen;
                name1 = (char *)name_rmt->name;
        }
        if (entry2->flags & XFS_ATTR_LOCAL) {
-               name_loc = XFS_ATTR_LEAF_NAME_LOCAL(leaf2, args->index2);
+               name_loc = xfs_attr_leaf_name_local(leaf2, args->index2);
                namelen2 = name_loc->namelen;
                name2 = (char *)name_loc->nameval;
        } else {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf2, args->index2);
+               name_rmt = xfs_attr_leaf_name_remote(leaf2, args->index2);
                namelen2 = name_rmt->namelen;
                name2 = (char *)name_rmt->name;
        }
@@ -2691,7 +2633,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
                          XFS_DA_LOGRANGE(leaf1, entry1, sizeof(*entry1)));
        if (args->rmtblkno) {
                ASSERT((entry1->flags & XFS_ATTR_LOCAL) == 0);
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf1, args->index);
+               name_rmt = xfs_attr_leaf_name_remote(leaf1, args->index);
                name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
                name_rmt->valuelen = cpu_to_be32(args->valuelen);
                xfs_da_log_buf(args->trans, bp1,
@@ -2702,7 +2644,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
        xfs_da_log_buf(args->trans, bp2,
                          XFS_DA_LOGRANGE(leaf2, entry2, sizeof(*entry2)));
        if ((entry2->flags & XFS_ATTR_LOCAL) == 0) {
-               name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf2, args->index2);
+               name_rmt = xfs_attr_leaf_name_remote(leaf2, args->index2);
                name_rmt->valueblk = 0;
                name_rmt->valuelen = 0;
                xfs_da_log_buf(args->trans, bp2,
@@ -2715,7 +2657,7 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
        /*
         * Commit the flag value change and start the next trans in series.
         */
-       error = xfs_attr_rolltrans(&args->trans, args->dp);
+       error = xfs_trans_roll(&args->trans, args->dp);
 
        return(error);
 }
@@ -2773,7 +2715,7 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp)
        /*
         * Commit the invalidate and start the next transaction.
         */
-       error = xfs_attr_rolltrans(trans, dp);
+       error = xfs_trans_roll(trans, dp);
 
        return (error);
 }
@@ -2875,7 +2817,8 @@ xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
                /*
                 * Atomically commit the whole invalidate stuff.
                 */
-               if ((error = xfs_attr_rolltrans(trans, dp)))
+               error = xfs_trans_roll(trans, dp);
+               if (error)
                        return (error);
        }
 
@@ -2908,7 +2851,7 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
        for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
                if (be16_to_cpu(entry->nameidx) &&
                    ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
-                       name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
+                       name_rmt = xfs_attr_leaf_name_remote(leaf, i);
                        if (name_rmt->valueblk)
                                count++;
                }
@@ -2936,7 +2879,7 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
        for (i = 0; i < be16_to_cpu(leaf->hdr.count); entry++, i++) {
                if (be16_to_cpu(entry->nameidx) &&
                    ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
-                       name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
+                       name_rmt = xfs_attr_leaf_name_remote(leaf, i);
                        if (name_rmt->valueblk) {
                                lp->valueblk = be32_to_cpu(name_rmt->valueblk);
                                lp->valuelen = XFS_B_TO_FSB(dp->i_mount,
@@ -2959,7 +2902,7 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
                        error = tmp;    /* save only the 1st errno */
        }
 
-       kmem_free((xfs_caddr_t)list, size);
+       kmem_free((xfs_caddr_t)list);
        return(error);
 }
 
@@ -2990,7 +2933,7 @@ xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp,
                nmap = 1;
                error = xfs_bmapi(*trans, dp, (xfs_fileoff_t)tblkno, tblkcnt,
                                        XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
-                                       NULL, 0, &map, &nmap, NULL);
+                                       NULL, 0, &map, &nmap, NULL, NULL);
                if (error) {
                        return(error);
                }
@@ -3014,7 +2957,8 @@ xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp,
                        /*
                         * Roll to next transaction.
                         */
-                       if ((error = xfs_attr_rolltrans(trans, dp)))
+                       error = xfs_trans_roll(trans, dp);
+                       if (error)
                                return (error);
                }
 
@@ -3024,60 +2968,3 @@ xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp,
 
        return(0);
 }
-
-
-/*
- * Roll from one trans in the sequence of PERMANENT transactions to the next.
- */
-int
-xfs_attr_rolltrans(xfs_trans_t **transp, xfs_inode_t *dp)
-{
-       xfs_trans_t *trans;
-       unsigned int logres, count;
-       int     error;
-
-       /*
-        * Ensure that the inode is always logged.
-        */
-       trans = *transp;
-       xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
-
-       /*
-        * Copy the critical parameters from one trans to the next.
-        */
-       logres = trans->t_log_res;
-       count = trans->t_log_count;
-       *transp = xfs_trans_dup(trans);
-
-       /*
-        * Commit the current transaction.
-        * If this commit failed, then it'd just unlock those items that
-        * are not marked ihold. That also means that a filesystem shutdown
-        * is in progress. The caller takes the responsibility to cancel
-        * the duplicate transaction that gets returned.
-        */
-       if ((error = xfs_trans_commit(trans, 0, NULL)))
-               return (error);
-
-       trans = *transp;
-
-       /*
-        * Reserve space in the log for th next transaction.
-        * This also pushes items in the "AIL", the list of logged items,
-        * out to disk if they are taking up space at the tail of the log
-        * that we want to use.  This requires that either nothing be locked
-        * across this call, or that anything that is locked be logged in
-        * the prior and the next transactions.
-        */
-       error = xfs_trans_reserve(trans, 0, logres, 0,
-                                 XFS_TRANS_PERM_LOG_RES, count);
-       /*
-        *  Ensure that the inode is in the new transaction and locked.
-        */
-       if (!error) {
-               xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
-               xfs_trans_ihold(trans, dp);
-       }
-       return (error);
-
-}