+static void add_cgroup(struct thread_data *td, const char *name,
+ struct flist_head *clist)
+{
+ struct cgroup_member *cm;
+
+ if (!lock)
+ return;
+
+ cm = smalloc(sizeof(*cm));
+ if (!cm) {
+err:
+ log_err("fio: failed to allocate cgroup member\n");
+ return;
+ }
+
+ INIT_FLIST_HEAD(&cm->list);
+ cm->root = smalloc_strdup(name);
+ if (!cm->root) {
+ sfree(cm);
+ goto err;
+ }
+ if (td->o.cgroup_nodelete)
+ cm->cgroup_nodelete = 1;
+ fio_mutex_down(lock);
+ flist_add_tail(&cm->list, clist);
+ fio_mutex_up(lock);
+}
+
+void cgroup_kill(struct flist_head *clist)
+{
+ struct flist_head *n, *tmp;
+ struct cgroup_member *cm;
+
+ if (!lock)
+ return;
+
+ fio_mutex_down(lock);
+
+ flist_for_each_safe(n, tmp, clist) {
+ cm = flist_entry(n, struct cgroup_member, list);
+ if (!cm->cgroup_nodelete)
+ rmdir(cm->root);
+ flist_del(&cm->list);
+ sfree(cm->root);
+ sfree(cm);
+ }
+
+ fio_mutex_up(lock);
+}
+
+static char *get_cgroup_root(struct thread_data *td, char *mnt)