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