]> git.neil.brown.name Git - LaFS.git/commitdiff
Further tidy up for make_orphan
authorNeilBrown <neilb@suse.de>
Thu, 27 Aug 2009 01:46:02 +0000 (11:46 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 27 Aug 2009 01:46:02 +0000 (11:46 +1000)
Move the calls to orphan_abort and orphan_commit into make_orphan
to follow the pattern used elsewhere.
This requires moving the i_mutex lock out into make_orphan,
but otherwise seems to be a good improvement.

orphan.c

index 0674e42a25e9b7bec271efbf53cb5a9403d15423..21c258564dd3190b028f6aafbf6eb69430e3f4ee 100644 (file)
--- a/orphan.c
+++ b/orphan.c
@@ -128,9 +128,7 @@ static int orphan_prepare(struct fs *fs)
        return err;
 }
 
-static void orphan_abort(struct fs *fs);
-static void orphan_commit(struct fs *fs, struct datablock *b, struct datablock *ob);
-static int orphan_pin(struct fs *fs, struct datablock *b)
+static struct datablock *orphan_pin(struct fs *fs, struct datablock *b)
 {
        struct orphan_md *om = &LAFSI(fs->orphans)->md.orphan;
        u32 slot;
@@ -138,7 +136,6 @@ static int orphan_pin(struct fs *fs, struct datablock *b)
        u32 bnum;
        struct datablock *ob;
 
-       mutex_lock_nested(&fs->orphans->i_mutex, I_MUTEX_QUOTA);
        slot = om->nextfree;
        bnum = slot >> (fs->prime_sb->s_blocksize_bits-4);
        dprintk("slot=%d bnum=%d\n", slot, bnum);
@@ -149,15 +146,10 @@ static int orphan_pin(struct fs *fs, struct datablock *b)
        lafs_phase_wait(&ob->b);
        err = lafs_pin_dblock(ob);
        if (err) {
-               if (err != -EAGAIN)
-                       orphan_abort(fs);
-               mutex_unlock(&fs->orphans->i_mutex);
                putdref(ob, MKREF(orphan));
-               return err;
+               return ERR_PTR(err);
        }
-       orphan_commit(fs, b, ob);
-       mutex_unlock(&fs->orphans->i_mutex);
-       return 0;
+       return ob;
 }
 
 static void orphan_commit(struct fs *fs, struct datablock *b, struct datablock *ob)
@@ -238,6 +230,7 @@ static void orphan_abort(struct fs *fs)
 int lafs_make_orphan(struct fs *fs, struct datablock *db)
 {
        int err;
+       struct datablock *ob;
 
        if (test_bit(B_Orphan, &db->b.flags))
                return 0;
@@ -247,12 +240,19 @@ int lafs_make_orphan(struct fs *fs, struct datablock *db)
                return err;
  retry:
        lafs_checkpoint_lock(fs);
-       err = orphan_pin(fs, db);
-       if (err == -EAGAIN) {
+       mutex_lock_nested(&fs->orphans->i_mutex, I_MUTEX_QUOTA);
+       ob = orphan_pin(fs, db);
+       if (IS_ERR(ob) && PTR_ERR(ob) == -EAGAIN) {
+               mutex_unlock(&fs->orphans->i_mutex);
                lafs_checkpoint_unlock_wait(fs);
                goto retry;
        }
-       /* there is no 'commit' - 'pin' did all the work */
+       if (IS_ERR(ob)) {
+               orphan_abort(fs);
+               err = PTR_ERR(ob);
+       } else
+               orphan_commit(fs, db, ob);
+       mutex_unlock(&fs->orphans->i_mutex);
        lafs_checkpoint_unlock(fs);
        return err;
 }