dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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