Rework new lup policy to work on 32bit systems (#1603)

__int128 is not available on 32bit platforms. Moved to extended
precision floats.
This commit is contained in:
trapexit 2025-12-14 14:56:34 -06:00 • committed by GitHub
parent 22df87c86a
commit 4d1760cb69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 174 additions and 155 deletions

View file

@ -0,0 +1,24 @@
#pragma once
#include <stdint.h>
typedef uint32_t u32;
typedef int32_t s32;
typedef uint64_t u64;
typedef int64_t s64;
typedef const uint32_t cu32;
typedef const int32_t cs32;
typedef const uint64_t cu64;
typedef const int64_t cs64;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef char assertion_f32_is_32bit[sizeof(f32) == 4 ? 1 : -1];
typedef char assertion_f64_is_64bit[sizeof(f64) == 8 ? 1 : -1];
typedef char assertion_f80_is_at_least_64bit[sizeof(f64) >= 8 ? 1 : -1];
typedef const float cf32;
typedef const double cf64;
typedef const long double cf80;

View file

@ -1,6 +1,6 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
#include <climits>
#include <string>

View file

@ -18,7 +18,7 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
#include "fuse_msgbuf_t.h"
u32 msgbuf_get_pagesize();

View file

@ -1,13 +0,0 @@
#pragma once
#include <stdint.h>
typedef uint64_t u32;
typedef int64_t s32;
typedef uint64_t u64;
typedef int64_t s64;
typedef const uint64_t cu32;
typedef const int64_t cs32;
typedef const uint64_t cu64;
typedef const int64_t cs64;

View file

@ -18,7 +18,7 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
#include "strvec.hpp"
#include "tofrom_string.hpp"
#include "fs_path.hpp"

View file

@ -23,7 +23,7 @@
#include "fs_glob.hpp"
#include "fs_is_rofs.hpp"
#include "fs_realpathize.hpp"
#include "int_types.h"
#include "base_types.h"
#include "num.hpp"
#include "str.hpp"
#include "syslog.hpp"

View file

@ -18,7 +18,7 @@
#include "fh.hpp"
#include "int_types.h"
#include "base_types.h"
class DirInfo : public FH

View file

@ -20,9 +20,9 @@
#include "fh.hpp"
#include "fs_path.hpp"
#include <mutex>
#include "base_types.h"
#include "int_types.h"
#include <mutex>
class FileInfo : public FH

View file

@ -18,7 +18,7 @@
#include <string>
#include "int_types.h"
#include "base_types.h"
#define FS_ATTR_NONE (0)
#define FS_ATTR_CLEAR_IMMUTABLE (1 << 0)

View file

@ -18,7 +18,7 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
namespace fs

View file

@ -20,7 +20,7 @@
#include "fs_copy_file_range.hpp"
#include "fs_fstat.hpp"
#include "int_types.h"
#include "base_types.h"
static

View file

@ -16,7 +16,7 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
namespace fs

View file

@ -16,7 +16,7 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
namespace fs
{

View file

@ -1,6 +1,6 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
#include "fs_path.hpp"
#include <sys/stat.h>

View file

@ -16,6 +16,7 @@
#include "fs_movefile_and_open.hpp"
#include "base_types.h"
#include "errno.hpp"
#include "fs_clonepath.hpp"
#include "fs_close.hpp"
@ -30,7 +31,6 @@
#include "fs_rename.hpp"
#include "fs_stat.hpp"
#include "fs_unlink.hpp"
#include "int_types.h"
#include "policy.hpp"
#include "ugid.hpp"

View file

@ -18,7 +18,7 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
#include "to_neg_errno.hpp"
#include <unistd.h>

View file

@ -1,20 +1,21 @@
#include "mergerfs_fsck.hpp"
#include "fs_close.hpp"
#include "fs_copyfile.hpp"
#include "fs_lchmod.hpp"
#include "fs_lchown.hpp"
#include "fs_close.hpp"
#include "fs_lgetxattr.hpp"
#include "fs_lstat.hpp"
#include "fs_open.hpp"
#include "int_types.h"
#include "str.hpp"
#include "fs_copyfile.hpp"
#include "mergerfs_api.hpp"
#include "str.hpp"
#include "fmt/core.h"
#include "fmt/chrono.h"
#include "CLI11.hpp"
#include "base_types.h"
#include <filesystem>
namespace FS = std::filesystem;

View file

@ -1,6 +1,6 @@
#pragma once
#include "int_types.h"
#include "base_types.h"
#include <sys/ioctl.h>

View file

@ -26,6 +26,8 @@
#include "policy_error.hpp"
#include "rwlock.hpp"
#include "base_types.h"
#include <limits>
#include <string>
@ -33,60 +35,61 @@ using std::string;
static
int
_action(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch *> &paths_)
_action(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch*> &paths_)
{
int rv;
int error;
fs::info_t info;
Branch *obranch;
u64 best_used;
u64 best_total;
best_used = 0;
best_total = 1;
obranch = nullptr;
error = ENOENT;
uint64_t best_used = 0;
uint64_t best_total = 1;
for (auto &branch : *branches_)
{
if (branch.ro())
error_and_continue(error, EROFS);
if (!fs::exists(branch.path, fusepath_))
error_and_continue(error, ENOENT);
rv = fs::info(branch.path, &info);
if (rv < 0)
error_and_continue(error, ENOENT);
if (info.readonly)
error_and_continue(error, EROFS);
uint64_t used = info.spaceused;
uint64_t total = info.spaceused + info.spaceavail;
if (total == 0)
for(auto &branch : *branches_)
{
used = 0;
total = 1;
}
if(branch.ro())
error_and_continue(error,EROFS);
if(!fs::exists(branch.path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch.path,&info);
if(rv < 0)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
u64 used = info.spaceused;
u64 total = info.spaceused + info.spaceavail;
if(total == 0)
{
used = 0;
total = 1;
}
if(obranch == nullptr)
{
best_used = used;
best_total = total;
obranch = &branch;
continue;
}
f80 lhs = (f80)used * (f80)best_total;
f80 rhs = (f80)best_used * (f80)total;
if(lhs >= rhs)
continue;
if (obranch == nullptr)
{
best_used = used;
best_total = total;
obranch = &branch;
continue;
}
unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total;
unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total;
if (lhs >= rhs)
continue;
best_used = used;
best_total = total;
obranch = &branch;
}
if (obranch == nullptr)
if(obranch == nullptr)
return -error;
paths_.push_back(obranch);
@ -101,51 +104,53 @@ _search(const Branches::Ptr &branches_,
std::vector<Branch *> &paths_)
{
int rv;
uint64_t used;
uint64_t avail;
uint64_t best_used = 0;
uint64_t best_total = 1;
u64 used;
u64 avail;
u64 best_used;
u64 best_total;
Branch *obranch;
best_used = 0;
best_total = 1;
obranch = nullptr;
for (auto &branch : *branches_)
{
if (!fs::exists(branch.path, fusepath_))
continue;
rv = fs::statvfs_cache_spaceused(branch.path, &used);
if (rv < 0)
continue;
rv = fs::statvfs_cache_spaceavail(branch.path, &avail);
if (rv < 0)
continue;
uint64_t total = used + avail;
if (total == 0)
for(auto &branch : *branches_)
{
used = 0;
total = 1;
}
if(!fs::exists(branch.path,fusepath_))
continue;
rv = fs::statvfs_cache_spaceused(branch.path,&used);
if(rv < 0)
continue;
rv = fs::statvfs_cache_spaceavail(branch.path,&avail);
if(rv < 0)
continue;
u64 total = used + avail;
if(total == 0)
{
used = 0;
total = 1;
}
if(obranch == nullptr)
{
best_used = used;
best_total = total;
obranch = &branch;
continue;
}
f80 lhs = (f80)used * (f80)best_total;
f80 rhs = (f80)best_used * (f80)total;
if(lhs >= rhs)
continue;
if (obranch == nullptr)
{
best_used = used;
best_total = total;
obranch = &branch;
continue;
}
unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total;
unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total;
if (lhs >= rhs)
continue;
best_used = used;
best_total = total;
obranch = &branch;
}
if (obranch == nullptr)
if(obranch == nullptr)
return -ENOENT;
paths_.push_back(obranch);
@ -155,59 +160,60 @@ _search(const Branches::Ptr &branches_,
static
int
_create(const Branches::Ptr &branches_,
std::vector<Branch *> &paths_)
_create(const Branches::Ptr &branches_,
std::vector<Branch*> &paths_)
{
int rv;
int error;
u64 best_used;
u64 best_total;
fs::info_t info;
Branch *obranch;
best_used = 0;
best_total = 1;
obranch = nullptr;
error = ENOENT;
uint64_t best_used = 0;
uint64_t best_total = 1;
for (auto &branch : *branches_)
{
if (branch.ro_or_nc())
error_and_continue(error, EROFS);
rv = fs::info(branch.path, &info);
if (rv < 0)
error_and_continue(error, ENOENT);
if (info.readonly)
error_and_continue(error, EROFS);
if (info.spaceavail < branch.minfreespace())
error_and_continue(error, ENOSPC);
uint64_t used = info.spaceused;
uint64_t total = info.spaceused + info.spaceavail;
if (total == 0)
for(auto &branch : *branches_)
{
used = 0;
total = 1;
}
if(branch.ro_or_nc())
error_and_continue(error,EROFS);
rv = fs::info(branch.path,&info);
if(rv < 0)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < branch.minfreespace())
error_and_continue(error,ENOSPC);
u64 used = info.spaceused;
u64 total = info.spaceused + info.spaceavail;
if(total == 0)
{
used = 0;
total = 1;
}
if(obranch == nullptr)
{
best_used = used;
best_total = total;
obranch = &branch;
continue;
}
f80 lhs = (f80)used * (f80)best_total;
f80 rhs = (f80)best_used * (f80)total;
if(lhs >= rhs)
continue;
if (obranch == nullptr)
{
best_used = used;
best_total = total;
obranch = &branch;
continue;
}
unsigned __int128 lhs = (unsigned __int128)used * (unsigned __int128)best_total;
unsigned __int128 rhs = (unsigned __int128)best_used * (unsigned __int128)total;
if (lhs >= rhs)
continue;
best_used = used;
best_total = total;
obranch = &branch;
}
if (obranch == nullptr)
if(obranch == nullptr)
return -error;
paths_.push_back(obranch);
@ -216,25 +222,25 @@ _create(const Branches::Ptr &branches_,
}
int
Policy::LUP::Action::operator()(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch *> &paths_) const
Policy::LUP::Action::operator()(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch*> &paths_) const
{
return ::_action(branches_, fusepath_, paths_);
return ::_action(branches_,fusepath_,paths_);
}
int
Policy::LUP::Create::operator()(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch *> &paths_) const
Policy::LUP::Create::operator()(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch*> &paths_) const
{
return ::_create(branches_, paths_);
return ::_create(branches_,paths_);
}
int
Policy::LUP::Search::operator()(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch *> &paths_) const
Policy::LUP::Search::operator()(const Branches::Ptr &branches_,
const fs::path &fusepath_,
std::vector<Branch*> &paths_) const
{
return ::_search(branches_, fusepath_, paths_);
return ::_search(branches_,fusepath_,paths_);
}

View file

@ -19,7 +19,8 @@
#pragma once
#include "fuse_kernel.h"
#include "int_types.h"
#include "base_types.h"
#include <string>