From nobody Sat May 4 01:34:03 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640620609365737.0226210870971; Mon, 27 Dec 2021 07:56:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.252003.432990 (Exim 4.92) (envelope-from ) id 1n1sME-0008GP-Us; Mon, 27 Dec 2021 15:56:18 +0000 Received: by outflank-mailman (output) from mailman id 252003.432990; Mon, 27 Dec 2021 15:56:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sME-0008GG-Rg; Mon, 27 Dec 2021 15:56:18 +0000 Received: by outflank-mailman (input) for mailman id 252003; Mon, 27 Dec 2021 15:56:17 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMD-0007zI-75 for xen-devel@lists.xenproject.org; Mon, 27 Dec 2021 15:56:17 +0000 Received: from mailhost.m5p.com (mailhost.m5p.com [74.104.188.4]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 854ba648-672d-11ec-9e60-abaf8a552007; Mon, 27 Dec 2021 16:56:15 +0100 (CET) Received: from m5p.com (mailhost.m5p.com [IPv6:2001:470:1f07:15ff:0:0:0:f7]) by mailhost.m5p.com (8.16.1/8.15.2) with ESMTPS id 1BRFu4kE054486 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 27 Dec 2021 10:56:10 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.16.1/8.15.2/Submit) id 1BRFu42s054485; Mon, 27 Dec 2021 07:56: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: 854ba648-672d-11ec-9e60-abaf8a552007 Message-Id: <80dd561339dbe54f1ed2c2302ace389e87d445fe.1640590794.git.ehem+xen@m5p.com> In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Wei Liu Cc: Anthony PERARD Cc: Juergen Gross Date: Fri, 18 Dec 2020 13:37:44 -0800 Subject: [PATCH 1/5] tools/libxl: Mark pointer args of many functions constant X-Spam-Status: No, score=2.5 required=10.0 tests=DATE_IN_PAST_96_XX, KHOP_HELO_FCRDNS autolearn=no autolearn_force=no version=3.4.5 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on mattapan.m5p.com X-ZM-MESSAGEID: 1640620614667000001 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 Reviewed-by: Luca Fancellu --- 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 e1acf6648d..b076d7f4a3 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 86556b6113..da2dbd67ad 100644 --- a/tools/libs/light/libxl_internal.c +++ b/tools/libs/light/libxl_internal.c @@ -333,7 +333,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 @@ -345,7 +345,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 37d5c27756..117a98acab 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -2080,9 +2080,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 @@ -4580,7 +4580,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; } @@ -4675,22 +4675,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 { @@ -4821,12 +4821,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 0630959e76..f40a004e95 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; } @@ -41,7 +41,7 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, b= ool 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 2.30.2 From nobody Sat May 4 01:34:03 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640620610877346.3154812391781; Mon, 27 Dec 2021 07:56:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.252004.433001 (Exim 4.92) (envelope-from ) id 1n1sMP-0000CF-7S; Mon, 27 Dec 2021 15:56:29 +0000 Received: by outflank-mailman (output) from mailman id 252004.433001; Mon, 27 Dec 2021 15:56:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMP-0000C8-3s; Mon, 27 Dec 2021 15:56:29 +0000 Received: by outflank-mailman (input) for mailman id 252004; Mon, 27 Dec 2021 15:56:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMN-0000AO-Vz for xen-devel@lists.xenproject.org; Mon, 27 Dec 2021 15:56:27 +0000 Received: from mailhost.m5p.com (mailhost.m5p.com [74.104.188.4]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b18dd06-672d-11ec-bb0b-79c175774b5d; Mon, 27 Dec 2021 16:56:26 +0100 (CET) Received: from m5p.com (mailhost.m5p.com [IPv6:2001:470:1f07:15ff:0:0:0:f7]) by mailhost.m5p.com (8.16.1/8.15.2) with ESMTPS id 1BRFuFg7054491 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 27 Dec 2021 10:56:21 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.16.1/8.15.2/Submit) id 1BRFuFLH054490; Mon, 27 Dec 2021 07:56:15 -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: 8b18dd06-672d-11ec-bb0b-79c175774b5d Message-Id: <26c5803fdb59bd0bd06f2509097d5929dd4f67f2.1640590794.git.ehem+xen@m5p.com> In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Wei Liu Cc: Anthony PERARD Date: Fri, 18 Dec 2020 13:32:33 -0800 Subject: [PATCH 2/5] tools/xl: Mark libxl_domain_config * arg of printf_info_*() const X-Spam-Status: No, score=2.5 required=10.0 tests=DATE_IN_PAST_96_XX, KHOP_HELO_FCRDNS autolearn=no autolearn_force=no version=3.4.5 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on mattapan.m5p.com X-ZM-MESSAGEID: 1640620612302000003 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 Reviewed-by: Luca Fancellu --- 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 c5c4bedbdd..720adb0048 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -300,7 +300,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 712b7638b0..23d82ce2a2 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 2.30.2 From nobody Sat May 4 01:34:03 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640620624269781.577718147806; Mon, 27 Dec 2021 07:57:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.252010.433023 (Exim 4.92) (envelope-from ) id 1n1sMY-00014e-TA; Mon, 27 Dec 2021 15:56:38 +0000 Received: by outflank-mailman (output) from mailman id 252010.433023; Mon, 27 Dec 2021 15:56:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMY-00014U-PX; Mon, 27 Dec 2021 15:56:38 +0000 Received: by outflank-mailman (input) for mailman id 252010; Mon, 27 Dec 2021 15:56:37 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMX-0007zI-Ea for xen-devel@lists.xenproject.org; Mon, 27 Dec 2021 15:56:37 +0000 Received: from mailhost.m5p.com (mailhost.m5p.com [74.104.188.4]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9163f135-672d-11ec-9e60-abaf8a552007; Mon, 27 Dec 2021 16:56:36 +0100 (CET) Received: from m5p.com (mailhost.m5p.com [IPv6:2001:470:1f07:15ff:0:0:0:f7]) by mailhost.m5p.com (8.16.1/8.15.2) with ESMTPS id 1BRFuO2j054498 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 27 Dec 2021 10:56:32 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.16.1/8.15.2/Submit) id 1BRFuOhH054497; Mon, 27 Dec 2021 07:56:24 -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: 9163f135-672d-11ec-9e60-abaf8a552007 Message-Id: In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Wei Liu Cc: Anthony PERARD Date: Thu, 17 Dec 2020 17:42:42 -0800 Subject: [PATCH 3/5] tools/xl: Rename printf_info()/list_domains_details() to dump_by_...() X-Spam-Status: No, score=2.5 required=10.0 tests=DATE_IN_PAST_96_XX, KHOP_HELO_FCRDNS autolearn=no autolearn_force=no version=3.4.5 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on mattapan.m5p.com X-ZM-MESSAGEID: 1640620624974000001 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 Reviewed-by: Luca Fancellu --- 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 720adb0048..be5f4e11fe 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -300,6 +300,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 23d82ce2a2..3647468420 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); @@ -442,7 +440,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 @@ -453,7 +454,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"); @@ -472,16 +473,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; @@ -490,11 +491,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, @@ -571,7 +573,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 2.30.2 From nobody Sat May 4 01:34:03 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640620630381432.2618679349324; Mon, 27 Dec 2021 07:57:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.252017.433034 (Exim 4.92) (envelope-from ) id 1n1sMj-0001nz-5B; Mon, 27 Dec 2021 15:56:49 +0000 Received: by outflank-mailman (output) from mailman id 252017.433034; Mon, 27 Dec 2021 15:56:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMj-0001nm-1O; Mon, 27 Dec 2021 15:56:49 +0000 Received: by outflank-mailman (input) for mailman id 252017; Mon, 27 Dec 2021 15:56:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMh-0007zI-48 for xen-devel@lists.xenproject.org; Mon, 27 Dec 2021 15:56:47 +0000 Received: from mailhost.m5p.com (mailhost.m5p.com [74.104.188.4]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 973dfb0a-672d-11ec-9e60-abaf8a552007; Mon, 27 Dec 2021 16:56:46 +0100 (CET) Received: from m5p.com (mailhost.m5p.com [IPv6:2001:470:1f07:15ff:0:0:0:f7]) by mailhost.m5p.com (8.16.1/8.15.2) with ESMTPS id 1BRFuaGj054512 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 27 Dec 2021 10:56:42 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.16.1/8.15.2/Submit) id 1BRFuaVn054511; Mon, 27 Dec 2021 07:56:36 -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: 973dfb0a-672d-11ec-9e60-abaf8a552007 Message-Id: <8f95e4a6664a24fd990cbb8162a1855c95cb6b66.1640590794.git.ehem+xen@m5p.com> In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Wei Liu Cc: Anthony PERARD Date: Thu, 17 Dec 2020 17:42:42 -0800 Subject: [PATCH 4/5] tools/xl: Merge down debug/dry-run section of create_domain() X-Spam-Status: No, score=2.5 required=10.0 tests=DATE_IN_PAST_96_XX, KHOP_HELO_FCRDNS autolearn=no autolearn_force=no version=3.4.5 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on mattapan.m5p.com X-ZM-MESSAGEID: 1640620630614000001 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 Reviewed-by: Luca Fancellu --- 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 2.30.2 From nobody Sat May 4 01:34:03 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1640620639515717.3520141393305; Mon, 27 Dec 2021 07:57:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.252022.433045 (Exim 4.92) (envelope-from ) id 1n1sMr-0002SR-HD; Mon, 27 Dec 2021 15:56:57 +0000 Received: by outflank-mailman (output) from mailman id 252022.433045; Mon, 27 Dec 2021 15:56:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMr-0002S4-BZ; Mon, 27 Dec 2021 15:56:57 +0000 Received: by outflank-mailman (input) for mailman id 252022; Mon, 27 Dec 2021 15:56:56 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n1sMq-0000AO-L3 for xen-devel@lists.xenproject.org; Mon, 27 Dec 2021 15:56:56 +0000 Received: from mailhost.m5p.com (mailhost.m5p.com [74.104.188.4]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9d13fa6c-672d-11ec-bb0b-79c175774b5d; Mon, 27 Dec 2021 16:56:55 +0100 (CET) Received: from m5p.com (mailhost.m5p.com [IPv6:2001:470:1f07:15ff:0:0:0:f7]) by mailhost.m5p.com (8.16.1/8.15.2) with ESMTPS id 1BRFujqi054523 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 27 Dec 2021 10:56:52 -0500 (EST) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.16.1/8.15.2/Submit) id 1BRFujIk054522; Mon, 27 Dec 2021 07:56:45 -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: 9d13fa6c-672d-11ec-bb0b-79c175774b5d Message-Id: <2d1335a4056558d172d9aa3e59982eb761647418.1640590794.git.ehem+xen@m5p.com> In-Reply-To: References: From: Elliott Mitchell To: xen-devel@lists.xenproject.org Cc: Wei Liu Cc: Anthony PERARD Date: Thu, 10 Dec 2020 15:09:06 -0800 Subject: [PATCH 5/5] tools/xl: Fix potential deallocation bug X-Spam-Status: No, score=2.5 required=10.0 tests=DATE_IN_PAST_96_XX, KHOP_HELO_FCRDNS autolearn=no autolearn_force=no version=3.4.5 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on mattapan.m5p.com X-ZM-MESSAGEID: 1640620640166000001 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 Reviewed-by: Luca Fancellu --- tools/xl/xl_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c index 3647468420..938f06f1a8 100644 --- a/tools/xl/xl_info.c +++ b/tools/xl/xl_info.c @@ -579,7 +579,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 2.30.2