qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] block/vdi: Add locking for parallel requests
@ 2015-02-27 14:05 Max Reitz
  2015-02-27 16:57 ` Stefan Hajnoczi
  2015-02-27 17:42 ` Paolo Bonzini
  0 siblings, 2 replies; 20+ messages in thread
From: Max Reitz @ 2015-02-27 14:05 UTC (permalink / raw)
  To: qemu-block
  Cc: Kevin Wolf, qemu-stable, qemu-devel, Max Reitz, Stefan Hajnoczi,
	Paolo Bonzini

Concurrently modifying the bmap does not seem to be a good idea; this patch adds
a lock for it. See https://bugs.launchpad.net/qemu/+bug/1422307 for what
can go wrong without.

Cc: qemu-stable <qemu-stable@nongnu.org>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
v2:
- Make the mutex cover vdi_co_write() completely [Kevin]
- Add a TODO comment [Kevin]
---
 block/vdi.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/block/vdi.c b/block/vdi.c
index 74030c6..f5f42ef 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -51,6 +51,7 @@
 
 #include "qemu-common.h"
 #include "block/block_int.h"
+#include "block/coroutine.h"
 #include "qemu/module.h"
 #include "migration/migration.h"
 
@@ -196,6 +197,8 @@ typedef struct {
     /* VDI header (converted to host endianness). */
     VdiHeader header;
 
+    CoMutex bmap_lock;
+
     Error *migration_blocker;
 } BDRVVdiState;
 
@@ -498,6 +501,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail_free_bmap;
     }
 
+    qemu_co_mutex_init(&s->bmap_lock);
+
     /* Disable migration when vdi images are used */
     error_set(&s->migration_blocker,
               QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
@@ -607,6 +612,9 @@ static int vdi_co_write(BlockDriverState *bs,
 
     logout("\n");
 
+    /* TODO: Figure out why this is necessary */
+    qemu_co_mutex_lock(&s->bmap_lock);
+
     while (ret >= 0 && nb_sectors > 0) {
         block_index = sector_num / s->block_sectors;
         sector_in_block = sector_num % s->block_sectors;
@@ -656,6 +664,7 @@ static int vdi_co_write(BlockDriverState *bs,
 
     logout("finished data write\n");
     if (ret < 0) {
+        qemu_co_mutex_unlock(&s->bmap_lock);
         return ret;
     }
 
@@ -674,6 +683,7 @@ static int vdi_co_write(BlockDriverState *bs,
         block = NULL;
 
         if (ret < 0) {
+            qemu_co_mutex_unlock(&s->bmap_lock);
             return ret;
         }
 
@@ -690,6 +700,7 @@ static int vdi_co_write(BlockDriverState *bs,
         ret = bdrv_write(bs->file, offset, base, n_sectors);
     }
 
+    qemu_co_mutex_unlock(&s->bmap_lock);
     return ret;
 }
 
-- 
2.1.0

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

end of thread, other threads:[~2015-02-27 21:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-27 14:05 [Qemu-devel] [PATCH v2] block/vdi: Add locking for parallel requests Max Reitz
2015-02-27 16:57 ` Stefan Hajnoczi
2015-02-27 16:57   ` Max Reitz
2015-02-27 17:25   ` Stefan Weil
2015-02-27 17:28     ` Max Reitz
2015-02-27 17:34       ` Stefan Weil
2015-02-27 18:07       ` Stefan Weil
2015-02-27 18:09         ` Max Reitz
2015-02-27 18:12           ` Stefan Weil
2015-02-27 18:15             ` Max Reitz
2015-02-27 18:55               ` Max Reitz
2015-02-27 20:21                 ` Stefan Weil
2015-02-27 20:23                   ` Max Reitz
2015-02-27 20:37                     ` Stefan Weil
2015-02-27 17:35     ` Paolo Bonzini
2015-02-27 17:42 ` Paolo Bonzini
2015-02-27 18:09   ` Max Reitz
2015-02-27 18:27     ` Max Reitz
2015-02-27 21:44   ` Stefan Weil
2015-02-27 21:46     ` Max Reitz

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