Blame SOURCES/0026-mdadm-block-update-ppl-for-non-raid456-levels.patch

c0f891
From 70f1ff4291b0388adca1f4c91918ce1175e8b360 Mon Sep 17 00:00:00 2001
c0f891
From: Lukasz Florczak <lukasz.florczak@linux.intel.com>
c0f891
Date: Wed, 15 Jun 2022 14:28:39 +0200
37f2b0
Subject: [PATCH 26/83] mdadm: block update=ppl for non raid456 levels
c0f891
c0f891
Option ppl should be used only for raid levels 4, 5 and 6. Cancel update
c0f891
for other levels.
c0f891
c0f891
Applied globally for imsm and ddf format.
c0f891
c0f891
Additionally introduce is_level456() helper function.
c0f891
c0f891
Signed-off-by: Lukasz Florczak <lukasz.florczak@linux.intel.com>
c0f891
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
c0f891
---
c0f891
 Assemble.c | 11 +++++------
c0f891
 Grow.c     |  2 +-
c0f891
 Manage.c   | 14 ++++++++++++--
c0f891
 mdadm.h    | 11 +++++++++++
c0f891
 super0.c   |  2 +-
c0f891
 super1.c   |  3 +--
c0f891
 6 files changed, 31 insertions(+), 12 deletions(-)
