Blame SOURCES/bcc-0.20.0-tools-Fix-BCC-bio-tools-with-recent-kernel-change.patch

afd259
From 59a4e7ea490f78ba289c1ba461bfe1fce9e7ef19 Mon Sep 17 00:00:00 2001
afd259
From: Hengqi Chen <chenhengqi@outlook.com>
afd259
Date: Sat, 11 Dec 2021 17:36:17 +0800
afd259
Subject: [PATCH] tools: Fix BCC bio tools with recent kernel change
afd259
afd259
Several BCC bio tools are broken due to kernel change ([0]).
afd259
blk_account_io_{start, done} were renamed to __blk_account_io_{start, done},
afd259
and the symbols gone from /proc/kallsyms. Fix them by checking symbol existence.
afd259
afd259
  [0]: https://github.com/torvalds/linux/commit/be6bfe36db1795babe9d92178a47b2e02193cb0f
afd259
afd259
Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
afd259
---
afd259
 tools/biolatency.py | 12 ++++++++----
afd259
 tools/biolatpcts.py |  5 ++++-
afd259
 tools/biosnoop.py   | 11 ++++++++---
afd259
 tools/biotop.py     | 11 ++++++++---
afd259
 4 files changed, 28 insertions(+), 11 deletions(-)
afd259
afd259
diff --git a/tools/biolatency.py b/tools/biolatency.py
afd259
index 0599609b..2e75a5de 100755
afd259
--- a/tools/biolatency.py
afd259
+++ b/tools/biolatency.py
afd259
@@ -168,13 +168,18 @@ bpf_text = bpf_text.replace("STORE", store_str)
afd259
 # load BPF program
afd259
 b = BPF(text=bpf_text)
afd259
 if args.queued:
afd259
-    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_req_start")
afd259
+    if BPF.get_kprobe_functions(b'__blk_account_io_start'):
afd259
+        b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_req_start")
afd259
+    else:
afd259
+        b.attach_kprobe(event="blk_account_io_start", fn_name="trace_req_start")
afd259
 else:
afd259
     if BPF.get_kprobe_functions(b'blk_start_request'):
afd259
         b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
afd259
     b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
afd259
-b.attach_kprobe(event="blk_account_io_done",
afd259
-    fn_name="trace_req_done")
afd259
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
afd259
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_done")
afd259
+else:
afd259
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_done")
afd259
 
afd259
 if not args.json:
afd259
     print("Tracing block device I/O... Hit Ctrl-C to end.")
afd259
@@ -277,4 +282,3 @@ dist = b.get_table("dist")
afd259
     countdown -= 1
afd259
     if exiting or countdown == 0:
afd259
         exit()
afd259
-
afd259
diff --git a/tools/biolatpcts.py b/tools/biolatpcts.py
afd259
index 5ab8aa5f..a2f59592 100755
afd259
--- a/tools/biolatpcts.py
afd259
+++ b/tools/biolatpcts.py
afd259
@@ -142,7 +142,10 @@ bpf_source = bpf_source.replace('__MAJOR__', str(major))
afd259
 bpf_source = bpf_source.replace('__MINOR__', str(minor))
afd259
 
afd259
 bpf = BPF(text=bpf_source)
afd259
-bpf.attach_kprobe(event="blk_account_io_done", fn_name="kprobe_blk_account_io_done")
afd259
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
afd259
+    bpf.attach_kprobe(event="__blk_account_io_done", fn_name="kprobe_blk_account_io_done")
afd259
+else:
afd259
+    bpf.attach_kprobe(event="blk_account_io_done", fn_name="kprobe_blk_account_io_done")
afd259
 
afd259
 # times are in usecs
afd259
 MSEC = 1000
afd259
diff --git a/tools/biosnoop.py b/tools/biosnoop.py
afd259
index 333949b5..2b954ac9 100755
afd259
--- a/tools/biosnoop.py
afd259
+++ b/tools/biosnoop.py
afd259
@@ -163,12 +163,17 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
afd259
 
afd259
 # initialize BPF
afd259
 b = BPF(text=bpf_text)
afd259
-b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
afd259
+if BPF.get_kprobe_functions(b'__blk_account_io_start'):
afd259
+    b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_pid_start")
afd259
+else:
afd259
+    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
afd259
 if BPF.get_kprobe_functions(b'blk_start_request'):
afd259
     b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
afd259
 b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
afd259
-b.attach_kprobe(event="blk_account_io_done",
afd259
-    fn_name="trace_req_completion")
afd259
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
afd259
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_completion")
afd259
+else:
afd259
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_completion")
afd259
 
afd259
 # header
afd259
 print("%-11s %-14s %-6s %-7s %-1s %-10s %-7s" % ("TIME(s)", "COMM", "PID",
afd259
diff --git a/tools/biotop.py b/tools/biotop.py
afd259
index 596f0076..0ebfef0e 100755
afd259
--- a/tools/biotop.py
afd259
+++ b/tools/biotop.py
afd259
@@ -180,12 +180,17 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
afd259
     exit()
afd259
 
afd259
 b = BPF(text=bpf_text)
afd259
-b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
afd259
+if BPF.get_kprobe_functions(b'__blk_account_io_start'):
afd259
+    b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_pid_start")
afd259
+else:
afd259
+    b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
afd259
 if BPF.get_kprobe_functions(b'blk_start_request'):
afd259
     b.attach_kprobe(event="blk_start_request", fn_name="trace_req_start")
afd259
 b.attach_kprobe(event="blk_mq_start_request", fn_name="trace_req_start")
afd259
-b.attach_kprobe(event="blk_account_io_done",
afd259
-    fn_name="trace_req_completion")
afd259
+if BPF.get_kprobe_functions(b'__blk_account_io_done'):
afd259
+    b.attach_kprobe(event="__blk_account_io_done", fn_name="trace_req_completion")
afd259
+else:
afd259
+    b.attach_kprobe(event="blk_account_io_done", fn_name="trace_req_completion")
afd259
 
afd259
 print('Tracing... Output every %d secs. Hit Ctrl-C to end' % interval)
afd259
 
afd259
-- 
afd259
2.35.1
afd259