Skip to contentSkip to conversation

dm-raid: add merge method to target

PATCH [email protected] 1 participant 1 message May 15, 2015 Device mapper

lore
Share & tools
lore
#0 lore raw

From: Heinz Mauelshagen <[email protected]>

Patch series
"[PATCH v2 0/4] dm-raid: Add support for the MD RAID0 personality" is missing a merge function which can lead to data corruption on read ahead.

This patch introduces it
It inquires the MD raid0 personalities mergeable_bvec to make sure, that read ahead payload gets limited properly.

The problem did not occur with the other raid levels, because it either did not apply without striping or got avoided via stripe caching.

---
 drivers/md/dm-raid.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/md/dm-raid.c +19 -0
index 97e1651..06f9d63 100644
@@ -1717,6 +1717,24 @@ static void raid_resume(struct dm_target *ti)
 	mddev_resume(&rs->md);
 }
 
+static int raid_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
+		      struct bio_vec *biovec, int max_size)
+{
+	struct raid_set *rs = ti->private;
+	struct md_personality *pers = rs->md.pers;
+
+	if (pers && pers->mergeable_bvec)
+		return min(max_size, pers->mergeable_bvec(&rs->md, bvm, biovec));
+
+	/*
+	 * In case we can't request the personality because
+	 * the raid set is not running yet
+	 *
+	 * -> return safe minimum
+	 */
+	return rs->md.chunk_sectors;
+}
+
 static struct target_type raid_target = {
 	.name = "raid",
 	.version = {1, 7, 0},
@@ -1731,6 +1749,7 @@ static struct target_type raid_target = {
 	.presuspend = raid_presuspend,
 	.postsuspend = raid_postsuspend,
 	.resume = raid_resume,
+	.merge = raid_merge
 };
 
 static int __init dm_raid_init(void)
Signature · 1 line
2.1.0