NeilBrown: Grow: be more careful when using array.size

Martin F. Krafft madduck at alioth.debian.org
Wed Jan 27 02:03:44 UTC 2010


Module: mdadm
Branch: upstream
Commit: f98841b3852ceb7fce56a6f818236a4af9b5a00a
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=f98841b3852ceb7fce56a6f818236a4af9b5a00a

Author: NeilBrown <neilb at suse.de>
Date:   Thu Nov 26 16:28:35 2009 +1100

Grow: be more careful when using array.size

As array.size is 32bit we need to prefer the 'component_size'
read from sysfs when that is available.
Grow wasn't always suitably careful.

Signed-off-by: NeilBrown <neilb at suse.de>

---

 Grow.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/Grow.c b/Grow.c
index a654d4e..d8d91cb 100644
--- a/Grow.c
+++ b/Grow.c
@@ -569,10 +569,17 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
 			goto release;
 		}
 		ioctl(fd, GET_ARRAY_INFO, &array);
+		size = get_component_size(fd);
+		if (size == 0)
+			size = array.size;
 		if (!quiet)
-			fprintf(stderr, Name ": component size of %s has been set to %dK\n",
-				devname, array.size);
+			fprintf(stderr, Name ": component size of %s has been set to %lluK\n",
+				devname, size);
 		changed = 1;
+	} else {
+		size = get_component_size(fd);
+		if (size == 0)
+			size = array.size;
 	}
 
 	/* ======= set level =========== */
@@ -844,10 +851,10 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
 
 		if (chunksize) {
 			nchunk = chunksize * 1024;
-			if (array.size % chunksize) {
-				fprintf(stderr, Name ": component size %dK is not"
+			if (size % chunksize) {
+				fprintf(stderr, Name ": component size %lluK is not"
 					" a multiple of chunksize %dK\n",
-					array.size, chunksize);
+					size, chunksize);
 				break;
 			}
 		}
@@ -891,13 +898,12 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
 		}
 
 		/* Check that we can hold all the data */
-		size = ndata * (long long)array.size;
 		get_dev_size(fd, NULL, &array_size);
-		if (size < (array_size/1024)) {
+		if (ndata * size < (array_size/1024)) {
 			fprintf(stderr, Name ": this change will reduce the size of the array.\n"
 				"       use --grow --array-size first to truncate array.\n"
 				"       e.g. mdadm --grow %s --array-size %llu\n",
-				devname, size);
+				devname, ndata * size);
 			rv = 1;
 			break;
 		}




More information about the pkg-mdadm-commits mailing list