From patchwork Tue Jul 18 14:25:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9848527 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 8CD41602C8 for ; Tue, 18 Jul 2017 14:28:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F0CB2852B for ; Tue, 18 Jul 2017 14:28:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73C3328577; Tue, 18 Jul 2017 14:28: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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, 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 E45C02852B for ; Tue, 18 Jul 2017 14:28: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 1dXTRk-0002ku-NW; Tue, 18 Jul 2017 14:25:56 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXTRj-0002hL-CL for xen-devel@lists.xenproject.org; Tue, 18 Jul 2017 14:25:55 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id B8/5A-02176-27A1E695; Tue, 18 Jul 2017 14:25:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRWlGSWpSXmKPExsVyMfS6s26RVF6 kwbtvzBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aHE4oF160q9netY2pgnKvexcjFISQwg1Hi z+a9LCAOi8BLFokfp6+CORIC/awSDfO+M3YxcgI5SRLrz69ggbDLJKasamQCsYUE5CUOtlxmh xg1jUni89edYEVsAloS92+vYAOxRQSUJO6tmgzWwCyQIrF3XRvYUGEBR4nP/w6zg9gsAqoSc6 ZtAevlBYpv2t/KDrFMTuLmuU7mLkYODk6g+NYZ5RB7HSRutL5in8AosICRYRWjRnFqUVlqka6 RoV5SUWZ6RkluYmaOrqGBsV5uanFxYnpqTmJSsV5yfu4mRmBg1TMwMO5g7Nnrd4hRkoNJSZR3 9YHcSCG+pPyUyozE4oz4otKc1OJDjBocHAI/n/5tYZRiycvPS1WS4OWRzIsUEixKTU+tSMvMA YY+TKkEB4+SCG++BFCat7ggMbc4Mx0idYrRnuPKlXVfmDg2rF4PJKcc2A4kX034/41JCGyqlD hvB8hUAZC2jNI8uKGwWL3EKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZjXDGQKT2ZeCdzuV0B nMQGdJeybA3JWSSJCSqqBcWPfzjDtlM8HVf3C2q/OezSj/LkH+7KmqT2XntU8iUq9Uq78IDjI r2oeW9gLNmHe/YoLDx8R67jsmLwlou/R/VnNN4MPSbGsfLAyPK53JdPeTTyFmS/z5wTHqx1et KzdU1Tqoft5k/n6fnHWWaoXk/7d2rRXryXx0uR/KesOvytfvOFG7Ksj5kosxRmJhlrMRcWJAB 2GBmDQAgAA X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1500387953!94319923!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.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6952 invoked from network); 18 Jul 2017 14:25:53 -0000 Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by server-2.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Jul 2017 14:25:53 -0000 Received: by mail-lf0-f67.google.com with SMTP id w198so1437993lff.3 for ; Tue, 18 Jul 2017 07:25:53 -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=GWe41d2WV16DbWeJGuarDZoTe0Vw71GW7vmtlU5R818=; b=qdDJdAkoP+iJp4F+3xtMGOt+nu0XG9gtP9kyH9CjqqM67Q3vhpnv+9Dwr8JwtQQ7ji gUkQSPkuq88xgfRGLpsOHVHjUTj2t0usZyYRW7QLh4Oi/i4w0pWftG0qn9ad6/jBy3mO s5d1eEm3CFrWE5KfGbIaU6Ea1PgiDywmO5Qcgg2umQDJvt2nh1PHjt8TUVELog487/Z1 6hYy8GPtS7ykX7LBg8mwMI0Auqs+eg90R2SK5iUftgAwbSvsjBuPN1fRogQP2Ir4ofLz BuX68PnIQFnyKJRpA/rKsjNKq4ZLncPYwkGhfRGLjZekW9mwUr9dMb/Voontm1SOwt39 KAKQ== 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=GWe41d2WV16DbWeJGuarDZoTe0Vw71GW7vmtlU5R818=; b=smt/m5VDOjEavyf7Aaeq4w/tSprZLJqi05jTBemDZ1TJnWTrU/wVm9H7Wwr0S+U4QV 38XLt7MT8ZnwnF34jv2eDgfTSi1XWHARCCyEYz8oNxG1b8C3hdq6hlDCBlEYyfOoJ2Xv V+T5QD9NUTRRMXM4xgTrqMnHfAiwEgXwTlwWEFH8dqaJFyvGp2nLvQdoObYaMw1bXHLY uN9Gpz96ETUdO/Kg/7r52tkfwK1umCrt27Krwb9VAzDJWuO2KYOndOs8xmgsMy8goUi3 z1FtIg1cZyMsMRBN01eDjXGkA54cDx9QV1s6xrAcQa+uvh1kluitz8C6nRJPAtQCXwGu Q+og== X-Gm-Message-State: AIVw113zeJan9/wmOxPj10VoTNig5+yzSqLGN2Q64P30Fm+vxntYowud O0XLVwrJFP8yxN6Q6Ug= X-Received: by 10.46.19.26 with SMTP id 26mr878242ljt.100.1500387952976; Tue, 18 Jul 2017 07:25:52 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-58.209.223.85.sovam.net.ua. [85.223.209.58]) by smtp.gmail.com with ESMTPSA id s134sm620442lfe.27.2017.07.18.07.25.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 07:25:52 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Tue, 18 Jul 2017 17:25:29 +0300 Message-Id: <1500387930-16317-13-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500387930-16317-1-git-send-email-al1img@gmail.com> References: <1500387930-16317-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v4 12/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 f1d4848..ca7b165 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; int i; diff --git a/tools/libxl/libxl_disk.c b/tools/libxl/libxl_disk.c index f4f10cb..c41c7b5 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 4b1c5ab..5fd0356 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -4282,55 +4282,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. * @@ -4360,6 +4311,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 c3f1e5c..159d046 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 07fb202..e526c08 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -245,8 +245,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; @@ -1199,8 +1199,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;