Skip to contentSkip to conversation

libxl: add PV display device driver interface

PATCH Superseded Oleksandr Grytsov 4 participants 56 messages Jul 18, 2017 – Sep 7, 2017

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover libxl: add PV display device driver interface

From: Oleksandr Grytsov <[email protected]>

Changes since V3:
* libxl__device_add renamed to libxl__device_add_async and reworked

    to match the former design;
  * libxl__device_add used for devices which don't require updating domain
    config but simple write to Xen Store (9pfs, vkb, vfb);

* following devices are changed to use the libxl__device_add:
9pfs, vkb, vfb, nic, vtpm. Other device (console, pci, usb, disk) have very different adding pattern and required to unreasonable extend libxl__device_add_async and its parameters;
* disk device list changed to use libxl__device_list;
* previous comments are applied.

Patches on github [1].

[1] https://github.com/al1img/xen/tree/xl-vdispl-v4

Oleksandr Grytsov (13):
libxl: add generic function to add device
libxl: add generic functions to get and free device list
libxl: add vdispl device
xl: add PV display device commands
docs: add PV display driver information
libxl: change p9 to use generec add function
libxl: change vkb to use generec add function
libxl: change vfb to use generec add function
libxl: change disk to use generic getting list functions
libxl: change nic to use generec add function
libxl: change vtpm to use generec add function
libxl: remove unneeded DEVICE_ADD macro
libxl: make pci and usb setdefault function generic

 docs/man/xl.cfg.pod.5.in              |  49 ++++++
 docs/man/xl.pod.1.in                  |  42 +++++
 tools/libxl/Makefile                  |   2 +-
 tools/libxl/libxl.h                   |  54 +++++--
 tools/libxl/libxl_9pfs.c              |  67 +++-----
 tools/libxl/libxl_checkpoint_device.c |  16 +-
 tools/libxl/libxl_colo_save.c         |   4 +-
 tools/libxl/libxl_console.c           | 153 ++++--------------
 tools/libxl/libxl_create.c            |  17 +-
 tools/libxl/libxl_device.c            | 262 ++++++++++++++++++++++++++++++
 tools/libxl/libxl_disk.c              | 101 ++++--------
 tools/libxl/libxl_dm.c                |  10 +-
 tools/libxl/libxl_internal.h          | 126 ++++++---------
 tools/libxl/libxl_nic.c               | 212 +++++--------------------
 tools/libxl/libxl_pci.c               |  10 +-
 tools/libxl/libxl_types.idl           |  40 ++++-
 tools/libxl/libxl_types_internal.idl  |   1 +
 tools/libxl/libxl_usb.c               |  21 ++-
 tools/libxl/libxl_utils.h             |   4 +
 tools/libxl/libxl_vdispl.c            | 289 ++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_vtpm.c              | 229 ++++++++-------------------
 tools/ocaml/libs/xl/xenlight_stubs.c  |   6 +-
 tools/xl/Makefile                     |   1 +
 tools/xl/xl.h                         |   3 +
 tools/xl/xl_block.c                   |   3 +-
 tools/xl/xl_cmdtable.c                |  19 +++
 tools/xl/xl_nic.c                     |   3 +-
 tools/xl/xl_parse.c                   |  79 +++++++++-
 tools/xl/xl_parse.h                   |   2 +-
 tools/xl/xl_vdispl.c                  | 163 +++++++++++++++++++
 tools/xl/xl_vtpm.c                    |   3 +-
 31 files changed, 1293 insertions(+), 698 deletions(-)
 create mode 100644 tools/libxl/libxl_vdispl.c
 create mode 100644 tools/xl/xl_vdispl.c
Signature · 7 lines
2.7.4


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

PATCH v4 1/13 libxl: add generic function to add device

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_add to simple write XenStore device conifg and libxl__device_add_async to update domain configuration and write XenStore device config asynchroniously. Almost all devices have similar libxl__device_xxxx_add function. This generic functions implement same functionality but using the device handling framework. Th device specific part such as setting xen store configurationis moved to set_xenstore_config callback of the device framework.

---
 tools/libxl/libxl_create.c   |   3 +
 tools/libxl/libxl_device.c   | 198 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_disk.c     |   2 +
 tools/libxl/libxl_internal.h |  36 ++++++++
 tools/libxl/libxl_nic.c      |   2 +
 tools/libxl/libxl_pci.c      |   2 +
 tools/libxl/libxl_usb.c      |   6 ++
 tools/libxl/libxl_vtpm.c     |   2 +
 8 files changed, 251 insertions(+)
tools/libxl/libxl_create.c +3 -0
index bffbc45..b2163cd 100644
@@ -1430,6 +1430,9 @@ out:
 
 #define libxl_device_dtdev_list NULL
 #define libxl_device_dtdev_compare NULL
+#define libxl__device_from_dtdev NULL
+#define libxl__device_dtdev_setdefault NULL
+#define libxl__device_dtdev_update_devid NULL
 static DEFINE_DEVICE_TYPE_STRUCT(dtdev);
 
 const struct libxl_device_type *device_type_tbl[] = {
tools/libxl/libxl_device.c +198 -0

204 lines not on this page · raw message

tools/libxl/libxl_disk.c +2 -0
index 63de75c..f2f3635 100644
@@ -1244,6 +1244,8 @@ static int libxl_device_disk_dm_needed(void *e, unsigned domid)
            elem->backend_domid == domid;
 }
 
+#define libxl__device_disk_update_devid NULL
+
 DEFINE_DEVICE_TYPE_STRUCT(disk,
     .merge       = libxl_device_disk_merge,
     .dm_needed   = libxl_device_disk_dm_needed,
tools/libxl/libxl_internal.h +36 -0
index afe6652..075dfe3 100644
@@ -3467,6 +3467,18 @@ _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st);
         return AO_INPROGRESS;                                           \
     }
 
+#define LIBXL_DEFINE_UPDATE_DEVID(type, name)                           \
+    int libxl__device_##type##_update_devid(libxl__gc *gc,              \
+                                            uint32_t domid,             \
+                                            libxl_device_##type *type)  \
+    {                                                                   \
+        if (type->devid == -1)                                          \
+            type->devid = libxl__device_nextid(gc, domid, name);        \
+        if (type->devid < 0)                                            \
+            return ERROR_FAIL;                                          \
+        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)
@@ -3484,11 +3496,18 @@ struct libxl_device_type {
     void (*add)(libxl__egc *, libxl__ao *, uint32_t, libxl_domain_config *,
                 libxl__multidev *);
     void *(*list)(libxl_ctx *, uint32_t, int *);
+    int (*set_default)(libxl__gc *, uint32_t, void *, bool);
+    int (*to_device)(libxl__gc *, uint32_t, void *, libxl__device *);
+    void (*init)(void *);
+    void (*copy)(libxl_ctx *, void *, void *);
     void (*dispose)(void *);
     int (*compare)(void *, void *);
     void (*merge)(libxl_ctx *, void *, void *);
     int (*dm_needed)(void *, unsigned);
     void (*update_config)(libxl__gc *, void *, void *);
+    int (*update_devid)(libxl__gc *, uint32_t, void *);
+    int (*set_xenstore_config)(libxl__gc *, uint32_t, void *, flexarray_t *,
+                               flexarray_t *, flexarray_t *);
 };
 
 #define DEFINE_DEVICE_TYPE_STRUCT_X(name, sname, ...)                          \
@@ -3500,9 +3519,19 @@ struct libxl_device_type {
         .add           = libxl__add_ ## name ## s,                             \
         .list          = (void *(*)(libxl_ctx *, uint32_t, int *))             \
                          libxl_device_ ## sname ## _list,                      \
+        .set_default   = (int (*)(libxl__gc *, uint32_t, void *, bool hotplug))\
+                         libxl__device_ ## sname ## _setdefault,               \
+        .to_device     = (int (*)(libxl__gc *, uint32_t,                       \
+                                  void *, libxl__device *))                    \
+                         libxl__device_from_ ## name,                          \
+        .init          = (void (*)(void *))libxl_device_ ## sname ## _init,    \
+        .copy          = (void (*)(libxl_ctx *, void *, void *))               \
+                         libxl_device_ ## sname ## _copy,                      \
         .dispose       = (void (*)(void *))libxl_device_ ## sname ## _dispose, \
         .compare       = (int (*)(void *, void *))                             \
                          libxl_device_ ## sname ## _compare,                   \
+        .update_devid  = (int (*)(libxl__gc *, uint32_t, void *))              \
+                         libxl__device_ ## sname ## _update_devid,             \
         __VA_ARGS__                                                            \
     }
 
@@ -4350,6 +4379,13 @@ static inline bool libxl__acpi_defbool_val(const libxl_domain_build_info *b_info
     return libxl_defbool_val(b_info->acpi) &&
            libxl_defbool_val(b_info->u.hvm.acpi);
 }
+
+void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
+                             const struct libxl_device_type *dt, void *type,
+                             libxl__ao_device *aodev);
+int libxl__device_add(libxl__gc *gc, uint32_t domid,
+                      const struct libxl_device_type *dt, void *type);
+
 #endif
 
 /*
tools/libxl/libxl_nic.c +2 -0
index 4b6e8c0..dd07a6c 100644
@@ -669,6 +669,8 @@ LIBXL_DEFINE_DEVICE_ADD(nic)
 LIBXL_DEFINE_DEVICES_ADD(nic)
 LIBXL_DEFINE_DEVICE_REMOVE(nic)
 
+#define libxl__device_nic_update_devid NULL
+
 DEFINE_DEVICE_TYPE_STRUCT(nic,
     .update_config = libxl_device_nic_update_config
 );
tools/libxl/libxl_pci.c +2 -0
index b14df16..c3f1e5c 100644
@@ -1708,6 +1708,8 @@ static int libxl_device_pci_compare(libxl_device_pci *d1,
     return COMPARE_PCI(d1, d2);
 }
 
+#define libxl__device_pci_update_devid NULL
+
 DEFINE_DEVICE_TYPE_STRUCT_X(pcidev, pci);
 
 /*
tools/libxl/libxl_usb.c +6 -0
index d8948d5..07fb202 100644
@@ -1965,9 +1965,15 @@ void libxl_device_usbdev_list_free(libxl_device_usbdev *list, int nr)
    free(list);
 }
 
+#define libxl__device_usbctrl_update_devid NULL
+
 DEFINE_DEVICE_TYPE_STRUCT(usbctrl,
     .dm_needed = libxl_device_usbctrl_dm_needed
 );
+
+#define libxl__device_from_usbdev NULL
+#define libxl__device_usbdev_update_devid NULL
+
 DEFINE_DEVICE_TYPE_STRUCT(usbdev);
 
 /*
tools/libxl/libxl_vtpm.c +2 -0
index 9ee8cce..cbd5461 100644
@@ -364,6 +364,8 @@ LIBXL_DEFINE_DEVICE_ADD(vtpm)
 static LIBXL_DEFINE_DEVICES_ADD(vtpm)
 LIBXL_DEFINE_DEVICE_REMOVE(vtpm)
 
+#define libxl__device_vtpm_update_devid NULL
+
 DEFINE_DEVICE_TYPE_STRUCT(vtpm,
     .update_config = libxl_device_vtpm_update_config
 );
Signature · 7 lines
2.7.4


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

Re: [PATCH v4 01/13] libxl: add generic function to add device

Quoted 11 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_add to simple write XenStore device conifg and libxl__device_add_async to update domain configuration and write XenStore device config asynchroniously. Almost all devices have similar libxl__device_xxxx_add function. This generic functions implement same functionality but using the device handling framework. Th device specific part such as setting xen store configurationis moved to set_xenstore_config callback of the device framework.

The two add functions look correct.

Some comments below.

Quoted 31 lines
---
 tools/libxl/libxl_create.c   |   3 +
 tools/libxl/libxl_device.c   | 198 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_disk.c     |   2 +
 tools/libxl/libxl_internal.h |  36 ++++++++
 tools/libxl/libxl_nic.c      |   2 +
 tools/libxl/libxl_pci.c      |   2 +
 tools/libxl/libxl_usb.c      |   6 ++
 tools/libxl/libxl_vtpm.c     |   2 +
 8 files changed, 251 insertions(+)
tools/libxl/libxl_create.c +3 -0
index bffbc45..b2163cd 100644
@@ -1430,6 +1430,9 @@ out:
 
 #define libxl_device_dtdev_list NULL
 #define libxl_device_dtdev_compare NULL
+#define libxl__device_from_dtdev NULL
+#define libxl__device_dtdev_setdefault NULL
+#define libxl__device_dtdev_update_devid NULL
 static DEFINE_DEVICE_TYPE_STRUCT(dtdev);
 
 const struct libxl_device_type *device_type_tbl[] = {
tools/libxl/libxl_device.c +0 -0
index 00356af..07165f0 100644

tools/libxl/libxl_device.c out: · line 1802

Quoted 10 lines
tools/libxl/libxl_device.c +7 -0
@@ -1793,6 +1793,204 @@ out:
     return AO_CREATE_FAIL(rc);
 }
 
+static void device_add_domain_config(libxl__gc *gc,
+                                     libxl_domain_config *d_config,
+                                     const struct libxl_device_type *dt,
+                                     void *type)
+{
+    int *num_dev;
+    int i;

unsigned int please.

tools/libxl/libxl_device.c out: · line 1815

Quoted 13 lines
tools/libxl/libxl_device.c +13 -0
+    void *item = NULL;
+
+    num_dev = libxl__device_type_get_num(dt, 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)) {
+            item = libxl__device_type_get_elem(dt, d_config, i);
+        }
+    }
+
+    if (!item) {
+        void **devs= libxl__device_type_get_ptr(dt, d_config);

Space after devs.

Quoted 42 lines
tools/libxl/libxl_device.c +42 -0
+        *devs = libxl__realloc(NOGC, *devs,
+                               dt->dev_elem_size * (*num_dev + 1));
+        item = libxl__device_type_get_elem(dt, d_config, *num_dev);
+        (*num_dev)++;
+    } else {
+        dt->dispose(item);
+    }
+
+    dt->init(item);
+    dt->copy(CTX, item, type);
+}
+
+void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
+                             const struct libxl_device_type *dt, void *type,
+                             libxl__ao_device *aodev)
+{
+    STATE_AO_GC(aodev->ao);
+    flexarray_t *back;
+    flexarray_t *front, *ro_front;
+    libxl__device *device;
+    xs_transaction_t t = XBT_NULL;
+    libxl_domain_config d_config;
+    void *type_saved;
+    libxl__domain_userdata_lock *lock = NULL;
+    int rc;
+
+    libxl_domain_config_init(&d_config);
+
+    type_saved = libxl__malloc(gc, dt->dev_elem_size);
+
+    dt->init(type_saved);
+    dt->copy(CTX, type_saved, type);
+
+    if (dt->set_default) {
+        rc = dt->set_default(gc, domid, type, aodev->update_json);
+        if (rc) goto out;
+    }
+
+    if (dt->update_devid) {
+        rc = dt->update_devid(gc, domid, type);
+        if (rc) goto out;
+    }

tools/libxl/libxl_device.c out: · line 1867

Quoted 10 lines
tools/libxl/libxl_device.c +10 -0
+
+    if (dt->update_config)
+        dt->update_config(gc, type_saved, type);
+
+    GCNEW(device);
+    rc = dt->to_device(gc, domid, type, device);
+    if (rc) goto out;
+
+    if (aodev->update_json) {
+

Extraneous empty line here.

Quoted 134 lines
tools/libxl/libxl_device.c +126 -0
+        lock = libxl__lock_domain_userdata(gc, domid);
+        if (!lock) {
+            rc = ERROR_LOCK_FAIL;
+            goto out;
+        }
+
+        rc = libxl__get_domain_configuration(gc, domid, &d_config);
+        if (rc) goto out;
+
+        device_add_domain_config(gc, &d_config, dt, type_saved);
+
+        rc = libxl__dm_check_start(gc, &d_config, domid);
+        if (rc) goto out;
+    }
+
+    back = flexarray_make(gc, 16, 1);
+    front = flexarray_make(gc, 16, 1);
+    ro_front = flexarray_make(gc, 16, 1);
+
+    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+
+    flexarray_append_pair(front, "backend-id",
+                          GCSPRINTF("%d", device->backend_domid));
+    flexarray_append_pair(front, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+
+    if (dt->set_xenstore_config)
+        dt->set_xenstore_config(gc, domid, type, back, front, ro_front);
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
+
+        rc = libxl__device_exists(gc, t, device);
+        if (rc < 0) goto out;
+        if (rc == 1) {              /* already exists in xenstore */
+            LOGD(ERROR, domid, "device already exists in xenstore");
+            aodev->action = LIBXL__DEVICE_ACTION_ADD; /* for error message */
+            rc = ERROR_DEVICE_EXISTS;
+            goto out;
+        }
+
+        if (aodev->update_json) {
+            rc = libxl__set_domain_configuration(gc, domid, &d_config);
+            if (rc) goto out;
+        }
+
+        libxl__device_generic_add(gc, t, device,
+                                  libxl__xs_kvs_of_flexarray(gc, back),
+                                  libxl__xs_kvs_of_flexarray(gc, front),
+                                  libxl__xs_kvs_of_flexarray(gc, ro_front));
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out;
+    }
+
+    aodev->dev = device;
+    aodev->action = LIBXL__DEVICE_ACTION_ADD;
+    libxl__wait_device_connection(egc, aodev);
+
+    rc = 0;
+
+out:
+    libxl__xs_transaction_abort(gc, &t);
+    if (lock) libxl__unlock_domain_userdata(lock);
+    dt->dispose(type_saved);
+    libxl_domain_config_dispose(&d_config);
+    aodev->rc = rc;
+    if (rc) aodev->callback(egc, aodev);
+    return;
+}
+
+int libxl__device_add(libxl__gc *gc, uint32_t domid,
+                      const struct libxl_device_type *dt, void *type)
+{
+    flexarray_t *back;
+    flexarray_t *front, *ro_front;
+    libxl__device *device;
+    int rc;
+
+    if (dt->set_default) {
+        rc = dt->set_default(gc, domid, type, false);
+        if (rc) goto out;
+    }
+
+    if (dt->update_devid) {
+        rc = dt->update_devid(gc, domid, type);
+        if (rc) goto out;
+    }
+
+    GCNEW(device);
+    rc = dt->to_device(gc, domid, type, device);
+    if (rc) goto out;
+
+    back = flexarray_make(gc, 16, 1);
+    front = flexarray_make(gc, 16, 1);
+    ro_front = flexarray_make(gc, 16, 1);
+
+    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append_pair(front, "backend-id",
+                          libxl__sprintf(gc, "%d", device->backend_domid));
+    flexarray_append_pair(front, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+
+    if (dt->set_xenstore_config)
+        dt->set_xenstore_config(gc, domid, type, back, front, ro_front);
+
+    rc = libxl__device_generic_add(gc, XBT_NULL, device,
+                                   libxl__xs_kvs_of_flexarray(gc, back),
+                                   libxl__xs_kvs_of_flexarray(gc, front),
+                                   libxl__xs_kvs_of_flexarray(gc, ro_front));
+    if (rc) goto out;
+
+    rc = 0;
+
+out:
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_disk.c +0 -0
index 63de75c..f2f3635 100644

tools/libxl/libxl_disk.c static int libxl_device_disk_dm_needed(void *e, unsigned domid) · line 1248

Quoted 5 lines
tools/libxl/libxl_disk.c +2 -0
@@ -1244,6 +1244,8 @@ static int libxl_device_disk_dm_needed(void *e, unsigned domid)
            elem->backend_domid == domid;
 }
 
+#define libxl__device_disk_update_devid NULL
+

Is this correct for disk (and other device types as well)?

Since you've defined LIBXL_DEFINE_UPDATE_DEVID, you should be able to use that immediately?

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

#3 lore raw

Re: [PATCH v4 01/13] libxl: add generic function to add device

Quoted 51 lines · Wei Liu
Quoted 11 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_add to simple write XenStore device conifg and libxl__device_add_async to update domain configuration and write XenStore device config asynchroniously. Almost all devices have similar libxl__device_xxxx_add function. This generic functions implement same functionality but using the device handling framework. Th device specific part such as setting xen store configurationis moved to set_xenstore_config callback of the device framework.

The two add functions look correct.

Some comments below.

Quoted 34 lines
---
 tools/libxl/libxl_create.c   |   3 +
 tools/libxl/libxl_device.c   | 198 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_disk.c     |   2 +
 tools/libxl/libxl_internal.h |  36 ++++++++
 tools/libxl/libxl_nic.c      |   2 +
 tools/libxl/libxl_pci.c      |   2 +
 tools/libxl/libxl_usb.c      |   6 ++
 tools/libxl/libxl_vtpm.c     |   2 +
 8 files changed, 251 insertions(+)
tools/libxl/libxl_create.c +3 -0
index bffbc45..b2163cd 100644
@@ -1430,6 +1430,9 @@ out:
 
 #define libxl_device_dtdev_list NULL
 #define libxl_device_dtdev_compare NULL
+#define libxl__device_from_dtdev NULL
+#define libxl__device_dtdev_setdefault NULL
+#define libxl__device_dtdev_update_devid NULL
 static DEFINE_DEVICE_TYPE_STRUCT(dtdev);
 
 const struct libxl_device_type *device_type_tbl[] = {
tools/libxl/libxl_device.c +0 -0
index 00356af..07165f0 100644
@@ -1793,6 +1793,204 @@ out:
     return AO_CREATE_FAIL(rc);
 }
 
Quoted 9 lines

tools/libxl/libxl_device.c out: · line 1802

Quoted 7 lines
tools/libxl/libxl_device.c +7 -0
+static void device_add_domain_config(libxl__gc *gc,
+                                     libxl_domain_config *d_config,
+                                     const struct libxl_device_type *dt,
+                                     void *type)
+{
+    int *num_dev;
+    int i;

unsigned int please.

For "i" counter only or for num_dev as well?
For "i" is ok but num_dev better to keep int.

Quoted 209 lines
Quoted 4 lines
tools/libxl/libxl_device.c +3 -0
+    void *item = NULL;
+
+    num_dev = libxl__device_type_get_num(dt, d_config);

tools/libxl/libxl_device.c out: · line 1815

Quoted 10 lines
tools/libxl/libxl_device.c +10 -0
+
+    /* Check for existing device */
+    for (i = 0; i < *num_dev; i++) {
+        if (dt->compare(libxl__device_type_get_elem(dt, d_config, i), type)) {
+            item = libxl__device_type_get_elem(dt, d_config, i);
+        }
+    }
+
+    if (!item) {
+        void **devs= libxl__device_type_get_ptr(dt, d_config);

Space after devs.

Quoted 42 lines
tools/libxl/libxl_device.c +42 -0
+        *devs = libxl__realloc(NOGC, *devs,
+                               dt->dev_elem_size * (*num_dev + 1));
+        item = libxl__device_type_get_elem(dt, d_config, *num_dev);
+        (*num_dev)++;
+    } else {
+        dt->dispose(item);
+    }
+
+    dt->init(item);
+    dt->copy(CTX, item, type);
+}
+
+void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
+                             const struct libxl_device_type *dt, void *type,
+                             libxl__ao_device *aodev)
+{
+    STATE_AO_GC(aodev->ao);
+    flexarray_t *back;
+    flexarray_t *front, *ro_front;
+    libxl__device *device;
+    xs_transaction_t t = XBT_NULL;
+    libxl_domain_config d_config;
+    void *type_saved;
+    libxl__domain_userdata_lock *lock = NULL;
+    int rc;
+
+    libxl_domain_config_init(&d_config);
+
+    type_saved = libxl__malloc(gc, dt->dev_elem_size);
+
+    dt->init(type_saved);
+    dt->copy(CTX, type_saved, type);
+
+    if (dt->set_default) {
+        rc = dt->set_default(gc, domid, type, aodev->update_json);
+        if (rc) goto out;
+    }
+
+    if (dt->update_devid) {
+        rc = dt->update_devid(gc, domid, type);
+        if (rc) goto out;
+    }

tools/libxl/libxl_device.c out: · line 1867

Quoted 10 lines
tools/libxl/libxl_device.c +10 -0
+
+    if (dt->update_config)
+        dt->update_config(gc, type_saved, type);
+
+    GCNEW(device);
+    rc = dt->to_device(gc, domid, type, device);
+    if (rc) goto out;
+
+    if (aodev->update_json) {
+

Extraneous empty line here.

Quoted 137 lines
tools/libxl/libxl_device.c +126 -0
+        lock = libxl__lock_domain_userdata(gc, domid);
+        if (!lock) {
+            rc = ERROR_LOCK_FAIL;
+            goto out;
+        }
+
+        rc = libxl__get_domain_configuration(gc, domid, &d_config);
+        if (rc) goto out;
+
+        device_add_domain_config(gc, &d_config, dt, type_saved);
+
+        rc = libxl__dm_check_start(gc, &d_config, domid);
+        if (rc) goto out;
+    }
+
+    back = flexarray_make(gc, 16, 1);
+    front = flexarray_make(gc, 16, 1);
+    ro_front = flexarray_make(gc, 16, 1);
+
+    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+
+    flexarray_append_pair(front, "backend-id",
+                          GCSPRINTF("%d", device->backend_domid));
+    flexarray_append_pair(front, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+
+    if (dt->set_xenstore_config)
+        dt->set_xenstore_config(gc, domid, type, back, front, ro_front);
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
+
+        rc = libxl__device_exists(gc, t, device);
+        if (rc < 0) goto out;
+        if (rc == 1) {              /* already exists in xenstore */
+            LOGD(ERROR, domid, "device already exists in xenstore");
+            aodev->action = LIBXL__DEVICE_ACTION_ADD; /* for error message */
+            rc = ERROR_DEVICE_EXISTS;
+            goto out;
+        }
+
+        if (aodev->update_json) {
+            rc = libxl__set_domain_configuration(gc, domid, &d_config);
+            if (rc) goto out;
+        }
+
+        libxl__device_generic_add(gc, t, device,
+                                  libxl__xs_kvs_of_flexarray(gc, back),
+                                  libxl__xs_kvs_of_flexarray(gc, front),
+                                  libxl__xs_kvs_of_flexarray(gc, ro_front));
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out;
+    }
+
+    aodev->dev = device;
+    aodev->action = LIBXL__DEVICE_ACTION_ADD;
+    libxl__wait_device_connection(egc, aodev);
+
+    rc = 0;
+
+out:
+    libxl__xs_transaction_abort(gc, &t);
+    if (lock) libxl__unlock_domain_userdata(lock);
+    dt->dispose(type_saved);
+    libxl_domain_config_dispose(&d_config);
+    aodev->rc = rc;
+    if (rc) aodev->callback(egc, aodev);
+    return;
+}
+
+int libxl__device_add(libxl__gc *gc, uint32_t domid,
+                      const struct libxl_device_type *dt, void *type)
+{
+    flexarray_t *back;
+    flexarray_t *front, *ro_front;
+    libxl__device *device;
+    int rc;
+
+    if (dt->set_default) {
+        rc = dt->set_default(gc, domid, type, false);
+        if (rc) goto out;
+    }
+
+    if (dt->update_devid) {
+        rc = dt->update_devid(gc, domid, type);
+        if (rc) goto out;
+    }
+
+    GCNEW(device);
+    rc = dt->to_device(gc, domid, type, device);
+    if (rc) goto out;
+
+    back = flexarray_make(gc, 16, 1);
+    front = flexarray_make(gc, 16, 1);
+    ro_front = flexarray_make(gc, 16, 1);
+
+    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+    flexarray_append_pair(front, "backend-id",
+                          libxl__sprintf(gc, "%d", device->backend_domid));
+    flexarray_append_pair(front, "state",
+                          GCSPRINTF("%d", XenbusStateInitialising));
+
+    if (dt->set_xenstore_config)
+        dt->set_xenstore_config(gc, domid, type, back, front, ro_front);
+
+    rc = libxl__device_generic_add(gc, XBT_NULL, device,
+                                   libxl__xs_kvs_of_flexarray(gc, back),
+                                   libxl__xs_kvs_of_flexarray(gc, front),
+                                   libxl__xs_kvs_of_flexarray(gc, ro_front));
+    if (rc) goto out;
+
+    rc = 0;
+
+out:
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_disk.c +0 -0
index 63de75c..f2f3635 100644
@@ -1244,6 +1244,8 @@ static int libxl_device_disk_dm_needed(void *e, unsigned domid)
            elem->backend_domid == domid;
 }
 
Quoted 4 lines

tools/libxl/libxl_disk.c static int libxl_device_disk_dm_needed(void *e, unsigned domid) · line 1248

Quoted 2 lines
tools/libxl/libxl_disk.c +2 -0
+#define libxl__device_disk_update_devid NULL
+

Is this correct for disk (and other device types as well)?

What exactly is correct? libxl__device_disk_update_devid NULL or libxl__device_add_async function?

Quoted 3 lines

Since you've defined LIBXL_DEFINE_UPDATE_DEVID, you should be able to use that immediately?

Actually disk doesn't call update dev ID. So assigning it to NULL I guess is ok here.

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

Re: [PATCH v4 01/13] libxl: add generic function to add device

Quoted 62 lines · Oleksandr Grytsov
Quoted 51 lines · Wei Liu
Quoted 11 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_add to simple write XenStore device conifg and libxl__device_add_async to update domain configuration and write XenStore device config asynchroniously. Almost all devices have similar libxl__device_xxxx_add function. This generic functions implement same functionality but using the device handling framework. Th device specific part such as setting xen store configurationis moved to set_xenstore_config callback of the device framework.

The two add functions look correct.

Some comments below.

Quoted 34 lines
---
 tools/libxl/libxl_create.c   |   3 +
 tools/libxl/libxl_device.c   | 198 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_disk.c     |   2 +
 tools/libxl/libxl_internal.h |  36 ++++++++
 tools/libxl/libxl_nic.c      |   2 +
 tools/libxl/libxl_pci.c      |   2 +
 tools/libxl/libxl_usb.c      |   6 ++
 tools/libxl/libxl_vtpm.c     |   2 +
 8 files changed, 251 insertions(+)
tools/libxl/libxl_create.c +3 -0
index bffbc45..b2163cd 100644
@@ -1430,6 +1430,9 @@ out:
 
 #define libxl_device_dtdev_list NULL
 #define libxl_device_dtdev_compare NULL
+#define libxl__device_from_dtdev NULL
+#define libxl__device_dtdev_setdefault NULL
+#define libxl__device_dtdev_update_devid NULL
 static DEFINE_DEVICE_TYPE_STRUCT(dtdev);
 
 const struct libxl_device_type *device_type_tbl[] = {
tools/libxl/libxl_device.c +0 -0
index 00356af..07165f0 100644
@@ -1793,6 +1793,204 @@ out:
     return AO_CREATE_FAIL(rc);
 }
 
Quoted 9 lines

tools/libxl/libxl_device.c out: · line 1802

Quoted 7 lines
tools/libxl/libxl_device.c +7 -0
+static void device_add_domain_config(libxl__gc *gc,
+                                     libxl_domain_config *d_config,
+                                     const struct libxl_device_type *dt,
+                                     void *type)
+{
+    int *num_dev;
+    int i;

unsigned int please.

Quoted 3 lines

For "i" counter only or for num_dev as well?
For "i" is ok but num_dev better to keep int.

For i only.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tools/libxl/libxl_device.c +0 -0
  * mode: C
tools/libxl/libxl_disk.c +0 -0
index 63de75c..f2f3635 100644
@@ -1244,6 +1244,8 @@ static int libxl_device_disk_dm_needed(void *e, unsigned domid)
            elem->backend_domid == domid;
 }
 
Quoted 8 lines
Quoted 4 lines

tools/libxl/libxl_disk.c static int libxl_device_disk_dm_needed(void *e, unsigned domid) · line 1248

Quoted 2 lines
tools/libxl/libxl_disk.c +2 -0
+#define libxl__device_disk_update_devid NULL
+

Is this correct for disk (and other device types as well)?

What exactly is correct? libxl__device_disk_update_devid NULL or libxl__device_add_async function?

Defining all the update_devid functions to be NULL. They should be defined with the macros now, right?

I notice in later patches they are changed, so I'm not too fuss either way. If you want to keep them to be defined as NULL please say so in commit message.

Quoted 7 lines
Quoted 3 lines

Since you've defined LIBXL_DEFINE_UPDATE_DEVID, you should be able to use that immediately?

