We have a trick in vmstate_save_vmsd_v() where we will try to compress
multiple JSON vmstate field dumps into one line with a count to avoid
duplicated entries.

That only applies to the cases where vmsd_can_compress() should return
true.  For example, vmsd_desc_field_start() later (who will take the
updated max_elems as the last parameter) will ignore the value passed in
when vmsd_can_compress() returns false.

Add that check to the trick too, it will be used later to bypass this logic
to some special new VMSD fields.

No functional change intended in this patch alone.

Signed-off-by: Peter Xu <[email protected]>
---
 migration/vmstate.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/migration/vmstate.c b/migration/vmstate.c
index e29a8c3f49..caa7b50bce 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -578,7 +578,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const 
VMStateDescription *vmsd,
                 }
 
                 /*
-                 * This logic only matters when dumping VM Desc.
+                 * This logic only matters when dumping VM Desc, and only
+                 * when the VMSD field can be compressed.
                  *
                  * Due to the fake nullptr handling above, if there's mixed
                  * null/non-null data, it doesn't make sense to emit a
@@ -587,7 +588,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const 
VMStateDescription *vmsd,
                  * vs. nullptr). Search ahead for the next null/non-null 
element
                  * and start a new compressed array if found.
                  */
-                if (vmdesc && (field->flags & VMS_ARRAY_OF_POINTER) &&
+                if (vmdesc && vmsd_can_compress(field) &&
+                    (field->flags & VMS_ARRAY_OF_POINTER) &&
                     is_null != is_prev_null) {
 
                     is_prev_null = is_null;
-- 
2.50.1


Reply via email to