From patchwork Thu Oct 5 09:30:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9986673 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 56B75605A8 for ; Thu, 5 Oct 2017 09:33:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 488FD28BE1 for ; Thu, 5 Oct 2017 09:33:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D9E828C10; Thu, 5 Oct 2017 09:33:12 +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 9D76A28BE1 for ; Thu, 5 Oct 2017 09:33:11 +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 1e02Ug-0005lH-By; Thu, 05 Oct 2017 09:31:02 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e02Ue-0005il-Rm for xen-devel@lists.xenproject.org; Thu, 05 Oct 2017 09:31:00 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 3C/05-03093-4DBF5D95; Thu, 05 Oct 2017 09:31:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCIsWRWlGSWpSXmKPExsVyMfS6k+7l31c jDW7v0rP4vmUykwOjx+EPV1gCGKNYM/OS8isSWDPObj3PVvDHpWLNwm1MDYzPtLoYuTiEBGYy Snx+/Z4NxGEReMkicbTpHiuIIyHQzyrReHYbUxcjJ5CTJbHgYB8rhJ0m0d4+lQXCrpRoufKdD cQWEpCXONhymR1i7BQmiTm7v7CDJNgEtCTu314BViQioCRxb9VksKHMAikSe9e1MYLYwgKREi s7NgDZHEBnqEo8OJkDEuYVcJCY3viLHWKXnMTNc53MIDangKPEl2+HofY6SPT33GSawCi4gJF hFaNGcWpRWWqRrrGBXlJRZnpGSW5iZo6uoYGZXm5qcXFiempOYlKxXnJ+7iZGYMgxAMEOxr9r Aw8xSnIwKYnyan29GinEl5SfUpmRWJwRX1Sak1p8iFGDg0Pg59O/LYxSLHn5ealKErxcH4DqB ItS01Mr0jJzgFEBUyrBwaMkwvv7I1Cat7ggMbc4Mx0idYrRkuPCnUt/mDgO7LkFJDtu3v3DJA Q2T0qclxdkngBIQ0ZpHtw4WOReYpSVEuZlBDpWiKcgtSg3swRV/hWjOAejkjDvDZApPJl5JXB bXwEdxAR00JymKyAHlSQipKQaGAV1JTPnfnfwT9igruyn2bNkwnM3Ncf7WQsseIwn7pmRt75r 6s7KTfUK/knh0+PUFOJVhITZEjbsPbJK/LnN942rjNOefle+X3zZwnT7Xa5/ElEb3zDWJ29c8 pzxb+xbiYbKgKtGjNV31PLq3cwiRNOucqYICb0QnWqn8OvyxOMJbzlWXwgWVGIpzkg01GIuKk 4EAPXjPJrXAgAA X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1507195859!76445487!1 X-Originating-IP: [209.85.215.66] 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 55029 invoked from network); 5 Oct 2017 09:30:59 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-12.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 5 Oct 2017 09:30:59 -0000 Received: by mail-lf0-f66.google.com with SMTP id m142so12450496lfg.8 for ; Thu, 05 Oct 2017 02:30:59 -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=4r4jB90GPdqujDClCwnKHIfzYdMONBQeGiUv5lJgedc=; b=Hvk8J8hoNKHwQGKy96IgmlOlANiVVqNi/VUqd5YsnN/+wW2XGQFG+4qk4ynmVSCdK1 Gg3PIaTHDsVF9jdi65LMcnAtKl17x3XN5FYJ0VQ/CrqLGvVZHPAv9HI/RYAhCoLM7SH0 s9g73y6i0QHO9wClyABpp2Cvbi9hpwLvt2fRCR+jensfXLLpgN3L5EXVaRhDdYNNOUU5 G966/haKdNuFCOuChd5mbFTI8BvzWXPaXcqCpxPlt9kYlCZlec7cBP9h4/BqBIEvjxOx awNxfWzUeVzSoKAmTSstgCcmu1g/vAZ5FaNbRxLiypz0NZB1i0KzxdkjBiam45s/7jg7 /eMg== 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=4r4jB90GPdqujDClCwnKHIfzYdMONBQeGiUv5lJgedc=; b=UTf2qwCdOI6OjjJIb4HNK6Qp6HulolgSm0U3mdJIEruD9Cd3cHW8NL/um1DsjStg8k bYbSZsaMxg8SPmoev9f0/g/MAHWuZJxbjEf4XfZzZW7P8U9riphjy8DinRrGe89oUELu 9Edihv+knWq2BTd5xon6NlsATX5S6vid6iNppRVtaTZNPXc0FgzmhlP+vZ+2OE4tY45Q A7sDtOxutSHbIrfSk5eezBZk4hHqjF5dVf9rfg0h9gB1ny1HLiDcrQcQeoF698ULhnwO OOhzHcsQkOv+/XvkOMp7O538iYEEoBid2UD7HkWnWb3mFR01pAeOwIxc0k+SvDJiLm0l +NPQ== X-Gm-Message-State: AHPjjUhPHvvBw/pqSqTsWo4CToZsu/YtD3+WD+m5+2Gh/HwFrj8RzYMd Dw0vyAsIO0J7O15n943OESH2ig== X-Google-Smtp-Source: AOwi7QAM5fI8oqYcyv/vmRwgXnkORim7xqwf62pi5CYRoM7a+SrWQ/7sDgeR4xBfHXViODG8brhGZg== X-Received: by 10.25.169.19 with SMTP id s19mr7283302lfe.235.1507195858674; Thu, 05 Oct 2017 02:30:58 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-52.209.223.85.sovam.net.ua. [85.223.209.52]) by smtp.gmail.com with ESMTPSA id z1sm868340lja.42.2017.10.05.02.30.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Oct 2017 02:30:58 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Thu, 5 Oct 2017 12:30:48 +0300 Message-Id: <1507195848-18346-5-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507195848-18346-1-git-send-email-al1img@gmail.com> References: <1507195848-18346-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH 4/4] libxl: move ibxl_devid_to_device_... to LIBXL_DEFINE_DEVID_TO_DEVICE 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_internal.h | 38 ++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_nic.c | 26 +------------------------- tools/libxl/libxl_vdispl.c | 35 +---------------------------------- tools/libxl/libxl_vkb.c | 35 +---------------------------------- tools/libxl/libxl_vsnd.c | 36 +----------------------------------- 5 files changed, 42 insertions(+), 128 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index d1a8d8e..26204f0 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3470,6 +3470,44 @@ _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st); return 0; \ } +#define LIBXL_DEFINE_DEVID_TO_DEVICE(name) \ + int libxl_devid_to_device_##name(libxl_ctx *ctx, uint32_t domid, \ + int devid, \ + libxl_device_##name *type) \ + { \ + GC_INIT(ctx); \ + \ + char *device_path; \ + const char *tmp; \ + int rc; \ + \ + libxl_device_##name##_init(type); \ + \ + device_path = GCSPRINTF("%s/device/%s/%d", \ + libxl__xs_libxl_path(gc, domid), \ + libxl__device_kind_to_string( \ + libxl__##name##_devtype.type), \ + devid); \ + \ + if (libxl__xs_read_mandatory(gc, XBT_NULL, device_path, &tmp)) {\ + rc = ERROR_NOTFOUND; goto out; \ + } \ + \ + if (libxl__##name##_devtype.from_xenstore) { \ + rc = libxl__##name##_devtype.from_xenstore(gc, device_path, \ + devid, type); \ + if (rc) goto out; \ + } \ + \ + rc = 0; \ + \ + out: \ + \ + GC_FREE; \ + return rc; \ + } + + #define LIBXL_DEFINE_DEVICE_REMOVE(type) \ LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, remove, 0) \ LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, destroy, 1) diff --git a/tools/libxl/libxl_nic.c b/tools/libxl/libxl_nic.c index 2d01803..b9ad262 100644 --- a/tools/libxl/libxl_nic.c +++ b/tools/libxl/libxl_nic.c @@ -381,31 +381,6 @@ static int libxl__nic_from_xenstore(libxl__gc *gc, const char *libxl_path, return rc; } -int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid, - int devid, libxl_device_nic *nic) -{ - GC_INIT(ctx); - char *libxl_dom_path, *libxl_path; - int rc = ERROR_FAIL; - - libxl_device_nic_init(nic); - libxl_dom_path = libxl__xs_libxl_path(gc, domid); - if (!libxl_dom_path) - goto out; - - libxl_path = GCSPRINTF("%s/device/%s/%d", libxl_dom_path, - libxl__device_kind_to_string(LIBXL__DEVICE_KIND_VIF), - devid); - - rc = libxl__nic_from_xenstore(gc, libxl_path, devid, nic); - if (rc) goto out; - - rc = 0; -out: - GC_FREE; - return rc; -} - libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num) { libxl_device_nic *r; @@ -529,6 +504,7 @@ out: static LIBXL_DEFINE_UPDATE_DEVID(nic) static LIBXL_DEFINE_DEVICE_FROM_TYPE(nic) +LIBXL_DEFINE_DEVID_TO_DEVICE(nic) LIBXL_DEFINE_DEVICE_ADD(nic) LIBXL_DEFINE_DEVICES_ADD(nic) LIBXL_DEFINE_DEVICE_REMOVE(nic) diff --git a/tools/libxl/libxl_vdispl.c b/tools/libxl/libxl_vdispl.c index 0d87500..1cea0bd 100644 --- a/tools/libxl/libxl_vdispl.c +++ b/tools/libxl/libxl_vdispl.c @@ -198,44 +198,11 @@ out: return rc; } -int libxl_devid_to_device_vdispl(libxl_ctx *ctx, uint32_t domid, - int devid, libxl_device_vdispl *vdispl) -{ - GC_INIT(ctx); - - libxl_device_vdispl *vdispls = NULL; - int n, i; - int rc; - - libxl_device_vdispl_init(vdispl); - - vdispls = libxl__device_list(gc, &libxl__vdispl_devtype, domid, &n); - - if (!vdispls) { rc = ERROR_NOTFOUND; goto out; } - - for (i = 0; i < n; ++i) { - if (devid == vdispls[i].devid) { - libxl_device_vdispl_copy(ctx, vdispl, &vdispls[i]); - rc = 0; - goto out; - } - } - - rc = ERROR_NOTFOUND; - -out: - - if (vdispls) - libxl__device_list_free(&libxl__vdispl_devtype, vdispls, n); - - GC_FREE; - return rc; -} - static LIBXL_DEFINE_DEVICE_FROM_TYPE(vdispl) static LIBXL_DEFINE_UPDATE_DEVID(vdispl) static LIBXL_DEFINE_DEVICES_ADD(vdispl) +LIBXL_DEFINE_DEVID_TO_DEVICE(vdispl) LIBXL_DEFINE_DEVICE_ADD(vdispl) LIBXL_DEFINE_DEVICE_REMOVE(vdispl) LIBXL_DEFINE_DEVICE_LIST(vdispl) diff --git a/tools/libxl/libxl_vkb.c b/tools/libxl/libxl_vkb.c index 6ee0a7e..d4d531a 100644 --- a/tools/libxl/libxl_vkb.c +++ b/tools/libxl/libxl_vkb.c @@ -61,40 +61,6 @@ out: return AO_INPROGRESS; } -int libxl_devid_to_device_vkb(libxl_ctx *ctx, uint32_t domid, - int devid, libxl_device_vkb *vkb) -{ - GC_INIT(ctx); - - libxl_device_vkb *vkbs = NULL; - int n, i; - int rc; - - libxl_device_vkb_init(vkb); - - vkbs = libxl__device_list(gc, &libxl__vkb_devtype, domid, &n); - - if (!vkbs) { rc = ERROR_NOTFOUND; goto out; } - - for (i = 0; i < n; ++i) { - if (devid == vkbs[i].devid) { - libxl_device_vkb_copy(ctx, vkb, &vkbs[i]); - rc = 0; - goto out; - } - } - - rc = ERROR_NOTFOUND; - -out: - - if (vkbs) - libxl__device_list_free(&libxl__vkb_devtype, vkbs, n); - - GC_FREE; - return rc; -} - int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb, libxl_vkbinfo *info) @@ -152,6 +118,7 @@ static LIBXL_DEFINE_DEVICE_FROM_TYPE(vkb) #define libxl__add_vkbs NULL #define libxl_device_vkb_compare NULL +LIBXL_DEFINE_DEVID_TO_DEVICE(vkb) LIBXL_DEFINE_DEVICE_LIST(vkb) LIBXL_DEFINE_DEVICE_REMOVE(vkb) diff --git a/tools/libxl/libxl_vsnd.c b/tools/libxl/libxl_vsnd.c index 8cc3a4b..b44c73c 100644 --- a/tools/libxl/libxl_vsnd.c +++ b/tools/libxl/libxl_vsnd.c @@ -593,45 +593,11 @@ out: return rc; } -int libxl_devid_to_device_vsnd(libxl_ctx *ctx, uint32_t domid, - int devid, libxl_device_vsnd *vsnd) -{ - GC_INIT(ctx); - - libxl_device_vsnd *vsnds = NULL; - int n, i; - int rc; - - libxl_device_vsnd_init(vsnd); - - vsnds = libxl__device_list(gc, &libxl__vsnd_devtype, domid, &n); - - if (!vsnds) { rc = ERROR_NOTFOUND; goto out; } - - for (i = 0; i < n; ++i) { - if (devid == vsnds[i].devid) { - libxl_device_vsnd_copy(ctx, vsnd, &vsnds[i]); - rc = 0; - goto out; - } - } - - rc = ERROR_NOTFOUND; - -out: - - if (vsnds) - libxl__device_list_free(&libxl__vsnd_devtype, vsnds, n); - - GC_FREE; - return rc; -} - - static LIBXL_DEFINE_UPDATE_DEVID(vsnd) static LIBXL_DEFINE_DEVICE_FROM_TYPE(vsnd) static LIBXL_DEFINE_DEVICES_ADD(vsnd) +LIBXL_DEFINE_DEVID_TO_DEVICE(vsnd) LIBXL_DEFINE_DEVICE_ADD(vsnd) LIBXL_DEFINE_DEVICE_REMOVE(vsnd) LIBXL_DEFINE_DEVICE_LIST(vsnd)