]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Reduce openning of dev in create.
authorNeil Brown <neilb@suse.de>
Thu, 15 May 2008 06:48:08 +0000 (16:48 +1000)
committerNeil Brown <neilb@suse.de>
Thu, 15 May 2008 06:48:08 +0000 (16:48 +1000)
Now that validate_geometry opens and checks the device,
we don't need to do it as much in top level Create.
We only need it to check for old array or filesystem info.
So only open the device at that place.

Create.c

index d423585d9796f938e9de9102ec3c8559cdcb93ce..629d359c26a85ce8c3bcea8d82dda9ab280f4fa9 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -205,7 +205,6 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        for (dv=devlist; dv; dv=dv->next, dnum++) {
                char *dname = dv->devname;
                unsigned long long freesize;
-               int fd;
                if (strcasecmp(dname, "missing")==0) {
                        if (first_missing > dnum)
                                first_missing = dnum;
@@ -217,13 +216,6 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                info.array.working_disks++;
                if (dnum < raiddisks)
                        info.array.active_disks++;
-               fd = open(dname, O_RDONLY|O_EXCL, 0);
-               if (fd <0 ) {
-                       fprintf(stderr, Name ": Cannot open %s: %s\n",
-                               dname, strerror(errno));
-                       fail=1;
-                       continue;
-               }
                if (st == NULL) {
                        struct createinfo *ci = conf_get_create_info();
                        if (ci)
@@ -281,7 +273,6 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                                " %lluK < %lluK + metadata\n",
                                dname, freesize, size);
                        fail = 1;
-                       close(fd);
                        continue;
                }
                if (maxdisc == NULL || (maxdisc && freesize > maxsize)) {
@@ -293,11 +284,18 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                        minsize = freesize;
                }
                if (runstop != 1 || verbose >= 0) {
+                       int fd = open(dname, O_RDONLY, 0);
+                       if (fd <0 ) {
+                               fprintf(stderr, Name ": Cannot open %s: %s\n",
+                                       dname, strerror(errno));
+                               fail=1;
+                               continue;
+                       }
                        warn |= check_ext2(fd, dname);
                        warn |= check_reiser(fd, dname);
                        warn |= check_raid(fd, dname);
+                       close(fd);
                }
-               close(fd);
        }
        if (fail) {
                fprintf(stderr, Name ": create aborted\n");