From: Jens Axboe <axboe@kernel.dk>
To: Zhu Yanhai <zhu.yanhai@gmail.com>
Cc: fio@vger.kernel.org, Zhu Yanhai <gaoyang.zyh@taobao.com>
Subject: Re: [PATCH] Use the reentrant getmntent_r instead of getmntent
Date: Tue, 22 Nov 2011 09:35:51 +0100 [thread overview]
Message-ID: <4ECB5EE7.7020804@kernel.dk> (raw)
In-Reply-To: <1321945003-14786-1-git-send-email-gaoyang.zyh@taobao.com>
On 2011-11-22 07:56, Zhu Yanhai wrote:
> 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
> ---
> cgroup.c | 5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/cgroup.c b/cgroup.c
> index f36683a..4f02ecd 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, 256)) != NULL) {
> if (!strcmp(mnt->mnt_type, "cgroup") &&
> strstr(mnt->mnt_opts, "blkio"))
> break;
Thanks applied, with a small change to use sizeof(buf) instead of 256 in
both places.
--
Jens Axboe
prev parent reply other threads:[~2011-11-22 8:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-22 6:56 [PATCH] Use the reentrant getmntent_r instead of getmntent Zhu Yanhai
2011-11-22 8:35 ` Jens Axboe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ECB5EE7.7020804@kernel.dk \
--to=axboe@kernel.dk \
--cc=fio@vger.kernel.org \
--cc=gaoyang.zyh@taobao.com \
--cc=zhu.yanhai@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox