]> git.neil.brown.name Git - LaFS.git/commitdiff
Use orphan_abort in lafs_orphan_release
authorNeilBrown <neilb@suse.de>
Thu, 27 Aug 2009 01:46:00 +0000 (11:46 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 27 Aug 2009 01:46:00 +0000 (11:46 +1000)
lafs_orphan_release currently open-codes all of orphan_abort,
except the i_mutex locking is a bit different.  So change locking
rules for orphan_abort, then use that directly in lafs_orphan_release.

orphan.c

index 624cd68e79f6d58fe70bf1984f27310514632d8b..1bc5c0a096c84c7a41761319959af8c442f6fe4d 100644 (file)
--- a/orphan.c
+++ b/orphan.c
@@ -128,6 +128,7 @@ static int orphan_prepare(struct fs *fs)
        return err;
 }
 
+static void orphan_abort(struct fs *fs);
 static int orphan_pin(struct fs *fs, struct datablock *b)
 {
        struct orphan_md *om = &LAFSI(fs->orphans)->md.orphan;
@@ -149,6 +150,8 @@ 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;
@@ -192,7 +195,7 @@ static void orphan_abort(struct fs *fs)
        u32 bnum;
        struct datablock *b;
        struct orphan_md *om = &LAFSI(fs->orphans)->md.orphan;
-       mutex_lock_nested(&fs->orphans->i_mutex, I_MUTEX_QUOTA);
+
        om->reserved--;
        bnum = (om->nextfree + om->reserved) >>
                (fs->prime_sb->s_blocksize_bits-4);
@@ -212,7 +215,6 @@ static void orphan_abort(struct fs *fs)
                lafs_erase_dblock(b);
 
        putdref(b, MKREF(orphan_reserve));
-       mutex_unlock(&fs->orphans->i_mutex);
 }
 
 /* When we are about to make a change which might make a block
@@ -242,11 +244,9 @@ int lafs_make_orphan(struct fs *fs, struct datablock *db)
                lafs_checkpoint_unlock_wait(fs);
                goto retry;
        }
-       if (err)
-               orphan_abort(fs);
        /* there is no 'commit' - 'pin' did all the work */
        lafs_checkpoint_unlock(fs);
-       return 0;
+       return err;
 }
 
 /*
@@ -268,7 +268,6 @@ void lafs_orphan_release(struct fs *fs, struct datablock *b)
        struct orphan_md *om = &LAFSI(fs->orphans)->md.orphan;
        struct orphan *or, *lastor, last;
        int ent, lastent;
-       u32 bnum;
 
        if (!test_bit(B_Orphan, &b->b.flags))
                return;
@@ -395,24 +394,7 @@ void lafs_orphan_release(struct fs *fs, struct datablock *b)
        putdref(b, MKREF(orphan_list));
 
        /* Now drop the reservation we just synthesised */
-       om->reserved--;
-       bnum = (om->nextfree + om->reserved) >> (b->b.inode->i_blkbits-4);
-       b = lafs_get_block(fs->orphans, bnum, NULL, GFP_KERNEL,
-                          MKREF(orphan_release2));
-       /* Note that we now own two references to this block, one
-        * we just got and one we are trying to get rid of
-        */
-       putdref(b, MKREF(orphan_release2));
-
-       /* If this was the last block in the file,
-        * we need to punch a hole
-        */
-       if (((om->nextfree + om->reserved + 1) >> (b->b.inode->i_blkbits-4))
-           != bnum)
-               /* FIXME share code with orphan_abort */
-               lafs_erase_dblock(b);
-       putdref(b, MKREF(orphan_reserve));
-
+       orphan_abort(fs);
  out_unlock:
        mutex_unlock(&fs->orphans->i_mutex);
  out: