From: Darrick J. Wong <djwong@xxxxxxxxxx> Support syncfs in the upper level library. Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --- include/fuse.h | 5 +++++ lib/fuse.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/fuse.h b/include/fuse.h index f8a57154017a2a..baf7a2e90af5e7 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -903,6 +903,11 @@ struct fuse_operations { */ int (*iomap_config) (uint64_t supported_flags, off_t maxbytes, struct fuse_iomap_config *cfg); + + /** + * Flush the entire filesystem to disk. + */ + int (*syncfs) (const char *path); }; /** Extra context that may be needed by some filesystems diff --git a/lib/fuse.c b/lib/fuse.c index 7b28f848116abb..4e207491532e8b 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -2993,6 +2993,16 @@ int fuse_fs_iomap_inval(uint64_t nodeid, uint64_t attr_ino, loff_t read_off, &write); } +static int fuse_fs_syncfs(struct fuse_fs *fs, const char *path) +{ + fuse_get_context()->private_data = fs->user_data; + if (!fs->op.syncfs) + return -ENOSYS; + if (fs->debug) + fuse_log(FUSE_LOG_DEBUG, "syncfs[%s]\n", path); + return fs->op.syncfs(path); +} + static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr, int valid, struct fuse_file_info *fi) { @@ -4866,6 +4876,26 @@ static void fuse_lib_iomap_config(fuse_req_t req, uint64_t flags, fuse_reply_iomap_config(req, &cfg); } +static void fuse_lib_syncfs(fuse_req_t req, fuse_ino_t ino) +{ + struct fuse *f = req_fuse_prepare(req); + struct fuse_intr_data d; + char *path; + int err; + + err = get_path(f, ino, &path); + if (err) { + reply_err(req, err); + return; + } + + fuse_prepare_interrupt(f, req, &d); + err = fuse_fs_syncfs(f->fs, path); + fuse_finish_interrupt(f, req, &d); + free_path(f, ino, path); + reply_err(req, err); +} + static int clean_delay(struct fuse *f) { /* @@ -4967,6 +4997,7 @@ static struct fuse_lowlevel_ops fuse_path_ops = { #ifdef HAVE_STATX .statx = fuse_lib_statx, #endif + .syncfs = fuse_lib_syncfs, .iomap_begin = fuse_lib_iomap_begin, .iomap_end = fuse_lib_iomap_end, .iomap_ioend = fuse_lib_iomap_ioend,