Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[firefly-linux-kernel-4.4.55.git] / fs / xfs / xfs_attr_leaf.c
index 3adfc5dcfe7d5a4a1aec09879883ec4ad50b88bb..9455051f01208e61ae7d32cf9ab2cbad858d5fe7 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"
@@ -194,7 +192,7 @@ xfs_attr_shortform_create(xfs_da_args_t *args)
        xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK);
        hdr = (xfs_attr_sf_hdr_t *)ifp->if_u1.if_data;
        hdr->count = 0;
-       INT_SET(hdr->totsize, ARCH_CONVERT, sizeof(*hdr));
+       hdr->totsize = cpu_to_be16(sizeof(*hdr));
        xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
 }
 
@@ -224,8 +222,7 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
        ASSERT(ifp->if_flags & XFS_IFINLINE);
        sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT);
-                               sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
+       for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
 #ifdef DEBUG
                if (sfe->namelen != args->namelen)
                        continue;
@@ -248,13 +245,13 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
        sfe = (xfs_attr_sf_entry_t *)((char *)sf + offset);
 
        sfe->namelen = args->namelen;
-       INT_SET(sfe->valuelen, ARCH_CONVERT, args->valuelen);
+       sfe->valuelen = args->valuelen;
        sfe->flags = (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE :
                        ((args->flags & ATTR_ROOT) ? XFS_ATTR_ROOT : 0);
        memcpy(sfe->nameval, args->name, args->namelen);
        memcpy(&sfe->nameval[args->namelen], args->value, args->valuelen);
-       INT_MOD(sf->hdr.count, ARCH_CONVERT, 1);
-       INT_MOD(sf->hdr.totsize, ARCH_CONVERT, size);
+       sf->hdr.count++;
+       be16_add(&sf->hdr.totsize, size);
        xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
 
        xfs_sbversion_add_attr2(mp, args->trans);
@@ -277,7 +274,7 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
        base = sizeof(xfs_attr_sf_hdr_t);
        sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;
        sfe = &sf->list[0];
-       end = INT_GET(sf->hdr.count, ARCH_CONVERT);
+       end = sf->hdr.count;
        for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
                                        base += size, i++) {
                size = XFS_ATTR_SF_ENTSIZE(sfe);
@@ -300,11 +297,11 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
         * Fix up the attribute fork data, covering the hole
         */
        end = base + size;
-       totsize = INT_GET(sf->hdr.totsize, ARCH_CONVERT);
+       totsize = be16_to_cpu(sf->hdr.totsize);
        if (end != totsize)
                memmove(&((char *)sf)[base], &((char *)sf)[end], totsize - end);
-       INT_MOD(sf->hdr.count, ARCH_CONVERT, -1);
-       INT_MOD(sf->hdr.totsize, ARCH_CONVERT, -size);
+       sf->hdr.count--;
+       be16_add(&sf->hdr.totsize, -size);
 
        /*
         * Fix up the start offset of the attribute fork
@@ -360,7 +357,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
        ASSERT(ifp->if_flags & XFS_IFINLINE);
        sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT);
+       for (i = 0; i < sf->hdr.count;
                                sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
                if (sfe->namelen != args->namelen)
                        continue;
@@ -391,7 +388,7 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
        ASSERT(args->dp->i_d.di_aformat == XFS_IFINLINE);
        sf = (xfs_attr_shortform_t *)args->dp->i_afp->if_u1.if_data;
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT);
+       for (i = 0; i < sf->hdr.count;
                                sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
                if (sfe->namelen != args->namelen)
                        continue;
@@ -404,14 +401,14 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
                    ((sfe->flags & XFS_ATTR_ROOT) != 0))
                        continue;
                if (args->flags & ATTR_KERNOVAL) {
-                       args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+                       args->valuelen = sfe->valuelen;
                        return(XFS_ERROR(EEXIST));
                }
-               if (args->valuelen < INT_GET(sfe->valuelen, ARCH_CONVERT)) {
-                       args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+               if (args->valuelen < sfe->valuelen) {
+                       args->valuelen = sfe->valuelen;
                        return(XFS_ERROR(ERANGE));
                }
-               args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+               args->valuelen = sfe->valuelen;
                memcpy(args->value, &sfe->nameval[args->namelen],
                                                    args->valuelen);
                return(XFS_ERROR(EEXIST));
@@ -438,7 +435,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
        dp = args->dp;
        ifp = dp->i_afp;
        sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
-       size = INT_GET(sf->hdr.totsize, ARCH_CONVERT);
+       size = be16_to_cpu(sf->hdr.totsize);
        tmpbuffer = kmem_alloc(size, KM_SLEEP);
        ASSERT(tmpbuffer != NULL);
        memcpy(tmpbuffer, ifp->if_u1.if_data, size);
@@ -481,11 +478,11 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
        nargs.oknoent = 1;
 
        sfe = &sf->list[0];
-       for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
+       for (i = 0; i < sf->hdr.count; i++) {
                nargs.name = (char *)sfe->nameval;
                nargs.namelen = sfe->namelen;
                nargs.value = (char *)&sfe->nameval[nargs.namelen];
-               nargs.valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT);
+               nargs.valuelen = sfe->valuelen;
                nargs.hashval = xfs_da_hashname((char *)sfe->nameval,
                                                sfe->namelen);
                nargs.flags = (sfe->flags & XFS_ATTR_SECURE) ? ATTR_SECURE :
@@ -514,11 +511,9 @@ xfs_attr_shortform_compare(const void *a, const void *b)
 
        sa = (xfs_attr_sf_sort_t *)a;
        sb = (xfs_attr_sf_sort_t *)b;
-       if (INT_GET(sa->hash, ARCH_CONVERT)
-                               < INT_GET(sb->hash, ARCH_CONVERT)) {
+       if (sa->hash < sb->hash) {
                return(-1);
-       } else if (INT_GET(sa->hash, ARCH_CONVERT)
-                               > INT_GET(sb->hash, ARCH_CONVERT)) {
+       } else if (sa->hash > sb->hash) {
                return(1);
        } else {
                return(sa->entno - sb->entno);
@@ -527,7 +522,7 @@ xfs_attr_shortform_compare(const void *a, const void *b)
 
 /*
  * 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.
@@ -560,10 +555,8 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
         * If the buffer is large enough, do not bother with sorting.
         * Note the generous fudge factor of 16 overhead bytes per entry.
         */
-       if ((dp->i_afp->if_bytes + INT_GET(sf->hdr.count, ARCH_CONVERT) * 16)
-                                                       < context->bufsize) {
-               for (i = 0, sfe = &sf->list[0];
-                               i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
+       if ((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;
 
                        if (((context->flags & ATTR_SECURE) != 0) !=
@@ -584,14 +577,13 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                        if (context->flags & ATTR_KERNOVAL) {
                                ASSERT(context->flags & ATTR_KERNAMELS);
                                context->count += namesp->attr_namelen +
-                                       INT_GET(sfe->namelen, ARCH_CONVERT) + 1;
+                                       sfe->namelen + 1;
                        }
                        else {
                                if (xfs_attr_put_listent(context, namesp,
                                                   (char *)sfe->nameval,
                                                   (int)sfe->namelen,
-                                                  (int)INT_GET(sfe->valuelen,
-                                                               ARCH_CONVERT)))
+                                                  (int)sfe->valuelen))
                                        break;
                        }
                        sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
@@ -603,7 +595,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
        /*
         * It didn't all fit, so we have to sort everything on hashval.
         */
-       sbsize = INT_GET(sf->hdr.count, ARCH_CONVERT) * sizeof(*sbuf);
+       sbsize = sf->hdr.count * sizeof(*sbuf);
        sbp = sbuf = kmem_alloc(sbsize, KM_SLEEP);
 
        /*
@@ -611,8 +603,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
         * the relevant info from only those that match into a buffer.
         */
        nsbuf = 0;
-       for (i = 0, sfe = &sf->list[0];
-                       i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
+       for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
                if (unlikely(
                    ((char *)sfe < (char *)sf) ||
                    ((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) {
@@ -636,8 +627,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                        continue;
                }
                sbp->entno = i;
-               INT_SET(sbp->hash, ARCH_CONVERT,
-                       xfs_da_hashname((char *)sfe->nameval, sfe->namelen));
+               sbp->hash = xfs_da_hashname((char *)sfe->nameval, sfe->namelen);
                sbp->name = (char *)sfe->nameval;
                sbp->namelen = sfe->namelen;
                /* These are bytes, and both on-disk, don't endian-flip */
@@ -660,12 +650,12 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
        cursor->initted = 1;
        cursor->blkno = 0;
        for (sbp = sbuf, i = 0; i < nsbuf; i++, sbp++) {
-               if (INT_GET(sbp->hash, ARCH_CONVERT) == cursor->hashval) {
+               if (sbp->hash == cursor->hashval) {
                        if (cursor->offset == count) {
                                break;
                        }
                        count++;
-               } else if (INT_GET(sbp->hash, ARCH_CONVERT) > cursor->hashval) {
+               } else if (sbp->hash > cursor->hashval) {
                        break;
                }
        }
@@ -685,8 +675,8 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                        ((sbp->flags & XFS_ATTR_ROOT) ? &attr_trusted :
                          &attr_user);
 
-               if (cursor->hashval != INT_GET(sbp->hash, ARCH_CONVERT)) {
-                       cursor->hashval = INT_GET(sbp->hash, ARCH_CONVERT);
+               if (cursor->hashval != sbp->hash) {
+                       cursor->hashval = sbp->hash;
                        cursor->offset = 0;
                }
                if (context->flags & ATTR_KERNOVAL) {
@@ -696,7 +686,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
                } else {
                        if (xfs_attr_put_listent(context, namesp,
                                        sbp->name, sbp->namelen,
-                                       INT_GET(sbp->valuelen, ARCH_CONVERT)))
+                                       sbp->valuelen))
                                break;
                }
                cursor->offset++;
@@ -877,8 +867,8 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)
        /* both on-disk, don't endian-flip twice */
        node->btree[0].hashval =
                leaf->entries[be16_to_cpu(leaf->hdr.count)-1 ].hashval;
-       INT_SET(node->btree[0].before, ARCH_CONVERT, blkno);
-       INT_SET(node->hdr.count, ARCH_CONVERT, 1);
+       node->btree[0].before = cpu_to_be32(blkno);
+       node->hdr.count = cpu_to_be16(1);
        xfs_da_log_buf(args->trans, bp1, 0, XFS_LBSIZE(dp->i_mount) - 1);
        error = 0;
 out:
@@ -1549,7 +1539,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) {
@@ -2006,11 +1996,9 @@ xfs_attr_leaf_lookup_int(xfs_dabuf_t *bp, xfs_da_args_t *args)
                            ((entry->flags & XFS_ATTR_ROOT) != 0))
                                continue;
                        args->index = probe;
-                       args->rmtblkno
-                                 = INT_GET(name_rmt->valueblk, ARCH_CONVERT);
+                       args->rmtblkno = be32_to_cpu(name_rmt->valueblk);
                        args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount,
-                                                  INT_GET(name_rmt->valuelen,
-                                                               ARCH_CONVERT));
+                                                  be32_to_cpu(name_rmt->valuelen));
                        return(XFS_ERROR(EEXIST));
                }
        }
@@ -2057,8 +2045,8 @@ xfs_attr_leaf_getvalue(xfs_dabuf_t *bp, xfs_da_args_t *args)
                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 = INT_GET(name_rmt->valuelen, ARCH_CONVERT);
-               args->rmtblkno = INT_GET(name_rmt->valueblk, ARCH_CONVERT);
+               valuelen = be32_to_cpu(name_rmt->valuelen);
+               args->rmtblkno = be32_to_cpu(name_rmt->valueblk);
                args->rmtblkcnt = XFS_B_TO_FSB(args->dp->i_mount, valuelen);
                if (args->flags & ATTR_KERNOVAL) {
                        args->valuelen = valuelen;
@@ -2413,8 +2401,7 @@ xfs_attr_leaf_list_int(xfs_dabuf_t *bp, xfs_attr_list_context_t *context)
                                retval = xfs_attr_put_listent(context, namesp,
                                        (char *)name_rmt->name,
                                        (int)name_rmt->namelen,
-                                       (int)INT_GET(name_rmt->valuelen,
-                                                               ARCH_CONVERT));
+                                       be32_to_cpu(name_rmt->valuelen));
                        }
                }
                if (retval == 0) {
@@ -2549,8 +2536,8 @@ 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);
-               INT_SET(name_rmt->valueblk, ARCH_CONVERT, args->rmtblkno);
-               INT_SET(name_rmt->valuelen, ARCH_CONVERT, args->valuelen);
+               name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
+               name_rmt->valuelen = cpu_to_be32(args->valuelen);
                xfs_da_log_buf(args->trans, bp,
                         XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt)));
        }
