From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Monakhov Subject: [PATCH 2/8] xfstests: add different logging option to fsstress Date: Sat, 29 Oct 2011 04:48:11 +0400 Message-ID: <1319849297-3506-3-git-send-email-dmonakhov@openvz.org> References: <1319849297-3506-1-git-send-email-dmonakhov@openvz.org> Cc: xfs@oss.sgi.com, hch@lst.de, aelder@sgi.com, Dmitry Monakhov To: linux-fsdevel@vger.kernel.org Return-path: Received: from mail-bw0-f46.google.com ([209.85.214.46]:37588 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756010Ab1J2Asd (ORCPT ); Fri, 28 Oct 2011 20:48:33 -0400 Received: by mail-bw0-f46.google.com with SMTP id zt4so871791bkb.19 for ; Fri, 28 Oct 2011 17:48:32 -0700 (PDT) In-Reply-To: <1319849297-3506-1-git-send-email-dmonakhov@openvz.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Currently the only way to log fsstress's output is to redirect it's shared stdout to pipe which is very painfull because: 1) Pipe writers are serialized via i_mutex so we waste cpu-cores power on stupid sinchronization for loging purpose, instead of hunting real race conditions, and bugs inside file system. 2) Usually output is corrupted due to luck of sychronization on shared stdout. Since fsstress's children operate on independend paths, let's just open didicated log file for each child and simply avoid useless sycnhronization. Reviewed-by: Christoph Hellwig Signed-off-by: Dmitry Monakhov --- ltp/fsstress.c | 33 ++++++++++++++++++++++++++++++++- 1 files changed, 32 insertions(+), 1 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 51ecda2..c7001f3 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -258,6 +258,8 @@ int main(int argc, char **argv) char buf[10]; int c; char *dirname = NULL; + char *logname = NULL; + char rpath[PATH_MAX]; int fd; int i; int j; @@ -273,7 +275,7 @@ int main(int argc, char **argv) nops = sizeof(ops) / sizeof(ops[0]); ops_end = &ops[nops]; myprog = argv[0]; - while ((c = getopt(argc, argv, "d:e:f:i:m:n:p:rs:vwzHS")) != -1) { + while ((c = getopt(argc, argv, "d:e:f:i:m:n:o:p:rs:vwzHS")) != -1) { switch (c) { case 'd': dirname = optarg; @@ -311,6 +313,10 @@ int main(int argc, char **argv) case 'n': operations = atoi(optarg); break; + case 'o': + logname = optarg; + break; + case 'p': nproc = atoi(optarg); break; @@ -351,10 +357,26 @@ int main(int argc, char **argv) } (void)mkdir(dirname, 0777); + if (logname && logname[0] != '/') { + if (getcwd(rpath, sizeof(rpath)) < 0){ + perror("getcwd failed"); + exit(1); + } + } else { + rpath[0] = '\0'; + } if (chdir(dirname) < 0) { perror(dirname); exit(1); } + if (logname) { + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/%s", rpath, logname); + if (freopen(path, "a", stdout) == NULL) { + perror("freopen logfile failed"); + exit(1); + } + } sprintf(buf, "fss%x", (unsigned int)getpid()); fd = creat(buf, 0666); if (lseek64(fd, (off64_t)(MAXFSIZE32 + 1ULL), SEEK_SET) < 0) @@ -409,6 +431,15 @@ int main(int argc, char **argv) close(fd); for (i = 0; i < nproc; i++) { if (fork() == 0) { + if (logname) { + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/%s.%d", + rpath, logname, i); + if (freopen(path, "a", stdout) == NULL) { + perror("freopen logfile failed"); + exit(1); + } + } procid = i; doproc(); return 0; -- 1.7.1