config: rework global config, remove rwlock, make branches RCU like

Also added unit tests. Should have done separately but found a number of bugs.
This commit is contained in:
Antonio SJ Musumeci 2020-12-19 15:06:08 -05:00
parent 2e4c6c5fd1
commit 538467b86d
327 changed files with 6691 additions and 3036 deletions

View file

@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE
#include "branch.hpp"
#include "branches.hpp"
#include "errno.hpp"
#include "fs_closedir.hpp"
#include "fs_devid.hpp"
@ -27,10 +27,9 @@
#include "fs_readdir.hpp"
#include "fs_stat.hpp"
#include "hashset.hpp"
#include "rwlock.hpp"
#include <fuse.h>
#include <fuse_dirents.h>
#include "fuse.h"
#include "fuse_dirents.h"
#include <string>
#include <vector>
@ -40,6 +39,7 @@
using std::string;
using std::vector;
namespace l
{
static
@ -57,9 +57,9 @@ namespace l
static
int
readdir(const BranchVec &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
readdir(const Branches::CPtr &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
{
dev_t dev;
HashSet names;
@ -67,13 +67,13 @@ namespace l
string fullpath;
uint64_t namelen;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
for(const auto &branch : *branches_)
{
int rv;
int dirfd;
DIR *dh;
basepath = fs::path::make(branches_[i].path,dirname_);
basepath = fs::path::make(branch.path,dirname_);
dh = fs::opendir(basepath);
if(!dh)
@ -81,8 +81,6 @@ namespace l
dirfd = fs::dirfd(dh);
dev = fs::devid(dirfd);
if(dev == (dev_t)-1)
dev = i;
rv = 0;
for(struct dirent *de = fs::readdir(dh); de && !rv; de = fs::readdir(dh))
@ -110,25 +108,14 @@ namespace l
return 0;
}
static
int
readdir(const Branches &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
{
rwlock::ReadGuard guard(branches_.lock);
return l::readdir(branches_.vec,dirname_,buf_);
}
}
namespace FUSE
{
int
readdir_posix(const Branches &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
readdir_posix(const Branches::CPtr &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
{
return l::readdir(branches_,dirname_,buf_);
}