]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
UBIFS: TNC / GC race fixes
authorAdrian Hunter <ext-adrian.hunter@nokia.com>
Fri, 12 Sep 2008 09:27:47 +0000 (12:27 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 17 Sep 2008 11:23:26 +0000 (14:23 +0300)
- update GC sequence number if any nodes may have been moved
even if GC did not finish the LEB
- don't ignore error return when reading

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
fs/ubifs/gc.c
fs/ubifs/tnc.c

index 13f1019c859f254bed9ee9512007b50ee79274da..02aba36fe3d4994ac6dbdba97d0705371cd8bf21 100644 (file)
@@ -334,15 +334,15 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
 
                err = move_nodes(c, sleb);
                if (err)
-                       goto out;
+                       goto out_inc_seq;
 
                err = gc_sync_wbufs(c);
                if (err)
-                       goto out;
+                       goto out_inc_seq;
 
                err = ubifs_change_one_lp(c, lnum, c->leb_size, 0, 0, 0, 0);
                if (err)
-                       goto out;
+                       goto out_inc_seq;
 
                /* Allow for races with TNC */
                c->gced_lnum = lnum;
@@ -369,6 +369,14 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
 out:
        ubifs_scan_destroy(sleb);
        return err;
+
+out_inc_seq:
+       /* We may have moved at least some nodes so allow for races with TNC */
+       c->gced_lnum = lnum;
+       smp_wmb();
+       c->gc_seq += 1;
+       smp_wmb();
+       goto out;
 }
 
 /**
index 7da209ab93788f8cafb30d6532b946897d9ae384..7634c5970887960a9555e82757bf11ffe704a5f3 100644 (file)
@@ -1476,7 +1476,7 @@ again:
        }
 
        err = fallible_read_node(c, key, &zbr, node);
-       if (maybe_leb_gced(c, zbr.lnum, gc_seq1)) {
+       if (err <= 0 || maybe_leb_gced(c, zbr.lnum, gc_seq1)) {
                /*
                 * The node may have been GC'ed out from under us so try again
                 * while keeping the TNC mutex locked.