From 5931fef7b0cb2317850f5f007dec2f3bbd6a7004 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 27 Jun 2014 18:31:36 +0000 Subject: Slice configuration for client --- netfs/etc/client.xml | 30 ++++++++++++++++++------------ netfs/fuse/Jamfile.jam | 24 +++++++++++++++++++++--- netfs/fuse/configuration.ice | 24 ++++++++++++++++++++++++ netfs/fuse/fuse.cpp | 23 ++++++++++++++++------- netfs/fuse/fuse.h | 10 +++++----- netfs/fuse/fuseConfig.cpp | 29 ----------------------------- netfs/fuse/fuseConfig.h | 33 --------------------------------- 7 files changed, 84 insertions(+), 89 deletions(-) create mode 100644 netfs/fuse/configuration.ice delete mode 100644 netfs/fuse/fuseConfig.cpp delete mode 100644 netfs/fuse/fuseConfig.h diff --git a/netfs/etc/client.xml b/netfs/etc/client.xml index 9eab8fc..b3af798 100644 --- a/netfs/etc/client.xml +++ b/netfs/etc/client.xml @@ -1,18 +1,24 @@ - - + + portage - - tcp -p 4000 -h localhost - - - + + portage + + tcp -p 4000 -h localhost + + + + store - - tcp -p 4000 -h defiant - - - + + store + + tcp -p 4000 -h defiant + + + + diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index 40a86f3..8814a9d 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -1,3 +1,6 @@ +lib slicer : : : : /usr/include/slicer ; +lib slicer-xml : : : : /usr/include/slicer ; + cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 ../../libmisc @@ -7,13 +10,26 @@ cpp-pch pch : pch.hpp : ..//boost_thread ..//fuse ..//Ice - ..//libxml2 ; +obj configuration : + configuration.ice + : + yes + ..//Ice + ..//IceUtil + ..//pthread + slicer + : : + ..//IceUtil + ..//Ice + ..//boost_system + slicer + ; exe netfs : pch - ../../libmisc/xml.cpp + configuration [ glob *.cpp ] [ glob ../../libfusepp/fuse*.cpp ] : @@ -21,6 +37,7 @@ exe netfs : ../../libmisc ../../libfusepp ../ice//netfsComms + configuration ../ice//netfsComms ../lib//netfsCommon ..//boost_thread @@ -29,6 +46,7 @@ exe netfs : ..//Ice ..//IceUtil ..//pthread - ..//libxml2 + slicer + slicer-xml ; diff --git a/netfs/fuse/configuration.ice b/netfs/fuse/configuration.ice new file mode 100644 index 0000000..6f76b37 --- /dev/null +++ b/netfs/fuse/configuration.ice @@ -0,0 +1,24 @@ +module NetFS { + module Client { + ["slicer:element:endpoint"] + sequence EndpointList; + + class Resource { + ["slicer:name:export"] + string ExportName; + + ["slicer:name:endpoints"] + EndpointList Endpoints; + }; + + ["slicer:key:name","slicer:value:resource","slicer:item:resource"] + dictionary ResourceMap; + + ["slicer:root:config"] + class Configuration { + ["slicer:name:resources"] + ResourceMap Resources; + }; + }; +}; + diff --git a/netfs/fuse/fuse.cpp b/netfs/fuse/fuse.cpp index 9887e7b..c0aca45 100644 --- a/netfs/fuse/fuse.cpp +++ b/netfs/fuse/fuse.cpp @@ -5,6 +5,8 @@ #include "lockHelpers.h" #include "cache.impl.h" #include +#include +#include template class Cache>>; template class OptimisticCallCacheable; @@ -35,7 +37,7 @@ void * NetFS::FuseApp::init(struct fuse_conn_info *) { ic = Ice::initialize(_argc, _argv); - fc = FuseConfig::Load(configPath); + fc = Slicer::Deserialize(configPath); return NULL; } @@ -51,9 +53,9 @@ NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) else if (arg[0] == '-') { return 1; } - else if (exportName.empty()) { + else if (resourceName.empty()) { const char * colon = strchr(arg, ':'); - exportName = colon + 1; + resourceName = colon + 1; configPath.assign(arg, colon); return 0; } @@ -69,12 +71,15 @@ NetFS::FuseApp::connectToService() { if (!service) { Lock(_lock); - FuseConfig::ExportPtr e = fc->exports[exportName]; - const std::string & ep = *e->endpoints.begin(); + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such resource: " + resourceName); + } + const std::string & ep = e->second->Endpoints.front(); service = NetFS::ServicePrx::checkedCast(ic->stringToProxy("Service:" + ep)); if (!service) { - throw "Invalid service proxy"; + throw std::runtime_error("Invalid service proxy: " + ep); } } } @@ -83,7 +88,11 @@ void NetFS::FuseApp::connectToVolume() { if (!volume) { - volume = service->connect(exportName, "bar"); + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such export: " + resourceName); + } + volume = service->connect(e->second->ExportName, "bar"); if (!volume) { throw "Invalid filesystem proxy"; } diff --git a/netfs/fuse/fuse.h b/netfs/fuse/fuse.h index 859c3e6..1f80686 100644 --- a/netfs/fuse/fuse.h +++ b/netfs/fuse/fuse.h @@ -1,11 +1,11 @@ -#ifndef FUSE_H -#define FUSE_H +#ifndef NETFS_FUSE_H +#define NETFS_FUSE_H #include #include #include #include "fuseapp.h" -#include "fuseConfig.h" +#include "configuration.h" #include "cache.h" namespace NetFS { @@ -91,14 +91,14 @@ namespace NetFS { int & _argc; char ** _argv; Ice::CommunicatorPtr ic; - FuseConfigPtr fc; + Client::ConfigurationPtr fc; mutable boost::shared_mutex _lock; NetFS::VolumePrx volume; NetFS::ServicePrx service; std::string mountPoint; - std::string exportName; + std::string resourceName; std::string configPath; OpenDirs openDirs; diff --git a/netfs/fuse/fuseConfig.cpp b/netfs/fuse/fuseConfig.cpp deleted file mode 100644 index 168550e..0000000 --- a/netfs/fuse/fuseConfig.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "pch.hpp" -#include "fuseConfig.h" -#include - -FuseConfigPtr -FuseConfig::Load(const std::string & path) -{ - xmlDoc * doc = xmlReadFile(path.c_str(), NULL, 0); - FuseConfigPtr dc = new FuseConfig(doc->children); - xmlFreeDoc(doc); - return dc; -} - -FuseConfig::FuseConfig(xmlNodePtr conf) -{ - foreachxml(exp, xmlGetNode(conf, "exports"), "export") { - ExportPtr e = new Export(exp); - exports[e->name] = e; - } -} - -FuseConfig::Export::Export(xmlNodePtr conf) : - name(xmlGetNodeValue(conf, "name")) -{ - foreachxml(ep, xmlGetNode(conf, "endpoints"), "endpoint") { - endpoints.insert(xmlGetNodeValue(ep)); - } -} - diff --git a/netfs/fuse/fuseConfig.h b/netfs/fuse/fuseConfig.h deleted file mode 100644 index 32f25b4..0000000 --- a/netfs/fuse/fuseConfig.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef FUSECONFIG_H -#define FUSECONFIG_H - -#include -#include -#include -#include -#include "xml.h" - -class FuseConfig : public IceUtil::Shared { - public: - class Export; - typedef IceUtil::Handle ExportPtr; - typedef std::map ExportMap; - class Export : public IceUtil::Shared { - public: - typedef std::set Endpoints; - Export(xmlNodePtr); - - std::string name; - Endpoints endpoints; - }; - - FuseConfig(xmlNodePtr); - static IceUtil::Handle Load(const std::string & path); - - ExportMap exports; -}; -typedef IceUtil::Handle FuseConfigPtr; - -#endif - - -- cgit v1.2.3