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

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