From 57c121a887ae8c5947089eafda5709fcba5c3726 Mon Sep 17 00:00:00 2001 From: randomdan Date: Mon, 2 Jun 2014 10:34:05 +0000 Subject: Use slicer for configuration reading, revise sample configs accordingly --- netfs/client.xml | 18 ------------- netfs/daemon.xml | 24 ----------------- netfs/daemon/Jamfile.jam | 27 ++++++++++++++++++-- netfs/daemon/configuration.ice | 34 +++++++++++++++++++++++++ netfs/daemon/daemon.cpp | 32 +++++++++++++++-------- netfs/daemon/daemon.h | 9 +++++-- netfs/daemon/daemonConfig.cpp | 58 ------------------------------------------ netfs/daemon/daemonConfig.h | 48 ---------------------------------- netfs/daemon/daemonService.cpp | 11 ++++---- netfs/daemon/daemonService.h | 5 ++-- netfs/etc/client.xml | 18 +++++++++++++ netfs/etc/daemon.xml | 29 +++++++++++---------- netfs/etc/init | 5 ++++ netfs/fuse/Jamfile.jam | 1 + netfs/lib/Jamfile.jam | 3 +-- 15 files changed, 135 insertions(+), 187 deletions(-) delete mode 100644 netfs/client.xml delete mode 100644 netfs/daemon.xml create mode 100644 netfs/daemon/configuration.ice delete mode 100644 netfs/daemon/daemonConfig.cpp delete mode 100644 netfs/daemon/daemonConfig.h create mode 100644 netfs/etc/client.xml diff --git a/netfs/client.xml b/netfs/client.xml deleted file mode 100644 index 9eab8fc..0000000 --- a/netfs/client.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - portage - - tcp -p 4000 -h localhost - - - - store - - tcp -p 4000 -h defiant - - - - - diff --git a/netfs/daemon.xml b/netfs/daemon.xml deleted file mode 100644 index 5e1ef0c..0000000 --- a/netfs/daemon.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - tcp -p 4000 - akira - - - tcp -p 4000 - riogrande - - - - - portage - /usr/portage - - akira - vmware2 - - - - - diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam index 1ea5dca..766c9a5 100644 --- a/netfs/daemon/Jamfile.jam +++ b/netfs/daemon/Jamfile.jam @@ -1,12 +1,33 @@ +lib slicer : : : : /usr/include/slicer ; +lib slicer-xml : : : : /usr/include/slicer ; + cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 ../../libmisc ../ice//netfsComms + netfsdConfiguration ../ice//netfsComms ../lib//netfsCommon ..//boost_thread ..//Ice - ..//libxml2 + ; + +lib netfsdConfiguration : + configuration.ice + : + ..//Ice + ..//IceUtil + ..//pthread + ..//boost_filesystem + ..//boost_system + slicer + yes + : : + . + ..//IceUtil + ..//Ice + ..//boost_system + slicer ; lib netfsd : @@ -16,6 +37,8 @@ lib netfsd : _FILE_OFFSET_BITS=64 ../libmisc ../ice//netfsComms + netfsdConfiguration + netfsdConfiguration ../ice//netfsComms ../lib//netfsCommon ..//boost_random @@ -25,7 +48,7 @@ lib netfsd : ..//Ice ..//IceUtil ..//IceBox - ..//libxml2 + slicer-xml ; diff --git a/netfs/daemon/configuration.ice b/netfs/daemon/configuration.ice new file mode 100644 index 0000000..bb77344 --- /dev/null +++ b/netfs/daemon/configuration.ice @@ -0,0 +1,34 @@ +module NetFS { + module Daemon { + class Host { + ["slicer:name:endpoint"] + string Endpoint; + }; + + ["slicer:key:hostname","slicer:value:host","slicer:item:host"] + dictionary HostMap; + + class Export { + ["slicer:name:root"] + string RootPath; + }; + + ["slicer:key:name","slicer:value:export","slicer:item:export"] + dictionary ExportMap; + + ["slicer:root:config"] + class Configuration { + ["slicer:name:exports"] + ExportMap Exports; + + ["slicer:name:hosts"] + HostMap Hosts; + }; + + ["slicer:ignore"] + class RuntimeConfiguration { + Configuration CurrentConfiguration; + Host Self; + }; + }; +}; diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index 3736167..199ecaa 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -1,37 +1,47 @@ #include "pch.hpp" #include #include -#include #include "daemon.h" -#include "daemonConfig.h" #include "daemonService.h" #include "daemonVolume.h" +#include +#include #include "ioHelpers.h" #include -int16_t -makeHostID() +std::string +NetFSDaemon::hostname() { char buf[128]; gethostname(buf, sizeof(buf)); - boost::crc_basic<16> crc_ccitt1( 0x1021, 0xFFFF, 0, false, false ); - crc_ccitt1.process_bytes(buf, sizeof(buf)); - return crc_ccitt1.checksum(); + return buf; } // name = NetFSDaemonAdapter void NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq&) { + this->ic = ic; Ice::PropertiesPtr props = ic->getProperties(); - dc = DaemonConfig::Load(props->getProperty("NetFSD.ConfigPath")); + LoadConfiguration(props->getProperty("NetFSD.ConfigPath")); - int16_t hostseed = makeHostID(); - adapter = ic->createObjectAdapterWithEndpoints(name, dc->self->iceEndpoint); - adapter->add(new ServiceServer(hostseed, dc), ic->stringToIdentity("Service")); + adapter = ic->createObjectAdapterWithEndpoints(name, dc->Self->Endpoint); + adapter->add(new ServiceServer(dc->CurrentConfiguration), ic->stringToIdentity("Service")); adapter->activate(); } +void +NetFSDaemon::LoadConfiguration(const boost::filesystem::path & path) +{ + dc = new NetFS::Daemon::RuntimeConfiguration(); + dc->CurrentConfiguration = Slicer::Deserialize(path); + auto selfItr = dc->CurrentConfiguration->Hosts.find(hostname()); + if (selfItr == dc->CurrentConfiguration->Hosts.end()) { + throw std::runtime_error("This host is not defined in the configuration."); + } + dc->Self = selfItr->second; +} + void NetFSDaemon::stop() { diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index a28ddac..82af76e 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -7,7 +7,7 @@ #include #include #include -#include "daemonConfig.h" +#include #include #include @@ -17,8 +17,13 @@ class NetFSDaemon : public IceBox::Service { virtual void stop(); private: + void LoadConfiguration(const boost::filesystem::path & path); + + Ice::CommunicatorPtr ic; Ice::ObjectAdapterPtr adapter; - DaemonConfigPtr dc; + NetFS::Daemon::RuntimeConfigurationPtr dc; + + static std::string hostname(); }; class TempPrivs { diff --git a/netfs/daemon/daemonConfig.cpp b/netfs/daemon/daemonConfig.cpp deleted file mode 100644 index 7f75900..0000000 --- a/netfs/daemon/daemonConfig.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "pch.hpp" -#include "daemonConfig.h" -#include - -std::string -myHostname() -{ - char buf[128]; - gethostname(buf, sizeof(buf)); - return buf; -} - -bool -DaemonConfig::Host::operator<(const DaemonConfig::Host & other) const -{ - return (this->name < other.name); -} - -DaemonConfigPtr -DaemonConfig::Load(const std::string & path) -{ - xmlDoc * doc = xmlReadFile(path.c_str(), NULL, 0); - DaemonConfigPtr dc = new DaemonConfig(doc->children); - xmlFreeDoc(doc); - return dc; -} - -DaemonConfig::DaemonConfig(xmlNodePtr conf) -{ - foreachxml(hos, xmlGetNode(conf, "hosts"), "host") { - HostPtr h = new Host(hos); - hosts[h->name] = h; - if (h->self) { - self = h; - } - } - foreachxml(exp, xmlGetNode(conf, "exports"), "export") { - ExportPtr e = new Export(exp, hosts); - exports[e->name] = e; - } -} - -DaemonConfig::Export::Export(xmlNodePtr exp, const HostMap & hosts) : - root(xmlGetNodeValue(exp, "root")), - name(xmlGetNodeValue(exp, "name")) -{ - foreachxml(rep, xmlGetNode(exp, "replicate"), "name") { - replicate.insert(hosts.find(xmlGetNodeValue(rep))->second); - } -} - -DaemonConfig::Host::Host(xmlNodePtr hos) : - iceEndpoint(xmlGetNodeValue(hos, "endpoint")), - name(xmlGetNodeValue(hos, "name")), - self(name == myHostname()) -{ -} - diff --git a/netfs/daemon/daemonConfig.h b/netfs/daemon/daemonConfig.h deleted file mode 100644 index c4513cb..0000000 --- a/netfs/daemon/daemonConfig.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef DAEMONCONFIG_H -#define DAEMONCONFIG_H - -#include -#include -#include -#include -#include -#include "xml.h" - -class DaemonConfig : public IceUtil::Shared { - public: - class Host : public IceUtil::Shared { - public: - Host(xmlNodePtr); - - std::string iceEndpoint; - std::string name; - bool self; - bool operator<(const Host &) const; - }; - typedef IceUtil::Handle HostPtr; - typedef std::map HostMap; - typedef std::set HostSet; - - class Export : public IceUtil::Shared { - public: - Export(xmlNodePtr, const HostMap &); - - boost::filesystem::path root; - std::string name; - HostSet replicate; - }; - typedef IceUtil::Handle ExportPtr; - typedef std::map ExportMap; - - DaemonConfig(xmlNodePtr); - static IceUtil::Handle Load(const std::string & path); - - - ExportMap exports; - HostMap hosts; - HostPtr self; -}; -typedef IceUtil::Handle DaemonConfigPtr; - -#endif - diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp index 3a2e823..80305fd 100644 --- a/netfs/daemon/daemonService.cpp +++ b/netfs/daemon/daemonService.cpp @@ -2,9 +2,8 @@ #include "daemonService.h" #include "daemonVolume.h" -ServiceServer::ServiceServer(int16_t hs, DaemonConfigPtr c) : - config(c), - hostseed(hs) +ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) : + config(c) { } @@ -12,10 +11,10 @@ NetFS::VolumePrx ServiceServer::connect(const std::string & share, const std::string &, const Ice::Current & ice) { //boost::lock_guard lg(lock); - DaemonConfig::ExportMap::iterator e = config->exports.find(share); - if (e == config->exports.end()) { + NetFS::Daemon::ExportMap::iterator e = config->Exports.find(share); + if (e == config->Exports.end()) { throw NetFS::ConfigError(); } - return NetFS::VolumePrx::checkedCast(ice.adapter->addWithUUID(new VolumeServer(e->second->root, &uentries, &gentries))); + return NetFS::VolumePrx::checkedCast(ice.adapter->addWithUUID(new VolumeServer(e->second->RootPath, &uentries, &gentries))); } diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h index d41af54..4785dfa 100644 --- a/netfs/daemon/daemonService.h +++ b/netfs/daemon/daemonService.h @@ -6,13 +6,12 @@ class ServiceServer : public NetFS::Service { public: - ServiceServer(int16_t hostseed, DaemonConfigPtr c); + ServiceServer(NetFS::Daemon::ConfigurationPtr c); virtual NetFS::VolumePrx connect(const std::string & share, const std::string & auth, const Ice::Current&) override; private: - DaemonConfigPtr config; - const int16_t hostseed; + NetFS::Daemon::ConfigurationPtr config; UserEntCache uentries; GroupEntCache gentries; diff --git a/netfs/etc/client.xml b/netfs/etc/client.xml new file mode 100644 index 0000000..9eab8fc --- /dev/null +++ b/netfs/etc/client.xml @@ -0,0 +1,18 @@ + + + + + portage + + tcp -p 4000 -h localhost + + + + store + + tcp -p 4000 -h defiant + + + + + diff --git a/netfs/etc/daemon.xml b/netfs/etc/daemon.xml index 03e2c2a..ce1a0ff 100644 --- a/netfs/etc/daemon.xml +++ b/netfs/etc/daemon.xml @@ -1,16 +1,19 @@ - - - - - - + + + akira + + tcp -p 4000 + + + + + + portage + + /usr/portage + + + - diff --git a/netfs/etc/init b/netfs/etc/init index 4b8dc45..6e406c5 100644 --- a/netfs/etc/init +++ b/netfs/etc/init @@ -8,6 +8,11 @@ start() { /usr/bin/icebox \ --IceBox.Service.NetFSD=netfsd:createNetFSDaemon \ --NetFSD.ConfigPath=/etc/netfs/daemon.xml \ + --Ice.UseSyslog=1 \ + --Ice.ProgramName=netfsd \ + --Ice.SyslogFacility=LOG_DAEMON \ + --NetFSD.ThreadPool.SizeMax=200 \ + --NetFSD.ThreadPool.Size=8 \ --daemon --pidfile /var/run/netfsd.pid eend $? } diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index 873f67c..40a86f3 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -13,6 +13,7 @@ cpp-pch pch : pch.hpp : exe netfs : pch + ../../libmisc/xml.cpp [ glob *.cpp ] [ glob ../../libfusepp/fuse*.cpp ] : diff --git a/netfs/lib/Jamfile.jam b/netfs/lib/Jamfile.jam index bf6dd1a..45d40f1 100644 --- a/netfs/lib/Jamfile.jam +++ b/netfs/lib/Jamfile.jam @@ -6,12 +6,11 @@ cpp-pch pch : pch.hpp : lib netfsCommon : pch [ glob *.cpp ] - ../../libmisc/xml.cpp : + : _FILE_OFFSET_BITS=64 ../../libmisc ..//boost_system ..//boost_thread - ..//libxml2 ../ice//netfsComms ../ice//netfsComms : : -- cgit v1.2.3