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