]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
libxl: use libxl__device_kind to get device XS entry
authorOleksandr Grytsov <oleksandr_grytsov@epam.com>
Wed, 24 Jan 2018 17:19:56 +0000 (19:19 +0200)
committerWei Liu <wei.liu2@citrix.com>
Thu, 25 Jan 2018 11:35:14 +0000 (11:35 +0000)
On adding to XS name of device is taken from
libxl__device_kind enum. On getting device from XS
the name is hardcoded. It leads to potential
mistmatch errors. The patch is using libxl__device_kind
everywere to have one source of device name.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
14 files changed:
tools/libxl/libxl_9pfs.c
tools/libxl/libxl_colo_nic.c
tools/libxl/libxl_console.c
tools/libxl/libxl_create.c
tools/libxl/libxl_device.c
tools/libxl/libxl_disk.c
tools/libxl/libxl_domain.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_netbuffer.c
tools/libxl/libxl_nic.c
tools/libxl/libxl_pci.c
tools/libxl/libxl_usb.c
tools/libxl/libxl_vdispl.c
tools/libxl/libxl_vtpm.c

index 9db887b5d8cef83eef4d6a4be1abb15fe9d8727d..c3dd7865a9ff75fdf5b142f8f306d6df9f06629d 100644 (file)
@@ -58,7 +58,7 @@ static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t domid,
 
 LIBXL_DEFINE_DEVICE_REMOVE(p9)
 
