[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 16/21] Merge section header writing
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PULL 16/21] Merge section header writing |
Date: |
Wed, 3 Jun 2015 14:05:52 +0200 |
From: "Dr. David Alan Gilbert" <address@hidden>
The header writing for device sections is open coded in
a few places, merge it into one.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
migration/savevm.c | 72 +++++++++++++++++++++---------------------------------
1 file changed, 28 insertions(+), 44 deletions(-)
diff --git a/migration/savevm.c b/migration/savevm.c
index 5324c4c..2942ed6 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -611,6 +611,27 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se,
QJSON *vmdesc)
vmstate_save_state(f, se->vmsd, se->opaque, vmdesc);
}
+/*
+ * Write the header for device section (QEMU_VM_SECTION START/END/PART/FULL)
+ */
+static void save_section_header(QEMUFile *f, SaveStateEntry *se,
+ uint8_t section_type)
+{
+ qemu_put_byte(f, section_type);
+ qemu_put_be32(f, se->section_id);
+
+ if (section_type == QEMU_VM_SECTION_FULL ||
+ section_type == QEMU_VM_SECTION_START) {
+ /* ID string */
+ size_t len = strlen(se->idstr);
+ qemu_put_byte(f, len);
+ qemu_put_buffer(f, (uint8_t *)se->idstr, len);
+
+ qemu_put_be32(f, se->instance_id);
+ qemu_put_be32(f, se->version_id);
+ }
+}
+
bool qemu_savevm_state_blocked(Error **errp)
{
SaveStateEntry *se;
@@ -647,8 +668,6 @@ void qemu_savevm_state_begin(QEMUFile *f,
}
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
- int len;
-
if (!se->ops || !se->ops->save_live_setup) {
continue;
}
@@ -657,17 +676,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
continue;
}
}
- /* Section type */
- qemu_put_byte(f, QEMU_VM_SECTION_START);
- qemu_put_be32(f, se->section_id);
-
- /* ID string */
- len = strlen(se->idstr);
- qemu_put_byte(f, len);
- qemu_put_buffer(f, (uint8_t *)se->idstr, len);
-
- qemu_put_be32(f, se->instance_id);
- qemu_put_be32(f, se->version_id);
+ save_section_header(f, se, QEMU_VM_SECTION_START);
ret = se->ops->save_live_setup(f, se->opaque);
if (ret < 0) {
@@ -702,9 +711,8 @@ int qemu_savevm_state_iterate(QEMUFile *f)
return 0;
}
trace_savevm_section_start(se->idstr, se->section_id);
- /* Section type */
- qemu_put_byte(f, QEMU_VM_SECTION_PART);
- qemu_put_be32(f, se->section_id);
+
+ save_section_header(f, se, QEMU_VM_SECTION_PART);
ret = se->ops->save_live_iterate(f, se->opaque);
trace_savevm_section_end(se->idstr, se->section_id, ret);
@@ -750,9 +758,8 @@ void qemu_savevm_state_complete(QEMUFile *f)
}
}
trace_savevm_section_start(se->idstr, se->section_id);
- /* Section type */
- qemu_put_byte(f, QEMU_VM_SECTION_END);
- qemu_put_be32(f, se->section_id);
+
+ save_section_header(f, se, QEMU_VM_SECTION_END);
ret = se->ops->save_live_complete(f, se->opaque);
trace_savevm_section_end(se->idstr, se->section_id, ret);
@@ -766,7 +773,6 @@ void qemu_savevm_state_complete(QEMUFile *f)
json_prop_int(vmdesc, "page_size", TARGET_PAGE_SIZE);
json_start_array(vmdesc, "devices");
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
- int len;
if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
continue;
@@ -777,17 +783,7 @@ void qemu_savevm_state_complete(QEMUFile *f)
json_prop_str(vmdesc, "name", se->idstr);
json_prop_int(vmdesc, "instance_id", se->instance_id);
- /* Section type */
- qemu_put_byte(f, QEMU_VM_SECTION_FULL);
- qemu_put_be32(f, se->section_id);
-
- /* ID string */
- len = strlen(se->idstr);
- qemu_put_byte(f, len);
- qemu_put_buffer(f, (uint8_t *)se->idstr, len);
-
- qemu_put_be32(f, se->instance_id);
- qemu_put_be32(f, se->version_id);
+ save_section_header(f, se, QEMU_VM_SECTION_FULL);
vmstate_save(f, se, vmdesc);
@@ -887,8 +883,6 @@ static int qemu_save_device_state(QEMUFile *f)
cpu_synchronize_all_states();
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
- int len;
-
if (se->is_ram) {
continue;
}
@@ -896,17 +890,7 @@ static int qemu_save_device_state(QEMUFile *f)
continue;
}
- /* Section type */
- qemu_put_byte(f, QEMU_VM_SECTION_FULL);
- qemu_put_be32(f, se->section_id);
-
- /* ID string */
- len = strlen(se->idstr);
- qemu_put_byte(f, len);
- qemu_put_buffer(f, (uint8_t *)se->idstr, len);
-
- qemu_put_be32(f, se->instance_id);
- qemu_put_be32(f, se->version_id);
+ save_section_header(f, se, QEMU_VM_SECTION_FULL);
vmstate_save(f, se, NULL);
}
--
2.4.1
- [Qemu-devel] [PULL 01/21] migration: move ram stuff to migration/ram, (continued)
- [Qemu-devel] [PULL 01/21] migration: move ram stuff to migration/ram, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 08/21] migration: create savevm_state, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 11/21] Split header writing out of qemu_savevm_state_begin, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 09/21] migration: Use normal VMStateDescriptions for Subsections, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 12/21] qemu_ram_foreach_block: pass up error value, and down the ramblock name, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 14/21] Move copy out of qemu_peek_buffer, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 10/21] Add qemu_get_counted_string to read a string prefixed by a count byte, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 13/21] Create MigrationIncomingState, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 15/21] Move loadvm_handlers into MigrationIncomingState, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 19/21] Teach analyze-migration.py about section footers, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 16/21] Merge section header writing,
Juan Quintela <=
- [Qemu-devel] [PULL 17/21] Disable section footers on older machine types, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 18/21] Add a protective section footer, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 20/21] Rename RDMA structures to make destination clear, Juan Quintela, 2015/06/03
- [Qemu-devel] [PULL 21/21] Remove unneeded memset, Juan Quintela, 2015/06/03
- Re: [Qemu-devel] [PULL 00/21] Migration pull request, Peter Maydell, 2015/06/04