From patchwork Thu Nov 2 18:06:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 10039137 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 0DFCF600C5 for ; Thu, 2 Nov 2017 18:09:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04F7D28698 for ; Thu, 2 Nov 2017 18:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC36328B30; Thu, 2 Nov 2017 18:09:24 +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 5211228698 for ; Thu, 2 Nov 2017 18:09:24 +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 1eAJtG-00059D-Aj; Thu, 02 Nov 2017 18:06:54 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAJtE-00057l-By for xen-devel@lists.xen.org; Thu, 02 Nov 2017 18:06:52 +0000 Received: from [85.158.137.68] by server-14.bemta-3.messagelabs.com id 07/6F-00431-BBE5BF95; Thu, 02 Nov 2017 18:06:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmkeJIrShJLcpLzFFi42LpnVTnqrsr7ne kwb3fhhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bujXvZCvb4V8zrNG5gXGbVxcjFISQwgUni 57duRgjnD6PE2+k/mSGcDYwSF/e9ZodwuhglDrTOACrj5GAT0JNoPf+ZGcQWETCSaDs+kR3EZ haokfh6eS1YXFjAQ6Ln63G2LkYODhYBVYm2q+EgYV4BO4nHs5rByiUE5CV2tV1kBSnhFLCXmD CjACQsBFTSvWYLVImhxOmH2xgnMPItYGRYxahenFpUllqka6GXVJSZnlGSm5iZo2toYKyXm1p cnJiempOYVKyXnJ+7iREYJAxAsIPxQrvzIUZJDiYlUd67G39FCvEl5adUZiQWZ8QXleakFh9i lOHgUJLg3Rj7O1JIsCg1PbUiLTMHGK4waQkOHiUR3jsgad7igsTc4sx0iNQpRmOOjpt3/zBxP Jv5uoFZiCUvPy9VSpw3A6RUAKQ0ozQPbhAsji4xykoJ8zICnSbEU5BalJtZgir/ilGcg1FJmP cIyBSezLwSuH2vgE5hAjrFS+IHyCkliQgpqQbGU9O/TPr6YtG2s1d/Ogu8Wvb4WE+qbcWH5pe Hd1ZOuLhRMuHmhme3pb+eOvDewS8mbPrdH3cqtK5KdE7IS//UJvfM6Kl8w7/ANDG2faqzlb5M 2Ri1fVniSg69siW/F1+3erjp8J370nHbo/3yXNZyPXzKE3uy9ohCVaf5kX9fm27ZSSzarqVz4 rgSS3FGoqEWc1FxIgBrcF79ngIAAA== X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1509646009!57704629!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 8639 invoked from network); 2 Nov 2017 18:06:50 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-9.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Nov 2017 18:06:50 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA2I6kBf018489 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 18:06:46 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vA2I6jpg028750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 18:06:46 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vA2I6jGj005477; Thu, 2 Nov 2017 18:06:45 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:44 -0700 From: Joao Martins To: Xen Development List Date: Thu, 2 Nov 2017 18:06:12 +0000 Message-Id: <20171102180616.24084-5-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: userv0021.oracle.com [156.151.31.71] Cc: Wei Liu , Joao Martins , Ian Jackson Subject: [Xen-devel] [PATCH RFC 4/8] libxl: add backend_features to libxl_device_nic 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 Adds "backend_features" to the libxl_device_nic structure to represent a set of features to be set on the device by the admin. These backend_features is a key value store representing an array of = , which would then be translated into (backend-only permissions) xenstore entries in the form of: /local/domain//backend/vif///require /local/domain/[...]/require/ = Entries get stored under the require directory within the backend path. Adjust libxl__device_add and libxl__device_add_async to pass the third argument as the backend-only entries to be written to backend_path. Signed-off-by: Joao Martins --- tools/libxl/libxl.h | 8 ++++++++ tools/libxl/libxl_9pfs.c | 2 +- tools/libxl/libxl_console.c | 2 +- tools/libxl/libxl_device.c | 14 ++++++++------ tools/libxl/libxl_internal.h | 2 +- tools/libxl/libxl_nic.c | 13 ++++++++++++- tools/libxl/libxl_types.idl | 1 + tools/libxl/libxl_vdispl.c | 3 ++- tools/libxl/libxl_vtpm.c | 2 +- 9 files changed, 35 insertions(+), 12 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 82990089ef..5b4fbebf7b 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1109,6 +1109,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); */ #define LIBXL_HAVE_DISK_BACKEND_FEATURES 1 +/* + * LIBXL_HAVE_VIF_BACKEND_FEATURES + * + * libxl_device_nic contains backend_features which can be used to control + * what features are exposed to guest vifs. + */ +#define LIBXL_HAVE_VIF_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_9pfs.c b/tools/libxl/libxl_9pfs.c index 9db887b5d8..3b80b358f4 100644 --- a/tools/libxl/libxl_9pfs.c +++ b/tools/libxl/libxl_9pfs.c @@ -42,7 +42,7 @@ static LIBXL_DEFINE_UPDATE_DEVID(p9, "9pfs") static int libxl__set_xenstore_p9(libxl__gc *gc, uint32_t domid, libxl_device_p9 *p9, flexarray_t *back, flexarray_t *front, - flexarray_t *ro_front) + flexarray_t *ro_front, flexarray_t *require) { flexarray_append_pair(back, "path", p9->path); flexarray_append_pair(back, "security_model", p9->security_model); diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c index f40def1276..1c5a298750 100644 --- a/tools/libxl/libxl_console.c +++ b/tools/libxl/libxl_console.c @@ -730,7 +730,7 @@ static LIBXL_DEFINE_UPDATE_DEVID(vfb, "vfb") static int libxl__set_xenstore_vfb(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb, flexarray_t *back, flexarray_t *front, - flexarray_t *ro_front) + flexarray_t *ro_front, flexarray_t *require) { flexarray_append_pair(back, "vnc", libxl_defbool_val(vfb->vnc.enable) ? "1" : "0"); diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 05178fb480..87983e2ef9 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -1860,7 +1860,7 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid, libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); - flexarray_t *back; + flexarray_t *back, *require; flexarray_t *front, *ro_front; libxl__device *device; xs_transaction_t t = XBT_NULL; @@ -1912,6 +1912,7 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid, back = flexarray_make(gc, 16, 1); front = flexarray_make(gc, 16, 1); ro_front = flexarray_make(gc, 16, 1); + require = flexarray_make(gc, 16, 1); flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid)); flexarray_append_pair(back, "online", "1"); @@ -1924,7 +1925,7 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid, GCSPRINTF("%d", XenbusStateInitialising)); if (dt->set_xenstore_config) - dt->set_xenstore_config(gc, domid, type, back, front, ro_front); + dt->set_xenstore_config(gc, domid, type, back, front, ro_front, require); for (;;) { rc = libxl__xs_transaction_start(gc, &t); @@ -1948,7 +1949,7 @@ void libxl__device_add_async(libxl__egc *egc, uint32_t domid, libxl__xs_kvs_of_flexarray(gc, back), libxl__xs_kvs_of_flexarray(gc, front), libxl__xs_kvs_of_flexarray(gc, ro_front), - NULL); + libxl__xs_kvs_of_flexarray(gc, require)); rc = libxl__xs_transaction_commit(gc, &t); if (!rc) break; @@ -1974,7 +1975,7 @@ out: int libxl__device_add(libxl__gc *gc, uint32_t domid, const struct libxl_device_type *dt, void *type) { - flexarray_t *back; + flexarray_t *back, *require; flexarray_t *front, *ro_front; libxl__device *device; int rc; @@ -1996,6 +1997,7 @@ int libxl__device_add(libxl__gc *gc, uint32_t domid, back = flexarray_make(gc, 16, 1); front = flexarray_make(gc, 16, 1); ro_front = flexarray_make(gc, 16, 1); + require = flexarray_make(gc, 16, 1); flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid)); flexarray_append_pair(back, "online", "1"); @@ -2007,13 +2009,13 @@ int libxl__device_add(libxl__gc *gc, uint32_t domid, GCSPRINTF("%d", XenbusStateInitialising)); if (dt->set_xenstore_config) - dt->set_xenstore_config(gc, domid, type, back, front, ro_front); + dt->set_xenstore_config(gc, domid, type, back, front, ro_front, require); 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), - NULL); + libxl__xs_kvs_of_flexarray(gc, require)); if (rc) goto out; rc = 0; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 19c02e27a0..0881147d3c 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3507,7 +3507,7 @@ typedef int (*device_from_xenstore_fn_t)(libxl__gc *, const char *, libxl_devid, void *); typedef int (*device_set_xenstore_config_fn_t)(libxl__gc *, uint32_t, void *, flexarray_t *, flexarray_t *, - flexarray_t *); + flexarray_t *, flexarray_t *); struct libxl_device_type { char *type; diff --git a/tools/libxl/libxl_nic.c b/tools/libxl/libxl_nic.c index 1e6ba6c78d..d67155d58d 100644 --- a/tools/libxl/libxl_nic.c +++ b/tools/libxl/libxl_nic.c @@ -143,7 +143,7 @@ static LIBXL_DEFINE_UPDATE_DEVID(nic, "vif") static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic, flexarray_t *back, flexarray_t *front, - flexarray_t *ro_front) + flexarray_t *ro_front, flexarray_t *require) { flexarray_grow(back, 2); @@ -253,6 +253,17 @@ static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid, flexarray_append(front, GCSPRINTF( LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); + if (nic->backend_features) { + libxl_key_value_list features = nic->backend_features; + int i; + + for (i = 0; features[i] != NULL; i += 2) { + flexarray_append(require, libxl__strdup(gc, features[i])); + if (features[i+1]) + flexarray_append(require, libxl__strdup(gc, features[i+1])); + } + } + return 0; } diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 949a797402..fba6127bbc 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -652,6 +652,7 @@ libxl_device_disk = Struct("device_disk", [ libxl_device_nic = Struct("device_nic", [ ("backend_domid", libxl_domid), ("backend_domname", string), + ("backend_features", libxl_key_value_list), ("devid", libxl_devid), ("mtu", integer), ("model", string), diff --git a/tools/libxl/libxl_vdispl.c b/tools/libxl/libxl_vdispl.c index e61ef2dfcd..3c266f4c73 100644 --- a/tools/libxl/libxl_vdispl.c +++ b/tools/libxl/libxl_vdispl.c @@ -76,7 +76,8 @@ static void libxl__device_vdispl_add(libxl__egc *egc, uint32_t domid, static int libxl__set_xenstore_vdispl(libxl__gc *gc, uint32_t domid, libxl_device_vdispl *vdispl, flexarray_t *back, flexarray_t *front, - flexarray_t *ro_front) + flexarray_t *ro_front, + flexarray_t *require) { int i; diff --git a/tools/libxl/libxl_vtpm.c b/tools/libxl/libxl_vtpm.c index 3f0c56349d..1fbb95c8aa 100644 --- a/tools/libxl/libxl_vtpm.c +++ b/tools/libxl/libxl_vtpm.c @@ -54,7 +54,7 @@ static LIBXL_DEFINE_UPDATE_DEVID(vtpm, "vtpm") static int libxl__set_xenstore_vtpm(libxl__gc *gc, uint32_t domid, libxl_device_vtpm *vtpm, flexarray_t *back, flexarray_t *front, - flexarray_t *ro_front) + flexarray_t *ro_front, flexarray_t *require) { flexarray_append_pair(back, "handle", GCSPRINTF("%d", vtpm->devid)); flexarray_append_pair(back, "uuid",