]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Create missing /dev files where needed.
authorNeil Brown <neilb@suse.de>
Tue, 28 Mar 2006 06:26:53 +0000 (06:26 +0000)
committerNeil Brown <neilb@suse.de>
Tue, 28 Mar 2006 06:26:53 +0000 (06:26 +0000)
Whenever we need a device file to open, if one cannot be found in /dev,
create a temporary one.

Signed-off-by: Neil Brown <neilb@suse.de>
Detail.c
Grow.c
Manage.c
Monitor.c
config.c
mdadm.h
mdassemble.c
mdopen.c
super0.c
util.c

index a11393352e337d350d53c258273eeec829778b94..d322732c4222433092997ad45072bc3c2924f48a 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -105,12 +105,12 @@ int Detail(char *dev, int brief, int test)
                    disk.major == 0 &&
                    disk.minor == 0)
                        continue;
-               if ((dv=map_dev(disk.major, disk.minor))) {
+               if ((dv=map_dev(disk.major, disk.minor, 1))) {
                        if (!super && (disk.state & (1<<MD_DISK_ACTIVE))) {
                                /* try to read the superblock from this device
                                 * to get more info
                                 */
-                               int fd2 = open(dv, O_RDONLY);
+                               int fd2 = dev_open(dv, O_RDONLY);
                                if (fd2 >=0 && st &&
                                    st->ss->load_super(st, fd2, &super, NULL) == 0) {
                                        struct mdinfo info;
@@ -307,7 +307,7 @@ int Detail(char *dev, int brief, int test)
                                rv |= 2;
                        rv |= 1;
                }
-               if ((dv=map_dev(disk.major, disk.minor))) {
+               if ((dv=map_dev(disk.major, disk.minor, 0))) {
                        if (brief) {
                                if (devices) {
                                        devices = realloc(devices,
diff --git a/Grow.c b/Grow.c
index 4a225c7342dbd17833015c2e562105afc0ff3215..de53df18559c69fabcabe2f8daa5d627b594e6a1 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -92,13 +92,13 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                                d);
                        return 1;
                }
-               dv = map_dev(disk.major, disk.minor);
+               dv = map_dev(disk.major, disk.minor, 1);
                if (!dv) {
                        fprintf(stderr, Name ": cannot find device file for device %d\n",
                                d);
                        return 1;
                }
-               fd2 = open(dv, O_RDWR);
+               fd2 = dev_open(dv, O_RDWR);
                if (!fd2) {
                        fprintf(stderr, Name ": cannot open device file %s\n", dv);
                        return 1;
@@ -154,13 +154,13 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                                d);
                        return 1;
                }
-               dv = map_dev(disk.major, disk.minor);
+               dv = map_dev(disk.major, disk.minor, 1);
                if (!dv) {
                        fprintf(stderr, Name ": cannot find device file for device %d\n",
                                d);
                        return 1;
                }
-               fd2 = open(dv, O_RDWR);
+               fd2 = dev_open(dv, O_RDWR);
                if (fd2 < 0) {
                        fprintf(stderr, Name ": cannot open device file %s\n", dv);
                        return 1;
@@ -298,10 +298,10 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
                                continue;
                        if ((disk.state & (1<<MD_DISK_SYNC))==0)
                                continue;
-                       dv = map_dev(disk.major, disk.minor);
+                       dv = map_dev(disk.major, disk.minor, 1);
                        if (dv) {
                                void *super;
-                               int fd2 = open(dv, O_RDWR);
+                               int fd2 = dev_open(dv, O_RDWR);
                                if (fd2 < 0)
                                        continue;
                                if (st->ss->load_super(st, fd2, &super, NULL)==0) {
@@ -343,9 +343,9 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
                        if ((disk.major==0 && disk.minor==0) ||
                            (disk.state & (1<<MD_DISK_REMOVED)))
                                continue;
-                       dv = map_dev(disk.major, disk.minor);
+                       dv = map_dev(disk.major, disk.minor, 1);
                        if (!dv) continue;
-                       fd2 = open(dv, O_RDONLY);
+                       fd2 = dev_open(dv, O_RDONLY);
                        if (fd2 >= 0 &&
                            st->ss->load_super(st, fd2, &super, NULL) == 0) {
                                close(fd2);
@@ -647,8 +647,8 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                        if (sd->state & (1<<MD_DISK_FAULTY))
                                continue;
                        if (sd->state & (1<<MD_DISK_SYNC)) {
-                               char *dn = map_dev(sd->major, sd->minor);
-                               fdlist[sd->role] = open(dn, O_RDONLY);
+                               char *dn = map_dev(sd->major, sd->minor, 1);
+                               fdlist[sd->role] = dev_open(dn, O_RDONLY);
                                offsets[sd->role] = sd->offset;
                                if (fdlist[sd->role] < 0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
@@ -657,8 +657,8 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                                }
                        } else {
                                /* spare */
-                               char *dn = map_dev(sd->major, sd->minor);
-                               fdlist[d] = open(dn, O_RDWR);
+                               char *dn = map_dev(sd->major, sd->minor, 1);
+                               fdlist[d] = dev_open(dn, O_RDWR);
                                offsets[d] = sd->offset;
                                if (fdlist[d]<0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
index f7f3f6effe4f41ae58d0105f3fe2c7e85e830cee..9e643163cf273e4dff84897b7f683f3a9b6d0910 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -249,9 +249,9 @@ int Manage_subdevs(char *devname, int fd,
                                                continue;
                                        if ((disc.state & 4)==0) continue; /* sync */
                                        /* Looks like a good device to try */
-                                       dev = map_dev(disc.major, disc.minor);
+                                       dev = map_dev(disc.major, disc.minor, 1);
                                        if (!dev) continue;
-                                       dfd = open(dev, O_RDONLY);
+                                       dfd = dev_open(dev, O_RDONLY);
                                        if (dfd < 0) continue;
                                        if (st->ss->load_super(st, dfd, &dsuper, NULL)) {
                                                close(dfd);
index 2ea0bc8f4e39767df3adadb13c9e78f3fea17e0e..0ab5e0cea5ffdd53d3476f8a3315a39ac6495cc9 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -309,7 +309,7 @@ int Monitor(mddev_dev_t devlist,
                                disc.number = i;
                                if (ioctl(fd, GET_DISK_INFO, &disc)>= 0) {
                                        newstate = disc.state;
-                                       dv = map_dev(disc.major, disc.minor);
+                                       dv = map_dev(disc.major, disc.minor, 1);
                                } else if (mse &&  mse->pattern && i < strlen(mse->pattern))
                                        switch(mse->pattern[i]) {
                                        case 'U': newstate = 6 /* ACTIVE/SYNC */; break;
@@ -317,7 +317,7 @@ int Monitor(mddev_dev_t devlist,
                                        }
                                if (dv == NULL && st->devid[i])
                                        dv = map_dev(major(st->devid[i]),
-                                                    minor(st->devid[i]));
+                                                    minor(st->devid[i]), 1);
                                change = newstate ^ st->devstate[i];
                                if (st->utime && change && !st->err) {
                                        if (i < (unsigned)array.raid_disks &&
index c09c2061b5a75e40e73fa00818aa908c7c58956d..1408b252d22d53110dda3f7f3ea9a4ee2548b2ec 100644 (file)
--- a/config.c
+++ b/config.c
@@ -229,11 +229,7 @@ mddev_dev_t load_partitions(void)
                        continue;
                minor = strtoul(mp, NULL, 10);
 
-               name = map_dev(major, minor);
-               if (!name) {
-                       snprintf(buf, 1024, "%d:%d", major, minor);
-                       name = buf;
-               }
+               name = map_dev(major, minor, 1);
 
                d = malloc(sizeof(*d));
                d->devname = strdup(name);
diff --git a/mdadm.h b/mdadm.h
index 17526237c85f1b7db7b6d5339d41d774f679324d..a9ae698d36a1b2e7fe07f7b8e15050387b4454cc 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -246,7 +246,7 @@ extern char *map_num(mapping_t *map, int num);
 extern int map_name(mapping_t *map, char *name);
 extern mapping_t r5layout[], pers[], modes[], faultylayout[];
 
-extern char *map_dev(int major, int minor);
+extern char *map_dev(int major, int minor, int create);
 
 
 extern struct superswitch {
index 597cdb8f1473458e835185ff6d22162ac8bd518e..fc0c7a16fd5608232c5a5f0665dc27f7264103e8 100644 (file)
@@ -97,7 +97,7 @@ int main() {
                                continue;
                        rv |= Assemble(array_list->st, array_list->devname, mdfd,
                                           array_list, configfile,
-                                          NULL,
+                                          NULL, NULL,
                                           readonly, runstop, NULL, verbose, force);
                }
 }
index e4139e551e92251655704683a1859cb8c78d1145..8c3eabb45d3148b99bcfb639bebb5b5367dd7af8 100644 (file)
--- a/mdopen.c
+++ b/mdopen.c
@@ -176,7 +176,7 @@ int open_mddev(char *dev, int autof)
                                                minor = (-1-num) << MdpMinorShift;
                                        else
                                                minor = num;
-                                       dn = map_dev(major,minor);
+                                       dn = map_dev(major,minor, 0);
                                        if (dn==NULL || is_standard(dn, NULL)) {
                                                /* this number only used by a 'standard' name,
                                                 * so it is safe to use
index c7f2f613e2ec81aae244c6aa31962623b33fb45c..a36b0a7862588394abb94dadba4b259c2a420574 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -204,7 +204,7 @@ static void examine_super0(void *sbv)
                if (dp->state & (1<<MD_DISK_REMOVED)) printf(" removed");
                if (wonly) printf(" write-mostly");
                if (dp->state == 0) printf(" spare");
-               if ((dv=map_dev(dp->major, dp->minor)))
+               if ((dv=map_dev(dp->major, dp->minor, 0)))
                        printf("   %s", dv);
                printf("\n");
                if (d == -1) printf("\n");
diff --git a/util.c b/util.c
index ab606ab12fa08f4861eb6fef549e89050f6f4131..873deba67eacdb434e7a5c272d1182ddebc5f3ef 100644 (file)
--- a/util.c
+++ b/util.c
@@ -358,7 +358,7 @@ int devlist_ready = 0;
 int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
 {
 }
-char *map_dev(int major, int minor)
+char *map_dev(int major, int minor, int create)
 {
 #if 0
        fprintf(stderr, "Warning - fail to map %d,%d to a device name\n",
@@ -404,7 +404,7 @@ int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
  * deliberately so prefer it over a standard name.
  * This applies only to names for MD devices.
  */
-char *map_dev(int major, int minor)
+char *map_dev(int major, int minor, int create)
 {
        struct devmap *p;
        char *std = NULL, *nonstd=NULL;
@@ -431,6 +431,12 @@ char *map_dev(int major, int minor)
                                        nonstd = p->name;
                        }
                }
+       if (create && !std && !nonstd) {
+               static char buf[30];
+               snprintf(buf, 1024, "%d:%d", major, minor);
+               nonstd = buf;
+       }
+
        return nonstd ? nonstd : std;
 }
 
@@ -573,7 +579,7 @@ char *get_md_name(int dev)
                    && (stb.st_rdev == rdev))
                        return devname;
        }
-       dn = map_dev(major(rdev), minor(rdev));
+       dn = map_dev(major(rdev), minor(rdev), 0);
        if (dn)
                return dn;
        snprintf(devname, sizeof(devname), "/dev/.tmp.md%d", dev);