Skip to contentSkip to conversation

migration/savevm: move non SaveStateEntry condition check out of iteration

PATCH In review Wei Yang 3 participants 10 messages Jul 9, 2019 – Aug 7, 2019

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

cover migration/savevm: move non SaveStateEntry condition check out of iteration

qemu_savevm_state_complete_precopy() iterates SaveStateEntry and does proper tasks for migration.

For each iteration, in_postcopy and iterable_only would be checked to see whether it should skip. Since these two conditions are not SaveStateEntry specific, it is proper to move the check out of iteration.

These three patches prepare the code and move the condition check out of the iteration.

Wei Yang (3):
migration/savevm: flush file for iterable_only case migration/savevm: split qemu_savevm_state_complete_precopy() into two
parts
migration/savevm: move non SaveStateEntry condition check out of
iteration

 migration/savevm.c | 68 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 50 insertions(+), 18 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/3 migration/savevm: flush file for iterable_only case

It would be proper to flush file even for iterable_only case.

---
 migration/savevm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
migration/savevm.c +2 -1
index c0e557b4c2..becedcc1c6 100644
@@ -1292,7 +1292,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
 
     if (iterable_only) {
-        return 0;
+        goto flush;
     }
 
     vmdesc = qjson_new();
@@ -1353,6 +1353,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
     qjson_destroy(vmdesc);
 
+flush:
     qemu_fflush(f);
     return 0;
 }
Signature · 1 line
2.17.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] migration/savevm: flush file for iterable_only case

Quoted 3 lines · * Wei Yang ([email protected]) wrote:

It would be proper to flush file even for iterable_only case.

OK, I don't think this is actually necessary; but it's safe. We only really need the flush at the end of the file, and in the non-iterable-only case it's not the end of the file.

Since it makes your next change simpler,

Quoted 28 lines
---
 migration/savevm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
migration/savevm.c +2 -1
index c0e557b4c2..becedcc1c6 100644
@@ -1292,7 +1292,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
 
     if (iterable_only) {
-        return 0;
+        goto flush;
     }
 
     vmdesc = qjson_new();
@@ -1353,6 +1353,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
     qjson_destroy(vmdesc);
 
+flush:
     qemu_fflush(f);
     return 0;
 }
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] migration/savevm: flush file for iterable_only case

Quoted 10 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Wei Yang ([email protected]) wrote:

It would be proper to flush file even for iterable_only case.

OK, I don't think this is actually necessary; but it's safe. We only really need the flush at the end of the file, and in the non-iterable-only case it's not the end of the file.

Since it makes your next change simpler,

Yep, you are so kind.

Quoted 33 lines
Quoted 28 lines
---
 migration/savevm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
migration/savevm.c +2 -1
index c0e557b4c2..becedcc1c6 100644
@@ -1292,7 +1292,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
 
     if (iterable_only) {
-        return 0;
+        goto flush;
     }
 
     vmdesc = qjson_new();
@@ -1353,6 +1353,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
     qjson_destroy(vmdesc);
 
+flush:
     qemu_fflush(f);
     return 0;
 }
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
author
#4 lore raw

PATCH 2/3 migration/savevm: split qemu_savevm_state_complete_precopy() into two parts

In reply to Wei Yang

This is a preparation patch for further cleanup.

No functional change, just wrap two major part of qemu_savevm_state_complete_precopy() into function.

---
 migration/savevm.c | 66 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 17 deletions(-)
migration/savevm.c +49 -17
index becedcc1c6..c41e13e322 100644
@@ -1246,23 +1246,12 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f)
     qemu_fflush(f);
 }
 
-int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
-                                       bool inactivate_disks)
+static
+int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
+                                                bool iterable_only)
 {
-    QJSON *vmdesc;
-    int vmdesc_len;
     SaveStateEntry *se;
     int ret;
-    bool in_postcopy = migration_in_postcopy();
-    Error *local_err = NULL;
-
-    if (precopy_notify(PRECOPY_NOTIFY_COMPLETE, &local_err)) {
-        error_report_err(local_err);
-    }
-
-    trace_savevm_state_complete_precopy();
-
-    cpu_synchronize_all_states();
 
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops ||
@@ -1291,9 +1280,18 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
         }
     }
 
-    if (iterable_only) {
-        goto flush;
-    }
+    return 0;
+}
+
+static
+int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
+                                                    bool in_postcopy,
+                                                    bool inactivate_disks)
+{
+    QJSON *vmdesc;
+    int vmdesc_len;
+    SaveStateEntry *se;
+    int ret;
 
     vmdesc = qjson_new();
     json_prop_int(vmdesc, "page_size", qemu_target_page_size());
@@ -1353,6 +1351,40 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
     qjson_destroy(vmdesc);
 
+    return 0;
+}
+
+int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
+                                       bool inactivate_disks)
+{
+    int ret;
+    Error *local_err = NULL;
+    bool in_postcopy = migration_in_postcopy();
+
+    if (precopy_notify(PRECOPY_NOTIFY_COMPLETE, &local_err)) {
+        error_report_err(local_err);
+    }
+
+    trace_savevm_state_complete_precopy();
+
+    cpu_synchronize_all_states();
+
+    ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy,
+                                                      iterable_only);
+    if (ret) {
+        return ret;
+    }
+
+    if (iterable_only) {
+        goto flush;
+    }
+
+    ret = qemu_savevm_state_complete_precopy_non_iterable(f, in_postcopy,
+                                                          inactivate_disks);
+    if (ret) {
+        return ret;
+    }
+
 flush:
     qemu_fflush(f);
     return 0;
Signature · 1 line
2.17.1
Reviewed-by on v1 2/3
#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] migration/savevm: split qemu_savevm_state_complete_precopy() into two parts

Quoted 6 lines · * Wei Yang ([email protected]) wrote:

This is a preparation patch for further cleanup.

No functional change, just wrap two major part of qemu_savevm_state_complete_precopy() into function.

Quoted 101 lines
---
 migration/savevm.c | 66 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 17 deletions(-)
migration/savevm.c +49 -17
index becedcc1c6..c41e13e322 100644
@@ -1246,23 +1246,12 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f)
     qemu_fflush(f);
 }
 
-int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
-                                       bool inactivate_disks)
+static
+int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
+                                                bool iterable_only)
 {
-    QJSON *vmdesc;
-    int vmdesc_len;
     SaveStateEntry *se;
     int ret;
-    bool in_postcopy = migration_in_postcopy();
-    Error *local_err = NULL;
-
-    if (precopy_notify(PRECOPY_NOTIFY_COMPLETE, &local_err)) {
-        error_report_err(local_err);
-    }
-
-    trace_savevm_state_complete_precopy();
-
-    cpu_synchronize_all_states();
 
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (!se->ops ||
@@ -1291,9 +1280,18 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
         }
     }
 
-    if (iterable_only) {
-        goto flush;
-    }
+    return 0;
+}
+
+static
+int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
+                                                    bool in_postcopy,
+                                                    bool inactivate_disks)
+{
+    QJSON *vmdesc;
+    int vmdesc_len;
+    SaveStateEntry *se;
+    int ret;
 
     vmdesc = qjson_new();
     json_prop_int(vmdesc, "page_size", qemu_target_page_size());
@@ -1353,6 +1351,40 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
     }
     qjson_destroy(vmdesc);
 
+    return 0;
+}
+
+int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
+                                       bool inactivate_disks)
+{
+    int ret;
+    Error *local_err = NULL;
+    bool in_postcopy = migration_in_postcopy();
+
+    if (precopy_notify(PRECOPY_NOTIFY_COMPLETE, &local_err)) {
+        error_report_err(local_err);
+    }
+
+    trace_savevm_state_complete_precopy();
+
+    cpu_synchronize_all_states();
+
+    ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy,
+                                                      iterable_only);
+    if (ret) {
+        return ret;
+    }
+
+    if (iterable_only) {
+        goto flush;
+    }
+
+    ret = qemu_savevm_state_complete_precopy_non_iterable(f, in_postcopy,
+                                                          inactivate_disks);
+    if (ret) {
+        return ret;
+    }
+
 flush:
     qemu_fflush(f);
     return 0;
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#6 lore raw

PATCH 3/3 migration/savevm: move non SaveStateEntry condition check out of iteration

In reply to Wei Yang

in_postcopy and iterable_only are not SaveStateEntry specific, it would be more proper to check them out of iteration.

---
 migration/savevm.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
migration/savevm.c +6 -7
index c41e13e322..8a2ada529e 100644
@@ -1247,8 +1247,7 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f)
 }
 
 static
-int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
-                                                bool iterable_only)
+int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy)
 {
     SaveStateEntry *se;
     int ret;
@@ -1257,7 +1256,6 @@ int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
         if (!se->ops ||
             (in_postcopy && se->ops->has_postcopy &&
              se->ops->has_postcopy(se->opaque)) ||
-            (in_postcopy && !iterable_only) ||
             !se->ops->save_live_complete_precopy) {
             continue;
         }
@@ -1369,10 +1367,11 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
 
     cpu_synchronize_all_states();
 
-    ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy,
-                                                      iterable_only);
-    if (ret) {
-        return ret;
+    if (!in_postcopy || iterable_only) {
+        ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy);
+        if (ret) {
+            return ret;
+        }
     }
 
     if (iterable_only) {
Signature · 1 line
2.17.1
Reviewed-by on v1 3/3
#7 lore raw
Quoted 4 lines · * Wei Yang ([email protected]) wrote:

in_postcopy and iterable_only are not SaveStateEntry specific, it would be more proper to check them out of iteration.

Worth it just to make that big if statement simpler!

Quoted 45 lines
---
 migration/savevm.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
migration/savevm.c +6 -7
index c41e13e322..8a2ada529e 100644
@@ -1247,8 +1247,7 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f)
 }
 
 static
-int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
-                                                bool iterable_only)
+int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy)
 {
     SaveStateEntry *se;
     int ret;
@@ -1257,7 +1256,6 @@ int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
         if (!se->ops ||
             (in_postcopy && se->ops->has_postcopy &&
              se->ops->has_postcopy(se->opaque)) ||
-            (in_postcopy && !iterable_only) ||
             !se->ops->save_live_complete_precopy) {
             continue;
         }
@@ -1369,10 +1367,11 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
 
     cpu_synchronize_all_states();
 
-    ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy,
-                                                      iterable_only);
-    if (ret) {
-        return ret;
+    if (!in_postcopy || iterable_only) {
+        ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy);
+        if (ret) {
+            return ret;
+        }
     }
 
     if (iterable_only) {
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#8 lore raw
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Wei Yang ([email protected]) wrote:

in_postcopy and iterable_only are not SaveStateEntry specific, it would be more proper to check them out of iteration.

Worth it just to make that big if statement simpler!

Yep, the original one looks a little hard to understand.

Thanks for your comment.

Quoted 50 lines
Quoted 45 lines
---
 migration/savevm.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
migration/savevm.c +6 -7
index c41e13e322..8a2ada529e 100644
@@ -1247,8 +1247,7 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f)
 }
 
 static
-int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
-                                                bool iterable_only)
+int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy)
 {
     SaveStateEntry *se;
     int ret;
@@ -1257,7 +1256,6 @@ int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy,
         if (!se->ops ||
             (in_postcopy && se->ops->has_postcopy &&
              se->ops->has_postcopy(se->opaque)) ||
-            (in_postcopy && !iterable_only) ||
             !se->ops->save_live_complete_precopy) {
             continue;
         }
@@ -1369,10 +1367,11 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
 
     cpu_synchronize_all_states();
 
-    ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy,
-                                                      iterable_only);
-    if (ret) {
-        return ret;
+    if (!in_postcopy || iterable_only) {
+        ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy);
+        if (ret) {
+            return ret;
+        }
     }
 
     if (iterable_only) {
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
#9 lore raw
In reply to Wei Yang
Quoted 10 lines · * Wei Yang ([email protected]) wrote:

qemu_savevm_state_complete_precopy() iterates SaveStateEntry and does proper tasks for migration.

For each iteration, in_postcopy and iterable_only would be checked to see whether it should skip. Since these two conditions are not SaveStateEntry specific, it is proper to move the check out of iteration.

These three patches prepare the code and move the condition check out of the iteration.

Queued

Quoted 8 lines

Wei Yang (3):
migration/savevm: flush file for iterable_only case migration/savevm: split qemu_savevm_state_complete_precopy() into two
parts
migration/savevm: move non SaveStateEntry condition check out of
iteration

Quoted 7 lines
 migration/savevm.c | 68 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 50 insertions(+), 18 deletions(-)
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK