dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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