From: Jan Kiszka <jan.kiszka@web.de>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Juan Quintela <quintela@redhat.com>
Subject: [Qemu-devel] [PATCH v2 3/6] vmstate: Add support for alias ID
Date: Sat, 15 May 2010 13:32:40 +0200 [thread overview]
Message-ID: <dc881c62b51fe61f1666d37533d2b045d5ae47e7.1273923157.git.jan.kiszka@web.de> (raw)
In-Reply-To: <cover.1273923157.git.jan.kiszka@web.de>
In-Reply-To: <cover.1273923157.git.jan.kiszka@web.de>
From: Jan Kiszka <jan.kiszka@siemens.com>
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 <jan.kiszka@siemens.com>
---
hw/hw.h | 4 ++++
hw/qdev.c | 16 ++++++++++++++--
hw/qdev.h | 4 ++++
savevm.c | 20 +++++++++++++++++---
4 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index 2d39724..fc2d184 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -758,5 +758,9 @@ extern void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque);
extern int vmstate_register(int instance_id, const VMStateDescription *vmsd,
void *base);
+extern int vmstate_register_with_alias_id(int instance_id,
+ const VMStateDescription *vmsd,
+ void *base, int alias_id,
+ int required_for_version);
void vmstate_unregister(const VMStateDescription *vmsd, void *opaque);
#endif
diff --git a/hw/qdev.c b/hw/qdev.c
index d3bf0fa..af17486 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) {
diff --git a/hw/qdev.h b/hw/qdev.h
index d8fbc73..a44060e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -44,6 +44,8 @@ struct DeviceState {
QLIST_HEAD(, BusState) child_bus;
int num_child_bus;
QLIST_ENTRY(DeviceState) sibling;
+ int instance_id_alias;
+ int alias_required_for_version;
};
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
@@ -112,6 +114,8 @@ int qdev_device_help(QemuOpts *opts);
DeviceState *qdev_device_add(QemuOpts *opts);
int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
void qdev_init_nofail(DeviceState *dev);
+void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
+ int required_for_version);
int qdev_unplug(DeviceState *dev);
void qdev_free(DeviceState *dev);
int qdev_simple_unplug_cb(DeviceState *dev);
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;
--
1.6.0.2
next prev parent reply other threads:[~2010-05-15 11:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-15 11:32 [Qemu-devel] [PATCH v2 0/6] vmstate: Drop post_save / allow instance ID aliases Jan Kiszka
2010-05-15 11:32 ` [Qemu-devel] [PATCH v2 1/6] tmp105: Drop unused faults field Jan Kiszka
2010-05-15 12:33 ` [Qemu-devel] " andrzej zaborowski
2010-05-15 13:22 ` Jan Kiszka
2010-05-15 11:32 ` [Qemu-devel] [PATCH v2 2/6] vmstate: Drop unused post_save handler Jan Kiszka
2010-05-15 11:32 ` Jan Kiszka [this message]
2010-05-15 11:32 ` [Qemu-devel] [PATCH v2 4/6] serial: Register vmstate via qdev Jan Kiszka
2010-05-15 11:32 ` [Qemu-devel] [PATCH v2 5/6] fdc: " Jan Kiszka
2010-05-15 11:32 ` [Qemu-devel] [PATCH v2 6/6] mc146818rtc: " Jan Kiszka
2010-05-15 15:24 ` [Qemu-devel] Re: [PATCH v2 0/6] vmstate: Drop post_save / allow instance ID aliases Blue Swirl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dc881c62b51fe61f1666d37533d2b045d5ae47e7.1273923157.git.jan.kiszka@web.de \
--to=jan.kiszka@web.de \
--cc=blauwirbel@gmail.com \
--cc=jan.kiszka@siemens.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).