Commit da27b481 authored by Nikos Tsironis's avatar Nikos Tsironis Committed by Greg Kroah-Hartman
Browse files

dm era: Update in-core bitset after committing the metadata

commit 2099b145 upstream.

In case of a system crash, dm-era might fail to mark blocks as written
in its metadata, although the corresponding writes to these blocks were
passed down to the origin device and completed successfully.

Consider the following sequence of events:

1. We write to a block that has not been yet written in the current era
2. era_map() checks the in-core bitmap for the current era and sees
   that the block is not marked as written.
3. The write is deferred for submission after the metadata have been
   updated and committed.
4. The worker thread processes the deferred write
   (process_deferred_bios()) and marks the block as written in the
   in-core bitmap, **before** committing the metadata.
5. The worker thread starts committing the metadata.
6. We do more writes that map to the same block as the write of step (1)
7. era_map() checks the in-core bitmap and sees that the block is marked
   as written, **although the metadata have not been committed yet**.
8. These writes are passed down to the origin device immediately and the
   device reports them as completed.
9. The system crashes, e.g., power failure, before the commit from step
   (5) finishes.

When the system recovers and we query the dm-era target for the list of
written blocks it doesn't report the aforementioned block as written,
although the writes of step (6) completed successfully.

The issue is that era_map() decides whether to defer or not a write
based on non committed information. The root cause of the bug is that we
update the in-core bitmap, **before** committing the metadata.

Fix this by updating the in-core bitmap **after** successfully
committing the metadata.

Fixes: eec40579

 ("dm: add era target")
Cc: # v3.15+
Signed-off-by: default avatarNikos Tsironis <>
Signed-off-by: Mike Snitzer's avatarMike Snitzer <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent a586531f
......@@ -134,7 +134,7 @@ static int writeset_test_and_set(struct dm_disk_bitset *info,
int r;
if (!test_and_set_bit(block, ws->bits)) {
if (!test_bit(block, ws->bits)) {
r = dm_bitset_set_bit(info, ws->md.root, block, &ws->md.root);
if (r) {
/* FIXME: fail mode */
......@@ -1226,8 +1226,10 @@ static void process_deferred_bios(struct era *era)
int r;
struct bio_list deferred_bios, marked_bios;
struct bio *bio;
struct blk_plug plug;
bool commit_needed = false;
bool failed = false;
struct writeset *ws = era->md->current_writeset;
......@@ -1237,9 +1239,11 @@ static void process_deferred_bios(struct era *era)
if (bio_list_empty(&deferred_bios))
while ((bio = bio_list_pop(&deferred_bios))) {
r = writeset_test_and_set(&era->md->bitset_info,
r = writeset_test_and_set(&era->md->bitset_info, ws,
get_block(era, bio));
if (r < 0) {
......@@ -1247,7 +1251,6 @@ static void process_deferred_bios(struct era *era)
* FIXME: finish.
failed = true;
} else if (r == 0)
commit_needed = true;
......@@ -1263,9 +1266,19 @@ static void process_deferred_bios(struct era *era)
if (failed)
while ((bio = bio_list_pop(&marked_bios)))
while ((bio = bio_list_pop(&marked_bios)))
else {
while ((bio = bio_list_pop(&marked_bios))) {
* Only update the in-core writeset if the on-disk one
* was updated too.
if (commit_needed)
set_bit(get_block(era, bio), ws->bits);
static void process_rpc_calls(struct era *era)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment