summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-07-20 15:02:00 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-07-20 15:02:00 +0100
commitf79ccf1ee4a076da0b31e93f2308e5dab20babff (patch)
tree1d322edb246f3e9fc9ca1f67cf0e87609673ef11
parentUse system default toolset instead of specifying one (diff)
downloadnetfs-f79ccf1ee4a076da0b31e93f2308e5dab20babff.tar.bz2
netfs-f79ccf1ee4a076da0b31e93f2308e5dab20babff.tar.xz
netfs-f79ccf1ee4a076da0b31e93f2308e5dab20babff.zip
Fix almost all clang-tidy warnings in netfs/fuse
Almost entire variable naming, a few other tweaks (moves etc)
-rw-r--r--netfs/fuse/fuseApp.cpp127
-rw-r--r--netfs/fuse/fuseApp.h69
-rw-r--r--netfs/fuse/fuseApp.impl.h17
-rw-r--r--netfs/fuse/fuseAppBase.cpp49
-rw-r--r--netfs/fuse/fuseAppBase.h40
-rw-r--r--netfs/fuse/fuseConfigImpl.cpp5
-rw-r--r--netfs/fuse/fuseDirs.cpp49
-rw-r--r--netfs/fuse/fuseDirs.h2
-rw-r--r--netfs/fuse/fuseFiles.cpp326
-rw-r--r--netfs/fuse/fuseFiles.h6
-rw-r--r--netfs/fuse/fuseMappers.ice4
-rw-r--r--netfs/fuse/fuseMappersImpl.cpp59
-rw-r--r--netfs/fuse/fuseMappersImpl.h10
-rw-r--r--netfs/fuse/fuseMisc.cpp45
-rw-r--r--netfs/fuse/fuseSystem.cpp4
-rw-r--r--netfs/fuse/netfs.cpp8
-rw-r--r--netfs/unittests/mockFuse.cpp9
-rw-r--r--netfs/unittests/mockFuse.h2
-rw-r--r--netfs/unittests/mockMount.cpp5
-rw-r--r--netfs/unittests/mockMount.h3
-rw-r--r--netfs/unittests/testCore.cpp61
-rw-r--r--netfs/unittests/testEdgeCases.cpp16
22 files changed, 484 insertions, 432 deletions
diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp
index 0018b20..5f58f28 100644
--- a/netfs/fuse/fuseApp.cpp
+++ b/netfs/fuse/fuseApp.cpp
@@ -1,7 +1,7 @@
#include "fuseApp.h"
#include "cache.impl.h"
-#include "fuseDirs.h"
-#include "fuseFiles.h"
+#include "fuseDirs.h" // IWYU pragma: keep - OpenDir definition
+#include "fuseFiles.h" // IWYU pragma: keep - OpenFile definition
#include "fuseMappersImpl.h"
#include "lockHelpers.h"
#include <Glacier2/Router.h>
@@ -15,32 +15,34 @@
#include <slicer/slicer.h>
#include <uriParse.h>
+constexpr static unsigned short DEFAULT_PORT = 4000;
+constexpr static unsigned short DEFAULT_MAX_MESSAGE_SIZE = 1024;
+constexpr static unsigned short KILO_MULTIPLIER = 1024;
+
namespace AdHoc {
template class Cache<struct stat, std::size_t>;
template class CallCacheable<struct stat, std::size_t>;
}
-NetFS::FuseApp::FuseApp(Ice::StringSeq && a) : iceArgs(std::move(a)) { }
+NetFS::FuseApp::FuseApp(Ice::StringSeq args) : iceArgs(std::move(args)) { }
NetFS::FuseApp::~FuseApp()
{
- for (const OpenDirs::value_type & of : openDirs) {
+ for (const OpenDirs::value_type & openDir : openDirs) {
// LCOV_EXCL_START
try {
- of.second->remote->close();
+ openDir.second->remote->close();
}
- catch (...) {
- // Can't do anything useful here
+ catch (...) { // NOLINT(bugprone-empty-catch) - Can't do anything useful here
}
// LCOV_EXCL_STOP
}
- for (const OpenFiles::value_type & of : openFiles) {
+ for (const OpenFiles::value_type & openFile : openFiles) {
// LCOV_EXCL_START
try {
- of.second->remote->close();
+ openFile.second->remote->close();
}
- catch (...) {
- // Can't do anything useful here
+ catch (...) { // NOLINT(bugprone-empty-catch) - Can't do anything useful here
}
// LCOV_EXCL_STOP
}
@@ -48,16 +50,14 @@ NetFS::FuseApp::~FuseApp()
try {
volume->disconnect();
}
- catch (...) {
- // Can't do anything useful here
+ catch (...) { // NOLINT(bugprone-empty-catch) - Can't do anything useful here
}
}
if (session) {
try {
session->destroy();
}
- catch (...) {
- // Can't do anything useful here
+ catch (...) { // NOLINT(bugprone-empty-catch) - Can't do anything useful here
}
}
if (ic) {
@@ -85,73 +85,76 @@ NetFS::FuseApp::init(struct fuse_conn_info *, struct fuse_config *)
}
BOOST_ASSERT(fcr);
converter.mapper = fcr->Mapper;
- clientSettings.MessageSizeMax = ic->getProperties()->getPropertyAsIntWithDefault("Ice.MessageSizeMax", 1024);
+ clientSettings.MessageSizeMax
+ = ic->getProperties()->getPropertyAsIntWithDefault("Ice.MessageSizeMax", DEFAULT_MAX_MESSAGE_SIZE);
return this;
}
NetFS::Client::ResourcePtr
NetFS::FuseApp::configureFromFile(const std::filesystem::path & path, const std::string & resourceName)
{
- auto s = Slicer::FileDeserializerFactory::createNew(path.extension().string(), path);
- auto c = Slicer::DeserializeAnyWith<NetFS::Client::ConfigurationPtr>(s);
- return AdHoc::safeMapLookup<Client::ResourceNotFound>(c->Resources, resourceName);
+ auto deserialiser = Slicer::FileDeserializerFactory::createNew(path.extension().string(), path);
+ auto configuration = Slicer::DeserializeAnyWith<NetFS::Client::ConfigurationPtr>(deserialiser);
+ return AdHoc::safeMapLookup<Client::ResourceNotFound>(configuration->Resources, resourceName);
}
AdHocFormatter(IceEndpointFmt, "%? -h %? -p %?");
+
NetFS::Client::ResourcePtr
NetFS::FuseApp::configureFromUri(const std::string & uriString)
{
const AdHoc::Uri uri(uriString);
- auto r = std::make_shared<NetFS::Client::Resource>();
- r->ExportName = uri.path->string();
- r->Endpoints.emplace_back(IceEndpointFmt::get(uri.scheme, uri.host, uri.port ? *uri.port : 4000));
+ auto resource = std::make_shared<NetFS::Client::Resource>();
+ resource->ExportName = uri.path->string();
+ resource->Endpoints.emplace_back(IceEndpointFmt::get(uri.scheme, uri.host, uri.port ? *uri.port : DEFAULT_PORT));
if (uri.password) {
- r->AuthToken = *uri.password;
+ resource->AuthToken = *uri.password;
}
auto set = [&uri](const auto & param, auto & setting) {
- if (auto p = uri.query.find(param); p != uri.query.end()) {
- setting = boost::lexical_cast<std::remove_reference_t<decltype(setting)>>(p->second);
+ if (auto value = uri.query.find(param); value != uri.query.end()) {
+ setting = boost::lexical_cast<std::remove_reference_t<decltype(setting)>>(value->second);
}
};
- auto setWith = [&uri](const auto & param, auto & setting, auto && f) {
- if (auto p = uri.query.find(param); p != uri.query.end()) {
- setting = f(p->second);
+ auto setWith = [&uri](const auto & param, auto & setting, auto && func) {
+ if (auto value = uri.query.find(param); value != uri.query.end()) {
+ setting = func(value->second);
}
};
- set("async", r->Async);
- setWith("mapper", r->Mapper, [&set, &setWith](auto && m) -> NetFS::Mapping::MapperPtr {
- if (m == "hide") {
+ set("async", resource->Async);
+ setWith("mapper", resource->Mapper, [&set, &setWith](auto && mapper) -> NetFS::Mapping::MapperPtr {
+ if (mapper == "hide") {
return std::make_shared<NetFS::Client::HideUnknownMapperImpl>();
}
- else if (m == "mask") {
- auto mi = std::make_shared<NetFS::Client::MaskUnknownMapperImpl>();
- set("mapper.unknownuser", mi->UnknownUser);
- set("mapper.unknowngroup", mi->UnknownGroup);
- setWith("mapper.usermask", mi->UserMask, Client::from_octal);
- setWith("mapper.groupmask", mi->GroupMask, Client::from_octal);
- return mi;
+ if (mapper == "mask") {
+ auto mapperImpl = std::make_shared<NetFS::Client::MaskUnknownMapperImpl>();
+ set("mapper.unknownuser", mapperImpl->UnknownUser);
+ set("mapper.unknowngroup", mapperImpl->UnknownGroup);
+ setWith("mapper.usermask", mapperImpl->UserMask, Client::fromOctal);
+ setWith("mapper.groupmask", mapperImpl->GroupMask, Client::fromOctal);
+ return mapperImpl;
}
return {};
});
- return r;
+ return resource;
}
int
NetFS::FuseApp::opt_parse(void * data, const char * arg, int, struct fuse_args *)
{
auto & iceArgs = *static_cast<Ice::StringSeq *>(data);
- if (strncmp(arg, "--Ice.", 6) == 0) {
+ std::string_view argV {arg};
+ if (argV.starts_with("--Ice.")) {
iceArgs.emplace_back(arg);
return 0;
}
- else if (strncmp(arg, "_netdev", 7) == 0) {
+ if (argV == "_netdev") {
return 0;
}
- else if (arg[0] == '-') {
+ if (argV.front() == '-') {
return 1;
}
- else if (iceArgs.empty() || strncmp(iceArgs.front().c_str(), "--Ice.", 6) == 0) {
+ if (iceArgs.empty() || iceArgs.front().starts_with("--Ice.")) {
iceArgs.emplace(iceArgs.begin(), arg);
return 0;
}
@@ -176,7 +179,9 @@ NetFS::FuseApp::connectSession()
NetFS::FuseApp::CombinedSettings
NetFS::FuseApp::combineSettings(const Settings & daemon, const Settings & client)
{
- return {safe {std::min(daemon.MessageSizeMax.value_or(1024), client.MessageSizeMax.value_or(1024)) * 1024}};
+ return {safe {std::min(daemon.MessageSizeMax.value_or(DEFAULT_MAX_MESSAGE_SIZE),
+ client.MessageSizeMax.value_or(DEFAULT_MAX_MESSAGE_SIZE))
+ * KILO_MULTIPLIER}};
}
void
@@ -185,8 +190,8 @@ NetFS::FuseApp::connectToService()
Lock(mutex);
if (!service) {
auto proxyAddr = fcr->ServiceIdentity;
- for (const auto & ep : fcr->Endpoints) {
- proxyAddr += ":" + ep;
+ for (const auto & endpoint : fcr->Endpoints) {
+ proxyAddr += ":" + endpoint;
}
service = Ice::checkedCast<NetFS::ServicePrx>(ic->stringToProxy(proxyAddr));
if (!service) {
@@ -212,20 +217,20 @@ NetFS::FuseApp::connectToVolume(bool force)
void
NetFS::FuseApp::connectHandles()
{
- for (const OpenFiles::value_type & of : openFiles) {
+ for (const OpenFiles::value_type & openFile : openFiles) {
try {
- of.second->remote->ice_ping();
+ openFile.second->remote->ice_ping();
}
catch (const Ice::ObjectNotExistException &) {
- of.second->remote = volume->open(reqEnv(), of.second->path, of.second->flags & !O_CREAT);
+ openFile.second->remote = volume->open(reqEnv(), openFile.second->path, openFile.second->flags & !O_CREAT);
}
}
- for (const OpenDirs::value_type & of : openDirs) {
+ for (const OpenDirs::value_type & openDir : openDirs) {
try {
- of.second->remote->ice_ping();
+ openDir.second->remote->ice_ping();
}
catch (const Ice::ObjectNotExistException &) {
- of.second->remote = volume->opendir(reqEnv(), of.second->path);
+ openDir.second->remote = volume->opendir(reqEnv(), openDir.second->path);
}
}
}
@@ -262,10 +267,10 @@ NetFS::FuseApp::verifyConnection()
}
int
-NetFS::FuseApp::onError(const std::exception & e) noexcept
+NetFS::FuseApp::onError(const std::exception & error) noexcept
{
- if (dynamic_cast<const Ice::SocketException *>(&e) || dynamic_cast<const Ice::TimeoutException *>(&e)) {
- log(LOG_ERR, e.what());
+ if (dynamic_cast<const Ice::SocketException *>(&error) || dynamic_cast<const Ice::TimeoutException *>(&error)) {
+ log(LOG_ERR, error.what());
try {
verifyConnection();
connectSession();
@@ -278,7 +283,7 @@ NetFS::FuseApp::onError(const std::exception & e) noexcept
return -EIO;
}
}
- if (dynamic_cast<const Ice::RequestFailedException *>(&e)) {
+ if (dynamic_cast<const Ice::RequestFailedException *>(&error)) {
try {
connectToVolume(true);
connectHandles();
@@ -288,10 +293,10 @@ NetFS::FuseApp::onError(const std::exception & e) noexcept
return -EIO;
}
}
- if (dynamic_cast<const NetFS::AuthError *>(&e)) {
+ if (dynamic_cast<const NetFS::AuthError *>(&error)) {
return -EPERM;
}
- return FuseAppBase::onError(e);
+ return FuseAppBase::onError(error);
}
void
@@ -305,7 +310,7 @@ NetFS::FuseApp::beforeOperation()
NetFS::ReqEnv
NetFS::FuseApp::reqEnv()
{
- struct fuse_context * c = fuse_get_context();
- auto t = converter.mapper->mapFileSystem(safe {c->uid}, safe {c->gid});
- return {std::move(t.username), std::move(t.groupname)};
+ struct fuse_context * context = fuseGetContext();
+ auto transportContext = converter.mapper->mapFileSystem(safe {context->uid}, safe {context->gid});
+ return {.user = std::move(transportContext.username), .grp = std::move(transportContext.groupname)};
}
diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h
index b2166df..8dcc2ec 100644
--- a/netfs/fuse/fuseApp.h
+++ b/netfs/fuse/fuseApp.h
@@ -8,7 +8,6 @@
#include <c++11Helpers.h>
#include <entCache.h>
#include <filesystem>
-#include <functional>
#include <service.h>
#include <shared_mutex>
#include <typeConverter.h>
@@ -26,12 +25,13 @@ namespace NetFS {
using OpenFilePtr = std::shared_ptr<OpenFile>;
using OpenFiles = std::map<FuseHandleTypeId, OpenFilePtr>;
- explicit FuseApp(Ice::StringSeq &&);
+ explicit FuseApp(Ice::StringSeq);
SPECIAL_MEMBERS_DELETE(FuseApp);
~FuseApp() override;
// lifecycle
void * init(struct fuse_conn_info * info, struct fuse_config * cfg) override;
+ // NOLINTNEXTLINE(readability-identifier-naming)
static int opt_parse(void * data, const char * arg, int, struct fuse_args *);
protected:
@@ -42,60 +42,61 @@ namespace NetFS {
void verifyConnection();
struct CombinedSettings {
- size_t MessageSizeMax {};
+ size_t messageSizeMax {};
};
public:
// misc
- int access(const char * p, int a) override;
- int getattr(const char *, struct stat *, struct fuse_file_info *) override;
- int chmod(const char *, mode_t, struct fuse_file_info *) override;
- int chown(const char *, uid_t, gid_t, struct fuse_file_info *) override;
- int link(const char *, const char *) override;
- int readlink(const char *, char *, size_t) override;
- int rename(const char *, const char *, unsigned int) override;
- int symlink(const char *, const char *) override;
- int unlink(const char *) override;
- // NOLINTNEXTLINE(hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
- int utimens(const char *, const struct timespec tv[2], struct fuse_file_info *) override;
- int mknod(const char *, mode_t, dev_t) override;
+ int access(const char * path, int accessMode) override;
+ int getattr(const char * path, struct stat *, struct fuse_file_info *) override;
+ int chmod(const char * path, mode_t, struct fuse_file_info *) override;
+ int chown(const char * path, uid_t, gid_t, struct fuse_file_info *) override;
+ int link(const char * path1, const char * path2) override;
+ int readlink(const char * path, char *, size_t) override;
+ int rename(const char * path1, const char * path2, unsigned int) override;
+ int symlink(const char * path1, const char * path2) override;
+ int unlink(const char * path) override;
+ // NOLINTNEXTLINE(*-c-arrays)
+ int utimens(const char * path, const struct timespec times[2], struct fuse_file_info *) override;
+ int mknod(const char * path, mode_t, dev_t) override;
// dirs
- int opendir(const char * p, struct fuse_file_info * fi) override;
- int releasedir(const char *, struct fuse_file_info * fi) override;
- int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi,
+ int opendir(const char * path, struct fuse_file_info *) override;
+ int releasedir(const char * path, struct fuse_file_info *) override;
+ int readdir(const char * path, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info *,
enum fuse_readdir_flags) override;
- int mkdir(const char *, mode_t) override;
- int rmdir(const char *) override;
+ int mkdir(const char * path, mode_t) override;
+ int rmdir(const char * path) override;
// files
- int open(const char * p, struct fuse_file_info * fi) override;
- int create(const char *, mode_t, struct fuse_file_info *) override;
- int flush(const char *, struct fuse_file_info * fi) override;
- int release(const char *, struct fuse_file_info * fi) override;
- int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi) override;
- int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi) override;
- ssize_t copy_file_range(const char *, struct fuse_file_info *, off_t, const char *, struct fuse_file_info *,
- off_t, size_t, int) override;
- int truncate(const char *, off_t, struct fuse_file_info *) override;
+ int open(const char * path, struct fuse_file_info *) override;
+ int create(const char * path, mode_t, struct fuse_file_info *) override;
+ int flush(const char * path, struct fuse_file_info *) override;
+ int release(const char * path, struct fuse_file_info *) override;
+ int read(const char * path, char * buf, size_t size, off_t offset, struct fuse_file_info *) override;
+ int write(const char * path, const char * buf, size_t size, off_t offset, struct fuse_file_info *) override;
+ ssize_t copy_file_range(const char * path, struct fuse_file_info *, off_t, const char *,
+ struct fuse_file_info *, off_t, size_t, int) override;
+ int truncate(const char * path, off_t, struct fuse_file_info *) override;
// fs
- int statfs(const char *, struct statvfs *) override;
+ int statfs(const char * path, struct statvfs *) override;
// stuff
int onError(const std::exception & err) noexcept override;
void beforeOperation() override;
- virtual struct fuse_context * fuse_get_context() = 0;
+ virtual struct fuse_context * fuseGetContext() = 0;
static NetFS::Client::ResourcePtr configureFromFile(const std::filesystem::path &, const std::string &);
static NetFS::Client::ResourcePtr configureFromUri(const std::string &);
static CombinedSettings combineSettings(const Settings & daemon, const Settings & client);
protected:
- template<typename Handle, typename... Params> void setProxy(FuseHandleTypeId & fh, const Params &...);
+ template<typename Handle, typename... Params> void setProxy(FuseHandleTypeId &, const Params &...);
template<typename Handle> Handle getProxy(FuseHandleTypeId localID);
template<typename Handle> void clearProxy(FuseHandleTypeId localID);
template<typename Handle> std::map<FuseHandleTypeId, Handle> & getMap();
- template<typename F>
- static inline auto waitOnWriteRangeAndThen(size_t s, off_t o, const OpenFilePtr & of, const F & f);
+ template<typename Callback>
+ static inline auto waitOnWriteRangeAndThen(
+ size_t size, off_t offset, const OpenFilePtr &, const Callback & callback);
ReqEnv reqEnv();
diff --git a/netfs/fuse/fuseApp.impl.h b/netfs/fuse/fuseApp.impl.h
index f509ad9..322ed46 100644
--- a/netfs/fuse/fuseApp.impl.h
+++ b/netfs/fuse/fuseApp.impl.h
@@ -7,33 +7,32 @@
namespace NetFS {
template<typename Handle, typename... Params>
void
- FuseApp::setProxy(uint64_t & fh, const Params &... params)
+ FuseApp::setProxy(uint64_t & fileHandle, const Params &... params)
{
auto & map = getMap<Handle>();
Lock(proxyMapMutex);
- while (map.find(fh = ++openHandleId) != map.end()) { }
- map.emplace(fh, std::make_shared<typename Handle::element_type>(params...));
+ while (map.find(fileHandle = ++openHandleId) != map.end()) { }
+ map.emplace(fileHandle, std::make_shared<typename Handle::element_type>(params...));
}
template<typename Handle>
Handle
- FuseApp::getProxy(uint64_t localID)
+ FuseApp::getProxy(uint64_t localId)
{
const auto & map = getMap<Handle>();
SharedLock(proxyMapMutex);
- auto i = map.find(localID);
- if (i != map.end()) {
- return i->second;
+ if (auto proxyIter = map.find(localId); proxyIter != map.end()) {
+ return proxyIter->second;
}
throw NetFS::SystemError(EBADF);
}
template<typename Handle>
void
- FuseApp::clearProxy(uint64_t localID)
+ FuseApp::clearProxy(uint64_t localId)
{
auto & map = getMap<Handle>();
Lock(proxyMapMutex);
- map.erase(localID);
+ map.erase(localId);
}
}
diff --git a/netfs/fuse/fuseAppBase.cpp b/netfs/fuse/fuseAppBase.cpp
index 49bb1d9..838f1d9 100644
--- a/netfs/fuse/fuseAppBase.cpp
+++ b/netfs/fuse/fuseAppBase.cpp
@@ -4,7 +4,6 @@
#include <cerrno>
#include <cstdio>
#include <cstdlib>
-#include <typeinfo>
#include <unistd.h>
FuseAppBase * FuseAppBase::fuseApp;
@@ -32,214 +31,256 @@ FuseAppBase::init(fuse_conn_info *, fuse_config *)
{
return nullptr;
}
+
int
FuseAppBase::access(const char *, int)
{
return -ENOSYS;
}
+
int
FuseAppBase::chmod(const char *, mode_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::chown(const char *, uid_t, gid_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::create(const char *, mode_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::getattr(const char *, struct stat *, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::flush(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::fsync(const char *, int, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::truncate(const char *, off_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::getxattr(const char *, const char *, char *, size_t)
{
return -ENOSYS;
}
+
int
FuseAppBase::link(const char *, const char *)
{
return -ENOSYS;
}
+
int
FuseAppBase::listxattr(const char *, char *, size_t)
{
return -ENOSYS;
}
+
int
FuseAppBase::mkdir(const char *, mode_t)
{
return -ENOSYS;
}
+
int
FuseAppBase::mknod(const char *, mode_t, dev_t)
{
return -ENOSYS;
}
+
int
FuseAppBase::open(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::opendir(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *, enum fuse_readdir_flags)
{
return -ENOSYS;
}
+
int
FuseAppBase::readlink(const char *, char *, size_t)
{
return -ENOSYS;
}
+
int
FuseAppBase::release(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::releasedir(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::removexattr(const char *, const char *)
{
return -ENOSYS;
}
+
int
FuseAppBase::rename(const char *, const char *, unsigned int)
{
return -ENOSYS;
}
+
int
FuseAppBase::rmdir(const char *)
{
return -ENOSYS;
}
+
int
FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int)
{
return -ENOSYS;
}
+
int
FuseAppBase::statfs(const char *, struct statvfs *)
{
return -ENOSYS;
}
+
int
FuseAppBase::symlink(const char *, const char *)
{
return -ENOSYS;
}
+
int
FuseAppBase::unlink(const char *)
{
return -ENOSYS;
}
+
int
FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *)
{
return -ENOSYS;
}
+
int
-// NOLINTNEXTLINE(modernize-avoid-c-arrays, hicpp-avoid-c-arrays)
+// NOLINTNEXTLINE(*-c-arrays)
FuseAppBase::utimens(const char *, const struct timespec[2], struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::bmap(const char *, size_t, uint64_t *)
{
return -ENOSYS;
}
+
int
FuseAppBase::ioctl(const char *, unsigned int, void *, struct fuse_file_info *, unsigned int, void *)
{
return -ENOSYS;
}
+
int
FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *)
{
return -ENOSYS;
}
+
int
FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
int
FuseAppBase::flock(const char *, struct fuse_file_info *, int)
{
return -ENOSYS;
}
+
int
FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *)
{
return -ENOSYS;
}
+
ssize_t
FuseAppBase::copy_file_range(
const char *, struct fuse_file_info *, off_t, const char *, struct fuse_file_info *, off_t, size_t, int)
{
return -ENOSYS;
}
+
off_t
FuseAppBase::lseek(const char *, off_t, int, struct fuse_file_info *)
{
return -ENOSYS;
}
+
// LCOV_EXCL_STOP
void
FuseAppBase::log(int level, const char * message) const noexcept
{
logf(level, "%s", message);
}
+
void
FuseAppBase::logf(int level, const char * fmt, ...) const noexcept
{
@@ -250,9 +291,9 @@ FuseAppBase::logf(int level, const char * fmt, ...) const noexcept
}
int
-FuseAppBase::onError(const std::exception & e) noexcept
+FuseAppBase::onError(const std::exception & error) noexcept
{
- logf(LOG_ERR, "Unknown exception (what: %s)", e.what());
+ logf(LOG_ERR, "Unknown exception (what: %s)", error.what());
return -ENOSYS;
}
diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h
index 480bac6..8f3bffe 100644
--- a/netfs/fuse/fuseAppBase.h
+++ b/netfs/fuse/fuseAppBase.h
@@ -48,16 +48,19 @@ public:
virtual int unlink(const char *);
virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *);
virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *);
- // NOLINTNEXTLINE(hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
- virtual int utimens(const char *, const struct timespec tv[2], struct fuse_file_info *);
+ // NOLINTNEXTLINE(*-c-arrays)
+ virtual int utimens(const char *, const struct timespec times[2], struct fuse_file_info *);
virtual int bmap(const char *, size_t blocksize, uint64_t * idx);
virtual int ioctl(
const char *, unsigned int cmd, void * arg, struct fuse_file_info *, unsigned int flags, void * data);
virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *);
+ // NOLINTNEXTLINE(readability-identifier-naming)
virtual int write_buf(const char *, struct fuse_bufvec * buf, off_t off, struct fuse_file_info *);
+ // NOLINTNEXTLINE(readability-identifier-naming)
virtual int read_buf(const char *, struct fuse_bufvec ** bufp, size_t size, off_t off, struct fuse_file_info *);
- virtual int flock(const char *, struct fuse_file_info *, int op);
+ virtual int flock(const char *, struct fuse_file_info *, int operation);
virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *);
+ // NOLINTNEXTLINE(readability-identifier-naming)
virtual ssize_t copy_file_range(
const char *, struct fuse_file_info *, off_t, const char *, struct fuse_file_info *, off_t, size_t, int);
virtual off_t lseek(const char *, off_t off, int whence, struct fuse_file_info *);
@@ -74,14 +77,14 @@ public:
protected:
static FuseAppBase * fuseApp;
- template<bool Implemented, auto bfunc>
+ template<bool Implemented, auto BaseFunc>
constexpr static auto
getInternalHelper()
{
if constexpr (Implemented) {
- return [](auto... a) {
+ return [](auto... arg) {
SharedLock(fuseApp->mutex);
- return (fuseApp->*bfunc)(a...);
+ return (fuseApp->*BaseFunc)(arg...);
};
}
else {
@@ -89,33 +92,34 @@ protected:
}
}
- template<bool Implemented, auto bfunc>
+ template<bool Implemented, auto BaseFunc>
constexpr static auto
getHelper()
{
+ constexpr auto ATTEMPTS = 10;
if constexpr (Implemented) {
- return [](auto... a) {
- using Return = decltype((fuseApp->*bfunc)(a...));
- for (int t = 0;; ++t) {
+ return [](auto... arg) {
+ using Return = decltype((fuseApp->*BaseFunc)(arg...));
+ for (int attempt = 0;; ++attempt) {
try {
fuseApp->beforeOperation();
SharedLock(fuseApp->mutex);
- return (fuseApp->*bfunc)(a...);
+ return (fuseApp->*BaseFunc)(arg...);
}
catch (const std::exception & ex) {
- if (t < 10) {
+ if (attempt < ATTEMPTS) {
if (Return rtn = fuseApp->onError(ex)) {
return rtn;
}
}
else {
fuseApp->logf(
- LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(bfunc).name());
+ LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(BaseFunc).name());
return static_cast<Return>(-EIO);
}
}
catch (...) {
- fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(bfunc).name());
+ fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(BaseFunc).name());
return static_cast<Return>(-EIO);
}
}
@@ -134,7 +138,7 @@ public:
getInternalHelper<!std::is_same_v<decltype(&FuseAppBase::func), decltype(&FuseApp::func)>, &FuseAppBase::func>()
#define GetHelper(func) \
getHelper<!std::is_same_v<decltype(&FuseAppBase::func), decltype(&FuseApp::func)>, &FuseAppBase::func>()
- constexpr const static fuse_operations operations {
+ constexpr const static fuse_operations OPERATIONS {
GetHelper(getattr),
GetHelper(readlink),
GetHelper(mknod),
@@ -182,10 +186,10 @@ public:
#undef GetIntHelper
protected:
- template<typename Func, Func f, typename... Args>
+ template<typename Func, Func AppFunc, typename... Args>
static int
- internalHelper(Args... a)
+ internalHelper(Args... arg)
{
- return (fuseApp->*f)(a...);
+ return (fuseApp->*AppFunc)(arg...);
}
};
diff --git a/netfs/fuse/fuseConfigImpl.cpp b/netfs/fuse/fuseConfigImpl.cpp
index fa542fe..9dca813 100644
--- a/netfs/fuse/fuseConfigImpl.cpp
+++ b/netfs/fuse/fuseConfigImpl.cpp
@@ -2,8 +2,9 @@
#include <fuseConfig.h>
AdHocFormatter(ResourceNotFoundMsg, "No such resource: %?");
+
void
-NetFS::Client::ResourceNotFound::ice_print(std::ostream & s) const
+NetFS::Client::ResourceNotFound::ice_print(std::ostream & stream) const
{
- ResourceNotFoundMsg::write(s, resourceName);
+ ResourceNotFoundMsg::write(stream, resourceName);
}
diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp
index 3ea7c0d..1b98048 100644
--- a/netfs/fuse/fuseDirs.cpp
+++ b/netfs/fuse/fuseDirs.cpp
@@ -4,7 +4,10 @@
#include <numeric.h>
namespace NetFS {
- FuseApp::OpenDir::OpenDir(DirectoryPrxPtr r, std::string p) : remote(std::move(r)), path(std::move(p)) { }
+ FuseApp::OpenDir::OpenDir(DirectoryPrxPtr remotePrx, std::string remotePath) :
+ remote(std::move(remotePrx)), path(std::move(remotePath))
+ {
+ }
template<>
std::map<FuseApp::FuseHandleTypeId, FuseApp::OpenDirPtr> &
@@ -14,11 +17,11 @@ namespace NetFS {
}
int
- FuseApp::opendir(const char * p, struct fuse_file_info * fi)
+ FuseApp::opendir(const char * path, struct fuse_file_info * fileInfo)
{
try {
- auto remote = volume->opendir(reqEnv(), p);
- setProxy<OpenDirPtr>(fi->fh, remote, p);
+ auto remote = volume->opendir(reqEnv(), path);
+ setProxy<OpenDirPtr>(fileInfo->fh, remote, path);
return 0;
}
catch (SystemError & e) {
@@ -27,42 +30,42 @@ namespace NetFS {
}
int
- FuseApp::releasedir(const char *, struct fuse_file_info * fi)
+ FuseApp::releasedir(const char *, struct fuse_file_info * fileInfo)
{
try {
- auto remote = getProxy<OpenDirPtr>(fi->fh)->remote;
+ auto remote = getProxy<OpenDirPtr>(fileInfo->fh)->remote;
remote->close();
- clearProxy<OpenDirPtr>(fi->fh);
+ clearProxy<OpenDirPtr>(fileInfo->fh);
return 0;
}
catch (SystemError & e) {
- clearProxy<OpenDirPtr>(fi->fh);
+ clearProxy<OpenDirPtr>(fileInfo->fh);
return -e.syserrno;
}
}
int
- FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi,
+ FuseApp::readdir(const char * path, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fileInfo,
enum fuse_readdir_flags flags)
{
try {
- auto od = getProxy<OpenDirPtr>(fi->fh);
- const std::filesystem::path path {p};
+ auto openDir = getProxy<OpenDirPtr>(fileInfo->fh);
+ const std::filesystem::path fspath {path};
auto expiry = time(nullptr) + 2;
if (flags & FUSE_READDIR_PLUS) {
- for (const auto & e : od->remote->listdir()) {
- if (auto stat = converter.convert(e.second); stat.st_mode) {
- filler(buf, e.first.c_str(), nullptr, 0, FUSE_FILL_DIR_PLUS);
- const auto k {std::filesystem::hash_value(path / e.first)};
- statCache.remove(k);
- statCache.add(k, stat, expiry);
+ for (const auto & entry : openDir->remote->listdir()) {
+ if (auto stat = converter.convert(entry.second); stat.st_mode) {
+ filler(buf, entry.first.c_str(), nullptr, 0, FUSE_FILL_DIR_PLUS);
+ const auto key {std::filesystem::hash_value(fspath / entry.first)};
+ statCache.remove(key);
+ statCache.add(key, stat, expiry);
}
}
}
else {
// Standard read dir cannot know the local system cannot represent the inode
- for (const auto & e : od->remote->readdir()) {
- filler(buf, e.c_str(), nullptr, 0, fuse_fill_dir_flags {});
+ for (const auto & entry : openDir->remote->readdir()) {
+ filler(buf, entry.c_str(), nullptr, 0, fuse_fill_dir_flags {});
}
}
return 0;
@@ -73,10 +76,10 @@ namespace NetFS {
}
int
- FuseApp::mkdir(const char * p, mode_t m)
+ FuseApp::mkdir(const char * path, mode_t mode)
{
try {
- volume->mkdir(reqEnv(), p, safe {m});
+ volume->mkdir(reqEnv(), path, safe {mode});
return 0;
}
catch (SystemError & e) {
@@ -85,10 +88,10 @@ namespace NetFS {
}
int
- FuseApp::rmdir(const char * p)
+ FuseApp::rmdir(const char * path)
{
try {
- volume->rmdir(reqEnv(), p);
+ volume->rmdir(reqEnv(), path);
return 0;
}
catch (SystemError & e) {
diff --git a/netfs/fuse/fuseDirs.h b/netfs/fuse/fuseDirs.h
index 87a5b06..4b04027 100644
--- a/netfs/fuse/fuseDirs.h
+++ b/netfs/fuse/fuseDirs.h
@@ -1,6 +1,6 @@
#pragma once
-#include "fuseApp.impl.h"
+#include "fuseApp.impl.h" // IWYU pragma: keep
namespace NetFS {
class FuseApp::OpenDir {
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index 149e8b3..a3c9dd4 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -1,12 +1,10 @@
#include "fuseFiles.h"
-#include "fuseApp.impl.h"
+#include "fuseApp.impl.h" // IWYU pragma: keep - getProxy definition
#include "lockHelpers.h"
#include <Ice/BuiltinSequences.h>
#include <algorithm>
-#include <atomic>
#include <cstring>
#include <entCache.h>
-#include <exception>
#include <functional>
#include <future>
#include <iterator>
@@ -20,8 +18,8 @@
namespace NetFS {
FuseApp::OpenFile::WriteState::WriteState() : future(promise.get_future().share()) { }
- FuseApp::OpenFile::OpenFile(FilePrxPtr r, std::string p, int f, size_t mms) :
- remote(std::move(r)), path(std::move(p)), flags(f), bodyMaxSize(mms - 1024)
+ FuseApp::OpenFile::OpenFile(FilePrxPtr remotePrx, std::string remotePath, int openFlags, size_t messageMaxSize) :
+ remote(std::move(remotePrx)), path(std::move(remotePath)), flags(openFlags), bodyMaxSize(messageMaxSize - 1024)
{
}
@@ -39,35 +37,35 @@ namespace NetFS {
SharedLock(mutex);
return bg;
}();
- for (const auto & w : cbg) {
- w.second->future.get();
+ for (const auto & operation : cbg) {
+ operation.second->future.get();
}
}
void
FuseApp::OpenFile::flush()
{
- auto first = [this]() {
+ auto getFirstBackgroundOp = [this]() {
SharedLock(mutex);
return bg.empty() ? nullptr : bg.begin()->second;
};
- while (auto w = first()) {
- w->future.get();
+ while (auto operation = getFirstBackgroundOp()) {
+ operation->future.get();
}
}
FuseApp::OpenFile::BGs::interval_type
- FuseApp::OpenFile::range(off_t o, size_t s)
+ FuseApp::OpenFile::range(off_t offset, size_t size)
{
- return OpenFile::BGs::interval_type::right_open(safe {o}, safe {o} + s);
+ return OpenFile::BGs::interval_type::right_open(safe {offset}, safe {offset} + size);
}
int
- FuseApp::open(const char * p, struct fuse_file_info * fi)
+ FuseApp::open(const char * path, struct fuse_file_info * fileInfo)
{
try {
- auto remote = volume->open(reqEnv(), p, fi->flags);
- setProxy<OpenFilePtr>(fi->fh, remote, p, fi->flags, combinedSettings.MessageSizeMax);
+ auto remote = volume->open(reqEnv(), path, fileInfo->flags);
+ setProxy<OpenFilePtr>(fileInfo->fh, remote, path, fileInfo->flags, combinedSettings.messageSizeMax);
return 0;
}
catch (SystemError & e) {
@@ -76,11 +74,11 @@ namespace NetFS {
}
int
- FuseApp::create(const char * p, mode_t m, struct fuse_file_info * fi)
+ FuseApp::create(const char * path, mode_t mode, struct fuse_file_info * fileInfo)
{
try {
- auto remote = volume->create(reqEnv(), p, fi->flags, safe {m});
- setProxy<OpenFilePtr>(fi->fh, remote, p, fi->flags, combinedSettings.MessageSizeMax);
+ auto remote = volume->create(reqEnv(), path, fileInfo->flags, safe {mode});
+ setProxy<OpenFilePtr>(fileInfo->fh, remote, path, fileInfo->flags, combinedSettings.messageSizeMax);
return 0;
}
catch (SystemError & e) {
@@ -89,34 +87,34 @@ namespace NetFS {
}
int
- FuseApp::release(const char *, struct fuse_file_info * fi)
+ FuseApp::release(const char *, struct fuse_file_info * fileInfo)
{
try {
- auto of = getProxy<OpenFilePtr>(fi->fh);
- auto remote = of->remote;
+ auto openFile = getProxy<OpenFilePtr>(fileInfo->fh);
+ auto remote = openFile->remote;
try {
- of->flush();
- clearProxy<OpenFilePtr>(fi->fh);
+ openFile->flush();
+ clearProxy<OpenFilePtr>(fileInfo->fh);
remote->close();
}
catch (SystemError & e) {
- clearProxy<OpenFilePtr>(fi->fh);
+ clearProxy<OpenFilePtr>(fileInfo->fh);
remote->close();
throw;
}
return 0;
}
catch (SystemError & e) {
- clearProxy<OpenFilePtr>(fi->fh);
+ clearProxy<OpenFilePtr>(fileInfo->fh);
return -e.syserrno;
}
}
int
- FuseApp::flush(const char *, struct fuse_file_info * fi)
+ FuseApp::flush(const char *, struct fuse_file_info * fileInfo)
{
try {
- getProxy<OpenFilePtr>(fi->fh)->flush();
+ getProxy<OpenFilePtr>(fileInfo->fh)->flush();
return 0;
}
catch (SystemError & e) {
@@ -124,68 +122,67 @@ namespace NetFS {
}
}
- template<typename F>
+ template<typename Callback>
inline auto
- FuseApp::waitOnWriteRangeAndThen(size_t s, off_t o, const OpenFilePtr & of, const F & f)
+ FuseApp::waitOnWriteRangeAndThen(size_t size, off_t offset, const OpenFilePtr & openFile, const Callback & callback)
{
- const auto key = OpenFile::range(o, s);
+ const auto key = OpenFile::range(offset, size);
while (true) {
- std::unique_lock lock(of->mutex);
+ std::unique_lock lock(openFile->mutex);
// Acquire operations to wait for
- const auto R = of->bg.equal_range(key);
- if (R.first == R.second) {
+ const auto pendingRange = openFile->bg.equal_range(key);
+ if (pendingRange.first == pendingRange.second) {
// Perform operation
- return f(key);
+ return callback(key);
}
- else {
- const auto overlap = [R]() {
- std::vector<std::shared_future<void>> out;
- out.reserve(safe<ptrdiff_t> {std::distance(R.first, R.second)});
- std::transform(R.first, R.second, std::back_inserter(out), [](auto && i) {
- return i.second->future;
- });
- return out;
- }();
- // Wait for them whilst unlocked
- lock.release()->unlock();
- try {
- std::for_each(overlap.begin(), overlap.end(), [](auto && r) {
- r.get();
- });
- }
- catch (const SystemError &) {
- throw;
- }
- catch (...) {
- throw SystemError {ECOMM};
- }
- // Cause this thread to yield so the callback can lock mutex
- usleep(0);
+ const auto overlap = [pendingRange]() {
+ std::vector<std::shared_future<void>> out;
+ out.reserve(safe<ptrdiff_t> {std::distance(pendingRange.first, pendingRange.second)});
+ std::transform(pendingRange.first, pendingRange.second, std::back_inserter(out), [](auto && operation) {
+ return operation.second->future;
+ });
+ return out;
+ }();
+ // Wait for them whilst unlocked
+ lock.release()->unlock();
+ try {
+ std::for_each(overlap.begin(), overlap.end(), [](auto && operationFuture) {
+ operationFuture.get();
+ });
}
+ catch (const SystemError &) {
+ throw;
+ }
+ catch (...) {
+ throw SystemError {ECOMM};
+ }
+ // Cause this thread to yield so the callback can lock mutex
+ usleep(0);
}
}
- template<typename CB>
- void
- blockSizeIterate(FuseApp::OpenFile::BlockSizes bs, CB && cb)
- {
- if (bs.size1) {
- cb(bs.size1);
- }
- while (bs.N--) {
- cb(bs.sizeN);
+ namespace {
+ void
+ blockSizeIterate(FuseApp::OpenFile::BlockSizes blockSizes, auto && callback)
+ {
+ if (blockSizes.size1) {
+ callback(blockSizes.size1);
+ }
+ while (blockSizes.count--) {
+ callback(blockSizes.sizeN);
+ }
}
- }
- template<typename T>
- auto
- operator++(std::vector<std::unique_ptr<T>> & v)
- {
- return v.emplace_back(std::make_unique<T>()).get();
+ template<typename T>
+ auto
+ appendNewDefault(std::vector<std::unique_ptr<T>> & container)
+ {
+ return container.emplace_back(std::make_unique<T>()).get();
+ }
}
int
- FuseApp::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi)
+ FuseApp::read(const char *, char * buf, size_t size, off_t offset, struct fuse_file_info * fileInfo)
{
try {
using BackgroundOps = std::vector<std::unique_ptr<std::promise<int>>>;
@@ -195,58 +192,57 @@ namespace NetFS {
return safe {data.size()};
};
auto collateTotal = [](auto && ops) {
- return std::accumulate(ops.begin(), ops.end(), 0, [](auto && total, auto & op) {
- return total += op->get_future().get();
+ return std::accumulate(ops.begin(), ops.end(), 0, [](auto && total, auto & operation) {
+ return total += operation->get_future().get();
});
};
- auto of = getProxy<OpenFilePtr>(fi->fh);
- auto remote = of->remote;
- auto blockSizes = of->blockSizes(s);
+ auto openFile = getProxy<OpenFilePtr>(fileInfo->fh);
+ auto remote = openFile->remote;
+ auto blockSizes = openFile->blockSizes(size);
if (fcr->Async) {
BackgroundFuncs fs;
BackgroundOps ops;
blockSizeIterate(blockSizes,
- [&ops, &fs, &o, &of, &remote, blockOffset = 0U, &cpy](safe<size_t> blockSize) mutable {
- const auto p = ++ops;
- fs.push_back(waitOnWriteRangeAndThen(
- blockSize, o, of, [p, o, blockOffset, blockSize, &remote, &cpy](const auto &) {
+ [&ops, &fs, &offset, &openFile, &remote, blockOffset = 0U, &cpy](
+ safe<size_t> blockSize) mutable {
+ const auto p = appendNewDefault(ops);
+ fs.push_back(waitOnWriteRangeAndThen(blockSize, offset, openFile,
+ [p, offset, blockOffset, blockSize, &remote, &cpy](const auto &) {
return remote->readAsync(
- o, blockSize,
+ offset, blockSize,
[cpy, p, blockOffset](auto && resultBuf) {
p->set_value(
cpy(blockOffset, std::forward<Ice::ByteSeq>(resultBuf)));
},
- [p](auto ex) {
- p->set_exception(ex);
+ [p](auto error) {
+ p->set_exception(std::move(error));
});
}));
- o += blockSize;
+ offset += blockSize;
blockOffset += blockSize;
});
return collateTotal(ops);
}
- else if (of->bodyMaxSize < s) {
+ if (openFile->bodyMaxSize < size) {
BackgroundFuncs fs;
BackgroundOps ops;
- blockSizeIterate(
- blockSizes, [&o, &remote, blockOffset = 0U, &ops, &fs, &cpy](safe<size_t> blockSize) mutable {
- const auto p = ++ops;
+ blockSizeIterate(blockSizes,
+ [&offset, &remote, blockOffset = 0U, &ops, &fs, &cpy](safe<size_t> blockSize) mutable {
+ const auto p = appendNewDefault(ops);
fs.push_back(remote->readAsync(
- o, blockSize,
+ offset, blockSize,
[cpy, p, blockOffset](auto && resultBuf) {
p->set_value(cpy(blockOffset, std::forward<Ice::ByteSeq>(resultBuf)));
},
- [p](auto ex) {
- p->set_exception(ex);
+ [p](auto error) {
+ p->set_exception(std::move(error));
}));
- o += blockSize;
+ offset += blockSize;
blockOffset += blockSize;
});
return collateTotal(ops);
}
- else {
- return cpy(0, remote->read(o, safe {s}));
- }
+ return cpy(0, remote->read(offset, safe {size}));
}
catch (SystemError & e) {
return -e.syserrno;
@@ -254,48 +250,48 @@ namespace NetFS {
}
int
- FuseApp::write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi)
+ FuseApp::write(const char *, const char * buf, size_t size, off_t offset, struct fuse_file_info * fileInfo)
{
try {
- auto of = getProxy<OpenFilePtr>(fi->fh);
- auto remote = of->remote;
+ auto openFile = getProxy<OpenFilePtr>(fileInfo->fh);
+ auto remote = openFile->remote;
auto bytes = reinterpret_cast<const ::Ice::Byte *>(buf);
if (fcr->Async) {
- blockSizeIterate(of->blockSizes(s), [&bytes, &o, &remote, &of](safe<size_t> blockSize) {
- waitOnWriteRangeAndThen(blockSize, o, of, [o, blockSize, bytes, &of, remote](const auto & key) {
- auto p = std::make_shared<OpenFile::WriteState>();
- of->bg.insert({key, p});
- remote->writeAsync(
- o, blockSize, std::make_pair(bytes, bytes + blockSize),
- [p, of, key]() {
- p->promise.set_value();
- ScopeLock(of->mutex) {
- of->bg.erase(key);
- }
- },
- [p, of](auto e) {
- p->promise.set_exception(e);
- });
- });
- bytes += blockSize;
- o += blockSize;
- });
+ blockSizeIterate(
+ openFile->blockSizes(size), [&bytes, &offset, &remote, &openFile](safe<size_t> blockSize) {
+ waitOnWriteRangeAndThen(blockSize, offset, openFile,
+ [offset, blockSize, bytes, &openFile, remote](const auto & key) {
+ auto p = std::make_shared<OpenFile::WriteState>();
+ openFile->bg.insert({key, p});
+ remote->writeAsync(
+ offset, blockSize, std::make_pair(bytes, bytes + blockSize),
+ [p, openFile, key]() {
+ p->promise.set_value();
+ ScopeLock(openFile->mutex) {
+ openFile->bg.erase(key);
+ }
+ },
+ [p, openFile](auto error) {
+ p->promise.set_exception(std::move(error));
+ });
+ });
+ bytes += blockSize;
+ offset += blockSize;
+ });
}
- else if (of->bodyMaxSize < s) {
+ else if (openFile->bodyMaxSize < size) {
std::vector<std::future<void>> ops;
- blockSizeIterate(of->blockSizes(s), [&ops, &bytes, &o, &remote](safe<size_t> blockSize) {
- ops.emplace_back(remote->writeAsync(o, blockSize, std::make_pair(bytes, bytes + blockSize)));
+ blockSizeIterate(openFile->blockSizes(size), [&ops, &bytes, &offset, &remote](safe<size_t> blockSize) {
+ ops.emplace_back(remote->writeAsync(offset, blockSize, std::make_pair(bytes, bytes + blockSize)));
bytes += blockSize;
- o += blockSize;
- });
- std::for_each(ops.begin(), ops.end(), [](auto && op) {
- op.get();
+ offset += blockSize;
});
+ std::ranges::for_each(ops, &std::future<void>::get);
}
else {
- remote->write(o, safe {s}, std::make_pair(bytes, bytes + s));
+ remote->write(offset, safe {size}, std::make_pair(bytes, bytes + size));
}
- return safe {s};
+ return safe {size};
}
catch (SystemError & e) {
return -e.syserrno;
@@ -306,39 +302,35 @@ namespace NetFS {
FuseApp::OpenFile::blockSizes(size_t total, size_t max) noexcept
{
if (max >= total) { // Simple case, all in remainder block
- return {total, 0, 0};
+ return {.size1 = total, .sizeN = 0, .count = 0};
}
- else if (total % max == 0) { // Simplish case, multiples of max
- return {0, max, total / max};
+ if (total % max == 0) { // Simplish case, multiples of max
+ return {.size1 = 0, .sizeN = max, .count = total / max};
}
- else {
- const auto blocks = (total / max);
- const auto blockSize = (total / (blocks + 1)) + 1;
- const auto batchTotal = blockSize * blocks;
- const auto remainder = total - batchTotal;
+ const auto blocks = (total / max);
+ const auto blockSize = (total / (blocks + 1)) + 1;
+ const auto batchTotal = blockSize * blocks;
+ const auto remainder = total - batchTotal;
- return {remainder, blockSize, blocks};
- }
+ return {.size1 = remainder, .sizeN = blockSize, .count = blocks};
}
size_t
FuseApp::OpenFile::BlockSizes::total() const noexcept
{
- return size1 + (sizeN * N);
+ return size1 + (sizeN * count);
}
ssize_t
- FuseApp::copy_file_range(const char *, struct fuse_file_info * fi_in, off_t offset_in, const char *,
- struct fuse_file_info * fi_out, off_t offset_out, size_t size, int flags)
+ FuseApp::copy_file_range(const char *, struct fuse_file_info * fileInfoIn, off_t offsetIn, const char *,
+ struct fuse_file_info * fileInfoOut, off_t offsetOut, size_t size, int flags)
{
try {
- auto of_in = getProxy<OpenFilePtr>(fi_in->fh);
- auto of_out = getProxy<OpenFilePtr>(fi_out->fh);
- auto remote_in = of_in->remote;
- auto remote_out = of_out->remote;
- of_in->wait();
- of_out->wait();
- return remote_in->copyrange(remote_out, offset_in, offset_out, safe {size}, flags);
+ auto openFileIn = getProxy<OpenFilePtr>(fileInfoIn->fh);
+ auto openFileOut = getProxy<OpenFilePtr>(fileInfoOut->fh);
+ openFileIn->wait();
+ openFileOut->wait();
+ return openFileIn->remote->copyrange(openFileOut->remote, offsetIn, offsetOut, safe {size}, flags);
}
catch (SystemError & e) {
return -e.syserrno;
@@ -346,17 +338,16 @@ namespace NetFS {
}
int
- FuseApp::truncate(const char * p, off_t o, fuse_file_info * fi)
+ FuseApp::truncate(const char * path, off_t offset, fuse_file_info * fileInfo)
{
try {
- if (fi) {
- auto of = getProxy<OpenFilePtr>(fi->fh);
- of->wait();
- auto remote = of->remote;
- remote->ftruncate(o);
+ if (fileInfo) {
+ auto openFile = getProxy<OpenFilePtr>(fileInfo->fh);
+ openFile->wait();
+ openFile->remote->ftruncate(offset);
}
else {
- volume->truncate(reqEnv(), p, o);
+ volume->truncate(reqEnv(), path, offset);
}
return 0;
}
@@ -366,24 +357,23 @@ namespace NetFS {
}
int
- FuseApp::getattr(const char * p, struct stat * s, fuse_file_info * fi)
+ FuseApp::getattr(const char * path, struct stat * stat, fuse_file_info * fileInfo)
{
try {
- if (fi) {
- auto of = getProxy<OpenFilePtr>(fi->fh);
- of->wait();
- auto remote = of->remote;
- *s = converter.convert(remote->fgetattr());
+ if (fileInfo) {
+ auto openFile = getProxy<OpenFilePtr>(fileInfo->fh);
+ openFile->wait();
+ *stat = converter.convert(openFile->remote->fgetattr());
}
else {
- if (auto cacehedStat = statCache.get(std::filesystem::hash_value(p))) {
- *s = *cacehedStat;
+ if (auto cacehedStat = statCache.get(std::filesystem::hash_value(path))) {
+ *stat = *cacehedStat;
}
else {
- *s = converter.convert(volume->getattr(reqEnv(), p));
+ *stat = converter.convert(volume->getattr(reqEnv(), path));
}
}
- return s->st_mode ? 0 : -ENOENT;
+ return stat->st_mode ? 0 : -ENOENT;
}
catch (SystemError & e) {
return -e.syserrno;
@@ -391,10 +381,10 @@ namespace NetFS {
}
int
- FuseApp::unlink(const char * p)
+ FuseApp::unlink(const char * path)
{
try {
- volume->unlink(reqEnv(), p);
+ volume->unlink(reqEnv(), path);
return 0;
}
catch (SystemError & e) {
diff --git a/netfs/fuse/fuseFiles.h b/netfs/fuse/fuseFiles.h
index 087e1ee..4fe38e5 100644
--- a/netfs/fuse/fuseFiles.h
+++ b/netfs/fuse/fuseFiles.h
@@ -6,13 +6,13 @@
namespace NetFS {
class FuseApp::OpenFile {
public:
- OpenFile(FilePrxPtr remote, std::string path, int flags, size_t messageMaxSize);
+ OpenFile(FilePrxPtr remotePrx, std::string remotePath, int openFlags, size_t messageMaxSize);
void flush();
void wait() const;
struct BlockSizes {
- size_t size1, sizeN, N;
+ size_t size1, sizeN, count;
auto operator<=>(const BlockSizes &) const = default;
[[nodiscard]] size_t total() const noexcept;
};
@@ -29,6 +29,7 @@ namespace NetFS {
const std::string path;
const int flags;
const size_t bodyMaxSize;
+
class WriteState {
public:
WriteState();
@@ -36,6 +37,7 @@ namespace NetFS {
std::promise<void> promise;
std::shared_future<void> future;
};
+
using BGs = boost::icl::interval_map<size_t, std::shared_ptr<WriteState>>;
static BGs::interval_type range(off_t, size_t);
BGs bg;
diff --git a/netfs/fuse/fuseMappers.ice b/netfs/fuse/fuseMappers.ice
index 0eb5ea5..c404472 100644
--- a/netfs/fuse/fuseMappers.ice
+++ b/netfs/fuse/fuseMappers.ice
@@ -13,9 +13,9 @@ module NetFS {
string UnknownUser = "nobody";
["slicer:name:unknowngroup"]
string UnknownGroup = "nogroup";
- ["slicer:name:usermask","slicer:conversion:std.string:NetFS.Client.from_octal:NetFS.Client.to_octal:nodeclare"]
+ ["slicer:name:usermask","slicer:conversion:std.string:NetFS.Client.fromOctal:NetFS.Client.toOctal:nodeclare"]
int UserMask = 0700;
- ["slicer:name:groupmask","slicer:conversion:std.string:NetFS.Client.from_octal:NetFS.Client.to_octal:nodeclare"]
+ ["slicer:name:groupmask","slicer:conversion:std.string:NetFS.Client.fromOctal:NetFS.Client.toOctal:nodeclare"]
int GroupMask = 0070;
};
};
diff --git a/netfs/fuse/fuseMappersImpl.cpp b/netfs/fuse/fuseMappersImpl.cpp
index 7e129f6..a6ac148 100644
--- a/netfs/fuse/fuseMappersImpl.cpp
+++ b/netfs/fuse/fuseMappersImpl.cpp
@@ -1,75 +1,74 @@
#include "fuseMappersImpl.h"
#include <entCache.h>
+#include <format>
#include <numeric.h>
namespace NetFS::Client {
constexpr int MASK_EVERYTHING = ~0;
- static_assert(MASK_EVERYTHING == static_cast<int>(0xFFFFFFFF));
Mapping::FileSystem
- HideUnknownMapperImpl::mapTransport(const std::string & un, const std::string & gn)
+ HideUnknownMapperImpl::mapTransport(const std::string & userName, const std::string & groupName)
{
- auto u = users->getEntry(un);
- auto g = groups->getEntry(gn);
- if (!u || !g) {
- return {0, 0, MASK_EVERYTHING};
+ auto user = users->getEntry(userName);
+ auto group = groups->getEntry(groupName);
+ if (!user || !group) {
+ return {.uid = 0, .gid = 0, .mask = MASK_EVERYTHING};
}
- return {static_cast<int>(u->id), static_cast<int>(g->id), 0};
+ return {.uid = safe(user->id), .gid = safe(group->id), .mask = 0};
}
Mapping::Transport
HideUnknownMapperImpl::mapFileSystem(int uid, int gid)
{
- auto u = users->getEntry(safe {uid});
- auto g = groups->getEntry(safe {gid});
- if (!u || !g) {
+ auto user = users->getEntry(safe {uid});
+ auto group = groups->getEntry(safe {gid});
+ if (!user || !group) {
throw NetFS::SystemError(EPERM);
}
- return {u->name, g->name, 0};
+ return {.username = user->name, .groupname = group->name, .mask = 0};
}
Mapping::FileSystem
- MaskUnknownMapperImpl::mapTransport(const std::string & un, const std::string & gn)
+ MaskUnknownMapperImpl::mapTransport(const std::string & userName, const std::string & groupName)
{
int mask = 0;
auto apply = [&mask](const auto & resolver, const auto & entry, const auto & fallbackentry, auto entrymask) {
- auto e = resolver->getEntry(entry);
- if (!e) {
- e = resolver->getEntry(fallbackentry);
- if (!e) {
+ auto resolvedEntry = resolver->getEntry(entry);
+ if (!resolvedEntry) {
+ resolvedEntry = resolver->getEntry(fallbackentry);
+ if (!resolvedEntry) {
throw NetFS::SystemError(EPERM);
}
mask |= entrymask;
}
- return e;
+ return resolvedEntry;
};
- auto u = apply(users, un, UnknownUser, UserMask);
- auto g = apply(groups, gn, UnknownGroup, GroupMask);
- return {static_cast<int>(u->id), static_cast<int>(g->id), mask};
+ auto user = apply(users, userName, UnknownUser, UserMask);
+ auto group = apply(groups, groupName, UnknownGroup, GroupMask);
+ return {.uid = safe(user->id), .gid = safe(group->id), .mask = mask};
}
Mapping::Transport
MaskUnknownMapperImpl::mapFileSystem(int uid, int gid)
{
- auto u = users->getEntry(safe {uid});
- auto g = groups->getEntry(safe {gid});
- if (!u || !g) {
+ auto user = users->getEntry(safe {uid});
+ auto group = groups->getEntry(safe {gid});
+ if (!user || !group) {
throw NetFS::SystemError(EPERM);
}
- return {u->name, g->name, 0};
+ return {.username = user->name, .groupname = group->name, .mask = 0};
}
Ice::Int
- from_octal(const std::string & in)
+ fromOctal(const std::string & input)
{
- return std::stoi(in, nullptr, 8);
+ static constexpr int OCTAL_BASE = 8;
+ return std::stoi(input, nullptr, OCTAL_BASE);
}
std::string
- to_octal(const Ice::Int & in)
+ toOctal(const Ice::Int & input)
{
- std::stringstream s;
- s << std::oct << in;
- return s.str();
+ return std::format("{:o}", input);
}
}
diff --git a/netfs/fuse/fuseMappersImpl.h b/netfs/fuse/fuseMappersImpl.h
index e37874a..f97acb3 100644
--- a/netfs/fuse/fuseMappersImpl.h
+++ b/netfs/fuse/fuseMappersImpl.h
@@ -1,21 +1,19 @@
#pragma once
#include "baseMapper.h"
-#include "entries.h"
-#include "entryResolver.h"
#include <fuseMappers.h>
#include <visibility.h>
namespace NetFS::Client {
- std::string to_octal(const Ice::Int &);
- Ice::Int from_octal(const std::string &);
+ std::string toOctal(const Ice::Int &);
+ Ice::Int fromOctal(const std::string &);
class DLL_PUBLIC HideUnknownMapperImpl : public HideUnknownMapper, Mapping::BaseMapper {
public:
using BaseMapper::BaseMapper;
Mapping::Transport mapFileSystem(int uid, int gid) override;
- Mapping::FileSystem mapTransport(const std::string & un, const std::string & gn) override;
+ Mapping::FileSystem mapTransport(const std::string & userName, const std::string & groupName) override;
};
class DLL_PUBLIC MaskUnknownMapperImpl : public MaskUnknownMapper, Mapping::BaseMapper {
@@ -23,6 +21,6 @@ namespace NetFS::Client {
using BaseMapper::BaseMapper;
Mapping::Transport mapFileSystem(int uid, int gid) override;
- Mapping::FileSystem mapTransport(const std::string & un, const std::string & gn) override;
+ Mapping::FileSystem mapTransport(const std::string & userName, const std::string & groupName) override;
};
}
diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp
index 8069234..21c4a32 100644
--- a/netfs/fuse/fuseMisc.cpp
+++ b/netfs/fuse/fuseMisc.cpp
@@ -2,18 +2,19 @@
#include <cstring>
#include <entCache.h>
#include <numeric.h>
+#include <span>
int
-NetFS::FuseApp::access(const char * p, int a)
+NetFS::FuseApp::access(const char * path, int accessMode)
{
- return -volume->access(reqEnv(), p, a);
+ return -volume->access(reqEnv(), path, accessMode);
}
int
-NetFS::FuseApp::chmod(const char * p, mode_t m, fuse_file_info *)
+NetFS::FuseApp::chmod(const char * path, mode_t mode, fuse_file_info *)
{
try {
- volume->chmod(reqEnv(), p, safe {m});
+ volume->chmod(reqEnv(), path, safe {mode});
return 0;
}
catch (NetFS::SystemError & e) {
@@ -22,10 +23,10 @@ NetFS::FuseApp::chmod(const char * p, mode_t m, fuse_file_info *)
}
int
-NetFS::FuseApp::chown(const char * p, uid_t u, gid_t g, fuse_file_info *)
+NetFS::FuseApp::chown(const char * path, uid_t uid, gid_t gid, fuse_file_info *)
{
try {
- volume->chown(reqEnv(), p, safe {u}, safe {g});
+ volume->chown(reqEnv(), path, safe {uid}, safe {gid});
return 0;
}
catch (NetFS::SystemError & e) {
@@ -34,10 +35,10 @@ NetFS::FuseApp::chown(const char * p, uid_t u, gid_t g, fuse_file_info *)
}
int
-NetFS::FuseApp::link(const char * p1, const char * p2)
+NetFS::FuseApp::link(const char * path1, const char * path2)
{
try {
- volume->link(reqEnv(), p1, p2);
+ volume->link(reqEnv(), path1, path2);
return 0;
}
catch (NetFS::SystemError & e) {
@@ -46,10 +47,10 @@ NetFS::FuseApp::link(const char * p1, const char * p2)
}
int
-NetFS::FuseApp::mknod(const char * p, mode_t mode, dev_t dev)
+NetFS::FuseApp::mknod(const char * path, mode_t mode, dev_t dev)
{
try {
- volume->mknod(reqEnv(), p, safe {mode}, safe {dev});
+ volume->mknod(reqEnv(), path, safe {mode}, safe {dev});
return 0;
}
catch (NetFS::SystemError & e) {
@@ -58,10 +59,10 @@ NetFS::FuseApp::mknod(const char * p, mode_t mode, dev_t dev)
}
int
-NetFS::FuseApp::symlink(const char * p1, const char * p2)
+NetFS::FuseApp::symlink(const char * path1, const char * path2)
{
try {
- volume->symlink(reqEnv(), p1, p2);
+ volume->symlink(reqEnv(), path1, path2);
return 0;
}
catch (NetFS::SystemError & e) {
@@ -70,12 +71,14 @@ NetFS::FuseApp::symlink(const char * p1, const char * p2)
}
int
-NetFS::FuseApp::readlink(const char * p, char * p2, size_t s)
+NetFS::FuseApp::readlink(const char * path, char * path2, size_t size)
{
try {
- std::string l = volume->readlink(reqEnv(), p);
- l.copy(p2, s);
- p2[l.length()] = '\0';
+ const auto link = volume->readlink(reqEnv(), path);
+ if (size <= link.length()) {
+ return -ENAMETOOLONG;
+ }
+ link.copy(path2, size);
return 0;
}
catch (NetFS::SystemError & e) {
@@ -84,10 +87,10 @@ NetFS::FuseApp::readlink(const char * p, char * p2, size_t s)
}
int
-NetFS::FuseApp::rename(const char * p1, const char * p2, unsigned int flags)
+NetFS::FuseApp::rename(const char * path1, const char * path2, unsigned int flags)
{
try {
- volume->rename(reqEnv(), p1, p2, safe {flags});
+ volume->rename(reqEnv(), path1, path2, safe {flags});
return 0;
}
catch (NetFS::SystemError & e) {
@@ -96,11 +99,13 @@ NetFS::FuseApp::rename(const char * p1, const char * p2, unsigned int flags)
}
int
-// NOLINTNEXTLINE(modernize-avoid-c-arrays,hicpp-avoid-c-arrays)
+// NOLINTNEXTLINE(*-c-arrays)
NetFS::FuseApp::utimens(const char * path, const struct timespec times[2], fuse_file_info *)
{
try {
- volume->utimens(reqEnv(), path, times[0].tv_sec, times[0].tv_nsec, times[1].tv_sec, times[1].tv_nsec);
+ std::span<const struct timespec, 2> timesSpan(times, 2);
+ volume->utimens(reqEnv(), path, timesSpan.front().tv_sec, timesSpan.front().tv_nsec, timesSpan.back().tv_sec,
+ timesSpan.back().tv_nsec);
return 0;
}
catch (NetFS::SystemError & e) {
diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp
index 413bbda..91d71f1 100644
--- a/netfs/fuse/fuseSystem.cpp
+++ b/netfs/fuse/fuseSystem.cpp
@@ -1,10 +1,10 @@
#include "fuseApp.h"
int
-NetFS::FuseApp::statfs(const char * p, struct statvfs * vfs)
+NetFS::FuseApp::statfs(const char * path, struct statvfs * vfs)
{
try {
- *vfs = converter.TypeConverter::convert(volume->statfs(reqEnv(), p));
+ *vfs = converter.TypeConverter::convert(volume->statfs(reqEnv(), path));
return 0;
}
catch (NetFS::SystemError & e) {
diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp
index 7c5ea1a..a28ab16 100644
--- a/netfs/fuse/netfs.cpp
+++ b/netfs/fuse/netfs.cpp
@@ -4,8 +4,8 @@
class FuseImpl : public fuse_args, public NetFS::FuseApp {
public:
- FuseImpl(int c, char ** v) :
- fuse_args(FUSE_ARGS_INIT(c, v)), NetFS::FuseApp([this]() {
+ FuseImpl(int argcIn, char ** argvIn) :
+ fuse_args(FUSE_ARGS_INIT(argcIn, argvIn)), NetFS::FuseApp([this]() {
Ice::StringSeq rtn;
if (fuse_opt_parse(this, &rtn, nullptr, opt_parse) == -1) {
exit(-1);
@@ -24,7 +24,7 @@ public:
SPECIAL_MEMBERS_DELETE(FuseImpl);
struct fuse_context *
- fuse_get_context() override
+ fuseGetContext() override
{
return ::fuse_get_context();
}
@@ -32,7 +32,7 @@ public:
int
run()
{
- return ::fuse_main(argc, argv, &operations, this);
+ return ::fuse_main(argc, argv, &OPERATIONS, this);
}
void
diff --git a/netfs/unittests/mockFuse.cpp b/netfs/unittests/mockFuse.cpp
index 0de5cf2..36a5aed 100644
--- a/netfs/unittests/mockFuse.cpp
+++ b/netfs/unittests/mockFuse.cpp
@@ -13,7 +13,7 @@ FuseMock::FuseMock(std::string ep, Ice::StringSeq a) :
}
struct fuse_context *
-FuseMock::fuse_get_context()
+FuseMock::fuseGetContext()
{
return &context;
}
@@ -54,15 +54,16 @@ void
FuseMock::vlogf(int, const char * fmt, va_list args) const noexcept
{
static std::mutex btm;
+
ScopeLock(btm) {
BOOST_TEST_MESSAGE(vstringf(fmt, args));
}
}
FuseMockHost::FuseMockHost(std::string ep, const Ice::StringSeq & a) :
- app(std::make_unique<FuseMock>(std::move(ep), a)), fuse(&app->operations)
+ app(std::make_unique<FuseMock>(std::move(ep), a)), fuse(&app->OPERATIONS)
{
- if (app->operations.init) {
- app->operations.init(nullptr, nullptr);
+ if (app->OPERATIONS.init) {
+ app->OPERATIONS.init(nullptr, nullptr);
}
}
diff --git a/netfs/unittests/mockFuse.h b/netfs/unittests/mockFuse.h
index 7a380eb..cd15cad 100644
--- a/netfs/unittests/mockFuse.h
+++ b/netfs/unittests/mockFuse.h
@@ -8,7 +8,7 @@ class DLL_PUBLIC FuseMock : public NetFS::FuseApp {
public:
FuseMock(std::string, Ice::StringSeq);
- struct fuse_context * fuse_get_context() override;
+ struct fuse_context * fuseGetContext() override;
void vlogf(int, const char *, va_list) const throw() override;
void connectToService() override;
diff --git a/netfs/unittests/mockMount.cpp b/netfs/unittests/mockMount.cpp
index 5c6a0b8..81ba0d2 100644
--- a/netfs/unittests/mockMount.cpp
+++ b/netfs/unittests/mockMount.cpp
@@ -11,7 +11,7 @@ MockFuseApp::MockFuseApp() : NetFS::FuseApp({::testUri}), fargs {}
::fuse_opt_add_arg(&fargs, "-onoauto_cache");
::fuse_opt_add_arg(&fargs, "-oattr_timeout=0");
::fuse_opt_add_arg(&fargs, "-oac_attr_timeout=0");
- fs = ::fuse_new(&fargs, &operations, sizeof(fuse_operations), this);
+ fs = ::fuse_new(&fargs, &OPERATIONS, sizeof(fuse_operations), this);
BOOST_REQUIRE(fs);
}
@@ -46,7 +46,7 @@ MockFuseApp::~MockFuseApp()
}
struct fuse_context *
-MockFuseApp::fuse_get_context()
+MockFuseApp::fuseGetContext()
{
return ::fuse_get_context();
}
@@ -69,6 +69,7 @@ MockFuseApp::vlogf(int, const char * fmt, va_list args) const noexcept
{
std::unique_ptr<char, void (*)(void *)> msg(vstrdupf(fmt, args), std::free);
static std::mutex btm;
+
ScopeLock(btm) {
BOOST_TEST_MESSAGE(msg.get());
}
diff --git a/netfs/unittests/mockMount.h b/netfs/unittests/mockMount.h
index 8495718..2fec87a 100644
--- a/netfs/unittests/mockMount.h
+++ b/netfs/unittests/mockMount.h
@@ -15,9 +15,10 @@ public:
~MockFuseApp() override;
SPECIAL_MEMBERS_DELETE(MockFuseApp);
- struct fuse_context * fuse_get_context() override;
+ struct fuse_context * fuseGetContext() override;
void vlogf(int, const char * fmt, va_list args) const noexcept override;
+
const auto &
getStatCache() const
{
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp
index a6a74d5..6f4511f 100644
--- a/netfs/unittests/testCore.cpp
+++ b/netfs/unittests/testCore.cpp
@@ -30,6 +30,7 @@ namespace std {
}
AdHocFormatter(StatDebug, "dev: %? inode: %?");
+
// LCOV_EXCL_START
template<typename T, size_t l>
ostream &
@@ -44,6 +45,7 @@ namespace std {
{
return StatDebug::write(s, ss.st_dev, ss.st_ino);
}
+
// LCOV_EXCL_STOP
}
@@ -87,8 +89,8 @@ BOOST_FIXTURE_TEST_SUITE(NetfsCore, Core);
BOOST_AUTO_TEST_CASE(fuse_operations_correct)
{
- BOOST_CHECK(NetFS::FuseApp::operations.access);
- BOOST_CHECK(!NetFS::FuseApp::operations.destroy);
+ BOOST_CHECK(NetFS::FuseApp::OPERATIONS.access);
+ BOOST_CHECK(!NetFS::FuseApp::OPERATIONS.destroy);
// open should be defined
BOOST_REQUIRE(fuse->open);
@@ -128,9 +130,8 @@ BOOST_AUTO_TEST_CASE(clientInitialised)
BOOST_AUTO_TEST_CASE(testNavigation)
{
- struct stat attr {
- }, rootattr {}, insideattr {};
- struct fuse_file_info fi { };
+ struct stat attr {}, rootattr {}, insideattr {};
+ struct fuse_file_info fi {};
int fd = fuse->create("/inside", 0666, &fi);
BOOST_REQUIRE(fd >= 0);
fuse->release("/inside", &fi);
@@ -165,7 +166,7 @@ BOOST_AUTO_TEST_CASE(testSandboxing)
std::filesystem::remove(tmpDir / "outside");
std::filesystem::remove(tmpDir / "sub" / "outside");
std::filesystem::remove(tmpDir / "sub");
- struct fuse_file_info fi { };
+ struct fuse_file_info fi {};
BOOST_REQUIRE_EQUAL(fuse->create("../outside", 0666, &fi), -EPERM);
BOOST_REQUIRE(!std::filesystem::exists(tmpDir / "outside"));
BOOST_REQUIRE_EQUAL(fuse->create("/../outside", 0666, &fi), -EPERM);
@@ -189,7 +190,7 @@ BOOST_AUTO_TEST_CASE(testSandboxing)
void
enableWriteOnDir(const fuse_operations * fuse, const char * dir)
{
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->chmod(dir, 0700, nullptr), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr(dir, &st, nullptr), 0);
BOOST_REQUIRE_EQUAL(st.st_mode, 0700 | S_IFDIR);
@@ -198,7 +199,7 @@ enableWriteOnDir(const fuse_operations * fuse, const char * dir)
void
disableWriteOnDir(const fuse_operations * fuse, const char * dir)
{
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->chmod(dir, 0500, nullptr), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr(dir, &st, nullptr), 0);
BOOST_REQUIRE_EQUAL(st.st_mode, 0500 | S_IFDIR);
@@ -206,8 +207,8 @@ disableWriteOnDir(const fuse_operations * fuse, const char * dir)
BOOST_AUTO_TEST_CASE(directories)
{
- struct fuse_file_info fi { };
- struct stat st { };
+ struct fuse_file_info fi {};
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), 0);
BOOST_REQUIRE(std::filesystem::is_directory(tmpDir / testExport / "test"));
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), -EEXIST);
@@ -250,9 +251,8 @@ BOOST_AUTO_TEST_CASE(directories)
BOOST_AUTO_TEST_CASE(files)
{
- struct fuse_file_info fi { };
- struct stat st {
- }, st2 {};
+ struct fuse_file_info fi {};
+ struct stat st {}, st2 {};
fi.flags = O_RDWR;
BOOST_REQUIRE_EQUAL(fuse->open("/test", &fi), -ENOENT);
BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), 0);
@@ -307,8 +307,7 @@ BOOST_AUTO_TEST_CASE(files)
BOOST_AUTO_TEST_CASE(files_copy_range)
{
- struct fuse_file_info fiin {
- }, fiout {};
+ struct fuse_file_info fiin {}, fiout {};
fiin.flags = O_RDWR;
fiout.flags = O_RDWR;
BOOST_REQUIRE_EQUAL(fuse->create("/src", 0600, &fiin), 0);
@@ -324,8 +323,8 @@ BOOST_AUTO_TEST_CASE(files_copy_range)
BOOST_AUTO_TEST_CASE(bgwriteOverlapped, *boost::unit_test::timeout(2))
{
- struct fuse_file_info fi { };
- struct stat st { };
+ struct fuse_file_info fi {};
+ struct stat st {};
fi.flags = O_RDWR;
constexpr auto s = sizeof(int32_t);
constexpr auto N = 20U;
@@ -345,8 +344,8 @@ BOOST_AUTO_TEST_CASE(bgwriteOverlapped, *boost::unit_test::timeout(2))
BOOST_AUTO_TEST_CASE(bgwriteDistinct, *boost::unit_test::timeout(2))
{
- struct fuse_file_info fi { };
- struct stat st { };
+ struct fuse_file_info fi {};
+ struct stat st {};
fi.flags = O_RDWR;
constexpr auto s = sizeof(int32_t);
constexpr auto N = 20U;
@@ -382,7 +381,7 @@ BOOST_AUTO_TEST_CASE(symlinks)
BOOST_AUTO_TEST_CASE(access)
{
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->access("/", F_OK), 0);
BOOST_REQUIRE_EQUAL(fuse->access("/missing", F_OK), -ENOENT);
// Basic assertions
@@ -408,7 +407,7 @@ BOOST_AUTO_TEST_CASE(access)
BOOST_AUTO_TEST_CASE(permissionsDirs)
{
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir/yes", 0000), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st, nullptr), 0);
@@ -424,8 +423,8 @@ BOOST_AUTO_TEST_CASE(permissionsDirs)
BOOST_AUTO_TEST_CASE(permissionsFiles)
{
- struct stat st { };
- struct fuse_file_info fi { };
+ struct stat st {};
+ struct fuse_file_info fi {};
fi.flags = O_RDWR;
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
BOOST_REQUIRE_NE(fuse->create("/dir/yes", 0000, &fi), -1);
@@ -445,7 +444,7 @@ BOOST_AUTO_TEST_CASE(mknod)
{
BOOST_REQUIRE_EQUAL(fuse->mknod("/nod", 0600 | S_IFIFO, 0), 0);
BOOST_REQUIRE_EQUAL(fuse->mknod("/nod", 0600 | S_IFIFO, 0), -EEXIST);
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->getattr("/nod", &st, nullptr), 0);
BOOST_REQUIRE_EQUAL(st.st_mode, 0600 | S_IFIFO);
BOOST_REQUIRE_EQUAL(fuse->unlink("/nod"), 0);
@@ -457,7 +456,7 @@ BOOST_AUTO_TEST_CASE(mknod)
BOOST_AUTO_TEST_CASE(renameToDir)
{
- struct fuse_file_info fi { };
+ struct fuse_file_info fi {};
BOOST_REQUIRE_EQUAL(fuse->create("/file", 0600, &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->release("/file", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
@@ -476,7 +475,7 @@ BOOST_AUTO_TEST_CASE(renameToDir)
BOOST_AUTO_TEST_CASE(renameFlags)
{
- struct fuse_file_info fi { };
+ struct fuse_file_info fi {};
BOOST_REQUIRE_EQUAL(fuse->create("/file", 0600, &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->release("/file", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->create("/file2", 0600, &fi), 0);
@@ -495,7 +494,7 @@ BOOST_AUTO_TEST_CASE(chown)
{
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0777), 0);
BOOST_REQUIRE_EQUAL(fuse->chown("/dir", getuid(), getgid(), nullptr), 0);
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st, nullptr), 0);
BOOST_REQUIRE_EQUAL(st.st_uid, getuid());
BOOST_REQUIRE_EQUAL(st.st_gid, getgid());
@@ -510,7 +509,7 @@ BOOST_AUTO_TEST_CASE(utimens)
BOOST_REQUIRE_EQUAL(fuse->utimens("/file", times.data(), nullptr), 0);
times[1].tv_nsec = -200;
BOOST_REQUIRE_EQUAL(fuse->utimens("/file", times.data(), nullptr), -EINVAL);
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->getattr("/file", &st, nullptr), 0);
BOOST_REQUIRE_EQUAL(st.st_atime, 1);
BOOST_REQUIRE_EQUAL(st.st_atim.tv_sec, 1);
@@ -536,7 +535,7 @@ BOOST_FIXTURE_TEST_SUITE(NetfsAltCore, AltCore);
BOOST_AUTO_TEST_CASE(noListDir)
{
- struct fuse_file_info fi { };
+ struct fuse_file_info fi {};
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), 0);
BOOST_REQUIRE(std::filesystem::is_directory(tmpDir / testExport / "test"));
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), -EEXIST);
@@ -575,8 +574,8 @@ BOOST_AUTO_TEST_CASE(noListDir)
BOOST_AUTO_TEST_CASE(testFGWrites)
{
- struct fuse_file_info fi { };
- struct stat st { };
+ struct fuse_file_info fi {};
+ struct stat st {};
fi.flags = O_RDWR;
BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->write("/test", "some test buffer", 16, 0, &fi), 16);
diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp
index 0c78084..75ff3aa 100644
--- a/netfs/unittests/testEdgeCases.cpp
+++ b/netfs/unittests/testEdgeCases.cpp
@@ -16,19 +16,19 @@ BOOST_AUTO_TEST_CASE(createAndDaemonRestart)
MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string()});
- struct statvfs s { };
+ struct statvfs s {};
BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
const char * fileName = "/createMe";
BOOST_TEST_CHECKPOINT("Create a new file");
- struct fuse_file_info fh { };
+ struct fuse_file_info fh {};
memset(&fh, 0, sizeof(fh));
fh.flags = O_WRONLY | O_CREAT | O_APPEND;
BOOST_REQUIRE_EQUAL(0, fuse.fuse->create(fileName, 0100644, &fh));
BOOST_REQUIRE(fh.fh);
BOOST_TEST_CHECKPOINT("Fetch file attributes");
- struct stat st { };
+ struct stat st {};
BOOST_REQUIRE_EQUAL(0, fuse.fuse->getattr(fileName, &st, &fh));
BOOST_REQUIRE_EQUAL(st.st_size, 0);
BOOST_REQUIRE_EQUAL(st.st_uid, getuid());
@@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(noDaemonAtStartUp)
{
FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string()});
- struct statvfs s { };
+ struct statvfs s {};
BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
@@ -73,12 +73,14 @@ BOOST_AUTO_TEST_CASE(noDaemonAtStartUp)
BOOST_AUTO_TEST_CASE(daemonUnavailableAfterUse)
{
FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string()});
- struct statvfs s { };
+
+ struct statvfs s {};
{
MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
}
+
BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
{
MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
@@ -99,7 +101,7 @@ BOOST_AUTO_TEST_CASE(manyThreads)
std::atomic<unsigned int> success {0}, failure {0};
for (int x = 0; x < 20; x++) {
ths.emplace_back([&] {
- struct statvfs s { };
+ struct statvfs s {};
while (running) {
if (fuse.fuse->statfs("/", &s) == 0) {
success++;
@@ -129,7 +131,7 @@ namespace std {
ostream &
operator<<(ostream & s, const FuseMock::OpenFile::BlockSizes & b)
{
- return s << '(' << b.size1 << '+' << b.sizeN << '*' << b.N << ')';
+ return s << '(' << b.size1 << '+' << b.sizeN << '*' << b.count << ')';
}
}