]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: add command line option -i to start an idle thread
authorAmir Goldstein <amir73il@gmail.com>
Mon, 31 Oct 2016 23:38:19 +0000 (10:38 +1100)
committerDave Chinner <david@fromorbit.com>
Mon, 31 Oct 2016 23:38:19 +0000 (10:38 +1100)
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 <amir73il@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
io/Makefile
io/init.c
man/man8/xfs_io.8

index e948006b067c973df7aca2a1aa7be8f2b6492ad5..1072e748e20bb701415550c16b7004b4d917c99e 100644 (file)
@@ -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 cowextsize.c
 
-LLDLIBS = $(LIBXCMD) $(LIBHANDLE)
+LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE)
 LLDFLAGS = -static-libtool-libs
 
index 6b88cc66663836fec6b954d7d9ddd1f380ea9115..2db48a2827e5af3d50f172f9ef12cbe5d4ca8c83 100644 (file)
--- a/io/init.c
+++ b/io/init.c
@@ -16,6 +16,7 @@
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <pthread.h>
 #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;
 }
index eb7b878d88f8fd37e7fd196d4bdf33b0c63c44b4..885df7f141e28dffcc3bdc00ac9b82dd97a9afa7 100644 (file)
@@ -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.