vmstate: add qom interface to get id

Add an interface to get the instance id, instead of depending on
Device and qdev_get_dev_path().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
This commit is contained in:
Marc-André Lureau 2019-08-28 16:00:19 +04:00
parent b0b74e1f17
commit 107b59698f
8 changed files with 85 additions and 0 deletions

View file

@ -9,6 +9,7 @@ common-obj-y += hotplug.o
common-obj-$(CONFIG_SOFTMMU) += nmi.o
common-obj-$(CONFIG_SOFTMMU) += vm-change-state-handler.o
common-obj-y += cpu.o
common-obj-y += vmstate-if.o
common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
common-obj-$(CONFIG_XILINX_AXI) += stream.o

View file

@ -1087,9 +1087,18 @@ static void device_unparent(Object *obj)
}
}
static char *
device_vmstate_if_get_id(VMStateIf *obj)
{
DeviceState *dev = DEVICE(obj);
return qdev_get_dev_path(dev);
}
static void device_class_init(ObjectClass *class, void *data)
{
DeviceClass *dc = DEVICE_CLASS(class);
VMStateIfClass *vc = VMSTATE_IF_CLASS(class);
class->unparent = device_unparent;
@ -1101,6 +1110,7 @@ static void device_class_init(ObjectClass *class, void *data)
*/
dc->hotpluggable = true;
dc->user_creatable = true;
vc->get_id = device_vmstate_if_get_id;
}
void device_class_set_parent_reset(DeviceClass *dc,
@ -1158,6 +1168,10 @@ static const TypeInfo device_type_info = {
.class_init = device_class_init,
.abstract = true,
.class_size = sizeof(DeviceClass),
.interfaces = (InterfaceInfo[]) {
{ TYPE_VMSTATE_IF },
{ }
}
};
static void qdev_register_types(void)

23
hw/core/vmstate-if.c Normal file
View file

@ -0,0 +1,23 @@
/*
* VMState interface
*
* Copyright (c) 2009-2019 Red Hat Inc
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include "qemu/osdep.h"
#include "hw/vmstate-if.h"
static const TypeInfo vmstate_if_info = {
.name = TYPE_VMSTATE_IF,
.parent = TYPE_INTERFACE,
.class_size = sizeof(VMStateIfClass),
};
static void vmstate_register_types(void)
{
type_register_static(&vmstate_if_info);
}
type_init(vmstate_register_types);