Skip to contentSkip to conversation

xfs_io: add sync and syncfs commands

PATCH In review Eric Sandeen 3 participants 5 messages Oct 24, 2014 – Oct 27, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_io: add sync and syncfs commands

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.

---

configure.ac +1 -0
index ae17c68..bf0c205 100644
@@ -111,6 +111,7 @@ AC_HAVE_FALLOCATE
 AC_HAVE_FIEMAP
 AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
+AC_HAVE_SYNCFS
 AC_HAVE_BLKID_TOPO($enable_blkid)
 AC_HAVE_READDIR
 
include/builddefs.in +1 -0
index 944bcf6..b8bde5f 100644
@@ -103,6 +103,7 @@ HAVE_FALLOCATE = @have_fallocate@
 HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
+HAVE_SYNCFS = @have_syncfs@
 HAVE_READDIR = @have_readdir@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
io/Makefile +5 -1
index c16af87..82593a6 100644
@@ -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
io/init.c +2 -1
index bfc35bf..1b07518 100644
@@ -80,8 +80,9 @@ init_commands(void)
 	resblks_init();
 	sendfile_init();
 	shutdown_init();
-	truncate_init();
+	sync_init();
 	sync_range_init();
+	truncate_init();
 }
 
 static int
io/io.h +1 -0
index 1b3bca1..db8b513 100644
@@ -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
io/sync.c new file +70 -0

70 lines not on this page · raw message

m4/package_libcdev.m4 +17 -0
index 8267ba0..51182e4 100644
@@ -171,6 +171,23 @@ AC_DEFUN([AC_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_syncfs=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_syncfs)
+  ])
+
+#
 # Check if we have a readdir libc call
 #
 AC_DEFUN([AC_HAVE_READDIR],
man/man8/xfs_io.8 +10 -0
index e40fbf9..cf27b99 100644
@@ -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

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw
Quoted 134 lines · Eric Sandeen

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.

---

configure.ac +1 -0
index ae17c68..bf0c205 100644
@@ -111,6 +111,7 @@ AC_HAVE_FALLOCATE
 AC_HAVE_FIEMAP
 AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
+AC_HAVE_SYNCFS
 AC_HAVE_BLKID_TOPO($enable_blkid)
 AC_HAVE_READDIR
 
include/builddefs.in +1 -0
index 944bcf6..b8bde5f 100644
@@ -103,6 +103,7 @@ HAVE_FALLOCATE = @have_fallocate@
 HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
+HAVE_SYNCFS = @have_syncfs@
 HAVE_READDIR = @have_readdir@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
io/Makefile +5 -1
index c16af87..82593a6 100644
@@ -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
io/init.c +2 -1
index bfc35bf..1b07518 100644
@@ -80,8 +80,9 @@ init_commands(void)
 	resblks_init();
 	sendfile_init();
 	shutdown_init();
-	truncate_init();
+	sync_init();
 	sync_range_init();
+	truncate_init();
 }
 
 static int
io/io.h +1 -0
index 1b3bca1..db8b513 100644
@@ -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
io/sync.c new file +45 -0
new file mode 100644
index 0000000..a6c6215
@@ -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);

io/sync.c line 55

Quoted 10 lines
io/sync.c new file +10 -0
+	return 0;
+}
+#endif
+
+void
+sync_init(void)
+{
+	sync_cmd.name = "sync";
+	sync_cmd.cfunc = sync_f;
+	sync_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;

Not a big deal given that we have sync(1), but CMD_NOFILE_OK..?

The rest looks good to me.

Brian

Quoted 65 lines
io/sync.c new file +15 -0
+	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
+}
m4/package_libcdev.m4 +17 -0
index 8267ba0..51182e4 100644
@@ -171,6 +171,23 @@ AC_DEFUN([AC_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_syncfs=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_syncfs)
+  ])
+
+#
 # Check if we have a readdir libc call
 #
 AC_DEFUN([AC_HAVE_READDIR],
man/man8/xfs_io.8 +10 -0
index e40fbf9..cf27b99 100644
@@ -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
Quoted 4 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 1 line · Brian Foster

On Fri, Oct 24, 2014 at 01:06:09PM -0500, Eric Sandeen wrote:

...

Quoted 9 lines

io/sync.c line 55

Quoted 6 lines
io/sync.c new file +6 -0
+void
+sync_init(void)
+{
+	sync_cmd.name = "sync";
+	sync_cmd.cfunc = sync_f;
+	sync_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;

Not a big deal given that we have sync(1), but CMD_NOFILE_OK..?

Quoted 3 lines

The rest looks good to me.

Brian

Ah, good eye, thanks. Will send V2.

-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

PATCH v2 1/1 xfs_io: add sync and syncfs commands

In reply to Eric Sandeen

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.

---

V2: sync doesn't need to have a file open

io/Makefile +5 -1
index c16af87..82593a6 100644
@@ -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
io/init.c +2 -1
index bfc35bf..1b07518 100644
@@ -80,8 +80,9 @@ init_commands(void)
 	resblks_init();
 	sendfile_init();
 	shutdown_init();
-	truncate_init();
+	sync_init();
 	sync_range_init();
+	truncate_init();
 }
 
 static int
io/io.h +1 -0
index 1b3bca1..db8b513 100644
@@ -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
io/sync.c new file +70 -0

70 lines not on this page · raw message

m4/package_libcdev.m4 +17 -0
index 8267ba0..919ae0a 100644
@@ -171,6 +171,23 @@ AC_DEFUN([AC_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
 #
 AC_DEFUN([AC_HAVE_READDIR],
man/man8/xfs_io.8 +10 -0
index e40fbf9..cf27b99 100644
@@ -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

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v2 1/1
#4 lore raw
Quoted 7 lines · Eric Sandeen

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.

---

Looks good to me.

Quoted 181 lines

V2: sync doesn't need to have a file open

io/Makefile +5 -1
index c16af87..82593a6 100644
@@ -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
io/init.c +2 -1
index bfc35bf..1b07518 100644
@@ -80,8 +80,9 @@ init_commands(void)
 	resblks_init();
 	sendfile_init();
 	shutdown_init();
-	truncate_init();
+	sync_init();
 	sync_range_init();
+	truncate_init();
 }
 
 static int
io/io.h +1 -0
index 1b3bca1..db8b513 100644
@@ -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
io/sync.c new file +70 -0
new file mode 100644
index 0000000..683899b
@@ -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
+}
m4/package_libcdev.m4 +17 -0
index 8267ba0..919ae0a 100644
@@ -171,6 +171,23 @@ AC_DEFUN([AC_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
 #
 AC_DEFUN([AC_HAVE_READDIR],
man/man8/xfs_io.8 +10 -0
index e40fbf9..cf27b99 100644
@@ -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
Quoted 4 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs