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 b7203a9247
commit 5a8e0cdc2d
2 changed files with 31 additions and 3 deletions

View file

@ -90,19 +90,27 @@ fs::statvfs_cache(const std::string &path_,
}
}
int rv = 0;
std::unique_lock<std::shared_mutex> lk(g_cache_mutex);
// Only a successful statvfs refreshes the entry. A failure is
// returned to the caller and retried on the next call.
Element &e = g_cache[path_];
if((now - e.time) > g_timeout)
{
int rv;
struct statvfs st;
rv = fs::statvfs(path_,&st);
if(rv < 0)
return rv;
e.time = now;
rv = fs::statvfs(path_,&e.st);
e.st = st;
}
*st_ = e.st;
return rv;
return 0;
}
int