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 a113933..d322732 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;
                    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
                                 */
                        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;
                                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;
                }
                                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,
                        if (brief) {
                                if (devices) {
                                        devices = realloc(devices,
diff --git a/Grow.c b/Grow.c
index 4a225c7..de53df1 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;
                }
                                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;
                }
                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;
                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;
                }
                                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;
                }
                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;
                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;
                                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;
                        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) {
                                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;
                        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;
                        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);
                        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)) {
                        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",
                                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 */
                                }
                        } 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",
                                offsets[d] = sd->offset;
                                if (fdlist[d]<0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
index f7f3f6e..9e64316 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 */
                                                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;
                                        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);
                                        if (dfd < 0) continue;
                                        if (st->ss->load_super(st, dfd, &dsuper, NULL)) {
                                                close(dfd);
index 2ea0bc8..0ab5e0c 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;
                                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;
                                } 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]),
                                        }
                                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 &&
                                change = newstate ^ st->devstate[i];
                                if (st->utime && change && !st->err) {
                                        if (i < (unsigned)array.raid_disks &&
index c09c206..1408b25 100644 (file)
--- a/config.c
+++ b/config.c
@@ -229,11 +229,7 @@ mddev_dev_t load_partitions(void)
                        continue;
                minor = strtoul(mp, NULL, 10);
 
                        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);
 
                d = malloc(sizeof(*d));
                d->devname = strdup(name);
diff --git a/mdadm.h b/mdadm.h
index 1752623..a9ae698 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 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 {
 
 
 extern struct superswitch {
index 597cdb8..fc0c7a1 100644 (file)
@@ -97,7 +97,7 @@ int main() {
                                continue;
                        rv |= Assemble(array_list->st, array_list->devname, mdfd,
                                           array_list, configfile,
                                continue;
                        rv |= Assemble(array_list->st, array_list->devname, mdfd,
                                           array_list, configfile,
-                                          NULL,
+                                          NULL, NULL,
                                           readonly, runstop, NULL, verbose, force);
                }
 }
                                           readonly, runstop, NULL, verbose, force);
                }
 }
index e4139e5..8c3eabb 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;
                                                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
                                        if (dn==NULL || is_standard(dn, NULL)) {
                                                /* this number only used by a 'standard' name,
                                                 * so it is safe to use
index c7f2f61..a36b0a7 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 (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");
                        printf("   %s", dv);
                printf("\n");
                if (d == -1) printf("\n");
diff --git a/util.c b/util.c
index ab606ab..873deba 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)
 {
 }
 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",
 {
 #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.
  */
  * 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;
 {
        struct devmap *p;
        char *std = NULL, *nonstd=NULL;
@@ -431,6 +431,12 @@ char *map_dev(int major, int minor)
                                        nonstd = p->name;
                        }
                }
                                        nonstd = p->name;
                        }
                }
+       if (create && !std && !nonstd) {
+               static char buf[30];
+               snprintf(buf, 1024, "%d:%d", major, minor);
+               nonstd = buf;
+       }
+
        return nonstd ? nonstd : std;
 }
 
        return nonstd ? nonstd : std;
 }
 
@@ -573,7 +579,7 @@ char *get_md_name(int dev)
                    && (stb.st_rdev == rdev))
                        return devname;
        }
                    && (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);
        if (dn)
                return dn;
        snprintf(devname, sizeof(devname), "/dev/.tmp.md%d", dev);