[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 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>
---
 tools/libxl/libxl_internal.h | 38 ++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nic.c      | 26 +-------------------------
 tools/libxl/libxl_vdispl.c   | 35 +----------------------------------
 tools/libxl/libxl_vkb.c      | 35 +----------------------------------
 tools/libxl/libxl_vsnd.c     | 36 +-----------------------------------
 5 files changed, 42 insertions(+), 128 deletions(-)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index d1a8d8e..26204f0 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3470,6 +3470,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 2d01803..b9ad262 100644
--- a/tools/libxl/libxl_nic.c
+++ b/tools/libxl/libxl_nic.c
@@ -381,31 +381,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_dom_path, *libxl_path;
-    int rc = ERROR_FAIL;
-
-    libxl_device_nic_init(nic);
-    libxl_dom_path = libxl__xs_libxl_path(gc, domid);
-    if (!libxl_dom_path)
-        goto out;
-
-    libxl_path = GCSPRINTF("%s/device/%s/%d", libxl_dom_path,
-                           
libxl__device_kind_to_string(LIBXL__DEVICE_KIND_VIF),
-                           devid);
-
-    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;
@@ -529,6 +504,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 0d87500..1cea0bd 100644
--- a/tools/libxl/libxl_vdispl.c
+++ b/tools/libxl/libxl_vdispl.c
@@ -198,44 +198,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)
diff --git a/tools/libxl/libxl_vkb.c b/tools/libxl/libxl_vkb.c
index 6ee0a7e..d4d531a 100644
--- a/tools/libxl/libxl_vkb.c
+++ b/tools/libxl/libxl_vkb.c
@@ -61,40 +61,6 @@ out:
     return AO_INPROGRESS;
 }
 
-int libxl_devid_to_device_vkb(libxl_ctx *ctx, uint32_t domid,
-                              int devid, libxl_device_vkb *vkb)
-{
-    GC_INIT(ctx);
-
-    libxl_device_vkb *vkbs = NULL;
-    int n, i;
-    int rc;
-
-    libxl_device_vkb_init(vkb);
-
-    vkbs = libxl__device_list(gc, &libxl__vkb_devtype, domid, &n);
-
-    if (!vkbs) { rc = ERROR_NOTFOUND; goto out; }
-
-    for (i = 0; i < n; ++i) {
-        if (devid == vkbs[i].devid) {
-            libxl_device_vkb_copy(ctx, vkb, &vkbs[i]);
-            rc = 0;
-            goto out;
-        }
-    }
-
-    rc = ERROR_NOTFOUND;
-
-out:
-
-    if (vkbs)
-        libxl__device_list_free(&libxl__vkb_devtype, vkbs, n);
-
-    GC_FREE;
-    return rc;
-}
-
 int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_t domid,
                              libxl_device_vkb *vkb,
                              libxl_vkbinfo *info)
@@ -152,6 +118,7 @@ static LIBXL_DEFINE_DEVICE_FROM_TYPE(vkb)
 #define libxl__add_vkbs NULL
 #define libxl_device_vkb_compare NULL
 
+LIBXL_DEFINE_DEVID_TO_DEVICE(vkb)
 LIBXL_DEFINE_DEVICE_LIST(vkb)
 LIBXL_DEFINE_DEVICE_REMOVE(vkb)
 
diff --git a/tools/libxl/libxl_vsnd.c b/tools/libxl/libxl_vsnd.c
index 8cc3a4b..b44c73c 100644
--- a/tools/libxl/libxl_vsnd.c
+++ b/tools/libxl/libxl_vsnd.c
@@ -593,45 +593,11 @@ out:
      return rc;
 }
 
-int libxl_devid_to_device_vsnd(libxl_ctx *ctx, uint32_t domid,
-                               int devid, libxl_device_vsnd *vsnd)
-{
-    GC_INIT(ctx);
-
-    libxl_device_vsnd *vsnds = NULL;
-    int n, i;
-    int rc;
-
-    libxl_device_vsnd_init(vsnd);
-
-    vsnds = libxl__device_list(gc, &libxl__vsnd_devtype, domid, &n);
-
-    if (!vsnds) { rc = ERROR_NOTFOUND; goto out; }
-
-    for (i = 0; i < n; ++i) {
-        if (devid == vsnds[i].devid) {
-            libxl_device_vsnd_copy(ctx, vsnd, &vsnds[i]);
-            rc = 0;
-            goto out;
-        }
-    }
-
-    rc = ERROR_NOTFOUND;
-
-out:
-
-    if (vsnds)
-        libxl__device_list_free(&libxl__vsnd_devtype, vsnds, n);
-
-    GC_FREE;
-    return rc;
-}
-
-
 static LIBXL_DEFINE_UPDATE_DEVID(vsnd)
 static LIBXL_DEFINE_DEVICE_FROM_TYPE(vsnd)
 static LIBXL_DEFINE_DEVICES_ADD(vsnd)
 
+LIBXL_DEFINE_DEVID_TO_DEVICE(vsnd)
 LIBXL_DEFINE_DEVICE_ADD(vsnd)
 LIBXL_DEFINE_DEVICE_REMOVE(vsnd)
 LIBXL_DEFINE_DEVICE_LIST(vsnd)
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.