Skip to content

Commit

Permalink
libbpf-tools: Fix bio tools
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
chenhengqi authored and yonghong-song committed Jun 13, 2022
1 parent 5e3d41e commit a184f09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libbpf-tools/biosnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
start_ts = e->ts;
blk_fill_rwbs(rwbs, e->cmd_flags);
partition = partitions__get_by_dev(partitions, e->dev);
printf("%-11.6f %-14.14s %-6d %-7s %-4s %-10lld %-7d ",
printf("%-11.6f %-14.14s %-7d %-7s %-4s %-10lld %-7d ",
(e->ts - start_ts) / 1000000000.0,
e->comm, e->pid, partition ? partition->name : "Unknown", rwbs,
e->sector, e->len);
Expand Down Expand Up @@ -230,6 +230,13 @@ int main(int argc, char **argv)
obj->rodata->targ_queued = env.queued;
obj->rodata->filter_cg = env.cg;

if (fentry_can_attach("blk_account_io_start", NULL))
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"blk_account_io_start");
else
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"__blk_account_io_start");

err = biosnoop_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object: %d\n", err);
Expand Down Expand Up @@ -304,7 +311,7 @@ int main(int argc, char **argv)
goto cleanup;
}

printf("%-11s %-14s %-6s %-7s %-4s %-10s %-7s ",
printf("%-11s %-14s %-7s %-7s %-4s %-10s %-7s ",
"TIME(s)", "COMM", "PID", "DISK", "T", "SECTOR", "BYTES");
if (env.queued)
printf("%7s ", "QUE(ms)");
Expand Down
12 changes: 12 additions & 0 deletions libbpf-tools/biostacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ int main(int argc, char **argv)

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

if (fentry_can_attach("blk_account_io_start", NULL)) {
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"blk_account_io_start");
bpf_program__set_attach_target(obj->progs.blk_account_io_done, 0,
"blk_account_io_done");
} else {
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"__blk_account_io_start");
bpf_program__set_attach_target(obj->progs.blk_account_io_done, 0,
"__blk_account_io_done");
}

err = biostacks_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object: %d\n", err);
Expand Down

0 comments on commit a184f09

Please sign in to comment.