Skip to contentSkip to conversation

Some cleanup of device_add_domain_config

PATCH In review Anthony PERARD 2 participants 7 messages Apr 5, 2019 – Apr 9, 2019

lore
Share & tools
lore
#0 lore raw

cover Some cleanup of device_add_domain_config

Documentation of device_add_domain_config and constify `src'.

Anthony PERARD (3):
libxl: Constify libxl_device_*_compare functions
libxl: Constify src of device_compare_fn_t
libxl: Document device_add_domain_config

 tools/libxl/libxl_device.c   |  6 +++---
 tools/libxl/libxl_disk.c     |  4 ++--
 tools/libxl/libxl_internal.h | 19 ++++++++++++++++---
 tools/libxl/libxl_nic.c      |  4 ++--
 tools/libxl/libxl_pci.c      |  4 ++--
 tools/libxl/libxl_usb.c      |  8 ++++----
 tools/libxl/libxl_vdispl.c   |  4 ++--
 tools/libxl/libxl_vsnd.c     |  4 ++--
 tools/libxl/libxl_vtpm.c     |  4 ++--
 9 files changed, 35 insertions(+), 22 deletions(-)
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/3 libxl: Constify libxl_device_*_compare functions

---
 tools/libxl/libxl_disk.c     | 4 ++--
 tools/libxl/libxl_internal.h | 2 +-
 tools/libxl/libxl_nic.c      | 4 ++--
 tools/libxl/libxl_pci.c      | 4 ++--
 tools/libxl/libxl_usb.c      | 8 ++++----
 tools/libxl/libxl_vdispl.c   | 4 ++--
 tools/libxl/libxl_vsnd.c     | 4 ++--
 tools/libxl/libxl_vtpm.c     | 4 ++--
 8 files changed, 17 insertions(+), 17 deletions(-)
tools/libxl/libxl_disk.c +2 -2
index e9eceb65e3..79e30f8d52 100644
@@ -1126,8 +1126,8 @@ LIBXL_DEFINE_DEVICE_ADD(disk)
 LIBXL_DEFINE_DEVICES_ADD(disk)
 LIBXL_DEFINE_DEVICE_REMOVE(disk)
 
-static int libxl_device_disk_compare(libxl_device_disk *d1,
-                                     libxl_device_disk *d2)
+static int libxl_device_disk_compare(const libxl_device_disk *d1,
+                                     const libxl_device_disk *d2)
 {
     return COMPARE_DISK(d1, d2);
 }
tools/libxl/libxl_internal.h +1 -1
index 459f9bffa8..c75c98156a 100644
@@ -3728,7 +3728,7 @@ typedef int (*device_to_device_fn_t)(libxl__gc *, uint32_t, void *,
 typedef void (*device_init_fn_t)(void *);
 typedef void (*device_copy_fn_t)(libxl_ctx *, void *, void *);
 typedef void (*device_dispose_fn_t)(void *);
-typedef int (*device_compare_fn_t)(void *, void *);
+typedef int (*device_compare_fn_t)(const void *, const void *);
 typedef void (*device_merge_fn_t)(libxl_ctx *, void *, void *);
 typedef int (*device_dm_needed_fn_t)(void *, unsigned);
 typedef void (*device_update_config_fn_t)(libxl__gc *, void *, void *);
tools/libxl/libxl_nic.c +2 -2
index 01b711b84e..f2b5e02285 100644
@@ -454,8 +454,8 @@ const char *libxl__device_nic_devname(libxl__gc *gc,
     }
 }
 
-static int libxl_device_nic_compare(libxl_device_nic *d1,
-                                    libxl_device_nic *d2)
+static int libxl_device_nic_compare(const libxl_device_nic *d1,
+                                    const libxl_device_nic *d2)
 {
     return COMPARE_DEVID(d1, d2);
 }
tools/libxl/libxl_pci.c +2 -2
index 87afa03d9e..4ec6872798 100644
@@ -1679,8 +1679,8 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,
     return 0;
 }
 
-static int libxl_device_pci_compare(libxl_device_pci *d1,
-                                    libxl_device_pci *d2)
+static int libxl_device_pci_compare(const libxl_device_pci *d1,
+                                    const libxl_device_pci *d2)
 {
     return COMPARE_PCI(d1, d2);
 }
tools/libxl/libxl_usb.c +4 -4
index 67d2fb4e37..adb122ac85 100644
@@ -1925,8 +1925,8 @@ int libxl_ctrlport_to_device_usbdev(libxl_ctx *ctx,
     return rc;
 }
 
-static int libxl_device_usbctrl_compare(libxl_device_usbctrl *d1,
-                                        libxl_device_usbctrl *d2)
+static int libxl_device_usbctrl_compare(const libxl_device_usbctrl *d1,
+                                        const libxl_device_usbctrl *d2)
 {
     return COMPARE_USBCTRL(d1, d2);
 }
@@ -1939,8 +1939,8 @@ static int libxl_device_usbctrl_dm_needed(void *e, unsigned domid)
            elem->backend_domid == domid;
 }
 
-static int libxl_device_usbdev_compare(libxl_device_usbdev *d1,
-                                       libxl_device_usbdev *d2)
+static int libxl_device_usbdev_compare(const libxl_device_usbdev *d1,
+                                       const libxl_device_usbdev *d2)
 {
     return COMPARE_USB(d1, d2);
 }
tools/libxl/libxl_vdispl.c +2 -2
index 351f6beccb..c9cc455176 100644
@@ -48,8 +48,8 @@ static void libxl__update_config_vdispl(libxl__gc *gc,
     dst->be_alloc = src->be_alloc;
 }
 
-static int libxl_device_vdispl_compare(libxl_device_vdispl *d1,
-                                       libxl_device_vdispl *d2)
+static int libxl_device_vdispl_compare(const libxl_device_vdispl *d1,
+                                       const libxl_device_vdispl *d2)
 {
     return COMPARE_DEVID(d1, d2);
 }
tools/libxl/libxl_vsnd.c +2 -2
index 9570a4cf0e..1151cbc567 100644
@@ -290,8 +290,8 @@ static void libxl__update_config_vsnd(libxl__gc *gc,
     dst->devid = src->devid;
 }
 
-static int libxl_device_vsnd_compare(libxl_device_vsnd *d1,
-                                     libxl_device_vsnd *d2)
+static int libxl_device_vsnd_compare(const libxl_device_vsnd *d1,
+                                     const libxl_device_vsnd *d2)
 {
     return COMPARE_DEVID(d1, d2);
 }
tools/libxl/libxl_vtpm.c +2 -2
index 7c91f99673..f750395f6f 100644
@@ -183,8 +183,8 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx,
     return rc;
 }
 
-static int libxl_device_vtpm_compare(libxl_device_vtpm *d1,
-                                     libxl_device_vtpm *d2)
+static int libxl_device_vtpm_compare(const libxl_device_vtpm *d1,
+                                     const libxl_device_vtpm *d2)
 {
     return COMPARE_DEVID(d1, d2);
 }
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH 2/3 libxl: Constify src of device_compare_fn_t

In reply to Anthony PERARD

All functions libxl_device_*_copy which implements device_compare_fn_t already have the `src' parameter defined with const.

