Skip to content

Commit a184f09

Browse files
chenhengqiyonghong-song
authored andcommitted
libbpf-tools: Fix bio tools
The tools biosnoop and biostacks are broken due to kernel change ([0]). blk_account_io_{start, done} were renamed to __blk_account_io_{start, done}, and the symbols gone from vmlinux BTF. Fix them by checking symbol existence. [0]: torvalds/linux@be6bfe3 Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
1 parent 5e3d41e commit a184f09

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

libbpf-tools/biosnoop.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
167167
start_ts = e->ts;
168168
blk_fill_rwbs(rwbs, e->cmd_flags);
169169
partition = partitions__get_by_dev(partitions, e->dev);
170-
printf("%-11.6f %-14.14s %-6d %-7s %-4s %-10lld %-7d ",
170+
printf("%-11.6f %-14.14s %-7d %-7s %-4s %-10lld %-7d ",
171171
(e->ts - start_ts) / 1000000000.0,
172172
e->comm, e->pid, partition ? partition->name : "Unknown", rwbs,
173173
e->sector, e->len);
@@ -230,6 +230,13 @@ int main(int argc, char **argv)
230230
obj->rodata->targ_queued = env.queued;
231231
obj->rodata->filter_cg = env.cg;
232232

233+
if (fentry_can_attach("blk_account_io_start", NULL))
234+
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
235+
"blk_account_io_start");
236+
else
237+
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
238+
"__blk_account_io_start");
239+
233240
err = biosnoop_bpf__load(obj);
234241
if (err) {
235242
fprintf(stderr, "failed to load BPF object: %d\n", err);
@@ -304,7 +311,7 @@ int main(int argc, char **argv)
304311
goto cleanup;
305312
}
306313

307-
printf("%-11s %-14s %-6s %-7s %-4s %-10s %-7s ",
314+
printf("%-11s %-14s %-7s %-7s %-4s %-10s %-7s ",
308315
"TIME(s)", "COMM", "PID", "DISK", "T", "SECTOR", "BYTES");
309316
if (env.queued)
310317
printf("%7s ", "QUE(ms)");

libbpf-tools/biostacks.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ int main(int argc, char **argv)
173173

174174
obj->rodata->targ_ms = env.milliseconds;
175175

176+
if (fentry_can_attach("blk_account_io_start", NULL)) {
177+
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
178+
"blk_account_io_start");
179+
bpf_program__set_attach_target(obj->progs.blk_account_io_done, 0,
180+
"blk_account_io_done");
181+
} else {
182+
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
183+
"__blk_account_io_start");
184+
bpf_program__set_attach_target(obj->progs.blk_account_io_done, 0,
185+
"__blk_account_io_done");
186+
}
187+
176188
err = biostacks_bpf__load(obj);
177189
if (err) {
178190
fprintf(stderr, "failed to load BPF object: %d\n", err);

0 commit comments

Comments
 (0)