Browse Source

Merge pull request #80 from trapexit/minfreespace-xattr

add minfreespace to xattr interface
pull/83/head
Antonio SJ Musumeci 10 years ago
parent
commit
eebfe456f6
  1. 2
      README.md
  2. 15
      src/getxattr.cpp
  3. 12
      src/listxattr.cpp
  4. 27
      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 #####
* user.mergerfs.srcmounts
* user.mergerfs.minfreespace
* user.mergerfs.category.action
* user.mergerfs.category.create
* 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
user.mergerfs.srcmounts: /tmp/a:/tmp/b
user.mergerfs.minfreespace: 4294967295
user.mergerfs.category.action: all
user.mergerfs.category.create: epmfs
user.mergerfs.category.search: ff

15
src/getxattr.cpp

@ -29,6 +29,7 @@
#include <set>
#include <algorithm>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
@ -92,6 +93,18 @@ _getxattr_controlfile_srcmounts(const Config &config,
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
int
_getxattr_controlfile(const Config &config,
@ -108,6 +121,8 @@ _getxattr_controlfile(const Config &config,
if(!strcmp("srcmounts",attrbasename))
_getxattr_controlfile_srcmounts(config,attrvalue);
else if(!strcmp("minfreespace",attrbasename))
_getxattr_controlfile_minfreespace(config,attrvalue);
else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
_getxattr_controlfile_category_policy(config,&attrbasename[sizeof("category.")-1],attrvalue);
else if(!strncmp("func.",attrbasename,sizeof("func.")-1))

12
src/listxattr.cpp

@ -37,6 +37,7 @@
#include "ugid.hpp"
#include "rwlock.hpp"
#include "xattr.hpp"
#include "buildvector.hpp"
using std::string;
using std::vector;
@ -48,12 +49,17 @@ _listxattr_controlfile(char *list,
const size_t size)
{
string xattrs;
const vector<string> strs =
buildvector<string>
("user.mergerfs.srcmounts")
("user.mergerfs.minfreespace");
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');
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');
if(size == 0)

27
src/option_parser.cpp

@ -35,6 +35,7 @@
#include <iostream>
#include "str.hpp"
#include "num.hpp"
#include "config.hpp"
#include "policy.hpp"
@ -106,29 +107,11 @@ int
parse_and_process_minfreespace(const std::string &value,
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:
return 1;
}
rv = num::to_size_t(value,minfreespace);
if(rv == -1)
return 1;
return 0;
}

23
src/setxattr.cpp

@ -38,6 +38,7 @@
#include "rwlock.hpp"
#include "xattr.hpp"
#include "str.hpp"
#include "num.hpp"
using std::string;
using std::vector;
@ -165,6 +166,24 @@ _setxattr_srcmounts(vector<string> &srcmounts,
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
int
_setxattr_controlfile_func_policy(config::Config &config,
@ -224,6 +243,10 @@ _setxattr_controlfile(config::Config &config,
config.destmount,
attrval,
flags);
else if(!strcmp("minfreespace",attrbasename))
return _setxattr_minfreespace(config,
attrval,
flags);
else if(!strncmp("category.",attrbasename,sizeof("category.")-1))
return _setxattr_controlfile_category_policy(config,
&attrbasename[sizeof("category.")-1],

Loading…
Cancel
Save