xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xen.org
Cc: Juergen Gross <jgross@suse.com>,
	wei.liu2@citrix.com, ian.jackson@eu.citrix.com
Subject: [PATCH v2 4/4] libxl: move DEFINE_DEVICE* macros to libxl_internal.h
Date: Wed,  6 Jul 2016 16:55:34 +0200	[thread overview]
Message-ID: <1467816934-7183-5-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1467816934-7183-1-git-send-email-jgross@suse.com>

In order to be able to have all functions related to a device type in
a single source file move the macros used to generate device type
specific functions to libxl_internal.h. Rename the macros as they are
no longer local to a source file. While at it hide device remove and
device destroy in one macro as those are always used in pairs. Move
usage of the macros to the appropriate source files.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/libxl/libxl.c          | 143 +++++++++----------------------------------
 tools/libxl/libxl_device.c   |  36 -----------
 tools/libxl/libxl_internal.h | 106 +++++++++++++++++++++-----------
 tools/libxl/libxl_pvusb.c    |  25 +++++---
 4 files changed, 115 insertions(+), 195 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index b3deef0..68b77b9 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1980,7 +1980,7 @@ out:
 /******************************************************************************/
 
 /* generic callback for devices that only need to set ao_complete */
-static void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev)
+void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
 
@@ -2055,9 +2055,9 @@ static int libxl__device_from_vtpm(libxl__gc *gc, uint32_t domid,
    return 0;
 }
 
-void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
-                           libxl_device_vtpm *vtpm,
-                           libxl__ao_device *aodev)
+static void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
+                                   libxl_device_vtpm *vtpm,
+                                   libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
     flexarray_t *front;
@@ -2629,8 +2629,9 @@ out:
     return;
 }
 
-void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
-                           libxl_device_disk *disk, libxl__ao_device *aodev)
+static void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
+                                   libxl_device_disk *disk,
+                                   libxl__ao_device *aodev)
 {
     device_disk_add(egc, domid, disk, aodev, NULL, NULL);
 }
@@ -3432,8 +3433,9 @@ static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
-void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
-                           libxl_device_nic *nic, libxl__ao_device *aodev)
+static void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
+                                  libxl_device_nic *nic,
+                                  libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
     flexarray_t *front;
@@ -4298,136 +4300,49 @@ out:
 
 /******************************************************************************/
 
-/* Macro for defining device remove/destroy functions in a compact way */
 /* The following functions are defined:
+ * libxl_device_disk_add
+ * libxl__add_disks
  * libxl_device_disk_remove
  * libxl_device_disk_destroy
+ * libxl_device_nic_add
+ * libxl__add_nics
  * libxl_device_nic_remove
  * libxl_device_nic_destroy
+ * libxl_device_vtpm_add
+ * libxl__add_vtpms
  * libxl_device_vtpm_remove
  * libxl_device_vtpm_destroy
  * libxl_device_vkb_remove
  * libxl_device_vkb_destroy
  * libxl_device_vfb_remove
  * libxl_device_vfb_destroy
- * libxl_device_usbctrl_remove
- * libxl_device_usbctrl_destroy
  */
-#define DEFINE_DEVICE_REMOVE_EXT(type, remtype, removedestroy, f)        \
-    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \
-        uint32_t domid, libxl_device_##type *type,                      \
-        const libxl_asyncop_how *ao_how)                                \
-    {                                                                   \
-        AO_CREATE(ctx, domid, ao_how);                                  \
-        libxl__device *device;                                          \
-        libxl__ao_device *aodev;                                        \
-        int rc;                                                         \
-                                                                        \
-        GCNEW(device);                                                  \
-        rc = libxl__device_from_##type(gc, domid, type, device);        \
-        if (rc != 0) goto out;                                          \
-                                                                        \
-        GCNEW(aodev);                                                   \
-        libxl__prepare_ao_device(ao, aodev);                            \
-        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
-        aodev->dev = device;                                            \
-        aodev->callback = device_addrm_aocomplete;                      \
-        aodev->force = f;                                               \
-        libxl__initiate_device_##remtype##_remove(egc, aodev);          \
-                                                                        \
-    out:                                                                \
-        if (rc) return AO_CREATE_FAIL(rc);                              \
-        return AO_INPROGRESS;                                           \
-    }
-
-#define DEFINE_DEVICE_REMOVE(type, removedestroy, f) \
-    DEFINE_DEVICE_REMOVE_EXT(type, generic, removedestroy, f)
-
-#define DEFINE_DEVICE_REMOVE_CUSTOM(type, removedestroy, f)  \
-    DEFINE_DEVICE_REMOVE_EXT(type, type, removedestroy, f)
-
-/* Define all remove/destroy functions and undef the macro */
-
-/* disk */
-DEFINE_DEVICE_REMOVE(disk, remove, 0)
-DEFINE_DEVICE_REMOVE(disk, destroy, 1)
-
-/* nic */
-DEFINE_DEVICE_REMOVE(nic, remove, 0)
-DEFINE_DEVICE_REMOVE(nic, destroy, 1)
-
-/* vkb */
-DEFINE_DEVICE_REMOVE(vkb, remove, 0)
-DEFINE_DEVICE_REMOVE(vkb, destroy, 1)
-
-/* vfb */
-
-DEFINE_DEVICE_REMOVE(vfb, remove, 0)
-DEFINE_DEVICE_REMOVE(vfb, destroy, 1)
-
-/* vtpm */
-DEFINE_DEVICE_REMOVE(vtpm, remove, 0)
-DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
-
-/* usbctrl */
-DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, remove, 0)
-DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, destroy, 1)
 
 /* channel/console hotunplug is not implemented. There are 2 possibilities:
  * 1. add support for secondary consoles to xenconsoled
  * 2. dynamically add/remove qemu chardevs via qmp messages. */
 
-#undef DEFINE_DEVICE_REMOVE
-#undef DEFINE_DEVICE_REMOVE_CUSTOM
-#undef DEFINE_DEVICE_REMOVE_EXT
-
-/******************************************************************************/
-
-/* Macro for defining device addition functions in a compact way */
-/* The following functions are defined:
- * libxl_device_disk_add
- * libxl_device_nic_add
- * libxl_device_vtpm_add
- * libxl_device_usbctrl_add
- * libxl_device_usbdev_add
- */
-
-#define DEFINE_DEVICE_ADD(type)                                         \
-    int libxl_device_##type##_add(libxl_ctx *ctx,                       \
-        uint32_t domid, libxl_device_##type *type,                      \
-        const libxl_asyncop_how *ao_how)                                \
-    {                                                                   \
-        AO_CREATE(ctx, domid, ao_how);                                  \
-        libxl__ao_device *aodev;                                        \
-                                                                        \
-        GCNEW(aodev);                                                   \
-        libxl__prepare_ao_device(ao, aodev);                            \
-        aodev->action = LIBXL__DEVICE_ACTION_ADD;                       \
-        aodev->callback = device_addrm_aocomplete;                      \
-        aodev->update_json = true;                                      \
-        libxl__device_##type##_add(egc, domid, type, aodev);            \
-                                                                        \
-        return AO_INPROGRESS;                                           \
-    }
-
-/* Define alladd functions and undef the macro */
-
 /* disk */
-DEFINE_DEVICE_ADD(disk)
+LIBXL_DEFINE_DEVICE_ADD(disk)
+LIBXL_DEFINE_DEVICES_ADD(disk)
+LIBXL_DEFINE_DEVICE_REMOVE(disk)
 
 /* nic */
-DEFINE_DEVICE_ADD(nic)
+LIBXL_DEFINE_DEVICE_ADD(nic)
+LIBXL_DEFINE_DEVICES_ADD(nic)
+LIBXL_DEFINE_DEVICE_REMOVE(nic)
 
 /* vtpm */
