kill I_LOCK
[safe/jmp/linux-2.6] / fs / xfs / xfs_dir2_block.c
index f6b919a..ddc4ecc 100644 (file)
@@ -22,6 +22,7 @@
 #include "xfs_inum.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
+#include "xfs_ag.h"
 #include "xfs_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
@@ -35,8 +36,8 @@
 #include "xfs_dir2_data.h"
 #include "xfs_dir2_leaf.h"
 #include "xfs_dir2_block.h"
-#include "xfs_dir2_trace.h"
 #include "xfs_error.h"
+#include "xfs_trace.h"
 
 /*
  * Local function prototypes.
@@ -93,7 +94,8 @@ xfs_dir2_block_addname(
        __be16                  *tagp;          /* pointer to tag value */
        xfs_trans_t             *tp;            /* transaction structure */
 
-       xfs_dir2_trace_args("block_addname", args);
+       trace_xfs_dir2_block_addname(args);
+
        dp = args->dp;
        tp = args->trans;
        mp = dp->i_mount;
@@ -214,7 +216,7 @@ xfs_dir2_block_addname(
        /*
         * If this isn't a real add, we're done with the buffer.
         */
-       if (args->justcheck)
+       if (args->op_flags & XFS_DA_OP_JUSTCHECK)
                xfs_da_brelse(tp, bp);
        /*
         * If we don't have space for the new entry & leaf ...
@@ -224,7 +226,7 @@ xfs_dir2_block_addname(
                 * Not trying to actually do anything, or don't have
                 * a space reservation: return no-space.
                 */
-               if (args->justcheck || args->total == 0)
+               if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || args->total == 0)
                        return XFS_ERROR(ENOSPC);
                /*
                 * Convert to the next larger format.
@@ -239,7 +241,7 @@ xfs_dir2_block_addname(
        /*
         * Just checking, and it would work, so say so.
         */
-       if (args->justcheck)
+       if (args->op_flags & XFS_DA_OP_JUSTCHECK)
                return 0;
        needlog = needscan = 0;
        /*
@@ -270,7 +272,7 @@ xfs_dir2_block_addname(
                }
                lfloglow = toidx + 1 - (be32_to_cpu(btp->stale) - 1);
                lfloghigh -= be32_to_cpu(btp->stale) - 1;
-               be32_add(&btp->count, -(be32_to_cpu(btp->stale) - 1));
+               be32_add_cpu(&btp->count, -(be32_to_cpu(btp->stale) - 1));
                xfs_dir2_data_make_free(tp, bp,
                        (xfs_dir2_data_aoff_t)((char *)blp - (char *)block),
                        (xfs_dir2_data_aoff_t)((be32_to_cpu(btp->stale) - 1) * sizeof(*blp)),
@@ -325,7 +327,7 @@ xfs_dir2_block_addname(
                /*
                 * Update the tail (entry count).
                 */
-               be32_add(&btp->count, 1);
+               be32_add_cpu(&btp->count, 1);
                /*
                 * If we now need to rebuild the bestfree map, do so.
                 * This needs to happen before the next call to use_free.
@@ -386,7 +388,7 @@ xfs_dir2_block_addname(
                        lfloglow = MIN(mid, lfloglow);
                        lfloghigh = MAX(highstale, lfloghigh);
                }
-               be32_add(&btp->stale, -1);
+               be32_add_cpu(&btp->stale, -1);
        }
        /*
         * Point to the new data entry.
@@ -447,7 +449,6 @@ xfs_dir2_block_getdents(
        xfs_mount_t             *mp;            /* filesystem mount point */
        char                    *ptr;           /* current data entry */
        int                     wantoff;        /* starting block offset */
-       xfs_ino_t               ino;
        xfs_off_t               cook;
 
        mp = dp->i_mount;
@@ -507,20 +508,14 @@ xfs_dir2_block_getdents(
                        continue;
 
                cook = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
-                                                   ptr - (char *)block);
-               ino = be64_to_cpu(dep->inumber);
-#if XFS_BIG_INUMS
-               ino += mp->m_inoadd;
-#endif
+                                           (char *)dep - (char *)block);
 
                /*
                 * If it didn't fit, set the final offset to here & return.
                 */
-               if (filldir(dirent, dep->name, dep->namelen, cook,
-                           ino, DT_UNKNOWN)) {
-                       *offset = xfs_dir2_db_off_to_dataptr(mp,
-                                       mp->m_dirdatablk,
-                                       (char *)dep - (char *)block);
+               if (filldir(dirent, dep->name, dep->namelen, cook & 0x7fffffff,
+                           be64_to_cpu(dep->inumber), DT_UNKNOWN)) {
+                       *offset = cook & 0x7fffffff;
                        xfs_da_brelse(NULL, bp);
                        return 0;
                }
@@ -530,7 +525,8 @@ xfs_dir2_block_getdents(
         * Reached the end of the block.
         * Set the offset to a non-existent block 1 and return.
         */
-       *offset = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk + 1, 0);
+       *offset = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk + 1, 0) &
+                       0x7fffffff;
        xfs_da_brelse(NULL, bp);
        return 0;
 }
@@ -595,7 +591,8 @@ xfs_dir2_block_lookup(
        int                     error;          /* error return value */
        xfs_mount_t             *mp;            /* filesystem mount point */
 
-       xfs_dir2_trace_args("block_lookup", args);
+       trace_xfs_dir2_block_lookup(args);
+
        /*
         * Get the buffer, look up the entry.
         * If not found (ENOENT) then return, have no buffer.
@@ -611,14 +608,15 @@ xfs_dir2_block_lookup(
        /*
         * Get the offset from the leaf entry, to point to the data.
         */
-       dep = (xfs_dir2_data_entry_t *)
-             ((char *)block + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
+       dep = (xfs_dir2_data_entry_t *)((char *)block +
+               xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
        /*
-        * Fill in inode number, release the block.
+        * Fill in inode number, CI name if appropriate, release the block.
         */
        args->inumber = be64_to_cpu(dep->inumber);
+       error = xfs_dir_cilookup_result(args, dep->name, dep->namelen);
        xfs_da_brelse(args->trans, bp);
-       return XFS_ERROR(EEXIST);
+       return XFS_ERROR(error);
 }
 
 /*
@@ -644,6 +642,7 @@ xfs_dir2_block_lookup_int(
        int                     mid;            /* binary search current idx */
        xfs_mount_t             *mp;            /* filesystem mount point */
        xfs_trans_t             *tp;            /* transaction pointer */
+       enum xfs_dacmp          cmp;            /* comparison result */
 
        dp = args->dp;
        tp = args->trans;
@@ -674,7 +673,7 @@ xfs_dir2_block_lookup_int(
                else
                        high = mid - 1;
                if (low > high) {
-                       ASSERT(args->oknoent);
+                       ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);
                        xfs_da_brelse(tp, bp);
                        return XFS_ERROR(ENOENT);
                }
@@ -698,20 +697,31 @@ xfs_dir2_block_lookup_int(
                dep = (xfs_dir2_data_entry_t *)
                        ((char *)block + xfs_dir2_dataptr_to_off(mp, addr));
                /*
-                * Compare, if it's right give back buffer & entry number.
+                * Compare name and if it's an exact match, return the index
+                * and buffer. If it's the first case-insensitive match, store
+                * the index and buffer and continue looking for an exact match.
                 */
-               if (dep->namelen == args->namelen &&
-                   dep->name[0] == args->name[0] &&
-                   memcmp(dep->name, args->name, args->namelen) == 0) {
+               cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen);
+               if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
+                       args->cmpresult = cmp;
                        *bpp = bp;
                        *entno = mid;
-                       return 0;
+                       if (cmp == XFS_CMP_EXACT)
+                               return 0;
                }
-       } while (++mid < be32_to_cpu(btp->count) && be32_to_cpu(blp[mid].hashval) == hash);
+       } while (++mid < be32_to_cpu(btp->count) &&
+                       be32_to_cpu(blp[mid].hashval) == hash);
+
+       ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);
+       /*
+        * Here, we can only be doing a lookup (not a rename or replace).
+        * If a case-insensitive match was found earlier, return success.
+        */
+       if (args->cmpresult == XFS_CMP_CASE)
+               return 0;
        /*
         * No match, release the buffer and return ENOENT.
         */
-       ASSERT(args->oknoent);
        xfs_da_brelse(tp, bp);
        return XFS_ERROR(ENOENT);
 }
@@ -739,7 +749,8 @@ xfs_dir2_block_removename(
        int                     size;           /* shortform size */
        xfs_trans_t             *tp;            /* transaction pointer */
 
-       xfs_dir2_trace_args("block_removename", args);
+       trace_xfs_dir2_block_removename(args);
+
        /*
         * Look up the entry in the block.  Gets the buffer and entry index.
         * It will always be there, the vnodeops level does a lookup first.
@@ -768,7 +779,7 @@ xfs_dir2_block_removename(
        /*
         * Fix up the block tail.
         */
-       be32_add(&btp->stale, 1);
+       be32_add_cpu(&btp->stale, 1);
        xfs_dir2_block_log_tail(tp, bp);
        /*
         * Remove the leaf entry by marking it stale.
@@ -815,7 +826,8 @@ xfs_dir2_block_replace(
        int                     error;          /* error return value */
        xfs_mount_t             *mp;            /* filesystem mount point */
 
-       xfs_dir2_trace_args("block_replace", args);
+       trace_xfs_dir2_block_replace(args);
+
        /*
         * Lookup the entry in the directory.  Get buffer and entry index.
         * This will always succeed since the caller has already done a lookup.
@@ -889,7 +901,8 @@ xfs_dir2_leaf_to_block(
        int                     to;             /* block/leaf to index */
        xfs_trans_t             *tp;            /* transaction pointer */
 
-       xfs_dir2_trace_args_bb("leaf_to_block", args, lbp, dbp);
+       trace_xfs_dir2_leaf_to_block(args);
+
        dp = args->dp;
        tp = args->trans;
        mp = dp->i_mount;
@@ -1034,8 +1047,10 @@ xfs_dir2_sf_to_block(
        xfs_dir2_sf_t           *sfp;           /* shortform structure */
        __be16                  *tagp;          /* end of data entry */
        xfs_trans_t             *tp;            /* transaction pointer */
+       struct xfs_name         name;
+
+       trace_xfs_dir2_sf_to_block(args);
 
-       xfs_dir2_trace_args("sf_to_block", args);
        dp = args->dp;
        tp = args->trans;
        mp = dp->i_mount;
@@ -1072,7 +1087,7 @@ xfs_dir2_sf_to_block(
         */
        error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, &blkno);
        if (error) {
-               kmem_free(buf, buf_len);
+               kmem_free(buf);
                return error;
        }
        /*
@@ -1080,7 +1095,7 @@ xfs_dir2_sf_to_block(
         */
        error = xfs_dir2_data_init(args, blkno, &bp);
        if (error) {
-               kmem_free(buf, buf_len);
+               kmem_free(buf);
                return error;
        }
        block = bp->data;
@@ -1188,8 +1203,10 @@ xfs_dir2_sf_to_block(
                tagp = xfs_dir2_data_entry_tag_p(dep);
                *tagp = cpu_to_be16((char *)dep - (char *)block);
                xfs_dir2_data_log_entry(tp, bp, dep);
-               blp[2 + i].hashval = cpu_to_be32(xfs_da_hashname(
-                                       (char *)sfep->name, sfep->namelen));
+               name.name = sfep->name;
+               name.len = sfep->namelen;
+               blp[2 + i].hashval = cpu_to_be32(mp->m_dirnameops->
+                                                       hashname(&name));
                blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
                                                 (char *)dep - (char *)block));
                offset = (int)((char *)(tagp + 1) - (char *)block);
@@ -1199,7 +1216,7 @@ xfs_dir2_sf_to_block(
                        sfep = xfs_dir2_sf_nextentry(sfp, sfep);
        }
        /* Done with the temporary buffer */
-       kmem_free(buf, buf_len);
+       kmem_free(buf);
        /*
         * Sort the leaf entries by hash value.
         */