Actually disk doesn't call update dev ID. So assigning it to NULL I guess is ok here.

Yes. I think so. Please consider other device types then.

Quoted 3 lines
Signature · 2 lines
Best Regards,
Oleksandr Grytsov.

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

#5 lore raw

Re: [PATCH v4 01/13] libxl: add generic function to add device

Quoted 95 lines · Wei Liu
Quoted 62 lines · Oleksandr Grytsov
Quoted 51 lines · Wei Liu
Quoted 11 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_add to simple write XenStore device conifg and libxl__device_add_async to update domain configuration and write XenStore device config asynchroniously. Almost all devices have similar libxl__device_xxxx_add function. This generic functions implement same functionality but using the device handling framework. Th device specific part such as setting xen store configurationis moved to set_xenstore_config callback of the device framework.

The two add functions look correct.

Some comments below.

Quoted 34 lines
---
 tools/libxl/libxl_create.c   |   3 +
 tools/libxl/libxl_device.c   | 198 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_disk.c     |   2 +
 tools/libxl/libxl_internal.h |  36 ++++++++
 tools/libxl/libxl_nic.c      |   2 +
 tools/libxl/libxl_pci.c      |   2 +
 tools/libxl/libxl_usb.c      |   6 ++
 tools/libxl/libxl_vtpm.c     |   2 +
 8 files changed, 251 insertions(+)
tools/libxl/libxl_create.c +3 -0
index bffbc45..b2163cd 100644
@@ -1430,6 +1430,9 @@ out:
 
 #define libxl_device_dtdev_list NULL
 #define libxl_device_dtdev_compare NULL
+#define libxl__device_from_dtdev NULL
+#define libxl__device_dtdev_setdefault NULL
+#define libxl__device_dtdev_update_devid NULL
 static DEFINE_DEVICE_TYPE_STRUCT(dtdev);
 
 const struct libxl_device_type *device_type_tbl[] = {
tools/libxl/libxl_device.c +0 -0
index 00356af..07165f0 100644
@@ -1793,6 +1793,204 @@ out:
     return AO_CREATE_FAIL(rc);
 }
 
Quoted 9 lines

tools/libxl/libxl_device.c out: · line 1802

Quoted 7 lines
tools/libxl/libxl_device.c +7 -0
+static void device_add_domain_config(libxl__gc *gc,
+                                     libxl_domain_config *d_config,
+                                     const struct libxl_device_type *dt,
+                                     void *type)
+{
+    int *num_dev;
+    int i;

unsigned int please.

Quoted 3 lines

For "i" counter only or for num_dev as well?
For "i" is ok but num_dev better to keep int.

For i only.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tools/libxl/libxl_device.c +0 -0
  * mode: C
tools/libxl/libxl_disk.c +0 -0
index 63de75c..f2f3635 100644
@@ -1244,6 +1244,8 @@ static int libxl_device_disk_dm_needed(void *e, unsigned domid)
            elem->backend_domid == domid;
 }
 
Quoted 8 lines
Quoted 4 lines

tools/libxl/libxl_disk.c static int libxl_device_disk_dm_needed(void *e, unsigned domid) · line 1248

Quoted 2 lines
tools/libxl/libxl_disk.c +2 -0
+#define libxl__device_disk_update_devid NULL
+

Is this correct for disk (and other device types as well)?

What exactly is correct? libxl__device_disk_update_devid NULL or libxl__device_add_async function?

Defining all the update_devid functions to be NULL. They should be defined with the macros now, right?

I notice in later patches they are changed, so I'm not too fuss either way. If you want to keep them to be defined as NULL please say so in commit message.

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Since you've defined LIBXL_DEFINE_UPDATE_DEVID, you should be able to use that immediately?

Actually disk doesn't call update dev ID. So assigning it to NULL I guess is ok here.

Yes. I think so. Please consider other device types then.

Ok, I will use the macro in every device which need update devid in this patch. Also I will call this function in add device function.

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

#6 lore raw

PATCH v4 2/13 libxl: add generic functions to get and free device list

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_list and libxl__device_list_free functions to handle device list using the device framework.

---
 tools/libxl/libxl_device.c   | 66 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  8 ++++++
 2 files changed, 74 insertions(+)
tools/libxl/libxl_device.c +66 -0
index 07165f0..f1d4848 100644
@@ -1991,6 +1991,72 @@ out:
     return rc;
 }
 
+void *libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt,
+                         uint32_t domid, const char* name, int *num)
+{
+    void *r = NULL;
+    void *list = NULL;
+    void *item = NULL;
+    char *libxl_path;
+    char **dir = NULL;
+    unsigned int ndirs = 0;
+    int rc;
+
+    *num = 0;
+
+    libxl_path = GCSPRINTF("%s/device/%s",
+                           libxl__xs_libxl_path(gc, domid), name);
+
+    dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs);
+
+    if (dir && ndirs) {
+        list = libxl__malloc(NOGC, dt->dev_elem_size * ndirs);
+        void *end = (uint8_t *)list + ndirs * dt->dev_elem_size;
+        item = list;
+
+        while (item < end) {
+            dt->init(item);
+
+            if (dt->from_xenstore) {
+                char* device_libxl_path = GCSPRINTF("%s/%s", libxl_path, *dir);
+                rc = dt->from_xenstore(gc, device_libxl_path, atoi(*dir), item);
+                if (rc) goto out;
+            }
+
+            item = (uint8_t*)item + dt->dev_elem_size;
+            ++dir;
+        }
+    }
+
+    *num = ndirs;
+    r = list;
+    list = NULL;
+
+out:
+
+    if (list) {
+        *num = 0;
+        while(item >= list) {
+            dt->dispose(item);
+            item = (uint8_t*)item - dt->dev_elem_size;
+        }
+        free(list);
+    }
+
+    return r;
+}
+
+void libxl__device_list_free(const struct libxl_device_type *dt,
+                             void *list, int num)
+{
+    int i;
+
+    for (i = 0; i < num; i++)
+        dt->dispose((uint8_t*)list + i * dt->dev_elem_size);
+
+    free(list);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_internal.h +8 -0
index 075dfe3..271ac89 100644
@@ -3506,6 +3506,7 @@ struct libxl_device_type {
     int (*dm_needed)(void *, unsigned);
     void (*update_config)(libxl__gc *, void *, void *);
     int (*update_devid)(libxl__gc *, uint32_t, void *);
+    int (*from_xenstore)(libxl__gc *, const char *, libxl_devid, void *);
     int (*set_xenstore_config)(libxl__gc *, uint32_t, void *, flexarray_t *,
                                flexarray_t *, flexarray_t *);
 };
@@ -4386,6 +4387,13 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
 int libxl__device_add(libxl__gc *gc, uint32_t domid,
                       const struct libxl_device_type *dt, void *type);
 
+/* Caller is responsible for freeing the memory by calling
+ * libxl__device_list_free
+ */
+void* libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt,
+                         uint32_t domid, const char* name, int *num);
+void libxl__device_list_free(const struct libxl_device_type *dt,
+                             void *list, int num);
 #endif
 
 /*
Signature · 7 lines
2.7.4


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

Re: [PATCH v4 02/13] libxl: add generic functions to get and free device list

Quoted 43 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_list and libxl__device_list_free functions to handle device list using the device framework.

---
 tools/libxl/libxl_device.c   | 66 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  8 ++++++
 2 files changed, 74 insertions(+)
tools/libxl/libxl_device.c +23 -0
index 07165f0..f1d4848 100644
@@ -1991,6 +1991,72 @@ out:
     return rc;
 }
 
+void *libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt,
+                         uint32_t domid, const char* name, int *num)
+{
+    void *r = NULL;
+    void *list = NULL;
+    void *item = NULL;
+    char *libxl_path;
+    char **dir = NULL;
+    unsigned int ndirs = 0;
+    int rc;
+
+    *num = 0;
+
+    libxl_path = GCSPRINTF("%s/device/%s",
+                           libxl__xs_libxl_path(gc, domid), name);
+
+    dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs);
+
+    if (dir && ndirs) {
+        list = libxl__malloc(NOGC, dt->dev_elem_size * ndirs);
+        void *end = (uint8_t *)list + ndirs * dt->dev_elem_size;
+        item = list;
+

tools/libxl/libxl_device.c out: · line 2026

Quoted 10 lines
tools/libxl/libxl_device.c +10 -0
+        while (item < end) {
+            dt->init(item);
+
+            if (dt->from_xenstore) {
+                char* device_libxl_path = GCSPRINTF("%s/%s", libxl_path, *dir);
+                rc = dt->from_xenstore(gc, device_libxl_path, atoi(*dir), item);
+                if (rc) goto out;
+            }
+
+            item = (uint8_t*)item + dt->dev_elem_size;

Space before *.

tools/libxl/libxl_device.c out: · line 2039

Quoted 13 lines
tools/libxl/libxl_device.c +13 -0
+            ++dir;
+        }
+    }
+
+    *num = ndirs;
+    r = list;
+    list = NULL;
+
+out:
+
+    if (list) {
+        *num = 0;
+        while(item >= list) {

Space after while, but ...

tools/libxl/libxl_device.c out: · line 2043

Quoted 4 lines
tools/libxl/libxl_device.c +4 -0
+            dt->dispose(item);
+            item = (uint8_t*)item - dt->dev_elem_size;
+        }
+        free(list);

You should be able to use libxl__device_list_free here.

Quoted 48 lines
tools/libxl/libxl_device.c +16 -0
+    }
+
+    return r;
+}
+
+void libxl__device_list_free(const struct libxl_device_type *dt,
+                             void *list, int num)
+{
+    int i;
+
+    for (i = 0; i < num; i++)
+        dt->dispose((uint8_t*)list + i * dt->dev_elem_size);
+
+    free(list);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_internal.h +8 -0
index 075dfe3..271ac89 100644
@@ -3506,6 +3506,7 @@ struct libxl_device_type {
     int (*dm_needed)(void *, unsigned);
     void (*update_config)(libxl__gc *, void *, void *);
     int (*update_devid)(libxl__gc *, uint32_t, void *);
+    int (*from_xenstore)(libxl__gc *, const char *, libxl_devid, void *);
     int (*set_xenstore_config)(libxl__gc *, uint32_t, void *, flexarray_t *,
                                flexarray_t *, flexarray_t *);
 };
@@ -4386,6 +4387,13 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
 int libxl__device_add(libxl__gc *gc, uint32_t domid,
                       const struct libxl_device_type *dt, void *type);
 
+/* Caller is responsible for freeing the memory by calling
+ * libxl__device_list_free
+ */
+void* libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt,
+                         uint32_t domid, const char* name, int *num);
+void libxl__device_list_free(const struct libxl_device_type *dt,
+                             void *list, int num);
 #endif
 
 /*
Signature · 1 line
2.7.4

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

#8 lore raw

Re: [PATCH v4 02/13] libxl: add generic functions to get and free device list

Quoted 73 lines · Wei Liu
Quoted 43 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add libxl__device_list and libxl__device_list_free functions to handle device list using the device framework.

---
 tools/libxl/libxl_device.c   | 66 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  8 ++++++
 2 files changed, 74 insertions(+)
tools/libxl/libxl_device.c +23 -0
index 07165f0..f1d4848 100644
@@ -1991,6 +1991,72 @@ out:
     return rc;
 }
 
+void *libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt,
+                         uint32_t domid, const char* name, int *num)
+{
+    void *r = NULL;
+    void *list = NULL;
+    void *item = NULL;
+    char *libxl_path;
+    char **dir = NULL;
+    unsigned int ndirs = 0;
+    int rc;
+
+    *num = 0;
+
+    libxl_path = GCSPRINTF("%s/device/%s",
+                           libxl__xs_libxl_path(gc, domid), name);
+
+    dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs);
+
+    if (dir && ndirs) {
+        list = libxl__malloc(NOGC, dt->dev_elem_size * ndirs);
+        void *end = (uint8_t *)list + ndirs * dt->dev_elem_size;
+        item = list;
+

tools/libxl/libxl_device.c out: · line 2026

Quoted 10 lines
tools/libxl/libxl_device.c +10 -0
+        while (item < end) {
+            dt->init(item);
+
+            if (dt->from_xenstore) {
+                char* device_libxl_path = GCSPRINTF("%s/%s", libxl_path, *dir);
+                rc = dt->from_xenstore(gc, device_libxl_path, atoi(*dir), item);
+                if (rc) goto out;
+            }
+
+            item = (uint8_t*)item + dt->dev_elem_size;

Space before *.

tools/libxl/libxl_device.c out: · line 2039

Quoted 13 lines
tools/libxl/libxl_device.c +13 -0
+            ++dir;
+        }
+    }
+
+    *num = ndirs;
+    r = list;
+    list = NULL;
+
+out:
+
+    if (list) {
+        *num = 0;
+        while(item >= list) {

Space after while, but ...

Quoted 6 lines

tools/libxl/libxl_device.c out: · line 2043

Quoted 4 lines
tools/libxl/libxl_device.c +4 -0
+            dt->dispose(item);
+            item = (uint8_t*)item - dt->dev_elem_size;
+        }
+        free(list);

You should be able to use libxl__device_list_free here.

Good catch. I will use list_free here. This requires slight changes in above loop:
i need to count initialized elements in order to pass it to list_free.

Quoted 45 lines
Quoted 45 lines
tools/libxl/libxl_device.c +16 -0
+    }
+
+    return r;
+}
+
+void libxl__device_list_free(const struct libxl_device_type *dt,
+                             void *list, int num)
+{
+    int i;
+
+    for (i = 0; i < num; i++)
+        dt->dispose((uint8_t*)list + i * dt->dev_elem_size);
+
+    free(list);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_internal.h +8 -0
index 075dfe3..271ac89 100644
@@ -3506,6 +3506,7 @@ struct libxl_device_type {
     int (*dm_needed)(void *, unsigned);
     void (*update_config)(libxl__gc *, void *, void *);
     int (*update_devid)(libxl__gc *, uint32_t, void *);
+    int (*from_xenstore)(libxl__gc *, const char *, libxl_devid, void *);
     int (*set_xenstore_config)(libxl__gc *, uint32_t, void *, flexarray_t *,
                                flexarray_t *, flexarray_t *);
 };
@@ -4386,6 +4387,13 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid,
 int libxl__device_add(libxl__gc *gc, uint32_t domid,
                       const struct libxl_device_type *dt, void *type);
 
+/* Caller is responsible for freeing the memory by calling
+ * libxl__device_list_free
+ */
+void* libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt,
+                         uint32_t domid, const char* name, int *num);
+void libxl__device_list_free(const struct libxl_device_type *dt,
+                             void *list, int num);
 #endif
 
Quoted 4 lines
Quoted 4 lines
tools/libxl/libxl_internal.h +0 -1
 /*
--

2.7.4

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

#9 lore raw

PATCH v4 3/13 libxl: add vdispl device

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/Makefile                 |   2 +-
 tools/libxl/libxl.h                  |  24 +++
 tools/libxl/libxl_create.c           |   1 +
 tools/libxl/libxl_internal.h         |   1 +
 tools/libxl/libxl_types.idl          |  38 ++++-
 tools/libxl/libxl_types_internal.idl |   1 +
 tools/libxl/libxl_utils.h            |   4 +
 tools/libxl/libxl_vdispl.c           | 289 +++++++++++++++++++++++++++++++++++
 8 files changed, 358 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_vdispl.c
tools/libxl/Makefile +1 -1
index 1bf6b8c..6f57e65 100644
@@ -138,7 +138,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
 			libxl_dom_suspend.o libxl_dom_save.o libxl_usb.o \
 			libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \
 			libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \
-			libxl_9pfs.o libxl_domain.o \
+			libxl_9pfs.o libxl_domain.o libxl_vdispl.o \
                         $(LIBXL_OBJS-y)
 LIBXL_OBJS += libxl_genid.o
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl.h +24 -0
index cf8687a..4c0d612 100644
@@ -1851,6 +1851,30 @@ libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *n
 int libxl_device_vtpm_getinfo(libxl_ctx *ctx, uint32_t domid,
                                libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo);
 
+/* Virtual displays */
+int libxl_device_vdispl_add(libxl_ctx *ctx, uint32_t domid,
+                            libxl_device_vdispl *displ,
+                            const libxl_asyncop_how *ao_how)
+                            LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_vdispl_remove(libxl_ctx *ctx, uint32_t domid,
+                               libxl_device_vdispl *vdispl,
+                               const libxl_asyncop_how *ao_how)
+                               LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_vdispl_destroy(libxl_ctx *ctx, uint32_t domid,
+                                libxl_device_vdispl *vdispl,
+                                const libxl_asyncop_how *ao_how)
+                                LIBXL_EXTERNAL_CALLERS_ONLY;
+
+libxl_device_vdispl *libxl_device_vdispl_list(libxl_ctx *ctx,
+                                              uint32_t domid, int *num)
+                                              LIBXL_EXTERNAL_CALLERS_ONLY;
+void libxl_device_vdispl_list_free(libxl_device_vdispl* list, int num)
+                                   LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_vdispl_getinfo(libxl_ctx *ctx, uint32_t domid,
+                                libxl_device_vdispl *vdispl,
+                                libxl_vdisplinfo *vdisplinfo)
+                                LIBXL_EXTERNAL_CALLERS_ONLY;
+
 /* Keyboard */
 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
                          const libxl_asyncop_how *ao_how)
tools/libxl/libxl_create.c +1 -0
index b2163cd..912bd21 100644
@@ -1443,6 +1443,7 @@ const struct libxl_device_type *device_type_tbl[] = {
     &libxl__usbdev_devtype,
     &libxl__pcidev_devtype,
     &libxl__dtdev_devtype,
+    &libxl__vdispl_devtype,
     NULL
 };
 
tools/libxl/libxl_internal.h +1 -0
index 271ac89..68c08aa 100644
@@ -3564,6 +3564,7 @@ extern const struct libxl_device_type libxl__vtpm_devtype;
 extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
+extern const struct libxl_device_type libxl__vdispl_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +37 -1
index 2204425..25563cf 100644
@@ -755,7 +755,21 @@ libxl_device_vtpm = Struct("device_vtpm", [
     ("backend_domname",  string),
     ("devid",            libxl_devid),
     ("uuid",             libxl_uuid),
-])
+    ])
+
+libxl_connector_param = Struct("connector_param", [
+    ("id", string),
+    ("width", uint32),
+    ("height", uint32)
+    ])
+
+libxl_device_vdispl = Struct("device_vdispl", [
+    ("backend_domid", libxl_domid),
+    ("backend_domname", string),
+    ("devid", libxl_devid),
+    ("be_alloc", bool),
+    ("connectors", Array(libxl_connector_param, "num_connectors"))
+    ])
 
 libxl_device_p9 = Struct("device_p9", [
     ("backend_domid",    libxl_domid),
@@ -791,6 +805,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
     ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("vdispls", Array(libxl_device_vdispl, "num_vdispls")),
     # a channel manifests as a console with a name,
     # see docs/misc/channels.txt
     ("channels", Array(libxl_device_channel, "num_channels")),
@@ -887,6 +902,27 @@ libxl_physinfo = Struct("physinfo", [
     ("cap_hvm_directio", bool),
     ], dir=DIR_OUT)
 
+libxl_connectorinfo = Struct("connectorinfo", [
+    ("id", string),
+    ("width", uint32),
+    ("height", uint32),
+    ("req_evtch", integer),
+    ("req_rref", integer),
+    ("evt_evtch", integer),
+    ("evt_rref", integer),
+    ], dir=DIR_OUT)
+
+libxl_vdisplinfo = Struct("vdisplinfo", [
+    ("backend", string),
+    ("backend_id", uint32),
+    ("frontend", string),
+    ("frontend_id", uint32),
+    ("devid", libxl_devid),
+    ("state", integer),
+    ("be_alloc", bool),
+    ("connectors", Array(libxl_connectorinfo, "num_connectors"))
+    ], dir=DIR_OUT)
+
 # NUMA node characteristics: size and free are how much memory it has, and how
 # much of it is free, respectively. dists is an array of distances from this
 # node to each other node.
tools/libxl/libxl_types_internal.idl +1 -0
index 7dc4d0f..673a6d5 100644
@@ -26,6 +26,7 @@ libxl__device_kind = Enumeration("device_kind", [
     (9, "VUSB"),
     (10, "QUSB"),
     (11, "9PFS"),
+    (12, "VDISPL"),
     ])
 
 libxl__console_backend = Enumeration("console_backend", [
tools/libxl/libxl_utils.h +4 -0
index 25773d8..9e743dc 100644
@@ -78,6 +78,10 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,
                                int devid, libxl_device_vtpm *vtpm);
 int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t domid,
                                   int devid, libxl_device_usbctrl *usbctrl);
+
+int libxl_devid_to_device_vdispl(libxl_ctx *ctx, uint32_t domid,
+                                 int devid, libxl_device_vdispl *vdispl);
+
 int libxl_ctrlport_to_device_usbdev(libxl_ctx *ctx, uint32_t domid,
                                     int ctrl, int port,
                                     libxl_device_usbdev *usbdev);
tools/libxl/libxl_vdispl.c new file +289 -0

289 lines not on this page · raw message

Signature · 7 lines
2.7.4


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

Re: [PATCH v4 03/13] libxl: add vdispl device

Quoted 12 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/Makefile                 |   2 +-
 tools/libxl/libxl.h                  |  24 +++
 tools/libxl/libxl_create.c           |   1 +
 tools/libxl/libxl_internal.h         |   1 +
 tools/libxl/libxl_types.idl          |  38 ++++-
 tools/libxl/libxl_types_internal.idl |   1 +
 tools/libxl/libxl_utils.h            |   4 +
 tools/libxl/libxl_vdispl.c           | 289 +++++++++++++++++++++++++++++++++++

Only skim-read this patch because changes are rather self-contained.

tools/libxl/libxl_vdispl.c line 121

Quoted 10 lines
tools/libxl/libxl_vdispl.c new file +10 -0
+static int libxl__device_vdispl_getconnectors(libxl_ctx *ctx,
+                                              const char *path,
+                                              libxl_vdisplinfo *info)
+{
+    GC_INIT(ctx);
+    char *connector = NULL;
+    char *connector_path = NULL;
+    int i, rc;
+
+    GCNEW_ARRAY(connector_path, 128);

Using char[128] should be fine.

tools/libxl/libxl_vdispl.c line 128

Quoted 7 lines
tools/libxl/libxl_vdispl.c new file +7 -0
+
+    info->num_connectors = 0;
+
+    rc = snprintf(connector_path, 128, "%s/%d", path, info->num_connectors);
+    if (rc < 0) goto out;
+
+    while((connector = xs_read(ctx->xsh, XBT_NULL, connector_path, NULL))

Coding style.

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

#11 lore raw

Re: [PATCH v4 03/13] libxl: add vdispl device

Wei Liu writes ("Re: [PATCH v4 03/13] libxl: add vdispl device"):

Quoted 1 line
Quoted 1 line

+ rc = snprintf(connector_path, 128, "%s/%d", path, info->num_connectors);

Why not use GCSPRINTF ? These statically sized buffers etc. are an invitation to bugs.

Ian.

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

#12 lore raw

Re: [PATCH v4 03/13] libxl: add vdispl device

Quoted 5 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v4 03/13] libxl: add vdispl device"):

Quoted 1 line
Quoted 1 line

+ rc = snprintf(connector_path, 128, "%s/%d", path, info->num_connectors);

Why not use GCSPRINTF ? These statically sized buffers etc. are an invitation to bugs.

Right, that's a better suggestion.

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

#13 lore raw

Re: [PATCH v4 03/13] libxl: add vdispl device

Quoted 8 lines · Wei Liu
Quoted 5 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v4 03/13] libxl: add vdispl device"):

Quoted 1 line
Quoted 1 line

+ rc = snprintf(connector_path, 128, "%s/%d", path, info->num_connectors);

Why not use GCSPRINTF ? These statically sized buffers etc. are an invitation to bugs.

Right, that's a better suggestion.

I reuse connector_path buffer as path to read connector settings from xen store. So if I use GCSPRINTF for each setting then this function will allocate about 256 bytes for one connector. In typical scenario each frontend will have 1 or 2 connectors.

If it is ok I will use GCSPRINTF.

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

#14 lore raw

Re: [PATCH v4 03/13] libxl: add vdispl device

Quoted 8 lines · Oleksandr Grytsov
Quoted 7 lines · Wei Liu
Quoted 5 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v4 03/13] libxl: add vdispl device"):

Quoted 1 line
Quoted 1 line

+ rc = snprintf(connector_path, 128, "%s/%d", path, info->num_connectors);

Why not use GCSPRINTF ? These statically sized buffers etc. are an invitation to bugs.

Quoted 7 lines
Quoted 1 line

Right, that's a better suggestion.

I reuse connector_path buffer as path to read connector settings from xen store. So if I use GCSPRINTF for each setting then this function will allocate about 256 bytes for one connector. In typical scenario each frontend will have 1 or 2 connectors.

That's OK I think.

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

#15 lore raw

PATCH v4 4/13 xl: add PV display device commands

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Add commands: vdispl-attach, vdispl-list, vdispl-detach and domain config vdispl parser

---
 tools/xl/Makefile      |   1 +
 tools/xl/xl.h          |   3 +
 tools/xl/xl_cmdtable.c |  19 ++++++
 tools/xl/xl_parse.c    |  75 ++++++++++++++++++++++-
 tools/xl/xl_parse.h    |   2 +-
 tools/xl/xl_vdispl.c   | 163 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 261 insertions(+), 2 deletions(-)
 create mode 100644 tools/xl/xl_vdispl.c
tools/xl/Makefile +1 -0
index e16f877..5c784b5 100644
@@ -21,6 +21,7 @@ XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o
 XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o
 XL_OBJS += xl_psr.o xl_info.o xl_console.o xl_misc.o
 XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o
+XL_OBJS += xl_vdispl.o
 
 $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
 $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
tools/xl/xl.h +3 -0
index aa95b77..d361241 100644
@@ -166,6 +166,9 @@ int main_blockdetach(int argc, char **argv);
 int main_vtpmattach(int argc, char **argv);
 int main_vtpmlist(int argc, char **argv);
 int main_vtpmdetach(int argc, char **argv);
+int main_vdisplattach(int argc, char **argv);
+int main_vdispllist(int argc, char **argv);
+int main_vdispldetach(int argc, char **argv);
 int main_usbctrl_attach(int argc, char **argv);
 int main_usbctrl_detach(int argc, char **argv);
 int main_usbdev_attach(int argc, char **argv);
tools/xl/xl_cmdtable.c +19 -0
index 30eb93c..5ae2477 100644
@@ -372,6 +372,25 @@ struct cmd_spec cmd_table[] = {
       "Destroy a domain's virtual TPM device",
       "<Domain> <DevId|uuid>",
     },
+    { "vdispl-attach",
+      &main_vdisplattach, 1, 1,
+      "Create a new virtual display device",
+      "<Domain> [backend=<BackDomain>] [be-alloc=<BackAlloc>] [connectors='<Connectors>']",
+      "    BackAlloc  - set to 1 to if backend allocates display buffers\n"
+      "    Connectors - list of connector's description in ID:WxH format,\n"
+      "                 where: ID - unique connector ID, W - connector width,\n"
+      "                 H - connector height: connectors='id0:800x600;id1:1024x768'\n"
+    },
+    { "vdispl-list",
+      &main_vdispllist, 0, 0,
+      "List virtual display devices for a domain",
+      "<Domain(s)>",
+    },
+    { "vdispl-detach",
+      &main_vdispldetach, 0, 1,
+      "Destroy a domain's virtual display device",
+      "<Domain> <DevId>",
+    },
     { "uptime",
       &main_uptime, 0, 0,
       "Print uptime for all/some domains",
tools/xl/xl_parse.c +74 -1

93 lines not on this page · raw message

tools/xl/xl_parse.h +1 -1
index db8bc3f..cc459fb 100644
@@ -33,7 +33,7 @@ int parse_usbctrl_config(libxl_device_usbctrl *usbctrl, char *token);
 int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token);
 int parse_cpurange(const char *cpu, libxl_bitmap *cpumap);
 int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token);
-
+int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token);
 
 int match_option_size(const char *prefix, size_t len,
                       char *arg, char **argopt);
tools/xl/xl_vdispl.c new file +163 -0

163 lines not on this page · raw message

Signature · 7 lines
2.7.4


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

PATCH v4 5/13 docs: add PV display driver information

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 docs/man/xl.cfg.pod.5.in | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 docs/man/xl.pod.1.in     | 42 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)
docs/man/xl.cfg.pod.5.in +49 -0
index 13167ff..7eb5be4 100644
@@ -1096,6 +1096,55 @@ FIFO-based event channel ABI support up to 131,071 event channels.
 Other guests are limited to 4095 (64-bit x86 and ARM) or 1023 (32-bit
 x86).
 
+=item B<vdispl=[ "VDISPL_SPEC_STRING", "VDISPL_SPEC_STRING", ...]>
+
+Specifies the virtual display devices to be provided to the guest.
+
+Each B<VDISPL_SPEC_STRING> is a comma-separated list of C<KEY=VALUE>
+settings, from the following list:
+
+=over 4
+
+=item C<backend=DOMAIN>
+
+Specifies the backend domain name or id. If not specified Domain-0 is used.
+
+=item C<be-alloc=BOOLEAN>
+
+Indicates if backend can be a buffer provider/allocator for this domain. See
+display protocol for details.
+
+=item C<connectors=CONNECTORS>
+
+Specifies virtual connectors for the device in following format
+<id>:<W>x<H>;<id>:<W>x<H>... where:
+
+=over 4
+
+=item C<id>
+
+String connector ID. Space, comma symbols are not allowed.
+
+=item C<W>
+
+Connector width in pixels.
+
+=item C<H>
+
+Connector height in pixels.
+
+=back
+
+B<EXAMPLE>
+
+=over 4
+
+connectors=id0:1920x1080;id1:800x600;id2:640x480
+
+=back
+
+=back
+
 =back
 
 =head2 Paravirtualised (PV) Guest Specific Options
docs/man/xl.pod.1.in +42 -0

48 lines not on this page · raw message

Signature · 7 lines
2.7.4


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

PATCH v4 6/13 libxl: change p9 to use generec add function

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/libxl_9pfs.c     | 67 +++++++++++++++-----------------------------
 tools/libxl/libxl_create.c   |  2 +-
 tools/libxl/libxl_internal.h |  7 +----
 tools/libxl/libxl_types.idl  |  2 +-
 tools/xl/xl_parse.c          |  4 +--
 5 files changed, 28 insertions(+), 54 deletions(-)
tools/libxl/libxl_9pfs.c +23 -44
index 07e3e5f..394d8b4 100644
@@ -17,12 +17,10 @@
 
 #include "libxl_internal.h"
 
-int libxl__device_p9_setdefault(libxl__gc *gc, libxl_device_p9 *p9)
+static int libxl__device_p9_setdefault(libxl__gc *gc, uint32_t domid,
+                                       libxl_device_p9 *p9, bool hotplug)
 {
-    int rc;
-
-    rc = libxl__resolve_domid(gc, p9->backend_domname, &p9->backend_domid);
-    return rc;
+    return libxl__resolve_domid(gc, p9->backend_domname, &p9->backend_domid);
 }
 
 static int libxl__device_from_p9(libxl__gc *gc, uint32_t domid,
@@ -39,49 +37,30 @@ static int libxl__device_from_p9(libxl__gc *gc, uint32_t domid,
    return 0;
 }
 
-
-int libxl__device_p9_add(libxl__gc *gc, uint32_t domid,
-                         libxl_device_p9 *p9)
+static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t domid,
+                                  libxl_device_p9 *p9,
+                                  flexarray_t *back, flexarray_t *front,
+                                  flexarray_t *ro_front)
 {
-    flexarray_t *front;
-    flexarray_t *back;
-    libxl__device device;
-    int rc;
-
-    rc = libxl__device_p9_setdefault(gc, p9);
-    if (rc) goto out;
-
-    front = flexarray_make(gc, 16, 1);
-    back = flexarray_make(gc, 16, 1);
-
-    if (p9->devid == -1) {
-        if ((p9->devid = libxl__device_nextid(gc, domid, "9pfs")) < 0) {
-            rc = ERROR_FAIL;
-            goto out;
-        }
-    }
-
-    rc = libxl__device_from_p9(gc, domid, p9, &device);
-    if (rc != 0) goto out;
-
-    flexarray_append_pair(back, "frontend-id", libxl__sprintf(gc, "%d", domid));
-    flexarray_append_pair(back, "online", "1");
-    flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitialising));
-    flexarray_append_pair(front, "backend-id",
-                          libxl__sprintf(gc, "%d", p9->backend_domid));
-    flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateInitialising));
-    flexarray_append_pair(front, "tag", p9->tag);
     flexarray_append_pair(back, "path", p9->path);
     flexarray_append_pair(back, "security_model", p9->security_model);
 
