fix: don't cache a failed statvfs as a success

- With cache.statfs=N, statvfs_cache set the entry's timestamp before
  calling statvfs. When that call failed, the failure was returned
  once and then every caller for the next N seconds got success with
  the entry's old or zeroed stats, and create policies chose
  branches from them.
- Refresh the entry only when statvfs succeeds. A failure is
  returned and retried on the next call.
- tests.cpp checks that a second lookup of a missing path still
  fails.
This commit is contained in:
Antonio SJ Musumeci 2026-11-21 14:34:26 -05:00
parent 7d677d1a37
commit 5e74822f91
2 changed files with 31 additions and 3 deletions

View file

@ -5,6 +5,7 @@
#include "fs_copyfile.hpp"
#include "fs_inode.hpp"
#include "fs_movefile_and_open.hpp"
#include "fs_statvfs_cache.hpp"
#include "from_string.hpp"
#include "fuse_link.hpp"
#include "fuse_readdir_factory.hpp"
@ -3775,6 +3776,24 @@ test_readdir_factory_rejects_oversized_counts()
TEST_CHECK(FUSE::ReadDirFactory::make("cor:99999999999") == nullptr);
}
// A failed statvfs must not be served from the cache as a success.
void
test_statvfs_cache_does_not_cache_failure()
{
int rv;
struct statvfs st;
const std::string path = "/nonexistent/mergerfs-statvfs-cache-test";
fs::statvfs_cache_timeout(60);
rv = fs::statvfs_cache(path,&st);
TEST_CHECK(rv == -ENOENT);
TEST_MSG("first rv: %d",rv);
rv = fs::statvfs_cache(path,&st);
TEST_CHECK(rv == -ENOENT);
TEST_MSG("second rv: %d",rv);
fs::statvfs_cache_timeout(0);
}
void
test_hashset_put_and_size()
{
@ -4483,6 +4502,7 @@ TEST_LIST =
{"fs_copyfile_source_changes_cleanup_tmpfiles",test_fs_copyfile_source_changes_cleanup_tmpfiles},
{"fs_movefile_and_open_same_branch",test_fs_movefile_and_open_same_branch},
{"readdir_factory_rejects_oversized_counts",test_readdir_factory_rejects_oversized_counts},
{"statvfs_cache_does_not_cache_failure",test_statvfs_cache_does_not_cache_failure},
{"str_eq_nullptr",test_str_eq_nullptr},
{"str_startswith_char_nullptr",test_str_startswith_char_nullptr},
{"str_from_u64_suffixes",test_str_from_u64_suffixes},