From 1dfb4dd993f7122353fb2894f09dfcba894cd7d5 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Fri, 29 Jul 2011 14:26:33 -0300 Subject: Replace the VMSTOP macros with a proper state type Today, when notifying a VM state change with vm_state_notify(), we pass a VMSTOP macro as the 'reason' argument. This is not ideal because the VMSTOP macros tell why qemu stopped and not exactly what the current VM state is. One example to demonstrate this problem is that vm_start() calls vm_state_notify() with reason=0, which turns out to be VMSTOP_USER. This commit fixes that by replacing the VMSTOP macros with a proper state type called RunState. Signed-off-by: Luiz Capitulino --- hw/ide/ahci.c | 2 +- hw/ide/core.c | 4 ++-- hw/ide/internal.h | 3 ++- hw/ide/pci.c | 2 +- hw/kvmclock.c | 3 ++- hw/qxl.c | 5 +++-- hw/scsi-disk.c | 4 ++-- hw/virtio-blk.c | 5 +++-- hw/virtio.c | 2 +- hw/watchdog.c | 2 +- 10 files changed, 18 insertions(+), 14 deletions(-) (limited to 'hw') diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index a8659cf8b9..b8132369ad 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1103,7 +1103,7 @@ static void ahci_irq_set(void *opaque, int n, int level) { } -static void ahci_dma_restart_cb(void *opaque, int running, int reason) +static void ahci_dma_restart_cb(void *opaque, int running, RunState state) { } diff --git a/hw/ide/core.c b/hw/ide/core.c index 9297b9e657..4d5a076ad2 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -527,7 +527,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op) s->bus->dma->ops->set_unit(s->bus->dma, s->unit); s->bus->error_status = op; bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read); - vm_stop(VMSTOP_DISKFULL); + vm_stop(RSTATE_IO_ERROR); } else { if (op & BM_STATUS_DMA_RETRY) { dma_buf_commit(s, 0); @@ -1910,7 +1910,7 @@ static int ide_nop_int(IDEDMA *dma, int x) return 0; } -static void ide_nop_restart(void *opaque, int x, int y) +static void ide_nop_restart(void *opaque, int x, RunState y) { } diff --git a/hw/ide/internal.h b/hw/ide/internal.h index 233915ce0d..9046e96013 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -9,6 +9,7 @@ #include #include "iorange.h" #include "dma.h" +#include "sysemu.h" /* debug IDE devices */ //#define DEBUG_IDE @@ -387,7 +388,7 @@ typedef void EndTransferFunc(IDEState *); typedef void DMAStartFunc(IDEDMA *, IDEState *, BlockDriverCompletionFunc *); typedef int DMAFunc(IDEDMA *); typedef int DMAIntFunc(IDEDMA *, int); -typedef void DMARestartFunc(void *, int, int); +typedef void DMARestartFunc(void *, int, RunState); struct unreported_events { bool eject_request; diff --git a/hw/ide/pci.c b/hw/ide/pci.c index 9fded02954..f133c422b6 100644 --- a/hw/ide/pci.c +++ b/hw/ide/pci.c @@ -222,7 +222,7 @@ static void bmdma_restart_bh(void *opaque) } } -static void bmdma_restart_cb(void *opaque, int running, int reason) +static void bmdma_restart_cb(void *opaque, int running, RunState state) { IDEDMA *dma = opaque; BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma); diff --git a/hw/kvmclock.c b/hw/kvmclock.c index b73aec409c..88961be42b 100644 --- a/hw/kvmclock.c +++ b/hw/kvmclock.c @@ -59,7 +59,8 @@ static int kvmclock_post_load(void *opaque, int version_id) return kvm_vm_ioctl(kvm_state, KVM_SET_CLOCK, &data); } -static void kvmclock_vm_state_change(void *opaque, int running, int reason) +static void kvmclock_vm_state_change(void *opaque, int running, + RunState state) { KVMClockState *s = opaque; diff --git a/hw/qxl.c b/hw/qxl.c index a282d2396b..6db2f1a466 100644 --- a/hw/qxl.c +++ b/hw/qxl.c @@ -1453,10 +1453,11 @@ static void qxl_hw_text_update(void *opaque, console_ch_t *chardata) } } -static void qxl_vm_change_state_handler(void *opaque, int running, int reason) +static void qxl_vm_change_state_handler(void *opaque, int running, + RunState state) { PCIQXLDevice *qxl = opaque; - qemu_spice_vm_change_state_handler(&qxl->ssd, running, reason); + qemu_spice_vm_change_state_handler(&qxl->ssd, running, state); if (running) { /* diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 4a60820b18..96c554fe29 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -217,7 +217,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type) r->status |= SCSI_REQ_STATUS_RETRY | type; bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read); - vm_stop(VMSTOP_DISKFULL); + vm_stop(RSTATE_IO_ERROR); } else { switch (error) { case ENOMEM: @@ -338,7 +338,7 @@ static void scsi_dma_restart_bh(void *opaque) } } -static void scsi_dma_restart_cb(void *opaque, int running, int reason) +static void scsi_dma_restart_cb(void *opaque, int running, RunState state) { SCSIDiskState *s = opaque; diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index c2ee0001eb..daa8e42be7 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -77,7 +77,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, req->next = s->rq; s->rq = req; bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read); - vm_stop(VMSTOP_DISKFULL); + vm_stop(RSTATE_IO_ERROR); } else { virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); bdrv_acct_done(s->bs, &req->acct); @@ -439,7 +439,8 @@ static void virtio_blk_dma_restart_bh(void *opaque) virtio_submit_multiwrite(s->bs, &mrb); } -static void virtio_blk_dma_restart_cb(void *opaque, int running, int reason) +static void virtio_blk_dma_restart_cb(void *opaque, int running, + RunState state) { VirtIOBlock *s = opaque; diff --git a/hw/virtio.c b/hw/virtio.c index 13aa0faf27..74ab79e6b5 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -837,7 +837,7 @@ void virtio_cleanup(VirtIODevice *vdev) g_free(vdev); } -static void virtio_vmstate_change(void *opaque, int running, int reason) +static void virtio_vmstate_change(void *opaque, int running, RunState state) { VirtIODevice *vdev = opaque; bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK); diff --git a/hw/watchdog.c b/hw/watchdog.c index 1c900a1189..71c6c7df63 100644 --- a/hw/watchdog.c +++ b/hw/watchdog.c @@ -132,7 +132,7 @@ void watchdog_perform_action(void) case WDT_PAUSE: /* same as 'stop' command in monitor */ watchdog_mon_event("pause"); - vm_stop(VMSTOP_WATCHDOG); + vm_stop(RSTATE_WATCHDOG); break; case WDT_DEBUG: -- cgit v1.2.3 From 1354869c380cf4560fa3f0520e914cb5ee380ac8 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Fri, 29 Jul 2011 15:36:43 -0300 Subject: Drop the vm_running global variable Use runstate_is_running() instead, which is introduced by this commit. Signed-off-by: Luiz Capitulino --- hw/etraxfs_dma.c | 2 +- hw/kvmclock.c | 2 +- hw/virtio.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'hw') diff --git a/hw/etraxfs_dma.c b/hw/etraxfs_dma.c index e8ad9e6a0b..d3082acc8f 100644 --- a/hw/etraxfs_dma.c +++ b/hw/etraxfs_dma.c @@ -732,7 +732,7 @@ static void DMA_run(void *opaque) struct fs_dma_ctrl *etraxfs_dmac = opaque; int p = 1; - if (vm_running) + if (runstate_is_running()) p = etraxfs_dmac_run(etraxfs_dmac); if (p) diff --git a/hw/kvmclock.c b/hw/kvmclock.c index 88961be42b..5388bc489d 100644 --- a/hw/kvmclock.c +++ b/hw/kvmclock.c @@ -46,7 +46,7 @@ static void kvmclock_pre_save(void *opaque) * it on next vmsave (which would return a different value). Will be reset * when the VM is continued. */ - s->clock_valid = !vm_running; + s->clock_valid = !runstate_is_running(); } static int kvmclock_post_load(void *opaque, int version_id) diff --git a/hw/virtio.c b/hw/virtio.c index 74ab79e6b5..c577bbe483 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -870,7 +870,7 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id, vdev->queue_sel = 0; vdev->config_vector = VIRTIO_NO_VECTOR; vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX); - vdev->vm_running = vm_running; + vdev->vm_running = runstate_is_running(); for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) { vdev->vq[i].vector = VIRTIO_NO_VECTOR; vdev->vq[i].vdev = vdev; -- cgit v1.2.3