From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org, Eduardo Habkost <eduardo@habkost.net>,
Markus Armbruster <armbru@redhat.com>,
"Daniel P . Berrange" <berrange@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Thomas Huth" <thuth@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>,
qemu-block@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>
Subject: [RFC PATCH 3/4] util: Introduce helpers to compare QEMU versions
Date: Mon, 9 Jan 2023 23:54:18 +0100 [thread overview]
Message-ID: <20230109225419.22621-4-philmd@linaro.org> (raw)
In-Reply-To: <20230109225419.22621-1-philmd@linaro.org>
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
next prev parent reply other threads:[~2023-01-09 22:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-09 22:54 [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate() Philippe Mathieu-Daudé
2023-01-09 22:54 ` [RFC PATCH 1/4] " Philippe Mathieu-Daudé
2023-01-10 9:52 ` Daniel P. Berrangé
2023-01-10 9:55 ` Daniel P. Berrangé
2023-01-09 22:54 ` [RFC PATCH 2/4] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width' Philippe Mathieu-Daudé
2023-01-10 9:50 ` Daniel P. Berrangé
2023-01-09 22:54 ` Philippe Mathieu-Daudé [this message]
2023-01-09 22:54 ` [RFC PATCH 4/4] qom: Warn when deprecated class property can be removed Philippe Mathieu-Daudé
2023-01-10 9:34 ` Bernhard Beschow
2023-01-10 9:49 ` Daniel P. Berrangé
2023-01-10 13:02 ` [RFC PATCH 0/4] qom: Introduce object_class_property_deprecate() Kevin Wolf
2023-01-11 9:55 ` Philippe Mathieu-Daudé
2023-01-11 9:59 ` Daniel P. Berrangé
2023-01-11 10:08 ` Philippe Mathieu-Daudé
2023-01-11 10:29 ` Daniel P. Berrangé
2023-01-11 11:29 ` Markus Armbruster
2023-01-11 13:15 ` Philippe Mathieu-Daudé
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=20230109225419.22621-4-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eduardo@habkost.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).