From nobody Mon Feb 9 07:42:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1609801170; cv=none; d=zohomail.com; s=zohoarc; b=HAY7o3gYfGlfPWOg5PJPchtggfv9iQ8ry6Gl8iwhSTyg3l4H/fYQYFfV4uULQ3Gjx2IuycbtX2c3juGtB2Gdo0NzVpnizdU6b2mh5BfsZye0VAO6IqUn7+Bg3F5EqADKyRL0Xf8zjJdeS/VGIIIZ+wXpZVSZgvzXWnZFXrSRgSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609801170; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=MswfUeUFE+jm3/+RSIEQsIKQP575kx+uU9w/kBu4LFc=; b=iHrDxXuKsJiw3eHcB12Ny90YiwtyKPu7eSeaOeI9FRSgB3zZR/s/KP5WsibJNsduHE8pp6SKkd7RACewT3ImGoVvxEmTgKSWL5NGw9UwtZHT0gYqpWKbeHIC1jKWKzKbkLMfWXDAcao/bMUZzvUo/nhPo8fgTZjOf1ryzwUb0SQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1609801170015753.3883222746739; Mon, 4 Jan 2021 14:59:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61616.108489 (Exim 4.92) (envelope-from ) id 1kwYoi-00021X-8M; Mon, 04 Jan 2021 22:59:12 +0000 Received: by outflank-mailman (output) from mailman id 61616.108489; Mon, 04 Jan 2021 22:59:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYoi-000219-0B; Mon, 04 Jan 2021 22:59:12 +0000 Received: by outflank-mailman (input) for mailman id 61616; Mon, 04 Jan 2021 22:59:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYiO-0000oY-Tn for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:40 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id be390425-e523-4291-b9e2-b28c9aa5a300; Mon, 04 Jan 2021 22:52:22 +0000 (UTC) Received: from m5p.com (mailhost.m5p.com [IPv6:2001:470:1f07:15ff:0:0:0:f7]) by mailhost.m5p.com (8.15.2/8.15.2) with ESMTPS id 104MqCdc071464 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:18 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MqCX9071463; Mon, 4 Jan 2021 14:52:12 -0800 (PST) (envelope-from ehem) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: be390425-e523-4291-b9e2-b28c9aa5a300 Message-Id: <18f651f76d3af79d87d2c19ac74795c0ba587824.1608663694.git.ehem+xen@m5p.com> In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD Date: Thu, 10 Dec 2020 15:09:06 -0800 Subject: [WIP PATCH 10/16] WIP: tools/xl: Implement output format option X-Spam-Status: No, score=2.1 required=10.0 tests=DATE_IN_PAST_96_XX, KHOP_HELO_FCRDNS autolearn=no autolearn_force=no version=3.4.4 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mattapan.m5p.com Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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[] =3D { &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, } } =20 +static const libxl_dominfo *_discard; + +const format_table_t formats =3D { + ['A' - 'A'] =3D {"NODE Affinity", "", format_node}, + ['X' - 'A'] =3D {"ID", "X", format_normal, + (int *)&_discard->domid - (int *)_discard, {.i =3D 0}}, + ['c' - 'A'] =3D {"Claim", "lu", format_normal, + (unsigned long *)&_discard->outstanding_memkb - + (unsigned long *)_discard, {.lu =3D 1024}}, + ['i' - 'A'] =3D {"ID", "d", format_normal, + (int *)&_discard->domid - (int *)_discard, {.i =3D 0}}, + ['l' - 'A'] =3D {"Security Label", "s", format_normal, + (char **)&_discard->ssid_label - (char **)_discard}, + ['m' - 'A'] =3D {"Mem", "lu", format_memory}, + ['n' - 'A'] =3D {"Name", "s", format_allocstr, + (uint32_t *)&_discard->domid - (uint32_t *)_discard, + {.xlfunc =3D libxl_domid_to_name}}, + ['o' - 'A'] =3D {"ID", "o", format_normal, + (int *)&_discard->domid - (int *)_discard, {.i =3D 0}}, + ['p' - 'A'] =3D {"Cpupool", "s", format_allocstr, + (uint32_t *)&_discard->cpupool - (uint32_t *)_discard, + {.xlfunc =3D libxl_cpupoolid_to_name}}, + ['r' - 'A'] =3D {"Reason", "", format_reason}, + ['s' - 'A'] =3D {"State", "s", format_state}, + ['t' - 'A'] =3D {"Time(s)", "qu", format_time}, + ['u' - 'A'] =3D {" UUID ", "", format_uu= id, + (char *)&_discard->uuid - (char *)_discard}, + ['v' - 'A'] =3D {"VCPUs", "d", format_normal, + (int *)&_discard->vcpu_online - (int *)_discard, {.i = =3D 0}}, + ['x' - 'A'] =3D {"ID", "x", format_normal, + (int *)&_discard->domid - (int *)_discard, {.i =3D 0}}, +}; + =20 static void list_vm(void) { @@ -417,11 +450,13 @@ int main_list(int argc, char **argv) bool context =3D false; bool cpupool =3D false; bool details =3D false; + const char *formatstr =3D NULL; bool numa =3D false; bool verbose =3D false; static struct option opts[] =3D { {"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=3D0; int nb_domain, rc; =20 - SWITCH_FOREACH_OPT(opt, "Zchlnv", opts, "list", 0) { + SWITCH_FOREACH_OPT(opt, "F:Zchlnv", opts, "list", 0) { + case 'F': + formatstr =3D optarg; + break; case 'Z': context =3D true; break; @@ -480,7 +518,15 @@ int main_list(int argc, char **argv) =20 if (details) dump_by_dominfo_list(default_output_format, stdout, info, nb_domai= n); - 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); =20 --=20 --=20 (\___(\___(\______ --=3D> 8-) EHM <=3D-- ______/)___/)___= /) \BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) / \_CS\ | _____ -O #include O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445