diff options
Diffstat (limited to 'netfs/daemon/daemonVolume.cpp')
-rw-r--r-- | netfs/daemon/daemonVolume.cpp | 92 |
1 files changed, 51 insertions, 41 deletions
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; +} + |