Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6dcfac4f authored by Adrian Hunter's avatar Adrian Hunter Committed by Artem Bityutskiy
Browse files

UBIFS: TNC / GC race fixes



- 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: default avatarAdrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 0855f310
Loading
Loading
Loading
Loading
+11 −3
Original line number Original line Diff line number Diff line
@@ -334,15 +334,15 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)


		err = move_nodes(c, sleb);
		err = move_nodes(c, sleb);
		if (err)
		if (err)
			goto out;
			goto out_inc_seq;


		err = gc_sync_wbufs(c);
		err = gc_sync_wbufs(c);
		if (err)
		if (err)
			goto out;
			goto out_inc_seq;


		err = ubifs_change_one_lp(c, lnum, c->leb_size, 0, 0, 0, 0);
		err = ubifs_change_one_lp(c, lnum, c->leb_size, 0, 0, 0, 0);
		if (err)
		if (err)
			goto out;
			goto out_inc_seq;


		/* Allow for races with TNC */
		/* Allow for races with TNC */
		c->gced_lnum = lnum;
		c->gced_lnum = lnum;
@@ -369,6 +369,14 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
out:
out:
	ubifs_scan_destroy(sleb);
	ubifs_scan_destroy(sleb);
	return err;
	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;
}
}


/**
/**
+1 −1
Original line number Original line Diff line number Diff line
@@ -1476,7 +1476,7 @@ int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
	}
	}


	err = fallible_read_node(c, key, &zbr, node);
	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
		 * The node may have been GC'ed out from under us so try again
		 * while keeping the TNC mutex locked.
		 * while keeping the TNC mutex locked.