Add podman release build tooling + misc build fixes (#1455)

This commit is contained in:
trapexit 2025-05-08 00:00:53 -05:00 • committed by GitHub
parent 344014aa81
commit fa3266ca7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
90 changed files with 1207 additions and 3657 deletions

View file

@ -30,11 +30,11 @@ public:
typedef E ENUM;
public:
Enum<ENUM>()
Enum()
{
}
Enum<ENUM>(const ENUM data_)
Enum(const ENUM data_)
: _data(data_)
{
}

View file

@ -15,9 +15,9 @@
*/
#ifdef __linux__
#warning "using fs_attr_linux.icpp"
#pragma message "using fs_attr_linux.icpp"
#include "fs_attr_linux.icpp"
#else
#warning "using fs_attr_unsupported.icpp"
#pragma message "using fs_attr_unsupported.icpp"
#include "fs_attr_unsupported.icpp"
#endif

View file

@ -17,9 +17,9 @@
*/
#ifdef __linux__
#warning "using fs_copy_file_range_linux.icpp"
#pragma message "using fs_copy_file_range_linux.icpp"
#include "fs_copy_file_range_linux.icpp"
#else
#warning "using fs_copy_file_range_unsupported.icpp"
#pragma message "using fs_copy_file_range_unsupported.icpp"
#include "fs_copy_file_range_unsupported.icpp"
#endif

View file

@ -17,10 +17,10 @@
#include <fcntl.h>
#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
#warning "using fs_fadvise_posix.icpp"
#pragma message "using fs_fadvise_posix.icpp"
#include "fs_fadvise_posix.icpp"
#else
#warning "using fs_fadvise_unsupported.icpp"
#pragma message "using fs_fadvise_unsupported.icpp"
#include "fs_fadvise_unsupported.icpp"
#endif

View file

@ -17,9 +17,9 @@
*/
#ifdef __linux__
#warning "using fs_ficlone_linux.icpp"
#pragma message "using fs_ficlone_linux.icpp"
#include "fs_ficlone_linux.icpp"
#else
#warning "using fs_ficlone_unsupported.icpp"
#pragma message "using fs_ficlone_unsupported.icpp"
#include "fs_ficlone_unsupported.icpp"
#endif

View file

@ -23,13 +23,13 @@
#include <sys/stat.h>
#ifdef __linux__
#warning "using fs_futimens_linux.hpp"
#pragma message "using fs_futimens_linux.hpp"
#include "fs_futimens_linux.hpp"
#elif __FreeBSD__ >= 11
#warning "using fs_futimens_freebsd_11.hpp"
#pragma message "using fs_futimens_freebsd_11.hpp"
#include "fs_futimens_freebsd_11.hpp"
#else
#warning "using fs_futimens_generic.hpp"
#pragma message "using fs_futimens_generic.hpp"
#include "fs_futimens_generic.hpp"
#endif

View file

@ -17,9 +17,9 @@
*/
#if __APPLE__
#warning "using fs_futimesat_osx.icpp"
#pragma message "using fs_futimesat_osx.icpp"
#include "fs_futimesat_osx.icpp"
#else
#warning "using fs_futimesat_generic.icpp"
#pragma message "using fs_futimesat_generic.icpp"
#include "fs_futimesat_generic.icpp"
#endif

View file

@ -15,9 +15,9 @@
*/
#ifdef __linux__
#warning "using fs_sendfile_linux.icpp"
#pragma message "using fs_sendfile_linux.icpp"
#include "fs_sendfile_linux.icpp"
#else
#warning "using fs_sendfile_unsupported.icpp"
#pragma message "using fs_sendfile_unsupported.icpp"
#include "fs_sendfile_unsupported.icpp"
#endif

View file

@ -11,6 +11,10 @@
#include <fcntl.h>
#include <sys/stat.h>
#ifdef STATX_TYPE
#define MERGERFS_STATX_SUPPORTED
#endif
namespace fs
{
static
@ -22,7 +26,7 @@ namespace fs
const unsigned int mask_,
struct fuse_statx *st_)
{
#ifdef STATX_TYPE
#ifdef MERGERFS_STATX_SUPPORTED
int rv;
rv = ::statx(dirfd_,

View file

@ -19,12 +19,12 @@
#pragma once
#ifdef __linux__
#warning "using fs_utimensat_linux.hpp"
#pragma message "using fs_utimensat_linux.hpp"
#include "fs_utimensat_linux.hpp"
#elif __FreeBSD__
#warning "using fs_utimensat_freebsd.hpp"
#pragma message "using fs_utimensat_freebsd.hpp"
#include "fs_utimensat_freebsd.hpp"
#else
#warning "using fs_utimensat_generic.hpp"
#pragma message "using fs_utimensat_generic.hpp"
#include "fs_utimensat_generic.hpp"
#endif

View file

@ -1,186 +1,9 @@
#include "fuse_statx.hpp"
#include "config.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_inode.hpp"
#include "fs_path.hpp"
#include "fs_statx.hpp"
#include "symlinkify.hpp"
#include "ugid.hpp"
#include "fmt/core.h"
#include "fuse.h"
#include <string>
static
void
_set_stat_if_leads_to_dir(const std::string &path_,
struct fuse_statx *st_)
{
int rv;
struct fuse_statx st;
rv = fs::statx(AT_FDCWD,path_,AT_SYMLINK_FOLLOW,STATX_TYPE,st_);
if(rv < 0)
return;
if(S_ISDIR(st.mode))
*st_ = st;
return;
}
static
void
_set_stat_if_leads_to_reg(const std::string &path_,
struct fuse_statx *st_)
{
int rv;
struct fuse_statx st;
rv = fs::statx(AT_FDCWD,path_,AT_SYMLINK_FOLLOW,STATX_TYPE,st_);
if(rv < 0)
return;
if(S_ISREG(st.mode))
*st_ = st;
return;
}
static
int
_statx_controlfile(struct fuse_statx *st_)
{
static const uid_t uid = ::getuid();
static const gid_t gid = ::getgid();
static const time_t now = ::time(NULL);
st_->ino = 0;
st_->mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
st_->nlink = 1;
st_->uid = uid;
st_->gid = gid;
st_->size = 0;
st_->blocks = 0;
st_->atime.tv_sec = now;
st_->mtime.tv_sec = now;
st_->ctime.tv_sec = now;
return 0;
}
static
int
_statx(const Policy::Search &searchFunc_,
const Branches &branches_,
const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
const bool symlinkify_,
const time_t symlinkify_timeout_,
FollowSymlinks followsymlinks_)
{
int rv;
std::string fullpath;
StrVec basepaths;
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
switch(followsymlinks_)
{
case FollowSymlinks::ENUM::NEVER:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
break;
case FollowSymlinks::ENUM::DIRECTORY:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
if((rv >= 0) && S_ISLNK(st_->mode))
::_set_stat_if_leads_to_dir(fullpath,st_);
break;
case FollowSymlinks::ENUM::REGULAR:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
if((rv >= 0) && S_ISLNK(st_->mode))
::_set_stat_if_leads_to_reg(fullpath,st_);
break;
case FollowSymlinks::ENUM::ALL:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_FOLLOW,mask_,st_);
if(rv < 0)
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
break;
}
if(rv < 0)
return rv;
if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_))
symlinkify::convert(fullpath,st_);
fs::inode::calc(basepaths[0],fusepath_,st_);
return 0;
}
static
int
_statx(const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
int rv;
Config::Read cfg;
const fuse_context *fc = fuse_get_context();
const ugid::Set ugid(fc->uid,fc->gid);
rv = ::_statx(cfg->func.getattr.policy,
cfg->branches,
fusepath_,
flags_,
mask_,
st_,
cfg->symlinkify,
cfg->symlinkify_timeout,
cfg->follow_symlinks);
timeout_->entry = ((rv >= 0) ?
cfg->cache_entry :
cfg->cache_negative_entry);
timeout_->attr = cfg->cache_attr;
return rv;
}
int
FUSE::statx(const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
if(fusepath_ == CONTROLFILE)
return ::_statx_controlfile(st_);
return ::_statx(fusepath_,flags_|AT_STATX_DONT_SYNC,mask_,st_,timeout_);
}
int
FUSE::statx_fh(const uint64_t fh_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
FileInfo *fi = reinterpret_cast<FileInfo*>(fh_);
return ::_statx(fi->fusepath.c_str(),flags_,mask_,st_,timeout_);
}
#ifdef MERGERFS_STATX_SUPPORTED
#pragma message "statx supported"
# include "fuse_statx_supported.icpp"
#else
#pragma message "statx NOT supported"
# include "fuse_statx_unsupported.icpp"
#endif

View file

@ -0,0 +1,186 @@
#include "fuse_statx.hpp"
#include "config.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_inode.hpp"
#include "fs_path.hpp"
#include "fs_statx.hpp"
#include "symlinkify.hpp"
#include "ugid.hpp"
#include "fmt/core.h"
#include "fuse.h"
#include <string>
static
void
_set_stat_if_leads_to_dir(const std::string &path_,
struct fuse_statx *st_)
{
int rv;
struct fuse_statx st;
rv = fs::statx(AT_FDCWD,path_,AT_SYMLINK_FOLLOW,STATX_TYPE,st_);
if(rv < 0)
return;
if(S_ISDIR(st.mode))
*st_ = st;
return;
}
static
void
_set_stat_if_leads_to_reg(const std::string &path_,
struct fuse_statx *st_)
{
int rv;
struct fuse_statx st;
rv = fs::statx(AT_FDCWD,path_,AT_SYMLINK_FOLLOW,STATX_TYPE,st_);
if(rv < 0)
return;
if(S_ISREG(st.mode))
*st_ = st;
return;
}
static
int
_statx_controlfile(struct fuse_statx *st_)
{
static const uid_t uid = ::getuid();
static const gid_t gid = ::getgid();
static const time_t now = ::time(NULL);
st_->ino = 0;
st_->mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
st_->nlink = 1;
st_->uid = uid;
st_->gid = gid;
st_->size = 0;
st_->blocks = 0;
st_->atime.tv_sec = now;
st_->mtime.tv_sec = now;
st_->ctime.tv_sec = now;
return 0;
}
static
int
_statx(const Policy::Search &searchFunc_,
const Branches &branches_,
const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
const bool symlinkify_,
const time_t symlinkify_timeout_,
FollowSymlinks followsymlinks_)
{
int rv;
std::string fullpath;
StrVec basepaths;
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
switch(followsymlinks_)
{
case FollowSymlinks::ENUM::NEVER:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
break;
case FollowSymlinks::ENUM::DIRECTORY:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
if((rv >= 0) && S_ISLNK(st_->mode))
::_set_stat_if_leads_to_dir(fullpath,st_);
break;
case FollowSymlinks::ENUM::REGULAR:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
if((rv >= 0) && S_ISLNK(st_->mode))
::_set_stat_if_leads_to_reg(fullpath,st_);
break;
case FollowSymlinks::ENUM::ALL:
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_FOLLOW,mask_,st_);
if(rv < 0)
rv = fs::statx(AT_FDCWD,fullpath,flags_|AT_SYMLINK_NOFOLLOW,mask_,st_);
break;
}
if(rv < 0)
return rv;
if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_))
symlinkify::convert(fullpath,st_);
fs::inode::calc(basepaths[0],fusepath_,st_);
return 0;
}
static
int
_statx(const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
int rv;
Config::Read cfg;
const fuse_context *fc = fuse_get_context();
const ugid::Set ugid(fc->uid,fc->gid);
rv = ::_statx(cfg->func.getattr.policy,
cfg->branches,
fusepath_,
flags_,
mask_,
st_,
cfg->symlinkify,
cfg->symlinkify_timeout,
cfg->follow_symlinks);
timeout_->entry = ((rv >= 0) ?
cfg->cache_entry :
cfg->cache_negative_entry);
timeout_->attr = cfg->cache_attr;
return rv;
}
int
FUSE::statx(const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
if(fusepath_ == CONTROLFILE)
return ::_statx_controlfile(st_);
return ::_statx(fusepath_,flags_|AT_STATX_DONT_SYNC,mask_,st_,timeout_);
}
int
FUSE::statx_fh(const uint64_t fh_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
FileInfo *fi = reinterpret_cast<FileInfo*>(fh_);
return ::_statx(fi->fusepath.c_str(),flags_,mask_,st_,timeout_);
}

