Blame SOURCES/kvm-qdev-add-qdev_add_vm_change_state_handler.patch

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