Browse Source

Merge pull request #80 from trapexit/minfreespace-xattr

add minfreespace to xattr interface
pull/83/head
Antonio SJ Musumeci 9 years ago
parent
commit
eebfe456f6
  1. 2
      README.md
  2. 15
      src/getxattr.cpp
  3. 12
      src/listxattr.cpp
  4. 25
      src/option_parser.cpp
  5. 23
      src/setxattr.cpp

2
README.md

@ -120,6 +120,7 @@ Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/
##### Keys ##### ##### Keys #####
* user.mergerfs.srcmounts * user.mergerfs.srcmounts
* user.mergerfs.minfreespace
* user.mergerfs.category.action * user.mergerfs.category.action
* user.mergerfs.category.create * user.mergerfs.category.create
* user.mergerfs.category.search * user.mergerfs.category.search
@ -149,6 +150,7 @@ Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/
``` ```
[trapexit:/tmp/mount] $ xattr -l .mergerfs [trapexit:/tmp/mount] $ xattr -l .mergerfs
user.mergerfs.srcmounts: /tmp/a:/tmp/b user.mergerfs.srcmounts: /tmp/a:/tmp/b
user.mergerfs.minfreespace: 4294967295
user.mergerfs.category.action: all user.mergerfs.category.action: all
user.mergerfs.category.create: epmfs user.mergerfs.category.create: epmfs
user.mergerfs.category.search: ff user.mergerfs.category.search: ff

15
src/getxattr.cpp

@ -29,6 +29,7 @@
#include <set> #include <set>
#include <algorithm> #include <algorithm>
#include <stdio.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
@ -92,6 +93,18 @@ _getxattr_controlfile_srcmounts(const Config &config,
attrvalue = str::join(config.srcmounts,':'); attrvalue = str::join(config.srcmounts,':');
} }
static
void
_getxattr_controlfile_minfreespace(const Config &config,
string &attrvalue)
{
char buf[64];
snprintf(buf,sizeof(buf),"%li",config.minfreespace);
attrvalue = buf;
}
static static
int int
_getxattr_controlfile(const Config &config, _getxattr_controlfile(const Config &config,
@ -108,6 +121,8 @@ _getxattr_controlfile(const Config &config,
if(!strcmp("srcmounts",attrbasename)) if(!strcmp("srcmounts",attrbasename))
_getxattr_controlfile_srcmounts(config,attrvalue); _getxattr_controlfile_srcmounts(config,attrvalue);
else if(!strcmp("minfreespace",attrbasename))
_getxattr_controlfile_minfreespace(config,attrvalue);
else if(!strncmp("category.",attrbasename,sizeof("category.")-1)) else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
_getxattr_controlfile_category_policy(config,&attrbasename[sizeof("category.")-1],attrvalue); _getxattr_controlfile_category_policy(config,&attrbasename[sizeof("category.")-1],attrvalue);
else if(!strncmp("func.",attrbasename,sizeof("func.")-1)) else if(!strncmp("func.",attrbasename,sizeof("func.")-1))

12
src/listxattr.cpp

@ -37,6 +37,7 @@
#include "ugid.hpp" #include "ugid.hpp"
#include "rwlock.hpp" #include "rwlock.hpp"
#include "xattr.hpp" #include "xattr.hpp"
#include "buildvector.hpp"
using std::string; using std::string;
using std::vector; using std::vector;
@ -48,12 +49,17 @@ _listxattr_controlfile(char *list,
const size_t size) const size_t size)
{ {
string xattrs; string xattrs;
const vector<string> strs =
buildvector<string>
("user.mergerfs.srcmounts")
("user.mergerfs.minfreespace");
xattrs.reserve(512); xattrs.reserve(512);
xattrs.append("user.mergerfs.srcmounts",sizeof("user.mergerfs.srcmounts"));
for(int i = Category::Enum::BEGIN; i < Category::Enum::END; i++)
for(size_t i = 0; i < strs.size(); i++)
xattrs += (strs[i] + '\0');
for(size_t i = Category::Enum::BEGIN; i < Category::Enum::END; i++)
xattrs += ("user.mergerfs.category." + (std::string)*Category::categories[i] + '\0'); xattrs += ("user.mergerfs.category." + (std::string)*Category::categories[i] + '\0');
for(int i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
for(size_t i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
xattrs += ("user.mergerfs.func." + (std::string)*FuseFunc::fusefuncs[i] + '\0'); xattrs += ("user.mergerfs.func." + (std::string)*FuseFunc::fusefuncs[i] + '\0');
if(size == 0) if(size == 0)

25
src/option_parser.cpp

@ -35,6 +35,7 @@
#include <iostream> #include <iostream>
#include "str.hpp" #include "str.hpp"
#include "num.hpp"
#include "config.hpp" #include "config.hpp"
#include "policy.hpp" #include "policy.hpp"
@ -106,29 +107,11 @@ int
parse_and_process_minfreespace(const std::string &value, parse_and_process_minfreespace(const std::string &value,
size_t &minfreespace) size_t &minfreespace)
{ {
char *endptr;
minfreespace = strtoll(value.c_str(),&endptr,10);
switch(*endptr)
{
case 'k':
case 'K':
minfreespace *= 1024;
break;
case 'm':
case 'M':
minfreespace *= (1024 * 1024);
break;
case 'g':
case 'G':
minfreespace *= (1024 * 1024 * 1024);
break;
int rv;
default:
rv = num::to_size_t(value,minfreespace);
if(rv == -1)
return 1; return 1;
}
return 0; return 0;
} }

23
src/setxattr.cpp

@ -38,6 +38,7 @@
#include "rwlock.hpp" #include "rwlock.hpp"
#include "xattr.hpp" #include "xattr.hpp"
#include "str.hpp" #include "str.hpp"
#include "num.hpp"
using std::string; using std::string;
using std::vector; using std::vector;
@ -165,6 +166,24 @@ _setxattr_srcmounts(vector<string> &srcmounts,
return -EINVAL; return -EINVAL;
} }
static
int
_setxattr_minfreespace(config::Config &config,
const string &attrval,
const int flags)
{
int rv;
if((flags & XATTR_CREATE) == XATTR_CREATE)
return -EEXIST;
rv = num::to_size_t(attrval,config.minfreespace);
if(rv == -1)
return -EINVAL;
return 0;
}
static static
int int
_setxattr_controlfile_func_policy(config::Config &config, _setxattr_controlfile_func_policy(config::Config &config,
@ -224,6 +243,10 @@ _setxattr_controlfile(config::Config &config,
config.destmount, config.destmount,
attrval, attrval,
flags); flags);
else if(!strcmp("minfreespace",attrbasename))
return _setxattr_minfreespace(config,
attrval,
flags);
else if(!strncmp("category.",attrbasename,sizeof("category.")-1)) else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
return _setxattr_controlfile_category_policy(config, return _setxattr_controlfile_category_policy(config,
&attrbasename[sizeof("category.")-1], &attrbasename[sizeof("category.")-1],

Loading…
Cancel
Save