Cleanup profile support
[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
9int load_profile(const char *profile)
10{
11 struct profile_ops *ops;
12 struct flist_head *n;
13
14 dprint(FD_PROFILE, "loading profile '%s'\n", profile);
15
16 flist_for_each(n, &profile_list) {
17 ops = flist_entry(n, struct profile_ops, list);
18 if (!strcmp(profile, ops->name))
19 break;
20
21 ops = NULL;
22 }
23
24 if (ops) {
2363d8df
JA
25 ops->prep_cmd();
26 add_job_opts(ops->cmdline);
79d16311
JA
27 return 0;
28 }
29
30 log_err("fio: profile '%s' not found\n", profile);
31 return 1;
32}
33
07b3232d 34static int add_profile_options(struct profile_ops *ops)
e2de69da 35{
07b3232d 36 struct fio_option *o;
e2de69da
JA
37
38 if (!ops->options)
07b3232d 39 return 0;
e2de69da 40
07b3232d
JA
41 o = ops->options;
42 while (o->name) {
43 o->prof_name = ops->name;
44 if (add_option(o))
45 return 1;
46 o++;
e2de69da 47 }
07b3232d
JA
48
49 return 0;
e2de69da
JA
50}
51
07b3232d 52int register_profile(struct profile_ops *ops)
79d16311 53{
07b3232d
JA
54 int ret;
55
79d16311
JA
56 dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
57 flist_add_tail(&ops->list, &profile_list);
07b3232d
JA
58 ret = add_profile_options(ops);
59 if (ret)
60 invalidate_profile_options(ops->name);
61
62 return ret;
79d16311
JA
63}
64
65void unregister_profile(struct profile_ops *ops)
66{
67 dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
68 flist_del(&ops->list);
07b3232d 69 invalidate_profile_options(ops->name);
79d16311 70}