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

[Xen-devel] [PATCH 3/4] libxl: move libxl__device_from_ to LIBXL_DEFINE_DEVICE_FROM_TYPE



From: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>

LIBXL_DEFINE_DEVICE_FROM_TYPE uses libxl__..._devtype.type to
be assigned as device and backend type.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>
---
 tools/libxl/libxl_9pfs.c     | 19 +++----------------
 tools/libxl/libxl_console.c  | 18 +++---------------
 tools/libxl/libxl_internal.h | 15 +++++++++++++++
 tools/libxl/libxl_nic.c      | 19 +++----------------
 tools/libxl/libxl_vdispl.c   | 20 ++++----------------
 tools/libxl/libxl_vkb.c      | 15 +--------------
 tools/libxl/libxl_vsnd.c     | 21 +++++----------------
 tools/libxl/libxl_vtpm.c     | 21 ++++-----------------
 8 files changed, 38 insertions(+), 110 deletions(-)

diff --git a/tools/libxl/libxl_9pfs.c b/tools/libxl/libxl_9pfs.c
index 1298db1..e5c41e9 100644
--- a/tools/libxl/libxl_9pfs.c
+++ b/tools/libxl/libxl_9pfs.c
@@ -23,22 +23,6 @@ static int libxl__device_p9_setdefault(libxl__gc *gc, 
uint32_t domid,
     return libxl__resolve_domid(gc, p9->backend_domname, &p9->backend_domid);
 }
 
-static int libxl__device_from_p9(libxl__gc *gc, uint32_t domid,
-                                 libxl_device_p9 *p9,
-                                 libxl__device *device)
-{
-   device->backend_devid   = p9->devid;
-   device->backend_domid   = p9->backend_domid;
-   device->backend_kind    = LIBXL__DEVICE_KIND_9PFS;
-   device->devid           = p9->devid;
-   device->domid           = domid;
-   device->kind            = LIBXL__DEVICE_KIND_9PFS;
-
-   return 0;
-}
-
-static LIBXL_DEFINE_UPDATE_DEVID(p9)
-
 static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t domid,
                                   libxl_device_p9 *p9,
                                   flexarray_t *back, flexarray_t *front,
@@ -56,6 +40,9 @@ static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t 
domid,
 #define libxl_device_p9_list NULL
 #define libxl_device_p9_compare NULL
 
+static LIBXL_DEFINE_UPDATE_DEVID(p9)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(p9)
+
 LIBXL_DEFINE_DEVICE_REMOVE(p9)
 
 DEFINE_DEVICE_TYPE_STRUCT(p9, 9PFS,
diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c
index 002bcae..329db6c 100644
--- a/tools/libxl/libxl_console.c
+++ b/tools/libxl/libxl_console.c
@@ -613,19 +613,6 @@ static int libxl__device_vfb_setdefault(libxl__gc *gc, 
uint32_t domid,
     return rc;
 }
 
-static int libxl__device_from_vfb(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_vfb *vfb,
-                                  libxl__device *device)
-{
-    device->backend_devid = vfb->devid;
-    device->backend_domid = vfb->backend_domid;
-    device->backend_kind = LIBXL__DEVICE_KIND_VFB;
-    device->devid = vfb->devid;
-    device->domid = domid;
-    device->kind = LIBXL__DEVICE_KIND_VFB;
-    return 0;
-}
-
 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
                          const libxl_asyncop_how *ao_how)
 {
@@ -643,8 +630,6 @@ out:
     return AO_INPROGRESS;
 }
 
-static LIBXL_DEFINE_UPDATE_DEVID(vfb)
-
 static int libxl__set_xenstore_vfb(libxl__gc *gc, uint32_t domid,
                                    libxl_device_vfb *vfb,
                                   flexarray_t *back, flexarray_t *front,
@@ -685,6 +670,9 @@ static int libxl__set_xenstore_vfb(libxl__gc *gc, uint32_t 
domid,
 #define libxl_device_vfb_list NULL
 #define libxl_device_vfb_compare NULL
 
+static LIBXL_DEFINE_UPDATE_DEVID(vfb)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vfb)
+
 /* vfb */
 LIBXL_DEFINE_DEVICE_REMOVE(vfb)
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index ef9e781..d1a8d8e 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3455,6 +3455,21 @@ _hidden void libxl__bootloader_run(libxl__egc*, 
libxl__bootloader_state *st);
         return 0;                                                       \
     }
 
