[Devel] [PATCH RH8] ploop: Zero tail of tail page

Kirill Tkhai ktkhai at virtuozzo.com
Thu Dec 10 14:52:24 MSK 2020


In case of BAT ends in middle of page, zero its tail.
Otherwise, garbage is there.

https://jira.sw.ru/browse/PSBM-123639
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c |    5 +++++
 drivers/md/dm-ploop.h     |    1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index d6b687806118..da18dd2e4638 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -168,6 +168,11 @@ static int ploop_read_bat(struct ploop *ploop, struct bio *bio)
 			from = kmap(bio->bi_io_vec[page].bv_page);
 			memcpy(to, from, nr_copy * sizeof(map_index_t));
 			kunmap(bio->bi_io_vec[page].bv_page);
+			if (unlikely(nr_copy < BAT_ENTRIES_PER_PAGE)) {
+				memset(from + nr_copy, 0, sizeof(map_index_t) *
+				       (BAT_ENTRIES_PER_PAGE - nr_copy));
+			}
+
 			ret = parse_bat_entries(ploop, to, md->bat_levels,
 						nr_copy, id);
 			kunmap(md->page);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index dc5362f01e21..a025df4bf328 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -6,6 +6,7 @@
 
 #define PLOOP_MAP_OFFSET 16
 typedef u32 map_index_t;
+#define BAT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(map_index_t))
 
 #define SIGNATURE_DISK_IN_USE           0x746F6E59
 




More information about the Devel mailing list