All of lore.kernel.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: linux-btrfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v2 06/13] btrfs-progs: receive: add stub implementation for pwritev2
Date: Wed, 18 Nov 2020 11:18:53 -0800	[thread overview]
Message-ID: <fbfec817eede33f202464cb240547993e4a0170a.1605723745.git.osandov@osandov.com> (raw)
In-Reply-To: <cover.1605723600.git.osandov@fb.com>

From: Boris Burkov <borisb@fb.com>

Encoded writes in receive will use pwritev2. It is possible that the
system libc does not export this function, so we stub it out and detect
whether to build the stub code with autoconf.

This syscall has special semantics in x32 (no hi lo, just takes loff_t)
so we have to detect that case and use the appropriate arguments.

Signed-off-by: Boris Burkov <boris@bur.io>
---
 Makefile     |  4 ++--
 configure.ac |  1 +
 stubs.c      | 24 ++++++++++++++++++++++++
 stubs.h      | 11 +++++++++++
 4 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 stubs.c
 create mode 100644 stubs.h

diff --git a/Makefile b/Makefile
index 381b630d..505e39d7 100644
--- a/Makefile
+++ b/Makefile
@@ -173,12 +173,12 @@ libbtrfs_objects = common/send-stream.o common/send-utils.o kernel-lib/rbtree.o
 		   kernel-lib/raid56.o kernel-lib/tables.o \
 		   common/device-scan.o common/path-utils.o \
 		   common/utils.o libbtrfsutil/subvolume.o libbtrfsutil/stubs.o \
-		   crypto/hash.o crypto/xxhash.o $(CRYPTO_OBJECTS)
+		   crypto/hash.o crypto/xxhash.o $(CRYPTO_OBJECTS) stubs.o
 libbtrfs_headers = common/send-stream.h common/send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
 	       crypto/crc32c.h kernel-lib/list.h kerncompat.h \
 	       kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
 	       common/extent-cache.h kernel-shared/extent_io.h ioctl.h \
-	       kernel-shared/ctree.h btrfsck.h version.h
+	       kernel-shared/ctree.h btrfsck.h version.h stubs.h
 libbtrfsutil_major := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MAJOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
 libbtrfsutil_minor := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MINOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
 libbtrfsutil_patch := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_PATCH ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
diff --git a/configure.ac b/configure.ac
index dd4adedf..eaf353cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,6 +57,7 @@ AC_CHECK_FUNCS([openat], [],
 	[AC_MSG_ERROR([cannot find openat() function])])
 
 AC_CHECK_FUNCS([reallocarray])
+AC_CHECK_FUNCS([pwritev2])
 
 m4_ifndef([PKG_PROG_PKG_CONFIG],
   [m4_fatal([Could not locate the pkg-config autoconf
diff --git a/stubs.c b/stubs.c
new file mode 100644
index 00000000..ab68a411
--- /dev/null
+++ b/stubs.c
@@ -0,0 +1,24 @@
+#if HAVE_PWRITEV2 != 1
+
+#include "stubs.h"
+
+#include "kerncompat.h"
+
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/uio.h>
+
+ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset,
+		 int flags)
+{
+/* these conditions indicate an x32 system, which has a different pwritev2 */
+#if defined(__x86_64__) && defined(__ILP32__)
+	return syscall(SYS_pwritev2, fd, iov, iovcnt, offset, flags);
+#else
+	unsigned long hi = offset >> (BITS_PER_LONG / 2) >> (BITS_PER_LONG / 2);
+	unsigned long lo = offset;
+
+	return syscall(SYS_pwritev2, fd, iov, iovcnt, lo, hi, flags);
+#endif // X32
+}
+#endif /* HAVE_PWRIVEV2 */
diff --git a/stubs.h b/stubs.h
new file mode 100644
index 00000000..b39f8a69
--- /dev/null
+++ b/stubs.h
@@ -0,0 +1,11 @@
+#ifndef _BTRFS_STUBS_H
+#define _BTRFS_STUBS_H
+
+#include <sys/types.h>
+
+struct iovec;
+
+ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset,
+		 int flags);
+
+#endif
-- 
2.29.2


  parent reply	other threads:[~2020-11-18 19:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 19:18 [PATCH v2 0/5] btrfs: implement send/receive of compressed extents without decompressing Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 1/5] btrfs: add send stream v2 definitions Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 01/13] btrfs-progs: send: fix crash on unknown option Omar Sandoval
2020-12-16 16:20   ` David Sterba
2020-11-18 19:18 ` [PATCH v2 02/13] btrfs-progs: receive: support v2 send stream larger tlv_len Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 2/5] btrfs: send: write larger chunks when using stream v2 Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 03/13] btrfs-progs: receive: dynamically allocate sctx->read_buf Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 3/5] btrfs: send: allocate send buffer with alloc_page() and vmap() for v2 Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 04/13] btrfs-progs: receive: support v2 send stream DATA tlv format Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 4/5] btrfs: send: send compressed extents with encoded writes Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 05/13] btrfs-progs: receive: add send stream v2 cmds and attrs to send.h Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 5/5] btrfs: send: enable support for stream v2 and compressed writes Omar Sandoval
2020-11-18 19:18 ` Omar Sandoval [this message]
2020-11-18 19:18 ` [PATCH v2 07/13] btrfs-progs: receive: open files with O_CLOEXEC Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 08/13] btrfs-progs: receive: process encoded_write commands Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 09/13] btrfs-progs: receive: encoded_write fallback to explicit decode and write Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 10/13] btrfs-progs: receive: process fallocate commands Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 11/13] btrfs-progs: receive: process setflags ioctl commands Omar Sandoval
2020-11-18 19:18 ` [PATCH v2 12/13] btrfs-progs: send: stream v2 ioctl flags Omar Sandoval
2020-11-18 19:19 ` [PATCH v2 13/13] btrfs-progs: receive: add tests for basic encoded_write send/receive Omar Sandoval

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=fbfec817eede33f202464cb240547993e4a0170a.1605723745.git.osandov@osandov.com \
    --to=osandov@osandov.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /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.