summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2009-12-07 08:01:26 +0100
committerJens Axboe <jens.axboe@oracle.com>2009-12-07 08:01:26 +0100
commit6adb38a1a1cbe95f7131815416c8bb31683c3f47 (patch)
tree8ea9e7f59890e868e78f23c46725da4af0c41f36
parented81ee199ec8f3cdfcdc78ff067a0397c3b02f5f (diff)
downloadfio-6adb38a1a1cbe95f7131815416c8bb31683c3f47.tar.gz
fio-6adb38a1a1cbe95f7131815416c8bb31683c3f47.tar.bz2
Autodetect cgroup blkio mount point
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r--HOWTO13
-rw-r--r--cgroup.c69
-rw-r--r--cgroup.h9
-rw-r--r--fio.114
-rw-r--r--fio.c7
-rw-r--r--fio.h1
-rw-r--r--options.c7
7 files changed, 61 insertions, 59 deletions
diff --git a/HOWTO b/HOWTO
index 7a7d14ea..0b40f758 100644
--- a/HOWTO
+++ b/HOWTO
@@ -1004,18 +1004,13 @@ continue_on_error=bool Normally fio will exit the job on the first observed
given in the stats is the first error that was hit during the
run.
-cgroup_root=str Root of the mounted blkio cgroup file systems. This is a Linux
- specific IO controller. If your system doesn't have it mounted,
- you can do so with:
+cgroup=str Add job to this control group. If it doesn't exist, it will
+ be created. The system must have a mounted cgroup blkio
+ mount point for this to work. If your system doesn't have it
+ mounted, you can do so with:
# mount -t cgroup -o blkio none /cgroup
- The cgroup_root defaults to /cgroup, if mounted elsewhere
- please specify this option.
-
-cgroup=str Add job to this control group. If it doesn't exist, it will
- be created.
-
cgroup_weight=int Set the weight of the cgroup to this value. See
the documentation that comes with the kernel, allowed values
are in the range of 100..1000.
diff --git a/cgroup.c b/cgroup.c
index 29d89dd3..14bbc57b 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -3,6 +3,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
+#include <mntent.h>
#include "fio.h"
#include "flist.h"
#include "cgroup.h"
@@ -15,6 +16,33 @@ struct cgroup_member {
char *root;
};
+static char *find_cgroup_mnt(struct thread_data *td)
+{
+ char *mntpoint = NULL;
+ struct mntent *mnt;
+ FILE *f;
+
+ f = setmntent("/proc/mounts", "r");
+ if (!f) {
+ td_verror(td, errno, "setmntent /proc/mounts");
+ return NULL;
+ }
+
+ while ((mnt = getmntent(f)) != NULL) {
+ if (!strcmp(mnt->mnt_type, "cgroup") &&
+ strstr(mnt->mnt_opts, "blkio"))
+ break;
+ }
+
+ if (mnt)
+ mntpoint = smalloc_strdup(mnt->mnt_dir);
+ else
+ log_err("fio: cgroup blkio does not appear to be mounted\n");
+
+ endmntent(f);
+ return mntpoint;
+}
+
static void add_cgroup(const char *name, struct flist_head *clist)
{
struct cgroup_member *cm;
@@ -46,26 +74,14 @@ void cgroup_kill(struct flist_head *clist)
fio_mutex_up(lock);
}
-/*
- * Check if the given root appears valid
- */
-static int cgroup_check_fs(struct thread_data *td)
-{
- struct stat sb;
- char tmp[256];
-
- sprintf(tmp, "%s/tasks", td->o.cgroup_root);
- return stat(tmp, &sb);
-}
-
-static char *get_cgroup_root(struct thread_data *td)
+static char *get_cgroup_root(struct thread_data *td, char *mnt)
{
char *str = malloc(64);
if (td->o.cgroup)
- sprintf(str, "%s/%s", td->o.cgroup_root, td->o.cgroup);
+ sprintf(str, "%s/%s", mnt, td->o.cgroup);
else
- sprintf(str, "%s/%s", td->o.cgroup_root, td->o.name);
+ sprintf(str, "%s/%s", mnt, td->o.name);
return str;
}
@@ -100,30 +116,31 @@ static int cgroup_write_pid(struct thread_data *td, const char *root)
/*
* Move pid to root class
*/
-static int cgroup_del_pid(struct thread_data *td)
+static int cgroup_del_pid(struct thread_data *td, char *mnt)
{
- return cgroup_write_pid(td, td->o.cgroup_root);
+ return cgroup_write_pid(td, mnt);
}
-int cgroup_setup(struct thread_data *td, struct flist_head *clist)
+int cgroup_setup(struct thread_data *td, struct flist_head *clist, char **mnt)
{
char *root;
- if (cgroup_check_fs(td)) {
- log_err("fio: blkio cgroup mount point %s not valid\n",
- td->o.cgroup_root);
- return 1;
+ if (!*mnt) {
+ *mnt = find_cgroup_mnt(td);
+ if (!*mnt)
+ return 1;
}
/*
* Create container, if it doesn't exist
*/
- root = get_cgroup_root(td);
+ root = get_cgroup_root(td, *mnt);
if (mkdir(root, 0755) < 0) {
int __e = errno;
if (__e != EEXIST) {
td_verror(td, __e, "cgroup mkdir");
+ log_err("fio: path %s\n", root);
goto err;
}
} else
@@ -146,14 +163,14 @@ err:
return 1;
}
-void cgroup_shutdown(struct thread_data *td)
+void cgroup_shutdown(struct thread_data *td, char **mnt)
{
- if (cgroup_check_fs(td))
+ if (*mnt == NULL)
return;
if (!td->o.cgroup_weight && !td->o.cgroup)
return;
- cgroup_del_pid(td);
+ cgroup_del_pid(td, *mnt);
}
static void fio_init cgroup_init(void)
diff --git a/cgroup.h b/cgroup.h
index b246ef86..f7ad210d 100644
--- a/cgroup.h
+++ b/cgroup.h
@@ -3,20 +3,21 @@
#ifdef FIO_HAVE_CGROUPS
-int cgroup_setup(struct thread_data *td, struct flist_head *list);
-void cgroup_shutdown(struct thread_data *td);
+int cgroup_setup(struct thread_data *, struct flist_head *, char **);
+void cgroup_shutdown(struct thread_data *, char **);
void cgroup_kill(struct flist_head *list);
#else
-static inline int cgroup_setup(struct thread_data *td, struct flist_head *list);
+static inline int cgroup_setup(struct thread_data *td, struct flist_head *list,
+ char **mnt)
{
td_verror(td, EINVAL, "cgroup_setup");
return 1;
}
-static inline void cgroup_shutdown(struct thread_data *td)
+static inline void cgroup_shutdown(struct thread_data *td, char **mnt)
{
}
diff --git a/fio.1 b/fio.1
index 648b4e9c..2e0a283d 100644
--- a/fio.1
+++ b/fio.1
@@ -725,18 +725,12 @@ entering the kernel with a gettimeofday() call. The CPU set aside for doing
these time calls will be excluded from other uses. Fio will manually clear it
from the CPU mask of other jobs.
.TP
-.BI cgroup_root \fR=\fPstr
-Root of the mounted blkio cgroup file systems. This is a Linux
-specific IO controller. If your system doesn't have it mounted,
-you can do so with:
-
-# mount -t cgroup -o blkio none /cgroup
-
-The cgroup_root defaults to /cgroup, if mounted elsewhere please specify this
-option.
-.TP
.BI cgroup \fR=\fPstr
Add job to this control group. If it doesn't exist, it will be created.
+The system must have a mounted cgroup blkio mount point for this to work. If
+your system doesn't have it mounted, you can do so with:
+
+# mount -t cgroup -o blkio none /cgroup
.TP
.BI cgroup_weight \fR=\fPint
Set the weight of the cgroup to this value. See the documentation that comes
diff --git a/fio.c b/fio.c
index bcc130bb..7d4c96a2 100644
--- a/fio.c
+++ b/fio.c
@@ -62,6 +62,7 @@ static int exit_value;
static struct itimerval itimer;
static pthread_t gtod_thread;
static struct flist_head *cgroup_list;
+static char *cgroup_mnt;
struct io_log *agg_io_log[2];
@@ -1077,7 +1078,7 @@ static void *thread_main(void *data)
}
}
- if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list))
+ if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt))
goto err;
if (nice(td->o.nice) == -1) {
@@ -1209,7 +1210,7 @@ err:
close_and_free_files(td);
close_ioengine(td);
cleanup_io_u(td);
- cgroup_shutdown(td);
+ cgroup_shutdown(td, &cgroup_mnt);
if (td->o.cpumask_set) {
int ret = fio_cpuset_exit(&td->o.cpumask);
@@ -1674,6 +1675,8 @@ int main(int argc, char *argv[])
cgroup_kill(cgroup_list);
sfree(cgroup_list);
+ if (cgroup_mnt)
+ sfree(cgroup_mnt);
fio_mutex_remove(startup_mutex);
fio_mutex_remove(writeout_mutex);
diff --git a/fio.h b/fio.h
index 17aeaada..b1af7b1b 100644
--- a/fio.h
+++ b/fio.h
@@ -275,7 +275,6 @@ struct thread_options {
/*
* blkio cgroup support
*/
- char *cgroup_root;
char *cgroup;
unsigned int cgroup_weight;
};
diff --git a/options.c b/options.c
index 77cfd424..16908a07 100644
--- a/options.c
+++ b/options.c
@@ -1727,13 +1727,6 @@ static struct fio_option options[] = {
.help = "Select a specific builtin performance test",
},
{
- .name = "cgroup_root",
- .type = FIO_OPT_STR_STORE,
- .off1 = td_var_offset(cgroup_root),
- .help = "Root of mounted blkio cgroup",
- .def = "/cgroup",
- },
- {
.name = "cgroup",
.type = FIO_OPT_STR_STORE,
.off1 = td_var_offset(cgroup),