From: Darrick J. Wong <djwong@xxxxxxxxxx> Create hooks in the lowlevel library for syncfs. Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --- include/fuse_lowlevel.h | 16 ++++++++++++++++ lib/fuse_lowlevel.c | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h index f690c62fcdd61c..77685e433e4f7d 100644 --- a/include/fuse_lowlevel.h +++ b/include/fuse_lowlevel.h @@ -1400,6 +1400,22 @@ struct fuse_lowlevel_ops { * @param maxbytes maximum supported file size */ void (*iomap_config) (fuse_req_t req, uint32_t flags, int64_t maxbytes); + + /** + * Flush the entire filesystem to disk. + * + * If this request is answered with an error code of ENOSYS, this is + * treated as a permanent failure, i.e. all future syncfs() requests + * will fail with the same error code without being sent to the + * filesystem process. + * + * Valid replies: + * fuse_reply_err + * + * @param req request handle + * @param ino the inode number + */ + void (*syncfs) (fuse_req_t req, fuse_ino_t ino); #endif /* FUSE_USE_VERSION >= 318 */ }; diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index e31ce96593a9b3..ec30ebc4cdd074 100644 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -2636,6 +2636,23 @@ static void do_iomap_config(fuse_req_t req, const fuse_ino_t nodeid, _do_iomap_config(req, nodeid, inarg, NULL); } +static void _do_syncfs(fuse_req_t req, const fuse_ino_t nodeid, + const void *op_in, const void *in_payload) +{ + (void)op_in; + (void)in_payload; + + if (req->se->op.syncfs) + req->se->op.syncfs(req, nodeid); + else + fuse_reply_err(req, ENOSYS); +} + +static void do_syncfs(fuse_req_t req, const fuse_ino_t nodeid, const void *inarg) +{ + _do_syncfs(req, nodeid, inarg, NULL); +} + static bool want_flags_valid(uint64_t capable, uint64_t want) { uint64_t unknown_flags = want & (~capable); @@ -3609,6 +3626,7 @@ static struct { [FUSE_RENAME2] = { do_rename2, "RENAME2" }, [FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" }, [FUSE_LSEEK] = { do_lseek, "LSEEK" }, + [FUSE_SYNCFS] = { do_syncfs, "SYNCFS" }, [FUSE_IOMAP_CONFIG]= { do_iomap_config, "IOMAP_CONFIG" }, [FUSE_IOMAP_BEGIN] = { do_iomap_begin, "IOMAP_BEGIN" }, [FUSE_IOMAP_END] = { do_iomap_end, "IOMAP_END" }, @@ -3667,6 +3685,7 @@ static struct { [FUSE_RENAME2] = { _do_rename2, "RENAME2" }, [FUSE_COPY_FILE_RANGE] = { _do_copy_file_range, "COPY_FILE_RANGE" }, [FUSE_LSEEK] = { _do_lseek, "LSEEK" }, + [FUSE_SYNCFS] = { _do_syncfs, "SYNCFS" }, [FUSE_IOMAP_CONFIG] = { _do_iomap_config, "IOMAP_CONFIG" }, [FUSE_IOMAP_BEGIN] = { _do_iomap_begin, "IOMAP_BEGIN" }, [FUSE_IOMAP_END] = { _do_iomap_end, "IOMAP_END" },