-DEFINE_DEVICE_ADD(vtpm)
+LIBXL_DEFINE_DEVICE_ADD(vtpm)
+static LIBXL_DEFINE_DEVICES_ADD(vtpm)
+LIBXL_DEFINE_DEVICE_REMOVE(vtpm)
 
-/* usbctrl */
-DEFINE_DEVICE_ADD(usbctrl)
+/* vkb */
+LIBXL_DEFINE_DEVICE_REMOVE(vkb)
 
-/* usb */
-DEFINE_DEVICE_ADD(usbdev)
-
-#undef DEFINE_DEVICE_ADD
+/* vfb */
+LIBXL_DEFINE_DEVICE_REMOVE(vfb)
 
 /******************************************************************************/
 
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 4717027..200bfad 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -677,42 +677,6 @@ void libxl__multidev_prepared(libxl__egc *egc,
 
 /******************************************************************************/
 
-/* Macro for defining the functions that will add a bunch of disks when
- * inside an async op with multidev.
- * This macro is added to prevent repetition of code.
- *
- * The following functions are defined:
- * libxl__add_disks
- * libxl__add_nics
- * libxl__add_vtpms
- * libxl__add_usbctrls
- * libxl__add_usbs
- */
-
-#define DEFINE_DEVICES_ADD(type)                                        \
-    void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \
-                              libxl_domain_config *d_config,            \
-                              libxl__multidev *multidev)                \
-    {                                                                   \
-        AO_GC;                                                          \
-        int i;                                                          \
-        for (i = 0; i < d_config->num_##type##s; i++) {                 \
-            libxl__ao_device *aodev = libxl__multidev_prepare(multidev);  \
-            libxl__device_##type##_add(egc, domid, &d_config->type##s[i], \
-                                       aodev);                          \
-        }                                                               \
-    }
-
-DEFINE_DEVICES_ADD(disk)
-DEFINE_DEVICES_ADD(nic)
-DEFINE_DEVICES_ADD(vtpm)
-DEFINE_DEVICES_ADD(usbctrl)
-DEFINE_DEVICES_ADD(usbdev)
-
-#undef DEFINE_DEVICES_ADD
-
-/******************************************************************************/
-
 int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
 {
     const char *be_path = libxl__device_backend_path(gc, dev);
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 79ce392..00b1f0c 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2379,6 +2379,9 @@ typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
  */
 _hidden void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev);
 
+/* generic callback for devices that only need to set ao_complete */
+_hidden void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev);
+
 struct libxl__ao_device {
     /* filled in by user */
     libxl__ao *ao;
@@ -2621,26 +2624,6 @@ struct libxl__multidev {
  * xenstore entry afterwards. We have both JSON and xenstore entry,
  * it's a valid state.
  */
-_hidden void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
-                                    libxl_device_disk *disk,
-                                    libxl__ao_device *aodev);
-
-/* AO operation to connect a nic device */
-_hidden void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
-                                   libxl_device_nic *nic,
-                                   libxl__ao_device *aodev);
-
-_hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
-                                   libxl_device_vtpm *vtpm,
-                                   libxl__ao_device *aodev);
-
-_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
-                                       libxl_device_usbctrl *usbctrl,
-                                       libxl__ao_device *aodev);
-
-_hidden void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid,
-                                      libxl_device_usbdev *usbdev,
-                                      libxl__ao_device *aodev);
 
 /* Internal function to connect a vkb device */
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
@@ -2674,10 +2657,6 @@ _hidden void libxl__wait_device_connection(libxl__egc*,
 _hidden void libxl__initiate_device_generic_remove(libxl__egc *egc,
                                                    libxl__ao_device *aodev);
 
-_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,
-                               libxl_device_usbctrl *usbctrl,
-                               libxl__device *device);
-
 _hidden void libxl__initiate_device_usbctrl_remove(libxl__egc *egc,
                                                    libxl__ao_device *aodev);
 
