dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/super1add-support-for-multiple-ppls.patch

b7f731
From fa601c2e897adfb3d2316377354269ffdeb824c3 Mon Sep 17 00:00:00 2001
b7f731
From: Pawel Baldysiak <pawel.baldysiak@intel.com>
b7f731
Date: Thu, 28 Sep 2017 14:41:08 +0200
b7f731
Subject: [PATCH 02/12] super1: Add support for multiple-ppls
b7f731
b7f731
Add support for super1 with multiple ppls. Extend ppl area size to 1MB.
b7f731
Use 1MB as default during creation. Always start array as single ppl -
b7f731
if kernel is capable of multiple ppls and there is enough space reserved -
b7f731
it will switch the policy during first metadata update.
b7f731
b7f731
Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
b7f731
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
b7f731
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
b7f731
---
b7f731
 super1.c | 65 ++++++++++++++++++++++++++++++++++++----------------------------
b7f731
 1 file changed, 37 insertions(+), 28 deletions(-)
b7f731
b7f731
diff --git a/super1.c b/super1.c
b7f731
index 3cfbbc0..f80e38a 100644
b7f731
--- a/super1.c
b7f731
+++ b/super1.c
b7f731
@@ -121,6 +121,9 @@ struct misc_dev_info {
b7f731
 	__u64 device_size;
b7f731
 };
b7f731
 
b7f731
+#define MULTIPLE_PPL_AREA_SIZE_SUPER1 (1024 * 1024) /* Size of the whole
b7f731
+						     * mutliple PPL area
b7f731
+						     */
b7f731
 /* feature_map bits */
b7f731
 #define MD_FEATURE_BITMAP_OFFSET	1
b7f731
 #define	MD_FEATURE_RECOVERY_OFFSET	2 /* recovery_offset is present and
b7f731
@@ -140,6 +143,7 @@ struct misc_dev_info {
b7f731
 #define	MD_FEATURE_BITMAP_VERSIONED	256 /* bitmap version number checked properly */
b7f731
 #define	MD_FEATURE_JOURNAL		512 /* support write journal */
b7f731
 #define	MD_FEATURE_PPL			1024 /* support PPL */
b7f731
+#define	MD_FEATURE_MUTLIPLE_PPLS	2048 /* support for multiple PPLs */
b7f731
 #define	MD_FEATURE_ALL			(MD_FEATURE_BITMAP_OFFSET	\
b7f731
 					|MD_FEATURE_RECOVERY_OFFSET	\
b7f731
 					|MD_FEATURE_RESHAPE_ACTIVE	\
b7f731
@@ -150,6 +154,7 @@ struct misc_dev_info {
b7f731
 					|MD_FEATURE_BITMAP_VERSIONED	\
b7f731
 					|MD_FEATURE_JOURNAL		\
b7f731
 					|MD_FEATURE_PPL			\
b7f731
+					|MD_FEATURE_MULTIPLE_PPLS	\
b7f731
 					)
b7f731
 
b7f731
 static int role_from_sb(struct mdp_superblock_1 *sb)
b7f731
@@ -298,6 +303,12 @@ static int awrite(struct align_fd *afd, void *buf, int len)
b7f731
 	return len;
b7f731
 }
b7f731
 
b7f731
+static inline unsigned int md_feature_any_ppl_on(__u32 feature_map)
b7f731
+{
b7f731
+	return ((__cpu_to_le32(feature_map) &
b7f731
+	    (MD_FEATURE_PPL | MD_FEATURE_MUTLIPLE_PPLS)));
b7f731
+}
b7f731
+
b7f731
 static inline unsigned int choose_ppl_space(int chunk)
b7f731
 {
b7f731
 	return (PPL_HEADER_SIZE >> 9) + (chunk > 128*2 ? chunk : 128*2);
b7f731
@@ -409,7 +420,7 @@ static void examine_super1(struct supertype *st, char *homehost)
b7f731
 	if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BITMAP_OFFSET)) {
b7f731
 		printf("Internal Bitmap : %ld sectors from superblock\n",
b7f731
 		       (long)(int32_t)__le32_to_cpu(sb->bitmap_offset));
b7f731
-	} else if (sb->feature_map & __cpu_to_le32(MD_FEATURE_PPL)) {
b7f731
+	} else if (md_feature_any_ppl_on(sb->feature_map)) {
b7f731
 		printf("            PPL : %u sectors at offset %d sectors from superblock\n",
b7f731
 		       __le16_to_cpu(sb->ppl.size),
b7f731
 		       __le16_to_cpu(sb->ppl.offset));
b7f731
@@ -985,7 +996,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map)
b7f731
 		info->bitmap_offset = (int32_t)__le32_to_cpu(sb->bitmap_offset);
