From patchwork Thu Nov 2 18:06:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 10039131 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 01DD7600C5 for ; Thu, 2 Nov 2017 18:09:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE9AD290DE for ; Thu, 2 Nov 2017 18:09:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E309129216; Thu, 2 Nov 2017 18:09:18 +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, UNPARSEABLE_RELAY 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 3217C290DE for ; Thu, 2 Nov 2017 18:09:18 +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 1eAJtE-00057r-0F; Thu, 02 Nov 2017 18:06:52 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAJtC-00057f-A4 for xen-devel@lists.xen.org; Thu, 02 Nov 2017 18:06:50 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id EB/86-14867-9BE5BF95; Thu, 02 Nov 2017 18:06:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42LpnVTnqrsj7ne kwbGHRhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bcWbPYC3bFV1ydv5q9gbHbrYuRi0NIYBKT xLNz85i6GDmBnF+MEv1vQyESGxglzh1bzQrhdDFKfOhbzQ5SxSagJ9F6/jMziC0iYCTRdnwiW JxZoEbi6+W1YHFhAU+Jxf+/MILYLAKqEq+23QXbwCtgJ7H1x19WEFtCQF5iV9tFIJuDg1PAXm LCjAKII+wkutdsYYcoMZZof3uRbQIj3wJGhlWMGsWpRWWpRbpGRnpJRZnpGSW5iZk5uoYGZnq 5qcXFiempOYlJxXrJ+bmbGIGBwgAEOxjXzA88xCjJwaQkynt3469IIb6k/JTKjMTijPii0pzU 4kOMMhwcShK8tbG/I4UEi1LTUyvSMnOAIQuTluDgURLhvQOS5i0uSMwtzkyHSJ1iNObouHn3D xPHs5mvG5iFWPLy81KlxHnvgpQKgJRmlObBDYLF0iVGWSlhXkag04R4ClKLcjNLUOVfMYpzMC oJ87aATOHJzCuB2/cK6BQmoFO8JH6AnFKSiJCSamCMYGa5cErA81fxc8GjjfE33cKbfjE83vH AS7jqWPJs8wlnZ+dx5t2avyGhLKTL8X2K8nMpM8ElTKnH3h9i0nTSmr2+d4Un10WB5iPpXzee 6tY03Kp/7fZCufrC/d3+u4X1auYxlhesW6ej81CipJjDISz824X284bHuMw61vCs5Dl26oKD4 FUlluKMREMt5qLiRABqzU8UoAIAAA== X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1509646007!57125175!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35659 invoked from network); 2 Nov 2017 18:06:48 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-6.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Nov 2017 18:06:48 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA2I6itj018469 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 18:06:44 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vA2I6hw5009255 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 18:06:44 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vA2I6h4s010220; Thu, 2 Nov 2017 18:06:43 GMT Received: from paddy.uk.oracle.com (/10.175.173.7) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Nov 2017 11:06:42 -0700 From: Joao Martins To: Xen Development List Date: Thu, 2 Nov 2017 18:06:11 +0000 Message-Id: <20171102180616.24084-4-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171102180616.24084-1-joao.m.martins@oracle.com> References: <20171102180616.24084-1-joao.m.martins@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: Wei Liu , Joao Martins , Ian Jackson Subject: [Xen-devel] [PATCH RFC 3/8] libxl: add backend_features to libxl_device_disk 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 The function libxl__device_generic_add will have an additional argument whereby it adds a second set of entries visible to the backend only. These entries will then be used for devices thus overriding backend maximum feature set with this user-defined ones. libxl_device_disk.backend_features are a key value store storing: = xl|libxl are stateless with respect to feature names therefore is up to the admin to carefully select those. If backend isn't supported therefore the features won't be overwritten. Signed-off-by: Joao Martins --- tools/libxl/libxl.h | 8 ++++++++ tools/libxl/libxl_console.c | 5 +++-- tools/libxl/libxl_device.c | 37 +++++++++++++++++++++++++++++++++---- tools/libxl/libxl_disk.c | 17 +++++++++++++++-- tools/libxl/libxl_internal.h | 4 +++- tools/libxl/libxl_pci.c | 2 +- tools/libxl/libxl_types.idl | 1 + tools/libxl/libxl_usb.c | 2 +- 8 files changed, 65 insertions(+), 11 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 5e9aed739d..82990089ef 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1101,6 +1101,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); */ #define LIBXL_HAVE_SET_PARAMETERS 1 +/* + * LIBXL_HAVE_DISK_BACKEND_FEATURES + * + * libxl_device_disk contains backend_features which can be used to control + * what features are exposed to guest vbds. + */ +#define LIBXL_HAVE_DISK_BACKEND_FEATURES 1 + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c index c05dc28b99..f40def1276 100644 --- a/tools/libxl/libxl_console.c +++ b/tools/libxl/libxl_console.c @@ -339,7 +339,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid, 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)); + libxl__xs_kvs_of_flexarray(gc, ro_front), NULL); rc = 0; out: return rc; @@ -385,7 +385,8 @@ int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid, rc = libxl__device_generic_add(gc, XBT_NULL, &device, libxl__xs_kvs_of_flexarray(gc, back), NULL, - libxl__xs_kvs_of_flexarray(gc, ro_front)); + libxl__xs_kvs_of_flexarray(gc, ro_front), + NULL); return rc; } diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 5438577c3c..05178fb480 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -43,6 +43,15 @@ char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device) device->domid, device->devid); } +char *libxl__device_require_path(libxl__gc *gc, libxl__device *device) +{ + char *dom_path = libxl__xs_get_dompath(gc, device->backend_domid); + + return GCSPRINTF("%s/backend/%s/%u/%d/require", dom_path, + libxl__device_kind_to_string(device->backend_kind), + device->domid, device->devid); +} + char *libxl__device_libxl_path(libxl__gc *gc, libxl__device *device) { char *libxl_dom_path = libxl__xs_libxl_path(gc, device->domid); @@ -114,13 +123,16 @@ out: } int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t, - libxl__device *device, char **bents, char **fents, char **ro_fents) + libxl__device *device, char **bents, char **fents, char **ro_fents, + char **brents) { libxl_ctx *ctx = libxl__gc_owner(gc); - char *frontend_path = NULL, *backend_path = NULL, *libxl_path; + char *frontend_path = NULL, *backend_path = NULL, *require_path = NULL, + *libxl_path; struct xs_permissions frontend_perms[2]; struct xs_permissions ro_frontend_perms[2]; struct xs_permissions backend_perms[2]; + struct xs_permissions require_perms[1]; int create_transaction = t == XBT_NULL; int libxl_only = device->backend_kind == LIBXL__DEVICE_KIND_NONE; int rc; @@ -131,6 +143,7 @@ int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t, } else { frontend_path = libxl__device_frontend_path(gc, device); backend_path = libxl__device_backend_path(gc, device); + require_path = libxl__device_require_path(gc, device); } libxl_path = libxl__device_libxl_path(gc, device); @@ -144,6 +157,9 @@ int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t, ro_frontend_perms[1].id = backend_perms[1].id = device->domid; ro_frontend_perms[1].perms = backend_perms[1].perms = XS_PERM_READ; + require_perms[0].id = device->backend_domid; + require_perms[0].perms = XS_PERM_NONE; + retry_transaction: if (create_transaction) t = xs_transaction_start(ctx->xsh); @@ -200,6 +216,12 @@ retry_transaction: frontend_path, strlen(frontend_path)); libxl__xs_writev(gc, t, backend_path, bents); } + if (brents) { + xs_mkdir(ctx->xsh, t, require_path); + xs_set_permissions(ctx->xsh, t, require_path, require_perms, + ARRAY_SIZE(require_perms)); + libxl__xs_writev(gc, t, require_path, brents); + } /* * We make a copy of everything for the backend in the libxl @@ -226,6 +248,11 @@ retry_transaction: */ rc = libxl__xs_writev(gc, t, libxl_path, bents); if (rc) goto out; + + if (brents) { + rc = libxl__xs_writev(gc, t, libxl_path, brents); + if (rc) goto out; + } } if (!create_transaction) @@ -1920,7 +1947,8 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid, 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)); + libxl__xs_kvs_of_flexarray(gc, ro_front), + NULL); rc = libxl__xs_transaction_commit(gc, &t); if (!rc) break; @@ -1984,7 +2012,8 @@ int libxl__device_add(libxl__gc *gc, uint32_t domid, 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)); + libxl__xs_kvs_of_flexarray(gc, ro_front), + NULL); if (rc) goto out; rc = 0; diff --git a/tools/libxl/libxl_disk.c b/tools/libxl/libxl_disk.c index 895bf4f89a..8caf763c88 100644 --- a/tools/libxl/libxl_disk.c +++ b/tools/libxl/libxl_disk.c @@ -239,14 +239,16 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid, STATE_AO_GC(aodev->ao); flexarray_t *front = NULL; flexarray_t *back = NULL; + flexarray_t *require = NULL; char *dev = NULL, *script; libxl__device *device; - int rc; + int rc, i; libxl_ctx *ctx = gc->owner; xs_transaction_t t = XBT_NULL; libxl_domain_config d_config; libxl_device_disk disk_saved; libxl__domain_userdata_lock *lock = NULL; + libxl_key_value_list back_features = disk->backend_features; libxl_domain_config_init(&d_config); libxl_device_disk_init(&disk_saved); @@ -300,6 +302,7 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid, front = flexarray_make(gc, 16, 1); back = flexarray_make(gc, 16, 1); + require = flexarray_make(gc, 16, 1); GCNEW(device); rc = libxl__device_from_disk(gc, domid, disk, device); @@ -433,6 +436,15 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid, } } + if (back_features) { + for (i = 0; back_features[i] != NULL; i += 2) { + flexarray_append(require, libxl__strdup(gc, back_features[i])); + if (back_features[i + 1]) + flexarray_append(require, + libxl__strdup(gc, back_features[i + 1])); + } + } + if (!get_vdev && aodev->update_json) { rc = libxl__set_domain_configuration(gc, domid, &d_config); if (rc) goto out; @@ -441,7 +453,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid, libxl__device_generic_add(gc, t, device, libxl__xs_kvs_of_flexarray(gc, back), libxl__xs_kvs_of_flexarray(gc, front), - NULL); + NULL, + libxl__xs_kvs_of_flexarray(gc, require)); rc = libxl__xs_transaction_commit(gc, &t); if (!rc) break; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 45e6df6c82..19c02e27a0 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1216,8 +1216,10 @@ _hidden int libxl__device_vuart_add(libxl__gc *gc, uint32_t domid, _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); + libxl__device *device, char **bents, + char **fents, char **ro_fents, char **brents); _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device); +_hidden char *libxl__device_require_path(libxl__gc *gc, libxl__device *device); _hidden char *libxl__device_libxl_path(libxl__gc *gc, libxl__device *device); _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path, libxl__device *dev); diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 88a55ce8bd..1d595513f5 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -106,7 +106,7 @@ int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, return libxl__device_generic_add(gc, XBT_NULL, &device, libxl__xs_kvs_of_flexarray(gc, back), libxl__xs_kvs_of_flexarray(gc, front), - NULL); + NULL, NULL); } static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting) diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index a239324341..949a797402 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -627,6 +627,7 @@ libxl_device_vkb = Struct("device_vkb", [ libxl_device_disk = Struct("device_disk", [ ("backend_domid", libxl_domid), ("backend_domname", string), + ("backend_features", libxl_key_value_list), ("pdev_path", string), ("vdev", string), ("backend", libxl_disk_backend), diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index cb0e792724..97e54272f1 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -283,7 +283,7 @@ static int libxl__device_usbctrl_add_xenstore(libxl__gc *gc, uint32_t domid, libxl__device_generic_add(gc, t, device, libxl__xs_kvs_of_flexarray(gc, back), libxl__xs_kvs_of_flexarray(gc, front), - NULL); + NULL, NULL); rc = libxl__xs_transaction_commit(gc, &t); if (!rc) break;