Commit c6621392 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Alasdair G Kergon

dm snapshot: avoid dropping lock in __find_pending_exception

It is uncommon and bug-prone to drop a lock in a function that is called with
the lock held, so this is moved to the caller.

Cc: stable@kernel.org
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 2913808e
...@@ -992,23 +992,10 @@ __lookup_pending_exception(struct dm_snapshot *s, chunk_t chunk) ...@@ -992,23 +992,10 @@ __lookup_pending_exception(struct dm_snapshot *s, chunk_t chunk)
* this. * this.
*/ */
static struct dm_snap_pending_exception * static struct dm_snap_pending_exception *
__find_pending_exception(struct dm_snapshot *s, struct bio *bio) __find_pending_exception(struct dm_snapshot *s,
struct dm_snap_pending_exception *pe, chunk_t chunk)
{ {
struct dm_snap_pending_exception *pe, *pe2; struct dm_snap_pending_exception *pe2;
chunk_t chunk = sector_to_chunk(s, bio->bi_sector);
/*
* Create a new pending exception, we don't want
* to hold the lock while we do this.
*/
up_write(&s->lock);
pe = alloc_pending_exception(s);
down_write(&s->lock);
if (!s->valid) {
free_pending_exception(pe);
return NULL;
}
pe2 = __lookup_pending_exception(s, chunk); pe2 = __lookup_pending_exception(s, chunk);
if (pe2) { if (pe2) {
...@@ -1083,7 +1070,17 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio, ...@@ -1083,7 +1070,17 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
if (bio_rw(bio) == WRITE) { if (bio_rw(bio) == WRITE) {
pe = __lookup_pending_exception(s, chunk); pe = __lookup_pending_exception(s, chunk);
if (!pe) { if (!pe) {
pe = __find_pending_exception(s, bio); up_write(&s->lock);
pe = alloc_pending_exception(s);
down_write(&s->lock);
if (!s->valid) {
free_pending_exception(pe);
r = -EIO;
goto out_unlock;
}
pe = __find_pending_exception(s, pe, chunk);
if (!pe) { if (!pe) {
__invalidate_snapshot(s, -ENOMEM); __invalidate_snapshot(s, -ENOMEM);
r = -EIO; r = -EIO;
...@@ -1220,7 +1217,16 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio) ...@@ -1220,7 +1217,16 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
pe = __lookup_pending_exception(snap, chunk); pe = __lookup_pending_exception(snap, chunk);
if (!pe) { if (!pe) {
pe = __find_pending_exception(snap, bio); up_write(&snap->lock);
pe = alloc_pending_exception(snap);
down_write(&snap->lock);
if (!snap->valid) {
free_pending_exception(pe);
goto next_snapshot;
}
pe = __find_pending_exception(snap, pe, chunk);
if (!pe) { if (!pe) {
__invalidate_snapshot(snap, -ENOMEM); __invalidate_snapshot(snap, -ENOMEM);
goto next_snapshot; goto next_snapshot;
......
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