[v4,14/39] dyndbg: update default trace destination on reopen

Message ID 20240210235009.2405808-15-ukaszb@chromium.org
State New
Headers
Series dyndbg: add support for writing debug logs to trace |

Commit Message

Łukasz Bartosik Feb. 10, 2024, 11:49 p.m. UTC
  The change updates default trace destination when a user requests
to open '0' ('0' writes debug logs to global trace-events buffer
/sys/kernel/tracing/trace) or open an already opened trace instance.

Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
 lib/dynamic_debug.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
  

Patch

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index f41b0b0c8b47..f91c51234456 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -354,10 +354,21 @@  static void update_tr_default_dst(int trace_dst)
 static int handle_trace_open_cmd(const char *arg)
 {
 	struct dd_private_tracebuf *buf;
-	int idx, ret = 0;
+	int idx = 0, ret = 0;
 
 	mutex_lock(&ddebug_lock);
 
+	/*
+	 * request to open '0' or an already opened trace instance
+	 * results in update of default trace destination
+	 */
+	if (!strcmp(arg, DD_TR_EVENT))
+		goto update;
+
+	idx = find_tr_instance(arg);
+	if (idx >= 0)
+		goto update;
+
 	/* bit 0 is not used, reserved for trace prdbg and devdbg events */
 	idx = find_next_zero_bit(trc_tbl.bmap, trc_tbl.bmap_size, 1);
 	if (idx == trc_tbl.bmap_size) {
@@ -371,12 +382,6 @@  static int handle_trace_open_cmd(const char *arg)
 		goto end;
 	}
 
-	if (find_tr_instance(arg) >= 0) {
-		pr_err("instance is already opened name:%s\n", arg);
-		ret = -EEXIST;
-		goto end;
-	}
-
 	buf = &trc_tbl.buf[idx];
 	buf->name = kstrdup(arg, GFP_KERNEL);
 	if (!buf->name) {
@@ -402,6 +407,7 @@  static int handle_trace_open_cmd(const char *arg)
 	buf->use_cnt = 0;
 	set_bit(idx, trc_tbl.bmap);
 	v3pr_info("opened trace instance idx=%d, name=%s\n", idx, arg);
+update:
 	update_tr_default_dst(idx);
 end:
 	mutex_unlock(&ddebug_lock);