From 4d2ffa08b601bdd40d9ccf225480c0a7e90ca078 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sat, 15 May 2010 13:32:40 +0200 Subject: vmstate: Add support for alias ID Some legacy users (mostly PC devices) of vmstate_register manage instance IDs on their own, and that unfortunately in a way that is incompatible with automatically generated ones. This so far prevents switching those users to vmstates that are registered by qdev. To establish a migration path, this patch introduces the concept of alias IDs. They can be passed to an extended vmstate registration service, and qdev provides a set service to be used during device init. find_se will consider the alias in addition to the default ID. We can then start generating the default ID automatically and writing it on vmsave, thus converting that format without breaking support for upward migration. The user is required specify the highest vmstate version for which the alias is required. Once this version falls behind the minimum required for a specific vmstate, an assertion triggers to motivate cleaning up the obsolete alias. Signed-off-by: Jan Kiszka Signed-off-by: Blue Swirl --- hw/qdev.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'hw/qdev.c') diff --git a/hw/qdev.c b/hw/qdev.c index d3bf0fa43d..af17486976 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -93,6 +93,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) assert(bus->allow_hotplug); dev->hotplugged = 1; } + dev->instance_id_alias = -1; dev->state = DEV_STATE_CREATED; return dev; } @@ -278,12 +279,23 @@ int qdev_init(DeviceState *dev) return rc; } qemu_register_reset(qdev_reset, dev); - if (dev->info->vmsd) - vmstate_register(-1, dev->info->vmsd, dev); + if (dev->info->vmsd) { + vmstate_register_with_alias_id(-1, dev->info->vmsd, dev, + dev->instance_id_alias, + dev->alias_required_for_version); + } dev->state = DEV_STATE_INITIALIZED; return 0; } +void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, + int required_for_version) +{ + assert(dev->state == DEV_STATE_CREATED); + dev->instance_id_alias = alias_id; + dev->alias_required_for_version = required_for_version; +} + int qdev_unplug(DeviceState *dev) { if (!dev->parent_bus->allow_hotplug) { -- cgit v1.2.3