open_dev_excl: allow device to be read-only.
For many operations we don't need a writable device. So if opening O_RDWR fails in open_dev_excl, then try again O_RDONLY. If we really needed write, a subsequent operation will failed. But if we didn't, we succeed when otherwise we wouldn't have. Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
972728bb1b
commit
7187750e8d
7
util.c
7
util.c
|
@ -1015,12 +1015,17 @@ int open_dev_excl(int devnum)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
int i;
|
int i;
|
||||||
|
int flags = O_RDWR;
|
||||||
|
|
||||||
sprintf(buf, "%d:%d", dev2major(devnum), dev2minor(devnum));
|
sprintf(buf, "%d:%d", dev2major(devnum), dev2minor(devnum));
|
||||||
for (i=0 ; i<25 ; i++) {
|
for (i=0 ; i<25 ; i++) {
|
||||||
int fd = dev_open(buf, O_RDWR|O_EXCL);
|
int fd = dev_open(buf, flags|O_EXCL);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
if (errno == EACCES && flags == O_RDWR) {
|
||||||
|
flags = O_RDONLY;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (errno != EBUSY)
|
if (errno != EBUSY)
|
||||||
return fd;
|
return fd;
|
||||||
usleep(200000);
|
usleep(200000);
|
||||||
|
|
Loading…
Reference in New Issue