Commit 11a1feb6552e3a4709e454faea5e3be5ca8d9e6a

Authored by Avi Kivity
Committed by Anthony Liguori
1 parent 736d0c25

raw-posix: Remove O_RDWR when attempting to open a file read-only

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_RDWR flag from the previous attempt.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 1 additions and 0 deletions
block/raw-posix.c
... ... @@ -133,6 +133,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,
133 133 s->lseek_err_cnt = 0;
134 134  
135 135 s->open_flags |= O_BINARY;
  136 + s->open_flags &= ~O_ACCMODE;
136 137 if ((flags & BDRV_O_ACCESS) == BDRV_O_RDWR) {
137 138 s->open_flags |= O_RDWR;
138 139 } else {
... ...