* [WIP PATCH 14/16] WIP: tools/xl: Enhance "list" command
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
@ 2020-12-09 22:34 ` Elliott Mitchell
2020-12-09 22:34 ` [WIP PATCH 07/16] tools/xl: Sort list command options Elliott Mitchell
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-09 22:34 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
Add several features to specify output. Allow omitting potentially
unneeded lines and add argument for exact line format.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_cmdtable.c | 2 ++
tools/xl/xl_list.c | 16 +++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index f44c65a3f8..91c2026bc8 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -53,6 +53,7 @@ struct cmd_spec cmd_table[] = {
&main_list, 0, 0,
"List information about all/some domains",
"[options] [Domain]\n",
+ "-0, --no-domain0 Omit information for Domain 0\n"
"-F, --format Specify output format string\n"
" Similar to printf(3) formatting, conversion characters are:\n"
" %A NODE Affinity\n"
@@ -67,6 +68,7 @@ struct cmd_spec cmd_table[] = {
" %t Time(s)\n"
" %u UUID\n"
" %v vCPUs\n"
+ "-H, --no-header Omit table header\n"
"-Z, --context Prints out security context\n"
"-c, --cpupool Prints the cpupool the domain is in\n"
"-l, --long Output all VM details\n"
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index 3ed6da8feb..49ff2acaad 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -397,6 +397,8 @@ int main_list(int argc, char **argv)
bool context = false;
bool cpupool = false;
bool details = false;
+ bool dom0 = true;
+ bool header = true;
const char *formatstr = NULL;
bool numa = false;
bool verbose = false;
@@ -405,6 +407,8 @@ int main_list(int argc, char **argv)
{"cpupool", 0, 0, 'c'},
{"format", 0, 0, 'F'},
{"long", 0, 0, 'l'},
+ {"no-domain0", 0, 0, '0'},
+ {"no-header", 0, 0, 'H'},
{"numa", 0, 0, 'n'},
{"verbose", 0, 0, 'v'},
COMMON_LONG_OPTS
@@ -414,10 +418,16 @@ int main_list(int argc, char **argv)
libxl_dominfo *info, *info_free=0;
int nb_domain, rc;
- SWITCH_FOREACH_OPT(opt, "F:Zchlnv", opts, "list", 0) {
+ SWITCH_FOREACH_OPT(opt, "0F:HZchlnv", opts, "list", 0) {
+ case '0':
+ dom0 = false;
+ break;
case 'F':
formatstr = optarg;
break;
+ case 'H':
+ header = false;
+ break;
case 'Z':
context = true;
break;
@@ -476,10 +486,10 @@ int main_list(int argc, char **argv)
return EXIT_FAILURE;
}
- format(formats, formatstr, NULL);
+ if (header) format(formats, formatstr, NULL);
while (nb_domain) {
- format(formats, formatstr, info);
+ if (info->domid || dom0) format(formats, formatstr, info);
++info;
--nb_domain;
}
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 07/16] tools/xl: Sort list command options
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
2020-12-09 22:34 ` [WIP PATCH 14/16] WIP: tools/xl: Enhance "list" command Elliott Mitchell
@ 2020-12-09 22:34 ` Elliott Mitchell
2020-12-09 22:45 ` [WIP PATCH 06/16] tools/xl: Split list commands off of xl_info.c Elliott Mitchell
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-09 22:34 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
Simply a minor housekeeping task. Unfortunately no single order really
dominates. Some spots use the option name, some the option letter.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_cmdtable.c | 4 ++--
tools/xl/xl_list.c | 22 +++++++++++-----------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 6ab5e47da3..6a05bf7ce2 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -53,11 +53,11 @@ struct cmd_spec cmd_table[] = {
&main_list, 0, 0,
"List information about all/some domains",
"[options] [Domain]\n",
- "-l, --long Output all VM details\n"
- "-v, --verbose Prints out UUIDs and security context\n"
"-Z, --context Prints out security context\n"
"-c, --cpupool Prints the cpupool the domain is in\n"
+ "-l, --long Output all VM details\n"
"-n, --numa Prints out NUMA node affinity"
+ "-v, --verbose Prints out UUIDs and security context\n"
},
{ "destroy",
&main_destroy, 0, 1,
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index ac6a9e5eac..8b391a9056 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -129,17 +129,17 @@ static void list_domains(bool verbose, bool context, bool claim, bool numa,
int main_list(int argc, char **argv)
{
int opt;
- bool verbose = false;
bool context = false;
- bool details = false;
bool cpupool = false;
+ bool details = false;
bool numa = false;
+ bool verbose = false;
static struct option opts[] = {
- {"long", 0, 0, 'l'},
- {"verbose", 0, 0, 'v'},
{"context", 0, 0, 'Z'},
{"cpupool", 0, 0, 'c'},
+ {"long", 0, 0, 'l'},
{"numa", 0, 0, 'n'},
+ {"verbose", 0, 0, 'v'},
COMMON_LONG_OPTS
};
@@ -147,22 +147,22 @@ int main_list(int argc, char **argv)
libxl_dominfo *info, *info_free=0;
int nb_domain, rc;
- SWITCH_FOREACH_OPT(opt, "lvhZcn", opts, "list", 0) {
- case 'l':
- details = true;
- break;
- case 'v':
- verbose = true;
- break;
+ SWITCH_FOREACH_OPT(opt, "Zchlnv", opts, "list", 0) {
case 'Z':
context = true;
break;
case 'c':
cpupool = true;
break;
+ case 'l':
+ details = true;
+ break;
case 'n':
numa = true;
break;
+ case 'v':
+ verbose = true;
+ break;
}
libxl_dominfo_init(&info_buf);
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 06/16] tools/xl: Split list commands off of xl_info.c
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
2020-12-09 22:34 ` [WIP PATCH 14/16] WIP: tools/xl: Enhance "list" command Elliott Mitchell
2020-12-09 22:34 ` [WIP PATCH 07/16] tools/xl: Sort list command options Elliott Mitchell
@ 2020-12-09 22:45 ` Elliott Mitchell
2020-12-10 23:09 ` [WIP PATCH 09/16] WIP: tools/xl: Implement generalized output formatting for `xl list` Elliott Mitchell
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-09 22:45 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
The domain listing commands have more in common with each other than
hypervisor information commands.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
I'm concerned about my header-stripping job. Notably the headers
<sys/stat.h>, <sys/types.h>, and <libxlutil.h> were removed from *both*
files. This could be cause for celebration, or this could mean my
build system's headers are nice and someone else's system needs these.
---
tools/xl/Makefile | 2 +-
tools/xl/xl_info.c | 221 ---------------------------------------
tools/xl/xl_list.c | 254 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 255 insertions(+), 222 deletions(-)
create mode 100644 tools/xl/xl_list.c
diff --git a/tools/xl/Makefile b/tools/xl/Makefile
index bdf67c8464..eb20d834d4 100644
--- a/tools/xl/Makefile
+++ b/tools/xl/Makefile
@@ -21,7 +21,7 @@ XL_OBJS = xl.o xl_cmdtable.o xl_sxp.o xl_utils.o $(XL_OBJS-y)
XL_OBJS += xl_parse.o xl_cpupool.o xl_flask.o
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_info.o xl_list.o xl_console.o xl_misc.o
XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o
XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o
diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c
index bc88014f10..e12f26994e 100644
--- a/tools/xl/xl_info.c
+++ b/tools/xl/xl_info.c
@@ -17,8 +17,6 @@
#include <fcntl.h>
#include <inttypes.h>
#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <sys/utsname.h>
#include <time.h>
#include <unistd.h>
@@ -26,7 +24,6 @@
#include <libxl.h>
#include <libxl_json.h>
#include <libxl_utils.h>
-#include <libxlutil.h>
#include "xl.h"
#include "xl_utils.h"
@@ -336,105 +333,6 @@ static void print_info(int numa)
return;
}
-static void list_vm(void)
-{
- libxl_vminfo *info;
- char *domname;
- int nb_vm, i;
-
- info = libxl_list_vm(ctx, &nb_vm);
-
- if (!info) {
- fprintf(stderr, "libxl_list_vm failed.\n");
- exit(EXIT_FAILURE);
- }
- printf("UUID ID name\n");
- for (i = 0; i < nb_vm; i++) {
- domname = libxl_domid_to_name(ctx, info[i].domid);
- printf(LIBXL_UUID_FMT " %d %-30s\n", LIBXL_UUID_BYTES(info[i].uuid),
- info[i].domid, domname);
- free(domname);
- }
- libxl_vminfo_list_free(info, nb_vm);
-}
-
-static void list_domains(bool verbose, bool context, bool claim, bool numa,
- bool cpupool, const libxl_dominfo *info, int nb_domain)
-{
- int i;
- static const char shutdown_reason_letters[]= "-rscwS";
- libxl_bitmap nodemap;
- libxl_physinfo physinfo;
-
- libxl_bitmap_init(&nodemap);
- libxl_physinfo_init(&physinfo);
-
- printf("Name ID Mem VCPUs\tState\tTime(s)");
- if (verbose) printf(" UUID Reason-Code\tSecurity Label");
- if (context && !verbose) printf(" Security Label");
- if (claim) printf(" Claimed");
- if (cpupool) printf(" Cpupool");
- if (numa) {
- if (libxl_node_bitmap_alloc(ctx, &nodemap, 0)) {
- fprintf(stderr, "libxl_node_bitmap_alloc_failed.\n");
- exit(EXIT_FAILURE);
- }
- if (libxl_get_physinfo(ctx, &physinfo) != 0) {
- fprintf(stderr, "libxl_physinfo failed.\n");
- libxl_bitmap_dispose(&nodemap);
- exit(EXIT_FAILURE);
- }
-
- printf(" NODE Affinity");
- }
- printf("\n");
- for (i = 0; i < nb_domain; i++) {
- char *domname;
- libxl_shutdown_reason shutdown_reason;
- domname = libxl_domid_to_name(ctx, info[i].domid);
- shutdown_reason = info[i].shutdown ? info[i].shutdown_reason : 0;
- printf("%-40s %5d %5lu %5d %c%c%c%c%c%c %8.1f",
- domname,
- info[i].domid,
- (unsigned long) ((info[i].current_memkb +
- info[i].outstanding_memkb)/ 1024),
- info[i].vcpu_online,
- info[i].running ? 'r' : '-',
- info[i].blocked ? 'b' : '-',
- info[i].paused ? 'p' : '-',
- info[i].shutdown ? 's' : '-',
- (shutdown_reason >= 0 &&
- shutdown_reason < sizeof(shutdown_reason_letters)-1
- ? shutdown_reason_letters[shutdown_reason] : '?'),
- info[i].dying ? 'd' : '-',
- ((float)info[i].cpu_time / 1e9));
- free(domname);
- if (verbose) {
- printf(" " LIBXL_UUID_FMT, LIBXL_UUID_BYTES(info[i].uuid));
- if (info[i].shutdown) printf(" %8x", shutdown_reason);
- else printf(" %8s", "-");
- }
- if (claim)
- printf(" %5lu", (unsigned long)info[i].outstanding_memkb / 1024);
- if (verbose || context)
- printf(" %16s", info[i].ssid_label ? : "-");
- if (cpupool) {
- char *poolname = libxl_cpupoolid_to_name(ctx, info[i].cpupool);
- printf("%16s", poolname);
- free(poolname);
- }
- if (numa) {
- libxl_domain_get_nodeaffinity(ctx, info[i].domid, &nodemap);
-
- putchar(' ');
- print_bitmap(nodemap.map, physinfo.nr_nodes, stdout);
- }
- putchar('\n');
- }
-
- libxl_bitmap_dispose(&nodemap);
- libxl_physinfo_dispose(&physinfo);
-}
void dump_by_dominfo_list(enum output_format output_format,
FILE *fh,
@@ -501,99 +399,6 @@ out:
}
-int main_list(int argc, char **argv)
-{
- int opt;
- bool verbose = false;
- bool context = false;
- bool details = false;
- bool cpupool = false;
- bool numa = false;
- static struct option opts[] = {
- {"long", 0, 0, 'l'},
- {"verbose", 0, 0, 'v'},
- {"context", 0, 0, 'Z'},
- {"cpupool", 0, 0, 'c'},
- {"numa", 0, 0, 'n'},
- COMMON_LONG_OPTS
- };
-
- libxl_dominfo info_buf;
- libxl_dominfo *info, *info_free=0;
- int nb_domain, rc;
-
- SWITCH_FOREACH_OPT(opt, "lvhZcn", opts, "list", 0) {
- case 'l':
- details = true;
- break;
- case 'v':
- verbose = true;
- break;
- case 'Z':
- context = true;
- break;
- case 'c':
- cpupool = true;
- break;
- case 'n':
- numa = true;
- break;
- }
-
- libxl_dominfo_init(&info_buf);
-
- if (optind >= argc) {
- info = libxl_list_domain(ctx, &nb_domain);
- if (!info) {
- fprintf(stderr, "libxl_list_domain failed.\n");
- return EXIT_FAILURE;
- }
- info_free = info;
- } else if (optind == argc-1) {
- uint32_t domid = find_domain(argv[optind]);
- rc = libxl_domain_info(ctx, &info_buf, domid);
- if (rc == ERROR_DOMAIN_NOTFOUND) {
- fprintf(stderr, "Error: Domain \'%s\' does not exist.\n",
- argv[optind]);
- return EXIT_FAILURE;
- }
- if (rc) {
- fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc);
- return EXIT_FAILURE;
- }
- info = &info_buf;
- nb_domain = 1;
- } else {
- help("list");
- return EXIT_FAILURE;
- }
-
- if (details)
- dump_by_dominfo_list(default_output_format, stdout, info, nb_domain);
- else
- list_domains(verbose, context, false /* claim */, numa, cpupool,
- info, nb_domain);
-
- if (info_free)
- libxl_dominfo_list_free(info, nb_domain);
-
- libxl_dominfo_dispose(&info_buf);
-
- return EXIT_SUCCESS;
-}
-
-int main_vm_list(int argc, char **argv)
-{
- int opt;
-
- SWITCH_FOREACH_OPT(opt, "", NULL, "vm-list", 0) {
- /* No options */
- }
-
- list_vm();
- return EXIT_SUCCESS;
-}
-
int main_info(int argc, char **argv)
{
int opt;
@@ -703,32 +508,6 @@ static char *uptime_to_string(unsigned long uptime, int short_mode)
return time_string;
}
-int main_claims(int argc, char **argv)
-{
- libxl_dominfo *info;
- int opt;
- int nb_domain;
-
- SWITCH_FOREACH_OPT(opt, "", NULL, "claims", 0) {
- /* No options */
- }
-
- if (!claim_mode)
- fprintf(stderr, "claim_mode not enabled (see man xl.conf).\n");
-
- info = libxl_list_domain(ctx, &nb_domain);
- if (!info) {
- fprintf(stderr, "libxl_list_domain failed.\n");
- return 1;
- }
-
- list_domains(false /* verbose */, false /* context */, true /* claim */,
- false /* numa */, false /* cpupool */, info, nb_domain);
-
- libxl_dominfo_list_free(info, nb_domain);
- return 0;
-}
-
static char *current_time_to_string(time_t now)
{
char now_str[100];
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
new file mode 100644
index 0000000000..ac6a9e5eac
--- /dev/null
+++ b/tools/xl/xl_list.c
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2009-2020 Citrix Ltd and other contributors
+ *
+ * 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.
+ */
+
+#define _GNU_SOURCE
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <libxl.h>
+#include <libxl_utils.h>
+
+#include "xl.h"
+#include "xl_utils.h"
+
+
+static void list_vm(void)
+{
+ libxl_vminfo *info;
+ char *domname;
+ int nb_vm, i;
+
+ info = libxl_list_vm(ctx, &nb_vm);
+
+ if (!info) {
+ fprintf(stderr, "libxl_list_vm failed.\n");
+ exit(EXIT_FAILURE);
+ }
+ printf("UUID ID name\n");
+ for (i = 0; i < nb_vm; i++) {
+ domname = libxl_domid_to_name(ctx, info[i].domid);
+ printf(LIBXL_UUID_FMT " %d %-30s\n", LIBXL_UUID_BYTES(info[i].uuid),
+ info[i].domid, domname);
+ free(domname);
+ }
+ libxl_vminfo_list_free(info, nb_vm);
+}
+
+static void list_domains(bool verbose, bool context, bool claim, bool numa,
+ bool cpupool, const libxl_dominfo *info, int nb_domain)
+{
+ int i;
+ static const char shutdown_reason_letters[]= "-rscwS";
+ libxl_bitmap nodemap;
+ libxl_physinfo physinfo;
+
+ libxl_bitmap_init(&nodemap);
+ libxl_physinfo_init(&physinfo);
+
+ printf("Name ID Mem VCPUs\tState\tTime(s)");
+ if (verbose) printf(" UUID Reason-Code\tSecurity Label");
+ if (context && !verbose) printf(" Security Label");
+ if (claim) printf(" Claimed");
+ if (cpupool) printf(" Cpupool");
+ if (numa) {
+ if (libxl_node_bitmap_alloc(ctx, &nodemap, 0)) {
+ fprintf(stderr, "libxl_node_bitmap_alloc_failed.\n");
+ exit(EXIT_FAILURE);
+ }
+ if (libxl_get_physinfo(ctx, &physinfo) != 0) {
+ fprintf(stderr, "libxl_physinfo failed.\n");
+ libxl_bitmap_dispose(&nodemap);
+ exit(EXIT_FAILURE);
+ }
+
+ printf(" NODE Affinity");
+ }
+ printf("\n");
+ for (i = 0; i < nb_domain; i++) {
+ char *domname;
+ libxl_shutdown_reason shutdown_reason;
+ domname = libxl_domid_to_name(ctx, info[i].domid);
+ shutdown_reason = info[i].shutdown ? info[i].shutdown_reason : 0;
+ printf("%-40s %5d %5lu %5d %c%c%c%c%c%c %8.1f",
+ domname,
+ info[i].domid,
+ (unsigned long) ((info[i].current_memkb +
+ info[i].outstanding_memkb)/ 1024),
+ info[i].vcpu_online,
+ info[i].running ? 'r' : '-',
+ info[i].blocked ? 'b' : '-',
+ info[i].paused ? 'p' : '-',
+ info[i].shutdown ? 's' : '-',
+ (shutdown_reason >= 0 &&
+ shutdown_reason < sizeof(shutdown_reason_letters)-1
+ ? shutdown_reason_letters[shutdown_reason] : '?'),
+ info[i].dying ? 'd' : '-',
+ ((float)info[i].cpu_time / 1e9));
+ free(domname);
+ if (verbose) {
+ printf(" " LIBXL_UUID_FMT, LIBXL_UUID_BYTES(info[i].uuid));
+ if (info[i].shutdown) printf(" %8x", shutdown_reason);
+ else printf(" %8s", "-");
+ }
+ if (claim)
+ printf(" %5lu", (unsigned long)info[i].outstanding_memkb / 1024);
+ if (verbose || context)
+ printf(" %16s", info[i].ssid_label ? : "-");
+ if (cpupool) {
+ char *poolname = libxl_cpupoolid_to_name(ctx, info[i].cpupool);
+ printf("%16s", poolname);
+ free(poolname);
+ }
+ if (numa) {
+ libxl_domain_get_nodeaffinity(ctx, info[i].domid, &nodemap);
+
+ putchar(' ');
+ print_bitmap(nodemap.map, physinfo.nr_nodes, stdout);
+ }
+ putchar('\n');
+ }
+
+ libxl_bitmap_dispose(&nodemap);
+ libxl_physinfo_dispose(&physinfo);
+}
+
+
+int main_list(int argc, char **argv)
+{
+ int opt;
+ bool verbose = false;
+ bool context = false;
+ bool details = false;
+ bool cpupool = false;
+ bool numa = false;
+ static struct option opts[] = {
+ {"long", 0, 0, 'l'},
+ {"verbose", 0, 0, 'v'},
+ {"context", 0, 0, 'Z'},
+ {"cpupool", 0, 0, 'c'},
+ {"numa", 0, 0, 'n'},
+ COMMON_LONG_OPTS
+ };
+
+ libxl_dominfo info_buf;
+ libxl_dominfo *info, *info_free=0;
+ int nb_domain, rc;
+
+ SWITCH_FOREACH_OPT(opt, "lvhZcn", opts, "list", 0) {
+ case 'l':
+ details = true;
+ break;
+ case 'v':
+ verbose = true;
+ break;
+ case 'Z':
+ context = true;
+ break;
+ case 'c':
+ cpupool = true;
+ break;
+ case 'n':
+ numa = true;
+ break;
+ }
+
+ libxl_dominfo_init(&info_buf);
+
+ if (optind >= argc) {
+ info = libxl_list_domain(ctx, &nb_domain);
+ if (!info) {
+ fprintf(stderr, "libxl_list_domain failed.\n");
+ return EXIT_FAILURE;
+ }
+ info_free = info;
+ } else if (optind == argc-1) {
+ uint32_t domid = find_domain(argv[optind]);
+ rc = libxl_domain_info(ctx, &info_buf, domid);
+ if (rc == ERROR_DOMAIN_NOTFOUND) {
+ fprintf(stderr, "Error: Domain \'%s\' does not exist.\n",
+ argv[optind]);
+ return EXIT_FAILURE;
+ }
+ if (rc) {
+ fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc);
+ return EXIT_FAILURE;
+ }
+ info = &info_buf;
+ nb_domain = 1;
+ } else {
+ help("list");
+ return EXIT_FAILURE;
+ }
+
+ if (details)
+ dump_by_dominfo_list(default_output_format, stdout, info, nb_domain);
+ else
+ list_domains(verbose, context, false /* claim */, numa, cpupool,
+ info, nb_domain);
+
+ if (info_free)
+ libxl_dominfo_list_free(info, nb_domain);
+
+ libxl_dominfo_dispose(&info_buf);
+
+ return EXIT_SUCCESS;
+}
+
+int main_vm_list(int argc, char **argv)
+{
+ int opt;
+
+ SWITCH_FOREACH_OPT(opt, "", NULL, "vm-list", 0) {
+ /* No options */
+ }
+
+ list_vm();
+ return EXIT_SUCCESS;
+}
+
+int main_claims(int argc, char **argv)
+{
+ libxl_dominfo *info;
+ int opt;
+ int nb_domain;
+
+ SWITCH_FOREACH_OPT(opt, "", NULL, "claims", 0) {
+ /* No options */
+ }
+
+ if (!claim_mode)
+ fprintf(stderr, "claim_mode not enabled (see man xl.conf).\n");
+
+ info = libxl_list_domain(ctx, &nb_domain);
+ if (!info) {
+ fprintf(stderr, "libxl_list_domain failed.\n");
+ return 1;
+ }
+
+ list_domains(false /* verbose */, false /* context */, true /* claim */,
+ false /* numa */, false /* cpupool */, info, nb_domain);
+
+ libxl_dominfo_list_free(info, nb_domain);
+ return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 09/16] WIP: tools/xl: Implement generalized output formatting for `xl list`
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (2 preceding siblings ...)
2020-12-09 22:45 ` [WIP PATCH 06/16] tools/xl: Split list commands off of xl_info.c Elliott Mitchell
@ 2020-12-10 23:09 ` Elliott Mitchell
2020-12-10 23:09 ` [WIP PATCH 10/16] WIP: tools/xl: Implement output format option Elliott Mitchell
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-10 23:09 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
Implement a generalized output formatting function for the `xl list`
subcommands. Notably `xl list` and `xl vm-list` could make use of
alternative output list formats.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
I'm a bit unsure of #include <xen-tools/libs.h>. When looking for an
implementation of ARRAY_SIZE(), that was the header I found. I can
readily write it myself, but rather than inlining, I looked for a copy in
a header and found that.
---
tools/xl/xl_list.c | 285 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 285 insertions(+)
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index e30536fd9a..1c04f2126b 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -14,10 +14,14 @@
#define _GNU_SOURCE
+#include <ctype.h>
#include <inttypes.h>
#include <stdlib.h>
+#include <stddef.h>
#include <unistd.h>
+#include <xen-tools/libs.h>
+
#include <libxl.h>
#include <libxl_utils.h>
@@ -25,6 +29,287 @@
#include "xl_utils.h"
+struct format_entry;
+
+typedef void (format_function_t)(const struct format_entry *,
+ const void *, const char *, size_t);
+
+typedef struct format_entry {
+ char *const header;
+ char formatc[3];
+ format_function_t *formatf;
+ ptrdiff_t offset;
+ union {
+ int i;
+ unsigned long lu;
+ float f;
+ void *v;
+ char *(*xlfunc)(libxl_ctx *, uint32_t);
+ } extra;
+} format_table_t['z' - 'A' + 1];
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
+static void format_normal(const struct format_entry *entry,
+ const void *info, const char *format,
+ size_t len)
+{
+ char *buf = alloca(len + 3);
+ memcpy(buf, format, len);
+ if (info) {
+ const char *str;
+ int i;
+ unsigned long lu;
+ float f;
+ strcpy(buf + len, entry->formatc);
+ switch (entry->formatc[0]) {
+ case 's':
+ str = ((char **)info)[entry->offset];
+ if (!str) str = "-";
+ printf(buf, str);
+ break;
+ case 'f':
+ f = ((float *)info)[entry->offset];
+ if (entry->extra.f != 0) f /= entry->extra.f;
+ printf(buf, f);
+ break;
+ case 'l':
+ lu = ((unsigned long *)info)[entry->offset];
+ if (entry->extra.lu) lu /= entry->extra.lu;
+ printf(buf, lu);
+ break;
+ case 'd':
+ default:
+ i = ((int *)info)[entry->offset];
+ if (entry->extra.i) i /= entry->extra.i;
+ printf(buf, i);
+ break;
+ }
+ } else {
+ if (entry->formatc[0] == 'f') {
+ char *tmp;
+ buf[len] = '\0';
+ if ((tmp = rindex(buf, '.')))
+ len = tmp - buf - 1;
+ }
+ strcpy(buf + len, "s");
+ printf(buf, entry->header);
+ }
+}
+
+static void format_allocstr(const struct format_entry *entry,
+ const void *info, const char *format,
+ size_t len)
+{
+ char *fmt = alloca(len + 2);
+ char *outbuf;
+ memcpy(fmt, format, len);
+ strcpy(fmt + len, "s");
+
+ if (info) {
+ outbuf = entry->extra.xlfunc(ctx, ((uint32_t *)info)[entry->offset]);
+ printf(fmt, outbuf);
+ free(outbuf);
+ } else printf(fmt, entry->header);
+}
+
+static void format_uuid(const struct format_entry *entry,
+ const void *info, const char *format,
+ size_t len)
+{
+ if (info) printf(LIBXL_UUID_FMT, LIBXL_UUID_BYTES(*(libxl_uuid *)((char *)info + entry->offset)));
+ else fputs(entry->header, stdout);
+}
+
+static void format_time(const struct format_entry *entry,
+ const void *_info, const char *format,
+ size_t len)
+{
+ const libxl_dominfo *info = _info;
+ char *fmt = alloca(len + 2);
+ memcpy(fmt, format, len);
+
+ if (info) {
+ strcpy(fmt + len, "f");
+ printf(fmt, ((float)info->cpu_time / 1e9));
+ } else {
+ char *tmp;
+ if (!(tmp = index(fmt, '.'))) tmp = fmt + len;
+ strcpy(tmp, "s");
+ printf(fmt, entry->header);
+ }
+}
+
+static void format_state(const struct format_entry *entry,
+ const void *_info, const char *format,
+ size_t len)
+{
+ const libxl_dominfo *info = _info;
+ if (info) {
+ const char shutdown_reason_letters[] = "-rscwS";
+ libxl_shutdown_reason shutdown_reason;
+ static const char letters[] = "rbps";
+ int i;
+ const bool *flags;
+
+ flags = &info->running;
+ for (i = 0; i < strlen(letters); ++i)
+ putchar(flags[i] ? letters[i] : '-');
+
+ shutdown_reason = info->shutdown ? info->shutdown_reason : 0;
+ putchar((shutdown_reason >= 0 &&
+ shutdown_reason < sizeof(shutdown_reason_letters)-1
+ ? shutdown_reason_letters[shutdown_reason] : '?'));
+
+ putchar(info->dying ? 'd' : '-');
+ } else printf("%6s", entry->header);
+}
+
+static void format_reason(const struct format_entry *entry,
+ const void *_info, const char *format,
+ size_t len)
+{
+ const libxl_dominfo *info = _info;
+ const char *output = entry->header;
+ if (info) {
+ if (info->shutdown) {
+ printf("%8x", info->shutdown_reason);
+ return;
+ }
+ output = "-";
+ }
+ printf("%8s", output);
+}
+
+static void format_memory(const struct format_entry *entry,
+ const void *_info, const char *format,
+ size_t len)
+{
+ const libxl_dominfo *info = _info;
+ char *fmt = alloca(len + 3);
+ memcpy(fmt, format, len);
+ if (info) {
+ strcpy(fmt + len, entry->formatc);
+ printf(fmt, (info->current_memkb + info->outstanding_memkb) >> 10);
+ } else {
+ strcpy(fmt + len, "s");
+ printf(fmt, "Mem");
+ }
+}
+
+static void format_node(const struct format_entry *entry,
+ const void *_info, const char *format,
+ size_t len)
+{
+ const libxl_dominfo *info = _info;
+ static bool need_init = true;
+ static libxl_bitmap nodemap;
+ static libxl_physinfo physinfo;
+
+ if (need_init) {
+ libxl_bitmap_init(&nodemap);
+ libxl_physinfo_init(&physinfo);
+ need_init = false;
+
+ if (libxl_node_bitmap_alloc(ctx, &nodemap, 0)) {
+ fprintf(stderr, "libxl_node_bitmap_alloc_failed.\n");
+ exit(EXIT_FAILURE);
+ }
+ if (libxl_get_physinfo(ctx, &physinfo) != 0) {
+ fprintf(stderr, "libxl_physinfo failed.\n");
+ libxl_bitmap_dispose(&nodemap);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (info) {
+ libxl_domain_get_nodeaffinity(ctx, info->domid, &nodemap);
+
+ putchar(' ');
+ print_bitmap(nodemap.map, physinfo.nr_nodes, stdout);
+ } else fputs(entry->header, stdout);
+
+#if 0
+ /* unfortunately these get leaked on exit */
+ libxl_bitmap_dispose(&nodemap);
+ libxl_physinfo_dispose(&physinfo);
+#endif
+}
+
+#pragma GCC diagnostic pop
+
+static bool isfmtchar(int c)
+{
+ const bool opts[] = {
+ ['0'] = true,
+ ['1'] = true,
+ ['2'] = true,
+ ['3'] = true,
+ ['4'] = true,
+ ['5'] = true,
+ ['6'] = true,
+ ['7'] = true,
+ ['8'] = true,
+ ['9'] = true,
+ ['.'] = true,
+ ['#'] = true,
+ ['-'] = true,
+ ['+'] = true,
+ [' '] = true,
+ ['\''] = true,
+ };
+ if ((unsigned int)c < ARRAY_SIZE(opts) && opts[c]) return true;
+ else return false;
+}
+
+static void format(const format_table_t fmttab, const char *fmt,
+ const void *info)
+{
+ while (fmt[0]) {
+ if (fmt[0] == '\\') {
+ switch (fmt[1]) {
+ case 0:
+ /* Uhm... */
+ return;
+ case '0':
+ putchar(0);
+ break;
+ case 'n':
+ fputs("\n", stdout);
+ break;
+ case 't':
+ putchar('\t');
+ break;
+ default:
+ putchar(fmt[1]);
+ }
+ fmt+=2;
+ } else if (fmt[0] == '%') {
+ size_t len=1;
+ unsigned char entryn;
+
+ while (isfmtchar(fmt[len])) ++len;
+
+ entryn = fmt[len] - 'A';
+ if (entryn < sizeof(format_table_t) / sizeof(fmttab[0]) &&
+ fmttab[entryn].formatf)
+ fmttab[entryn].formatf(fmttab + entryn, info, fmt, len);
+ else {
+ fprintf(stderr, "Invalid conversion character \'%c\'\n",
+ entryn);
+ exit(EXIT_FAILURE);
+ }
+
+ fmt += len + 1;
+ } else {
+ putchar(*fmt);
+ ++fmt;
+ }
+ }
+}
+
+
static void list_vm(void)
{
libxl_vminfo *info;
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 10/16] WIP: tools/xl: Implement output format option
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (3 preceding siblings ...)
2020-12-10 23:09 ` [WIP PATCH 09/16] WIP: tools/xl: Implement generalized output formatting for `xl list` Elliott Mitchell
@ 2020-12-10 23:09 ` Elliott Mitchell
2020-12-10 23:09 ` [WIP PATCH 08/16] tools/xl: Fix potential deallocation bug Elliott Mitchell
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-10 23:09 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
Often it is desireable to only list a specific subset of fields, or list
them in an unusual order. Previously `xl list` gave output in a fixed
order, now add "-F" to allow specifying fields and formatting.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_cmdtable.c | 14 ++++++++++++
tools/xl/xl_list.c | 50 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 6a05bf7ce2..f44c65a3f8 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -53,6 +53,20 @@ struct cmd_spec cmd_table[] = {
&main_list, 0, 0,
"List information about all/some domains",
"[options] [Domain]\n",
+ "-F, --format Specify output format string\n"
+ " Similar to printf(3) formatting, conversion characters are:\n"
+ " %A NODE Affinity\n"
+ " %c Claimed\n"
+ " %i Domain Id (%o, %x, and %X allow octal and hexadecimal)\n"
+ " %l Security label\n"
+ " %m Memory (Megabytes)\n"
+ " %n Domain name\n"
+ " %p CPU Pool\n"
+ " %r Shutdown reason\n"
+ " %s State\n"
+ " %t Time(s)\n"
+ " %u UUID\n"
+ " %v vCPUs\n"
"-Z, --context Prints out security context\n"
"-c, --cpupool Prints the cpupool the domain is in\n"
"-l, --long Output all VM details\n"
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index 1c04f2126b..c79b5e041b 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -309,6 +309,39 @@ static void format(const format_table_t fmttab, const char *fmt,
}
}
+static const libxl_dominfo *_discard;
+
+const format_table_t formats = {
+ ['A' - 'A'] = {"NODE Affinity", "", format_node},
+ ['X' - 'A'] = {"ID", "X", format_normal,
+ (int *)&_discard->domid - (int *)_discard, {.i = 0}},
+ ['c' - 'A'] = {"Claim", "lu", format_normal,
+ (unsigned long *)&_discard->outstanding_memkb -
+ (unsigned long *)_discard, {.lu = 1024}},
+ ['i' - 'A'] = {"ID", "d", format_normal,
+ (int *)&_discard->domid - (int *)_discard, {.i = 0}},
+ ['l' - 'A'] = {"Security Label", "s", format_normal,
+ (char **)&_discard->ssid_label - (char **)_discard},
+ ['m' - 'A'] = {"Mem", "lu", format_memory},
+ ['n' - 'A'] = {"Name", "s", format_allocstr,
+ (uint32_t *)&_discard->domid - (uint32_t *)_discard,
+ {.xlfunc = libxl_domid_to_name}},
+ ['o' - 'A'] = {"ID", "o", format_normal,
+ (int *)&_discard->domid - (int *)_discard, {.i = 0}},
+ ['p' - 'A'] = {"Cpupool", "s", format_allocstr,
+ (uint32_t *)&_discard->cpupool - (uint32_t *)_discard,
+ {.xlfunc = libxl_cpupoolid_to_name}},
+ ['r' - 'A'] = {"Reason", "", format_reason},
+ ['s' - 'A'] = {"State", "s", format_state},
+ ['t' - 'A'] = {"Time(s)", "qu", format_time},
+ ['u' - 'A'] = {" UUID ", "", format_uuid,
+ (char *)&_discard->uuid - (char *)_discard},
+ ['v' - 'A'] = {"VCPUs", "d", format_normal,
+ (int *)&_discard->vcpu_online - (int *)_discard, {.i = 0}},
+ ['x' - 'A'] = {"ID", "x", format_normal,
+ (int *)&_discard->domid - (int *)_discard, {.i = 0}},
+};
+
static void list_vm(void)
{
@@ -417,11 +450,13 @@ int main_list(int argc, char **argv)
bool context = false;
bool cpupool = false;
bool details = false;
+ const char *formatstr = NULL;
bool numa = false;
bool verbose = false;
static struct option opts[] = {
{"context", 0, 0, 'Z'},
{"cpupool", 0, 0, 'c'},
+ {"format", 0, 0, 'F'},
{"long", 0, 0, 'l'},
{"numa", 0, 0, 'n'},
{"verbose", 0, 0, 'v'},
@@ -432,7 +467,10 @@ int main_list(int argc, char **argv)
libxl_dominfo *info, *info_free=0;
int nb_domain, rc;
- SWITCH_FOREACH_OPT(opt, "Zchlnv", opts, "list", 0) {
+ SWITCH_FOREACH_OPT(opt, "F:Zchlnv", opts, "list", 0) {
+ case 'F':
+ formatstr = optarg;
+ break;
case 'Z':
context = true;
break;
@@ -480,7 +518,15 @@ int main_list(int argc, char **argv)
if (details)
dump_by_dominfo_list(default_output_format, stdout, info, nb_domain);
- else
+ else if (formatstr) {
+ format(formats, formatstr, NULL);
+
+ while (nb_domain) {
+ format(formats, formatstr, info);
+ ++info;
+ --nb_domain;
+ }
+ } else
list_domains(verbose, context, false /* claim */, numa, cpupool,
info, nb_domain);
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 08/16] tools/xl: Fix potential deallocation bug
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (4 preceding siblings ...)
2020-12-10 23:09 ` [WIP PATCH 10/16] WIP: tools/xl: Implement output format option Elliott Mitchell
@ 2020-12-10 23:09 ` Elliott Mitchell
2020-12-12 6:18 ` [WIP PATCH 11/16] WIP: tools/xl: Replace most of list_domains with use of format() Elliott Mitchell
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-10 23:09 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
There is potential for the info and info_free variable's purposes to
diverge. If info was overwritten with a distinct value, yet info_free
still needed deallocation a bug would occur on this line. Preemptively
address this issue (making use of divergent info/info_free values is
under consideration).
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_list.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index 8b391a9056..e30536fd9a 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -200,7 +200,7 @@ int main_list(int argc, char **argv)
info, nb_domain);
if (info_free)
- libxl_dominfo_list_free(info, nb_domain);
+ libxl_dominfo_list_free(info_free, nb_domain);
libxl_dominfo_dispose(&info_buf);
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 11/16] WIP: tools/xl: Replace most of list_domains with use of format()
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (5 preceding siblings ...)
2020-12-10 23:09 ` [WIP PATCH 08/16] tools/xl: Fix potential deallocation bug Elliott Mitchell
@ 2020-12-12 6:18 ` Elliott Mitchell
2020-12-13 4:42 ` [WIP PATCH 12/16] WIP: UNTESTED: tools/xl: Replace remaining options with format() Elliott Mitchell
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-12 6:18 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
With a generalized formatting function now available, start to replace
the old specialized formatting bits.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_list.c | 40 ++++++++++------------------------------
1 file changed, 10 insertions(+), 30 deletions(-)
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index c79b5e041b..10d076864e 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -369,16 +369,18 @@ static void list_domains(bool verbose, bool context, bool claim, bool numa,
bool cpupool, const libxl_dominfo *info, int nb_domain)
{
int i;
- static const char shutdown_reason_letters[]= "-rscwS";
+ const char lead[] = "%-40n %5i %5m %5v %s %8.1t";
+
libxl_bitmap nodemap;
libxl_physinfo physinfo;
libxl_bitmap_init(&nodemap);
libxl_physinfo_init(&physinfo);
- printf("Name ID Mem VCPUs\tState\tTime(s)");
- if (verbose) printf(" UUID Reason-Code\tSecurity Label");
- if (context && !verbose) printf(" Security Label");
+ format(formats, lead, NULL);
+ if (verbose) {
+ format(formats, " %u %r %16l", NULL);
+ } else if (context) format(formats, " %16l", NULL);
if (claim) printf(" Claimed");
if (cpupool) printf(" Cpupool");
if (numa) {
@@ -396,35 +398,13 @@ static void list_domains(bool verbose, bool context, bool claim, bool numa,
}
printf("\n");
for (i = 0; i < nb_domain; i++) {
- char *domname;
- libxl_shutdown_reason shutdown_reason;
- domname = libxl_domid_to_name(ctx, info[i].domid);
- shutdown_reason = info[i].shutdown ? info[i].shutdown_reason : 0;
- printf("%-40s %5d %5lu %5d %c%c%c%c%c%c %8.1f",
- domname,
- info[i].domid,
- (unsigned long) ((info[i].current_memkb +
- info[i].outstanding_memkb)/ 1024),
- info[i].vcpu_online,
- info[i].running ? 'r' : '-',
- info[i].blocked ? 'b' : '-',
- info[i].paused ? 'p' : '-',
- info[i].shutdown ? 's' : '-',
- (shutdown_reason >= 0 &&
- shutdown_reason < sizeof(shutdown_reason_letters)-1
- ? shutdown_reason_letters[shutdown_reason] : '?'),
- info[i].dying ? 'd' : '-',
- ((float)info[i].cpu_time / 1e9));
- free(domname);
- if (verbose) {
- printf(" " LIBXL_UUID_FMT, LIBXL_UUID_BYTES(info[i].uuid));
- if (info[i].shutdown) printf(" %8x", shutdown_reason);
- else printf(" %8s", "-");
- }
+ format(formats, lead, info + i);
+ if (verbose)
+ format(formats, " %u %r", info + i);
if (claim)
printf(" %5lu", (unsigned long)info[i].outstanding_memkb / 1024);
if (verbose || context)
- printf(" %16s", info[i].ssid_label ? : "-");
+ format(formats, " %16l", info + i);
if (cpupool) {
char *poolname = libxl_cpupoolid_to_name(ctx, info[i].cpupool);
printf("%16s", poolname);
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 12/16] WIP: UNTESTED: tools/xl: Replace remaining options with format()
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (6 preceding siblings ...)
2020-12-12 6:18 ` [WIP PATCH 11/16] WIP: tools/xl: Replace most of list_domains with use of format() Elliott Mitchell
@ 2020-12-13 4:42 ` Elliott Mitchell
2020-12-13 5:14 ` [WIP PATCH 13/16] WIP: tools/xl: Purge list_domains() Elliott Mitchell
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-13 4:42 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
format() is meant to be a powerful tool, sweep the remaining bits
away. Unfortunately I am unable to test this portion.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_list.c | 44 ++++++++------------------------------------
1 file changed, 8 insertions(+), 36 deletions(-)
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index 10d076864e..ee20d2feee 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -371,56 +371,28 @@ static void list_domains(bool verbose, bool context, bool claim, bool numa,
int i;
const char lead[] = "%-40n %5i %5m %5v %s %8.1t";
- libxl_bitmap nodemap;
- libxl_physinfo physinfo;
-
- libxl_bitmap_init(&nodemap);
- libxl_physinfo_init(&physinfo);
-
format(formats, lead, NULL);
if (verbose) {
format(formats, " %u %r %16l", NULL);
} else if (context) format(formats, " %16l", NULL);
- if (claim) printf(" Claimed");
- if (cpupool) printf(" Cpupool");
- if (numa) {
- if (libxl_node_bitmap_alloc(ctx, &nodemap, 0)) {
- fprintf(stderr, "libxl_node_bitmap_alloc_failed.\n");
- exit(EXIT_FAILURE);
- }
- if (libxl_get_physinfo(ctx, &physinfo) != 0) {
- fprintf(stderr, "libxl_physinfo failed.\n");
- libxl_bitmap_dispose(&nodemap);
- exit(EXIT_FAILURE);
- }
-
- printf(" NODE Affinity");
- }
+ if (claim) format(formats, " %5c", NULL);
+ if (cpupool) format(formats, " %16p", NULL);
+ if (numa) format(formats, " %A", NULL);
printf("\n");
for (i = 0; i < nb_domain; i++) {
format(formats, lead, info + i);
if (verbose)
format(formats, " %u %r", info + i);
if (claim)
- printf(" %5lu", (unsigned long)info[i].outstanding_memkb / 1024);
+ format(formats, " %5c", info + i);
if (verbose || context)
format(formats, " %16l", info + i);
- if (cpupool) {
- char *poolname = libxl_cpupoolid_to_name(ctx, info[i].cpupool);
- printf("%16s", poolname);
- free(poolname);
- }
- if (numa) {
- libxl_domain_get_nodeaffinity(ctx, info[i].domid, &nodemap);
-
- putchar(' ');
- print_bitmap(nodemap.map, physinfo.nr_nodes, stdout);
- }
+ if (cpupool)
+ format(formats, " %16p", info + i);
+ if (numa)
+ format(formats, " %A", info + i);
putchar('\n');
}
-
- libxl_bitmap_dispose(&nodemap);
- libxl_physinfo_dispose(&physinfo);
}
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 13/16] WIP: tools/xl: Purge list_domains()
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (7 preceding siblings ...)
2020-12-13 4:42 ` [WIP PATCH 12/16] WIP: UNTESTED: tools/xl: Replace remaining options with format() Elliott Mitchell
@ 2020-12-13 5:14 ` Elliott Mitchell
2020-12-18 1:42 ` [WIP PATCH 04/16] tools/xl: Rename printf_info()/list_domains_details() to dump_by_...() Elliott Mitchell
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-13 5:14 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
Everything previously done by list_domains() is now done with
build_list_domain_format() and format().
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_list.c | 90 +++++++++++++++++++++++++++-------------------
1 file changed, 53 insertions(+), 37 deletions(-)
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index ee20d2feee..3ed6da8feb 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -342,6 +342,31 @@ const format_table_t formats = {
(int *)&_discard->domid - (int *)_discard, {.i = 0}},
};
+static char *build_list_domain_format(bool verbose, bool context, bool claim,
+ bool numa, bool cpupool)
+{
+ int size = 4096;
+ char *fmt = malloc(size);
+ const char lead[] = "%-40n %5i %5m %5v %s %8.1t";
+
+ if (!fmt) return NULL;
+
+ memcpy(fmt, lead, sizeof(lead));
+
+ if (verbose) strcat(fmt, " %u %r %16l");
+ else if (context) strcat(fmt, " %16l");
+
+ if (claim) strcat(fmt, " %5c");
+
+ if (cpupool) strcat(fmt, " %16p");
+
+ if (numa) strcat(fmt, " %A");
+
+ strcat(fmt, "\n");
+
+ return realloc(fmt, strlen(fmt) + 1);
+}
+
static void list_vm(void)
{
@@ -365,36 +390,6 @@ static void list_vm(void)
libxl_vminfo_list_free(info, nb_vm);
}
-static void list_domains(bool verbose, bool context, bool claim, bool numa,
- bool cpupool, const libxl_dominfo *info, int nb_domain)
-{
- int i;
- const char lead[] = "%-40n %5i %5m %5v %s %8.1t";
-
- format(formats, lead, NULL);
- if (verbose) {
- format(formats, " %u %r %16l", NULL);
- } else if (context) format(formats, " %16l", NULL);
- if (claim) format(formats, " %5c", NULL);
- if (cpupool) format(formats, " %16p", NULL);
- if (numa) format(formats, " %A", NULL);
- printf("\n");
- for (i = 0; i < nb_domain; i++) {
- format(formats, lead, info + i);
- if (verbose)
- format(formats, " %u %r", info + i);
- if (claim)
- format(formats, " %5c", info + i);
- if (verbose || context)
- format(formats, " %16l", info + i);
- if (cpupool)
- format(formats, " %16p", info + i);
- if (numa)
- format(formats, " %A", info + i);
- putchar('\n');
- }
-}
-
int main_list(int argc, char **argv)
{
@@ -470,7 +465,17 @@ int main_list(int argc, char **argv)
if (details)
dump_by_dominfo_list(default_output_format, stdout, info, nb_domain);
- else if (formatstr) {
+ else {
+ char *fr = NULL;
+
+ if (!formatstr) formatstr = fr = build_list_domain_format(verbose,
+ context, false /* claim */, numa, cpupool);
+
+ if (!formatstr) {
+ fprintf(stderr, "Memory allocation failure.\n");
+ return EXIT_FAILURE;
+ }
+
format(formats, formatstr, NULL);
while (nb_domain) {
@@ -478,9 +483,9 @@ int main_list(int argc, char **argv)
++info;
--nb_domain;
}
- } else
- list_domains(verbose, context, false /* claim */, numa, cpupool,
- info, nb_domain);
+
+ if (fr) free(fr);
+ }
if (info_free)
libxl_dominfo_list_free(info_free, nb_domain);
@@ -506,7 +511,8 @@ int main_claims(int argc, char **argv)
{
libxl_dominfo *info;
int opt;
- int nb_domain;
+ int nb_domain, i;
+ char *fmt;
SWITCH_FOREACH_OPT(opt, "", NULL, "claims", 0) {
/* No options */
@@ -521,9 +527,19 @@ int main_claims(int argc, char **argv)
return 1;
}
- list_domains(false /* verbose */, false /* context */, true /* claim */,
- false /* numa */, false /* cpupool */, info, nb_domain);
+ fmt = build_list_domain_format(false /* verbose */, false /* context */,
+ true /* claim */, false /* numa */, false /* cpupool */);
+
+ if (!fmt) {
+ fprintf(stderr, "Memory allocation failure.\n");
+ return 1;
+ }
+
+ format(formats, fmt, NULL);
+
+ for (i = 0; i < nb_domain; ++i) format(formats, fmt, info + i);
+ free(fmt);
libxl_dominfo_list_free(info, nb_domain);
return 0;
}
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 04/16] tools/xl: Rename printf_info()/list_domains_details() to dump_by_...()
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (8 preceding siblings ...)
2020-12-13 5:14 ` [WIP PATCH 13/16] WIP: tools/xl: Purge list_domains() Elliott Mitchell
@ 2020-12-18 1:42 ` Elliott Mitchell
2020-12-18 1:42 ` [WIP PATCH 05/16] tools/xl: Merge down debug/dry-run section of create_domain() Elliott Mitchell
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-18 1:42 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
printf_info()/list_domains_details() had been serving fairly similar
purposes. Increase their consistency (add file-handle and output_format
arguments to list_domains_details(), reorder arguments) and then rename
to better reflect their functionality.
Both were simply outputting full domain information. As this is more of
a dump operation, "dump" is a better name.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl.h | 8 ++++++++
tools/xl/xl_info.c | 30 ++++++++++++++++--------------
tools/xl/xl_misc.c | 5 +----
3 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index ffb222d280..760c8fcf40 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -299,6 +299,14 @@ typedef enum {
DOMAIN_RESTART_SOFT_RESET, /* Soft reset should be performed */
} domain_restart_type;
+extern void dump_by_config(enum output_format output_format,
+ FILE *fh,
+ const libxl_domain_config *d_config,
+ int domid);
+extern void dump_by_dominfo_list(enum output_format output_format,
+ FILE *fh,
+ const libxl_dominfo info[],
+ int nb_domain);
extern void printf_info_sexp(int domid, const libxl_domain_config *d_config, FILE *fh);
extern void apply_global_affinity_masks(libxl_domain_type type,
libxl_bitmap *vcpu_affinity_array,
diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c
index cc50463df6..bc88014f10 100644
--- a/tools/xl/xl_info.c
+++ b/tools/xl/xl_info.c
@@ -94,12 +94,10 @@ out:
return s;
}
-void printf_info(enum output_format output_format,
- int domid,
- libxl_domain_config *d_config, FILE *fh);
-void printf_info(enum output_format output_format,
- int domid,
- libxl_domain_config *d_config, FILE *fh)
+void dump_by_config(enum output_format output_format,
+ FILE *fh,
+ const libxl_domain_config *const d_config,
+ int domid)
{
if (output_format == OUTPUT_FORMAT_SXP)
return printf_info_sexp(domid, d_config, fh);
@@ -438,7 +436,10 @@ static void list_domains(bool verbose, bool context, bool claim, bool numa,
libxl_physinfo_dispose(&physinfo);
}
-static void list_domains_details(const libxl_dominfo *info, int nb_domain)
+void dump_by_dominfo_list(enum output_format output_format,
+ FILE *fh,
+ const libxl_dominfo info[],
+ int nb_domain)
{
libxl_domain_config d_config;
@@ -449,7 +450,7 @@ static void list_domains_details(const libxl_dominfo *info, int nb_domain)
const char *buf;
libxl_yajl_length yajl_len = 0;
- if (default_output_format == OUTPUT_FORMAT_JSON) {
+ if (output_format == OUTPUT_FORMAT_JSON) {
hand = libxl_yajl_gen_alloc(NULL);
if (!hand) {
fprintf(stderr, "unable to allocate JSON generator\n");
@@ -468,16 +469,16 @@ static void list_domains_details(const libxl_dominfo *info, int nb_domain)
&d_config, NULL);
if (rc)
continue;
- if (default_output_format == OUTPUT_FORMAT_JSON)
+ if (output_format == OUTPUT_FORMAT_JSON)
s = printf_info_one_json(hand, info[i].domid, &d_config);
else
- printf_info_sexp(info[i].domid, &d_config, stdout);
+ printf_info_sexp(info[i].domid, &d_config, fh);
libxl_domain_config_dispose(&d_config);
if (s != yajl_gen_status_ok)
goto out;
}
- if (default_output_format == OUTPUT_FORMAT_JSON) {
+ if (output_format == OUTPUT_FORMAT_JSON) {
s = yajl_gen_array_close(hand);
if (s != yajl_gen_status_ok)
goto out;
@@ -486,11 +487,12 @@ static void list_domains_details(const libxl_dominfo *info, int nb_domain)
if (s != yajl_gen_status_ok)
goto out;
- puts(buf);
+ fputs(buf, fh);
+ fputc('\n', fh);
}
out:
- if (default_output_format == OUTPUT_FORMAT_JSON) {
+ if (output_format == OUTPUT_FORMAT_JSON) {
yajl_gen_free(hand);
if (s != yajl_gen_status_ok)
fprintf(stderr,
@@ -567,7 +569,7 @@ int main_list(int argc, char **argv)
}
if (details)
- list_domains_details(info, nb_domain);
+ dump_by_dominfo_list(default_output_format, stdout, info, nb_domain);
else
list_domains(verbose, context, false /* claim */, numa, cpupool,
info, nb_domain);
diff --git a/tools/xl/xl_misc.c b/tools/xl/xl_misc.c
index 08f0fb6dc9..bcf178762b 100644
--- a/tools/xl/xl_misc.c
+++ b/tools/xl/xl_misc.c
@@ -256,9 +256,6 @@ int main_dump_core(int argc, char **argv)
return EXIT_SUCCESS;
}
-extern void printf_info(enum output_format output_format,
- int domid,
- libxl_domain_config *d_config, FILE *fh);
int main_config_update(int argc, char **argv)
{
uint32_t domid;
@@ -344,7 +341,7 @@ int main_config_update(int argc, char **argv)
parse_config_data(filename, config_data, config_len, &d_config);
if (debug || dryrun_only)
- printf_info(default_output_format, -1, &d_config, stdout);
+ dump_by_config(default_output_format, stdout, &d_config, -1);
if (!dryrun_only) {
fprintf(stderr, "setting dom%u configuration\n", domid);
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 05/16] tools/xl: Merge down debug/dry-run section of create_domain()
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (9 preceding siblings ...)
2020-12-18 1:42 ` [WIP PATCH 04/16] tools/xl: Rename printf_info()/list_domains_details() to dump_by_...() Elliott Mitchell
@ 2020-12-18 1:42 ` Elliott Mitchell
2020-12-18 21:32 ` [WIP PATCH 03/16] tools/xl: Mark libxl_domain_config * arg of printf_info_*() const Elliott Mitchell
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-18 1:42 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
create_domain()'s use of printf_info_sexp() could be merged down to a
single dump_by_config(), do so. This results in an extra JSON dictionary
in output, but I doubt that is an issue for dry-run or debugging output.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_vmcontrol.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c
index 435155a033..4b95e7e463 100644
--- a/tools/xl/xl_vmcontrol.c
+++ b/tools/xl/xl_vmcontrol.c
@@ -856,19 +856,7 @@ int create_domain(struct domain_create *dom_info)
if (debug || dom_info->dryrun) {
FILE *cfg_print_fh = (debug && !dom_info->dryrun) ? stderr : stdout;
- if (default_output_format == OUTPUT_FORMAT_SXP) {
- printf_info_sexp(-1, &d_config, cfg_print_fh);
- } else {
- char *json = libxl_domain_config_to_json(ctx, &d_config);
- if (!json) {
- fprintf(stderr,
- "Failed to convert domain configuration to JSON\n");
- exit(1);
- }
- fputs(json, cfg_print_fh);
- free(json);
- flush_stream(cfg_print_fh);
- }
+ dump_by_config(default_output_format, cfg_print_fh, &d_config, -1);
}
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 03/16] tools/xl: Mark libxl_domain_config * arg of printf_info_*() const
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (10 preceding siblings ...)
2020-12-18 1:42 ` [WIP PATCH 05/16] tools/xl: Merge down debug/dry-run section of create_domain() Elliott Mitchell
@ 2020-12-18 21:32 ` Elliott Mitchell
2020-12-18 21:37 ` [WIP PATCH 01/16] tools/libxl: Mark pointer args of many functions constant Elliott Mitchell
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-18 21:32 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
With libxl having gotten a lot more constant, now printf_info_sexp() and
printf_info_one_json() can add consts. May not be particularly
important, but it is best to mark things constant when they are known to
be so.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl.h | 2 +-
tools/xl/xl_info.c | 2 +-
tools/xl/xl_sxp.c | 6 +++---
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index 06569c6c4a..ffb222d280 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -299,7 +299,7 @@ typedef enum {
DOMAIN_RESTART_SOFT_RESET, /* Soft reset should be performed */
} domain_restart_type;
-extern void printf_info_sexp(int domid, libxl_domain_config *d_config, FILE *fh);
+extern void printf_info_sexp(int domid, const libxl_domain_config *d_config, FILE *fh);
extern void apply_global_affinity_masks(libxl_domain_type type,
libxl_bitmap *vcpu_affinity_array,
unsigned int size);
diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c
index ca417df8e8..cc50463df6 100644
--- a/tools/xl/xl_info.c
+++ b/tools/xl/xl_info.c
@@ -59,7 +59,7 @@ static int maybe_printf(const char *fmt, ...)
}
static yajl_gen_status printf_info_one_json(yajl_gen hand, int domid,
- libxl_domain_config *d_config)
+ const libxl_domain_config *d_config)
{
yajl_gen_status s;
diff --git a/tools/xl/xl_sxp.c b/tools/xl/xl_sxp.c
index 359a001570..d5b9051dfc 100644
--- a/tools/xl/xl_sxp.c
+++ b/tools/xl/xl_sxp.c
@@ -26,13 +26,13 @@
/* In general you should not add new output to this function since it
* is intended only for legacy use.
*/
-void printf_info_sexp(int domid, libxl_domain_config *d_config, FILE *fh)
+void printf_info_sexp(int domid, const libxl_domain_config *d_config, FILE *fh)
{
int i;
libxl_dominfo info;
- libxl_domain_create_info *c_info = &d_config->c_info;
- libxl_domain_build_info *b_info = &d_config->b_info;
+ const libxl_domain_create_info *c_info = &d_config->c_info;
+ const libxl_domain_build_info *b_info = &d_config->b_info;
fprintf(fh, "(domain\n\t(domid %d)\n", domid);
fprintf(fh, "\t(create_info)\n");
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 01/16] tools/libxl: Mark pointer args of many functions constant
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (11 preceding siblings ...)
2020-12-18 21:32 ` [WIP PATCH 03/16] tools/xl: Mark libxl_domain_config * arg of printf_info_*() const Elliott Mitchell
@ 2020-12-18 21:37 ` Elliott Mitchell
2020-12-18 22:45 ` [WIP PATCH 02/16] tools/libxl: Tiny optimization of libxl__mac_is_default() Elliott Mitchell
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-18 21:37 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
Anything *_is_empty(), *_is_default(), or *_gen_json() is going to be
examining the pointed to thing, not modifying it. This potentially
results in higher-performance output. This also allows spreading
constants further, allowing more checking and security.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/include/libxl_json.h | 22 ++++++++++++----------
tools/libs/light/gentypes.py | 8 ++++----
tools/libs/light/libxl_cpuid.c | 2 +-
tools/libs/light/libxl_internal.c | 4 ++--
tools/libs/light/libxl_internal.h | 18 +++++++++---------
tools/libs/light/libxl_json.c | 18 ++++++++++--------
tools/libs/light/libxl_nocpuid.c | 4 ++--
7 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/tools/include/libxl_json.h b/tools/include/libxl_json.h
index 260783bfde..63f0e58fe1 100644
--- a/tools/include/libxl_json.h
+++ b/tools/include/libxl_json.h
@@ -23,17 +23,19 @@
#endif
yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val);
-yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, libxl_defbool *p);
-yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, libxl_uuid *p);
-yajl_gen_status libxl_mac_gen_json(yajl_gen hand, libxl_mac *p);
-yajl_gen_status libxl_bitmap_gen_json(yajl_gen hand, libxl_bitmap *p);
+yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, const libxl_defbool *p);
+yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, const libxl_uuid *p);
+yajl_gen_status libxl_mac_gen_json(yajl_gen hand, const libxl_mac *p);
+yajl_gen_status libxl_bitmap_gen_json(yajl_gen hand, const libxl_bitmap *p);
yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand,
- libxl_cpuid_policy_list *p);
-yajl_gen_status libxl_string_list_gen_json(yajl_gen hand, libxl_string_list *p);
+ const libxl_cpuid_policy_list *p);
+yajl_gen_status libxl_string_list_gen_json(yajl_gen hand,
+ const libxl_string_list *p);
yajl_gen_status libxl_key_value_list_gen_json(yajl_gen hand,
- libxl_key_value_list *p);
-yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand, libxl_hwcap *p);
-yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand, libxl_ms_vm_genid *p);
+ const libxl_key_value_list *p);
+yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand, const libxl_hwcap *p);
+yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand,
+ const libxl_ms_vm_genid *p);
#include <_libxl_types_json.h>
@@ -91,6 +93,6 @@ static inline yajl_gen libxl_yajl_gen_alloc(const yajl_alloc_funcs *allocFuncs)
#endif /* !HAVE_YAJL_V2 */
yajl_gen_status libxl_domain_config_gen_json(yajl_gen hand,
- libxl_domain_config *p);
+ const libxl_domain_config *p);
#endif /* LIBXL_JSON_H */
diff --git a/tools/libs/light/gentypes.py b/tools/libs/light/gentypes.py
index 9a45e45acc..7e02a5366f 100644
--- a/tools/libs/light/gentypes.py
+++ b/tools/libs/light/gentypes.py
@@ -632,7 +632,7 @@ if __name__ == '__main__':
ty.make_arg("p"),
ku.keyvar.type.make_arg(ku.keyvar.name)))
if ty.json_gen_fn is not None:
- f.write("%schar *%s_to_json(libxl_ctx *ctx, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p")))
+ f.write("%schar *%s_to_json(libxl_ctx *ctx, const %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p")))
if ty.json_parse_fn is not None:
f.write("%sint %s_from_json(libxl_ctx *ctx, %s, const char *s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
if isinstance(ty, idl.Enumeration):
@@ -662,7 +662,7 @@ if __name__ == '__main__':
""" % (header_json_define, header_json_define, " ".join(sys.argv)))
for ty in [ty for ty in types if ty.json_gen_fn is not None]:
- f.write("%syajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
+ f.write("%syajl_gen_status %s_gen_json(yajl_gen hand, const %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("\n")
f.write("""#endif /* %s */\n""" % header_json_define)
@@ -766,13 +766,13 @@ if __name__ == '__main__':
f.write("\n")
for ty in [t for t in types if t.json_gen_fn is not None]:
- f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s)\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
+ f.write("yajl_gen_status %s_gen_json(yajl_gen hand, const %s)\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("{\n")
f.write(libxl_C_type_gen_json(ty, "p"))
f.write("}\n")
f.write("\n")
- f.write("char *%s_to_json(libxl_ctx *ctx, %s)\n" % (ty.typename, ty.make_arg("p")))
+ f.write("char *%s_to_json(libxl_ctx *ctx, const %s)\n" % (ty.typename, ty.make_arg("p")))
f.write("{\n")
f.write(libxl_C_type_to_json(ty, "p"))
f.write("}\n")
diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c
index 259612834e..1cb49e3154 100644
--- a/tools/libs/light/libxl_cpuid.c
+++ b/tools/libs/light/libxl_cpuid.c
@@ -14,7 +14,7 @@
#include "libxl_internal.h"
-int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl)
+int libxl__cpuid_policy_is_empty(const libxl_cpuid_policy_list *pl)
{
return !libxl_cpuid_policy_list_length(pl);
}
diff --git a/tools/libs/light/libxl_internal.c b/tools/libs/light/libxl_internal.c
index d93a75533f..32b8788b59 100644
--- a/tools/libs/light/libxl_internal.c
+++ b/tools/libs/light/libxl_internal.c
@@ -332,7 +332,7 @@ _hidden int libxl__parse_mac(const char *s, libxl_mac mac)
return 0;
}
-_hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b)
+_hidden int libxl__compare_macs(const libxl_mac *a, const libxl_mac *b)
{
int i;
@@ -344,7 +344,7 @@ _hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b)
return 0;
}
-_hidden int libxl__mac_is_default(libxl_mac *mac)
+_hidden int libxl__mac_is_default(const libxl_mac *mac)
{
return (!(*mac)[0] && !(*mac)[1] && !(*mac)[2] &&
!(*mac)[3] && !(*mac)[4] && !(*mac)[5]);
diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h
index c79523ba92..b866827507 100644
--- a/tools/libs/light/libxl_internal.h
+++ b/tools/libs/light/libxl_internal.h
@@ -2073,9 +2073,9 @@ struct libxl__xen_console_reader {
/* parse the string @s as a sequence of 6 colon separated bytes in to @mac */
_hidden int libxl__parse_mac(const char *s, libxl_mac mac);
/* compare mac address @a and @b. 0 if the same, -ve if a<b and +ve if a>b */
-_hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b);
+_hidden int libxl__compare_macs(const libxl_mac *a, const libxl_mac *b);
/* return true if mac address is all zero (the default value) */
-_hidden int libxl__mac_is_default(libxl_mac *mac);
+_hidden int libxl__mac_is_default(const libxl_mac *mac);
/* init a recursive mutex */
_hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock);
@@ -4573,7 +4573,7 @@ _hidden int libxl__ms_vm_genid_set(libxl__gc *gc, uint32_t domid,
#define LIBXL__DEFBOOL_STR_DEFAULT "<default>"
#define LIBXL__DEFBOOL_STR_FALSE "False"
#define LIBXL__DEFBOOL_STR_TRUE "True"
-static inline int libxl__defbool_is_default(libxl_defbool *db)
+static inline int libxl__defbool_is_default(const libxl_defbool *db)
{
return !db->val;
}
@@ -4668,22 +4668,22 @@ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len);
#include "_libxl_types_internal_private.h"
/* This always return false, there's no "default value" for hw cap */
-static inline int libxl__hwcap_is_default(libxl_hwcap *hwcap)
+static inline int libxl__hwcap_is_default(const libxl_hwcap *hwcap)
{
return 0;
}
-static inline int libxl__string_list_is_empty(libxl_string_list *psl)
+static inline int libxl__string_list_is_empty(const libxl_string_list *psl)
{
return !libxl_string_list_length(psl);
}
-static inline int libxl__key_value_list_is_empty(libxl_key_value_list *pkvl)
+static inline int libxl__key_value_list_is_empty(const libxl_key_value_list *pkvl)
{
return !libxl_key_value_list_length(pkvl);
}
-int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl);
+int libxl__cpuid_policy_is_empty(const libxl_cpuid_policy_list *pl);
/* Portability note: a proper flock(2) implementation is required */
typedef struct {
@@ -4814,12 +4814,12 @@ void* libxl__device_list(libxl__gc *gc, const libxl__device_type *dt,
void libxl__device_list_free(const libxl__device_type *dt,
void *list, int num);
-static inline bool libxl__timer_mode_is_default(libxl_timer_mode *tm)
+static inline bool libxl__timer_mode_is_default(const libxl_timer_mode *tm)
{
return *tm == LIBXL_TIMER_MODE_DEFAULT;
}
-static inline bool libxl__string_is_default(char **s)
+static inline bool libxl__string_is_default(char *const *s)
{
return *s == NULL;
}
diff --git a/tools/libs/light/libxl_json.c b/tools/libs/light/libxl_json.c
index 9b8ef2cab9..88e81f9905 100644
--- a/tools/libs/light/libxl_json.c
+++ b/tools/libs/light/libxl_json.c
@@ -95,7 +95,7 @@ yajl_gen_status libxl__yajl_gen_enum(yajl_gen hand, const char *str)
* YAJL generators for builtin libxl types.
*/
yajl_gen_status libxl_defbool_gen_json(yajl_gen hand,
- libxl_defbool *db)
+ const libxl_defbool *db)
{
return libxl__yajl_gen_asciiz(hand, libxl_defbool_to_string(*db));
}
@@ -137,7 +137,7 @@ int libxl__bool_parse_json(libxl__gc *gc, const libxl__json_object *o,
}
yajl_gen_status libxl_uuid_gen_json(yajl_gen hand,
- libxl_uuid *uuid)
+ const libxl_uuid *uuid)
{
char buf[LIBXL_UUID_FMTLEN+1];
snprintf(buf, sizeof(buf), LIBXL_UUID_FMT, LIBXL_UUID_BYTES((*uuid)));
@@ -154,7 +154,7 @@ int libxl__uuid_parse_json(libxl__gc *gc, const libxl__json_object *o,
}
yajl_gen_status libxl_bitmap_gen_json(yajl_gen hand,
- libxl_bitmap *bitmap)
+ const libxl_bitmap *bitmap)
{
yajl_gen_status s;
int i;
@@ -208,7 +208,7 @@ int libxl__bitmap_parse_json(libxl__gc *gc, const libxl__json_object *o,
}
yajl_gen_status libxl_key_value_list_gen_json(yajl_gen hand,
- libxl_key_value_list *pkvl)
+ const libxl_key_value_list *pkvl)
{
libxl_key_value_list kvl = *pkvl;
yajl_gen_status s;
@@ -269,7 +269,8 @@ int libxl__key_value_list_parse_json(libxl__gc *gc, const libxl__json_object *o,
return 0;
}
-yajl_gen_status libxl_string_list_gen_json(yajl_gen hand, libxl_string_list *pl)
+yajl_gen_status libxl_string_list_gen_json(yajl_gen hand,
+ const libxl_string_list *pl)
{
libxl_string_list l = *pl;
yajl_gen_status s;
@@ -322,7 +323,7 @@ int libxl__string_list_parse_json(libxl__gc *gc, const libxl__json_object *o,
return 0;
}
-yajl_gen_status libxl_mac_gen_json(yajl_gen hand, libxl_mac *mac)
+yajl_gen_status libxl_mac_gen_json(yajl_gen hand, const libxl_mac *mac)
{
char buf[LIBXL_MAC_FMTLEN+1];
snprintf(buf, sizeof(buf), LIBXL_MAC_FMT, LIBXL_MAC_BYTES((*mac)));
@@ -339,7 +340,7 @@ int libxl__mac_parse_json(libxl__gc *gc, const libxl__json_object *o,
}
yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand,
- libxl_hwcap *p)
+ const libxl_hwcap *p)
{
yajl_gen_status s;
int i;
@@ -377,7 +378,8 @@ int libxl__hwcap_parse_json(libxl__gc *gc, const libxl__json_object *o,
return 0;
}
-yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand, libxl_ms_vm_genid *p)
+yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand,
+ const libxl_ms_vm_genid *p)
{
yajl_gen_status s;
int i;
diff --git a/tools/libs/light/libxl_nocpuid.c b/tools/libs/light/libxl_nocpuid.c
index f47336565b..73580351b3 100644
--- a/tools/libs/light/libxl_nocpuid.c
+++ b/tools/libs/light/libxl_nocpuid.c
@@ -14,7 +14,7 @@
#include "libxl_internal.h"
-int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl)
+int libxl__cpuid_policy_is_empty(const libxl_cpuid_policy_list *pl)
{
return 1;
}
@@ -40,7 +40,7 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore,
}
yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand,
- libxl_cpuid_policy_list *pcpuid)
+ const libxl_cpuid_policy_list *pcpuid)
{
return 0;
}
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 02/16] tools/libxl: Tiny optimization of libxl__mac_is_default()
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (12 preceding siblings ...)
2020-12-18 21:37 ` [WIP PATCH 01/16] tools/libxl: Mark pointer args of many functions constant Elliott Mitchell
@ 2020-12-18 22:45 ` Elliott Mitchell
2020-12-19 7:23 ` [WIP PATCH 15/16] WIP: tools/xl: Implement output format option for "vm-list" command Elliott Mitchell
2020-12-20 7:43 ` [WIP PATCH 16/16] WIP: tools/xl: Enhance " Elliott Mitchell
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-18 22:45 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
This should result in fewer branch instructions and a small performance
gain.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/libs/light/libxl_internal.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/libs/light/libxl_internal.c b/tools/libs/light/libxl_internal.c
index 32b8788b59..b4b2eb4deb 100644
--- a/tools/libs/light/libxl_internal.c
+++ b/tools/libs/light/libxl_internal.c
@@ -346,8 +346,8 @@ _hidden int libxl__compare_macs(const libxl_mac *a, const libxl_mac *b)
_hidden int libxl__mac_is_default(const libxl_mac *mac)
{
- return (!(*mac)[0] && !(*mac)[1] && !(*mac)[2] &&
- !(*mac)[3] && !(*mac)[4] && !(*mac)[5]);
+ return !((*mac)[0] | (*mac)[1] | (*mac)[2] |
+ (*mac)[3] | (*mac)[4] | (*mac)[5]);
}
_hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock)
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 15/16] WIP: tools/xl: Implement output format option for "vm-list" command
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (13 preceding siblings ...)
2020-12-18 22:45 ` [WIP PATCH 02/16] tools/libxl: Tiny optimization of libxl__mac_is_default() Elliott Mitchell
@ 2020-12-19 7:23 ` Elliott Mitchell
2020-12-20 7:43 ` [WIP PATCH 16/16] WIP: tools/xl: Enhance " Elliott Mitchell
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-19 7:23 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
While the "vm-list" subcommand has far fewer fields than the "list"
subcommand, one might still desire to list a subset of the fields.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_cmdtable.c | 7 ++++-
tools/xl/xl_list.c | 66 +++++++++++++++++++++++++-----------------
2 files changed, 46 insertions(+), 27 deletions(-)
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 91c2026bc8..c083566989 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -256,7 +256,12 @@ struct cmd_spec cmd_table[] = {
{ "vm-list",
&main_vm_list, 0, 0,
"List guest domains, excluding dom0, stubdoms, etc.",
- "",
+ "[options]\n",
+ "-F, --format Specify output format string\n"
+ " Similar to printf(3) formatting, conversion characters are:\n"
+ " %i Domain Id (%o, %x, and %X allow octal and hexadecimal)\n"
+ " %n Domain name\n"
+ " %u UUID\n"
},
{ "info",
&main_info, 0, 0,
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index 49ff2acaad..58809aa10b 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -310,6 +310,7 @@ static void format(const format_table_t fmttab, const char *fmt,
}
static const libxl_dominfo *_discard;
+static const libxl_vminfo *_discard_vm;
const format_table_t formats = {
['A' - 'A'] = {"NODE Affinity", "", format_node},
@@ -340,6 +341,20 @@ const format_table_t formats = {
(int *)&_discard->vcpu_online - (int *)_discard, {.i = 0}},
['x' - 'A'] = {"ID", "x", format_normal,
(int *)&_discard->domid - (int *)_discard, {.i = 0}},
+}, formats_vm = {
+ ['X' - 'A'] = {"ID", "X", format_normal,
+ (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = 0}},
+ ['i' - 'A'] = {"ID", "d", format_normal,
+ (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = 0}},
+ ['n' - 'A'] = {" name", "s", format_allocstr,
+ (uint32_t *)&_discard_vm->domid - (uint32_t *)_discard_vm,
+ {.xlfunc = libxl_domid_to_name}},
+ ['o' - 'A'] = {"ID", "o", format_normal,
+ (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = 0}},
+ ['u' - 'A'] = {"UUID ", "", format_uuid,
+ (char *)&_discard_vm->uuid - (char *)_discard_vm},
+ ['x' - 'A'] = {"ID", "x", format_normal,
+ (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = 0}},
};
static char *build_list_domain_format(bool verbose, bool context, bool claim,
@@ -368,29 +383,6 @@ static char *build_list_domain_format(bool verbose, bool context, bool claim,
}
-static void list_vm(void)
-{
- libxl_vminfo *info;
- char *domname;
- int nb_vm, i;
-
- info = libxl_list_vm(ctx, &nb_vm);
-
- if (!info) {
- fprintf(stderr, "libxl_list_vm failed.\n");
- exit(EXIT_FAILURE);
- }
- printf("UUID ID name\n");
- for (i = 0; i < nb_vm; i++) {
- domname = libxl_domid_to_name(ctx, info[i].domid);
- printf(LIBXL_UUID_FMT " %d %-30s\n", LIBXL_UUID_BYTES(info[i].uuid),
- info[i].domid, domname);
- free(domname);
- }
- libxl_vminfo_list_free(info, nb_vm);
-}
-
-
int main_list(int argc, char **argv)
{
int opt;
@@ -507,13 +499,35 @@ int main_list(int argc, char **argv)
int main_vm_list(int argc, char **argv)
{
+ const char *formatstr = "%u %5i %n\n";
int opt;
+ static const struct option opts[] = {
+ {"format", 0, 0, 'F'},
+ };
- SWITCH_FOREACH_OPT(opt, "", NULL, "vm-list", 0) {
- /* No options */
+ libxl_vminfo *info;
+ int nb_vm, i;
+
+ SWITCH_FOREACH_OPT(opt, "F:", opts, "vm-list", 0) {
+ case 'F':
+ formatstr = optarg;
+ break;
+ }
+
+ info = libxl_list_vm(ctx, &nb_vm);
+
+ if (!info) {
+ fprintf(stderr, "libxl_list_vm failed.\n");
+ exit(EXIT_FAILURE);
}
- list_vm();
+ format(formats_vm, formatstr, NULL);
+
+ for (i = 0; i < nb_vm; i++)
+ format(formats_vm, formatstr, info + i);
+
+ libxl_vminfo_list_free(info, nb_vm);
+
return EXIT_SUCCESS;
}
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [WIP PATCH 16/16] WIP: tools/xl: Enhance "vm-list" command
2020-12-22 19:01 [WIP PATCH 00/16] Addition of formatting options to `xl list` subcommands Elliott Mitchell
` (14 preceding siblings ...)
2020-12-19 7:23 ` [WIP PATCH 15/16] WIP: tools/xl: Implement output format option for "vm-list" command Elliott Mitchell
@ 2020-12-20 7:43 ` Elliott Mitchell
15 siblings, 0 replies; 17+ messages in thread
From: Elliott Mitchell @ 2020-12-20 7:43 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
Add several features to specify output. Allow omitting potentially
unneeded lines and add argument for exact line format.
Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
tools/xl/xl_list.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index 58809aa10b..ef44466017 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -500,18 +500,28 @@ int main_list(int argc, char **argv)
int main_vm_list(int argc, char **argv)
{
const char *formatstr = "%u %5i %n\n";
+ bool dom0 = true;
+ bool header = true;
int opt;
static const struct option opts[] = {
{"format", 0, 0, 'F'},
+ {"no-domain0", 0, 0, '0'},
+ {"no-header", 0, 0, 'H'},
};
libxl_vminfo *info;
int nb_vm, i;
- SWITCH_FOREACH_OPT(opt, "F:", opts, "vm-list", 0) {
+ SWITCH_FOREACH_OPT(opt, "0F:H", opts, "vm-list", 0) {
+ case '0':
+ dom0 = false;
+ break;
case 'F':
formatstr = optarg;
break;
+ case 'H':
+ header = false;
+ break;
}
info = libxl_list_vm(ctx, &nb_vm);
@@ -521,10 +531,10 @@ int main_vm_list(int argc, char **argv)
exit(EXIT_FAILURE);
}
- format(formats_vm, formatstr, NULL);
+ if (header) format(formats_vm, formatstr, NULL);
for (i = 0; i < nb_vm; i++)
- format(formats_vm, formatstr, info + i);
+ if (info[i].domid || dom0) format(formats_vm, formatstr, info + i);
libxl_vminfo_list_free(info, nb_vm);
--
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply related [flat|nested] 17+ messages in thread