-    libxl__device_generic_add(gc, XBT_NULL, &device,
-                              libxl__xs_kvs_of_flexarray(gc, back),
-                              libxl__xs_kvs_of_flexarray(gc, front),
-                              NULL);
-    rc = 0;
-out:
-    return rc;
+    flexarray_append_pair(front, "tag", p9->tag);
+
+    return 0;
 }
 
-LIBXL_DEFINE_DEVICE_REMOVE(p9)
+#define libxl__add_p9s NULL
+#define libxl_device_p9_list NULL
+#define libxl_device_p9_compare NULL
 
+LIBXL_DEFINE_DEVICE_REMOVE(p9)
+static LIBXL_DEFINE_UPDATE_DEVID(p9, "9pfs")
+
+DEFINE_DEVICE_TYPE_STRUCT(p9,
+    .skip_attach = 1,
+    .set_xenstore_config = (int (*)(libxl__gc *, uint32_t, void *,
+                                    flexarray_t *back, flexarray_t *front,
+                                    flexarray_t *ro_front))
+                           libxl__set_xenstore_p9
+);
tools/libxl/libxl_create.c +1 -1
index 912bd21..f483475 100644
@@ -1325,7 +1325,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
     }
 
     for (i = 0; i < d_config->num_p9s; i++)
-        libxl__device_p9_add(gc, domid, &d_config->p9[i]);
+        libxl__device_add(gc, domid, &libxl__p9_devtype, &d_config->p9s[i]);
 
     switch (d_config->c_info.type) {
     case LIBXL_DOMAIN_TYPE_HVM:
tools/libxl/libxl_internal.h +1 -6
index 68c08aa..c53bbd1 100644
@@ -1252,8 +1252,6 @@ _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb);
 _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
-_hidden int libxl__device_p9_setdefault(libxl__gc *gc,
-                                        libxl_device_p9 *p9);
 
 _hidden const char *libxl__device_nic_devname(libxl__gc *gc,
                                               uint32_t domid,
@@ -2668,10 +2666,6 @@ _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid,
                                   libxl_device_vfb *vfb);
 
-/* Internal function to connect a 9pfs device */
-_hidden int libxl__device_p9_add(libxl__gc *gc, uint32_t domid,
-                                 libxl_device_p9 *p9);
-
 /* Waits for the passed device to reach state XenbusStateInitWait.
  * This is not really useful by itself, but is important when executing
  * hotplug scripts, since we need to be sure the device is in the correct
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +1 -1
index 25563cf..96dbaed 100644
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),
     ("vdispls", Array(libxl_device_vdispl, "num_vdispls")),
     # a channel manifests as a console with a name,
     # see docs/misc/channels.txt
tools/xl/xl_parse.c +2 -2
index 2140905..19eadd9 100644
@@ -1419,9 +1419,9 @@ void parse_config_data(const char *config_source,
         char *p, *p2, *buf2;
 
         d_config->num_p9s = 0;
-        d_config->p9 = NULL;
+        d_config->p9s = NULL;
         while ((buf = xlu_cfg_get_listitem (p9devs, d_config->num_p9s)) != NULL) {
-            p9 = ARRAY_EXTEND_INIT(d_config->p9,
+            p9 = ARRAY_EXTEND_INIT(d_config->p9s,
                                    d_config->num_p9s,
                                    libxl_device_p9_init);
             libxl_device_p9_init(p9);
Signature · 7 lines
2.7.4


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

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

On Tue, Jul 18, 2017 at 05:25:23PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 16 lines

/* Waits for the passed device to reach state XenbusStateInitWait.
* This is not really useful by itself, but is important when executing
* hotplug scripts, since we need to be sure the device is in the correct

tools/libxl/libxl_internal.h +1 -0
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +0 -0
index 25563cf..96dbaed 100644

tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 807

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -1
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),

Oh, no, please don't do this. We can't change the name of the fields.

There is already on irregular device type -- the PCI device. I suppose you probably need another hook somewhere. And please convert PCI devices if you can.

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

#21 lore raw

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 26 lines · Wei Liu

On Tue, Jul 18, 2017 at 05:25:23PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 16 lines

/* Waits for the passed device to reach state XenbusStateInitWait.
* This is not really useful by itself, but is important when executing
* hotplug scripts, since we need to be sure the device is in the correct

tools/libxl/libxl_internal.h +1 -0
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +0 -0
index 25563cf..96dbaed 100644

tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 807

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -1
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),

Oh, no, please don't do this. We can't change the name of the fields.

Quoted 3 lines

There is already on irregular device type -- the PCI device. I suppose you probably need another hook somewhere. And please convert PCI devices if you can.

OK, going through the code I think we need to come to a conclusion if we want an extra callback to handle the irregular device names first because that's likely to affect the code of the framework in previous patch.

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

#22 lore raw

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 27 lines · Wei Liu
Quoted 26 lines · Wei Liu

On Tue, Jul 18, 2017 at 05:25:23PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 16 lines

/* Waits for the passed device to reach state XenbusStateInitWait.
* This is not really useful by itself, but is important when executing
* hotplug scripts, since we need to be sure the device is in the correct

tools/libxl/libxl_internal.h +1 -0
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +0 -0
index 25563cf..96dbaed 100644

tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 807

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -1
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),

Oh, no, please don't do this. We can't change the name of the fields.

Quoted 8 lines
Quoted 3 lines

There is already on irregular device type -- the PCI device. I suppose you probably need another hook somewhere. And please convert PCI devices if you can.

OK, going through the code I think we need to come to a conclusion if we want an extra callback to handle the irregular device names first because that's likely to affect the code of the framework in previous patch.

Actually creating new callback to handle irregular device name looks not so good.
There is the pattern which all namings should follow. May be it has to be documented
somewhere. p9 was added recently we can ask the author to review this rename. From other side this rename touches only internals changes: no changes in config file
or CLI interface.

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 37 lines · Oleksandr Grytsov
Quoted 27 lines · Wei Liu
Quoted 26 lines · Wei Liu

On Tue, Jul 18, 2017 at 05:25:23PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 16 lines

/* Waits for the passed device to reach state XenbusStateInitWait.
* This is not really useful by itself, but is important when executing
* hotplug scripts, since we need to be sure the device is in the correct

tools/libxl/libxl_internal.h +1 -0
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +0 -0
index 25563cf..96dbaed 100644

tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 807

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -1
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),

Oh, no, please don't do this. We can't change the name of the fields.

Quoted 8 lines
Quoted 3 lines

There is already on irregular device type -- the PCI device. I suppose you probably need another hook somewhere. And please convert PCI devices if you can.

OK, going through the code I think we need to come to a conclusion if we want an extra callback to handle the irregular device names first because that's likely to affect the code of the framework in previous patch.

Quoted 4 lines

Actually creating new callback to handle irregular device name looks not so good.
There is the pattern which all namings should follow. May be it has to be documented

The normal pattern is DEVTYPEs.

Quoted 1 line

somewhere. p9 was added recently we can ask the author to review this rename.

Once it is released we can't change it, of course unless we deem it unstable. I'm two minded here. P9 was released in 4.9, which was only a few months old.

But we definitely can't change the PCI type. It has been around since forever. And there is provision in code to deal with that.

Quoted 4 lines

From other side this rename touches only internals changes: no changes in config file
or CLI interface.

As said, the framework need to be ready to deal with PCI anyway.

What sort of issues do you foresee here?

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

#24 lore raw

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 43 lines · Wei Liu
Quoted 37 lines · Oleksandr Grytsov
Quoted 27 lines · Wei Liu
Quoted 26 lines · Wei Liu

On Tue, Jul 18, 2017 at 05:25:23PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 16 lines

/* Waits for the passed device to reach state XenbusStateInitWait.
* This is not really useful by itself, but is important when executing
* hotplug scripts, since we need to be sure the device is in the correct

tools/libxl/libxl_internal.h +1 -0
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +0 -0
index 25563cf..96dbaed 100644

tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 807

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -1
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),

Oh, no, please don't do this. We can't change the name of the fields.

Quoted 8 lines
Quoted 3 lines

There is already on irregular device type -- the PCI device. I suppose you probably need another hook somewhere. And please convert PCI devices if you can.

OK, going through the code I think we need to come to a conclusion if we want an extra callback to handle the irregular device names first because that's likely to affect the code of the framework in previous patch.

Quoted 4 lines

Actually creating new callback to handle irregular device name looks not so good.
There is the pattern which all namings should follow. May be it has to be documented

Quoted 8 lines

The normal pattern is DEVTYPEs.

Quoted 1 line

somewhere. p9 was added recently we can ask the author to review this rename.

Once it is released we can't change it, of course unless we deem it unstable. I'm two minded here. P9 was released in 4.9, which was only a few months old.

IMHO this the bug I mean wrong naming and it should be fixed.

Quoted 2 lines

But we definitely can't change the PCI type. It has been around since forever. And there is provision in code to deal with that.

Agree, I didn't touch PCI.

Quoted 8 lines
Quoted 4 lines

From other side this rename touches only internals changes: no changes in config file
or CLI interface.

As said, the framework need to be ready to deal with PCI anyway.

What sort of issues do you foresee here?

Do you mean in case to rework PCI to use the device framework?

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 65 lines · Oleksandr Grytsov
Quoted 43 lines · Wei Liu
Quoted 37 lines · Oleksandr Grytsov
Quoted 27 lines · Wei Liu
Quoted 26 lines · Wei Liu

On Tue, Jul 18, 2017 at 05:25:23PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 16 lines

/* Waits for the passed device to reach state XenbusStateInitWait.
* This is not really useful by itself, but is important when executing
* hotplug scripts, since we need to be sure the device is in the correct

tools/libxl/libxl_internal.h +1 -0
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +0 -0
index 25563cf..96dbaed 100644

tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 807

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -1
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),

Oh, no, please don't do this. We can't change the name of the fields.

Quoted 8 lines
Quoted 3 lines

There is already on irregular device type -- the PCI device. I suppose you probably need another hook somewhere. And please convert PCI devices if you can.

OK, going through the code I think we need to come to a conclusion if we want an extra callback to handle the irregular device names first because that's likely to affect the code of the framework in previous patch.

Quoted 4 lines

Actually creating new callback to handle irregular device name looks not so good.
There is the pattern which all namings should follow. May be it has to be documented

Quoted 8 lines

The normal pattern is DEVTYPEs.

Quoted 1 line

somewhere. p9 was added recently we can ask the author to review this rename.

Once it is released we can't change it, of course unless we deem it unstable. I'm two minded here. P9 was released in 4.9, which was only a few months old.

IMHO this the bug I mean wrong naming and it should be fixed.

Quoted 2 lines

But we definitely can't change the PCI type. It has been around since forever. And there is provision in code to deal with that.

Agree, I didn't touch PCI.

Quoted 5 lines
Quoted 4 lines

From other side this rename touches only internals changes: no changes in config file
or CLI interface.

Quoted 6 lines
Quoted 3 lines

As said, the framework need to be ready to deal with PCI anyway.

What sort of issues do you foresee here?

Do you mean in case to rework PCI to use the device framework?

No, I mean adding the new hook. You said "handle irregular device name looks not so good"

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

#26 lore raw

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 68 lines · Wei Liu
Quoted 67 lines · Oleksandr Grytsov
Quoted 43 lines · Wei Liu
Quoted 37 lines · Oleksandr Grytsov
Quoted 27 lines · Wei Liu
Quoted 26 lines · Wei Liu

On Tue, Jul 18, 2017 at 05:25:23PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 16 lines

/* Waits for the passed device to reach state XenbusStateInitWait.
* This is not really useful by itself, but is important when executing
* hotplug scripts, since we need to be sure the device is in the correct

(quoted diff) +1 -0
@@ -3565,6 +3559,7 @@ extern const struct libxl_device_type libxl__usbctrl_devtype;
 extern const struct libxl_device_type libxl__usbdev_devtype;
 extern const struct libxl_device_type libxl__pcidev_devtype;
 extern const struct libxl_device_type libxl__vdispl_devtype;
+extern const struct libxl_device_type libxl__p9_devtype;
 
 extern const struct libxl_device_type *device_type_tbl[];
 
tools/libxl/libxl_types.idl +0 -0
index 25563cf..96dbaed 100644

tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 807

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -1
@@ -804,7 +804,7 @@ libxl_domain_config = Struct("domain_config", [
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
-    ("p9", Array(libxl_device_p9, "num_p9s")),
+    ("p9s", Array(libxl_device_p9, "num_p9s")),

Oh, no, please don't do this. We can't change the name of the fields.

Quoted 8 lines
Quoted 3 lines

There is already on irregular device type -- the PCI device. I suppose you probably need another hook somewhere. And please convert PCI devices if you can.

OK, going through the code I think we need to come to a conclusion if we want an extra callback to handle the irregular device names first because that's likely to affect the code of the framework in previous patch.

Quoted 4 lines

Actually creating new callback to handle irregular device name looks not so good.
There is the pattern which all namings should follow. May be it has to be documented

Quoted 8 lines

The normal pattern is DEVTYPEs.

Quoted 1 line

somewhere. p9 was added recently we can ask the author to review this rename.

Once it is released we can't change it, of course unless we deem it unstable. I'm two minded here. P9 was released in 4.9, which was only a few months old.

IMHO this the bug I mean wrong naming and it should be fixed.

Quoted 2 lines

But we definitely can't change the PCI type. It has been around since forever. And there is provision in code to deal with that.

Agree, I didn't touch PCI.

Quoted 7 lines
Quoted 4 lines

From other side this rename touches only internals changes: no changes in config file
or CLI interface.

As said, the framework need to be ready to deal with PCI anyway.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

What sort of issues do you foresee here?

Do you mean in case to rework PCI to use the device framework?

No, I mean adding the new hook. You said "handle irregular device name looks not so good"

As for me when only internal name of structure or fields are changed then it should not break anyone configs, setup etc. Creating hooks in this case makes code hard to read and maintain.

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

On Wed, Aug 02, 2017 at 02:37:10PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

From other side this rename touches only internals changes: no changes in config file
or CLI interface.

As said, the framework need to be ready to deal with PCI anyway.

What sort of issues do you foresee here?

Do you mean in case to rework PCI to use the device framework?

Quoted 7 lines
Quoted 2 lines

No, I mean adding the new hook. You said "handle irregular device name looks not so good"

As for me when only internal name of structure or fields are changed then it should not break anyone configs, setup etc. Creating hooks in this case makes code hard to read and maintain.

I think you missed my points:

1. libxl types generated from libxl_types.idl aren't just used by xl. Some applications will use libxl types directly. Not breaking xl config doesn't mean not breaking other toolstacks like libvirt. In this particular case, I think we might be able to change p9 to p9s because it is only released a few months back because the only other known toolstack that uses libxl can't possibly use that field at the moment. But Ian might disagree.

2. There is another type, pci dev, that has been there since forever. We need a hook to deal with it, we can't rename it.

1 and 2 are orthogonal. 2 is a hard requirement.

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

#28 lore raw

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 24 lines · Wei Liu

On Wed, Aug 02, 2017 at 02:37:10PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

From other side this rename touches only internals changes: no changes in config file
or CLI interface.

As said, the framework need to be ready to deal with PCI anyway.

What sort of issues do you foresee here?

Do you mean in case to rework PCI to use the device framework?

Quoted 7 lines
Quoted 2 lines

No, I mean adding the new hook. You said "handle irregular device name looks not so good"

As for me when only internal name of structure or fields are changed then it should not break anyone configs, setup etc. Creating hooks in this case makes code hard to read and maintain.

I think you missed my points:

Quoted 7 lines

1. libxl types generated from libxl_types.idl aren't just used by xl. Some applications will use libxl types directly. Not breaking xl config doesn't mean not breaking other toolstacks like libvirt. In this particular case, I think we might be able to change p9 to p9s because it is only released a few months back because the only other known toolstack that uses libxl can't possibly use that field at the moment. But Ian might disagree.

I got it. I think that we have to change p9 to p9s ASAP to avoid future hooks.

Quoted 3 lines

2. There is another type, pci dev, that has been there since forever. We need a hook to deal with it, we can't rename it.

For PCI all hooks are already there (DEFINE_DEVICE_TYPE_STRUCT_X to handle pcidev and pci). Also I didn't change PCI fields, names etc. In libxl_domain_config it is already pcidevs. So, we are safe with PCI. Sorry I don't understand your concern about PCI. Or I miss something?

Quoted 1 line

1 and 2 are orthogonal. 2 is a hard requirement.

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

Re: [PATCH v4 06/13] libxl: change p9 to use generec add function

Quoted 35 lines · Oleksandr Grytsov
Quoted 24 lines · Wei Liu

On Wed, Aug 02, 2017 at 02:37:10PM +0300, Oleksandr Grytsov wrote:
[...]

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

From other side this rename touches only internals changes: no changes in config file
or CLI interface.

As said, the framework need to be ready to deal with PCI anyway.

What sort of issues do you foresee here?

Do you mean in case to rework PCI to use the device framework?

Quoted 7 lines
Quoted 2 lines

No, I mean adding the new hook. You said "handle irregular device name looks not so good"

As for me when only internal name of structure or fields are changed then it should not break anyone configs, setup etc. Creating hooks in this case makes code hard to read and maintain.

I think you missed my points:

Quoted 7 lines

1. libxl types generated from libxl_types.idl aren't just used by xl. Some applications will use libxl types directly. Not breaking xl config doesn't mean not breaking other toolstacks like libvirt. In this particular case, I think we might be able to change p9 to p9s because it is only released a few months back because the only other known toolstack that uses libxl can't possibly use that field at the moment. But Ian might disagree.

I got it. I think that we have to change p9 to p9s ASAP to avoid future hooks.

Quoted 8 lines
Quoted 3 lines

2. There is another type, pci dev, that has been there since forever. We need a hook to deal with it, we can't rename it.

For PCI all hooks are already there (DEFINE_DEVICE_TYPE_STRUCT_X to handle pcidev and pci). Also I didn't change PCI fields, names etc. In libxl_domain_config it is already pcidevs. So, we are safe with PCI. Sorry I don't understand your concern about PCI. Or I miss something?

Yes I think we're covered there. That macro only covers the case where new characters are appended.

I was thinking maybe we should have something that deal with new names weather they are longer or shorter than expected.

But I see now it is probably better to rename the p9 device. I will send out an email asking for opinions.

Quoted 7 lines
Quoted 2 lines

1 and 2 are orthogonal. 2 is a hard requirement.

Signature · 2 lines
Best Regards,
Oleksandr Grytsov.

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

#31 lore raw

PATCH v4 7/13 libxl: change vkb to use generec add function

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/libxl_console.c  | 79 ++++++++------------------------------------
 tools/libxl/libxl_create.c   |  5 +--
 tools/libxl/libxl_dm.c       |  3 +-
 tools/libxl/libxl_internal.h |  6 +---
 4 files changed, 19 insertions(+), 74 deletions(-)
tools/libxl/libxl_console.c +13 -66
index 446e766..48fccec 100644
@@ -583,11 +583,10 @@ int libxl_device_channel_getinfo(libxl_ctx *ctx, uint32_t domid,
     return rc;
 }
 
-int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb)
+static int libxl__device_vkb_setdefault(libxl__gc *gc, uint32_t domid,
+                                        libxl_device_vkb *vkb, bool hotplug)
 {
-    int rc;
-    rc = libxl__resolve_domid(gc, vkb->backend_domname, &vkb->backend_domid);
-    return rc;
+    return libxl__resolve_domid(gc, vkb->backend_domname, &vkb->backend_domid);
 }
 
 static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,
@@ -604,68 +603,6 @@ static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
-int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
-                         const libxl_asyncop_how *ao_how)
-{
-    AO_CREATE(ctx, domid, ao_how);
-    int rc;
-
-    rc = libxl__device_vkb_add(gc, domid, vkb);
-    if (rc) {
-        LOGD(ERROR, domid, "Unable to add vkb device");
-        goto out;
-    }
-
-out:
-    libxl__ao_complete(egc, ao, rc);
-    return AO_INPROGRESS;
-}
-
-int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
-                          libxl_device_vkb *vkb)
-{
-    flexarray_t *front;
-    flexarray_t *back;
-    libxl__device device;
-    int rc;
-
-    rc = libxl__device_vkb_setdefault(gc, vkb);
-    if (rc) goto out;
-
-    front = flexarray_make(gc, 16, 1);
-    back = flexarray_make(gc, 16, 1);
-
-    if (vkb->devid == -1) {
-        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb")) < 0) {
-            rc = ERROR_FAIL;
-            goto out;
-        }
-    }
-
-    rc = libxl__device_from_vkb(gc, domid, vkb, &device);
-    if (rc != 0) goto out;
-
-    flexarray_append(back, "frontend-id");
-    flexarray_append(back, GCSPRINTF("%d", domid));
-    flexarray_append(back, "online");
-    flexarray_append(back, "1");
-    flexarray_append(back, "state");
-    flexarray_append(back, GCSPRINTF("%d", XenbusStateInitialising));
-
-    flexarray_append(front, "backend-id");
-    flexarray_append(front, GCSPRINTF("%d", vkb->backend_domid));
-    flexarray_append(front, "state");
-    flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising));
-
-    libxl__device_generic_add(gc, XBT_NULL, &device,
-                              libxl__xs_kvs_of_flexarray(gc, back),
-                              libxl__xs_kvs_of_flexarray(gc, front),
-                              NULL);
-    rc = 0;
-out:
-    return rc;
-}
-
 int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb)
 {
     int rc;
@@ -789,7 +726,17 @@ out:
  * 2. dynamically add/remove qemu chardevs via qmp messages. */
 
 /* vkb */
