raw-posix block driver fixes
cover raw-posix block driver fixes
Fix the recent regression opening read-only files as well as using the wrong constants for open flags.
Avi Kivity (2):
raw-posix: open flags use BDRV_ namespace, not posix namespace
raw-posix: Remove O_RDWR when attempting to open a file read-only
block/raw-posix.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
PATCH 1/2 raw-posix: open flags use BDRV_ namespace, not posix namespace
The flags argument to raw_common_open() contain bits defined by the BDRV_O_* namespace, not the posix O_* namespace.
Adjust to use the correct constants.
--- block/raw-posix.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
block/raw-posix.c +1 -1
@@ -133,7 +133,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, s->lseek_err_cnt =0 ; s->open_flags |=O_BINARY ; -if ((flags &BDRV_O_ACCESS ) ==O_RDWR ) { +if ((flags &BDRV_O_ACCESS ) ==BDRV_O_RDWR ) { s->open_flags |=O_RDWR ; }else { s->open_flags |=O_RDONLY ;
Signature · 1 line
1.6.0.6
PATCH 2/2 raw-posix: Remove O_RDWR when attempting to open a file read-only
In reply to Avi KivityWhen we open a file, we first attempt to open it read-write, then fall back to read-only. Unfortunately we reuse the flags from the previous attempt, so both attempts try to open the file with write permissions, and fail.
Fix by clearing the O_RDWR flag from the previous attempt.
--- block/raw-posix.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
block/raw-posix.c +1 -0
@@ -136,6 +136,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,if ((flags &BDRV_O_ACCESS ) ==BDRV_O_RDWR ) { s->open_flags |=O_RDWR ; }else { + s->open_flags &= ~O_RDWR ; s->open_flags |=O_RDONLY ; bs->read_only =1 ; }
Signature · 1 line
1.6.0.6
Re: [Qemu-devel] [PATCH 2/2] raw-posix: Remove O_RDWR when attempting to open a file read-only
Quoted 16 lines · Avi Kivity
When we open a file, we first attempt to open it read-write, then fall back to read-only. Unfortunately we reuse the flags from the previous attempt, so both attempts try to open the file with write permissions, and fail.
Fix by clearing the
O_RDWRflag from the previous attempt.Signed-off-by Avi Kivity <[email protected]>--- block/raw-posix.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)block/raw-posix.c +0
-0
block/raw-posix.c static int raw_open_common(BlockDriverState *bs, const char *filename, · line 142
Quoted 7 lines
block/raw-posix.c +1
-0@@ -136,6 +136,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,if ((flags &BDRV_O_ACCESS ) ==BDRV_O_RDWR ) { s->open_flags |=O_RDWR ; }else { + s->open_flags &= ~O_RDWR ; s->open_flags |=O_RDONLY ; bs->read_only =1 ; }
Does the standard say anything about the values of the constants? Wouldn't it be cleaner to have a s->open_flags &= ~O_ACCMODE before the if instead, so that O_RDONLY is reset in the other case?
Kevin
Re: [Qemu-devel] [PATCH 2/2] raw-posix: Remove O_RDWR when attempting to open a file read-only
Quoted 10 lines · Kevin Wolf
Quoted 5 lines
+ s->open_flags&= ~O_RDWR; s->open_flags |= O_RDONLY; bs->read_only = 1; }Does the standard say anything about the values of the constants? Wouldn't it be cleaner to have a s->open_flags&= ~O_ACCMODE before the if instead, so that
O_RDONLYis reset in the other case?
Didn't know about O_ACCMODE. Will fix and repost.
Signature · 1 line
error compiling committee.c: too many arguments to function