]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add must_be_container helper.
authorNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)
This checks a block device to see if it could be a container, and
in particular cannot be a member device.

Signed-off-by: NeilBrown <neilb@suse.de>
Examine.c
Incremental.c
mdadm.h
util.c

index 3c1e73f9c1516349bdef1d0ed8f64ecf02a0dccf..ffca9ca5f9d615721b68db3a9af0a1d2eda57788 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -76,11 +76,10 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan,
                        err = 1;
                }
                else {
-                       unsigned long long size;
                        int container = 0;
                        if (forcest)
                                st = dup_super(forcest);
-                       else if (get_dev_size(fd, NULL, &size) == 0 || size == 0) {
+                       else if (must_be_container(fd)) {
                                /* might be a container */
                                st = super_by_fd(fd, NULL);
                                container = 1;
index 0df69b7d95bd26aaf7fde5eb118744633fd7c7d8..b7bf0b4f417d60c8736ab6a0ed10e2e7fb2a3309 100644 (file)
@@ -103,7 +103,6 @@ int Incremental(char *devname, int verbose, int runstop,
        char *name_to_use;
        mdu_array_info_t ainf;
        struct dev_policy *policy = NULL;
-       unsigned long long size;
 
        struct createinfo *ci = conf_get_create_info();
 
@@ -127,9 +126,7 @@ int Incremental(char *devname, int verbose, int runstop,
                return rv;
        }
        /* If the device is a container, we do something very different */
-       if (get_dev_size(dfd, devname, &size) == 0)
-               goto out;
-       if (size == 0) {
+       if (must_be_container(dfd)) {
                if (!st)
                        st = super_by_fd(dfd, NULL);
                if (st)
diff --git a/mdadm.h b/mdadm.h
index 6d1169b1002fbdb2bb02e52636d3f0c642abb175..13e1df9446e5b8d4699d3f2a60f435bba870bad9 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -739,6 +739,7 @@ static inline struct supertype *guess_super(int fd) {
 }
 extern struct supertype *dup_super(struct supertype *st);
 extern int get_dev_size(int fd, char *dname, unsigned long long *sizep);
+extern int must_be_container(int fd);
 extern void get_one_disk(int mdfd, mdu_array_info_t *ainf,
                         mdu_disk_info_t *disk);
 void wait_for(char *dev, int fd);
diff --git a/util.c b/util.c
index f744cdbe1ac9ba5aa33cda6c3bd998b7856599cb..ac5d8b137822583569fa415f486497b5c874a88c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1189,6 +1189,20 @@ int get_dev_size(int fd, char *dname, unsigned long long *sizep)
        return 1;
 }
 
+/* Return true if this can only be a container, not a member device.
+ * i.e. is and md device and size is zero
+ */
+int must_be_container(int fd)
+{
+       unsigned long long size;
+       if (md_get_version(fd) < 0)
+               return 0;
+       if (get_dev_size(fd, NULL, &size) == 0)
+               return 1;
+       if (size == 0)
+               return 1;
+       return 0;
+}
 
 /* Sets endofpart parameter to the last block used by the last GPT partition on the device.
  * Returns: 1 if successful