From eddc79b4f292519e47428f75341023ea810a4d12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sun, 23 Feb 2014 16:27:21 +0100 Subject: [PATCH] Add a new factory with separated plugin interfaces. --- src/CMakeLists.txt | 5 ++ src/xattr/CMakeLists.txt | 4 + src/xattr/VfsXattrFactory.cpp | 184 ++++++++++++++++++++++++++++++++++++++++++ src/xattr/VfsXattrFactory.h | 52 ++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 src/xattr/CMakeLists.txt create mode 100644 src/xattr/VfsXattrFactory.cpp create mode 100644 src/xattr/VfsXattrFactory.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7e1d270..1032962 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..0a3b1c9 --- /dev/null +++ b/src/xattr/CMakeLists.txt @@ -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 index 0000000..e8e8d0e --- /dev/null +++ b/src/xattr/VfsXattrFactory.cpp @@ -0,0 +1,184 @@ +/// @file VfsXattrFactory.cpp +/// @brief VFS Plugin entry point. +#include +#include +#include +#include +#include + +#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 index 0000000..6e32857 --- /dev/null +++ b/src/xattr/VfsXattrFactory.h @@ -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 +#include +#include +#include +#include +#include + + +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 -- 1.8.2.3