[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174786678417.1385038.7137986464704269574.stgit@frogsfrogsfrogs>
Date: Wed, 21 May 2025 15:43:33 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: linux-ext4@...r.kernel.org
Subject: [PATCH 1/7] fuse2fs: use file handles when possible
From: Darrick J. Wong <djwong@...nel.org>
Use file handles when possible, so the f* family of file syscalls
doesn't have to do a complete path lookup for every single call.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
misc/fuse2fs.c | 90 +++++++++++++++++++++++++++++++++++---------------------
1 file changed, 56 insertions(+), 34 deletions(-)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 9c1e5b00703bbe..de5cfa3d776127 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -737,6 +737,7 @@ static void *op_init(struct fuse_conn_info *conn
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
conn->time_gran = 1;
cfg->use_ino = 1;
+ cfg->nullpath_ok = 1;
#endif
if (fs->flags & EXT2_FLAG_RW) {
fs->super->s_mnt_count++;
@@ -802,9 +803,49 @@ static int stat_inode(ext2_filsys fs, ext2_ino_t ino, struct stat *statbuf)
return ret;
}
+static int __path_or_file_info_to_ino(struct fuse2fs *ff, const char *path,
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ struct fuse_file_info *fp EXT2FS_ATTR((unused)),
+#endif
+ ext2_ino_t *inop,
+ const char *func,
+ int line)
+{
+ ext2_filsys fs = ff->fs;
+ errcode_t err;
+
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+ if (fp) {
+ struct fuse2fs_file_handle *fh =
+ (struct fuse2fs_file_handle *)(uintptr_t)fp->fh;
+
+ if (fh->ino == 0)
+ return -ESTALE;
+
+ *inop = fh->ino;
+ dbg_printf(ff, "%s: get ino=%d\n", func, fh->ino);
+ return 0;
+ }
+#endif
+ dbg_printf(ff, "%s: get path=%s\n", func, path);
+ err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, inop);
+ if (err)
+ return __translate_error(fs, 0, err, func, line);
+
+ return 0;
+}
+
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+# define path_or_file_info_to_ino(ff, path, fp, inop) \
+ __path_or_file_info_to_ino((ff), (path), (fp), (inop), __func__, __LINE__)
+#else
+# define path_or_file_info_to_ino(ff, path, fp, inop) \
+ __path_or_file_info_to_ino((ff), (path), NULL, (inop), __func__, __LINE__)
+#endif
+
static int op_getattr(const char *path, struct stat *statbuf
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
- , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+ , struct fuse_file_info *fi
#endif
)
{
@@ -812,18 +853,14 @@ static int op_getattr(const char *path, struct stat *statbuf
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
ext2_filsys fs;
ext2_ino_t ino;
- errcode_t err;
int ret = 0;
FUSE2FS_CHECK_CONTEXT(ff);
fs = ff->fs;
- dbg_printf(ff, "%s: path=%s\n", __func__, path);
pthread_mutex_lock(&ff->bfl);
- err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino);
- if (err) {
- ret = translate_error(fs, 0, err);
+ ret = path_or_file_info_to_ino(ff, path, fi, &ino);
+ if (ret)
goto out;
- }
ret = stat_inode(fs, ino, statbuf);
out:
pthread_mutex_unlock(&ff->bfl);
@@ -2108,7 +2145,7 @@ static int in_file_group(struct fuse_context *ctxt,
static int op_chmod(const char *path, mode_t mode
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
- , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+ , struct fuse_file_info *fi
#endif
)
{
@@ -2123,11 +2160,9 @@ static int op_chmod(const char *path, mode_t mode
FUSE2FS_CHECK_CONTEXT(ff);
fs = ff->fs;
pthread_mutex_lock(&ff->bfl);
- err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino);
- if (err) {
- ret = translate_error(fs, 0, err);
+ ret = path_or_file_info_to_ino(ff, path, fi, &ino);
+ if (ret)
goto out;
- }
dbg_printf(ff, "%s: path=%s mode=0%o ino=%d\n", __func__, path, mode, ino);
err = fuse2fs_read_inode(fs, ino, &inode);
@@ -2182,7 +2217,7 @@ static int op_chmod(const char *path, mode_t mode
static int op_chown(const char *path, uid_t owner, gid_t group
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
- , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+ , struct fuse_file_info *fi
#endif
)
{
@@ -2197,11 +2232,9 @@ static int op_chown(const char *path, uid_t owner, gid_t group
FUSE2FS_CHECK_CONTEXT(ff);
fs = ff->fs;
pthread_mutex_lock(&ff->bfl);
- err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino);
- if (err) {
- ret = translate_error(fs, 0, err);
+ ret = path_or_file_info_to_ino(ff, path, fi, &ino);
+ if (ret)
goto out;
- }
dbg_printf(ff, "%s: path=%s owner=%d group=%d ino=%d\n", __func__,
path, owner, group, ino);
@@ -2324,29 +2357,20 @@ static int truncate_helper(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
static int op_truncate(const char *path, off_t len
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
- , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+ , struct fuse_file_info *fi
#endif
)
{
struct fuse_context *ctxt = fuse_get_context();
struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
- ext2_filsys fs;
ext2_ino_t ino;
- errcode_t err;
int ret = 0;
FUSE2FS_CHECK_CONTEXT(ff);
- fs = ff->fs;
pthread_mutex_lock(&ff->bfl);
- err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino);
- if (err) {
- ret = translate_error(fs, 0, err);
+ ret = path_or_file_info_to_ino(ff, path, fi, &ino);
+ if (ret)
goto out;
- }
- if (!ino) {
- ret = -ESTALE;
- goto out;
- }
dbg_printf(ff, "%s: ino=%d len=%jd\n", __func__, ino, len);
ret = check_inum_access(ff, ino, W_OK);
@@ -3412,7 +3436,7 @@ static int op_fgetattr(const char *path EXT2FS_ATTR((unused)),
static int op_utimens(const char *path, const struct timespec ctv[2]
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
- , struct fuse_file_info *fi EXT2FS_ATTR((unused))
+ , struct fuse_file_info *fi
#endif
)
{
@@ -3429,11 +3453,9 @@ static int op_utimens(const char *path, const struct timespec ctv[2]
FUSE2FS_CHECK_CONTEXT(ff);
fs = ff->fs;
pthread_mutex_lock(&ff->bfl);
- err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, path, &ino);
- if (err) {
- ret = translate_error(fs, 0, err);
+ ret = path_or_file_info_to_ino(ff, path, fi, &ino);
+ if (ret)
goto out;
- }
dbg_printf(ff, "%s: ino=%d atime=%lld.%ld mtime=%lld.%ld\n", __func__,
ino,
(long long int)ctv[0].tv_sec, ctv[0].tv_nsec,
Powered by blists - more mailing lists