Blame SOURCES/kvm-qdev-add-HotplugHandler-post_plug-callback.patch

1bdc94
From 5cdd4dfafc5280d312001371c6917ccaf2ba06c3 Mon Sep 17 00:00:00 2001
1bdc94
From: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
Date: Tue, 24 Jul 2018 15:13:07 +0200
1bdc94
Subject: [PATCH 08/15] qdev: add HotplugHandler->post_plug() callback
1bdc94
1bdc94
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
Message-id: <20180724151308.20500-2-stefanha@redhat.com>
1bdc94
Patchwork-id: 81485
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 1/2] qdev: add HotplugHandler->post_plug() callback
1bdc94
Bugzilla: 1607891
1bdc94
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
1bdc94
RH-Acked-by: Pankaj Gupta <pagupta@redhat.com>
1bdc94
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
1bdc94
1bdc94
The ->pre_plug() callback is invoked before the device is realized.  The
1bdc94
->plug() callback is invoked when the device is being realized but
1bdc94
before it is reset.
1bdc94
1bdc94
This patch adds a ->post_plug() callback which is invoked after the
1bdc94
device has been reset.  This callback is needed by HotplugHandlers that
1bdc94
need to wait until after ->reset().
1bdc94
1bdc94
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
Message-Id: <20180716083732.3347-2-stefanha@redhat.com>
1bdc94
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1bdc94
(cherry picked from commit 25e8978817a54745c44d956d8303e6be6f2c4047)
1bdc94
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 hw/core/hotplug.c    | 10 ++++++++++
1bdc94
 hw/core/qdev.c       |  4 ++++
1bdc94
 include/hw/hotplug.h | 11 +++++++++++
1bdc94
 3 files changed, 25 insertions(+)
1bdc94
1bdc94
diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c
1bdc94
index 17ac986..2253072 100644
1bdc94
--- a/hw/core/hotplug.c
1bdc94
+++ b/hw/core/hotplug.c
1bdc94
@@ -35,6 +35,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler,
1bdc94
     }
1bdc94
 }
1bdc94
 
1bdc94
+void hotplug_handler_post_plug(HotplugHandler *plug_handler,
1bdc94
+                               DeviceState *plugged_dev)
1bdc94
+{
1bdc94
+    HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
1bdc94
+
1bdc94
+    if (hdc->post_plug) {
1bdc94
+        hdc->post_plug(plug_handler, plugged_dev);
1bdc94
+    }
1bdc94
+}
1bdc94
+
1bdc94
 void hotplug_handler_unplug_request(HotplugHandler *plug_handler,
1bdc94
                                     DeviceState *plugged_dev,
1bdc94
                                     Error **errp)
1bdc94
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
1bdc94
index ce7c316..24f1ae7 100644
1bdc94
--- a/hw/core/qdev.c
1bdc94
+++ b/hw/core/qdev.c
1bdc94
@@ -893,6 +893,10 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
1bdc94
             device_reset(dev);
1bdc94
         }
1bdc94
         dev->pending_deleted_event = false;
1bdc94
+
1bdc94
+        if (hotplug_ctrl) {
1bdc94
+            hotplug_handler_post_plug(hotplug_ctrl, dev);
1bdc94
+        }
1bdc94
     } else if (!value && dev->realized) {
1bdc94
         Error **local_errp = NULL;
1bdc94
         QLIST_FOREACH(bus, &dev->child_bus, sibling) {
1bdc94
diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h
1bdc94
index 1a0516a..51541d6 100644
1bdc94
--- a/include/hw/hotplug.h
1bdc94
+++ b/include/hw/hotplug.h
1bdc94
@@ -47,6 +47,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,
1bdc94
  * @parent: Opaque parent interface.
1bdc94
  * @pre_plug: pre plug callback called at start of device.realize(true)
1bdc94
  * @plug: plug callback called at end of device.realize(true).
1bdc94
+ * @post_plug: post plug callback called after device.realize(true) and device
1bdc94
+ *             reset
1bdc94
  * @unplug_request: unplug request callback.
1bdc94
  *                  Used as a means to initiate device unplug for devices that
1bdc94
  *                  require asynchronous unplug handling.
1bdc94
@@ -61,6 +63,7 @@ typedef struct HotplugHandlerClass {
1bdc94
     /* <public> */
1bdc94
     hotplug_fn pre_plug;
1bdc94
     hotplug_fn plug;
1bdc94
+    void (*post_plug)(HotplugHandler *plug_handler, DeviceState *plugged_dev);
1bdc94
     hotplug_fn unplug_request;
1bdc94
     hotplug_fn unplug;
1bdc94
 } HotplugHandlerClass;
1bdc94
@@ -84,6 +87,14 @@ void hotplug_handler_pre_plug(HotplugHandler *plug_handler,
1bdc94
                               Error **errp);
1bdc94
 
1bdc94
 /**
1bdc94
+ * hotplug_handler_post_plug:
1bdc94
+ *
1bdc94
+ * Call #HotplugHandlerClass.post_plug callback of @plug_handler.
1bdc94
+ */
1bdc94
+void hotplug_handler_post_plug(HotplugHandler *plug_handler,
1bdc94
+                               DeviceState *plugged_dev);
1bdc94
+
1bdc94
+/**
1bdc94
  * hotplug_handler_unplug_request:
1bdc94
  *
1bdc94
  * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94