Skip to contentSkip to conversation

Subject: [PATCH 0/2] raw-posix block driver fixes (v2)

PATCH In review Avi Kivity 2 participants 6 messages Jun 16, 2009 Block layer

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

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(-)
author
#1 lore raw

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
index 5032348..5790206 100644
@@ -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
#2 lore raw

[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
index 5032348..5790206 100644
@@ -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.

author
#3 lore raw

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

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

---
 block/raw-posix.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
block/raw-posix.c +1 -0
index 5790206..ccb014a 100644
@@ -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
#4 lore raw

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

---
 block/raw-posix.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
block/raw-posix.c +0 -0
index 5790206..ccb014a 100644

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.

#5 lore raw

[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.