]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Release 3.2.6 - stability release
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index d32e6506492fa980c4dc36f82b628f6943413752..7f00b01201cb96826de473fac6f182047e9ec9f5 100644 (file)
--- a/util.c
+++ b/util.c
@@ -194,6 +194,7 @@ long long parse_size(char *size)
         * followed by 'K', 'M', or 'G'.
         * Without a suffix, K is assumed.
         * Number returned is in sectors (half-K)
+        * -1 returned on error.
         */
        char *c;
        long long s = strtoll(size, &c, 10);
@@ -215,7 +216,7 @@ long long parse_size(char *size)
                }
        }
        if (*c)
-               s = 0;
+               s = -1;
        return s;
 }
 
@@ -331,14 +332,15 @@ int enough(int level, int raid_disks, int layout, int clean, char *avail)
                        /* there must be one of the 'copies' form 'first' */
                        int n = copies;
                        int cnt=0;
+                       int this = first;
                        while (n--) {
-                               if (avail[first])
+                               if (avail[this])
                                        cnt++;
-                               first = (first+1) % raid_disks;
+                               this = (this+1) % raid_disks;
                        }
                        if (cnt == 0)
                                return 0;
-
+                       first = (first+(layout&255)) % raid_disks;
                } while (first != 0);
                return 1;
 
@@ -377,7 +379,7 @@ int enough_fd(int fd)
            array.raid_disks <= 0)
                return 0;
        avail = calloc(array.raid_disks, 1);
-       for (i=0; i < 1024 && array.nr_disks > 0; i++) {
+       for (i=0; i < MAX_DISKS && array.nr_disks > 0; i++) {
                disk.number = i;
                if (ioctl(fd, GET_DISK_INFO, &disk) != 0)
                        continue;
@@ -795,10 +797,14 @@ int find_free_devnum(int use_partitions)
             devnum = devnum ? devnum-1 : (1<<20)-1) {
                char *dn;
                int _devnum;
+               char nbuf[50];
 
                _devnum = use_partitions ? (-1-devnum) : devnum;
                if (mddev_busy(_devnum))
                        continue;
+               sprintf(nbuf, "%s%d", use_partitions?"mdp":"md", devnum);
+               if (!conf_name_is_free(nbuf))
+                       continue;
                /* make sure it is new to /dev too, at least as a
                 * non-standard */
                dn = map_dev(dev2major(_devnum), dev2minor(_devnum), 0);
@@ -1274,7 +1280,7 @@ void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk)
        int d;
 
        ioctl(mdfd, GET_ARRAY_INFO, ainf);
-       for (d = 0 ; d < 1024 ; d++) {
+       for (d = 0 ; d < MAX_DISKS ; d++) {
                if (ioctl(mdfd, GET_DISK_INFO, disk) == 0 &&
                    (disk->major || disk->minor))
                        return;
@@ -1309,6 +1315,20 @@ int open_container(int fd)
                        continue;
                if (de->d_name[0] == '.')
                        continue;
+               /* Need to make sure it is a container and not a volume */
+               sprintf(e, "/%s/md/metadata_version", de->d_name);
+               dfd = open(path, O_RDONLY);
+               if (dfd < 0)
+                       continue;
+               n = read(dfd, buf, sizeof(buf));
+               close(dfd);
+               if (n <= 0 || (unsigned)n >= sizeof(buf))
+                       continue;
+               buf[n] = 0;
+               if (strncmp(buf, "external", 8) != 0 ||
+                   n < 10 ||
+                   buf[9] == '/')
+                       continue;
                sprintf(e, "/%s/dev", de->d_name);
                dfd = open(path, O_RDONLY);
                if (dfd < 0)