@@ -3390,6 +3369,73 @@ _hidden void libxl__bootloader_init(libxl__bootloader_state *bl);
 _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st);
 
 /*----- Generic Device Handling -----*/
+#define LIBXL_DEFINE_DEVICE_ADD(type)                                   \
+    int libxl_device_##type##_add(libxl_ctx *ctx,                       \
+        uint32_t domid, libxl_device_##type *type,                      \
+        const libxl_asyncop_how *ao_how)                                \
+    {                                                                   \
+        AO_CREATE(ctx, domid, ao_how);                                  \
+        libxl__ao_device *aodev;                                        \
+                                                                        \
+        GCNEW(aodev);                                                   \
+        libxl__prepare_ao_device(ao, aodev);                            \
+        aodev->action = LIBXL__DEVICE_ACTION_ADD;                       \
+        aodev->callback = device_addrm_aocomplete;                      \
+        aodev->update_json = true;                                      \
+        libxl__device_##type##_add(egc, domid, type, aodev);            \
+                                                                        \
+        return AO_INPROGRESS;                                           \
+    }
+
+#define LIBXL_DEFINE_DEVICES_ADD(type)                                  \
+    void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \
+                              libxl_domain_config *d_config,            \
+                              libxl__multidev *multidev)                \
+    {                                                                   \
+        AO_GC;                                                          \
+        int i;                                                          \
+        for (i = 0; i < d_config->num_##type##s; i++) {                 \
+            libxl__ao_device *aodev = libxl__multidev_prepare(multidev);  \
+            libxl__device_##type##_add(egc, domid, &d_config->type##s[i], \
+                                       aodev);                          \
+        }                                                               \
+    }
+
+#define LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, remtype, removedestroy, f) \
+    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \
+        uint32_t domid, libxl_device_##type *type,                      \
+        const libxl_asyncop_how *ao_how)                                \
+    {                                                                   \
+        AO_CREATE(ctx, domid, ao_how);                                  \
+        libxl__device *device;                                          \
+        libxl__ao_device *aodev;                                        \
+        int rc;                                                         \
+                                                                        \
+        GCNEW(device);                                                  \
+        rc = libxl__device_from_##type(gc, domid, type, device);        \
+        if (rc != 0) goto out;                                          \
+                                                                        \
+        GCNEW(aodev);                                                   \
+        libxl__prepare_ao_device(ao, aodev);                            \
+        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
+        aodev->dev = device;                                            \
+        aodev->callback = device_addrm_aocomplete;                      \
+        aodev->force = f;                                               \
+        libxl__initiate_device_##remtype##_remove(egc, aodev);          \
+                                                                        \
+    out:                                                                \
+        if (rc) return AO_CREATE_FAIL(rc);                              \
+        return AO_INPROGRESS;                                           \
+    }
+
+#define LIBXL_DEFINE_DEVICE_REMOVE(type)                                \
+    LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, remove, 0)            \
+    LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, destroy, 1)
+
+#define LIBXL_DEFINE_DEVICE_REMOVE_CUSTOM(type)                         \
+    LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, type, remove, 0)               \
+    LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, type, destroy, 1)
+
 struct libxl_device_type {
     char *type;
     int num_offset;   /* Offset of # of devices in libxl_domain_config */
@@ -3508,18 +3554,6 @@ _hidden void libxl__add_nics(libxl__egc *egc, libxl__ao *ao, uint32_t domid,
                              libxl_domain_config *d_config,
                              libxl__multidev *multidev);
 
-_hidden void libxl__add_vtpms(libxl__egc *egc, libxl__ao *ao, uint32_t domid,
-                             libxl_domain_config *d_config,
-                             libxl__multidev *multidev);
-
-_hidden void libxl__add_usbctrls(libxl__egc *egc, libxl__ao *ao,
-                                 uint32_t domid, libxl_domain_config *d_config,
-                                 libxl__multidev *multidev);
-
-_hidden void libxl__add_usbdevs(libxl__egc *egc, libxl__ao *ao,
-                                uint32_t domid, libxl_domain_config *d_config,
-                                libxl__multidev *multidev);
-
 /*----- device model creation -----*/
 
 /* First layer; wraps libxl__spawn_spawn. */
diff --git a/tools/libxl/libxl_pvusb.c b/tools/libxl/libxl_pvusb.c
index 5edd206..41ea6bc 100644
--- a/tools/libxl/libxl_pvusb.c
+++ b/tools/libxl/libxl_pvusb.c
@@ -69,9 +69,9 @@ out:
     return rc;
 }
 