View file

@ -0,0 +1,21 @@
#include "fuse_statx.hpp"
int
FUSE::statx(const char *fusepath_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
return -ENOSYS;
}
int
FUSE::statx_fh(const uint64_t fh_,
const uint32_t flags_,
const uint32_t mask_,
struct fuse_statx *st_,
fuse_timeouts_t *timeout_)
{
return -ENOSYS;
}

View file

@ -269,8 +269,8 @@ namespace l
if(uid == 0)
return;
char const *s = "mergerfs is not running as root and may not work correctly\n";
fprintf(stderr,"warning: %s",s);
const char s[] = "mergerfs is not running as root and may not work correctly\n";
fmt::print(stderr,"warning: {}",s);
SysLog::warning(s);
}
@ -287,8 +287,6 @@ namespace l
SysLog::open();
SysLog::info("mergerfs v{} started",MERGERFS_VERSION);
l::warn_if_not_root();
memset(&ops,0,sizeof(fuse_operations));
args.argc = argc_;
@ -311,6 +309,8 @@ namespace l
return 1;
}
l::warn_if_not_root();
l::setup_resources(cfg->scheduling_priority);
l::setup_signal_handlers();
l::get_fuse_operations(ops,cfg->nullrw);

View file

@ -16,6 +16,8 @@
#include "ef.hpp"
#include "fmt/core.h"
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@ -114,21 +116,17 @@ namespace num
std::string
humanize(const uint64_t bytes_)
{
char buf[64];
if(bytes_ < KB)
sprintf(buf,"%" PRIu64 "",bytes_);
return fmt::format("{}",bytes_);
ef(((bytes_ / TB) * TB) == bytes_)
sprintf(buf,"%" PRIu64 "T",bytes_ / TB);
return fmt::format("{}T",bytes_ / TB);
ef(((bytes_ / GB) * GB) == bytes_)
sprintf(buf,"%" PRIu64 "G",bytes_ / GB);
return fmt::format("{}G",bytes_ / GB);
ef(((bytes_ / MB) * MB) == bytes_)
sprintf(buf,"%" PRIu64 "M",bytes_ / MB);
return fmt::format("{}M",bytes_ / MB);
ef(((bytes_ / KB) * KB) == bytes_)
sprintf(buf,"%" PRIu64 "K",bytes_ / KB);
else
sprintf(buf,"%" PRIu64 "",bytes_);
return fmt::format("{}K",bytes_ / KB);
return std::string(buf);
return fmt::format("{}",bytes_);
}
}

View file

@ -18,8 +18,8 @@
#include "policies.hpp"
#include "policy.hpp"
#include "policy_eprand.hpp"
#include "rnd.hpp"
#include <algorithm>
int
Policy::EPRand::Action::operator()(const Branches::CPtr &branches_,
@ -30,10 +30,7 @@ Policy::EPRand::Action::operator()(const Branches::CPtr &branches_,
rv = Policies::Action::epall(branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());
paths_->resize(1);
}
RND::shrink_to_rand_elem(*paths_);
return rv;
}
@ -47,10 +44,7 @@ Policy::EPRand::Create::operator()(const Branches::CPtr &branches_,
rv = Policies::Create::epall(branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());
paths_->resize(1);
}
RND::shrink_to_rand_elem(*paths_);
return rv;
}
@ -64,10 +58,7 @@ Policy::EPRand::Search::operator()(const Branches::CPtr &branches_,
rv = Policies::Search::epall(branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());
paths_->resize(1);
}
RND::shrink_to_rand_elem(*paths_);
return rv;
}

View file

@ -18,8 +18,7 @@
#include "policy.hpp"
#include "policy_rand.hpp"
#include "policies.hpp"
#include <algorithm>
#include "rnd.hpp"
int
Policy::Rand::Action::operator()(const Branches::CPtr &branches_,
@ -30,10 +29,7 @@ Policy::Rand::Action::operator()(const Branches::CPtr &branches_,
rv = Policies::Action::all(branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());
paths_->resize(1);
}
RND::shrink_to_rand_elem(*paths_);
return rv;
}
@ -47,10 +43,7 @@ Policy::Rand::Create::operator()(const Branches::CPtr &branches_,
rv = Policies::Create::all(branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());
paths_->resize(1);
}
RND::shrink_to_rand_elem(*paths_);
return rv;
}
@ -64,10 +57,7 @@ Policy::Rand::Search::operator()(const Branches::CPtr &branches_,
rv = Policies::Search::all(branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());
paths_->resize(1);
}
RND::shrink_to_rand_elem(*paths_);
return rv;
}

