]> git.neil.brown.name Git - LaFS.git/commitdiff
Introduce lafs_index_empty.
authorNeilBrown <neilb@suse.de>
Tue, 25 Aug 2009 07:09:51 +0000 (17:09 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 25 Aug 2009 07:09:51 +0000 (17:09 +1000)
We currently use lafs_leaf_next to test if an index block is empty,
but that doesn't work on internal nodes of course.
So create lafs_index_empty for that purpose.

index.c
lafs.h
modify.c

diff --git a/index.c b/index.c
index a66db7cb5a9734adc4b430e209b3269971e5c0b3..73005eefb7a141b7dfd7ab22c405b343b00c12e8 100644 (file)
--- a/index.c
+++ b/index.c
@@ -1247,6 +1247,26 @@ index_lookup(void *bf, int len, u32 target, u32 *addrp, u32 *nextp)
        return p;
 }
 
+int lafs_index_empty(struct indexblock *ib)
+{
+       char *buf = map_iblock(ib);
+       int blocksize = ib->b.inode->i_sb->s_blocksize;
+       struct lafs_inode *li = LAFSI(ib->b.inode);
+       u32 addr;
+       u64 phys;
+
+       if (test_bit(B_InoIdx, &ib->b.flags))
+               phys = index_lookup(buf + li->metadata_size,
+                                   blocksize - li->metadata_size,
+                                   ib->b.fileaddr, &addr, NULL);
+       else
+               phys = index_lookup(buf, blocksize,
+                                   ib->b.fileaddr, &addr, NULL);
+       unmap_iblock(ib, buf);
+
+       return phys == 0;
+}
+
 struct indexblock *
 lafs_leaf_find(struct inode *inode, u32 addr, int adopt, u32 *next,
               int async, REFARG)
diff --git a/lafs.h b/lafs.h
index 22e526819d48798d14a3b117495bd917f90abd9a..fa154e0e5f624e747e1123921b9203bb026e84c0 100644 (file)
--- a/lafs.h
+++ b/lafs.h
@@ -103,6 +103,7 @@ int __must_check lafs_find_next(struct inode *b, loff_t *bnum);
 struct indexblock *lafs_leaf_find(struct inode *inode, u32 addr,
                                  int adopt, u32 *next, int async, REFARG);
 u32 lafs_leaf_next(struct indexblock *ib, u32 start);
+int lafs_index_empty(struct indexblock *ib);
 #ifdef DEBUG_IOLOCK
 #define set_iolock_info(b) ( (b)->iolock_file = __FILE__, (b)->iolock_line = __LINE__)
 #else
index ed60ed70d0cb353dde4f295a458f5553f7d1fc9b..fa7cf422b0d336e326cbd647595910290f375cce 100644 (file)
--- a/modify.c
+++ b/modify.c
@@ -1718,9 +1718,14 @@ void lafs_incorporate(struct fs *fs, struct indexblock *ib)
         * B_Valid so that it doesn't get written out,
         * but rather gets allocated as '0'.
         */
-       if (test_bit(B_Valid, &ib->b.flags) &&
-           lafs_leaf_next(ib, ib->b.fileaddr) == 0xFFFFFFFF)
-               clear_bit(B_Valid, &ib->b.flags);
+       if (test_bit(B_Valid, &ib->b.flags)) {
+               if (ib->depth == 1 &&
+                   lafs_leaf_next(ib, ib->b.fileaddr) == 0xFFFFFFFF)
+                       clear_bit(B_Valid, &ib->b.flags);
+               if (ib->depth > 1 &&
+                   lafs_index_empty(ib))
+                       clear_bit(B_Valid, &ib->b.flags);
+       }
 }
 
 /***************************************************************