dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/0013-imsm-fix-reshape-for-2TB-drives.patch

5eacff
From 9f4218274cd4a1e1f356a1617f9a1d09960cf255 Mon Sep 17 00:00:00 2001
5eacff
From: Pawel Baldysiak <pawel.baldysiak@intel.com>
5eacff
Date: Mon, 28 Jan 2019 17:10:41 +0100
5eacff
Subject: [RHEL7.7 PATCH 13/24] imsm: fix reshape for >2TB drives
5eacff
5eacff
If reshape is performed on drives larger then 2 TB,
5eacff
migration checkpoint area that is calculated exeeds 32-bit value.
5eacff
This checkpoint area is a reserved space threated as backup
5eacff
during reshape - at the end of the drive, right before metadata.
5eacff
As a result - wrong space is used and the data that may exists there
5eacff
is overwritten.
5eacff
5eacff
Adding additional field to migration record to track high order 32-bits
5eacff
of pba of this area. Three other fields that may exceed 32-bit value
5eacff
for large drives are added as well.
5eacff
5eacff
Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
5eacff
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5eacff
---
5eacff
 super-intel.c | 149 +++++++++++++++++++++++++++++++++++++++++-----------------
5eacff
 1 file changed, 107 insertions(+), 42 deletions(-)
5eacff
5eacff
diff --git a/super-intel.c b/super-intel.c
5eacff
index 38a1b6c..1cc7d5f 100644
5eacff
--- a/super-intel.c
5eacff
+++ b/super-intel.c
5eacff
@@ -296,7 +296,7 @@ struct migr_record {
5eacff
 	__u32 rec_status;	    /* Status used to determine how to restart
5eacff
 				     * migration in case it aborts
5eacff
 				     * in some fashion */
5eacff
-	__u32 curr_migr_unit;	    /* 0..numMigrUnits-1 */
5eacff
+	__u32 curr_migr_unit_lo;    /* 0..numMigrUnits-1 */
5eacff
 	__u32 family_num;	    /* Family number of MPB
5eacff
 				     * containing the RaidDev
5eacff
 				     * that is migrating */
5eacff
@@ -306,16 +306,23 @@ struct migr_record {
5eacff
 	__u32 dest_depth_per_unit;  /* Num member blocks each destMap
5eacff
 				     * member disk
5eacff
 				     * advances per unit-of-operation */
5eacff
-	__u32 ckpt_area_pba;	    /* Pba of first block of ckpt copy area */
5eacff
-	__u32 dest_1st_member_lba;  /* First member lba on first
5eacff
-				     * stripe of destination */
5eacff
-	__u32 num_migr_units;	    /* Total num migration units-of-op */
5eacff
+	__u32 ckpt_area_pba_lo;	    /* Pba of first block of ckpt copy area */
5eacff
+	__u32 dest_1st_member_lba_lo;	/* First member lba on first
5eacff
+					 * stripe of destination */
5eacff
+	__u32 num_migr_units_lo;    /* Total num migration units-of-op */
5eacff
 	__u32 post_migr_vol_cap;    /* Size of volume after
5eacff
 				     * migration completes */
5eacff
 	__u32 post_migr_vol_cap_hi; /* Expansion space for LBA64 */
5eacff
 	__u32 ckpt_read_disk_num;   /* Which member disk in destSubMap[0] the
5eacff
 				     * migration ckpt record was read from
5eacff
 				     * (for recovered migrations) */
5eacff
+	__u32 curr_migr_unit_hi;    /* 0..numMigrUnits-1 high order 32 bits */
5eacff
+	__u32 ckpt_area_pba_hi;	    /* Pba of first block of ckpt copy area
5eacff
+				     * high order 32 bits */
5eacff
+	__u32 dest_1st_member_lba_hi; /* First member lba on first stripe of
5eacff
+				       * destination - high order 32 bits */
5eacff
+	__u32 num_migr_units_hi;      /* Total num migration units-of-op
5eacff
+				       * high order 32 bits */
5eacff
 } __attribute__ ((__packed__));
5eacff
 
5eacff
 struct md_list {
5eacff
@@ -1208,6 +1215,38 @@ static unsigned long long imsm_dev_size(struct imsm_dev *dev)
5eacff
 	return join_u32(dev->size_low, dev->size_high);
5eacff
 }
5eacff
 
5eacff
+static unsigned long long migr_chkp_area_pba(struct migr_record *migr_rec)
5eacff
+{
5eacff
+	if (migr_rec == NULL)
5eacff
+		return 0;
5eacff
+	return join_u32(migr_rec->ckpt_area_pba_lo,
5eacff
+			migr_rec->ckpt_area_pba_hi);
5eacff
+}
5eacff
+
5eacff
+static unsigned long long current_migr_unit(struct migr_record *migr_rec)
5eacff
+{
5eacff
+	if (migr_rec == NULL)
5eacff
+		return 0;
5eacff
+	return join_u32(migr_rec->curr_migr_unit_lo,
5eacff
+			migr_rec->curr_migr_unit_hi);
5eacff
+}
5eacff
+
5eacff
+static unsigned long long migr_dest_1st_member_lba(struct migr_record *migr_rec)
5eacff
+{
5eacff
+	if (migr_rec == NULL)
5eacff
+		return 0;
5eacff
+	return join_u32(migr_rec->dest_1st_member_lba_lo,
5eacff
+			migr_rec->dest_1st_member_lba_hi);
5eacff
+}
5eacff
+
5eacff
+static unsigned long long get_num_migr_units(struct migr_record *migr_rec)
5eacff
+{
5eacff
+	if (migr_rec == NULL)
5eacff
+		return 0;
5eacff
+	return join_u32(migr_rec->num_migr_units_lo,
5eacff
+			migr_rec->num_migr_units_hi);
5eacff
+}
5eacff
+
5eacff
 static void set_total_blocks(struct imsm_disk *disk, unsigned long long n)
5eacff
 {
5eacff
 	split_ull(n, &disk->total_blocks_lo, &disk->total_blocks_hi);
5eacff
@@ -1233,6 +1272,33 @@ static void set_imsm_dev_size(struct imsm_dev *dev, unsigned long long n)
5eacff
 	split_ull(n, &dev->size_low, &dev->size_high);
5eacff
 }
5eacff
 
5eacff
+static void set_migr_chkp_area_pba(struct migr_record *migr_rec,
5eacff
+				   unsigned long long n)
5eacff
+{
5eacff
+	split_ull(n, &migr_rec->ckpt_area_pba_lo, &migr_rec->ckpt_area_pba_hi);
5eacff
+}
5eacff
+
5eacff
+static void set_current_migr_unit(struct migr_record *migr_rec,
5eacff
+				  unsigned long long n)
5eacff
+{
5eacff
+	split_ull(n, &migr_rec->curr_migr_unit_lo,
5eacff
+		  &migr_rec->curr_migr_unit_hi);
5eacff
+}
5eacff
+
5eacff
+static void set_migr_dest_1st_member_lba(struct migr_record *migr_rec,
5eacff
+					 unsigned long long n)
5eacff
+{
5eacff
+	split_ull(n, &migr_rec->dest_1st_member_lba_lo,
5eacff
+		  &migr_rec->dest_1st_member_lba_hi);
5eacff
+}
5eacff
+
5eacff
+static void set_num_migr_units(struct migr_record *migr_rec,
5eacff
+			       unsigned long long n)
5eacff
+{
5eacff
+	split_ull(n, &migr_rec->num_migr_units_lo,
5eacff
+		  &migr_rec->num_migr_units_hi);
5eacff
+}
5eacff
+
5eacff
 static unsigned long long per_dev_array_size(struct imsm_map *map)
5eacff
 {
5eacff
 	unsigned long long array_size = 0;
5eacff
@@ -1629,12 +1695,14 @@ void convert_to_4k_imsm_migr_rec(struct intel_super *super)
5eacff
 	struct migr_record *migr_rec = super->migr_rec;
5eacff
 
5eacff
 	migr_rec->blocks_per_unit /= IMSM_4K_DIV;
5eacff
-	migr_rec->ckpt_area_pba /= IMSM_4K_DIV;
5eacff
-	migr_rec->dest_1st_member_lba /= IMSM_4K_DIV;
5eacff
 	migr_rec->dest_depth_per_unit /= IMSM_4K_DIV;
5eacff
 	split_ull((join_u32(migr_rec->post_migr_vol_cap,
5eacff
 		 migr_rec->post_migr_vol_cap_hi) / IMSM_4K_DIV),
5eacff
 		 &migr_rec->post_migr_vol_cap, &migr_rec->post_migr_vol_cap_hi);
5eacff
+	set_migr_chkp_area_pba(migr_rec,
5eacff
+		 migr_chkp_area_pba(migr_rec) / IMSM_4K_DIV);
5eacff
+	set_migr_dest_1st_member_lba(migr_rec,
5eacff
+		 migr_dest_1st_member_lba(migr_rec) / IMSM_4K_DIV);
5eacff
 }
5eacff
 
5eacff
 void convert_to_4k_imsm_disk(struct imsm_disk *disk)
5eacff
@@ -1727,8 +1795,8 @@ void examine_migr_rec_imsm(struct intel_super *super)
5eacff
 			printf("Normal\n");
5eacff
 		else
5eacff
 			printf("Contains Data\n");
5eacff
-		printf("               Current Unit : %u\n",
5eacff
-		       __le32_to_cpu(migr_rec->curr_migr_unit));
5eacff
+		printf("               Current Unit : %llu\n",
5eacff
+		       current_migr_unit(migr_rec));
5eacff
 		printf("                     Family : %u\n",
5eacff
 		       __le32_to_cpu(migr_rec->family_num));
5eacff
 		printf("                  Ascending : %u\n",
5eacff
@@ -1737,16 +1805,15 @@ void examine_migr_rec_imsm(struct intel_super *super)
5eacff
 		       __le32_to_cpu(migr_rec->blocks_per_unit));
5eacff
 		printf("       Dest. Depth Per Unit : %u\n",
5eacff
 		       __le32_to_cpu(migr_rec->dest_depth_per_unit));
5eacff
-		printf("        Checkpoint Area pba : %u\n",
5eacff
-		       __le32_to_cpu(migr_rec->ckpt_area_pba));
5eacff
-		printf("           First member lba : %u\n",
5eacff
-		       __le32_to_cpu(migr_rec->dest_1st_member_lba));
5eacff
-		printf("      Total Number of Units : %u\n",
5eacff
-		       __le32_to_cpu(migr_rec->num_migr_units));
5eacff
-		printf("             Size of volume : %u\n",
5eacff
-		       __le32_to_cpu(migr_rec->post_migr_vol_cap));
5eacff
-		printf("  Expansion space for LBA64 : %u\n",
5eacff
-		       __le32_to_cpu(migr_rec->post_migr_vol_cap_hi));
5eacff
+		printf("        Checkpoint Area pba : %llu\n",
5eacff
+		       migr_chkp_area_pba(migr_rec));
5eacff
+		printf("           First member lba : %llu\n",
5eacff
+		       migr_dest_1st_member_lba(migr_rec));
5eacff
+		printf("      Total Number of Units : %llu\n",
5eacff
+		       get_num_migr_units(migr_rec));
5eacff
+		printf("             Size of volume : %llu\n",
5eacff
+		       join_u32(migr_rec->post_migr_vol_cap,
5eacff
+				migr_rec->post_migr_vol_cap_hi));
5eacff
 		printf("       Record was read from : %u\n",
5eacff
 		       __le32_to_cpu(migr_rec->ckpt_read_disk_num));
5eacff
 
5eacff
@@ -1759,13 +1826,15 @@ void convert_from_4k_imsm_migr_rec(struct intel_super *super)
5eacff
 	struct migr_record *migr_rec = super->migr_rec;
5eacff
 
5eacff
 	migr_rec->blocks_per_unit *= IMSM_4K_DIV;
5eacff
-	migr_rec->ckpt_area_pba *= IMSM_4K_DIV;
5eacff
-	migr_rec->dest_1st_member_lba *= IMSM_4K_DIV;
5eacff
 	migr_rec->dest_depth_per_unit *= IMSM_4K_DIV;
5eacff
 	split_ull((join_u32(migr_rec->post_migr_vol_cap,
5eacff
 		 migr_rec->post_migr_vol_cap_hi) * IMSM_4K_DIV),
5eacff
 		 &migr_rec->post_migr_vol_cap,
5eacff
 		 &migr_rec->post_migr_vol_cap_hi);
5eacff
+	set_migr_chkp_area_pba(migr_rec,
5eacff
+		 migr_chkp_area_pba(migr_rec) * IMSM_4K_DIV);
5eacff
+	set_migr_dest_1st_member_lba(migr_rec,
5eacff
+		 migr_dest_1st_member_lba(migr_rec) * IMSM_4K_DIV);
5eacff
 }
5eacff
 
5eacff
 void convert_from_4k(struct intel_super *super)
5eacff
@@ -3096,7 +3165,7 @@ static int imsm_create_metadata_checkpoint_update(
5eacff
 		return 0;
5eacff
 	}
5eacff
 	(*u)->type = update_general_migration_checkpoint;
5eacff
-	(*u)->curr_migr_unit = __le32_to_cpu(super->migr_rec->curr_migr_unit);
5eacff
+	(*u)->curr_migr_unit = current_migr_unit(super->migr_rec);
5eacff
 	dprintf("prepared for %u\n", (*u)->curr_migr_unit);
5eacff
 
5eacff
 	return update_memory_size;
5eacff
@@ -3397,13 +3466,13 @@ static void getinfo_super_imsm_volume(struct supertype *st, struct mdinfo *info,
5eacff
 		case MIGR_GEN_MIGR: {
5eacff
 			__u64 blocks_per_unit = blocks_per_migr_unit(super,
5eacff
 								     dev);
5eacff
-			__u64 units = __le32_to_cpu(migr_rec->curr_migr_unit);
5eacff
+			__u64 units = current_migr_unit(migr_rec);
5eacff
 			unsigned long long array_blocks;
5eacff
 			int used_disks;
5eacff
 
5eacff
 			if (__le32_to_cpu(migr_rec->ascending_migr) &&
5eacff
 			    (units <
5eacff
-				(__le32_to_cpu(migr_rec->num_migr_units)-1)) &&
5eacff
+				(get_num_migr_units(migr_rec)-1)) &&
5eacff
 			    (super->migr_rec->rec_status ==
5eacff
 					__cpu_to_le32(UNIT_SRC_IN_CP_AREA)))
5eacff
 				units++;
5eacff
@@ -10697,7 +10766,7 @@ void init_migr_record_imsm(struct supertype *st, struct imsm_dev *dev,
5eacff
 
5eacff
 	if (array_blocks % __le32_to_cpu(migr_rec->blocks_per_unit))
5eacff
 		num_migr_units++;
5eacff
-	migr_rec->num_migr_units = __cpu_to_le32(num_migr_units);
5eacff
+	set_num_migr_units(migr_rec, num_migr_units);
5eacff
 
5eacff
 	migr_rec->post_migr_vol_cap =  dev->size_low;
5eacff
 	migr_rec->post_migr_vol_cap_hi = dev->size_high;
5eacff
@@ -10714,7 +10783,7 @@ void init_migr_record_imsm(struct supertype *st, struct imsm_dev *dev,
5eacff
 			min_dev_sectors = dev_sectors;
5eacff
 		close(fd);
5eacff
 	}
5eacff
-	migr_rec->ckpt_area_pba = __cpu_to_le32(min_dev_sectors -
5eacff
+	set_migr_chkp_area_pba(migr_rec, min_dev_sectors -
5eacff
 					RAID_DISK_RESERVED_BLOCKS_IMSM_HI);
5eacff
 
5eacff
 	write_imsm_migr_rec(st);
5eacff
@@ -10765,8 +10834,7 @@ int save_backup_imsm(struct supertype *st,
5eacff
 
5eacff
 	start = info->reshape_progress * 512;
5eacff
 	for (i = 0; i < new_disks; i++) {
5eacff
-		target_offsets[i] = (unsigned long long)
5eacff
-		  __le32_to_cpu(super->migr_rec->ckpt_area_pba) * 512;
5eacff
+		target_offsets[i] = migr_chkp_area_pba(super->migr_rec) * 512;
5eacff
 		/* move back copy area adderss, it will be moved forward
5eacff
 		 * in restore_stripes() using start input variable
5eacff
 		 */
5eacff
@@ -10845,12 +10913,11 @@ int save_checkpoint_imsm(struct supertype *st, struct mdinfo *info, int state)
5eacff
 	if (info->reshape_progress % blocks_per_unit)
5eacff
 		curr_migr_unit++;
5eacff
 
5eacff
-	super->migr_rec->curr_migr_unit =
5eacff
-		__cpu_to_le32(curr_migr_unit);
5eacff
+	set_current_migr_unit(super->migr_rec, curr_migr_unit);
5eacff
 	super->migr_rec->rec_status = __cpu_to_le32(state);
5eacff
-	super->migr_rec->dest_1st_member_lba =
5eacff
-		__cpu_to_le32(curr_migr_unit *
5eacff
-			      __le32_to_cpu(super->migr_rec->dest_depth_per_unit));
5eacff
+	set_migr_dest_1st_member_lba(super->migr_rec,
5eacff
+			super->migr_rec->dest_depth_per_unit * curr_migr_unit);
5eacff
+
5eacff
 	if (write_imsm_migr_rec(st) < 0) {
5eacff
 		dprintf("imsm: Cannot write migration record outside backup area\n");
5eacff
 		return 1;
5eacff
@@ -10884,8 +10951,8 @@ int recover_backup_imsm(struct supertype *st, struct mdinfo *info)
5eacff
 	char *buf = NULL;
5eacff
 	int retval = 1;
5eacff
 	unsigned int sector_size = super->sector_size;
5eacff
-	unsigned long curr_migr_unit = __le32_to_cpu(migr_rec->curr_migr_unit);
5eacff
-	unsigned long num_migr_units = __le32_to_cpu(migr_rec->num_migr_units);
5eacff
+	unsigned long curr_migr_unit = current_migr_unit(migr_rec);
5eacff
+	unsigned long num_migr_units = get_num_migr_units(migr_rec);
5eacff
 	char buffer[20];
5eacff
 	int skipped_disks = 0;
5eacff
 
5eacff
@@ -10912,11 +10979,9 @@ int recover_backup_imsm(struct supertype *st, struct mdinfo *info)
5eacff
 	map_dest = get_imsm_map(id->dev, MAP_0);
5eacff
 	new_disks = map_dest->num_members;
5eacff
 
5eacff
-	read_offset = (unsigned long long)
5eacff
-			__le32_to_cpu(migr_rec->ckpt_area_pba) * 512;
5eacff
+	read_offset = migr_chkp_area_pba(migr_rec) * 512;
5eacff
 
5eacff
-	write_offset = ((unsigned long long)
5eacff
-			__le32_to_cpu(migr_rec->dest_1st_member_lba) +
5eacff
+	write_offset = (migr_dest_1st_member_lba(migr_rec) +
5eacff
 			pba_of_lba0(map_dest)) * 512;
5eacff
 
5eacff
 	unit_len = __le32_to_cpu(migr_rec->dest_depth_per_unit) * 512;
5eacff
@@ -12019,12 +12084,12 @@ static int imsm_manage_reshape(
5eacff
 	max_position = sra->component_size * ndata;
5eacff
 	source_layout = imsm_level_to_layout(map_src->raid_level);
5eacff
 
5eacff
-	while (__le32_to_cpu(migr_rec->curr_migr_unit) <
5eacff
-	       __le32_to_cpu(migr_rec->num_migr_units)) {
5eacff
+	while (current_migr_unit(migr_rec) <
5eacff
+	       get_num_migr_units(migr_rec)) {
5eacff
 		/* current reshape position [blocks] */
5eacff
 		unsigned long long current_position =
5eacff
 			__le32_to_cpu(migr_rec->blocks_per_unit)
5eacff
-			* __le32_to_cpu(migr_rec->curr_migr_unit);
5eacff
+			* current_migr_unit(migr_rec);
5eacff
 		unsigned long long border;
5eacff
 
5eacff
 		/* Check that array hasn't become failed.
5eacff
-- 
5eacff
2.7.5
5eacff