summaryrefslogtreecommitdiff
path: root/profile.c
blob: 9f588a17bfc75e9f91db53ec1ae8a44cff02cba2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "fio.h"
#include "profile.h"
#include "debug.h"
#include "flist.h"
#include "options.h"

static FLIST_HEAD(profile_list);

int load_profile(const char *profile)
{
	struct profile_ops *ops;
	struct flist_head *n;

	dprint(FD_PROFILE, "loading profile '%s'\n", profile);

	flist_for_each(n, &profile_list) {
		ops = flist_entry(n, struct profile_ops, list);
		if (!strcmp(profile, ops->name))
			break;

		ops = NULL;
	}

	if (ops) {
		add_job_opts(ops->def_ops);
		return 0;
	}

	log_err("fio: profile '%s' not found\n", profile);
	return 1;
}

static void add_profile_options(struct profile_ops *ops)
{
	struct fio_option *fo;
	struct ext_option *eo;
	
	if (!ops->options)
		return;

	fo = ops->options;
	while (fo->name) {
		eo = malloc(sizeof(*eo));
		eo->prof_name = ops->name;
		memcpy(&eo->o, fo, sizeof(*fo));
		register_ext_option(eo);
		fo++;
	}
}

void register_profile(struct profile_ops *ops)
{
	dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
	flist_add_tail(&ops->list, &profile_list);
	add_profile_options(ops);
}

void unregister_profile(struct profile_ops *ops)
{
	dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
	flist_del(&ops->list);
	prune_profile_options(ops->name);
}