]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: add a new 'log_writes' command
authorRoss Zwisler <ross.zwisler@linux.intel.com>
Thu, 4 Jan 2018 19:58:29 +0000 (13:58 -0600)
committerEric Sandeen <sandeen@redhat.com>
Thu, 4 Jan 2018 19:58:29 +0000 (13:58 -0600)
Add a new 'log_writes' command to xfs_io so that we can add dm-log-writes
log marks.  It's helpful to allow users of xfs_io to adds these marks from
within xfs_io instead of waiting until after xfs_io exits because then they
are able to replay the dm-log-writes log up to immediately after another
xfs_io operation such as mwrite.  This isolates the log replay from other
operations that happen as part of xfs_io exiting (file handles being
closed, mmaps being torn down, etc.).  This also allows users to insert
multiple marks between different xfs_io commands.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Suggested-by: Dave Chinner <david@fromorbit.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
configure.ac
debian/control
include/builddefs.in
io/Makefile
io/init.c
io/io.h
io/log_writes.c [new file with mode: 0644]
m4/Makefile
m4/package_devmapper.m4 [new file with mode: 0644]
man/man8/xfs_io.8

index f3325aa044089089138e1699c774e90a67bd3cc6..f83d5817b8c0402a3a349ad646e7a05535176cab 100644 (file)
@@ -164,6 +164,7 @@ AC_NEED_INTERNAL_FSXATTR
 AC_HAVE_GETFSMAP
 AC_HAVE_STATFS_FLAGS
 AC_HAVE_MAP_SYNC
+AC_HAVE_DEVMAPPER
 
 if test "$enable_blkid" = yes; then
 AC_HAVE_BLKID_TOPO
index ad816622620e724cf87ccd7907cb9044c8b5e3b2..5c26e3d7e1456dab45c7c942333567fd17a5b9c8 100644 (file)
@@ -3,7 +3,7 @@ Section: admin
 Priority: optional
 Maintainer: XFS Development Team <linux-xfs@vger.kernel.org>
 Uploaders: Nathan Scott <nathans@debian.org>, Anibal Monsalve Salazar <anibal@debian.org>
-Build-Depends: uuid-dev, dh-autoreconf, debhelper (>= 5), gettext, libtool, libreadline-gplv2-dev | libreadline5-dev, libblkid-dev (>= 2.17), linux-libc-dev
+Build-Depends: uuid-dev, dh-autoreconf, debhelper (>= 5), gettext, libtool, libreadline-gplv2-dev | libreadline5-dev, libblkid-dev (>= 2.17), linux-libc-dev, libdevmapper-dev
 Standards-Version: 3.9.1
 Homepage: http://xfs.org/
 
index 1f3302232170b322b12ddc10ca06432e9ed60609..94707038ce908ad2e1cde45dfeff1a3df9ab90e9 100644 (file)
@@ -35,6 +35,7 @@ LIBTERMCAP = @libtermcap@
 LIBEDITLINE = @libeditline@
 LIBREADLINE = @libreadline@
 LIBBLKID = @libblkid@
+LIBDEVMAPPER = @libdevmapper@
 LIBXFS = $(TOPDIR)/libxfs/libxfs.la
 LIBFROG = $(TOPDIR)/libfrog/libfrog.la
 LIBXCMD = $(TOPDIR)/libxcmd/libxcmd.la
@@ -117,6 +118,7 @@ NEED_INTERNAL_FSXATTR = @need_internal_fsxattr@
 HAVE_GETFSMAP = @have_getfsmap@
 HAVE_STATFS_FLAGS = @have_statfs_flags@
 HAVE_MAP_SYNC = @have_map_sync@
+HAVE_DEVMAPPER = @have_devmapper@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall
 #         -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
index 979434a2a15852c070d87ceb6b7876a09c5a5240..8055d4bd3131a4dcece6a188d0abbc7adaca4bef 100644 (file)
@@ -108,6 +108,12 @@ ifeq ($(HAVE_MAP_SYNC),yes)
 LCFLAGS += -DHAVE_MAP_SYNC
 endif
 
+ifeq ($(HAVE_DEVMAPPER),yes)
+CFILES += log_writes.c
+LLDLIBS += $(LIBDEVMAPPER)
+LCFLAGS += -DHAVE_DEVMAPPER
+endif
+
 # On linux we get fsmap from the system or define it ourselves
 # so include this based on platform type.  If this reverts to only
 # the autoconf check w/o local definition, change to testing HAVE_GETFSMAP
index 9e576fe203b2fc4ebbdfa4e924f260014cca90cd..6f47ed250579ab0abf50688979502d42d594269c 100644 (file)
--- a/io/init.c
+++ b/io/init.c
@@ -72,6 +72,7 @@ init_commands(void)
        help_init();
        imap_init();
        inject_init();
+       log_writes_init();
        madvise_init();
        mincore_init();
        mmap_init();