-DEFINE_DEVICE_TYPE_STRUCT(p9,
+DEFINE_DEVICE_TYPE_STRUCT(p9, 9PFS,
     .skip_attach = 1,
     .set_xenstore_config = (device_set_xenstore_config_fn_t)
                            libxl__set_xenstore_p9,
index a164e22b996c4efcd6bfe4d3a79341a281e75ef0..bf5c48f0b49de867f86761a89f566c3a07e4f3a6 100644 (file)
@@ -60,8 +60,9 @@ static const char *get_vifname(libxl__checkpoint_device *dev,
     /* Convenience aliases */
     const uint32_t domid = dev->cds->domid;
 
-    path = GCSPRINTF("%s/backend/vif/%d/%d/vifname",
-                     libxl__xs_get_dompath(gc, 0), domid, nic->devid);
+    path = GCSPRINTF("%s/vifname",
+                     libxl__domain_device_backend_path(gc, 0,
+                     domid, nic->devid, LIBXL__DEVICE_KIND_VIF));
     rc = libxl__xs_read_checked(gc, XBT_NULL, path, &vifname);
     if (!rc && !vifname) {
         vifname = libxl__device_nic_devname(gc, domid,
index 6bfc0e55c60b84fdf67906940fe1978f1c5fe2eb..4891aa18d7a80726ee66fcf01b848a600b259d10 100644 (file)
@@ -37,8 +37,9 @@ static int libxl__console_tty_path(libxl__gc *gc, uint32_t domid, int cons_num,
         if (cons_num == 0)
             *tty_path = GCSPRINTF("%s/console/tty", dom_path);
         else
-            *tty_path = GCSPRINTF("%s/device/console/%d/tty", dom_path,
-                                  cons_num);
+            *tty_path = GCSPRINTF("%s/tty",
+                                  libxl__domain_device_frontend_path(gc, domid,
+                                  cons_num, LIBXL__DEVICE_KIND_CONSOLE));
         rc = 0;
         break;
     default:
@@ -498,8 +499,10 @@ static int libxl__append_channel_list(libxl__gc *gc,
     libxl_device_channel *next = NULL;
     int rc = 0, i;
 
-    libxl_dir_path = GCSPRINTF("%s/device/console",
-                               libxl__xs_libxl_path(gc, domid));
+    libxl_dir_path = GCSPRINTF("%s/device/%s",
+                               libxl__xs_libxl_path(gc, domid),
+                               libxl__device_kind_to_string(
+                               LIBXL__DEVICE_KIND_CONSOLE));
     dir = libxl__xs_directory(gc, XBT_NULL, libxl_dir_path, &n);
     if (!dir || !n)
       goto out;
@@ -564,18 +567,19 @@ int libxl_device_channel_getinfo(libxl_ctx *ctx, uint32_t domid,
                                  libxl_channelinfo *channelinfo)
 {
     GC_INIT(ctx);
-    char *dompath, *fe_path, *libxl_path;
+    char *fe_path, *libxl_path;
     char *val;
     int rc;
 
-    dompath = libxl__xs_get_dompath(gc, domid);
     channelinfo->devid = channel->devid;
 
-    fe_path = GCSPRINTF("%s/device/console/%d", dompath,
-                        channelinfo->devid + 1);
-    libxl_path = GCSPRINTF("%s/device/console/%d",
-                           libxl__xs_libxl_path(gc, domid),
-                           channelinfo->devid + 1);
+    fe_path = libxl__domain_device_frontend_path(gc, domid,
+                                                 channelinfo->devid + 1,
+                                                 LIBXL__DEVICE_KIND_CONSOLE);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid,
+                                                 channelinfo->devid + 1,
+                                                 LIBXL__DEVICE_KIND_CONSOLE);
+
     channelinfo->backend = xs_read(ctx->xsh, XBT_NULL,
                                    GCSPRINTF("%s/backend", libxl_path), NULL);
     if (!channelinfo->backend) {
@@ -772,7 +776,7 @@ static int libxl__set_xenstore_vfb(libxl__gc *gc, uint32_t domid,
 
 LIBXL_DEFINE_DEVICE_REMOVE(vkb)
 
-DEFINE_DEVICE_TYPE_STRUCT(vkb,
+DEFINE_DEVICE_TYPE_STRUCT(vkb, VKBD,
     .skip_attach = 1
 );
 
@@ -783,7 +787,7 @@ DEFINE_DEVICE_TYPE_STRUCT(vkb,
 /* vfb */
 LIBXL_DEFINE_DEVICE_REMOVE(vfb)
 
-DEFINE_DEVICE_TYPE_STRUCT(vfb,
+DEFINE_DEVICE_TYPE_STRUCT(vfb, VFB,
     .skip_attach = 1,
     .set_xenstore_config = (device_set_xenstore_config_fn_t)
                            libxl__set_xenstore_vfb,
index 1fa1d3a62152f2cfbf79457409c776d3823fa246..3812e67d459974708c556f7a668fc563a7b2c72f 100644 (file)
@@ -1484,7 +1484,7 @@ out:
 #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);
+static DEFINE_DEVICE_TYPE_STRUCT(dtdev, NONE);
 
 const struct libxl_device_type *device_type_tbl[] = {
     &libxl__disk_devtype,
@@ -1510,7 +1510,7 @@ static void domcreate_attach_devices(libxl__egc *egc,
 
     if (ret) {
         LOGD(ERROR, domid, "unable to add %s devices",
-             device_type_tbl[dcs->device_type_idx]->type);
+             libxl__device_kind_to_string(device_type_tbl[dcs->device_type_idx]->type));
         goto error_out;
     }
 
index 5438577c3cb5536eb3bdf5aaec1e6c6f3e10bbab..6e2c93f8e089b97de70e367333547f8ee71ee1f3 100644 (file)
@@ -24,16 +24,28 @@ static char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
 
     /* Console 0 is a special case */
     if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
-        return GCSPRINTF("%s/console", dom_path);
+        return GCSPRINTF("%s/%s", dom_path,
+                         libxl__device_kind_to_string(device->kind));
 
     if (device->kind == LIBXL__DEVICE_KIND_VUART)
-        return GCSPRINTF("%s/vuart/%d", dom_path, device->devid);
+        return GCSPRINTF("%s/%s/%d", dom_path,
+                         libxl__device_kind_to_string(device->kind),
+                         device->devid);
 
     return GCSPRINTF("%s/device/%s/%d", dom_path,
                      libxl__device_kind_to_string(device->kind),
                      device->devid);
 }
 
+char *libxl__domain_device_frontend_path(libxl__gc *gc, uint32_t domid, uint32_t devid,
+                                         libxl__device_kind device_kind)
+{
+    char *dom_path = libxl__xs_get_dompath(gc, domid);
+
+    return GCSPRINTF("%s/device/%s/%d", dom_path,
+                     libxl__device_kind_to_string(device_kind), devid);
+}
+
 char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device)
 {
     char *dom_path = libxl__xs_get_dompath(gc, device->backend_domid);
@@ -43,6 +55,17 @@ char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device)
                      device->domid, device->devid);
 }
 
+char *libxl__domain_device_backend_path(libxl__gc *gc, uint32_t backend_domid,
+                                        uint32_t domid, uint32_t devid,
+                                        libxl__device_kind backend_kind)
+{
+    char *dom_path = libxl__xs_get_dompath(gc, backend_domid);
+
+    return GCSPRINTF("%s/backend/%s/%u/%d", dom_path,
+                     libxl__device_kind_to_string(backend_kind),
+                     domid, devid);
+}
+
 char *libxl__device_libxl_path(libxl__gc *gc, libxl__device *device)
 {
     char *libxl_dom_path = libxl__xs_libxl_path(gc, device->domid);
@@ -52,6 +75,15 @@ char *libxl__device_libxl_path(libxl__gc *gc, libxl__device *device)
                      device->devid);
 }
 
+char *libxl__domain_device_libxl_path(libxl__gc *gc,  uint32_t domid, uint32_t devid,
+                                      libxl__device_kind device_kind)
+{
+    char *libxl_dom_path = libxl__xs_libxl_path(gc, domid);
+
+    return GCSPRINTF("%s/device/%s/%d", libxl_dom_path,
+                     libxl__device_kind_to_string(device_kind), devid);
+}
+
 /* Returns 1 if device exists, 0 if not, ERROR_* (<0) on error. */
 int libxl__device_exists(libxl__gc *gc, xs_transaction_t t,
                          libxl__device *device)
@@ -2007,7 +2039,8 @@ void *libxl__device_list(libxl__gc *gc, const struct libxl_device_type *dt,
     *num = 0;
 
     libxl_path = GCSPRINTF("%s/device/%s",
-                           libxl__xs_libxl_path(gc, domid), dt->entry);
+                           libxl__xs_libxl_path(gc, domid),
+                           libxl__device_kind_to_string(dt->type));
 
     dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs);
 
index 895bf4f89ab6e73ca86178ba9889b59fac36b388..e9eceb65e3b387216d9b25372d2db9c16faa4d46 100644 (file)
@@ -97,14 +97,13 @@ int libxl_evenable_disk_eject(libxl_ctx *ctx, uint32_t guest_domid,
 
     int devid = libxl__device_disk_dev_number(vdev, NULL, NULL);
 
-    path = GCSPRINTF("%s/device/vbd/%d/eject",
-                 libxl__xs_get_dompath(gc, domid),
-                 devid);
+    path = GCSPRINTF("%s/eject",
+                    libxl__domain_device_frontend_path(gc, domid, devid,
+                    LIBXL__DEVICE_KIND_VBD));
     if (!path) { rc = ERROR_NOMEM; goto out; }
 
-    const char *libxl_path = GCSPRINTF("%s/device/vbd/%d",
-                                 libxl__xs_libxl_path(gc, domid),
-                                 devid);
+    const char *libxl_path = libxl__domain_device_frontend_path(gc, domid, devid,
+                                                                LIBXL__DEVICE_KIND_VBD);
     evg->be_ptr_path = libxl__sprintf(NOGC, "%s/backend", libxl_path);
 
     const char *configured_vdev;
@@ -599,7 +598,7 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
                               const char *vdev, libxl_device_disk *disk)
 {
     GC_INIT(ctx);
-    char *dom_xl_path, *libxl_path;
+    char *libxl_path;
     int devid = libxl__device_disk_dev_number(vdev, NULL, NULL);
     int rc = ERROR_FAIL;
 
@@ -608,14 +607,11 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
 
     libxl_device_disk_init(disk);
 
-    dom_xl_path = libxl__xs_libxl_path(gc, domid);
-    if (!dom_xl_path) {
-        goto out;
-    }
-    libxl_path = GCSPRINTF("%s/device/vbd/%d", dom_xl_path, devid);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, devid,
+                                                 LIBXL__DEVICE_KIND_VBD);
 
     rc = libxl__disk_from_xenstore(gc, libxl_path, devid, disk);
-out:
+
     GC_FREE;
     return rc;
 }
@@ -624,19 +620,19 @@ int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_disk *disk, libxl_diskinfo *diskinfo)
 {
     GC_INIT(ctx);
-    char *dompath, *fe_path, *libxl_path;
+    char *fe_path, *libxl_path;
     char *val;
     int rc;
 
     diskinfo->backend = NULL;
 
-    dompath = libxl__xs_get_dompath(gc, domid);
     diskinfo->devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
 
     /* tap devices entries in xenstore are written as vbd devices. */
-    fe_path = GCSPRINTF("%s/device/vbd/%d", dompath, diskinfo->devid);
-    libxl_path = GCSPRINTF("%s/device/vbd/%d",
-                           libxl__xs_libxl_path(gc, domid), diskinfo->devid);
+    fe_path = libxl__domain_device_frontend_path(gc, domid, diskinfo->devid,
+                                                 LIBXL__DEVICE_KIND_VBD);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, diskinfo->devid,
+                                                 LIBXL__DEVICE_KIND_VBD);
     diskinfo->backend = xs_read(ctx->xsh, XBT_NULL,
                                 GCSPRINTF("%s/backend", libxl_path), NULL);
     if (!diskinfo->backend) {
@@ -871,7 +867,6 @@ static char * libxl__alloc_vdev(libxl__gc *gc, void *get_vdev_user,
 {
     const char *blkdev_start = (const char *) get_vdev_user;
     int devid = 0, disk = 0, part = 0;
-    char *libxl_dom_path = libxl__xs_libxl_path(gc, LIBXL_TOOLSTACK_DOMID);
 
     libxl__device_disk_dev_number(blkdev_start, &disk, &part);
     if (part != 0) {
@@ -884,9 +879,10 @@ static char * libxl__alloc_vdev(libxl__gc *gc, void *get_vdev_user,
                 NULL, NULL);
         if (devid < 0)
             return NULL;
-        if (libxl__xs_read(gc, t,
-                    GCSPRINTF("%s/device/vbd/%d/backend",
-                        libxl_dom_path, devid)) == NULL) {
+        if (libxl__xs_read(gc, t, GCSPRINTF("%s/backend",
+                           libxl__domain_device_libxl_path(gc,
+                           LIBXL_TOOLSTACK_DOMID, devid,
+                           LIBXL__DEVICE_KIND_VBD))) == NULL) {
             if (errno == ENOENT)
                 return libxl__devid_to_vdev(gc, devid);
             else
@@ -1179,7 +1175,7 @@ LIBXL_DEFINE_DEVICE_LIST(disk)
 
 #define libxl__device_disk_update_devid NULL
 
-DEFINE_DEVICE_TYPE_STRUCT_X(disk, disk, vbd,
+DEFINE_DEVICE_TYPE_STRUCT(disk, VBD,
     .merge       = libxl_device_disk_merge,
     .dm_needed   = libxl_device_disk_dm_needed,
     .from_xenstore = (device_from_xenstore_fn_t)libxl__disk_from_xenstore,
index aaa22ef5766229e85a87b0930937adca3a5be8e0..13b1c73d40966d3ef7c2b66984c1b3b6a4b7a3ff 100644 (file)
@@ -1684,7 +1684,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
             p = libxl__device_list(gc, dt, domid, &num);
             if (p == NULL) {
                 LOGD(DEBUG, domid, "No %s from xenstore",
-                     dt->type);
+                     libxl__device_kind_to_string(dt->type));
             }
             devs = libxl__device_type_get_ptr(dt, d_config);
 
index 7ff9a67e5067a0eb6d80734ea6ad7c1c705e4dad..1e5e2e74ac9d98096e83a06126259802c3fdb81a 100644 (file)
@@ -1222,8 +1222,15 @@ _hidden int libxl__device_exists(libxl__gc *gc, xs_transaction_t t,
                                  libxl__device *device);
 _hidden int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t,
         libxl__device *device, char **bents, char **fents, char **ro_fents);
+_hidden char *libxl__domain_device_frontend_path(libxl__gc *gc, uint32_t domid, uint32_t devid,
+                                                 libxl__device_kind device_kind);
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
+_hidden char *libxl__domain_device_backend_path(libxl__gc *gc, uint32_t backend_domid,
+                                                uint32_t domid, uint32_t devid,
+                                                libxl__device_kind device_kind);
 _hidden char *libxl__device_libxl_path(libxl__gc *gc, libxl__device *device);
+_hidden char *libxl__domain_device_libxl_path(libxl__gc *gc, uint32_t domid, uint32_t devid,
+                                              libxl__device_kind device_kind);
 _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
                                       libxl__device *dev);
 _hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev);
@@ -3513,8 +3520,7 @@ typedef int (*device_set_xenstore_config_fn_t)(libxl__gc *, uint32_t, void *,
                                                flexarray_t *);
 
 struct libxl_device_type {
-    char *type;
-    char *entry;
+    libxl__device_kind type;
     int skip_attach;   /* Skip entry in domcreate_attach_devices() if 1 */
     int ptr_offset;    /* Offset of device array ptr in libxl_domain_config */
     int num_offset;    /* Offset of # of devices in libxl_domain_config */
@@ -3534,10 +3540,9 @@ struct libxl_device_type {
     device_set_xenstore_config_fn_t set_xenstore_config;
 };
 
-#define DEFINE_DEVICE_TYPE_STRUCT_X(name, sname, sentry, ...)                  \
+#define DEFINE_DEVICE_TYPE_STRUCT_X(name, sname, kind, ...)                    \
     const struct libxl_device_type libxl__ ## name ## _devtype = {             \
-        .type          = #sname,                                               \
-        .entry         = #sentry,                                              \
+        .type          = LIBXL__DEVICE_KIND_ ## kind,                       \
         .ptr_offset    = offsetof(libxl_domain_config, name ## s),             \
         .num_offset    = offsetof(libxl_domain_config, num_ ## name ## s),     \
         .dev_elem_size = sizeof(libxl_device_ ## sname),                       \
@@ -3556,8 +3561,8 @@ struct libxl_device_type {
         __VA_ARGS__                                                            \
     }
 
-#define DEFINE_DEVICE_TYPE_STRUCT(name, ...)                                   \
-    DEFINE_DEVICE_TYPE_STRUCT_X(name, name, name, __VA_ARGS__)
+#define DEFINE_DEVICE_TYPE_STRUCT(name, kind, ...)                             \
+    DEFINE_DEVICE_TYPE_STRUCT_X(name, name, kind, __VA_ARGS__)
 
 static inline void **libxl__device_type_get_ptr(
     const struct libxl_device_type *dt, const libxl_domain_config *d_config)
index 323cdd8c519e44bb5751d66689c9c3eb56c9d67b..4b219144079993422c82ed9fd1111c8f35f40738 100644 (file)
@@ -126,8 +126,10 @@ static const char *get_vifname(libxl__checkpoint_device *dev,
     /* Convenience aliases */
     const uint32_t domid = dev->cds->domid;
 
-    path = GCSPRINTF("%s/backend/vif/%d/%d/vifname",
-                     libxl__xs_get_dompath(gc, 0), domid, nic->devid);
+    path = GCSPRINTF("%s/vifname",
+                     libxl__domain_device_backend_path(gc, 0, domid,
+                     nic->devid, LIBXL__DEVICE_KIND_VIF));
+
     rc = libxl__xs_read_checked(gc, XBT_NULL, path, &vifname);
     if (!rc && !vifname) {
         vifname = libxl__device_nic_devname(gc, domid,
index 1e6ba6c78dd8ab3fa9218cfd84ef513293cd601e..e2512fc060f9a4d4140cfe76dcaa87bc72de0e84 100644 (file)
@@ -400,15 +400,13 @@ int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                               int devid, libxl_device_nic *nic)
 {
     GC_INIT(ctx);
-    char *libxl_dom_path, *libxl_path;
+    char *libxl_path;
     int rc = ERROR_FAIL;
 
     libxl_device_nic_init(nic);
-    libxl_dom_path = libxl__xs_libxl_path(gc, domid);
-    if (!libxl_dom_path)
-        goto out;
 
-    libxl_path = GCSPRINTF("%s/device/vif/%d", libxl_dom_path, devid);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, devid,
+                                                 LIBXL__DEVICE_KIND_VIF);
 
     rc = libxl__nic_from_xenstore(gc, libxl_path, devid, nic);
     if (rc) goto out;
@@ -441,16 +439,16 @@ int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_nic *nic, libxl_nicinfo *nicinfo)
 {
     GC_INIT(ctx);
-    char *dompath, *nicpath, *libxl_path;
+    char *nicpath, *libxl_path;
     char *val;
     int rc;
 
-    dompath = libxl__xs_get_dompath(gc, domid);
     nicinfo->devid = nic->devid;
 
-    nicpath = GCSPRINTF("%s/device/vif/%d", dompath, nicinfo->devid);
-    libxl_path = GCSPRINTF("%s/device/vif/%d",
-                           libxl__xs_libxl_path(gc, domid), nicinfo->devid);
+    nicpath = libxl__domain_device_frontend_path(gc, domid, nicinfo->devid,
+                                                 LIBXL__DEVICE_KIND_VIF);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, nicinfo->devid,
+                                                 LIBXL__DEVICE_KIND_VIF);
     nicinfo->backend = xs_read(ctx->xsh, XBT_NULL,
                                 GCSPRINTF("%s/backend", libxl_path), NULL);
     if (!nicinfo->backend) {
@@ -539,7 +537,7 @@ LIBXL_DEFINE_DEVICE_ADD(nic)
 LIBXL_DEFINE_DEVICES_ADD(nic)
 LIBXL_DEFINE_DEVICE_REMOVE(nic)
 
-DEFINE_DEVICE_TYPE_STRUCT_X(nic, nic, vif,
+DEFINE_DEVICE_TYPE_STRUCT(nic, VIF,
     .update_config = libxl_device_nic_update_config,
     .from_xenstore = (device_from_xenstore_fn_t)libxl__nic_from_xenstore,
     .set_xenstore_config = (device_set_xenstore_config_fn_t)
index 88a55ce8bdcdb539836400828c23ee1aaf940b67..4755a0c93cfb7927d5ee479e193bfcb322254b0d 100644 (file)
@@ -125,7 +125,8 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_d
     libxl_device_pci_init(&pcidev_saved);
     libxl_device_pci_copy(CTX, &pcidev_saved, pcidev);
 
-    be_path = GCSPRINTF("%s/backend/pci/%d/0", libxl__xs_get_dompath(gc, 0), domid);
+    be_path = libxl__domain_device_backend_path(gc, 0, domid, 0,
+                                                LIBXL__DEVICE_KIND_PCI);
     num_devs = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/num_devs", be_path));
     if (!num_devs)
         return libxl__create_pci_backend(gc, domid, pcidev, 1);
@@ -195,7 +196,8 @@ static int libxl__device_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, libx
     int num, i, j;
     xs_transaction_t t;
 
-    be_path = GCSPRINTF("%s/backend/pci/%d/0", libxl__xs_get_dompath(gc, 0), domid);
+    be_path = libxl__domain_device_backend_path(gc, 0, domid, 0,
+                                                LIBXL__DEVICE_KIND_PCI);
     num_devs_path = GCSPRINTF("%s/num_devs", be_path);
     num_devs = libxl__xs_read(gc, XBT_NULL, num_devs_path);
     if (!num_devs)
@@ -315,14 +317,17 @@ static int get_all_assigned_devices(libxl__gc *gc, libxl_device_pci **list, int
     for(i = 0; i < nd; i++) {
         char *path, *num_devs;
 
-        path = GCSPRINTF("/local/domain/0/backend/pci/%s/0/num_devs", domlist[i]);
+        path = GCSPRINTF("/local/domain/0/backend/%s/%s/0/num_devs",
+                         libxl__device_kind_to_string(LIBXL__DEVICE_KIND_PCI),
+                         domlist[i]);
         num_devs = libxl__xs_read(gc, XBT_NULL, path);
         if ( num_devs ) {
             int ndev = atoi(num_devs), j;
             char *devpath, *bdf;
 
             for(j = 0; j < ndev; j++) {
-                devpath = GCSPRINTF("/local/domain/0/backend/pci/%s/0/dev-%u",
+                devpath = GCSPRINTF("/local/domain/0/backend/%s/%s/0/dev-%u",
+                                    libxl__device_kind_to_string(LIBXL__DEVICE_KIND_PCI),
                                     domlist[i], j);
                 bdf = libxl__xs_read(gc, XBT_NULL, devpath);
                 if ( bdf ) {
@@ -1589,7 +1594,8 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num
 
     *num = 0;
 
-    be_path = GCSPRINTF("%s/backend/pci/%d/0", libxl__xs_get_dompath(gc, 0), domid);
+    be_path = libxl__domain_device_backend_path(gc, 0, domid, 0,
+                                                LIBXL__DEVICE_KIND_PCI);
     num_devs = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/num_devs", be_path));
     if (!num_devs)
         goto out;
@@ -1682,7 +1688,7 @@ static int libxl_device_pci_compare(libxl_device_pci *d1,
 
 #define libxl__device_pci_update_devid NULL
 
-DEFINE_DEVICE_TYPE_STRUCT_X(pcidev, pci, pci);
+DEFINE_DEVICE_TYPE_STRUCT_X(pcidev, pci, PCI);
 
 /*
  * Local variables:
index cb0e7927248f186f155dea4763cb9b36cc65d81f..78a78c737f2fdaff5e8cf0a8cf8ace630f14f3d7 100644 (file)
@@ -310,8 +310,8 @@ static void libxl__device_usbctrl_del_xenstore(libxl__gc *gc, uint32_t domid,
     xs_transaction_t t = XBT_NULL;
     int rc;
 
-    libxl_path = GCSPRINTF("%s/device/vusb/%d",
-                           libxl__xs_libxl_path(gc, domid), usbctrl->devid);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, usbctrl->devid,
+                                                 LIBXL__DEVICE_KIND_VUSB);
     be_path = vusb_be_from_xs_libxl_type(gc, libxl_path, usbctrl->type);
 
     for (;;) {
@@ -574,8 +574,9 @@ libxl_device_usbctrl_list(libxl_ctx *ctx, uint32_t domid, int *num)
 
     *num = 0;
 
-    libxl_vusbs_path = GCSPRINTF("%s/device/vusb",
-                     libxl__xs_libxl_path(gc, domid));
+    libxl_vusbs_path = GCSPRINTF("%s/device/%s",
+                     libxl__xs_libxl_path(gc, domid),
+                     libxl__device_kind_to_string(LIBXL__DEVICE_KIND_VUSB));
     entry = libxl__xs_directory(gc, XBT_NULL, libxl_vusbs_path, &nentries);
 
     if (entry && nentries) {
@@ -644,8 +645,8 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid,
                                  libxl_usbctrlinfo *usbctrlinfo)
 {
     GC_INIT(ctx);
-    const char *dompath, *fe_path, *be_path, *tmp;
-    const char *libxl_dom_path, *libxl_path;
+    const char *fe_path, *be_path, *tmp;
+    const char *libxl_path;
     int rc;
 
     usbctrlinfo->devid = usbctrl->devid;
@@ -666,14 +667,14 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid,
         tmp ? atoi(tmp) : -1;                                           \
     })
 
-    libxl_dom_path = libxl__xs_libxl_path(gc, domid);
-    libxl_path = GCSPRINTF("%s/device/vusb/%d", libxl_dom_path, usbctrl->devid);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, usbctrl->devid,
+                                                 LIBXL__DEVICE_KIND_VUSB);
     libxl_usbctrl_type_from_string(READ_SUBPATH(libxl_path, "type"),
                                    &usbctrlinfo->type);
 
     if (usbctrlinfo->type != LIBXL_USBCTRL_TYPE_DEVICEMODEL) {
-        dompath = libxl__xs_get_dompath(gc, domid);
-        fe_path = GCSPRINTF("%s/device/vusb/%d", dompath, usbctrl->devid);
+        fe_path = libxl__domain_device_frontend_path(gc, domid, usbctrl->devid,
+                                                     LIBXL__DEVICE_KIND_VUSB);
         be_path = READ_SUBPATH(libxl_path, "backend");
         usbctrlinfo->backend = libxl__strdup(NOGC, be_path);
         rc = libxl__backendpath_parse_domid(gc, be_path,
@@ -821,8 +822,9 @@ static int get_assigned_devices(libxl__gc *gc,
         unsigned int nc = 0;
         uint32_t domid = atoi(domlist[i]);
 
-        libxl_vusbs_path = GCSPRINTF("%s/device/vusb",
-                                     libxl__xs_libxl_path(gc, domid));
+        libxl_vusbs_path = GCSPRINTF("%s/device/%s",
+                                     libxl__xs_libxl_path(gc, domid),
+                                     libxl__device_kind_to_string(LIBXL__DEVICE_KIND_VUSB));
         usbctrls = libxl__xs_directory(gc, XBT_NULL,
                                        libxl_vusbs_path, &nc);
 
@@ -900,8 +902,8 @@ libxl__device_usbdev_list_for_usbctrl(libxl__gc *gc,
     *usbdevs = NULL;
     *num = 0;
 
-    libxl_path = GCSPRINTF("%s/device/vusb/%d",
-                           libxl__xs_libxl_path(gc, domid), usbctrl);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, usbctrl,
+                                                 LIBXL__DEVICE_KIND_VUSB);
 
     be_path = vusb_be_from_xs_libxl(gc, libxl_path);
     if (!be_path) {
@@ -959,8 +961,10 @@ libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num)
 
     *num = 0;
 
-    libxl_vusbs_path = GCSPRINTF("%s/device/vusb",
-                                 libxl__xs_libxl_path(gc, domid));
+    libxl_vusbs_path = GCSPRINTF("%s/device/%s",
+                                 libxl__xs_libxl_path(gc, domid),
+                                 libxl__device_kind_to_string(
+                                 LIBXL__DEVICE_KIND_VUSB));
     usbctrls = libxl__xs_directory(gc, XBT_NULL, libxl_vusbs_path, &nc);
 
     for (i = 0; i < nc; i++) {
@@ -990,7 +994,8 @@ static char *vusb_get_port_path(libxl__gc *gc, uint32_t domid,
     char *path;
 
     if (type == LIBXL_USBCTRL_TYPE_DEVICEMODEL)
-        path = GCSPRINTF("%s/device/vusb", libxl__xs_libxl_path(gc, domid));
+        path = GCSPRINTF("%s/device/%s", libxl__xs_libxl_path(gc, domid),
+                         libxl__device_kind_to_string(LIBXL__DEVICE_KIND_VUSB));
     else
         path = GCSPRINTF("%s/backend/%s/%d",
                          libxl__xs_get_dompath(gc, LIBXL_TOOLSTACK_DOMID),
@@ -1096,9 +1101,8 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc,
         /* A controller was specified; look it up */
         const char *libxl_path, *be_path, *tmp;
 
-        libxl_path = GCSPRINTF("%s/device/vusb/%d",
-                            libxl__xs_libxl_path(gc, domid),
-                            usbdev->ctrl);
+        libxl_path = libxl__domain_device_libxl_path(gc, domid, usbdev->ctrl,
+                                                        LIBXL__DEVICE_KIND_VUSB);
 
         be_path = vusb_be_from_xs_libxl(gc, libxl_path);
         if (!be_path) {
@@ -1888,12 +1892,11 @@ int libxl_ctrlport_to_device_usbdev(libxl_ctx *ctx,
                                     libxl_device_usbdev *usbdev)
 {
     GC_INIT(ctx);
-    const char *libxl_dom_path, *libxl_path, *be_path, *busid;
+    const char *libxl_path, *be_path, *busid;
     int rc;
 
-    libxl_dom_path = libxl__xs_libxl_path(gc, domid);
-
-    libxl_path = GCSPRINTF("%s/device/vusb/%d", libxl_dom_path, ctrl);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, ctrl,
+                 LIBXL__DEVICE_KIND_VUSB);
     be_path = vusb_be_from_xs_libxl(gc, libxl_path);
     if (!be_path) {
         rc = ERROR_FAIL;
@@ -1962,14 +1965,14 @@ void libxl_device_usbdev_list_free(libxl_device_usbdev *list, int nr)
 
 #define libxl__device_usbctrl_update_devid NULL
 
-DEFINE_DEVICE_TYPE_STRUCT(usbctrl,
+DEFINE_DEVICE_TYPE_STRUCT(usbctrl, VUSB,
     .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);
+DEFINE_DEVICE_TYPE_STRUCT(usbdev, VUSB);
 
 /*
  * Local variables:
index e61ef2dfcd313be8f0422ae20214f350b8e10c85..d9889b8ca9e2c5e7ead3f9309291147f1958fa9c 100644 (file)
@@ -168,18 +168,18 @@ int libxl_device_vdispl_getinfo(libxl_ctx *ctx, uint32_t domid,
                                 libxl_vdisplinfo *info)
 {
     GC_INIT(ctx);
-    char *libxl_path, *dompath, *devpath;
+    char *libxl_path, *devpath;
     char *val;
     int rc;
 
     libxl_vdisplinfo_init(info);
-    dompath = libxl__xs_get_dompath(gc, domid);
     info->devid = vdispl->devid;
 
-    devpath = GCSPRINTF("%s/device/vdispl/%d", dompath, info->devid);
-    libxl_path = GCSPRINTF("%s/device/vdispl/%d",
-                           libxl__xs_libxl_path(gc, domid),
-                           info->devid);
+    devpath = libxl__domain_device_frontend_path(gc, domid, info->devid,
+                                                 LIBXL__DEVICE_KIND_VDISPL);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, info->devid,
+                                                 LIBXL__DEVICE_KIND_VDISPL);
+
     info->backend = xs_read(ctx->xsh, XBT_NULL,
                             GCSPRINTF("%s/backend", libxl_path),
                             NULL);
@@ -249,7 +249,7 @@ LIBXL_DEFINE_DEVICE_REMOVE(vdispl)
 static LIBXL_DEFINE_UPDATE_DEVID(vdispl, "vdispl")
 LIBXL_DEFINE_DEVICE_LIST(vdispl)
 
-DEFINE_DEVICE_TYPE_STRUCT(vdispl,
+DEFINE_DEVICE_TYPE_STRUCT(vdispl, VDISPL,
     .update_config = (device_update_config_fn_t)libxl__update_config_vdispl,
     .from_xenstore = (device_from_xenstore_fn_t)libxl__vdispl_from_xenstore,
     .set_xenstore_config = (device_set_xenstore_config_fn_t)
index 3f0c56349dae26fea1cc7019c6d93058fe25bf8d..d273edd7b47440f08dc35433a4db222a7ffbda97 100644 (file)
@@ -110,17 +110,17 @@ int libxl_device_vtpm_getinfo(libxl_ctx *ctx,
                               libxl_vtpminfo *vtpminfo)
 {
     GC_INIT(ctx);
-    char *libxl_path, *dompath, *vtpmpath;
+    char *libxl_path, *vtpmpath;
     char *val;
     int rc = 0;
 
     libxl_vtpminfo_init(vtpminfo);
-    dompath = libxl__xs_get_dompath(gc, domid);
     vtpminfo->devid = vtpm->devid;
 
-    vtpmpath = GCSPRINTF("%s/device/vtpm/%d", dompath, vtpminfo->devid);
-    libxl_path = GCSPRINTF("%s/device/vtpm/%d",
-                           libxl__xs_libxl_path(gc, domid), vtpminfo->devid);
+    vtpmpath = libxl__domain_device_frontend_path(gc, domid, vtpminfo->devid,
+                                                  LIBXL__DEVICE_KIND_VTPM);
+    libxl_path = libxl__domain_device_libxl_path(gc, domid, vtpminfo->devid,
+                                                 LIBXL__DEVICE_KIND_VTPM);
     vtpminfo->backend = xs_read(ctx->xsh, XBT_NULL,
           GCSPRINTF("%s/backend", libxl_path), NULL);
     if (!vtpminfo->backend) {
@@ -244,7 +244,7 @@ static LIBXL_DEFINE_DEVICES_ADD(vtpm)
 LIBXL_DEFINE_DEVICE_REMOVE(vtpm)
 LIBXL_DEFINE_DEVICE_LIST(vtpm)
 
-DEFINE_DEVICE_TYPE_STRUCT(vtpm,
+DEFINE_DEVICE_TYPE_STRUCT(vtpm, VTPM,
     .update_config = libxl_device_vtpm_update_config,
     .from_xenstore = (device_from_xenstore_fn_t)libxl__vtpm_from_xenstore,
     .set_xenstore_config = (device_set_xenstore_config_fn_t)