All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sandeen.net>
To: xfs-oss <xfs@oss.sgi.com>
Subject: [PATCH 2/2 V2] xfs_io: configure tests for preadv/pwritev & sync_file_range
Date: Tue, 09 Oct 2012 22:40:11 -0500	[thread overview]
Message-ID: <5074EE1B.3090600@sandeen.net> (raw)
In-Reply-To: <5074A05A.6000709@sandeen.net>

On older systems we may not have preadv/pwritev and/or
sync_file_range.

Add the configure magic, and stub out the code
where needed.

(sync_file_range just needed a better test; preadv/pwritev
took a little more rearranging)

And fix a couple typos ("numberic") while we're at it.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: add -DHAVE_PWRITEV and use that test in io/pwrite.c
rather than HAVE_PREADV

diff --git a/configure.in b/configure.in
index 664c0e9..b927c32 100644
--- a/configure.in
+++ b/configure.in
@@ -108,6 +108,8 @@ AC_HAVE_GETMNTENT
 AC_HAVE_GETMNTINFO
 AC_HAVE_FALLOCATE
 AC_HAVE_FIEMAP
+AC_HAVE_PREADV
+AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_BLKID_TOPO($enable_blkid)
 
 AC_TYPE_PSINT
diff --git a/include/builddefs.in b/include/builddefs.in
index 04590d2..0a3fa1a 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -101,6 +101,8 @@ HAVE_GETMNTENT = @have_getmntent@
 HAVE_GETMNTINFO = @have_getmntinfo@
 HAVE_FALLOCATE = @have_fallocate@
 HAVE_FIEMAP = @have_fiemap@
+HAVE_PREADV = @have_preadv@
+HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
diff --git a/io/Makefile b/io/Makefile
index bf46d56..50edf91 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -58,7 +58,7 @@ CFILES += inject.c resblks.c
 LCFLAGS += -DHAVE_INJECT -DHAVE_RESBLKS
 endif
 
-ifeq ($(PKG_PLATFORM),linux)
+ifeq ($(HAVE_SYNC_FILE_RANGE),yes)
 CFILES += sync_file_range.c
 LCFLAGS += -DHAVE_SYNC_FILE_RANGE
 endif
@@ -75,6 +75,11 @@ ifeq ($(HAVE_FALLOCATE),yes)
 LCFLAGS += -DHAVE_FALLOCATE
 endif
 
+# Also implies PWRITEV
+ifeq ($(HAVE_PREADV),yes)
+LCFLAGS += -DHAVE_PREADV -DHAVE_PWRITEV
+endif
+
 default: depend $(LTCOMMAND)
 
 include $(BUILDRULES)
diff --git a/io/pread.c b/io/pread.c
index 7e2ed7d..a42baed 100644
--- a/io/pread.c
+++ b/io/pread.c
@@ -47,7 +47,9 @@ pread_help(void)
 " -R   -- read at random offsets in the range of bytes\n"
 " -Z N -- zeed the random number generator (used when reading randomly)\n"
 "         (heh, zorry, the -s/-S arguments were already in use in pwrite)\n"
+#ifdef HAVE_PREADV
 " -V N -- use vectored IO with N iovecs of blocksize each (preadv)\n"
+#endif
 "\n"
 " When in \"random\" mode, the number of read operations will equal the\n"
 " number required to do a complete forward/backward scan of the range.\n"
@@ -168,8 +170,9 @@ dump_buffer(
 	}
 }
 
+#ifdef HAVE_PREADV
 static int
