|
|
383d26 |
From 032fc7e1bc37a62ea45d77be9e96847a58bb25c9 Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
383d26 |
Date: Tue, 16 Jul 2019 13:22:14 +0200
|
|
|
383d26 |
Subject: [PATCH 21/23] qdev: add qdev_add_vm_change_state_handler()
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
383d26 |
Message-id: <20190716132215.18503-3-stefanha@redhat.com>
|
|
|
383d26 |
Patchwork-id: 89537
|
|
|
383d26 |
O-Subject: [RHEL-7.8 RHEL-7.7.z qemu-kvm-rhev PATCH 2/3] qdev: add qdev_add_vm_change_state_handler()
|
|
|
383d26 |
Bugzilla: 1673546
|
|
|
383d26 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
383d26 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
Children sometimes depend on their parent's vm change state handler
|
|
|
383d26 |
having completed. Add a vm change state handler API for devices that
|
|
|
383d26 |
guarantees tree depth ordering.
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
383d26 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
(cherry picked from commit e965ffa70ac8ddc334dd5990f6907789bd9e6af6)
|
|
|
383d26 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
---
|
|
|
383d26 |
hw/core/Makefile.objs | 1 +
|
|
|
383d26 |
hw/core/vm-change-state-handler.c | 61 +++++++++++++++++++++++++++++++++++++++
|
|
|
383d26 |
include/hw/qdev-core.h | 5 ++++
|
|
|
383d26 |
3 files changed, 67 insertions(+)
|
|
|
383d26 |
create mode 100644 hw/core/vm-change-state-handler.c
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
|
|
|
383d26 |
index e967fb2..28531b0 100644
|
|
|
383d26 |
--- a/hw/core/Makefile.objs
|
|
|
383d26 |
+++ b/hw/core/Makefile.objs
|
|
|
383d26 |
@@ -7,6 +7,7 @@ common-obj-$(CONFIG_SOFTMMU) += fw-path-provider.o
|
|
|
383d26 |
common-obj-y += irq.o
|
|
|
383d26 |
common-obj-y += hotplug.o
|
|
|
383d26 |
common-obj-$(CONFIG_SOFTMMU) += nmi.o
|
|
|
383d26 |
+common-obj-$(CONFIG_SOFTMMU) += vm-change-state-handler.o
|
|
|
383d26 |
|
|
|
383d26 |
common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
|
|
|
383d26 |
common-obj-$(CONFIG_XILINX_AXI) += stream.o
|
|
|
383d26 |
diff --git a/hw/core/vm-change-state-handler.c b/hw/core/vm-change-state-handler.c
|
|
|
383d26 |
new file mode 100644
|
|
|
383d26 |
index 0000000..f814813
|
|
|
383d26 |
--- /dev/null
|
|
|
383d26 |
+++ b/hw/core/vm-change-state-handler.c
|
|
|
383d26 |
@@ -0,0 +1,61 @@
|
|
|
383d26 |
+/*
|
|
|
383d26 |
+ * qdev vm change state handlers
|
|
|
383d26 |
+ *
|
|
|
383d26 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
383d26 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
383d26 |
+ * the Free Software Foundation; either version 2 of the License,
|
|
|
383d26 |
+ * or (at your option) any later version.
|
|
|
383d26 |
+ *
|
|
|
383d26 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
383d26 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
383d26 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
383d26 |
+ * GNU General Public License for more details.
|
|
|
383d26 |
+ *
|
|
|
383d26 |
+ * You should have received a copy of the GNU General Public License
|
|
|
383d26 |
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
383d26 |
+ */
|
|
|
383d26 |
+
|
|
|
383d26 |
+#include "qemu/osdep.h"
|
|
|
383d26 |
+#include "hw/qdev.h"
|
|
|
383d26 |
+
|
|
|
383d26 |
+static int qdev_get_dev_tree_depth(DeviceState *dev)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ int depth;
|
|
|
383d26 |
+
|
|
|
383d26 |
+ for (depth = 0; dev; depth++) {
|
|
|
383d26 |
+ BusState *bus = dev->parent_bus;
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if (!bus) {
|
|
|
383d26 |
+ break;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ dev = bus->parent;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ return depth;
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+/**
|
|
|
383d26 |
+ * qdev_add_vm_change_state_handler:
|
|
|
383d26 |
+ * @dev: the device that owns this handler
|
|
|
383d26 |
+ * @cb: the callback function to be invoked
|
|
|
383d26 |
+ * @opaque: user data passed to the callback function
|
|
|
383d26 |
+ *
|
|
|
383d26 |
+ * This function works like qemu_add_vm_change_state_handler() except callbacks
|
|
|
383d26 |
+ * are invoked in qdev tree depth order. Ordering is desirable when callbacks
|
|
|
383d26 |
+ * of children depend on their parent's callback having completed first.
|
|
|
383d26 |
+ *
|
|
|
383d26 |
+ * For example, when qdev_add_vm_change_state_handler() is used, a host
|
|
|
383d26 |
+ * controller's callback is invoked before the children on its bus when the VM
|
|
|
383d26 |
+ * starts running. The order is reversed when the VM stops running.
|
|
|
383d26 |
+ *
|
|
|
383d26 |
+ * Returns: an entry to be freed with qemu_del_vm_change_state_handler()
|
|
|
383d26 |
+ */
|
|
|
383d26 |
+VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
|
|
|
383d26 |
+ VMChangeStateHandler *cb,
|
|
|
383d26 |
+ void *opaque)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ int depth = qdev_get_dev_tree_depth(dev);
|
|
|
383d26 |
+
|
|
|
383d26 |
+ return qemu_add_vm_change_state_handler_prio(cb, opaque, depth);
|
|
|
383d26 |
+}
|
|
|
383d26 |
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
|
|
|
383d26 |
index 9453588..ff8bd5a 100644
|
|
|
383d26 |
--- a/include/hw/qdev-core.h
|
|
|
383d26 |
+++ b/include/hw/qdev-core.h
|
|
|
383d26 |
@@ -6,6 +6,7 @@
|
|
|
383d26 |
#include "qom/object.h"
|
|
|
383d26 |
#include "hw/irq.h"
|
|
|
383d26 |
#include "hw/hotplug.h"
|
|
|
383d26 |
+#include "sysemu/sysemu.h"
|
|
|
383d26 |
|
|
|
383d26 |
enum {
|
|
|
383d26 |
DEV_NVECTORS_UNSPECIFIED = -1,
|
|
|
383d26 |
@@ -446,4 +447,8 @@ static inline bool qbus_is_hotpluggable(BusState *bus)
|
|
|
383d26 |
void device_listener_register(DeviceListener *listener);
|
|
|
383d26 |
void device_listener_unregister(DeviceListener *listener);
|
|
|
383d26 |
|
|
|
383d26 |
+VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
|
|
|
383d26 |
+ VMChangeStateHandler *cb,
|
|
|
383d26 |
+ void *opaque);
|
|
|
383d26 |
+
|
|
|
383d26 |
#endif
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|