@@ -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,
@@ -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)
@@ -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)
@@ -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)
@@ -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,
@@ -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
@@ -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,
@@ -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)