Re: [Xen-devel] [PATCH 4/5] xl: add vsnd CLI commands

2017-10-30 Thread Wei Liu
On Mon, Oct 02, 2017 at 12:49:23PM +0300, Oleksandr Grytsov wrote:
> From: Oleksandr Grytsov 
> 
> Add CLI commands to attach, detach and list virtual sound devices
> 
> Signed-off-by: Oleksandr Grytsov 

Acked-by: Wei Liu 

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH 4/5] xl: add vsnd CLI commands

2017-10-02 Thread Oleksandr Grytsov
From: Oleksandr Grytsov 

Add CLI commands to attach, detach and list virtual sound devices

Signed-off-by: Oleksandr Grytsov 
---
 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",
+  _vsndattach, 1, 1,
+  "Create a new virtual sound device",
+  " ...",
+},
+{ "vsnd-list",
+  _vsndlist, 0, 0,
+  "List virtual display devices for a domain",
+  "",
+},
+{ "vsnd-detach",
+  _vsnddetach, 0, 1,
+  "Destroy a domain's virtual sound device",
+  " ",
+},
 { "uptime",
   _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 000..5e27a5d
--- /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();
+domid = find_domain(argv[optind++]);
+
+for (argv += optind, argc -= optind; argc > 0; ++argv, --argc) {
+rc = parse_vsnd_item(, *argv);
+if (rc) goto out;
+}
+
+if (dryrun_only) {
+char *json = libxl_device_vsnd_to_json(ctx, );
+printf("vsnd: %s\n", json);
+free(json);
+goto out;
+}
+
+if (libxl_device_vsnd_add(ctx, domid, , 0)) {
+fprintf(stderr, "libxl_device_vsnd_add failed.\n");
+rc = ERROR_FAIL; goto out;
+}
+
+rc = 0;
+
+out:
+libxl_device_vsnd_dispose();
+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