-do_pread(
+do_preadv(
 	int		fd,
 	off64_t		offset,
 	ssize_t		count,
@@ -179,10 +182,6 @@ do_pread(
 	ssize_t		oldlen = 0;
 	ssize_t		bytes = 0;
 
-
-	if (!vectors)
-		return pread64(fd, buffer, min(count, buffer_size), offset);
-
 	/* trim the iovec if necessary */
 	if (count < buffersize) {
 		size_t	len = 0;
@@ -204,6 +203,22 @@ do_pread(
 
 	return bytes;
 }
+#else
+#define do_preadv(fd, offset, count, buffer_size) (0)
+#endif
+
+static int
+do_pread(
+	int		fd,
+	off64_t		offset,
+	ssize_t		count,
+	ssize_t		buffer_size)
+{
+	if (!vectors)
+		return pread64(fd, buffer, min(count, buffer_size), offset);
+
+	return do_preadv(fd, offset, count, buffer_size);
+}
 
 static int
 read_random(
@@ -406,14 +421,16 @@ pread_f(
 		case 'v':
 			vflag = 1;
 			break;
+#ifdef HAVE_PREADV
 		case 'V':
 			vectors = strtoul(optarg, &sp, 0);
 			if (!sp || sp == optarg) {
-				printf(_("non-numberic vector count == %s\n"),
+				printf(_("non-numeric vector count == %s\n"),
 					optarg);
 				return 0;
 			}
 			break;
+#endif
 		case 'Z':
 			zeed = strtoul(optarg, &sp, 0);
 			if (!sp || sp == optarg) {
diff --git a/io/pwrite.c b/io/pwrite.c
index 73acbac..a2f0a81 100644
--- a/io/pwrite.c
+++ b/io/pwrite.c
@@ -51,24 +51,23 @@ pwrite_help(void)
 " -R   -- write at random offsets in the specified range of bytes\n"
 " -Z N -- zeed the random number generator (used when writing randomly)\n"
 "         (heh, zorry, the -s/-S arguments were already in use in pwrite)\n"
+#ifdef HAVE_PWRITEV
 " -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n"
+#endif
 "\n"));
 }
 
+#ifdef HAVE_PWRITEV
 static int
-do_pwrite(
+do_pwritev(
 	int		fd,
 	off64_t		offset,
 	ssize_t		count,
 	ssize_t		buffer_size)
 {
-	int		vecs = 0;
-	ssize_t		oldlen = 0;
-	ssize_t		bytes = 0;
-
-
-	if (!vectors)
-		return pwrite64(fd, buffer, min(count, buffer_size), offset);
+	int vecs = 0;
+	ssize_t oldlen = 0;
+	ssize_t bytes = 0;
 
 	/* trim the iovec if necessary */
 	if (count < buffersize) {
@@ -91,6 +90,23 @@ do_pwrite(
 
 	return bytes;
 }
+#else
+#define do_pwritev(fd, offset, count, buffer_size) (0)
+#endif
+
+static int
+do_pwrite(
+	int		fd,
+	off64_t		offset,
+	ssize_t		count,
+	ssize_t		buffer_size)
+{
+	if (!vectors)
+		return pwrite64(fd, buffer, min(count, buffer_size), offset);
+
+	return do_pwritev(fd, offset, count, buffer_size);
+}
+
 static int
 write_random(
 	off64_t		offset,
@@ -297,7 +313,7 @@ pwrite_f(
 		case 'V':
 			vectors = strtoul(optarg, &sp, 0);
 			if (!sp || sp == optarg) {
-				printf(_("non-numberic vector count == %s\n"),
+				printf(_("non-numeric vector count == %s\n"),
 					optarg);
 				return 0;
 			}
diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4
index 1e2c256..f489f52 100644
--- a/m4/package_libcdev.m4
+++ b/m4/package_libcdev.m4
@@ -135,3 +135,38 @@ AC_DEFUN([AC_HAVE_FIEMAP],
        AC_MSG_RESULT(no))
     AC_SUBST(have_fiemap)
   ])
+
+#
+# Check if we have a preadv libc call (Linux)
+#
+AC_DEFUN([AC_HAVE_PREADV],
+  [ AC_MSG_CHECKING([for preadv])
+    AC_TRY_LINK([
+#define _FILE_OFFSET_BITS 64
+#define _BSD_SOURCE
+#include <sys/uio.h>
+    ], [
+         preadv(0, 0, 0, 0);
+    ], have_preadv=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_preadv)
+  ])
+
+#
+# Check if we have a sync_file_range libc call (Linux)
+#
+AC_DEFUN([AC_HAVE_SYNC_FILE_RANGE],
+  [ AC_MSG_CHECKING([for sync_file_range])
+    AC_TRY_LINK([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <fcntl.h>
+    ], [
+         sync_file_range(0, 0, 0, 0);
+    ], have_sync_file_range=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_sync_file_range)
+  ])
+


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2012-10-10  3:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-09 22:02 [PATCH 1/2] xfs_io: include headers for preadv/pwritev Eric Sandeen
2012-10-09 22:08 ` [PATCH 2/2] xfs_io: configure tests for preadv/pwritev & sync_file_range Eric Sandeen
2012-10-09 22:28   ` Dave Chinner
2012-10-09 22:32     ` Eric Sandeen
2012-10-09 22:56       ` Dave Chinner
2012-10-09 22:57         ` Eric Sandeen
2012-10-09 23:05           ` Dave Chinner
2012-10-10  3:40   ` Eric Sandeen [this message]
2012-10-10 23:25     ` [PATCH 2/2 V2] " Dave Chinner
2012-10-09 22:21 ` [PATCH 1/2] xfs_io: include headers for preadv/pwritev Dave Chinner
2012-10-10  3:37 ` [PATCH 1/2 V2] " Eric Sandeen
2012-10-10 23:24   ` Dave Chinner
2012-10-11 20:40 ` [PATCH 1/2] " Mark Tinguely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5074EE1B.3090600@sandeen.net \
    --to=sandeen@sandeen.net \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.