libbpf-tools: fix for block io tracepoints changed
authorHengqi Chen <chenhengqi@outlook.com>
Sat, 20 Mar 2021 04:18:35 +0000 (12:18 +0800)
committeryonghong-song <ys114321@gmail.com>
Tue, 6 Apr 2021 03:41:56 +0000 (20:41 -0700)
Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
libbpf-tools/biosnoop.bpf.c
libbpf-tools/bitesize.bpf.c

index cd0fa0e592cd7e8ce94fd6c99fbb4cc79645d01f..766979672e5169682c9c1bfe0cde90fea5210588 100644 (file)
@@ -11,6 +11,8 @@
 const volatile bool targ_queued = false;
 const volatile dev_t targ_dev = -1;
 
+extern __u32 LINUX_KERNEL_VERSION __kconfig;
+
 struct piddata {
        char comm[TASK_COMM_LEN];
        u32 pid;
@@ -93,15 +95,31 @@ int trace_rq_start(struct request *rq, bool insert)
 }
 
 SEC("tp_btf/block_rq_insert")
-int BPF_PROG(block_rq_insert, struct request_queue *q, struct request *rq)
+int BPF_PROG(block_rq_insert)
 {
-       return trace_rq_start(rq, true);
+       /**
+        * commit a54895fa (v5.11-rc1) changed tracepoint argument list
+        * from TP_PROTO(struct request_queue *q, struct request *rq)
+        * to TP_PROTO(struct request *rq)
+        */
+       if (LINUX_KERNEL_VERSION > KERNEL_VERSION(5, 10, 0))
+               return trace_rq_start((void *)ctx[0], true);
+       else
+               return trace_rq_start((void *)ctx[1], true);
 }
 
 SEC("tp_btf/block_rq_issue")
-int BPF_PROG(block_rq_issue, struct request_queue *q, struct request *rq)
+int BPF_PROG(block_rq_issue)
 {
-       return trace_rq_start(rq, false);
+       /**
+        * commit a54895fa (v5.11-rc1) changed tracepoint argument list
+        * from TP_PROTO(struct request_queue *q, struct request *rq)
+        * to TP_PROTO(struct request *rq)
+        */
+       if (LINUX_KERNEL_VERSION > KERNEL_VERSION(5, 10, 0))
+               return trace_rq_start((void *)ctx[0], false);
+       else
+               return trace_rq_start((void *)ctx[1], false);
 }
 
 SEC("tp_btf/block_rq_complete")
index c0492848ed2eeaeec266c4215a9ba69446e1c59b..7b4d3f9d74c9d10de65aa1a6e260566927c03d85 100644 (file)
@@ -10,6 +10,8 @@
 const volatile char targ_comm[TASK_COMM_LEN] = {};
 const volatile dev_t targ_dev = -1;
 
+extern __u32 LINUX_KERNEL_VERSION __kconfig;
+
 struct {
        __uint(type, BPF_MAP_TYPE_HASH);
        __uint(max_entries, 10240);
@@ -31,8 +33,7 @@ static __always_inline bool comm_allowed(const char *comm)
        return true;
 }
 
-SEC("tp_btf/block_rq_issue")
-int BPF_PROG(block_rq_issue, struct request_queue *q, struct request *rq)
+static int trace_rq_issue(struct request *rq)
 {
        struct hist_key hkey;
        struct hist *histp;
@@ -66,4 +67,18 @@ int BPF_PROG(block_rq_issue, struct request_queue *q, struct request *rq)
        return 0;
 }
 
+SEC("tp_btf/block_rq_issue")
+int BPF_PROG(block_rq_issue)
+{
+       /**
+        * commit a54895fa (v5.11-rc1) changed tracepoint argument list
+        * from TP_PROTO(struct request_queue *q, struct request *rq)
+        * to TP_PROTO(struct request *rq)
+        */
+       if (LINUX_KERNEL_VERSION > KERNEL_VERSION(5, 10, 0))
+               return trace_rq_issue((void *)ctx[0]);
+       else
+               return trace_rq_issue((void *)ctx[1]);
+}
+
 char LICENSE[] SEC("license") = "GPL";