+static struct cgroup_mnt *find_cgroup_mnt(struct thread_data *td)
+{
+ struct cgroup_mnt *cgroup_mnt = NULL;
+ struct mntent *mnt, dummy;
+ char buf[256] = {0};
+ FILE *f;
+ bool cgroup2 = false;
+
+ f = setmntent("/proc/mounts", "r");
+ if (!f) {
+ td_verror(td, errno, "setmntent /proc/mounts");
+ return NULL;
+ }
+
+ while ((mnt = getmntent_r(f, &dummy, buf, sizeof(buf))) != NULL) {
+ if (!strcmp(mnt->mnt_type, "cgroup") &&
+ strstr(mnt->mnt_opts, "blkio"))
+ break;
+ if (!strcmp(mnt->mnt_type, "cgroup2")) {
+ cgroup2 = true;
+ break;
+ }
+ }
+
+ if (mnt) {
+ cgroup_mnt = smalloc(sizeof(*cgroup_mnt));
+ if (cgroup_mnt) {
+ cgroup_mnt->path = smalloc_strdup(mnt->mnt_dir);
+ if (!cgroup_mnt->path) {
+ sfree(cgroup_mnt);
+ log_err("fio: could not allocate memory\n");
+ } else {
+ cgroup_mnt->cgroup2 = cgroup2;
+ }
+ }
+ } else {
+ log_err("fio: cgroup blkio does not appear to be mounted\n");
+ }
+
+ endmntent(f);
+ return cgroup_mnt;
+}
+
+static void add_cgroup(struct thread_data *td, const char *name,
+ struct flist_head *clist)