Disk prefix - support in VFS IO Driver.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 15 Oct 2013 11:35:28 +0000 (13:35 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 15 Oct 2013 11:35:28 +0000 (13:35 +0200)
src/Vfs.cpp
src/VfsIO.cpp
src/VfsIO.h

index f4d76a5..ad943d7 100644 (file)
@@ -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_);
 }
 
 
index 1bbd7e6..41111b1 100644 (file)
@@ -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;
+}
index 0f1abc8..e8e6d82 100644 (file)
@@ -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);
   };
 
 };