qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] Fix vvfat breakage
@ 2010-09-10 10:27 Kevin Wolf
  2010-09-10 10:27 ` [Qemu-devel] [PATCH 1/3] vvfat: Fix segfault on write to read-only disk Kevin Wolf
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kevin Wolf @ 2010-09-10 10:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf

I tried to use vvfat recently, just to find that some changes have
completely broken it. With these patches it works "good enough" for me
again.

Kevin Wolf (3):
  vvfat: Fix segfault on write to read-only disk
  vvfat: Fix double free for opening the image rw
  vvfat: Use cache=unsafe

 block/vvfat.c |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/3] vvfat: Fix segfault on write to read-only disk
  2010-09-10 10:27 [Qemu-devel] [PATCH 0/3] Fix vvfat breakage Kevin Wolf
@ 2010-09-10 10:27 ` Kevin Wolf
  2010-09-10 10:27 ` [Qemu-devel] [PATCH 2/3] vvfat: Fix double free for opening the image rw Kevin Wolf
  2010-09-10 10:27 ` [Qemu-devel] [PATCH 3/3] vvfat: Use cache=unsafe Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2010-09-10 10:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf

vvfat tries to set the readonly flag in its open function, but nowadays
this is overwritted with the readonly=... command line option. Check in
bdrv_write if the vvfat was opened read-only and return an error in this
case.

Without this check, vvfat tries to access the qcow bs, which is NULL
without enabled write support.

Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
---
 block/vvfat.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 365332a..5898d66 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2665,6 +2665,11 @@ static int vvfat_write(BlockDriverState *bs, int64_t sector_num,
 
 DLOG(checkpoint());
 
+    /* Check if we're operating in read-only mode */
+    if (s->qcow == NULL) {
+        return -EACCES;
+    }
+
     vvfat_close_current_file(s);
 
     /*
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/3] vvfat: Fix double free for opening the image rw
  2010-09-10 10:27 [Qemu-devel] [PATCH 0/3] Fix vvfat breakage Kevin Wolf
  2010-09-10 10:27 ` [Qemu-devel] [PATCH 1/3] vvfat: Fix segfault on write to read-only disk Kevin Wolf
@ 2010-09-10 10:27 ` Kevin Wolf
  2010-09-10 10:27 ` [Qemu-devel] [PATCH 3/3] vvfat: Use cache=unsafe Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2010-09-10 10:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf

Allocation and deallocation of bs->opaque is not in the control of a
block driver. Therefore it should not set bs->opaque to a data structure
used by another bs, or closing the image will lead to a double free.

Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
---
 block/vvfat.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 5898d66..0772037 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2768,12 +2768,12 @@ static int vvfat_is_allocated(BlockDriverState *bs,
 
 static int write_target_commit(BlockDriverState *bs, int64_t sector_num,
 	const uint8_t* buffer, int nb_sectors) {
-    BDRVVVFATState* s = bs->opaque;
+    BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque);
     return try_commit(s);
 }
 
 static void write_target_close(BlockDriverState *bs) {
-    BDRVVVFATState* s = bs->opaque;
+    BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque);
     bdrv_delete(s->qcow);
     free(s->qcow_filename);
 }
@@ -2816,7 +2816,8 @@ static int enable_write_target(BDRVVVFATState *s)
 
     s->bs->backing_hd = calloc(sizeof(BlockDriverState), 1);
     s->bs->backing_hd->drv = &vvfat_write_target;
-    s->bs->backing_hd->opaque = s;
+    s->bs->backing_hd->opaque = qemu_malloc(sizeof(void*));
+    *(void**)s->bs->backing_hd->opaque = s;
 
     return 0;
 }
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 3/3] vvfat: Use cache=unsafe
  2010-09-10 10:27 [Qemu-devel] [PATCH 0/3] Fix vvfat breakage Kevin Wolf
  2010-09-10 10:27 ` [Qemu-devel] [PATCH 1/3] vvfat: Fix segfault on write to read-only disk Kevin Wolf
  2010-09-10 10:27 ` [Qemu-devel] [PATCH 2/3] vvfat: Fix double free for opening the image rw Kevin Wolf
@ 2010-09-10 10:27 ` Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2010-09-10 10:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf

The qcow file used for write support in vvfat is a temporary file,
so we can use cache=unsafe there. Without this, write support is just
too slow to be of any use.

Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
---
 block/vvfat.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 0772037..53e57bf 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2788,6 +2788,7 @@ static int enable_write_target(BDRVVVFATState *s)
 {
     BlockDriver *bdrv_qcow;
     QEMUOptionParameter *options;
+    int ret;
     int size = sector2cluster(s, s->sector_count);
     s->used_clusters = calloc(size, 1);
 
@@ -2803,11 +2804,16 @@ 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, BDRV_O_RDWR, bdrv_qcow) < 0)
-    {
-	return -1;
+    if (s->qcow == NULL) {
+        return -1;
+    }
+
+    ret = bdrv_open(s->qcow, s->qcow_filename,
+            BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow);
+    if (ret < 0) {
+	return ret;
     }
 
 #ifndef _WIN32
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-10 10:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-10 10:27 [Qemu-devel] [PATCH 0/3] Fix vvfat breakage Kevin Wolf
2010-09-10 10:27 ` [Qemu-devel] [PATCH 1/3] vvfat: Fix segfault on write to read-only disk Kevin Wolf
2010-09-10 10:27 ` [Qemu-devel] [PATCH 2/3] vvfat: Fix double free for opening the image rw Kevin Wolf
2010-09-10 10:27 ` [Qemu-devel] [PATCH 3/3] vvfat: Use cache=unsafe Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).