From: Alex Williamson <alex.williamson@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: qemu-devel@nongnu.org, quintela@redhat.com
Subject: [Qemu-devel] Re: [PATCH] Remove code duplication from savevm instance_id creation code.
Date: Wed, 10 Nov 2010 09:01:53 -0700 [thread overview]
Message-ID: <1289404913.14321.90.camel@x201> (raw)
In-Reply-To: <20101107121638.GD30855@redhat.com>
On Sun, 2010-11-07 at 14:16 +0200, Gleb Natapov wrote:
> Code in register_savevm_live() and vmstate_register_with_alias_id()
> looks identical except idstr used. Move into separate function.
>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
looks ok to me.
Acked-by: Alex Williamson <alex.williamson@redhat.com>
> diff --git a/savevm.c b/savevm.c
> index cf56121..6ca6920 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -1080,6 +1080,33 @@ static int calculate_compat_instance_id(const char *idstr)
> return instance_id;
> }
>
> +static void setup_instance_id(DeviceState *dev, const char *idstr,
> + int instance_id, SaveStateEntry *se)
> +{
> + if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
> + char *id = dev->parent_bus->info->get_dev_path(dev);
> + if (id) {
> + pstrcpy(se->idstr, sizeof(se->idstr), id);
> + pstrcat(se->idstr, sizeof(se->idstr), "/");
> + qemu_free(id);
> +
> + se->compat = qemu_mallocz(sizeof(CompatEntry));
> + pstrcpy(se->compat->idstr, sizeof(se->compat->idstr), idstr);
> + se->compat->instance_id = instance_id == -1 ?
> + calculate_compat_instance_id(idstr) : instance_id;
> + instance_id = -1;
> + }
> + }
> + pstrcat(se->idstr, sizeof(se->idstr), idstr);
> +
> + if (instance_id == -1) {
> + se->instance_id = calculate_new_instance_id(se->idstr);
> + } else {
> + se->instance_id = instance_id;
> + }
> + assert(!se->compat || se->instance_id == 0);
> +}
> +
> /* 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
> @@ -1107,28 +1134,8 @@ int register_savevm_live(DeviceState *dev,
> se->vmsd = NULL;
> se->no_migrate = 0;
>
> - if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
> - char *id = dev->parent_bus->info->get_dev_path(dev);
> - if (id) {
> - pstrcpy(se->idstr, sizeof(se->idstr), id);
> - pstrcat(se->idstr, sizeof(se->idstr), "/");
> - qemu_free(id);
> -
> - se->compat = qemu_mallocz(sizeof(CompatEntry));
> - pstrcpy(se->compat->idstr, sizeof(se->compat->idstr), idstr);
> - se->compat->instance_id = instance_id == -1 ?
> - calculate_compat_instance_id(idstr) : instance_id;
> - instance_id = -1;
> - }
> - }
> - pstrcat(se->idstr, sizeof(se->idstr), idstr);
> + setup_instance_id(dev, idstr, instance_id, se);
>
> - if (instance_id == -1) {
> - se->instance_id = calculate_new_instance_id(se->idstr);
> - } else {
> - se->instance_id = instance_id;
> - }
> - assert(!se->compat || se->instance_id == 0);
> /* add at the end of list */
> QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
> return 0;
> @@ -1217,28 +1224,8 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
> se->vmsd = vmsd;
> se->alias_id = alias_id;
>
> - if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
> - char *id = dev->parent_bus->info->get_dev_path(dev);
> - if (id) {
> - pstrcpy(se->idstr, sizeof(se->idstr), id);
> - pstrcat(se->idstr, sizeof(se->idstr), "/");
> - qemu_free(id);
> -
> - se->compat = qemu_mallocz(sizeof(CompatEntry));
> - pstrcpy(se->compat->idstr, sizeof(se->compat->idstr), vmsd->name);
> - se->compat->instance_id = instance_id == -1 ?
> - calculate_compat_instance_id(vmsd->name) : instance_id;
> - instance_id = -1;
> - }
> - }
> - pstrcat(se->idstr, sizeof(se->idstr), vmsd->name);
> + setup_instance_id(dev, vmsd->name, instance_id, se);
>
> - if (instance_id == -1) {
> - se->instance_id = calculate_new_instance_id(se->idstr);
> - } else {
> - se->instance_id = instance_id;
> - }
> - assert(!se->compat || se->instance_id == 0);
> /* add at the end of list */
> QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
> return 0;
> --
> Gleb.
prev parent reply other threads:[~2010-11-10 16:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-07 12:16 [Qemu-devel] [PATCH] Remove code duplication from savevm instance_id creation code Gleb Natapov
2010-11-10 16:01 ` Alex Williamson [this message]
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=1289404913.14321.90.camel@x201 \
--to=alex.williamson@redhat.com \
--cc=gleb@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.