From patchwork Wed Nov 1 15:04:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 10036469 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 C9E5E602B5 for ; Wed, 1 Nov 2017 15:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6B122843B for ; Wed, 1 Nov 2017 15:07:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB2B628C4D; Wed, 1 Nov 2017 15:07:34 +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 1D8E628C42 for ; Wed, 1 Nov 2017 15:07:33 +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 1e9uZh-00056A-Tg; Wed, 01 Nov 2017 15:05:01 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9uZh-00055V-0y for xen-devel@lists.xenproject.org; Wed, 01 Nov 2017 15:05:01 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id CF/BC-01775-C92E9F95; Wed, 01 Nov 2017 15:05:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPIsWRWlGSWpSXmKPExsVyMfS6s+7sRz8 jDU7sUrf4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOOHbrOXHDHseJbj2wD4x+DLkYuDiGBaYwS O/+9YQJxWAReskh8fb+ABcSREOhnldh1czVrFyMnkJMl8frmCzYIO01i6qcGRgi7VOLmgZvMI LaQgLzEwZbL7BBjpzBJbH61gx0kwSagJXH/9gqwZhEBJYl7qyYzgdjMAikSe9e1gQ0SFjCUWN Q6H8xmEVCV6Lv/lwXE5hWwl5j18RjUEXISN891gi3jFHCQuP1iLlANB9Aye4ndVyonMAouYGR YxahRnFpUllqka2Spl1SUmZ5RkpuYmaNraGCsl5taXJyYnpqTmFSsl5yfu4kRGHD1DAyMOxib 9vodYpTkYFIS5dW8/zNSiC8pP6UyI7E4I76oNCe1+BCjBgeHwM+nf1sYpVjy8vNSlSR4Ax8C1 QkWpaanVqRl5gBjAqZUgoNHSYT36AOgNG9xQWJucWY6ROoUoyvHhTuX/jBxHNt0GUge2HMLSH bcvAskn8183cAsBDZbSpyXARiRQgIgzRmleXCjYfF8iVFWSpiXkYGBQYinILUoN7MEVf4Vozg Ho5Iw72mQC3ky80rgLngFdBwT0HFeEj9AjitJREhJNTD6nG68KVjP8+vog2lVSu+t38VtM7OJ OWsz5fMe6+/vnjm5+R10Xa1Uc5C/+9yX+Qkf5qo/ZtlQabAmy2dFVb/Xh3/fkjpOxt8/InJXg KvlYLGcqETwxJ7Zgu5POM/f+VsbMO95sy+7+70fndwrP36PfvvRKsB6ovlD67N7Loj+1t+ud2 Kh0cQUJZbijERDLeai4kQA8yWKz+ICAAA= X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1509548699!101286910!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 33671 invoked from network); 1 Nov 2017 15:04:59 -0000 Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by server-2.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Nov 2017 15:04:59 -0000 Received: by mail-lf0-f67.google.com with SMTP id 75so2893468lfx.1 for ; Wed, 01 Nov 2017 08:04:59 -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=oxi3NXWB+KULyjGihp1UcpkNflSCbj0Izu5oLzLfKNc=; b=FNbNotdTAoVAqMqlLL4O316BaiCd5VA1oEq/uxX/b7aKRaeeIgWIGatjEW8kEo/dFP Dh+LYq3H/kPfZmcKgjo6a5h7+b/E4mGDmMEHdEduM8p0OQVI3EfxOloNA5nDQZQDKuTb 29TyqykPau9MB5JJbMVsbmCQ6vxiXLm2F8/sfbgsSAAf9vZD8tDewhMpjzfZOIEqThZm LuM8DOxyA6k6oudcH4wZczX2+zMJAtfnHOTN4u/qJ7/T2Rr4uEyodo2X4Qj8zDJCWSp5 a9m+YKAK9YiWUc2uZEKnFTf8ko398PSb14vIFz/FP+MzqQPm0+zGEF3eYMH5JfCYOB9L ex+g== 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=oxi3NXWB+KULyjGihp1UcpkNflSCbj0Izu5oLzLfKNc=; b=TCuuudwhfn6F7hqkLNZpWYJ782VsCPIT0BBcM6eJqRvau644Wh2dsIAsOOawgd3cb9 VVTLZ4jo3cBP3N3kI2BoTrAHF8ZaC9vf0QDgvlNDebJAAwiBxvjl26BHCVxg7Z2ewKJx PYKqBL2dsFtOTyd6aMiekGX/bz8EuSyT32s84HdSCF8Y5pzf7N2PGx01YtgEU/T08X76 vHOdaTSstIlh8UmPMiqGCx62+KfCgu9vfMLu34ldnVkQ8gObPKcX4ww/zr+Rxp5knGOR cwK6hIffmNk39oIi2tAkm7Ppbq8ODWmXZLoO/qL3ShXEP0KfV8K0IHrkKKE8JUI++cED Y47g== X-Gm-Message-State: AMCzsaWe1uZFKeyyDK9LG1A9mUq6r8tWYEd0gRNrXJBLiuc7Yzu9156F U/Hr/WpVhpOASwircle9uUdbOw== X-Google-Smtp-Source: ABhQp+Sn3XjCdsENNIUUDMfyBU7c+UbpcVM8udyW/2ecnQrJELj2UkJUIfv302p9t88NDNYg3qhlOw== X-Received: by 10.25.15.22 with SMTP id e22mr59669lfi.64.1509548698593; Wed, 01 Nov 2017 08:04:58 -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 77sm173505ljj.12.2017.11.01.08.04.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Nov 2017 08:04:57 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Wed, 1 Nov 2017 17:04:46 +0200 Message-Id: <1509548687-6071-5-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509548687-6071-1-git-send-email-al1img@gmail.com> References: <1509548687-6071-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/5] xl: add vsnd CLI 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 CLI commands to attach, detach and list virtual sound devices Signed-off-by: Oleksandr Grytsov Acked-by: Wei Liu --- tools/xl/Makefile | 2 +- tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 15 ++++ tools/xl/xl_vsnd.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 tools/xl/xl_vsnd.c diff --git a/tools/xl/Makefile b/tools/xl/Makefile index a5117ab..66bdbde 100644 --- a/tools/xl/Makefile +++ b/tools/xl/Makefile @@ -22,7 +22,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_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 += xl_vdispl.o xl_vsnd.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS += $(CFLAGS_XL) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 31d660b..703caa6 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -170,6 +170,9 @@ 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_vsndattach(int argc, char **argv); +int main_vsndlist(int argc, char **argv); +int main_vsnddetach(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 c304a85..8e162ce 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -397,6 +397,21 @@ struct cmd_spec cmd_table[] = { "Destroy a domain's virtual display device", " ", }, + { "vsnd-attach", + &main_vsndattach, 1, 1, + "Create a new virtual sound device", + " ...", + }, + { "vsnd-list", + &main_vsndlist, 0, 0, + "List virtual display devices for a domain", + "", + }, + { "vsnd-detach", + &main_vsnddetach, 0, 1, + "Destroy a domain's virtual sound device", + " ", + }, { "uptime", &main_uptime, 0, 0, "Print uptime for all/some domains", diff --git a/tools/xl/xl_vsnd.c b/tools/xl/xl_vsnd.c new file mode 100644 index 0000000..41ee0ba --- /dev/null +++ b/tools/xl/xl_vsnd.c @@ -0,0 +1,203 @@ +/* + * 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_vsndattach(int argc, char **argv) +{ + int opt; + int rc; + uint32_t domid; + libxl_device_vsnd vsnd; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vsnd-attach", 2) { + /* No options */ + } + + libxl_device_vsnd_init(&vsnd); + domid = find_domain(argv[optind++]); + + for (argv += optind, argc -= optind; argc > 0; ++argv, --argc) { + rc = parse_vsnd_item(&vsnd, *argv); + if (rc) goto out; + } + + if (dryrun_only) { + char *json = libxl_device_vsnd_to_json(ctx, &vsnd); + printf("vsnd: %s\n", json); + free(json); + goto out; + } + + if (libxl_device_vsnd_add(ctx, domid, &vsnd, 0)) { + fprintf(stderr, "libxl_device_vsnd_add failed.\n"); + rc = ERROR_FAIL; goto out; + } + + rc = 0; + +out: + libxl_device_vsnd_dispose(&vsnd); + return rc; +} + +static void print_params(libxl_vsnd_params *params) +{ + int i; + + if (params->channels_min) { + printf(", channels-min: %u", params->channels_min); + } + + if (params->channels_max) { + printf(", channels-max: %u", params->channels_max); + } + + if (params->buffer_size) { + printf(", buffer-size: %u", params->buffer_size); + } + + if (params->num_sample_rates) { + printf(", sample-rates: "); + for (i = 0; i < params->num_sample_rates - 1; i++) { + printf("%u;", params->sample_rates[i]); + } + printf("%u", params->sample_rates[i]); + } + + if (params->num_sample_formats) { + printf(", sample-formats: "); + for (i = 0; i < params->num_sample_formats - 1; i++) { + printf("%s;", libxl_vsnd_pcm_format_to_string(params->sample_formats[i])); + } + printf("%s", libxl_vsnd_pcm_format_to_string(params->sample_formats[i])); + } + + printf("\n"); +} + +int main_vsndlist(int argc, char **argv) +{ + int opt; + int i, j, k, n; + libxl_device_vsnd *vsnds; + libxl_vsndinfo vsndinfo; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vsnd-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; + } + + vsnds = libxl_device_vsnd_list(ctx, domid, &n); + + if (!vsnds) continue; + + for (i = 0; i < n; i++) { + libxl_vsndinfo_init(&vsndinfo); + if (libxl_device_vsnd_getinfo(ctx, domid, &vsnds[i], + &vsndinfo) == 0) { + printf("\ndevid: %d, be-domid: %d, handle: %d, state: %d, " + "be-path: %s, fe-path: %s\n", + vsndinfo.devid, vsndinfo.backend_id, + vsndinfo.frontend_id, vsndinfo.state, + vsndinfo.backend, vsndinfo.frontend); + + printf("short-name: \"%s\", long-name: \"%s\"", + vsnds[i].short_name, vsnds[i].long_name); + print_params(&vsnds[i].params); + + for (j = 0; j < vsndinfo.num_vsnd_pcms; j++) { + libxl_vsnd_pcm *pcm = &vsnds[i].pcms[j]; + + printf("\tpcm: %d, name: \"%s\"", j, pcm->name); + print_params(&pcm->params); + + for(k = 0; k < vsnds[i].pcms[j].num_vsnd_streams; k++) { + libxl_vsnd_stream *stream = &vsnds[i].pcms[j].streams[k]; + libxl_streaminfo *info = &vsndinfo.pcms[j].streams[k]; + + printf("\t\tstream: %d, id: \"%s\", type: %s", + k, stream->id, + libxl_vsnd_stream_type_to_string(stream->type)); + print_params(&stream->params); + printf("\t\t\tevent-channel: %d, ring-ref: %d\n", + info->req_evtch, info->req_rref); + } + } + } + libxl_vsndinfo_dispose(&vsndinfo); + } + libxl_device_vsnd_list_free(vsnds, n); + } + return 0; +} + +int main_vsnddetach(int argc, char **argv) +{ + uint32_t domid, devid; + int opt, rc; + libxl_device_vsnd vsnd; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vsnd-detach", 2) { + /* No options */ + } + + domid = find_domain(argv[optind++]); + devid = atoi(argv[optind++]); + + libxl_device_vsnd_init(&vsnd); + + if (libxl_devid_to_device_vsnd(ctx, domid, devid, &vsnd)) { + fprintf(stderr, "Error: Device %d not connected.\n", devid); + rc = ERROR_FAIL; + goto out; + } + + rc = libxl_device_vsnd_remove(ctx, domid, &vsnd, 0); + if (rc) { + fprintf(stderr, "libxl_device_vsnd_remove failed.\n"); + rc = ERROR_FAIL; + goto out; + } + + rc = 0; + +out: + libxl_device_vsnd_dispose(&vsnd); + return rc; +} + + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */