direct-io.hg

changeset 15392:ea52a66e43a8

hvm: Fix ioemu Qcow support.

Normally by default, SIGUSR2 is not blocked, so the signal masks of
SIGUSR2 in all threads is unblocked.

When creating HVM guest, if we use the Qcow format image file, in the
main thread, Qcow uses SIGUSR2 to be notified of the completion of the
request after it issues an AIO request; in tools/ioemu/block.c:
bdrv_read_em(), in some point between bdrv_aio_read() and
qemu_aio_wait(), Dom0 may send a SIGUSR2 to Qemu immediately to
indicate the completion of an AIO request -- since at the moment
SIGUSR2 in main thread is blocked by qemu_aio_wait_start(), the signal
may be delivered to one non-main thread, causing the signal handler of
SIGUSR2 is invoked, then the main thread hangs in
qemu_aio_wait()->syswait()...

This patch blocks SIGUSR2 at the beginning of Qemu's main(), so it
ensures SIGUSR2 is blocked by default when a new thread is created,
then only the threads that use the signal unblock it.

Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
author kfraser@localhost.localdomain
date Wed Jun 20 14:36:11 2007 +0100 (2007-06-20)
parents fe3df33e2761
children 63077ce6a7dc
files tools/ioemu/block-raw.c tools/ioemu/vl.c
line diff
     1.1 --- a/tools/ioemu/block-raw.c	Wed Jun 20 13:39:54 2007 +0100
     1.2 +++ b/tools/ioemu/block-raw.c	Wed Jun 20 14:36:11 2007 +0100
     1.3 @@ -166,7 +166,7 @@ typedef struct RawAIOCB {
     1.4      struct RawAIOCB *next;
     1.5  } RawAIOCB;
     1.6  
     1.7 -static int aio_sig_num = SIGUSR2;
     1.8 +const int aio_sig_num = SIGUSR2;
     1.9  static RawAIOCB *first_aio; /* AIO issued */
    1.10  static int aio_initialized = 0;
    1.11  
     2.1 --- a/tools/ioemu/vl.c	Wed Jun 20 13:39:54 2007 +0100
     2.2 +++ b/tools/ioemu/vl.c	Wed Jun 20 14:36:11 2007 +0100
     2.3 @@ -7059,6 +7059,18 @@ int main(int argc, char **argv)
     2.4  #endif
     2.5  
     2.6      char qemu_dm_logfilename[128];
     2.7 +    
     2.8 +    /* Ensure that SIGUSR2 is blocked by default when a new thread is created,
     2.9 +       then only the threads that use the signal unblock it -- this fixes a
    2.10 +       race condition in Qcow support where the AIO signal is misdelivered.  */
    2.11 +    {
    2.12 +        extern const int aio_sig_num;
    2.13 +        sigset_t set;
    2.14 +
    2.15 +        sigemptyset(&set);
    2.16 +        sigaddset(&set, aio_sig_num);
    2.17 +        sigprocmask(SIG_BLOCK, &set, NULL);
    2.18 +    }
    2.19  
    2.20      LIST_INIT (&vm_change_state_head);
    2.21  #ifndef _WIN32