]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: add sync and syncfs commands
authorEric Sandeen <sandeen@sandeen.net>
Wed, 29 Oct 2014 05:33:49 +0000 (16:33 +1100)
committerDave Chinner <david@fromorbit.com>
Wed, 29 Oct 2014 05:33:49 +0000 (16:33 +1100)
There's no easy way to invoke syncfs from the commandline,
as far as I know, so add it to xfs_io to be handy.

Add sync while we're at it, just for completeness.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
io/Makefile
io/init.c
io/io.h
io/sync.c [new file with mode: 0644]
m4/package_libcdev.m4
man/man8/xfs_io.8

index c16af87c76067b257b76d8b53041ae7e070cc046..82593a636dd9402c1aa4206b6dd08ed694362804 100644 (file)
@@ -11,7 +11,7 @@ HFILES = init.h io.h
 CFILES = init.c \
        attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c link.c \
        mmap.c open.c parent.c pread.c prealloc.c pwrite.c seek.c shutdown.c \
-       truncate.c
+       sync.c truncate.c
 
 LLDLIBS = $(LIBXCMD) $(LIBHANDLE)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE)
@@ -64,6 +64,10 @@ CFILES += sync_file_range.c
 LCFLAGS += -DHAVE_SYNC_FILE_RANGE
 endif
 
+ifeq ($(HAVE_SYNCFS),yes)
+LCFLAGS += -DHAVE_SYNCFS
+endif
+
 ifeq ($(ENABLE_READLINE),yes)
 LLDLIBS += $(LIBREADLINE) $(LIBTERMCAP)
 endif
index bfc35bf97355a33adbf5d7c6c1e7be6ade3bbe7a..1b0751899de52951f8fba502800b660f64e457a8 100644 (file)
--- a/io/init.c
+++ b/io/init.c
@@ -80,8 +80,9 @@ init_commands(void)
        resblks_init();
        sendfile_init();
        shutdown_init();
-       truncate_init();
+       sync_init();
        sync_range_init();
+       truncate_init();
 }
 
 static int
diff --git a/io/io.h b/io/io.h
index 1b3bca1e704b343d24e19c22a9fcf73922ec18f7..db8b5138c207c81f00add4ddffdfa95cb839c161 100644 (file)
--- a/io/io.h
+++ b/io/io.h
@@ -109,6 +109,7 @@ extern void         pwrite_init(void);
 extern void            quit_init(void);
 extern void            seek_init(void);
 extern void            shutdown_init(void);
+extern void            sync_init(void);
 extern void            truncate_init(void);
 
 #ifdef HAVE_FADVISE
diff --git a/io/sync.c b/io/sync.c
new file mode 100644 (file)
index 0000000..683899b
--- /dev/null
+++ b/io/sync.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * 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 <xfs/xfs.h>
+#include <xfs/command.h>
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t sync_cmd;
+
+static int
+sync_f(
+       int                     argc,
+       char                    **argv)
+{
+       /* sync can't fail */
+       sync();
+       return 0;
+}
+
+#ifdef HAVE_SYNCFS
+static cmdinfo_t syncfs_cmd;
+
+static int
+syncfs_f(
+       int                     argc,
+       char                    **argv)
+{
+       /* syncfs can't fail */
+       syncfs(file->fd);
+       return 0;
+}
+#endif
+
+void
+sync_init(void)
+{
+       sync_cmd.name = "sync";
+       sync_cmd.cfunc = sync_f;
+       sync_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK | CMD_FOREIGN_OK;
+       sync_cmd.oneline =
+               _("calls sync(2) to flush all in-core filesystem state to disk");
+
+       add_command(&sync_cmd);
+
+#ifdef HAVE_SYNCFS
+       syncfs_cmd.name = "syncfs";
+       syncfs_cmd.cfunc = syncfs_f;
+       syncfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+       syncfs_cmd.oneline =
+               _("calls syncfs(2) to flush all in-core filesystem state to disk");
+
+       add_command(&syncfs_cmd);
+#endif
+}
index 8267ba065f5d227a241a2e8dc708f72642f21a41..919ae0a6be8db82ceab169ffa992a8a5b2db0139 100644 (file)
@@ -170,6 +170,23 @@ AC_DEFUN([AC_HAVE_SYNC_FILE_RANGE],
     AC_SUBST(have_sync_file_range)
   ])
 
+#
+# Check if we have a syncfs libc call (Linux)
+#
+AC_DEFUN([AC_HAVE_SYNCFS],
+  [ AC_MSG_CHECKING([for syncfs])
+    AC_TRY_LINK([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <unistd.h>
+    ], [
+         syncfs(0);
+    ], have_sync_fs=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_syncfs)
+  ])
+
 #
 # Check if we have a readdir libc call
 #
index e40fbf9304a57527044880745530791154b55403..cf27b993abd3bdeed6ba00ec8fd9a38ab20ce71d 100644 (file)
@@ -362,6 +362,16 @@ start writeback of dirty data in the given range (SYNC_FILE_RANGE_WRITE).
 .RE
 .PD
 .TP
+.B sync
+Calls
+.BR sync (2)
+to flush all filesystems' in-core data to disk.
+.TP
+.B syncfs
+Calls
+.BR syncfs (2)
+to flush this filesystem's in-core data to disk.
+.TP
 .BI resvsp " offset length"
 Allocates reserved, unwritten space for part of a file using the
 XFS_IOC_RESVSP system call described in the