Fix compile on CentOS/RHEL5
[fio.git] / profile.c
CommitLineData
79d16311
JA
1#include "fio.h"
2#include "profile.h"
3#include "debug.h"
4#include "flist.h"
e2de69da 5#include "options.h"
79d16311
JA
6
7static FLIST_HEAD(profile_list);
8
15dc1934 9struct profile_ops *find_profile(const char *profile)
79d16311 10{
15dc1934 11 struct profile_ops *ops = NULL;
79d16311
JA
12 struct flist_head *n;
13
79d16311
JA
14 flist_for_each(n, &profile_list) {
15 ops = flist_entry(n, struct profile_ops, list);
16 if (!strcmp(profile, ops->name))
17 break;
18
19 ops = NULL;
20 }
21
15dc1934
JA
22 return ops;
23}
24
25int load_profile(const char *profile)
26{
27 struct profile_ops *ops;
28
29 dprint(FD_PROFILE, "loading profile '%s'\n", profile);
30
31 ops = find_profile(profile);
79d16311 32 if (ops) {
d4afedfd 33 if (ops->prep_cmd()) {
90777558 34 log_err("fio: profile %s prep failed\n", profile);
d4afedfd
JA
35 return 1;
36 }
46bcd498 37 add_job_opts(ops->cmdline, FIO_CLIENT_TYPE_CLI);
79d16311
JA
38 return 0;
39 }
40
41 log_err("fio: profile '%s' not found\n", profile);
42 return 1;
43}
44
07b3232d 45static int add_profile_options(struct profile_ops *ops)
e2de69da 46{
07b3232d 47 struct fio_option *o;
3c3ed070 48
e2de69da 49 if (!ops->options)
07b3232d 50 return 0;
e2de69da 51
07b3232d
JA
52 o = ops->options;
53 while (o->name) {
54 o->prof_name = ops->name;
7b504edd 55 o->prof_opts = ops->opt_data;
07b3232d
JA
56 if (add_option(o))
57 return 1;
58 o++;
e2de69da 59 }
07b3232d
JA
60
61 return 0;
e2de69da
JA
62}
63
07b3232d 64int register_profile(struct profile_ops *ops)
79d16311 65{
07b3232d
JA
66 int ret;
67
79d16311 68 dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
f5b6bb85 69
07b3232d 70 ret = add_profile_options(ops);
f5b6bb85
JA
71 if (!ret) {
72 flist_add_tail(&ops->list, &profile_list);
73 add_opt_posval("profile", ops->name, ops->desc);
74 return 0;
75 }
07b3232d 76
f5b6bb85 77 invalidate_profile_options(ops->name);
07b3232d 78 return ret;
79d16311
JA
79}
80
81void unregister_profile(struct profile_ops *ops)
82{
83 dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
84 flist_del(&ops->list);
07b3232d 85 invalidate_profile_options(ops->name);
f5b6bb85 86 del_opt_posval("profile", ops->name);
79d16311 87}
15dc1934
JA
88
89void profile_add_hooks(struct thread_data *td)
90{
91 struct profile_ops *ops;
92
93 if (!exec_profile)
94 return;
95
96 ops = find_profile(exec_profile);
97 if (!ops)
98 return;
99
d72be545 100 if (ops->io_ops) {
7eb36574 101 td->prof_io_ops = *ops->io_ops;
d72be545
JA
102 td->flags |= TD_F_PROFILE_OPS;
103 }
15dc1934 104}
58c55ba0
JA
105
106int profile_td_init(struct thread_data *td)
107{
108 struct prof_io_ops *ops = &td->prof_io_ops;
109
110 if (ops->td_init)
111 return ops->td_init(td);
112
113 return 0;
114}
115
116void profile_td_exit(struct thread_data *td)
117{
118 struct prof_io_ops *ops = &td->prof_io_ops;
119
120 if (ops->td_exit)
121 ops->td_exit(td);
122}