+#define LIBXL_DEFINE_DEVICE_FROM_TYPE(name)                             \
+    int libxl__device_from_##name(libxl__gc *gc, uint32_t domid,        \
+                                  libxl_device_##name *type,            \
+                                  libxl__device *device)                \
+    {                                                                   \
+        device->backend_devid   = type->devid;                          \
+        device->backend_domid   = type->backend_domid;                  \
+        device->backend_kind    = libxl__##name##_devtype.type;         \
+        device->devid           = type->devid;                          \
+        device->domid           = domid;                                \
+        device->kind            = libxl__##name##_devtype.type;         \
+                                                                        \
+        return 0;                                                       \
+    }
+
 #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 fb5ae44..2d01803 100644
--- a/tools/libxl/libxl_nic.c
+++ b/tools/libxl/libxl_nic.c
@@ -117,20 +117,6 @@ static int libxl__device_nic_setdefault(libxl__gc *gc, 
uint32_t domid,
     return rc;
 }
 
-static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_nic *nic,
-                                  libxl__device *device)
-{
-    device->backend_devid    = nic->devid;
-    device->backend_domid    = nic->backend_domid;
-    device->backend_kind     = LIBXL__DEVICE_KIND_VIF;
-    device->devid            = nic->devid;
-    device->domid            = domid;
-    device->kind             = LIBXL__DEVICE_KIND_VIF;
-
-    return 0;
-}
-
 static void libxl__update_config_nic(libxl__gc *gc, libxl_device_nic *dst,
                                      const libxl_device_nic *src)
 {
@@ -139,8 +125,6 @@ static void libxl__update_config_nic(libxl__gc *gc, 
libxl_device_nic *dst,
     libxl_mac_copy(CTX, &dst->mac, &src->mac);
 }
 
-static LIBXL_DEFINE_UPDATE_DEVID(nic)
-
 static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
                                    libxl_device_nic *nic,
                                    flexarray_t *back, flexarray_t *front,
@@ -542,6 +526,9 @@ out:
     return ret;
 }
 
+static LIBXL_DEFINE_UPDATE_DEVID(nic)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(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 f2d1444..0d87500 100644
--- a/tools/libxl/libxl_vdispl.c
+++ b/tools/libxl/libxl_vdispl.c
@@ -22,20 +22,6 @@ static int libxl__device_vdispl_setdefault(libxl__gc *gc, 
uint32_t domid,
                                 &vdispl->backend_domid);
 }
 
-static int libxl__device_from_vdispl(libxl__gc *gc, uint32_t domid,
-                                     libxl_device_vdispl *vdispl,
-                                     libxl__device *device)
-{
-   device->backend_devid   = vdispl->devid;
-   device->backend_domid   = vdispl->backend_domid;
-   device->backend_kind    = LIBXL__DEVICE_KIND_VDISPL;
-   device->devid           = vdispl->devid;
-   device->domid           = domid;
-   device->kind            = LIBXL__DEVICE_KIND_VDISPL;
-
-   return 0;
-}
-
 static int libxl__vdispl_from_xenstore(libxl__gc *gc, const char *libxl_path,
                                        libxl_devid devid,
                                        libxl_device_vdispl *vdispl)
@@ -246,10 +232,12 @@ out:
     return rc;
 }
 
-LIBXL_DEFINE_DEVICE_ADD(vdispl)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vdispl)
+static LIBXL_DEFINE_UPDATE_DEVID(vdispl)
 static LIBXL_DEFINE_DEVICES_ADD(vdispl)
+
+LIBXL_DEFINE_DEVICE_ADD(vdispl)
 LIBXL_DEFINE_DEVICE_REMOVE(vdispl)
-static LIBXL_DEFINE_UPDATE_DEVID(vdispl)
 LIBXL_DEFINE_DEVICE_LIST(vdispl)
 
 DEFINE_DEVICE_TYPE_STRUCT(vdispl, VDISPL,
diff --git a/tools/libxl/libxl_vkb.c b/tools/libxl/libxl_vkb.c
index 13aa01f..6ee0a7e 100644
--- a/tools/libxl/libxl_vkb.c
+++ b/tools/libxl/libxl_vkb.c
@@ -21,20 +21,6 @@ static int libxl__device_vkb_setdefault(libxl__gc *gc, 
uint32_t domid,
     return libxl__resolve_domid(gc, vkb->backend_domname, &vkb->backend_domid);
 }
 
-static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_vkb *vkb,
-                                  libxl__device *device)
-{
-    device->backend_devid = vkb->devid;
-    device->backend_domid = vkb->backend_domid;
-    device->backend_kind = LIBXL__DEVICE_KIND_VKBD;
-    device->devid = vkb->devid;
-    device->domid = domid;
-    device->kind = LIBXL__DEVICE_KIND_VKBD;
-
-    return 0;
-}
-
 static int libxl__device_vkb_dm_needed(libxl_device_vkb *vkb, uint32_t domid)
 {
    if (vkb->backend_type == LIBXL_VKB_BACKEND_QEMU)
@@ -161,6 +147,7 @@ out:
 }
 
 static LIBXL_DEFINE_UPDATE_DEVID(vkb)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vkb)
 
 #define libxl__add_vkbs NULL
 #define libxl_device_vkb_compare NULL
