All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Coiby Xu" <Coiby.Xu@gmail.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"John Snow" <jsnow@redhat.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
	qemu-block@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Fam Zheng" <fam@euphon.net>,
	qemu-s390x@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>
Subject: [PULL 23/26] migration: Perform vmsd structure check during tests
Date: Thu,  2 Feb 2023 17:06:37 +0100	[thread overview]
Message-ID: <20230202160640.2300-24-quintela@redhat.com> (raw)
In-Reply-To: <20230202160640.2300-1-quintela@redhat.com>

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Perform a check on vmsd structures during test runs in the hope
of catching any missing terminators and other simple screwups.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/savevm.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/migration/savevm.c b/migration/savevm.c
index 5c3e5b1bb5..e9cf4999ad 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -66,6 +66,7 @@
 #include "net/announce.h"
 #include "qemu/yank.h"
 #include "yank_functions.h"
+#include "sysemu/qtest.h"
 
 const unsigned int postcopy_ram_discard_version;
 
@@ -804,6 +805,42 @@ void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque)
     }
 }
 
+/*
+ * Perform some basic checks on vmsd's at registration
+ * time.
+ */
+static void vmstate_check(const VMStateDescription *vmsd)
+{
+    const VMStateField *field = vmsd->fields;
+    const VMStateDescription **subsection = vmsd->subsections;
+
+    if (field) {
+        while (field->name) {
+            if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) {
+                /* Recurse to sub structures */
+                vmstate_check(field->vmsd);
+            }
+            /* Carry on */
+            field++;
+        }
+        /* Check for the end of field list canary */
+        if (field->flags != VMS_END) {
+            error_report("VMSTATE not ending with VMS_END: %s", vmsd->name);
+            g_assert_not_reached();
+        }
+    }
+
+    while (subsection && *subsection) {
+        /*
+         * The name of a subsection should start with the name of the
+         * current object.
+         */
+        assert(!strncmp(vmsd->name, (*subsection)->name, strlen(vmsd->name)));
+        vmstate_check(*subsection);
+        subsection++;
+    }
+}
+
 int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id,
                                    const VMStateDescription *vmsd,
                                    void *opaque, int alias_id,
@@ -849,6 +886,11 @@ int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id,
     } else {
         se->instance_id = instance_id;
     }
+
+    /* Perform a recursive sanity check during the test runs */
+    if (qtest_enabled()) {
+        vmstate_check(vmsd);
+    }
     assert(!se->compat || se->instance_id == 0);
     savevm_state_handler_insert(se);
     return 0;
-- 
2.39.1



  parent reply	other threads:[~2023-02-02 16:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 16:06 [PULL 00/26] Next patches Juan Quintela
2023-02-02 16:06 ` [PULL 01/26] migration: Fix migration crash when target psize larger than host Juan Quintela
2023-02-02 16:06 ` [PULL 02/26] migration: No save_live_pending() method uses the QEMUFile parameter Juan Quintela
2023-02-02 16:06 ` [PULL 03/26] migration: Split save_live_pending() into state_pending_* Juan Quintela
2023-02-02 16:06 ` [PULL 04/26] migration: Remove unused threshold_size parameter Juan Quintela
2023-02-02 16:06 ` [PULL 05/26] migration: simplify migration_iteration_run() Juan Quintela
2023-02-02 16:06 ` [PULL 06/26] util/userfaultfd: Add uffd_open() Juan Quintela
2023-02-02 16:06 ` [PULL 07/26] migration/ram: Fix populate_read_range() Juan Quintela
2023-02-02 16:06 ` [PULL 08/26] migration/ram: Fix error handling in ram_write_tracking_start() Juan Quintela
2023-02-02 16:06 ` [PULL 09/26] migration/ram: Don't explicitly unprotect when unregistering uffd-wp Juan Quintela
2023-02-02 16:06 ` [PULL 10/26] migration/ram: Rely on used_length for uffd_change_protection() Juan Quintela
2023-02-02 16:06 ` [PULL 11/26] migration/ram: Optimize ram_write_tracking_start() for RamDiscardManager Juan Quintela
2023-02-02 16:06 ` [PULL 12/26] migration/savevm: Move more savevm handling into vmstate_save() Juan Quintela
2023-02-02 16:06 ` [PULL 13/26] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup() Juan Quintela
2023-02-02 16:06 ` [PULL 14/26] migration/savevm: Allow immutable device state to be migrated early (i.e., before RAM) Juan Quintela
2023-02-02 16:06 ` [PULL 15/26] migration/vmstate: Introduce VMSTATE_WITH_TMP_TEST() and VMSTATE_BITMAP_TEST() Juan Quintela
2023-02-02 16:06 ` [PULL 16/26] migration/ram: Factor out check for advised postcopy Juan Quintela
2023-02-02 16:06 ` [PULL 17/26] virtio-mem: Fail if a memory backend with "prealloc=on" is specified Juan Quintela
2023-02-02 16:06 ` [PULL 18/26] virtio-mem: Migrate immutable properties early Juan Quintela
2023-02-02 16:06 ` [PULL 19/26] virtio-mem: Proper support for preallocation with migration Juan Quintela
2023-02-02 16:06 ` [PULL 20/26] migration: Show downtime during postcopy phase Juan Quintela
2023-02-02 16:06 ` [PULL 21/26] migration/rdma: fix return value for qio_channel_rdma_{readv, writev} Juan Quintela
2023-02-02 16:06 ` [PULL 22/26] migration: Add canary to VMSTATE_END_OF_LIST Juan Quintela
2023-02-02 16:06 ` Juan Quintela [this message]
2023-02-02 16:06 ` [PULL 24/26] migration/dirtyrate: Show sample pages only in page-sampling mode Juan Quintela
2023-02-02 16:06 ` [PULL 25/26] io: Add support for MSG_PEEK for socket channel Juan Quintela
2023-02-02 16:06 ` [PULL 26/26] migration: check magic value for deciding the mapping of channels Juan Quintela
2023-02-04 10:19 ` [PULL 00/26] Next patches Peter Maydell
2023-02-06 22:06   ` Peter Xu
2023-02-06 23:33     ` Juan Quintela
2023-02-07  0:49 ` Juan Quintela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230202160640.2300-24-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=Coiby.Xu@gmail.com \
    --cc=alex.williamson@redhat.com \
    --cc=berrange@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=fam@euphon.net \
    --cc=farman@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=jsnow@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    --cc=wangyanan55@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.