Even more read-write/read-only fixes and cleanup
cover Even more read-write/read-only fixes and cleanup
A comment from Christoph Hellwig made me check (and fix) some stuff.
I'm afraid there are some more callers that needs to explicitly ask for read-write permissions. I'd like to get comments about that.
P.S. The qcow2 bug (I introduced) in pre-allocate showed me there's a need to check return value.
Naphtali Sprei (3):
No need anymore for bdrv_set_read_only
Ask for read-write permissions when opening files where needed Read-only device changed to opens it's file for read-only.
block.c | 7 ------- block.h | 1 - block/bochs.c | 6 ++---- block/parallels.c | 6 ++---- block/qcow2.c | 2 +- block/vvfat.c | 2 +- qemu-img.c | 4 ++-- 7 files changed, 8 insertions(+), 20 deletions(-)
cover *** SUBJECT HERE ***
*** BLURB HERE ***
Naphtali Sprei (3):
No need anymoe for bdrv_set_read_only
Ask for read-write permissions when opening files Read-only device changed to opens it's file for read-only.
block.c | 7 ------- block.h | 1 - block/bochs.c | 6 ++---- block/parallels.c | 6 ++---- block/qcow2.c | 2 +- block/vvfat.c | 2 +- qemu-img.c | 4 ++-- 7 files changed, 8 insertions(+), 20 deletions(-)
cover *** SUBJECT HERE ***
*** BLURB HERE ***
Naphtali Sprei (3):
No need anymore for bdrv_set_read_only
Ask for read-write permissions when opening files where needed Read-only device changed to opens it's file for read-only.
block.c | 7 ------- block.h | 1 - block/bochs.c | 6 ++---- block/parallels.c | 6 ++---- block/qcow2.c | 2 +- block/vvfat.c | 2 +- qemu-img.c | 4 ++-- 7 files changed, 8 insertions(+), 20 deletions(-)
PATCH 1/3 No need anymoe for bdrv_set_read_only
--- block.c | 7 ------- block.h | 1 - 2 files changed, 0 insertions(+), 8 deletions(-)
block.c +0 -7
@@ -1009,13 +1009,6 @@ int bdrv_is_read_only(BlockDriverState *bs)return bs->read_only; } -int bdrv_set_read_only (BlockDriverState *bs,int read_only) -{ -int ret = bs->read_only; - bs->read_only = read_only; -return ret; -} -int bdrv_is_sg (BlockDriverState *bs) {return bs->sg;
block.h +0 -1
@@ -147,7 +147,6 @@ int bdrv_get_type_hint(BlockDriverState *bs);int bdrv_get_translation_hint (BlockDriverState *bs);int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs); -int bdrv_set_read_only (BlockDriverState *bs,int read_only);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);int bdrv_is_inserted (BlockDriverState *bs);
Signature · 1 line
1.6.3.3
PATCH 1/3 No need anymore for bdrv_set_read_only
--- block.c | 7 ------- block.h | 1 - 2 files changed, 0 insertions(+), 8 deletions(-)
block.c +0 -7
@@ -1009,13 +1009,6 @@ int bdrv_is_read_only(BlockDriverState *bs)return bs->read_only; } -int bdrv_set_read_only (BlockDriverState *bs,int read_only) -{ -int ret = bs->read_only; - bs->read_only = read_only; -return ret; -} -int bdrv_is_sg (BlockDriverState *bs) {return bs->sg;
block.h +0 -1
@@ -147,7 +147,6 @@ int bdrv_get_type_hint(BlockDriverState *bs);int bdrv_get_translation_hint (BlockDriverState *bs);int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs); -int bdrv_set_read_only (BlockDriverState *bs,int read_only);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);int bdrv_is_inserted (BlockDriverState *bs);
Signature · 1 line
1.6.3.3
PATCH 2/3 Ask for read-write permissions when opening files
Found some places that seems needs this explicitly, now that read-write is not the default.
--- block/qcow2.c | 2 +- block/vvfat.c | 2 +- qemu-img.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
block/qcow2.c +1 -1
@@ -961,7 +961,7 @@ static int qcow_create2(const char *filename, int64_t total_size,if (prealloc) {BlockDriverState *bs; bs =bdrv_new ("" ); -bdrv_open (bs, filename,BDRV_O_CACHE_WB ); +bdrv_open (bs, filename,BDRV_O_CACHE_WB |BDRV_O_RDWR );preallocate (bs);bdrv_close (bs); }
block/vvfat.c +1 -1
@@ -2787,7 +2787,7 @@ static int enable_write_target(BDRVVVFATState *s)if (bdrv_create (bdrv_qcow, s->qcow_filename, options) <0 )return -1 ; s->qcow =bdrv_new ("" ); -if (s->qcow ==NULL ||bdrv_open (s->qcow, s->qcow_filename,0 ) <0 ) +if (s->qcow ==NULL ||bdrv_open (s->qcow, s->qcow_filename,BDRV_O_RDWR ) <0 )return -1 ;#ifndef _WIN32
qemu-img.c +2 -2
@@ -1116,7 +1116,7 @@ static int img_rebase(int argc, char **argv)if (!bs)error ("Not enough memory" ); - flags =BRDV_O_FLAGS | (unsafe ?BDRV_O_NO_BACKING :0 ); + flags =BRDV_O_FLAGS |BDRV_O_RDWR | (unsafe ?BDRV_O_NO_BACKING :0 );if (bdrv_open2 (bs, filename, flags,NULL ) <0 ) {error ("Could not open '%s'" , filename); }
@@ -1157,7 +1157,7 @@ static int img_rebase(int argc, char **argv) } bs_new_backing =bdrv_new ("new_backing" ); -if (bdrv_open2 (bs_new_backing, out_baseimg,BRDV_O_FLAGS , +if (bdrv_open2 (bs_new_backing, out_baseimg,BRDV_O_FLAGS |BDRV_O_RDWR , new_backing_drv)) {error ("Could not open new backing file '%s'" , backing_name);
Signature · 1 line
1.6.3.3
PATCH 2/3 Ask for read-write permissions when opening files where needed
Found some places that seems needs this explicitly, now that read-write is not the default.
--- block/qcow2.c | 2 +- block/vvfat.c | 2 +- qemu-img.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
block/qcow2.c +1 -1
@@ -961,7 +961,7 @@ static int qcow_create2(const char *filename, int64_t total_size,if (prealloc) {BlockDriverState *bs; bs =bdrv_new ("" ); -bdrv_open (bs, filename,BDRV_O_CACHE_WB ); +bdrv_open (bs, filename,BDRV_O_CACHE_WB |BDRV_O_RDWR );preallocate (bs);bdrv_close (bs); }
block/vvfat.c +1 -1
@@ -2787,7 +2787,7 @@ static int enable_write_target(BDRVVVFATState *s)if (bdrv_create (bdrv_qcow, s->qcow_filename, options) <0 )return -1 ; s->qcow =bdrv_new ("" ); -if (s->qcow ==NULL ||bdrv_open (s->qcow, s->qcow_filename,0 ) <0 ) +if (s->qcow ==NULL ||bdrv_open (s->qcow, s->qcow_filename,BDRV_O_RDWR ) <0 )return -1 ;#ifndef _WIN32
qemu-img.c +2 -2
@@ -1116,7 +1116,7 @@ static int img_rebase(int argc, char **argv)if (!bs)error ("Not enough memory" ); - flags =BRDV_O_FLAGS | (unsafe ?BDRV_O_NO_BACKING :0 ); + flags =BRDV_O_FLAGS |BDRV_O_RDWR | (unsafe ?BDRV_O_NO_BACKING :0 );if (bdrv_open2 (bs, filename, flags,NULL ) <0 ) {error ("Could not open '%s'" , filename); }
@@ -1157,7 +1157,7 @@ static int img_rebase(int argc, char **argv) } bs_new_backing =bdrv_new ("new_backing" ); -if (bdrv_open2 (bs_new_backing, out_baseimg,BRDV_O_FLAGS , +if (bdrv_open2 (bs_new_backing, out_baseimg,BRDV_O_FLAGS |BDRV_O_RDWR , new_backing_drv)) {error ("Could not open new backing file '%s'" , backing_name);
Signature · 1 line
1.6.3.3
PATCH 3/3 Read-only device changed to opens it's file for read-only.
--- block/bochs.c | 6 ++---- block/parallels.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-)
block/bochs.c +2 -4
@@ -116,11 +116,9 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags)struct bochs_header bochs;struct bochs_header_v1 header_v1; - fd =open (filename,O_RDWR |O_BINARY ); + fd =open (filename,O_RDONLY |O_BINARY );if (fd <0 ) { - fd =open (filename,O_RDONLY |O_BINARY ); -if (fd <0 ) -return -1 ; +return -1 ; } bs->read_only =1 ;// no write support yet
block/parallels.c +2 -4
@@ -74,11 +74,9 @@ static int parallels_open(BlockDriverState *bs, const char *filename, int flags)int fd, i;struct parallels_header ph; - fd =open (filename,O_RDWR |O_BINARY |O_LARGEFILE ); + fd =open (filename,O_RDONLY |O_BINARY |O_LARGEFILE );if (fd <0 ) { - fd =open (filename,O_RDONLY |O_BINARY |O_LARGEFILE ); -if (fd <0 ) -return -1 ; +return -1 ; } bs->read_only =1 ;// no write support yet
Signature · 1 line
1.6.3.3
Anthony Liguori
AppliedRe: [Qemu-devel] [PATCH 1/3] No need anymoe for bdrv_set_read_only
In reply to Naphtali SpreiQuoted 2 lines · Naphtali Sprei
Signed-off-by Naphtali Sprei<[email protected]>
Applied all. Thanks.
Regards,
Anthony Liguori
Quoted 36 lines
--- block.c | 7 ------- block.h | 1 - 2 files changed, 0 insertions(+), 8 deletions(-)block.c +0
-7@@ -1009,13 +1009,6 @@ int bdrv_is_read_only(BlockDriverState *bs)return bs->read_only; } -int bdrv_set_read_only (BlockDriverState *bs,int read_only) -{ -int ret = bs->read_only; - bs->read_only = read_only; -return ret; -} -int bdrv_is_sg (BlockDriverState *bs) {return bs->sg;block.h +0
-1@@ -147,7 +147,6 @@ int bdrv_get_type_hint(BlockDriverState *bs);int bdrv_get_translation_hint (BlockDriverState *bs);int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs); -int bdrv_set_read_only (BlockDriverState *bs,int read_only);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);int bdrv_is_inserted (BlockDriverState *bs);