From patchwork Thu Mar 23 10:10:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9640665 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 2F82F601E9 for ; Thu, 23 Mar 2017 10:12:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1997E2793B for ; Thu, 23 Mar 2017 10:12:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E48B27F17; Thu, 23 Mar 2017 10:12:57 +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 5DA772793B for ; Thu, 23 Mar 2017 10:12:56 +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 1cqzhb-0003vN-AW; Thu, 23 Mar 2017 10:10:43 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cqzhZ-0003u0-Vn for xen-devel@lists.xenproject.org; Thu, 23 Mar 2017 10:10:42 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id D0/B2-25093-12F93D85; Thu, 23 Mar 2017 10:10:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrMIsWRWlGSWpSXmKPExsXiVRvkrKsw/3K EQW+/gsX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmrHvwkL2gicBFUe+PmRrYLxl08XIxSEkMINR YtHpf4wgDovASxaJE/umsYM4EgL9rBJbJz0BcjiBnBiJK1vvQdnlEpf3rGQDsYUE5CUOtlxmh xg1jUniwtulTCAJNgEtifu3V4AViQgoSdxbNRkszixgJPHy1XKwQcIC5hJvJr5kAbFZBFQlDs 7dCRbnFbCX2N77iQVimZzEzXOdzCA2p4CDRNuXD0wQi+0lvk7tYJrAKLCAkWEVo0ZxalFZapG uoZFeUlFmekZJbmJmjq6hgZlebmpxcWJ6ak5iUrFecn7uJkZgcDEAwQ7GyxsDDjFKcjApifLG uV6OEOJLyk+pzEgszogvKs1JLT7EqMHBIfDz6d8WRimWvPy8VCUJ3gVzgeoEi1LTUyvSMnOA4 Q9TKsHBoyTCmw+S5i0uSMwtzkyHSJ1iNOaYM3v3GyaOD/2H3zAJgU2SEuddC1IqAFKaUZoHNw gWl5cYZaWEeRmBzhTiKUgtys0sQZV/xSjOwagkzKs7D2gKT2ZeCdy+V0CnMAGdUrbnAsgpJYk IKakGxpuvfzZulay7uJFB7+Od6ay24fMuzZV49qMt4Wqy3vrGx8f4NOX1Q0wXN1uVn11UcvCl x99E7/ifHrp3RP+pPfPUik1hWj3h7OHwq0fOSPjlSb14Vvy7+PT/2s1Wa68LtB2d8InTjPGm6 e6O0nVyewrs05m64r6kCFTsNNR/sGSVmW3XjA8CUkosxRmJhlrMRcWJAPIhoQXGAgAA X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-11.tower-21.messagelabs.com!1490263840!63715449!1 X-Originating-IP: [74.125.82.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57633 invoked from network); 23 Mar 2017 10:10:40 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-11.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 23 Mar 2017 10:10:40 -0000 Received: by mail-wm0-f67.google.com with SMTP id n11so15495725wma.0 for ; Thu, 23 Mar 2017 03:10:40 -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=Hhdds0WyqEr0RW9uC6hCfZV9o101yWh03GXBLsItnu0=; b=VG+WrK1yrHFsxEhKxAWu2UjygVrFQi/Kf3P8cfU+OVUdtgTkMsNZsoZs3ocxVW6s2S zGLFO94qu/SEL8IA5FPxRhXbmHENxXSIVCWXM5Jmww+DAoIjmbWNTsQXf59p7yQgfiau ZLqCUGSpgEHI+esr3ERChu2Y0zwXjnKjXYDk9DeLyS9BQiIBMbWqNORsDnbQ6lC/cP3G aPIlxAy5CmhX4f1vGlyLZr8a7Km5w6xzD99hRxNhKZOx1tQf5wusz1CRWo7n8PyO4OsK eqq8aQuTsVSflVMt+LuW6WjKJQEujwnQlIvfWCCzz+NdnrolTL7QuT/wi5HNGIsNP2wl 2veg== 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=Hhdds0WyqEr0RW9uC6hCfZV9o101yWh03GXBLsItnu0=; b=RCk5ySgMjwVzwJf8WsnhRUH/fliRm+yVaF1B9V+2ljI+LGx0l8AMxVB8+GEKQiIuwR um7RmJ3A4AEOtQuCYa6W5pdq6WmC1mh54QjO4mCgDS7UQ3z98I/h/XFX5xwmShutZ9Ko BxXP/dn491npcpMWznvwH1cDE8KIv1hdTE8j4HlhwMyvYCdSuSNGkKKDIjZjshO6JqS+ LiH0A21aok7P+2rys6qLrNp7KBFj0ivrBP7dSjJeYSAPlSG7+qkTBBO/Z4T+8BHYUm4j y2EI22zRt1FYlX+ENy7cWAe1FSkFE/Lakv4XpXZ9MuEAPrllOQsGgyZ99hJB3bFlUIgn 7CXg== X-Gm-Message-State: AFeK/H0/JbNaRCIQ4RVFSsanHHUzvRfw9bb3tx9/ORtC6S6aKzbmbbZ+Hn/nGbdo6y9JRg== X-Received: by 10.28.184.8 with SMTP id i8mr11317437wmf.26.1490263839804; Thu, 23 Mar 2017 03:10:39 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-56.209.223.85.sovam.net.ua. [85.223.209.56]) by smtp.gmail.com with ESMTPSA id t85sm3656303wmt.23.2017.03.23.03.10.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Mar 2017 03:10:39 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Thu, 23 Mar 2017 12:10:32 +0200 Message-Id: <1490263832-9068-3-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490263832-9068-1-git-send-email-al1img@gmail.com> References: <1490263832-9068-1-git-send-email-al1img@gmail.com> Cc: Oleksandr Grytsov Subject: [Xen-devel] [PATCH 2/2] xl: add PV display device commands 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/xl/Makefile | 1 + tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 16 +++++ tools/xl/xl_parse.c | 44 +++++++++++++- tools/xl/xl_parse.h | 2 +- tools/xl/xl_vdispl.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 tools/xl/xl_vdispl.c diff --git a/tools/xl/Makefile b/tools/xl/Makefile index e16f877..5c784b5 100644 --- a/tools/xl/Makefile +++ b/tools/xl/Makefile @@ -21,6 +21,7 @@ XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o XL_OBJS += xl_psr.o xl_info.o xl_console.o xl_misc.o XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o +XL_OBJS += xl_vdispl.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS += $(CFLAGS_XL) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 1ad0726..370a0d4 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -165,6 +165,9 @@ int main_blockdetach(int argc, char **argv); int main_vtpmattach(int argc, char **argv); int main_vtpmlist(int argc, char **argv); int main_vtpmdetach(int argc, char **argv); +int main_vdisplattach(int argc, char **argv); +int main_vdispllist(int argc, char **argv); +int main_vdispldetach(int argc, char **argv); int main_usbctrl_attach(int argc, char **argv); int main_usbctrl_detach(int argc, char **argv); int main_usbdev_attach(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 1219b33..1050dc1 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -372,6 +372,22 @@ struct cmd_spec cmd_table[] = { "Destroy a domain's virtual TPM device", " ", }, + { "vdispl-attach", + &main_vdisplattach, 1, 1, + "Create a new virtual display device", + " [devId=] [backend=] [beAlloc=]", + " BackAlloc - set to 1 to allow backend allocated display buffers" + }, + { "vdispl-list", + &main_vdispllist, 0, 0, + "List virtual display devices for a domain", + "", + }, + { "vdispl-detach", + &main_vdispldetach, 0, 1, + "Destroy a domain's virtual display device", + " ", + }, { "uptime", &main_uptime, 0, 0, "Print uptime for all/some domains", diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 1ef0c27..6d378ed 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -707,6 +707,25 @@ int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) return 0; } +int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token) +{ + char *oparg; + + if (MATCH_OPTION("backend", token, oparg)) { + vdispl->backend_domid = find_domain(oparg); + vdispl->backend_domname = strdup(oparg); + } else if (MATCH_OPTION("devId", token, oparg)) { + vdispl->devid = atoi(oparg); + } else if (MATCH_OPTION("beAlloc", token, oparg)) { + vdispl->be_alloc = strtoul(oparg, NULL, 0); + } else { + fprintf(stderr, "Unknown string `%s' in vdispl spec\n", token); + return 1; + } + + return 0; +} + void parse_config_data(const char *config_source, const char *config_data, int config_len, @@ -716,7 +735,7 @@ void parse_config_data(const char *config_source, long l, vcpus = 0; XLU_Config *config; XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, - *usbctrls, *usbdevs; + *usbctrls, *usbdevs, *vdispls; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian; int pci_power_mgmt = 0; @@ -1295,6 +1314,29 @@ void parse_config_data(const char *config_source, } } + if (!xlu_cfg_get_list(config, "vdispl", &vdispls, 0, 0)) { + d_config->num_vdispls = 0; + d_config->vdispls = NULL; + while ((buf = xlu_cfg_get_listitem(vdispls, d_config->num_vdispls)) != NULL) { + libxl_device_vdispl *vdispl; + char * buf2 = strdup(buf); + char *p; + vdispl = ARRAY_EXTEND_INIT(d_config->vdispls, + d_config->num_vdispls, + libxl_device_vdispl_init); + p = strtok (buf2, ","); + while (p != NULL) + { + while (*p == ' ') p++; + if (parse_vdispl_config(vdispl, p)) { + exit(1); + } + p = strtok (NULL, ","); + } + free(buf2); + } + } + if (!xlu_cfg_get_list (config, "channel", &channels, 0, 0)) { d_config->num_channels = 0; d_config->channels = NULL; diff --git a/tools/xl/xl_parse.h b/tools/xl/xl_parse.h index db8bc3f..cc459fb 100644 --- a/tools/xl/xl_parse.h +++ b/tools/xl/xl_parse.h @@ -33,7 +33,7 @@ int parse_usbctrl_config(libxl_device_usbctrl *usbctrl, char *token); int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token); int parse_cpurange(const char *cpu, libxl_bitmap *cpumap); int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token); - +int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token); int match_option_size(const char *prefix, size_t len, char *arg, char **argopt); diff --git a/tools/xl/xl_vdispl.c b/tools/xl/xl_vdispl.c new file mode 100644 index 0000000..4df90c9 --- /dev/null +++ b/tools/xl/xl_vdispl.c @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2016 EPAM Systems Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include + +#include +#include +#include + +#include "xl.h" +#include "xl_utils.h" +#include "xl_parse.h" + +int main_vdisplattach(int argc, char **argv) +{ + int opt; + int rc; + char *oparg; + uint32_t domid; + libxl_device_vdispl vdispl; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vdispl-attach", 1) { + /* No options */ + } + + libxl_device_vdispl_init(&vdispl); + domid = find_domain(argv[optind++]); + + for (argv += optind, argc -= optind; argc > 0; ++argv, --argc) { + if (MATCH_OPTION("devId", *argv, oparg)) { + vdispl.devid = atoi(oparg); + } else if (MATCH_OPTION("backend", *argv, oparg)) { + vdispl.backend_domid = find_domain(oparg); + replace_string(&vdispl.backend_domname, oparg); + } else if (MATCH_OPTION("beAlloc", *argv, oparg)) { + vdispl.be_alloc = strtoul(oparg, NULL, 0); + } else { + fprintf(stderr, "unrecognized argument `%s'\n", *argv); + rc = 1; + goto out; + } + } + + if (dryrun_only) { + char *json = libxl_device_vdispl_to_json(ctx, &vdispl); + printf("vdispl: %s\n", json); + free(json); + goto out; + } + + if (libxl_device_vdispl_add(ctx, domid, &vdispl, 0)) { + fprintf(stderr, "libxl_device_vdispl_add failed.\n"); + rc = ERROR_FAIL; + } + + rc = 0; + +out: + libxl_device_vdispl_dispose(&vdispl); + return rc; +} + +int main_vdispllist(int argc, char **argv) +{ + int opt; + int i, n; + libxl_device_vdispl *vdispls; + libxl_vdisplinfo vdisplinfo; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vdispl-list", 1) { + /* No options */ + } + + /* vdisplinfo.uuid should be outputted too */ + printf("%-5s %-3s %-6s %-5s %-8s %-40s %-40s\n", + "Vdev", "BE", "handle", "state", "be-alloc", "BE-path", "FE-path"); + for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) { + uint32_t domid; + + if (libxl_domain_qualifier_to_domid(ctx, *argv, &domid) < 0) { + fprintf(stderr, "%s is an invalid domain identifier\n", *argv); + continue; + } + + vdispls = libxl_device_vdispl_list(ctx, domid, &n); + + if (!vdispls) { + continue; + } + + for (i = 0; i < n; i++) { + libxl_vdisplinfo_init(&vdisplinfo); + if (libxl_device_vdispl_getinfo(ctx, domid, &vdispls[i], + &vdisplinfo) == 0) { + /* Vdev BE hdl st be-alloc BE-path FE-path*/ + printf("%-5d %-3d %-6d %-5d %-8d %-40s %-40s\n", + vdisplinfo.devid, vdisplinfo.backend_id, + vdisplinfo.frontend_id, + vdisplinfo.state, vdisplinfo.be_alloc, + vdisplinfo.backend, vdisplinfo.frontend); + } + libxl_vdisplinfo_dispose(&vdisplinfo); + } + + libxl_device_vdispl_list_free(vdispls, n); + } + return 0; +} + +int main_vdispldetach(int argc, char **argv) +{ + uint32_t domid, devid; + int opt, rc; + libxl_device_vdispl vdispl; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vdispl-detach", 2) { + /* No options */ + } + + domid = find_domain(argv[optind++]); + devid = atoi(argv[optind++]); + + libxl_device_vdispl_init(&vdispl); + + if (libxl_devid_to_device_vdispl(ctx, domid, devid, &vdispl)) { + fprintf(stderr, "Error: Device %d not connected.\n", devid); + rc = ERROR_FAIL; + goto out; + } + + rc = libxl_device_vdispl_remove(ctx, domid, &vdispl, 0); + if (rc) { + fprintf(stderr, "libxl_device_vdispl_remove failed.\n"); + rc = ERROR_FAIL; + goto out; + } + + rc = 0; + +out: + libxl_device_vdispl_dispose(&vdispl); + return rc; +} + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */