vmstate: replace DeviceState with VMStateIf

Replace DeviceState dependency with VMStateIf on vmstate API.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Acked-by: Halil Pasic <pasic@linux.ibm.com>
This commit is contained in:
Marc-André Lureau 2019-08-28 16:02:32 +04:00
parent 107b59698f
commit 3cad405bab
17 changed files with 41 additions and 38 deletions

View File

@ -822,7 +822,7 @@ static void onenand_realize(DeviceState *dev, Error **errp)
onenand_mem_setup(s); onenand_mem_setup(s);
sysbus_init_irq(sbd, &s->intr); sysbus_init_irq(sbd, &s->intr);
sysbus_init_mmio(sbd, &s->container); sysbus_init_mmio(sbd, &s->container);
vmstate_register(dev, vmstate_register(VMSTATE_IF(dev),
((s->shift & 0x7f) << 24) ((s->shift & 0x7f) << 24)
| ((s->id.man & 0xff) << 16) | ((s->id.man & 0xff) << 16)
| ((s->id.dev & 0xff) << 8) | ((s->id.dev & 0xff) << 8)

View File

@ -889,7 +889,8 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
dev->canonical_path = object_get_canonical_path(OBJECT(dev)); dev->canonical_path = object_get_canonical_path(OBJECT(dev));
if (qdev_get_vmsd(dev)) { if (qdev_get_vmsd(dev)) {
if (vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev, if (vmstate_register_with_alias_id(VMSTATE_IF(dev),
-1, qdev_get_vmsd(dev), dev,
dev->instance_id_alias, dev->instance_id_alias,
dev->alias_required_for_version, dev->alias_required_for_version,
&local_err) < 0) { &local_err) < 0) {
@ -923,7 +924,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
local_err ? NULL : &local_err); local_err ? NULL : &local_err);
} }
if (qdev_get_vmsd(dev)) { if (qdev_get_vmsd(dev)) {
vmstate_unregister(dev, qdev_get_vmsd(dev), dev); vmstate_unregister(VMSTATE_IF(dev), qdev_get_vmsd(dev), dev);
} }
if (dc->unrealize) { if (dc->unrealize) {
dc->unrealize(dev, local_err ? NULL : &local_err); dc->unrealize(dev, local_err ? NULL : &local_err);
@ -947,7 +948,7 @@ child_realize_fail:
} }
if (qdev_get_vmsd(dev)) { if (qdev_get_vmsd(dev)) {
vmstate_unregister(dev, qdev_get_vmsd(dev), dev); vmstate_unregister(VMSTATE_IF(dev), qdev_get_vmsd(dev), dev);
} }
post_realize_fail: post_realize_fail:

View File

@ -302,7 +302,7 @@ static void pci_cmd646_ide_realize(PCIDevice *dev, Error **errp)
} }
g_free(irq); g_free(irq);
vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d); vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
qemu_register_reset(cmd646_reset, d); qemu_register_reset(cmd646_reset, d);
} }

View File

@ -75,7 +75,7 @@ static void isa_ide_realizefn(DeviceState *dev, Error **errp)
ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2); ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
isa_init_irq(isadev, &s->irq, s->isairq); isa_init_irq(isadev, &s->irq, s->isairq);
ide_init2(&s->bus, s->irq); ide_init2(&s->bus, s->irq);
vmstate_register(dev, 0, &vmstate_ide_isa, s); vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_isa, s);
ide_register_restart_cb(&s->bus); ide_register_restart_cb(&s->bus);
} }

View File

@ -156,7 +156,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
bmdma_setup_bar(d); bmdma_setup_bar(d);
pci_register_bar(dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &d->bmdma_bar); pci_register_bar(dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &d->bmdma_bar);
vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d); vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
pci_piix_init_ports(d); pci_piix_init_ports(d);
} }

View File

@ -190,7 +190,7 @@ static void via_ide_realize(PCIDevice *dev, Error **errp)
bmdma_setup_bar(d); bmdma_setup_bar(d);
pci_register_bar(dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &d->bmdma_bar); pci_register_bar(dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &d->bmdma_bar);
vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d); vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
ide_bus_new(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2); ide_bus_new(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);

View File

@ -146,7 +146,7 @@ static int max111x_init(SSISlave *d, int inputs)
s->input[7] = 0x80; s->input[7] = 0x80;
s->com = 0; s->com = 0;
vmstate_register(dev, -1, &vmstate_max111x, s); vmstate_register(VMSTATE_IF(dev), -1, &vmstate_max111x, s);
return 0; return 0;
} }

View File

@ -1815,7 +1815,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
{ {
EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
vmstate_unregister(&pci_dev->qdev, s->vmstate, s); vmstate_unregister(VMSTATE_IF(&pci_dev->qdev), s->vmstate, s);
g_free(s->vmstate); g_free(s->vmstate);
eeprom93xx_free(&pci_dev->qdev, s->eeprom); eeprom93xx_free(&pci_dev->qdev, s->eeprom);
qemu_del_nic(s->nic); qemu_del_nic(s->nic);
@ -1874,7 +1874,7 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp)
s->vmstate = g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100)); s->vmstate = g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100));
s->vmstate->name = qemu_get_queue(s->nic)->model; s->vmstate->name = qemu_get_queue(s->nic)->model;
vmstate_register(&pci_dev->qdev, -1, s->vmstate, s); vmstate_register(VMSTATE_IF(&pci_dev->qdev), -1, s->vmstate, s);
} }
static void eepro100_instance_init(Object *obj) static void eepro100_instance_init(Object *obj)

View File

@ -2853,7 +2853,8 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
if (migration_in_setup(s) && !should_be_hidden) { if (migration_in_setup(s) && !should_be_hidden) {
if (failover_unplug_primary(n)) { if (failover_unplug_primary(n)) {
vmstate_unregister(n->primary_dev, qdev_get_vmsd(n->primary_dev), vmstate_unregister(VMSTATE_IF(n->primary_dev),
qdev_get_vmsd(n->primary_dev),
n->primary_dev); n->primary_dev);
qapi_event_send_unplug_primary(n->primary_device_id); qapi_event_send_unplug_primary(n->primary_device_id);
atomic_set(&n->primary_should_be_hidden, true); atomic_set(&n->primary_should_be_hidden, true);

View File

@ -321,7 +321,7 @@ eeprom_t *eeprom93xx_new(DeviceState *dev, uint16_t nwords)
/* Output DO is tristate, read results in 1. */ /* Output DO is tristate, read results in 1. */
eeprom->eedo = 1; eeprom->eedo = 1;
logout("eeprom = 0x%p, nwords = %u\n", eeprom, nwords); logout("eeprom = 0x%p, nwords = %u\n", eeprom, nwords);
vmstate_register(dev, 0, &vmstate_eeprom, eeprom); vmstate_register(VMSTATE_IF(dev), 0, &vmstate_eeprom, eeprom);
return eeprom; return eeprom;
} }
@ -329,7 +329,7 @@ void eeprom93xx_free(DeviceState *dev, eeprom_t *eeprom)
{ {
/* Destroy EEPROM. */ /* Destroy EEPROM. */
logout("eeprom = 0x%p\n", eeprom); logout("eeprom = 0x%p\n", eeprom);
vmstate_unregister(dev, &vmstate_eeprom, eeprom); vmstate_unregister(VMSTATE_IF(dev), &vmstate_eeprom, eeprom);
g_free(eeprom); g_free(eeprom);
} }

View File

@ -511,7 +511,7 @@ static void realize(DeviceState *d, Error **errp)
error_propagate(errp, err); error_propagate(errp, err);
return; return;
} }
vmstate_register(DEVICE(drc), spapr_drc_index(drc), &vmstate_spapr_drc, vmstate_register(VMSTATE_IF(drc), spapr_drc_index(drc), &vmstate_spapr_drc,
drc); drc);
trace_spapr_drc_realize_complete(spapr_drc_index(drc)); trace_spapr_drc_realize_complete(spapr_drc_index(drc));
} }
@ -523,7 +523,7 @@ static void unrealize(DeviceState *d, Error **errp)
gchar *name; gchar *name;
trace_spapr_drc_unrealize(spapr_drc_index(drc)); trace_spapr_drc_unrealize(spapr_drc_index(drc));
vmstate_unregister(DEVICE(drc), &vmstate_spapr_drc, drc); vmstate_unregister(VMSTATE_IF(drc), &vmstate_spapr_drc, drc);
root_container = container_get(object_get_root(), DRC_CONTAINER_PATH); root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
name = g_strdup_printf("%x", spapr_drc_index(drc)); name = g_strdup_printf("%x", spapr_drc_index(drc));
object_property_del(root_container, name, errp); object_property_del(root_container, name, errp);
@ -619,7 +619,8 @@ static void realize_physical(DeviceState *d, Error **errp)
return; return;
} }
vmstate_register(DEVICE(drcp), spapr_drc_index(SPAPR_DR_CONNECTOR(drcp)), vmstate_register(VMSTATE_IF(drcp),
spapr_drc_index(SPAPR_DR_CONNECTOR(drcp)),
&vmstate_spapr_drc_physical, drcp); &vmstate_spapr_drc_physical, drcp);
qemu_register_reset(drc_physical_reset, drcp); qemu_register_reset(drc_physical_reset, drcp);
} }
@ -635,7 +636,7 @@ static void unrealize_physical(DeviceState *d, Error **errp)
return; return;
} }
vmstate_unregister(DEVICE(drcp), &vmstate_spapr_drc_physical, drcp); vmstate_unregister(VMSTATE_IF(drcp), &vmstate_spapr_drc_physical, drcp);
qemu_unregister_reset(drc_physical_reset, drcp); qemu_unregister_reset(drc_physical_reset, drcp);
} }

View File

