qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH] block: asynchronously stop the VM on I/O errors
Date: Tue,  3 Jun 2014 16:16:27 +0200	[thread overview]
Message-ID: <1401804987-31085-1-git-send-email-pbonzini@redhat.com> (raw)

With virtio-blk dataplane, I/O errors might occur while QEMU is
not in the main I/O thread.  However, it's invalid to call vm_stop
when we're neither in a VCPU thread nor in the main I/O thread,
even if we were to take the iothread mutex around it.

To avoid this problem, simply raise a request to the main I/O thread,
similar to what QEMU does when vm_stop is called from a CPU thread.
We know that bdrv_error_action is called from an AIO callback, and
the moment at which the callback will fire is not well-defined; it
depends on the moment at which the disk or OS finishes the operation,
which can happen at any time.

Note that QEMU is certainly not in a CPU thread and we do not need to
call cpu_stop_current() like vm_stop() does.

This makes bdrv_error_action() thread safe.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.c         | 2 +-
 stubs/vm-stop.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index fc2edd3..fa41598 100644
--- a/block.c
+++ b/block.c
@@ -3515,7 +3515,7 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
     assert(error >= 0);
     bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
     if (action == BDRV_ACTION_STOP) {
-        vm_stop(RUN_STATE_IO_ERROR);
+        qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
         bdrv_iostatus_set_err(bs, error);
     }
 }
diff --git a/stubs/vm-stop.c b/stubs/vm-stop.c
index f82c897..7fbeefd 100644
--- a/stubs/vm-stop.c
+++ b/stubs/vm-stop.c
@@ -1,7 +1,7 @@
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
 
-int vm_stop(RunState state)
+void qemu_system_vmstop_request(RunState state)
 {
     abort();
 }
-- 
1.8.3.1

             reply	other threads:[~2014-06-03 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03 14:16 Paolo Bonzini [this message]
2014-06-03 14:37 ` [Qemu-devel] [PATCH] block: asynchronously stop the VM on I/O errors Kevin Wolf
2014-06-03 15:51   ` Paolo Bonzini
2014-06-04  8:28     ` Kevin Wolf
2014-06-04  9:04       ` Paolo Bonzini

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=1401804987-31085-1-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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).