From patchwork Mon Nov 27 12:43:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10076773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF452602BC for ; Mon, 27 Nov 2017 12:44:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A25482896E for ; Mon, 27 Nov 2017 12:44:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9730128DDF; Mon, 27 Nov 2017 12:44:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 62CE12896E for ; Mon, 27 Nov 2017 12:44:55 +0000 (UTC) Received: from localhost ([::1]:60499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJImM-0006Gc-Ta for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Nov 2017 07:44:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJIli-0005zS-G8 for qemu-devel@nongnu.org; Mon, 27 Nov 2017 07:44:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJIld-0006WW-JR for qemu-devel@nongnu.org; Mon, 27 Nov 2017 07:44:14 -0500 Received: from mail-eopbgr40117.outbound.protection.outlook.com ([40.107.4.117]:45024 helo=EUR03-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eJIlc-0006Vl-SL for qemu-devel@nongnu.org; Mon, 27 Nov 2017 07:44:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xWMRYpMC1ctF4FheqMaBDkccpDHIp/Gb41rdboDufAc=; b=W8rxUbvb0Ruqf1S6tmu5eF6Pc61rowT4Y6LSYFxIjwV6+hPKipwtBlUEG0tpf/ECCpIHr/C/CF6F6jjuJjCtlAOLNIU9n1WBnUkb7s0b0Yvl4hJkA/a15hS1GDscJqRqG9+4/2EUcb3+lenWR0Ya9Ra10o64gWalvSBDvW3XG2k= Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR08MB0845.eurprd08.prod.outlook.com (2a01:111:e400:5a05::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Mon, 27 Nov 2017 12:44:04 +0000 From: Roman Kagan To: qemu-devel@nongnu.org, Fam Zheng , Thomas Huth , "Daniel P. Berrange" Date: Mon, 27 Nov 2017 15:43:55 +0300 Message-Id: <20171127124355.26015-1-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0502CA0023.eurprd05.prod.outlook.com (2603:10a6:3:e3::33) To VI1PR08MB0845.eurprd08.prod.outlook.com (2a01:111:e400:5a05::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c7ab647b-97ae-45d6-8c07-08d535948b19 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(2017052603258); SRVR:VI1PR08MB0845; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0845; 3:9up/Gb5EU8zO+NthIDE5uVHFF2xo7Fe4TOFrXzXktk7mlkPRlKNSIWQqTYQPjDdvxzu9c1EYW9u0x6ROjbfap3JpkSsyS2wvSRzLdeOfAKnbHSkAzDgs4nLk88AVQom8vp6gchMVXMU6WkrEqKU4TY+RLiSBOOyz7e6PkYxby0to6qb9IUZHYjclZa9m44Q6d7CX8lwz1sgNNqHZzGGlB01pHohvvBZq0eUq5Dpd3s275jCAVwqvG2eibclmmcvQ; 25:z0yE6I3wrRXdyAffdQhy9+rLcSTuEQJmbUH3DscbbhnUVI5FvOckW/NqNNlbtdpNiN1Z3gSeOkQPSZHHAyra4A/VGdwj1xdWWGNSGXrAFju882IvGx/dV8BKiSJb4MLnCjujCOZXM2drqAHn8EyaZMfsAIqBxxTZ0LEWQ7TLZM12TaYp+zD9GZbjfg+cUnfc8/T3Kuczn91UsyLb0g64Fl/UJXbr3k+OXp68sbf1cu6vHXN91fLWcx8lGxJKMFDHfYOFbSi5dmI+HZXnw6gPBtBIeIJK5Syg1j0/w2ZA4t6LA+Jho0HxZbvjqFD3ORZht61koHTTCBpeuoO3aHftjBAy4N3tGT58/fdXjOIt9hE=; 31:grVX1bGxtHzi2SJTU8fik62EwAEhoFnCZbJCybrYuH0+iqtwJ/xt/WD3lNH4jhQysGq2k3Qqe16uPzQ1FKIgMp8N6cWbPjo17a+EwyJ9ol9ktm1TnZhGSWpAeZxi9Vaou4o1fSEySwkoYokSaK+seuxT6X5rH8gyFovRj/LJ5mCsFsAQge5aA/GxSXiXHZceLNeWIoI4L3VP2UONF/r+jk/+/JzMM2N/ArU3rMI0dFI= X-MS-TrafficTypeDiagnostic: VI1PR08MB0845: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0845; 20:ibm8Q5mi6ykOZGeYQYcqPpic/NHuy6mw5BXRJbhycsYRNPnBsDGwSUmMv5NoPsaB/fxKrpKv8SKskRMtAYaXmZtqmvga1g0xT4YuH8k3eww3jKUvNj3CHxLPKoiPXpw51Tuh2JVfWigAiH4G3l99yDULXMIec8btANwRmQPiC3/AMewgIE/4ZYwyPVONPaRIEU7MjirPBKwN4osgbPJqNwmp1yVaqdKET8I8Kz300fc+D8OJ977dbBqrKATela+o1Z4Kw+nI4KbXBy6ElAsbI3IdXOmcWTPJxme4rizOiiSWeAv2kH90l1h8hTgKEMKxdmFMDA0WCHAu63KFCkP2ziSod7UffFth4NahPv0BYyGIcOYYLygxpWP7Gr5VF15nmtY/4elY3vMc1fjocJMRtihabhxKpBGr2y8NB/E2jsE=; 4:k2OMS3rZZCAbQ4c3YiaZa7pyIsRRMhKrnE09d4unvNO63RMKZPXMTJskK+DyVG1kaMNeQk7Y7YuL59vDrKPXSekEzgIoY1uHhzEHoHCQGRhZU5v39QfSg0vJcjCCmhJYyz3KgrspUa8SXDkXAx2ILOk6C6t+vhlEpVU+2wV5znpyW6kvk6FzNeemJ2Ogmg/I5k4vK7uGSwoZxxEYuJ07ZohwdUyyuY/KjF07jOxPdFG9Dl6nouDhGGm107yvXs5bega2GlblxrQaPsla2gytEw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3231022)(3002001)(93006095)(93001095)(10201501046)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(20161123555025)(20161123558100)(6072148)(201708071742011); SRVR:VI1PR08MB0845; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR08MB0845; X-Forefront-PRVS: 0504F29D72 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(366004)(346002)(376002)(39830400002)(189002)(199003)(8936002)(7736002)(305945005)(478600001)(110136005)(86362001)(107886003)(6666003)(33646002)(8676002)(81166006)(316002)(81156014)(16526018)(69596002)(6506006)(50226002)(55236003)(25786009)(6486002)(52116002)(68736007)(50466002)(97736004)(36756003)(51416003)(105586002)(2906002)(101416001)(53416004)(50986999)(3846002)(6116002)(6512007)(1076002)(47776003)(106356001)(16586007)(48376002)(189998001)(53936002)(4326008)(66066001)(5660300001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB0845; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0845; 23:xVOrqOaI5Pa7lyGksCEuWkSA34mo3muz85yRWb+YB?= =?us-ascii?Q?Yb9LYO7S0q6a5LXCEj7OFf9kgy+P2OwnCzuappJjuCkCR+/sVJsdZefSGuHQ?= =?us-ascii?Q?agng/l+F0X1ATKq1oPeCIenp0CXBWwGf5sOWh0r0Ft9AWny7uLmPanPse31H?= =?us-ascii?Q?LX3uOH6LPyltzp4cPllOgpQ+d2O008sVXNCO1q7AWjjnPI8i9xfhuyXux1N1?= =?us-ascii?Q?OlgF7KBHjHeZ8kTI1YuM+CHrAsK44qqyXDBTS+pPEmpTHYlVC547YByMtp4R?= =?us-ascii?Q?6+TuuXGtZX6BQRPwtyIpQUlpn5ytZtQT0+SDnYMc6n+pez5hKseu2cqj8c80?= =?us-ascii?Q?dJxgAO/qeXTEGqkHgB6LN0XS6oVFvBc2zP2nlRXX0dYc4IrHjnFFDt3lmitH?= =?us-ascii?Q?0y6MWgPTfB1tYBBjGZ8eY30QpxZRmLA37GlFKv3UbeP1qx/trbSF9ca9BIx+?= =?us-ascii?Q?XDYh1YgfwpsDp7sZvofk2j++fYVB0LH+toq04bLKS65C/UGHSnSEw/16/jV2?= =?us-ascii?Q?MGhrsC52N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ZDSufXP8Nd1eFaxkboIzZnkbP09T2fMSZ82YEM6ZKUGxTA+Bwwd7dvB05XFbhSEJnPe+beUMX2OqLyUjf9FlmfC4X4ys8iIB6yaWfMQ1x3XuKKd3uz7SWYQ5a/EkJ2ftbwKd0uOP3absNOUdBCs=; 5:LRuIqgztzlJ9MXNeYEgWD3pY9i35TGd9WdHA3fi8S3/Otx25cl9sbU5+dAjjAUu1lId0AzozfpCPxkqzgB1CuZGW12ZKRYEA1ca4i/sJcIYjTNZEUSffCIO/NWEN8vIms42Cys0jtzAr6SoWdF0+kYX6C4UEPZe6CaXSZZjayw4=; 24:JC5Xn5EkmYUFxy/Kp6o11tQACYefTtp1an6VsKttVzmrMjrmN492rPtsDQK0zMy3lswnUENGm+e2SzFZnTLI9/b97PX7bH49hFyG9Lw7uRc=; 7:Llz0xZMPOuEl4ijKG+FxJ8K4MkncPSqKk4OwYaO7ns9NgvUlKRzCy4SZUnsOy/mCm38FPVyNmuMSnDh8KcJ5mYK3GS24IEvd0sIVF15erNN5hbT9RN8EIJBm+9iw0VCji87ilcBf9TibR0Gl2NG14ItTY1gy1Py9N1mdonqtR1t6RHwHF887pfykwaqhvVz/fbaYzyWR2F2WeOSLb7Tco4PXKw/JstKfvHOXOpG29Xb2GOKvlJvCPPIITi6f8Aqo SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0845; 20:IL8ICw6D1HrqJs9NNZfD/BWx4rGs7JdZbsq501OQYR7SccrzE61XgEIMsQMPIWt8eAvyQtKCwIlZYUXYl06iyXe/nzHnd/0FKo16kRD860a/UdHqxj5iAnfnAgwMq5DJS/ywKUGTlixJmwU6jUGLaCtJ3s+dCctaZKuZ+/Dve/0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2017 12:44:04.3088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c7ab647b-97ae-45d6-8c07-08d535948b19 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB0845 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.117 Subject: [Qemu-devel] [PATCH v2] util: add is_equal to UUID API X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Denis V. Lunev" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP It's going to be useful, in particular, in VMBus code massively using uuids aka GUIDs. Signed-off-by: Roman Kagan --- v1 -> v2: - drop dedicated testcase (for it was of no value) and incorporate is_null and is_equal assertions into uuid_generate testcase include/qemu/uuid.h | 2 ++ tests/test-uuid.c | 8 +++++++- util/uuid.c | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h index afe4840296..09489ce5c5 100644 --- a/include/qemu/uuid.h +++ b/include/qemu/uuid.h @@ -48,6 +48,8 @@ void qemu_uuid_generate(QemuUUID *out); int qemu_uuid_is_null(const QemuUUID *uu); +int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv); + void qemu_uuid_unparse(const QemuUUID *uuid, char *out); char *qemu_uuid_unparse_strdup(const QemuUUID *uuid); diff --git a/tests/test-uuid.c b/tests/test-uuid.c index d3a2791fd4..22b4b0727d 100644 --- a/tests/test-uuid.c +++ b/tests/test-uuid.c @@ -93,12 +93,18 @@ static inline bool uuid_is_valid(QemuUUID *uuid) static void test_uuid_generate(void) { + QemuUUID uuid_not_null = { { { + 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0, + 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42 + } } }; QemuUUID uuid; int i; for (i = 0; i < 100; ++i) { qemu_uuid_generate(&uuid); g_assert(uuid_is_valid(&uuid)); + g_assert_false(qemu_uuid_is_null(&uuid)); + g_assert_false(qemu_uuid_is_equal(&uuid_not_null, &uuid)); } } @@ -168,8 +174,8 @@ static void test_uuid_unparse_strdup(void) int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); - g_test_add_func("/uuid/generate", test_uuid_generate); g_test_add_func("/uuid/is_null", test_uuid_is_null); + g_test_add_func("/uuid/generate", test_uuid_generate); g_test_add_func("/uuid/parse", test_uuid_parse); g_test_add_func("/uuid/unparse", test_uuid_unparse); g_test_add_func("/uuid/unparse_strdup", test_uuid_unparse_strdup); diff --git a/util/uuid.c b/util/uuid.c index dd6b5fdf05..ebf06c049a 100644 --- a/util/uuid.c +++ b/util/uuid.c @@ -41,7 +41,12 @@ void qemu_uuid_generate(QemuUUID *uuid) int qemu_uuid_is_null(const QemuUUID *uu) { static QemuUUID null_uuid; - return memcmp(uu, &null_uuid, sizeof(QemuUUID)) == 0; + return qemu_uuid_is_equal(uu, &null_uuid); +} + +int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv) +{ + return memcmp(lhv, rhv, sizeof(QemuUUID)) == 0; } void qemu_uuid_unparse(const QemuUUID *uuid, char *out)