+
+#define libxl__add_vkbs NULL
+#define libxl_device_vkb_list NULL
+#define libxl_device_vkb_compare NULL
+
 LIBXL_DEFINE_DEVICE_REMOVE(vkb)
+static LIBXL_DEFINE_UPDATE_DEVID(vkb, "vkbd")
+
+DEFINE_DEVICE_TYPE_STRUCT(vkb,
+    .skip_attach = 1
+);
 
 /* vfb */
 LIBXL_DEFINE_DEVICE_REMOVE(vfb)
tools/libxl/libxl_create.c +3 -2
index f483475..9634811 100644
@@ -1346,7 +1346,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         }
 
         libxl_device_vkb_init(&vkb);
-        libxl__device_vkb_add(gc, domid, &vkb);
+        libxl__device_add(gc, domid, &libxl__vkb_devtype, &vkb);
         libxl_device_vkb_dispose(&vkb);
 
         dcs->sdss.dm.guest_domid = domid;
@@ -1372,7 +1372,8 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
 
         for (i = 0; i < d_config->num_vfbs; i++) {
             libxl__device_vfb_add(gc, domid, &d_config->vfbs[i]);
-            libxl__device_vkb_add(gc, domid, &d_config->vkbs[i]);
+            libxl__device_add(gc, domid, &libxl__vkb_devtype,
+                              &d_config->vkbs[i]);
         }
 
         init_console_info(gc, &console, 0);
tools/libxl/libxl_dm.c +2 -1
index 44ebd70..b37f47e 100644
@@ -1978,7 +1978,8 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
     ret = libxl__device_vfb_add(gc, dm_domid, &dm_config->vfbs[0]);
     if (ret)
         goto out;
-    ret = libxl__device_vkb_add(gc, dm_domid, &dm_config->vkbs[0]);
+    ret = libxl__device_add(gc, dm_domid, &libxl__vkb_devtype,
+                            &dm_config->vkbs[0]);
     if (ret)
         goto out;
 
tools/libxl/libxl_internal.h +1 -5
index c53bbd1..49440d7 100644
@@ -1248,7 +1248,6 @@ _hidden int libxl__device_disk_setdefault(libxl__gc *gc,
 _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,
                                          uint32_t domid, bool hotplug);
 _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
-_hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb);
 _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
@@ -2658,10 +2657,6 @@ struct libxl__multidev {
  * it's a valid state.
  */
 
-/* Internal function to connect a vkb device */
-_hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_vkb *vkb);
-
 /* Internal function to connect a vfb device */
 _hidden int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid,
                                   libxl_device_vfb *vfb);
@@ -3552,6 +3547,7 @@ static inline int *libxl__device_type_get_num(
     return (int *)((void *)d_config + dt->num_offset);
 }
 
+extern const struct libxl_device_type libxl__vkb_devtype;
 extern const struct libxl_device_type libxl__disk_devtype;
 extern const struct libxl_device_type libxl__nic_devtype;
 extern const struct libxl_device_type libxl__vtpm_devtype;
Signature · 7 lines
2.7.4


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

PATCH v4 8/13 libxl: change vfb to use generec add function

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/libxl_console.c  | 74 ++++++++++++--------------------------------
 tools/libxl/libxl_create.c   |  3 +-
 tools/libxl/libxl_dm.c       |  3 +-
 tools/libxl/libxl_internal.h |  6 +---
 4 files changed, 25 insertions(+), 61 deletions(-)
tools/libxl/libxl_console.c +20 -54
index 48fccec..4aae82c 100644
@@ -603,7 +603,8 @@ static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
-int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb)
+static int libxl__device_vfb_setdefault(libxl__gc *gc, uint32_t domid,
+                                        libxl_device_vfb *vfb, bool hotplug)
 {
     int rc;
 
@@ -639,49 +640,11 @@ static int libxl__device_from_vfb(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
-int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
-                         const libxl_asyncop_how *ao_how)
+static int libxl__set_xenstore_vfb(libxl__gc *gc, uint32_t domid,
+                                   libxl_device_vfb *vfb,
+                                  flexarray_t *back, flexarray_t *front,
+                                  flexarray_t *ro_front)
 {
-    AO_CREATE(ctx, domid, ao_how);
-    int rc;
-
-    rc = libxl__device_vfb_add(gc, domid, vfb);
-    if (rc) {
-        LOGD(ERROR, domid, "Unable to add vfb device");
-        goto out;
-    }
-
-out:
-    libxl__ao_complete(egc, ao, rc);
-    return AO_INPROGRESS;
-}
-
-int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
-{
-    flexarray_t *front;
-    flexarray_t *back;
-    libxl__device device;
-    int rc;
-
-    rc = libxl__device_vfb_setdefault(gc, vfb);
-    if (rc) goto out;
-
-    front = flexarray_make(gc, 16, 1);
-    back = flexarray_make(gc, 16, 1);
-
-    if (vfb->devid == -1) {
-        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb")) < 0) {
-            rc = ERROR_FAIL;
-            goto out;
-        }
-    }
-
-    rc = libxl__device_from_vfb(gc, domid, vfb, &device);
-    if (rc != 0) goto out;
-
-    flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid));
-    flexarray_append_pair(back, "online", "1");
-    flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitialising));
     flexarray_append_pair(back, "vnc",
                           libxl_defbool_val(vfb->vnc.enable) ? "1" : "0");
     flexarray_append_pair(back, "vnclisten", vfb->vnc.listen);
@@ -701,17 +664,7 @@ int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
         flexarray_append_pair(back, "display", vfb->sdl.display);
     }
 
-    flexarray_append_pair(front, "backend-id",
-                          GCSPRINTF("%d", vfb->backend_domid));
-    flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateInitialising));
-
-    libxl__device_generic_add(gc, XBT_NULL, &device,
-                              libxl__xs_kvs_of_flexarray(gc, back),
-                              libxl__xs_kvs_of_flexarray(gc, front),
-                              NULL);
-    rc = 0;
-out:
-    return rc;
+    return 0;
 }
 
 /* The following functions are defined:
@@ -738,8 +691,21 @@ DEFINE_DEVICE_TYPE_STRUCT(vkb,
     .skip_attach = 1
 );
 
+#define libxl__add_vfbs NULL
+#define libxl_device_vfb_list NULL
+#define libxl_device_vfb_compare NULL
+
 /* vfb */
 LIBXL_DEFINE_DEVICE_REMOVE(vfb)
+static LIBXL_DEFINE_UPDATE_DEVID(vfb, "vfb")
+
+DEFINE_DEVICE_TYPE_STRUCT(vfb,
+    .skip_attach = 1,
+    .set_xenstore_config = (int (*)(libxl__gc *, uint32_t, void *,
+                                    flexarray_t *back, flexarray_t *front,
+                                    flexarray_t *ro_front))
+                           libxl__set_xenstore_vfb
+);
 
 libxl_xen_console_reader *
     libxl_xen_console_read_start(libxl_ctx *ctx, int clear)
tools/libxl/libxl_create.c +2 -1
index 9634811..8089713 100644
@@ -1371,7 +1371,8 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         libxl__device device;
 
         for (i = 0; i < d_config->num_vfbs; i++) {
-            libxl__device_vfb_add(gc, domid, &d_config->vfbs[i]);
+            libxl__device_add(gc, domid, &libxl__vfb_devtype,
+                              &d_config->vfbs[i]);
             libxl__device_add(gc, domid, &libxl__vkb_devtype,
                               &d_config->vkbs[i]);
         }
tools/libxl/libxl_dm.c +2 -1
index b37f47e..0a4f811 100644
@@ -1975,7 +1975,8 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
         if (ret)
             goto out;
     }
-    ret = libxl__device_vfb_add(gc, dm_domid, &dm_config->vfbs[0]);
+    ret = libxl__device_add(gc, dm_domid, &libxl__vfb_devtype,
+                            &dm_config->vfbs[0]);
     if (ret)
         goto out;
     ret = libxl__device_add(gc, dm_domid, &libxl__vkb_devtype,
tools/libxl/libxl_internal.h +1 -5
index 49440d7..36b4d1e 100644
@@ -1247,7 +1247,6 @@ _hidden int libxl__device_disk_setdefault(libxl__gc *gc,
                                           uint32_t domid);
 _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,
                                          uint32_t domid, bool hotplug);
-_hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
 _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
@@ -2657,10 +2656,6 @@ struct libxl__multidev {
  * it's a valid state.
  */
 
-/* Internal function to connect a vfb device */
-_hidden int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_vfb *vfb);
-
 /* Waits for the passed device to reach state XenbusStateInitWait.
  * This is not really useful by itself, but is important when executing
  * hotplug scripts, since we need to be sure the device is in the correct
@@ -3547,6 +3542,7 @@ static inline int *libxl__device_type_get_num(
     return (int *)((void *)d_config + dt->num_offset);
 }
 
+extern const struct libxl_device_type libxl__vfb_devtype;
 extern const struct libxl_device_type libxl__vkb_devtype;
 extern const struct libxl_device_type libxl__disk_devtype;
 extern const struct libxl_device_type libxl__nic_devtype;
Signature · 7 lines
2.7.4


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

PATCH v4 9/13 libxl: change disk to use generic getting list functions

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/libxl.h                   |  9 +++-
 tools/libxl/libxl_checkpoint_device.c |  7 ++-
 tools/libxl/libxl_create.c            |  3 +-
 tools/libxl/libxl_disk.c              | 94 ++++++++++-------------------------
 tools/libxl/libxl_internal.h          |  7 ---
 tools/ocaml/libs/xl/xenlight_stubs.c  |  3 +-
 tools/xl/xl_block.c                   |  3 +-
 7 files changed, 40 insertions(+), 86 deletions(-)
tools/libxl/libxl.h +7 -2
index 4c0d612..991b947 100644
@@ -1723,9 +1723,14 @@ int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid,
                               const libxl_asyncop_how *ao_how)
                               LIBXL_EXTERNAL_CALLERS_ONLY;
 
-libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num);
+libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx,
+                                          uint32_t domid, int *num)
+                                          LIBXL_EXTERNAL_CALLERS_ONLY;
+void libxl_device_disk_list_free(libxl_device_disk* list, int num)
+                                 LIBXL_EXTERNAL_CALLERS_ONLY;
 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
-                              libxl_device_disk *disk, libxl_diskinfo *diskinfo);
+                              libxl_device_disk *disk, libxl_diskinfo *diskinfo)
+                              LIBXL_EXTERNAL_CALLERS_ONLY;
 
 /*
  * Insert a CD-ROM device. A device corresponding to disk must already
tools/libxl/libxl_checkpoint_device.c +3 -4
index 01e74b5..7bd832b 100644
@@ -66,7 +66,8 @@ void libxl__checkpoint_devices_setup(libxl__egc *egc,
         cds->nics = libxl_device_nic_list(CTX, cds->domid, &cds->num_nics);
 
     if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VBD))
-        cds->disks = libxl_device_disk_list(CTX, cds->domid, &cds->num_disks);
+        cds->disks = libxl__device_list(gc, &libxl__disk_devtype, cds->domid,
+                                        "disk", &cds->num_disks);
 
     if (cds->num_nics == 0 && cds->num_disks == 0)
         goto out;
@@ -221,9 +222,7 @@ static void devices_teardown_cb(libxl__egc *egc,
     cds->num_nics = 0;
 
     /* clean disk */
-    for (i = 0; i < cds->num_disks; i++)
-        libxl_device_disk_dispose(&cds->disks[i]);
-    free(cds->disks);
+    libxl__device_list_free(&libxl__vdispl_devtype, cds->disks, cds->num_disks);
     cds->disks = NULL;
     cds->num_disks = 0;
 
tools/libxl/libxl_create.c +2 -1
index 8089713..569ff25 100644
@@ -936,7 +936,8 @@ static void initiate_domain_create(libxl__egc *egc,
     store_libxl_entry(gc, domid, &d_config->b_info);
 
     for (i = 0; i < d_config->num_disks; i++) {
-        ret = libxl__device_disk_setdefault(gc, &d_config->disks[i], domid);
+        ret = libxl__disk_devtype.set_default(gc, domid, &d_config->disks[i],
+                                              false);
         if (ret) {
             LOGD(ERROR, domid, "Unable to set disk defaults for disk %d", i);
             goto error_out;
tools/libxl/libxl_disk.c +26 -68

178 lines not on this page · raw message

tools/libxl/libxl_internal.h +0 -7
index 36b4d1e..9f8b56a 100644
@@ -1242,9 +1242,6 @@ _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
                                         libxl_domain_create_info *c_info);
 _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info);
-_hidden int libxl__device_disk_setdefault(libxl__gc *gc,
-                                          libxl_device_disk *disk,
-                                          uint32_t domid);
 _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,
                                          uint32_t domid, bool hotplug);
 _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
@@ -1755,10 +1752,6 @@ _hidden char *libxl__blktap_devpath(libxl__gc *gc,
  */
 _hidden int libxl__device_destroy_tapdisk(libxl__gc *gc, const char *params);
 
-_hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
-                                   const libxl_device_disk *disk,
-                                   libxl__device *device);
-
 /* Calls poll() again - useful to check whether a signaled condition
  * is still true.  Cannot fail.  Returns currently-true revents. */
 _hidden short libxl__fd_poll_recheck(libxl__egc *egc, int fd, short events);
tools/ocaml/libs/xl/xenlight_stubs.c +1 -2
index 98b52b9..55f09d7 100644
@@ -763,9 +763,8 @@ value stub_xl_device_disk_list(value ctx, value domid)
 		Field(list, 1) = temp;
 		temp = list;
 		Store_field(list, 0, Val_device_disk(&c_list[i]));
-		libxl_device_disk_dispose(&c_list[i]);
 	}
-	free(c_list);
+	libxl_device_disk_list_free(c_list, nb);
 
 	CAMLreturn(list);
 }
tools/xl/xl_block.c +1 -2
index da337ef..acaf9b9 100644
@@ -88,9 +88,8 @@ int main_blocklist(int argc, char **argv)
                        diskinfo.state, diskinfo.evtch, diskinfo.rref, diskinfo.backend);
                 libxl_diskinfo_dispose(&diskinfo);
             }
-            libxl_device_disk_dispose(&disks[i]);
         }
-        free(disks);
+        libxl_device_disk_list_free(disks, nb);
     }
     return 0;
 }
Signature · 7 lines
2.7.4


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

Re: [PATCH v4 09/13] libxl: change disk to use generic getting list functions

Quoted 2 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

[...]

Quoted 17 lines

/*
* Insert a CD-ROM device. A device corresponding to disk must already

tools/libxl/libxl_checkpoint_device.c +2 -1
index 01e74b5..7bd832b 100644
@@ -66,7 +66,8 @@ void libxl__checkpoint_devices_setup(libxl__egc *egc,
         cds->nics = libxl_device_nic_list(CTX, cds->domid, &cds->num_nics);
 
     if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VBD))
-        cds->disks = libxl_device_disk_list(CTX, cds->domid, &cds->num_disks);
+        cds->disks = libxl__device_list(gc, &libxl__disk_devtype, cds->domid,
+                                        "disk", &cds->num_disks);
 
     if (cds->num_nics == 0 && cds->num_disks == 0)
         goto out;

tools/libxl/libxl_checkpoint_device.c static void devices_teardown_cb(libxl__egc *egc, · line 225

Quoted 7 lines
tools/libxl/libxl_checkpoint_device.c +1 -3
@@ -221,9 +222,7 @@ static void devices_teardown_cb(libxl__egc *egc,
     cds->num_nics = 0;
 
     /* clean disk */
-    for (i = 0; i < cds->num_disks; i++)
-        libxl_device_disk_dispose(&cds->disks[i]);
-    free(cds->disks);
+    libxl__device_list_free(&libxl__vdispl_devtype, cds->disks, cds->num_disks);

Wrong type.

Quoted 3 lines
tools/libxl/libxl_checkpoint_device.c +0 -0
     cds->disks = NULL;
     cds->num_disks = 0;
 

[...]

tools/libxl/libxl_checkpoint_device.c static int libxl_device_disk_dm_needed(void *e, unsigned domid) · line 1210

Quoted 8 lines
tools/libxl/libxl_checkpoint_device.c +3 -1
@@ -1249,7 +1205,9 @@ static int libxl_device_disk_dm_needed(void *e, unsigned domid)
 DEFINE_DEVICE_TYPE_STRUCT(disk,
     .merge       = libxl_device_disk_merge,
     .dm_needed   = libxl_device_disk_dm_needed,
-    .skip_attach = 1
+    .from_xenstore = (int (*)(libxl__gc *, const char *, libxl_devid, void *))
+                     libxl__disk_from_xenstore,
+  .skip_attach = 1

Unrelated change.

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

#37 lore raw

PATCH v4 10/13 libxl: change nic to use generec add function

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/libxl.h                   |   9 +-
 tools/libxl/libxl_checkpoint_device.c |   9 +-
 tools/libxl/libxl_colo_save.c         |   4 +-
 tools/libxl/libxl_dm.c                |   4 +-
 tools/libxl/libxl_internal.h          |   2 -
 tools/libxl/libxl_nic.c               | 212 +++++++---------------------------
 tools/ocaml/libs/xl/xenlight_stubs.c  |   3 +-
 tools/xl/xl_nic.c                     |   3 +-
 8 files changed, 59 insertions(+), 187 deletions(-)
tools/libxl/libxl.h +7 -2
index 991b947..4a29b43 100644
@@ -1824,9 +1824,14 @@ int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid,
                              const libxl_asyncop_how *ao_how)
                              LIBXL_EXTERNAL_CALLERS_ONLY;
 
-libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num);
+libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx,
+                                        uint32_t domid, int *num)
+                                        LIBXL_EXTERNAL_CALLERS_ONLY;
+void libxl_device_nic_list_free(libxl_device_nic* list, int num)
+                                LIBXL_EXTERNAL_CALLERS_ONLY;
 int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
-                              libxl_device_nic *nic, libxl_nicinfo *nicinfo);
+                             libxl_device_nic *nic, libxl_nicinfo *nicinfo)
+                             LIBXL_EXTERNAL_CALLERS_ONLY;
 
 /*
  * Virtual Channels
tools/libxl/libxl_checkpoint_device.c +3 -6
index 7bd832b..eb9c604 100644
@@ -63,7 +63,8 @@ void libxl__checkpoint_devices_setup(libxl__egc *egc,
     cds->num_disks = 0;
 
     if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VIF))
-        cds->nics = libxl_device_nic_list(CTX, cds->domid, &cds->num_nics);
+        cds->nics = libxl__device_list(gc, &libxl__nic_devtype, cds->domid,
+                                       "vif", &cds->num_nics);
 
     if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VBD))
         cds->disks = libxl__device_list(gc, &libxl__disk_devtype, cds->domid,
@@ -206,8 +207,6 @@ static void devices_teardown_cb(libxl__egc *egc,
                                 libxl__multidev *multidev,
                                 int rc)
 {
-    int i;
-
     STATE_AO_GC(multidev->ao);
 
     /* Convenience aliases */
@@ -215,9 +214,7 @@ static void devices_teardown_cb(libxl__egc *egc,
                             CONTAINER_OF(multidev, *cds, multidev);
 
     /* clean nic */
-    for (i = 0; i < cds->num_nics; i++)
-        libxl_device_nic_dispose(&cds->nics[i]);
-    free(cds->nics);
+    libxl__device_list_free(&libxl__nic_devtype, cds->nics, cds->num_nics);
     cds->nics = NULL;
     cds->num_nics = 0;
 
tools/libxl/libxl_colo_save.c +3 -1
index f687d5a..8a9d37a 100644
@@ -87,6 +87,7 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
     libxl__srm_save_autogen_callbacks *const callbacks =
         &dss->sws.shs.callbacks.save.a;
     libxl_device_nic *nics;
+    int nb;
 
     STATE_AO_GC(dss->ao);
 
@@ -122,9 +123,10 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
         cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD);
 
         /* Use this args we can connect to qemu colo-compare */
-        nics = libxl_device_nic_list(CTX, cds->domid, &cds->num_nics);
+        nics = libxl_device_nic_list(CTX, cds->domid, &nb);
         css->cps.checkpoint_host = nics->colo_checkpoint_host;
         css->cps.checkpoint_port = nics->colo_checkpoint_port;
+        libxl_device_nic_list_free(nics, nb);
     } else {
         cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VIF) |
                                  (1 << LIBXL__DEVICE_KIND_VBD);
tools/libxl/libxl_dm.c +2 -2
index 0a4f811..eee4c98 100644
@@ -1970,8 +1970,8 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
          * called libxl_device_nic_add at this point, but qemu needs
          * the nic information to be complete.
          */
-        ret = libxl__device_nic_setdefault(gc, &dm_config->nics[i], dm_domid,
-                                           false);
+        ret = libxl__nic_devtype.set_default(gc, dm_domid, &dm_config->nics[i],
+                                             false);
         if (ret)
             goto out;
     }
tools/libxl/libxl_internal.h +0 -2
index 9f8b56a..4b1c5ab 100644
@@ -1242,8 +1242,6 @@ _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
                                         libxl_domain_create_info *c_info);
 _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info);
-_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,
-                                         uint32_t domid, bool hotplug);
 _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
tools/libxl/libxl_nic.c +42 -170

295 lines not on this page · raw message

tools/ocaml/libs/xl/xenlight_stubs.c +1 -2
index 55f09d7..badf9c9 100644
@@ -734,9 +734,8 @@ value stub_xl_device_nic_list(value ctx, value domid)
 		Field(list, 1) = temp;
 		temp = list;
 		Store_field(list, 0, Val_device_nic(&c_list[i]));
-		libxl_device_nic_dispose(&c_list[i]);
 	}
-	free(c_list);
+	libxl_device_nic_list_free(c_list, nb)
 
 	CAMLreturn(list);
 }
tools/xl/xl_nic.c +1 -2
index a78d944..2315dcd 100644
@@ -124,9 +124,8 @@ int main_networklist(int argc, char **argv)
                        nicinfo.rref_tx, nicinfo.rref_rx, nicinfo.backend);
                 libxl_nicinfo_dispose(&nicinfo);
             }
-            libxl_device_nic_dispose(&nics[i]);
         }
-        free(nics);
+        libxl_device_nic_list_free(nics, nb);
     }
     return 0;
 }
Signature · 7 lines
2.7.4


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

Re: [PATCH v4 10/13] libxl: change nic to use generec add function

Quoted 8 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

tools/libxl/libxl_nic.c +0 -0
index dd07a6c..16a6c8c 100644

tools/libxl/libxl_nic.c line 29

Quoted 10 lines
tools/libxl/libxl_nic.c +3 -0
@@ -20,15 +20,18 @@
 int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                             const char *mac, libxl_device_nic *nic)
 {
+    GC_INIT(ctx);
     libxl_device_nic *nics;
     int nb, rc, i;
     libxl_mac mac_n;
 
+    libxl_device_nic_init(nic);
+

Why is this change introduced?

This is changing the behaviour of the API.

To be clear I don't think its original behaviour is desirable. But if you are to change it, please make a separate patch.

tools/libxl/libxl_nic.c line 37

Quoted 9 lines
tools/libxl/libxl_nic.c +1 -1
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
         return rc;
 
-    nics = libxl_device_nic_list(ctx, domid, &nb);
+    nics = libxl__device_list(gc, &libxl__nic_devtype, domid, "vif", &nb);
     if (!nics)
         return ERROR_FAIL;
 

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

#39 lore raw

Re: [PATCH v4 10/13] libxl: change nic to use generec add function

Quoted 22 lines · Wei Liu
Quoted 8 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

tools/libxl/libxl_nic.c +0 -0
index dd07a6c..16a6c8c 100644

tools/libxl/libxl_nic.c line 29

Quoted 10 lines
tools/libxl/libxl_nic.c +3 -0
@@ -20,15 +20,18 @@
 int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                             const char *mac, libxl_device_nic *nic)
 {
+    GC_INIT(ctx);
     libxl_device_nic *nics;
     int nb, rc, i;
     libxl_mac mac_n;
 
+    libxl_device_nic_init(nic);
+

Why is this change introduced?

Quoted 4 lines

This is changing the behaviour of the API.

To be clear I don't think its original behaviour is desirable. But if you are to change it, please make a separate patch.

Yes, the behavior is changed. I will revert these changes.

Quoted 9 lines
Quoted 9 lines
tools/libxl/libxl_nic.c +1 -1
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
         return rc;
 
-    nics = libxl_device_nic_list(ctx, domid, &nb);
+    nics = libxl__device_list(gc, &libxl__nic_devtype, domid, "vif", &nb);
     if (!nics)
         return ERROR_FAIL;
 
Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

PATCH v4 11/13 libxl: change vtpm to use generec add function

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/libxl.h      |  12 ++-
 tools/libxl/libxl_vtpm.c | 231 +++++++++++++----------------------------------
 tools/xl/xl_vtpm.c       |   3 +-
 3 files changed, 73 insertions(+), 173 deletions(-)
tools/libxl/libxl.h +7 -5
index 4a29b43..c169eff 100644
@@ -1580,9 +1580,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
                                 int *nb_vcpu, int *nr_cpus_out);
 void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int nr_vcpus);
 
-void libxl_device_vtpm_list_free(libxl_device_vtpm*, int nr_vtpms);
-void libxl_vtpminfo_list_free(libxl_vtpminfo *, int nr_vtpms);
-
 /*
  * Devices
  * =======
@@ -1857,9 +1854,14 @@ int libxl_device_vtpm_destroy(libxl_ctx *ctx, uint32_t domid,
                               const libxl_asyncop_how *ao_how)
                               LIBXL_EXTERNAL_CALLERS_ONLY;
 
-libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *num);
+libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx,
+                                          uint32_t domid, int *num)
+                                          LIBXL_EXTERNAL_CALLERS_ONLY;
+void libxl_device_vtpm_list_free(libxl_device_vtpm*, int num)
+                                 LIBXL_EXTERNAL_CALLERS_ONLY;
 int libxl_device_vtpm_getinfo(libxl_ctx *ctx, uint32_t domid,
-                               libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo);
+                              libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo)
+                              LIBXL_EXTERNAL_CALLERS_ONLY;
 
 /* Virtual displays */
 int libxl_device_vdispl_add(libxl_ctx *ctx, uint32_t domid,
tools/libxl/libxl_vtpm.c +65 -166

307 lines not on this page · raw message

tools/xl/xl_vtpm.c +1 -2
index 6f56be0..0ba5041 100644
@@ -105,9 +105,8 @@ int main_vtpmlist(int argc, char **argv)
 
               libxl_vtpminfo_dispose(&vtpminfo);
            }
