From patchwork Wed Nov 1 15:05:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 10036475 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 B80C3604D7 for ; Wed, 1 Nov 2017 15:07:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DC52209CD for ; Wed, 1 Nov 2017 15:07:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 705BA28C44; Wed, 1 Nov 2017 15:07:41 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 19FBF28C28 for ; Wed, 1 Nov 2017 15:07:39 +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 1e9ua3-0005Lj-PA; Wed, 01 Nov 2017 15:05:23 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9ua2-0005K1-8m for xen-devel@lists.xenproject.org; Wed, 01 Nov 2017 15:05:22 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id 72/49-25852-1B2E9F95; Wed, 01 Nov 2017 15:05:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJIsWRWlGSWpSXmKPExsVyMfS6i+6GRz8 jDe7vN7f4vmUykwOjx+EPV1gCGKNYM/OS8isSWDPmnj3OVLDIpuLO11csDYxXtbsYuTiEBGYw Smw/08UK4rAIvGSR+Np/DcyREOhnlTj99RhjFyMnkJMlcfjFOTYIO03iwtozTBB2icSnqytZQ GwhAXmJgy2X2SHGTmWSmNvzD6yITUBL4v7tFWDNIgJKEvdWTQaLMwukSOxd1wa0gINDWMBOYu fyKpAwi4CqxIydf9hBwrwC9hIXjkGtkpO4ea6TGcTmFHCQONIykwlirb3Ez1mz2CYwCi5gZFj FqFGcWlSWWqRrbKiXVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKyXnJ+7iREYcAxAsIOxaVHg IUZJDiYlUV7N+z8jhfiS8lMqMxKLM+KLSnNSiw8xanBwCPx8+reFUYolLz8vVUmClxkY2EKCR anpqRVpmTnAmIApleDgURLh3fgQKM1bXJCYW5yZDpE6xWjPceHOpT9MHAf23AKSHTfvAslnM1 83MAuBTZUS52UAmSoA0pZRmgc3FBbDlxhlpYR5GYFOFuIpSC3KzSxBlX/FKM7BqCTM++wB0BS ezLwSuN2vgM5iAjrLS+IHyFkliQgpqQbG+bGrvWtZ3q1trYi4ZnPLTb+j9E/h1n+L3SZ2e84U LVj25+6FRyJyLKxubcaHjnw7Uzj/6c/rTVHCCZm+UyXlFNezSLboXVCRuMnjeFtT4cfuYP3uC 4L5p6Rm60oFK0fv5Tf6UOi+mStUe/Uatab0bfm1i+vOijQl3Yp++uhEzKbV++e08QoosRRnJB pqMRcVJwIAkx00SdwCAAA= X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1509548720!69692023!1 X-Originating-IP: [209.85.215.68] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49672 invoked from network); 1 Nov 2017 15:05:20 -0000 Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by server-5.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Nov 2017 15:05:20 -0000 Received: by mail-lf0-f68.google.com with SMTP id r135so2113555lfe.5 for ; Wed, 01 Nov 2017 08:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KUVKY9j22qS7RAW6JBMNiEKypJfQNjTlCPnhBby2lA4=; b=KWFaBRsGC/KynF09dLs7RpxdykJD7y0XRs/Rw4A6jNEt3ZHTsBmbORvV6i1A+UCDuO AeSsWb3vZJlAN+WrAbCZXXuu7oAbHoJ6J4TJeM7wDMsKoc9H8RYqM8mRtplGZGt5COiZ HJJP4ZmIc5RY+Gg5W0BPzdVhwEJh9OjR+e7Ng2sGNzwBLy7J/p/2SJqPZnA13BV7sQ66 QaCuOKKR8yTMMaHFSM8oTzsBw51YPvHWNq3AHCDGPgbJkVdvc5FAiVMVTT5xX/qbBmJU XuXLnnoaUSad+/EAQ6tI6P5hS/+8azV86SsvLs+RGRsg8xjXnS6+wxnm6K2xAnLLRbH2 qwOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KUVKY9j22qS7RAW6JBMNiEKypJfQNjTlCPnhBby2lA4=; b=cE/7L5YcyXaqKVwXsBrpEGg2p88U+MDH2Ep6gxb2rew+YjYEmmpqxWgnBLlr9Doi6h nQGd4ZuOLj8ooCWB+iqeIBORgPZC6eeD6G/OuTA09F14SQALowvZ9w/CO+4RM7ooajd6 Ly7xajsVfgXQsp/t4XihPwJDPrfCsVFhqXJFz6FIWOg1SP7ZKQlJCwijs3zBnEWuN/kO sLS24isR/GF32uZ/O3m7LNAeyajlKnDxdncguylqov4DcacjwYxlOdOL2EZuxi0p+imU Yza/uRcvrdjRCluoaBFF1rQFrXc5QYRSIvUGtW8ouS+mZlVvYiYpJCcTpXRcO2yj7KZk hxnQ== X-Gm-Message-State: AMCzsaVZHtOoP4C10uB1H4Ds405PlSUxn1eVy6iRl+Mv+DihiOJO/Oxc ycVL/94szVHqkTBq7z8CfqloqA== X-Google-Smtp-Source: ABhQp+QoHUvhTZwt/FcbwziVJCsoXyQ5VkKHlwjqircFCRFx9VuXcgV+MpUfXA9ik5khT8kjsflPJQ== X-Received: by 10.46.22.88 with SMTP id 24mr72014ljw.20.1509548719850; Wed, 01 Nov 2017 08:05:19 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-59.209.223.85.sovam.net.ua. [85.223.209.59]) by smtp.gmail.com with ESMTPSA id o88sm139569lfk.33.2017.11.01.08.05.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Nov 2017 08:05:19 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Wed, 1 Nov 2017 17:05:05 +0200 Message-Id: <1509548707-6134-5-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509548707-6134-1-git-send-email-al1img@gmail.com> References: <1509548707-6134-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v1 4/6] libxl: vkb add list and info functions 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 From: Oleksandr Grytsov Signed-off-by: Oleksandr Grytsov --- tools/libxl/libxl.h | 10 ++++ tools/libxl/libxl_types.idl | 11 ++++ tools/libxl/libxl_utils.h | 3 ++ tools/libxl/libxl_vkb.c | 129 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 150 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index acb73ce..f2f8442 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1950,6 +1950,16 @@ int libxl_device_vkb_destroy(libxl_ctx *ctx, uint32_t domid, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; +libxl_device_vkb *libxl_device_vkb_list(libxl_ctx *ctx, + uint32_t domid, int *num) + LIBXL_EXTERNAL_CALLERS_ONLY; +void libxl_device_vkb_list_free(libxl_device_vkb* list, int num) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_t domid, + libxl_device_vkb *vkb, + libxl_vkbinfo *vkbinfo) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* Framebuffer */ int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb, const libxl_asyncop_how *ao_how) diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index c3876a2..d19af46 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -1015,6 +1015,17 @@ libxl_vsndinfo = Struct("vsndinfo", [ ("pcms", Array(libxl_pcminfo, "num_vsnd_pcms")) ]) +libxl_vkbinfo = Struct("vkbinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", libxl_devid), + ("state", integer), + ("evtch", integer), + ("rref", integer) + ], dir=DIR_OUT) + # NUMA node characteristics: size and free are how much memory it has, and how # much of it is free, respectively. dists is an array of distances from this # node to each other node. diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h index 5455752..44409af 100644 --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -79,6 +79,9 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid, int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_usbctrl *usbctrl); +int libxl_devid_to_device_vkb(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_vkb *vkb); + int libxl_devid_to_device_vdispl(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_vdispl *vdispl); diff --git a/tools/libxl/libxl_vkb.c b/tools/libxl/libxl_vkb.c index 88ab186..72ae53d 100644 --- a/tools/libxl/libxl_vkb.c +++ b/tools/libxl/libxl_vkb.c @@ -13,6 +13,7 @@ */ #include "libxl_internal.h" +#include static int libxl__device_vkb_setdefault(libxl__gc *gc, uint32_t domid, libxl_device_vkb *vkb, bool hotplug) @@ -62,6 +63,45 @@ static int libxl__set_xenstore_vkb(libxl__gc *gc, uint32_t domid, return 0; } +static int libxl__vkb_from_xenstore(libxl__gc *gc, const char *libxl_path, + libxl_devid devid, + libxl_device_vkb *vkb) +{ + const char *be_path, *be_type, *fe_path; + int rc; + + vkb->devid = devid; + + rc = libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + &be_path); + if (rc) goto out; + + rc = libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/frontend", libxl_path), + &fe_path); + if (rc) goto out; + + rc = libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/backend-type", libxl_path), + &be_type); + if (rc) goto out; + + rc = libxl_vkb_backend_from_string(be_type, &vkb->backend_type); + if (rc) goto out; + + vkb->id = xs_read(CTX->xsh, XBT_NULL, GCSPRINTF("%s/id", fe_path), NULL); + + rc = libxl__backendpath_parse_domid(gc, be_path, &vkb->backend_domid); + if (rc) goto out; + + rc = 0; + +out: + + return rc; +} + int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb, const libxl_asyncop_how *ao_how) { @@ -79,19 +119,102 @@ out: return AO_INPROGRESS; } +int libxl_devid_to_device_vkb(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_vkb *vkb) +{ + GC_INIT(ctx); + + libxl_device_vkb *vkbs = NULL; + int n, i; + int rc; + + libxl_device_vkb_init(vkb); + + vkbs = libxl__device_list(gc, &libxl__vkb_devtype, domid, &n); + + if (!vkbs) { rc = ERROR_NOTFOUND; goto out; } + + for (i = 0; i < n; ++i) { + if (devid == vkbs[i].devid) { + libxl_device_vkb_copy(ctx, vkb, &vkbs[i]); + rc = 0; + goto out; + } + } + + rc = ERROR_NOTFOUND; + +out: + + if (vkbs) + libxl__device_list_free(&libxl__vkb_devtype, vkbs, n); + + GC_FREE; + return rc; +} + +int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_t domid, + libxl_device_vkb *vkb, + libxl_vkbinfo *info) +{ + GC_INIT(ctx); + char *libxl_path, *dompath, *devpath; + char *val; + int rc; + + libxl_vkbinfo_init(info); + dompath = libxl__xs_get_dompath(gc, domid); + info->devid = vkb->devid; + + devpath = GCSPRINTF("%s/device/vkbd/%d", dompath, info->devid); + libxl_path = GCSPRINTF("%s/device/vkbd/%d", + libxl__xs_libxl_path(gc, domid), + info->devid); + info->backend = xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + NULL); + if (!info->backend) { rc = ERROR_FAIL; goto out; } + + rc = libxl__backendpath_parse_domid(gc, info->backend, &info->backend_id); + if (rc) goto out; + + val = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/state", devpath)); + info->state = val ? strtoul(val, NULL, 10) : -1; + + info->frontend = xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/frontend", libxl_path), + NULL); + info->frontend_id = domid; + + val = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/"XENKBD_FIELD_EVT_CHANNEL, devpath)); + info->evtch = val ? strtoul(val, NULL, 10) : -1; + + val = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/"XENKBD_FIELD_RING_GREF, devpath)); + info->rref = val ? strtoul(val, NULL, 10) : -1; + + rc = 0; + +out: + GC_FREE; + return rc; +} + static LIBXL_DEFINE_UPDATE_DEVID(vkb, "vkbd") #define libxl__add_vkbs NULL -#define libxl_device_vkb_list NULL #define libxl_device_vkb_compare NULL +LIBXL_DEFINE_DEVICE_LIST(vkb) LIBXL_DEFINE_DEVICE_REMOVE(vkb) -DEFINE_DEVICE_TYPE_STRUCT_X(vkb, vkb, vkbd +DEFINE_DEVICE_TYPE_STRUCT_X(vkb, vkb, vkbd, .skip_attach = 1, .dm_needed = (device_dm_needed_fn_t)libxl__device_vkb_dm_needed, .set_xenstore_config = (device_set_xenstore_config_fn_t) - libxl__set_xenstore_vkb + libxl__set_xenstore_vkb, + .from_xenstore = (device_from_xenstore_fn_t)libxl__vkb_from_xenstore ); /*