From patchwork Thu Sep 8 07:20:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 9320533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6053260869 for ; Thu, 8 Sep 2016 07:22:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 438C22961B for ; Thu, 8 Sep 2016 07:22:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 381BA2961F; Thu, 8 Sep 2016 07:22:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 956FC2961B for ; Thu, 8 Sep 2016 07:22:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhtdT-0007ZK-AE; Thu, 08 Sep 2016 07:20:35 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhtdR-0007Vu-6K for xen-devel@lists.xen.org; Thu, 08 Sep 2016 07:20:33 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 7C/94-06162-04111D75; Thu, 08 Sep 2016 07:20:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVyuP0Ov6694MV wg9lHFC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1owPNyIKlhlVrN1xgrmB8aZqFyMnh4SAkcTb if+Yuhi5OIQEFjJKHNq4lRkkwSagKrHh+ilWEFtEQFri2ufLjCA2s0CxxIJvL8DiwgKeEi3LJ 4HZLED1MxdOZgGxeQXsJXZvuM4CsUBO4vrM6UwgNqeAg8TFU4fZQGwhoJp9Ox+wT2DkXsDIsI pRvTi1qCy1SNdcL6koMz2jJDcxM0fX0MBYLze1uDgxPTUnMalYLzk/dxMj0LcMQLCDsfG70yF GSQ4mJVFen+IL4UJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeNfzXwwXEixKTU+tSMvMAQYZTFqC g0dJhPcQSJq3uCAxtzgzHSJ1ilFRSpz3JUhCACSRUZoH1wYL7EuMslLCvIxAhwjxFKQW5WaWo Mq/YhTnYFQS5n0NMoUnM68EbvoroMVMQIuFTp0HWVySiJCSamCM6bnmwCpzNv/Dg4i0Jz+lXI JFcovV2JwPF9VZLmRgkF/8/MHRkPz/Cz7uNfuye9dSof+HfxWGONyXXfR2/nYJM6m1j5bLmV0 43cB1jft+61tuXb9pf/ljPNJK2NaukWMpm8UqrpubHvgpiENJZFrkv3nXTzfVHzi8IyDdLX7D JFknq9MGc04qsRRnJBpqMRcVJwIAAU4JRmcCAAA= X-Env-Sender: jgross@suse.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1473319231!58959667!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 38544 invoked from network); 8 Sep 2016 07:20:31 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-13.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 8 Sep 2016 07:20:31 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BDC00AC77; Thu, 8 Sep 2016 07:20:30 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xen.org Date: Thu, 8 Sep 2016 09:20:24 +0200 Message-Id: <1473319226-27221-5-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.6 In-Reply-To: <1473319226-27221-1-git-send-email-jgross@suse.com> References: <1473319226-27221-1-git-send-email-jgross@suse.com> Cc: George.Dunlap@eu.citrix.com, wei.liu2@citrix.com, ian.jackson@eu.citrix.com, Juergen Gross Subject: [Xen-devel] [PATCH 4/6] libxl: add basic support for devices without backend X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 9c77b62..5211f20 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 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 @@ -662,12 +676,18 @@ 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); 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; @@ -681,10 +701,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;