From patchwork Tue Sep 12 13:48:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9949279 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 8ADC460360 for ; Tue, 12 Sep 2017 13:51:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AA8B287A9 for ; Tue, 12 Sep 2017 13:51:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F87B28FE9; Tue, 12 Sep 2017 13:51:13 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, 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 52449287A9 for ; Tue, 12 Sep 2017 13:51:12 +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 1drlYH-0005UF-Pe; Tue, 12 Sep 2017 13:48:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drlYG-0005Sy-2o for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 13:48:32 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id 86/1F-02817-FA5E7B95; Tue, 12 Sep 2017 13:48:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRWlGSWpSXmKPExsVyMfS6s+66p9s jDTbvUbf4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOmHVvBXrAxruLk0u+sDYwvXboYuTiEBKYz Sqx494oJxGEReMkisa11KTuIIyHQzyoxofUJWxcjJ5CTJHHu0x92CDtN4sKCd6wQdrnEs0XdT CC2kIC8xMGWy+wQY6cwSTTceMsMkmAT0JK4f3sF2CARASWJe6smgzUwC6RI7F3XxghiCwvYSH xsegO2gEVAVaKh8yZYDa+Ag0TLtyNQR8hJ3DzXCTaTU8BRov13FzPEYgeJK2v2sE1gFFzAyLC KUb04tagstUjXUC+pKDM9oyQ3MTNH19DAVC83tbg4MT01JzGpWC85P3cTIzDk6hkYGHcwNvU6 H2KU5GBSEuVVvr89UogvKT+lMiOxOCO+qDQntfgQowYHh8DPp39bGKVY8vLzUpUkeMOeANUJF qWmp1akZeYAowKmVIKDR0mEtxIkzVtckJhbnJkOkTrFaM9x4c6lP0wcxzZdBpIH9twCkh037/ 5hEgKbKiXOmw/SJgDSllGaBzcUFsWXGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzVoNM4cn MK4Hb/QroLCags3gubQE5qyQRISXVwOgcr3yDY11kQFT2lLYvF36ZhXWv+cKcuXjK7PR/Ny8X RZZ/F2B6qnfsspv88fdXrLi7p7CGaHLGT6hivx/jcns/x4f2GZ19c84Lc86Yp/Znqnt7itsad 3nTRLZKPfdISZGG5EXz+iZsjo6tduVVEFua7d4y+1Zm4tobWWm2GTbGIlOlLLcxKbEUZyQaaj EXFScCAGLKqCzdAgAA X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1505224110!95670888!1 X-Originating-IP: [209.85.215.67] 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 33426 invoked from network); 12 Sep 2017 13:48:30 -0000 Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by server-13.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 13:48:30 -0000 Received: by mail-lf0-f67.google.com with SMTP id y15so5396309lfd.0 for ; Tue, 12 Sep 2017 06:48:30 -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=OvOXUNKfWpE2aT9ka7y7TBJ6UOhLJSGFh1jyaiU24kE=; b=HUfF6aF9cKSPYqaQKDLlrsvqTLRXd8Tj5e2TohazNqA1O7+eDNZ6z1i7mzc7MWQtvM bILgWwxot3TaY5f5jemICxAHwm7Za+d8uywMJCBjtORBhwjEE7VKXyzGNjFNaaCm7g1h JIJwLsmalWmTj66bEThTRuBcTBJvmQoopX5ynif/63Dbk47yFQJ5zWwTzq0C06Godvlc 5SX2p4f+C5F23Xy3B3ygV4y6qsOwz6MZK8Uchd8weiwD2eFF7iffI4nuX58MScC6YMEz MReF6xtil7fNO9CDKC6ZSMAvCBCRAqAEbM9MYa5QGVW9B5hsoMI0X/DTsemEz95iQ9yH mrFQ== 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=OvOXUNKfWpE2aT9ka7y7TBJ6UOhLJSGFh1jyaiU24kE=; b=DJq7bebXCSjahmnCVV4VB6e35AODzUpmvOjQjHavE71G13PuklPqD2blgQgaWZOHbm kqxay+hTUFkv6yJm4VF7aSFFoyXFskMKgoyrIlXXpzz+q9C+hOFBnoi4U5594PYJ6YLz Fj8OcPNY0t0jfx9jjK47ua2z6/WQYCOLHVeIHlDHdlpV6jBSgI6v9f6xwGqv4jLmqjLB TGdQg4H+sjjWOUQairHOprUX5W3tuku+ViU2SwY2VUBxgj/HJGchpZbvzDUBLg6i1nu3 7zpwene3XCkBLvKokGU9tbYRajale0upQ0XOFf2SGHqxuEILhj6oYlniso3ckaHfxidm 9mlQ== X-Gm-Message-State: AHPjjUi3iq/up+WJgVUXIxAr/nbIDrVX0kwNSAsc+t7LUZlaIVYMcoQf WJiY8sJ0KYVPC1OIbUo= X-Google-Smtp-Source: AOwi7QD7ua7ZkjC2UvlKc8TLHMTLWHU0QiGEb2l2eanPRpqLZEETdUeIaZWmSneafL7v5WUANocpmg== X-Received: by 10.25.15.22 with SMTP id e22mr4510684lfi.16.1505224109591; Tue, 12 Sep 2017 06:48:29 -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 s5sm690074lfb.14.2017.09.12.06.48.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Sep 2017 06:48:28 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Tue, 12 Sep 2017 16:48:09 +0300 Message-Id: <1505224098-19330-5-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505224098-19330-1-git-send-email-al1img@gmail.com> References: <1505224098-19330-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v6 04/13] 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 Add commands: vdispl-attach, vdispl-list, vdispl-detach and domain config vdispl parser Signed-off-by: Oleksandr Grytsov Acked-by: Wei Liu --- tools/xl/Makefile | 1 + tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 19 ++++++ tools/xl/xl_parse.c | 75 ++++++++++++++++++++++- tools/xl/xl_parse.h | 2 +- tools/xl/xl_vdispl.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 tools/xl/xl_vdispl.c diff --git a/tools/xl/Makefile b/tools/xl/Makefile index c868899..41a09ed 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 5d3d2a4..98d62e9 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -167,6 +167,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 ba0159d..d0330cd 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -377,6 +377,25 @@ struct cmd_spec cmd_table[] = { "Destroy a domain's virtual TPM device", " ", }, + { "vdispl-attach", + &main_vdisplattach, 1, 1, + "Create a new virtual display device", + " [backend=] [be-alloc=] [connectors='']", + " BackAlloc - set to 1 to if backend allocates display buffers\n" + " Connectors - list of connector's description in ID:WxH format,\n" + " where: ID - unique connector ID, W - connector width,\n" + " H - connector height: connectors='id0:800x600;id1:1024x768'\n" + }, + { "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 02ddd2e..9965b83 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -804,6 +804,51 @@ int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) return 0; } +int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token) +{ + char *oparg; + libxl_string_list connectors = NULL; + int i; + int rc; + + if (MATCH_OPTION("backend", token, oparg)) { + vdispl->backend_domname = strdup(oparg); + } else if (MATCH_OPTION("be-alloc", token, oparg)) { + vdispl->be_alloc = strtoul(oparg, NULL, 0); + } else if (MATCH_OPTION("connectors", token, oparg)) { + split_string_into_string_list(oparg, ";", &connectors); + + vdispl->num_connectors = libxl_string_list_length(&connectors); + vdispl->connectors = calloc(vdispl->num_connectors, + sizeof(*vdispl->connectors)); + + for(i = 0; i < vdispl->num_connectors; i++) + { + char *resolution; + + rc = split_string_into_pair(connectors[i], ":", + &vdispl->connectors[i].id, + &resolution); + + rc= sscanf(resolution, "%ux%u", &vdispl->connectors[i].width, + &vdispl->connectors[i].height); + if (rc != 2) { + fprintf(stderr, "Can't parse connector resolution\n"); + goto out; + } + } + } else { + fprintf(stderr, "Unknown string \"%s\" in vdispl spec\n", token); + rc = 1; goto out; + } + + rc = 0; + +out: + libxl_string_list_dispose(&connectors); + return rc; +} + void parse_config_data(const char *config_source, const char *config_data, int config_len, @@ -813,7 +858,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, *p9devs; + *usbctrls, *usbdevs, *p9devs, *vdispls; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs, *mca_caps; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_caps; @@ -1489,6 +1534,34 @@ 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)) { + free(buf2); + exit(1); + } + p = strtok (NULL, ","); + } + free(buf2); + if (vdispl->num_connectors == 0) { + fprintf(stderr, "At least one connector should be specified.\n"); + exit(1); + } + } + } + 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..3cc99b6 --- /dev/null +++ b/tools/xl/xl_vdispl.c @@ -0,0 +1,163 @@ +/* + * 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; + 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) { + rc = parse_vdispl_config(&vdispl, *argv); + if (rc) goto out; + } + + if (vdispl.num_connectors == 0) { + fprintf(stderr, "At least one connector should be specified.\n"); + rc = ERROR_FAIL; 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; goto out; + } + + rc = 0; + +out: + libxl_device_vdispl_dispose(&vdispl); + return rc; +} + +int main_vdispllist(int argc, char **argv) +{ + int opt; + int i, j, n; + libxl_device_vdispl *vdispls; + libxl_vdisplinfo vdisplinfo; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vdispl-list", 1) { + /* No options */ + } + + 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) { + printf("DevId: %d, BE: %d, handle: %d, state: %d, " + "be-alloc: %d, BE-path: %s, FE-path: %s\n", + vdisplinfo.devid, vdisplinfo.backend_id, + vdisplinfo.frontend_id, + vdisplinfo.state, vdisplinfo.be_alloc, + vdisplinfo.backend, vdisplinfo.frontend); + + for (j = 0; j < vdisplinfo.num_connectors; j++) { + printf("\tConnector: %d, id: %s, width: %d, height: %d, " + "req-rref: %d, req-evtch: %d, " + "evt-rref: %d, evt-evtch: %d\n", + j, vdisplinfo.connectors[j].id, + vdisplinfo.connectors[j].width, + vdisplinfo.connectors[j].height, + vdisplinfo.connectors[j].req_rref, + vdisplinfo.connectors[j].req_evtch, + vdisplinfo.connectors[j].evt_rref, + vdisplinfo.connectors[j].evt_evtch); + } + } + 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: + */