Re: [RFC PATCH v3 7/8] selftests/fuse: add fuse symlink caching test
From: Luis Henriques
Date: Mon Sep 07 2026 - 07:12:11 EST
On Sat, Sep 05 2026, Amir Goldstein wrote:
> On Fri, Sep 4, 2026 at 12:38 PM Luis Henriques <luis@xxxxxxxxxx> wrote:
>>
>> This patch adds a simple test that allows to verify that, when resolving a
>> symlink, user-space is called only the first time when caching is enabled
>> or, if caching is disabled, every time the symlink resolution is requested.
>>
>> Signed-off-by: Luis Henriques <luis@xxxxxxxxxx>
>> ---
>> .../selftests/filesystems/fuse/.gitignore | 1 +
>> .../selftests/filesystems/fuse/Makefile | 2 +
>> .../fuse/fuse_symlink_cache_test.c | 167 ++++++++++++++++++
>> 3 files changed, 170 insertions(+)
>> create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_symlink_cache_test.c
>>
>> diff --git a/tools/testing/selftests/filesystems/fuse/.gitignore b/tools/testing/selftests/filesystems/fuse/.gitignore
>> index f7f3dd345a50..ebfe7133d811 100644
>> --- a/tools/testing/selftests/filesystems/fuse/.gitignore
>> +++ b/tools/testing/selftests/filesystems/fuse/.gitignore
>> @@ -3,3 +3,4 @@ fuse_mnt
>> fusectl_test
>> write_extend_eof_test
>> fuse_acl_cache_test
>> +fuse_symlink_cache_test
>> diff --git a/tools/testing/selftests/filesystems/fuse/Makefile b/tools/testing/selftests/filesystems/fuse/Makefile
>> index 7744f796eb06..3a5a557dde7a 100644
>> --- a/tools/testing/selftests/filesystems/fuse/Makefile
>> +++ b/tools/testing/selftests/filesystems/fuse/Makefile
>> @@ -5,6 +5,7 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
>> TEST_GEN_PROGS := fusectl_test
>> TEST_GEN_PROGS += write_extend_eof_test
>> TEST_GEN_PROGS += fuse_acl_cache_test
>> +TEST_GEN_PROGS += fuse_symlink_cache_test
>> TEST_GEN_FILES := fuse_mnt
>>
>> include ../../lib.mk
>> @@ -28,5 +29,6 @@ $(OUTPUT)/fuse_mnt: CFLAGS += $(VAR_CFLAGS)
>> $(OUTPUT)/fuse_mnt: LDLIBS += $(VAR_LDLIBS)
>>
>> $(OUTPUT)/fuse_acl_cache_test: fuse_common.c fuse_acl_cache_test.c
>> +$(OUTPUT)/fuse_symlink_cache_test: fuse_common.c fuse_symlink_cache_test.c
>>
>> EXTRA_CLEAN := fuse_common.o
>> diff --git a/tools/testing/selftests/filesystems/fuse/fuse_symlink_cache_test.c b/tools/testing/selftests/filesystems/fuse/fuse_symlink_cache_test.c
>> new file mode 100644
>> index 000000000000..ca3c5cdaf578
>> --- /dev/null
>> +++ b/tools/testing/selftests/filesystems/fuse/fuse_symlink_cache_test.c
>> @@ -0,0 +1,167 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Simple filesystem to test FUSE symlink cache
>> + *
>> + * This is a simple FUSE filesystem that contains two objects: a file named
>> + * 'file' and a symlink to that file named 'link'. If symlink caching is
>> + * disabled (i.e. FUSE_CAP_CACHE_SYMLINKS is reset during FUSE_INIT), whenever
>> + * the ->readlink() is executed to resolve 'link' a counter will be incremented.
>> + *
>> + * If symlink caching is enabled (i.e. FUSE_CAP_CACHE_SYMLINKS is set during
>> + * FUSE_INIT), resolving a symlink will only call into user-space the first
>> + * time.
>> + */
>> +
>> +#define FUSE_USE_VERSION 31
>> +
>> +#include <stdio.h>
>> +#include <limits.h>
>> +#include <fuse_lowlevel.h>
>> +
>> +#include "kselftest_harness.h"
>> +
>> +#include "fuse_common.h"
>> +
>> +#define FILENAME "file"
>> +#define FILE_INO 42
>> +
>> +#define LINKNAME "link"
>> +#define LINK_INO 43
>> +
>> +#define TIMEOUT 86400.0f
>> +
>> +struct test_state {
>> + pthread_mutex_t lock;
>> + bool cache;
>> + int readlink_counter;
>> +} test_state = {
>> + .lock = PTHREAD_MUTEX_INITIALIZER,
>> +};
>> +
>> +static void fs_init(void *userdata, struct fuse_conn_info *conn)
>> +{
>> + pthread_mutex_lock(&test_state.lock);
>> + if (test_state.cache)
>> + fuse_set_feature_flag(conn, FUSE_CAP_CACHE_SYMLINKS);
>> + else
>> + fuse_unset_feature_flag(conn, FUSE_CAP_CACHE_SYMLINKS);
>> + pthread_mutex_unlock(&test_state.lock);
>> +}
>> +
>> +static void fs_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
>> +{
>> + struct fuse_entry_param e = {};
>> +
>> + if (parent != FUSE_ROOT_ID ||
>> + (!strcmp(name, FILENAME) && !(strcmp(name, LINKNAME))))
>
> You probably meant strcmp() != 0 ...
> Did you miss this Sashiko comment?
Oops! I did fix one similar comment (probably in a different test) but
missed this one. I'll fix it for the next iteration. (And I'll still
need to have a look at sashiko again for any new comments for this
revision).
Cheers,
--
Luís