[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/9] migration: check required subsections are loaded, once
From: |
marcandre . lureau |
Subject: |
[PATCH v2 5/9] migration: check required subsections are loaded, once |
Date: |
Tue, 24 Oct 2023 12:40:39 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Check that required subsections have been loaded.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
migration/vmstate.c | 40 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)
diff --git a/migration/vmstate.c b/migration/vmstate.c
index 16e33a5d34..d6fe38a5e1 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -451,22 +451,51 @@ int vmstate_save_state_v(QEMUFile *f, const
VMStateDescription *vmsd,
}
static const VMStateDescription *
-vmstate_get_subsection(const VMStateDescription **sub, char *idstr)
+vmstate_get_subsection(const VMStateDescription **sub, char *idstr, bool
*visited)
{
+ size_t i = 0;
+
while (sub && *sub) {
if (strcmp(idstr, (*sub)->name) == 0) {
+ if (visited[i]) {
+ return NULL;
+ }
+ visited[i] = true;
return *sub;
}
+ i++;
sub++;
}
return NULL;
}
+static size_t
+vmstate_get_n_subsections(const VMStateDescription **sub)
+{
+ size_t n = 0;
+
+ if (!sub) {
+ return 0;
+ }
+
+ while (sub[n]) {
+ n++;
+ }
+
+ return n;
+}
+
static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque)
{
+ size_t i, n;
+ g_autofree bool *visited = NULL;
+
trace_vmstate_subsection_load(vmsd->name);
+ n = vmstate_get_n_subsections(vmsd->subsections);
+ visited = g_new0(bool, n);
+
while (qemu_peek_byte(f, 0) == QEMU_VM_SUBSECTION) {
char idstr[256], *idstr_ret;
int ret;
@@ -492,7 +521,7 @@ static int vmstate_subsection_load(QEMUFile *f, const
VMStateDescription *vmsd,
/* it doesn't have a valid subsection name */
return 0;
}
- sub_vmsd = vmstate_get_subsection(vmsd->subsections, idstr);
+ sub_vmsd = vmstate_get_subsection(vmsd->subsections, idstr, visited);
if (sub_vmsd == NULL) {
trace_vmstate_subsection_load_bad(vmsd->name, idstr, "(lookup)");
return -ENOENT;
@@ -509,6 +538,13 @@ static int vmstate_subsection_load(QEMUFile *f, const
VMStateDescription *vmsd,
}
}
+ for (i = 0; i < n; i++) {
+ if (!visited[i] && vmstate_section_needed(vmsd->subsections[i],
opaque)) {
+ trace_vmstate_subsection_load_bad(vmsd->name,
vmsd->subsections[i]->name, "(not visited)");
+ return -ENOENT;
+ }
+ }
+
trace_vmstate_subsection_load_good(vmsd->name);
return 0;
}
--
2.41.0
- [PATCH v2 0/9] RFC: migration: check required entries and sections are loaded, marcandre . lureau, 2023/10/24
- [PATCH v2 1/9] block/fdc: 'phase' is not needed on load, marcandre . lureau, 2023/10/24
- [PATCH v2 2/9] virtio: make endian_needed() work during loading, marcandre . lureau, 2023/10/24
- [PATCH v2 4/9] migration: rename vmstate_save_needed->vmstate_section_needed, marcandre . lureau, 2023/10/24
- [PATCH v2 3/9] net/slirp: use different IDs for each instance, marcandre . lureau, 2023/10/24
- [PATCH v2 6/9] migration: check required entries are loaded, once, marcandre . lureau, 2023/10/24
- [PATCH v2 5/9] migration: check required subsections are loaded, once,
marcandre . lureau <=
- [PATCH v2 8/9] test-vmstate: add some subsection tests, marcandre . lureau, 2023/10/24
- [PATCH v2 7/9] migration: set file error on subsection loading, marcandre . lureau, 2023/10/24
- [PATCH v2 9/9] docs/migration: reflect the changes about needed subsections, marcandre . lureau, 2023/10/24