From: Gleb Natapov <gleb@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] Fix VM state change handlers running out of order
Date: Wed, 29 Jul 2009 10:27:43 +0300 [thread overview]
Message-ID: <20090729072743.GH30449@redhat.com> (raw)
In-Reply-To: <87y6q8ws5t.fsf_-_@pike.pond.sub.org>
On Tue, Jul 28, 2009 at 02:33:41PM -0400, Markus Armbruster wrote:
> Fix this by moving the actual write from each VM state change handler
> into a new bottom half (suggested by Gleb Natapov).
>
This is exactly what I meant. Thanks.
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Gleb Natapov <gleb@redhat.com>
> ---
> hw/ide.c | 22 +++++++++++++++++++---
> hw/scsi-disk.c | 21 ++++++++++++++++++---
> hw/virtio-blk.c | 20 +++++++++++++++++---
> 3 files changed, 54 insertions(+), 9 deletions(-)
>
> diff --git a/hw/ide.c b/hw/ide.c
> index 1e56786..2eea438 100644
> --- a/hw/ide.c
> +++ b/hw/ide.c
> @@ -501,6 +501,7 @@ typedef struct BMDMAState {
> QEMUIOVector qiov;
> int64_t sector_num;
> uint32_t nsector;
> + QEMUBH *bh;
> } BMDMAState;
>
> typedef struct PCIIDEState {
> @@ -1109,11 +1110,13 @@ static void ide_sector_write(IDEState *s)
> }
> }
>
> -static void ide_dma_restart_cb(void *opaque, int running, int reason)
> +static void ide_dma_restart_bh(void *opaque)
> {
> BMDMAState *bm = opaque;
> - if (!running)
> - return;
> +
> + qemu_bh_delete(bm->bh);
> + bm->bh = NULL;
> +
> if (bm->status & BM_STATUS_DMA_RETRY) {
> bm->status &= ~BM_STATUS_DMA_RETRY;
> ide_dma_restart(bm->ide_if);
> @@ -1123,6 +1126,19 @@ static void ide_dma_restart_cb(void *opaque, int running, int reason)
> }
> }
>
> +static void ide_dma_restart_cb(void *opaque, int running, int reason)
> +{
> + BMDMAState *bm = opaque;
> +
> + if (!running)
> + return;
> +
> + if (!bm->bh) {
> + bm->bh = qemu_bh_new(ide_dma_restart_bh, bm);
> + qemu_bh_schedule(bm->bh);
> + }
> +}
> +
> static void ide_write_dma_cb(void *opaque, int ret)
> {
> BMDMAState *bm = opaque;
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 8b6426f..5b825c9 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -74,6 +74,7 @@ struct SCSIDeviceState
> scsi_completionfn completion;
> void *opaque;
> char drive_serial_str[21];
> + QEMUBH *bh;
> };
>
> /* Global pool of SCSIRequest structures. */
> @@ -308,12 +309,13 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
> return 0;
> }
>
> -static void scsi_dma_restart_cb(void *opaque, int running, int reason)
> +static void scsi_dma_restart_bh(void *opaque)
> {
> SCSIDeviceState *s = opaque;
> SCSIRequest *r = s->requests;
> - if (!running)
> - return;
> +
> + qemu_bh_delete(s->bh);
> + s->bh = NULL;
>
> while (r) {
> if (r->status & SCSI_REQ_STATUS_RETRY) {
> @@ -324,6 +326,19 @@ static void scsi_dma_restart_cb(void *opaque, int running, int reason)
> }
> }
>
> +static void scsi_dma_restart_cb(void *opaque, int running, int reason)
> +{
> + SCSIDeviceState *s = opaque;
> +
> + if (!running)
> + return;
> +
> + if (!s->bh) {
> + s->bh = qemu_bh_new(scsi_dma_restart_bh, s);
> + qemu_bh_schedule(s->bh);
> + }
> +}
> +
> /* Return a pointer to the data buffer. */
> static uint8_t *scsi_get_buf(SCSIDevice *d, uint32_t tag)
> {
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index 2beff52..5036b5b 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -26,6 +26,7 @@ typedef struct VirtIOBlock
> VirtQueue *vq;
> void *rq;
> char serial_str[BLOCK_SERIAL_STRLEN + 1];
> + QEMUBH *bh;
> } VirtIOBlock;
>
> static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
> @@ -302,13 +303,13 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
> */
> }
>
> -static void virtio_blk_dma_restart_cb(void *opaque, int running, int reason)
> +static void virtio_blk_dma_restart_bh(void *opaque)
> {
> VirtIOBlock *s = opaque;
> VirtIOBlockReq *req = s->rq;
>
> - if (!running)
> - return;
> + qemu_bh_delete(s->bh);
> + s->bh = NULL;
>
> s->rq = NULL;
>
> @@ -318,6 +319,19 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running, int reason)
> }
> }
>
> +static void virtio_blk_dma_restart_cb(void *opaque, int running, int reason)
> +{
> + VirtIOBlock *s = opaque;
> +
> + if (!running)
> + return;
> +
> + if (!s->bh) {
> + s->bh = qemu_bh_new(virtio_blk_dma_restart_bh, s);
> + qemu_bh_schedule(s->bh);
> + }
> +}
> +
> static void virtio_blk_reset(VirtIODevice *vdev)
> {
> /*
> --
> 1.6.2.5
--
Gleb.
prev parent reply other threads:[~2009-07-29 7:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-23 21:49 [Qemu-devel] -drive werror=stop can cause state change handlers run out of order Markus Armbruster
2009-07-27 18:44 ` [Qemu-devel] " Markus Armbruster
2009-07-27 18:51 ` Markus Armbruster
2009-07-28 18:33 ` [Qemu-devel] [PATCH] Fix VM state change handlers running " Markus Armbruster
2009-07-29 7:27 ` Gleb Natapov [this message]
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=20090729072743.GH30449@redhat.com \
--to=gleb@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).