From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [PATCH v2 06/20] fuse: Implement hole detection through lseek
Date: Tue, 22 Sep 2020 12:49:18 +0200 [thread overview]
Message-ID: <20200922104932.46384-7-mreitz@redhat.com> (raw)
In-Reply-To: <20200922104932.46384-1-mreitz@redhat.com>
This is a relatively new feature in libfuse (available since 3.8.0,
which was released in November 2019), so we have to let configure check
whether it is available before making use of it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
configure | 32 +++++++++++++++++++
block/export/fuse.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
meson.build | 1 +
3 files changed, 110 insertions(+)
diff --git a/configure b/configure
index 21c31e4694..6b9184b62a 100755
--- a/configure
+++ b/configure
@@ -6226,11 +6226,39 @@ EOF
fuse_libs=$(pkg-config --libs fuse3)
if compile_prog "$fuse_cflags" "$fuse_libs"; then
fuse=yes
+
+ cat > $TMPC <<EOF
+#define FUSE_USE_VERSION 31
+#include <fuse.h>
+#include <fuse_lowlevel.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+static void fuse_lseek(fuse_req_t req, fuse_ino_t inode, off_t offset,
+ int whence, struct fuse_file_info *fi)
+{
+ if (whence == SEEK_DATA || whence == SEEK_HOLE) {
+ fuse_reply_lseek(req, offset);
+ } else {
+ fuse_reply_err(req, EINVAL);
+ }
+}
+const struct fuse_lowlevel_ops fuse_ops = {
+ .lseek = fuse_lseek,
+};
+int main(void) { return 0; }
+EOF
+ if compile_prog "$fuse_cflags" "$fuse_libs"; then
+ fuse_lseek=yes
+ else
+ fuse_lseek=no
+ fi
else
if test "$fuse" = "yes"; then
feature_not_found "fuse"
fi
fuse=no
+ fuse_lseek=no
fi
fi
@@ -7425,6 +7453,10 @@ if test "$fuse" = "yes"; then
echo "CONFIG_FUSE=y" >> $config_host_mak
echo "FUSE_CFLAGS=$fuse_cflags" >> $config_host_mak
echo "FUSE_LIBS=$fuse_libs" >> $config_host_mak
+
+ if test "$fuse_lseek" = "yes"; then
+ echo "CONFIG_FUSE_LSEEK=y" >> $config_host_mak
+ fi
fi
if test "$tcg_interpreter" = "yes"; then
diff --git a/block/export/fuse.c b/block/export/fuse.c
index 7dfb4eb280..ee90f5a185 100644
--- a/block/export/fuse.c
+++ b/block/export/fuse.c
@@ -548,6 +548,80 @@ static void fuse_flush(fuse_req_t req, fuse_ino_t inode,
fuse_reply_err(req, ret < 0 ? -ret : 0);
}
+#ifdef CONFIG_FUSE_LSEEK
+/**
+ * Let clients inquire allocation status.
+ */
+static void fuse_lseek(fuse_req_t req, fuse_ino_t inode, off_t offset,
+ int whence, struct fuse_file_info *fi)
+{
+ FuseExport *exp = fuse_req_userdata(req);
+
+ if (whence != SEEK_HOLE && whence != SEEK_DATA) {
+ fuse_reply_err(req, EINVAL);
+ return;
+ }
+
+ while (true) {
+ int64_t pnum;
+ int ret;
+
+ ret = bdrv_block_status_above(blk_bs(exp->common.blk), NULL,
+ offset, INT64_MAX, &pnum, NULL, NULL);
+ if (ret < 0) {
+ fuse_reply_err(req, -ret);
+ return;
+ }
+
+ if (!pnum && (ret & BDRV_BLOCK_EOF)) {
+ int64_t blk_len;
+
+ /*
+ * If blk_getlength() rounds (e.g. by sectors), then the
+ * export length will be rounded, too. However,
+ * bdrv_block_status_above() may return EOF at unaligned
+ * offsets. We must not let this become visible and thus
+ * always simulate a hole between @offset (the real EOF)
+ * and @blk_len (the client-visible EOF).
+ */
+
+ blk_len = blk_getlength(exp->common.blk);
+ if (blk_len < 0) {
+ fuse_reply_err(req, -blk_len);
+ return;
+ }
+
+ if (offset > blk_len || whence == SEEK_DATA) {
+ fuse_reply_err(req, ENXIO);
+ } else {
+ fuse_reply_lseek(req, offset);
+ }
+ return;
+ }
+
+ if (ret & BDRV_BLOCK_DATA) {
+ if (whence == SEEK_DATA) {
+ fuse_reply_lseek(req, offset);
+ return;
+ }
+ } else {
+ if (whence == SEEK_HOLE) {
+ fuse_reply_lseek(req, offset);
+ return;
+ }
+ }
+
+ /* Safety check against infinite loops */
+ if (!pnum) {
+ fuse_reply_err(req, ENXIO);
+ return;
+ }
+
+ offset += pnum;
+ }
+}
+#endif
+
static const struct fuse_lowlevel_ops fuse_ops = {
.lookup = fuse_lookup,
.getattr = fuse_getattr,
@@ -557,6 +631,9 @@ static const struct fuse_lowlevel_ops fuse_ops = {
.write = fuse_write,
.fallocate = fuse_fallocate,
.flush = fuse_flush,
+#ifdef CONFIG_FUSE_LSEEK
+ .lseek = fuse_lseek,
+#endif
};
const BlockExportDriver blk_exp_fuse = {
diff --git a/meson.build b/meson.build
index 85addd8562..1db6a46d14 100644
--- a/meson.build
+++ b/meson.build
@@ -1537,6 +1537,7 @@ summary_info += {'thread sanitizer': config_host.has_key('CONFIG_TSAN')}
summary_info += {'rng-none': config_host.has_key('CONFIG_RNG_NONE')}
summary_info += {'Linux keyring': config_host.has_key('CONFIG_SECRET_KEYRING')}
summary_info += {'fuse exports': config_host.has_key('CONFIG_FUSE')}
+summary_info += {'fuse lseek': config_host.has_key('CONFIG_FUSE_LSEEK')}
summary(summary_info, bool_yn: true)
if not supported_cpus.contains(cpu)
--
2.26.2
next prev parent reply other threads:[~2020-09-22 10:59 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-22 10:49 [PATCH v2 00/20] block/export: Allow exporting BDSs via FUSE Max Reitz
2020-09-22 10:49 ` [PATCH v2 01/20] configure: Detect libfuse Max Reitz
2020-09-22 11:14 ` Thomas Huth
2020-09-22 11:21 ` Paolo Bonzini
2020-09-22 11:46 ` Max Reitz
2020-09-22 15:37 ` Max Reitz
2020-09-22 15:45 ` Paolo Bonzini
2020-09-22 10:49 ` [PATCH v2 02/20] fuse: Allow exporting BDSs via FUSE Max Reitz
2020-10-15 8:57 ` Kevin Wolf
2020-10-15 14:46 ` Max Reitz
2020-10-15 15:41 ` Kevin Wolf
2020-10-15 15:59 ` Max Reitz
2020-10-15 17:01 ` Kevin Wolf
2020-09-22 10:49 ` [PATCH v2 03/20] fuse: Implement standard FUSE operations Max Reitz
2020-10-15 9:46 ` Kevin Wolf
2020-10-15 15:18 ` Max Reitz
2020-10-15 15:58 ` Kevin Wolf
2020-10-15 16:04 ` Max Reitz
2020-09-22 10:49 ` [PATCH v2 04/20] fuse: Allow growable exports Max Reitz
2020-10-15 10:41 ` Kevin Wolf
2020-10-15 15:20 ` Max Reitz
2020-09-22 10:49 ` [PATCH v2 05/20] fuse: (Partially) implement fallocate() Max Reitz
2020-09-22 10:49 ` Max Reitz [this message]
2020-09-22 10:49 ` [PATCH v2 07/20] iotests: Do not needlessly filter _make_test_img Max Reitz
2020-09-22 10:49 ` [PATCH v2 08/20] iotests: Do not pipe _make_test_img Max Reitz
2020-09-22 10:49 ` [PATCH v2 09/20] iotests: Use convert -n in some cases Max Reitz
2020-09-22 10:49 ` [PATCH v2 10/20] iotests/046: Avoid renaming images Max Reitz
2020-09-22 10:49 ` [PATCH v2 11/20] iotests: Derive image names from $TEST_IMG Max Reitz
2020-09-22 10:49 ` [PATCH v2 12/20] iotests/091: Use _cleanup_qemu instad of "wait" Max Reitz
2020-09-22 10:49 ` [PATCH v2 13/20] iotests: Restrict some Python tests to file Max Reitz
2020-09-22 10:49 ` [PATCH v2 14/20] iotests: Let _make_test_img guess $TEST_IMG_FILE Max Reitz
2020-09-22 10:49 ` [PATCH v2 15/20] iotests/287: Clean up subshell test image Max Reitz
2020-09-22 10:49 ` [PATCH v2 16/20] storage-daemon: Call bdrv_close_all() on exit Max Reitz
2020-09-22 10:49 ` [PATCH v2 17/20] iotests: Give access to the qemu-storage-daemon Max Reitz
2020-10-15 11:27 ` Kevin Wolf
2020-10-15 15:22 ` Max Reitz
2020-09-22 10:49 ` [PATCH v2 18/20] iotests: Allow testing FUSE exports Max Reitz
2020-10-15 11:43 ` Kevin Wolf
2020-10-15 15:27 ` Max Reitz
2020-09-22 10:49 ` [PATCH v2 19/20] iotests: Enable fuse for many tests Max Reitz
2020-09-22 10:49 ` [PATCH v2 20/20] iotests/308: Add test for FUSE exports Max Reitz
2020-09-22 15:58 ` [PATCH v2 00/20] block/export: Allow exporting BDSs via FUSE Daniel P. Berrangé
2020-09-23 7:21 ` Max Reitz
2020-09-23 9:08 ` Stefan Hajnoczi
2020-10-15 12:01 ` Kevin Wolf
2020-10-15 16:47 ` Max Reitz
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=20200922104932.46384-7-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).