From patchwork Thu Sep 7 07:26:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9941667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1F766038C for ; Thu, 7 Sep 2017 07:26:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9413E28533 for ; Thu, 7 Sep 2017 07:26:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88FB528536; Thu, 7 Sep 2017 07:26:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 032CC28533 for ; Thu, 7 Sep 2017 07:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752315AbdIGH0O (ORCPT ); Thu, 7 Sep 2017 03:26:14 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:38576 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752783AbdIGH0O (ORCPT ); Thu, 7 Sep 2017 03:26:14 -0400 Received: by mail-wr0-f193.google.com with SMTP id p37so1897481wrb.5 for ; Thu, 07 Sep 2017 00:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JSV0F0WuVdWTaF/p/wrNUZW8Q6obDntXMc6IQ2Uhj9Y=; b=LjBkXnpWnf7Fnz/EK4KkhBqKUWIySPgnSswaoTc/4hDqDhiO35X4zTbI0nSPJ+Y9CP AMRzR88ZQrFMpr8QVDmY8BwPIRJj3MK3vbU1BqOhSOc05SzAObHuBRqEkQi46JBP/p+B 3BK6PpjSU29efXNrjSp/ixTCJdM4idXqA12/LuE8kNjmXc3CYKIUa24tHIAfiDAZ7nth 634FF3KW1IDC2ZvkJwwWntbQ/qO0IcolL+OyZXqd6/A57ar7SohzwNektz8kk7e1wzFS 0QBo+z3dtWA6STTO6WcqO/r+WZpZKJQmm2lDa4kCKfaf2+xk5BI9Z9IiwdejIRGdpxrl aRnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JSV0F0WuVdWTaF/p/wrNUZW8Q6obDntXMc6IQ2Uhj9Y=; b=EaMY+iT3i6uZFIk8zPey5LtePk9bGcwj8VHKsRS/mYPc3l+q/ZnQE65a/Vw2ZbdRlN FooPx2DAnjbUOk+5sViWXTuFcdXgptTqmKWu53Sfvm8NvpRvFyL9IeXLEiUObSVIpWhI vGqyM1u1mx9J5LB9/DaeLz/K+udsAFiNkpUO9Omdiqkmv1Qi78RR8hTBGqQR49LdRw8s 5Uz2BbX7yozOrU89zNBajWSxK7IMuZ4/sH5eiCLxDoK8jWrmeq+744m+EvvPM09es1tF 2AGzXhRYSTU2jRrN8fMKeTEZnHwHXiQhEv9haFeUJRJkGiOt7SfLr4kl6SiK8tv4wqZF zHqQ== X-Gm-Message-State: AHPjjUgLzTrC8pMyeqhYxl3EC2Z6I/N0fqkmJ2gnQEl4DPBKViMou6dV CkiZyXOzjGBt8Q== X-Google-Smtp-Source: ADKCNb4nUdM5EW7KCIhDfvr3gbYMoXKFaHEFwdWm4nREq9eq/rxZYZ64/PDaWwCcs+F0o6BhPhqW0A== X-Received: by 10.223.164.22 with SMTP id d22mr1098550wra.7.1504769172720; Thu, 07 Sep 2017 00:26:12 -0700 (PDT) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id 61sm1394452wre.44.2017.09.07.00.26.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Sep 2017 00:26:12 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: fstests@vger.kernel.org Subject: [PATCH v4 2/5] fsx: add optional logid prefix to log messages Date: Thu, 7 Sep 2017 10:26:35 +0300 Message-Id: <1504769198-4921-3-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504769198-4921-1-git-send-email-amir73il@gmail.com> References: <1504769198-4921-1-git-send-email-amir73il@gmail.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When redirecting the intermixed output of several fsx processes to a single output file, it is usefull to prefix debug log messages with a log id. Use fsx -j to define the log messages prefix. Fix implementation of prt() function to avoid using a temp buffer and convert some more printf() calls to use ptr() instead. Signed-off-by: Amir Goldstein --- ltp/fsx.c | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/ltp/fsx.c b/ltp/fsx.c index ac466ee..4e733f9 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -119,6 +119,7 @@ char *temp_buf; /* a pointer to the current data */ char *fname; /* name of our test file */ char *bname; /* basename of our test file */ char *logdev; /* -i flag */ +char *logid; /* -j flag */ char dname[1024]; /* -P flag */ int dirpath = 0; /* -P flag */ int fd; /* fd for our test file */ @@ -195,13 +196,16 @@ static void *round_ptr_up(void *ptr, unsigned long align, unsigned long offset) } void -vwarnc(int code, const char *fmt, va_list ap) { - fprintf(stderr, "fsx: "); - if (fmt != NULL) { - vfprintf(stderr, fmt, ap); - fprintf(stderr, ": "); - } - fprintf(stderr, "%s\n", strerror(code)); +vwarnc(int code, const char *fmt, va_list ap) +{ + if (logid) + fprintf(stderr, "%s: ", logid); + fprintf(stderr, "fsx: "); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + fprintf(stderr, "%s\n", strerror(code)); } void @@ -212,20 +216,21 @@ warn(const char * fmt, ...) { va_end(ap); } -#define BUF_SIZE 1024 - void prt(const char *fmt, ...) { va_list args; - char buffer[BUF_SIZE]; + if (logid) + fprintf(stdout, "%s: ", logid); va_start(args, fmt); - vsnprintf(buffer, BUF_SIZE, fmt, args); + vfprintf(stdout, fmt, args); va_end(args); - fprintf(stdout, "%s", buffer); - if (fsxlogf) - fprintf(fsxlogf, "%s", buffer); + if (fsxlogf) { + va_start(args, fmt); + vfprintf(fsxlogf, fmt, args); + va_end(args); + } } void @@ -1624,12 +1629,13 @@ void usage(void) { fprintf(stdout, "usage: %s", - "fsx [-dnqxAFLOWZ] [-b opnum] [-c Prob] [-i logdev] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ + "fsx [-dnqxAFLOWZ] [-b opnum] [-c Prob] [-i logdev] [-j logid] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ -b opnum: beginning operation number (default 1)\n\ -c P: 1 in P chance of file close+open at each op (default infinity)\n\ -d: debug output for all operations\n\ -f flush and invalidate cache after I/O\n\ -i logdev: do integrity testing, logdev is the dm log writes device\n\ + -j logid: prefix debug log messsages with this id\n\ -l flen: the upper bound on file size (default 262144)\n\ -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\ -n: no verifications of file size\n\ @@ -1862,14 +1868,13 @@ main(int argc, char **argv) setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */ while ((ch = getopt_long(argc, argv, - "b:c:dfi:l:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZ", + "b:c:dfi:j:l:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZ", longopts, NULL)) != EOF) switch (ch) { case 'b': simulatedopcount = getnum(optarg, &endp); if (!quiet) - fprintf(stdout, "Will begin at operation %ld\n", - simulatedopcount); + prt("Will begin at operation %ld\n", simulatedopcount); if (simulatedopcount == 0) usage(); simulatedopcount -= 1; @@ -1877,9 +1882,7 @@ main(int argc, char **argv) case 'c': closeprob = getnum(optarg, &endp); if (!quiet) - fprintf(stdout, - "Chance of close/open is 1 in %d\n", - closeprob); + prt("Chance of close/open is 1 in %d\n", closeprob); if (closeprob <= 0) usage(); break; @@ -1897,6 +1900,13 @@ main(int argc, char **argv) exit(101); } break; + case 'j': + logid = strdup(optarg); + if (!logid) { + prterr("strdup"); + exit(101); + } + break; case 'l': maxfilelen = getnum(optarg, &endp); if (maxfilelen <= 0) @@ -2012,14 +2022,14 @@ main(int argc, char **argv) seed += (int)getpid(); } if (!quiet) - fprintf(stdout, "Seed set to %d\n", seed); + prt("Seed set to %d\n", seed); if (seed < 0) usage(); break; case 'W': mapped_writes = 0; if (!quiet) - fprintf(stdout, "mapped writes DISABLED\n"); + prt("mapped writes DISABLED\n"); break; case 'Z': o_direct = O_DIRECT;