Use O_EXCL when opening component devices to be assembled into an array
In 2.6, this will fail if the device is already in use, so we can detect this error more easily. Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
This commit is contained in:
parent
b568741513
commit
d7eaf49f65
10
Assemble.c
10
Assemble.c
|
@ -193,7 +193,7 @@ int Assemble(char *mddev, int mdfd,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
dfd = open(devname, O_RDONLY, 0);
|
dfd = open(devname, O_RDONLY|O_EXCL, 0);
|
||||||
if (dfd < 0) {
|
if (dfd < 0) {
|
||||||
if (inargv || verbose)
|
if (inargv || verbose)
|
||||||
fprintf(stderr, Name ": cannot open device %s: %s\n",
|
fprintf(stderr, Name ": cannot open device %s: %s\n",
|
||||||
|
@ -326,7 +326,7 @@ int Assemble(char *mddev, int mdfd,
|
||||||
super.recovery_cp = 0;
|
super.recovery_cp = 0;
|
||||||
}
|
}
|
||||||
super.sb_csum = calc_sb_csum(&super);
|
super.sb_csum = calc_sb_csum(&super);
|
||||||
dfd = open(devname, O_RDWR, 0);
|
dfd = open(devname, O_RDWR|O_EXCL, 0);
|
||||||
if (dfd < 0)
|
if (dfd < 0)
|
||||||
fprintf(stderr, Name ": Cannot open %s for superblock update\n",
|
fprintf(stderr, Name ": Cannot open %s for superblock update\n",
|
||||||
devname);
|
devname);
|
||||||
|
@ -435,7 +435,7 @@ int Assemble(char *mddev, int mdfd,
|
||||||
devices[chosen_drive].devname, devices[chosen_drive].raid_disk,
|
devices[chosen_drive].devname, devices[chosen_drive].raid_disk,
|
||||||
(int)(devices[chosen_drive].events),
|
(int)(devices[chosen_drive].events),
|
||||||
(int)(devices[most_recent].events));
|
(int)(devices[most_recent].events));
|
||||||
fd = open(devices[chosen_drive].devname, O_RDWR);
|
fd = open(devices[chosen_drive].devname, O_RDWR|O_EXCL);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, Name ": Couldn't open %s for write - not updating\n",
|
fprintf(stderr, Name ": Couldn't open %s for write - not updating\n",
|
||||||
devices[chosen_drive].devname);
|
devices[chosen_drive].devname);
|
||||||
|
@ -484,7 +484,7 @@ int Assemble(char *mddev, int mdfd,
|
||||||
if (!devices[j].uptodate)
|
if (!devices[j].uptodate)
|
||||||
continue;
|
continue;
|
||||||
chosen_drive = j;
|
chosen_drive = j;
|
||||||
if ((fd=open(devices[j].devname, O_RDONLY))< 0) {
|
if ((fd=open(devices[j].devname, O_RDONLY|O_EXCL))< 0) {
|
||||||
fprintf(stderr, Name ": Cannot open %s: %s\n",
|
fprintf(stderr, Name ": Cannot open %s: %s\n",
|
||||||
devices[j].devname, strerror(errno));
|
devices[j].devname, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -556,7 +556,7 @@ This doesnt work yet
|
||||||
|| (old_linux && (change & 1))) {
|
|| (old_linux && (change & 1))) {
|
||||||
int fd;
|
int fd;
|
||||||
super.sb_csum = calc_sb_csum(&super);
|
super.sb_csum = calc_sb_csum(&super);
|
||||||
fd = open(devices[chosen_drive].devname, O_RDWR);
|
fd = open(devices[chosen_drive].devname, O_RDWR|O_EXCL);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, Name ": Could open %s for write - cannot Assemble array.\n",
|
fprintf(stderr, Name ": Could open %s for write - cannot Assemble array.\n",
|
||||||
devices[chosen_drive].devname);
|
devices[chosen_drive].devname);
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
Changes Prior to 1.10.0 release
|
||||||
|
- Fix bug with --config=partitions
|
||||||
|
- Open sub-devices with O_EXCL to detect if already in use
|
||||||
|
|
||||||
Changes Prior to 1.9.0 release
|
Changes Prior to 1.9.0 release
|
||||||
- Fix rpm build problem (stray %)
|
- Fix rpm build problem (stray %)
|
||||||
- Minor manpage updates
|
- Minor manpage updates
|
||||||
|
|
4
Create.c
4
Create.c
|
@ -187,7 +187,7 @@ int Create(char *mddev, int mdfd,
|
||||||
array.working_disks++;
|
array.working_disks++;
|
||||||
if (dnum < raiddisks)
|
if (dnum < raiddisks)
|
||||||
array.active_disks++;
|
array.active_disks++;
|
||||||
fd = open(dname, O_RDONLY, 0);
|
fd = open(dname, O_RDONLY|O_EXCL, 0);
|
||||||
if (fd <0 ) {
|
if (fd <0 ) {
|
||||||
fprintf(stderr, Name ": Cannot open %s: %s\n",
|
fprintf(stderr, Name ": Cannot open %s: %s\n",
|
||||||
dname, strerror(errno));
|
dname, strerror(errno));
|
||||||
|
@ -368,7 +368,7 @@ int Create(char *mddev, int mdfd,
|
||||||
disk.minor = 0;
|
disk.minor = 0;
|
||||||
disk.state = 1; /* faulty */
|
disk.state = 1; /* faulty */
|
||||||
} else {
|
} else {
|
||||||
fd = open(dv->devname, O_RDONLY, 0);
|
fd = open(dv->devname, O_RDONLY|O_EXCL, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, Name ": failed to open %s after earlier success - aborting\n",
|
fprintf(stderr, Name ": failed to open %s after earlier success - aborting\n",
|
||||||
dv->devname);
|
dv->devname);
|
||||||
|
|
2
Kill.c
2
Kill.c
|
@ -44,7 +44,7 @@ int Kill(char *dev, int force)
|
||||||
mdp_super_t super;
|
mdp_super_t super;
|
||||||
int fd, rv = 0;
|
int fd, rv = 0;
|
||||||
|
|
||||||
fd = open(dev, O_RDWR);
|
fd = open(dev, O_RDWR|O_EXCL);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n",
|
fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n",
|
||||||
dev);
|
dev);
|
||||||
|
|
8
Manage.c
8
Manage.c
|
@ -194,6 +194,14 @@ int Manage_subdevs(char *devname, int fd,
|
||||||
return 1;
|
return 1;
|
||||||
case 'a':
|
case 'a':
|
||||||
/* add the device - hot or cold */
|
/* add the device - hot or cold */
|
||||||
|
/* Make sure it isn' in use (in 2.6 or later) */
|
||||||
|
fd = open(dv->devname, O_RDONLY|O_EXCL);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, Name ": Cannot open %s: %s\n",
|
||||||
|
dv->devname, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
if (ioctl(fd, HOT_ADD_DISK, (unsigned long)stb.st_rdev)==0) {
|
if (ioctl(fd, HOT_ADD_DISK, (unsigned long)stb.st_rdev)==0) {
|
||||||
fprintf(stderr, Name ": hot added %s\n",
|
fprintf(stderr, Name ": hot added %s\n",
|
||||||
dv->devname);
|
dv->devname);
|
||||||
|
|
Loading…
Reference in New Issue