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 for-6.0 v3 06/20] fuse: Implement hole detection through lseek
Date: Tue, 27 Oct 2020 20:05:46 +0100 [thread overview]
Message-ID: <20201027190600.192171-7-mreitz@redhat.com> (raw)
In-Reply-To: <20201027190600.192171-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 add a dedicated
check whether it is available before making use of it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
configure | 8 ++++-
meson.build | 20 ++++++++++++
block/export/fuse.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
meson_options.txt | 2 ++
4 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/configure b/configure
index fc315deebe..f74b7ef3f4 100755
--- a/configure
+++ b/configure
@@ -449,6 +449,7 @@ ninja=""
skip_meson=no
gettext=""
fuse="auto"
+fuse_lseek="auto"
bogus_os="no"
malloc_trim="auto"
@@ -1524,6 +1525,10 @@ for opt do
;;
--disable-fuse) fuse="disabled"
;;
+ --enable-fuse-lseek) fuse_lseek="enabled"
+ ;;
+ --disable-fuse-lseek) fuse_lseek="disabled"
+ ;;
*)
echo "ERROR: unknown option $opt"
echo "Try '$0 --help' for more information"
@@ -1847,6 +1852,7 @@ disabled with --disable-FEATURE, default is enabled if available:
rng-none dummy RNG, avoid using /dev/(u)random and getrandom()
libdaxctl libdaxctl support
fuse FUSE block device export
+ fuse-lseek SEEK_HOLE/SEEK_DATA support for FUSE exports
NOTE: The object files are built at the place where configure is launched
EOF
@@ -6988,7 +6994,7 @@ NINJA=$ninja $meson setup \
-Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
-Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
-Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
- -Dfuse=$fuse \
+ -Dfuse=$fuse -Dfuse_lseek=$fuse_lseek \
$cross_arg \
"$PWD" "$source_path"
diff --git a/meson.build b/meson.build
index 4e8436b456..ea1a68b46d 100644
--- a/meson.build
+++ b/meson.build
@@ -736,10 +736,28 @@ if not has_malloc_trim and get_option('malloc_trim').enabled()
endif
endif
+if get_option('fuse').disabled() and get_option('fuse_lseek').enabled()
+ error('Cannot enable fuse-lseek while fuse is disabled')
+endif
+
fuse = dependency('fuse3', required: get_option('fuse'),
version: '>=3.1', method: 'pkg-config',
static: enable_static)
+fuse_lseek = not_found
+if not get_option('fuse_lseek').disabled()
+ if fuse.version().version_compare('>=3.8')
+ # Dummy dependency
+ fuse_lseek = declare_dependency()
+ elif get_option('fuse_lseek').enabled()
+ if fuse.found()
+ error('fuse-lseek requires libfuse >=3.8, found ' + fuse.version())
+ else
+ error('fuse-lseek requires libfuse, which was not found')
+ endif
+ endif
+endif
+
#################
# config-host.h #
#################
@@ -773,6 +791,7 @@ config_host_data.set('CONFIG_KEYUTILS', keyutils.found())
config_host_data.set('CONFIG_GETTID', has_gettid)
config_host_data.set('CONFIG_MALLOC_TRIM', has_malloc_trim)
config_host_data.set('CONFIG_FUSE', fuse.found())
+config_host_data.set('CONFIG_FUSE_LSEEK', fuse_lseek.found())
config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
@@ -2169,6 +2188,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': fuse.found()}
+summary_info += {'FUSE lseek': fuse_lseek.found()}
summary(summary_info, bool_yn: true)
if not supported_cpus.contains(cpu)
diff --git a/block/export/fuse.c b/block/export/fuse.c
index 0b9d226b2f..38f74c94da 100644
--- a/block/export/fuse.c
+++ b/block/export/fuse.c
@@ -627,6 +627,80 @@ static void fuse_flush(fuse_req_t req, fuse_ino_t inode,
fuse_fsync(req, inode, 1, fi);
}
+#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 = {
.init = fuse_init,
.lookup = fuse_lookup,
@@ -638,6 +712,9 @@ static const struct fuse_lowlevel_ops fuse_ops = {
.fallocate = fuse_fallocate,
.flush = fuse_flush,
.fsync = fuse_fsync,
+#ifdef CONFIG_FUSE_LSEEK
+ .lseek = fuse_lseek,
+#endif
};
const BlockExportDriver blk_exp_fuse = {
diff --git a/meson_options.txt b/meson_options.txt
index 2ef4ec628f..f9e7d89f9d 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -66,6 +66,8 @@ option('virtiofsd', type: 'feature', value: 'auto',
description: 'build virtiofs daemon (virtiofsd)')
option('fuse', type: 'feature', value: 'auto',
description: 'FUSE block device export')
+option('fuse_lseek', type : 'feature', value : 'auto',
+ description: 'SEEK_HOLE/SEEK_DATA support for FUSE exports')
option('capstone', type: 'combo', value: 'auto',
choices: ['disabled', 'enabled', 'auto', 'system', 'internal'],
--
2.26.2
next prev parent reply other threads:[~2020-10-27 19:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 19:05 [PATCH for-6.0 v3 00/20] block/export: Allow exporting BDSs via FUSE Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 01/20] meson: Detect libfuse Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 02/20] fuse: Allow exporting BDSs via FUSE Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 03/20] fuse: Implement standard FUSE operations Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 04/20] fuse: Allow growable exports Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 05/20] fuse: (Partially) implement fallocate() Max Reitz
2020-10-27 19:05 ` Max Reitz [this message]
2020-10-27 19:05 ` [PATCH for-6.0 v3 07/20] iotests: Do not needlessly filter _make_test_img Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 08/20] iotests: Do not pipe _make_test_img Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 09/20] iotests: Use convert -n in some cases Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 10/20] iotests/046: Avoid renaming images Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 11/20] iotests: Derive image names from $TEST_IMG Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 12/20] iotests/091: Use _cleanup_qemu instad of "wait" Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 13/20] iotests: Restrict some Python tests to file Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 14/20] iotests: Let _make_test_img guess $TEST_IMG_FILE Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 15/20] iotests/287: Clean up subshell test image Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 16/20] storage-daemon: Call bdrv_close_all() on exit Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 17/20] iotests: Give access to the qemu-storage-daemon Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 18/20] iotests: Allow testing FUSE exports Max Reitz
2020-10-27 19:05 ` [PATCH for-6.0 v3 19/20] iotests: Enable fuse for many tests Max Reitz
2020-10-27 19:06 ` [PATCH for-6.0 v3 20/20] iotests/308: Add test for FUSE exports Max Reitz
2020-12-07 15:15 ` [PATCH for-6.0 v3 00/20] block/export: Allow exporting BDSs via FUSE Kevin Wolf
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=20201027190600.192171-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).