biosnoop: show partition number
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
`biosnoop-bpfcc` (as of Debian buster, package bpfcc-tools=0.8.0-4; can't get the [current upstream version biosnoop.py](https://github.com/iovisor/bcc/blob/master/tools/biosnoop.py) to compile) will only print the disk name, but not the partition number:
```
host ~ # biosnoop-bpfcc | head
TIME(s) COMM PID DISK T SECTOR BYTES LAT(ms)
0.000000000 smbd 23977 sda W 16217088 4096 0.08
0.000036000 smbd 23977 sdb W 16217088 4096 0.11
0.000306000 smbd 23977 sda W 145944280 4096 0.39
0.000315000 smbd 23977 sdb W 145944280 4096 0.39
0.000623000 smbd 23977 sdb W 145944400 4096 0.69
0.000655000 smbd 23977 sda W 145944400 4096 0.73
0.000720000 smbd 23977 sdb W 2243599032 8192 0.79
0.000729000 smbd 23977 sda W 2243599032 8192 0.81
0.001038000 smbd 23977 sdb W 2243599408 4096 1.11
```
I needed to figure out which process was accessing `/dev/sd[ab]1`, so this wasn't immediately useful. I haphazardly hacked partition number output into the code:
``` diff
host ~ # diff -u =biosnoop-bpfcc biosnoop-bpfcc
--- /usr/sbin/biosnoop-bpfcc 2019-02-04 11:10:29.000000000 +0100
+++ biosnoop-bpfcc 2021-03-10 12:46:32.225811209 +0100
@@ -35,6 +35,7 @@
u64 sector;
u64 len;
u64 ts;
+ u8 part_no;
char disk_name[DISK_NAME_LEN];
char name[TASK_COMM_LEN];
};
@@ -97,6 +98,7 @@
struct gendisk *rq_disk = req->rq_disk;
bpf_probe_read(&data.disk_name, sizeof(data.disk_name),
rq_disk->disk_name);
+ data.part_no = req->part->partno;
}
/*
@@ -139,6 +141,7 @@
("sector", ct.c_ulonglong),
("len", ct.c_ulonglong),
("ts", ct.c_ulonglong),
+ ("part_no", ct.c_uint8),
("disk_name", ct.c_char * DISK_NAME_LEN),
("name", ct.c_char * TASK_COMM_LEN)
]
@@ -178,7 +181,7 @@
print("%-14.9f %-14.14s %-6s %-7s %-2s %-9s %-7s %7.2f" % (
delta / 1000000, event.name.decode('utf-8', 'replace'), event.pid,
- event.disk_name.decode('utf-8', 'replace'), rwflg, val,
+ event.disk_name.decode('utf-8', 'replace') + str(event.part_no), rwflg, val,
event.len, float(event.delta) / 1000000))
prev_ts = event.ts
```
This worked for me:
```
host ~ # ./biosnoop-bpfcc | grep 'sd[ab]1'
45.523952000 lvs 2437 sda1 R 2048 131072 23.39
45.531841000 lvs 2437 sdb1 R 2048 131072 31.20
348.280517000 lvs 20464 sdb1 R 2048 131072 11.90
348.300381000 lvs 20464 sda1 R 2048 131072 18.11
651.168481000 lvs 4241 sda1 R 2048 131072 9.87
651.170764000 lvs 4241 sdb1 R 2048 131072 20.18
792.194199000 lvs 13309 sda1 R 2048 131072 15.38
792.211849000 lvs 13309 sdb1 R 2048 131072 32.82
874.594627000 lvs 16563 sda1 R 2048 131072 39.51
874.669798000 lvs 16563 sdb1 R 2048 131072 114.56
957.403398000 lvs 21855 sda1 R 2048 131072 12.58
957.411141000 lvs 21855 sdb1 R 2048 131072 20.15
1260.488296000 lvs 11923 sda1 R 2048 131072 9.65
1260.501561000 lvs 11923 sdb1 R 2048 131072 26.41
1563.048093000 lvs 29968 sda1 R 2048 131072 13.93
1563.083581000 lvs 29968 sdb1 R 2048 131072 49.34
1865.624004000 lvs 2918 sdb1 R 2048 131072 30.23
1865.624663000 lvs 2918 sda1 R 2048 131072 26.18
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the current upstream biosnoop.py linked in the issue and compare its event structure, partition handling, and output formatting with the provided diff. Run biosnoop-bpfcc against partitioned devices and verify that the displayed disk names include the partition number, such as sda1 and sdb1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, linux, python
- Domain
- observability, operating-systems
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100