[RFC PATCH 08/10] hw/misc/vmcoreinfo: Implement 'vmcore-info' object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



'vmcore-info' object allow to transition from '-device'
to 'object', following the deprecation process.

No need to modify VMCoreInfoState since DeviceState
already inherits from Object state.

Signed-off-by: Philippe Mathieu-Daudé <philmd@xxxxxxxxxx>
---
 include/hw/misc/vmcoreinfo.h |  4 ++-
 hw/misc/vmcoreinfo.c         | 48 +++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/include/hw/misc/vmcoreinfo.h b/include/hw/misc/vmcoreinfo.h
index 122c69686b0..d4cce42cee6 100644
--- a/include/hw/misc/vmcoreinfo.h
+++ b/include/hw/misc/vmcoreinfo.h
@@ -16,8 +16,10 @@
 #include "standard-headers/linux/qemu_fw_cfg.h"
 #include "qom/object.h"
 
+#define TYPE_VMCOREINFO "vmcore-info"
+OBJECT_DECLARE_SIMPLE_TYPE(VMCoreInfoState, VMCOREINFO)
+
 #define TYPE_VMCOREINFO_DEVICE "vmcoreinfo"
-typedef struct VMCoreInfoState VMCoreInfoState;
 DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO_DEVICE,
                          TYPE_VMCOREINFO_DEVICE)
 
diff --git a/hw/misc/vmcoreinfo.c b/hw/misc/vmcoreinfo.c
index a0511ea0da4..e2258e08fb1 100644
--- a/hw/misc/vmcoreinfo.c
+++ b/hw/misc/vmcoreinfo.c
@@ -12,11 +12,11 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qemu/module.h"
 #include "sysemu/reset.h"
 #include "hw/nvram/fw_cfg.h"
 #include "migration/vmstate.h"
 #include "hw/misc/vmcoreinfo.h"
+#include "qom/object_interfaces.h"
 
 static const VMStateDescription vmstate_vmcoreinfo = {
     .name = "vmcoreinfo",
@@ -32,6 +32,11 @@ static const VMStateDescription vmstate_vmcoreinfo = {
     },
 };
 
+static char *vmcoreinfo_get_vmstate_id(VMStateIf *vmif)
+{
+    return g_strdup(TYPE_VMCOREINFO);
+}
+
 static void fw_cfg_vmci_write(void *opaque, off_t offset, size_t len)
 {
     VMCoreInfoState *s = opaque;
@@ -88,6 +93,32 @@ static void vmcoreinfo_device_realize(DeviceState *dev, Error **errp)
     vmcoreinfo_realize(VMCOREINFO_DEVICE(dev), errp);
 }
 
+static bool vmcoreinfo_can_be_deleted(UserCreatable *uc)
+{
+    return false;
+}
+
+static void vmcoreinfo_complete(UserCreatable *uc, Error **errp)
+{
+    if (vmstate_register_any(VMSTATE_IF(uc), &vmstate_vmcoreinfo, uc) < 0) {
+        error_setg(errp, "%s: Failed to register vmstate", TYPE_VMCOREINFO);
+    }
+
+    vmcoreinfo_realize(VMCOREINFO(uc), errp);
+}
+
+static void vmcoreinfo_class_init(ObjectClass *oc, void *data)
+{
+    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+    VMStateIfClass *vc = VMSTATE_IF_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
+
+    ucc->complete = vmcoreinfo_complete;
+    ucc->can_be_deleted = vmcoreinfo_can_be_deleted;
+    vc->get_id = vmcoreinfo_get_vmstate_id;
+    rc->phases.hold = vmcoreinfo_reset_hold;
+}
+
 static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -106,6 +137,18 @@ static const TypeInfo vmcoreinfo_types[] = {
         .parent         = TYPE_DEVICE,
         .instance_size  = sizeof(VMCoreInfoState),
         .class_init     = vmcoreinfo_device_class_init,
+    },
+    {
+        .name           = TYPE_VMCOREINFO,
+        .parent         = TYPE_OBJECT,
+        .instance_size  = sizeof(VMCoreInfoState),
+        .class_init     = vmcoreinfo_class_init,
+        .interfaces = (InterfaceInfo[]) {
+            { TYPE_RESETTABLE_INTERFACE },
+            { TYPE_USER_CREATABLE },
+            { TYPE_VMSTATE_IF },
+            { }
+        }
     }
 };
 
@@ -116,6 +159,9 @@ VMCoreInfoState *vmcoreinfo_find(void)
     Object *obj;
 
     obj = object_resolve_path_type("", TYPE_VMCOREINFO_DEVICE, NULL);
+    if (!obj) {
+        obj = object_resolve_path_type("", TYPE_VMCOREINFO, NULL);
+    }
 
     return obj ? (VMCoreInfoState *)obj : NULL;
 }
-- 
2.47.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux