From 7fcbe6ac74f7a957d0be810401b93c30e7831bd8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 10 Jul 2015 23:29:59 +0100 Subject: Basic WIP support for Glacier2 routing --- netfs/fuse/Jamfile.jam | 3 +++ netfs/fuse/fuseApp.cpp | 27 ++++++++++++++++++++++++++ netfs/fuse/fuseApp.h | 4 ++++ netfs/unittests/testCore.cpp | 45 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index c5d3a7a..b0f04d6 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -1,4 +1,5 @@ lib fuse : : fuse ; +lib Glacier2 : : Glacier2 ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -43,6 +44,7 @@ lib netfsClient : ..//boost_thread ..//boost_system ..//Ice + Glacier2 ..//IceUtil ..//pthread ..//slicer @@ -52,6 +54,7 @@ lib netfsClient : . ../../libfusepp ../ice//netfsComms + Glacier2 ../ice//netfsComms netfsClientConfiguration netfsClientConfiguration diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index 940d0e6..0e7f941 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "fuseApp.h" #include "lockHelpers.h" @@ -13,6 +14,7 @@ template class OptimisticCallCacheabledisconnect(); } + if (session) { + session->destroy(); + } if (ic) { ic->destroy(); } @@ -73,6 +78,17 @@ NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) return 1; } +void +NetFS::FuseApp::connectSession() +{ + if (!sessionOpened && ic->getDefaultRouter()) { + Lock(_lock); + auto router = Glacier2::RouterPrx::checkedCast(ic->getDefaultRouter()); + session = router->createSession("", ""); + sessionOpened = true; + } +} + void NetFS::FuseApp::connectToService() { @@ -134,6 +150,15 @@ void NetFS::FuseApp::verifyConnection() { Lock(_lock); + if (session) { + try { + session->ice_ping(); + } + catch (const Ice::Exception &) { + session = NULL; + sessionOpened = false; + } + } if (service) { try { service->ice_ping(); @@ -157,6 +182,7 @@ NetFS::FuseApp::onError(const std::exception & e) throw() { if (dynamic_cast(&e)) { verifyConnection(); + connectSession(); connectToService(); connectToVolume(); connectHandles(); @@ -168,6 +194,7 @@ NetFS::FuseApp::onError(const std::exception & e) throw() NetFS::ReqEnv NetFS::FuseApp::reqEnv() { + connectSession(); connectToService(); connectToVolume(); struct fuse_context * c = fuse_get_context(); diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index e514b55..335a1c0 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "fuseAppBase.h" #include "fuseConfig.h" @@ -40,6 +41,7 @@ namespace NetFS { void * init (struct fuse_conn_info * info); int opt_parse(void *, const char * arg, int key, struct fuse_args *); + void connectSession(); void connectToService(); void connectToVolume(); void connectHandles(); @@ -102,6 +104,8 @@ namespace NetFS { NetFS::VolumePrx volume; NetFS::ServicePrx service; + Glacier2::SessionPrx session; + bool sessionOpened; std::string mountPoint; std::string resourceName; diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 02405d9..b19c453 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -1,6 +1,8 @@ #define BOOST_TEST_MODULE TestNetFSCore #include #include +#include +#include #include #include #include @@ -37,8 +39,8 @@ class MockDaemon : public NetFSDaemon { class MockDaemonHost { public: - MockDaemonHost() : - params({}), + MockDaemonHost(const Ice::StringSeq & ps = {}) : + params(ps), ic(Ice::initialize(params)), daemon(new MockDaemon()) { @@ -121,6 +123,19 @@ class FuseMockHost { FuseAppBase::run(argc, a, app); } + FuseMockHost(int c, char ** v) : + argc(c), + app(new FuseMock(c, v)), + fuse(&app->ops) + { + FuseAppBase::run(argc, v, app); + } + + ~FuseMockHost() + { + delete app; + } + int argc; FuseMock * app; fuse_operations * fuse; @@ -176,7 +191,6 @@ BOOST_AUTO_TEST_CASE ( clientInitialised ) BOOST_AUTO_TEST_SUITE_END(); - BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) { MockDaemonHostPtr daemon(new MockDaemonHost()); @@ -219,3 +233,28 @@ BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh)); } +BOOST_AUTO_TEST_CASE ( withRouter ) +{ + BOOST_REQUIRE_EQUAL(0, + system("/usr/bin/glacier2router --Glacier2.Client.Endpoints='tcp -p 4063' --Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier --daemon --pidfile /tmp/glacier.pid")); + sleep(1); + + BOOST_SCOPE_EXIT(void) { + system("kill $(cat /tmp/glacier.pid)"); + } BOOST_SCOPE_EXIT_END; + + { + char * argv[] = { + strdup((RootDir / ":testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()), + strdup("--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 4063") + }; + + MockDaemonHostPtr daemon(new MockDaemonHost()); + FuseMockHost fuse(3, argv); + + struct statvfs s; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + } +} + -- cgit v1.2.3