Skip to content

Commit 27992ef

Browse files
bsberndMiklos Szeredi
authored andcommitted
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 <bschubert@ddn.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 2412085 commit 27992ef

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
@@ -1657,7 +1657,7 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
16571657
goto err;
16581658

16591659
err = -ENAMETOOLONG;
1660-
if (outarg.namelen > FUSE_NAME_MAX)
1660+
if (outarg.namelen > fc->name_max)
16611661
goto err;
16621662

16631663
err = -EINVAL;
@@ -1706,7 +1706,7 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
17061706
goto err;
17071707

17081708
err = -ENAMETOOLONG;
1709-
if (outarg.namelen > FUSE_NAME_MAX)
1709+
if (outarg.namelen > fc->name_max)
17101710
goto err;
17111711

17121712
err = -EINVAL;

fs/fuse/dir.c

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

371371
*inode = NULL;
372372
err = -ENAMETOOLONG;
373-
if (name->len > FUSE_NAME_MAX)
373+
if (name->len > fm->fc->name_max)
374374
goto out;
375375

376376

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
@@ -924,6 +928,9 @@ struct fuse_conn {
924928
/** Version counter for evict inode */
925929
atomic64_t evict_ctr;
926930

931+
/* maximum file name length */
932+
u32 name_max;
933+
927934
/** Called on final put */
928935
void (*release)(struct fuse_conn *);
929936

fs/fuse/inode.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
982982
fc->user_ns = get_user_ns(user_ns);
983983
fc->max_pages = FUSE_DEFAULT_MAX_PAGES_PER_REQ;
984984
fc->max_pages_limit = fuse_max_pages_limit;
985+
fc->name_max = FUSE_NAME_LOW_MAX;
985986
fc->timeout.req_timeout = 0;
986987

987988
if (IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
@@ -1373,6 +1374,13 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
13731374
fc->max_pages =
13741375
min_t(unsigned int, fc->max_pages_limit,
13751376
max_t(unsigned int, arg->max_pages, 1));
1377+
1378+
/*
1379+
* PATH_MAX file names might need two pages for
1380+
* ops like rename
1381+
*/
1382+
if (fc->max_pages > 1)
1383+
fc->name_max = FUSE_NAME_MAX;
13761384
}
13771385
if (IS_ENABLED(CONFIG_FUSE_DAX)) {
13781386
if (flags & FUSE_MAP_ALIGNMENT &&

0 commit comments

Comments
 (0)