summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-05-23 10:13:56 +0000
committerrandomdan <randomdan@localhost>2014-05-23 10:13:56 +0000
commitb12d5d10f81b51681ac4b63ed49c6e72871de8bb (patch)
tree0b2959b52cc270fbd52fd818d43a02ff8ffb860a
parentAsynchronously call getattr for directory entries on readdir and cache them f... (diff)
downloadnetfs-b12d5d10f81b51681ac4b63ed49c6e72871de8bb.tar.bz2
netfs-b12d5d10f81b51681ac4b63ed49c6e72871de8bb.tar.xz
netfs-b12d5d10f81b51681ac4b63ed49c6e72871de8bb.zip
Use single shared entCache
-rw-r--r--netfs/daemon/daemonFile.cpp12
-rw-r--r--netfs/daemon/daemonFile.h6
-rw-r--r--netfs/daemon/daemonService.cpp2
-rw-r--r--netfs/daemon/daemonService.h3
-rw-r--r--netfs/daemon/daemonVolume.cpp92
-rw-r--r--netfs/daemon/daemonVolume.h11
6 files changed, 73 insertions, 53 deletions
diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp
index 0b94787..5c74fda 100644
--- a/netfs/daemon/daemonFile.cpp
+++ b/netfs/daemon/daemonFile.cpp
@@ -6,8 +6,10 @@
#include <sys/stat.h>
#include "daemonFile.h"
-FileServer::FileServer(int f) :
- fd(f)
+FileServer::FileServer(int f, UserEntCache * u, GroupEntCache * g) :
+ fd(f),
+ uentries(u),
+ gentries(g)
{
}
@@ -18,7 +20,7 @@ FileServer::~FileServer()
void
FileServer::ftruncate(const NetFS::ReqEnv & re, Ice::Long size, const Ice::Current&)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
if (::ftruncate(fd, size) != 0) {
throw NetFS::SystemError(errno);
@@ -28,13 +30,13 @@ FileServer::ftruncate(const NetFS::ReqEnv & re, Ice::Long size, const Ice::Curre
NetFS::Attr
FileServer::fgetattr(const NetFS::ReqEnv & re, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
struct stat s;
if (::fstat(fd, &s) != 0) {
throw NetFS::SystemError(errno);
}
NetFS::Attr a;
- a << StatSource { s, boost::bind(&UserEntCache::getName, &uentries, _1), boost::bind(&GroupEntCache::getName, &gentries, _1) };
+ a << StatSource { s, boost::bind(&UserEntCache::getName, uentries, _1), boost::bind(&GroupEntCache::getName, gentries, _1) };
return a;
}
diff --git a/netfs/daemon/daemonFile.h b/netfs/daemon/daemonFile.h
index 9f170e4..6493bf8 100644
--- a/netfs/daemon/daemonFile.h
+++ b/netfs/daemon/daemonFile.h
@@ -6,7 +6,7 @@
class FileServer : public NetFS::File {
public:
- FileServer(int fd);
+ FileServer(int fd, UserEntCache * u, GroupEntCache * g);
virtual ~FileServer();
virtual void close(const Ice::Current&) override;
@@ -19,8 +19,8 @@ class FileServer : public NetFS::File {
private:
const int fd;
- UserEntCache uentries;
- GroupEntCache gentries;
+ UserEntCache * uentries;
+ GroupEntCache * gentries;
};
#endif
diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp
index 024e5a5..3a2e823 100644
--- a/netfs/daemon/daemonService.cpp
+++ b/netfs/daemon/daemonService.cpp
@@ -16,6 +16,6 @@ ServiceServer::connect(const std::string & share, const std::string &, const Ice
if (e == config->exports.end()) {
throw NetFS::ConfigError();
}
- return NetFS::VolumePrx::checkedCast(ice.adapter->addWithUUID(new VolumeServer(e->second->root)));
+ return NetFS::VolumePrx::checkedCast(ice.adapter->addWithUUID(new VolumeServer(e->second->root, &uentries, &gentries)));
}
diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h
index 5618c84..7bdce16 100644
--- a/netfs/daemon/daemonService.h
+++ b/netfs/daemon/daemonService.h
@@ -12,6 +12,9 @@ class ServiceServer : public NetFS::Service {
private:
DaemonConfigPtr config;
const int16_t hostseed;
+
+ UserEntCache uentries;
+ GroupEntCache gentries;
};
#endif
diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp
index b87958b..ef64529 100644
--- a/netfs/daemon/daemonVolume.cpp
+++ b/netfs/daemon/daemonVolume.cpp
@@ -9,11 +9,14 @@
#include "daemonVolume.h"
#include "daemonFile.h"
#include "daemonDirectory.h"
+#include "lockHelpers.h"
extern std::map<Ice::Int, int> files;
-VolumeServer::VolumeServer(const boost::filesystem::path & r) :
- root(r)
+VolumeServer::VolumeServer(const boost::filesystem::path & r, UserEntCache * u, GroupEntCache * g) :
+ root(r),
+ uentries(u),
+ gentries(g)
{
}
@@ -30,31 +33,31 @@ VolumeServer::disconnect(const Ice::Current & ice)
Ice::Int
VolumeServer::access(const NetFS::ReqEnv & re, const std::string & path, Ice::Int mode, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
- boost::filesystem::path p = root / path;
+ TempPrivs tp(re, uentries, gentries);
+ boost::filesystem::path p(resolvePath(path));
return ::access(p.string().c_str(), mode);
}
NetFS::Attr
VolumeServer::getattr(const NetFS::ReqEnv & re, const std::string & path, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
struct stat s;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::lstat(p.string().c_str(), &s) != 0) {
throw NetFS::SystemError(errno);
}
NetFS::Attr a;
- a << StatSource { s, boost::bind(&UserEntCache::getName, &uentries, _1), boost::bind(&GroupEntCache::getName, &gentries, _1) };
+ a << StatSource { s, boost::bind(&UserEntCache::getName, uentries, _1), boost::bind(&GroupEntCache::getName, gentries, _1) };
return a;
}
void
VolumeServer::symlink(const NetFS::ReqEnv & re, const std::string & path1, const std::string & path2, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path2;
+ boost::filesystem::path p(resolvePath(path2));
if (::symlink(path1.c_str(), p.string().c_str()) != 0) {
throw NetFS::SystemError(errno);
}
@@ -63,10 +66,10 @@ VolumeServer::symlink(const NetFS::ReqEnv & re, const std::string & path1, const
void
VolumeServer::link(const NetFS::ReqEnv & re, const std::string & path1, const std::string & path2, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p1 = root / path1;
- boost::filesystem::path p2 = root / path2;
+ boost::filesystem::path p1(resolvePath(path1));
+ boost::filesystem::path p2(resolvePath(path2));
if (::link(p1.string().c_str(), p2.string().c_str()) != 0) {
throw NetFS::SystemError(errno);
}
@@ -75,10 +78,10 @@ VolumeServer::link(const NetFS::ReqEnv & re, const std::string & path1, const st
void
VolumeServer::rename(const NetFS::ReqEnv & re, const std::string & from, const std::string & to, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path f = root / from;
- boost::filesystem::path t = root / to;
+ boost::filesystem::path f(resolvePath(from));
+ boost::filesystem::path t(resolvePath(to));
if (::rename(f.string().c_str(), t.string().c_str()) != 0) {
throw NetFS::SystemError(errno);
}
@@ -87,10 +90,10 @@ VolumeServer::rename(const NetFS::ReqEnv & re, const std::string & from, const s
std::string
VolumeServer::readlink(const NetFS::ReqEnv & re, const std::string & path, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
char buf[PATH_MAX];
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
ssize_t rc = ::readlink(p.string().c_str(), buf, PATH_MAX);
if (rc == -1) {
throw NetFS::SystemError(errno);
@@ -101,9 +104,9 @@ VolumeServer::readlink(const NetFS::ReqEnv & re, const std::string & path, const
void
VolumeServer::chmod(const NetFS::ReqEnv & re, const std::string & path, Ice::Int mode, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::chmod(p.string().c_str(), mode) != 0) {
throw NetFS::SystemError(errno);
}
@@ -112,9 +115,9 @@ VolumeServer::chmod(const NetFS::ReqEnv & re, const std::string & path, Ice::Int
void
VolumeServer::chown(const NetFS::ReqEnv & re, const std::string & path, Ice::Int uid, Ice::Int gid, const Ice::Current &)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::lchown(p.string().c_str(), uid, gid) != 0) {
throw NetFS::SystemError(errno);
}
@@ -124,14 +127,14 @@ void
VolumeServer::utimens(const NetFS::ReqEnv & re, const std::string & path,
Ice::Long s0, Ice::Long ns0, Ice::Long s1, Ice::Long ns1, const Ice::Current&)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
struct timespec times[2];
times[0].tv_sec = s0;
times[0].tv_nsec = ns0;
times[1].tv_sec = s1;
times[1].tv_nsec = ns1;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::utimensat(0, p.string().c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
throw NetFS::SystemError(errno);
}
@@ -140,10 +143,10 @@ VolumeServer::utimens(const NetFS::ReqEnv & re, const std::string & path,
NetFS::VFS
VolumeServer::statfs(const NetFS::ReqEnv & re, const std::string & path, const Ice::Current&)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
struct statvfs s;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::statvfs(p.string().c_str(), &s) != 0) {
throw NetFS::SystemError(errno);
}
@@ -155,9 +158,9 @@ VolumeServer::statfs(const NetFS::ReqEnv & re, const std::string & path, const I
void
VolumeServer::truncate(const NetFS::ReqEnv & re, const std::string & path, Ice::Long size, const Ice::Current&)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::truncate(p.string().c_str(), size) != 0) {
throw NetFS::SystemError(errno);
}
@@ -166,9 +169,9 @@ VolumeServer::truncate(const NetFS::ReqEnv & re, const std::string & path, Ice::
void
VolumeServer::unlink(const NetFS::ReqEnv & re, const std::string & path, const Ice::Current&)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::unlink(p.string().c_str()) != 0) {
throw NetFS::SystemError(errno);
}
@@ -183,35 +186,35 @@ VolumeServer::openReadOnly(const NetFS::ReqEnv & re, const std::string & path, I
NetFS::FilePrx
VolumeServer::open(const NetFS::ReqEnv & re, const std::string & path, Ice::Int flags, const Ice::Current & ice)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
int fd = ::open(p.string().c_str(), flags);
if (fd == -1) {
throw NetFS::SystemError(errno);
}
- return NetFS::FilePrx::checkedCast(ice.adapter->addWithUUID(new FileServer(fd)));
+ return NetFS::FilePrx::checkedCast(ice.adapter->addWithUUID(new FileServer(fd, uentries, gentries)));
}
NetFS::FilePrx
VolumeServer::create(const NetFS::ReqEnv & re, const std::string & path, Ice::Int flags, Ice::Int mode, const Ice::Current & ice)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
int fd = ::open(p.string().c_str(), O_CREAT | flags, mode);
if (fd == -1) {
throw NetFS::SystemError(errno);
}
- return NetFS::FilePrx::checkedCast(ice.adapter->addWithUUID(new FileServer(fd)));
+ return NetFS::FilePrx::checkedCast(ice.adapter->addWithUUID(new FileServer(fd, uentries, gentries)));
}
NetFS::DirectoryPrx
VolumeServer::opendir(const NetFS::ReqEnv & re, const std::string & path, const Ice::Current & ice)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
DIR * od = ::opendir(p.string().c_str());
if (!od) {
throw NetFS::SystemError(errno);
@@ -222,9 +225,9 @@ VolumeServer::opendir(const NetFS::ReqEnv & re, const std::string & path, const
void
VolumeServer::mkdir(const NetFS::ReqEnv & re, const std::string & path, Ice::Int mode, const Ice::Current&)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::mkdir(p.string().c_str(), mode) != 0) {
throw NetFS::SystemError(errno);
}
@@ -233,11 +236,18 @@ VolumeServer::mkdir(const NetFS::ReqEnv & re, const std::string & path, Ice::Int
void
VolumeServer::rmdir(const NetFS::ReqEnv & re, const std::string & path, const Ice::Current&)
{
- TempPrivs tp(re, &uentries, &gentries);
+ TempPrivs tp(re, uentries, gentries);
errno = 0;
- boost::filesystem::path p = root / path;
+ boost::filesystem::path p(resolvePath(path));
if (::rmdir(p.string().c_str()) != 0) {
throw NetFS::SystemError(errno);
}
}
+boost::filesystem::path
+VolumeServer::resolvePath(const std::string & path) const
+{
+ Lock(lock);
+ return root / path;
+}
+
diff --git a/netfs/daemon/daemonVolume.h b/netfs/daemon/daemonVolume.h
index e8a5b72..c52e81a 100644
--- a/netfs/daemon/daemonVolume.h
+++ b/netfs/daemon/daemonVolume.h
@@ -3,10 +3,11 @@
#include <volume.h>
#include "entCache.h"
+#include <boost/thread/shared_mutex.hpp>
class VolumeServer : public NetFS::Volume {
public:
- VolumeServer(const boost::filesystem::path & root);
+ VolumeServer(const boost::filesystem::path & root, UserEntCache * u, GroupEntCache * g);
virtual ~VolumeServer();
virtual NetFS::DirectoryPrx opendir(const NetFS::ReqEnv &, const std::string & path, const Ice::Current&) override;
@@ -36,11 +37,15 @@ class VolumeServer : public NetFS::Volume {
virtual void disconnect(const Ice::Current&) override;
+ protected:
+ boost::filesystem::path resolvePath(const std::string & path) const;
+
private:
const boost::filesystem::path root;
+ mutable boost::shared_mutex lock;
- UserEntCache uentries;
- GroupEntCache gentries;
+ UserEntCache * uentries;
+ GroupEntCache * gentries;
};
#endif