]> 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 ac0f78c50189d14e910caf7ed4e4245aac9a62f1..7f00b01201cb96826de473fac6f182047e9ec9f5 100644 (file)
--- a/util.c
+++ b/util.c
@@ -332,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;
 
@@ -796,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);
@@ -1310,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)