Blame SOURCES/bcc-0.24.0-biolatency-biolatpcts-biosnoop-biotop-Build-fix-for-.patch

ddf812
From 879792d2d47c1308e884fb59d92fe535f7bb8d71 Mon Sep 17 00:00:00 2001
ddf812
From: Tejun Heo <tj@kernel.org>
ddf812
Date: Thu, 10 Mar 2022 08:37:21 -1000
ddf812
Subject: [PATCH 1/2] biolatency, biolatpcts, biosnoop, biotop: Build fix for
ddf812
 v5.17+
ddf812
ddf812
During 5.17 dev cycle, the kernel dropped request->rq_disk. It can now be
ddf812
accessed through request->q->disk. Fix the python ones in tools/. There are
ddf812
more usages in other places which need to be fixed too.
ddf812
ddf812
Signed-off-by: Tejun Heo <tj@kernel.org>
ddf812
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
ddf812
---
ddf812
 tools/biolatency.py |  8 ++++++--
ddf812
 tools/biolatpcts.py | 11 ++++++++---
ddf812
 tools/biosnoop.py   |  6 +++++-
ddf812
 tools/biotop.py     |  9 +++++++--
ddf812
 4 files changed, 26 insertions(+), 8 deletions(-)
ddf812
ddf812
diff --git a/tools/biolatency.py b/tools/biolatency.py
ddf812
index 427cee47..10c852ac 100755
ddf812
--- a/tools/biolatency.py
ddf812
+++ b/tools/biolatency.py
ddf812
@@ -128,12 +128,16 @@ storage_str = ""
ddf812
 store_str = ""
ddf812
 if args.disks:
ddf812
     storage_str += "BPF_HISTOGRAM(dist, disk_key_t);"
ddf812
-    store_str += """
ddf812
+    disks_str = """
ddf812
     disk_key_t key = {.slot = bpf_log2l(delta)};
ddf812
-    void *__tmp = (void *)req->rq_disk->disk_name;
ddf812
+    void *__tmp = (void *)req->__RQ_DISK__->disk_name;
ddf812
     bpf_probe_read(&key.disk, sizeof(key.disk), __tmp);
ddf812
     dist.atomic_increment(key);
ddf812
     """
ddf812
+    if BPF.kernel_struct_has_field(b'request', b'rq_disk'):
ddf812
+        store_str += disks_str.replace('__RQ_DISK__', 'rq_disk')
ddf812
+    else:
ddf812
+        store_str += disks_str.replace('__RQ_DISK__', 'q->disk')
ddf812
 elif args.flags:
ddf812
     storage_str += "BPF_HISTOGRAM(dist, flag_key_t);"
ddf812
     store_str += """
ddf812
diff --git a/tools/biolatpcts.py b/tools/biolatpcts.py
ddf812
index 0f334419..ea8b1ce6 100755
ddf812
--- a/tools/biolatpcts.py
ddf812
+++ b/tools/biolatpcts.py
ddf812
@@ -72,9 +72,9 @@ void kprobe_blk_account_io_done(struct pt_regs *ctx, struct request *rq, u64 now
ddf812
         if (!rq->__START_TIME_FIELD__)
ddf812
                 return;
ddf812
 
ddf812
-        if (!rq->rq_disk ||
ddf812
-            rq->rq_disk->major != __MAJOR__ ||
ddf812
-            rq->rq_disk->first_minor != __MINOR__)
ddf812
+        if (!rq->__RQ_DISK__ ||
ddf812
+            rq->__RQ_DISK__->major != __MAJOR__ ||
ddf812
+            rq->__RQ_DISK__->first_minor != __MINOR__)
ddf812
                 return;
ddf812
 
ddf812
         cmd_flags = rq->cmd_flags;
ddf812
@@ -142,6 +142,11 @@ bpf_source = bpf_source.replace('__START_TIME_FIELD__', start_time_field)
ddf812
 bpf_source = bpf_source.replace('__MAJOR__', str(major))
ddf812
 bpf_source = bpf_source.replace('__MINOR__', str(minor))
ddf812
 
ddf812
+if BPF.kernel_struct_has_field(b'request', b'rq_disk'):
ddf812
+    bpf_source = bpf_source.replace('__RQ_DISK__', 'rq_disk')
ddf812
+else:
ddf812
+    bpf_source = bpf_source.replace('__RQ_DISK__', 'q->disk')
ddf812
+
ddf812
 bpf = BPF(text=bpf_source)
ddf812
 if BPF.get_kprobe_functions(b'__blk_account_io_done'):
ddf812
     bpf.attach_kprobe(event="__blk_account_io_done", fn_name="kprobe_blk_account_io_done")
ddf812
diff --git a/tools/biosnoop.py b/tools/biosnoop.py
ddf812
index ae38e384..a2b636aa 100755
ddf812
--- a/tools/biosnoop.py
ddf812
+++ b/tools/biosnoop.py
ddf812
@@ -125,7 +125,7 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
ddf812
         data.pid = valp->pid;
ddf812
         data.sector = req->__sector;
ddf812
         bpf_probe_read_kernel(&data.name, sizeof(data.name), valp->name);
ddf812
-        struct gendisk *rq_disk = req->rq_disk;
ddf812
+        struct gendisk *rq_disk = req->__RQ_DISK__;
ddf812
         bpf_probe_read_kernel(&data.disk_name, sizeof(data.disk_name),
ddf812
                        rq_disk->disk_name);
ddf812
     }
ddf812
@@ -156,6 +156,10 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
ddf812
     bpf_text = bpf_text.replace('##QUEUE##', '1')
ddf812
 else:
ddf812
     bpf_text = bpf_text.replace('##QUEUE##', '0')
ddf812
+if BPF.kernel_struct_has_field(b'request', b'rq_disk'):
ddf812
+    bpf_text = bpf_text.replace('__RQ_DISK__', 'rq_disk')
ddf812
+else:
ddf812
+    bpf_text = bpf_text.replace('__RQ_DISK__', 'q->disk')
ddf812
 if debug or args.ebpf:
ddf812
     print(bpf_text)
ddf812
     if args.ebpf:
ddf812
diff --git a/tools/biotop.py b/tools/biotop.py
ddf812
index b3e3ea00..882835f6 100755
ddf812
--- a/tools/biotop.py
ddf812
+++ b/tools/biotop.py
ddf812
@@ -129,8 +129,8 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
ddf812
 
ddf812
     // setup info_t key
ddf812
     struct info_t info = {};
ddf812
-    info.major = req->rq_disk->major;
ddf812
-    info.minor = req->rq_disk->first_minor;
ddf812
+    info.major = req->__RQ_DISK__->major;
ddf812
+    info.minor = req->__RQ_DISK__->first_minor;
ddf812
 /*
ddf812
  * The following deals with a kernel version change (in mainline 4.7, although
ddf812
  * it may be backported to earlier kernels) with how block request write flags
ddf812
@@ -174,6 +174,11 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
ddf812
     print(bpf_text)
ddf812
     exit()
ddf812
 
ddf812
+if BPF.kernel_struct_has_field(b'request', b'rq_disk'):
ddf812
+    bpf_text = bpf_text.replace('__RQ_DISK__', 'rq_disk')
ddf812
+else:
ddf812
+    bpf_text = bpf_text.replace('__RQ_DISK__', 'q->disk')
ddf812
+
ddf812
 b = BPF(text=bpf_text)
ddf812
 if BPF.get_kprobe_functions(b'__blk_account_io_start'):
ddf812
     b.attach_kprobe(event="__blk_account_io_start", fn_name="trace_pid_start")
ddf812
-- 
ddf812
2.35.1
ddf812