Skip to content

Commit

Permalink
dm snapshot: avoid having two exceptions for the same chunk
Browse files Browse the repository at this point in the history
We need to check if the exception was completed after dropping the lock.

After regaining the lock, __find_pending_exception checks if the exception
was already placed into &s->pending hash.

But we don't check if the exception was already completed and placed into
&s->complete hash. If the process waiting in alloc_pending_exception was
delayed at this point because of a scheduling latency and the exception
was meanwhile completed, we'd miss that and allocate another pending
exception for already completed chunk.

It would lead to a situation where two records for the same chunk exist
and potential data corruption because multiple snapshot I/Os to the
affected chunk could be redirected to different locations in the
snapshot.

Cc: stable@kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
  • Loading branch information
Mikulas Patocka authored and Alasdair G Kergon committed Apr 2, 2009
1 parent c662139 commit 35bf659
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions drivers/md/dm-snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,13 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
goto out_unlock;
}

e = lookup_exception(&s->complete, chunk);
if (e) {
free_pending_exception(pe);
remap_exception(s, e, bio, chunk);
goto out_unlock;
}

pe = __find_pending_exception(s, pe, chunk);
if (!pe) {
__invalidate_snapshot(s, -ENOMEM);
Expand Down Expand Up @@ -1226,6 +1233,12 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
goto next_snapshot;
}

e = lookup_exception(&snap->complete, chunk);
if (e) {
free_pending_exception(pe);
goto next_snapshot;
}

pe = __find_pending_exception(snap, pe, chunk);
if (!pe) {
__invalidate_snapshot(snap, -ENOMEM);
Expand Down

0 comments on commit 35bf659

Please sign in to comment.