b7f731
 		if (__le32_to_cpu(bsb->nodes) > 1)
b7f731
 			info->array.state |= (1 << MD_SB_CLUSTERED);
b7f731
-	} else if (sb->feature_map & __le32_to_cpu(MD_FEATURE_PPL)) {
b7f731
+	} else if (md_feature_any_ppl_on(sb->feature_map)) {
b7f731
 		info->ppl_offset = __le16_to_cpu(sb->ppl.offset);
b7f731
 		info->ppl_size = __le16_to_cpu(sb->ppl.size);
b7f731
 		info->ppl_sector = super_offset + info->ppl_offset;
b7f731
@@ -1140,7 +1151,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map)
b7f731
 	if (sb->feature_map & __le32_to_cpu(MD_FEATURE_JOURNAL)) {
b7f731
 		info->journal_device_required = 1;
b7f731
 		info->consistency_policy = CONSISTENCY_POLICY_JOURNAL;
b7f731
-	} else if (sb->feature_map & __le32_to_cpu(MD_FEATURE_PPL)) {
b7f731
+	} else if (md_feature_any_ppl_on(sb->feature_map)) {
b7f731
 		info->consistency_policy = CONSISTENCY_POLICY_PPL;
b7f731
 	} else if (sb->feature_map & __le32_to_cpu(MD_FEATURE_BITMAP_OFFSET)) {
b7f731
 		info->consistency_policy = CONSISTENCY_POLICY_BITMAP;
b7f731
@@ -1324,7 +1335,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
b7f731
 		if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BITMAP_OFFSET)) {
b7f731
 			bitmap_offset = (long)__le32_to_cpu(sb->bitmap_offset);
b7f731
 			bm_sectors = calc_bitmap_size(bms, 4096) >> 9;
b7f731
-		} else if (sb->feature_map & __cpu_to_le32(MD_FEATURE_PPL)) {
b7f731
+		} else if (md_feature_any_ppl_on(sb->feature_map)) {
b7f731
 			bitmap_offset = (long)__le16_to_cpu(sb->ppl.offset);
b7f731
 			bm_sectors = (long)__le16_to_cpu(sb->ppl.size);
b7f731
 		}
b7f731
@@ -1377,7 +1388,6 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
b7f731
 		unsigned long long data_size = __le64_to_cpu(sb->data_size);
b7f731
 		long bb_offset = __le32_to_cpu(sb->bblog_offset);
b7f731
 		int space;
b7f731
-		int optimal_space;
b7f731
 		int offset;
b7f731
 
b7f731
 		if (sb->feature_map & __cpu_to_le32(MD_FEATURE_BITMAP_OFFSET)) {
b7f731
@@ -1408,18 +1418,23 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
b7f731
 			return -2;
b7f731
 		}
b7f731
 
b7f731
-		optimal_space = choose_ppl_space(__le32_to_cpu(sb->chunksize));
b7f731
-
b7f731
-		if (space > optimal_space)
b7f731
-			space = optimal_space;
b7f731
-		if (space > UINT16_MAX)
b7f731
-			space = UINT16_MAX;
b7f731
+		if (space >= (MULTIPLE_PPL_AREA_SIZE_SUPER1 >> 9)) {
b7f731
+			space = (MULTIPLE_PPL_AREA_SIZE_SUPER1 >> 9);
b7f731
+		} else {
b7f731
+			int optimal_space = choose_ppl_space(
b7f731
+						__le32_to_cpu(sb->chunksize));
b7f731
+			if (space > optimal_space)
b7f731
+				space = optimal_space;
b7f731
+			if (space > UINT16_MAX)
b7f731
+				space = UINT16_MAX;
b7f731
+		}
b7f731
 
b7f731
 		sb->ppl.offset = __cpu_to_le16(offset);
b7f731
 		sb->ppl.size = __cpu_to_le16(space);
b7f731
 		sb->feature_map |= __cpu_to_le32(MD_FEATURE_PPL);
b7f731
 	} else if (strcmp(update, "no-ppl") == 0) {
b7f731
-		sb->feature_map &= ~ __cpu_to_le32(MD_FEATURE_PPL);
b7f731
+		sb->feature_map &= ~__cpu_to_le32(MD_FEATURE_PPL |
b7f731
+						   MD_FEATURE_MUTLIPLE_PPLS);
b7f731
 	} else if (strcmp(update, "name") == 0) {
b7f731
 		if (info->name[0] == 0)
b7f731
 			sprintf(info->name, "%d", info->array.md_minor);
b7f731
@@ -1974,20 +1989,12 @@ static int write_init_super1(struct supertype *st)
b7f731
 					(((char *)sb) + MAX_SB_SIZE);
b7f731
 			bm_space = calc_bitmap_size(bms, 4096) >> 9;
b7f731
 			bm_offset = (long)__le32_to_cpu(sb->bitmap_offset);
b7f731
-		} else if (sb->feature_map & __cpu_to_le32(MD_FEATURE_PPL)) {
b7f731
-			bm_space =
b7f731
-			  choose_ppl_space(__le32_to_cpu(sb->chunksize));
b7f731
-			if (bm_space > UINT16_MAX)
b7f731
-				bm_space = UINT16_MAX;
b7f731
-			if (st->minor_version == 0) {
b7f731
+		} else if (md_feature_any_ppl_on(sb->feature_map)) {
b7f731
+			bm_space = MULTIPLE_PPL_AREA_SIZE_SUPER1 >> 9;
b7f731
+			if (st->minor_version == 0)
b7f731
 				bm_offset = -bm_space - 8;
b7f731
-				if (bm_offset < INT16_MIN) {
b7f731
-					bm_offset = INT16_MIN;
b7f731
-					bm_space = -bm_offset - 8;
b7f731
-				}
b7f731
-			} else {
b7f731
+			else
b7f731
 				bm_offset = 8;
b7f731
-			}
b7f731
 			sb->ppl.offset = __cpu_to_le16(bm_offset);
b7f731
 			sb->ppl.size = __cpu_to_le16(bm_space);
b7f731
 		} else {
b7f731
@@ -2069,7 +2076,7 @@ static int write_init_super1(struct supertype *st)
b7f731
 		     MD_FEATURE_BITMAP_OFFSET)) {
b7f731
 			rv = st->ss->write_bitmap(st, di->fd, NodeNumUpdate);
b7f731
 		} else if (rv == 0 &&
b7f731
-			 (__le32_to_cpu(sb->feature_map) & MD_FEATURE_PPL)) {
b7f731
+		    md_feature_any_ppl_on(sb->feature_map)) {
b7f731
 			struct mdinfo info;
b7f731
 
b7f731
 			st->ss->getinfo_super(st, &info, NULL);
b7f731
@@ -2345,7 +2352,7 @@ static __u64 avail_size1(struct supertype *st, __u64 devsize,
b7f731
 		struct bitmap_super_s *bsb;
b7f731
 		bsb = (struct bitmap_super_s *)(((char*)super)+MAX_SB_SIZE);
b7f731
 		bmspace = calc_bitmap_size(bsb, 4096) >> 9;
b7f731
-	} else if (__le32_to_cpu(super->feature_map) & MD_FEATURE_PPL) {
b7f731
+	} else if (md_feature_any_ppl_on(super->feature_map)) {
b7f731
 		bmspace = __le16_to_cpu(super->ppl.size);
b7f731
 	}
b7f731
 
b7f731
@@ -2769,8 +2776,10 @@ static int validate_geometry1(struct supertype *st, int level,
b7f731
 	}
b7f731
 
b7f731
 	/* creating:  allow suitable space for bitmap or PPL */
b7f731
-	bmspace = consistency_policy == CONSISTENCY_POLICY_PPL ?
b7f731
-		  choose_ppl_space((*chunk)*2) : choose_bm_space(devsize);
b7f731
+	if (consistency_policy == CONSISTENCY_POLICY_PPL)
b7f731
+		bmspace = MULTIPLE_PPL_AREA_SIZE_SUPER1 >> 9;
b7f731
+	else
b7f731
+		bmspace = choose_bm_space(devsize);
b7f731
 
b7f731
 	if (data_offset == INVALID_SECTORS)
b7f731
 		data_offset = st->data_offset;
b7f731
-- 
b7f731
2.7.4
b7f731