Merge pull request #139 from trapexit/setxattr-cleanup

cleanup controlfile manipulation
This commit is contained in:
Antonio SJ Musumeci 2015-09-14 22:42:06 -04:00
commit 1cc1b1f746

View File

@ -189,7 +189,7 @@ _setxattr_minfreespace(Config &config,
static static
int int
_setxattr_controlfile_func_policy(Config &config, _setxattr_controlfile_func_policy(Config &config,
const char *funcname, const string &funcname,
const string &attrval, const string &attrval,
const int flags) const int flags)
{ {
@ -208,7 +208,7 @@ _setxattr_controlfile_func_policy(Config &config,
static static
int int
_setxattr_controlfile_category_policy(Config &config, _setxattr_controlfile_category_policy(Config &config,
const char *categoryname, const string &categoryname,
const string &attrval, const string &attrval,
const int flags) const int flags)
{ {
@ -227,38 +227,45 @@ _setxattr_controlfile_category_policy(Config &config,
static static
int int
_setxattr_controlfile(Config &config, _setxattr_controlfile(Config &config,
const char *attrname, const string &attrname,
const string &attrval, const string &attrval,
const int flags) const int flags)
{ {
const char *attrbasename = &attrname[sizeof("user.mergerfs.")-1]; vector<string> attr;
if(strncmp("user.mergerfs.",attrname,sizeof("user.mergerfs.")-1)) str::split(attr,attrname,'.');
return -ENOATTR;
if(attrval.empty()) switch(attr.size())
return -EINVAL; {
case 3:
if(attr[2] == "srcmounts")
return _setxattr_srcmounts(config.srcmounts,
config.srcmountslock,
config.destmount,
attrval,
flags);
else if(attr[2] == "minfreespace")
return _setxattr_minfreespace(config,
attrval,
flags);
break;
if(!strcmp("srcmounts",attrbasename)) case 4:
return _setxattr_srcmounts(config.srcmounts, if(attr[2] == "category")
config.srcmountslock, return _setxattr_controlfile_category_policy(config,
config.destmount, attr[3],
attrval, attrval,
flags); flags);
else if(!strcmp("minfreespace",attrbasename)) else if(attr[2] == "func")
return _setxattr_minfreespace(config, return _setxattr_controlfile_func_policy(config,
attrval, attr[3],
flags);
else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
return _setxattr_controlfile_category_policy(config,
&attrbasename[sizeof("category.")-1],
attrval, attrval,
flags); flags);
else if(!strncmp("func.",attrbasename,sizeof("func.")-1)) break;
return _setxattr_controlfile_func_policy(config,
&attrbasename[sizeof("func.")-1], default:
attrval, break;
flags); }
return -EINVAL; return -EINVAL;
} }