diff --git a/tools/libxl/libxl_vsnd.c b/tools/libxl/libxl_vsnd.c
index 8dfda46..8cc3a4b 100644
--- a/tools/libxl/libxl_vsnd.c
+++ b/tools/libxl/libxl_vsnd.c
@@ -23,20 +23,6 @@ static int libxl__device_vsnd_setdefault(libxl__gc *gc, 
uint32_t domid,
                                 &vsnd->backend_domid);
 }
 
-static int libxl__device_from_vsnd(libxl__gc *gc, uint32_t domid,
-                                   libxl_device_vsnd *vsnd,
-                                   libxl__device *device)
-{
-   device->backend_devid   = vsnd->devid;
-   device->backend_domid   = vsnd->backend_domid;
-   device->backend_kind    = LIBXL__DEVICE_KIND_VSND;
-   device->devid           = vsnd->devid;
-   device->domid           = domid;
-   device->kind            = LIBXL__DEVICE_KIND_VSND;
-
-   return 0;
-}
-
 static int libxl__sample_rates_from_string(libxl__gc *gc, const char *str,
                                            libxl_vsnd_params *params)
 {
@@ -641,10 +627,13 @@ out:
     return rc;
 }
 
-LIBXL_DEFINE_DEVICE_ADD(vsnd)
+
+static LIBXL_DEFINE_UPDATE_DEVID(vsnd)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vsnd)
 static LIBXL_DEFINE_DEVICES_ADD(vsnd)
+
+LIBXL_DEFINE_DEVICE_ADD(vsnd)
 LIBXL_DEFINE_DEVICE_REMOVE(vsnd)
-static LIBXL_DEFINE_UPDATE_DEVID(vsnd)
 LIBXL_DEFINE_DEVICE_LIST(vsnd)
 
 DEFINE_DEVICE_TYPE_STRUCT(vsnd, VSND,
diff --git a/tools/libxl/libxl_vtpm.c b/tools/libxl/libxl_vtpm.c
index f9ba481..3a9e972 100644
--- a/tools/libxl/libxl_vtpm.c
+++ b/tools/libxl/libxl_vtpm.c
@@ -28,20 +28,6 @@ static int libxl__device_vtpm_setdefault(libxl__gc *gc, 
uint32_t domid,
     return rc;
 }
 
-static int libxl__device_from_vtpm(libxl__gc *gc, uint32_t domid,
-                                   libxl_device_vtpm *vtpm,
-                                   libxl__device *device)
-{
-   device->backend_devid   = vtpm->devid;
-   device->backend_domid   = vtpm->backend_domid;
-   device->backend_kind    = LIBXL__DEVICE_KIND_VTPM;
-   device->devid           = vtpm->devid;
-   device->domid           = domid;
-   device->kind            = LIBXL__DEVICE_KIND_VTPM;
-
-   return 0;
-}
-
 static void libxl__update_config_vtpm(libxl__gc *gc, libxl_device_vtpm *dst,
                                       libxl_device_vtpm *src)
 {
@@ -49,8 +35,6 @@ static void libxl__update_config_vtpm(libxl__gc *gc, 
libxl_device_vtpm *dst,
     libxl_uuid_copy(CTX, &dst->uuid, &src->uuid);
 }
 
-static LIBXL_DEFINE_UPDATE_DEVID(vtpm)
-
 static int libxl__set_xenstore_vtpm(libxl__gc *gc, uint32_t domid,
                                     libxl_device_vtpm *vtpm,
                                     flexarray_t *back, flexarray_t *front,
@@ -243,8 +227,11 @@ static void libxl_device_vtpm_update_config(libxl__gc *gc, 
void *d, void *s)
     libxl__update_config_vtpm(gc, d, s);
 }
 
-LIBXL_DEFINE_DEVICE_ADD(vtpm)
+static LIBXL_DEFINE_UPDATE_DEVID(vtpm)
+static LIBXL_DEFINE_DEVICE_FROM_TYPE(vtpm)
 static LIBXL_DEFINE_DEVICES_ADD(vtpm)
+
+LIBXL_DEFINE_DEVICE_ADD(vtpm)
 LIBXL_DEFINE_DEVICE_REMOVE(vtpm)
 LIBXL_DEFINE_DEVICE_LIST(vtpm)
 
-- 
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®.