[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/30] migration/savevm: Move more savevm handling into vmstate_sa
From: |
Juan Quintela |
Subject: |
[PULL 12/30] migration/savevm: Move more savevm handling into vmstate_save() |
Date: |
Tue, 7 Feb 2023 01:56:32 +0100 |
From: David Hildenbrand <david@redhat.com>
Let's move more code into vmstate_save(), reducing code duplication and
preparing for reuse of vmstate_save() in qemu_savevm_state_setup(). We
have to move vmstate_save() to make the compiler happy.
We'll now also trace from qemu_save_device_state(), triggering the same
tracepoints as previously called from
qemu_savevm_state_complete_precopy_non_iterable() only. Note that
qemu_save_device_state() ignores iterable device state, such as RAM,
and consequently doesn't trigger some other trace points (e.g.,
trace_savevm_state_setup()).
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/savevm.c | 79 ++++++++++++++++++++++------------------------
1 file changed, 37 insertions(+), 42 deletions(-)
diff --git a/migration/savevm.c b/migration/savevm.c
index e1caa3ea7c..3e3631652e 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -898,17 +898,6 @@ static void vmstate_save_old_style(QEMUFile *f,
SaveStateEntry *se,
}
}
-static int vmstate_save(QEMUFile *f, SaveStateEntry *se,
- JSONWriter *vmdesc)
-{
- trace_vmstate_save(se->idstr, se->vmsd ? se->vmsd->name : "(old)");
- if (!se->vmsd) {
- vmstate_save_old_style(f, se, vmdesc);
- return 0;
- }
- return vmstate_save_state(f, se->vmsd, se->opaque, vmdesc);
-}
-
/*
* Write the header for device section (QEMU_VM_SECTION START/END/PART/FULL)
*/
@@ -942,6 +931,43 @@ static void save_section_footer(QEMUFile *f,
SaveStateEntry *se)
}
}
+static int vmstate_save(QEMUFile *f, SaveStateEntry *se, JSONWriter *vmdesc)
+{
+ int ret;
+
+ if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
+ return 0;
+ }
+ if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) {
+ trace_savevm_section_skip(se->idstr, se->section_id);
+ return 0;
+ }
+
+ trace_savevm_section_start(se->idstr, se->section_id);
+ save_section_header(f, se, QEMU_VM_SECTION_FULL);
+ if (vmdesc) {
+ json_writer_start_object(vmdesc, NULL);
+ json_writer_str(vmdesc, "name", se->idstr);
+ json_writer_int64(vmdesc, "instance_id", se->instance_id);
+ }
+
+ trace_vmstate_save(se->idstr, se->vmsd ? se->vmsd->name : "(old)");
+ if (!se->vmsd) {
+ vmstate_save_old_style(f, se, vmdesc);
+ } else {
+ ret = vmstate_save_state(f, se->vmsd, se->opaque, vmdesc);
+ if (ret) {
+ return ret;
+ }
+ }
+
+ trace_savevm_section_end(se->idstr, se->section_id, 0);
+ save_section_footer(f, se);
+ if (vmdesc) {
+ json_writer_end_object(vmdesc);
+ }
+ return 0;
+}
/**
* qemu_savevm_command_send: Send a 'QEMU_VM_COMMAND' type element with the
* command and associated data.
@@ -1375,31 +1401,11 @@ int
qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
json_writer_int64(vmdesc, "page_size", qemu_target_page_size());
json_writer_start_array(vmdesc, "devices");
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
-
- if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
- continue;
- }
- if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) {
- trace_savevm_section_skip(se->idstr, se->section_id);
- continue;
- }
-
- trace_savevm_section_start(se->idstr, se->section_id);
-
- json_writer_start_object(vmdesc, NULL);
- json_writer_str(vmdesc, "name", se->idstr);
- json_writer_int64(vmdesc, "instance_id", se->instance_id);
-
- save_section_header(f, se, QEMU_VM_SECTION_FULL);
ret = vmstate_save(f, se, vmdesc);
if (ret) {
qemu_file_set_error(f, ret);
return ret;
}
- trace_savevm_section_end(se->idstr, se->section_id, 0);
- save_section_footer(f, se);
-
- json_writer_end_object(vmdesc);
}
if (inactivate_disks) {
@@ -1618,21 +1624,10 @@ int qemu_save_device_state(QEMUFile *f)
if (se->is_ram) {
continue;
}
- if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
- continue;
- }
- if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) {
- continue;
- }
-
- save_section_header(f, se, QEMU_VM_SECTION_FULL);
-
ret = vmstate_save(f, se, NULL);
if (ret) {
return ret;
}
-
- save_section_footer(f, se);
}
qemu_put_byte(f, QEMU_VM_EOF);
--
2.39.1
- Re: [PULL 03/30] migration: Split save_live_pending() into state_pending_*, (continued)
- [PULL 05/30] migration: simplify migration_iteration_run(), Juan Quintela, 2023/02/06
- [PULL 06/30] util/userfaultfd: Add uffd_open(), Juan Quintela, 2023/02/06
- [PULL 07/30] migration/ram: Fix populate_read_range(), Juan Quintela, 2023/02/06
- [PULL 08/30] migration/ram: Fix error handling in ram_write_tracking_start(), Juan Quintela, 2023/02/06
- [PULL 09/30] migration/ram: Don't explicitly unprotect when unregistering uffd-wp, Juan Quintela, 2023/02/06
- [PULL 10/30] migration/ram: Rely on used_length for uffd_change_protection(), Juan Quintela, 2023/02/06
- [PULL 11/30] migration/ram: Optimize ram_write_tracking_start() for RamDiscardManager, Juan Quintela, 2023/02/06
- [PULL 13/30] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup(), Juan Quintela, 2023/02/06
- [PULL 12/30] migration/savevm: Move more savevm handling into vmstate_save(),
Juan Quintela <=
- [PULL 14/30] migration/savevm: Allow immutable device state to be migrated early (i.e., before RAM), Juan Quintela, 2023/02/06
- [PULL 15/30] migration/vmstate: Introduce VMSTATE_WITH_TMP_TEST() and VMSTATE_BITMAP_TEST(), Juan Quintela, 2023/02/06
- [PULL 16/30] migration/ram: Factor out check for advised postcopy, Juan Quintela, 2023/02/06
- [PULL 17/30] virtio-mem: Fail if a memory backend with "prealloc=on" is specified, Juan Quintela, 2023/02/06
- [PULL 18/30] virtio-mem: Migrate immutable properties early, Juan Quintela, 2023/02/06
- [PULL 19/30] virtio-mem: Proper support for preallocation with migration, Juan Quintela, 2023/02/06
- [PULL 20/30] migration: Show downtime during postcopy phase, Juan Quintela, 2023/02/06
- [PULL 21/30] migration/rdma: fix return value for qio_channel_rdma_{readv, writev}, Juan Quintela, 2023/02/06
- [PULL 22/30] migration: Add canary to VMSTATE_END_OF_LIST, Juan Quintela, 2023/02/06
- [PULL 23/30] migration: Perform vmsd structure check during tests, Juan Quintela, 2023/02/06