summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-10-11 17:15:55 +1100
committerNeilBrown <neilb@suse.de>2012-10-18 15:40:24 +1100
commit9ff1427837d2691b28f9f02721c32c1af97faa64 (patch)
tree6403968ded7ddd453903e9b12ec03008d1b7fae2
parent335d2a6ee8611006e0d77b0d4f92e4a096f6cedb (diff)
downloadmdadm-9ff1427837d2691b28f9f02721c32c1af97faa64.tar.gz
Fix open_container
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>
-rw-r--r--util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/util.c b/util.c
index eef0d6f..7f00b01 100644
--- 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)