]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: Add support for pwritev2()
authorGoldwyn Rodrigues <rgoldwyn@suse.com>
Thu, 9 Nov 2017 20:56:25 +0000 (14:56 -0600)
committerEric Sandeen <sandeen@redhat.com>
Thu, 9 Nov 2017 20:56:25 +0000 (14:56 -0600)
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
configure.ac
include/builddefs.in
io/Makefile
io/pwrite.c
m4/package_libcdev.m4

index 210e606fd33b1b05c560c35618f606f2cb53314e..cb23fb8dae0dff3bea3dfafb974b744ffb0285c7 100644 (file)
@@ -150,6 +150,7 @@ AC_HAVE_GETMNTENT
 AC_HAVE_GETMNTINFO
 AC_HAVE_FALLOCATE
 AC_HAVE_FIEMAP
+AC_HAVE_PWRITEV2
 AC_HAVE_PREADV
 AC_HAVE_COPY_FILE_RANGE
 AC_HAVE_SYNC_FILE_RANGE
index 2df12a75866106b568cc29d0e98211a56a507a16..1d454b6ebff20337143ecf8aae39d8ff7e9a452e 100644 (file)
@@ -103,6 +103,7 @@ HAVE_GETMNTINFO = @have_getmntinfo@
 HAVE_FALLOCATE = @have_fallocate@
 HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
+HAVE_PWRITEV2 = @have_pwritev2@
 HAVE_COPY_FILE_RANGE = @have_copy_file_range@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
 HAVE_SYNCFS = @have_syncfs@
index 47b0a669bce060dea0cd175eb505efe66f0bf598..050d6bd0124e93606e91f1e76a56aae42d15d7a4 100644 (file)
@@ -90,6 +90,10 @@ ifeq ($(HAVE_PREADV),yes)
 LCFLAGS += -DHAVE_PREADV -DHAVE_PWRITEV
 endif
 
+ifeq ($(HAVE_PWRITEV2),yes)
+LCFLAGS += -DHAVE_PWRITEV2
+endif
+
 ifeq ($(HAVE_READDIR),yes)
 CFILES += readdir.c
 LCFLAGS += -DHAVE_READDIR
index 8af607effba70954372c68793befafe98127bcff..abd3a184dc34fd6208c9c035cfb22aa846f3c95a 100644 (file)
@@ -62,7 +62,8 @@ do_pwritev(
        int             fd,
        off64_t         offset,
        ssize_t         count,
-       ssize_t         buffer_size)
+       ssize_t         buffer_size,
+       int             pwritev2_flags)
 {
        int vecs = 0;
        ssize_t oldlen = 0;
@@ -81,7 +82,14 @@ do_pwritev(
        } else {
                vecs = vectors;
        }
+#ifdef HAVE_PWRITEV2
+       if (pwritev2_flags)
+               bytes = pwritev2(fd, iov, vectors, offset, pwritev2_flags);
+       else
+               bytes = pwritev(fd, iov, vectors, offset);
+#else
        bytes = pwritev(fd, iov, vectors, offset);
+#endif
 
        /* restore trimmed iov */
        if (oldlen)
@@ -98,12 +106,13 @@ do_pwrite(
        int             fd,
        off64_t         offset,
        ssize_t         count,
-       ssize_t         buffer_size)
+       ssize_t         buffer_size,
+       int             pwritev2_flags)
 {
        if (!vectors)
                return pwrite(fd, buffer, min(count, buffer_size), offset);
 
-       return do_pwritev(fd, offset, count, buffer_size);
+       return do_pwritev(fd, offset, count, buffer_size, pwritev2_flags);
 }
 
 static int
