]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - fs/ufs/inode.c
[PATCH] ufs: little directory lookup optimization
[karo-tx-linux.git] / fs / ufs / inode.c
index 3c3f62ce2ad9a926e71b5e52bb76f6b763009425..c57612d443d058e840df3112fd721af8954b745a 100644 (file)
 #include "swab.h"
 #include "util.h"
 
-#undef UFS_INODE_DEBUG
-#undef UFS_INODE_DEBUG_MORE
-
-#ifdef UFS_INODE_DEBUG
-#define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
-#else
-#define UFSD(x)
-#endif
-
 static int ufs_block_to_path(struct inode *inode, sector_t i_block, sector_t offsets[4])
 {
        struct ufs_sb_private_info *uspi = UFS_SB(inode->i_sb)->s_uspi;
@@ -61,7 +52,7 @@ static int ufs_block_to_path(struct inode *inode, sector_t i_block, sector_t off
        int n = 0;
 
 
-       UFSD(("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks));
+       UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
        if (i_block < 0) {
                ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
        } else if (i_block < direct_blocks) {
@@ -104,8 +95,8 @@ u64  ufs_frag_map(struct inode *inode, sector_t frag)
        unsigned flags = UFS_SB(sb)->s_flags;
        u64 temp = 0L;
 
-       UFSD((": frag = %llu  depth = %d\n", (unsigned long long)frag, depth));
-       UFSD((": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",uspi->s_fpbshift,uspi->s_apbmask,mask));
+       UFSD(": frag = %llu  depth = %d\n", (unsigned long long)frag, depth);
+       UFSD(": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",uspi->s_fpbshift,uspi->s_apbmask,mask);
 
        if (depth == 0)
                return 0;
@@ -161,9 +152,21 @@ out:
        return ret;
 }
 
-static struct buffer_head * ufs_inode_getfrag (struct inode *inode,
-       unsigned int fragment, unsigned int new_fragment,
-       unsigned int required, int *err, int metadata, long *phys, int *new)
+static void ufs_clear_block(struct inode *inode, struct buffer_head *bh)
+{
+       lock_buffer(bh);
+       memset(bh->b_data, 0, inode->i_sb->s_blocksize);
+       set_buffer_uptodate(bh);
+       mark_buffer_dirty(bh);
+       unlock_buffer(bh);
+       if (IS_SYNC(inode))
+               sync_dirty_buffer(bh);
+}
+
+static struct buffer_head *ufs_inode_getfrag(struct inode *inode,
+                                            unsigned int fragment, unsigned int new_fragment,
+                                            unsigned int required, int *err, int metadata,
+                                            long *phys, int *new, struct page *locked_page)
 {
        struct ufs_inode_info *ufsi = UFS_I(inode);
        struct super_block * sb;
@@ -174,8 +177,8 @@ static struct buffer_head * ufs_inode_getfrag (struct inode *inode,
        __fs32 * p, * p2;
        unsigned flags = 0;
 
-       UFSD(("ENTER, ino %lu, fragment %u, new_fragment %u, required %u\n",
-               inode->i_ino, fragment, new_fragment, required))         
+       UFSD("ENTER, ino %lu, fragment %u, new_fragment %u, required %u\n",
+               inode->i_ino, fragment, new_fragment, required);
 
        sb = inode->i_sb;
        uspi = UFS_SB(sb)->s_uspi;
@@ -198,13 +201,13 @@ repeat:
                if (metadata) {
                        result = sb_getblk(sb, uspi->s_sbbase + tmp + blockoff);
                        if (tmp == fs32_to_cpu(sb, *p)) {
-                               UFSD(("EXIT, result %u\n", tmp + blockoff))
+                               UFSD("EXIT, result %u\n", tmp + blockoff);
                                return result;
                        }
                        brelse (result);
                        goto repeat;
                } else {
-                       *phys = tmp;
+                       *phys = tmp + blockoff;
                        return NULL;
                }
        }
@@ -221,7 +224,8 @@ repeat:
                if (lastblockoff) {
                        p2 = ufsi->i_u1.i_data + lastblock;
                        tmp = ufs_new_fragments (inode, p2, lastfrag, 
-                               fs32_to_cpu(sb, *p2), uspi->s_fpb - lastblockoff, err);
+                                                fs32_to_cpu(sb, *p2), uspi->s_fpb - lastblockoff,
+                                                err, locked_page);
                        if (!tmp) {
                                if (lastfrag != ufsi->i_lastfrag)
                                        goto repeat;
@@ -233,14 +237,16 @@ repeat:
                }
                goal = fs32_to_cpu(sb, ufsi->i_u1.i_data[lastblock]) + uspi->s_fpb;
                tmp = ufs_new_fragments (inode, p, fragment - blockoff, 
-                       goal, required + blockoff, err);
+                                        goal, required + blockoff,
+                                        err, locked_page);
        }
        /*
         * We will extend last allocated block
         */
        else if (lastblock == block) {
-               tmp = ufs_new_fragments (inode, p, fragment - (blockoff - lastblockoff),
-                       fs32_to_cpu(sb, *p), required +  (blockoff - lastblockoff), err);
+               tmp = ufs_new_fragments(inode, p, fragment - (blockoff - lastblockoff),
+                                       fs32_to_cpu(sb, *p), required +  (blockoff - lastblockoff),
+                                       err, locked_page);
        }
        /*
         * We will allocate new block before last allocated block
@@ -248,8 +254,8 @@ repeat:
        else /* (lastblock > block) */ {
                if (lastblock && (tmp = fs32_to_cpu(sb, ufsi->i_u1.i_data[lastblock-1])))
                        goal = tmp + uspi->s_fpb;
-               tmp = ufs_new_fragments (inode, p, fragment - blockoff, 
-                       goal, uspi->s_fpb, err);
+               tmp = ufs_new_fragments(inode, p, fragment - blockoff,
+                                       goal, uspi->s_fpb, err, locked_page);
        }
        if (!tmp) {
                if ((!blockoff && *p) || 
@@ -259,14 +265,11 @@ repeat:
                return NULL;
        }
 
-       /* The nullification of framgents done in ufs/balloc.c is
-        * something I don't have the stomache to move into here right
-        * now. -DaveM
-        */
        if (metadata) {
                result = sb_getblk(inode->i_sb, tmp + blockoff);
+               ufs_clear_block(inode, result);
        } else {
-               *phys = tmp;
+               *phys = tmp + blockoff;
                result = NULL;
                *err = 0;
                *new = 1;
@@ -276,7 +279,7 @@ repeat:
        if (IS_SYNC(inode))
                ufs_sync_inode (inode);
        mark_inode_dirty(inode);
-       UFSD(("EXIT, result %u\n", tmp + blockoff))
+       UFSD("EXIT, result %u\n", tmp + blockoff);
        return result;
 
      /* This part : To be implemented ....
@@ -295,9 +298,10 @@ repeat2:
      */
 }
 
-static struct buffer_head * ufs_block_getfrag (struct inode *inode,
-       struct buffer_head *bh, unsigned int fragment, unsigned int new_fragment, 
-       unsigned int blocksize, int * err, int metadata, long *phys, int *new)
+static struct buffer_head *ufs_block_getfrag(struct inode *inode, struct buffer_head *bh,
+                                            unsigned int fragment, unsigned int new_fragment,
+                                            unsigned int blocksize, int * err, int metadata,
+                                            long *phys, int *new, struct page *locked_page)
 {
        struct super_block * sb;
        struct ufs_sb_private_info * uspi;
@@ -310,7 +314,7 @@ static struct buffer_head * ufs_block_getfrag (struct inode *inode,
        block = ufs_fragstoblks (fragment);
        blockoff = ufs_fragnum (fragment);
 
-       UFSD(("ENTER, ino %lu, fragment %u, new_fragment %u\n", inode->i_ino, fragment, new_fragment))  
+       UFSD("ENTER, ino %lu, fragment %u, new_fragment %u\n", inode->i_ino, fragment, new_fragment);
 
        result = NULL;
        if (!bh)
@@ -333,7 +337,7 @@ repeat:
                        brelse (result);
                        goto repeat;
                } else {
-                       *phys = tmp;
+                       *phys = tmp + blockoff;
                        goto out;
                }
        }
@@ -342,21 +346,20 @@ repeat:
                goal = tmp + uspi->s_fpb;
        else
                goal = bh->b_blocknr + uspi->s_fpb;
-       tmp = ufs_new_fragments (inode, p, ufs_blknum(new_fragment), goal, uspi->s_fpb, err);
+       tmp = ufs_new_fragments(inode, p, ufs_blknum(new_fragment), goal,
+                               uspi->s_fpb, err, locked_page);
        if (!tmp) {
                if (fs32_to_cpu(sb, *p))
                        goto repeat;
                goto out;
        }               
 
-       /* The nullification of framgents done in ufs/balloc.c is
-        * something I don't have the stomache to move into here right
-        * now. -DaveM
-        */
+
        if (metadata) {
                result = sb_getblk(sb, tmp + blockoff);
+               ufs_clear_block(inode, result);
        } else {
-               *phys = tmp;
+               *phys = tmp + blockoff;
                *new = 1;
        }
 
@@ -365,10 +368,10 @@ repeat:
                sync_dirty_buffer(bh);
        inode->i_ctime = CURRENT_TIME_SEC;
        mark_inode_dirty(inode);
-       UFSD(("result %u\n", tmp + blockoff));
+       UFSD("result %u\n", tmp + blockoff);
 out:
        brelse (bh);
-       UFSD(("EXIT\n"));
+       UFSD("EXIT\n");
        return result;
 }
 
@@ -387,7 +390,7 @@ int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buffer_hea
        
        if (!create) {
                phys64 = ufs_frag_map(inode, fragment);
-               UFSD(("phys64 = %llu \n",phys64));
+               UFSD("phys64 = %llu \n",phys64);
                if (phys64)
                        map_bh(bh_result, sb, phys64);
                return 0;
@@ -402,7 +405,7 @@ int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buffer_hea
 
        lock_kernel();
 
-       UFSD(("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment))
+       UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
        if (fragment < 0)
                goto abort_negative;
        if (fragment >
@@ -418,15 +421,15 @@ int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buffer_hea
         * it much more readable:
         */
 #define GET_INODE_DATABLOCK(x) \
-               ufs_inode_getfrag(inode, x, fragment, 1, &err, 0, &phys, &new)
+       ufs_inode_getfrag(inode, x, fragment, 1, &err, 0, &phys, &new, bh_result->b_page)
 #define GET_INODE_PTR(x) \
-               ufs_inode_getfrag(inode, x, fragment, uspi->s_fpb, &err, 1, NULL, NULL)
+       ufs_inode_getfrag(inode, x, fragment, uspi->s_fpb, &err, 1, NULL, NULL, bh_result->b_page)
 #define GET_INDIRECT_DATABLOCK(x) \
-               ufs_block_getfrag(inode, bh, x, fragment, sb->s_blocksize, \
-                                 &err, 0, &phys, &new);
+       ufs_block_getfrag(inode, bh, x, fragment, sb->s_blocksize,      \
+                         &err, 0, &phys, &new, bh_result->b_page);
 #define GET_INDIRECT_PTR(x) \
-               ufs_block_getfrag(inode, bh, x, fragment, sb->s_blocksize, \
-                                 &err, 1, NULL, NULL);
+       ufs_block_getfrag(inode, bh, x, fragment, sb->s_blocksize,      \
+                         &err, 1, NULL, NULL, bh_result->b_page);
 
        if (ptr < UFS_NDIR_FRAGMENT) {
                bh = GET_INODE_DATABLOCK(ptr);
@@ -502,7 +505,7 @@ struct buffer_head * ufs_bread (struct inode * inode, unsigned fragment,
 {
        struct buffer_head * bh;
 
-       UFSD(("ENTER, ino %lu, fragment %u\n", inode->i_ino, fragment))
+       UFSD("ENTER, ino %lu, fragment %u\n", inode->i_ino, fragment);
        bh = ufs_getfrag (inode, fragment, create, err);
        if (!bh || buffer_uptodate(bh))                 
                return bh;
@@ -540,6 +543,28 @@ struct address_space_operations ufs_aops = {
        .bmap = ufs_bmap
 };
 
+static void ufs_set_inode_ops(struct inode *inode)
+{
+       if (S_ISREG(inode->i_mode)) {
+               inode->i_op = &ufs_file_inode_operations;
+               inode->i_fop = &ufs_file_operations;
+               inode->i_mapping->a_ops = &ufs_aops;
+       } else if (S_ISDIR(inode->i_mode)) {
+               inode->i_op = &ufs_dir_inode_operations;
+               inode->i_fop = &ufs_dir_operations;
+               inode->i_mapping->a_ops = &ufs_aops;
+       } else if (S_ISLNK(inode->i_mode)) {
+               if (!inode->i_blocks)
+                       inode->i_op = &ufs_fast_symlink_inode_operations;
+               else {
+                       inode->i_op = &page_symlink_inode_operations;
+                       inode->i_mapping->a_ops = &ufs_aops;
+               }
+       } else
+               init_special_inode(inode, inode->i_mode,
+                                  ufs_get_inode_dev(inode->i_sb, UFS_I(inode)));
+}
+
 void ufs_read_inode (struct inode * inode)
 {
        struct ufs_inode_info *ufsi = UFS_I(inode);
@@ -552,7 +577,7 @@ void ufs_read_inode (struct inode * inode)
        unsigned i;
        unsigned flags;
        
-       UFSD(("ENTER, ino %lu\n", inode->i_ino))
+       UFSD("ENTER, ino %lu\n", inode->i_ino);
        
        sb = inode->i_sb;
        uspi = UFS_SB(sb)->s_uspi;
@@ -603,38 +628,22 @@ void ufs_read_inode (struct inode * inode)
        ufsi->i_shadow = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_shadow);
        ufsi->i_oeftflag = fs32_to_cpu(sb, ufs_inode->ui_u3.ui_sun.ui_oeftflag);
        ufsi->i_lastfrag = (inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift;
+       ufsi->i_dir_start_lookup = 0;
        
        if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
                for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++)
                        ufsi->i_u1.i_data[i] = ufs_inode->ui_u2.ui_addr.ui_db[i];
-       }
-       else {
+       } else {
                for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++)
                        ufsi->i_u1.i_symlink[i] = ufs_inode->ui_u2.ui_symlink[i];
        }
        ufsi->i_osync = 0;
 
-       if (S_ISREG(inode->i_mode)) {
-               inode->i_op = &ufs_file_inode_operations;
-               inode->i_fop = &ufs_file_operations;
-               inode->i_mapping->a_ops = &ufs_aops;
-       } else if (S_ISDIR(inode->i_mode)) {
-               inode->i_op = &ufs_dir_inode_operations;
-               inode->i_fop = &ufs_dir_operations;
-       } else if (S_ISLNK(inode->i_mode)) {
-               if (!inode->i_blocks)
-                       inode->i_op = &ufs_fast_symlink_inode_operations;
-               else {
-                       inode->i_op = &page_symlink_inode_operations;
-                       inode->i_mapping->a_ops = &ufs_aops;
-               }
-       } else
-               init_special_inode(inode, inode->i_mode,
-                       ufs_get_inode_dev(sb, ufsi));
+       ufs_set_inode_ops(inode);
 
        brelse (bh);
 
-       UFSD(("EXIT\n"))
+       UFSD("EXIT\n");
        return;
 
 bad_inode:
@@ -642,7 +651,7 @@ bad_inode:
        return;
 
 ufs2_inode :
-       UFSD(("Reading ufs2 inode, ino %lu\n", inode->i_ino))
+       UFSD("Reading ufs2 inode, ino %lu\n", inode->i_ino);
 
        ufs2_inode = (struct ufs2_inode *)(bh->b_data + sizeof(struct ufs2_inode) * ufs_inotofsbo(inode->i_ino));
 
@@ -690,27 +699,11 @@ ufs2_inode :
        }
        ufsi->i_osync = 0;
 
-       if (S_ISREG(inode->i_mode)) {
-               inode->i_op = &ufs_file_inode_operations;
-               inode->i_fop = &ufs_file_operations;
-               inode->i_mapping->a_ops = &ufs_aops;
-       } else if (S_ISDIR(inode->i_mode)) {
-               inode->i_op = &ufs_dir_inode_operations;
-               inode->i_fop = &ufs_dir_operations;
-       } else if (S_ISLNK(inode->i_mode)) {
-               if (!inode->i_blocks)
-                       inode->i_op = &ufs_fast_symlink_inode_operations;
-               else {
-                       inode->i_op = &page_symlink_inode_operations;
-                       inode->i_mapping->a_ops = &ufs_aops;
-               }
-       } else   /* TODO  : here ...*/
-               init_special_inode(inode, inode->i_mode,
-                       ufs_get_inode_dev(sb, ufsi));
+       ufs_set_inode_ops(inode);
 
        brelse(bh);
 
-       UFSD(("EXIT\n"))
+       UFSD("EXIT\n");
        return;
 }
 
@@ -724,7 +717,7 @@ static int ufs_update_inode(struct inode * inode, int do_sync)
        unsigned i;
        unsigned flags;
 
-       UFSD(("ENTER, ino %lu\n", inode->i_ino))
+       UFSD("ENTER, ino %lu\n", inode->i_ino);
 
        sb = inode->i_sb;
        uspi = UFS_SB(sb)->s_uspi;
@@ -785,7 +778,7 @@ static int ufs_update_inode(struct inode * inode, int do_sync)
                sync_dirty_buffer(bh);
        brelse (bh);
        
-       UFSD(("EXIT\n"))
+       UFSD("EXIT\n");
        return 0;
 }