From patchwork Sat Dec 12 06:18:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliott Mitchell X-Patchwork-Id: 11997679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00,DATE_IN_PAST_96_XX, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C979FC433E0 for ; Mon, 4 Jan 2021 22:52:40 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 910562072E for ; Mon, 4 Jan 2021 22:52:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 910562072E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=m5p.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.61567.108445 (Exim 4.92) (envelope-from ) id 1kwYiE-0001OL-Hg; Mon, 04 Jan 2021 22:52:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 61567.108445; Mon, 04 Jan 2021 22:52:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYiE-0001OE-EY; Mon, 04 Jan 2021 22:52:30 +0000 Received: by outflank-mailman (input) for mailman id 61567; Mon, 04 Jan 2021 22:52:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYiD-0001O0-SV for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:29 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id af198cf0-2695-4410-9693-9f57bc21a189; Mon, 04 Jan 2021 22:52:29 +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 104MqKYE071472 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:25 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MqKI4071471; Mon, 4 Jan 2021 14:52:20 -0800 (PST) (envelope-from ehem) 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: af198cf0-2695-4410-9693-9f57bc21a189 Message-Id: <6d58dc4f945abebfab21d46cd52940e984eb8ae6.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: Fri, 11 Dec 2020 22:18:14 -0800 Subject: [WIP PATCH 11/16] WIP: tools/xl: Replace most of list_domains with use of format() With a generalized formatting function now available, start to replace the old specialized formatting bits. Signed-off-by: Elliott Mitchell --- 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);