Skip to contentSkip to conversation

migration: Allow unregister of save_live handlers

PATCH Superseded Juan Quintela 2 participants 3 messages May 24, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 include/migration/vmstate.h | 2 ++
 migration/savevm.c          | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/migration/vmstate.h +2 -0
index f97411d..1d20e30 100644
@@ -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
index d971e5e..187f386 100644
@@ -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->is_allocated) {
+                g_free(se->ops);
+            }
             g_free(se);
         }
     }
Signature · 1 line
2.9.3
#1 lore raw
Quoted 38 lines · Juan Quintela

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.

---
 include/migration/vmstate.h | 2 ++
 migration/savevm.c          | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/migration/vmstate.h +2 -0
index f97411d..1d20e30 100644
@@ -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 +1 -0
index d971e5e..187f386 100644
@@ -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);
 }

migration/savevm.c void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) · line 655

Quoted 5 lines
migration/savevm.c +1 -1
@@ -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->is_allocated) {

Would it be good to check against (se->ops && se->ops->is_allocated)? Since I see that devices registered via vmstate_register_with_alias_id() won't have this se->ops. I just don't know whether that case will be allowed to be unregistered with current function.

Thanks,

Quoted 8 lines
migration/savevm.c +2 -0
+                g_free(se->ops);
+            }
             g_free(se);
         }
     }
Signature · 1 line
2.9.3
Signature · 1 line
Peter Xu
#2 lore raw
Quoted 42 lines · Peter Xu
Quoted 41 lines · Juan Quintela

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.

---
 include/migration/vmstate.h | 2 ++
 migration/savevm.c          | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/migration/vmstate.h +2 -0
index f97411d..1d20e30 100644
@@ -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 +1 -0
index d971e5e..187f386 100644
@@ -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);
Quoted 8 lines

migration/savevm.c void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) · line 655

Quoted 2 lines
migration/savevm.c +1 -1
-            g_free(se->ops);
+            if (se->ops->is_allocated) {

Would it be good to check against (se->ops && se->ops->is_allocated)? Since I see that devices registered via vmstate_register_with_alias_id() won't have this se->ops. I just don't know whether that case will be allowed to be unregistered with current function.

good point. I thought that not having ->ops was wrong, but I had completely forgot about the alias case. Fixing it.

Thanks, Juan.