Subject: [PATCH 0/2] raw-posix block driver fixes (v2)
cover Subject: [PATCH 0/2] raw-posix block driver fixes (v2)
Fix the recent regression opening read-only files as well as using the wrong constants for open flags.
Changes since v1:
- use O_ACCMODE unconditionally to clear the previous access mode, instead of O_RDWR
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
[Qemu-devel] Re: [PATCH 1/2] raw-posix: open flags use BDRV_ namespace, not posix namespace
block/raw-posix.c static int raw_open_common(BlockDriverState *bs, const char *filename, · line 139
Quoted 13 lines · Avi Kivity
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 ;
Looks good.
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
@@ -133,6 +133,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, s->lseek_err_cnt =0 ; s->open_flags |=O_BINARY ; + s->open_flags &= ~O_ACCMODE ;if ((flags &BDRV_O_ACCESS ) ==BDRV_O_RDWR ) { s->open_flags |=O_RDWR ; }else {
Signature · 1 line
1.6.0.6
[Qemu-devel] Re: [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 139
Quoted 7 lines
block/raw-posix.c +1
-0@@ -133,6 +133,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, s->lseek_err_cnt =0 ; s->open_flags |=O_BINARY ; + s->open_flags &= ~O_ACCMODE ;if ((flags &BDRV_O_ACCESS ) ==BDRV_O_RDWR ) { s->open_flags |=O_RDWR ; }else {
Also looks good.
[Qemu-devel] Re: [PATCH 2/2] raw-posix: Remove O_RDWR when attempting to open a file read-only
Quoted 1 line · Christoph Hellwig
Also looks good.
Actually I think the variant from Blue Swirl is better as it gives us a clean state to start from.