From patchwork Tue Sep 12 13:48:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9949269 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 299EC60360 for ; Tue, 12 Sep 2017 13:51:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A3EE287A9 for ; Tue, 12 Sep 2017 13:51:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F16028F9C; Tue, 12 Sep 2017 13:51:04 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7D3A0287A9 for ; Tue, 12 Sep 2017 13:51:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drlYV-0005lA-0W; Tue, 12 Sep 2017 13:48:47 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drlYT-0005in-Vg for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 13:48:46 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id F2/02-03093-DB5E7B95; Tue, 12 Sep 2017 13:48:45 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRWlGSWpSXmKPExsVyMfS6s+7Op9s jDTbt17P4vmUykwOjx+EPV1gCGKNYM/OS8isSWDNO3dzDWtBhXbF7+XHWBsaT6l2MXBxCAtMY JXac+scK4rAIvGSReLRzMxuIIyHQzyqx7s5PoAwnkJMkcaz9CCOEnSax5OJMFgi7SuLojstgc SEBeYmDLZfZIewpTBL7DuSA2GwCWhL3b69gA7FFBJQk7q2azARiMwukSOxd1wbWKyzgKLHuwS 8wm0VAVeLF/h6wvbxA8b4bi5ggdslJ3DzXyQxicwLF2393MUPscpC4smYP2wRGwQWMDKsYNYp Ti8pSi3QNTfWSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxKTivWS83M3MQJDjgEIdjB+WxZwiFGS g0lJlFf5/vZIIb6k/JTKjMTijPii0pzU4kOMGhwcAj+f/m1hlGLJy89LVZLgnfQEqE6wKDU9t SItMwcYFTClEhw8SiK8lSBp3uKCxNzizHSI1ClGe44Ldy79YeI4tukykDyw5xaQ7Lh59w+TEN hUKXHefJA2AZC2jNI8uKGwKL7EKCslzMsIdLIQT0FqUW5mCar8K0ZxDkYlYd4tIFN4MvNK4Ha /AjqLCegsnktbQM4qSURISTUwatbLW016EHRVkbf74K2K1MP7MnIUA+ZMvPx82WO3b19++Ske ecBzOevZdxF9TZmtPX9MHrgYTd3SJmCZl/I7vDqlnrHuxuWfDWuiv6zrPS1wzzVG9F308xn8+ vsvRXu/m83aa5m/8qBN5nGX+jYJCa+7LbbrnrJNlJGIeCS+rMrwz5v7J+UmK7EUZyQaajEXFS cCACpcwC3dAgAA X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1505224121!82349216!1 X-Originating-IP: [209.85.215.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 25757 invoked from network); 12 Sep 2017 13:48:41 -0000 Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by server-8.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 13:48:41 -0000 Received: by mail-lf0-f67.google.com with SMTP id c8so5379935lfe.2 for ; Tue, 12 Sep 2017 06:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=okHv1tlHkseoRdRcZHAia8HEZ70oOnjPI4vAW7XV/+A=; b=LO0yyqRZWvOm0McZxld5sCzQRiLP5iCiSjFg35QLdzxdLUIaOAJgm7vWG6eAV6GSXP msqe42Vctau8eGHh1xJ0OD2W9R8ANFjKWJZnySiKZyBij904YHEy/VUcdilKxo+3SgAp txuqyRw0cH8ImaySb/SO7Ru8x9aZs4k/2ScNcuIqqkb+/GWj1vuYODne4H53Y6722jpc ctFEb3iTkcgbQl3AajrVSJVNnaNiiO/shqDRw45JrYudtmYjqi0IeRyR11aClcgvhl/d W6N6TBkaiMrhag0undVhFG2q5+PxKSJ3X1Rwycm7uI2p3W6eeeB5YgPyokKytg7SxcO2 0Uzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=okHv1tlHkseoRdRcZHAia8HEZ70oOnjPI4vAW7XV/+A=; b=YEZ7o0hTVwkRogXnZJQEQR0p340R48M+3rXJYjMrWHCF/xTdh1fMG8UfLAIGQAoXXM NSwkvsmV7WXxWs8rFCMF3tZEhzGzAdA+67beR9ZFZf/Wf9I5OLr/0r0R5YWpp4Bkm2qo c2T3cYfWITUCUQ0GAWCgwABcJ+AiooZJXMX9SprexxLSRc5e54gSfkAJfvuW0OuLVrWf xWiySzkR5TMMXSy8+EGPnGdttcguqwnDlNN5fz2XeokOKlyYxDb+74bR53qJ3DO8JEF5 zXxdmP/1bE1h/b3L+s/uXr6bzIpfYm+nsGQKfvNpi+r+1q+fhNsExJballnB2Irpr7kX 8+6w== X-Gm-Message-State: AHPjjUjzSg0guS4YUiAR+K3UxUG2wyz+xABDXOGrKjmcg9mcUri4W2OS yyoRfapnOEHDgzil0y0= X-Google-Smtp-Source: AOwi7QCTWrjN9v7PuqxmVLA6LwlUx10Uj41JCUQPAq2cX7pUTKnJLuRJ3uRA23qxHJ1bV1PBT2UZLw== X-Received: by 10.25.33.129 with SMTP id h123mr4693459lfh.140.1505224120765; Tue, 12 Sep 2017 06:48:40 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-56.209.223.85.sovam.net.ua. [85.223.209.56]) by smtp.gmail.com with ESMTPSA id s5sm690074lfb.14.2017.09.12.06.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Sep 2017 06:48:40 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Tue, 12 Sep 2017 16:48:18 +0300 Message-Id: <1505224098-19330-14-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505224098-19330-1-git-send-email-al1img@gmail.com> References: <1505224098-19330-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v6 13/13] libxl: remove unneeded DEVICE_ADD macro X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Grytsov Signed-off-by: Oleksandr Grytsov Acked-by: Wei Liu --- tools/libxl/libxl_device.c | 6 ++--- tools/libxl/libxl_disk.c | 5 +++-- tools/libxl/libxl_internal.h | 52 +++----------------------------------------- tools/libxl/libxl_pci.c | 3 ++- tools/libxl/libxl_usb.c | 8 +++---- 5 files changed, 14 insertions(+), 60 deletions(-) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 487be28..67b7afb 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -1793,10 +1793,8 @@ out: return AO_CREATE_FAIL(rc); } -static void device_add_domain_config(libxl__gc *gc, - libxl_domain_config *d_config, - const struct libxl_device_type *dt, - void *type) +void device_add_domain_config(libxl__gc *gc, libxl_domain_config *d_config, + const struct libxl_device_type *dt, void *type) { int *num_dev; unsigned int i; diff --git a/tools/libxl/libxl_disk.c b/tools/libxl/libxl_disk.c index c20cc49..cfa5e8a 100644 --- a/tools/libxl/libxl_disk.c +++ b/tools/libxl/libxl_disk.c @@ -277,7 +277,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid, rc = libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; - DEVICE_ADD(disk, disks, domid, &disk_saved, COMPARE_DISK, &d_config); + device_add_domain_config(gc, &d_config, &libxl__disk_devtype, + &disk_saved); rc = libxl__dm_check_start(gc, &d_config, domid); if (rc) goto out; @@ -832,7 +833,7 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, rc = libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; - DEVICE_ADD(disk, disks, domid, &disk_saved, COMPARE_DISK, &d_config); + device_add_domain_config(gc, &d_config, &libxl__disk_devtype, &disk_saved); rc = libxl__dm_check_start(gc, &d_config, domid); if (rc) goto out; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 976827a..81e87ae 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -4281,55 +4281,6 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx, (a)->port == (b)->port) #define COMPARE_USBCTRL(a, b) ((a)->devid == (b)->devid) -/* DEVICE_ADD - * - * Add a device in libxl_domain_config structure - * - * It takes 6 parameters: - * type: the type of the device, say nic, vtpm, disk, pci etc - * ptr: pointer to the start of the array, the array must be - * of type libxl_device_#type - * domid: domain id of target domain - * dev: the device that is to be added / removed / updated - * compare: the COMPARE_* macro used to compare @dev's identifier to - * those in the array pointed to by @ptr - * d_config: pointer to template domain config - * - * For most device types (nic, vtpm), the array pointer @ptr can be - * derived from @type, pci device being the exception, hence we need - * to have @ptr. - * - * If there is already a device with the same identifier in d_config, - * that entry is updated. - */ -#define DEVICE_ADD(type, ptr, domid, dev, compare, d_config) \ - ({ \ - int DA_x; \ - libxl_device_##type *DA_p = NULL; \ - \ - /* Check for existing device */ \ - for (DA_x = 0; DA_x < (d_config)->num_##ptr; DA_x++) { \ - if (compare(&(d_config)->ptr[DA_x], (dev))) { \ - DA_p = &(d_config)->ptr[DA_x]; \ - break; \ - } \ - } \ - \ - if (!DA_p) { \ - (d_config)->ptr = \ - libxl__realloc(NOGC, (d_config)->ptr, \ - ((d_config)->num_##ptr + 1) * \ - sizeof(libxl_device_##type)); \ - DA_p = &(d_config)->ptr[(d_config)->num_##ptr]; \ - (d_config)->num_##ptr++; \ - } else { \ - libxl_device_##type##_dispose(DA_p); \ - } \ - \ - libxl_device_##type##_init(DA_p); \ - libxl_device_##type##_copy(CTX, DA_p, (dev)); \ - }) - /* This function copies X bytes from source to destination bitmap, * where X is the smaller of the two sizes. * @@ -4359,6 +4310,9 @@ static inline bool libxl__acpi_defbool_val(const libxl_domain_build_info *b_info libxl_defbool_val(b_info->u.hvm.acpi); } +void device_add_domain_config(libxl__gc *gc, libxl_domain_config *d_config, + const struct libxl_device_type *dt, void *type); + void libxl__device_add_async(libxl__egc *egc, uint32_t domid, const struct libxl_device_type *dt, void *type, libxl__ao_device *aodev); diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 7a2d42f..f929e5a 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -160,7 +160,8 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_d rc = libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; - DEVICE_ADD(pci, pcidevs, domid, &pcidev_saved, COMPARE_PCI, &d_config); + device_add_domain_config(gc, &d_config, &libxl__pcidev_devtype, + &pcidev_saved); rc = libxl__dm_check_start(gc, &d_config, domid); if (rc) goto out; diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 7f78f4e..1d5a243 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -246,8 +246,8 @@ static int libxl__device_usbctrl_add_xenstore(libxl__gc *gc, uint32_t domid, rc = libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; - DEVICE_ADD(usbctrl, usbctrls, domid, &usbctrl_saved, - COMPARE_USBCTRL, &d_config); + device_add_domain_config(gc, &d_config, &libxl__usbctrl_devtype, + &usbctrl_saved); rc = libxl__dm_check_start(gc, &d_config, domid); if (rc) goto out; @@ -1194,8 +1194,8 @@ static int libxl__device_usbdev_add_xenstore(libxl__gc *gc, uint32_t domid, rc = libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; - DEVICE_ADD(usbdev, usbdevs, domid, &usbdev_saved, - COMPARE_USB, &d_config); + device_add_domain_config(gc, &d_config, &libxl__usbdev_devtype, + &usbdev_saved); rc = libxl__dm_check_start(gc, &d_config, domid); if (rc) goto out;