aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-07-08 15:21:20 +0100
committerPeter Maydell <peter.maydell@linaro.org>2019-07-08 15:21:20 +0100
commita4efdb6b24dceccd97f0a615a1752eb6fb92d46b (patch)
tree62ff443f3810dfde90b675fe9bdb17da737ecabc /hw
parentdf34fe314b5da628bc9a2664fb1b887bc0a6cc6d (diff)
parentf7077c9860a438087c2d9a8cc27cb8438c98a748 (diff)
downloadqemu-a4efdb6b24dceccd97f0a615a1752eb6fb92d46b.zip
qemu-a4efdb6b24dceccd97f0a615a1752eb6fb92d46b.tar.gz
qemu-a4efdb6b24dceccd97f0a615a1752eb6fb92d46b.tar.bz2
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches: - virtio-scsi: Fix request resubmission after I/O error with iothreads - qcow2: Fix missing v2/v3 subformat aliases for amend - qcow(1): More specific error message for wrong format version - MAINTAINERS: update RBD block maintainer # gpg: Signature made Mon 08 Jul 2019 15:17:27 BST # gpg: using RSA key 7F09B272C88F2FD6 # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * remotes/kevin/tags/for-upstream: qcow2: Allow -o compat=v3 during qemu-img amend MAINTAINERS: update RBD block maintainer block/qcow: Improve error when opening qcow2 files as qcow virtio-scsi: restart DMA after iothread qdev: add qdev_add_vm_change_state_handler() vl: add qemu_add_vm_change_state_handler_prio() Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/core/Makefile.objs1
-rw-r--r--hw/core/vm-change-state-handler.c61
-rw-r--r--hw/scsi/scsi-bus.c4
-rw-r--r--hw/virtio/virtio.c4
4 files changed, 66 insertions, 4 deletions
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index 585b734..f8481d9 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -7,6 +7,7 @@ common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
common-obj-y += irq.o
common-obj-y += hotplug.o
common-obj-$(CONFIG_SOFTMMU) += nmi.o
+common-obj-$(CONFIG_SOFTMMU) += vm-change-state-handler.o
common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
common-obj-$(CONFIG_XILINX_AXI) += stream.o
diff --git a/hw/core/vm-change-state-handler.c b/hw/core/vm-change-state-handler.c
new file mode 100644
index 0000000..f814813
--- /dev/null
+++ b/hw/core/vm-change-state-handler.c
@@ -0,0 +1,61 @@
+/*
+ * qdev vm change state handlers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/qdev.h"
+
+static int qdev_get_dev_tree_depth(DeviceState *dev)
+{
+ int depth;
+
+ for (depth = 0; dev; depth++) {
+ BusState *bus = dev->parent_bus;
+
+ if (!bus) {
+ break;
+ }
+
+ dev = bus->parent;
+ }
+
+ return depth;
+}
+
+/**
+ * qdev_add_vm_change_state_handler:
+ * @dev: the device that owns this handler
+ * @cb: the callback function to be invoked
+ * @opaque: user data passed to the callback function
+ *
+ * This function works like qemu_add_vm_change_state_handler() except callbacks
+ * are invoked in qdev tree depth order. Ordering is desirable when callbacks
+ * of children depend on their parent's callback having completed first.
+ *
+ * For example, when qdev_add_vm_change_state_handler() is used, a host
+ * controller's callback is invoked before the children on its bus when the VM
+ * starts running. The order is reversed when the VM stops running.
+ *
+ * Returns: an entry to be freed with qemu_del_vm_change_state_handler()
+ */
+VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
+ VMChangeStateHandler *cb,
+ void *opaque)
+{
+ int depth = qdev_get_dev_tree_depth(dev);
+
+ return qemu_add_vm_change_state_handler_prio(cb, opaque, depth);
+}
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index 196136a..fdc3a0e 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -207,8 +207,8 @@ static void scsi_qdev_realize(DeviceState *qdev, Error **errp)
error_propagate(errp, local_err);
return;
}
- dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
- dev);
+ dev->vmsentry = qdev_add_vm_change_state_handler(DEVICE(dev),
+ scsi_dma_restart_cb, dev);
}
static void scsi_qdev_unrealize(DeviceState *qdev, Error **errp)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 18f9f4c..a94ea18 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2362,8 +2362,8 @@ void virtio_init(VirtIODevice *vdev, const char *name,
} else {
vdev->config = NULL;
}
- vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
- vdev);
+ vdev->vmstate = qdev_add_vm_change_state_handler(DEVICE(vdev),
+ virtio_vmstate_change, vdev);
vdev->device_endian = virtio_default_endian();
vdev->use_guest_notifier_mask = true;
}