dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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