@@ -111,7 +120,8 @@ write_random(
        off64_t         offset,
        long long       count,
        unsigned int    seed,
-       long long       *total)
+       long long       *total,
+       int             pwritev2_flags)
 {
        off64_t         off, range;
        ssize_t         bytes;
@@ -133,7 +143,8 @@ write_random(
                                buffersize;
                else
                        off = offset;
-               bytes = do_pwrite(file->fd, off, buffersize, buffersize);
+               bytes = do_pwrite(file->fd, off, buffersize, buffersize,
+                               pwritev2_flags);
                if (bytes == 0)
                        break;
                if (bytes < 0) {
@@ -153,7 +164,8 @@ static int
 write_backward(
        off64_t         offset,
        long long       *count,
-       long long       *total)
+       long long       *total,
+       int             pwritev2_flags)
 {
        off64_t         end, off = offset;
        ssize_t         bytes = 0, bytes_requested;
@@ -171,7 +183,8 @@ write_backward(
        if ((bytes_requested = (off % buffersize))) {
                bytes_requested = min(cnt, bytes_requested);
                off -= bytes_requested;
-               bytes = do_pwrite(file->fd, off, bytes_requested, buffersize);
+               bytes = do_pwrite(file->fd, off, bytes_requested, buffersize,
+                               pwritev2_flags);
                if (bytes == 0)
                        return ops;
                if (bytes < 0) {
@@ -189,7 +202,8 @@ write_backward(
        while (cnt > end) {
                bytes_requested = min(cnt, buffersize);
                off -= bytes_requested;
-               bytes = do_pwrite(file->fd, off, cnt, buffersize);
+               bytes = do_pwrite(file->fd, off, cnt, buffersize,
+                               pwritev2_flags);
                if (bytes == 0)
                        break;
                if (bytes < 0) {
@@ -212,7 +226,8 @@ write_buffer(
        size_t          bs,
        int             fd,
        off64_t         skip,
-       long long       *total)
+       long long       *total,
+       int             pwritev2_flags)
 {
        ssize_t         bytes;
        long long       bar = min(bs, count);
@@ -224,7 +239,7 @@ write_buffer(
                        if (read_buffer(fd, skip + *total, bs, &bar, 0, 1) < 0)
                                break;
                }
-               bytes = do_pwrite(file->fd, offset, count, bar);
+               bytes = do_pwrite(file->fd, offset, count, bar, pwritev2_flags);
                if (bytes == 0)
                        break;
                if (bytes < 0) {
@@ -258,6 +273,7 @@ pwrite_f(
        int             Cflag, qflag, uflag, dflag, wflag, Wflag;
        int             direction = IO_FORWARD;
        int             c, fd = -1;
+       int             pwritev2_flags = 0;
 
        Cflag = qflag = uflag = dflag = wflag = Wflag = 0;
        init_cvtnum(&fsblocksize, &fssectsize);
@@ -372,13 +388,14 @@ pwrite_f(
        case IO_RANDOM:
                if (!zeed)      /* srandom seed */
                        zeed = time(NULL);
-               c = write_random(offset, count, zeed, &total);
+               c = write_random(offset, count, zeed, &total, pwritev2_flags);
                break;
        case IO_FORWARD:
-               c = write_buffer(offset, count, bsize, fd, skip, &total);
+               c = write_buffer(offset, count, bsize, fd, skip, &total,
+                               pwritev2_flags);
                break;
        case IO_BACKWARD:
-               c = write_backward(offset, &count, &total);
+               c = write_backward(offset, &count, &total, pwritev2_flags);
                break;
        default:
                total = 0;
index af2a9631b8ba2cdb47a56a994848f10695896836..fdf9d69c245ac873ede0fa3046b8baae1773ccdb 100644 (file)
@@ -147,6 +147,22 @@ AC_DEFUN([AC_HAVE_PREADV],
     AC_SUBST(have_preadv)
   ])
 
+#
+# Check if we have a pwritev2 libc call (Linux)
+#
+AC_DEFUN([AC_HAVE_PWRITEV2],
+  [ AC_MSG_CHECKING([for pwritev2])
+    AC_TRY_LINK([
+#define _BSD_SOURCE
+#include <sys/uio.h>
+    ], [
+         pwritev2(0, 0, 0, 0, 0);
+    ], have_pwritev2=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_pwritev2)
+  ])
+
 #
 # Check if we have a copy_file_range system call (Linux)
 #