diff --git a/io/io.h b/io/io.h
index 5255c08705d23d079599d8117bf234ff9a77b187..5cf7c3084b00fe440b13fccbffba81836dc69fb6 100644 (file)
--- a/io/io.h
+++ b/io/io.h
@@ -187,4 +187,10 @@ extern void                fsmap_init(void);
 # define fsmap_init()  do { } while (0)
 #endif
 
+#ifdef HAVE_DEVMAPPER
+extern void            log_writes_init(void);
+#else
+#define log_writes_init()      do { } while (0)
+#endif
+
 extern void            scrub_init(void);
diff --git a/io/log_writes.c b/io/log_writes.c
new file mode 100644 (file)
index 0000000..46ea1c2
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "platform_defs.h"
+#include <libdevmapper.h>
+#include "command.h"
+#include "init.h"
+
+static cmdinfo_t log_writes_cmd;
+
+static int
+mark_log(const char *device, const char *mark)
+{
+       struct dm_task  *dmt;
+       const int       size = 80;
+       char            message[size];
+       int             len, ret = 0;
+
+       len = snprintf(message, size, "mark %s", mark);
+       if (len >= size) {
+               printf("mark '%s' is too long\n", mark);
+               return ret;
+       }
+
+       if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
+               return ret;
+
+       if (!dm_task_set_name(dmt, device))
+               goto out;
+
+       if (!dm_task_set_sector(dmt, 0))
+               goto out;
+
+       if (!dm_task_set_message(dmt, message))
+               goto out;
+
+       if (dm_task_run(dmt))
+               ret = 1;
+out:
+       dm_task_destroy(dmt);
+       return ret;
+}
+
+static int
+log_writes_f(
+       int                     argc,
+       char                    **argv)
+{
+       const char      *device = NULL;
+       const char      *mark = NULL;
+       int             c;
+
+       exitcode = 1;
+       while ((c = getopt(argc, argv, "d:m:")) != EOF) {
+               switch (c) {
+               case 'd':
+                       device = optarg;
+                       break;
+               case 'm':
+                       mark = optarg;
+                       break;
+               default:
+                       return command_usage(&log_writes_cmd);
+               }
+       }
+
+       if (device == NULL || mark == NULL)
+               return command_usage(&log_writes_cmd);
+
+       if (mark_log(device, mark))
+               exitcode = 0;
+
+       return 0;
+}
+
+void
+log_writes_init(void)
+{
+       log_writes_cmd.name = "log_writes";
+       log_writes_cmd.altname = "lw";
+       log_writes_cmd.cfunc = log_writes_f;
+       log_writes_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK | CMD_FOREIGN_OK
+                               | CMD_FLAG_ONESHOT;
+       log_writes_cmd.argmin = 0;
+       log_writes_cmd.argmax = -1;
+       log_writes_cmd.args = _("-d device -m mark");
+       log_writes_cmd.oneline =
+               _("create mark <mark> in the dm-log-writes log specified by <device>");
+
+       add_command(&log_writes_cmd);
+}
index 4706121b4b54ae570d30f5ceebd6977ede1c7ef4..77f2edda9da3bc72ec5c5216f25342de5ebc079a 100644 (file)
@@ -15,6 +15,7 @@ CONFIGURE = \
 LSRCFILES = \
        manual_format.m4 \
        package_blkid.m4 \
+       package_devmapper.m4 \
        package_globals.m4 \
        package_libcdev.m4 \
        package_pthread.m4 \
diff --git a/m4/package_devmapper.m4 b/m4/package_devmapper.m4
new file mode 100644 (file)
index 0000000..821f283
--- /dev/null
@@ -0,0 +1,11 @@
+#
+# See if libdevmapper is available on the system.
+#
+AC_DEFUN([AC_HAVE_DEVMAPPER],
+[ AC_SEARCH_LIBS([dm_task_create], [devmapper],
+        libdevmapper="-ldevmapper"
+        have_devmapper=yes,
+        have_devmapper=no,)
+    AC_SUBST(have_devmapper)
+    AC_SUBST(libdevmapper)
+])
index 3f77781f3384c7b2842101beabe3cf44b48a47cc..b47076082ad655e03f401440958d6d5b0d83accc 100644 (file)
@@ -1143,7 +1143,27 @@ parameter specifies which type of metadata to scrub.
 For AG metadata, one AG number must be specified.
 For file metadata, the scrub is applied to the open file unless the
 inode number and generation number are specified.
+.RE
+.PD
+.TP
+.BI "log_writes \-d " device " \-m "  mark
+Create a mark named
+.I mark
+in the dm-log-writes log specified by
+.I device.
+This is intended to be equivalent to the shell command:
 
+.B dmsetup message
+.I device
+.B 0 mark
+.I mark
+.PD
+.RE
+.TP
+.B lw
+See the
+.B log_writes
+command.
 .SH SEE ALSO
 .BR mkfs.xfs (8),
 .BR xfsctl (3),
@@ -1161,4 +1181,5 @@ inode number and generation number are specified.
 .BR open (2),
 .BR pread (2),
 .BR pwrite (2),
-.BR readdir (3).
+.BR readdir (3),
+.BR dmsetup (8).