[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v1 4/4] libxl: move ibxl_devid_to_device_... to LIBXL_DEFINE_DEVID_TO_DEVICE
From: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx> Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx> Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/libxl/libxl_internal.h | 38 ++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_nic.c | 22 +--------------------- tools/libxl/libxl_vdispl.c | 35 +---------------------------------- 3 files changed, 40 insertions(+), 55 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 4f1e026..506687f 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3490,6 +3490,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 e028fda..01b711b 100644 --- a/tools/libxl/libxl_nic.c +++ b/tools/libxl/libxl_nic.c @@ -380,27 +380,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_path; - int rc = ERROR_FAIL; - - libxl_device_nic_init(nic); - - libxl_path = libxl__domain_device_libxl_path(gc, domid, devid, - LIBXL__DEVICE_KIND_VIF); - - 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; @@ -520,6 +499,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 da5b10f..55dfac3 100644 --- a/tools/libxl/libxl_vdispl.c +++ b/tools/libxl/libxl_vdispl.c @@ -195,44 +195,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) -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |