summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-08-30 19:22:42 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2020-08-30 19:28:42 +0100
commit68329fe3f6dcd5ec769dab52ba7cfd25ec1f5494 (patch)
tree5606f17a9cf8ca17fa907bfc658ac32a01e6aff6
parentEntryResolvers return where they got the resolution from (diff)
downloadnetfs-68329fe3f6dcd5ec769dab52ba7cfd25ec1f5494.tar.bz2
netfs-68329fe3f6dcd5ec769dab52ba7cfd25ec1f5494.tar.xz
netfs-68329fe3f6dcd5ec769dab52ba7cfd25ec1f5494.zip
Clang format all the code
-rw-r--r--netfs/daemon/daemon.cpp23
-rw-r--r--netfs/daemon/daemon.h31
-rw-r--r--netfs/daemon/daemonConfigImpl.cpp3
-rw-r--r--netfs/daemon/daemonDirectory.cpp20
-rw-r--r--netfs/daemon/daemonDirectory.h17
-rw-r--r--netfs/daemon/daemonFile.cpp33
-rw-r--r--netfs/daemon/daemonFile.h22
-rw-r--r--netfs/daemon/daemonService.cpp10
-rw-r--r--netfs/daemon/daemonService.h18
-rw-r--r--netfs/daemon/daemonVolume.cpp68
-rw-r--r--netfs/daemon/daemonVolume.h66
-rw-r--r--netfs/daemon/modeCheck.cpp36
-rw-r--r--netfs/daemon/modeCheck.h39
-rw-r--r--netfs/fuse/fuseApp.cpp22
-rw-r--r--netfs/fuse/fuseApp.h220
-rw-r--r--netfs/fuse/fuseApp.impl.h8
-rw-r--r--netfs/fuse/fuseAppBase.cpp143
-rw-r--r--netfs/fuse/fuseAppBase.h236
-rw-r--r--netfs/fuse/fuseConfigImpl.cpp3
-rw-r--r--netfs/fuse/fuseDirs.cpp154
-rw-r--r--netfs/fuse/fuseDirs.h9
-rw-r--r--netfs/fuse/fuseFiles.cpp449
-rw-r--r--netfs/fuse/fuseFiles.h35
-rw-r--r--netfs/fuse/fuseMisc.cpp4
-rw-r--r--netfs/fuse/fuseSystem.cpp1
-rw-r--r--netfs/fuse/netfs.cpp81
-rw-r--r--netfs/ice/entryResolver.h15
-rw-r--r--netfs/ice/exceptionsImpl.cpp3
-rw-r--r--netfs/ice/typeConverter.cpp16
-rw-r--r--netfs/ice/typeConverter.h33
-rw-r--r--netfs/lib/entCache.cpp1
-rw-r--r--netfs/lib/entCache.h84
-rw-r--r--netfs/lib/entCache.impl.h64
-rw-r--r--netfs/unittests/mockDaemon.cpp20
-rw-r--r--netfs/unittests/mockDaemon.h37
-rw-r--r--netfs/unittests/mockFuse.cpp8
-rw-r--r--netfs/unittests/mockFuse.h31
-rw-r--r--netfs/unittests/testCore.cpp248
-rw-r--r--netfs/unittests/testEdgeCases.cpp87
-rw-r--r--netfs/unittests/testFuse.cpp136
-rw-r--r--netfs/unittests/testGlacier.cpp31
-rw-r--r--netfs/unittests/testLib.cpp24
42 files changed, 1274 insertions, 1315 deletions
diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp
index ddd67f2..e232aaa 100644
--- a/netfs/daemon/daemon.cpp
+++ b/netfs/daemon/daemon.cpp
@@ -1,11 +1,11 @@
-#include <Ice/Ice.h>
#include "daemon.h"
#include "daemonService.h"
#include "daemonVolume.h"
-#include <slicer/slicer.h>
#include "modeCheck.h"
-#include <sys/stat.h>
+#include <Ice/Ice.h>
#include <safeMapFind.h>
+#include <slicer/slicer.h>
+#include <sys/stat.h>
NetFSDaemon::~NetFSDaemon()
{
@@ -32,7 +32,7 @@ NetFSDaemon::hostname()
// name = NetFSDaemonAdapter
void
-NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq&)
+NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &)
{
this->ic = ic;
Ice::PropertiesPtr props = ic->getProperties();
@@ -66,12 +66,11 @@ NetFSDaemon::stop()
}
extern "C" {
- DLL_PUBLIC
- IceBox::Service *
- // NOLINTNEXTLINE(performance-unnecessary-value-param)
- createNetFSDaemon(Ice::CommunicatorPtr)
- {
- return new NetFSDaemon();
- }
+DLL_PUBLIC
+IceBox::Service *
+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
+ createNetFSDaemon(Ice::CommunicatorPtr)
+{
+ return new NetFSDaemon();
+}
}
-
diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h
index cea9643..373c0cb 100644
--- a/netfs/daemon/daemon.h
+++ b/netfs/daemon/daemon.h
@@ -3,32 +3,31 @@
#include <Ice/Ice.h>
#include <IceBox/IceBox.h>
+#include <c++11Helpers.h>
#include <daemonConfig.h>
#include <filesystem>
#include <visibility.h>
-#include <c++11Helpers.h>
class DLL_PUBLIC NetFSDaemon : public IceBox::Service {
- public:
- NetFSDaemon() = default;
- SPECIAL_MEMBERS_MOVE_RO(NetFSDaemon);
- ~NetFSDaemon() override;
+public:
+ NetFSDaemon() = default;
+ SPECIAL_MEMBERS_MOVE_RO(NetFSDaemon);
+ ~NetFSDaemon() override;
- void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override;
- void stop() override;
+ void start(const std::string &, const Ice::CommunicatorPtr &, const Ice::StringSeq &) override;
+ void stop() override;
- protected:
- [[nodiscard]] virtual NetFS::Daemon::ConfigurationPtr ReadConfiguration(const std::filesystem::path & path) const;
+protected:
+ [[nodiscard]] virtual NetFS::Daemon::ConfigurationPtr ReadConfiguration(const std::filesystem::path & path) const;
- private:
- void LoadConfiguration(const std::filesystem::path & path);
+private:
+ void LoadConfiguration(const std::filesystem::path & path);
- Ice::CommunicatorPtr ic;
- Ice::ObjectAdapterPtr adapter;
- NetFS::Daemon::RuntimeConfigurationPtr dc;
+ Ice::CommunicatorPtr ic;
+ Ice::ObjectAdapterPtr adapter;
+ NetFS::Daemon::RuntimeConfigurationPtr dc;
- std::string hostname();
+ std::string hostname();
};
#endif
-
diff --git a/netfs/daemon/daemonConfigImpl.cpp b/netfs/daemon/daemonConfigImpl.cpp
index 48b1d0e..e45cf97 100644
--- a/netfs/daemon/daemonConfigImpl.cpp
+++ b/netfs/daemon/daemonConfigImpl.cpp
@@ -1,5 +1,5 @@
-#include <daemonConfig.h>
#include <compileTimeFormatter.h>
+#include <daemonConfig.h>
AdHocFormatter(HostNotConfiguredMsg, "This host [%?] is not defined in the configuration");
void
@@ -7,4 +7,3 @@ NetFS::Daemon::HostNotConfigured::ice_print(std::ostream & s) const
{
HostNotConfiguredMsg::write(s, hostName);
}
-
diff --git a/netfs/daemon/daemonDirectory.cpp b/netfs/daemon/daemonDirectory.cpp
index 22c0e4f..cf56c72 100644
--- a/netfs/daemon/daemonDirectory.cpp
+++ b/netfs/daemon/daemonDirectory.cpp
@@ -1,17 +1,13 @@
+#include "daemonDirectory.h"
#include <Ice/ObjectAdapter.h>
-#include <dirent.h>
#include <cerrno>
+#include <dirent.h>
+#include <fcntl.h>
#include <map>
#include <sys/stat.h>
#include <sys/types.h>
-#include <fcntl.h>
-#include "daemonDirectory.h"
-DirectoryServer::DirectoryServer(DIR * d, EntryTypeConverter & t) :
- EntryTypeConverter(t),
- od(d)
-{
-}
+DirectoryServer::DirectoryServer(DIR * d, EntryTypeConverter & t) : EntryTypeConverter(t), od(d) { }
void
DirectoryServer::close(const Ice::Current & ice)
@@ -26,7 +22,7 @@ DirectoryServer::close(const Ice::Current & ice)
}
NetFS::NameList
-DirectoryServer::readdir(const Ice::Current&)
+DirectoryServer::readdir(const Ice::Current &)
{
errno = 0;
NetFS::NameList list;
@@ -42,7 +38,7 @@ DirectoryServer::readdir(const Ice::Current&)
}
NetFS::DirectoryContents
-DirectoryServer::listdir(const Ice::Current&)
+DirectoryServer::listdir(const Ice::Current &)
{
errno = 0;
NetFS::DirectoryContents list;
@@ -53,7 +49,8 @@ DirectoryServer::listdir(const Ice::Current&)
throw NetFS::SystemError(errno);
// LCOV_EXCL_STOP
}
- struct stat s {};
+ struct stat s {
+ };
if (::fstatat(fd, d->d_name, &s, AT_SYMLINK_NOFOLLOW) != 0) {
// LCOV_EXCL_START
throw NetFS::SystemError(errno);
@@ -63,4 +60,3 @@ DirectoryServer::listdir(const Ice::Current&)
}
return list;
}
-
diff --git a/netfs/daemon/daemonDirectory.h b/netfs/daemon/daemonDirectory.h
index e74f5dc..83a827a 100644
--- a/netfs/daemon/daemonDirectory.h
+++ b/netfs/daemon/daemonDirectory.h
@@ -6,18 +6,15 @@
#include <typeConverter.h>
class DirectoryServer : public NetFS::Directory, EntryTypeConverter {
- public:
- DirectoryServer(DIR * od, EntryTypeConverter &);
+public:
+ DirectoryServer(DIR * od, EntryTypeConverter &);
- void close(const Ice::Current&) override;
- NetFS::NameList readdir(const Ice::Current&) override;
- NetFS::DirectoryContents listdir(const Ice::Current&) override;
+ void close(const Ice::Current &) override;
+ NetFS::NameList readdir(const Ice::Current &) override;
+ NetFS::DirectoryContents listdir(const Ice::Current &) override;
- private:
- DIR * od;
+private:
+ DIR * od;
};
#endif
-
-
-
diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp
index ec96bc3..56adcc5 100644
--- a/netfs/daemon/daemonFile.cpp
+++ b/netfs/daemon/daemonFile.cpp
@@ -1,21 +1,17 @@
+#include "daemonFile.h"
#include <Ice/ObjectAdapter.h>
#include <cerrno>
-#include <map>
+#include <entCache.h>
#include <fcntl.h>
-#include <typeConverter.h>
+#include <map>
#include <sys/stat.h>
-#include "daemonFile.h"
-#include <entCache.h>
+#include <typeConverter.h>
#include <unistd.h>
-FileServer::FileServer(int f, EntryTypeConverter & t) :
- EntryTypeConverter(t),
- fd(f)
-{
-}
+FileServer::FileServer(int f, EntryTypeConverter & t) : EntryTypeConverter(t), fd(f) { }
void
-FileServer::ftruncate(const NetFS::ReqEnv re, Ice::Long size, const Ice::Current&)
+FileServer::ftruncate(const NetFS::ReqEnv re, Ice::Long size, const Ice::Current &)
{
(void)re;
errno = 0;
@@ -28,7 +24,8 @@ NetFS::Attr
FileServer::fgetattr(const NetFS::ReqEnv re, const Ice::Current &)
{
(void)re;
- struct stat s {};
+ struct stat s {
+ };
if (::fstat(fd, &s) != 0) {
throw NetFS::SystemError(errno);
}
@@ -46,7 +43,7 @@ FileServer::close(const Ice::Current & ice)
}
NetFS::Buffer
-FileServer::read(Ice::Long offset, Ice::Long size, const Ice::Current&)
+FileServer::read(Ice::Long offset, Ice::Long size, const Ice::Current &)
{
NetFS::Buffer buf;
buf.resize(size);
@@ -62,7 +59,7 @@ FileServer::read(Ice::Long offset, Ice::Long size, const Ice::Current&)
}
void
-FileServer::write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, const Ice::Current&)
+FileServer::write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, const Ice::Current &)
{
errno = 0;
if (pwrite(fd, &data.front(), size, offset) != size) {
@@ -71,14 +68,13 @@ FileServer::write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, co
}
Ice::Long
-FileServer::copyrange(NetFS::FilePrxPtr to, Ice::Long offsrc, Ice::Long offdst, Ice::Long size, Ice::Int flags, const Ice::Current& ice)
+FileServer::copyrange(NetFS::FilePrxPtr to, Ice::Long offsrc, Ice::Long offdst, Ice::Long size, Ice::Int flags,
+ const Ice::Current & ice)
{
- if (auto obj = ice.adapter->findByProxy(to);
- auto file = std::dynamic_pointer_cast<FileServer>(obj)) {
+ if (auto obj = ice.adapter->findByProxy(to); auto file = std::dynamic_pointer_cast<FileServer>(obj)) {
errno = 0;
off_t src = offsrc, dst = offdst;
- if (auto rtn = copy_file_range(fd, &src, file->fd, &dst, size, flags);
- rtn != -1) {
+ if (auto rtn = copy_file_range(fd, &src, file->fd, &dst, size, flags); rtn != -1) {
return rtn;
}
throw NetFS::SystemError(errno);
@@ -88,4 +84,3 @@ FileServer::copyrange(NetFS::FilePrxPtr to, Ice::Long offsrc, Ice::Long offdst,
return size;
}
}
-
diff --git a/netfs/daemon/daemonFile.h b/netfs/daemon/daemonFile.h
index 7c4c121..e5b7475 100644
--- a/netfs/daemon/daemonFile.h
+++ b/netfs/daemon/daemonFile.h
@@ -5,21 +5,19 @@
#include <typeConverter.h>
class FileServer : public NetFS::File, EntryTypeConverter {
- public:
- FileServer(int fd, EntryTypeConverter &);
+public:
+ FileServer(int fd, EntryTypeConverter &);
- void close(const Ice::Current&) override;
- void ftruncate(const NetFS::ReqEnv, Ice::Long size, const Ice::Current&) override;
- NetFS::Attr fgetattr(const NetFS::ReqEnv, const Ice::Current&) override;
+ void close(const Ice::Current &) override;
+ void ftruncate(const NetFS::ReqEnv, Ice::Long size, const Ice::Current &) override;
+ NetFS::Attr fgetattr(const NetFS::ReqEnv, const Ice::Current &) override;
- NetFS::Buffer read(Ice::Long offset, Ice::Long size, const Ice::Current&) override;
- void write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, const Ice::Current&) override;
- Ice::Long copyrange(NetFS::FilePrxPtr, Ice::Long, Ice::Long, Ice::Long, Ice::Int, const Ice::Current&) override;
+ NetFS::Buffer read(Ice::Long offset, Ice::Long size, const Ice::Current &) override;
+ void write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, const Ice::Current &) override;
+ Ice::Long copyrange(NetFS::FilePrxPtr, Ice::Long, Ice::Long, Ice::Long, Ice::Int, const Ice::Current &) override;
- private:
- const int fd;
+private:
+ const int fd;
};
#endif
-
-
diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp
index fd5a0fd..18b050d 100644
--- a/netfs/daemon/daemonService.cpp
+++ b/netfs/daemon/daemonService.cpp
@@ -1,12 +1,9 @@
-#include "daemon.h"
#include "daemonService.h"
+#include "daemon.h"
#include "daemonVolume.h"
#include <safeMapFind.h>
-ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) :
- config(std::move(c))
-{
-}
+ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) : config(std::move(c)) { }
NetFS::VolumePrxPtr
ServiceServer::connect(const std::string share, const std::string authtoken, const Ice::Current & ice)
@@ -16,6 +13,5 @@ ServiceServer::connect(const std::string share, const std::string authtoken, con
throw NetFS::AuthError();
}
return Ice::uncheckedCast<NetFS::VolumePrx>(ice.adapter->addFacetWithUUID(
- std::make_shared<VolumeServer>(ex->RootPath, userLookup, groupLookup), "v01"));
+ std::make_shared<VolumeServer>(ex->RootPath, userLookup, groupLookup), "v01"));
}
-
diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h
index 64ae45c..e0f80ef 100644
--- a/netfs/daemon/daemonService.h
+++ b/netfs/daemon/daemonService.h
@@ -1,23 +1,21 @@
#ifndef DAEMONSERVICE_H
#define DAEMONSERVICE_H
-#include <service.h>
-#include <entCache.h>
#include <daemonConfig.h>
#include <entCache.h>
+#include <service.h>
class ServiceServer : public NetFS::Service {
- public:
- explicit ServiceServer(NetFS::Daemon::ConfigurationPtr c);
+public:
+ explicit ServiceServer(NetFS::Daemon::ConfigurationPtr c);
- NetFS::VolumePrxPtr connect(const std::string share, const std::string auth, const Ice::Current&) override;
+ NetFS::VolumePrxPtr connect(const std::string share, const std::string auth, const Ice::Current &) override;
- private:
- EntCache<User> userLookup;
- EntCache<Group> groupLookup;
+private:
+ EntCache<User> userLookup;
+ EntCache<Group> groupLookup;
- NetFS::Daemon::ConfigurationPtr config;
+ NetFS::Daemon::ConfigurationPtr config;
};
#endif
-
diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp
index 096d748..3ae43da 100644
--- a/netfs/daemon/daemonVolume.cpp
+++ b/netfs/daemon/daemonVolume.cpp
@@ -1,25 +1,22 @@
-#include <Ice/ObjectAdapter.h>
-#include <cerrno>
-#include <map>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <climits>
-#include <fcntl.h>
#include "daemonVolume.h"
-#include "daemonFile.h"
+#include "daemon.h"
#include "daemonDirectory.h"
+#include "daemonFile.h"
#include "modeCheck.h"
+#include <Ice/ObjectAdapter.h>
#include <boost/algorithm/string/predicate.hpp>
+#include <cerrno>
+#include <climits>
#include <entCache.h>
-#include "daemon.h"
+#include <fcntl.h>
+#include <map>
+#include <sys/stat.h>
+#include <unistd.h>
extern std::map<Ice::Int, int> files;
VolumeServer::VolumeServer(const std::filesystem::path & r, const EntCache<User> & u, const EntCache<Group> & g) :
- root(std::filesystem::canonical(r)),
- userLookup(u),
- groupLookup(g),
- converter(u, g)
+ root(std::filesystem::canonical(r)), userLookup(u), groupLookup(g), converter(u, g)
{
}
@@ -33,7 +30,8 @@ Ice::Int
VolumeServer::access(const NetFS::ReqEnv re, std::string path, Ice::Int mode, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
- struct stat s {};
+ struct stat s {
+ };
std::filesystem::path p(resolvePath(std::move(path)));
if (::stat(p.c_str(), &s) != 0) {
return errno;
@@ -59,7 +57,8 @@ NetFS::Attr
VolumeServer::getattr(const NetFS::ReqEnv re, std::string path, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
- struct stat s {};
+ struct stat s {
+ };
std::filesystem::path p(resolvePath(std::move(path)));
mc.AssertReadParent(p);
if (::lstat(p.c_str(), &s) != 0) {
@@ -69,7 +68,7 @@ VolumeServer::getattr(const NetFS::ReqEnv re, std::string path, const Ice::Curre
}
void
-VolumeServer::mknod(const NetFS::ReqEnv re, std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current&)
+VolumeServer::mknod(const NetFS::ReqEnv re, std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
@@ -113,7 +112,8 @@ VolumeServer::link(const NetFS::ReqEnv re, std::string path1, std::string path2,
}
void
-VolumeServer::rename(const NetFS::ReqEnv re, std::string from, std::string to, const Ice::optional<Ice::Int> flags, const Ice::Current &)
+VolumeServer::rename(const NetFS::ReqEnv re, std::string from, std::string to, const Ice::optional<Ice::Int> flags,
+ const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
@@ -170,12 +170,12 @@ VolumeServer::chown(const NetFS::ReqEnv re, std::string path, Ice::Int uid, Ice:
}
void
-VolumeServer::utimens(const NetFS::ReqEnv re, std::string path,
- Ice::Long s0, Ice::Long ns0, Ice::Long s1, Ice::Long ns1, const Ice::Current&)
+VolumeServer::utimens(const NetFS::ReqEnv re, std::string path, Ice::Long s0, Ice::Long ns0, Ice::Long s1,
+ Ice::Long ns1, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
- std::array<struct timespec, 2> times { { { s0, ns0 }, { s1, ns1 } } };
+ std::array<struct timespec, 2> times {{{s0, ns0}, {s1, ns1}}};
std::filesystem::path p(resolvePath(std::move(path)));
mc.AssertWrite(p);
if (::utimensat(0, p.c_str(), times.data(), AT_SYMLINK_NOFOLLOW) != 0) {
@@ -184,11 +184,12 @@ VolumeServer::utimens(const NetFS::ReqEnv re, std::string path,
}
NetFS::VFS
-VolumeServer::statfs(const NetFS::ReqEnv re, std::string path, const Ice::Current&)
+VolumeServer::statfs(const NetFS::ReqEnv re, std::string path, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
- struct statvfs s {};
+ struct statvfs s {
+ };
std::filesystem::path p(resolvePath(std::move(path)));
mc.AssertRead(p);
if (::statvfs(p.c_str(), &s) != 0) {
@@ -198,7 +199,7 @@ VolumeServer::statfs(const NetFS::ReqEnv re, std::string path, const Ice::Curren
}
void
-VolumeServer::truncate(const NetFS::ReqEnv re, std::string path, Ice::Long size, const Ice::Current&)
+VolumeServer::truncate(const NetFS::ReqEnv re, std::string path, Ice::Long size, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
@@ -210,7 +211,7 @@ VolumeServer::truncate(const NetFS::ReqEnv re, std::string path, Ice::Long size,
}
void
-VolumeServer::unlink(const NetFS::ReqEnv re, std::string path, const Ice::Current&)
+VolumeServer::unlink(const NetFS::ReqEnv re, std::string path, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
@@ -235,8 +236,8 @@ VolumeServer::open(const NetFS::ReqEnv re, std::string path, Ice::Int flags, con
if (fd == -1) {
throw NetFS::SystemError(errno);
}
- return Ice::uncheckedCast<NetFS::FilePrx>(ice.adapter->addFacetWithUUID(
- std::make_shared<FileServer>(fd, converter), "v01"));
+ return Ice::uncheckedCast<NetFS::FilePrx>(
+ ice.adapter->addFacetWithUUID(std::make_shared<FileServer>(fd, converter), "v01"));
}
NetFS::FilePrxPtr
@@ -255,8 +256,8 @@ VolumeServer::create(const NetFS::ReqEnv re, std::string path, Ice::Int flags, I
::unlink(p.c_str());
throw NetFS::SystemError(errno);
}
- return Ice::uncheckedCast<NetFS::FilePrx>(ice.adapter->addFacetWithUUID(
- std::make_shared<FileServer>(fd, converter), "v01"));
+ return Ice::uncheckedCast<NetFS::FilePrx>(
+ ice.adapter->addFacetWithUUID(std::make_shared<FileServer>(fd, converter), "v01"));
}
NetFS::DirectoryPrxPtr
@@ -270,12 +271,12 @@ VolumeServer::opendir(const NetFS::ReqEnv re, std::string path, const Ice::Curre
if (!od) {
throw NetFS::SystemError(errno);
}
- return Ice::uncheckedCast<NetFS::DirectoryPrx>(ice.adapter->addWithUUID(
- std::make_shared<DirectoryServer>(od, converter)));
+ return Ice::uncheckedCast<NetFS::DirectoryPrx>(
+ ice.adapter->addWithUUID(std::make_shared<DirectoryServer>(od, converter)));
}
void
-VolumeServer::mkdir(const NetFS::ReqEnv re, std::string path, Ice::Int mode, const Ice::Current&)
+VolumeServer::mkdir(const NetFS::ReqEnv re, std::string path, Ice::Int mode, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
@@ -291,7 +292,7 @@ VolumeServer::mkdir(const NetFS::ReqEnv re, std::string path, Ice::Int mode, con
}
void
-VolumeServer::rmdir(const NetFS::ReqEnv re, std::string path, const Ice::Current&)
+VolumeServer::rmdir(const NetFS::ReqEnv re, std::string path, const Ice::Current &)
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
@@ -306,7 +307,7 @@ std::filesystem::path
normalizedAppend(std::filesystem::path out, const std::filesystem::path && in)
{
unsigned int depth = 0;
- for(const auto & e : in) {
+ for (const auto & e : in) {
if (e.empty() || e == "." || e == "/") {
continue;
}
@@ -330,4 +331,3 @@ VolumeServer::resolvePath(std::string && path) const
{
return normalizedAppend(root, std::move(path));
}
-
diff --git a/netfs/daemon/daemonVolume.h b/netfs/daemon/daemonVolume.h
index 0f91f67..b75c5d6 100644
--- a/netfs/daemon/daemonVolume.h
+++ b/netfs/daemon/daemonVolume.h
@@ -1,53 +1,55 @@
#ifndef DAEMONVOLUME_H
#define DAEMONVOLUME_H
-#include <volume.h>
-#include <shared_mutex>
-#include <filesystem>
#include <entCache.h>
+#include <filesystem>
+#include <shared_mutex>
#include <typeConverter.h>
+#include <volume.h>
class VolumeServer : public NetFS::Volume {
- public:
- VolumeServer(const std::filesystem::path & root, const EntCache<User> &, const EntCache<Group> &);
+public:
+ VolumeServer(const std::filesystem::path & root, const EntCache<User> &, const EntCache<Group> &);
- NetFS::DirectoryPrxPtr opendir(const NetFS::ReqEnv, std::string path, const Ice::Current&) override;
+ NetFS::DirectoryPrxPtr opendir(const NetFS::ReqEnv, std::string path, const Ice::Current &) override;
- void mkdir(const NetFS::ReqEnv, std::string path, Ice::Int id, const Ice::Current&) override;
- void rmdir(const NetFS::ReqEnv, std::string path, const Ice::Current&) override;
+ void mkdir(const NetFS::ReqEnv, std::string path, Ice::Int id, const Ice::Current &) override;
+ void rmdir(const NetFS::ReqEnv, std::string path, const Ice::Current &) override;
- void truncate(const NetFS::ReqEnv, std::string path, Ice::Long size, const Ice::Current&) override;
+ void truncate(const NetFS::ReqEnv, std::string path, Ice::Long size, const Ice::Current &) override;
- void unlink(const NetFS::ReqEnv, std::string path, const Ice::Current&) override;
+ void unlink(const NetFS::ReqEnv, std::string path, const Ice::Current &) override;
- NetFS::FilePrxPtr open(const NetFS::ReqEnv, std::string path, Ice::Int flags, const Ice::Current&) override;
- NetFS::FilePrxPtr create(const NetFS::ReqEnv, std::string path, Ice::Int flags, Ice::Int mode, const Ice::Current&) override;
+ NetFS::FilePrxPtr open(const NetFS::ReqEnv, std::string path, Ice::Int flags, const Ice::Current &) override;
+ NetFS::FilePrxPtr create(
+ const NetFS::ReqEnv, std::string path, Ice::Int flags, Ice::Int mode, const Ice::Current &) override;
- NetFS::VFS statfs(const NetFS::ReqEnv, std::string path, const Ice::Current&) override;
+ NetFS::VFS statfs(const NetFS::ReqEnv, std::string path, const Ice::Current &) override;
- Ice::Int access(const NetFS::ReqEnv, std::string path, Ice::Int mode, const Ice::Current&) override;
- NetFS::Attr getattr(const NetFS::ReqEnv, std::string path, const Ice::Current&) override;
- void mknod(const NetFS::ReqEnv, std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current&) override;
- void symlink(const NetFS::ReqEnv, const std::string path1, const std::string path2, const Ice::Current&) override;
- void link(const NetFS::ReqEnv, std::string path1, std::string path2, const Ice::Current&) override;
- void rename(const NetFS::ReqEnv, std::string path1, const std::string path2, const Ice::optional<Ice::Int>, const Ice::Current&) override;
- std::string readlink(const NetFS::ReqEnv, std::string path, const Ice::Current&) override;
- void chmod(const NetFS::ReqEnv, std::string path, Ice::Int mode, const Ice::Current&) override;
- void chown(const NetFS::ReqEnv, std::string path, Ice::Int uid, Ice::Int gid, const Ice::Current&) override;
- void utimens(const NetFS::ReqEnv, std::string path, Ice::Long, Ice::Long, Ice::Long, Ice::Long, const Ice::Current&) override;
+ Ice::Int access(const NetFS::ReqEnv, std::string path, Ice::Int mode, const Ice::Current &) override;
+ NetFS::Attr getattr(const NetFS::ReqEnv, std::string path, const Ice::Current &) override;
+ void mknod(const NetFS::ReqEnv, std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current &) override;
+ void symlink(const NetFS::ReqEnv, const std::string path1, const std::string path2, const Ice::Current &) override;
+ void link(const NetFS::ReqEnv, std::string path1, std::string path2, const Ice::Current &) override;
+ void rename(const NetFS::ReqEnv, std::string path1, const std::string path2, const Ice::optional<Ice::Int>,
+ const Ice::Current &) override;
+ std::string readlink(const NetFS::ReqEnv, std::string path, const Ice::Current &) override;
+ void chmod(const NetFS::ReqEnv, std::string path, Ice::Int mode, const Ice::Current &) override;
+ void chown(const NetFS::ReqEnv, std::string path, Ice::Int uid, Ice::Int gid, const Ice::Current &) override;
+ void utimens(const NetFS::ReqEnv, std::string path, Ice::Long, Ice::Long, Ice::Long, Ice::Long,
+ const Ice::Current &) override;
- void disconnect(const Ice::Current&) override;
+ void disconnect(const Ice::Current &) override;
- protected:
- inline std::filesystem::path resolvePath(std::string && path) const;
+protected:
+ inline std::filesystem::path resolvePath(std::string && path) const;
- private:
- const std::filesystem::path root;
+private:
+ const std::filesystem::path root;
- const EntCache<User> & userLookup;
- const EntCache<Group> & groupLookup;
- EntryTypeConverter converter;
+ const EntCache<User> & userLookup;
+ const EntCache<Group> & groupLookup;
+ EntryTypeConverter converter;
};
#endif
-
diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp
index 58ade75..6e65888 100644
--- a/netfs/daemon/modeCheck.cpp
+++ b/netfs/daemon/modeCheck.cpp
@@ -2,12 +2,10 @@
#include <entCache.h>
#include <exceptions.h>
-ModeCheck::ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path & r, const EntCache<User> & u, const EntCache<Group> & g) :
+ModeCheck::ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path & r, const EntCache<User> & u,
+ const EntCache<Group> & g) :
myu(u.getEntry(re.user)->id),
- myg(g.getEntry(re.grp)->id),
- root(r),
- userLookup(u),
- groupLookup(g)
+ myg(g.getEntry(re.grp)->id), root(r), userLookup(u), groupLookup(g)
{
}
@@ -64,10 +62,11 @@ ModeCheck::AssertWritePerms(const std::filesystem::path & p) const
}
}
- struct stat
+struct stat
ModeCheck::lstat(const std::filesystem::path & p)
{
- struct stat s {};
+ struct stat s {
+ };
if (::lstat(p.c_str(), &s) != 0) {
throw NetFS::SystemError(errno);
}
@@ -86,11 +85,9 @@ ModeCheck::ReadableBy(const struct stat & s, uid_t u, gid_t g) const
if (s.st_mode & S_IRUSR && s.st_uid == u) {
return true;
}
- if (s.st_mode & S_IRGRP &&
- (s.st_gid == g
- || userLookup.getEntry(u)->group == s.st_gid
- || groupLookup.getEntry(s.st_gid)->hasMember(u)))
- {
+ if (s.st_mode & S_IRGRP
+ && (s.st_gid == g || userLookup.getEntry(u)->group == s.st_gid
+ || groupLookup.getEntry(s.st_gid)->hasMember(u))) {
return true;
}
return false;
@@ -108,10 +105,9 @@ ModeCheck::WritableBy(const struct stat & s, uid_t u, gid_t g) const
if (s.st_mode & S_IWUSR && s.st_uid == u) {
return true;
}
- if (s.st_mode & S_IWGRP &&
- (s.st_gid == g
- || userLookup.getEntry(u)->group == s.st_gid
- || groupLookup.getEntry(s.st_gid)->hasMember(u))) {
+ if (s.st_mode & S_IWGRP
+ && (s.st_gid == g || userLookup.getEntry(u)->group == s.st_gid
+ || groupLookup.getEntry(s.st_gid)->hasMember(u))) {
return true;
}
return false;
@@ -129,12 +125,10 @@ ModeCheck::ExecutableBy(const struct stat & s, uid_t u, gid_t g) const
if (s.st_mode & S_IXUSR && s.st_uid == u) {
return true;
}
- if (s.st_mode & S_IXGRP &&
- (s.st_gid == g
- || userLookup.getEntry(u)->group == s.st_gid
- || groupLookup.getEntry(s.st_gid)->hasMember(u))) {
+ if (s.st_mode & S_IXGRP
+ && (s.st_gid == g || userLookup.getEntry(u)->group == s.st_gid
+ || groupLookup.getEntry(s.st_gid)->hasMember(u))) {
return true;
}
return false;
}
-
diff --git a/netfs/daemon/modeCheck.h b/netfs/daemon/modeCheck.h
index 01e9ecb..693ad8d 100644
--- a/netfs/daemon/modeCheck.h
+++ b/netfs/daemon/modeCheck.h
@@ -1,35 +1,34 @@
#ifndef NETFS_DAEMON_IOHELPERS
#define NETFS_DAEMON_IOHELPERS
+#include <entCache.h>
+#include <filesystem>
#include <sys/stat.h>
#include <types.h>
-#include <filesystem>
-#include <entCache.h>
class ModeCheck {
- public:
- ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path &, const EntCache<User> &, const EntCache<Group> &);
+public:
+ ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path &, const EntCache<User> &, const EntCache<Group> &);
- void AssertReadParent(const std::filesystem::path &) const;
- void AssertRead(const std::filesystem::path &) const;
- void AssertWriteParent(const std::filesystem::path &) const;
- void AssertWrite(const std::filesystem::path &) const;
- void AssertWritePerms(const std::filesystem::path &) const;
+ void AssertReadParent(const std::filesystem::path &) const;
+ void AssertRead(const std::filesystem::path &) const;
+ void AssertWriteParent(const std::filesystem::path &) const;
+ void AssertWrite(const std::filesystem::path &) const;
+ void AssertWritePerms(const std::filesystem::path &) const;
- const uid_t myu;
- const gid_t myg;
- const std::filesystem::path & root;
+ const uid_t myu;
+ const gid_t myg;
+ const std::filesystem::path & root;
- [[nodiscard]] bool ReadableBy(const struct stat &, uid_t u, gid_t g) const;
- [[nodiscard]] bool WritableBy(const struct stat &, uid_t u, gid_t g) const;
- [[nodiscard]] bool ExecutableBy(const struct stat &, uid_t u, gid_t g) const;
+ [[nodiscard]] bool ReadableBy(const struct stat &, uid_t u, gid_t g) const;
+ [[nodiscard]] bool WritableBy(const struct stat &, uid_t u, gid_t g) const;
+ [[nodiscard]] bool ExecutableBy(const struct stat &, uid_t u, gid_t g) const;
- private:
- static struct stat lstat(const std::filesystem::path &);
+private:
+ static struct stat lstat(const std::filesystem::path &);
- const EntCache<User> & userLookup;
- const EntCache<Group> & groupLookup;
+ const EntCache<User> & userLookup;
+ const EntCache<Group> & groupLookup;
};
#endif
-
diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp
index 29820b8..78a3a03 100644
--- a/netfs/fuse/fuseApp.cpp
+++ b/netfs/fuse/fuseApp.cpp
@@ -1,16 +1,16 @@
-#include <Glacier2/Router.h>
-#include <cstring>
#include "fuseApp.h"
-#include "lockHelpers.h"
#include "cache.impl.h"
-#include <entCache.h>
-#include <slicer/slicer.h>
-#include <uriParse.h>
-#include <safeMapFind.h>
-#include <compileTimeFormatter.h>
#include "fuseDirs.h"
#include "fuseFiles.h"
+#include "lockHelpers.h"
+#include <Glacier2/Router.h>
#include <boost/lexical_cast.hpp>
+#include <compileTimeFormatter.h>
+#include <cstring>
+#include <entCache.h>
+#include <safeMapFind.h>
+#include <slicer/slicer.h>
+#include <uriParse.h>
namespace AdHoc {
template class Cache<struct stat, std::string>;
@@ -18,10 +18,7 @@ namespace AdHoc {
}
NetFS::FuseApp::FuseApp(Ice::StringSeq && a) :
- iceArgs(std::move(a)),
- sessionOpened(false),
- openHandleId(0),
- converter(userLookup, groupLookup)
+ iceArgs(std::move(a)), sessionOpened(false), openHandleId(0), converter(userLookup, groupLookup)
{
}
@@ -283,4 +280,3 @@ NetFS::FuseApp::reqEnv()
groupLookup.getName(c->gid, &re.grp);
return re;
}
-
diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h
index 6869c01..d373e94 100644
--- a/netfs/fuse/fuseApp.h
+++ b/netfs/fuse/fuseApp.h
@@ -1,124 +1,122 @@
#ifndef NETFS_FUSE_H
#define NETFS_FUSE_H
-#include <shared_mutex>
-#include <functional>
-#include <filesystem>
-#include <Ice/Ice.h>
+#include "cache.h"
+#include "fuseAppBase.h"
+#include "fuseConfig.h"
#include <Glacier2/Session.h>
-#include <service.h>
+#include <Ice/Ice.h>
+#include <c++11Helpers.h>
#include <entCache.h>
+#include <filesystem>
+#include <functional>
+#include <service.h>
+#include <shared_mutex>
#include <typeConverter.h>
-#include "fuseAppBase.h"
-#include "fuseConfig.h"
-#include "cache.h"
#include <visibility.h>
-#include <c++11Helpers.h>
namespace NetFS {
class DLL_PUBLIC FuseApp : public FuseAppBaseT<FuseApp> {
- private:
- class OpenDir;
- using OpenDirPtr = std::shared_ptr<OpenDir>;
- using OpenDirs = std::map<int, OpenDirPtr>;
-
- class OpenFile;
- using OpenFilePtr = std::shared_ptr<OpenFile>;
- using OpenFiles = std::map<int, OpenFilePtr>;
-
- public:
- explicit FuseApp(Ice::StringSeq &&);
- SPECIAL_MEMBERS_DELETE(FuseApp);
- ~FuseApp() override;
-
- // lifecycle
- void * init (struct fuse_conn_info * info, struct fuse_config * cfg) override;
- static int opt_parse(void * data, const char * arg, int, struct fuse_args *);
-
- protected:
- void connectSession();
- virtual void connectToService();
- void connectToVolume();
- void connectHandles();
- void verifyConnection();
-
- 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;
- // 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, enum fuse_readdir_flags) override;
- int mkdir(const char *, mode_t) override;
- int rmdir(const char *) 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;
- // fs
- int statfs(const char *, struct statvfs *) override;
- // stuff
- int onError(const std::exception & err) noexcept override;
- void beforeOperation() override;
-
- virtual struct fuse_context * fuse_get_context() = 0;
-
- static NetFS::Client::ResourcePtr configureFromFile(const std::filesystem::path &, const std::string &);
- static NetFS::Client::ResourcePtr configureFromUri(const std::string &);
-
- protected:
- template<typename Handle, typename ... Params>
- void setProxy(uint64_t & fh, const Params & ...);
- template<typename Handle>
- Handle getProxy(uint64_t localID);
- template<typename Handle>
- void clearProxy(uint64_t localID);
- template<typename Handle>
- std::map<int, Handle> & getMap();
-
- template<typename Rtn, typename F> static inline Rtn
- waitOnWriteRangeAndThen(size_t s, off_t o, const OpenFilePtr & of, const F & f);
-
- ReqEnv reqEnv();
-
- Ice::StringSeq iceArgs;
- Ice::CommunicatorPtr ic;
- Client::ResourcePtr fcr;
- mutable std::shared_mutex _proxymaplock;
-
- NetFS::VolumePrxPtr volume;
- NetFS::ServicePrxPtr service;
- Glacier2::SessionPrxPtr session;
- bool sessionOpened;
-
- std::string mountPoint;
-
- OpenDirs openDirs;
- OpenFiles openFiles;
- int openHandleId;
-
- EntCache<User> userLookup;
- EntCache<Group> groupLookup;
- EntryTypeConverter converter;
-
- using StatCache = AdHoc::Cache<struct stat, std::string>;
- StatCache statCache;
+ private:
+ class OpenDir;
+ using OpenDirPtr = std::shared_ptr<OpenDir>;
+ using OpenDirs = std::map<int, OpenDirPtr>;
+
+ class OpenFile;
+ using OpenFilePtr = std::shared_ptr<OpenFile>;
+ using OpenFiles = std::map<int, OpenFilePtr>;
+
+ public:
+ explicit FuseApp(Ice::StringSeq &&);
+ SPECIAL_MEMBERS_DELETE(FuseApp);
+ ~FuseApp() override;
+
+ // lifecycle
+ void * init(struct fuse_conn_info * info, struct fuse_config * cfg) override;
+ static int opt_parse(void * data, const char * arg, int, struct fuse_args *);
+
+ protected:
+ void connectSession();
+ virtual void connectToService();
+ void connectToVolume();
+ void connectHandles();
+ void verifyConnection();
+
+ 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;
+ // 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,
+ enum fuse_readdir_flags) override;
+ int mkdir(const char *, mode_t) override;
+ int rmdir(const char *) 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;
+ // fs
+ int statfs(const char *, struct statvfs *) override;
+ // stuff
+ int onError(const std::exception & err) noexcept override;
+ void beforeOperation() override;
+
+ virtual struct fuse_context * fuse_get_context() = 0;
+
+ static NetFS::Client::ResourcePtr configureFromFile(const std::filesystem::path &, const std::string &);
+ static NetFS::Client::ResourcePtr configureFromUri(const std::string &);
+
+ protected:
+ template<typename Handle, typename... Params> void setProxy(uint64_t & fh, const Params &...);
+ template<typename Handle> Handle getProxy(uint64_t localID);
+ template<typename Handle> void clearProxy(uint64_t localID);
+ template<typename Handle> std::map<int, Handle> & getMap();
+
+ template<typename Rtn, typename F>
+ static inline Rtn waitOnWriteRangeAndThen(size_t s, off_t o, const OpenFilePtr & of, const F & f);
+
+ ReqEnv reqEnv();
+
+ Ice::StringSeq iceArgs;
+ Ice::CommunicatorPtr ic;
+ Client::ResourcePtr fcr;
+ mutable std::shared_mutex _proxymaplock;
+
+ NetFS::VolumePrxPtr volume;
+ NetFS::ServicePrxPtr service;
+ Glacier2::SessionPrxPtr session;
+ bool sessionOpened;
+
+ std::string mountPoint;
+
+ OpenDirs openDirs;
+ OpenFiles openFiles;
+ int openHandleId;
+
+ EntCache<User> userLookup;
+ EntCache<Group> groupLookup;
+ EntryTypeConverter converter;
+
+ using StatCache = AdHoc::Cache<struct stat, std::string>;
+ StatCache statCache;
};
}
diff --git a/netfs/fuse/fuseApp.impl.h b/netfs/fuse/fuseApp.impl.h
index 8dd9f1e..e433ee7 100644
--- a/netfs/fuse/fuseApp.impl.h
+++ b/netfs/fuse/fuseApp.impl.h
@@ -6,13 +6,14 @@
#include <safeMapFind.h>
namespace NetFS {
- template<typename Handle, typename ... Params>
+ template<typename Handle, typename... Params>
void
- FuseApp::setProxy(uint64_t & fh, const Params & ... params)
+ FuseApp::setProxy(uint64_t & fh, const Params &... params)
{
auto & map = getMap<Handle>();
Lock(_proxymaplock);
- while (map.find(fh = ++openHandleId) != map.end()) ;
+ while (map.find(fh = ++openHandleId) != map.end())
+ ;
map.emplace(fh, std::make_shared<typename Handle::element_type>(params...));
}
@@ -40,4 +41,3 @@ namespace NetFS {
}
#endif
-
diff --git a/netfs/fuse/fuseAppBase.cpp b/netfs/fuse/fuseAppBase.cpp
index 4d06b44..f2c1f30 100644
--- a/netfs/fuse/fuseAppBase.cpp
+++ b/netfs/fuse/fuseAppBase.cpp
@@ -1,11 +1,11 @@
#include "fuseAppBase.h"
-#include <cerrno>
+#include <boost/assert.hpp>
#include <cassert>
+#include <cerrno>
#include <cstdio>
-#include <unistd.h>
#include <cstdlib>
#include <typeinfo>
-#include <boost/assert.hpp>
+#include <unistd.h>
FuseAppBase * FuseAppBase::fuseApp;
@@ -27,177 +27,221 @@ FuseAppBase::~FuseAppBase()
// to call them in a realistic manner. They exist only as the default
// implementation of the function which is never passed to libfuse
// unless it is overridden.
-void * FuseAppBase::init(fuse_conn_info*, fuse_config *)
+void *
+FuseAppBase::init(fuse_conn_info *, fuse_config *)
{
return nullptr;
}
-int FuseAppBase::access(const char *, int)
+int
+FuseAppBase::access(const char *, int)
{
return -ENOSYS;
}
-int FuseAppBase::chmod(const char *, mode_t, struct fuse_file_info *)
+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 *)
+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 *)
+int
+FuseAppBase::create(const char *, mode_t, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::getattr(const char *, struct stat *, struct fuse_file_info *)
+int
+FuseAppBase::getattr(const char *, struct stat *, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::flush(const char *, struct fuse_file_info *)
+int
+FuseAppBase::flush(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::fsync(const char *, int, struct fuse_file_info *)
+int
+FuseAppBase::fsync(const char *, int, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *)
+int
+FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::truncate(const char *, off_t, struct fuse_file_info *)
+int
+FuseAppBase::truncate(const char *, off_t, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::getxattr(const char *, const char *, char *, size_t)
+int
+FuseAppBase::getxattr(const char *, const char *, char *, size_t)
{
return -ENOSYS;
}
-int FuseAppBase::link(const char *, const char *)
+int
+FuseAppBase::link(const char *, const char *)
{
return -ENOSYS;
}
-int FuseAppBase::listxattr(const char *, char *, size_t)
+int
+FuseAppBase::listxattr(const char *, char *, size_t)
{
return -ENOSYS;
}
-int FuseAppBase::mkdir(const char *, mode_t)
+int
+FuseAppBase::mkdir(const char *, mode_t)
{
return -ENOSYS;
}
-int FuseAppBase::mknod(const char *, mode_t, dev_t)
+int
+FuseAppBase::mknod(const char *, mode_t, dev_t)
{
return -ENOSYS;
}
-int FuseAppBase::open(const char *, struct fuse_file_info *)
+int
+FuseAppBase::open(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::opendir(const char *, struct fuse_file_info *)
+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 *)
+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)
+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)
+int
+FuseAppBase::readlink(const char *, char *, size_t)
{
return -ENOSYS;
}
-int FuseAppBase::release(const char *, struct fuse_file_info *)
+int
+FuseAppBase::release(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::releasedir(const char *, struct fuse_file_info *)
+int
+FuseAppBase::releasedir(const char *, struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::removexattr(const char *, const char *)
+int
+FuseAppBase::removexattr(const char *, const char *)
{
return -ENOSYS;
}
-int FuseAppBase::rename(const char *, const char *, unsigned int)
+int
+FuseAppBase::rename(const char *, const char *, unsigned int)
{
return -ENOSYS;
}
-int FuseAppBase::rmdir(const char *)
+int
+FuseAppBase::rmdir(const char *)
{
return -ENOSYS;
}
-int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int)
+int
+FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int)
{
return -ENOSYS;
}
-int FuseAppBase::statfs(const char *, struct statvfs *)
+int
+FuseAppBase::statfs(const char *, struct statvfs *)
{
return -ENOSYS;
}
-int FuseAppBase::symlink(const char *, const char *)
+int
+FuseAppBase::symlink(const char *, const char *)
{
return -ENOSYS;
}
-int FuseAppBase::unlink(const char *)
+int
+FuseAppBase::unlink(const char *)
{
return -ENOSYS;
}
-int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *)
+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 *)
+int
+FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *)
{
return -ENOSYS;
}
// NOLINTNEXTLINE(modernize-avoid-c-arrays, hicpp-avoid-c-arrays)
-int FuseAppBase::utimens(const char *, const struct timespec[2], struct fuse_file_info *)
+int
+FuseAppBase::utimens(const char *, const struct timespec[2], struct fuse_file_info *)
{
return -ENOSYS;
}
-int FuseAppBase::bmap(const char *, size_t, uint64_t *)
+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 *)
+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 *)
+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 *)
+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 *)
+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)
+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 *)
+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)
+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 *)
+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
+void
+FuseAppBase::log(int level, const char * message) const noexcept
{
logf(level, "%s", message);
}
-void FuseAppBase::logf(int level, const char * fmt, ...) const noexcept
+void
+FuseAppBase::logf(int level, const char * fmt, ...) const noexcept
{
va_list args;
va_start(args, fmt);
@@ -205,13 +249,14 @@ void FuseAppBase::logf(int level, const char * fmt, ...) const noexcept
va_end(args);
}
-int FuseAppBase::onError(const std::exception & e) noexcept
+int
+FuseAppBase::onError(const std::exception & e) noexcept
{
logf(LOG_ERR, "Unknown exception (what: %s)", e.what());
return -ENOSYS;
}
-void FuseAppBase::beforeOperation()
+void
+FuseAppBase::beforeOperation()
{
}
-
diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h
index 2709671..44f3c81 100644
--- a/netfs/fuse/fuseAppBase.h
+++ b/netfs/fuse/fuseAppBase.h
@@ -1,82 +1,89 @@
#ifndef FUSEAPP_H
#define FUSEAPP_H
-#include <fuse.h>
-#include <typeinfo>
-#include <exception>
-#include <cstdio>
+#include <c++11Helpers.h>
#include <cerrno>
+#include <cstdio>
+#include <exception>
+#include <fuse.h>
+#include <lockHelpers.h>
+#include <shared_mutex>
#include <syslog.h>
+#include <typeinfo>
#include <visibility.h>
-#include <c++11Helpers.h>
-#include <shared_mutex>
-#include <lockHelpers.h>
class DLL_PUBLIC FuseAppBase {
- public:
- FuseAppBase();
- SPECIAL_MEMBERS_DELETE(FuseAppBase);
- virtual ~FuseAppBase();
+public:
+ FuseAppBase();
+ SPECIAL_MEMBERS_DELETE(FuseAppBase);
+ virtual ~FuseAppBase();
- virtual void * init (struct fuse_conn_info * info, struct fuse_config * cfg);
- virtual int access(const char *, int);
- virtual int chmod(const char *, mode_t, struct fuse_file_info *);
- virtual int chown(const char *, uid_t, gid_t, struct fuse_file_info *);
- virtual int create(const char *, mode_t, struct fuse_file_info *);
- virtual int getattr(const char *, struct stat *, struct fuse_file_info *);
- virtual int flush(const char *, struct fuse_file_info *);
- virtual int fsync(const char *, int, struct fuse_file_info *);
- virtual int fsyncdir(const char *, int, struct fuse_file_info *);
- virtual int truncate(const char *, off_t, struct fuse_file_info *);
- virtual int getxattr(const char *, const char *, char *, size_t);
- virtual int link(const char *, const char *);
- virtual int listxattr(const char *, char *, size_t);
- virtual int mkdir(const char *, mode_t);
- virtual int mknod(const char *, mode_t, dev_t);
- virtual int open(const char *, struct fuse_file_info *);
- virtual int opendir(const char *, struct fuse_file_info *);
- virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *);
- virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *, enum fuse_readdir_flags);
- virtual int readlink(const char *, char *, size_t);
- virtual int release(const char *, struct fuse_file_info *);
- virtual int releasedir(const char *, struct fuse_file_info *);
- virtual int removexattr(const char *, const char *);
- virtual int rename(const char *, const char *, unsigned int);
- virtual int rmdir(const char *);
- virtual int setxattr(const char *, const char *, const char *, size_t, int);
- virtual int statfs(const char *, struct statvfs *);
- virtual int symlink(const char *, const char *);
- 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 *);
- 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 *);
- virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *);
- 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 fallocate(const char *, int, off_t, off_t, struct fuse_file_info *);
- 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 *);
- virtual int onError(const std::exception & err) noexcept;
- virtual void beforeOperation();
- void log(int level, const char * message) const noexcept;
- void logf(int level, const char * fmt, ...) const noexcept __attribute__ ((__format__ (__printf__, 3, 4)));
- virtual void vlogf(int level, const char * fmt, va_list) const noexcept __attribute__ ((__format__ (__printf__, 3, 0))) = 0;
+ virtual void * init(struct fuse_conn_info * info, struct fuse_config * cfg);
+ virtual int access(const char *, int);
+ virtual int chmod(const char *, mode_t, struct fuse_file_info *);
+ virtual int chown(const char *, uid_t, gid_t, struct fuse_file_info *);
+ virtual int create(const char *, mode_t, struct fuse_file_info *);
+ virtual int getattr(const char *, struct stat *, struct fuse_file_info *);
+ virtual int flush(const char *, struct fuse_file_info *);
+ virtual int fsync(const char *, int, struct fuse_file_info *);
+ virtual int fsyncdir(const char *, int, struct fuse_file_info *);
+ virtual int truncate(const char *, off_t, struct fuse_file_info *);
+ virtual int getxattr(const char *, const char *, char *, size_t);
+ virtual int link(const char *, const char *);
+ virtual int listxattr(const char *, char *, size_t);
+ virtual int mkdir(const char *, mode_t);
+ virtual int mknod(const char *, mode_t, dev_t);
+ virtual int open(const char *, struct fuse_file_info *);
+ virtual int opendir(const char *, struct fuse_file_info *);
+ virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *);
+ virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *, enum fuse_readdir_flags);
+ virtual int readlink(const char *, char *, size_t);
+ virtual int release(const char *, struct fuse_file_info *);
+ virtual int releasedir(const char *, struct fuse_file_info *);
+ virtual int removexattr(const char *, const char *);
+ virtual int rename(const char *, const char *, unsigned int);
+ virtual int rmdir(const char *);
+ virtual int setxattr(const char *, const char *, const char *, size_t, int);
+ virtual int statfs(const char *, struct statvfs *);
+ virtual int symlink(const char *, const char *);
+ 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 *);
+ 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 *);
+ virtual int write_buf(const char *, struct fuse_bufvec * buf, off_t off, struct fuse_file_info *);
+ 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 fallocate(const char *, int, off_t, off_t, struct fuse_file_info *);
+ 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 *);
+ virtual int onError(const std::exception & err) noexcept;
+ virtual void beforeOperation();
+ void log(int level, const char * message) const noexcept;
+ void logf(int level, const char * fmt, ...) const noexcept __attribute__((__format__(__printf__, 3, 4)));
+ virtual void vlogf(int level, const char * fmt, va_list) const noexcept
+ __attribute__((__format__(__printf__, 3, 0)))
+ = 0;
- mutable std::shared_mutex _lock;
- protected:
- static FuseAppBase * fuseApp;
+ mutable std::shared_mutex _lock;
+
+protected:
+ static FuseAppBase * fuseApp;
};
-template <typename FuseApp>
-class FuseAppBaseT : public FuseAppBase {
- public:
-#define GetIntHelper(func) getInternalHelper<decltype(&FuseAppBase::func), decltype(&FuseApp::func), &FuseAppBase::func>(&FuseAppBase::func)
-#define GetHelper(func) getHelper<decltype(&FuseAppBase::func), decltype(&FuseApp::func), &FuseAppBase::func>(&FuseAppBase::func)
- FuseAppBaseT() : operations({
+template<typename FuseApp> class FuseAppBaseT : public FuseAppBase {
+public:
+#define GetIntHelper(func) \
+ getInternalHelper<decltype(&FuseAppBase::func), decltype(&FuseApp::func), &FuseAppBase::func>(&FuseAppBase::func)
+#define GetHelper(func) \
+ getHelper<decltype(&FuseAppBase::func), decltype(&FuseApp::func), &FuseAppBase::func>(&FuseAppBase::func)
+ FuseAppBaseT() :
+ operations({
GetHelper(getattr),
GetHelper(readlink),
GetHelper(mknod),
@@ -105,7 +112,7 @@ class FuseAppBaseT : public FuseAppBase {
GetHelper(releasedir),
GetHelper(fsyncdir),
GetIntHelper(init),
- nullptr, //fuseDestroy
+ nullptr, // fuseDestroy
GetHelper(access),
GetHelper(create),
GetHelper(lock),
@@ -119,64 +126,65 @@ class FuseAppBaseT : public FuseAppBase {
GetHelper(fallocate),
GetHelper(copy_file_range),
GetHelper(lseek),
- })
- {
- }
+ })
+ {
+ }
#undef GetHelper
#undef GetIntHelper
- const struct fuse_operations operations;
+ const struct fuse_operations operations;
- private:
- template <typename BFunc, typename IFunc, BFunc bfunc, typename Rtn, typename ... Args>
- constexpr static auto getInternalHelper(Rtn(FuseAppBase::*)(Args...)) -> Rtn(*)(Args...)
- {
- if constexpr (!std::is_same<BFunc, IFunc>::value) {
- return [](Args ... a) {
- return (fuseApp->*bfunc)(a...);
- };
- }
- return nullptr;
+private:
+ template<typename BFunc, typename IFunc, BFunc bfunc, typename Rtn, typename... Args>
+ constexpr static auto getInternalHelper(Rtn (FuseAppBase::*)(Args...)) -> Rtn (*)(Args...)
+ {
+ if constexpr (!std::is_same<BFunc, IFunc>::value) {
+ return [](Args... a) {
+ return (fuseApp->*bfunc)(a...);
+ };
}
- template <typename BFunc, typename IFunc, BFunc bfunc, typename Rtn, typename ... Args>
- constexpr static auto getHelper(Rtn(FuseAppBase::*)(Args...)) -> Rtn(*)(Args...)
- {
- if constexpr (!std::is_same<BFunc, IFunc>::value) {
- return [](Args ... a) -> Rtn {
- for (int t = 0; ; ++t) {
- try {
- fuseApp->beforeOperation();
- SharedLock(fuseApp->_lock);
- return (fuseApp->*bfunc)(a...);
- }
- catch (const std::exception & ex) {
- if (t < 10) {
- if (int rtn = fuseApp->onError(ex)) {
- return rtn;
- }
- }
- else {
- fuseApp->logf(LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(bfunc).name());
- return -EIO;
+ return nullptr;
+ }
+ template<typename BFunc, typename IFunc, BFunc bfunc, typename Rtn, typename... Args>
+ constexpr static auto getHelper(Rtn (FuseAppBase::*)(Args...)) -> Rtn (*)(Args...)
+ {
+ if constexpr (!std::is_same<BFunc, IFunc>::value) {
+ return [](Args... a) -> Rtn {
+ for (int t = 0;; ++t) {
+ try {
+ fuseApp->beforeOperation();
+ SharedLock(fuseApp->_lock);
+ return (fuseApp->*bfunc)(a...);
+ }
+ catch (const std::exception & ex) {
+ if (t < 10) {
+ if (int rtn = fuseApp->onError(ex)) {
+ return rtn;
}
}
- catch (...) {
- fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(bfunc).name());
+ else {
+ fuseApp->logf(
+ LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(bfunc).name());
return -EIO;
}
}
- };
- }
- return nullptr;
+ catch (...) {
+ fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(bfunc).name());
+ return -EIO;
+ }
+ }
+ };
}
+ return nullptr;
+ }
- protected:
- template <typename Func, Func f, typename ... Args>
- static int internalHelper(Args ... a)
- {
- return (fuseApp->*f)(a...);
- }
+protected:
+ template<typename Func, Func f, typename... Args>
+ static int
+ internalHelper(Args... a)
+ {
+ return (fuseApp->*f)(a...);
+ }
};
#endif
-
diff --git a/netfs/fuse/fuseConfigImpl.cpp b/netfs/fuse/fuseConfigImpl.cpp
index 9129bfc..fa542fe 100644
--- a/netfs/fuse/fuseConfigImpl.cpp
+++ b/netfs/fuse/fuseConfigImpl.cpp
@@ -1,5 +1,5 @@
-#include <fuseConfig.h>
#include <compileTimeFormatter.h>
+#include <fuseConfig.h>
AdHocFormatter(ResourceNotFoundMsg, "No such resource: %?");
void
@@ -7,4 +7,3 @@ NetFS::Client::ResourceNotFound::ice_print(std::ostream & s) const
{
ResourceNotFoundMsg::write(s, resourceName);
}
-
diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp
index a1748d8..c1a91bd 100644
--- a/netfs/fuse/fuseDirs.cpp
+++ b/netfs/fuse/fuseDirs.cpp
@@ -1,98 +1,94 @@
#include "fuseDirs.h"
-#include <lockHelpers.h>
#include <entCache.h>
+#include <lockHelpers.h>
namespace NetFS {
-FuseApp::OpenDir::OpenDir(DirectoryPrxPtr r, std::string p) :
- remote(std::move(r)),
- path(std::move(p))
-{
-}
+ FuseApp::OpenDir::OpenDir(DirectoryPrxPtr r, std::string p) : remote(std::move(r)), path(std::move(p)) { }
-template<>
-std::map<int, FuseApp::OpenDirPtr> &
-FuseApp::getMap<FuseApp::OpenDirPtr>()
-{
- return openDirs;
-}
-
-int
-FuseApp::opendir(const char * p, struct fuse_file_info * fi)
-{
- try {
- auto remote = volume->opendir(reqEnv(), p);
- setProxy<OpenDirPtr>(fi->fh, remote, p);
- return 0;
- }
- catch (SystemError & e) {
- return -e.syserrno;
+ template<>
+ std::map<int, FuseApp::OpenDirPtr> &
+ FuseApp::getMap<FuseApp::OpenDirPtr>()
+ {
+ return openDirs;
}
-}
-int
-FuseApp::releasedir(const char *, struct fuse_file_info * fi)
-{
- try {
- auto remote = getProxy<OpenDirPtr>(fi->fh)->remote;
- remote->close();
- clearProxy<OpenDirPtr>(fi->fh);
- return 0;
+ int
+ FuseApp::opendir(const char * p, struct fuse_file_info * fi)
+ {
+ try {
+ auto remote = volume->opendir(reqEnv(), p);
+ setProxy<OpenDirPtr>(fi->fh, remote, p);
+ return 0;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
+ }
}
- catch (SystemError & e) {
- clearProxy<OpenDirPtr>(fi->fh);
- return -e.syserrno;
+
+ int
+ FuseApp::releasedir(const char *, struct fuse_file_info * fi)
+ {
+ try {
+ auto remote = getProxy<OpenDirPtr>(fi->fh)->remote;
+ remote->close();
+ clearProxy<OpenDirPtr>(fi->fh);
+ return 0;
+ }
+ catch (SystemError & e) {
+ clearProxy<OpenDirPtr>(fi->fh);
+ return -e.syserrno;
+ }
}
-}
-int
-FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi, enum fuse_readdir_flags flags)
-{
- try {
- auto od = getProxy<OpenDirPtr>(fi->fh);
- std::string path(p);
- auto expiry = time(nullptr) + 2;
- if (flags == FUSE_READDIR_PLUS) {
- for (const auto & e : od->remote->listdir()) {
- filler(buf, e.first.c_str(), nullptr, 0, FUSE_FILL_DIR_PLUS);
- std::string k(path + e.first);
- statCache.remove(k);
- statCache.add(k, converter.convert(e.second), expiry);
+ int
+ FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi,
+ enum fuse_readdir_flags flags)
+ {
+ try {
+ auto od = getProxy<OpenDirPtr>(fi->fh);
+ std::string path(p);
+ auto expiry = time(nullptr) + 2;
+ if (flags == FUSE_READDIR_PLUS) {
+ for (const auto & e : od->remote->listdir()) {
+ filler(buf, e.first.c_str(), nullptr, 0, FUSE_FILL_DIR_PLUS);
+ std::string k(path + e.first);
+ statCache.remove(k);
+ statCache.add(k, converter.convert(e.second), expiry);
+ }
}
- }
- else {
- for (const auto & e : od->remote->readdir()) {
- filler(buf, e.c_str(), nullptr, 0, (fuse_fill_dir_flags)0);
+ else {
+ for (const auto & e : od->remote->readdir()) {
+ filler(buf, e.c_str(), nullptr, 0, (fuse_fill_dir_flags)0);
+ }
}
+ return 0;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
}
- return 0;
- }
- catch (SystemError & e) {
- return -e.syserrno;
}
-}
-int
-FuseApp::mkdir(const char * p, mode_t m)
-{
- try {
- volume->mkdir(reqEnv(), p, m);
- return 0;
- }
- catch (SystemError & e) {
- return -e.syserrno;
+ int
+ FuseApp::mkdir(const char * p, mode_t m)
+ {
+ try {
+ volume->mkdir(reqEnv(), p, m);
+ return 0;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
+ }
}
-}
-int
-FuseApp::rmdir(const char * p)
-{
- try {
- volume->rmdir(reqEnv(), p);
- return 0;
- }
- catch (SystemError & e) {
- return -e.syserrno;
+ int
+ FuseApp::rmdir(const char * p)
+ {
+ try {
+ volume->rmdir(reqEnv(), p);
+ return 0;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
+ }
}
}
-}
-
diff --git a/netfs/fuse/fuseDirs.h b/netfs/fuse/fuseDirs.h
index 55088dd..bb02e65 100644
--- a/netfs/fuse/fuseDirs.h
+++ b/netfs/fuse/fuseDirs.h
@@ -5,13 +5,12 @@
namespace NetFS {
class FuseApp::OpenDir {
- public:
- OpenDir(DirectoryPrxPtr remote, std::string path);
+ public:
+ OpenDir(DirectoryPrxPtr remote, std::string path);
- DirectoryPrxPtr remote;
- const std::string path;
+ DirectoryPrxPtr remote;
+ const std::string path;
};
}
#endif
-
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index 48b3f87..0a59252 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -1,282 +1,277 @@
-#include <cstring>
-#include "fuseApp.impl.h"
#include "fuseFiles.h"
+#include "fuseApp.impl.h"
#include "lockHelpers.h"
+#include <cstring>
#include <entCache.h>
#include <mutex>
namespace NetFS {
-FuseApp::OpenFile::WriteState::WriteState() :
- future(promise.get_future().share())
-{
-}
-
-FuseApp::OpenFile::OpenFile(FilePrxPtr r, std::string p, int f) :
- remote(std::move(r)),
- path(std::move(p)),
- flags(f)
-{
-}
-
-template<>
-std::map<int, FuseApp::OpenFilePtr> &
-FuseApp::getMap<FuseApp::OpenFilePtr>()
-{
- return openFiles;
-}
+ FuseApp::OpenFile::WriteState::WriteState() : future(promise.get_future().share()) { }
-void
-FuseApp::OpenFile::wait() const
-{
- auto cbg = [this](){
- SharedLock(_lock);
- return bg;
- }();
- for (const auto & w : cbg) {
- w.second->future.wait();
+ FuseApp::OpenFile::OpenFile(FilePrxPtr r, std::string p, int f) : remote(std::move(r)), path(std::move(p)), flags(f)
+ {
}
-}
-void
-FuseApp::OpenFile::flush()
-{
- auto first = [this]() {
- SharedLock(_lock);
- return bg.empty() ? nullptr : bg.begin()->second;
- };
- while (auto w = first()) {
- // background operations are void, so no need to actually get the return value
- w->future.wait();
+ template<>
+ std::map<int, FuseApp::OpenFilePtr> &
+ FuseApp::getMap<FuseApp::OpenFilePtr>()
+ {
+ return openFiles;
}
-}
-FuseApp::OpenFile::BGs::interval_type
-FuseApp::OpenFile::range(off_t o, size_t s)
-{
- return OpenFile::BGs::interval_type::right_open(o, o + s);
-}
-
-int
-FuseApp::open(const char * p, struct fuse_file_info * fi)
-{
- try {
- auto remote = volume->open(reqEnv(), p, fi->flags);
- setProxy<OpenFilePtr>(fi->fh, remote, p, fi->flags);
- return 0;
- }
- catch (SystemError & e) {
- return -e.syserrno;
+ void
+ FuseApp::OpenFile::wait() const
+ {
+ auto cbg = [this]() {
+ SharedLock(_lock);
+ return bg;
+ }();
+ for (const auto & w : cbg) {
+ w.second->future.wait();
+ }
}
-}
-int
-FuseApp::create(const char * p, mode_t m, struct fuse_file_info * fi)
-{
- try {
- auto remote = volume->create(reqEnv(), p, fi->flags, m);
- setProxy<OpenFilePtr>(fi->fh, remote, p, fi->flags);
- return 0;
+ void
+ FuseApp::OpenFile::flush()
+ {
+ auto first = [this]() {
+ SharedLock(_lock);
+ return bg.empty() ? nullptr : bg.begin()->second;
+ };
+ while (auto w = first()) {
+ // background operations are void, so no need to actually get the return value
+ w->future.wait();
+ }
}
- catch (SystemError & e) {
- return -e.syserrno;
+
+ FuseApp::OpenFile::BGs::interval_type
+ FuseApp::OpenFile::range(off_t o, size_t s)
+ {
+ return OpenFile::BGs::interval_type::right_open(o, o + s);
}
-}
-int
-FuseApp::release(const char *, struct fuse_file_info * fi)
-{
- try {
- auto of = getProxy<OpenFilePtr>(fi->fh);
- auto remote = of->remote;
+ int
+ FuseApp::open(const char * p, struct fuse_file_info * fi)
+ {
try {
- of->flush();
+ auto remote = volume->open(reqEnv(), p, fi->flags);
+ setProxy<OpenFilePtr>(fi->fh, remote, p, fi->flags);
+ return 0;
}
catch (SystemError & e) {
+ return -e.syserrno;
}
- remote->close();
- clearProxy<OpenFilePtr>(fi->fh);
- return 0;
- }
- catch (SystemError & e) {
- clearProxy<OpenFilePtr>(fi->fh);
- return -e.syserrno;
- }
-}
-
-int
-FuseApp::flush(const char *, struct fuse_file_info * fi)
-{
- try {
- getProxy<OpenFilePtr>(fi->fh)->flush();
- return 0;
- }
- catch (SystemError & e) {
- return -e.syserrno;
}
-}
-template<typename Rtn, typename F>
-inline
-Rtn
-FuseApp::waitOnWriteRangeAndThen(size_t s, off_t o, const OpenFilePtr & of, const F & f)
-{
- const auto key = OpenFile::range(o, s);
- while (true) {
- std::unique_lock<decltype(of->_lock)> _l(of->_lock);
- // Acquire operations to wait for
- auto R = of->bg.equal_range(key);
- if (R.first == R.second) {
- // Perform operation
- return f(key);
+ int
+ FuseApp::create(const char * p, mode_t m, struct fuse_file_info * fi)
+ {
+ try {
+ auto remote = volume->create(reqEnv(), p, fi->flags, m);
+ setProxy<OpenFilePtr>(fi->fh, remote, p, fi->flags);
+ return 0;
}
- else {
- std::vector<std::shared_ptr<OpenFile::WriteState>> overlap;
- overlap.reserve(std::distance(R.first, R.second));
- for (auto i = R.first; i != R.second; i++) {
- overlap.push_back(i->second);
- }
- // Wait for them whilst unlocked
- _l.release()->unlock();
- for (const auto & r : overlap) {
- r->future.wait();
- }
- // Cause this thread to yield so the callback can acquire _lock
- usleep(0);
+ catch (SystemError & e) {
+ return -e.syserrno;
}
}
-}
-int
-FuseApp::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi)
-{
- try {
- auto cpy = [buf](const auto && data) {
- memcpy(buf, &data.front(), data.size());
- return data.size();
- };
- auto of = getProxy<OpenFilePtr>(fi->fh);
- auto remote = of->remote;
- if (fcr->Async) {
- auto p = waitOnWriteRangeAndThen<std::future<Buffer>>(s, o, of, [o, s, &remote](const auto &){
- return remote->readAsync(o, s);
- });
- return cpy(p.get());
+ int
+ FuseApp::release(const char *, struct fuse_file_info * fi)
+ {
+ try {
+ auto of = getProxy<OpenFilePtr>(fi->fh);
+ auto remote = of->remote;
+ try {
+ of->flush();
+ }
+ catch (SystemError & e) {
+ }
+ remote->close();
+ clearProxy<OpenFilePtr>(fi->fh);
+ return 0;
}
- else {
- return cpy(remote->read(o, s));
+ catch (SystemError & e) {
+ clearProxy<OpenFilePtr>(fi->fh);
+ return -e.syserrno;
}
}
- catch (SystemError & e) {
- return -e.syserrno;
- }
-}
-int
-FuseApp::write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi)
-{
- try {
- auto of = getProxy<OpenFilePtr>(fi->fh);
- auto remote = of->remote;
- if (fcr->Async) {
- waitOnWriteRangeAndThen<void>(s, o, of, [o, s, buf, &of, remote](const auto & key){
- auto p = std::make_shared<OpenFile::WriteState>();
- remote->writeAsync(o, s, Buffer(buf, buf + s), [p,of,key]() {
- p->promise.set_value();
- ScopeLock(of->_lock) {
- of->bg.erase(key);
- }
- }, [p,of,key](auto e) {
- p->promise.set_exception(e);
- ScopeLock(of->_lock) {
- of->bg.erase(key);
- }
- });
- of->bg.insert({key, p});
- });
+ int
+ FuseApp::flush(const char *, struct fuse_file_info * fi)
+ {
+ try {
+ getProxy<OpenFilePtr>(fi->fh)->flush();
+ return 0;
}
- else {
- remote->write(o, s, Buffer(buf, buf + s));
+ catch (SystemError & e) {
+ return -e.syserrno;
}
- return s;
- }
- catch (SystemError & e) {
- return -e.syserrno;
}
-}
-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)
-{
- 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, size, flags);
- }
- catch (SystemError & e) {
- return -e.syserrno;
+ template<typename Rtn, typename F>
+ inline Rtn
+ FuseApp::waitOnWriteRangeAndThen(size_t s, off_t o, const OpenFilePtr & of, const F & f)
+ {
+ const auto key = OpenFile::range(o, s);
+ while (true) {
+ std::unique_lock<decltype(of->_lock)> _l(of->_lock);
+ // Acquire operations to wait for
+ auto R = of->bg.equal_range(key);
+ if (R.first == R.second) {
+ // Perform operation
+ return f(key);
+ }
+ else {
+ std::vector<std::shared_ptr<OpenFile::WriteState>> overlap;
+ overlap.reserve(std::distance(R.first, R.second));
+ for (auto i = R.first; i != R.second; i++) {
+ overlap.push_back(i->second);
+ }
+ // Wait for them whilst unlocked
+ _l.release()->unlock();
+ for (const auto & r : overlap) {
+ r->future.wait();
+ }
+ // Cause this thread to yield so the callback can acquire _lock
+ usleep(0);
+ }
+ }
}
-}
-int
-FuseApp::truncate(const char * p, off_t o, fuse_file_info * fi)
-{
- try {
- if (fi) {
+ int
+ FuseApp::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi)
+ {
+ try {
+ auto cpy = [buf](const auto && data) {
+ memcpy(buf, &data.front(), data.size());
+ return data.size();
+ };
auto of = getProxy<OpenFilePtr>(fi->fh);
- of->wait();
auto remote = of->remote;
- remote->ftruncate(reqEnv(), o);
+ if (fcr->Async) {
+ auto p = waitOnWriteRangeAndThen<std::future<Buffer>>(s, o, of, [o, s, &remote](const auto &) {
+ return remote->readAsync(o, s);
+ });
+ return cpy(p.get());
+ }
+ else {
+ return cpy(remote->read(o, s));
+ }
}
- else {
- volume->truncate(reqEnv(), p, o);
+ catch (SystemError & e) {
+ return -e.syserrno;
}
- return 0;
- }
- catch (SystemError & e) {
- return -e.syserrno;
}
-}
-int
-FuseApp::getattr(const char * p, struct stat * s, fuse_file_info * fi)
-{
- try {
- if (fi) {
+ int
+ FuseApp::write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi)
+ {
+ try {
auto of = getProxy<OpenFilePtr>(fi->fh);
- of->wait();
auto remote = of->remote;
- *s = converter.convert(remote->fgetattr(reqEnv()));
- }
- else {
- if (auto cacehedStat = statCache.get(p)) {
- *s = *cacehedStat;
+ if (fcr->Async) {
+ waitOnWriteRangeAndThen<void>(s, o, of, [o, s, buf, &of, remote](const auto & key) {
+ auto p = std::make_shared<OpenFile::WriteState>();
+ remote->writeAsync(
+ o, s, Buffer(buf, buf + s),
+ [p, of, key]() {
+ p->promise.set_value();
+ ScopeLock(of->_lock) {
+ of->bg.erase(key);
+ }
+ },
+ [p, of, key](auto e) {
+ p->promise.set_exception(e);
+ ScopeLock(of->_lock) {
+ of->bg.erase(key);
+ }
+ });
+ of->bg.insert({key, p});
+ });
}
else {
- *s = converter.convert(volume->getattr(reqEnv(), p));
+ remote->write(o, s, Buffer(buf, buf + s));
}
+ return s;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
+ }
+ }
+ 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)
+ {
+ 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, size, flags);
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
}
- return 0;
}
- catch (SystemError & e) {
- return -e.syserrno;
+
+ int
+ FuseApp::truncate(const char * p, off_t o, fuse_file_info * fi)
+ {
+ try {
+ if (fi) {
+ auto of = getProxy<OpenFilePtr>(fi->fh);
+ of->wait();
+ auto remote = of->remote;
+ remote->ftruncate(reqEnv(), o);
+ }
+ else {
+ volume->truncate(reqEnv(), p, o);
+ }
+ return 0;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
+ }
}
-}
-int
-FuseApp::unlink(const char * p)
-{
- try {
- volume->unlink(reqEnv(), p);
- return 0;
+ int
+ FuseApp::getattr(const char * p, struct stat * s, fuse_file_info * fi)
+ {
+ try {
+ if (fi) {
+ auto of = getProxy<OpenFilePtr>(fi->fh);
+ of->wait();
+ auto remote = of->remote;
+ *s = converter.convert(remote->fgetattr(reqEnv()));
+ }
+ else {
+ if (auto cacehedStat = statCache.get(p)) {
+ *s = *cacehedStat;
+ }
+ else {
+ *s = converter.convert(volume->getattr(reqEnv(), p));
+ }
+ }
+ return 0;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
+ }
}
- catch (SystemError & e) {
- return -e.syserrno;
+
+ int
+ FuseApp::unlink(const char * p)
+ {
+ try {
+ volume->unlink(reqEnv(), p);
+ return 0;
+ }
+ catch (SystemError & e) {
+ return -e.syserrno;
+ }
}
}
-}
-
diff --git a/netfs/fuse/fuseFiles.h b/netfs/fuse/fuseFiles.h
index 4c9a31a..9143836 100644
--- a/netfs/fuse/fuseFiles.h
+++ b/netfs/fuse/fuseFiles.h
@@ -6,28 +6,27 @@
namespace NetFS {
class FuseApp::OpenFile {
- public:
- OpenFile(FilePrxPtr remote, std::string path, int flags);
+ public:
+ OpenFile(FilePrxPtr remote, std::string path, int flags);
- void flush();
- void wait() const;
+ void flush();
+ void wait() const;
- FilePrxPtr remote;
- const std::string path;
- const int flags;
- class WriteState {
- public:
- WriteState();
+ FilePrxPtr remote;
+ const std::string path;
+ const int flags;
+ class WriteState {
+ public:
+ WriteState();
- std::promise<void> promise;
- std::shared_future<void> future;
- };
- using BGs = boost::icl::interval_map<Ice::Long, std::shared_ptr<WriteState>>;
- static BGs::interval_type range(off_t, size_t);
- BGs bg;
- mutable std::shared_mutex _lock;
+ std::promise<void> promise;
+ std::shared_future<void> future;
+ };
+ using BGs = boost::icl::interval_map<Ice::Long, std::shared_ptr<WriteState>>;
+ static BGs::interval_type range(off_t, size_t);
+ BGs bg;
+ mutable std::shared_mutex _lock;
};
}
#endif
-
diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp
index c434333..36a695b 100644
--- a/netfs/fuse/fuseMisc.cpp
+++ b/netfs/fuse/fuseMisc.cpp
@@ -99,12 +99,10 @@ int
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);
+ volume->utimens(reqEnv(), path, times[0].tv_sec, times[0].tv_nsec, times[1].tv_sec, times[1].tv_nsec);
return 0;
}
catch (NetFS::SystemError & e) {
return -e.syserrno;
}
}
-
diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp
index ac87d14..413bbda 100644
--- a/netfs/fuse/fuseSystem.cpp
+++ b/netfs/fuse/fuseSystem.cpp
@@ -11,4 +11,3 @@ NetFS::FuseApp::statfs(const char * p, struct statvfs * vfs)
return -e.syserrno;
}
}
-
diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp
index 78a566b..9df3a75 100644
--- a/netfs/fuse/netfs.cpp
+++ b/netfs/fuse/netfs.cpp
@@ -2,49 +2,50 @@
#include <syslog.h>
class FuseImpl : public fuse_args, public NetFS::FuseApp {
- public:
- FuseImpl(int c, char ** v) :
- fuse_args(FUSE_ARGS_INIT(c, v)),
- NetFS::FuseApp([this](){
- Ice::StringSeq iceArgs;
- if (fuse_opt_parse(this, &iceArgs, nullptr, opt_parse) == -1) {
- exit(-1);
- }
- return iceArgs;
- }())
- {
- openlog("netfs", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
- }
- FuseImpl(const FuseImpl &) = delete;
- FuseImpl(FuseImpl &&) = delete;
-
- ~FuseImpl() override
- {
- closelog();
- }
-
- void operator=(const FuseImpl &) = delete;
- void operator=(FuseImpl &&) = delete;
-
- struct fuse_context * fuse_get_context() override
- {
- return ::fuse_get_context();
- }
-
- int run()
- {
- return ::fuse_main(argc, argv, &operations, this);
- }
-
- void vlogf(int priority, const char * fmt, va_list args) const noexcept override
- {
- vsyslog(priority, fmt, args);
- }
+public:
+ FuseImpl(int c, char ** v) :
+ fuse_args(FUSE_ARGS_INIT(c, v)), NetFS::FuseApp([this]() {
+ Ice::StringSeq iceArgs;
+ if (fuse_opt_parse(this, &iceArgs, nullptr, opt_parse) == -1) {
+ exit(-1);
+ }
+ return iceArgs;
+ }())
+ {
+ openlog("netfs", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
+ }
+ FuseImpl(const FuseImpl &) = delete;
+ FuseImpl(FuseImpl &&) = delete;
+
+ ~FuseImpl() override
+ {
+ closelog();
+ }
+
+ void operator=(const FuseImpl &) = delete;
+ void operator=(FuseImpl &&) = delete;
+
+ struct fuse_context *
+ fuse_get_context() override
+ {
+ return ::fuse_get_context();
+ }
+
+ int
+ run()
+ {
+ return ::fuse_main(argc, argv, &operations, this);
+ }
+
+ void
+ vlogf(int priority, const char * fmt, va_list args) const noexcept override
+ {
+ vsyslog(priority, fmt, args);
+ }
};
int
-main(int argc, char* argv[])
+main(int argc, char * argv[])
{
return FuseImpl(argc, argv).run();
}
-
diff --git a/netfs/ice/entryResolver.h b/netfs/ice/entryResolver.h
index 14f2d5d..973af4c 100644
--- a/netfs/ice/entryResolver.h
+++ b/netfs/ice/entryResolver.h
@@ -1,21 +1,20 @@
#ifndef NETFS_ENTRYRESOLVER_H
#define NETFS_ENTRYRESOLVER_H
-#include <cstddef>
+#include <cstdint>
+#include <unistd.h>
enum class ResolvedAs : uint8_t {
Real,
Fallback,
};
-template <typename id_t, typename name_t>
-class EntryResolver {
- public:
- virtual ~EntryResolver() = default;
+template<typename id_t, typename name_t> class EntryResolver {
+public:
+ virtual ~EntryResolver() = default;
- virtual ResolvedAs getID(const name_t &, id_t *) const = 0;
- virtual ResolvedAs getName(const id_t &, name_t *) const = 0;
+ virtual ResolvedAs getID(const name_t &, id_t *) const = 0;
+ virtual ResolvedAs getName(const id_t &, name_t *) const = 0;
};
#endif
-
diff --git a/netfs/ice/exceptionsImpl.cpp b/netfs/ice/exceptionsImpl.cpp
index 93f5930..9588476 100644
--- a/netfs/ice/exceptionsImpl.cpp
+++ b/netfs/ice/exceptionsImpl.cpp
@@ -1,5 +1,5 @@
-#include <exceptions.h>
#include <compileTimeFormatter.h>
+#include <exceptions.h>
AdHocFormatter(ExportNotFoundMsg, "Export [%?] not found on remote host");
void
@@ -7,4 +7,3 @@ NetFS::ExportNotFound::ice_print(std::ostream & s) const
{
ExportNotFoundMsg::write(s, exportName);
}
-
diff --git a/netfs/ice/typeConverter.cpp b/netfs/ice/typeConverter.cpp
index 8e75326..e365c5d 100644
--- a/netfs/ice/typeConverter.cpp
+++ b/netfs/ice/typeConverter.cpp
@@ -1,17 +1,14 @@
#include "typeConverter.h"
#include <boost/numeric/conversion/cast.hpp>
-EntryTypeConverter::EntryTypeConverter(const UserLookup & u, const GroupLookup & g) :
- userLookup(u),
- groupLookup(g)
-{
-}
+EntryTypeConverter::EntryTypeConverter(const UserLookup & u, const GroupLookup & g) : userLookup(u), groupLookup(g) { }
// Wrapper function to assure no unexpected corruption occurs
// during narrowing assignments.
// (bugprone-narrowing-conversions)
template<typename T, typename S>
-inline void safeAssign(T & t, const S & s)
+inline void
+safeAssign(T & t, const S & s)
{
t = boost::numeric_cast<T>(s);
}
@@ -19,7 +16,8 @@ inline void safeAssign(T & t, const S & s)
struct stat
EntryTypeConverter::convert(const NetFS::Attr & a) const
{
- struct stat s {};
+ struct stat s {
+ };
s.st_dev = a.dev;
s.st_ino = a.inode;
s.st_mode = a.mode;
@@ -45,7 +43,8 @@ EntryTypeConverter::convert(const NetFS::Attr & a) const
struct statvfs
TypeConverter::convert(const NetFS::VFS & v) const
{
- struct statvfs vfs {};
+ struct statvfs vfs {
+ };
vfs.f_bsize = v.blockSize;
vfs.f_frsize = v.fragmentSize;
vfs.f_blocks = v.blocks;
@@ -97,4 +96,3 @@ TypeConverter::convert(const struct statvfs & s) const
safeAssign(t.maxNameLen, s.f_namemax);
return t;
}
-
diff --git a/netfs/ice/typeConverter.h b/netfs/ice/typeConverter.h
index fedd204..3cd2941 100644
--- a/netfs/ice/typeConverter.h
+++ b/netfs/ice/typeConverter.h
@@ -1,33 +1,32 @@
#ifndef NETFS_TYPECONVERT_H
#define NETFS_TYPECONVERT_H
-#include <types.h>
+#include "entryResolver.h"
#include <sys/stat.h>
#include <sys/statvfs.h>
+#include <types.h>
#include <visibility.h>
-#include "entryResolver.h"
class DLL_PUBLIC TypeConverter {
- public:
- // VFS
- struct statvfs convert(const NetFS::VFS &) const;
- NetFS::VFS convert(const struct statvfs &) const;
+public:
+ // VFS
+ struct statvfs convert(const NetFS::VFS &) const;
+ NetFS::VFS convert(const struct statvfs &) const;
};
class DLL_PUBLIC EntryTypeConverter : public TypeConverter {
- public:
- using UserLookup = EntryResolver<uid_t, std::string>;
- using GroupLookup = EntryResolver<gid_t, std::string>;
- EntryTypeConverter(const UserLookup &, const GroupLookup &);
+public:
+ using UserLookup = EntryResolver<uid_t, std::string>;
+ using GroupLookup = EntryResolver<gid_t, std::string>;
+ EntryTypeConverter(const UserLookup &, const GroupLookup &);
- // Attributes
- struct stat convert(const NetFS::Attr &) const;
- NetFS::Attr convert(const struct stat &) const;
+ // Attributes
+ struct stat convert(const NetFS::Attr &) const;
+ NetFS::Attr convert(const struct stat &) const;
- protected:
- const UserLookup & userLookup;
- const GroupLookup & groupLookup;
+protected:
+ const UserLookup & userLookup;
+ const GroupLookup & groupLookup;
};
#endif
-
diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp
index a4436b9..d9f61df 100644
--- a/netfs/lib/entCache.cpp
+++ b/netfs/lib/entCache.cpp
@@ -7,4 +7,3 @@ static_assert(std::is_nothrow_move_assignable_v<Group>);
template class EntCache<User>;
template class EntCache<Group>;
-
diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h
index e0a06b5..e8c6461 100644
--- a/netfs/lib/entCache.h
+++ b/netfs/lib/entCache.h
@@ -1,71 +1,67 @@
#ifndef ENTCACHE_H
#define ENTCACHE_H
-#include <string>
+#include <c++11Helpers.h>
+#include <entryResolver.h>
#include <set>
#include <shared_mutex>
-#include <entryResolver.h>
-#include <c++11Helpers.h>
+#include <string>
class User {
- public:
- User(uid_t, std::string, gid_t);
- uid_t id;
- std::string name;
- gid_t group;
+public:
+ User(uid_t, std::string, gid_t);
+ uid_t id;
+ std::string name;
+ gid_t group;
};
class Group {
- public:
- Group(gid_t, std::string);
+public:
+ Group(gid_t, std::string);
- bool hasMember(uid_t) const;
+ bool hasMember(uid_t) const;
- gid_t id;
- std::string name;
- std::set<uid_t> members;
+ gid_t id;
+ std::string name;
+ std::set<uid_t> members;
};
-template<class entry_t>
-class EntCache : public EntryResolver<decltype(entry_t::id), decltype(entry_t::name)> {
- public:
- EntCache();
- EntCache(entry_t fb);
- ~EntCache() override;
+template<class entry_t> class EntCache : public EntryResolver<decltype(entry_t::id), decltype(entry_t::name)> {
+public:
+ EntCache();
+ EntCache(entry_t fb);
+ ~EntCache() override;
- SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(EntCache);
+ SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(EntCache);
- using id_t = decltype(entry_t::id);
- using name_t = decltype(entry_t::name);
- using entry_ptr = std::shared_ptr<entry_t>;
+ using id_t = decltype(entry_t::id);
+ using name_t = decltype(entry_t::name);
+ using entry_ptr = std::shared_ptr<entry_t>;
- struct Resolution : public entry_ptr {
- Resolution(entry_ptr, ResolvedAs = ResolvedAs::Real);
- ResolvedAs resolution;
- };
+ struct Resolution : public entry_ptr {
+ Resolution(entry_ptr, ResolvedAs = ResolvedAs::Real);
+ ResolvedAs resolution;
+ };
- ResolvedAs getID(const name_t &, id_t *) const override;
- ResolvedAs getName(const id_t &, name_t *) const override;
- template<class key_t>
- Resolution getEntry(const key_t &) const;
+ ResolvedAs getID(const name_t &, id_t *) const override;
+ ResolvedAs getName(const id_t &, name_t *) const override;
+ template<class key_t> Resolution getEntry(const key_t &) const;
- void setFallback(entry_t fb);
- void clearFallback();
+ void setFallback(entry_t fb);
+ void clearFallback();
- protected:
- void fillCache() const;
- template<class key_t>
- entry_ptr getEntryNoFill(const key_t &) const;
+protected:
+ void fillCache() const;
+ template<class key_t> entry_ptr getEntryNoFill(const key_t &) const;
- class Ids;
- std::unique_ptr<Ids> idcache;
- mutable std::shared_mutex lock;
- mutable time_t fillTime {0};
- entry_ptr fallback;
+ class Ids;
+ std::unique_ptr<Ids> idcache;
+ mutable std::shared_mutex lock;
+ mutable time_t fillTime {0};
+ entry_ptr fallback;
};
using UserEntCache = EntCache<User>;
using GroupEntCache = EntCache<Group>;
#endif
-
diff --git a/netfs/lib/entCache.impl.h b/netfs/lib/entCache.impl.h
index e0a8f85..0021f00 100644
--- a/netfs/lib/entCache.impl.h
+++ b/netfs/lib/entCache.impl.h
@@ -1,41 +1,33 @@
-#include "entCache.h"
#ifndef ENTCACHE_IMPL_H
#define ENTCACHE_IMPL_H
+#include "entCache.h"
+#include <boost/multi_index/member.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index_container.hpp>
#include <exceptions.h>
+#include <grp.h>
#include <lockHelpers.h>
#include <pwd.h>
-#include <grp.h>
#include <type_traits>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/member.hpp>
-#include <boost/multi_index/ordered_index.hpp>
template<class entry_t>
-class EntCache<entry_t>::Ids : public boost::multi_index::multi_index_container<std::shared_ptr<entry_t>,
- boost::multi_index::indexed_by<
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<id_t>, BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id), std::less<>>,
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<std::string>, BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name), std::less<>>
- > > {
- };
+class EntCache<entry_t>::Ids :
+ public boost::multi_index::multi_index_container<std::shared_ptr<entry_t>,
+ boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::tag<id_t>,
+ BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id), std::less<>>,
+ boost::multi_index::ordered_unique<boost::multi_index::tag<std::string>,
+ BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name), std::less<>>>> {
+};
-template<class entry_t>
-EntCache<entry_t>::EntCache() :
- idcache(std::make_unique<Ids>())
-{
-}
+template<class entry_t> EntCache<entry_t>::EntCache() : idcache(std::make_unique<Ids>()) { }
-template<class entry_t>
-EntCache<entry_t>::EntCache(entry_t fb) :
- idcache(std::make_unique<Ids>())
+template<class entry_t> EntCache<entry_t>::EntCache(entry_t fb) : idcache(std::make_unique<Ids>())
{
setFallback(std::move(fb));
}
-template<class entry_t>
-EntCache<entry_t>::~EntCache() = default;
+template<class entry_t> EntCache<entry_t>::~EntCache() = default;
template<class entry_t>
ResolvedAs
@@ -56,9 +48,7 @@ EntCache<entry_t>::getName(const EntCache<entry_t>::id_t & u, EntCache<entry_t>:
}
template<class entry_t>
-EntCache<entry_t>::Resolution::Resolution(entry_ptr e, ResolvedAs res) :
- entry_ptr(std::move(e)),
- resolution(res)
+EntCache<entry_t>::Resolution::Resolution(entry_ptr e, ResolvedAs res) : entry_ptr(std::move(e)), resolution(res)
{
}
@@ -77,7 +67,7 @@ EntCache<entry_t>::getEntry(const key_t & key) const
return ent;
}
if (fallback) {
- return { fallback, ResolvedAs::Fallback };
+ return {fallback, ResolvedAs::Fallback};
}
throw NetFS::SystemError(EPERM);
}
@@ -110,12 +100,7 @@ EntCache<entry_t>::clearFallback()
fallback.reset();
}
-User::User(uid_t u, std::string n, gid_t g) :
- id(u),
- name(std::move(n)),
- group(g)
-{
-}
+User::User(uid_t u, std::string n, gid_t g) : id(u), name(std::move(n)), group(g) { }
const int BUFLEN = 8196;
@@ -127,7 +112,8 @@ EntCache<User>::fillCache() const
setpwent();
idcache->clear();
std::array<char, BUFLEN> buf {};
- struct passwd pwbuf {}, * pwp;
+ struct passwd pwbuf {
+ }, *pwp;
while (getpwent_r(&pwbuf, buf.data(), buf.size(), &pwp) == 0) {
idcache->insert(std::make_shared<User>(pwp->pw_uid, pwp->pw_name, pwp->pw_gid));
}
@@ -135,11 +121,7 @@ EntCache<User>::fillCache() const
time(&fillTime);
}
-Group::Group(gid_t g, std::string n) :
- id(g),
- name(std::move(n))
-{
-}
+Group::Group(gid_t g, std::string n) : id(g), name(std::move(n)) { }
template<>
void
@@ -149,7 +131,8 @@ EntCache<Group>::fillCache() const
setgrent();
std::array<char, BUFLEN> buf {};
idcache->clear();
- struct group grpbuf {}, * grp;
+ struct group grpbuf {
+ }, *grp;
EntCache<User> instance;
while (getgrent_r(&grpbuf, buf.data(), buf.size(), &grp) == 0) {
auto g = std::make_shared<Group>(grp->gr_gid, grp->gr_name);
@@ -173,4 +156,3 @@ Group::hasMember(uid_t u) const
}
#endif
-
diff --git a/netfs/unittests/mockDaemon.cpp b/netfs/unittests/mockDaemon.cpp
index c2bfca2..0cb3172 100644
--- a/netfs/unittests/mockDaemon.cpp
+++ b/netfs/unittests/mockDaemon.cpp
@@ -1,31 +1,24 @@
#include "mockDaemon.h"
-#include <definedDirs.h>
#include <buffer.h>
+#include <definedDirs.h>
-const std::filesystem::path MockDaemonHost::TestExportRoot(binDir /
- UniqueExport::get(getpid()));
+const std::filesystem::path MockDaemonHost::TestExportRoot(binDir / UniqueExport::get(getpid()));
-MockDaemon::MockDaemon(std::string ep) :
- NetFSDaemon(),
- testEndpoint(std::move(ep))
-{
-}
+MockDaemon::MockDaemon(std::string ep) : NetFSDaemon(), testEndpoint(std::move(ep)) { }
NetFS::Daemon::ConfigurationPtr
MockDaemon::ReadConfiguration(const std::filesystem::path & path) const
{
auto c = NetFSDaemon::ReadConfiguration(path);
- for(const auto & e : c->Exports) {
+ for (const auto & e : c->Exports) {
e.second->RootPath = MockDaemonHost::TestExportRoot.string();
}
- c->Hosts.insert({ "unittest", std::make_shared<NetFS::Daemon::Host>(testEndpoint) });
+ c->Hosts.insert({"unittest", std::make_shared<NetFS::Daemon::Host>(testEndpoint)});
return c;
}
MockDaemonHost::MockDaemonHost(std::string ep, Ice::StringSeq ps) :
- testEndpoint(std::move(ep)),
- params(std::move(ps)),
- daemon(nullptr)
+ testEndpoint(std::move(ep)), params(std::move(ps)), daemon(nullptr)
{
std::filesystem::remove_all(TestExportRoot);
std::filesystem::create_directories(TestExportRoot);
@@ -68,4 +61,3 @@ MockDaemonHost::restart()
stop();
start();
}
-
diff --git a/netfs/unittests/mockDaemon.h b/netfs/unittests/mockDaemon.h
index 659d23c..fb129c4 100644
--- a/netfs/unittests/mockDaemon.h
+++ b/netfs/unittests/mockDaemon.h
@@ -1,40 +1,39 @@
#ifndef MOCKDAEMON_H
#define MOCKDAEMON_H
+#include <compileTimeFormatter.h>
#include <daemon.h>
#include <visibility.h>
-#include <compileTimeFormatter.h>
AdHocFormatter(UniqueExport, "testExport-%?");
class DLL_PUBLIC MockDaemon : public NetFSDaemon {
- public:
- MockDaemon(std::string ep);
+public:
+ MockDaemon(std::string ep);
- const std::string testEndpoint;
+ const std::string testEndpoint;
- protected:
- NetFS::Daemon::ConfigurationPtr ReadConfiguration(const std::filesystem::path &) const override;
+protected:
+ NetFS::Daemon::ConfigurationPtr ReadConfiguration(const std::filesystem::path &) const override;
};
class DLL_PUBLIC MockDaemonHost {
- public:
- MockDaemonHost(std::string ep, Ice::StringSeq ps = {});
- ~MockDaemonHost();
+public:
+ MockDaemonHost(std::string ep, Ice::StringSeq ps = {});
+ ~MockDaemonHost();
- void restart();
+ void restart();
- Ice::CommunicatorPtr ic;
- static const std::filesystem::path TestExportRoot;
+ Ice::CommunicatorPtr ic;
+ static const std::filesystem::path TestExportRoot;
- private:
- void start();
- void stop();
+private:
+ void start();
+ void stop();
- const std::string testEndpoint;
- Ice::StringSeq params;
- NetFSDaemon * daemon;
+ const std::string testEndpoint;
+ Ice::StringSeq params;
+ NetFSDaemon * daemon;
};
#endif
-
diff --git a/netfs/unittests/mockFuse.cpp b/netfs/unittests/mockFuse.cpp
index 8a85267..554a62d 100644
--- a/netfs/unittests/mockFuse.cpp
+++ b/netfs/unittests/mockFuse.cpp
@@ -3,9 +3,7 @@
#include <buffer.h>
FuseMock::FuseMock(std::string ep, Ice::StringSeq a) :
- NetFS::FuseApp(std::move(a)),
- testEndpoint(std::move(ep)),
- context({})
+ NetFS::FuseApp(std::move(a)), testEndpoint(std::move(ep)), context({})
{
::memset(&context, 0, sizeof(fuse_context));
context.pid = getpid();
@@ -43,11 +41,9 @@ FuseMock::vlogf(int, const char * fmt, va_list args) const noexcept
}
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);
}
}
-
diff --git a/netfs/unittests/mockFuse.h b/netfs/unittests/mockFuse.h
index 4461da6..c0e7828 100644
--- a/netfs/unittests/mockFuse.h
+++ b/netfs/unittests/mockFuse.h
@@ -5,29 +5,28 @@
#include <visibility.h>
class DLL_PUBLIC FuseMock : public NetFS::FuseApp {
- public:
- FuseMock(std::string, Ice::StringSeq);
+public:
+ FuseMock(std::string, Ice::StringSeq);
- struct fuse_context * fuse_get_context() override;
- void vlogf(int, const char *, va_list) const throw() override;
+ struct fuse_context * fuse_get_context() override;
+ void vlogf(int, const char *, va_list) const throw() override;
- void connectToService() override;
- private:
- const std::string testEndpoint;
- fuse_context context;
+ void connectToService() override;
+
+private:
+ const std::string testEndpoint;
+ fuse_context context;
};
class DLL_PUBLIC FuseMockHost {
- public:
- FuseMockHost(std::string, const Ice::StringSeq &);
+public:
+ FuseMockHost(std::string, const Ice::StringSeq &);
- private:
- std::unique_ptr<FuseMock> app;
+private:
+ std::unique_ptr<FuseMock> app;
- public:
- const fuse_operations * fuse;
+public:
+ const fuse_operations * fuse;
};
-
#endif
-
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp
index ee079a8..cdbb958 100644
--- a/netfs/unittests/testCore.cpp
+++ b/netfs/unittests/testCore.cpp
@@ -3,12 +3,12 @@
#define private public
#include "mockDaemon.h"
#include "mockFuse.h"
+#include <algorithm>
+#include <climits>
#include <definedDirs.h>
#include <filesystem>
-#include <ostream>
-#include <algorithm>
#include <fuseFiles.h>
-#include <climits>
+#include <ostream>
const auto testExport = UniqueExport::get(getpid());
const std::string testEndpoint("tcp -h localhost -p 12012");
@@ -24,7 +24,8 @@ operator==(const struct stat & a, const struct stat & b)
namespace std {
template<size_t l>
- bool operator==(const std::array<char, l> & a, const char * b)
+ bool
+ operator==(const std::array<char, l> & a, const char * b)
{
return strncmp(a.data(), b, l) == 0;
}
@@ -32,13 +33,15 @@ namespace std {
AdHocFormatter(StatDebug, "dev: %? inode: %?");
// LCOV_EXCL_START
template<typename T, size_t l>
- ostream & operator<<(ostream & s, const std::array<T, l> & a)
+ ostream &
+ operator<<(ostream & s, const std::array<T, l> & a)
{
std::copy(a.begin(), a.end(), std::ostream_iterator<T>(s));
return s;
}
- ostream & operator<<(ostream & s, const struct stat & ss)
+ ostream &
+ operator<<(ostream & s, const struct stat & ss)
{
return StatDebug::write(s, ss.st_dev, ss.st_ino);
}
@@ -46,51 +49,42 @@ namespace std {
}
class Core {
- public:
- Core(const std::string & daemonConfig = "defaultDaemon.xml", const std::string & fuseConfig = "defaultFuse.xml") :
- daemonHost(testEndpoint, {
- "--Ice.ThreadPool.Client.Size=4",
- "--Ice.ThreadPool.Client.SizeMax=20",
- "--Ice.ThreadPool.Server.Size=5",
- "--Ice.ThreadPool.Server.SizeMax=20",
- "--NetFSD.ConfigPath=" + (rootDir / daemonConfig).string()
- }),
- fuseHost(testEndpoint, {
- "--Ice.ThreadPool.Client.Size=6",
- "--Ice.ThreadPool.Client.SizeMax=20",
- (rootDir / fuseConfig).string() + ":testvol",
- (binDir / "test").string()
- }),
- ic(daemonHost.ic),
- fuse(fuseHost.fuse)
- {
- }
-
- static
- int
- nameListAdd(void *buf, const char *name, const struct stat *, off_t, fuse_fill_dir_flags)
- {
- static_cast<NetFS::NameList *>(buf)->push_back(name);
- return 0;
- }
+public:
+ Core(const std::string & daemonConfig = "defaultDaemon.xml", const std::string & fuseConfig = "defaultFuse.xml") :
+ daemonHost(testEndpoint,
+ {"--Ice.ThreadPool.Client.Size=4", "--Ice.ThreadPool.Client.SizeMax=20",
+ "--Ice.ThreadPool.Server.Size=5", "--Ice.ThreadPool.Server.SizeMax=20",
+ "--NetFSD.ConfigPath=" + (rootDir / daemonConfig).string()}),
+ fuseHost(testEndpoint,
+ {"--Ice.ThreadPool.Client.Size=6", "--Ice.ThreadPool.Client.SizeMax=20",
+ (rootDir / fuseConfig).string() + ":testvol", (binDir / "test").string()}),
+ ic(daemonHost.ic), fuse(fuseHost.fuse)
+ {
+ }
+ static int
+ nameListAdd(void * buf, const char * name, const struct stat *, off_t, fuse_fill_dir_flags)
+ {
+ static_cast<NetFS::NameList *>(buf)->push_back(name);
+ return 0;
+ }
- protected:
- MockDaemonHost daemonHost;
- FuseMockHost fuseHost;
+protected:
+ MockDaemonHost daemonHost;
+ FuseMockHost fuseHost;
- Ice::CommunicatorPtr ic;
+ Ice::CommunicatorPtr ic;
- public:
- const fuse_operations * fuse;
+public:
+ const fuse_operations * fuse;
};
class AltCore : public Core {
- public:
- AltCore() : Core("altDaemon.xml", "defaultFuse.xml") { }
+public:
+ AltCore() : Core("altDaemon.xml", "defaultFuse.xml") { }
};
-BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core );
+BOOST_FIXTURE_TEST_SUITE(NetfsCore, Core);
BOOST_AUTO_TEST_CASE(fuse_operations_correct)
{
@@ -102,7 +96,7 @@ BOOST_AUTO_TEST_CASE(fuse_operations_correct)
BOOST_REQUIRE(!fuse->fsync);
}
-BOOST_AUTO_TEST_CASE ( daemonInitialised )
+BOOST_AUTO_TEST_CASE(daemonInitialised)
{
auto service = Ice::checkedCast<NetFS::ServicePrx>(ic->stringToProxy("Service"));
BOOST_REQUIRE(service);
@@ -113,18 +107,20 @@ BOOST_AUTO_TEST_CASE ( daemonInitialised )
volume->disconnect();
}
-BOOST_AUTO_TEST_CASE ( clientInitialised )
+BOOST_AUTO_TEST_CASE(clientInitialised)
{
struct statvfs s;
- BOOST_REQUIRE_EQUAL(0, fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, fuse->statfs("/", &s));
BOOST_REQUIRE_EQUAL(s.f_fsid, 0);
- BOOST_REQUIRE_EQUAL(-ENOENT, fuse->statfs("/missing", &s));
+ BOOST_REQUIRE_EQUAL(-ENOENT, fuse->statfs("/missing", &s));
}
-BOOST_AUTO_TEST_CASE( testNavigation )
+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);
@@ -153,13 +149,14 @@ BOOST_AUTO_TEST_CASE( testNavigation )
BOOST_REQUIRE_EQUAL(attr, insideattr);
}
-BOOST_AUTO_TEST_CASE( testSandboxing )
+BOOST_AUTO_TEST_CASE(testSandboxing)
{
// A previous (bad) run might create one or more of these:
std::filesystem::remove(binDir / "outside");
std::filesystem::remove(binDir / "sub" / "outside");
std::filesystem::remove(binDir / "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(binDir / "outside"));
BOOST_REQUIRE_EQUAL(fuse->create("/../outside", 0666, &fi), -EPERM);
@@ -183,7 +180,8 @@ 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);
@@ -192,16 +190,19 @@ 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);
}
-BOOST_AUTO_TEST_CASE( directories )
+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(binDir / testExport / "test"));
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), -EEXIST);
@@ -242,10 +243,12 @@ BOOST_AUTO_TEST_CASE( directories )
BOOST_REQUIRE_EQUAL(fuse->opendir("/test", &fi), -ENOENT);
}
-BOOST_AUTO_TEST_CASE( files )
+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);
@@ -297,9 +300,10 @@ BOOST_AUTO_TEST_CASE( files )
BOOST_REQUIRE_EQUAL(fuse->unlink("/test3"), -ENOENT);
}
-BOOST_AUTO_TEST_CASE( files_copy_range )
+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);
@@ -313,10 +317,12 @@ BOOST_AUTO_TEST_CASE( files_copy_range )
BOOST_REQUIRE_EQUAL(fuse->release("/dst", &fiout), 0);
}
-BOOST_AUTO_TEST_CASE( bgwriteOverlapped, * boost::unit_test::timeout(2) )
+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);
auto N = 20;
@@ -328,16 +334,18 @@ BOOST_AUTO_TEST_CASE( bgwriteOverlapped, * boost::unit_test::timeout(2) )
BOOST_REQUIRE_EQUAL(st.st_size, N + s - 1);
std::array<char, s> buf;
BOOST_REQUIRE_EQUAL(fuse->read("/test", buf.data(), s, (N - 1), &fi), s);
- BOOST_REQUIRE_EQUAL(*(int*)buf.data(), N - 1);
+ BOOST_REQUIRE_EQUAL(*(int *)buf.data(), N - 1);
BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st, nullptr), 0);
BOOST_REQUIRE_EQUAL(st.st_size, N + s - 1);
}
-BOOST_AUTO_TEST_CASE( bgwriteDistinct, * 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);
auto N = 20;
@@ -349,13 +357,13 @@ BOOST_AUTO_TEST_CASE( bgwriteDistinct, * boost::unit_test::timeout(2) )
BOOST_REQUIRE_EQUAL(st.st_size, N * s);
std::array<char, s> buf;
BOOST_REQUIRE_EQUAL(fuse->read("/test", buf.data(), s, (N - 1) * s, &fi), s);
- BOOST_REQUIRE_EQUAL(*(int*)buf.data(), N - 1);
+ BOOST_REQUIRE_EQUAL(*(int *)buf.data(), N - 1);
BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st, nullptr), 0);
BOOST_REQUIRE_EQUAL(st.st_size, N * s);
}
-BOOST_AUTO_TEST_CASE( symlinks )
+BOOST_AUTO_TEST_CASE(symlinks)
{
std::array<char, PATH_MAX> buf;
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
@@ -371,9 +379,10 @@ BOOST_AUTO_TEST_CASE( symlinks )
enableWriteOnDir(fuse, "/");
}
-BOOST_AUTO_TEST_CASE( access )
+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
@@ -397,9 +406,10 @@ BOOST_AUTO_TEST_CASE( access )
BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st, nullptr), -ENOENT);
}
-BOOST_AUTO_TEST_CASE( permissionsDirs )
+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);
@@ -413,10 +423,12 @@ BOOST_AUTO_TEST_CASE( permissionsDirs )
BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st, nullptr), -ENOENT);
}
-BOOST_AUTO_TEST_CASE( permissionsFiles )
+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);
@@ -432,11 +444,12 @@ BOOST_AUTO_TEST_CASE( permissionsFiles )
BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st, nullptr), -ENOENT);
}
-BOOST_AUTO_TEST_CASE( mknod )
+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);
@@ -446,9 +459,10 @@ BOOST_AUTO_TEST_CASE( mknod )
enableWriteOnDir(fuse, "/");
}
-BOOST_AUTO_TEST_CASE( renameToDir )
+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);
@@ -465,9 +479,10 @@ BOOST_AUTO_TEST_CASE( renameToDir )
BOOST_REQUIRE_EQUAL(fuse->rmdir("/dir"), 0);
}
-BOOST_AUTO_TEST_CASE( renameFlags )
+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);
@@ -482,11 +497,12 @@ BOOST_AUTO_TEST_CASE( renameFlags )
BOOST_REQUIRE_EQUAL(fuse->access("/file2", F_OK), 0);
}
-BOOST_AUTO_TEST_CASE( chown )
+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());
@@ -494,14 +510,15 @@ BOOST_AUTO_TEST_CASE( chown )
BOOST_REQUIRE_EQUAL(fuse->rmdir("/dir"), 0);
}
-BOOST_AUTO_TEST_CASE( utimens )
+BOOST_AUTO_TEST_CASE(utimens)
{
BOOST_REQUIRE_EQUAL(fuse->mknod("/file", 0600, 0), 0);
- std::array<timespec, 2> times { { {1, 100}, { 2, 200 } } };
+ std::array<timespec, 2> times {{{1, 100}, {2, 200}}};
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);
@@ -523,11 +540,12 @@ BOOST_AUTO_TEST_CASE( utimens )
BOOST_AUTO_TEST_SUITE_END();
-BOOST_FIXTURE_TEST_SUITE( NetfsAltCore, AltCore );
+BOOST_FIXTURE_TEST_SUITE(NetfsAltCore, AltCore);
-BOOST_AUTO_TEST_CASE( noListDir )
+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(binDir / testExport / "test"));
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), -EEXIST);
@@ -564,10 +582,12 @@ BOOST_AUTO_TEST_CASE( noListDir )
BOOST_REQUIRE_EQUAL(fuse->opendir("/test", &fi), -ENOENT);
}
-BOOST_AUTO_TEST_CASE( testFGWrites )
+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);
@@ -581,49 +601,48 @@ BOOST_AUTO_TEST_CASE( testFGWrites )
BOOST_AUTO_TEST_SUITE_END();
-BOOST_AUTO_TEST_CASE( testNoAuthNoPass )
+BOOST_AUTO_TEST_CASE(testNoAuthNoPass)
{
Core c("defaultDaemon.xml", "defaultFuse.xml");
struct statvfs s;
- BOOST_REQUIRE_EQUAL(0, c.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, c.fuse->statfs("/", &s));
}
-BOOST_AUTO_TEST_CASE( testWithAuthNoPass )
+BOOST_AUTO_TEST_CASE(testWithAuthNoPass)
{
Core c("secureDaemon.xml", "defaultFuse.xml");
struct statvfs s;
- BOOST_REQUIRE_EQUAL(-EPERM, c.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(-EPERM, c.fuse->statfs("/", &s));
}
-BOOST_AUTO_TEST_CASE( testWithAuthWithPass )
+BOOST_AUTO_TEST_CASE(testWithAuthWithPass)
{
Core c("secureDaemon.xml", "secureFuse.xml");
struct statvfs s;
- BOOST_REQUIRE_EQUAL(0, c.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, c.fuse->statfs("/", &s));
}
-BOOST_AUTO_TEST_CASE( testNoAuthWithPass )
+BOOST_AUTO_TEST_CASE(testNoAuthWithPass)
{
Core c("defaultDaemon.xml", "secureFuse.xml");
struct statvfs s;
- BOOST_REQUIRE_EQUAL(0, c.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, c.fuse->statfs("/", &s));
}
-BOOST_AUTO_TEST_CASE( uriConnect )
+BOOST_AUTO_TEST_CASE(uriConnect)
{
- MockDaemonHost daemon(testEndpoint, {
- "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()
- });
- FuseMockHost fuse(std::string(), {
- testUri,
- (binDir / "test").string(),
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
+ FuseMockHost fuse(std::string(),
+ {
+ testUri,
+ (binDir / "test").string(),
});
struct statvfs s;
- BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
}
-BOOST_AUTO_TEST_CASE( interval_map_works_how_i_think )
+BOOST_AUTO_TEST_CASE(interval_map_works_how_i_think)
{
// Used as proof that setting and selecting ranges given an
// attempt to write to [offset, offset + size) will find
@@ -642,9 +661,9 @@ BOOST_AUTO_TEST_CASE( interval_map_works_how_i_think )
BOOST_REQUIRE(map.empty());
// Pretend we have 3 writes in progress
- map.insert({r(5, 10), std::make_shared<NetFS::FuseApp::OpenFile::WriteState>() }); // [5, 15)
- map.insert({r(15, 15), std::make_shared<NetFS::FuseApp::OpenFile::WriteState>() }); // [15, 30)
- map.insert({r(35, 10), std::make_shared<NetFS::FuseApp::OpenFile::WriteState>() }); // [35, 45)
+ map.insert({r(5, 10), std::make_shared<NetFS::FuseApp::OpenFile::WriteState>()}); // [5, 15)
+ map.insert({r(15, 15), std::make_shared<NetFS::FuseApp::OpenFile::WriteState>()}); // [15, 30)
+ map.insert({r(35, 10), std::make_shared<NetFS::FuseApp::OpenFile::WriteState>()}); // [35, 45)
// Then the following writes to [O, O+S) should wait on N pending writes
check(0, 1, 0); // Clear before
check(100, 10, 0); // Clear after
@@ -666,4 +685,3 @@ BOOST_AUTO_TEST_CASE( interval_map_works_how_i_think )
map.erase(r(35, 10));
BOOST_REQUIRE(map.empty());
}
-
diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp
index b0d0098..01eb6b7 100644
--- a/netfs/unittests/testEdgeCases.cpp
+++ b/netfs/unittests/testEdgeCases.cpp
@@ -1,34 +1,32 @@
#define BOOST_TEST_MODULE TestNetFSEdgeCases
-#include <boost/test/unit_test.hpp>
#include "mockDaemon.h"
#include "mockFuse.h"
+#include <boost/test/unit_test.hpp>
#include <definedDirs.h>
const std::string testEndpoint("tcp -h localhost -p 12014");
-BOOST_AUTO_TEST_CASE ( createAndDaemonRestart )
+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()
- });
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
+ FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string()});
- struct statvfs s {};
- BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &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());
@@ -55,56 +53,41 @@ BOOST_AUTO_TEST_CASE ( createAndDaemonRestart )
BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh));
}
-BOOST_AUTO_TEST_CASE( noDaemonAtStartUp )
+BOOST_AUTO_TEST_CASE(noDaemonAtStartUp)
{
- FuseMockHost fuse(testEndpoint, {
- (rootDir / "defaultFuse.xml:testvol").string(),
- (rootDir / "test").string()
- });
+ FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string()});
- struct statvfs s {};
- BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
- MockDaemonHost daemon(testEndpoint, {
- "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()
- });
+ struct statvfs s {
+ };
+ BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
- BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
}
-BOOST_AUTO_TEST_CASE ( daemonUnavailableAfterUse )
+BOOST_AUTO_TEST_CASE(daemonUnavailableAfterUse)
{
- FuseMockHost fuse(testEndpoint, {
- (rootDir / "defaultFuse.xml:testvol").string(),
- (rootDir / "test").string()
- });
- struct statvfs s {};
+ FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string()});
+ struct statvfs s {
+ };
{
- MockDaemonHost daemon(testEndpoint, {
- "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()
- });
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
- BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
}
- BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
{
- MockDaemonHost daemon(testEndpoint, {
- "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()
- });
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
- BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
}
- BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
+ BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s));
}
-BOOST_AUTO_TEST_CASE( manyThreads )
+BOOST_AUTO_TEST_CASE(manyThreads)
{
- MockDaemonHost daemon(testEndpoint, {
- "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()
- });
- FuseMockHost fuse(testEndpoint, {
- (rootDir / "defaultFuse.xml:testvol").string(),
- (rootDir / "test").string()
- });
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
+ FuseMockHost fuse(testEndpoint, {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string()});
bool running = true;
std::vector<std::thread> ths;
@@ -112,8 +95,9 @@ BOOST_AUTO_TEST_CASE( manyThreads )
std::atomic_uint success = 0;
for (int x = 0; x < 20; x++) {
ths.emplace_back([&] {
- struct statvfs s {};
- while(running && success < 1600) {
+ struct statvfs s {
+ };
+ while (running && success < 1600) {
if (fuse.fuse->statfs("/", &s) == 0) {
success++;
}
@@ -126,11 +110,10 @@ BOOST_AUTO_TEST_CASE( manyThreads )
daemon.restart();
sleep(1);
running = false;
-
+
for (auto & th : ths) {
th.join();
}
BOOST_CHECK_GT(success, 800);
}
-
diff --git a/netfs/unittests/testFuse.cpp b/netfs/unittests/testFuse.cpp
index b856e15..ded7077 100644
--- a/netfs/unittests/testFuse.cpp
+++ b/netfs/unittests/testFuse.cpp
@@ -1,78 +1,79 @@
#define BOOST_TEST_MODULE TestNetFSFuse
+#include "mockDaemon.h"
#include <boost/test/unit_test.hpp>
+#include <cache.impl.h>
#include <definedDirs.h>
#include <filesystem>
-#include <ostream>
-#include <thread>
#include <fuse.h>
#include <fuseApp.h>
-#include <cache.impl.h>
-#include "mockDaemon.h"
+#include <ostream>
+#include <thread>
-static const std::filesystem::path mntpnt { binDir / "mnt" };
+static const std::filesystem::path mntpnt {binDir / "mnt"};
const std::string testEndpoint("tcp -h localhost -p 12015");
const std::string testUri("tcp://localhost:12015/testvol");
class FuseMountPoint : public MockDaemonHost, public NetFS::FuseApp {
- public:
- FuseMountPoint() :
- MockDaemonHost(::testEndpoint, {
- "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()
- }),
- NetFS::FuseApp({::testUri})
- {
- std::filesystem::remove(mntpnt);
- std::filesystem::create_directory(mntpnt);
- struct fuse_args 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);
- BOOST_REQUIRE(fs);
- BOOST_REQUIRE_EQUAL(0,::fuse_mount(fs, mntpnt.c_str()));
- th = std::make_unique<std::thread>(::fuse_loop, fs);
- }
-
- ~FuseMountPoint() override
- {
- ::fuse_unmount(fs);
- if (th) {
- th->join();
- }
- std::filesystem::remove(mntpnt);
+public:
+ FuseMountPoint() :
+ MockDaemonHost(::testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()}),
+ NetFS::FuseApp({::testUri})
+ {
+ std::filesystem::remove(mntpnt);
+ std::filesystem::create_directory(mntpnt);
+ struct fuse_args 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);
+ BOOST_REQUIRE(fs);
+ BOOST_REQUIRE_EQUAL(0, ::fuse_mount(fs, mntpnt.c_str()));
+ th = std::make_unique<std::thread>(::fuse_loop, fs);
+ }
+
+ ~FuseMountPoint() override
+ {
+ ::fuse_unmount(fs);
+ if (th) {
+ th->join();
}
-
- FuseMountPoint(const FuseMountPoint &) = delete;
- FuseMountPoint(FuseMountPoint &&) = delete;
-
- FuseMountPoint & operator=(const FuseMountPoint &) = delete;
- FuseMountPoint & operator=(FuseMountPoint &&) = delete;
-
- struct fuse_context * fuse_get_context() override
- {
- return ::fuse_get_context();
- }
-
- static inline char * vstrdupf(const char * fmt, va_list args)
- {
- char * out {};
- BOOST_REQUIRE_GE(vasprintf(&out, fmt, args), 0);
- BOOST_REQUIRE(out);
- return out;
- }
-
- void vlogf(int, const char * fmt, va_list args) const noexcept override
- {
- std::unique_ptr<char, void(*)(void*)> msg(vstrdupf(fmt, args), std::free);
- BOOST_TEST_MESSAGE(msg.get());
- }
-
- struct fuse * fs;
- std::unique_ptr<std::thread> th;
+ std::filesystem::remove(mntpnt);
+ }
+
+ FuseMountPoint(const FuseMountPoint &) = delete;
+ FuseMountPoint(FuseMountPoint &&) = delete;
+
+ FuseMountPoint & operator=(const FuseMountPoint &) = delete;
+ FuseMountPoint & operator=(FuseMountPoint &&) = delete;
+
+ struct fuse_context *
+ fuse_get_context() override
+ {
+ return ::fuse_get_context();
+ }
+
+ static inline char *
+ vstrdupf(const char * fmt, va_list args)
+ {
+ char * out {};
+ BOOST_REQUIRE_GE(vasprintf(&out, fmt, args), 0);
+ BOOST_REQUIRE(out);
+ return out;
+ }
+
+ void
+ vlogf(int, const char * fmt, va_list args) const noexcept override
+ {
+ std::unique_ptr<char, void (*)(void *)> msg(vstrdupf(fmt, args), std::free);
+ BOOST_TEST_MESSAGE(msg.get());
+ }
+
+ struct fuse * fs;
+ std::unique_ptr<std::thread> th;
};
-#define BOOST_CHECK_EQUAL_FIELD(left, right, field) \
- BOOST_CHECK_EQUAL((left).field, (right).field);
+#define BOOST_CHECK_EQUAL_FIELD(left, right, field) BOOST_CHECK_EQUAL((left).field, (right).field);
#define BOOST_CHECK_EQUAL_STAT(left, right) \
BOOST_CHECK_NE(&(left), &(right)); \
@@ -86,13 +87,13 @@ class FuseMountPoint : public MockDaemonHost, public NetFS::FuseApp {
BOOST_CHECK_EQUAL_FIELD(left, right, st_rdev); \
BOOST_CHECK_EQUAL_FIELD(left, right, st_size); \
BOOST_CHECK_EQUAL_FIELD(left, right, st_blksize); \
- BOOST_CHECK_EQUAL_FIELD(left, right, st_blocks); \
+ BOOST_CHECK_EQUAL_FIELD(left, right, st_blocks);
-static
-auto
+static auto
get_lstat(const std::filesystem::path & p)
{
- struct stat st { };
+ struct stat st {
+ };
BOOST_TEST_INFO(p);
BOOST_REQUIRE_EQUAL(::lstat(p.c_str(), &st), 0);
return st;
@@ -100,12 +101,12 @@ get_lstat(const std::filesystem::path & p)
BOOST_FIXTURE_TEST_SUITE(fmp, FuseMountPoint);
-BOOST_AUTO_TEST_CASE(fuse, * boost::unit_test::timeout(5))
+BOOST_AUTO_TEST_CASE(fuse, *boost::unit_test::timeout(5))
{
BOOST_REQUIRE(std::filesystem::is_directory(mntpnt));
}
-BOOST_AUTO_TEST_CASE(fuse_ls, * boost::unit_test::timeout(5))
+BOOST_AUTO_TEST_CASE(fuse_ls, *boost::unit_test::timeout(5))
{
BOOST_REQUIRE(std::filesystem::is_directory(mntpnt));
BOOST_REQUIRE(std::filesystem::is_empty(mntpnt));
@@ -151,4 +152,3 @@ BOOST_AUTO_TEST_CASE(url_params_2)
auto fcs = NetFS::FuseApp::configureFromUri("tcp://localhost/foo?0&async=0");
BOOST_CHECK_EQUAL(fcs->Async, false);
}
-
diff --git a/netfs/unittests/testGlacier.cpp b/netfs/unittests/testGlacier.cpp
index f4474fb..47782c5 100644
--- a/netfs/unittests/testGlacier.cpp
+++ b/netfs/unittests/testGlacier.cpp
@@ -1,37 +1,36 @@
#define BOOST_TEST_MODULE TestNetFSGlacier
-#include <boost/test/unit_test.hpp>
#include "mockDaemon.h"
#include "mockFuse.h"
#include <boost/scope_exit.hpp>
+#include <boost/test/unit_test.hpp>
#include <definedDirs.h>
const std::string testEndpoint("tcp -h localhost -p 12013");
#define PID "/tmp/glacier.pid"
-BOOST_AUTO_TEST_CASE ( withRouter )
+BOOST_AUTO_TEST_CASE(withRouter)
{
std::filesystem::remove(PID);
BOOST_REQUIRE_EQUAL(0,
- system("/usr/bin/glacier2router --Glacier2.Client.Endpoints='tcp -p 14063' --Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier --daemon --pidfile " PID));
+ system("/usr/bin/glacier2router --Glacier2.Client.Endpoints='tcp -p 14063' "
+ "--Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier --daemon --pidfile " PID));
sleep(1);
- BOOST_SCOPE_EXIT(void) {
+ BOOST_SCOPE_EXIT(void)
+ {
BOOST_REQUIRE_EQUAL(0, system("kill $(cat " PID ")"));
std::filesystem::remove(PID);
- } BOOST_SCOPE_EXIT_END;
+ }
+ BOOST_SCOPE_EXIT_END;
{
- MockDaemonHost daemon(testEndpoint, {
- "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()
- });
- FuseMockHost fuse(testEndpoint, {
- (rootDir / "defaultFuse.xml:testvol").string(),
- (rootDir / "test").string(),
- "--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 14063"
- });
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
+ FuseMockHost fuse(testEndpoint,
+ {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string(),
+ "--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 14063"});
- struct statvfs s {};
- BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
+ struct statvfs s {
+ };
+ BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
}
}
-
diff --git a/netfs/unittests/testLib.cpp b/netfs/unittests/testLib.cpp
index 1e80590..b44ab37 100644
--- a/netfs/unittests/testLib.cpp
+++ b/netfs/unittests/testLib.cpp
@@ -1,11 +1,12 @@
#define BOOST_TEST_MODULE TestNetFSLib
-#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
+#include <boost/test/unit_test.hpp>
#include <entCache.impl.h>
#include <lockHelpers.h>
namespace std {
- ostream & operator<<(ostream & strm, const ResolvedAs & r)
+ ostream &
+ operator<<(ostream & strm, const ResolvedAs & r)
{
strm << r;
return strm;
@@ -13,11 +14,7 @@ namespace std {
}
struct TestEntry {
- TestEntry(int i, std::string n) :
- id(i),
- name(std::move(n))
- {
- }
+ TestEntry(int i, std::string n) : id(i), name(std::move(n)) { }
int id;
std::string name;
@@ -34,10 +31,10 @@ EntCache<TestEntry>::fillCache() const
idcache->insert(std::make_shared<TestEntry>(3, "user3"));
}
-const auto GoodIds = boost::unit_test::data::make({ 1, 2, 3 });
-const auto BadIds = boost::unit_test::data::make({ 0, -1, 10 });
-const auto GoodNames = boost::unit_test::data::make({ "user1", "user2", "user3" });
-const auto BadNames = boost::unit_test::data::make({ "", "bad", "user4" });
+const auto GoodIds = boost::unit_test::data::make({1, 2, 3});
+const auto BadIds = boost::unit_test::data::make({0, -1, 10});
+const auto GoodNames = boost::unit_test::data::make({"user1", "user2", "user3"});
+const auto BadNames = boost::unit_test::data::make({"", "bad", "user4"});
BOOST_FIXTURE_TEST_SUITE(tec, TestEntCache);
@@ -70,8 +67,8 @@ BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id)
BOOST_AUTO_TEST_SUITE_END();
class TestEntCacheWithFallback : public TestEntCache {
- public:
- TestEntCacheWithFallback() : TestEntCache({ 4, "fallback" }) { }
+public:
+ TestEntCacheWithFallback() : TestEntCache({4, "fallback"}) { }
};
BOOST_FIXTURE_TEST_SUITE(tecfb, TestEntCacheWithFallback);
@@ -105,4 +102,3 @@ BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id)
}
BOOST_AUTO_TEST_SUITE_END();
-