@@ -2703,8 +2690,8 @@ xfs_attr_leaf_flipflags(xfs_da_args_t *args)
        if (args->rmtblkno) {
                ASSERT((entry1->flags & XFS_ATTR_LOCAL) == 0);
                name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf1, args->index);
-               INT_SET(name_rmt->valueblk, ARCH_CONVERT, args->rmtblkno);
-               INT_SET(name_rmt->valuelen, ARCH_CONVERT, args->valuelen);
+               name_rmt->valueblk = cpu_to_be32(args->rmtblkno);
+               name_rmt->valuelen = cpu_to_be32(args->valuelen);
                xfs_da_log_buf(args->trans, bp1,
                         XFS_DA_LOGRANGE(leaf1, name_rmt, sizeof(*name_rmt)));
        }
@@ -2815,12 +2802,12 @@ xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
        node = bp->data;
        ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC);
        parent_blkno = xfs_da_blkno(bp);        /* save for re-read later */
-       count = INT_GET(node->hdr.count, ARCH_CONVERT);
+       count = be16_to_cpu(node->hdr.count);
        if (!count) {
                xfs_da_brelse(*trans, bp);
                return(0);
        }
-       child_fsb = INT_GET(node->btree[0].before, ARCH_CONVERT);
+       child_fsb = be32_to_cpu(node->btree[0].before);
        xfs_da_brelse(*trans, bp);      /* no locks for later trans */
 
        /*
@@ -2880,7 +2867,7 @@ xfs_attr_node_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp,
                                &bp, XFS_ATTR_FORK);
                        if (error)
                                return(error);
-                       child_fsb = INT_GET(node->btree[i+1].before, ARCH_CONVERT);
+                       child_fsb = be32_to_cpu(node->btree[i+1].before);
                        xfs_da_brelse(*trans, bp);
                }
                /*
@@ -2949,12 +2936,9 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
                    ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
                        name_rmt = XFS_ATTR_LEAF_NAME_REMOTE(leaf, i);
                        if (name_rmt->valueblk) {
-                               /* both on-disk, don't endian flip twice */
-                               lp->valueblk = name_rmt->valueblk;
-                               INT_SET(lp->valuelen, ARCH_CONVERT,
-                                               XFS_B_TO_FSB(dp->i_mount,
-                                                   INT_GET(name_rmt->valuelen,
-                                                             ARCH_CONVERT)));
+                               lp->valueblk = be32_to_cpu(name_rmt->valueblk);
+                               lp->valuelen = XFS_B_TO_FSB(dp->i_mount,
+                                                   be32_to_cpu(name_rmt->valuelen));
                                lp++;
                        }
                }
@@ -2967,10 +2951,8 @@ xfs_attr_leaf_inactive(xfs_trans_t **trans, xfs_inode_t *dp, xfs_dabuf_t *bp)
        error = 0;
        for (lp = list, i = 0; i < count; i++, lp++) {
                tmp = xfs_attr_leaf_freextent(trans, dp,
-                                                    INT_GET(lp->valueblk,
-                                                               ARCH_CONVERT),
-                                                    INT_GET(lp->valuelen,
-                                                               ARCH_CONVERT));
+                               lp->valueblk, lp->valuelen);
+
                if (error == 0)
                        error = tmp;    /* save only the 1st errno */
        }
@@ -3006,7 +2988,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);
                }