From nobody Tue Feb 10 01:35:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1667317438; cv=none; d=zohomail.com; s=zohoarc; b=gDtDWH5A/eWJPqmiE0wdS8LJR5Y7roFX7VgLtOyQh8SRaMoHHYK5Bh4MEWMVP7FRUj9dObghLf8h/Kj5fO4LVE19Ja12kHaze5e92reZr9Zi2mxhgfcvxH3xddXWHZdgVmPWQGElKKwpWtoLXJ//bpnbd7GsdtpgjUaPMwLEr14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667317438; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Jp/wq4hw5G22takTn0GXQsF4DTUlBtleEPwgDpe2N2w=; b=IELkXBGzb+KqaiJZGgPz/g7YqyGBEBbws67wRnnbWV7iO4Q3ONH0hUlWCVIIcZoQVW1tsbd4X5iCkIY/u78JwT4fIrBIdkCsMbvd71hXM+vZQF5bvkf0jSfTanIFYbTp85MXu3+rSl9z70WnWF/oR3Z68kbuSrthRdMcRkxOYGQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667317438972786.2073274341483; Tue, 1 Nov 2022 08:43:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.434977.687942 (Exim 4.92) (envelope-from ) id 1optQR-0003qz-6P; Tue, 01 Nov 2022 15:43:39 +0000 Received: by outflank-mailman (output) from mailman id 434977.687942; Tue, 01 Nov 2022 15:43:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1optQR-0003q9-26; Tue, 01 Nov 2022 15:43:39 +0000 Received: by outflank-mailman (input) for mailman id 434977; Tue, 01 Nov 2022 15:43: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 1optDl-0007Tl-Fd for xen-devel@lists.xenproject.org; Tue, 01 Nov 2022 15:30:33 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1f7647a8-59fa-11ed-91b5-6bf2151ebd3b; Tue, 01 Nov 2022 16:30:32 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3749F1F8CA; Tue, 1 Nov 2022 15:30:32 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E95471346F; Tue, 1 Nov 2022 15:30:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ACOxN5c7YWN8YQAAMHmgww (envelope-from ); Tue, 01 Nov 2022 15:30:31 +0000 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: 1f7647a8-59fa-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667316632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jp/wq4hw5G22takTn0GXQsF4DTUlBtleEPwgDpe2N2w=; b=VOH4FDu+f21xeut1KkronhOOj6gpTJwpJrvxdsvQ7VelIq34XFnchQYDzHiiR9tfGBrCKA f7l592e6rFlBB6FdvA+G8+BWV2JeL9CBXeYz7StmdM/p0ZnsXlJ3FT/czpyBL2JOGZ7KXY Du1EhRWa1wCxXgWt5lRNAcMKBDf2bZ4= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [PATCH 19/20] tools/xenstore: introduce trace classes Date: Tue, 1 Nov 2022 16:28:41 +0100 Message-Id: <20221101152842.4257-20-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221101152842.4257-1-jgross@suse.com> References: <20221101152842.4257-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1667317440323100011 Content-Type: text/plain; charset="utf-8" Make the xenstored internal trace configurable by adding classes which can be switched on and off independently from each other. Define the following classes: - obj: Creation and deletion of interesting "objects" (watch, transaction, connection) - io: incoming requests and outgoing responses - wrl: write limiting Per default "obj" and "io" are switched on. Entries written via trace() will always be printed (if tracing is on at all). Rename the misnamed xenstore-control commands "logfile" to "tracefile" and "log" to "trace". Add the capability to control the trace settings via the "trace" command and via a new "--trace-control" command line option. Add a missing trace_create() call for creating a transaction. Signed-off-by: Juergen Gross --- docs/misc/xenstore.txt | 18 +++++++---- tools/xenstore/xenstored_control.c | 41 +++++++++++++++++++----- tools/xenstore/xenstored_core.c | 44 +++++++++++++++++++++++--- tools/xenstore/xenstored_core.h | 6 ++++ tools/xenstore/xenstored_domain.c | 27 ++++++++-------- tools/xenstore/xenstored_transaction.c | 1 + 6 files changed, 105 insertions(+), 32 deletions(-) diff --git a/docs/misc/xenstore.txt b/docs/misc/xenstore.txt index 44428ae3a7..9db0385120 100644 --- a/docs/misc/xenstore.txt +++ b/docs/misc/xenstore.txt @@ -409,14 +409,8 @@ CONTROL |[|] error string in case of failure. -s can return "BUSY" in case of an active transaction, a retry of -s can be done in that case. - log|on - turn xenstore logging on - log|off - turn xenstore logging off - logfile| - log to specified file memreport|[] - print memory statistics to logfile (no + print memory statistics to tracefile (no specified) or to specific file print| print to syslog (xenstore runs as daemon) or @@ -432,6 +426,16 @@ CONTROL |[|] the domain quota-soft|[set ] like the "quota" command, but for soft-quota. + trace|[+|-] + without parameters: show possible trace switches + + activates trace entries for , + - deactivates trace entries for + trace|on + turn xenstore tracing on + trace|off + turn xenstore tracing off + tracefile| + trace to specified file help return list of supported commands for CONTROL =20 diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 41e6992591..0a985a1faa 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -179,9 +179,31 @@ static int do_control_check(const void *ctx, struct co= nnection *conn, return 0; } =20 -static int do_control_log(const void *ctx, struct connection *conn, - char **vec, int num) +static int do_control_trace(const void *ctx, struct connection *conn, + char **vec, int num) { + int ret; + + if (num =3D=3D 0) { + char *resp =3D talloc_asprintf(ctx, "Trace switch settings:\n"); + unsigned int idx; + bool on; + + if (!resp) + return ENOMEM; + for (idx =3D 0; trace_switches[idx]; idx++) { + on =3D trace_flags & (1u << idx); + resp =3D talloc_asprintf_append(resp, "%-8s: %s\n", + trace_switches[idx], + on ? "on" : "off"); + if (!resp) + return ENOMEM; + } + + send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); + return 0; + } + if (num !=3D 1) return EINVAL; =20 @@ -189,8 +211,11 @@ static int do_control_log(const void *ctx, struct conn= ection *conn, reopen_log(); else if (!strcmp(vec[0], "off")) close_log(); - else - return EINVAL; + else { + ret =3D set_trace_switch(vec[0]); + if (ret) + return ret; + } =20 send_ack(conn, XS_CONTROL); return 0; @@ -318,8 +343,8 @@ static int do_control_memreport(const void *ctx, struct= connection *conn, return 0; } #else -static int do_control_logfile(const void *ctx, struct connection *conn, - char **vec, int num) +static int do_control_tracefile(const void *ctx, struct connection *conn, + char **vec, int num) { if (num !=3D 1) return EINVAL; @@ -923,7 +948,7 @@ static int do_control_help(const void *, struct connect= ion *, char **, int); =20 static struct cmd_s cmds[] =3D { { "check", do_control_check, "" }, - { "log", do_control_log, "on|off" }, + { "trace", do_control_trace, "[on|off|[!]]" }, =20 #ifndef NO_LIVE_UPDATE /* @@ -949,7 +974,7 @@ static struct cmd_s cmds[] =3D { #ifdef __MINIOS__ { "memreport", do_control_memreport, "" }, #else - { "logfile", do_control_logfile, "" }, + { "tracefile", do_control_tracefile, "" }, { "memreport", do_control_memreport, "[]" }, #endif { "print", do_control_print, "" }, diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index e79d82cbff..86ef511ac0 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -85,6 +85,7 @@ static int reopen_log_pipe[2]; static int reopen_log_pipe0_pollfd_idx =3D -1; char *tracefile =3D NULL; TDB_CONTEXT *tdb_ctx =3D NULL; +unsigned int trace_flags =3D TRACE_OBJ | TRACE_IO; =20 static const char *sockmsg_string(enum xsd_sockmsg_type type); =20 @@ -139,13 +140,13 @@ static void trace_io(const struct connection *conn, time_t now; struct tm *tm; =20 - if (tracefd < 0) + if (tracefd < 0 || !(trace_flags & TRACE_IO)) return; =20 now =3D time(NULL); tm =3D localtime(&now); =20 - trace("%s %p %04d%02d%02d %02d:%02d:%02d %s (", + trace("io: %s %p %04d%02d%02d %02d:%02d:%02d %s (", out ? "OUT" : "IN", conn, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, @@ -158,12 +159,14 @@ static void trace_io(const struct connection *conn, =20 void trace_create(const void *data, const char *type) { - trace("CREATE %s %p\n", type, data); + if (trace_flags & TRACE_OBJ) + trace("obj: CREATE %s %p\n", type, data); } =20 void trace_destroy(const void *data, const char *type) { - trace("DESTROY %s %p\n", type, data); + if (trace_flags & TRACE_OBJ) + trace("obj: DESTROY %s %p\n", type, data); } =20 /** @@ -2590,6 +2593,8 @@ static void usage(void) " -N, --no-fork to request that the daemon does not fork,\n" " -P, --output-pid to request that the pid of the daemon is output= ,\n" " -T, --trace-file giving the file for logging, and\n" +" --trace-control [!] activate (no \"!\" prepended) or deacti= vate\n" +" a specific \n" " -E, --entry-nb limit the number of entries per domain,\n" " -S, --entry-size limit the size of entry per domain, and\n" " -W, --watch-nb limit the number of watches per domain,\n" @@ -2633,6 +2638,7 @@ static struct option options[] =3D { { "output-pid", 0, NULL, 'P' }, { "entry-size", 1, NULL, 'S' }, { "trace-file", 1, NULL, 'T' }, + { "trace-control", 1, NULL, 1 }, { "transaction", 1, NULL, 't' }, { "perm-nb", 1, NULL, 'A' }, { "path-max", 1, NULL, 'M' }, @@ -2707,6 +2713,33 @@ static void set_quota(const char *arg, bool soft) barf("unknown quota \"%s\"\n", arg); } =20 +/* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ +const char *trace_switches[] =3D { + "obj", "io", "wrl", + NULL +}; + +int set_trace_switch(const char *arg) +{ + bool remove =3D (arg[0] =3D=3D '!'); + unsigned int idx; + + if (remove) + arg++; + + for (idx =3D 0; trace_switches[idx]; idx++) { + if (!strcmp(arg, trace_switches[idx])) { + if (remove) + trace_flags &=3D ~(1u << idx); + else + trace_flags |=3D 1u << idx; + return 0; + } + } + + return EINVAL; +} + int main(int argc, char *argv[]) { int opt; @@ -2755,6 +2788,9 @@ int main(int argc, char *argv[]) case 'T': tracefile =3D optarg; break; + case 1: + set_trace_switch(optarg); + break; case 'I': if (optarg && !strcmp(optarg, "off")) tdb_flags =3D 0; diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 3b96ecd018..c85b15515c 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -287,6 +287,12 @@ extern char **orig_argv; =20 extern char *tracefile; extern int tracefd; +extern unsigned int trace_flags; +#define TRACE_OBJ 0x00000001 +#define TRACE_IO 0x00000002 +#define TRACE_WRL 0x00000004 +extern const char *trace_switches[]; +int set_trace_switch(const char *arg); =20 extern TDB_CONTEXT *tdb_ctx; extern int dom0_domid; diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 0bf35cd353..70d9e9572d 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -1256,6 +1256,12 @@ static long wrl_ndomains; static wrl_creditt wrl_reserve; /* [-wrl_config_newdoms_dburst, +_gburst ]= */ static time_t wrl_log_last_warning; /* 0: no previous warning */ =20 +#define trace_wrl(...) \ +do { \ + if (trace_flags & TRACE_WRL) \ + trace("wrl: " __VA_ARGS__); \ +} while (0) + void wrl_gettime_now(struct wrl_timestampt *now_wt) { struct timespec now_ts; @@ -1361,12 +1367,9 @@ void wrl_credit_update(struct domain *domain, struct= wrl_timestampt now) =20 domain->wrl_timestamp =3D now; =20 - trace("wrl: dom %4d %6ld msec %9ld credit %9ld reserve" - " %9ld discard\n", - domain->domid, - msec, - (long)domain->wrl_credit, (long)wrl_reserve, - (long)surplus); + trace_wrl("dom %4d %6ld msec %9ld credit %9ld reserve %9ld discard\n", + domain->domid, msec, (long)domain->wrl_credit, + (long)wrl_reserve, (long)surplus); } =20 void wrl_check_timeout(struct domain *domain, @@ -1398,10 +1401,9 @@ void wrl_check_timeout(struct domain *domain, if (*ptimeout=3D=3D-1 || wakeup < *ptimeout) *ptimeout =3D wakeup; =20 - trace("wrl: domain %u credit=3D%ld (reserve=3D%ld) SLEEPING for %d\n", - domain->domid, - (long)domain->wrl_credit, (long)wrl_reserve, - wakeup); + trace_wrl("domain %u credit=3D%ld (reserve=3D%ld) SLEEPING for %d\n", + domain->domid, (long)domain->wrl_credit, (long)wrl_reserve, + wakeup); } =20 #define WRL_LOG(now, ...) \ @@ -1419,9 +1421,8 @@ void wrl_apply_debit_actual(struct domain *domain) wrl_credit_update(domain, now); =20 domain->wrl_credit -=3D wrl_config_writecost; - trace("wrl: domain %u credit=3D%ld (reserve=3D%ld)\n", - domain->domid, - (long)domain->wrl_credit, (long)wrl_reserve); + trace_wrl("domain %u credit=3D%ld (reserve=3D%ld)\n", domain->domid, + (long)domain->wrl_credit, (long)wrl_reserve); =20 if (domain->wrl_credit < 0) { if (!domain->wrl_delay_logged) { diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index 82e5e66c18..1aa9d3cb3d 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -475,6 +475,7 @@ int do_transaction_start(const void *ctx, struct connec= tion *conn, if (!trans) return ENOMEM; =20 + trace_create(trans, "transaction"); INIT_LIST_HEAD(&trans->accessed); INIT_LIST_HEAD(&trans->changed_domains); trans->conn =3D conn; --=20 2.35.3