Fix compilation without cgroups
[fio.git] / verify-state.h
CommitLineData
9e9d41d7
JA
1#ifndef FIO_VERIFY_STATE_H
2#define FIO_VERIFY_STATE_H
3
4#include <stdint.h>
e139c0c0 5#include <string.h>
a86f6d07 6#include <limits.h>
734f7d02 7#include "lib/nowarn_snprintf.h"
9e9d41d7
JA
8
9struct thread_rand32_state {
10 uint32_t s[4];
11};
12
13struct thread_rand64_state {
14 uint64_t s[6];
15};
16
17struct thread_rand_state {
18 uint64_t use64;
19 union {
20 struct thread_rand32_state state32;
21 struct thread_rand64_state state64;
22 };
23};
24
25/*
26 * For dumping current write state
27 */
94a6e1bb
JA
28struct file_comp {
29 uint64_t fileno;
30 uint64_t offset;
9e9d41d7
JA
31};
32
94a6e1bb 33struct thread_io_list {
9e9d41d7 34 uint64_t no_comps;
94a6e1bb
JA
35 uint32_t depth;
36 uint32_t nofiles;
9e9d41d7
JA
37 uint64_t numberio;
38 uint64_t index;
94a6e1bb 39 struct thread_rand_state rand;
9e9d41d7 40 uint8_t name[64];
94a6e1bb 41 struct file_comp comps[0];
9e9d41d7
JA
42};
43
44struct all_io_list {
45 uint64_t threads;
46 struct thread_io_list state[0];
47};
48
94a6e1bb 49#define VSTATE_HDR_VERSION 0x03
9e9d41d7
JA
50
51struct verify_state_hdr {
52 uint64_t version;
53 uint64_t size;
54 uint64_t crc;
55};
56
57#define IO_LIST_ALL 0xffffffff
58
17d4fb1d 59struct io_u;
9e9d41d7
JA
60extern struct all_io_list *get_all_io_list(int, size_t *);
61extern void __verify_save_state(struct all_io_list *, const char *);
62extern void verify_save_state(int mask);
63extern int verify_load_state(struct thread_data *, const char *);
64extern void verify_free_state(struct thread_data *);
65extern int verify_state_should_stop(struct thread_data *, struct io_u *);
94a6e1bb
JA
66extern void verify_assign_state(struct thread_data *, void *);
67extern int verify_state_hdr(struct verify_state_hdr *, struct thread_io_list *);
9e9d41d7 68
94a6e1bb 69static inline size_t __thread_io_list_sz(uint32_t depth, uint32_t nofiles)
9e9d41d7 70{
94a6e1bb 71 return sizeof(struct thread_io_list) + depth * nofiles * sizeof(struct file_comp);
9e9d41d7
JA
72}
73
74static inline size_t thread_io_list_sz(struct thread_io_list *s)
75{
94a6e1bb 76 return __thread_io_list_sz(le32_to_cpu(s->depth), le32_to_cpu(s->nofiles));
9e9d41d7
JA
77}
78
79static inline struct thread_io_list *io_list_next(struct thread_io_list *s)
80{
d637b8b8 81 return (struct thread_io_list *)((char *) s + thread_io_list_sz(s));
9e9d41d7
JA
82}
83
84static inline void verify_state_gen_name(char *out, size_t size,
85 const char *name, const char *prefix,
86 int num)
87{
f5d1c719 88 char ename[PATH_MAX];
e139c0c0
JA
89 char *ptr;
90
e139c0c0
JA
91 /*
92 * Escape '/', just turn them into '.'
93 */
f5d1c719 94 ptr = ename;
5c8f0ba5
JA
95 do {
96 *ptr = *name;
e139c0c0
JA
97 if (*ptr == '\0')
98 break;
5c8f0ba5
JA
99 else if (*ptr == '/')
100 *ptr = '.';
101 ptr++;
102 name++;
103 } while (1);
f5d1c719 104
b4d2bc70 105 nowarn_snprintf(out, size, "%s-%s-%d-verify.state", prefix, ename, num);
f5d1c719 106 out[size - 1] = '\0';
9e9d41d7
JA
107}
108
109#endif