Add initial support for profile specific options
[fio.git] / profile.c
1 #include "fio.h"
2 #include "profile.h"
3 #include "debug.h"
4 #include "flist.h"
5 #include "options.h"
6
7 static FLIST_HEAD(profile_list);
8
9 int 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) {
25                 add_job_opts(ops->def_ops);
26                 return 0;
27         }
28
29         log_err("fio: profile '%s' not found\n", profile);
30         return 1;
31 }
32
33 static void add_profile_options(struct profile_ops *ops)
34 {
35         struct fio_option *fo;
36         struct ext_option *eo;
37         
38         if (!ops->options)
39                 return;
40
41         fo = ops->options;
42         while (fo->name) {
43                 eo = malloc(sizeof(*eo));
44                 eo->prof_name = ops->name;
45                 memcpy(&eo->o, fo, sizeof(*fo));
46                 register_ext_option(eo);
47                 fo++;
48         }
49 }
50
51 void register_profile(struct profile_ops *ops)
52 {
53         dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
54         flist_add_tail(&ops->list, &profile_list);
55         add_profile_options(ops);
56 }
57
58 void unregister_profile(struct profile_ops *ops)
59 {
60         dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
61         flist_del(&ops->list);
62         prune_profile_options(ops->name);
63 }