Create missing /dev files where needed.

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>
This commit is contained in:
Neil Brown 2006-03-28 06:26:53 +00:00
parent 8352ab3e2c
commit 16c6fa807c
10 changed files with 33 additions and 31 deletions

View File

@ -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,

24
Grow.c
View File

@ -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",

View File

@ -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);

View File

@ -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 &&

View File

@ -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);

View File

@ -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 {

View 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);
}
}

View File

@ -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

View File

@ -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");

12
util.c
View File

@ -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);