From patchwork Fri Nov 24 14:32:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10074109 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 AAF4A60375 for ; Fri, 24 Nov 2017 14:33:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D4E228C86 for ; Fri, 24 Nov 2017 14:33:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91FE42A210; Fri, 24 Nov 2017 14:33:27 +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 3E3A428C86 for ; Fri, 24 Nov 2017 14:33:26 +0000 (UTC) Received: from localhost ([::1]:49588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIF2j-0003Qq-E7 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 24 Nov 2017 09:33:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIF1j-0003Ow-34 for qemu-devel@nongnu.org; Fri, 24 Nov 2017 09:32:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eIF1f-0002Hb-Vp for qemu-devel@nongnu.org; Fri, 24 Nov 2017 09:32:23 -0500 Received: from mail-he1eur01on0113.outbound.protection.outlook.com ([104.47.0.113]:47053 helo=EUR01-HE1-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 1eIF1f-0002H9-8E for qemu-devel@nongnu.org; Fri, 24 Nov 2017 09:32:19 -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=kBGU3TRt20Krd2vqBj+wloEgCqhykwEBsKvJzSMDo3M=; b=Sl7atcCmjx0plQs/N8tVTkDsNVbrAsD9tmxw/tBn2K+g1e9L5ge/c5ipTAlVtrtv8fqAxhO9odD9v4iN46wxXmSOvW6Kd7rt5L6qS6L3f+83Uh8XRq0spRpAdRA0x3VCVWwqSrzxS/eeS25EFpFR+vsI9YpuLLd4rj10bmLIolI= Received: from rkaganb.sw.ru (195.214.232.6) by AM4PR08MB0835.eurprd08.prod.outlook.com (2a01:111:e400:59ee::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Fri, 24 Nov 2017 14:32:14 +0000 From: Roman Kagan To: qemu-devel@nongnu.org, Fam Zheng Date: Fri, 24 Nov 2017 17:32:06 +0300 Message-Id: <20171124143206.28833-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: HE1P191CA0017.EURP191.PROD.OUTLOOK.COM (2603:10a6:3:cf::27) To AM4PR08MB0835.eurprd08.prod.outlook.com (2a01:111:e400:59ee::17) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(2017052603199); SRVR:AM4PR08MB0835; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0835; 3:RYv8vOpikH+2httSP3DbgEi8MnC6vuJJ9EzXUngohgFPBaxnivWudL421hQDUD+v1r1+icYdBDV9emRyoAGq/zZQP9zzzDuzdA76FZ6Y5aoHGmzZLrtPHEsTCKwJpOHT7DLalrpOjvDrRX5Kpsy3WtoIZCSkWUYQmw4k4tK4usDbyks5+XkUSV6GzAu/4sXHEFJep2NpjB2V8kDd7yQ0wzzYTZDJcGHxWP8aIRhswTkrGNvTrkw4sA/7GN6tMhm9; 25:OZOykoVZP80aFrI47lK2n9qa92/HR8h9WCEjHFaQI+pamTijT2v2OTJ34WNvIzYLfGnkX+b8EqZvOtdhxz8Vqk9NZu1bnyM+Wb29Q872UOP/JoY3TQ6UihKEDZUGmTkNKjIFKCSGtIBUgBw5q66P3zeV3l2wAbIb7gEHVdCPKKSj3595g4JGJ6N9MLTdkzvWVbGbCPXYhcToulcMtkElbj+bGURUWTPWe6H7n5AdkqMTLcNOmI9i2n2gprtER3VMXWFYDiBF8P9bG29L4X/aq2PB7XsLmw6D2fB1zBZ9BvPfuWGSB3L7Rhl2aQcQQrnrzb8G6AUQPFVbSH3PcwO0WA==; 31:cgvRGFbk99t0tJm6ZNK/1lNkmHjsQhVXujzSLWiZhNFvnW/PTFXDrOCWOKZePnfSMgwLPratgy3AGnX9R7YH5bb0ArGD3vftax2YvvhktTWP4+7bPbCHRpvZBsHXPaMnOupKfI4Oh9b0QNbNzoBtTqniP5WX8skeQTB2e6QB9P/4qarzOnBIGWQrd7E/dIUIN80dSnYwiLDjbmQRA0Un4abfH3Ds7P17PPrL3a9YNgk= X-MS-TrafficTypeDiagnostic: AM4PR08MB0835: X-MS-Office365-Filtering-Correlation-Id: 94734eba-ed76-44e1-5696-08d533482877 X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0835; 20:Ed+9xC21FkKLHEQH6TY46eraPRKWqQoEmmqOkzckK3bhjdwuGP7UcFnocUbeKyPGF9W+G1obNH2brJLkcPmuunj+wStxJ7xoJB9Mp3fy1GH6B6EOlB4Fxo//YnNkfAyxaHBLJooem8eW8POMCE4mci76T75JT0/Z1qiS/6FAEH1ue8TUv/iscZI9uPGrZGaApt4JmLEnpPtgsyqPEeVCnW/U6QKdQU/ZN4xqIL9K7/5i2Md47ARIODRMvhpOKOHgIkWM2BFAbFh0hp6aoqXM3L+0YrwB0r1dBPw7XRZ7ENd37srv0zjS1jYNKHqkoiuiFRc9EUhR67pm/DyJafMIhIbSOO//aBjxX8JmrrSO97jvycG70hvsJSIuWu7fjXjXlTvxRivaaguLC68pjbDU5gl9BFoaHzV7xdtAZrghX/I=; 4:x9cuLpW5UX5QAOGztCemOlOewnWIpQiEdPeR/qJcz6yWK9zfhZShEgiuKdu0R2MQmy3evotysgtyM+sw/Eaju+JQlAipwvofGPxIMtjhvEHbYgFZO8NYW1wHsHEdRcWpta19BSPpI5xvQJjyk8EUx+jzt1Wy8UpkubnsvtQN7PAYk9vC5g3rwcLhdIWDFFzgwyU7erMKMQX8HNWBod5S6f/gHEj0mLEFg2DVC6M2WxZdK6A3qJGmymXaSUuHw6NtFWf6x9mVcrbL700gA1ptfg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(8121501046)(5005006)(10201501046)(3231022)(93006095)(93001095)(3002001)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123558100)(20161123564025)(6072148)(201708071742011); SRVR:AM4PR08MB0835; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM4PR08MB0835; X-Forefront-PRVS: 05015EB482 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(366004)(376002)(346002)(199003)(189002)(305945005)(189998001)(101416001)(7736002)(107886003)(6116002)(1076002)(3846002)(66066001)(16586007)(316002)(47776003)(50986999)(478600001)(16526018)(6512007)(36756003)(8676002)(53936002)(81166006)(81156014)(106356001)(105586002)(55236003)(69596002)(33646002)(4326008)(25786009)(6916009)(50226002)(53416004)(2906002)(8936002)(86362001)(68736007)(50466002)(48376002)(51416003)(6506006)(6486002)(97736004)(5660300001)(52116002)(6666003); DIR:OUT; SFP:1102; SCL:1; SRVR:AM4PR08MB0835; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR08MB0835; 23:fSUBu9HDDIiCqNVOvauzLWSwTBSJHwfeZz5FPvxa2?= =?us-ascii?Q?UBwOLAK7ht/ecG7HN+rxlpE/IXkQ91Qqo9Pgdu9lzhis85L4A8CFWSXt/BDC?= =?us-ascii?Q?qUUadFgG6qN/J+j7zwHTs+I8MzOOJp8e/A+MvqaKpQGK1m0HQLTeLaSque3l?= =?us-ascii?Q?Y0Xj3JjWE2f5oGYX6eaLN2n4M961b1yL0RzVIuSTGrGrn8iaxXgR7QKNU1NQ?= =?us-ascii?Q?8cobKfaOG6rjjbY1cZ9u9myxtF5XUprbFUnelD3YMvYKUgfCfGPxwzLN7ZhM?= =?us-ascii?Q?DmFwQfxe6sIgjFb3ZUErRWeAJkRCVGllnGtAX4uuJpscvj1IL3wYW7vY2hwI?= =?us-ascii?Q?uVPRJb2h1dkXu6aWdcLK+62PYTMbwsWg+rFVqE6K6tMfAKovg6qL37h/1d7Z?= =?us-ascii?Q?ghwVhnf0HMjrVZ3jQJZ4f792aLyw/mA+5guz3hrctK/xypa4OXTyePAZUIdV?= =?us-ascii?Q?Q7FqERnCVlZcRS8Y1leoYVOM6BjtwLxLZGH8yoZzpOaxfgXCT8j7lljNNtsb?= =?us-ascii?Q?kS37ESsTZP7YySmR7fs8FX3nj9hd9GJCfybo0v092vWgH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8VgxbBDglZ4QPyXCYZOH/PrPz65mE630z3iP+Q8z8Rg=; 5:Yo8QKjKcZ1mEhEWmWKtZgp0FJXhFQeSjEYcwGmUU3DJMTJeqi6dPFC7RZA43RJU3ZoYYjxxuF5VOvNpLQakbrvUZk7Id4dfcznal+tv3vgTU74xam7qy3tAYyzSw+mOlXxojQrHa+MhcCpOxehuvkQhwg1YBrS/ke82+/QodZg4=; 24:6p7WlRZbI+LsgDMYH8/F/asIGExrtHMJCRJVXgonRcdlgK7kzyEdy7UeiV5eVaeQZ7HCCLkHX90m5ekhlQRVfonG4+e73YJmRBc0yBQhGgM=; 7:Nq4tzrxfcL3UG66j3k8Px57flnsYab/y0/XA1Xfrqhb3F3RsvQ8soi0m0Y72iX/fNhDuOeOIyBi2cTp/0htLlB8eAK5pjuPXL/PEVuL1Z9Jakp6QL8WcWq20Gb/39XkAg/XxGEYNrWW8BZszkTfhkT/sLa95YhxkhyqSV0wuf9nVvOEPQ/SWFum6/bjyNZaR/SizQ244xTTgiuuxcwHGxkVgpDigmXBaYWVclnCKflIfosHoQJbf7RA/j7y4sP/Z SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0835; 20:rR1vB+01bH7lxaEH3Pcf4039HjASj9wtNJo+f6w5bTRA0+9Lz3QdGktxRC8e7bT+PtqIW3LRYLp78OegppiTOV+jR6JF7gmj8VrJPsd3SRLNdMhYdCRyn9UzVuVEmldBk5MuSVIcE0pgJIlLBHDVSE7oiiu8yYxSu0rEKkgcRgE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2017 14:32:14.9395 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94734eba-ed76-44e1-5696-08d533482877 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB0835 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.113 Subject: [Qemu-devel] [PATCH] 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 --- include/qemu/uuid.h | 2 ++ tests/test-uuid.c | 24 ++++++++++++++++++++++++ util/uuid.c | 7 ++++++- 3 files changed, 32 insertions(+), 1 deletion(-) 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..c6c8148117 100644 --- a/tests/test-uuid.c +++ b/tests/test-uuid.c @@ -116,6 +116,29 @@ static void test_uuid_is_null(void) g_assert_false(qemu_uuid_is_null(&uuid_not_null_2)); } +static void test_uuid_is_equal(void) +{ + int i; + QemuUUID uuid; + QemuUUID uuid_null = { }; + QemuUUID uuid_not_null = { { { + 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0, + 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42 + } } }; + QemuUUID uuid_null_2 = uuid_null; + QemuUUID uuid_not_null_2 = uuid_not_null; + + g_assert(qemu_uuid_is_equal(&uuid_null, &uuid_null_2)); + g_assert(qemu_uuid_is_equal(&uuid_not_null, &uuid_not_null_2)); + g_assert_false(qemu_uuid_is_equal(&uuid_null, &uuid_not_null)); + + for (i = 0; i < 100; ++i) { + qemu_uuid_generate(&uuid); + g_assert_false(qemu_uuid_is_equal(&uuid_null, &uuid)); + g_assert_false(qemu_uuid_is_equal(&uuid_not_null, &uuid)); + } +} + static void test_uuid_parse(void) { int i, r; @@ -170,6 +193,7 @@ 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/is_equal", test_uuid_is_equal); 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)