]> git.neil.brown.name Git - LaFS.git/commitdiff
Apply single-exit pattern in try_clean
authorNeilBrown <neilb@suse.de>
Sat, 14 Aug 2010 04:43:11 +0000 (14:43 +1000)
committerNeilBrown <neilb@suse.de>
Sat, 14 Aug 2010 07:58:20 +0000 (17:58 +1000)
This removes a lot of duplications

Signed-off-by: NeilBrown <neilb@suse.de>
clean.c
lafs.h

diff --git a/clean.c b/clean.c
index 653f3d2ce1773ee2ae0a901118b0cccfcf8d5803..806f9cf6ef60f61aa86e43c830e0d3201189893a 100644 (file)
--- a/clean.c
+++ b/clean.c
@@ -321,69 +321,51 @@ static int try_clean(struct fs *fs, struct toclean *tc)
                iput(ino);
        dprintk("start processing list\n");
        list_for_each_entry_safe(b, tmp, &tc->cleaning, cleaning) {
-               struct block *cb;
+               struct block *cb = NULL;
                int err = lafs_find_block_async(b);
                dprintk("find_async gives %d %s\n", err, strblk(&b->b));
                if (err == -EAGAIN)
                        continue;
-               if (err) {
+               if (err)
                        /* Eeek, what do I do?? */
-                       list_del_init(&b->cleaning);
-                       ino = b->b.inode;
-                       putdref(b, MKREF(cleaning));
-                       iput(ino);
-                       continue;
-               }
+                       goto done_cleaning;
+
                cb = first_in_seg(&b->b, fs, tc->dev, tc->seg, MKREF(clean2));
 
                if (cb == NULL) {
                        /* Moved, don't want this. */
                        dprintk("Not in seg\n");
-                       list_del_init(&b->cleaning);
-                       ino = b->b.inode;
-                       putdref(b, MKREF(cleaning));
-                       iput(ino);
-                       continue;
+                       goto done_cleaning;
                }
                err = lafs_load_block(cb, NULL);
-               if (err) {
-                       list_del_init(&b->cleaning);
-                       ino = b->b.inode;
-                       putdref(b, MKREF(cleaning));
-                       putref(cb, MKREF(clean2));
-                       iput(ino);
-                       continue;
-               }
+               if (err)
+                       goto done_cleaning;
+
                err = lafs_wait_block_async(cb);
                if (err == -EAGAIN) {
                        putref(cb, MKREF(clean2));
                        continue;
                }
-
-               if (err) {
-                       list_del_init(&b->cleaning);
-                       ino = b->b.inode;
-                       putref(cb, MKREF(clean2));
-                       putdref(b, MKREF(cleaning));
-                       iput(ino);
-                       continue;
-               }
+               if (err)
+                       goto done_cleaning;
 
                err = mark_cleaning(cb);
                dprintk("Want to clean %s (%d)\n",
                        strblk(cb), err);
+               if (err)
+                       rv = -1;
 
                /* as cb is B_Pinned, it holds an effective
                 * ref on the inode, so it is safe to drop our
                 * ref now
                 */
+       done_cleaning:
                list_del_init(&b->cleaning);
                ino = b->b.inode;
                putdref(b, MKREF(cleaning));
                putref(cb, MKREF(clean2));
                iput(ino);
-               rv = -1;
-               if (err)
+               if (rv)
                        goto out;
        }
        rv = tc->ch == NULL && tc->ss == 0 &&
diff --git a/lafs.h b/lafs.h
index 7ccef890db0f24500a26d1bcc090576fb9018a66..501cc5c49b4cd51f50d26d40d17299f266c793a7 100644 (file)
--- a/lafs.h
+++ b/lafs.h
@@ -485,6 +485,8 @@ static inline int _putref_norefile(struct block *b)
 
 static inline void _putref(struct block *b)
 {
+       if (!b)
+               return;
        BUG_ON(atomic_read(&b->refcnt)==0);
        lafs_refile(b, 1);
 }
@@ -494,7 +496,8 @@ struct indexblock *getiref_locked(struct indexblock *ib, REFARG);
 #if DEBUG_REF == 0
 #define _reflog(c,blk,ref,add) (c(blk))
 #else
-#define _reflog(c,blk,ref,add) ({ add? add_ref(blk,ref,__FILE__,__LINE__) : \
+#define _reflog(c,blk,ref,add) ({ !blk ? 0 : \
+                       add? add_ref(blk,ref,__FILE__,__LINE__) : \
                        del_ref(blk,ref, __FILE__,__LINE__); c(blk); })
 #endif
 #define getref(blk, r) ( ({BUG_ON((blk) && ! atomic_read(&(blk)->refcnt));}), _reflog(_getref, blk,r,1))