From nobody Sat May 4 17:19:31 2024 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=1609800697; cv=none; d=zohomail.com; s=zohoarc; b=jtG6GoGEEnRQESgPAJCVJvnSqHA255JuQyz/+IPrmPCg9+gjMpGCJti20CA8BJSwHfjuExMfkdG116r1Y/MHkZ2MFfz6pWO4rt0vjx5/v/Dzcxuw2Q17wItWpNFH6BUaWc58RuBTGB4q5UOOpmBDt9mwnNbeUqReXWOD/Z9Ugzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800697; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=G3sgaAVY768UEJnUJnD+eYQ2ecE9kw7QnKabeEo74ac=; b=U/bjnhbFJ+mTsWbmqVZBwBvQPALhNymsUL0OewRBEEXR9eFfHsfjO/0imjZ7ij32hutxa7yPT+DWGevixZy+Qk7KfKZWsuwyVICYVS7+6bFOy7gV/6IIJjw+ORt3lacBA6D1q3yYKl7vF7ekdhDZRv8/cDSPX/nNGx2hNsT0KOA= 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 1609800697371700.5475539516511; Mon, 4 Jan 2021 14:51:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61522.108349 (Exim 4.92) (envelope-from ) id 1kwYh2-0000Xn-Sj; Mon, 04 Jan 2021 22:51:16 +0000 Received: by outflank-mailman (output) from mailman id 61522.108349; Mon, 04 Jan 2021 22:51:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYh2-0000Xf-Nx; Mon, 04 Jan 2021 22:51:16 +0000 Received: by outflank-mailman (input) for mailman id 61522; Mon, 04 Jan 2021 22:51:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYh0-0000XS-LN for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:51:14 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 092c9ab9-e3a7-46b4-98e8-dcbe80642a46; Mon, 04 Jan 2021 22:51:13 +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 104Mp2SH071395 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:51:08 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104Mp2kg071394; Mon, 4 Jan 2021 14:51:02 -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: 092c9ab9-e3a7-46b4-98e8-dcbe80642a46 Message-Id: <7b6354965dcd8a8047f55e2ad40b2fd0057dced1.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, 18 Dec 2020 13:37:44 -0800 Subject: [WIP PATCH 01/16] tools/libxl: Mark pointer args of many functions constant 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" 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 --- 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 =20 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_lis= t *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_geni= d *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); =20 #include <_libxl_types_json.h> =20 @@ -91,6 +93,6 @@ static inline yajl_gen libxl_yajl_gen_alloc(const yajl_al= loc_funcs *allocFuncs) #endif /* !HAVE_YAJL_V2 */ =20 yajl_gen_status libxl_domain_config_gen_json(yajl_gen hand, - libxl_domain_config *p); + const libxl_domain_config *p); =20 #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__ =3D=3D '__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.hidd= en(), ty.typename, ty.make_arg("p"))) + f.write("%schar *%s_to_json(libxl_ctx *ctx, const %s);\n" % (t= y.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=3Didl.PASS_BY_REF= ERENCE))) if isinstance(ty, idl.Enumeration): @@ -662,7 +662,7 @@ if __name__ =3D=3D '__main__': """ % (header_json_define, header_json_define, " ".join(sys.argv))) =20 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" % (t= y.hidden(), ty.typename, ty.make_arg("p", passby=3Didl.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=3Didl.PASS_BY_REFERE= NCE))) =20 f.write("\n") f.write("""#endif /* %s */\n""" % header_json_define) @@ -766,13 +766,13 @@ if __name__ =3D=3D '__main__': f.write("\n") =20 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.t= ypename, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENCE))) + f.write("yajl_gen_status %s_gen_json(yajl_gen hand, const %s)\n" %= (ty.typename, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENCE))) f.write("{\n") f.write(libxl_C_type_gen_json(ty, "p")) f.write("}\n") f.write("\n") =20 - f.write("char *%s_to_json(libxl_ctx *ctx, %s)\n" % (ty.typename, t= y.make_arg("p"))) + f.write("char *%s_to_json(libxl_ctx *ctx, const %s)\n" % (ty.typen= ame, 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 @@ =20 #include "libxl_internal.h" =20 -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_int= ernal.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 m= ac) return 0; } =20 -_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; =20 @@ -344,7 +344,7 @@ _hidden int libxl__compare_macs(libxl_mac *a, libxl_mac= *b) return 0; } =20 -_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_int= ernal.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 ab= */ -_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 *l= ock); =20 @@ -4573,7 +4573,7 @@ _hidden int libxl__ms_vm_genid_set(libxl__gc *gc, uin= t32_t domid, #define LIBXL__DEFBOOL_STR_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" =20 /* 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; } =20 -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); } =20 -static inline int libxl__key_value_list_is_empty(libxl_key_value_list *pkv= l) +static inline int libxl__key_value_list_is_empty(const libxl_key_value_lis= t *pkvl) { return !libxl_key_value_list_length(pkvl); } =20 -int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl); +int libxl__cpuid_policy_is_empty(const libxl_cpuid_policy_list *pl); =20 /* 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); =20 -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 =3D=3D LIBXL_TIMER_MODE_DEFAULT; } =20 -static inline bool libxl__string_is_default(char **s) +static inline bool libxl__string_is_default(char *const *s) { return *s =3D=3D 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, } =20 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, } =20 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, } =20 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 =3D *pkvl; yajl_gen_status s; @@ -269,7 +269,8 @@ int libxl__key_value_list_parse_json(libxl__gc *gc, con= st libxl__json_object *o, return 0; } =20 -yajl_gen_status libxl_string_list_gen_json(yajl_gen hand, libxl_string_lis= t *pl) +yajl_gen_status libxl_string_list_gen_json(yajl_gen hand, + const libxl_string_list *pl) { libxl_string_list l =3D *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; } =20 -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__j= son_object *o, } =20 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; } =20 -yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand, libxl_ms_vm_geni= d *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_nocp= uid.c index f47336565b..73580351b3 100644 --- a/tools/libs/light/libxl_nocpuid.c +++ b/tools/libs/light/libxl_nocpuid.c @@ -14,7 +14,7 @@ =20 #include "libxl_internal.h" =20 -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, } =20 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; } --=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 From nobody Sat May 4 17:19:31 2024 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=1609800696; cv=none; d=zohomail.com; s=zohoarc; b=RgvJS7XuU8PMV/vNJz9vy7tYLV2AVRctZAMgKyZxpyqEg6o6kGHEZbsvS4J4lSH2Lp+8ggNazZcQzniOUCLilOlhII3oTD2YA90uEsE9s0zdoOcZqqkuBb6iinvvS0EKQK+6CXZ3qzbQay0vUIDsXLhOQ6UlRzBZ2P8zxMv9c7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800696; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=m7cm/9FB43PWTY7fiPkkRCXbzTJ0HzdFnUf8UBDfAt4=; b=oEpPtJHpwxuZVDvPGKDoGz79Q4w7qpqeWnpvRBacONfqlhwz0Ar080H6kdN0OpJPLLmpezU0WwHWd7Xm4CLLJQZwvm57CDI2y5Ksf66UIvu1yKDXgXUV0qyvHC29riHLvtzyj8+o04eWUDlTmfNFLSktPkKaU5+6ENPKR2sUiiE= 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 160980069621292.81349015629416; Mon, 4 Jan 2021 14:51:36 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61523.108360 (Exim 4.92) (envelope-from ) id 1kwYh8-0000a1-3B; Mon, 04 Jan 2021 22:51:22 +0000 Received: by outflank-mailman (output) from mailman id 61523.108360; Mon, 04 Jan 2021 22:51:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYh8-0000Zu-04; Mon, 04 Jan 2021 22:51:22 +0000 Received: by outflank-mailman (input) for mailman id 61523; Mon, 04 Jan 2021 22:51:20 +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 1kwYh6-0000ZU-QT for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:51:20 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 74eddb61-79df-4678-bd50-c2d0dfdcce29; Mon, 04 Jan 2021 22:51:20 +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 104MpADi071400 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:51:16 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MpAT8071399; Mon, 4 Jan 2021 14:51:10 -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: 74eddb61-79df-4678-bd50-c2d0dfdcce29 Message-Id: <03e1951b566bf6c010d9d62a1379288411fbab7b.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, 18 Dec 2020 14:45:02 -0800 Subject: [WIP PATCH 02/16] tools/libxl: Tiny optimization of libxl__mac_is_default() 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" This should result in fewer branch instructions and a small performance gain. Signed-off-by: Elliott Mitchell --- 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_int= ernal.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, con= st libxl_mac *b) =20 _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]); } =20 _hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *l= ock) --=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 From nobody Sat May 4 17:19:31 2024 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=1609800705; cv=none; d=zohomail.com; s=zohoarc; b=IPg5w0a36XFdPAVIItCE91y+BrAi2iLv+TTIuNLPdjiOTKHNRbQNVIt629beoMzU5oEGqh2Qzfe9IwFbXbbh+dIYHc1U6QfjC8KwqvkS05oNToPIgLeMUUUA/mgNby0DH4oIXig+GUKuo4ltqKEIhe6ksefbDM87Z0zUSLp0TwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800705; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=CXimBOZQhbcsKgCh8q5Wk7xE9PfLSUxt0aieHwRjuBU=; b=iRalAasfixQGIIURxvuiGXMIgkB6IFgctNxTaaZ43647xRhF26lcgSiY75boRx3xtWrEqHzVurYquhIUl6CxzIInyzaEZc9PwxZKCj+xjwWUXGgKV4qiCyJjkAePPCgri0F6L1UW88IAjs/taqo1PT5AYNKsTX39QCKoPuVaGCw= 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 1609800705057820.7118097421688; Mon, 4 Jan 2021 14:51:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61528.108373 (Exim 4.92) (envelope-from ) id 1kwYhH-0000fy-Cx; Mon, 04 Jan 2021 22:51:31 +0000 Received: by outflank-mailman (output) from mailman id 61528.108373; Mon, 04 Jan 2021 22:51:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhH-0000fr-9F; Mon, 04 Jan 2021 22:51:31 +0000 Received: by outflank-mailman (input) for mailman id 61528; Mon, 04 Jan 2021 22:51:30 +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 1kwYhG-0000ZU-NX for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:51:30 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 047c96d6-46a5-4970-aeab-412a4a802dc5; Mon, 04 Jan 2021 22:51:28 +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 104MpIhj071405 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:51:23 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MpInU071404; Mon, 4 Jan 2021 14:51:18 -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: 047c96d6-46a5-4970-aeab-412a4a802dc5 Message-Id: <576c76de7d4efd0ca219ec9c1b2fea2709f034ef.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, 18 Dec 2020 13:32:33 -0800 Subject: [WIP PATCH 03/16] tools/xl: Mark libxl_domain_config * arg of printf_info_*() const 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" 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 --- 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; =20 -extern void printf_info_sexp(int domid, libxl_domain_config *d_config, FIL= E *fh); +extern void printf_info_sexp(int domid, const libxl_domain_config *d_confi= g, 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, ...) } =20 static yajl_gen_status printf_info_one_json(yajl_gen hand, int domid, - libxl_domain_config *d_config) + const libxl_domain_config *d_c= onfig) { yajl_gen_status s; =20 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; =20 - libxl_domain_create_info *c_info =3D &d_config->c_info; - libxl_domain_build_info *b_info =3D &d_config->b_info; + const libxl_domain_create_info *c_info =3D &d_config->c_info; + const libxl_domain_build_info *b_info =3D &d_config->b_info; =20 fprintf(fh, "(domain\n\t(domid %d)\n", domid); fprintf(fh, "\t(create_info)\n"); --=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 From nobody Sat May 4 17:19:31 2024 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=1609800710; cv=none; d=zohomail.com; s=zohoarc; b=mCiYbmhC8y0p7vwMwFqthYyaTYb2XFH7+DhB3xJ4aYeDYN4T4B01e5ppdH/nWw/zLkZ1012Y6lm6guamaeDhL3HuPQxm66fBsiRG+mjSYGwry1gXWb+zI47ar8s4bcYRbM5A+4PdB6OMxYX5EZXyL0ALCeB6eqsHYBkIzuapiN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800710; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=BP6WARlMrp4uWuMyp+x+V/n9ooVDCxjoM0KYvViw2UE=; b=Nn5AisjCF71rE8qn3FLx5rXNb9XypiptWRoq0nFrCV6gpTaNL8wjCgUH2+TQQB/fo/AR5vMLwRSn29ZrfcVIpuI9jd+J1YVlLkaSmQZvmyMnTR/CxOn2sd2l/OoNr4Fpu6y2n2IiJ0t1lC5Q4FFfw9pYIpL39aYMdNIl6SuSyFM= 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 1609800710227239.0255060708513; Mon, 4 Jan 2021 14:51:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61532.108385 (Exim 4.92) (envelope-from ) id 1kwYhN-0000kV-MI; Mon, 04 Jan 2021 22:51:37 +0000 Received: by outflank-mailman (output) from mailman id 61532.108385; Mon, 04 Jan 2021 22:51:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhN-0000kN-Id; Mon, 04 Jan 2021 22:51:37 +0000 Received: by outflank-mailman (input) for mailman id 61532; Mon, 04 Jan 2021 22:51:36 +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 1kwYhL-0000jd-Vc for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:51:36 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ab6e5f3b-46a0-45dc-bb92-11cef390a97d; Mon, 04 Jan 2021 22:51:34 +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 104MpP0U071412 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:51:31 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MpPNH071411; Mon, 4 Jan 2021 14:51:25 -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: ab6e5f3b-46a0-45dc-bb92-11cef390a97d Message-Id: In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD Date: Thu, 17 Dec 2020 17:42:42 -0800 Subject: [WIP PATCH 04/16] tools/xl: Rename printf_info()/list_domains_details() to dump_by_...() 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" 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 --- 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; =20 +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_confi= g, 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; } =20 -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 =3D=3D OUTPUT_FORMAT_SXP) return printf_info_sexp(domid, d_config, fh); @@ -438,7 +436,10 @@ static void list_domains(bool verbose, bool context, b= ool claim, bool numa, libxl_physinfo_dispose(&physinfo); } =20 -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; =20 @@ -449,7 +450,7 @@ static void list_domains_details(const libxl_dominfo *i= nfo, int nb_domain) const char *buf; libxl_yajl_length yajl_len =3D 0; =20 - if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { + if (output_format =3D=3D OUTPUT_FORMAT_JSON) { hand =3D 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 =3D=3D OUTPUT_FORMAT_JSON) + if (output_format =3D=3D OUTPUT_FORMAT_JSON) s =3D 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 !=3D yajl_gen_status_ok) goto out; } =20 - if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { + if (output_format =3D=3D OUTPUT_FORMAT_JSON) { s =3D yajl_gen_array_close(hand); if (s !=3D yajl_gen_status_ok) goto out; @@ -486,11 +487,12 @@ static void list_domains_details(const libxl_dominfo = *info, int nb_domain) if (s !=3D yajl_gen_status_ok) goto out; =20 - puts(buf); + fputs(buf, fh); + fputc('\n', fh); } =20 out: - if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { + if (output_format =3D=3D OUTPUT_FORMAT_JSON) { yajl_gen_free(hand); if (s !=3D yajl_gen_status_ok) fprintf(stderr, @@ -567,7 +569,7 @@ int main_list(int argc, char **argv) } =20 if (details) - list_domains_details(info, nb_domain); + dump_by_dominfo_list(default_output_format, stdout, info, nb_domai= n); 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; } =20 -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); =20 if (debug || dryrun_only) - printf_info(default_output_format, -1, &d_config, stdout); + dump_by_config(default_output_format, stdout, &d_config, -1); =20 if (!dryrun_only) { fprintf(stderr, "setting dom%u configuration\n", domid); --=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 From nobody Sat May 4 17:19:31 2024 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=1609800717; cv=none; d=zohomail.com; s=zohoarc; b=mXJxq2UV7iaC+q2hPzWwOtz4ibqiWGVk4DK0ptly+48zK9UKOSbS+PBIYqOR8QSKmFM1/B+coBi3Q1UtqFXcOHrPKXhz7bh/hexgtE8pOlqXthwQJ6m/DQ7eekmQMoBhPIrV3nLPmstIxTZHmLMQAh7kLRY1kRiGpk3PdLe+l6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800717; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=hyGRDi+DqS4pNNKUXlOYGUGDHgLEYM2eepomrzQBt4M=; b=eS51CnnGEOxNQ1VNQ0mPPES1OQK2rAqNnUmymPmYH5REo838VDtB+A7zAk03L4TZMKNoQd+ohRVpC61a/EmgzkHNHRkofbA1S+WTc3D4SnJu2nCpkef+d5jXSqoLqm+dPCdo8y4txwxNwwrN/YykRdsDlGWu/X98pcRJCtwD734= 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 1609800717339306.46226495182214; Mon, 4 Jan 2021 14:51:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61537.108397 (Exim 4.92) (envelope-from ) id 1kwYhV-0000rK-5R; Mon, 04 Jan 2021 22:51:45 +0000 Received: by outflank-mailman (output) from mailman id 61537.108397; Mon, 04 Jan 2021 22:51:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhV-0000rD-1g; Mon, 04 Jan 2021 22:51:45 +0000 Received: by outflank-mailman (input) for mailman id 61537; Mon, 04 Jan 2021 22:51:43 +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 1kwYhT-0000qT-MZ for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:51:43 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 95d3c12e-e471-4cf5-a1bf-a9b373d21a4a; Mon, 04 Jan 2021 22:51:42 +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 104MpXOt071423 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:51:38 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MpXLe071422; Mon, 4 Jan 2021 14:51:33 -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: 95d3c12e-e471-4cf5-a1bf-a9b373d21a4a Message-Id: <727689d0c61e4309753fbb398b6cfd80be07942a.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, 17 Dec 2020 17:42:42 -0800 Subject: [WIP PATCH 05/16] tools/xl: Merge down debug/dry-run section of create_domain() 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" 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 --- 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) =20 if (debug || dom_info->dryrun) { FILE *cfg_print_fh =3D (debug && !dom_info->dryrun) ? stderr : std= out; - if (default_output_format =3D=3D OUTPUT_FORMAT_SXP) { - printf_info_sexp(-1, &d_config, cfg_print_fh); - } else { - char *json =3D 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); } =20 =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 From nobody Sat May 4 17:19:31 2024 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=1609800730; cv=none; d=zohomail.com; s=zohoarc; b=JeYUKOYIN0NobZNWaRMwDREvh6NgfA5hsuA/8ibY8y9S5E7zOUsKPGB4BW2SnxwndZ1yZcbENRHdxNq7KVLRRRFp9kUonT8utlSy1WszUI9s0a1AYLvOoI98s3p+Jvg4mHSR9SHDMAf36b4txQwZk6CVFbzWhMGJoiaJ9oOGrZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800730; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=QIL7lBA7c8RzwU3W3jsTns45lHBoqy8ZHbq09yq0qI4=; b=mAiXugysT0zTF53SpEo9ERpomV0p2RDJmclt/TThk9bcnrjGH1kSXs6EDu5Iam5TQnRRHURMEdZPxp6MalF2MgMvDJ/Xeu0eqw3H/JQKCOLfgN3IKJqwbuskpWqaxnXUQ+rvfP7wMNip6FY2uuI+qU2pAWWxkyC6mJVM0q1TKoQ= 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 1609800730843878.8738957613873; Mon, 4 Jan 2021 14:52:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61544.108408 (Exim 4.92) (envelope-from ) id 1kwYhe-0000yf-E3; Mon, 04 Jan 2021 22:51:54 +0000 Received: by outflank-mailman (output) from mailman id 61544.108408; Mon, 04 Jan 2021 22:51:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhe-0000yV-Am; Mon, 04 Jan 2021 22:51:54 +0000 Received: by outflank-mailman (input) for mailman id 61544; Mon, 04 Jan 2021 22:51:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhc-0000oY-Tc for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:51:52 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0e4fb3fa-0264-404b-a447-8668531a2d17; Mon, 04 Jan 2021 22:51:51 +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 104Mpe90071432 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:51:46 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MpeHL071431; Mon, 4 Jan 2021 14:51:40 -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: 0e4fb3fa-0264-404b-a447-8668531a2d17 Message-Id: In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD Date: Wed, 9 Dec 2020 14:45:15 -0800 Subject: [WIP PATCH 06/16] tools/xl: Split list commands off of xl_info.c 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" The domain listing commands have more in common with each other than hypervisor information commands. Signed-off-by: Elliott Mitchell --- I'm concerned about my header-stripping job. Notably the headers , , and 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 =3D xl.o xl_cmdtable.o xl_sxp.o xl_utils.o $(XL_O= BJS-y) XL_OBJS +=3D xl_parse.o xl_cpupool.o xl_flask.o XL_OBJS +=3D xl_vtpm.o xl_block.o xl_nic.o xl_usb.o XL_OBJS +=3D xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o -XL_OBJS +=3D xl_info.o xl_console.o xl_misc.o +XL_OBJS +=3D xl_info.o xl_list.o xl_console.o xl_misc.o XL_OBJS +=3D xl_vmcontrol.o xl_saverestore.o xl_migrate.o XL_OBJS +=3D xl_vdispl.o xl_vsnd.o xl_vkb.o =20 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 #include #include -#include -#include #include #include #include @@ -26,7 +24,6 @@ #include #include #include -#include =20 #include "xl.h" #include "xl_utils.h" @@ -336,105 +333,6 @@ static void print_info(int numa) return; } =20 -static void list_vm(void) -{ - libxl_vminfo *info; - char *domname; - int nb_vm, i; - - info =3D 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 =3D 0; i < nb_vm; i++) { - domname =3D 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_d= omain) -{ - int i; - static const char shutdown_reason_letters[]=3D "-rscwS"; - libxl_bitmap nodemap; - libxl_physinfo physinfo; - - libxl_bitmap_init(&nodemap); - libxl_physinfo_init(&physinfo); - - printf("Name ID Mem VCPUs\tSt= ate\tTime(s)"); - if (verbose) printf(" UUID Reason-Code\tS= ecurity 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) !=3D 0) { - fprintf(stderr, "libxl_physinfo failed.\n"); - libxl_bitmap_dispose(&nodemap); - exit(EXIT_FAILURE); - } - - printf(" NODE Affinity"); - } - printf("\n"); - for (i =3D 0; i < nb_domain; i++) { - char *domname; - libxl_shutdown_reason shutdown_reason; - domname =3D libxl_domid_to_name(ctx, info[i].domid); - shutdown_reason =3D 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 >=3D 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 / 102= 4); - if (verbose || context) - printf(" %16s", info[i].ssid_label ? : "-"); - if (cpupool) { - char *poolname =3D libxl_cpupoolid_to_name(ctx, info[i].cpupoo= l); - 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); -} =20 void dump_by_dominfo_list(enum output_format output_format, FILE *fh, @@ -501,99 +399,6 @@ out: } =20 =20 -int main_list(int argc, char **argv) -{ - int opt; - bool verbose =3D false; - bool context =3D false; - bool details =3D false; - bool cpupool =3D false; - bool numa =3D false; - static struct option opts[] =3D { - {"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=3D0; - int nb_domain, rc; - - SWITCH_FOREACH_OPT(opt, "lvhZcn", opts, "list", 0) { - case 'l': - details =3D true; - break; - case 'v': - verbose =3D true; - break; - case 'Z': - context =3D true; - break; - case 'c': - cpupool =3D true; - break; - case 'n': - numa =3D true; - break; - } - - libxl_dominfo_init(&info_buf); - - if (optind >=3D argc) { - info =3D libxl_list_domain(ctx, &nb_domain); - if (!info) { - fprintf(stderr, "libxl_list_domain failed.\n"); - return EXIT_FAILURE; - } - info_free =3D info; - } else if (optind =3D=3D argc-1) { - uint32_t domid =3D find_domain(argv[optind]); - rc =3D libxl_domain_info(ctx, &info_buf, domid); - if (rc =3D=3D 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 =3D &info_buf; - nb_domain =3D 1; - } else { - help("list"); - return EXIT_FAILURE; - } - - if (details) - dump_by_dominfo_list(default_output_format, stdout, info, nb_domai= n); - 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, in= t short_mode) return time_string; } =20 -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 =3D 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 +#include +#include + +#include +#include + +#include "xl.h" +#include "xl_utils.h" + + +static void list_vm(void) +{ + libxl_vminfo *info; + char *domname; + int nb_vm, i; + + info =3D 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 =3D 0; i < nb_vm; i++) { + domname =3D 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_d= omain) +{ + int i; + static const char shutdown_reason_letters[]=3D "-rscwS"; + libxl_bitmap nodemap; + libxl_physinfo physinfo; + + libxl_bitmap_init(&nodemap); + libxl_physinfo_init(&physinfo); + + printf("Name ID Mem VCPUs\tSt= ate\tTime(s)"); + if (verbose) printf(" UUID Reason-Code\tS= ecurity 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) !=3D 0) { + fprintf(stderr, "libxl_physinfo failed.\n"); + libxl_bitmap_dispose(&nodemap); + exit(EXIT_FAILURE); + } + + printf(" NODE Affinity"); + } + printf("\n"); + for (i =3D 0; i < nb_domain; i++) { + char *domname; + libxl_shutdown_reason shutdown_reason; + domname =3D libxl_domid_to_name(ctx, info[i].domid); + shutdown_reason =3D 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 >=3D 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 / 102= 4); + if (verbose || context) + printf(" %16s", info[i].ssid_label ? : "-"); + if (cpupool) { + char *poolname =3D libxl_cpupoolid_to_name(ctx, info[i].cpupoo= l); + 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 =3D false; + bool context =3D false; + bool details =3D false; + bool cpupool =3D false; + bool numa =3D false; + static struct option opts[] =3D { + {"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=3D0; + int nb_domain, rc; + + SWITCH_FOREACH_OPT(opt, "lvhZcn", opts, "list", 0) { + case 'l': + details =3D true; + break; + case 'v': + verbose =3D true; + break; + case 'Z': + context =3D true; + break; + case 'c': + cpupool =3D true; + break; + case 'n': + numa =3D true; + break; + } + + libxl_dominfo_init(&info_buf); + + if (optind >=3D argc) { + info =3D libxl_list_domain(ctx, &nb_domain); + if (!info) { + fprintf(stderr, "libxl_list_domain failed.\n"); + return EXIT_FAILURE; + } + info_free =3D info; + } else if (optind =3D=3D argc-1) { + uint32_t domid =3D find_domain(argv[optind]); + rc =3D libxl_domain_info(ctx, &info_buf, domid); + if (rc =3D=3D 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 =3D &info_buf; + nb_domain =3D 1; + } else { + help("list"); + return EXIT_FAILURE; + } + + if (details) + dump_by_dominfo_list(default_output_format, stdout, info, nb_domai= n); + 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 =3D 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: + */ --=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 From nobody Sat May 4 17:19:31 2024 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=1609800745; cv=none; d=zohomail.com; s=zohoarc; b=CX7696wo2+pNQq66gbV9u6giB32Yh/mm85/RdEN2zIJdw/ktjxu42RcILbf0gV7CYmkqTco2EjhOYdCA5ZUey0Sobghom5TIZOwad3hrfkobcat5z/dm9/7IBFXh4HuUIgf16yRgKrJASrzCZXflorwc95OzN8jE22+FcrnBUo4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800745; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=/DAtl29I47r02J1iKAFddBFld448KR070EvuR6athsA=; b=b8SRvZCkVvZqKi+frCECt0QrH3hRf9ZFU8lirUmVPNdq1IC9MqyKpmDEu2L7qt7f5SKAcciSPgTx1tpYoOQqf6l6RZTu6+dJOrs38UFO9U8NZzL6wHv+7S9hWF/67aLUocKMfsVPBnW/sJZJKohz4GRJyyLoHzTZEd8B2qPBy0U= 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 1609800745344969.3309615671661; Mon, 4 Jan 2021 14:52:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61556.108432 (Exim 4.92) (envelope-from ) id 1kwYhx-0001C2-2h; Mon, 04 Jan 2021 22:52:13 +0000 Received: by outflank-mailman (output) from mailman id 61556.108432; Mon, 04 Jan 2021 22:52:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhw-0001Bu-Vz; Mon, 04 Jan 2021 22:52:12 +0000 Received: by outflank-mailman (input) for mailman id 61556; Mon, 04 Jan 2021 22:52:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhu-0000oY-Ss for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:10 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9f1e43c2-3fb8-4ee3-909c-927d361f92ea; Mon, 04 Jan 2021 22:51:59 +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 104MpnaN071442 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:51:55 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104Mpnsm071441; Mon, 4 Jan 2021 14:51:49 -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: 9f1e43c2-3fb8-4ee3-909c-927d361f92ea Message-Id: <80f80b6bf5da09ceb332773b96f1dd554782b030.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: Wed, 9 Dec 2020 14:34:37 -0800 Subject: [WIP PATCH 07/16] tools/xl: Sort list command options 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" 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 --- 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[] =3D { &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 =3D false; bool context =3D false; - bool details =3D false; bool cpupool =3D false; + bool details =3D false; bool numa =3D false; + bool verbose =3D false; static struct option opts[] =3D { - {"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 }; =20 @@ -147,22 +147,22 @@ int main_list(int argc, char **argv) libxl_dominfo *info, *info_free=3D0; int nb_domain, rc; =20 - SWITCH_FOREACH_OPT(opt, "lvhZcn", opts, "list", 0) { - case 'l': - details =3D true; - break; - case 'v': - verbose =3D true; - break; + SWITCH_FOREACH_OPT(opt, "Zchlnv", opts, "list", 0) { case 'Z': context =3D true; break; case 'c': cpupool =3D true; break; + case 'l': + details =3D true; + break; case 'n': numa =3D true; break; + case 'v': + verbose =3D true; + break; } =20 libxl_dominfo_init(&info_buf); --=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 From nobody Sat May 4 17:19:31 2024 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=1609800743; cv=none; d=zohomail.com; s=zohoarc; b=gqXrLry6Dqrn5OMd3Jasc07bJ8nLTdRScZxrfqrLPPULtsGPTiBBTtMbPZQVCtuHxtlIkCIhOt9Kncyays9GUVTOSoHtMBgRtiDEbvA6TM0E7XlSohc8W0/bRljLm+lZfjVz8eOmcYlKwVGq55sd21rw6Dr7q1DCL34ld0mb5mY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800743; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=9uxl2ttEvVg/n/n3IVhidI6uvcYk3rVVfVXR9EoC59g=; b=OTms1y2dYUdgxJgPb8FL5dx6nuQz+wch9NQisxvZRp7qFPAc5QriOdFmhwKVWgALbYB2VDrDUEd6gjzGaGMDK4C6XECNcaPzvVV7XcLN2rhTQAB9Hb5bK/nbuC7B4UziG6ZK/GdTL+wbXonIdKA63E4MEMHyhDKeftPryxRh3TM= 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 1609800743000936.0864777513382; Mon, 4 Jan 2021 14:52:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61554.108421 (Exim 4.92) (envelope-from ) id 1kwYhu-00019d-Nu; Mon, 04 Jan 2021 22:52:10 +0000 Received: by outflank-mailman (output) from mailman id 61554.108421; Mon, 04 Jan 2021 22:52:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYhu-00019W-Kj; Mon, 04 Jan 2021 22:52:10 +0000 Received: by outflank-mailman (input) for mailman id 61554; Mon, 04 Jan 2021 22:52:09 +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 1kwYht-00018z-06 for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:09 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 476ca007-97e6-4a19-b946-41a7d28fb412; Mon, 04 Jan 2021 22:52:08 +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 104Mpvt3071451 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:03 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104Mpv9A071450; Mon, 4 Jan 2021 14:51:57 -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: 476ca007-97e6-4a19-b946-41a7d28fb412 Message-Id: <3433bf049b9d626282e49824a744c9264a6db215.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 08/16] tools/xl: Fix potential deallocation bug 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" 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 --- 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); =20 if (info_free) - libxl_dominfo_list_free(info, nb_domain); + libxl_dominfo_list_free(info_free, nb_domain); =20 libxl_dominfo_dispose(&info_buf); =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 From nobody Sat May 4 17:19:31 2024 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=1609801171; cv=none; d=zohomail.com; s=zohoarc; b=S7gHbJEqFKXfCASlROYRqW7tUZEAJNVIjqsMIBd2trYWOhAA6T3ChsJlGXUAZtmKTBn0mBcCGuyU704XhJGFzTDHa0zMhB5YnuJafPHePkC15c7xHJNGfm8dpGEi2vyPrPAyPTD4ErRaweiz/ZV6VwYivqxZhLAe9H9X6eWUVVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609801171; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kmYCzUMZVUQBOGPwej+XJa0Y2JHv3hXmkOJwqpuov+I=; b=C8V3FDrVAZuuQmaXumZ2Ym2mg2HVNE3QZg0N46rzZI1j6Hz82mW++Q648DYAqzVlPNX/qiEtDhbtBL880QWjA56w/j7LGeV+IsjQuUQ6HMVycJS480ajLvrW/2NJYE2iMsO/EwwbbMUyHUsFlW7L5d5FZNrzikJR2GJUNPA5x6Y= 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 1609801171354380.01581210860786; Mon, 4 Jan 2021 14:59:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61626.108526 (Exim 4.92) (envelope-from ) id 1kwYon-0002BT-Ii; Mon, 04 Jan 2021 22:59:17 +0000 Received: by outflank-mailman (output) from mailman id 61626.108526; Mon, 04 Jan 2021 22:59:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYon-0002Aw-6T; Mon, 04 Jan 2021 22:59:17 +0000 Received: by outflank-mailman (input) for mailman id 61626; Mon, 04 Jan 2021 22:59:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYi9-0000oY-TA for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:25 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 91638428-f27c-4490-b226-9fd16a395869; Mon, 04 Jan 2021 22:52:14 +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 104Mq4co071457 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:10 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104Mq4G4071456; Mon, 4 Jan 2021 14:52:04 -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: 91638428-f27c-4490-b226-9fd16a395869 Message-Id: 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 09/16] WIP: tools/xl: Implement generalized output formatting for `xl list` 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" 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 --- I'm a bit unsure of #include . 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 @@ =20 #define _GNU_SOURCE =20 +#include #include #include +#include #include =20 +#include + #include #include =20 @@ -25,6 +29,287 @@ #include "xl_utils.h" =20 =20 +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 =3D 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 =3D ((char **)info)[entry->offset]; + if (!str) str =3D "-"; + printf(buf, str); + break; + case 'f': + f =3D ((float *)info)[entry->offset]; + if (entry->extra.f !=3D 0) f /=3D entry->extra.f; + printf(buf, f); + break; + case 'l': + lu =3D ((unsigned long *)info)[entry->offset]; + if (entry->extra.lu) lu /=3D entry->extra.lu; + printf(buf, lu); + break; + case 'd': + default: + i =3D ((int *)info)[entry->offset]; + if (entry->extra.i) i /=3D entry->extra.i; + printf(buf, i); + break; + } + } else { + if (entry->formatc[0] =3D=3D 'f') { + char *tmp; + buf[len] =3D '\0'; + if ((tmp =3D rindex(buf, '.'))) + len =3D 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 =3D alloca(len + 2); + char *outbuf; + memcpy(fmt, format, len); + strcpy(fmt + len, "s"); + + if (info) { + outbuf =3D entry->extra.xlfunc(ctx, ((uint32_t *)info)[entry->offs= et]); + 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 *)((cha= r *)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 =3D _info; + char *fmt =3D 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 =3D index(fmt, '.'))) tmp =3D 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 =3D _info; + if (info) { + const char shutdown_reason_letters[] =3D "-rscwS"; + libxl_shutdown_reason shutdown_reason; + static const char letters[] =3D "rbps"; + int i; + const bool *flags; + + flags =3D &info->running; + for (i =3D 0; i < strlen(letters); ++i) + putchar(flags[i] ? letters[i] : '-'); + + shutdown_reason =3D info->shutdown ? info->shutdown_reason : 0; + putchar((shutdown_reason >=3D 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 =3D _info; + const char *output =3D entry->header; + if (info) { + if (info->shutdown) { + printf("%8x", info->shutdown_reason); + return; + } + output =3D "-"; + } + 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 =3D _info; + char *fmt =3D 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 =3D _info; + static bool need_init =3D true; + static libxl_bitmap nodemap; + static libxl_physinfo physinfo; + + if (need_init) { + libxl_bitmap_init(&nodemap); + libxl_physinfo_init(&physinfo); + need_init =3D 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) !=3D 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[] =3D { + ['0'] =3D true, + ['1'] =3D true, + ['2'] =3D true, + ['3'] =3D true, + ['4'] =3D true, + ['5'] =3D true, + ['6'] =3D true, + ['7'] =3D true, + ['8'] =3D true, + ['9'] =3D true, + ['.'] =3D true, + ['#'] =3D true, + ['-'] =3D true, + ['+'] =3D true, + [' '] =3D true, + ['\''] =3D 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] =3D=3D '\\') { + 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+=3D2; + } else if (fmt[0] =3D=3D '%') { + size_t len=3D1; + unsigned char entryn; + + while (isfmtchar(fmt[len])) ++len; + + entryn =3D 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 +=3D len + 1; + } else { + putchar(*fmt); + ++fmt; + } + } +} + + static void list_vm(void) { libxl_vminfo *info; --=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 From nobody Sat May 4 17:19:31 2024 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 From nobody Sat May 4 17:19:31 2024 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=1609800765; cv=none; d=zohomail.com; s=zohoarc; b=OgcHjA+Q7RUaqUf88FDQcR44GphFQNvYViDTZFL4MzfqbAMU/rDtVIr6KM1fE0yk5JiP6LPzb1AWXHpGzYJki1S2wGpqufJWMWKsLz01U7kMyYYiufxbNPbu7iEWLVMePio384kT/1REDxLjmUiwUz6rUTAWeE4n4jA5r3+B5Qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800765; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=XHSQgh7JF3BnfvdyvlGOHH4UwiCoAFi8HFnzJ8Vzyog=; b=ck7ArHNU7GOmu/yGPgeThNXGexU3tLnWpd8epDVpGp2KYVPxrPpXMjjdBuFqyasc2fz7Ab1j5Tm/7xS5IZZQkBFBrmaHMg1ZxHlYr5Z+C7Rpmgvv29skgmhNHeVTAti+fnq5HGP5TzqwFrPbdv5kgGsdmWqzyB5DktQpJjtbki0= 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 1609800765752589.6720953097637; Mon, 4 Jan 2021 14:52:45 -0800 (PST) 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 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-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: 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() 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" 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_d= omain) { int i; - static const char shutdown_reason_letters[]=3D "-rscwS"; + const char lead[] =3D "%-40n %5i %5m %5v %s %8.1t"; + libxl_bitmap nodemap; libxl_physinfo physinfo; =20 libxl_bitmap_init(&nodemap); libxl_physinfo_init(&physinfo); =20 - printf("Name ID Mem VCPUs\tSt= ate\tTime(s)"); - if (verbose) printf(" UUID Reason-Code\tS= ecurity 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 =3D 0; i < nb_domain; i++) { - char *domname; - libxl_shutdown_reason shutdown_reason; - domname =3D libxl_domid_to_name(ctx, info[i].domid); - shutdown_reason =3D 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 >=3D 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 / 102= 4); if (verbose || context) - printf(" %16s", info[i].ssid_label ? : "-"); + format(formats, " %16l", info + i); if (cpupool) { char *poolname =3D libxl_cpupoolid_to_name(ctx, info[i].cpupoo= l); printf("%16s", poolname); --=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 From nobody Sat May 4 17:19:31 2024 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=1609801168; cv=none; d=zohomail.com; s=zohoarc; b=WYibRn+7gS+pQWrJ89/oKn2UwuwMT1iPbhO6VrBydHWVs4pQ++DZUId0/0Ago5XwHiN+VgXwuW5Hds2GrS59uN4lbYEoBJQPWU4xy8ZUYuizeQg9uVcgVguYvzyprWZj53edGSS7+iFjb+nPoPNPcdQsgh/6TKqfUoJuW2UuaQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609801168; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=wbwefy/BhjssjtVGflbA4E14tjS1/wqDgkAp2P+niA4=; b=gZKp7G2+BaO+k9qoEqhnm3O5SOPZq0GGy8nd26bTKFipgNCoiT424SawMylFgCGze+RNPWjhV9PSGIjQpZcq8vPMC3H6LQ1nRH5JG0RtjuB2jBa9QM5zXzhIzFNr6bLw7Te5c2/ORSZfDTP03PfMO4jhv+mq2J/LUNVe0WxeaSI= 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 1609801168796400.6517301571072; Mon, 4 Jan 2021 14:59:28 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61618.108505 (Exim 4.92) (envelope-from ) id 1kwYoj-00023q-MG; Mon, 04 Jan 2021 22:59:13 +0000 Received: by outflank-mailman (output) from mailman id 61618.108505; Mon, 04 Jan 2021 22:59:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYoj-00023e-GA; Mon, 04 Jan 2021 22:59:13 +0000 Received: by outflank-mailman (input) for mailman id 61618; Mon, 04 Jan 2021 22:59:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYid-0000oY-UU for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:55 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0b44001d-3b0d-4343-ad88-190b0f2e10c3; Mon, 04 Jan 2021 22:52:36 +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 104MqR80071482 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:33 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MqRWR071481; Mon, 4 Jan 2021 14:52:27 -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: 0b44001d-3b0d-4343-ad88-190b0f2e10c3 Message-Id: <73e9c064c46da42fcd6cf30372049eceb0fc404f.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: Sat, 12 Dec 2020 20:42:33 -0800 Subject: [WIP PATCH 12/16] WIP: UNTESTED: tools/xl: Replace remaining options with format() 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" 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 --- 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[] =3D "%-40n %5i %5m %5v %s %8.1t"; =20 - 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) !=3D 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 =3D 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 / 102= 4); + format(formats, " %5c", info + i); if (verbose || context) format(formats, " %16l", info + i); - if (cpupool) { - char *poolname =3D libxl_cpupoolid_to_name(ctx, info[i].cpupoo= l); - 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); } =20 =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 From nobody Sat May 4 17:19:31 2024 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=1609801172; cv=none; d=zohomail.com; s=zohoarc; b=SoqgUwT19lA0KAIxXT6ugOvvlvk7+iXeOok+dafI9BFgyRWc8dlNAlHF8IM8FjBpqqu2yHvkp06gdbCbSYGuvWmgsD7szxIX7h2H5DxCteG0NmC2FnejO87VjIn1yN5zyaSL7iV7IAUdzDdXTLWgerHaIEtO2l/+Z+pjF6SCblE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609801172; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jLiyKBtwRjmc1U6BgKJsIeAxYPOdLaKJHcMdiBQpASM=; b=Kq7NDnfvlao/OIr3cRkZ3PxbBkrJBM42TQO9j7vt89j/pSiHfCrflj0TMHzaLQgMi9kzaLSx0U2Lfs18Ghx4Y51Gor4xdu7db8CFHt/iBDu6gtoYLRS0Xh7DmdmeGj8kCWIaUnB1TTQAlP0JTL//am5ZfYp32OxNGpIjrGLtYQw= 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 1609801172343372.1871990759362; Mon, 4 Jan 2021 14:59:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61619.108517 (Exim 4.92) (envelope-from ) id 1kwYom-0002AC-VZ; Mon, 04 Jan 2021 22:59:16 +0000 Received: by outflank-mailman (output) from mailman id 61619.108517; Mon, 04 Jan 2021 22:59:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYom-00029c-Rr; Mon, 04 Jan 2021 22:59:16 +0000 Received: by outflank-mailman (input) for mailman id 61619; Mon, 04 Jan 2021 22:59:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYii-0000oY-W7 for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:53:01 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0b7b0775-55e0-45be-b93d-4e1b891f2ea5; Mon, 04 Jan 2021 22:52:43 +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 104MqYZX071498 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:40 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MqY8L071497; Mon, 4 Jan 2021 14:52:34 -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: 0b7b0775-55e0-45be-b93d-4e1b891f2ea5 Message-Id: <42879b23f2c27ca89cda333b829488f33f3659ef.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: Sat, 12 Dec 2020 21:14:26 -0800 Subject: [WIP PATCH 13/16] WIP: tools/xl: Purge list_domains() 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" Everything previously done by list_domains() is now done with build_list_domain_format() and format(). Signed-off-by: Elliott Mitchell --- 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 =3D { (int *)&_discard->domid - (int *)_discard, {.i =3D 0}}, }; =20 +static char *build_list_domain_format(bool verbose, bool context, bool cla= im, + bool numa, bool cpupool) +{ + int size =3D 4096; + char *fmt =3D malloc(size); + const char lead[] =3D "%-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); +} + =20 static void list_vm(void) { @@ -365,36 +390,6 @@ static void list_vm(void) libxl_vminfo_list_free(info, nb_vm); } =20 -static void list_domains(bool verbose, bool context, bool claim, bool numa, - bool cpupool, const libxl_dominfo *info, int nb_d= omain) -{ - int i; - const char lead[] =3D "%-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 =3D 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'); - } -} - =20 int main_list(int argc, char **argv) { @@ -470,7 +465,17 @@ int main_list(int argc, char **argv) =20 if (details) dump_by_dominfo_list(default_output_format, stdout, info, nb_domai= n); - else if (formatstr) { + else { + char *fr =3D NULL; + + if (!formatstr) formatstr =3D fr =3D build_list_domain_format(verb= ose, + context, false /* claim */, numa, cpupool); + + if (!formatstr) { + fprintf(stderr, "Memory allocation failure.\n"); + return EXIT_FAILURE; + } + format(formats, formatstr, NULL); =20 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); + } =20 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; =20 SWITCH_FOREACH_OPT(opt, "", NULL, "claims", 0) { /* No options */ @@ -521,9 +527,19 @@ int main_claims(int argc, char **argv) return 1; } =20 - list_domains(false /* verbose */, false /* context */, true /* claim *= /, - false /* numa */, false /* cpupool */, info, nb_domain); + fmt =3D 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 =3D 0; i < nb_domain; ++i) format(formats, fmt, info + i); =20 + free(fmt); libxl_dominfo_list_free(info, nb_domain); return 0; } --=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 From nobody Sat May 4 17:19:31 2024 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=1609800788; cv=none; d=zohomail.com; s=zohoarc; b=GN+1kXx/wDoaHuUlQBhxdgNcSoc5rvfj4mPLKt1JWXwsF55ZJXvMfuOwSIlV+XRHc7YxhwssM7JLMKNkocALHAfT0NnRBKUj3VqXOiUYYPHcBSbtOi9nFnVsK5A52kZ7BjQf1nKRpX1xPfJ9nbEeSQ86fb/yjcaSXdFtBHaArk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800788; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=1ZGtOI2QIaTFREv02CI2NitI0UwJmUwfOvr+i/RVzfc=; b=nds4+NTQXeAfz8jX5ReMylXYliHU1uf/S8pCAlpkLjqwPzOGwRCzQpvb3vkSnW43iOyYvwTShhMGdBTA59yRNF2OK2+nebuw0PyW5uiurSGrATbf8jHe2JuXu0iyMc4eDp0cfqswU5SN8EOSqmBbyi1lsQhS/eHX7pR+9jAwrSc= 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 1609800788307239.6892372373868; Mon, 4 Jan 2021 14:53:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61574.108456 (Exim 4.92) (envelope-from ) id 1kwYib-0001Ya-R3; Mon, 04 Jan 2021 22:52:53 +0000 Received: by outflank-mailman (output) from mailman id 61574.108456; Mon, 04 Jan 2021 22:52:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYib-0001YT-O8; Mon, 04 Jan 2021 22:52:53 +0000 Received: by outflank-mailman (input) for mailman id 61574; Mon, 04 Jan 2021 22:52:52 +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 1kwYia-0001Y4-5z for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:52 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0be40137-2e97-4a36-9886-3693e0ce814a; Mon, 04 Jan 2021 22:52:51 +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 104MqgfU071507 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:47 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MqgmL071506; Mon, 4 Jan 2021 14:52:42 -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: 0be40137-2e97-4a36-9886-3693e0ce814a Message-Id: <23d48471e5f987736525b4d2be71419953fd4698.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: Wed, 9 Dec 2020 14:34:37 -0800 Subject: [WIP PATCH 14/16] WIP: tools/xl: Enhance "list" command 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" Add several features to specify output. Allow omitting potentially unneeded lines and add argument for exact line format. Signed-off-by: Elliott Mitchell --- 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[] =3D { &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[] =3D { " %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 =3D false; bool cpupool =3D false; bool details =3D false; + bool dom0 =3D true; + bool header =3D true; const char *formatstr =3D NULL; bool numa =3D false; bool verbose =3D 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=3D0; int nb_domain, rc; =20 - SWITCH_FOREACH_OPT(opt, "F:Zchlnv", opts, "list", 0) { + SWITCH_FOREACH_OPT(opt, "0F:HZchlnv", opts, "list", 0) { + case '0': + dom0 =3D false; + break; case 'F': formatstr =3D optarg; break; + case 'H': + header =3D false; + break; case 'Z': context =3D true; break; @@ -476,10 +486,10 @@ int main_list(int argc, char **argv) return EXIT_FAILURE; } =20 - format(formats, formatstr, NULL); + if (header) format(formats, formatstr, NULL); =20 while (nb_domain) { - format(formats, formatstr, info); + if (info->domid || dom0) format(formats, formatstr, info); ++info; --nb_domain; } --=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 From nobody Sat May 4 17:19:31 2024 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=1609800793; cv=none; d=zohomail.com; s=zohoarc; b=Wi21g0vB6pjYkQ/2aOZ67i5nMsOr8KEuhC6duYW2LtukgoIBoa1tLCLGRFgvPrlFqCJg1FXghrlAzFdf0mwVt9Y1HNpPUEOoOh7hFq035KQVWIs1cN+4ILlv6WkcYrsP+E/PCQ6AnkFjAJfCxLFX8RIQvRnmOBraree23UZrGL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609800793; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=TkfyoOfadk2DGbHbjDcLQbm5PJY3tEg//RvWtvrT6cg=; b=knsUTQls5+9bcLhNNGLYCFiciqi0k13X6VLFI1f7ofG6IprEWqQiWCRiU3/t0A8yhaT7x5B+l5CYzK5fxzHg1M0iL9dJqpAQQn/bpx2BJPpKAy/LuAv+3ivZTn5pdAlvh7diyhMMfTLR5QBNKKhuXrsQhOslIDDRV5RyPlv2mSc= 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 1609800793385757.9894403863029; Mon, 4 Jan 2021 14:53:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61577.108469 (Exim 4.92) (envelope-from ) id 1kwYij-0001d0-48; Mon, 04 Jan 2021 22:53:01 +0000 Received: by outflank-mailman (output) from mailman id 61577.108469; Mon, 04 Jan 2021 22:53:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYij-0001ct-0j; Mon, 04 Jan 2021 22:53:01 +0000 Received: by outflank-mailman (input) for mailman id 61577; Mon, 04 Jan 2021 22:52:59 +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 1kwYih-0001cF-9d for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:52:59 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id fbc95469-5e97-4dbe-a668-db3856b1b067; Mon, 04 Jan 2021 22:52:58 +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 104MqnT7071512 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:52:55 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MqnL5071511; Mon, 4 Jan 2021 14:52:49 -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: fbc95469-5e97-4dbe-a668-db3856b1b067 Message-Id: In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD Date: Fri, 18 Dec 2020 23:23:36 -0800 Subject: [WIP PATCH 15/16] WIP: tools/xl: Implement output format option for "vm-list" command 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" 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 --- 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[] =3D { { "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 c= har *fmt, } =20 static const libxl_dominfo *_discard; +static const libxl_vminfo *_discard_vm; =20 const format_table_t formats =3D { ['A' - 'A'] =3D {"NODE Affinity", "", format_node}, @@ -340,6 +341,20 @@ const format_table_t formats =3D { (int *)&_discard->vcpu_online - (int *)_discard, {.i = =3D 0}}, ['x' - 'A'] =3D {"ID", "x", format_normal, (int *)&_discard->domid - (int *)_discard, {.i =3D 0}}, +}, formats_vm =3D { + ['X' - 'A'] =3D {"ID", "X", format_normal, + (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = =3D 0}}, + ['i' - 'A'] =3D {"ID", "d", format_normal, + (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = =3D 0}}, + ['n' - 'A'] =3D {" name", "s", format_allocstr, + (uint32_t *)&_discard_vm->domid - (uint32_t *)_discard_= vm, + {.xlfunc =3D libxl_domid_to_name}}, + ['o' - 'A'] =3D {"ID", "o", format_normal, + (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = =3D 0}}, + ['u' - 'A'] =3D {"UUID ", "", format_uu= id, + (char *)&_discard_vm->uuid - (char *)_discard_vm}, + ['x' - 'A'] =3D {"ID", "x", format_normal, + (int *)&_discard_vm->domid - (int *)_discard_vm, {.i = =3D 0}}, }; =20 static char *build_list_domain_format(bool verbose, bool context, bool cla= im, @@ -368,29 +383,6 @@ static char *build_list_domain_format(bool verbose, bo= ol context, bool claim, } =20 =20 -static void list_vm(void) -{ - libxl_vminfo *info; - char *domname; - int nb_vm, i; - - info =3D 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 =3D 0; i < nb_vm; i++) { - domname =3D 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) =20 int main_vm_list(int argc, char **argv) { + const char *formatstr =3D "%u %5i %n\n"; int opt; + static const struct option opts[] =3D { + {"format", 0, 0, 'F'}, + }; =20 - 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 =3D optarg; + break; + } + + info =3D libxl_list_vm(ctx, &nb_vm); + + if (!info) { + fprintf(stderr, "libxl_list_vm failed.\n"); + exit(EXIT_FAILURE); } =20 - list_vm(); + format(formats_vm, formatstr, NULL); + + for (i =3D 0; i < nb_vm; i++) + format(formats_vm, formatstr, info + i); + + libxl_vminfo_list_free(info, nb_vm); + return EXIT_SUCCESS; } =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 From nobody Sat May 4 17:19:31 2024 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=1609801169; cv=none; d=zohomail.com; s=zohoarc; b=dEem23CO88Rv2fjuz+WLWjm6t5xB5X1JN/j4KaHjbesilkk3n3TPjAoMwmn+nIx/b1H2rgfDf5qxDYCcYTm2eX/zmN92b7Doup5M0ViTYx/EyV7NtxZrNoInolvoQSA6u8cqZU8hOWJr4s6Qkec7ZXQPgvUlobS/2/SYcAqDEao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609801169; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=cbme4x48GIiIl7113/1JiJFDJaCokY0b9TUtox4Fv6E=; b=ThpIG1+m12J1Q0iNgvk+kwQME/c8wMWI1c8hqWyvCdbPxsgbP4KpdiSNECVWTRhHnwtY9VmLiyr9pc/H9OQmGDczD7+kEvVrOcCdJNkwNrIAowNPlGaPdSKs6SVG+lIpziAuowx8Te8TKs0aWmfdC4h9btCam7O19ZrIPb0wctI= 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 1609801169042379.95568572036154; Mon, 4 Jan 2021 14:59:29 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.61608.108481 (Exim 4.92) (envelope-from ) id 1kwYoh-00020p-SI; Mon, 04 Jan 2021 22:59:11 +0000 Received: by outflank-mailman (output) from mailman id 61608.108481; Mon, 04 Jan 2021 22:59:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYoh-00020i-Ni; Mon, 04 Jan 2021 22:59:11 +0000 Received: by outflank-mailman (input) for mailman id 61608; Mon, 04 Jan 2021 22:59:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwYjH-0000oY-Vq for xen-devel@lists.xenproject.org; Mon, 04 Jan 2021 22:53:36 +0000 Received: from mailhost.m5p.com (unknown [74.104.188.4]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 21118051-e2b3-41c1-a8c5-e610e60ebd68; Mon, 04 Jan 2021 22:53:05 +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 104MqumN071518 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 4 Jan 2021 17:53:02 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 104MqulQ071517; Mon, 4 Jan 2021 14:52:56 -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: 21118051-e2b3-41c1-a8c5-e610e60ebd68 Message-Id: <7335199fc01d8dc6bf524cd764ed8e9107066380.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: Sat, 19 Dec 2020 23:43:08 -0800 Subject: [WIP PATCH 16/16] WIP: tools/xl: Enhance "vm-list" command 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" Add several features to specify output. Allow omitting potentially unneeded lines and add argument for exact line format. Signed-off-by: Elliott Mitchell --- 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 =3D "%u %5i %n\n"; + bool dom0 =3D true; + bool header =3D true; int opt; static const struct option opts[] =3D { {"format", 0, 0, 'F'}, + {"no-domain0", 0, 0, '0'}, + {"no-header", 0, 0, 'H'}, }; =20 libxl_vminfo *info; int nb_vm, i; =20 - SWITCH_FOREACH_OPT(opt, "F:", opts, "vm-list", 0) { + SWITCH_FOREACH_OPT(opt, "0F:H", opts, "vm-list", 0) { + case '0': + dom0 =3D false; + break; case 'F': formatstr =3D optarg; break; + case 'H': + header =3D false; + break; } =20 info =3D libxl_list_vm(ctx, &nb_vm); @@ -521,10 +531,10 @@ int main_vm_list(int argc, char **argv) exit(EXIT_FAILURE); } =20 - format(formats_vm, formatstr, NULL); + if (header) format(formats_vm, formatstr, NULL); =20 for (i =3D 0; i < nb_vm; i++) - format(formats_vm, formatstr, info + i); + if (info[i].domid || dom0) format(formats_vm, formatstr, info + i); =20 libxl_vminfo_list_free(info, nb_vm); =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