@@ -451,6 +451,12 @@
*/
#define LIBXL_HAVE_VIRIDIAN_EX_PROCESSOR_MASKS 1
+/*
+ * LIBXL_HAVE_DEVICE_PCI_LIST_FREE indicates that the
+ * libxl_device_pci_list_free() function is defined.
+ */
+#define LIBXL_HAVE_DEVICE_PCI_LIST_FREE 1
+
/*
* libxl ABI compatibility
*
@@ -2321,6 +2327,7 @@ int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid,
libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid,
int *num);
+void libxl_device_pci_list_free(libxl_device_pci* list, int num);
/*
* Turns the current process into a backend device service daemon
@@ -2011,7 +2011,7 @@ void *libxl__device_list(libxl__gc *gc, const libxl__device_type *dt,
void *r = NULL;
void *list = NULL;
void *item = NULL;
- char *libxl_path;
+ char *path;
char **dir = NULL;
unsigned int ndirs = 0;
unsigned int ndevs = 0;
@@ -2019,42 +2019,46 @@ void *libxl__device_list(libxl__gc *gc, const libxl__device_type *dt,
*num = 0;
- libxl_path = GCSPRINTF("%s/device/%s",
- libxl__xs_libxl_path(gc, domid),
- libxl__device_kind_to_string(dt->type));
-
- dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs);
+ if (dt->get_path) {
+ rc = dt->get_path(gc, domid, &path);
+ if (rc) goto out;
+ } else {
+ path = GCSPRINTF("%s/device/%s",
+ libxl__xs_libxl_path(gc, domid),
+ libxl__device_kind_to_string(dt->type));
+ }
- if (dir && ndirs) {
- if (dt->get_num) {
- if (ndirs != 1) {
- LOGD(ERROR, domid, "multiple entries in %s\n", libxl_path);
- rc = ERROR_FAIL;
- goto out;
- }
- rc = dt->get_num(gc, GCSPRINTF("%s/%s", libxl_path, *dir), &ndevs);
- if (rc) goto out;
- } else {
+ if (dt->get_num) {
+ rc = dt->get_num(gc, path, &ndevs);
+ if (rc) goto out;
+ } else {
+ dir = libxl__xs_directory(gc, XBT_NULL, path, &ndirs);
+ if (dir && ndirs)
ndevs = ndirs;
- }
- list = libxl__malloc(NOGC, dt->dev_elem_size * ndevs);
- item = list;
+ }
- while (*num < ndevs) {
- dt->init(item);
+ if (!ndevs)
+ return NULL;
- if (dt->from_xenstore) {
- int nr = dt->get_num ? *num : atoi(*dir);
- char *device_libxl_path = GCSPRINTF("%s/%s", libxl_path, *dir);
- rc = dt->from_xenstore(gc, device_libxl_path, nr, item);
- if (rc) goto out;
- }
+ list = libxl__malloc(NOGC, dt->dev_elem_size * ndevs);
+ item = list;
- item = (uint8_t *)item + dt->dev_elem_size;
- ++(*num);
- if (!dt->get_num)
- ++dir;
+ while (*num < ndevs) {
+ dt->init(item);
+
+ if (dt->from_xenstore) {
+ int nr = dt->get_num ? *num : atoi(*dir);
+ char *device_path = dt->get_num ? path :
+ GCSPRINTF("%s/%d", path, nr);
+
+ rc = dt->from_xenstore(gc, device_path, nr, item);
+ if (rc) goto out;
}
+
+ item = (uint8_t *)item + dt->dev_elem_size;
+ ++(*num);
+ if (!dt->get_num)
+ ++dir;
}
r = list;
@@ -3917,6 +3917,7 @@ typedef int (*device_dm_needed_fn_t)(void *, unsigned);
typedef void (*device_update_config_fn_t)(libxl__gc *, void *, void *);
typedef int (*device_update_devid_fn_t)(libxl__gc *, uint32_t, void *);
typedef int (*device_get_num_fn_t)(libxl__gc *, const char *, unsigned int *);
+typedef int (*device_get_path_fn_t)(libxl__gc *, uint32_t, char **);
typedef int (*device_from_xenstore_fn_t)(libxl__gc *, const char *,
libxl_devid, void *);
typedef int (*device_set_xenstore_config_fn_t)(libxl__gc *, uint32_t, void *,
@@ -3941,6 +3942,7 @@ struct libxl__device_type {
device_update_config_fn_t update_config;
device_update_devid_fn_t update_devid;
device_get_num_fn_t get_num;
+ device_get_path_fn_t get_path;
device_from_xenstore_fn_t from_xenstore;
device_set_xenstore_config_fn_t set_xenstore_config;
};
@@ -2393,29 +2393,13 @@ static int libxl__device_pci_get_num(libxl__gc *gc, const char *be_path,
return rc;
}
-libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num)
+static int libxl__device_pci_get_path(libxl__gc *gc, uint32_t domid,
+ char **path)
{
- GC_INIT(ctx);
- char *be_path;
- unsigned int n, i;
- libxl_device_pci *pcis = NULL;
-
- *num = 0;
-
- be_path = libxl__domain_device_backend_path(gc, 0, domid, 0,
- LIBXL__DEVICE_KIND_PCI);
- if (libxl__device_pci_get_num(gc, be_path, &n))
- goto out;
+ *path = libxl__domain_device_backend_path(gc, 0, domid, 0,
+ LIBXL__DEVICE_KIND_PCI);
- pcis = calloc(n, sizeof(libxl_device_pci));
-
- for (i = 0; i < n; i++)
- libxl__device_pci_from_xs_be(gc, be_path, i, pcis + i);
-
- *num = n;
-out:
- GC_FREE;
- return pcis;
+ return 0;
}
void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid,
@@ -2492,10 +2476,13 @@ static int libxl_device_pci_compare(const libxl_device_pci *d1,
return COMPARE_PCI(d1, d2);
}
+LIBXL_DEFINE_DEVICE_LIST(pci)
+
#define libxl__device_pci_update_devid NULL
DEFINE_DEVICE_TYPE_STRUCT(pci, PCI, pcidevs,
.get_num = libxl__device_pci_get_num,
+ .get_path = libxl__device_pci_get_path,
.from_xenstore = libxl__device_pci_from_xs_be,
);