-int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,
-                               libxl_device_usbctrl *usbctrl,
-                               libxl__device *device)
+static int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,
+                                      libxl_device_usbctrl *usbctrl,
+                                      libxl__device *device)
 {
     device->backend_devid   = usbctrl->devid;
     device->backend_domid   = usbctrl->backend_domid;
@@ -218,9 +218,9 @@ static char *pvusb_get_device_type(libxl_usbctrl_type type)
  * Before calling this function, aodev should be properly filled:
  * aodev->ao, aodev->callback, aodev->update_json, ...
  */
-void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
-                               libxl_device_usbctrl *usbctrl,
-                               libxl__ao_device *aodev)
+static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
+                                      libxl_device_usbctrl *usbctrl,
+                                      libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
     libxl__device *device;
@@ -263,6 +263,10 @@ out:
     return;
 }
 
+LIBXL_DEFINE_DEVICE_ADD(usbctrl)
+static LIBXL_DEFINE_DEVICES_ADD(usbctrl)
+LIBXL_DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl)
+
 static int libxl__device_usbdev_list_for_usbctrl(libxl__gc *gc, uint32_t domid,
                                                  libxl_devid usbctrl,
                                                  libxl_device_usbdev **usbdevs,
@@ -1423,9 +1427,9 @@ out:
  * Before calling this function, aodev should be properly filled:
  * aodev->ao, aodev->callback, aodev->update_json, ...
  */
-void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid,
-                              libxl_device_usbdev *usbdev,
-                              libxl__ao_device *aodev)
+static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid,
+                                     libxl_device_usbdev *usbdev,
+                                     libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
     int rc;
@@ -1491,6 +1495,9 @@ out:
     return;
 }
 
+LIBXL_DEFINE_DEVICE_ADD(usbdev)
+static LIBXL_DEFINE_DEVICES_ADD(usbdev)
+
 static int do_usbdev_remove(libxl__gc *gc, uint32_t domid,
                             libxl_device_usbdev *usbdev)
 {
-- 
2.6.6


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

  parent reply	other threads:[~2016-07-06 14:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06 14:55 [PATCH v2 0/4] libxl: add framework for device types Juergen Gross
2016-07-06 14:55 ` [PATCH v2 1/4] " Juergen Gross
2016-07-08 17:52   ` Ian Jackson
2016-07-06 14:55 ` [PATCH v2 2/4] libxl: refactor domcreate_attach_pci() to use device type framework Juergen Gross
2016-07-08 17:52   ` Ian Jackson
2016-07-06 14:55 ` [PATCH v2 3/4] libxl: refactor domcreate_attach_dtdev() " Juergen Gross
2016-07-08 17:53   ` Ian Jackson
2016-07-06 14:55 ` Juergen Gross [this message]
2016-07-08 17:53   ` [PATCH v2 4/4] libxl: move DEFINE_DEVICE* macros to libxl_internal.h Ian Jackson
2016-07-08 17:54 ` [PATCH v2 0/4] libxl: add framework for device types Ian Jackson
2016-07-11 10:47   ` Wei Liu
2016-07-12 13:40   ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467816934-7183-5-git-send-email-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).