diff mbox series

[v3,3/5] hw/boards: add machine_check_version()

Message ID 20240515141557.1277999-4-marcandre.lureau@redhat.com
State New
Headers show
Series Fix "virtio-gpu: fix scanout migration post-load" | expand

Commit Message

Marc-André Lureau May 15, 2024, 2:15 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Add optional major/minor version fields to the MachineClass, and a
helper to check if the current machine version is >= (major, minor).

This function can be used to check for extra migration fields, instead
of relying on structure version which are typically associated to a
machine version via compatibility properties.

Notes:
- undefined version is considered latest
- a few machines have a micro version, I don't think it's necessary to
  have here at this point
- there is already a less formal char *hw_version, but it is only used
  for legacy code (< 2.5)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/boards.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/include/hw/boards.h b/include/hw/boards.h
index 2fa800f11a..b36a363fb7 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -248,6 +248,8 @@  struct MachineClass {
     const char *alias;
     const char *desc;
     const char *deprecation_reason;
+    unsigned int major;
+    unsigned int minor;
 
     void (*init)(MachineState *state);
     void (*reset)(MachineState *state, ShutdownCause reason);
@@ -306,6 +308,18 @@  struct MachineClass {
     ram_addr_t (*fixup_ram_size)(ram_addr_t size);
 };
 
+static inline bool machine_check_version(int major, int minor)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
+
+    /* unversioned is latest */
+    if (mc->major == 0 && mc->minor == 0) {
+        return true;
+    }
+
+    return mc->major > major || (mc->major == major && mc->minor >= minor);
+}
+
 /**
  * DeviceMemoryState:
  * @base: address in guest physical address space where the memory