From patchwork Mon Oct 17 07:20:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9378461 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 6A782600CA for ; Mon, 17 Oct 2016 07:22:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49A1528EC1 for ; Mon, 17 Oct 2016 07:22:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A00728EBB; Mon, 17 Oct 2016 07:22:00 +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 5474328EBB for ; Mon, 17 Oct 2016 07:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757530AbcJQHV6 (ORCPT ); Mon, 17 Oct 2016 03:21:58 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:34667 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756546AbcJQHV6 (ORCPT ); Mon, 17 Oct 2016 03:21:58 -0400 Received: by mail-lf0-f67.google.com with SMTP id x23so19368219lfi.1; Mon, 17 Oct 2016 00:21:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SsxgIxW9aDTCT8yFdA5aTccPrPJXwWo70qDMKkQbZ3E=; b=fCTnZb3/Ozrtrw2I5seNJO12ofaRhnUdII4a5/4Gz48V9DLbXu3IBQ8dwjZABdZNIZ lX7u6lmBPXMVCXdLiGPkt2uUZW1sTQzhPHZr0sanqHDJEXOcAtHpV6urfZNbEouPQJ09 cCt0VBhOsUlkjY921M9JA+0syd8BbZjtxuxczKufMskLBBaR1gEOLqX+VrBvKB+BYsYU c2dMR0mwuqSVIv82nVOEgBkaFLtvmiiJbbxaaThT8EzYGdGmbeWTmO3yy15DlllunqKM FTBQ9eyDrf+YfeaYVZZbk5zMgyOdzrqn9DKBWcgGin3PEIZ67cKyjLHW6WsGRwJpe8MM 5JbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SsxgIxW9aDTCT8yFdA5aTccPrPJXwWo70qDMKkQbZ3E=; b=QY6rufAVt7r6pJrGBgF8w/kKknvfwI4koD0nipBDzjbyqixpad1wO1mPMXrjXyTWEF 9u7HaMjS6wBBpXwtgjh4rA7KROSiOEb25raI078UdArq7iBn7GWld3RWtwFPQnCGj9vI kBmOsbhjDdq41MFr+y0V7McXo78j8dBvBwycFApve2DaLYEkSY+s5WUIYE0Vd5DVl8JD v4WAnT6T8fth/LMEyMdAIT9fIOxTFVtgSbbaIa4CyiBEm/4L9DZRGIilQeWbCUIWH/Tc TuRHeWSQ+IqWupWhSeLOBriSXlsOBduEH6wORgKNw2RZZFIka1bSMbhoYtTkq2kZB8MH +Arw== X-Gm-Message-State: AA6/9Rl+PsHaB4zyA+LBgIBA7659TUNFXgV4LHwEronqd9ID7+0FSUSjlucjYP9Y2Zxxkg== X-Received: by 10.28.209.142 with SMTP id i136mr7790831wmg.1.1476688883033; Mon, 17 Oct 2016 00:21:23 -0700 (PDT) Received: from amir-VirtualBox.Home (bzq-79-177-34-153.red.bezeqint.net. [79.177.34.153]) by smtp.gmail.com with ESMTPSA id wh3sm50517274wjb.49.2016.10.17.00.21.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 00:21:21 -0700 (PDT) From: Amir Goldstein To: Dave Chinner Cc: Christoph Hellwig , linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v3] xfs_io: add command line option -i to start an idle thread Date: Mon, 17 Oct 2016 10:20:51 +0300 Message-Id: <1476688851-32647-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP xfs_io -i will start by spawning an idle thread. The purpose of this idle thread is to test io from a multi threaded process. With single threaded process, the file table is not shared and file structs are not reference counted. Spawning an idle thread can help detecting file struct reference leaks. Signed-off-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- io/Makefile | 2 +- io/init.c | 35 +++++++++++++++++++++++++++++++++-- man/man8/xfs_io.8 | 8 +++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/io/Makefile b/io/Makefile index 1997ca9..032a8c7 100644 --- a/io/Makefile +++ b/io/Makefile @@ -13,7 +13,7 @@ CFILES = init.c \ mmap.c open.c parent.c pread.c prealloc.c pwrite.c seek.c shutdown.c \ sync.c truncate.c reflink.c -LLDLIBS = $(LIBXCMD) $(LIBHANDLE) +LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBPTHREAD) LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) LLDFLAGS = -static-libtool-libs diff --git a/io/init.c b/io/init.c index 6b88cc6..2db48a2 100644 --- a/io/init.c +++ b/io/init.c @@ -16,6 +16,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include "platform_defs.h" #include "command.h" #include "input.h" @@ -25,6 +26,7 @@ char *progname; int exitcode; int expert; +int idlethread; size_t pagesize; struct timeval stopwatch; @@ -32,7 +34,7 @@ void usage(void) { fprintf(stderr, - _("Usage: %s [-adfmnrRstVx] [-p prog] [-c cmd]... file\n"), + _("Usage: %s [-adfimnrRstTVx] [-p prog] [-c cmd]... file\n"), progname); exit(1); } @@ -141,7 +143,7 @@ init( pagesize = getpagesize(); gettimeofday(&stopwatch, NULL); - while ((c = getopt(argc, argv, "ac:dFfmp:nrRstTVx")) != EOF) { + while ((c = getopt(argc, argv, "ac:dFfimp:nrRstTVx")) != EOF) { switch (c) { case 'a': flags |= IO_APPEND; @@ -158,6 +160,9 @@ init( case 'f': flags |= IO_CREAT; break; + case 'i': + idlethread = 1; + break; case 'm': mode = strtoul(optarg, &sp, 0); if (!sp || sp == optarg) { @@ -213,12 +218,38 @@ init( add_check_command(init_check_command); } +/* + * The purpose of this idle thread is to test io from a multi threaded process. + * With single threaded process, the file table is not shared and file structs + * are not reference counted. Spawning an idle thread can help detecting file + * struct reference leaks. + */ +void * +idle_loop(void *arg) +{ + for (;;) + pause(); +} + +void +start_idle_thread() +{ + pthread_t t; + + if (pthread_create(&t, NULL, idle_loop, NULL)) { + fprintf(stderr, "Error creating idle thread\n"); + exit(1); + } +} + int main( int argc, char **argv) { init(argc, argv); + if (idlethread) + start_idle_thread(); command_loop(); return exitcode; } diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index eb7b878..885df7f 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -4,7 +4,7 @@ xfs_io \- debug the I/O path of an XFS filesystem .SH SYNOPSIS .B xfs_io [ -.B \-adfmrRstxT +.B \-adfimrRstxT ] [ .B \-c .I cmd @@ -51,6 +51,12 @@ read-only, initially. This is required if .I file is immutable or append-only. .TP +.B \-i +Start an idle thread. The purpose of this idle thread is to test io +from a multi threaded process. With single threaded process, +the file table is not shared and file structs are not reference counted. +Spawning an idle thread can help detecting file struct reference leaks. +.TP .B \-x Expert mode. Dangerous commands are only available in this mode. These commands also tend to require additional privileges.