migration: Allow unregister of save_live handlers
PATCH v2 1/1 migration: Allow unregister of save_live handlers
Migration non save_live handlers have an ops member that is dinamically allocated by migration code. Save_live handlers have it passed as argument and are responsability of the caller. Add a new member is_allocated that remembers if ops has to be freed. This allows unregister_savevm() to work with save_live handlers.
---
check that se->ops is not NULL (thanks peterx)
--- include/migration/vmstate.h | 2 ++ migration/savevm.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)
include/migration/vmstate.h +2 -0
@@ -57,6 +57,8 @@ typedef struct SaveVMHandlers {uint64_t *non_postcopiable_pending, uint64_t *postcopiable_pending);LoadStateHandler *load_state; +/* Has been allocated by migratation code */ +bool is_allocated; } SaveVMHandlers; int register_savevm(DeviceState *dev,
migration/savevm.c +4 -1
@@ -628,6 +628,7 @@ int register_savevm(DeviceState *dev,SaveVMHandlers *ops =g_new0 (SaveVMHandlers,1 ); ops->save_state = save_state; ops->load_state = load_state; + ops->is_allocated = true;return register_savevm_live (dev, idstr, instance_id, version_id, ops, opaque); }
@@ -651,7 +652,9 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)if (strcmp (se->idstr, id) ==0 && se->opaque == opaque) {QTAILQ_REMOVE (&savevm_state.handlers, se, entry);g_free (se->compat); -g_free (se->ops); +if (se->ops && se->ops->is_allocated) { +g_free (se->ops); + }g_free (se); } }
Signature · 1 line
2.9.3
Quoted 7 lines · Juan Quintela
Migration non
save_livehandlers have an ops member that is dinamically allocated by migration code.Save_livehandlers have it passed as argument and are responsability of the caller. Add a new memberis_allocatedthat remembers if ops has to be freed. This allowsunregister_savevm()to work withsave_livehandlers.Signed-off-by Juan Quintela <[email protected]>
I thought Laurent will prepare one patch that will directly remove existing register_savevm() callers, no?
Quoted 48 lines
---
check that
se->opsis not NULL (thanks peterx)--- include/migration/vmstate.h | 2 ++ migration/savevm.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)include/migration/vmstate.h +2
-0@@ -57,6 +57,8 @@ typedef struct SaveVMHandlers {uint64_t *non_postcopiable_pending, uint64_t *postcopiable_pending);LoadStateHandler *load_state; +/* Has been allocated by migratation code */ +bool is_allocated; } SaveVMHandlers; int register_savevm(DeviceState *dev,migration/savevm.c +4
-1@@ -628,6 +628,7 @@ int register_savevm(DeviceState *dev,SaveVMHandlers *ops =g_new0 (SaveVMHandlers,1 ); ops->save_state = save_state; ops->load_state = load_state; + ops->is_allocated = true;return register_savevm_live (dev, idstr, instance_id, version_id, ops, opaque); }@@ -651,7 +652,9 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)if (strcmp (se->idstr, id) ==0 && se->opaque == opaque) {QTAILQ_REMOVE (&savevm_state.handlers, se, entry);g_free (se->compat); -g_free (se->ops); +if (se->ops && se->ops->is_allocated) { +g_free (se->ops); + }g_free (se); } }Signature · 1 line
2.9.3
Signature · 1 line
Peter Xu
Quoted 11 lines · Peter Xu
Quoted 7 lines · Juan Quintela
Migration non
save_livehandlers have an ops member that is dinamically allocated by migration code.Save_livehandlers have it passed as argument and are responsability of the caller. Add a new memberis_allocatedthat remembers if ops has to be freed. This allowsunregister_savevm()to work withsave_livehandlers.Signed-off-by Juan Quintela <[email protected]>I thought Laurent will prepare one patch that will directly remove existing
register_savevm()callers, no?
s390, vmxnet3 and slirp are using it. I am not sure that we will get that ones "changed" so easily.
Later, Juan.
Quoted 8 lines · * Juan Quintela ([email protected]) wrote:
Quoted 7 lines · Peter Xu
Quoted 6 lines · Juan Quintela
Migration non
save_livehandlers have an ops member that is dinamically allocated by migration code.Save_livehandlers have it passed as argument and are responsability of the caller. Add a new memberis_allocatedthat remembers if ops has to be freed. This allowsunregister_savevm()to work withsave_livehandlers.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Juan Quintela <[email protected]>I thought Laurent will prepare one patch that will directly remove existing
register_savevm()callers, no?s390, vmxnet3 and slirp are using it. I am not sure that we will get that ones "changed" so easily.
I think Halil is working on s390, slirp has a tricky loop I need to look at again. And vmxnet3 is...odd.
Dave
Quoted 1 line
Later, Juan.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK