From patchwork Mon Sep 11 17:14:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9947757 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 96AE16024A for ; Mon, 11 Sep 2017 17:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 871E928CCA for ; Mon, 11 Sep 2017 17:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B3BA28CD3; Mon, 11 Sep 2017 17:17:55 +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 1EDBE28CCA for ; Mon, 11 Sep 2017 17:17:55 +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 1drSIt-0001tM-JI; Mon, 11 Sep 2017 17:15:23 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drSIs-0001t4-I9 for xen-devel@lists.xenproject.org; Mon, 11 Sep 2017 17:15:22 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 63/57-15060-9A4C6B95; Mon, 11 Sep 2017 17:15:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRWlGSWpSXmKPExsVyMfS6k+7KI9s iDZ7t47T4vmUykwOjx+EPV1gCGKNYM/OS8isSWDPOvHIteCZZ0fvmBVsD41ThLkYuDiGB6YwS EzY8ZQVxWAReskj86HjPDOJICPSzShyfBZLhAHLiJJ7dNu5i5AQy0yTaW96yQ9hlEi82/GEGs YUE5CUOtlxmh7CnMUlsmqIEYrMJaEncv72CDcQWEVCSuLdqMhOIzSyQIrF3XRsjiC0sECSx/O JGVhCbRUBV4kj/UhaQtbwCDhInJ1RBrJKTuHmuE2wVp4CjxJIpXawQqxwkjjzvZJ/AKLiAkWE Vo0ZxalFZapGukaleUlFmekZJbmJmjq6hgZlebmpxcWJ6ak5iUrFecn7uJkZgsDEAwQ7GVQsC DzFKcjApifK+O74lUogvKT+lMiOxOCO+qDQntfgQowYHh8DPp39bGKVY8vLzUpUkeA8e3hYpJ FiUmp5akZaZA4wHmFIJDh4lEd4ckDRvcUFibnFmOkTqFKMlx4U7l/4wcRzYcwtIdty8+4dJCG yelDjvIpAGAZCGjNI8uHGwmL3EKCslzMsIdKwQT0FqUW5mCar8K0ZxDkYlYd7nIFN4MvNK4La +AjqICeggnktbQA4qSURISTUwrrNL/l78QW8Sk7X+px6bhOwTcU6zVgeKpd1zO/iTPfRiNa/U FebSwhs8dypOGvX1iD0Qb/tYIprO27OD0VaeI+gh073X/AbFMhKvyqtDVvh2urE/fB/Pl9Dp9 icxkeP+nlcdepOm2yyW1dlQcyX7ocenchbP/adMgr54ayWqz7WSWXJd/4ISS3FGoqEWc1FxIg D+KzL21AIAAA== X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1505150120!59237976!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 18542 invoked from network); 11 Sep 2017 17:15:21 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-6.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 11 Sep 2017 17:15:21 -0000 Received: by mail-lf0-f66.google.com with SMTP id y15so4244100lfd.0 for ; Mon, 11 Sep 2017 10:15:21 -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=xsyvmWyqR1ILX1zqbLk5pqxtMcAMTJGGBpQA46Iznxk=; b=goSpBkGLUS1ZVWRL6p4Oz1fl+iK8YkoiIbnR0r3MOrPipNBtJx72uFnl49OqC14v/p UhSGot4Z5QSRhINnvPcyRW1XO6yjLldiMmccEghFmovAmaox7LsmMV/uA8PcehM7ebkR j0pype/8wlL+DADU6Xla1qQjoS+BopOz/7GeteafvQyrdWi92qE/MCJZz8ChS+Mh0f5B p2XNFX4lT3uXR9FEwDv84CI02F8Ha3Gbiiny4YiBdNVvrBhDrtmL4uqGJN+nA3iDZZ0+ wVqjCL5i4r265z0DmuGeXN7LGb+/bWN3d0cj9P3GEfeIW/yCz3BxNO+1txB19vhOsbot 37hg== 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=xsyvmWyqR1ILX1zqbLk5pqxtMcAMTJGGBpQA46Iznxk=; b=e3978RllPlVaXMalQ6ZA4xrO5a+NqxKFXOjoeH++ivvjAyR9b8ak0w9V1BSNS9AeEn QUD0y1ELN1vFzl2Wd6Qp9jmGGsaQQwBfNSjB9SgY4wrNtt4ScQ+0TdXHgbF5QfrZvZKk 5aemt5XZMVytC73pwqnca6fi0q6uQFH8b78ZbBkg9n+UxUIXT/4mMNjf5hEnT5tG7qF4 c9ZrNRoPXyStxW9WPsAGbCV31cNr+jIAfuOcrp7t69EjffuQdxohxWSEpLMS2ACXHlAJ QSaNjYz2zj6QvTmxbbEMsAeUOLiUZ1kZp2Or1NOK6LCCt0kvkopAR2AXyhFVoqd6tQr0 yPQw== X-Gm-Message-State: AHPjjUhpZ1hSM3zFNeTIce7ZrOEyGJWsIx6gYMn6HvY4KjhNeHtxBpJx ZnI24qiUp39H4kDg X-Google-Smtp-Source: AOwi7QBoQRafqgCXh4kIWv6HtjoqAmQoOUaiMXK+HWF5H7mUwCUl3TnmKdBtt1xxVc4k9RA5r/fuPw== X-Received: by 10.46.22.13 with SMTP id w13mr4444754ljd.1.1505150120051; Mon, 11 Sep 2017 10:15:20 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-57.209.223.85.sovam.net.ua. [85.223.209.57]) by smtp.gmail.com with ESMTPSA id g21sm1893044lje.52.2017.09.11.10.15.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Sep 2017 10:15:19 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Mon, 11 Sep 2017 20:14:52 +0300 Message-Id: <1505150102-30806-3-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505150102-30806-1-git-send-email-al1img@gmail.com> References: <1505150102-30806-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v5 02/12] 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 /*