---
 tools/libxl/libxl_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_internal.h +1 -1
index c75c98156a..34dc886505 100644
@@ -3726,7 +3726,7 @@ typedef int (*device_set_default_fn_t)(libxl__gc *, uint32_t, void *, bool);
 typedef int (*device_to_device_fn_t)(libxl__gc *, uint32_t, void *,
                                      libxl__device *);
 typedef void (*device_init_fn_t)(void *);
-typedef void (*device_copy_fn_t)(libxl_ctx *, void *, void *);
+typedef void (*device_copy_fn_t)(libxl_ctx *, void *dst, const void *src);
 typedef void (*device_dispose_fn_t)(void *);
 typedef int (*device_compare_fn_t)(const void *, const void *);
 typedef void (*device_merge_fn_t)(libxl_ctx *, void *, void *);
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] libxl: Constify src of device_compare_fn_t

Quoted 4 lines · Anthony PERARD

All functions libxl_device_*_copy which implements device_compare_fn_t already have the `src' parameter defined with const.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

PATCH 3/3 libxl: Document device_add_domain_config

In reply to Anthony PERARD

Commit 03e1a56d81c16eece735e4d0ef74bfb10eaaba07 replaced DEVICE_ADD() calls by device_add_domain_config() calls but also removed the comment of DEVICE_ADD(). Copy the useful part of that comment to device_add_domain_config().

Also, rename the parameter type to dev, because that parameter isn't used as a type but as the device we want to add/update to d_config.

Also, constify dev because it isn't modified.

---
 tools/libxl/libxl_device.c   |  6 +++---
 tools/libxl/libxl_internal.h | 15 ++++++++++++++-
 2 files changed, 17 insertions(+), 4 deletions(-)
tools/libxl/libxl_device.c +3 -3
index a4a8e9ac32..87ddfc3ac7 100644
@@ -1852,7 +1852,7 @@ int libxl_device_events_handler(libxl_ctx *ctx,
 }
 
 void device_add_domain_config(libxl__gc *gc, libxl_domain_config *d_config,
-                              const struct libxl_device_type *dt, void *type)
+                              const struct libxl_device_type *dt, const void *dev)
 {
     int *num_dev;
     unsigned int i;
@@ -1862,7 +1862,7 @@ void device_add_domain_config(libxl__gc *gc, libxl_domain_config *d_config,
 
     /* Check for existing device */
     for (i = 0; i < *num_dev; i++) {
-        if (dt->compare(libxl__device_type_get_elem(dt, d_config, i), type)) {
+        if (dt->compare(libxl__device_type_get_elem(dt, d_config, i), dev)) {
             item = libxl__device_type_get_elem(dt, d_config, i);
         }
     }
@@ -1878,7 +1878,7 @@ void device_add_domain_config(libxl__gc *gc, libxl_domain_config *d_config,
     }
 
     dt->init(item);
-    dt->copy(CTX, item, type);
+    dt->copy(CTX, item, dev);
 }
 
 void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
tools/libxl/libxl_internal.h +14 -1
index 34dc886505..44e0221284 100644
@@ -4581,8 +4581,21 @@ static inline bool libxl__acpi_defbool_val(const libxl_domain_build_info *b_info
            libxl_defbool_val(b_info->u.hvm.acpi);
 }
 
+/*
+ * Add a device in libxl_domain_config structure
+ *
+ * If there is already a device with the same identifier in d_config,
+ * that entry is updated.
+ *
+ * parameters:
+ *  d_config: pointer to template domain config
+ *  dt:       type of `dev'
+ *  dev:      the device that is to be added / removed / updated
+ *            (a copy of `dev' will be made)
+ */
 void device_add_domain_config(libxl__gc *gc, libxl_domain_config *d_config,
-                              const struct libxl_device_type *dt, void *type);
+                              const struct libxl_device_type *dt,
+                              const void *dev);
 
 void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
                              const struct libxl_device_type *dt, void *type,
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] libxl: Document device_add_domain_config

Quoted 11 lines · Anthony PERARD

Commit 03e1a56d81c16eece735e4d0ef74bfb10eaaba07 replaced DEVICE_ADD() calls by device_add_domain_config() calls but also removed the comment of DEVICE_ADD(). Copy the useful part of that comment to device_add_domain_config().

Also, rename the parameter type to dev, because that parameter isn't used as a type but as the device we want to add/update to d_config.

Also, constify dev because it isn't modified.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel