| 1 | #include <sys/types.h> |
| 2 | #include <unistd.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <sys/ioctl.h> |
| 5 | #include <string.h> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include "blktrace_api.h" |
| 9 | |
| 10 | int start(int fd) |
| 11 | { |
| 12 | struct blk_user_trace_setup buts; |
| 13 | |
| 14 | memset(&buts, 0, sizeof(buts)); |
| 15 | // buts.buf_size = 512*1024; |
| 16 | // buts.buf_nr = 4; |
| 17 | // buts.act_mask = ~0; |
| 18 | |
| 19 | if (ioctl(fd, BLKTRACESETUP, &buts) < 0) { |
| 20 | perror("BLKTRACESETUP"); |
| 21 | return 1; |
| 22 | } |
| 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | int stop(int fd) |
| 28 | { |
| 29 | ioctl(fd, BLKTRACESTOP); |
| 30 | if(ioctl(fd, BLKTRACETEARDOWN) < 0) |
| 31 | perror("BLKTRACETEARDOWN"); |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | int main(int argc, char **argv) |
| 37 | { |
| 38 | int fd; |
| 39 | |
| 40 | if(argc < 3) { |
| 41 | fprintf(stderr, "usage: --start|--stop %s BLKDEV\n", argv[0]); |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | fd = open(argv[2], O_RDONLY | O_NONBLOCK); |
| 46 | if (fd < 0) { |
| 47 | perror(argv[0]); |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | if(!strcmp("--start", argv[1])) |
| 52 | start(fd); |
| 53 | else if(!strcmp("--stop", argv[1])) |
| 54 | stop(fd); |
| 55 | |
| 56 | close(fd); |
| 57 | |
| 58 | return 0; |
| 59 | } |