dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/0023-Create-Block-rounding-size-to-max.patch

8fbece
From 22dc741f63e6403d59c2c14f56fd4791265f9bbb Mon Sep 17 00:00:00 2001
8fbece
From: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
8fbece
Date: Mon, 1 Apr 2019 16:53:41 +0200
8fbece
Subject: [RHEL7.7 PATCH 23/24] Create: Block rounding size to max
8fbece
8fbece
When passed size is smaller than chunk, mdadm rounds it to 0 but 0 there
8fbece
means max available space.
8fbece
Block it for every metadata. Remove the same check from imsm routine.
8fbece
8fbece
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
8fbece
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
8fbece
---
8fbece
 Create.c      | 23 ++++++++++++++++++++---
8fbece
 super-intel.c |  5 ++---
8fbece
 2 files changed, 22 insertions(+), 6 deletions(-)
8fbece
8fbece
diff --git a/Create.c b/Create.c
8fbece
index 6f1b228..292f92a 100644
8fbece
--- a/Create.c
8fbece
+++ b/Create.c
8fbece
@@ -27,6 +27,18 @@
8fbece
 #include	"md_p.h"
8fbece
 #include	<ctype.h>
8fbece
 
8fbece
+static int round_size_and_verify(unsigned long long *size, int chunk)
8fbece
+{
8fbece
+	if (*size == 0)
8fbece
+		return 0;
8fbece
+	*size &= ~(unsigned long long)(chunk - 1);
8fbece
+	if (*size == 0) {
8fbece
+		pr_err("Size cannot be smaller than chunk.\n");
8fbece
+		return 1;
8fbece
+	}
8fbece
+	return 0;
8fbece
+}
8fbece
+
8fbece
 static int default_layout(struct supertype *st, int level, int verbose)
8fbece
 {
8fbece
 	int layout = UnSet;
8fbece
@@ -248,11 +260,14 @@ int Create(struct supertype *st, char *mddev,
8fbece
 		pr_err("unknown level %d\n", s->level);
8fbece
 		return 1;
8fbece
 	}
8fbece
+
8fbece
 	if (s->size == MAX_SIZE)
8fbece
 		/* use '0' to mean 'max' now... */
8fbece
 		s->size = 0;
8fbece
 	if (s->size && s->chunk && s->chunk != UnSet)
8fbece
-		s->size &= ~(unsigned long long)(s->chunk - 1);
8fbece
+		if (round_size_and_verify(&s->size, s->chunk))
8fbece
+			return 1;
8fbece
+
8fbece
 	newsize = s->size * 2;
8fbece
 	if (st && ! st->ss->validate_geometry(st, s->level, s->layout, s->raiddisks,
8fbece
 					      &s->chunk, s->size*2,
8fbece
@@ -267,7 +282,8 @@ int Create(struct supertype *st, char *mddev,
8fbece
 			/* default chunk was just set */
8fbece
 			if (c->verbose > 0)
8fbece
 				pr_err("chunk size defaults to %dK\n", s->chunk);
8fbece
-			s->size &= ~(unsigned long long)(s->chunk - 1);
8fbece
+			if (round_size_and_verify(&s->size, s->chunk))
8fbece
+				return 1;
8fbece
 			do_default_chunk = 0;
8fbece
 		}
8fbece
 	}
8fbece
@@ -413,7 +429,8 @@ int Create(struct supertype *st, char *mddev,
8fbece
 				/* default chunk was just set */
8fbece
 				if (c->verbose > 0)
8fbece
 					pr_err("chunk size defaults to %dK\n", s->chunk);
8fbece
-				s->size &= ~(unsigned long long)(s->chunk - 1);
8fbece
+				if (round_size_and_verify(&s->size, s->chunk))
8fbece
+					return 1;
8fbece
 				do_default_chunk = 0;
8fbece
 			}
8fbece
 		}
8fbece
diff --git a/super-intel.c b/super-intel.c
8fbece
index 5a7c9f8..2ba045a 100644
8fbece
--- a/super-intel.c
8fbece
+++ b/super-intel.c
8fbece
@@ -7455,9 +7455,8 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout,
8fbece
 							verbose);
8fbece
 	}
8fbece
 
8fbece
-	if (size && ((size < 1024) || (*chunk != UnSet &&
8fbece
-	    size < (unsigned long long) *chunk))) {
8fbece
-		pr_err("Given size must be greater than 1M and chunk size.\n");
8fbece
+	if (size && (size < 1024)) {
8fbece
+		pr_err("Given size must be greater than 1M.\n");
8fbece
 		/* Depends on algorithm in Create.c :
8fbece
 		 * if container was given (dev == NULL) return -1,
8fbece
 		 * if block device was given ( dev != NULL) return 0.
8fbece
-- 
8fbece
2.7.5
8fbece