Skip to content

Commit 573e7ab

Browse files
committed
fuse: Increase FUSE_NAME_MAX to PATH_MAX
Our file system has a translation capability for S3-to-posix. The current value of 1kiB is enough to cover S3 keys, but does not allow encoding of %xx escape characters. The limit is increased to (PATH_MAX - 1), as we need 3 x 1024 and that is close to PATH_MAX (4kB) already. -1 is used as the terminating null is not included in the length calculation. Testing large file names was hard with libfuse/example file systems, so I created a new memfs that does not have a 255 file name length limitation. libfuse/libfuse#1077 The connection is initialized with FUSE_NAME_LOW_MAX, which is set to the previous value of FUSE_NAME_MAX of 1024. With FUSE_MIN_READ_BUFFER of 8192 that is enough for two file names + fuse headers. When FUSE_INIT reply sets max_pages to a value > 1 we know that fuse daemon supports request buffers of at least 2 pages (+ header) and can therefore hold 2 x PATH_MAX file names - operations like rename or link that need two file names are no issue then. Signed-off-by: Bernd Schubert <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]> (cherry picked from commit 27992ef)
1 parent 4a7f142 commit 573e7ab

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

fs/fuse/dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
15031503
goto err;
15041504

15051505
err = -ENAMETOOLONG;
1506-
if (outarg.namelen > FUSE_NAME_MAX)
1506+
if (outarg.namelen > fc->name_max)
15071507
goto err;
15081508

15091509
err = -EINVAL;
@@ -1552,7 +1552,7 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
15521552
goto err;
15531553

15541554
err = -ENAMETOOLONG;
1555-
if (outarg.namelen > FUSE_NAME_MAX)
1555+
if (outarg.namelen > fc->name_max)
15561556
goto err;
15571557

15581558
err = -EINVAL;

fs/fuse/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name
372372

373373
*inode = NULL;
374374
err = -ENAMETOOLONG;
375-
if (name->len > FUSE_NAME_MAX)
375+
if (name->len > fm->fc->name_max)
376376
goto out;
377377

378378

fs/fuse/fuse_i.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838
/** Bias for fi->writectr, meaning new writepages must not be sent */
3939
#define FUSE_NOWRITE INT_MIN
4040

41-
/** It could be as large as PATH_MAX, but would that have any uses? */
42-
#define FUSE_NAME_MAX 1024
41+
/** Maximum length of a filename, not including terminating null */
42+
43+
/* maximum, small enough for FUSE_MIN_READ_BUFFER*/
44+
#define FUSE_NAME_LOW_MAX 1024
45+
/* maximum, but needs a request buffer > FUSE_MIN_READ_BUFFER */
46+
#define FUSE_NAME_MAX (PATH_MAX - 1)
4347

4448
/** Number of dentries for each connection in the control filesystem */
4549
#define FUSE_CTL_NUM_DENTRIES 5
@@ -857,6 +861,9 @@ struct fuse_conn {
857861
/** Version counter for evict inode */
858862
atomic64_t evict_ctr;
859863

864+
/* maximum file name length */
865+
u32 name_max;
866+
860867
/** Called on final put */
861868
void (*release)(struct fuse_conn *);
862869

fs/fuse/inode.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
976976
fc->user_ns = get_user_ns(user_ns);
977977
fc->max_pages = FUSE_DEFAULT_MAX_PAGES_PER_REQ;
978978
fc->max_pages_limit = fuse_max_pages_limit;
979+
fc->name_max = FUSE_NAME_LOW_MAX;
979980

980981
INIT_LIST_HEAD(&fc->mounts);
981982
list_add(&fm->fc_entry, &fc->mounts);
@@ -1325,6 +1326,13 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
13251326
fc->max_pages =
13261327
min_t(unsigned int, fc->max_pages_limit,
13271328
max_t(unsigned int, arg->max_pages, 1));
1329+
1330+
/*
1331+
* PATH_MAX file names might need two pages for
1332+
* ops like rename
1333+
*/
1334+
if (fc->max_pages > 1)
1335+
fc->name_max = FUSE_NAME_MAX;
13281336
}
13291337
if (IS_ENABLED(CONFIG_FUSE_DAX)) {
13301338
if (flags & FUSE_MAP_ALIGNMENT &&

0 commit comments

Comments
 (0)