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 --- savevm.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'savevm.c') diff --git a/savevm.c b/savevm.c index 74e553c..dc20390 100644 --- a/savevm.c +++ b/savevm.c @@ -991,6 +991,7 @@ typedef struct SaveStateEntry { QTAILQ_ENTRY(SaveStateEntry) entry; char idstr[256]; int instance_id; + int alias_id; int version_id; int section_id; SaveSetParamsHandler *set_params; @@ -1079,11 +1080,16 @@ void unregister_savevm(const char *idstr, void *opaque) } } -int vmstate_register(int instance_id, const VMStateDescription *vmsd, - void *opaque) +int vmstate_register_with_alias_id(int instance_id, + const VMStateDescription *vmsd, + void *opaque, int alias_id, + int required_for_version) { SaveStateEntry *se; + /* If this triggers, alias support can be dropped for the vmsd. */ + assert(alias_id == -1 || required_for_version >= vmsd->minimum_version_id); + se = qemu_mallocz(sizeof(SaveStateEntry)); pstrcpy(se->idstr, sizeof(se->idstr), vmsd->name); se->version_id = vmsd->version_id; @@ -1093,6 +1099,7 @@ int vmstate_register(int instance_id, const VMStateDescription *vmsd, se->load_state = NULL; se->opaque = opaque; se->vmsd = vmsd; + se->alias_id = alias_id; if (instance_id == -1) { se->instance_id = calculate_new_instance_id(vmsd->name); @@ -1104,6 +1111,12 @@ int vmstate_register(int instance_id, const VMStateDescription *vmsd, return 0; } +int vmstate_register(int instance_id, const VMStateDescription *vmsd, + void *opaque) +{ + return vmstate_register_with_alias_id(instance_id, vmsd, opaque, -1, 0); +} + void vmstate_unregister(const VMStateDescription *vmsd, void *opaque) { SaveStateEntry *se, *new_se; @@ -1433,7 +1446,8 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id) QTAILQ_FOREACH(se, &savevm_handlers, entry) { if (!strcmp(se->idstr, idstr) && - instance_id == se->instance_id) + (instance_id == se->instance_id || + instance_id == se->alias_id)) return se; } return NULL; -- cgit v1.1