|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [WIP PATCH 10/16] WIP: tools/xl: Implement output format option
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@xxxxxxx>
---
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@xxxxxxx PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |