From 599e72b74ed2c44fd846b95160c5037c16438994 Mon Sep 17 00:00:00 2001 From: Zhu Yanhai Date: Tue, 22 Nov 2011 09:35:29 +0100 Subject: [PATCH 1/1] Use the reentrant getmntent_r instead of getmntent The function find_cgroup_mnt() could be called under multithread scenario, so we should use the reentrant edition getmntent_r() instead of getmntent(). E.g, without this fix the output for below job file is wrong. [root@localhost blkio-test]# cat small-read-file [global] ioengine=sync direct=1 rw=read bs=4k filename=/dev/sdb time_based runtime=60 cgroup=small cgroup_weight=500 numjobs=32 group_reporting thread [file1] Then fio randomly says: [cut here] Starting 32 threads fio: cgroup blkio does not appear to be mounted fio: cgroup blkio does not appear to be mounted fio: cgroup blkio does not appear to be mounted Signed-off-by: Jens Axboe --- cgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cgroup.c b/cgroup.c index f36683ae..de00d986 100644 --- a/cgroup.c +++ b/cgroup.c @@ -22,7 +22,8 @@ struct cgroup_member { static char *find_cgroup_mnt(struct thread_data *td) { char *mntpoint = NULL; - struct mntent *mnt; + struct mntent *mnt, dummy; + char buf[256] = {0}; FILE *f; f = setmntent("/proc/mounts", "r"); @@ -31,7 +32,7 @@ static char *find_cgroup_mnt(struct thread_data *td) return NULL; } - while ((mnt = getmntent(f)) != NULL) { + while ((mnt = getmntent_r(f, &dummy, buf, sizeof(buf))) != NULL) { if (!strcmp(mnt->mnt_type, "cgroup") && strstr(mnt->mnt_opts, "blkio")) break; -- 2.25.1