From patchwork Tue Sep 12 13:48:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9949265 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 7C2C3603F3 for ; Tue, 12 Sep 2017 13:50:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D03828FF7 for ; Tue, 12 Sep 2017 13:50:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61EC728FF8; Tue, 12 Sep 2017 13:50:53 +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 EBE8728FFA for ; Tue, 12 Sep 2017 13:50:51 +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 1drlYE-0005Sc-Oo; Tue, 12 Sep 2017 13:48:30 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drlYD-0005SP-8J for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 13:48:29 +0000 Received: from [85.158.137.68] by server-14.bemta-3.messagelabs.com id 25/FA-01910-CA5E7B95; Tue, 12 Sep 2017 13:48:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCIsWRWlGSWpSXmKPExsVyMfS6i+7qp9s jDfo/mVl83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnb9/gW9ElVfO68xNjAuFO4i5GLQ0hgOqPE jB+vmUAcFoGXLBKrvz1mB3EkBPpZJfputABlOIGcJImTzSvYIew0iYfLeqDsSolv6z6xgthCA vISB1sus0OMncIk8X//QkaQBJuAlsT92yvYQGwRASWJe6smgw1lFkiR2LuuDaxGWCBI4tGJ6S wgNouAqsSRF1uZQWxeAQeJ1oVfWCGWyUncPNcJFucUcJRo/93FDLHYQeLKmj1sExgFFzAyrGL UKE4tKkst0jUy0EsqykzPKMlNzMzRNTQw1stNLS5OTE/NSUwq1kvOz93ECAy5egYGxh2MzSf8 DjFKcjApifIq398eKcSXlJ9SmZFYnBFfVJqTWnyIUYODQ+Dn078tjFIsefl5qUoSvJOeANUJF qWmp1akZeYAowKmVIKDR0mEtxIkzVtckJhbnJkOkTrFaMlx4c6lP0wcB/bcApIdN+/+YRICmy clzpsP0iAA0pBRmgc3Dha5lxhlpYR5GRkYGIR4ClKLcjNLUOVfMYpzMCoJ81aDTOHJzCuB2/o K6CAmoIN4Lm0BOagkESEl1cCo6Gn16hFDIPujYEUNtxiNk7v9la/z6ZY/bCvdsm9bRs9CaW/u 1/eSVwV1n4qLd0l0ur1aTkYwRm/X43tPJOtY/Fq/sR7M3X/NL+/3i8i1YsZ1ocJWevnmG1/Mv 3FiOo+7s774q89FC56LHeYKFfCwWnj//3OxietPBtyfx3Xfo5WHXei/ySolluKMREMt5qLiRA CZga041wIAAA== X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1505224107!113719279!1 X-Originating-IP: [209.85.215.68] 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 26127 invoked from network); 12 Sep 2017 13:48:27 -0000 Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by server-10.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 13:48:27 -0000 Received: by mail-lf0-f68.google.com with SMTP id y15so5396231lfd.0 for ; Tue, 12 Sep 2017 06:48:27 -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=E9BD/ecdi2E1IxKuXKcoIUQngjrHCd9m7SyNCEYuxd8=; b=sMbNrjxq81Km+aC2pQ01HfGFZjjRYrgNJMS008zKtN2pnDmpDe6gO2ZheJJYV+z7rE PTR263bmhgMUCFq/Vwzkjrt0M0GUTwqHLZWi3aOYyvZPsFKGX7GwyYFOCw52XB8Hgq/z qZ28Hqt5669w4VxTEgWwbrkIk+lrjXMxB9cxWFyaRouo1LpFkju92xG+anr2jEn5uLsW xxo2Zl8rxMkoYKmnHclh89AM93MdUz2Sc2D7lUc1eIH30LLvfO+lLXqxgl+lkFYQc4wY SWuiZvPtZwZaUMTLadCGLPzKwj73xilUAygEzf/icu9/SDyXM2xhyCtURyXLYTrj0MRJ i3nw== 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=E9BD/ecdi2E1IxKuXKcoIUQngjrHCd9m7SyNCEYuxd8=; b=dVQFFdJgMNxNZnxJU+z51MeWnOr7hEbTyCL5UaNXdb8wIG9ZwoeMtq1U3w8ot5DOVw 5BGkkioy7MzZwGEqAU3Ire3dSbY/xHS6OMvZcMpcGuOl2GCSJ4vFWHrj9v6tyGy2ncZ/ jOK5N+Ih9Ziw2L45itRSazjn86Fkq/BqoLOpznFM05F3azcFNOQ4N1FB/X1ZpiYZVFwa M1YhrAbnzv/s5YaPVFwjI371aTDm5J7+g//tSYYt2vchLAMLjvj/+gFWtjwi9daO3cH7 aRl+QJLJBRovyO8ksXiPmkp2bQIblchYtp9Kjinj7kWzGikPzmR2pqP3DvllwJuqHO/8 rkbw== X-Gm-Message-State: AHPjjUh2jS/Ig+YAltsCzBfrnW+XuERp1X1twvLzYdkVGlxdjlUfJpPv wco04cnDwGP5Uqo+DpE= X-Google-Smtp-Source: AOwi7QAaD4FK/0WSQx4Nzzlhzxw9mTN01T95JrNG37q8C4ZyZVeBdsejmwEUV4fMIwe81ykXKH3d5g== X-Received: by 10.25.235.90 with SMTP id j87mr5953189lfh.249.1505224106971; Tue, 12 Sep 2017 06:48:26 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Sep 2017 06:48:26 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Tue, 12 Sep 2017 16:48:07 +0300 Message-Id: <1505224098-19330-3-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 02/13] libxl: add generic functions to get and free device list 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 Add libxl__device_list and libxl__device_list_free functions to handle device list using the device framework. Signed-off-by: Oleksandr Grytsov Acked-by: Wei Liu --- tools/libxl/libxl_device.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 8 ++++++ 2 files changed, 69 insertions(+) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 3296e83..487be28 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -1990,6 +1990,67 @@ out: return rc; } +void *libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt, + uint32_t domid, const char* name, int *num) +{ + void *r = NULL; + void *list = NULL; + void *item = NULL; + char *libxl_path; + char **dir = NULL; + unsigned int ndirs = 0; + int rc; + + *num = 0; + + libxl_path = GCSPRINTF("%s/device/%s", + libxl__xs_libxl_path(gc, domid), name); + + dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs); + + if (dir && ndirs) { + list = libxl__malloc(NOGC, dt->dev_elem_size * ndirs); + item = list; + + while (*num < ndirs) { + dt->init(item); + ++(*num); + + if (dt->from_xenstore) { + char *device_libxl_path = GCSPRINTF("%s/%s", libxl_path, *dir); + rc = dt->from_xenstore(gc, device_libxl_path, atoi(*dir), item); + if (rc) goto out; + } + + item = (uint8_t *)item + dt->dev_elem_size; + ++dir; + } + } + + r = list; + list = NULL; + +out: + + if (list) { + libxl__device_list_free(dt, list, *num); + *num = 0; + } + + return r; +} + +void libxl__device_list_free(const struct libxl_device_type *dt, + void *list, int num) +{ + int i; + + for (i = 0; i < num; i++) + dt->dispose((uint8_t*)list + i * dt->dev_elem_size); + + free(list); +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index c99ef3b..c94a117 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3505,6 +3505,7 @@ struct libxl_device_type { int (*dm_needed)(void *, unsigned); void (*update_config)(libxl__gc *, void *, void *); int (*update_devid)(libxl__gc *, uint32_t, void *); + int (*from_xenstore)(libxl__gc *, const char *, libxl_devid, void *); int (*set_xenstore_config)(libxl__gc *, uint32_t, void *, flexarray_t *, flexarray_t *, flexarray_t *); }; @@ -4385,6 +4386,13 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid, int libxl__device_add(libxl__gc *gc, uint32_t domid, const struct libxl_device_type *dt, void *type); +/* Caller is responsible for freeing the memory by calling + * libxl__device_list_free + */ +void* libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt, + uint32_t domid, const char* name, int *num); +void libxl__device_list_free(const struct libxl_device_type *dt, + void *list, int num); #endif /*