Skip to content

Commit 3ee2548

Browse files
committed
dm snapshot: fix oversights in optional discard support
__find_snapshots_sharing_cow() should always be used with _origins_lock held so fix snapshot_io_hints() accordingly. Also, once a snapshot is being merged discards must not be allowed -- otherwise incorrect or duplicate work will be performed. Fixes: 2e60238 ("dm snapshot: add optional discard support features") Reported-by: Nikos Tsironis <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 3b8cafd commit 3ee2548

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/md/dm-snap.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,12 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio)
20722072
return DM_MAPIO_REMAPPED;
20732073
}
20742074

2075+
if (unlikely(bio_op(bio) == REQ_OP_DISCARD)) {
2076+
/* Once merging, discards no longer effect change */
2077+
bio_endio(bio);
2078+
return DM_MAPIO_SUBMITTED;
2079+
}
2080+
20752081
chunk = sector_to_chunk(s->store, bio->bi_iter.bi_sector);
20762082

20772083
down_write(&s->lock);
@@ -2331,13 +2337,17 @@ static void snapshot_io_hints(struct dm_target *ti, struct queue_limits *limits)
23312337
if (snap->discard_zeroes_cow) {
23322338
struct dm_snapshot *snap_src = NULL, *snap_dest = NULL;
23332339

2340+
down_read(&_origins_lock);
2341+
23342342
(void) __find_snapshots_sharing_cow(snap, &snap_src, &snap_dest, NULL);
23352343
if (snap_src && snap_dest)
23362344
snap = snap_src;
23372345

23382346
/* All discards are split on chunk_size boundary */
23392347
limits->discard_granularity = snap->store->chunk_size;
23402348
limits->max_discard_sectors = snap->store->chunk_size;
2349+
2350+
up_read(&_origins_lock);
23412351
}
23422352
}
23432353

0 commit comments

Comments
 (0)