]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Switch open_subarray to use the new load_container
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index b965c8d7883ddae9d8f7ec66a978fcf7374f59ed..f744cdbe1ac9ba5aa33cda6c3bd998b7856599cb 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1032,7 +1032,7 @@ struct superswitch *superlist[] =
 
 #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
 
-struct supertype *super_by_fd(int fd)
+struct supertype *super_by_fd(int fd, char **subarrayp)
 {
        mdu_array_info_t array;
        int vers;
@@ -1086,13 +1086,10 @@ struct supertype *super_by_fd(int fd)
                sysfs_free(sra);
        if (st) {
                st->sb = NULL;
-               if (subarray) {
-                       strncpy(st->subarray, subarray, 32);
-                       st->subarray[31] = 0;
-                       free(subarray);
-               } else
-                       st->subarray[0] = 0;
-       }
+               if (subarrayp)
+                       *subarrayp = subarray;
+       } else
+               free(subarray);
        return st;
 }
 #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
@@ -1111,7 +1108,6 @@ struct supertype *dup_super(struct supertype *orig)
        st->ss = orig->ss;
        st->max_devs = orig->max_devs;
        st->minor_version = orig->minor_version;
-       strcpy(st->subarray, orig->subarray);
        st->sb = NULL;
        st->info = NULL;
        return st;
@@ -1129,6 +1125,9 @@ struct supertype *guess_super_type(int fd, enum guess_types guess_type)
        int i;
 
        st = malloc(sizeof(*st));
+       memset(st, 0, sizeof(*st));
+       st->container_dev = NoMdDev;
+
        for (i=0 ; superlist[i]; i++) {
                int rv;
                ss = superlist[i];
@@ -1449,6 +1448,7 @@ int is_container_active(char *container)
 int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
 {
        struct mdinfo *mdi;
+       struct mdinfo *info;
        int fd, err = 1;
 
        fd = open(dev, O_RDWR|O_EXCL);
@@ -1498,20 +1498,27 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
                goto free_sysfs;
        }
 
-       strncpy(st->subarray, subarray, sizeof(st->subarray)-1);
+       if (!st->ss->load_container) {
+               if (!quiet)
+                       fprintf(stderr, Name ": %s is not a container\n", dev);
+               goto free_name;
+       }
 
-       if (st->ss->load_super(st, fd, NULL)) {
+       if (st->ss->load_container(st, fd, NULL)) {
                if (!quiet)
-                       fprintf(stderr, Name ": Failed to find subarray-%s in %s\n",
-                               st->subarray, dev);
+                       fprintf(stderr, Name ": Failed to load metadata for %s\n",
+                               dev);
                goto free_name;
        }
 
-       if (!st->loaded_container) {
+       info = st->ss->container_content(st, subarray);
+       if (!info) {
                if (!quiet)
-                       fprintf(stderr, Name ": %s is not a container\n", dev);
+                       fprintf(stderr, Name ": Failed to find subarray-%s in %s\n",
+                               subarray, dev);
                goto free_super;
        }
+       free(info);
 
        err = 0;