From: Oleksandr Grytsov <al1img@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com,
Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Subject: [PATCH v4 02/13] libxl: add generic functions to get and free device list
Date: Tue, 18 Jul 2017 17:25:19 +0300 [thread overview]
Message-ID: <1500387930-16317-3-git-send-email-al1img@gmail.com> (raw)
In-Reply-To: <1500387930-16317-1-git-send-email-al1img@gmail.com>
From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Add libxl__device_list and libxl__device_list_free
functions to handle device list using the device
framework.
Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
---
tools/libxl/libxl_device.c | 66 ++++++++++++++++++++++++++++++++++++++++++++
tools/libxl/libxl_internal.h | 8 ++++++
2 files changed, 74 insertions(+)
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 07165f0..f1d4848 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -1991,6 +1991,72 @@ 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);
+ void *end = (uint8_t *)list + ndirs * dt->dev_elem_size;
+ item = list;
+
+ while (item < end) {
+ dt->init(item);
+
+ 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;
+ }
+ }
+
+ *num = ndirs;
+ r = list;
+ list = NULL;
+
+out:
+
+ if (list) {
+ *num = 0;
+ while(item >= list) {
+ dt->dispose(item);
+ item = (uint8_t*)item - dt->dev_elem_size;
+ }
+ free(list);
+ }
+
+ 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 075dfe3..271ac89 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3506,6 +3506,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 *);
};
@@ -4386,6 +4387,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
/*
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-07-18 14:25 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-18 14:25 [PATCH v4 00/13] libxl: add PV display device driver interface Oleksandr Grytsov
2017-07-18 14:25 ` [PATCH v4 01/13] libxl: add generic function to add device Oleksandr Grytsov
2017-09-05 11:47 ` Wei Liu
2017-09-05 16:44 ` Oleksandr Grytsov
2017-09-06 9:36 ` Wei Liu
2017-09-06 12:08 ` Oleksandr Grytsov
2017-07-18 14:25 ` Oleksandr Grytsov [this message]
2017-09-05 11:51 ` [PATCH v4 02/13] libxl: add generic functions to get and free device list Wei Liu
2017-09-06 12:31 ` Oleksandr Grytsov
2017-07-18 14:25 ` [PATCH v4 03/13] libxl: add vdispl device Oleksandr Grytsov
2017-09-05 12:52 ` Wei Liu
2017-09-05 12:58 ` Ian Jackson
2017-09-05 13:04 ` Wei Liu
2017-09-06 13:02 ` Oleksandr Grytsov
2017-09-06 13:39 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 04/13] xl: add PV display device commands Oleksandr Grytsov
2017-07-28 14:11 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 05/13] docs: add PV display driver information Oleksandr Grytsov
2017-07-28 14:11 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 06/13] libxl: change p9 to use generec add function Oleksandr Grytsov
2017-07-28 14:11 ` Wei Liu
2017-07-28 16:23 ` Wei Liu
2017-07-30 18:42 ` Oleksandr Grytsov
2017-07-31 14:36 ` Wei Liu
2017-08-01 11:58 ` Oleksandr Grytsov
2017-08-01 13:00 ` Wei Liu
2017-08-02 11:37 ` Oleksandr Grytsov
2017-08-04 11:53 ` Wei Liu
2017-08-08 12:39 ` Oleksandr Grytsov
2017-08-08 15:05 ` Wei Liu
2017-09-05 12:53 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 07/13] libxl: change vkb " Oleksandr Grytsov
2017-09-05 12:54 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 08/13] libxl: change vfb " Oleksandr Grytsov
2017-09-05 12:55 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 09/13] libxl: change disk to use generic getting list functions Oleksandr Grytsov
2017-09-05 12:58 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 10/13] libxl: change nic to use generec add function Oleksandr Grytsov
2017-09-05 13:03 ` Wei Liu
2017-09-06 15:39 ` Oleksandr Grytsov
2017-07-18 14:25 ` [PATCH v4 11/13] libxl: change vtpm " Oleksandr Grytsov
2017-09-05 13:05 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 12/13] libxl: remove unneeded DEVICE_ADD macro Oleksandr Grytsov
2017-09-05 13:05 ` Wei Liu
2017-07-18 14:25 ` [PATCH v4 13/13] libxl: make pci and usb setdefault function generic Oleksandr Grytsov
2017-09-05 13:06 ` Wei Liu
2017-09-06 15:53 ` Oleksandr Grytsov
2017-09-07 9:05 ` Wei Liu
2017-07-27 11:30 ` [PATCH v4 00/13] libxl: add PV display device driver interface Oleksandr Andrushchenko
2017-07-27 14:49 ` Wei Liu
2017-07-28 14:13 ` Wei Liu
2017-08-17 10:13 ` Oleksandr Grytsov
2017-08-17 11:11 ` Wei Liu
2017-08-30 15:49 ` Oleksandr Grytsov
2017-08-30 15:52 ` Ian Jackson
2017-08-31 9:01 ` Oleksandr Grytsov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1500387930-16317-3-git-send-email-al1img@gmail.com \
--to=al1img@gmail.com \
--cc=ian.jackson@eu.citrix.com \
--cc=oleksandr_grytsov@epam.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).