mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-02-22 15:43:12 +08:00
Merge pull request #210 from trapexit/statvfs
fix statvfs drive dedup. closes #209
This commit is contained in:
commit
1160868243
@ -19,6 +19,7 @@
|
|||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -30,33 +31,35 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::set;
|
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
|
||||||
#define CMP(FOO) (lhs.f_##FOO < rhs.f_##FOO)
|
#define EQ(FOO) (lhs.f_##FOO == rhs.f_##FOO)
|
||||||
|
|
||||||
struct
|
static
|
||||||
statvfs_compare
|
bool
|
||||||
|
operator==(const struct statvfs &lhs,
|
||||||
|
const struct statvfs &rhs)
|
||||||
{
|
{
|
||||||
bool
|
return (EQ(bsize) &&
|
||||||
operator()(const struct statvfs &lhs,
|
EQ(frsize) &&
|
||||||
const struct statvfs &rhs) const
|
EQ(blocks) &&
|
||||||
{
|
EQ(bfree) &&
|
||||||
return (CMP(bsize) &&
|
EQ(bavail) &&
|
||||||
CMP(frsize) &&
|
EQ(files) &&
|
||||||
CMP(blocks) &&
|
EQ(ffree) &&
|
||||||
CMP(bfree) &&
|
EQ(favail) &&
|
||||||
CMP(bavail) &&
|
EQ(fsid) &&
|
||||||
CMP(files) &&
|
EQ(flag) &&
|
||||||
CMP(ffree) &&
|
EQ(namemax));
|
||||||
CMP(favail) &&
|
}
|
||||||
CMP(fsid) &&
|
|
||||||
CMP(flag) &&
|
|
||||||
CMP(namemax));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef set<struct statvfs,statvfs_compare> statvfs_set;
|
static
|
||||||
|
bool
|
||||||
|
member(const vector<struct statvfs> &haystack,
|
||||||
|
const struct statvfs &needle)
|
||||||
|
{
|
||||||
|
return (std::find(haystack.begin(),haystack.end(),needle) != haystack.end());
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
@ -92,18 +95,18 @@ int
|
|||||||
_statfs(const vector<string> &srcmounts,
|
_statfs(const vector<string> &srcmounts,
|
||||||
struct statvfs &fsstat)
|
struct statvfs &fsstat)
|
||||||
{
|
{
|
||||||
statvfs_set fsstats;
|
vector<struct statvfs> fsstats;
|
||||||
unsigned long min_bsize = ULONG_MAX;
|
unsigned long min_bsize = ULONG_MAX;
|
||||||
unsigned long min_frsize = ULONG_MAX;
|
unsigned long min_frsize = ULONG_MAX;
|
||||||
unsigned long min_namemax = ULONG_MAX;
|
unsigned long min_namemax = ULONG_MAX;
|
||||||
|
|
||||||
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
|
for(size_t i = 0, ei = srcmounts.size(); i < ei; i++)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
struct statvfs fsstat;
|
struct statvfs fsstat;
|
||||||
|
|
||||||
rv = ::statvfs(srcmounts[i].c_str(),&fsstat);
|
rv = ::statvfs(srcmounts[i].c_str(),&fsstat);
|
||||||
if(rv == -1)
|
if((rv == -1) || member(fsstats,fsstat))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(min_bsize > fsstat.f_bsize)
|
if(min_bsize > fsstat.f_bsize)
|
||||||
@ -113,18 +116,17 @@ _statfs(const vector<string> &srcmounts,
|
|||||||
if(min_namemax > fsstat.f_namemax)
|
if(min_namemax > fsstat.f_namemax)
|
||||||
min_namemax = fsstat.f_namemax;
|
min_namemax = fsstat.f_namemax;
|
||||||
|
|
||||||
fsstats.insert(fsstat);
|
fsstats.push_back(fsstat);
|
||||||
}
|
}
|
||||||
|
|
||||||
statvfs_set::const_iterator fsstatiter = fsstats.begin();
|
if(!fsstats.empty())
|
||||||
statvfs_set::const_iterator endfsstatiter = fsstats.end();
|
|
||||||
if(fsstatiter != endfsstatiter)
|
|
||||||
{
|
{
|
||||||
fsstat = *fsstatiter;
|
fsstat = fsstats[0];
|
||||||
_normalize_statvfs(&fsstat,min_bsize,min_frsize,min_namemax);
|
_normalize_statvfs(&fsstat,min_bsize,min_frsize,min_namemax);
|
||||||
for(++fsstatiter;fsstatiter != endfsstatiter;++fsstatiter)
|
|
||||||
|
for(size_t i = 1, ei = fsstats.size(); i < ei; i++)
|
||||||
{
|
{
|
||||||
struct statvfs tmp = *fsstatiter;
|
struct statvfs tmp = fsstats[i];
|
||||||
|
|
||||||
_normalize_statvfs(&tmp,min_bsize,min_frsize,min_namemax);
|
_normalize_statvfs(&tmp,min_bsize,min_frsize,min_namemax);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user