dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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