summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-06-02 10:34:05 +0000
committerrandomdan <randomdan@localhost>2014-06-02 10:34:05 +0000
commit57c121a887ae8c5947089eafda5709fcba5c3726 (patch)
tree31f7856aa9a31e416cf7d2de7512450dd99d9b0c
parentTest st_mode for the correct masks in ExecutableBy helper (diff)
downloadnetfs-57c121a887ae8c5947089eafda5709fcba5c3726.tar.bz2
netfs-57c121a887ae8c5947089eafda5709fcba5c3726.tar.xz
netfs-57c121a887ae8c5947089eafda5709fcba5c3726.zip
Use slicer for configuration reading, revise sample configs accordingly
-rw-r--r--netfs/daemon.xml24
-rw-r--r--netfs/daemon/Jamfile.jam27
-rw-r--r--netfs/daemon/configuration.ice34
-rw-r--r--netfs/daemon/daemon.cpp32
-rw-r--r--netfs/daemon/daemon.h9
-rw-r--r--netfs/daemon/daemonConfig.cpp58
-rw-r--r--netfs/daemon/daemonConfig.h48
-rw-r--r--netfs/daemon/daemonService.cpp11
-rw-r--r--netfs/daemon/daemonService.h5
-rw-r--r--netfs/etc/client.xml (renamed from netfs/client.xml)0
-rw-r--r--netfs/etc/daemon.xml29
-rw-r--r--netfs/etc/init5
-rw-r--r--netfs/fuse/Jamfile.jam1
-rw-r--r--netfs/lib/Jamfile.jam3
14 files changed, 117 insertions, 169 deletions
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 @@
-<?xml version="1.0" encoding="ascii"?>
-<config>
- <hosts>
- <host>
- <endpoint>tcp -p 4000</endpoint>
- <name>akira</name>
- </host>
- <host>
- <endpoint>tcp -p 4000</endpoint>
- <name>riogrande</name>
- </host>
- </hosts>
- <exports>
- <export>
- <name>portage</name>
- <root>/usr/portage</root>
- <replicate>
- <name>akira</name>
- <name>vmware2</name>
- </replicate>
- </export>
- </exports>
-</config>
-
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 : : : : <include>/usr/include/slicer ;
+lib slicer-xml : : : : <include>/usr/include/slicer ;
+
cpp-pch pch : pch.hpp :
<define>_FILE_OFFSET_BITS=64
<include>../../libmisc
<implicit-dependency>../ice//netfsComms
+ <implicit-dependency>netfsdConfiguration
<library>../ice//netfsComms
<library>../lib//netfsCommon
<library>..//boost_thread
<library>..//Ice
- <library>..//libxml2
+ ;
+
+lib netfsdConfiguration :
+ configuration.ice
+ :
+ <library>..//Ice
+ <library>..//IceUtil
+ <library>..//pthread
+ <library>..//boost_filesystem
+ <library>..//boost_system
+ <library>slicer
+ <slicer>yes
+ : :
+ <include>.
+ <library>..//IceUtil
+ <library>..//Ice
+ <library>..//boost_system
+ <library>slicer
;
lib netfsd :
@@ -16,6 +37,8 @@ lib netfsd :
<define>_FILE_OFFSET_BITS=64
<include>../libmisc
<implicit-dependency>../ice//netfsComms
+ <implicit-dependency>netfsdConfiguration
+ <library>netfsdConfiguration
<library>../ice//netfsComms
<library>../lib//netfsCommon
<library>..//boost_random
@@ -25,7 +48,7 @@ lib netfsd :
<library>..//Ice
<library>..//IceUtil
<library>..//IceBox
- <library>..//libxml2
+ <library>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<string, Host> HostMap;
+
+ class Export {
+ ["slicer:name:root"]
+ string RootPath;
+ };
+
+ ["slicer:key:name","slicer:value:export","slicer:item:export"]
+ dictionary<string, Export> 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,38 +1,48 @@
#include "pch.hpp"
#include <Ice/Ice.h>
#include <boost/foreach.hpp>
-#include <boost/crc.hpp>
#include "daemon.h"
-#include "daemonConfig.h"
#include "daemonService.h"
#include "daemonVolume.h"
+#include <slicer/slicer.h>
+#include <xml/serializer.h>
#include "ioHelpers.h"
#include <sys/stat.h>
-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<Slicer::Xml, NetFS::Daemon::Configuration>(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()
{
adapter->deactivate();
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 <boost/thread/mutex.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/nondet_random.hpp>
-#include "daemonConfig.h"
+#include <configuration.h>
#include <types.h>
#include <entCache.h>
@@ -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 <string.h>
-
-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 <string>
-#include <map>
-#include <set>
-#include <IceUtil/Shared.h>
-#include <boost/filesystem/path.hpp>
-#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<Host> HostPtr;
- typedef std::map<std::string, HostPtr> HostMap;
- typedef std::set<HostPtr> HostSet;
-
- class Export : public IceUtil::Shared {
- public:
- Export(xmlNodePtr, const HostMap &);
-
- boost::filesystem::path root;
- std::string name;
- HostSet replicate;
- };
- typedef IceUtil::Handle<Export> ExportPtr;
- typedef std::map<std::string, ExportPtr> ExportMap;
-
- DaemonConfig(xmlNodePtr);
- static IceUtil::Handle<DaemonConfig> Load(const std::string & path);
-
-
- ExportMap exports;
- HostMap hosts;
- HostPtr self;
-};
-typedef IceUtil::Handle<DaemonConfig> 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<boost::mutex> 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/client.xml b/netfs/etc/client.xml
index 9eab8fc..9eab8fc 100644
--- a/netfs/client.xml
+++ b/netfs/etc/client.xml
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 @@
<?xml version="1.0" encoding="ascii"?>
<config>
- <hosts>
- <!--host>
- <endpoint>tcp -p 4000</endpoint>
- <name>localhost</name>
- </host-->
- </hosts>
- <exports>
- <!--export>
- <name>portage</name>
- <root>/usr/portage</root>
- </export-->
- </exports>
+ <hosts>
+ <host>
+ <hostname>akira</hostname>
+ <host>
+ <endpoint>tcp -p 4000</endpoint>
+ </host>
+ </host>
+ </hosts>
+ <exports>
+ <export>
+ <name>portage</name>
+ <export>
+ <root>/usr/portage</root>
+ </export>
+ </export>
+ </exports>
</config>
-
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 :
+ :
<define>_FILE_OFFSET_BITS=64
<include>../../libmisc
<library>..//boost_system
<library>..//boost_thread
- <library>..//libxml2
<library>../ice//netfsComms
<implicit-dependency>../ice//netfsComms
: :