2 * Code related to setting up a blkio cgroup
10 * Check if the given root appears valid
12 static int cgroup_check_fs(struct thread_data *td)
17 sprintf(tmp, "%s/tasks", td->o.cgroup_root);
18 return stat(tmp, &sb);
21 static char *get_cgroup_root(struct thread_data *td)
23 char *str = malloc(64);
26 sprintf(str, "%s/%s", td->o.cgroup_root, td->o.cgroup);
28 sprintf(str, "%s/%s", td->o.cgroup_root, td->o.name);
34 * Add pid to given class
36 static int cgroup_add_pid(struct thread_data *td)
41 root = get_cgroup_root(td);
42 sprintf(tmp, "%s/tasks", root);
46 td_verror(td, errno, "cgroup open tasks");
50 fprintf(f, "%d", td->pid);
57 * Move pid to root class
59 static int cgroup_del_pid(struct thread_data *td)
64 sprintf(tmp, "%s/tasks", td->o.cgroup_root);
67 td_verror(td, errno, "cgroup open tasks");
71 fprintf(f, "%d", td->pid);
77 int cgroup_setup(struct thread_data *td)
82 if (cgroup_check_fs(td)) {
83 log_err("fio: blkio cgroup mount point %s not valid\n",
89 * Create container, if it doesn't exist
91 root = get_cgroup_root(td);
92 if (mkdir(root, 0755) < 0) {
96 td_verror(td, __e, "cgroup mkdir");
100 td->o.cgroup_was_created = 1;
102 sprintf(tmp, "%s/blkio.weight", root);
105 td_verror(td, errno, "cgroup open weight");
109 fprintf(f, "%d", td->o.cgroup_weight);
113 if (cgroup_add_pid(td))
119 void cgroup_shutdown(struct thread_data *td)
121 if (cgroup_check_fs(td))
123 if (!td->o.cgroup_weight)
128 if (td->o.cgroup_was_created) {
131 root = get_cgroup_root(td);