[Xen-devel] [PATCH v4 2/4] libxl: add basic support for devices without backend

2016-09-20 Thread Juergen Gross
With the planned support of HVM USB passthrough via the USB emulation
capabilities of qemu libxl has to support guest devices which have no
back- and frontend. Information about those devices will live in the
libxl part of Xenstore only.

Add some basic support to libxl to be able to cope with this scenario.

Signed-off-by: Juergen Gross 
---
V4: corrected libxl__device_destroy() to not use be_path being NULL
---
 tools/libxl/libxl_device.c   | 70 
 tools/libxl/libxl_types_internal.idl |  1 +
 tools/libxl/libxl_xshelp.c   |  6 +++-
 3 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index dbf157d..1cc9098 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -114,15 +114,21 @@ int libxl__device_generic_add(libxl__gc *gc, 
xs_transaction_t t,
 libxl__device *device, char **bents, char **fents, char **ro_fents)
 {
 libxl_ctx *ctx = libxl__gc_owner(gc);
-char *frontend_path, *backend_path, *libxl_path;
+char *frontend_path = NULL, *backend_path = NULL, *libxl_path;
 struct xs_permissions frontend_perms[2];
 struct xs_permissions ro_frontend_perms[2];
 struct xs_permissions backend_perms[2];
 int create_transaction = t == XBT_NULL;
+int libxl_only = device->backend_kind == LIBXL__DEVICE_KIND_NONE;
 int rc;
 
-frontend_path = libxl__device_frontend_path(gc, device);
-backend_path = libxl__device_backend_path(gc, device);
+if (libxl_only) {
+/* bents should be set as this is used to setup libxl_path content. */
+assert(!fents && !ro_fents);
+} else {
+frontend_path = libxl__device_frontend_path(gc, device);
+backend_path = libxl__device_backend_path(gc, device);
+}
 libxl_path = libxl__device_libxl_path(gc, device);
 
 frontend_perms[0].id = device->domid;
@@ -144,13 +150,15 @@ retry_transaction:
 rc = libxl__xs_rm_checked(gc, t, libxl_path);
 if (rc) goto out;
 
-rc = libxl__xs_write_checked(gc, t, GCSPRINTF("%s/frontend",libxl_path),
- frontend_path);
-if (rc) goto out;
+if (!libxl_only) {
+rc = libxl__xs_write_checked(gc, t, 
GCSPRINTF("%s/frontend",libxl_path),
+ frontend_path);
+if (rc) goto out;
 
-rc = libxl__xs_write_checked(gc, t, GCSPRINTF("%s/backend",libxl_path),
- backend_path);
-if (rc) goto out;
+rc = libxl__xs_write_checked(gc, t, GCSPRINTF("%s/backend",libxl_path),
+ backend_path);
+if (rc) goto out;
+}
 
 /* xxx much of this function lacks error checks! */
 
@@ -179,12 +187,15 @@ retry_transaction:
 }
 
 if (bents) {
-xs_rm(ctx->xsh, t, backend_path);
-xs_mkdir(ctx->xsh, t, backend_path);
-xs_set_permissions(ctx->xsh, t, backend_path, backend_perms, 
ARRAY_SIZE(backend_perms));
-xs_write(ctx->xsh, t, GCSPRINTF("%s/frontend", backend_path),
- frontend_path, strlen(frontend_path));
-libxl__xs_writev(gc, t, backend_path, bents);
+if (!libxl_only) {
+xs_rm(ctx->xsh, t, backend_path);
+xs_mkdir(ctx->xsh, t, backend_path);
+xs_set_permissions(ctx->xsh, t, backend_path, backend_perms,
+   ARRAY_SIZE(backend_perms));
+xs_write(ctx->xsh, t, GCSPRINTF("%s/frontend", backend_path),
+ frontend_path, strlen(frontend_path));
+libxl__xs_writev(gc, t, backend_path, bents);
+}
 
 /*
  * We make a copy of everything for the backend in the libxl
@@ -194,6 +205,9 @@ retry_transaction:
  * instead.  But there are still places in libxl that try to
  * reconstruct a config from xenstore.
  *
+ * For devices without PV backend (e.g. USB devices emulated via qemu)
+ * only the libxl path is written.
+ *
  * This duplication will typically produces duplicate keys
  * which will go out of date, but that's OK because nothing
  * reads those.  For example, there is usually
@@ -679,14 +693,21 @@ void libxl__multidev_prepared(libxl__egc *egc,
 
 int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
 {
-const char *be_path = libxl__device_backend_path(gc, dev);
-const char *fe_path = libxl__device_frontend_path(gc, dev);
+const char *be_path = NULL;
+const char *fe_path = NULL;
 const char *libxl_path = libxl__device_libxl_path(gc, dev);
-const char *tapdisk_path = GCSPRINTF("%s/%s", be_path, "tapdisk-params");
-const char *tapdisk_params;
+const char *tapdisk_path = NULL;
+const char *tapdisk_params = NULL;
 xs_transaction_t t = 0;
 int rc;
 uint32_t domid;
+int libxl_only = dev->backend_kind == LIBXL__DEVICE_KIND_NONE;
+
+if 

Re: [Xen-devel] [PATCH v4 2/4] libxl: add basic support for devices without backend

2016-09-20 Thread Wei Liu
On Tue, Sep 20, 2016 at 04:18:08PM +0200, Juergen Gross wrote:
> With the planned support of HVM USB passthrough via the USB emulation
> capabilities of qemu libxl has to support guest devices which have no
> back- and frontend. Information about those devices will live in the
> libxl part of Xenstore only.
> 
> Add some basic support to libxl to be able to cope with this scenario.
> 
> Signed-off-by: Juergen Gross 

Acked-by: Wei Liu 

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