]> git.neil.brown.name Git - LaFS.git/commitdiff
Make sure find_block loads data from inode.
authorNeilBrown <neilb@suse.de>
Mon, 7 Jun 2010 01:30:48 +0000 (11:30 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 7 Jun 2010 03:23:30 +0000 (13:23 +1000)
lafs_load_block expects not to need to read block 0
of a depth==0 inode as lafs_find_block is expected to
load that.
However there is a case where find_block (called from lafs_find_block)
skips the load.  So remove that case.

Signed-off-by: NeilBrown <neilb@suse.de>
index.c

diff --git a/index.c b/index.c
index 75120924f8e6e1b322d210467e14a384d9b42389..5d113ec359e1f45994ef43f2c840f288b55b6a39 100644 (file)
--- a/index.c
+++ b/index.c
@@ -1692,28 +1692,27 @@ find_block(struct datablock *b, int adopt, int async)
        LAFS_BUG(test_bit(B_Pinned, &b->b.flags) &&
                 b->b.parent == NULL,
                 &b->b);
-
-       if (test_bit(B_PhysValid, &b->b.flags)
-           && (!adopt || b->b.parent || test_bit(B_Root, &b->b.flags))) {
-               return 0;
-       }
        if (b->b.inode == NULL)
                return 0;
        lai = LAFSI(b->b.inode);
 
        if (lai->depth == 0) {
                /* Data is in the inode if anywhere */
-               b->b.physaddr = 0;
-               set_bit(B_PhysValid, &b->b.flags);
+               if (!test_bit(B_PhysValid, &b->b.flags)) {
+                       b->b.physaddr = 0;
+                       set_bit(B_PhysValid, &b->b.flags);
+               }
                db = lafs_inode_dblock(b->b.inode, async, MKREF(findblock));
                if (IS_ERR(db))
                        return PTR_ERR(db);
-               if (!test_bit(B_Valid, &b->b.flags) && b->b.fileaddr == 0)
+               if (!test_bit(B_Valid, &b->b.flags) && b->b.fileaddr == 0) {
                        /* Now is the best time to copy data from inode into
                         * datablock, as we know we have a valid inode block
                         * now.
                         */
+                       LAFS_BUG(b->b.physaddr != 0, &b->b);
                        fill_block_zero(b, db);
+               }
                if (adopt) {
                        ib = lafs_make_iblock(b->b.inode, adopt, async,
                                              MKREF(findblock));
@@ -1726,6 +1725,12 @@ find_block(struct datablock *b, int adopt, int async)
                        putdref(db, MKREF(findblock));
                return 0;
        }
+
+       if (test_bit(B_PhysValid, &b->b.flags)
+           && (!adopt || b->b.parent || test_bit(B_Root, &b->b.flags))) {
+               return 0;
+       }
+
        db = lafs_inode_dblock(b->b.inode, async, MKREF(findblock));
        if (IS_ERR(db))
                return PTR_ERR(db);