qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block: Fix race in gluster_finish_aiocb
@ 2013-08-21  2:02 Asias He
  2013-08-21  8:16 ` Paolo Bonzini
  2013-08-21 15:24 ` Stefan Hajnoczi
  0 siblings, 2 replies; 22+ messages in thread
From: Asias He @ 2013-08-21  2:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Vijay Bellur, Stefan Hajnoczi, Bharata B Rao,
	Asias He, MORITA Kazutaka

In block/gluster.c, we have

gluster_finish_aiocb
{
   if (retval != sizeof(acb)) {
      qemu_mutex_lock_iothread(); /* We are in gluster thread context */
      ...
      qemu_mutex_unlock_iothread();
   }
}

qemu tools, e.g. qemu-img, might race here because
qemu_mutex_{lock,unlock}_iothread are a nop operation and
gluster_finish_aiocb is in the gluster thread context.

To fix, we introduce our own mutex for qemu tools.

Signed-off-by: Asias He <asias@redhat.com>
---
 stubs/iothread-lock.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/stubs/iothread-lock.c b/stubs/iothread-lock.c
index 5d8aca1..d5c6dec 100644
--- a/stubs/iothread-lock.c
+++ b/stubs/iothread-lock.c
@@ -1,10 +1,21 @@
 #include "qemu-common.h"
 #include "qemu/main-loop.h"
 
+static QemuMutex qemu_tools_mutex;
+static pthread_once_t qemu_tools_once = PTHREAD_ONCE_INIT;
+
+static void qemu_tools_mutex_init(void)
+{
+    qemu_mutex_init(&qemu_tools_mutex);
+}
+
 void qemu_mutex_lock_iothread(void)
 {
+    pthread_once(&qemu_tools_once, qemu_tools_mutex_init);
+    qemu_mutex_lock(&qemu_tools_mutex);
 }
 
 void qemu_mutex_unlock_iothread(void)
 {
+    qemu_mutex_unlock(&qemu_tools_mutex);
 }
-- 
1.8.3.1

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

end of thread, other threads:[~2013-08-23  9:06 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-21  2:02 [Qemu-devel] [PATCH] block: Fix race in gluster_finish_aiocb Asias He
2013-08-21  8:16 ` Paolo Bonzini
2013-08-22  9:50   ` Asias He
2013-08-22  9:51     ` Paolo Bonzini
2013-08-23  8:32       ` Asias He
2013-08-23  9:05         ` Paolo Bonzini
2013-08-21 15:24 ` Stefan Hajnoczi
2013-08-21 15:40   ` Paolo Bonzini
2013-08-22  5:59     ` Bharata B Rao
2013-08-22  7:48       ` Stefan Hajnoczi
2013-08-22  9:06         ` Paolo Bonzini
2013-08-22  9:55           ` Bharata B Rao
2013-08-22 10:00             ` Paolo Bonzini
2013-08-22 10:28               ` Bharata B Rao
2013-08-22 11:15                 ` Paolo Bonzini
2013-08-22 13:25                   ` Bharata B Rao
2013-08-22 13:27                     ` Paolo Bonzini
2013-08-22 14:01                       ` Bharata B Rao
2013-08-22 14:52                         ` Paolo Bonzini
2013-08-23  6:48     ` Bharata B Rao
2013-08-23  7:33       ` Paolo Bonzini
2013-08-23  8:11         ` Bharata B Rao

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