[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <176169817837.1429568.4882681255799457147.stgit@frogsfrogsfrogs>
Date: Tue, 28 Oct 2025 18:12:20 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: linux-fsdevel@...r.kernel.org, joannelkoong@...il.com, bernd@...ernd.com,
neal@...pa.dev, miklos@...redi.hu, linux-ext4@...r.kernel.org
Subject: [PATCH 15/17] fuse4fs: separate invalidation
From: Darrick J. Wong <djwong@...nel.org>
Use the new stuff
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
fuse4fs/fuse4fs.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
misc/fuse2fs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+)
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 49b895dfbcc35b..5e66b7103f57f3 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -281,6 +281,9 @@ struct fuse4fs {
enum fuse4fs_iomap_state iomap_state;
uint32_t iomap_dev;
uint64_t iomap_cap;
+ void (*old_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
+ void (*old_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
+ int inuse);
#endif
unsigned int blockmask;
unsigned long offset;
@@ -6720,6 +6723,51 @@ static int fuse4fs_iomap_config_devices(struct fuse4fs *ff)
return 0;
}
+static void fuse4fs_invalidate_bdev(struct fuse4fs *ff, blk64_t blk, blk_t num)
+{
+ off_t offset = FUSE4FS_FSB_TO_B(ff, blk);
+ off_t length = FUSE4FS_FSB_TO_B(ff, num);
+ int ret;
+
+ ret = fuse_lowlevel_iomap_device_invalidate(ff->fuse, ff->iomap_dev,
+ offset, length);
+ if (!ret)
+ return;
+
+ if (num == 1)
+ err_printf(ff, "%s %llu: %s\n",
+ _("error invalidating block"),
+ (unsigned long long)blk,
+ strerror(ret));
+ else
+ err_printf(ff, "%s %llu-%llu: %s\n",
+ _("error invalidating blocks"),
+ (unsigned long long)blk,
+ (unsigned long long)blk + num - 1,
+ strerror(ret));
+}
+
+static void fuse4fs_alloc_stats(ext2_filsys fs, blk64_t blk, int inuse)
+{
+ struct fuse4fs *ff = fs->priv_data;
+
+ if (inuse < 0)
+ fuse4fs_invalidate_bdev(ff, blk, 1);
+ if (ff->old_alloc_stats)
+ ff->old_alloc_stats(fs, blk, inuse);
+}
+
+static void fuse4fs_alloc_stats_range(ext2_filsys fs, blk64_t blk, blk_t num,
+ int inuse)
+{
+ struct fuse4fs *ff = fs->priv_data;
+
+ if (inuse < 0)
+ fuse4fs_invalidate_bdev(ff, blk, num);
+ if (ff->old_alloc_stats_range)
+ ff->old_alloc_stats_range(fs, blk, num, inuse);
+}
+
static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
{
struct fuse_iomap_config cfg = { };
@@ -6764,6 +6812,19 @@ static void op_iomap_config(fuse_req_t req, uint64_t flags, uint64_t maxbytes)
if (ret)
goto out_unlock;
+ /*
+ * If we let iomap do all file block IO, then we need to watch for
+ * freed blocks so that we can invalidate any page cache that might
+ * get written to the block deivce.
+ */
+ if (fuse4fs_iomap_enabled(ff)) {
+ ext2fs_set_block_alloc_stats_callback(ff->fs,
+ fuse4fs_alloc_stats, &ff->old_alloc_stats);
+ ext2fs_set_block_alloc_stats_range_callback(ff->fs,
+ fuse4fs_alloc_stats_range,
+ &ff->old_alloc_stats_range);
+ }
+
out_unlock:
fuse4fs_finish(ff, ret);
if (ret)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 20201265916960..255f8d4b7ae652 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -275,6 +275,9 @@ struct fuse2fs {
enum fuse2fs_iomap_state iomap_state;
uint32_t iomap_dev;
uint64_t iomap_cap;
+ void (*old_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
+ void (*old_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
+ int inuse);
#endif
unsigned int blockmask;
unsigned long offset;
@@ -6253,6 +6256,50 @@ static int fuse2fs_iomap_config_devices(struct fuse2fs *ff)
return 0;
}
+static void fuse2fs_invalidate_bdev(struct fuse2fs *ff, blk64_t blk, blk_t num)
+{
+ off_t offset = FUSE2FS_FSB_TO_B(ff, blk);
+ off_t length = FUSE2FS_FSB_TO_B(ff, num);
+ int ret;
+
+ ret = fuse_fs_iomap_device_invalidate(ff->iomap_dev, offset, length);
+ if (!ret)
+ return;
+
+ if (num == 1)
+ err_printf(ff, "%s %llu: %s\n",
+ _("error invalidating block"),
+ (unsigned long long)blk,
+ strerror(ret));
+ else
+ err_printf(ff, "%s %llu-%llu: %s\n",
+ _("error invalidating blocks"),
+ (unsigned long long)blk,
+ (unsigned long long)blk + num - 1,
+ strerror(ret));
+}
+
+static void fuse2fs_alloc_stats(ext2_filsys fs, blk64_t blk, int inuse)
+{
+ struct fuse2fs *ff = fs->priv_data;
+
+ if (inuse < 0)
+ fuse2fs_invalidate_bdev(ff, blk, 1);
+ if (ff->old_alloc_stats)
+ ff->old_alloc_stats(fs, blk, inuse);
+}
+
+static void fuse2fs_alloc_stats_range(ext2_filsys fs, blk64_t blk, blk_t num,
+ int inuse)
+{
+ struct fuse2fs *ff = fs->priv_data;
+
+ if (inuse < 0)
+ fuse2fs_invalidate_bdev(ff, blk, num);
+ if (ff->old_alloc_stats_range)
+ ff->old_alloc_stats_range(fs, blk, num, inuse);
+}
+
static int op_iomap_config(uint64_t flags, off_t maxbytes,
struct fuse_iomap_config *cfg)
{
@@ -6297,6 +6344,19 @@ static int op_iomap_config(uint64_t flags, off_t maxbytes,
if (ret)
goto out_unlock;
+ /*
+ * If we let iomap do all file block IO, then we need to watch for
+ * freed blocks so that we can invalidate any page cache that might
+ * get written to the block deivce.
+ */
+ if (fuse2fs_iomap_enabled(ff)) {
+ ext2fs_set_block_alloc_stats_callback(ff->fs,
+ fuse2fs_alloc_stats, &ff->old_alloc_stats);
+ ext2fs_set_block_alloc_stats_range_callback(ff->fs,
+ fuse2fs_alloc_stats_range,
+ &ff->old_alloc_stats_range);
+ }
+
out_unlock:
fuse2fs_finish(ff, ret);
return ret;
Powered by blists - more mailing lists