c0f891
c0f891
diff --git a/Assemble.c b/Assemble.c
c0f891
index 4b213560..6df6bfbc 100644
c0f891
--- a/Assemble.c
c0f891
+++ b/Assemble.c
c0f891
@@ -906,8 +906,7 @@ static int force_array(struct mdinfo *content,
c0f891
 				 * devices in RAID4 or last devices in RAID4/5/6.
c0f891
 				 */
c0f891
 				delta = devices[j].i.delta_disks;
c0f891
-				if (devices[j].i.array.level >= 4 &&
c0f891
-				    devices[j].i.array.level <= 6 &&
c0f891
+				if (is_level456(devices[j].i.array.level) &&
c0f891
 				    i/2 >= content->array.raid_disks - delta)
c0f891
 					/* OK */;
c0f891
 				else if (devices[j].i.array.level == 4 &&
c0f891
@@ -1226,8 +1225,7 @@ static int start_array(int mdfd,
c0f891
 				fprintf(stderr, ".\n");
c0f891
 			}
c0f891
 			if (content->reshape_active &&
c0f891
-			    content->array.level >= 4 &&
c0f891
-			    content->array.level <= 6) {
c0f891
+			    is_level456(content->array.level)) {
c0f891
 				/* might need to increase the size
c0f891
 				 * of the stripe cache - default is 256
c0f891
 				 */
c0f891
@@ -1974,7 +1972,8 @@ int assemble_container_content(struct supertype *st, int mdfd,
c0f891
 	int start_reshape;
c0f891
 	char *avail;
c0f891
 	int err;
c0f891
-	int is_raid456, is_clean, all_disks;
c0f891
+	int is_clean, all_disks;
c0f891
+	bool is_raid456;
c0f891
 
c0f891
 	if (sysfs_init(content, mdfd, NULL)) {
c0f891
 		pr_err("Unable to initialize sysfs\n");
c0f891
@@ -2107,7 +2106,7 @@ int assemble_container_content(struct supertype *st, int mdfd,
c0f891
 		content->array.state |= 1;
c0f891
 	}
c0f891
 
c0f891
-	is_raid456 = (content->array.level >= 4 && content->array.level <= 6);
c0f891
+	is_raid456 = is_level456(content->array.level);
c0f891
 	is_clean = content->array.state & 1;
c0f891
 
c0f891
 	if (enough(content->array.level, content->array.raid_disks,
c0f891
diff --git a/Grow.c b/Grow.c
c0f891
index f6efbc48..8c520d42 100644
c0f891
--- a/Grow.c
c0f891
+++ b/Grow.c
c0f891
@@ -2944,7 +2944,7 @@ static int impose_level(int fd, int level, char *devname, int verbose)
c0f891
 	}
c0f891
 
c0f891
 	md_get_array_info(fd, &array);
c0f891
-	if (level == 0 && (array.level >= 4 && array.level <= 6)) {
c0f891
+	if (level == 0 && is_level456(array.level)) {
c0f891
 		/* To convert to RAID0 we need to fail and
c0f891
 		 * remove any non-data devices. */
c0f891
 		int found = 0;
c0f891
diff --git a/Manage.c b/Manage.c
c0f891
index f789e0c1..e5e6abe4 100644
c0f891
--- a/Manage.c
c0f891
+++ b/Manage.c
c0f891
@@ -307,7 +307,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
c0f891
 	 *  - unfreeze reshape
c0f891
 	 *  - wait on 'sync_completed' for that point to be reached.
c0f891
 	 */
c0f891
-	if (mdi && (mdi->array.level >= 4 && mdi->array.level <= 6) &&
c0f891
+	if (mdi && is_level456(mdi->array.level) &&
c0f891
 	    sysfs_attribute_available(mdi, NULL, "sync_action") &&
c0f891
 	    sysfs_attribute_available(mdi, NULL, "reshape_direction") &&
c0f891
 	    sysfs_get_str(mdi, NULL, "sync_action", buf, 20) > 0 &&
c0f891
@@ -1679,6 +1679,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident
c0f891
 {
c0f891
 	struct supertype supertype, *st = &supertype;
c0f891
 	int fd, rv = 2;
c0f891
+	struct mdinfo *info = NULL;
c0f891
 
c0f891
 	memset(st, 0, sizeof(*st));
c0f891
 
c0f891
@@ -1696,6 +1697,13 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident
c0f891
 	if (mdmon_running(st->devnm))
c0f891
 		st->update_tail = &st->updates;
c0f891
 
c0f891
+	info = st->ss->container_content(st, subarray);
c0f891
+
c0f891
+	if (strncmp(update, "ppl", 3) == 0 && !is_level456(info->array.level)) {
c0f891
+		pr_err("RWH policy ppl is supported only for raid4, raid5 and raid6.\n");
c0f891
+		goto free_super;
c0f891
+	}
c0f891
+
c0f891
 	rv = st->ss->update_subarray(st, subarray, update, ident);
c0f891
 
c0f891
 	if (rv) {
c0f891
@@ -1711,7 +1719,9 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident
c0f891
 		pr_err("Updated subarray-%s name from %s, UUIDs may have changed\n",
c0f891
 		       subarray, dev);
c0f891
 
c0f891
- free_super:
c0f891
+free_super:
c0f891
+	if (info)
c0f891
+		free(info);
c0f891
 	st->ss->free_super(st);
c0f891
 	close(fd);
c0f891
 
c0f891
diff --git a/mdadm.h b/mdadm.h
c0f891
index d53df169..974415b9 100644
c0f891
--- a/mdadm.h
c0f891
+++ b/mdadm.h
c0f891
@@ -796,6 +796,17 @@ static inline int is_fd_valid(int fd)
c0f891
 	return (fd > -1);
c0f891
 }
c0f891
 
c0f891
+/**
c0f891
+ * is_level456() - check whether given level is between inclusive 4 and 6.
c0f891
+ * @level: level to check.
c0f891
+ *
c0f891
+ * Return: true if condition is met, false otherwise
c0f891
+ */
c0f891
+static inline bool is_level456(int level)
c0f891
+{
c0f891
+	return (level >= 4 && level <= 6);
c0f891
+}
c0f891
+
c0f891
 /**
c0f891
  * close_fd() - verify, close and unset file descriptor.
c0f891
  * @fd: pointer to file descriptor.
c0f891
diff --git a/super0.c b/super0.c
c0f891
index 61c9ec1d..37f595ed 100644
c0f891
--- a/super0.c
c0f891
+++ b/super0.c
c0f891
@@ -683,7 +683,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
c0f891
 			int parity = sb->level == 6 ? 2 : 1;
c0f891
 			rv = 0;
c0f891
 
c0f891
-			if (sb->level >= 4 && sb->level <= 6 &&
c0f891
+			if (is_level456(sb->level) &&
c0f891
 			    sb->reshape_position % (
c0f891
 				    sb->new_chunk/512 *
c0f891
 				    (sb->raid_disks - sb->delta_disks - parity))) {
c0f891
diff --git a/super1.c b/super1.c
c0f891
index 3a0c69fd..71af860c 100644
c0f891
--- a/super1.c
c0f891
+++ b/super1.c
c0f891
@@ -1530,8 +1530,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
c0f891
 			 * So we reject a revert-reshape unless the
c0f891
 			 * alignment is good.
c0f891
 			 */
c0f891
-			if (__le32_to_cpu(sb->level) >= 4 &&
c0f891
-			    __le32_to_cpu(sb->level) <= 6) {
c0f891
+			if (is_level456(__le32_to_cpu(sb->level))) {
c0f891
 				reshape_sectors =
c0f891
 					__le64_to_cpu(sb->reshape_position);
c0f891
 				reshape_chunk = __le32_to_cpu(sb->new_chunk);
c0f891
-- 
37f2b0
2.38.1
c0f891