Commit | Line | Data |
---|---|---|
98996ef9 JA |
1 | /* |
2 | * Dump the contents of a verify state file in plain text | |
3 | */ | |
4 | #include <sys/types.h> | |
5 | #include <sys/stat.h> | |
6 | #include <stdio.h> | |
7 | #include <stdlib.h> | |
8 | #include <unistd.h> | |
9 | #include <errno.h> | |
10 | #include <fcntl.h> | |
11 | #include <string.h> | |
12 | #include "../log.h" | |
13 | #include "../os/os.h" | |
14 | #include "../verify-state.h" | |
15 | #include "../crc/crc32c.h" | |
16 | #include "debug.h" | |
17 | ||
18 | static void show_s(struct thread_io_list *s, unsigned int no_s) | |
19 | { | |
20 | int i; | |
21 | ||
22 | printf("Thread %u, %s\n", no_s, s->name); | |
23 | printf("Completions: %lu\n", s->no_comps); | |
24 | printf("Depth: %lu\n", s->depth); | |
25 | printf("Number IOs: %lu\n", s->numberio); | |
26 | printf("Index: %lu\n", s->index); | |
27 | ||
28 | printf("Completions:\n"); | |
29 | for (i = 0; i < s->no_comps; i++) | |
30 | printf("\t%lu\n", s->offsets[i]); | |
31 | } | |
32 | ||
33 | static void show_verify_state(void *buf, size_t size) | |
34 | { | |
35 | struct verify_state_hdr *hdr = buf; | |
36 | struct thread_io_list *s; | |
37 | uint32_t crc; | |
38 | int no_s; | |
39 | ||
40 | hdr->version = le64_to_cpu(hdr->version); | |
41 | hdr->size = le64_to_cpu(hdr->size); | |
42 | hdr->crc = le64_to_cpu(hdr->crc); | |
43 | ||
44 | printf("Version: %x, Size %u, crc %x\n", (unsigned int) hdr->version, | |
45 | (unsigned int) hdr->size, | |
46 | (unsigned int) hdr->crc); | |
47 | ||
48 | size -= sizeof(*hdr); | |
49 | if (hdr->size != size) { | |
50 | log_err("Size mismatch\n"); | |
51 | return; | |
52 | } | |
53 | ||
54 | s = buf + sizeof(*hdr); | |
55 | crc = fio_crc32c((unsigned char *) s, hdr->size); | |
56 | if (crc != hdr->crc) { | |
57 | log_err("crc mismatch %x != %x\n", crc, (unsigned int) hdr->crc); | |
58 | return; | |
59 | } | |
60 | ||
61 | if (hdr->version != 0x02) { | |
62 | log_err("Can only handle version 2 headers\n"); | |
63 | return; | |
64 | } | |
65 | ||
66 | no_s = 0; | |
67 | do { | |
68 | int i; | |
69 | ||
70 | s->no_comps = le64_to_cpu(s->no_comps); | |
71 | s->depth = le64_to_cpu(s->depth); | |
72 | s->numberio = le64_to_cpu(s->numberio); | |
73 | s->index = le64_to_cpu(s->index); | |
74 | ||
75 | for (i = 0; i < s->no_comps; i++) | |
76 | s->offsets[i] = le64_to_cpu(s->offsets[i]); | |
77 | ||
78 | show_s(s, no_s); | |
79 | no_s++; | |
80 | size -= __thread_io_list_sz(s->depth); | |
81 | s = (void *) s + __thread_io_list_sz(s->depth); | |
82 | } while (size != 0); | |
83 | } | |
84 | ||
85 | int main(int argc, char *argv[]) | |
86 | { | |
87 | struct stat sb; | |
88 | void *buf; | |
89 | int ret, fd; | |
90 | ||
91 | debug_init(); | |
92 | ||
93 | if (argc < 2) { | |
94 | log_err("Usage: %s <state file>\n", argv[0]); | |
95 | return 1; | |
96 | } | |
97 | ||
98 | fd = open(argv[1], O_RDONLY); | |
99 | if (fd < 0) { | |
100 | log_err("open %s: %s\n", argv[1], strerror(errno)); | |
101 | return 1; | |
102 | } | |
103 | ||
104 | if (fstat(fd, &sb) < 0) { | |
105 | log_err("stat: %s\n", strerror(errno)); | |
106 | close(fd); | |
107 | return 1; | |
108 | } | |
109 | ||
110 | buf = malloc(sb.st_size); | |
111 | ret = read(fd, buf, sb.st_size); | |
112 | if (ret < 0) { | |
113 | log_err("read: %s\n", strerror(errno)); | |
114 | close(fd); | |
115 | return 1; | |
116 | } else if (ret != sb.st_size) { | |
117 | log_err("Short read\n"); | |
118 | close(fd); | |
119 | return 1; | |
120 | } | |
121 | ||
122 | close(fd); | |
123 | show_verify_state(buf, sb.st_size); | |
124 | ||
125 | free(buf); | |
126 | return 0; | |
127 | } |