FUSE: pass Branches::Ptr by value with empty-branches guards

Previously most FUSE ops took a reference to the live cfg.branches
object. With atomic_load now producing a shared_ptr snapshot, pass
it by value: the op works against a single stable view of the
configuration for its whole lifetime, immune to concurrent
reconfiguration.

Also bail out with -ENOENT when the policy returns an empty branch
set rather than dereferencing branches[0]. This was reachable if a
policy rejected every branch (e.g. everything readonly while
looking for a writable target).

Covers access, chmod, chown, create, getattr, getxattr, ioctl,
link, listxattr, mkdir, mknod, open, readdir (cor/cosr),
readlink, removexattr, rename, rmdir, setxattr, statfs, statx,
symlink, truncate, unlink, utimens.

While here, in _getattr only dereference st_->st_mode when lstat
succeeded (it is otherwise uninitialized).
This commit is contained in:
Antonio S. Musumeci 2026-04-18 00:56:15 -04:00 • committed by trapexit
parent 98648ae44b
commit 0c17492c78
25 changed files with 110 additions and 45 deletions

View file

@ -70,8 +70,8 @@ _remove(const StrVec &toremove_)
static
int
_rename_create_path(const Policy::Search &searchPolicy_,
const Policy::Action &actionPolicy_,
const Branches::Ptr &branches_,
const Policy::Action &actionPolicy_,
const Branches::Ptr branches_,
const fs::path &oldfusepath_,
const fs::path &newfusepath_)
{
@ -86,10 +86,14 @@ _rename_create_path(const Policy::Search &searchPolicy_,
rv = actionPolicy_(branches_,oldfusepath_,oldbranches);
if(rv < 0)
return rv;
if(oldbranches.empty())
return -ENOENT;
rv = searchPolicy_(branches_,newfusepath_.parent_path(),newbranches);
if(rv < 0)
return rv;
if(newbranches.empty())
return -ENOENT;
for(auto &branch : *branches_)
{
@ -127,7 +131,7 @@ _rename_create_path(const Policy::Search &searchPolicy_,
static
int
_rename_preserve_path(const Policy::Action &actionPolicy_,
const Branches::Ptr &branches_,
const Branches::Ptr branches_,
const fs::path &oldfusepath_,
const fs::path &newfusepath_)
{
@ -198,7 +202,7 @@ _rename_exdev_rename_back(const std::vector<Branch*> &branches_,
static
int
_rename_exdev_rename_target(const Policy::Action &actionPolicy_,
const Branches::Ptr &ibranches_,
const Branches::Ptr ibranches_,
const fs::path &oldfusepath_,
std::vector<Branch*> &obranches_)
{
@ -245,8 +249,8 @@ _rename_exdev_rename_target(const Policy::Action &actionPolicy_,
static
int
_rename_exdev_rel_symlink(const fuse_req_ctx_t *ctx_,
const Policy::Action &actionPolicy_,
const Branches::Ptr &branches_,
const Policy::Action &actionPolicy_,
const Branches::Ptr branches_,
const fs::path &oldfusepath_,
const fs::path &newfusepath_)
{
@ -274,8 +278,8 @@ _rename_exdev_rel_symlink(const fuse_req_ctx_t *ctx_,
static
int
_rename_exdev_abs_symlink(const fuse_req_ctx_t *ctx_,
const Policy::Action &actionPolicy_,
const Branches::Ptr &branches_,
const Policy::Action &actionPolicy_,
const Branches::Ptr branches_,
const fs::path &mount_,
const fs::path &oldfusepath_,
const fs::path &newfusepath_)