ANDROID: dm-bow: ignore discard in CHECKPOINT state In the CHECKPOINT state, the original driver behavior was to pass discard requests through to the underlying device. This creates a severe data integrity issue, as it could physically erase data in ranges the driver considers `UNCHANGED` and is actively protecting. This pass-through behavior causes the driver's internal state map to become desynchronized from the actual physical state of the storage, undermining the purpose of the checkpoint. This commit modifies the I/O mapping logic in `dm_bow_map` to intercept discard requests received during the CHECKPOINT state. Instead of passing the request down, the driver now immediately completes the `bio` with a success status (`bio_endio`) and returns `DM_MAPIO_SUBMITTED`. This effectively and safely ignores the discard, preventing the unintended erasure of protected data and ensuring the checkpoint's integrity is maintained. Bug: 463896763 Bug: 433815205 Change-Id: Ic534f9729bd6bf73df41c2952853c75cee3b5c96 (cherry picked from commit a4a94617e6941915942489956fdc8a1bf2cc4729) Signed-off-by: Lianwei Wang <lianwei.wang@gm.com>
diff --git a/drivers/md/dm-bow.c b/drivers/md/dm-bow.c index 6ce39fa..9fa79b6 100644 --- a/drivers/md/dm-bow.c +++ b/drivers/md/dm-bow.c
@@ -1163,7 +1163,16 @@ static int dm_bow_map(struct dm_target *ti, struct bio *bio) } else if (state == CHECKPOINT) { if (bio->bi_iter.bi_sector == 0) ret = handle_sector0(bc, bio); - else if (bio_data_dir(bio) == WRITE) + else if (bio_op(bio) == REQ_OP_DISCARD) { + /* + * Ignore discard requests in CHECKPOINT state. + * Passing them through would physically erase data that we + * are trying to protect, creating a state mismatch. + * We complete the bio with success and stop processing. + */ + bio_endio(bio); + ret = DM_MAPIO_SUBMITTED; + } else if (bio_data_dir(bio) == WRITE) ret = queue_write(bc, bio); /* else pass-through */ }