From: František Dvořák Date: Tue, 15 Oct 2013 11:35:28 +0000 (+0200) Subject: Disk prefix - support in VFS IO Driver. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=729c580222814388a14ec39f1b1a6eae10948d44;p=dmlite-plugins-vfs.git Disk prefix - support in VFS IO Driver. --- diff --git a/src/Vfs.cpp b/src/Vfs.cpp index f4d76a5..ad943d7 100644 --- a/src/Vfs.cpp +++ b/src/Vfs.cpp @@ -121,7 +121,7 @@ PoolDriver* VfsFactory::createPoolDriver() throw (DmException) IODriver* VfsFactory::createIODriver(PluginManager*) throw (DmException) { syslog(LOG_DEBUG, "%s", __func__); - return new VfsIODriver(this->tokenPasswd_, this->tokenUseIp_); + return new VfsIODriver(this->diskPrefix_, this->tokenPasswd_, this->tokenUseIp_); } diff --git a/src/VfsIO.cpp b/src/VfsIO.cpp index 1bbd7e6..41111b1 100644 --- a/src/VfsIO.cpp +++ b/src/VfsIO.cpp @@ -10,8 +10,8 @@ using namespace dmlite; -VfsIODriver::VfsIODriver(std::string passwd, bool useIp): - si_(0), secCtx_(0), passwd_(passwd), useIp_(useIp) +VfsIODriver::VfsIODriver(const std::string& prefix, std::string passwd, bool useIp): + si_(0), secCtx_(0), prefix_(prefix), passwd_(passwd), useIp_(useIp) { // Nothing } @@ -69,7 +69,7 @@ IOHandler* VfsIODriver::createIOHandler(const std::string& pfn, } // Create - return new VfsIOHandler(pfn, flags, mode); + return new VfsIOHandler(pfn, prefix_, flags, mode); } @@ -80,7 +80,7 @@ void VfsIODriver::doneWriting(const Location &loc) throw (DmException) -VfsIOHandler::VfsIOHandler(const std::string& path, +VfsIOHandler::VfsIOHandler(const std::string& path, const std::string& prefix, int flags, mode_t mode) throw (DmException): eof_(false), pos_(0) { @@ -88,8 +88,10 @@ VfsIOHandler::VfsIOHandler(const std::string& path, if (path.compare(0, 5, "/vfs/") != 0) vfsThrow(EINVAL, "file not on the /vfs/ namespace"); - - real = path.substr(4); + + this->prefix_ = prefix; + + real = getLocalPath(path.substr(4)); this->fd_ = ::open(real.c_str(), flags, mode); syslog(LOG_DEBUG, "%s: open('%s', flags=%04X, mode=%04o) = %d", __func__, real.c_str(), flags, mode, this->fd_); @@ -179,3 +181,15 @@ bool VfsIOHandler::eof(void) throw (DmException) { return eof_; } + + + +const std::string VfsIOHandler::getLocalPath(const std::string &path) { + if (path.empty()) + return this->prefix_; + + if (path[0] != '/') + return this->prefix_ + "/" + path; + + return this->prefix_ + path; +} diff --git a/src/VfsIO.h b/src/VfsIO.h index 0f1abc8..e8e6d82 100644 --- a/src/VfsIO.h +++ b/src/VfsIO.h @@ -12,7 +12,7 @@ namespace dmlite { class VfsIODriver: public IODriver { public: - VfsIODriver(std::string passwd, bool useIp); + VfsIODriver(const std::string& prefix, std::string passwd, bool useIp); ~VfsIODriver(); std::string getImplId() const throw(); @@ -29,13 +29,14 @@ namespace dmlite { StackInstance* si_; const SecurityContext* secCtx_; + const std::string prefix_; std::string passwd_; bool useIp_; }; class VfsIOHandler: public IOHandler { public: - VfsIOHandler(const std::string& path, + VfsIOHandler(const std::string& path, const std::string& prefix, int flags, mode_t mode) throw (DmException); ~VfsIOHandler(); @@ -51,9 +52,11 @@ namespace dmlite { int fd_; bool eof_; long pos_; + std::string prefix_; private: std::string getImplId() const throw(); + const std::string getLocalPath(const std::string &path); }; };