[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] Re: [PATCH] Remove code duplication from savevm instance_id
From: |
Alex Williamson |
Subject: |
[Qemu-devel] Re: [PATCH] Remove code duplication from savevm instance_id creation code. |
Date: |
Wed, 10 Nov 2010 09:01:53 -0700 |
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 <address@hidden>
looks ok to me.
Acked-by: Alex Williamson <address@hidden>
> 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.