]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Warn the user about too small array size
authorKrzysztof Wojcik <krzysztof.wojcik@intel.com>
Mon, 14 Mar 2011 07:21:21 +0000 (18:21 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 14 Mar 2011 07:21:21 +0000 (18:21 +1100)
If single-disk RAID0 or RAID1 array is created, user may preserve data on
disk. If array given size covers all partitions on disk, all data will be
available on created array. If array size is too small (not covers
all partitions), data will be not accessible.
This patch introduces warning message during array creation if given size
is too small. User may interrupt creation process to avoid data loss.

Signed-off-by: Krzysztof Wojcik <krzysztof.wojcik@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Create.c
mdadm.h
util.c

index 2e3d7235cf1094152a1ea1892cdc8ffd80865828..6349f86538fd4cf4f6c59d10b49a70c572ece2e6 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -387,14 +387,14 @@ int Create(struct supertype *st, char *mddev,
                        if (strcmp(st->ss->name, "1.x") == 0 &&
                            st->minor_version >= 1)
                                /* metadata at front */
-                               warn |= check_partitions(fd, dname, 0);
+                               warn |= check_partitions(fd, dname, 0, 0);
                        else if (level == 1 || level == LEVEL_CONTAINER
                                    || (level == 0 && raiddisks == 1))
                                /* partitions could be meaningful */
-                               warn |= check_partitions(fd, dname, freesize*2);
+                               warn |= check_partitions(fd, dname, freesize*2, size*2);
                        else
                                /* partitions cannot be meaningful */
-                               warn |= check_partitions(fd, dname, 0);
+                               warn |= check_partitions(fd, dname, 0, 0);
                        if (strcmp(st->ss->name, "1.x") == 0 &&
                            st->minor_version >= 1 &&
                            did_default &&
diff --git a/mdadm.h b/mdadm.h
index fa84ad2719308e81e92757c4a6ead8848754088a..d3ed50a6d82e8811f5008c4ec92a2326ba1a797c 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1079,7 +1079,9 @@ extern int parse_layout_faulty(char *layout);
 extern int check_ext2(int fd, char *name);
 extern int check_reiser(int fd, char *name);
 extern int check_raid(int fd, char *name);
-extern int check_partitions(int fd, char *dname, unsigned long long freesize);
+extern int check_partitions(int fd, char *dname,
+                           unsigned long long freesize,
+                           unsigned long long size);
 
 extern int get_mdp_major(void);
 extern int dev_open(char *dev, int flags);
diff --git a/util.c b/util.c
index c22bb3bdc3148dd00fe7bdd167a901d5879b427c..cc6ccb4d25f99ae737ce65996cd3d1c71d80477a 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1370,7 +1370,8 @@ static int get_last_partition_end(int fd, unsigned long long *endofpart)
        return retval;
 }
 
-int check_partitions(int fd, char *dname, unsigned long long freesize)
+int check_partitions(int fd, char *dname, unsigned long long freesize,
+                       unsigned long long size)
 {
        /*
         * Check where the last partition ends
@@ -1393,6 +1394,12 @@ int check_partitions(int fd, char *dname, unsigned long long freesize)
                                Name ": metadata will over-write last partition on %s.\n",
                                dname);
                        return 1;
+               } else if (size && endofpart > size) {
+                       /* partitions will be truncated in new device */
+                       fprintf(stderr,
+                               Name ": array size is too small to cover all partitions on %s.\n",
+                               dname);
+                       return 1;
                }
        }
        return 0;