qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Asias He <asias@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Vijay Bellur <vbellur@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	Bharata B Rao <bharata@linux.vnet.ibm.com>,
	MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Subject: Re: [Qemu-devel] [PATCH] block: Fix race in gluster_finish_aiocb
Date: Fri, 23 Aug 2013 16:32:36 +0800	[thread overview]
Message-ID: <20130823083236.GA9717@hj.localdomain> (raw)
In-Reply-To: <5215DF04.3040601@redhat.com>

On Thu, Aug 22, 2013 at 11:51:00AM +0200, Paolo Bonzini wrote:
> Il 22/08/2013 11:50, Asias He ha scritto:
> > On Wed, Aug 21, 2013 at 10:16:02AM +0200, Paolo Bonzini wrote:
> >> Il 21/08/2013 04:02, Asias He ha scritto:
> >>> 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;
> >> 
> >> Doesn't work on Windows, but you can just add
> > 
> > Hmm, Any reasons, why it does not work on Windows?
> 
> There are no pthreads on Windows.
> 
> There is an emulation library, but we're not using it.

This one: http://www.sourceware.org/pthreads-win32 ?

I found other places use pthread_create. e.g.

[qemu]$ git grep pthread_create
audio/audio_pt_int.c:    err = pthread_create (&p->thread, NULL, func,
opaque);
audio/audio_pt_int.c:        efunc = "pthread_create";
clone_func, &info);
qemu-nbd.c:    pthread_create(&show_parts_thread, NULL, show_parts,
device);
qemu-nbd.c:        ret = pthread_create(&client_thread, NULL,
nbd_client_thread, device);

These bits are also not working on Windows?

> >> __attribute__((__constructor__)) to qemu_tools_mutex_init.
> > 
> > __attribute__((__constructor__)) works on Windows?
> 
> Yes, it is part of the runtime library's support for C++.  We use it
> already, see include/qemu/module.h.

Hmm, nice. 

> Paolo
> 
> >> Paolo
> >>
> >>> +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);
> >>>  }
> >>>
> >>
> > 
> 

-- 
Asias

  reply	other threads:[~2013-08-23  8:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130823083236.GA9717@hj.localdomain \
    --to=asias@redhat.com \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=morita.kazutaka@lab.ntt.co.jp \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vbellur@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).