-           libxl_device_vtpm_dispose(&vtpms[i]);
         }
-        free(vtpms);
+        libxl_device_vtpm_list_free(vtpms, nb);
     }
     return 0;
 }
Signature · 7 lines
2.7.4


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

PATCH v4 12/13 libxl: remove unneeded DEVICE_ADD macro

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

---
 tools/libxl/libxl_device.c   |  6 ++---
 tools/libxl/libxl_disk.c     |  5 +++--
 tools/libxl/libxl_internal.h | 52 +++-----------------------------------------
 tools/libxl/libxl_pci.c      |  3 ++-
 tools/libxl/libxl_usb.c      |  8 +++----
 5 files changed, 14 insertions(+), 60 deletions(-)
tools/libxl/libxl_device.c +2 -4
index f1d4848..ca7b165 100644
@@ -1793,10 +1793,8 @@ out:
     return AO_CREATE_FAIL(rc);
 }
 
-static void device_add_domain_config(libxl__gc *gc,
-                                     libxl_domain_config *d_config,
-                                     const struct libxl_device_type *dt,
-                                     void *type)
+void device_add_domain_config(libxl__gc *gc, libxl_domain_config *d_config,
+                              const struct libxl_device_type *dt, void *type)
 {
     int *num_dev;
     int i;
tools/libxl/libxl_disk.c +3 -2
index f4f10cb..c41c7b5 100644
@@ -277,7 +277,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         rc = libxl__get_domain_configuration(gc, domid, &d_config);
         if (rc) goto out;
 
-        DEVICE_ADD(disk, disks, domid, &disk_saved, COMPARE_DISK, &d_config);
+        device_add_domain_config(gc, &d_config, &libxl__disk_devtype,
+                                 &disk_saved);
 
         rc = libxl__dm_check_start(gc, &d_config, domid);
         if (rc) goto out;
@@ -832,7 +833,7 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
     rc = libxl__get_domain_configuration(gc, domid, &d_config);
     if (rc) goto out;
 
-    DEVICE_ADD(disk, disks, domid, &disk_saved, COMPARE_DISK, &d_config);
+    device_add_domain_config(gc, &d_config, &libxl__disk_devtype, &disk_saved);
 
     rc = libxl__dm_check_start(gc, &d_config, domid);
     if (rc) goto out;
tools/libxl/libxl_internal.h +3 -49

64 lines not on this page · raw message

tools/libxl/libxl_pci.c +2 -1
index c3f1e5c..159d046 100644
@@ -160,7 +160,8 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_d
     rc = libxl__get_domain_configuration(gc, domid, &d_config);
     if (rc) goto out;
 
-    DEVICE_ADD(pci, pcidevs, domid, &pcidev_saved, COMPARE_PCI, &d_config);
+    device_add_domain_config(gc, &d_config, &libxl__pcidev_devtype,
+                             &pcidev_saved);
 
     rc = libxl__dm_check_start(gc, &d_config, domid);
     if (rc) goto out;
tools/libxl/libxl_usb.c +4 -4
index 07fb202..e526c08 100644
@@ -245,8 +245,8 @@ static int libxl__device_usbctrl_add_xenstore(libxl__gc *gc, uint32_t domid,
         rc = libxl__get_domain_configuration(gc, domid, &d_config);
         if (rc) goto out;
 
-        DEVICE_ADD(usbctrl, usbctrls, domid, &usbctrl_saved,
-                   COMPARE_USBCTRL, &d_config);
+        device_add_domain_config(gc, &d_config, &libxl__usbctrl_devtype,
+                                 &usbctrl_saved);
 
         rc = libxl__dm_check_start(gc, &d_config, domid);
         if (rc) goto out;
@@ -1199,8 +1199,8 @@ static int libxl__device_usbdev_add_xenstore(libxl__gc *gc, uint32_t domid,
         rc = libxl__get_domain_configuration(gc, domid, &d_config);
         if (rc) goto out;
 
-        DEVICE_ADD(usbdev, usbdevs, domid, &usbdev_saved,
-                   COMPARE_USB, &d_config);
+        device_add_domain_config(gc, &d_config, &libxl__usbdev_devtype,
+                                         &usbdev_saved);
 
         rc = libxl__dm_check_start(gc, &d_config, domid);
         if (rc) goto out;
Signature · 7 lines
2.7.4


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

PATCH v4 13/13 libxl: make pci and usb setdefault function generic

In reply to Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Due to changes in device framework setdefault function should have same format. Otherwise calling devicetype set_default causes segfault.

---
 tools/libxl/libxl_internal.h | 1 -
 tools/libxl/libxl_pci.c      | 5 +++--
 tools/libxl/libxl_usb.c      | 7 ++++---
 3 files changed, 7 insertions(+), 6 deletions(-)
tools/libxl/libxl_internal.h +0 -1
index 5fd0356..e4799eb 100644
@@ -1242,7 +1242,6 @@ _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
                                         libxl_domain_create_info *c_info);
 _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info);
-_hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
 
tools/libxl/libxl_pci.c +3 -2
index 159d046..fa86bcf 100644
@@ -1158,7 +1158,8 @@ static int libxl__device_pci_reset(libxl__gc *gc, unsigned int domain, unsigned
     return -1;
 }
 
-int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci)
+static int libxl__device_pci_setdefault(libxl__gc *gc, uint32_t domid,
+                                 libxl_device_pci *pci, bool hotplug)
 {
     /* We'd like to force reserve rdm specific to a device by default.*/
     if (pci->rdm_policy == LIBXL_RDM_RESERVE_POLICY_INVALID)
@@ -1214,7 +1215,7 @@ int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcide
         }
     }
 
-    rc = libxl__device_pci_setdefault(gc, pcidev);
+    rc = libxl__device_pci_setdefault(gc, domid, pcidev, false);
     if (rc) goto out;
 
     if (pcidev->seize && !pciback_dev_is_assigned(gc, pcidev)) {
tools/libxl/libxl_usb.c +4 -3
index e526c08..9fdb284 100644
@@ -39,7 +39,8 @@ static int usbback_is_loaded(libxl__gc *gc)
 }
 
 static int libxl__device_usbctrl_setdefault(libxl__gc *gc, uint32_t domid,
-                                            libxl_device_usbctrl *usbctrl)
+                                            libxl_device_usbctrl *usbctrl,
+                                            bool update_json)
 {
     int rc;
     libxl_domain_type domtype = libxl__domain_type(gc, domid);
@@ -449,7 +450,7 @@ static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
     libxl__device *device;
     int rc;
 
-    rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl);
+    rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl, false);
     if (rc < 0) goto out;
 
     if (usbctrl->devid == -1) {
@@ -1079,7 +1080,7 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc,
 
             GCNEW(usbctrl);
             libxl_device_usbctrl_init(usbctrl);
-            rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl);
+            rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl, update_json);
             if (rc < 0) goto out;
 
             if (usbctrl->devid == -1) {
Signature · 7 lines
2.7.4


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

Re: [PATCH v4 13/13] libxl: make pci and usb setdefault function generic

Quoted 7 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Due to changes in device framework setdefault function should have same format. Otherwise calling devicetype set_default causes segfault.

Shouldn't this patch be placed before the introduction of the new framework?

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

#46 lore raw

Re: [PATCH v4 13/13] libxl: make pci and usb setdefault function generic

Quoted 11 lines · Wei Liu
Quoted 7 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Due to changes in device framework setdefault function should have same format. Otherwise calling devicetype set_default causes segfault.

Shouldn't this patch be placed before the introduction of the new framework?

Wrong function parameters will cause crash if devtype framework will be used. For example if someone call pci set_default:

libxl__nic_devtype.set_default(...)

So I guess the right place for these changes will be first patch where changes to devtype are introduced. I will fix setdefault function parameters for all devtypes. Does it sounds good?

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

Re: [PATCH v4 13/13] libxl: make pci and usb setdefault function generic

Quoted 4 lines · Oleksandr Grytsov

So I guess the right place for these changes will be first patch where changes to devtype are introduced. I will fix setdefault function parameters for all devtypes. Does it sounds good?

Yes.

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

#48 lore raw
In reply to Oleksandr Grytsov

ping

Quoted 65 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Changes since V3:
* libxl__device_add renamed to libxl__device_add_async and reworked

     to match the former design;
   * libxl__device_add used for devices which don't require updating domain
     config but simple write to Xen Store (9pfs, vkb, vfb);

* following devices are changed to use the libxl__device_add:
9pfs, vkb, vfb, nic, vtpm. Other device (console, pci, usb, disk) have very different adding pattern and required to unreasonable extend libxl__device_add_async and its parameters;
* disk device list changed to use libxl__device_list;
* previous comments are applied.

Patches on github [1].

[1] https://github.com/al1img/xen/tree/xl-vdispl-v4

Oleksandr Grytsov (13):
libxl: add generic function to add device
libxl: add generic functions to get and free device list
libxl: add vdispl device
xl: add PV display device commands
docs: add PV display driver information
libxl: change p9 to use generec add function
libxl: change vkb to use generec add function
libxl: change vfb to use generec add function
libxl: change disk to use generic getting list functions
libxl: change nic to use generec add function
libxl: change vtpm to use generec add function
libxl: remove unneeded DEVICE_ADD macro
libxl: make pci and usb setdefault function generic

  docs/man/xl.cfg.pod.5.in              |  49 ++++++
  docs/man/xl.pod.1.in                  |  42 +++++
  tools/libxl/Makefile                  |   2 +-
  tools/libxl/libxl.h                   |  54 +++++--
  tools/libxl/libxl_9pfs.c              |  67 +++-----
  tools/libxl/libxl_checkpoint_device.c |  16 +-
  tools/libxl/libxl_colo_save.c         |   4 +-
  tools/libxl/libxl_console.c           | 153 ++++--------------
  tools/libxl/libxl_create.c            |  17 +-
  tools/libxl/libxl_device.c            | 262 ++++++++++++++++++++++++++++++
  tools/libxl/libxl_disk.c              | 101 ++++--------
  tools/libxl/libxl_dm.c                |  10 +-
  tools/libxl/libxl_internal.h          | 126 ++++++---------
  tools/libxl/libxl_nic.c               | 212 +++++--------------------
  tools/libxl/libxl_pci.c               |  10 +-
  tools/libxl/libxl_types.idl           |  40 ++++-
  tools/libxl/libxl_types_internal.idl  |   1 +
  tools/libxl/libxl_usb.c               |  21 ++-
  tools/libxl/libxl_utils.h             |   4 +
  tools/libxl/libxl_vdispl.c            | 289 ++++++++++++++++++++++++++++++++++
  tools/libxl/libxl_vtpm.c              | 229 ++++++++-------------------
  tools/ocaml/libs/xl/xenlight_stubs.c  |   6 +-
  tools/xl/Makefile                     |   1 +
  tools/xl/xl.h                         |   3 +
  tools/xl/xl_block.c                   |   3 +-
  tools/xl/xl_cmdtable.c                |  19 +++
  tools/xl/xl_nic.c                     |   3 +-
  tools/xl/xl_parse.c                   |  79 +++++++++-
  tools/xl/xl_parse.h                   |   2 +-
  tools/xl/xl_vdispl.c                  | 163 +++++++++++++++++++
  tools/xl/xl_vtpm.c                    |   3 +-
  31 files changed, 1293 insertions(+), 698 deletions(-)
Quoted 3 lines

create mode 100644 tools/libxl/libxl_vdispl.c
create mode 100644 tools/xl/xl_vdispl.c

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

#50 lore raw
In reply to Oleksandr Grytsov
Quoted 14 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Changes since V3:
* libxl__device_add renamed to libxl__device_add_async and reworked

    to match the former design;
  * libxl__device_add used for devices which don't require updating domain
    config but simple write to Xen Store (9pfs, vkb, vfb);

* following devices are changed to use the libxl__device_add:
9pfs, vkb, vfb, nic, vtpm. Other device (console, pci, usb, disk) have very different adding pattern and required to unreasonable extend libxl__device_add_async and its parameters;
* disk device list changed to use libxl__device_list;
* previous comments are applied.

Quoted 3 lines

Patches on github [1].

[1] https://github.com/al1img/xen/tree/xl-vdispl-v4

So I just went through this series and pointed out issues I can immediately find. I will need to take a closer look at the framework itself next week.

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

#51 lore raw
Quoted 15 lines · Wei Liu
Quoted 14 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Changes since V3:
* libxl__device_add renamed to libxl__device_add_async and reworked

    to match the former design;
  * libxl__device_add used for devices which don't require updating domain
    config but simple write to Xen Store (9pfs, vkb, vfb);

* following devices are changed to use the libxl__device_add:
9pfs, vkb, vfb, nic, vtpm. Other device (console, pci, usb, disk) have very different adding pattern and required to unreasonable extend libxl__device_add_async and its parameters;
* disk device list changed to use libxl__device_list;
* previous comments are applied.

Quoted 7 lines
Quoted 3 lines

Patches on github [1].

[1] https://github.com/al1img/xen/tree/xl-vdispl-v4

So I just went through this series and pointed out issues I can immediately find. I will need to take a closer look at the framework itself next week.

ping

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#52 lore raw
Quoted 18 lines · Oleksandr Grytsov
Quoted 17 lines · Wei Liu
Quoted 16 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Changes since V3:
* libxl__device_add renamed to libxl__device_add_async and reworked

    to match the former design;
  * libxl__device_add used for devices which don't require updating domain
    config but simple write to Xen Store (9pfs, vkb, vfb);

* following devices are changed to use the libxl__device_add:
9pfs, vkb, vfb, nic, vtpm. Other device (console, pci, usb, disk) have very different adding pattern and required to unreasonable extend libxl__device_add_async and its parameters;
* disk device list changed to use libxl__device_list;
* previous comments are applied.

Patches on github [1].

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[1] https://github.com/al1img/xen/tree/xl-vdispl-v4

So I just went through this series and pointed out issues I can immediately find. I will need to take a closer look at the framework itself next week.

ping

I'm still waiting for the outcome from the other thread in which I proposed to change p9 to p9s. Ian is out of office at the moment.

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

#53 lore raw
Quoted 21 lines · Wei Liu
Quoted 20 lines · Oleksandr Grytsov
Quoted 19 lines · Wei Liu
Quoted 17 lines · Oleksandr Grytsov

From: Oleksandr Grytsov <[email protected]>

Changes since V3:
* libxl__device_add renamed to libxl__device_add_async and reworked

    to match the former design;
  * libxl__device_add used for devices which don't require updating domain
    config but simple write to Xen Store (9pfs, vkb, vfb);

* following devices are changed to use the libxl__device_add:
9pfs, vkb, vfb, nic, vtpm. Other device (console, pci, usb, disk) have very different adding pattern and required to unreasonable extend libxl__device_add_async and its parameters;
* disk device list changed to use libxl__device_list;
* previous comments are applied.

Patches on github [1].

[1] https://github.com/al1img/xen/tree/xl-vdispl-v4

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

So I just went through this series and pointed out issues I can immediately find. I will need to take a closer look at the framework itself next week.

ping

I'm still waiting for the outcome from the other thread in which I proposed to change p9 to p9s. Ian is out of office at the moment.

ping

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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

Oleksandr Grytsov writes ("Re: [PATCH v4 00/13] libxl: add PV display device driver interface"):

Quoted 5 lines · Wei Liu
Quoted 2 lines

I'm still waiting for the outcome from the other thread in which I proposed to change p9 to p9s. Ian is out of office at the moment.

ping

Sorry, I thought the previous mails were clear. I think changing the name is fine now, despite it being an API break, because we think there are very few out-of-tree callers.

Ian.

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

#55 lore raw
Quoted 5 lines · Ian Jackson

Oleksandr Grytsov writes ("Re: [PATCH v4 00/13] libxl: add PV display device driver interface"):

Quoted 4 lines · Wei Liu
Quoted 2 lines

I'm still waiting for the outcome from the other thread in which I proposed to change p9 to p9s. Ian is out of office at the moment.

Quoted 7 lines
Quoted 1 line

ping

Sorry, I thought the previous mails were clear. I think changing the name is fine now, despite it being an API break, because we think there are very few out-of-tree callers.

Ian.

Yes, it is clear about changing the name.
By pinging I mean review and feedback for all other patches in this patch set.

Signature · 7 lines
Best Regards,
Oleksandr Grytsov.

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