mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-22 07:56:32 -05:00
add ability to turn on/off xattr support at runtime
This commit is contained in:
parent
6ee44e451c
commit
65f482e483
9 changed files with 138 additions and 18 deletions
|
|
@ -47,6 +47,7 @@ namespace mergerfs
|
|||
ignorepponrename(false),
|
||||
security_capability(true),
|
||||
link_cow(false),
|
||||
xattr(0),
|
||||
POLICYINIT(access),
|
||||
POLICYINIT(chmod),
|
||||
POLICYINIT(chown),
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ namespace mergerfs
|
|||
bool ignorepponrename;
|
||||
bool security_capability;
|
||||
bool link_cow;
|
||||
int xattr;
|
||||
|
||||
public:
|
||||
const Policy *policies[FuseFunc::Enum::END];
|
||||
|
|
|
|||
|
|
@ -140,6 +140,28 @@ _getxattr_controlfile_bool(const bool boolvalue,
|
|||
attrvalue = (boolvalue ? "true" : "false");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_errno(const int errno_,
|
||||
string &attrvalue)
|
||||
{
|
||||
switch(errno_)
|
||||
{
|
||||
case 0:
|
||||
attrvalue = "passthrough";
|
||||
break;
|
||||
case ENOATTR:
|
||||
attrvalue = "noattr";
|
||||
break;
|
||||
case ENOTSUP:
|
||||
attrvalue = "notsup";
|
||||
break;
|
||||
default:
|
||||
attrvalue = "ERROR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_getxattr_controlfile_policies(const Config &config,
|
||||
|
|
@ -210,6 +232,8 @@ _getxattr_controlfile(const Config &config,
|
|||
_getxattr_controlfile_bool(config.ignorepponrename,attrvalue);
|
||||
else if(attr[2] == "security_capability")
|
||||
_getxattr_controlfile_bool(config.security_capability,attrvalue);
|
||||
else if(attr[2] == "xattr")
|
||||
_getxattr_controlfile_errno(config.xattr,attrvalue);
|
||||
else if(attr[2] == "link_cow")
|
||||
_getxattr_controlfile_bool(config.link_cow,attrvalue);
|
||||
else if(attr[2] == "policies")
|
||||
|
|
@ -347,16 +371,19 @@ namespace mergerfs
|
|||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if((config.security_capability == false) &&
|
||||
_is_attrname_security_capability(attrname))
|
||||
return -ENOATTR;
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _getxattr_controlfile(config,
|
||||
attrname,
|
||||
buf,
|
||||
count);
|
||||
|
||||
if((config.security_capability == false) &&
|
||||
_is_attrname_security_capability(attrname))
|
||||
return -ENOATTR;
|
||||
|
||||
if(config.xattr)
|
||||
return -config.xattr;
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,9 @@ _listxattr_controlfile(char *list,
|
|||
("user.mergerfs.symlinkify_timeout")
|
||||
("user.mergerfs.nullrw")
|
||||
("user.mergerfs.ignorepponrename")
|
||||
("user.mergerfs.security_capability")
|
||||
("user.mergerfs.link_cow")
|
||||
("user.mergerfs.security_capability")
|
||||
("user.mergerfs.xattr")
|
||||
("user.mergerfs.policies")
|
||||
("user.mergerfs.version")
|
||||
("user.mergerfs.pid");
|
||||
|
|
@ -115,6 +116,16 @@ namespace mergerfs
|
|||
if(fusepath == config.controlfile)
|
||||
return _listxattr_controlfile(list,size);
|
||||
|
||||
switch(config.xattr)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case ENOATTR:
|
||||
return 0;
|
||||
default:
|
||||
return -config.xattr;
|
||||
}
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include <iomanip>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "errno.hpp"
|
||||
#include "fs_glob.hpp"
|
||||
#include "num.hpp"
|
||||
#include "policy.hpp"
|
||||
|
|
@ -148,6 +149,23 @@ parse_and_process(const std::string &value,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_errno(const std::string &value_,
|
||||
int &errno_)
|
||||
{
|
||||
if(value_ == "passthrough")
|
||||
errno_ = 0;
|
||||
else if(value_ == "notsup")
|
||||
errno_ = ENOTSUP;
|
||||
else if(value_ == "noattr")
|
||||
errno_ = ENOATTR;
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
parse_and_process_arg(Config &config,
|
||||
|
|
@ -199,6 +217,8 @@ parse_and_process_kv_arg(Config &config,
|
|||
rv = parse_and_process(value,config.security_capability);
|
||||
else if(key == "link_cow")
|
||||
rv = parse_and_process(value,config.link_cow);
|
||||
else if(key == "xattr")
|
||||
rv = parse_and_process_errno(value,config.xattr);
|
||||
}
|
||||
|
||||
if(rv == -1)
|
||||
|
|
@ -305,11 +325,17 @@ usage(void)
|
|||
" -o ignorepponrename=<bool>\n"
|
||||
" Ignore path preserving when performing renames\n"
|
||||
" and links. default = false\n"
|
||||
" -o link_cow=<bool> delink/clone file on open to simulate CoW.\n"
|
||||
" default = false\n"
|
||||
" -o security_capability=<bool>\n"
|
||||
" When disabled return ENOATTR when the xattr\n"
|
||||
" security.capability is queried. default = true\n"
|
||||
" -o link_cow=<bool> delink/clone file on open to simulate CoW.\n"
|
||||
" default = false\n"
|
||||
" -o xattr=passthrough|noattr|notsup\n"
|
||||
" Runtime control of xattrs. By default xattr\n"
|
||||
" requests will pass through to the underlying\n"
|
||||
" filesystems. notattr will short circuit as if\n"
|
||||
" nothing exists. notsup will respond as if not\n"
|
||||
" supported or disabled. default = passthrough\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ namespace mergerfs
|
|||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -ENOTSUP;
|
||||
return -ENOATTR;
|
||||
if(config.xattr)
|
||||
return -config.xattr;
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
|
|
|||
|
|
@ -33,12 +33,21 @@
|
|||
#include "str.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
static const char SECURITY_CAPABILITY[] = "security.capability";
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::FuseFunc;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
bool
|
||||
_is_attrname_security_capability(const char *attrname_)
|
||||
{
|
||||
return (strcmp(attrname_,SECURITY_CAPABILITY) == 0);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_add_srcmounts(vector<string> &srcmounts,
|
||||
|
|
@ -411,6 +420,13 @@ namespace mergerfs
|
|||
string(attrval,attrvalsize),
|
||||
flags);
|
||||
|
||||
if((config.security_capability == false) &&
|
||||
_is_attrname_security_capability(attrname))
|
||||
return -ENOATTR;
|
||||
|
||||
if(config.xattr)
|
||||
return -config.xattr;
|
||||
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue