From patchwork Mon Jan 9 22:54:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 640707 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp2398944pvb; Mon, 9 Jan 2023 14:56:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXv2SGuw2gEYODThA/YXawJ2eDymDU3Q2StDzyK0a0B9eRmOwzV8rBWTgJbSQOVvaxqpMMf2 X-Received: by 2002:ad4:5287:0:b0:532:3194:8433 with SMTP id v7-20020ad45287000000b0053231948433mr5525298qvr.35.1673304995990; Mon, 09 Jan 2023 14:56:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673304995; cv=none; d=google.com; s=arc-20160816; b=GcyGulja5RhNKAhvvih4SAf0x06zc+i9rfihqSymlp7OZtwQW+jsNmNdNADCFw3LaW 8Sg+pC4Lq5e+BTSmW2omEKqsEIvEsSHUs2QyEcLDdqF3nuaKUs7JKP4SMHRYLuo6apXi arINB6RQvGe25RrORX6z1mv7LzMzP5FmWuxOlHnKux/pRJhNzubqy8mxXCbSBNlhMgfl gtKFsfuOeK5mwA9eNoPslJqFvsTKuyFRexG7bxOdMg1oX8w9cmoH8p83lOYJLQBOsoMx 7y9Sn5qSQPPkbhTyfqw8komJq5USiXQPcc1GDXdegs7+VUB/vxqLtwWAYIziTT8n7K6d uWYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zmsiOvblx944I2vPr/ngo2q8F1qd2s6a6mFL2ICxK8U=; b=dMf1KbyTT90yGmR670Crs5IMY0ZZswTqpV4D9K9epca+nNoYNsKas5ENrZgNTSNoyu pODD7pq6aGQF6wOdIwTLXdT13tcORpvPddiD/XREOgMfm6JeG4PWuvRmA/8kjMOQuayH kUxu+SwbqaXfTjkq+JxwnYb+RZTQbFZQv3QesPQ6tL/N5GVMIlZTOjV/x205gWTSLRQH C+WoAwgaNjcTG1qyT553Xeh5WoGJFb0n/7g+6m1DygZtTusN2P8Uwfq7ecNNsPW+3qQE H+oeKakZtysuSAMOdC4WFYVizGhfIlnl/XGlmP7vVS2rhyVodqUglu22COuoUJCPolYf y1Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zBOlBtqP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m8-20020ad45dc8000000b00531de4aac51si5307714qvh.244.2023.01.09.14.56.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jan 2023 14:56:35 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zBOlBtqP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pF12T-00058X-4L; Mon, 09 Jan 2023 17:54:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pF12Q-00051R-4W for qemu-devel@nongnu.org; Mon, 09 Jan 2023 17:54:42 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pF12N-0007jm-Pd for qemu-devel@nongnu.org; Mon, 09 Jan 2023 17:54:41 -0500 Received: by mail-wm1-x32a.google.com with SMTP id bi26-20020a05600c3d9a00b003d3404a89faso80472wmb.1 for ; Mon, 09 Jan 2023 14:54:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zmsiOvblx944I2vPr/ngo2q8F1qd2s6a6mFL2ICxK8U=; b=zBOlBtqPleDHf0VdO+y+cAIUshMH5wpIxsHdQ1/8Ysxewl1rpAxa0IohtYijfMmaFw 40lem8oQt0rbRt/u2PfxdcX4BcBBwHjzc+wxi3ZRb9IsSaLQo/xy79kali1Dz6fL+ZQ2 hHz8RwTTfKtBo/Tx9734tp7U+oNJCzbf8oStlbk6YwLz/dHpvKD5mAVLxCvkJ4GZ0N8K J5GdZjwR+HXN+tQXNgFjYi5gad0a4O2rHEWnotR8WsqfCrIrYmwryxDbYttxM2Jt/sNY B/0NZ2z+4RxUMOuGB4mEXhgTKJyKtzuV/FkJutV8BuwExV6ehmXhuhxJKMJyUExeWOPx 69BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zmsiOvblx944I2vPr/ngo2q8F1qd2s6a6mFL2ICxK8U=; b=pEwmIVELwcwbF3VbHDWl0eNfTNcWu0XfvHrbSkOZ9xPuy9cEvh0CQHlzn57jRRP/1x yep/E25EEa2gzmWQU7r/LlXoImv3z/Z5P6OhcbY6xkTzSdoZSCmBtPQxhC+ZSBmA7nL3 4UKhYXdO2HIuFbPl4f/QGQ8h4EO/IpeQrGQM5P/3cs/NjpVnysAX2DkrYY4x3T2AM28K 1/eJW/PLpOTWWFs56t9q0BMuvZZqBkQdBj7USljqH/77aj524eMbd4Rnm+jQrtYtDTzq 4Omq4Hp0KUq8CWMyCFhmor8k1D2H4HxiR+cIKPPvJvfOr7mAq0KzAOdpMIRIEMNPMrBq JueQ== X-Gm-Message-State: AFqh2kpxzgxbt9fG/x+eJ7+jf8grRRUs1z/q4MgDwJV/JE23SzvlnWuu LUQCWgl93g02JvnsGFPZC7+KxXCRVaDLMRDT X-Received: by 2002:a05:600c:348b:b0:3d2:2a72:2577 with SMTP id a11-20020a05600c348b00b003d22a722577mr46677666wmq.27.1673304878167; Mon, 09 Jan 2023 14:54:38 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id m25-20020a05600c3b1900b003d9ed49ee2bsm7266879wms.1.2023.01.09.14.54.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Jan 2023 14:54:37 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Eduardo Habkost , Markus Armbruster , "Daniel P . Berrange" Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Stefan Hajnoczi , Kevin Wolf , qemu-block@nongnu.org, Paolo Bonzini , Hanna Reitz Subject: [RFC PATCH 3/4] util: Introduce helpers to compare QEMU versions Date: Mon, 9 Jan 2023 23:54:18 +0100 Message-Id: <20230109225419.22621-4-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230109225419.22621-1-philmd@linaro.org> References: <20230109225419.22621-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=philmd@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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é --- 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); +}