@ -317,7 +317,7 @@ static void spapr_tce_table_realize(DeviceState *dev, Error **errp)
QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list); QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list);
vmstate_register(DEVICE(tcet), tcet->liobn, &vmstate_spapr_tce_table, vmstate_register(VMSTATE_IF(tcet), tcet->liobn, &vmstate_spapr_tce_table,
tcet); tcet);
} }
@ -420,7 +420,7 @@ static void spapr_tce_table_unrealize(DeviceState *dev, Error **errp)
{ {
SpaprTceTable *tcet = SPAPR_TCE_TABLE(dev); SpaprTceTable *tcet = SPAPR_TCE_TABLE(dev);
vmstate_unregister(DEVICE(tcet), &vmstate_spapr_tce_table, tcet); vmstate_unregister(VMSTATE_IF(tcet), &vmstate_spapr_tce_table, tcet);
QLIST_REMOVE(tcet, list); QLIST_REMOVE(tcet, list);

View File

@ -392,7 +392,7 @@ static inline void s390_skeys_set_migration_enabled(Object *obj, bool value,
register_savevm_live(TYPE_S390_SKEYS, 0, 1, register_savevm_live(TYPE_S390_SKEYS, 0, 1,
&savevm_s390_storage_keys, ss); &savevm_s390_storage_keys, ss);
} else { } else {
unregister_savevm(DEVICE(ss), TYPE_S390_SKEYS, ss); unregister_savevm(VMSTATE_IF(ss), TYPE_S390_SKEYS, ss);
} }
} }

View File

@ -76,6 +76,6 @@ int register_savevm_live(const char *idstr,
const SaveVMHandlers *ops, const SaveVMHandlers *ops,
void *opaque); void *opaque);
void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque); void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque);
#endif #endif

View File

@ -1158,22 +1158,22 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
/* Returns: 0 on success, -1 on failure */ /* Returns: 0 on success, -1 on failure */
int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, int vmstate_register_with_alias_id(VMStateIf *obj, int instance_id,
const VMStateDescription *vmsd, const VMStateDescription *vmsd,
void *base, int alias_id, void *base, int alias_id,
int required_for_version, int required_for_version,
Error **errp); Error **errp);
/* Returns: 0 on success, -1 on failure */ /* Returns: 0 on success, -1 on failure */
static inline int vmstate_register(DeviceState *dev, int instance_id, static inline int vmstate_register(VMStateIf *obj, int instance_id,
const VMStateDescription *vmsd, const VMStateDescription *vmsd,
void *opaque) void *opaque)
{ {
return vmstate_register_with_alias_id(dev, instance_id, vmsd, return vmstate_register_with_alias_id(obj, instance_id, vmsd,
opaque, -1, 0, NULL); opaque, -1, 0, NULL);
} }
void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd,
void *opaque); void *opaque);
struct MemoryRegion; struct MemoryRegion;

View File

@ -760,17 +760,17 @@ int register_savevm_live(const char *idstr,
return 0; return 0;
} }
void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque)
{ {
SaveStateEntry *se, *new_se; SaveStateEntry *se, *new_se;
char id[256] = ""; char id[256] = "";
if (dev) { if (obj) {
char *path = qdev_get_dev_path(dev); char *oid = vmstate_if_get_id(obj);
if (path) { if (oid) {
pstrcpy(id, sizeof(id), path); pstrcpy(id, sizeof(id), oid);
pstrcat(id, sizeof(id), "/"); pstrcat(id, sizeof(id), "/");
g_free(path); g_free(oid);
} }
} }
pstrcat(id, sizeof(id), idstr); pstrcat(id, sizeof(id), idstr);
@ -784,7 +784,7 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)
} }
} }
int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, int vmstate_register_with_alias_id(VMStateIf *obj, int instance_id,
const VMStateDescription *vmsd, const VMStateDescription *vmsd,
void *opaque, int alias_id, void *opaque, int alias_id,
int required_for_version, int required_for_version,
@ -802,8 +802,8 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
se->vmsd = vmsd; se->vmsd = vmsd;
se->alias_id = alias_id; se->alias_id = alias_id;
if (dev) { if (obj) {
char *id = qdev_get_dev_path(dev); char *id = vmstate_if_get_id(obj);
if (id) { if (id) {
if (snprintf(se->idstr, sizeof(se->idstr), "%s/", id) >= if (snprintf(se->idstr, sizeof(se->idstr), "%s/", id) >=
sizeof(se->idstr)) { sizeof(se->idstr)) {
@ -834,7 +834,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
return 0; return 0;
} }
void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd,
void *opaque) void *opaque)
{ {
SaveStateEntry *se, *new_se; SaveStateEntry *se, *new_se;

View File

@ -3,7 +3,7 @@
const VMStateDescription vmstate_dummy = {}; const VMStateDescription vmstate_dummy = {};
int vmstate_register_with_alias_id(DeviceState *dev, int vmstate_register_with_alias_id(VMStateIf *obj,
int instance_id, int instance_id,
const VMStateDescription *vmsd, const VMStateDescription *vmsd,
void *base, int alias_id, void *base, int alias_id,
@ -13,7 +13,7 @@ int vmstate_register_with_alias_id(DeviceState *dev,
return 0; return 0;
} }
void vmstate_unregister(DeviceState *dev, void vmstate_unregister(VMStateIf *obj,
const VMStateDescription *vmsd, const VMStateDescription *vmsd,
void *opaque) void *opaque)
{ {