[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 3/4] util: Introduce helpers to compare QEMU versions
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 3/4] util: Introduce helpers to compare QEMU versions |
Date: |
Mon, 9 Jan 2023 23:54:18 +0100 |
Add qemu_version_delta() to compare 2 QEMU versions,
and qemu_version_delta_current() to compare with the
current QEMU version.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/qemu/qemu-version.h | 36 ++++++++++++++++++++++++++++++++++++
util/meson.build | 1 +
util/qemu-version.c | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+)
create mode 100644 include/qemu/qemu-version.h
create mode 100644 util/qemu-version.c
diff --git a/include/qemu/qemu-version.h b/include/qemu/qemu-version.h
new file mode 100644
index 0000000000..c9274bfaf0
--- /dev/null
+++ b/include/qemu/qemu-version.h
@@ -0,0 +1,36 @@
+/*
+ * Utility function around QEMU release version
+ *
+ * Copyright (c) 2023 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_UTIL_VERSION_H
+#define QEMU_UTIL_VERSION_H
+
+/**
+ * qemu_version_delta - Return delta between two release versions ('A' and
'B').
+ * @version_major_a: Version 'A' major number
+ * @version_minor_a: Version 'A' minor number
+ * @version_major_b: Version 'B' major number
+ * @version_minor_b: Version 'B' minor number
+ *
+ * Returns a negative number is returned if 'A' is older than 'B', or positive
+ * if 'A' is newer than 'B'. The number represents the number of minor
versions.
+ */
+int qemu_version_delta(unsigned version_major_a, unsigned version_minor_a,
+ unsigned version_major_b, unsigned version_minor_b);
+
+/**
+ * qemu_version_delta_current - Return delta with current QEMU release version.
+ * @version_major: The major version
+ * @version_minor: The minor version
+ *
+ * Returns the number of minor versions between the current released
+ * version and the requested $major.$minor. A negative number is returned
+ * for older versions and positive for newer.
+ */
+int qemu_version_delta_current(unsigned version_major, unsigned version_minor);
+
+#endif
diff --git a/util/meson.build b/util/meson.build
index d8d109ff84..655debeec1 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -58,6 +58,7 @@ util_ss.add(files('yank.c'))
util_ss.add(files('int128.c'))
util_ss.add(files('memalign.c'))
util_ss.add(files('interval-tree.c'))
+util_ss.add(files('qemu-version.c'))
if have_user
util_ss.add(files('selfmap.c'))
diff --git a/util/qemu-version.c b/util/qemu-version.c
new file mode 100644
index 0000000000..d409a6e574
--- /dev/null
+++ b/util/qemu-version.c
@@ -0,0 +1,37 @@
+/*
+ * Utility function around QEMU release version
+ *
+ * Copyright (c) 2023 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/qemu-version.h"
+#include "config-host.h"
+
+#define QEMU_FIRST_MAJOR_VERSION_SUPPORTED 4
+#define QEMU_MINOR_VERSIONS_PER_MAJOR 3
+
+int qemu_version_delta(unsigned version_major_a, unsigned version_minor_a,
+ unsigned version_major_b, unsigned version_minor_b)
+{
+ int delta;
+
+ assert(version_major_a >= QEMU_FIRST_MAJOR_VERSION_SUPPORTED);
+ assert(version_major_b >= QEMU_FIRST_MAJOR_VERSION_SUPPORTED);
+ assert(version_minor_a < QEMU_MINOR_VERSIONS_PER_MAJOR);
+ assert(version_minor_b < QEMU_MINOR_VERSIONS_PER_MAJOR);
+
+ delta = version_major_b - version_major_a;
+ delta *= QEMU_MINOR_VERSIONS_PER_MAJOR;
+ delta += version_minor_b - version_minor_a;
+
+ return delta;
+}
+
+int qemu_version_delta_current(unsigned version_major, unsigned version_minor)
+{
+ return qemu_version_delta(QEMU_VERSION_MAJOR, QEMU_VERSION_MINOR,
+ version_major, version_minor);
+}
--
2.38.1
- [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Philippe Mathieu-Daudé, 2023/01/09
- [RFC PATCH 1/4] qom: Introduce object_class_property_deprecate(), Philippe Mathieu-Daudé, 2023/01/09
- [RFC PATCH 2/4] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width', Philippe Mathieu-Daudé, 2023/01/09
- [RFC PATCH 3/4] util: Introduce helpers to compare QEMU versions,
Philippe Mathieu-Daudé <=
- [RFC PATCH 4/4] qom: Warn when deprecated class property can be removed, Philippe Mathieu-Daudé, 2023/01/09
- Re: [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Kevin Wolf, 2023/01/10
- Re: [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Philippe Mathieu-Daudé, 2023/01/11
- Re: [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Daniel P . Berrangé, 2023/01/11
- Re: [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Philippe Mathieu-Daudé, 2023/01/11
- Re: [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Daniel P . Berrangé, 2023/01/11
- Re: [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Markus Armbruster, 2023/01/11
- Re: [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate(), Philippe Mathieu-Daudé, 2023/01/11