diff options
-rw-r--r-- | Jamroot.jam | 4 | ||||
-rw-r--r-- | netfs/daemon/daemonService.cpp | 7 | ||||
-rw-r--r-- | netfs/daemon/daemonService.h | 7 | ||||
-rw-r--r-- | netfs/daemon/daemonVolume.cpp | 7 | ||||
-rw-r--r-- | netfs/daemon/daemonVolume.h | 9 | ||||
-rw-r--r-- | netfs/daemon/modeCheck.cpp | 5 | ||||
-rw-r--r-- | netfs/daemon/modeCheck.h | 10 | ||||
-rw-r--r-- | netfs/fuse/fuseApp.impl.h | 3 | ||||
-rw-r--r-- | netfs/ice/typeConverter.cpp | 4 | ||||
-rw-r--r-- | netfs/lib/defaultMapper.cpp | 19 | ||||
-rw-r--r-- | netfs/lib/defaultMapper.h | 10 | ||||
-rw-r--r-- | netfs/lib/entCache.cpp | 6 | ||||
-rw-r--r-- | netfs/lib/entCache.h | 25 | ||||
-rw-r--r-- | netfs/lib/entCache.impl.h | 11 | ||||
-rw-r--r-- | netfs/lib/entries.cpp | 16 | ||||
-rw-r--r-- | netfs/lib/entries.h | 27 | ||||
-rw-r--r-- | netfs/lib/entryResolver.h | 7 |
17 files changed, 104 insertions, 73 deletions
diff --git a/Jamroot.jam b/Jamroot.jam index 368a244..af15ca5 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -14,8 +14,7 @@ project <cxxstd>17 <visibility>hidden <linkflags>"-Wl,-z,defs,--warn-once,--gc-sections" - <variant>release:<cxxflags>"-flto=3" - <variant>release:<linkflags>"-flto=3" + <variant>release:<lto>on <variant>debug<toolset>gcc:<cxxflags>-Wlogical-op <variant>debug:<warnings>extra <variant>debug:<warnings-as-errors>on @@ -36,6 +35,7 @@ project <toolset>tidy:<exclude>slicer-daemonConfig.cpp <toolset>tidy:<exclude>fuseConfig.h <toolset>tidy:<exclude>slicer-fuseConfig.cpp + <toolset>tidy:<exclude>slicer-mapper.cpp <toolset>tidy:<exclude>directory.h <toolset>tidy:<exclude>exceptions.h <toolset>tidy:<exclude>file.h diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp index 18b050d..6ffcf71 100644 --- a/netfs/daemon/daemonService.cpp +++ b/netfs/daemon/daemonService.cpp @@ -1,9 +1,14 @@ #include "daemonService.h" #include "daemon.h" #include "daemonVolume.h" +#include <entCache.h> #include <safeMapFind.h> -ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) : config(std::move(c)) { } +ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) : + userLookup(std::make_shared<EntCache<User>>()), groupLookup(std::make_shared<EntCache<Group>>()), + config(std::move(c)) +{ +} NetFS::VolumePrxPtr ServiceServer::connect(const std::string share, const std::string authtoken, const Ice::Current & ice) diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h index e0f80ef..753583e 100644 --- a/netfs/daemon/daemonService.h +++ b/netfs/daemon/daemonService.h @@ -2,7 +2,8 @@ #define DAEMONSERVICE_H #include <daemonConfig.h> -#include <entCache.h> +#include <entries.h> +#include <entryResolver.h> #include <service.h> class ServiceServer : public NetFS::Service { @@ -12,8 +13,8 @@ public: NetFS::VolumePrxPtr connect(const std::string share, const std::string auth, const Ice::Current &) override; private: - EntCache<User> userLookup; - EntCache<Group> groupLookup; + EntryResolverPtr<User> userLookup; + EntryResolverPtr<Group> groupLookup; NetFS::Daemon::ConfigurationPtr config; }; diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index 7ae3a1f..ff75e06 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -16,9 +16,10 @@ 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(std::make_shared<NetFS::Mapping::DefaultMapper>()) +VolumeServer::VolumeServer( + const std::filesystem::path & r, const EntryResolverPtr<User> & u, const EntryResolverPtr<Group> & g) : + root(std::filesystem::canonical(r)), + userLookup(*u), groupLookup(*g), converter(std::make_shared<NetFS::Mapping::DefaultMapper>(u, g)) { } diff --git a/netfs/daemon/daemonVolume.h b/netfs/daemon/daemonVolume.h index b75c5d6..649d8c2 100644 --- a/netfs/daemon/daemonVolume.h +++ b/netfs/daemon/daemonVolume.h @@ -1,7 +1,8 @@ #ifndef DAEMONVOLUME_H #define DAEMONVOLUME_H -#include <entCache.h> +#include <entries.h> +#include <entryResolver.h> #include <filesystem> #include <shared_mutex> #include <typeConverter.h> @@ -9,7 +10,7 @@ class VolumeServer : public NetFS::Volume { public: - VolumeServer(const std::filesystem::path & root, const EntCache<User> &, const EntCache<Group> &); + VolumeServer(const std::filesystem::path & root, const EntryResolverPtr<User> &, const EntryResolverPtr<Group> &); NetFS::DirectoryPrxPtr opendir(const NetFS::ReqEnv, std::string path, const Ice::Current &) override; @@ -47,8 +48,8 @@ protected: private: const std::filesystem::path root; - const EntCache<User> & userLookup; - const EntCache<Group> & groupLookup; + EntryResolver<User> & userLookup; + EntryResolver<Group> & groupLookup; EntryTypeConverter converter; }; diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp index 6e65888..177d9b8 100644 --- a/netfs/daemon/modeCheck.cpp +++ b/netfs/daemon/modeCheck.cpp @@ -1,9 +1,8 @@ #include "modeCheck.h" -#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 EntryResolver<User> & u, + const EntryResolver<Group> & g) : myu(u.getEntry(re.user)->id), myg(g.getEntry(re.grp)->id), root(r), userLookup(u), groupLookup(g) { diff --git a/netfs/daemon/modeCheck.h b/netfs/daemon/modeCheck.h index 693ad8d..6365816 100644 --- a/netfs/daemon/modeCheck.h +++ b/netfs/daemon/modeCheck.h @@ -1,14 +1,16 @@ #ifndef NETFS_DAEMON_IOHELPERS #define NETFS_DAEMON_IOHELPERS -#include <entCache.h> +#include <entries.h> +#include <entryResolver.h> #include <filesystem> #include <sys/stat.h> #include <types.h> class ModeCheck { public: - ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path &, const EntCache<User> &, const EntCache<Group> &); + ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path &, const EntryResolver<User> &, + const EntryResolver<Group> &); void AssertReadParent(const std::filesystem::path &) const; void AssertRead(const std::filesystem::path &) const; @@ -27,8 +29,8 @@ public: private: static struct stat lstat(const std::filesystem::path &); - const EntCache<User> & userLookup; - const EntCache<Group> & groupLookup; + const EntryResolver<User> & userLookup; + const EntryResolver<Group> & groupLookup; }; #endif diff --git a/netfs/fuse/fuseApp.impl.h b/netfs/fuse/fuseApp.impl.h index e433ee7..9947f36 100644 --- a/netfs/fuse/fuseApp.impl.h +++ b/netfs/fuse/fuseApp.impl.h @@ -12,8 +12,7 @@ namespace NetFS { { 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...)); } diff --git a/netfs/ice/typeConverter.cpp b/netfs/ice/typeConverter.cpp index 6b33828..b1ade2b 100644 --- a/netfs/ice/typeConverter.cpp +++ b/netfs/ice/typeConverter.cpp @@ -1,7 +1,7 @@ #include "typeConverter.h" #include <boost/numeric/conversion/cast.hpp> -EntryTypeConverter::EntryTypeConverter(NetFS::Mapping::MapperPtr m) : mapper(m) { } +EntryTypeConverter::EntryTypeConverter(NetFS::Mapping::MapperPtr m) : mapper(std::move(m)) { } // Wrapper function to assure no unexpected corruption occurs // during narrowing assignments. @@ -67,7 +67,7 @@ EntryTypeConverter::convert(const struct stat & s) const NetFS::Attr a {}; a.dev = s.st_dev; a.inode = s.st_ino; - a.mode = s.st_mode & ~map.mask; + safeAssign(a.mode, s.st_mode & ~map.mask); a.links = s.st_nlink; a.uid = std::move(map.username); a.gid = std::move(map.groupname); diff --git a/netfs/lib/defaultMapper.cpp b/netfs/lib/defaultMapper.cpp index 1d75e12..27b20d3 100644 --- a/netfs/lib/defaultMapper.cpp +++ b/netfs/lib/defaultMapper.cpp @@ -1,12 +1,23 @@ #include "defaultMapper.h" +#include "entCache.h" #include <exceptions.h> namespace NetFS::Mapping { + DefaultMapper::DefaultMapper() : + DefaultMapper(std::make_shared<EntCache<User>>(), std::make_shared<EntCache<Group>>()) + { + } + + DefaultMapper::DefaultMapper(EntryResolverPtr<User> u, EntryResolverPtr<Group> g) : + users(std::move(u)), groups(std::move(g)) + { + } + FileSystem DefaultMapper::mapTransport(const std::string & un, const std::string & gn) { - auto u = users.getEntry(un); - auto g = groups.getEntry(gn); + auto u = users->getEntry(un); + auto g = groups->getEntry(gn); if (!u || !g) { throw NetFS::SystemError(EPERM); } @@ -16,8 +27,8 @@ namespace NetFS::Mapping { Transport DefaultMapper::mapFileSystem(int uid, int gid) { - auto u = users.getEntry(uid); - auto g = groups.getEntry(gid); + auto u = users->getEntry(uid); + auto g = groups->getEntry(gid); if (!u || !g) { throw NetFS::SystemError(EPERM); } diff --git a/netfs/lib/defaultMapper.h b/netfs/lib/defaultMapper.h index 719c7bf..214f9ed 100644 --- a/netfs/lib/defaultMapper.h +++ b/netfs/lib/defaultMapper.h @@ -1,19 +1,23 @@ #ifndef NETFS_MAPPING_DEFAULTIMPL_H #define NETFS_MAPPING_DEFAULTIMPL_H -#include "entCache.h" +#include "entries.h" +#include "entryResolver.h" #include <mapper.h> namespace NetFS { namespace Mapping { class DefaultMapper : public Mapper { public: + DefaultMapper(); + DefaultMapper(EntryResolverPtr<User> users, EntryResolverPtr<Group> groups); + Transport mapFileSystem(int uid, int gid) override; FileSystem mapTransport(const std::string & un, const std::string & gn) override; protected: - UserEntCache users; - GroupEntCache groups; + EntryResolverPtr<User> users; + EntryResolverPtr<Group> groups; }; } } diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index d9f61df..e1a20a5 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -1,9 +1,5 @@ #include "entCache.impl.h" - -static_assert(std::is_nothrow_move_constructible_v<User>); -static_assert(std::is_nothrow_move_assignable_v<User>); -static_assert(std::is_nothrow_move_constructible_v<Group>); -static_assert(std::is_nothrow_move_assignable_v<Group>); +#include "entries.h" template class EntCache<User>; template class EntCache<Group>; diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index 02224f5..7a9a3ef 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -3,29 +3,7 @@ #include "entryResolver.h" #include <c++11Helpers.h> -#include <set> #include <shared_mutex> -#include <string> -#include <unistd.h> - -class User { -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); - - bool hasMember(uid_t) const; - - gid_t id; - std::string name; - std::set<uid_t> members; -}; template<class entry_t> class EntCache : public EntryResolver<entry_t> { public: @@ -58,7 +36,4 @@ protected: mutable time_t fillTime {0}; }; -using UserEntCache = EntCache<User>; -using GroupEntCache = EntCache<Group>; - #endif diff --git a/netfs/lib/entCache.impl.h b/netfs/lib/entCache.impl.h index 6243d7d..ad8fb33 100644 --- a/netfs/lib/entCache.impl.h +++ b/netfs/lib/entCache.impl.h @@ -2,6 +2,7 @@ #define ENTCACHE_IMPL_H #include "entCache.h" +#include "entries.h" #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index_container.hpp> @@ -50,8 +51,6 @@ EntCache<entry_t>::getEntryNoFill(const key_t & key) const noexcept return nullptr; } -User::User(uid_t u, std::string n, gid_t g) : id(u), name(std::move(n)), group(g) { } - const int BUFLEN = 8196; template<> @@ -71,8 +70,6 @@ EntCache<User>::fillCache() const noexcept time(&fillTime); } -Group::Group(gid_t g, std::string n) : id(g), name(std::move(n)) { } - template<> void EntCache<Group>::fillCache() const noexcept @@ -97,10 +94,4 @@ EntCache<Group>::fillCache() const noexcept time(&fillTime); } -bool -Group::hasMember(uid_t u) const -{ - return (members.find(u) != members.end()); -} - #endif diff --git a/netfs/lib/entries.cpp b/netfs/lib/entries.cpp new file mode 100644 index 0000000..bde15e6 --- /dev/null +++ b/netfs/lib/entries.cpp @@ -0,0 +1,16 @@ +#include "entries.h" + +static_assert(std::is_nothrow_move_constructible_v<User>); +static_assert(std::is_nothrow_move_assignable_v<User>); +static_assert(std::is_nothrow_move_constructible_v<Group>); +static_assert(std::is_nothrow_move_assignable_v<Group>); + +User::User(uid_t u, std::string n, gid_t g) : id(u), name(std::move(n)), group(g) { } + +Group::Group(gid_t g, std::string n) : id(g), name(std::move(n)) { } + +bool +Group::hasMember(uid_t u) const noexcept +{ + return (members.find(u) != members.end()); +} diff --git a/netfs/lib/entries.h b/netfs/lib/entries.h new file mode 100644 index 0000000..6e032e1 --- /dev/null +++ b/netfs/lib/entries.h @@ -0,0 +1,27 @@ +#ifndef ENTRIES_H +#define ENTRIES_H + +#include <set> +#include <string> +#include <unistd.h> + +class User { +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); + + bool hasMember(uid_t) const noexcept; + + gid_t id; + std::string name; + std::set<uid_t> members; +}; + +#endif diff --git a/netfs/lib/entryResolver.h b/netfs/lib/entryResolver.h index 84eb6ed..86aaace 100644 --- a/netfs/lib/entryResolver.h +++ b/netfs/lib/entryResolver.h @@ -6,9 +6,12 @@ template<typename entry_t> class EntryResolver { public: virtual ~EntryResolver() noexcept = default; + using EntryPtr = std::shared_ptr<entry_t>; - virtual std::shared_ptr<entry_t> getEntry(const decltype(entry_t::id) &) const noexcept = 0; - virtual std::shared_ptr<entry_t> getEntry(const decltype(entry_t::name) &) const noexcept = 0; + virtual EntryPtr getEntry(const decltype(entry_t::id) &) const noexcept = 0; + virtual EntryPtr getEntry(const decltype(entry_t::name) &) const noexcept = 0; }; +template<typename entry_t> using EntryResolverPtr = std::shared_ptr<EntryResolver<entry_t>>; + #endif |