View file

@ -10,10 +10,14 @@
#include "fs_openat.hpp"
#include "fs_read.hpp"
#include "fmt/core.h"
#include <array>
#include <pthread.h>
static int g_PROCFS_DIR_FD = -1;
const char PROCFS_PATH[] = "/proc";
constexpr const char PROCFS_PATH[] = "/proc";
int
procfs::init()
@ -33,15 +37,17 @@ procfs::get_name(const int tid_)
{
int fd;
int rv;
char commpath[256];
std::array<char,256> commpath;
fmt::format_to_n_result<char*> frv;
snprintf(commpath,sizeof(commpath),"%d/comm",tid_);
frv = fmt::format_to_n(commpath.data(),commpath.size()-1,"{}/comm",tid_);
frv.out[0] = '\0';
fd = fs::openat(g_PROCFS_DIR_FD,commpath,O_RDONLY);
fd = fs::openat(g_PROCFS_DIR_FD,commpath.data(),O_RDONLY);
if(fd < 0)
return {};
rv = fs::read(fd,commpath,sizeof(commpath));
rv = fs::read(fd,commpath.data(),commpath.size());
if(rv == -1)
return {};
@ -50,5 +56,5 @@ procfs::get_name(const int tid_)
fs::close(fd);
return commpath;
return commpath.data();
}

View file

@ -19,7 +19,7 @@
#pragma once
#include <cstdint>
#include <random>
class RND
{
@ -31,4 +31,21 @@ public:
static uint64_t rand64(const uint64_t max_);
static uint64_t rand64(const uint64_t min_,
const uint64_t max_);
template<typename T>
static
void
shrink_to_rand_elem(std::vector<T> &v_)
{
static std::mt19937 gen(std::random_device{}());
if(v_.size() <= 1)
return;
std::uniform_int_distribution<> dist(0,(v_.size() - 1));
std::swap(v_[0],v_[dist(gen)]);
v_.resize(1);
}
};

View file

@ -18,6 +18,8 @@
#include "to_string.hpp"
#include "fmt/core.h"
#include <cstdint>
#include <string>
@ -35,21 +37,13 @@ namespace str
std::string
to(const int int_)
{
char buf[24];
sprintf(buf,"%d",int_);
return buf;
return fmt::format("{}",int_);
}
std::string
to(const uint64_t uint64_)
{
char buf[64];
sprintf(buf,"%llu",(unsigned long long)uint64_);
return buf;
return fmt::format("{}",uint64_);
}
std::string

View file

@ -41,11 +41,11 @@ public:
}
public:
ToFromWrapper<T>()
ToFromWrapper()
{
}
ToFromWrapper<T>(const T data_)
ToFromWrapper(const T data_)
: _data(data_)
{
}
@ -112,11 +112,11 @@ public:
}
public:
ROToFromWrapper<T>()
ROToFromWrapper()
{
}
ROToFromWrapper<T>(const T data_)
ROToFromWrapper(const T data_)
: _data(data_)
{
}

View file

@ -28,9 +28,9 @@ namespace ugid
}
#if defined __linux__ and UGID_USE_RWLOCK == 0
#warning "using ugid_linux.hpp"
#pragma message "using ugid_linux.hpp"
#include "ugid_linux.hpp"
#else
#warning "using ugid_rwlock.hpp"
#pragma message "using ugid_rwlock.hpp"
#include "ugid_rwlock.hpp"
#endif