[PATCH v8 4/4] fix origin_map - don't split a bio for the origin device if it does not have registered snapshots.

From: Sergei Shtepa
Date: Fri Apr 09 2021 - 07:48:38 EST


Signed-off-by: Sergei Shtepa <sergei.shtepa@xxxxxxxxx>
---
drivers/md/dm-snap.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 11890db71f3f..81e8e3bb6d25 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -2685,11 +2685,18 @@ static int origin_map(struct dm_target *ti, struct bio *bio)
if (bio_data_dir(bio) != WRITE)
return DM_MAPIO_REMAPPED;

- available_sectors = o->split_boundary -
- ((unsigned)bio->bi_iter.bi_sector & (o->split_boundary - 1));
+ /*
+ * If no snapshot is connected to origin, then split_boundary
+ * will be set to zero. In this case, we don't need to split a bio.
+ */
+ if (o->split_boundary) {
+ available_sectors = o->split_boundary -
+ ((unsigned int)bio->bi_iter.bi_sector &
+ (o->split_boundary - 1));

- if (bio_sectors(bio) > available_sectors)
- dm_accept_partial_bio(bio, available_sectors);
+ if (bio_sectors(bio) > available_sectors)
+ dm_accept_partial_bio(bio, available_sectors);
+ }

/* Only tell snapshots if this is a write */
return do_origin(o->dev, bio, true);
--
2.20.1