From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xen.org
Cc: George.Dunlap@eu.citrix.com, wei.liu2@citrix.com,
ian.jackson@eu.citrix.com, Juergen Gross <jgross@suse.com>
Subject: [PATCH v3 2/4] libxl: add basic support for devices without backend
Date: Tue, 20 Sep 2016 14:01:08 +0200 [thread overview]
Message-ID: <1474372870-9408-3-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1474372870-9408-1-git-send-email-jgross@suse.com>
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 <jgross@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
---
tools/libxl/libxl_device.c | 59 ++++++++++++++++++++++++------------
tools/libxl/libxl_types_internal.idl | 1 +
tools/libxl/libxl_xshelp.c | 6 +++-
3 files changed, 46 insertions(+), 20 deletions(-)
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index dbf157d..f53f772 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,20 @@ 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;
xs_transaction_t t = 0;
int rc;
uint32_t domid;
+ int libxl_only = dev->backend_kind == LIBXL__DEVICE_KIND_NONE;
+
+ if (!libxl_only) {
+ be_path = libxl__device_backend_path(gc, dev);
+ fe_path = libxl__device_frontend_path(gc, dev);
+ }
rc = libxl__get_domid(gc, &domid);
if (rc) goto out;
@@ -704,10 +724,11 @@ int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
* The toolstack domain is in charge of removing the
* frontend and libxl paths.
*/
- libxl__xs_path_cleanup(gc, t, fe_path);
+ if (!libxl_only)
+ libxl__xs_path_cleanup(gc, t, fe_path);
libxl__xs_path_cleanup(gc, t, libxl_path);
}
- if (dev->backend_domid == domid) {
+ if (dev->backend_domid == domid && !libxl_only) {
/*
* The driver domain is in charge of removing what it can
* from the backend path.
diff --git a/tools/libxl/libxl_types_internal.idl b/tools/libxl/libxl_types_internal.idl
index 177f9b7..82e5c07 100644
--- a/tools/libxl/libxl_types_internal.idl
+++ b/tools/libxl/libxl_types_internal.idl
@@ -14,6 +14,7 @@ libxl__qmp_message_type = Enumeration("qmp_message_type", [
])
libxl__device_kind = Enumeration("device_kind", [
+ (0, "NONE"),
(1, "VIF"),
(2, "VBD"),
(3, "QDISK"),
diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c
index 4982b52..b3bac6d 100644
--- a/tools/libxl/libxl_xshelp.c
+++ b/tools/libxl/libxl_xshelp.c
@@ -20,8 +20,12 @@
char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array)
{
char **kvs;
- int i, length = array->count;
+ int i, length;
+ if (!array)
+ return NULL;
+
+ length = array->count;
if (!length)
return NULL;
--
2.6.6
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-09-20 12:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-20 12:01 [PATCH v3 0/4] libxl: add HVM USB passthrough capability Juergen Gross
2016-09-20 12:01 ` [PATCH v3 1/4] libxl: add function to remove usb controller xenstore entries Juergen Gross
2016-09-20 12:01 ` Juergen Gross [this message]
2016-09-20 12:01 ` [PATCH v3 3/4] libxl: add HVM usb passthrough support Juergen Gross
2016-09-20 13:24 ` Wei Liu
2016-09-20 12:01 ` [PATCH v3 4/4] docs: add HVM USB passthrough documentation Juergen Gross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1474372870-9408-3-git-send-email-jgross@suse.com \
--to=jgross@suse.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).