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 | ||
ac141834 JA |
22 | printf("Thread:\t\t%u\n", no_s); |
23 | printf("Name:\t\t%s\n", s->name); | |
24 | printf("Completions:\t%llu\n", (unsigned long long) s->no_comps); | |
25 | printf("Depth:\t\t%llu\n", (unsigned long long) s->depth); | |
0e0d9a3a | 26 | printf("Max completions per file:\t\t%lu\n", (unsigned long) s->max_no_comps_per_file); |
ac141834 JA |
27 | printf("Number IOs:\t%llu\n", (unsigned long long) s->numberio); |
28 | printf("Index:\t\t%llu\n", (unsigned long long) s->index); | |
98996ef9 JA |
29 | |
30 | printf("Completions:\n"); | |
eeea64a6 JA |
31 | if (!s->no_comps) |
32 | return; | |
33 | for (i = s->no_comps - 1; i >= 0; i--) { | |
94a6e1bb JA |
34 | printf("\t(file=%2llu) %llu\n", |
35 | (unsigned long long) s->comps[i].fileno, | |
36 | (unsigned long long) s->comps[i].offset); | |
37 | } | |
38 | } | |
39 | ||
40 | static void show(struct thread_io_list *s, size_t size) | |
41 | { | |
42 | int no_s; | |
43 | ||
44 | no_s = 0; | |
45 | do { | |
46 | int i; | |
47 | ||
48 | s->no_comps = le64_to_cpu(s->no_comps); | |
49 | s->depth = le32_to_cpu(s->depth); | |
0e0d9a3a | 50 | s->max_no_comps_per_file = le32_to_cpu(s->max_no_comps_per_file); |
94a6e1bb JA |
51 | s->nofiles = le32_to_cpu(s->nofiles); |
52 | s->numberio = le64_to_cpu(s->numberio); | |
53 | s->index = le64_to_cpu(s->index); | |
54 | ||
55 | for (i = 0; i < s->no_comps; i++) { | |
56 | s->comps[i].fileno = le64_to_cpu(s->comps[i].fileno); | |
57 | s->comps[i].offset = le64_to_cpu(s->comps[i].offset); | |
58 | } | |
59 | ||
60 | show_s(s, no_s); | |
61 | no_s++; | |
0e0d9a3a | 62 | size -= __thread_io_list_sz(s->max_no_comps_per_file, s->nofiles); |
d637b8b8 | 63 | s = (struct thread_io_list *)((char *) s + |
0e0d9a3a | 64 | __thread_io_list_sz(s->max_no_comps_per_file, s->nofiles)); |
94a6e1bb | 65 | } while (size != 0); |
98996ef9 JA |
66 | } |
67 | ||
68 | static void show_verify_state(void *buf, size_t size) | |
69 | { | |
70 | struct verify_state_hdr *hdr = buf; | |
71 | struct thread_io_list *s; | |
72 | uint32_t crc; | |
98996ef9 JA |
73 | |
74 | hdr->version = le64_to_cpu(hdr->version); | |
75 | hdr->size = le64_to_cpu(hdr->size); | |
76 | hdr->crc = le64_to_cpu(hdr->crc); | |
77 | ||
ac141834 JA |
78 | printf("Version:\t0x%x\n", (unsigned int) hdr->version); |
79 | printf("Size:\t\t%u\n", (unsigned int) hdr->size); | |
80 | printf("CRC:\t\t0x%x\n", (unsigned int) hdr->crc); | |
98996ef9 JA |
81 | |
82 | size -= sizeof(*hdr); | |
83 | if (hdr->size != size) { | |
84 | log_err("Size mismatch\n"); | |
85 | return; | |
86 | } | |
87 | ||
88 | s = buf + sizeof(*hdr); | |
89 | crc = fio_crc32c((unsigned char *) s, hdr->size); | |
90 | if (crc != hdr->crc) { | |
91 | log_err("crc mismatch %x != %x\n", crc, (unsigned int) hdr->crc); | |
92 | return; | |
93 | } | |
94 | ||
0e0d9a3a | 95 | if (hdr->version == 0x04) |
94a6e1bb JA |
96 | show(s, size); |
97 | else | |
98 | log_err("Unsupported version %d\n", (int) hdr->version); | |
98996ef9 JA |
99 | } |
100 | ||
b06370ef | 101 | static int show_file(const char *file) |
98996ef9 JA |
102 | { |
103 | struct stat sb; | |
104 | void *buf; | |
105 | int ret, fd; | |
106 | ||
b06370ef | 107 | fd = open(file, O_RDONLY); |
98996ef9 | 108 | if (fd < 0) { |
b06370ef | 109 | log_err("open %s: %s\n", file, strerror(errno)); |
98996ef9 JA |
110 | return 1; |
111 | } | |
112 | ||
113 | if (fstat(fd, &sb) < 0) { | |
114 | log_err("stat: %s\n", strerror(errno)); | |
115 | close(fd); | |
116 | return 1; | |
117 | } | |
118 | ||
119 | buf = malloc(sb.st_size); | |
120 | ret = read(fd, buf, sb.st_size); | |
121 | if (ret < 0) { | |
122 | log_err("read: %s\n", strerror(errno)); | |
123 | close(fd); | |
32e7c694 | 124 | free(buf); |
98996ef9 JA |
125 | return 1; |
126 | } else if (ret != sb.st_size) { | |
127 | log_err("Short read\n"); | |
128 | close(fd); | |
32e7c694 | 129 | free(buf); |
98996ef9 JA |
130 | return 1; |
131 | } | |
132 | ||
133 | close(fd); | |
134 | show_verify_state(buf, sb.st_size); | |
135 | ||
136 | free(buf); | |
137 | return 0; | |
138 | } | |
b06370ef JA |
139 | |
140 | int main(int argc, char *argv[]) | |
141 | { | |
142 | int i, ret; | |
143 | ||
144 | debug_init(); | |
145 | ||
146 | if (argc < 2) { | |
147 | log_err("Usage: %s <state file>\n", argv[0]); | |
148 | return 1; | |
149 | } | |
150 | ||
151 | ret = 0; | |
152 | for (i = 1; i < argc; i++) { | |
153 | ret = show_file(argv[i]); | |
154 | if (ret) | |
155 | break; | |
156 | } | |
157 | ||
158 | return ret; | |
159 | } |