fuse: caches documentation and testing
Subsystems (3)
v2 cover fuse: caches documentation and testing
Hi!
I'm (finally!) sending v2 of this patchset. It tries to document (and add a few kselftests) to the different types of caches that are currently in use within FUSE. As I mentioned in v1 the idea for documenting this came from Miklos during this year's LSFMM, where he mentioned he would like to see caches usage documented before he could merge an initial version of fusex.
This version documents symlinks, attributes, ACLs and readdir caches. Still
missing: dentries and data caching.
I'm still sending it as an RFC as I'm still not sure if it fulfils Miklos' initial goal.
As usual feedback is welcome, as I'll (slowly) continue looking into other cache types.
Major changes since v1:
- Added more caches to the document
- Changed tests format to single self-contained binaries
- Since Amir added a new fuse3-based test, the conversion to fuse3 of the fusectl has minor changes to the Makefile
- NOTE: I've kept Amir's Reviewed-by anyway (should I drop it?)
- Added the ACL test-cases to the new ACL test implemented by Amir
- This required some re-work of the existing test (patches 5 & 6)
- Added more tests
Luis Henriques (8):
Documentation: fuse: add document on caches being used by FUSE selftests/fuse: convert fusectl test to fuse3 selftests/fuse: check that fusectlfs is mounted selftests/fuse: add fuse symlink caching test selftests/fuse: factor-out test fixture setup/teardown selftests/fuse: use dynamically allocated memory to store ACLs selftests/fuse: add some extra ACL caching tests selftests/fuse: add fuse readdir caching test
.../filesystems/fuse/fuse-caches.rst | 142 ++++++++ .../selftests/filesystems/fuse/.gitignore | 3 + .../selftests/filesystems/fuse/Makefile | 28 +- .../filesystems/fuse/fuse_acl_cache_test.c | 289 ++++++++++++++-- .../selftests/filesystems/fuse/fuse_mnt.c | 17 +- .../fuse/fuse_readdir_cache_test.c | 314 ++++++++++++++++++ .../fuse/fuse_symlink_cache_test.c | 204 ++++++++++++ .../selftests/filesystems/fuse/fusectl_test.c | 7 + 8 files changed, 950 insertions(+), 54 deletions(-) create mode 100644 Documentation/filesystems/fuse/fuse-caches.rst create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_readdir_cache_test.c create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_symlink_cache_test.c
RFC PATCH v2 1/8 Documentation: fuse: add document on caches being used by FUSE
This new file aims at documenting the caches that are used by FUSE. At the moment only symlink, attributes, ACLs and readdir caches are described.
--- .../filesystems/fuse/fuse-caches.rst | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Documentation/filesystems/fuse/fuse-caches.rst
Documentation/filesystems/fuse/fuse-caches.rst new file +142 -0
@@ -0,0 +1,142 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========== +FUSE Caches +=========== + +Introduction +============ + +This document summarises the different types of caches that are used in FUSE. +For each cache type, it attempts to document the rules that are followed to +insert, validate and invalidate data into the cache. + +symlink caching +=============== + +Whenever there's a link resolution request, the VFS will call into +``fuse_get_link()`` which will then send a ``FUSE_READLINK`` request to the +user-space FUSE server. However, the server can ask the kernel to cache all +links resolutions by setting the ``FUSE_CACHE_SYMLINKS`` flag during the +``FUSE_INIT`` negotiation. + +If this flag is set, FUSE will immediately call into the VFS +``__page_get_link()`` from the ``->get_link()`` inode operation. The first time +this is done for a specific link, it will end-up sending the ``FUSE_READLINK`` +to user-space but the link contents will then be added into page-cache. The next +time the link needs to be resolved, it will use the link content that is already +cached, and will only fallback into sending the request to use-space if the +folio isn't up-to-date. + +Attributes caching +================== + +Attributes obtained from user-space, for example when an inode is first +looked-up, are cached in the kernel. However, these attributes have a timeout +associated and once expired they are invalidated. + +Thus, the ``FUSE_GETATTR`` operation will be sent to user-space only if the +attributes aren't yet available, the attributes aren't valid (timeout), or if +there is an explicit request for doing so (for example, by using the +``AT_STATX_FORCE_SYNC`` flag in ``statx``). This may happen in the following +situations: + +#. An explicit request from VFS to get the attributes for an inode (through the + ``->getattr()`` callback). +#. When an ``->llseek()`` is requested to FUSE with a type of request + (``whence``): + + - ``SEEK_{HOLE,DATA}`` and the user-space doesn't implement the + ``FUSE_LSEEK`` operation (it has returned ``ENOSYS``), or + - ``SEEK_END`` + +#. When doing a buffered read past EOF or automatic page cache invalidation mode + is enabled (``FUSE_AUTO_INVAL_DATA``). +#. When doing a buffered write with write-back cache enabled + (``FUSE_CAP_WRITEBACK_CACHE``). + +ACL caching +=========== + +FUSE has allowed the usage of POSIX ACLs for a long time as they could be set +and accessed simply as extended attributes. However, it was only with the +addition of the ``FUSE_POSIX_ACL`` flag that ACLs started to be fully supported. +Without this flag, ACLs can still be set, but the VFS won't use them for +performing permission checks - that would be the user-space server's +responsibility. + +Also, without setting ``FUSE_POSIX_ACL``, ACLs will not be cached by the kernel. +In this case, new inodes ``i_acl`` and ``i_default_acl`` fields will be set to +``ACL_DONT_CACHE``. + +On the other hand, if ``FUSE_POSIX_ACL`` is set during ``FUSE_INIT``, when an +ACL is accessed the VFS layer will first check if it's already cached. If it is +not, FUSE ``->get_acl`` operation is called, which will eventually send a +user-space request. Future accesses to this inode ACL will then use the cached +data. + +Setting an ACL in an inode, however, won't cache it immediately. It will send +user-space a request with the new ACL, and the FUSE server may perform some +modifications before storing it. + +On the other hand, ACLs will be removed for the cache in the following +situations: + +- When setting an ACL in an inode and the user-space server has set the + ``FUSE_POSIX_ACL`` flag, all previously cached ACLs for this inode will be + invalidated. +- When invalidating an inode through the ``FUSE_NOTIFY_INVAL_INODE`` operation. +- When ``->d_revalidate()`` is called for a dentry that requires a lookup (e.g. + it has expired) and that lookup operation is successful. +- When the VFS needs to check access rights for an inode (by calling + ``->permission()``), attributes may need to be refreshed. If that happens, + any cached ACLs for that inode will be invalidated. +- After setting an inode attribute (i.e. operation ``FUSE_SETATTR`` is sent to + user-space), the user-space server may have also updated the ACLs, so any + cached ACLs for this inode are also invalidated. +- While processing ``FUSE_READDIRPLUS`` and a new dentry is added (unless this + dentry is already being looked up (``DCACHE_PAR_LOOKUP``)) +- In general, when there is the need to sent a ``FUSE_STATX`` or + ``FUSE_GETATTR`` to user-space (e.g. because the attributes have expired). + This may happen in the following cases: + + - When doing an ``->llseek()`` on a file with ``SEEK_END``, ``SEEK_HOLE`` or + ``SEEK_DATA``. + - When the ``FUSE_AUTO_INVAL_DATA`` flag is set at ``INIT`` time (to + automatically invalidate cached pages), and a buffered read + (``->read_iter()``) past EOF is done on a non-passthrough file. + - When the ``FUSE_WRITEBACK_CACHE`` flag is set at ``INIT`` time, and a + buffered write (``->write_iter()``) past EOF is done on a non-passthrough + file. + - When the ``FUSE_AUTO_INVAL_DATA`` flag is set at ``INIT`` time and the VFS + needs to read a directory contents (``->iterate_shared()``) for a + directory that is allowed to be cached. + +readdir caching +=============== + +When opening a directory for doing a readdir, a ``FUSE_OPENDIR`` will be sent +and the user-space server will be responsible for setting the open flags related +with caching, namely ``FOPEN_KEEP_CACHE`` and ``FOPEN_CACHE_DIR``. + +If neither flags are set by the user-space FUSE server, then every ``readdir`` +will result in a ``FUSE_READDIR`` (or ``FUSE_READDIRPLUS``) request being sent. +If ``FOPEN_CACHE_DIR`` is set by the server, then the result of a ``readdir`` +will be cached by the kernel and reused. However, if ``FOPEN_KEEP_CACHE`` isn't +also set, the cache will be invalidated next time the directory is open. + +The readdir cache will also expire and resetted in the following situations if: + +- The inode ``mtime`` doesn't match the cache ``mtime``, +- The inode ``iversion`` doesn't match the cache ``iversion``, +- The FUSE connection ``epoch`` doesn't match the cache ``epoch``. + +dentry caching +============== + +TBD + +data caching +============ + +TBD
Re: [RFC PATCH v2 1/8] Documentation: fuse: add document on caches being used by FUSE
Quoted 48 lines · Luis Henriques
This new file aims at documenting the caches that are used by FUSE. At the moment only symlink, attributes, ACLs and readdir caches are described.
Signed-off-by Luis Henriques <[email protected]>--- .../filesystems/fuse/fuse-caches.rst | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Documentation/filesystems/fuse/fuse-caches.rstDocumentation/filesystems/fuse/fuse-caches.rst new file +32
-0@@ -0,0 +1,142 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========== +FUSE Caches +=========== + +Introduction +============ + +This document summarises the different types of caches that are used in FUSE. +For each cache type, it attempts to document the rules that are followed to +insert, validate and invalidate data into the cache. + +symlink caching +=============== + +Whenever there's a link resolution request, the VFS will call into +``fuse_get_link()`` which will then send a ``FUSE_READLINK`` request to the +user-space FUSE server. However, the server can ask the kernel to cache all +links resolutions by setting the ``FUSE_CACHE_SYMLINKS`` flag during the +``FUSE_INIT`` negotiation. + +If this flag is set, FUSE will immediately call into the VFS +``__page_get_link()`` from the ``->get_link()`` inode operation. The first time +this is done for a specific link, it will end-up sending the ``FUSE_READLINK`` +to user-space but the link contents will then be added into page-cache. The next +time the link needs to be resolved, it will use the link content that is already +cached, and will only fallback into sending the request to use-space if the +folio isn't up-to-date. + +Attributes caching +==================
Documentation/filesystems/fuse/fuse-caches.rst line 42
Quoted 10 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +10
-0+ +Attributes obtained from user-space, for example when an inode is first +looked-up, are cached in the kernel. However, these attributes have a timeout +associated and once expired they are invalidated. + +Thus, the ``FUSE_GETATTR`` operation will be sent to user-space only if the +attributes aren't yet available, the attributes aren't valid (timeout), or if +there is an explicit request for doing so (for example, by using the +``AT_STATX_FORCE_SYNC`` flag in ``statx``). This may happen in the following +situations:
"This may happen" what may happen? I don't see it referring to anything.
Quoted 4 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +4
-0+ +#. An explicit request from VFS to get the attributes for an inode (through the + ``->getattr()`` callback). +#. When an ``->llseek()`` is requested to FUSE with a type of request
Documentation/filesystems/fuse/fuse-caches.rst line 56
Quoted 10 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +10
-0+ (``whence``): + + - ``SEEK_{HOLE,DATA}`` and the user-space doesn't implement the + ``FUSE_LSEEK`` operation (it has returned ``ENOSYS``), or + - ``SEEK_END`` + +#. When doing a buffered read past EOF or automatic page cache invalidation mode + is enabled (``FUSE_AUTO_INVAL_DATA``). +#. When doing a buffered write with write-back cache enabled + (``FUSE_CAP_WRITEBACK_CACHE``).
This list is incomplete and strange. it has post EOF write for writeback which is the exception
and leaves out every non writeback write.
If you composed this list yourself I highly recommend an LLM for this task if you used LLM I suggest a stronger model.
Generally speaking, I find that today's robots are much better at writing these sorts of docs than I am - as long as I sit at the helm and guide them about where to expand on and where to keep it concise.
Quoted 14 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +14
-0+ +ACL caching +=========== + +FUSE has allowed the usage of POSIX ACLs for a long time as they could be set +and accessed simply as extended attributes. However, it was only with the +addition of the ``FUSE_POSIX_ACL`` flag that ACLs started to be fully supported. +Without this flag, ACLs can still be set, but the VFS won't use them for +performing permission checks - that would be the user-space server's +responsibility. + +Also, without setting ``FUSE_POSIX_ACL``, ACLs will not be cached by the kernel. +In this case, new inodes ``i_acl`` and ``i_default_acl`` fields will be set to +``ACL_DONT_CACHE``.
Documentation/filesystems/fuse/fuse-caches.rst line 80
Quoted 10 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +10
-0+ +On the other hand, if ``FUSE_POSIX_ACL`` is set during ``FUSE_INIT``, when an +ACL is accessed the VFS layer will first check if it's already cached. If it is +not, FUSE ``->get_acl`` operation is called, which will eventually send a +user-space request. Future accesses to this inode ACL will then use the cached +data. + +Setting an ACL in an inode, however, won't cache it immediately. It will send +user-space a request with the new ACL, and the FUSE server may perform some +modifications before storing it.
Do not encourage this by documenting it please.
It reinforces that this was by design, rather than an oversight which we don't know.
Quoted 23 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +23
-0+ +On the other hand, ACLs will be removed for the cache in the following +situations: + +- When setting an ACL in an inode and the user-space server has set the + ``FUSE_POSIX_ACL`` flag, all previously cached ACLs for this inode will be + invalidated. +- When invalidating an inode through the ``FUSE_NOTIFY_INVAL_INODE`` operation. +- When ``->d_revalidate()`` is called for a dentry that requires a lookup (e.g. + it has expired) and that lookup operation is successful. +- When the VFS needs to check access rights for an inode (by calling + ``->permission()``), attributes may need to be refreshed. If that happens, + any cached ACLs for that inode will be invalidated. +- After setting an inode attribute (i.e. operation ``FUSE_SETATTR`` is sent to + user-space), the user-space server may have also updated the ACLs, so any + cached ACLs for this inode are also invalidated. +- While processing ``FUSE_READDIRPLUS`` and a new dentry is added (unless this + dentry is already being looked up (``DCACHE_PAR_LOOKUP``)) +- In general, when there is the need to sent a ``FUSE_STATX`` or + ``FUSE_GETATTR`` to user-space (e.g. because the attributes have expired). + This may happen in the following cases: + + - When doing an ``->llseek()`` on a file with ``SEEK_END``, ``SEEK_HOLE`` or
Documentation/filesystems/fuse/fuse-caches.rst line 113
Quoted 10 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +10
-0+ ``SEEK_DATA``. + - When the ``FUSE_AUTO_INVAL_DATA`` flag is set at ``INIT`` time (to + automatically invalidate cached pages), and a buffered read + (``->read_iter()``) past EOF is done on a non-passthrough file. + - When the ``FUSE_WRITEBACK_CACHE`` flag is set at ``INIT`` time, and a + buffered write (``->write_iter()``) past EOF is done on a non-passthrough + file. + - When the ``FUSE_AUTO_INVAL_DATA`` flag is set at ``INIT`` time and the VFS + needs to read a directory contents (``->iterate_shared()``) for a + directory that is allowed to be cached.
No reason to repeat the reasons for attr cache invalidation that were just listed above
Documentation/filesystems/fuse/fuse-caches.rst line 126
Quoted 13 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +13
-0+ +readdir caching +=============== + +When opening a directory for doing a readdir, a ``FUSE_OPENDIR`` will be sent +and the user-space server will be responsible for setting the open flags related +with caching, namely ``FOPEN_KEEP_CACHE`` and ``FOPEN_CACHE_DIR``. + +If neither flags are set by the user-space FUSE server, then every ``readdir`` +will result in a ``FUSE_READDIR`` (or ``FUSE_READDIRPLUS``) request being sent. +If ``FOPEN_CACHE_DIR`` is set by the server, then the result of a ``readdir`` +will be cached by the kernel and reused. However, if ``FOPEN_KEEP_CACHE`` isn't +also set, the cache will be invalidated next time the directory is open.
Confusing.FOPEN_KEEP_CACHE is about keeping the cache on THIS open not on some NEXT open.
Thanks,
Amir.
Re: [RFC PATCH v2 1/8] Documentation: fuse: add document on caches being used by FUSE
Quoted 53 lines · Amir Goldstein
Quoted 52 lines · Luis Henriques
This new file aims at documenting the caches that are used by FUSE. At the moment only symlink, attributes, ACLs and readdir caches are described.
Signed-off-by Luis Henriques <[email protected]>--- .../filesystems/fuse/fuse-caches.rst | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Documentation/filesystems/fuse/fuse-caches.rstDocumentation/filesystems/fuse/fuse-caches.rst new file +36
-0@@ -0,0 +1,142 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========== +FUSE Caches +=========== + +Introduction +============ + +This document summarises the different types of caches that are used in FUSE. +For each cache type, it attempts to document the rules that are followed to +insert, validate and invalidate data into the cache. + +symlink caching +=============== + +Whenever there's a link resolution request, the VFS will call into +``fuse_get_link()`` which will then send a ``FUSE_READLINK`` request to the +user-space FUSE server. However, the server can ask the kernel to cache all +links resolutions by setting the ``FUSE_CACHE_SYMLINKS`` flag during the +``FUSE_INIT`` negotiation. + +If this flag is set, FUSE will immediately call into the VFS +``__page_get_link()`` from the ``->get_link()`` inode operation. The first time +this is done for a specific link, it will end-up sending the ``FUSE_READLINK`` +to user-space but the link contents will then be added into page-cache. The next +time the link needs to be resolved, it will use the link content that is already +cached, and will only fallback into sending the request to use-space if the +folio isn't up-to-date. + +Attributes caching +================== + +Attributes obtained from user-space, for example when an inode is first +looked-up, are cached in the kernel. However, these attributes have a timeout +associated and once expired they are invalidated.
Quoted 8 lines
Documentation/filesystems/fuse/fuse-caches.rst line 42
Quoted 6 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +6
-0+ +Thus, the ``FUSE_GETATTR`` operation will be sent to user-space only if the +attributes aren't yet available, the attributes aren't valid (timeout), or if +there is an explicit request for doing so (for example, by using the +``AT_STATX_FORCE_SYNC`` flag in ``statx``). This may happen in the following +situations:"This may happen" what may happen? I don't see it referring to anything.
Yeah, that sentence doesn't really make a lot of sense. I'll rephrase.
Quoted 10 lines
Quoted 10 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +10
-0+ +#. An explicit request from VFS to get the attributes for an inode (through the + ``->getattr()`` callback). +#. When an ``->llseek()`` is requested to FUSE with a type of request + (``whence``): + + - ``SEEK_{HOLE,DATA}`` and the user-space doesn't implement the + ``FUSE_LSEEK`` operation (it has returned ``ENOSYS``), or + - ``SEEK_END`` +
Quoted 8 lines
Documentation/filesystems/fuse/fuse-caches.rst line 56
Quoted 4 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +4
-0+#. When doing a buffered read past EOF or automatic page cache invalidation mode + is enabled (``FUSE_AUTO_INVAL_DATA``). +#. When doing a buffered write with write-back cache enabled + (``FUSE_CAP_WRITEBACK_CACHE``).This list is incomplete and strange. it has post EOF write for writeback which is the exception
and leaves out every non writeback write.
This list was meant to list the scenarios where the FUSE_GETATTR is sent (the "this may happen" above). But I'll review the list again.
Quoted 6 lines
If you composed this list yourself I highly recommend an LLM for this task if you used LLM I suggest a stronger model.
Generally speaking, I find that today's robots are much better at writing these sorts of docs than I am - as long as I sit at the helm and guide them about where to expand on and where to keep it concise.
Thank you for the suggestion (I did not use an LLM btw). In fact, do you think this document is really useful, given that everyone will be running an LLM anyway? (I've been asking this question myself...)
Quoted 20 lines
Quoted 20 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +20
-0+ +ACL caching +=========== + +FUSE has allowed the usage of POSIX ACLs for a long time as they could be set +and accessed simply as extended attributes. However, it was only with the +addition of the ``FUSE_POSIX_ACL`` flag that ACLs started to be fully supported. +Without this flag, ACLs can still be set, but the VFS won't use them for +performing permission checks - that would be the user-space server's +responsibility. + +Also, without setting ``FUSE_POSIX_ACL``, ACLs will not be cached by the kernel. +In this case, new inodes ``i_acl`` and ``i_default_acl`` fields will be set to +``ACL_DONT_CACHE``. + +On the other hand, if ``FUSE_POSIX_ACL`` is set during ``FUSE_INIT``, when an +ACL is accessed the VFS layer will first check if it's already cached. If it is +not, FUSE ``->get_acl`` operation is called, which will eventually send a +user-space request. Future accesses to this inode ACL will then use the cached +data.
Quoted 8 lines
Documentation/filesystems/fuse/fuse-caches.rst line 80
Quoted 4 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +4
-0+ +Setting an ACL in an inode, however, won't cache it immediately. It will send +user-space a request with the new ACL, and the FUSE server may perform some +modifications before storing it.Do not encourage this by documenting it please.
It reinforces that this was by design, rather than an oversight which we don't know.
Eh! OK, I'll stop that sentence after the comma :-)
Quoted 46 lines
Quoted 23 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +23
-0+ +On the other hand, ACLs will be removed for the cache in the following +situations: + +- When setting an ACL in an inode and the user-space server has set the + ``FUSE_POSIX_ACL`` flag, all previously cached ACLs for this inode will be + invalidated. +- When invalidating an inode through the ``FUSE_NOTIFY_INVAL_INODE`` operation. +- When ``->d_revalidate()`` is called for a dentry that requires a lookup (e.g. + it has expired) and that lookup operation is successful. +- When the VFS needs to check access rights for an inode (by calling + ``->permission()``), attributes may need to be refreshed. If that happens, + any cached ACLs for that inode will be invalidated. +- After setting an inode attribute (i.e. operation ``FUSE_SETATTR`` is sent to + user-space), the user-space server may have also updated the ACLs, so any + cached ACLs for this inode are also invalidated. +- While processing ``FUSE_READDIRPLUS`` and a new dentry is added (unless this + dentry is already being looked up (``DCACHE_PAR_LOOKUP``)) +- In general, when there is the need to sent a ``FUSE_STATX`` or + ``FUSE_GETATTR`` to user-space (e.g. because the attributes have expired). + This may happen in the following cases: + + - When doing an ``->llseek()`` on a file with ``SEEK_END``, ``SEEK_HOLE`` orDocumentation/filesystems/fuse/fuse-caches.rst line 113
Quoted 10 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +10
-0+ ``SEEK_DATA``. + - When the ``FUSE_AUTO_INVAL_DATA`` flag is set at ``INIT`` time (to + automatically invalidate cached pages), and a buffered read + (``->read_iter()``) past EOF is done on a non-passthrough file. + - When the ``FUSE_WRITEBACK_CACHE`` flag is set at ``INIT`` time, and a + buffered write (``->write_iter()``) past EOF is done on a non-passthrough + file. + - When the ``FUSE_AUTO_INVAL_DATA`` flag is set at ``INIT`` time and the VFS + needs to read a directory contents (``->iterate_shared()``) for a + directory that is allowed to be cached.No reason to repeat the reasons for attr cache invalidation that were just listed above
Quoted 9 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +9
-0+ +readdir caching +=============== + +When opening a directory for doing a readdir, a ``FUSE_OPENDIR`` will be sent +and the user-space server will be responsible for setting the open flags related +with caching, namely ``FOPEN_KEEP_CACHE`` and ``FOPEN_CACHE_DIR``. + +If neither flags are set by the user-space FUSE server, then every ``readdir``
Quoted 8 lines
Documentation/filesystems/fuse/fuse-caches.rst line 126
Quoted 4 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +4
-0+will result in a ``FUSE_READDIR`` (or ``FUSE_READDIRPLUS``) request being sent. +If ``FOPEN_CACHE_DIR`` is set by the server, then the result of a ``readdir`` +will be cached by the kernel and reused. However, if ``FOPEN_KEEP_CACHE`` isn't +also set, the cache will be invalidated next time the directory is open.Confusing.
FOPEN_KEEP_CACHEis about keeping the cache on THIS open not on some NEXT open.
Right, that's true. I just wanted to emphasise that the invalidation doesn't happen on a close, but on the next open. But I'll rephrase, thanks.
Cheers,
Signature · 1 line
Luís
Re: [RFC PATCH v2 1/8] Documentation: fuse: add document on caches being used by FUSE
Quoted 92 lines · Luis Henriques
Quoted 53 lines · Amir Goldstein
Quoted 52 lines · Luis Henriques
This new file aims at documenting the caches that are used by FUSE. At the moment only symlink, attributes, ACLs and readdir caches are described.
Signed-off-by Luis Henriques <[email protected]>--- .../filesystems/fuse/fuse-caches.rst | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Documentation/filesystems/fuse/fuse-caches.rstDocumentation/filesystems/fuse/fuse-caches.rst new file +36
-0@@ -0,0 +1,142 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========== +FUSE Caches +=========== + +Introduction +============ + +This document summarises the different types of caches that are used in FUSE. +For each cache type, it attempts to document the rules that are followed to +insert, validate and invalidate data into the cache. + +symlink caching +=============== + +Whenever there's a link resolution request, the VFS will call into +``fuse_get_link()`` which will then send a ``FUSE_READLINK`` request to the +user-space FUSE server. However, the server can ask the kernel to cache all +links resolutions by setting the ``FUSE_CACHE_SYMLINKS`` flag during the +``FUSE_INIT`` negotiation. + +If this flag is set, FUSE will immediately call into the VFS +``__page_get_link()`` from the ``->get_link()`` inode operation. The first time +this is done for a specific link, it will end-up sending the ``FUSE_READLINK`` +to user-space but the link contents will then be added into page-cache. The next +time the link needs to be resolved, it will use the link content that is already +cached, and will only fallback into sending the request to use-space if the +folio isn't up-to-date. + +Attributes caching +================== + +Attributes obtained from user-space, for example when an inode is first +looked-up, are cached in the kernel. However, these attributes have a timeout +associated and once expired they are invalidated.Quoted 8 lines
Documentation/filesystems/fuse/fuse-caches.rst line 42
Quoted 6 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +6
-0+ +Thus, the ``FUSE_GETATTR`` operation will be sent to user-space only if the +attributes aren't yet available, the attributes aren't valid (timeout), or if +there is an explicit request for doing so (for example, by using the +``AT_STATX_FORCE_SYNC`` flag in ``statx``). This may happen in the following +situations:"This may happen" what may happen? I don't see it referring to anything.
Yeah, that sentence doesn't really make a lot of sense. I'll rephrase.
Quoted 10 lines
Quoted 10 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +10
-0+ +#. An explicit request from VFS to get the attributes for an inode (through the + ``->getattr()`` callback). +#. When an ``->llseek()`` is requested to FUSE with a type of request + (``whence``): + + - ``SEEK_{HOLE,DATA}`` and the user-space doesn't implement the + ``FUSE_LSEEK`` operation (it has returned ``ENOSYS``), or + - ``SEEK_END`` +Quoted 8 lines
Documentation/filesystems/fuse/fuse-caches.rst line 56
Quoted 4 lines
Documentation/filesystems/fuse/fuse-caches.rst new file +4
-0+#. When doing a buffered read past EOF or automatic page cache invalidation mode + is enabled (``FUSE_AUTO_INVAL_DATA``). +#. When doing a buffered write with write-back cache enabled + (``FUSE_CAP_WRITEBACK_CACHE``).This list is incomplete and strange. it has post EOF write for writeback which is the exception
and leaves out every non writeback write.This list was meant to list the scenarios where the
FUSE_GETATTRis sent (the "this may happen" above). But I'll review the list again.Quoted 3 lines
If you composed this list yourself I highly recommend an LLM for this task if you used LLM I suggest a stronger model.
Quoted 8 lines
Quoted 3 lines
Generally speaking, I find that today's robots are much better at writing these sorts of docs than I am - as long as I sit at the helm and guide them about where to expand on and where to keep it concise.
Thank you for the suggestion (I did not use an LLM btw). In fact, do you think this document is really useful, given that everyone will be running an LLM anyway? (I've been asking this question myself...)
LLM is very good in collecting information and arranging it in nicely formatted structures, but you need to keep a very good eye on the output and you need to focus on it to make the document relevant to the prospective audience of human readers. Running LLM to document without a human on the helm you can get half truths and plain lies.
Also, for economic reasons, the way to work with LLM is to let it research the code base and create nice reviable "brain dumps" that you OR the LLM can read later into context.
Doing this research every time is neither cost effective nor reliable nor deterministic.
Thanks,
Amir.
RFC PATCH v2 2/8 selftests/fuse: convert fusectl test to fuse3
In reply to Luis HenriquesSince it is probably not worth adding new fuse kselftests based on fuse2, it is a good idea to convert the single existing test to fuse3. The conversion is trivial, as it only requires some changes to function signatures (the gettattr and truncate fuse operations), and to the filler() helper.
--- .../selftests/filesystems/fuse/Makefile | 21 +++++++------------ .../selftests/filesystems/fuse/fuse_mnt.c | 17 ++++++++------- 2 files changed, 17 insertions(+), 21 deletions(-)
tools/testing/selftests/filesystems/fuse/Makefile +7 -14
@@ -2,30 +2,23 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) -TEST_GEN_PROGS := fusectl_test +TEST_GEN_PROGS := fusectl_test fuse_acl_cache_test TEST_GEN_FILES := fuse_mnt -# fuse_acl_cache_test requires libfuse3; add it only when the library is present. -ACL_CFLAGS := $(shell pkg-config fuse3 --cflags 2>/dev/null) -ACL_LDLIBS := $(shell pkg-config fuse3 --libs 2>/dev/null) -ifneq ($(ACL_CFLAGS),) -TEST_GEN_PROGS += fuse_acl_cache_test -endif - include ../../lib.mk -VAR_CFLAGS := $(shell pkg-config fuse --cflags 2>/dev/null) +VAR_CFLAGS := $(shell pkg-config fuse3 --cflags 2>/dev/null) ifeq ($(VAR_CFLAGS),) -VAR_CFLAGS := -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse +VAR_CFLAGS := -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse3 endif -VAR_LDLIBS := $(shell pkg-config fuse --libs 2>/dev/null) +VAR_LDLIBS := $(shell pkg-config fuse3 --libs 2>/dev/null) ifeq ($(VAR_LDLIBS),) -VAR_LDLIBS := -lfuse -pthread +VAR_LDLIBS := -lfuse3 -pthread endif $(OUTPUT)/fuse_mnt: CFLAGS += $(VAR_CFLAGS) $(OUTPUT)/fuse_mnt: LDLIBS += $(VAR_LDLIBS) -$(OUTPUT)/fuse_acl_cache_test: CFLAGS += $(ACL_CFLAGS) -$(OUTPUT)/fuse_acl_cache_test: LDLIBS += $(ACL_LDLIBS) +$(OUTPUT)/fuse_acl_cache_test: CFLAGS += $(VAR_CFLAGS) +$(OUTPUT)/fuse_acl_cache_test: LDLIBS += $(VAR_LDLIBS)
tools/testing/selftests/filesystems/fuse/fuse_mnt.c +10 -7
@@ -4,7 +4,7 @@* Creates a simple FUSE filesystem with a single read-write file (/test) */ -#define FUSE_USE_VERSION 26 +#define FUSE_USE_VERSION 31#include <fuse.h> #include <stdio.h>
@@ -20,7 +20,8 @@ static char *content;static size_t content_size =0 ;static const char test_path[] ="/test" ; -static int test_getattr (const char *path,struct stat *st) +static int test_getattr (const char *path,struct stat *st, +struct fuse_file_info *fi) {memset (st,0 ,sizeof (*st));
@@ -41,14 +42,15 @@ static int test_getattr(const char *path, struct stat *st) }static int test_readdir (const char *path,void *buf,fuse_fill_dir_t filler, -off_t offset,struct fuse_file_info *fi) +off_t offset,struct fuse_file_info *fi, +enum fuse_readdir_flags flags) {if (strcmp (path,"/" ))return -ENOENT ; -filler (buf,"." ,NULL ,0 ); -filler (buf,".." ,NULL ,0 ); -filler (buf, test_path +1 ,NULL ,0 ); +filler (buf,"." ,NULL ,0 ,FUSE_FILL_DIR_DEFAULTS ); +filler (buf,".." ,NULL ,0 ,FUSE_FILL_DIR_DEFAULTS ); +filler (buf, test_path +1 ,NULL ,0 ,FUSE_FILL_DIR_DEFAULTS );return 0 ; }
@@ -107,7 +109,8 @@ static int test_write(const char *path, const char *buf, size_t size,return size; } -static int test_truncate (const char *path,off_t size) +static int test_truncate (const char *path,off_t size, +struct fuse_file_info *fi) {if (strcmp (path, test_path) !=0 )return -ENOENT ;
RFC PATCH v2 3/8 selftests/fuse: check that fusectlfs is mounted
In reply to Luis HenriquesThe control filesystem for FUSE needs to be mounted for the fusectl_test to be successfully run. Skip the test is that is not the case.
--- tools/testing/selftests/filesystems/fuse/fusectl_test.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/testing/selftests/filesystems/fuse/fusectl_test.c +7 -0
@@ -48,6 +48,7 @@ FIXTURE_SETUP(fusectl)uid_t uid =getuid ();gid_t gid =getgid ();char buf[32 ]; +char path_buf[PATH_MAX ];/* Setup userns */ ASSERT_EQ (unshare (CLONE_NEWNS |CLONE_NEWUSER ),0 );
@@ -93,6 +94,12 @@ FIXTURE_SETUP(fusectl) strerror(errno)); self->connection = statbuf.st_dev; + +sprintf (path_buf,"/sys/fs/fuse/connections/%d" , self->connection); +if (access (path_buf,F_OK ) !=0 ) +SKIP (return, +"fusectl doesn't seem to be mounted: %s\n" , +strerror (errno)); }FIXTURE_TEARDOWN (fusectl)
RFC PATCH v2 4/8 selftests/fuse: add fuse symlink caching test
In reply to Luis HenriquesThis 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.
--- .../selftests/filesystems/fuse/.gitignore | 1 + .../selftests/filesystems/fuse/Makefile | 5 +- .../fuse/fuse_symlink_cache_test.c | 204 ++++++++++++++++++ 3 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_symlink_cache_test.c
tools/testing/selftests/filesystems/fuse/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only fuse_mnt fusectl_test +fuse_symlink_cache_test
tools/testing/selftests/filesystems/fuse/Makefile +4 -1
@@ -2,7 +2,7 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) -TEST_GEN_PROGS := fusectl_test fuse_acl_cache_test +TEST_GEN_PROGS := fusectl_test fuse_acl_cache_test fuse_symlink_cache_test TEST_GEN_FILES := fuse_mnt include ../../lib.mk
@@ -22,3 +22,6 @@ $(OUTPUT)/fuse_mnt: LDLIBS += $(VAR_LDLIBS) $(OUTPUT)/fuse_acl_cache_test: CFLAGS += $(VAR_CFLAGS) $(OUTPUT)/fuse_acl_cache_test: LDLIBS += $(VAR_LDLIBS) + +$(OUTPUT)/fuse_symlink_cache_test: CFLAGS += $(VAR_CFLAGS) +$(OUTPUT)/fuse_symlink_cache_test: LDLIBS += $(VAR_LDLIBS)
tools/testing/selftests/filesystems/fuse/fuse_symlink_cache_test.c new file +204 -0
204 lines not on this page · raw message
RFC PATCH v2 5/8 selftests/fuse: factor-out test fixture setup/teardown
In reply to Luis HenriquesIn order to reduce new tests setup/teardown code duplication, factor-out these functions from the existing acl_cache test.
--- .../filesystems/fuse/fuse_acl_cache_test.c | 82 ++++++++++++------- 1 file changed, 53 insertions(+), 29 deletions(-)
tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c +53 -29
@@ -50,6 +50,8 @@#include "kselftest_harness.h" +#define MAX_ERR_MSG 256 +/* ---- ACL binary encoding ------------------------------------------------ */ /* * POSIX ACL v2 xattr format (little-endian):
@@ -193,52 +195,74 @@ FIXTURE(acl_cache) {pthread_t thread; }; -FIXTURE_SETUP (acl_cache) +int fs_setup (struct fuse_session **se,char *mountpoint,char *file_path, +pthread_t *thread,char *err) {char *fuse_argv[] = {"fuse_acl_cache_test" ,NULL };struct fuse_args args =FUSE_ARGS_INIT (1 , fuse_argv); - g_ds.acl = acl_a; - g_ds.acl_size =sizeof (acl_a); - g_ds.getxattr_count =0 ; - -strcpy (self->mountpoint,"/tmp/acl_cache_test_XXXXXX" ); -if (!mkdtemp (self->mountpoint)) -SKIP (return,"mkdtemp: %s" ,strerror (errno)); +strcpy (mountpoint,"/tmp/acl_cache_test_XXXXXX" ); +if (!mkdtemp (mountpoint)) { +snprintf (err,MAX_ERR_MSG ,"mkdtemp: %s" ,strerror (errno)); +return -1 ; + } -snprintf (self->file_path,sizeof (self->file_path), -"%s/" FILE_NAME , self->mountpoint); +snprintf (file_path,PATH_MAX ,"%s/" FILE_NAME , mountpoint); - self->se =fuse_session_new (&args, &fs_ops,sizeof (fs_ops),NULL ); -if (!self->se) { -rmdir (self->mountpoint); -SKIP (return,"fuse_session_new failed" ); + *se =fuse_session_new (&args, &fs_ops,sizeof (fs_ops),NULL ); +if (!*se) { +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"fuse_session_new failed" ); +return -1 ; } -if (fuse_session_mount (self->se, self->mountpoint)) { -fuse_session_destroy (self->se); -rmdir (self->mountpoint); -SKIP (return,"fuse_session_mount failed " -"(missing fusermount3 or insufficient privileges)" ); +if (fuse_session_mount (*se, mountpoint)) { +fuse_session_destroy (*se); +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"fuse_session_mount failed " +"(missing fusermount3 or insufficient privileges)" ); +return -1 ; } -if (pthread_create (&self->thread,NULL , run_daemon, self->se)) { -fuse_session_unmount (self->se); -fuse_session_destroy (self->se); -rmdir (self->mountpoint); -SKIP (return,"pthread_create: %s" ,strerror (errno)); +if (pthread_create (thread,NULL , run_daemon, *se)) { +fuse_session_unmount (*se); +fuse_session_destroy (*se); +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"pthread_create: %s" ,strerror (errno)); +return -1 ; }fuse_opt_free_args (&args); + +return 0 ; +} + +static void fs_teardown (struct fuse_session *se,pthread_t thread, +char *mountpoint) +{ +fuse_session_exit (se); +fuse_session_unmount (se); +pthread_join (thread,NULL ); +fuse_session_destroy (se); +rmdir (mountpoint); +} + +FIXTURE_SETUP (acl_cache) +{ +char err[MAX_ERR_MSG ]; + + g_ds.acl = acl_a; + g_ds.acl_size =sizeof (acl_a); + g_ds.getxattr_count =0 ; + +if (fs_setup (&self->se, self->mountpoint, self->file_path, + &self->thread, err)) +SKIP (return, err); }FIXTURE_TEARDOWN (acl_cache) { -fuse_session_exit (self->se); -fuse_session_unmount (self->se); -pthread_join (self->thread,NULL ); -fuse_session_destroy (self->se); -rmdir (self->mountpoint); +fs_teardown (self->se, self->thread, self->mountpoint); }static int do_force_statx (const char *path)
Re: [RFC PATCH v2 5/8] selftests/fuse: factor-out test fixture setup/teardown
Quoted 3 lines · Luis Henriques
In order to reduce new tests setup/teardown code duplication, factor-out these functions from the existing
acl_cachetest.
When I read this I thought you were going to share these helpers with the new symlink and readdir cache tests, but you did not.
Maybe a fuse_common.c would make sense to reduce boiler plate in new fuse tests.
These helpers and fixture look pretty similar in all three tests.
Thanks,
Amir.
Quoted 123 lines
Signed-off-by Luis Henriques <[email protected]>--- .../filesystems/fuse/fuse_acl_cache_test.c | 82 ++++++++++++------- 1 file changed, 53 insertions(+), 29 deletions(-)tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c +53
-29@@ -50,6 +50,8 @@#include "kselftest_harness.h" +#define MAX_ERR_MSG 256 +/* ---- ACL binary encoding ------------------------------------------------ */ /* * POSIX ACL v2 xattr format (little-endian): @@ -193,52 +195,74 @@ FIXTURE(acl_cache) {pthread_t thread; }; -FIXTURE_SETUP (acl_cache) +int fs_setup (struct fuse_session **se,char *mountpoint,char *file_path, +pthread_t *thread,char *err) {char *fuse_argv[] = {"fuse_acl_cache_test" ,NULL };struct fuse_args args =FUSE_ARGS_INIT (1 , fuse_argv); - g_ds.acl = acl_a; - g_ds.acl_size =sizeof (acl_a); - g_ds.getxattr_count =0 ; - -strcpy (self->mountpoint,"/tmp/acl_cache_test_XXXXXX" ); -if (!mkdtemp (self->mountpoint)) -SKIP (return,"mkdtemp: %s" ,strerror (errno)); +strcpy (mountpoint,"/tmp/acl_cache_test_XXXXXX" ); +if (!mkdtemp (mountpoint)) { +snprintf (err,MAX_ERR_MSG ,"mkdtemp: %s" ,strerror (errno)); +return -1 ; + } -snprintf (self->file_path,sizeof (self->file_path), -"%s/" FILE_NAME , self->mountpoint); +snprintf (file_path,PATH_MAX ,"%s/" FILE_NAME , mountpoint); - self->se =fuse_session_new (&args, &fs_ops,sizeof (fs_ops),NULL ); -if (!self->se) { -rmdir (self->mountpoint); -SKIP (return,"fuse_session_new failed" ); + *se =fuse_session_new (&args, &fs_ops,sizeof (fs_ops),NULL ); +if (!*se) { +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"fuse_session_new failed" ); +return -1 ; } -if (fuse_session_mount (self->se, self->mountpoint)) { -fuse_session_destroy (self->se); -rmdir (self->mountpoint); -SKIP (return,"fuse_session_mount failed " -"(missing fusermount3 or insufficient privileges)" ); +if (fuse_session_mount (*se, mountpoint)) { +fuse_session_destroy (*se); +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"fuse_session_mount failed " +"(missing fusermount3 or insufficient privileges)" ); +return -1 ; } -if (pthread_create (&self->thread,NULL , run_daemon, self->se)) { -fuse_session_unmount (self->se); -fuse_session_destroy (self->se); -rmdir (self->mountpoint); -SKIP (return,"pthread_create: %s" ,strerror (errno)); +if (pthread_create (thread,NULL , run_daemon, *se)) { +fuse_session_unmount (*se); +fuse_session_destroy (*se); +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"pthread_create: %s" ,strerror (errno)); +return -1 ; }fuse_opt_free_args (&args); + +return 0 ; +} + +static void fs_teardown (struct fuse_session *se,pthread_t thread, +char *mountpoint) +{ +fuse_session_exit (se); +fuse_session_unmount (se); +pthread_join (thread,NULL ); +fuse_session_destroy (se); +rmdir (mountpoint); +} + +FIXTURE_SETUP (acl_cache) +{ +char err[MAX_ERR_MSG ]; + + g_ds.acl = acl_a; + g_ds.acl_size =sizeof (acl_a); + g_ds.getxattr_count =0 ; + +if (fs_setup (&self->se, self->mountpoint, self->file_path, + &self->thread, err)) +SKIP (return, err); }FIXTURE_TEARDOWN (acl_cache) { -fuse_session_exit (self->se); -fuse_session_unmount (self->se); -pthread_join (self->thread,NULL ); -fuse_session_destroy (self->se); -rmdir (self->mountpoint); +fs_teardown (self->se, self->thread, self->mountpoint); }static int do_force_statx (const char *path)
Re: [RFC PATCH v2 5/8] selftests/fuse: factor-out test fixture setup/teardown
Quoted 5 lines · Amir Goldstein
Quoted 3 lines · Luis Henriques
In order to reduce new tests setup/teardown code duplication, factor-out these functions from the existing
acl_cachetest.
Quoted 7 lines
When I read this I thought you were going to share these helpers with the new symlink and readdir cache tests, but you did not.
Maybe a
fuse_common.cwould make sense to reduce boiler plate in new fuse tests.These helpers and fixture look pretty similar in all three tests.
True. I'll try to reduce the duplication by moving the common place.
Cheers,
Signature · 1 line
Luís
Quoted 127 lines
Thanks,
Amir.Quoted 123 lines
Signed-off-by Luis Henriques <[email protected]>--- .../filesystems/fuse/fuse_acl_cache_test.c | 82 ++++++++++++------- 1 file changed, 53 insertions(+), 29 deletions(-)tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c +53
-29@@ -50,6 +50,8 @@#include "kselftest_harness.h" +#define MAX_ERR_MSG 256 +/* ---- ACL binary encoding ------------------------------------------------ */ /* * POSIX ACL v2 xattr format (little-endian): @@ -193,52 +195,74 @@ FIXTURE(acl_cache) {pthread_t thread; }; -FIXTURE_SETUP (acl_cache) +int fs_setup (struct fuse_session **se,char *mountpoint,char *file_path, +pthread_t *thread,char *err) {char *fuse_argv[] = {"fuse_acl_cache_test" ,NULL };struct fuse_args args =FUSE_ARGS_INIT (1 , fuse_argv); - g_ds.acl = acl_a; - g_ds.acl_size =sizeof (acl_a); - g_ds.getxattr_count =0 ; - -strcpy (self->mountpoint,"/tmp/acl_cache_test_XXXXXX" ); -if (!mkdtemp (self->mountpoint)) -SKIP (return,"mkdtemp: %s" ,strerror (errno)); +strcpy (mountpoint,"/tmp/acl_cache_test_XXXXXX" ); +if (!mkdtemp (mountpoint)) { +snprintf (err,MAX_ERR_MSG ,"mkdtemp: %s" ,strerror (errno)); +return -1 ; + } -snprintf (self->file_path,sizeof (self->file_path), -"%s/" FILE_NAME , self->mountpoint); +snprintf (file_path,PATH_MAX ,"%s/" FILE_NAME , mountpoint); - self->se =fuse_session_new (&args, &fs_ops,sizeof (fs_ops),NULL ); -if (!self->se) { -rmdir (self->mountpoint); -SKIP (return,"fuse_session_new failed" ); + *se =fuse_session_new (&args, &fs_ops,sizeof (fs_ops),NULL ); +if (!*se) { +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"fuse_session_new failed" ); +return -1 ; } -if (fuse_session_mount (self->se, self->mountpoint)) { -fuse_session_destroy (self->se); -rmdir (self->mountpoint); -SKIP (return,"fuse_session_mount failed " -"(missing fusermount3 or insufficient privileges)" ); +if (fuse_session_mount (*se, mountpoint)) { +fuse_session_destroy (*se); +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"fuse_session_mount failed " +"(missing fusermount3 or insufficient privileges)" ); +return -1 ; } -if (pthread_create (&self->thread,NULL , run_daemon, self->se)) { -fuse_session_unmount (self->se); -fuse_session_destroy (self->se); -rmdir (self->mountpoint); -SKIP (return,"pthread_create: %s" ,strerror (errno)); +if (pthread_create (thread,NULL , run_daemon, *se)) { +fuse_session_unmount (*se); +fuse_session_destroy (*se); +rmdir (mountpoint); +snprintf (err,MAX_ERR_MSG ,"pthread_create: %s" ,strerror (errno)); +return -1 ; }fuse_opt_free_args (&args); + +return 0 ; +} + +static void fs_teardown (struct fuse_session *se,pthread_t thread, +char *mountpoint) +{ +fuse_session_exit (se); +fuse_session_unmount (se); +pthread_join (thread,NULL ); +fuse_session_destroy (se); +rmdir (mountpoint); +} + +FIXTURE_SETUP (acl_cache) +{ +char err[MAX_ERR_MSG ]; + + g_ds.acl = acl_a; + g_ds.acl_size =sizeof (acl_a); + g_ds.getxattr_count =0 ; + +if (fs_setup (&self->se, self->mountpoint, self->file_path, + &self->thread, err)) +SKIP (return, err); }FIXTURE_TEARDOWN (acl_cache) { -fuse_session_exit (self->se); -fuse_session_unmount (self->se); -pthread_join (self->thread,NULL ); -fuse_session_destroy (self->se); -rmdir (self->mountpoint); +fs_teardown (self->se, self->thread, self->mountpoint); }static int do_force_statx (const char *path)
RFC PATCH v2 6/8 selftests/fuse: use dynamically allocated memory to store ACLs
In reply to Luis HenriquesInstead of directly using static arrays for the ACL value, allocate memory for storing it. This will make it easier to implement ACL tests that also set the xattr dynamically.
--- .../filesystems/fuse/fuse_acl_cache_test.c | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-)
tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c +28 -6
@@ -90,7 +90,7 @@ static const uint8_t acl_b[] = {struct daemon_state {pthread_mutex_t lock; -const uint8_t *acl; +uint8_t *acl;size_t acl_size;int getxattr_count; };
@@ -152,15 +152,26 @@ static void fs_getattr(fuse_req_t req, fuse_ino_t ino,static void fs_getxattr (fuse_req_t req,fuse_ino_t ino,const char *name,size_t size) { +uint8_t *acl =NULL ; +size_t acl_size; +if (ino !=FILE_INO ||strcmp (name,"system.posix_acl_access" ) !=0 ) {fuse_reply_err (req,ENODATA );return ; } +if (size) { + acl =malloc (size); +if (!acl) { +fuse_reply_err (req,ENOMEM ); +return ; + } + }pthread_mutex_lock (&g_ds.lock); -const uint8_t *acl = g_ds.acl; -size_t acl_size = g_ds.acl_size; + acl_size = g_ds.acl_size; +if (acl && (size >= acl_size)) +memcpy (acl, g_ds.acl, acl_size); g_ds.getxattr_count++;pthread_mutex_unlock (&g_ds.lock);
@@ -170,6 +181,8 @@ static void fs_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,fuse_reply_err (req,ERANGE ); else fuse_reply_buf(req, (const char *)acl, acl_size); + +free (acl); }static const struct fuse_lowlevel_ops fs_ops = {
@@ -251,8 +264,10 @@ FIXTURE_SETUP(acl_cache) {char err[MAX_ERR_MSG ]; - g_ds.acl = acl_a; - g_ds.acl_size =sizeof (acl_a); + g_ds.acl_size =sizeof (acl_a); + g_ds.acl =malloc (g_ds.acl_size); +ASSERT_NE (g_ds.acl,NULL ); +memcpy (g_ds.acl, acl_a, g_ds.acl_size); g_ds.getxattr_count =0 ; if (fs_setup(&self->se, self->mountpoint, self->file_path,
@@ -263,6 +278,7 @@ FIXTURE_SETUP(acl_cache)FIXTURE_TEARDOWN (acl_cache) {fs_teardown (self->se, self->thread, self->mountpoint); +free (g_ds.acl); }static int do_force_statx (const char *path)
@@ -278,6 +294,7 @@ TEST_F(acl_cache, stale_after_force_sync)char buf[512 ];ssize_t sz;int count; +uint8_t *acl;/* * Step 1: two getxattr calls before any statx(FORCE_SYNC).
@@ -338,8 +355,13 @@ TEST_F(acl_cache, stale_after_force_sync)* !fc->posix_acl mounts (it skips forget_all_cached_acls in that case). * On a fixed kernel the ACL was never cached, so this is moot. */ + acl =malloc (sizeof (acl_b)); +ASSERT_NE (acl,NULL ); +memcpy (acl, acl_b,sizeof (acl_b)); +pthread_mutex_lock (&g_ds.lock); - g_ds.acl = acl_b; +free (g_ds.acl); + g_ds.acl = acl; g_ds.acl_size =sizeof (acl_b);pthread_mutex_unlock (&g_ds.lock);TH_LOG ("step 4: daemon switched to ACL_B (%zu bytes)" ,sizeof (acl_b));
RFC PATCH v2 7/8 selftests/fuse: add some extra ACL caching tests
In reply to Luis HenriquesThis adds some extra tests to ACL caching:
- Verify that reading ACLs results in the expected number of requests being sent user-space, depending on whether cache is enabled or disabled
- Verify caching behaviour on some caching invalidation scenarios
While there, add test binary to .gitignore.
--- .../selftests/filesystems/fuse/.gitignore | 1 + .../filesystems/fuse/fuse_acl_cache_test.c | 177 ++++++++++++++++++ 2 files changed, 178 insertions(+)
tools/testing/selftests/filesystems/fuse/.gitignore +1 -0
@@ -2,3 +2,4 @@ fuse_mnt fusectl_test fuse_symlink_cache_test +fuse_acl_cache_test
tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c +177 -0
218 lines not on this page · raw message
RFC PATCH v2 8/8 selftests/fuse: add fuse readdir caching test
In reply to Luis HenriquesThis new test will check the caching behaviour using combinations of two opendir flags: FOPEN_KEEP_CACHE and FOPEN_CACHE_DIR.
--- .../selftests/filesystems/fuse/.gitignore | 1 + .../selftests/filesystems/fuse/Makefile | 6 +- .../fuse/fuse_readdir_cache_test.c | 314 ++++++++++++++++++ 3 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_readdir_cache_test.c
tools/testing/selftests/filesystems/fuse/.gitignore +1 -0
@@ -3,3 +3,4 @@ fuse_mnt fusectl_test fuse_symlink_cache_test fuse_acl_cache_test +fuse_readdir_cache_test
tools/testing/selftests/filesystems/fuse/Makefile +5 -1
@@ -2,7 +2,8 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) -TEST_GEN_PROGS := fusectl_test fuse_acl_cache_test fuse_symlink_cache_test +TEST_GEN_PROGS := fusectl_test fuse_acl_cache_test fuse_symlink_cache_test \ + fuse_readdir_cache_test TEST_GEN_FILES := fuse_mnt include ../../lib.mk
@@ -25,3 +26,6 @@ $(OUTPUT)/fuse_acl_cache_test: LDLIBS += $(VAR_LDLIBS) $(OUTPUT)/fuse_symlink_cache_test: CFLAGS += $(VAR_CFLAGS) $(OUTPUT)/fuse_symlink_cache_test: LDLIBS += $(VAR_LDLIBS) + +$(OUTPUT)/fuse_readdir_cache_test: CFLAGS += $(VAR_CFLAGS) +$(OUTPUT)/fuse_readdir_cache_test: LDLIBS += $(VAR_LDLIBS)
tools/testing/selftests/filesystems/fuse/fuse_readdir_cache_test.c new file +314 -0
314 lines not on this page · raw message
Quoted 18 lines · Luis Henriques
Hi!
I'm (finally!) sending v2 of this patchset. It tries to document (and add a few kselftests) to the different types of caches that are currently in use within FUSE. As I mentioned in v1 the idea for documenting this came from Miklos during this year's LSFMM, where he mentioned he would like to see caches usage documented before he could merge an initial version of fusex.
This version documents symlinks, attributes, ACLs and readdir caches. Still
missing: dentries and data caching.I'm still sending it as an RFC as I'm still not sure if it fulfils Miklos' initial goal.
As usual feedback is welcome, as I'll (slowly) continue looking into other cache types.
Quoted 6 lines
Major changes since v1:
- Added more caches to the document
- Changed tests format to single self-contained binaries
- Since Amir added a new fuse3-based test, the conversion to fuse3 of the fusectl has minor changes to theMakefile
- NOTE: I've kept Amir's Reviewed-by anyway (should I drop it?)
It's fine. I trust your judgement.
Please see Sashiko review comments.
My main concern is with the doc - it's not an easy read and I would have liked it to be and I found many correctness error which is not a good sign.
Thanks,
Amir.
Quoted 26 lines · Amir Goldstein
Quoted 18 lines · Luis Henriques
Hi!
I'm (finally!) sending v2 of this patchset. It tries to document (and add a few kselftests) to the different types of caches that are currently in use within FUSE. As I mentioned in v1 the idea for documenting this came from Miklos during this year's LSFMM, where he mentioned he would like to see caches usage documented before he could merge an initial version of fusex.
This version documents symlinks, attributes, ACLs and readdir caches. Still
missing: dentries and data caching.I'm still sending it as an RFC as I'm still not sure if it fulfils Miklos' initial goal.
As usual feedback is welcome, as I'll (slowly) continue looking into other cache types.
Quoted 6 lines
Major changes since v1:
- Added more caches to the document
- Changed tests format to single self-contained binaries
- Since Amir added a new fuse3-based test, the conversion to fuse3 of the fusectl has minor changes to theMakefile
- NOTE: I've kept Amir's Reviewed-by anyway (should I drop it?)
Quoted 3 lines
It's fine. I trust your judgement.
Please see Sashiko review comments.
Sure, I will do that. (For some reason I assumed I would receive an email if there was a review for my patches. Looks like that's not the case.)
Quoted 3 lines
My main concern is with the doc - it's not an easy read and I would have liked it to be and I found many correctness error which is not a good sign.
Hmm... OK, I'll need to go through those errors and try my best to see if I can fix them.
Thanks a lot for your feedback, Amir. Much appreciated.
Cheers,
Signature · 1 line
Luís