From patchwork Mon Nov 27 13:05:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10076853 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 5648960353 for ; Mon, 27 Nov 2017 13:06:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44BEB28AFD for ; Mon, 27 Nov 2017 13:06:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38E1928DAC; Mon, 27 Nov 2017 13:06:40 +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 5F24128AFD for ; Mon, 27 Nov 2017 13:06:38 +0000 (UTC) Received: from localhost ([::1]:60844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJJ7M-0004Xf-LC for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Nov 2017 08:06:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJJ6N-0004XX-Ag for qemu-devel@nongnu.org; Mon, 27 Nov 2017 08:05:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJJ6K-000194-Mt for qemu-devel@nongnu.org; Mon, 27 Nov 2017 08:05:35 -0500 Received: from mail-eopbgr20114.outbound.protection.outlook.com ([40.107.2.114]:24928 helo=EUR02-VE1-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 1eJJ6K-00017r-CR for qemu-devel@nongnu.org; Mon, 27 Nov 2017 08:05:32 -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=hK7eZ5tXbwR7K8T66uQRAwAUY01/eY9zKqRAX6DH6E8=; b=PtG4ebtg1Q0cAdTDL9jDhDxfyO3GBIuZ2VSHYyJYVzWtk2KE0GrlyFbFKAc04OmfDRH77VSa6S3/eKurJrsNo+XDYiXHE5p0JeP/UV5gfL7/Kx+XHD/naXkpiYV0pH7c79cQAHvGNTctoQ9UOLpR1ARU2arpsMnRY6Z/c2ELQvw= 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 13:05:28 +0000 From: Roman Kagan To: qemu-devel@nongnu.org, "Michael S. Tsirkin" , Igor Mammedov , Ben Warren Date: Mon, 27 Nov 2017 16:05:17 +0300 Message-Id: <20171127130518.26703-2-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171127130518.26703-1-rkagan@virtuozzo.com> References: <20171127130518.26703-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR0202CA0007.eurprd02.prod.outlook.com (2603:10a6:4:29::17) To VI1PR08MB0845.eurprd08.prod.outlook.com (2a01:111:e400:5a05::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f8f4098d-b2c0-488a-a0b6-08d535978932 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:kjkqtvqN9aCQarVgcYE+RlOo7Nifn1bXZPM0i777viiT4ArUyzBPdcTP6ZIFeAuhfgqIKDKMdRc4KaQY3b9BQdh9ThAX6CYgS7840fzkpLUYEkslvj78xdk64mTJKRWhVVqfHXKJiIi1kSVhXSU+CcViYmKTJkjkmMrZCYzTzqQVYFGOcK587dz1UP35w0xHOMOWkxJYrSNv0lCGCPFBLsB39OqViqdamxlCDo8m46govouirAh2hb1e731aC8Q3; 25:jExKtVv1MnfzI98hKjj37Ue1hRNDb7O8A6MKWpSiioWw8QSbKGe8EfewF21AgyIF1Rh4MduKiw76mU2QvuiyFlrLEQFaRbPGWVQ1LRERTWdflD5QgvY6Lvv/g1RVo9dqe13puBvZjWS9pj6F6QEInXofA9md8lemc0XU+cOJZKrMoQovXGrDjwHWuL2eHXEfw1beNkuHLu7Yy2k1CiQYSabCCrxtxn/VC8NUDm5lDfxj203zH1eOUNui+Ul62BPSbGMFho15xdOCsOZaBLORNqxL2yrvbhWub+INCPx9Z7ccxTd3Oaf2coiRfP9Im9IoynHBF+QQmmlD16inc0qe5w==; 31:D/GKDYLaEpEbvxL9XM2SAs+o461hqAjoEad6RzMv0YoML0yjTDRLiVlZkzNIMFG4e6QX+XA2xJLpMDCIYWLzGv8ZbTl/yGk42V2BIFCmU8YwRuwQakpUoZ6JmHAf9xkg5oMPCIU+tjmo6mCgm2+R18nwXsv2GvFAQyU8AQcOAY5iMKdYvbUYUIQJF2VAtOXSrVB9QtjwAwA+hw0yvamDRXWIb5afHcnfH2GwO0HOh24= X-MS-TrafficTypeDiagnostic: VI1PR08MB0845: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0845; 20:GkUWRZo8fgo2irLngXQ6eXIYl0j9YrzG08XkPsQwpuj78GeOdQY7b9VKyrhyj+nnoK2NX5LBuuf3+45Pa5kTOVM35LUGCDHXBte3ZJFNT1JOLzdTgJrjsZACAaCtFfjE5qZWjb/CS8em3xqLIb5tD+dkvbHR1qv2aZ/ai5rvTDgDveNv3t7StGboRVjbqXHgkce73Et8qslltFW/jkYlaQWP0YZLDvEUz0mqe4cv3A21WuuinurbMwlnD+B4X5X8nsnGpWjvJVSL62Ll/DKGeEPPfBFdfPyfd0MmiplAY0Eoiiex1bMeYQFMd6lMZ0XlTtSfGFX3eGefSYbp99rWKqh4yY1GVWTnXcj1D4GgE1dT/pEgoUsIIzWLiKbMfDZLcAAwfDAPP/fkDMK6g6ErWetfZARUJJP6nqZiPWbh5P0=; 4:RUKppmW3nwmk2HRyVroNiIablwKrEkx3figmn/k5aZdqjbKEmhxXhWL90WaCkZBImjI6lM416Ku4D/bneVhiBL+lLEkHGZvgU8a6nb19W65mFuLCiFBl0XWcR01d6tCPgwIFVCLEkFUUXQW1JBNSQyNiyfjU86v3HtW5U3G80VLv9LzM4QXzue5fuf9snW15ueMkISql+/p5EMwWpLIXJmP1a75hLwc16RKiVWMC/M7Lqg6JRfB1Zd4dO87Xi+pmQ4pCoDnPsdz0TjnaIu8g3w== 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)(93006095)(93001095)(3002001)(3231022)(6041248)(20161123555025)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(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)(54906003)(110136005)(86362001)(6666003)(2950100002)(33646002)(8676002)(81166006)(316002)(81156014)(16526018)(69596002)(6506006)(50226002)(55236003)(6486002)(25786009)(52116002)(68736007)(50466002)(97736004)(36756003)(51416003)(105586002)(2906002)(101416001)(53416004)(76176999)(50986999)(3846002)(6116002)(1076002)(6512007)(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:3BGkbGuZlWDfKogRXXVhj2M2wD1jwcM344FJU7X3A?= =?us-ascii?Q?6oCcoMO9pWPqLbjFsJiYBVDqTzEAnk2t0XYLy+YcKHory0O7sExplOitAodq?= =?us-ascii?Q?9EZbzHQex8IwYcc53m3aJiixxW7skhmGUMIj7fhhGVqfTTgG41f8gLBX/Gxs?= =?us-ascii?Q?vNlSttEVnsYkH7iM3T38rkeOy28N7E98BHnp+EcGni3/gasY3agrRMSXdmTH?= =?us-ascii?Q?aivuC2I4+lP7s24gDhZiv2iIxHbuUKRgTia7bXwwTx+TEmooBl5EwS9yF2gl?= =?us-ascii?Q?Gez9f4yojj5JwgKtrGrawKRq8GD+gQcrs7YW+LLx7ob4Zi8Eze0rNT2HQfQu?= =?us-ascii?Q?gXZAlrXn5poeN5F6zPVnhgZ5tuBUawhLJsnNynGZddAFS4bfqD2FvqoJSjKB?= =?us-ascii?Q?fGnGpfHmKnUuRfryMLXAd/NS01PFrtKiCdDbRcQ61dDCCvJa0Qu+9iGRWXL3?= =?us-ascii?Q?tt2tccah7AbRmD5LKUVsXyItlMQ+NW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/+pYF9FsrVfWYGkPsvva1bQldmuL7pfLNcoSH/OODV/85Kt7VR+zVCHgETqJfNFADoD9r8hw//wRhYm17UOZbDqWR6kov669hRt9u2OEnxGZK+5cydx5cr8ZWIWZ5NhUNGU6g5aOT2eHGrblZ9/lD72ZcUzma/DCVYhh6E+HcOa/VCB8pHcRaHYzkxX+sk/pvqspN1m7rbhoPqwuIriGxQ3Iw9xtrBIbzHSQ8X55YD57iUClq6+m4hYIYGhAORX6hAe0=; 5:p2LBgP+fr4GLDFeOfPL2fCqALwitNxmFPnXw4wFheaOt/zwQbK81CwamHUAf+cUfPz7AzOd3pFZBQd57+4cIozmwN6XY+vPI8DfeXAucViPnunWCkAYkJxBMtZ3n5k7euu3NLW/ga7vEuAP7FDtPSJ3CutCDrbejarTPWy50XvM=; 24:D1sqhpPftBGePdh254GNnbxzfqEzM2VPPPcow6MORxt6Ad53wHp/64n2WYWXzitsTmyEHKQY6WCY8KjoZZmfnU8iGE1/hjZFlL6xi1TCrBw=; 7:md9jRl5vlswFbG4qy7skKNHMFqD/+fn+zfy8SncAYhuKv8n9rytONvtd6MFPvxXp7GxoSN/3qXZJ0+sO+Tz/kiuJjAzqWUolCb1BTldNRLQWtlxb2dFTejUGfp8spla+HS8Orun44SND9uLh44cOj4HnSporZGM3ot4/YESM3mJdpM39fWkUyPV74RlYmfrlajNWXUFxX5UugUj8vjDR7EpyObVWDCFZUswCDJ+GTO7096cvF9swticB3rroQJ69 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0845; 20:xu+JWgs0Rj6hYw6lzfMalaOLBjlarp81a1q5Go1chZxqfPIyf3XSIMHE0WdY9hUTQ1Dqv695+2HCQtX+kCCWEKQ05gEe1Jd2gi+TEJODdBGMK4UO2f4Nl+bRvRywEiliZsPp4iUXoksnyrUoQFYYRppw1oK9GiJ7GL5IVT8oTxE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2017 13:05:28.8891 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8f4098d-b2c0-488a-a0b6-08d535978932 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.2.114 Subject: [Qemu-devel] [PATCH v2 1/2] qdev-properties: add UUID property type 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , minyard@acm.org, "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 UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful. The property accepts a string-formatted UUID or a special keyword "auto" meaning a randomly generated UUID; the latter is also the default when the property is not given a value explicitly. Signed-off-by: Roman Kagan Reviewed-by: Marc-André Lureau --- v1 -> v2: - make the property default to autogeneration if not specified explicitly include/hw/qdev-properties.h | 9 +++++++ hw/core/qdev-properties.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index e2321f1cc1..efb22ba80c 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -30,6 +30,7 @@ extern const PropertyInfo qdev_prop_vlan; extern const PropertyInfo qdev_prop_pci_devfn; extern const PropertyInfo qdev_prop_blocksize; extern const PropertyInfo qdev_prop_pci_host_devaddr; +extern const PropertyInfo qdev_prop_uuid; extern const PropertyInfo qdev_prop_arraylen; extern const PropertyInfo qdev_prop_link; @@ -213,6 +214,14 @@ extern const PropertyInfo qdev_prop_link; #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *) +#define DEFINE_PROP_UUID(_name, _state, _field) { \ + .name = (_name), \ + .info = &qdev_prop_uuid, \ + .offset = offsetof(_state, _field) \ + + type_check(QemuUUID, typeof_field(_state, _field)), \ + .set_default = true, \ + } + #define DEFINE_PROP_END_OF_LIST() \ {} diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 1dc80fcea2..24c17800e3 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -10,6 +10,7 @@ #include "net/hub.h" #include "qapi/visitor.h" #include "chardev/char.h" +#include "qemu/uuid.h" void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp) @@ -883,6 +884,66 @@ const PropertyInfo qdev_prop_pci_host_devaddr = { .set = set_pci_host_devaddr, }; +/* --- UUID --- */ + +static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + QemuUUID *uuid = qdev_get_prop_ptr(dev, prop); + char buffer[UUID_FMT_LEN + 1]; + char *p = buffer; + + qemu_uuid_unparse(uuid, buffer); + + visit_type_str(v, name, &p, errp); +} + +#define UUID_VALUE_AUTO "auto" + +static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + QemuUUID *uuid = qdev_get_prop_ptr(dev, prop); + Error *local_err = NULL; + char *str; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + visit_type_str(v, name, &str, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (!strcmp(str, UUID_VALUE_AUTO)) { + qemu_uuid_generate(uuid); + } else if (qemu_uuid_parse(str, uuid) < 0) { + error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); + } + g_free(str); +} + +static void set_default_uuid_auto(Object *obj, const Property *prop) +{ + object_property_set_str(obj, UUID_VALUE_AUTO, prop->name, &error_abort); +} + +const PropertyInfo qdev_prop_uuid = { + .name = "str", + .description = "UUID (aka GUID) or \"" UUID_VALUE_AUTO + "\" for random value (default)", + .get = get_uuid, + .set = set_uuid, + .set_default_value = set_default_uuid_auto, +}; + /* --- support for array properties --- */ /* Used as an opaque for the object properties we add for each