[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <175573714037.21970.5650928421627307752.stgit@frogsfrogsfrogs>
Date: Wed, 20 Aug 2025 18:20:08 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: John@...ves.net, bernd@...ernd.com, linux-fsdevel@...r.kernel.org,
linux-ext4@...r.kernel.org, miklos@...redi.hu, joannelkoong@...il.com,
neal@...pa.dev
Subject: [PATCH 17/19] fuse4fs: separate invalidation
From: Darrick J. Wong <djwong@...nel.org>
Use the new stuff
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
misc/fuse2fs.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
misc/fuse4fs.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 874fe3bbcc3b9f..cc835f894122a4 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -277,6 +277,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;
@@ -5927,6 +5930,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)
{
@@ -5971,6 +6018,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;
diff --git a/misc/fuse4fs.c b/misc/fuse4fs.c
index 5127712e19e6f9..2371b9b37cc16a 100644
--- a/misc/fuse4fs.c
+++ b/misc/fuse4fs.c
@@ -273,6 +273,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;
@@ -6250,6 +6253,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 = { };
@@ -6294,6 +6342,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)
Powered by blists - more mailing lists