* Juan Quintela (quint...@redhat.com) wrote: > This way, we will put savevm global state here, instead of lots of variables. > > Signed-off-by: Juan Quintela <quint...@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilb...@redhat.com> > --- > savevm.c | 53 +++++++++++++++++++++++++++++------------------------ > 1 file changed, 29 insertions(+), 24 deletions(-) > > diff --git a/savevm.c b/savevm.c > index 3b0e222..1014e3e 100644 > --- a/savevm.c > +++ b/savevm.c > @@ -235,10 +235,15 @@ typedef struct SaveStateEntry { > int is_ram; > } SaveStateEntry; > > - > -static QTAILQ_HEAD(savevm_handlers, SaveStateEntry) savevm_handlers = > - QTAILQ_HEAD_INITIALIZER(savevm_handlers); > -static int global_section_id; > +typedef struct SaveState { > + QTAILQ_HEAD(, SaveStateEntry) handlers; > + int global_section_id; > +} SaveState; > + > +static SaveState savevm_state = { > + .handlers = QTAILQ_HEAD_INITIALIZER(savevm_state.handlers), > + .global_section_id = 0, > +}; > > static void dump_vmstate_vmsd(FILE *out_file, > const VMStateDescription *vmsd, int indent, > @@ -383,7 +388,7 @@ static int calculate_new_instance_id(const char *idstr) > SaveStateEntry *se; > int instance_id = 0; > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (strcmp(idstr, se->idstr) == 0 > && instance_id <= se->instance_id) { > instance_id = se->instance_id + 1; > @@ -397,7 +402,7 @@ static int calculate_compat_instance_id(const char *idstr) > SaveStateEntry *se; > int instance_id = 0; > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (!se->compat) { > continue; > } > @@ -425,7 +430,7 @@ int register_savevm_live(DeviceState *dev, > > se = g_malloc0(sizeof(SaveStateEntry)); > se->version_id = version_id; > - se->section_id = global_section_id++; > + se->section_id = savevm_state.global_section_id++; > se->ops = ops; > se->opaque = opaque; > se->vmsd = NULL; > @@ -457,7 +462,7 @@ int register_savevm_live(DeviceState *dev, > } > assert(!se->compat || se->instance_id == 0); > /* add at the end of list */ > - QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry); > + QTAILQ_INSERT_TAIL(&savevm_state.handlers, se, entry); > return 0; > } > > @@ -491,9 +496,9 @@ void unregister_savevm(DeviceState *dev, const char > *idstr, void *opaque) > } > pstrcat(id, sizeof(id), idstr); > > - QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) { > + QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) { > if (strcmp(se->idstr, id) == 0 && se->opaque == opaque) { > - QTAILQ_REMOVE(&savevm_handlers, se, entry); > + QTAILQ_REMOVE(&savevm_state.handlers, se, entry); > if (se->compat) { > g_free(se->compat); > } > @@ -515,7 +520,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int > instance_id, > > se = g_malloc0(sizeof(SaveStateEntry)); > se->version_id = vmsd->version_id; > - se->section_id = global_section_id++; > + se->section_id = savevm_state.global_section_id++; > se->opaque = opaque; > se->vmsd = vmsd; > se->alias_id = alias_id; > @@ -543,7 +548,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int > instance_id, > } > assert(!se->compat || se->instance_id == 0); > /* add at the end of list */ > - QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry); > + QTAILQ_INSERT_TAIL(&savevm_state.handlers, se, entry); > return 0; > } > > @@ -552,9 +557,9 @@ void vmstate_unregister(DeviceState *dev, const > VMStateDescription *vmsd, > { > SaveStateEntry *se, *new_se; > > - QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) { > + QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) { > if (se->vmsd == vmsd && se->opaque == opaque) { > - QTAILQ_REMOVE(&savevm_handlers, se, entry); > + QTAILQ_REMOVE(&savevm_state.handlers, se, entry); > if (se->compat) { > g_free(se->compat); > } > @@ -606,7 +611,7 @@ bool qemu_savevm_state_blocked(Error **errp) > { > SaveStateEntry *se; > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (se->vmsd && se->vmsd->unmigratable) { > error_setg(errp, "State blocked by non-migratable device '%s'", > se->idstr); > @@ -623,7 +628,7 @@ void qemu_savevm_state_begin(QEMUFile *f, > int ret; > > trace_savevm_state_begin(); > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (!se->ops || !se->ops->set_params) { > continue; > } > @@ -633,7 +638,7 @@ void qemu_savevm_state_begin(QEMUFile *f, > qemu_put_be32(f, QEMU_VM_FILE_MAGIC); > qemu_put_be32(f, QEMU_VM_FILE_VERSION); > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > int len; > > if (!se->ops || !se->ops->save_live_setup) { > @@ -676,7 +681,7 @@ int qemu_savevm_state_iterate(QEMUFile *f) > int ret = 1; > > trace_savevm_state_iterate(); > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (!se->ops || !se->ops->save_live_iterate) { > continue; > } > @@ -727,7 +732,7 @@ void qemu_savevm_state_complete(QEMUFile *f) > > cpu_synchronize_all_states(); > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (!se->ops || !se->ops->save_live_complete) { > continue; > } > @@ -752,7 +757,7 @@ void qemu_savevm_state_complete(QEMUFile *f) > vmdesc = qjson_new(); > json_prop_int(vmdesc, "page_size", TARGET_PAGE_SIZE); > json_start_array(vmdesc, "devices"); > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > int len; > > if ((!se->ops || !se->ops->save_state) && !se->vmsd) { > @@ -803,7 +808,7 @@ uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t > max_size) > SaveStateEntry *se; > uint64_t ret = 0; > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (!se->ops || !se->ops->save_live_pending) { > continue; > } > @@ -822,7 +827,7 @@ void qemu_savevm_state_cancel(void) > SaveStateEntry *se; > > trace_savevm_state_cancel(); > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (se->ops && se->ops->cancel) { > se->ops->cancel(se->opaque); > } > @@ -872,7 +877,7 @@ static int qemu_save_device_state(QEMUFile *f) > > cpu_synchronize_all_states(); > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > int len; > > if (se->is_ram) { > @@ -906,7 +911,7 @@ static SaveStateEntry *find_se(const char *idstr, int > instance_id) > { > SaveStateEntry *se; > > - QTAILQ_FOREACH(se, &savevm_handlers, entry) { > + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { > if (!strcmp(se->idstr, idstr) && > (instance_id == se->instance_id || > instance_id == se->alias_id)) > -- > 2.4.0 > > -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK