Skip to content

Commit

Permalink
bcache: bugfix for race between moving_gc and bucket_invalidate
Browse files Browse the repository at this point in the history
There is a possibility for a bucket to be invalidated by the allocator
while moving_gc was copying it's contents to another bucket, if the
bucket only held cached data. To prevent this moving checks for
a stale ptr (to an invalidated bucket), before and after reads.
It it finds one, it simply ignores moving that data. This only
affects bcache if the moving_gc was turned on, note that it's
off by default.

Signed-off-by: Nicholas Swenson <nks@daterainc.com>
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
  • Loading branch information
Kent Overstreet committed Dec 16, 2013
1 parent bf0a628 commit 6d3d1a9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/md/bcache/movinggc.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ static void write_moving_finish(struct closure *cl)

static void read_moving_endio(struct bio *bio, int error)
{
struct bbio *b = container_of(bio, struct bbio, bio);
struct moving_io *io = container_of(bio->bi_private,
struct moving_io, cl);

if (error)
io->op.error = error;
else if (!KEY_DIRTY(&b->key) &&
ptr_stale(io->op.c, &b->key, 0)) {
io->op.error = -EINTR;
}

bch_bbio_endio(io->op.c, bio, error, "reading data to move");
}
Expand Down Expand Up @@ -140,6 +145,11 @@ static void read_moving(struct cache_set *c)
if (!w)
break;

if (ptr_stale(c, &w->key, 0)) {
bch_keybuf_del(&c->moving_gc_keys, w);
continue;
}

io = kzalloc(sizeof(struct moving_io) + sizeof(struct bio_vec)
* DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS),
GFP_KERNEL);
Expand Down

0 comments on commit 6d3d1a9

Please sign in to comment.