From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: chrisw@redhat.com, kvm@vger.kernel.org, paul@codesourcery.com,
alex.williamson@redhat.com, kraxel@redhat.com, avi@redhat.com
Subject: [Qemu-devel] [RFC PATCH 3/5] savevm: Make use of the new DeviceState param
Date: Sun, 13 Jun 2010 23:51:34 -0600 [thread overview]
Message-ID: <20100614055134.879.72781.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100614054923.879.33717.stgit@localhost.localdomain>
Use the now passed in DeviceState along with qdev_get_dev_path() to
create meaningful id strings for the SaveStateEntry. We append the
driver provided string so we can differentiate multiple savevm
handlers per device:
"/main-system-bus/pci.0,addr=03.0/i82551,mac=52:54:00:12:34:56/eeprom"
"/main-system-bus/pci.0,addr=03.0/i82551,mac=52:54:00:12:34:56/i82551"
We also introduce compatibility fields so that we can attempt to
import savevm data from an older VM. These should be deprecated and
removed at some point.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
savevm.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 76 insertions(+), 7 deletions(-)
diff --git a/savevm.c b/savevm.c
index 81d544f..4cc542b 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1002,6 +1002,8 @@ typedef struct SaveStateEntry {
LoadStateHandler *load_state;
const VMStateDescription *vmsd;
void *opaque;
+ char compat_idstr[256];
+ int compat_instance_id;
} SaveStateEntry;
@@ -1023,6 +1025,20 @@ static int calculate_new_instance_id(const char *idstr)
return instance_id;
}
+static int calculate_new_compat_instance_id(const char *idstr)
+{
+ SaveStateEntry *se;
+ int instance_id = 0;
+
+ QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+ if (strcmp(idstr, se->compat_idstr) == 0
+ && instance_id <= se->compat_instance_id) {
+ instance_id = se->compat_instance_id + 1;
+ }
+ }
+ return instance_id;
+}
+
/* TODO: Individual devices generally have very little idea about the rest
of the system, so instance_id should be removed/replaced.
Meanwhile pass -1 as instance_id if you do not already have a clearly
@@ -1040,7 +1056,16 @@ int register_savevm_live(DeviceState *dev,
SaveStateEntry *se;
se = qemu_mallocz(sizeof(SaveStateEntry));
- pstrcpy(se->idstr, sizeof(se->idstr), idstr);
+
+ if (dev) {
+ char *path = qdev_get_dev_path(dev);
+ pstrcpy(se->idstr, sizeof(se->idstr), path);
+ pstrcat(se->idstr, sizeof(se->idstr), "/");
+ pstrcat(se->idstr, sizeof(se->idstr), idstr);
+ qemu_free(path);
+ } else {
+ pstrcpy(se->idstr, sizeof(se->idstr), idstr);
+ }
se->version_id = version_id;
se->section_id = global_section_id++;
se->set_params = set_params;
@@ -1050,11 +1075,19 @@ int register_savevm_live(DeviceState *dev,
se->opaque = opaque;
se->vmsd = NULL;
+ pstrcpy(se->compat_idstr, sizeof(se->idstr), idstr);
if (instance_id == -1) {
- se->instance_id = calculate_new_instance_id(idstr);
+ se->instance_id = calculate_new_instance_id(se->idstr);
+ se->compat_instance_id = calculate_new_compat_instance_id(idstr);
} else {
- se->instance_id = instance_id;
+ se->instance_id = se->compat_instance_id = instance_id;
+ }
+
+ if (dev && instance_id == -1 && se->instance_id != 0) {
+ fprintf(stderr, "%s: Failed to create unqiue path \"%s\"\n",
+ __FUNCTION__, se->idstr);
}
+
/* add at the end of list */
QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
return 0;
@@ -1075,13 +1108,25 @@ int register_savevm(DeviceState *dev,
void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)
{
SaveStateEntry *se, *new_se;
+ char *path;
+
+ if (dev) {
+ int len;
+ path = qdev_get_dev_path(dev);
+ len = strlen(path);
+ path = qemu_realloc(path, len + strlen(idstr) + 2);
+ sprintf(path + len, "/%s", idstr);
+ } else {
+ path = qemu_strdup(idstr);
+ }
QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
- if (strcmp(se->idstr, idstr) == 0 && se->opaque == opaque) {
+ if (strcmp(se->idstr, path) == 0 && se->opaque == opaque) {
QTAILQ_REMOVE(&savevm_handlers, se, entry);
qemu_free(se);
}
}
+ qemu_free(path);
}
int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
@@ -1095,7 +1140,16 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
assert(alias_id == -1 || required_for_version >= vmsd->minimum_version_id);
se = qemu_mallocz(sizeof(SaveStateEntry));
- pstrcpy(se->idstr, sizeof(se->idstr), vmsd->name);
+
+ if (dev) {
+ char *path = qdev_get_dev_path(dev);
+ pstrcpy(se->idstr, sizeof(se->idstr), path);
+ pstrcat(se->idstr, sizeof(se->idstr), "/");
+ pstrcat(se->idstr, sizeof(se->idstr), vmsd->name);
+ qemu_free(path);
+ } else {
+ pstrcpy(se->idstr, sizeof(se->idstr), vmsd->name);
+ }
se->version_id = vmsd->version_id;
se->section_id = global_section_id++;
se->save_live_state = NULL;
@@ -1105,11 +1159,19 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
se->vmsd = vmsd;
se->alias_id = alias_id;
+ pstrcpy(se->compat_idstr, sizeof(se->idstr), vmsd->name);
if (instance_id == -1) {
- se->instance_id = calculate_new_instance_id(vmsd->name);
+ se->instance_id = calculate_new_instance_id(se->idstr);
+ se->compat_instance_id = calculate_new_compat_instance_id(vmsd->name);
} else {
- se->instance_id = instance_id;
+ se->instance_id = se->compat_instance_id = instance_id;
}
+
+ if (dev && instance_id == -1 && se->instance_id != 0) {
+ fprintf(stderr, "%s: Failed to create unqiue path \"%s\"\n",
+ __FUNCTION__, se->idstr);
+ }
+
/* add at the end of list */
QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
return 0;
@@ -1456,6 +1518,13 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id)
instance_id == se->alias_id))
return se;
}
+
+ QTAILQ_FOREACH(se, &savevm_handlers, entry) {
+ if (!strcmp(se->compat_idstr, idstr) &&
+ (instance_id == se->compat_instance_id ||
+ instance_id == se->alias_id))
+ return se;
+ }
return NULL;
}
next prev parent reply other threads:[~2010-06-14 5:51 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-14 5:51 [Qemu-devel] [RFC PATCH 0/5] Introduce canonical device hierarchy string Alex Williamson
2010-06-14 5:51 ` [Qemu-devel] [RFC PATCH 1/5] qdev: Create qdev_get_dev_path() Alex Williamson
2010-06-14 6:39 ` Markus Armbruster
2010-06-14 12:52 ` Alex Williamson
2010-06-14 13:00 ` Jan Kiszka
2010-06-14 13:09 ` Paul Brook
2010-06-14 15:29 ` Alex Williamson
2010-06-14 15:42 ` Paul Brook
2010-06-14 16:00 ` Jan Kiszka
2010-06-14 16:38 ` Alex Williamson
2010-06-14 16:49 ` Jan Kiszka
2010-06-14 18:35 ` Alex Williamson
2010-06-14 21:43 ` Paul Brook
2010-06-14 22:11 ` Alex Williamson
2010-06-14 22:46 ` Paul Brook
2010-06-15 1:14 ` Alex Williamson
2010-06-15 11:24 ` Paul Brook
2010-06-15 8:47 ` Markus Armbruster
2010-06-15 9:34 ` Jan Kiszka
2010-06-15 11:28 ` Paul Brook
2010-06-15 11:45 ` Jan Kiszka
2010-06-15 12:04 ` Paul Brook
2010-06-15 12:16 ` Jan Kiszka
2010-06-15 12:39 ` Paul Brook
2010-06-15 13:00 ` Jan Kiszka
2010-06-15 13:14 ` Paul Brook
2010-06-15 13:16 ` Markus Armbruster
2010-06-15 13:32 ` Jan Kiszka
2010-06-15 20:53 ` Alex Williamson
2010-06-15 21:55 ` Paul Brook
2010-06-15 22:33 ` Alex Williamson
2010-06-15 23:01 ` Paul Brook
2010-06-15 23:10 ` Alex Williamson
2010-06-16 0:25 ` Chris Wright
2010-06-16 0:30 ` Paul Brook
2010-06-16 0:35 ` Chris Wright
2010-06-16 1:30 ` Paul Brook
2010-06-16 2:55 ` Alex Williamson
2010-06-16 8:23 ` Markus Armbruster
2010-06-17 22:25 ` Alex Williamson
2010-06-18 9:16 ` Jan Kiszka
2010-06-18 15:01 ` Alex Williamson
2010-06-18 15:22 ` Jan Kiszka
2010-06-18 14:03 ` Markus Armbruster
2010-06-18 14:14 ` Jan Kiszka
2010-06-18 15:21 ` Alex Williamson
2010-06-15 11:42 ` Markus Armbruster
2010-06-15 11:59 ` Jan Kiszka
2010-06-15 13:07 ` Markus Armbruster
2010-06-15 13:19 ` Paul Brook
2010-06-15 13:32 ` Paul Brook
2010-06-15 15:08 ` Jan Kiszka
2010-06-16 13:02 ` Markus Armbruster
2010-06-14 5:51 ` [Qemu-devel] [RFC PATCH 2/5] savevm: Add DeviceState param Alex Williamson
2010-06-14 5:51 ` Alex Williamson [this message]
2010-06-14 5:51 ` [Qemu-devel] [RFC PATCH 4/5] eepro100: Add a dev field to eeprom new/free functions Alex Williamson
2010-06-14 5:51 ` [Qemu-devel] [RFC PATCH 5/5] virtio-net: Incorporate a DeviceState pointer and let savevm track instances Alex Williamson
2010-06-14 7:02 ` [Qemu-devel] Re: [RFC PATCH 0/5] Introduce canonical device hierarchy string Gerd Hoffmann
2010-06-14 19:56 ` Alex Williamson
2010-06-15 8:53 ` Markus Armbruster
2010-06-15 18:01 ` Alex Williamson
2010-06-16 8:34 ` Markus Armbruster
2010-06-16 8:36 ` Markus Armbruster
2010-06-15 9:12 ` Gerd Hoffmann
2010-06-15 18:03 ` Alex Williamson
2010-06-16 9:46 ` RFC qdev path semantics (was: [Qemu-devel] [RFC PATCH 0/5] Introduce canonical device hierarchy string) Markus Armbruster
2010-06-16 10:40 ` Paul Brook
2010-06-16 11:37 ` [Qemu-devel] Re: RFC qdev path semantics Jan Kiszka
2010-06-16 11:45 ` Paul Brook
2010-06-16 12:01 ` Jan Kiszka
2010-06-16 12:21 ` Paul Brook
2010-06-16 13:50 ` Jan Kiszka
2010-06-16 13:05 ` Markus Armbruster
2010-06-16 13:23 ` Paul Brook
2010-06-16 14:31 ` Markus Armbruster
2010-06-17 21:43 ` Alex Williamson
2010-06-17 22:01 ` Paul Brook
2010-06-17 22:34 ` Alex Williamson
2010-06-18 7:52 ` Gerd Hoffmann
2010-06-18 14:58 ` Markus Armbruster
2010-06-22 14:27 ` Anthony Liguori
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=20100614055134.879.72781.stgit@localhost.localdomain \
--to=alex.williamson@redhat.com \
--cc=avi@redhat.com \
--cc=chrisw@redhat.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
/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).