Add a new factory with separated plugin interfaces.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 23 Feb 2014 15:27:21 +0000 (16:27 +0100)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 23 Feb 2014 15:59:24 +0000 (16:59 +0100)
src/CMakeLists.txt
src/xattr/CMakeLists.txt [new file with mode: 0644]
src/xattr/VfsXattrFactory.cpp [new file with mode: 0644]
src/xattr/VfsXattrFactory.h [new file with mode: 0644]

index 7e1d270..1032962 100644 (file)
@@ -1,5 +1,9 @@
 cmake_minimum_required (VERSION 2.6)
 
+include_directories (.)
+
+add_subdirectory (xattr)
+
 add_library (vfs MODULE Vfs.cpp
                         VfsAuthn.cpp
                         VfsAuthnSimple.cpp
@@ -8,6 +12,7 @@ add_library (vfs MODULE Vfs.cpp
                         VfsNs.cpp
                         VfsPool.cpp
                         Throw.cpp
+                        ${DMLITE_VFS_XATTR_SOURCES}
             )
 
 target_link_libraries (vfs ${DMLITE_LIBRARIES} -lattr)
diff --git a/src/xattr/CMakeLists.txt b/src/xattr/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0a3b1c9
--- /dev/null
@@ -0,0 +1,4 @@
+cmake_minimum_required (VERSION 2.6)
+
+set(DMLITE_VFS_XATTR_SOURCES xattr/VfsXattrFactory.cpp
+    PARENT_SCOPE)
diff --git a/src/xattr/VfsXattrFactory.cpp b/src/xattr/VfsXattrFactory.cpp
new file mode 100644 (file)
index 0000000..e8e8d0e
--- /dev/null
@@ -0,0 +1,184 @@
+/// @file   VfsXattrFactory.cpp
+/// @brief  VFS Plugin entry point.
+#include <cstring>
+#include <dmlite/cpp/dmlite.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <sys/utsname.h>
+
+#include "Vfs.h"
+#include "VfsXattrFactory.h"
+#include "VfsAuthn.h"
+#include "VfsNs.h"
+#include "VfsDriver.h"
+#include "VfsIO.h"
+#include "VfsPool.h"
+
+
+using namespace dmlite;
+
+
+
+std::string VfsXattrFactory::getImplId() const throw ()
+{
+  return "VfsXattrFactory";
+}
+
+
+VfsXattrFactory::VfsXattrFactory() throw (DmException)
+{
+  struct utsname hname;
+
+  // Hostname
+  wrapCall(uname(&hname));
+
+  // Domain
+  struct hostent* hent = gethostbyname(hname.nodename);
+
+  this->hostName_ = hent->h_name;
+
+  openlog("dmlite-vfs-plugin", LOG_PID, LOG_USER);
+}
+
+
+
+VfsXattrFactory::~VfsXattrFactory()
+{
+  // Nothing
+}
+
+
+
+void VfsXattrFactory::configure(const std::string& key, const std::string& value) throw (DmException)
+{
+  if (key == "TokenPassword") {
+    this->tokenPasswd_ = value;
+  }
+  else if (key == "TokenId") {
+    if (strcasecmp(value.c_str(), "ip") == 0)
+      this->tokenUseIp_ = true;
+    else
+      this->tokenUseIp_ = false;
+  }
+  else if (key == "TokenLife") {
+    this->tokenLife_ = (unsigned)atoi(value.c_str());
+  }
+  else if (key == "Allow") {
+    this->allow_ = value;
+  }
+  else if (key == "Deny") {
+    this->deny_ = value;
+  }
+  else if (key == "AllowWrite") {
+    this->allowWrite_ = value;
+  }
+  else if (key == "DenyWrite") {
+    this->denyWrite_ = value;
+  }
+  else if (key == "NSPrefix") {
+    this->nsPrefix_ = value;
+  }
+  else if (key == "DiskPrefix") {
+    this->diskPrefix_ = value;
+  }
+  else
+    throw DmException(DMLITE_CFGERR(DMLITE_UNKNOWN_KEY),
+                      "Unrecognised option " + key);
+}
+
+
+
+Catalog* VfsXattrFactory::createCatalog(PluginManager*) throw (DmException)
+{
+  debug("");
+  return new VfsCatalog(this->hostName_, this->nsPrefix_, this->allow_, this->deny_, this->allowWrite_, this->denyWrite_);
+}
+
+
+
+PoolManager* VfsXattrFactory::createPoolManager(PluginManager*) throw (DmException)
+{
+  debug("");
+  return new VfsPoolManager(this->hostName_,
+                            this->tokenPasswd_, this->tokenUseIp_,
+                            this->tokenLife_);
+}
+
+
+
+std::string VfsXattrFactory::implementedPool() throw ()
+{
+  return "vfs";
+}
+
+
+
+PoolDriver* VfsXattrFactory::createPoolDriver() throw (DmException)
+{
+  debug("");
+  return new VfsPoolDriver(this->hostName_, this->nsPrefix_,
+                           this->tokenPasswd_, this->tokenUseIp_,
+                           this->tokenLife_);
+}
+
+
+
+IODriver* VfsXattrFactory::createIODriver(PluginManager*) throw (DmException)
+{
+  debug("");
+  return new VfsIODriver(this->diskPrefix_, this->tokenPasswd_, this->tokenUseIp_);
+}
+
+
+
+Authn* VfsXattrFactory::createAuthn(PluginManager*) throw (DmException)
+{
+  debug("");
+  return new VfsAuthn(this->nsPrefix_);
+}
+
+
+
+static void registerPluginVfsAuthn(PluginManager* pm) throw(DmException)
+{
+  VfsXattrFactory* vfsXattrFactory = new VfsXattrFactory();
+
+  pm->registerAuthnFactory(vfsXattrFactory);
+}
+
+
+
+static void registerPluginVfsCatalog(PluginManager* pm) throw(DmException)
+{
+  VfsXattrFactory* vfsXattrFactory = new VfsXattrFactory();
+
+  pm->registerCatalogFactory(vfsXattrFactory);
+  pm->registerPoolManagerFactory(vfsXattrFactory);
+}
+
+
+
+static void registerPluginVfsDisk(PluginManager* pm) throw(DmException)
+{
+  VfsXattrFactory* vfsXattrFactory = new VfsXattrFactory();
+
+  pm->registerPoolDriverFactory(vfsXattrFactory);
+  pm->registerIOFactory(vfsXattrFactory);
+}
+
+
+
+
+/// This is what the PluginManager looks for
+PluginIdCard plugin_vfs_authn = {
+  PLUGIN_ID_HEADER,
+  registerPluginVfsAuthn
+};
+PluginIdCard plugin_vfs_ns = {
+  PLUGIN_ID_HEADER,
+  registerPluginVfsCatalog
+};
+PluginIdCard plugin_vfs_disk = {
+  PLUGIN_ID_HEADER,
+  registerPluginVfsDisk
+};
diff --git a/src/xattr/VfsXattrFactory.h b/src/xattr/VfsXattrFactory.h
new file mode 100644 (file)
index 0000000..6e32857
--- /dev/null
@@ -0,0 +1,52 @@
+/// @file   VfsXattrFactory.h
+/// @brief  Filesystem plugin with user extended attributes metadata extensions.
+#ifndef VFS_XATTR_FACTORY_H
+#define        VFS_XATTR_FACTORY_H
+
+#include <syslog.h>
+#include <dmlite/cpp/authn.h>
+#include <dmlite/cpp/catalog.h>
+#include <dmlite/cpp/dmlite.h>
+#include <dmlite/cpp/io.h>
+#include <dmlite/cpp/poolmanager.h>
+
+
+namespace dmlite {
+
+  class VfsXattrFactory: public CatalogFactory, public IOFactory,
+                    public PoolManagerFactory, public PoolDriverFactory,
+                    public AuthnFactory
+  {
+  public:
+    VfsXattrFactory() throw (DmException);
+    ~VfsXattrFactory();
+
+    void configure(const std::string& key, const std::string& value) throw (DmException);
+
+    Catalog*     createCatalog(PluginManager*)     throw (DmException);
+    PoolManager* createPoolManager(PluginManager*) throw (DmException);
+
+    std::string  implementedPool(void)  throw();
+    PoolDriver*  createPoolDriver(void) throw (DmException);
+
+    IODriver*    createIODriver(PluginManager*) throw (DmException);
+
+    Authn*       createAuthn(PluginManager *)      throw (DmException);
+
+  protected:
+    std::string hostName_;
+    std::string nsPrefix_;
+    std::string diskPrefix_;
+
+    std::string tokenPasswd_;
+    bool        tokenUseIp_;
+    unsigned    tokenLife_;
+    std::string allow_, deny_, allowWrite_, denyWrite_;
+
+  private:
+    std::string getImplId(void) const throw ();
+  };
+
+};
+
+#endif // VFS_XATTR_FACTORY_H