]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Fix open_container
authorNeilBrown <neilb@suse.de>
Thu, 11 Oct 2012 06:15:55 +0000 (17:15 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 18 Oct 2012 04:40:24 +0000 (15:40 +1100)
open_container should open a container which contains the device,
but sometimes it would open another volume which contains the
device.  Be more careful in 'holder' selection.

Signed-off-by: NeilBrown <neilb@suse.de>
util.c

diff --git a/util.c b/util.c
index eef0d6f059a3bbe694ae3b2604189d3e75167abf..7f00b01201cb96826de473fac6f182047e9ec9f5 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1315,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)