diff options
| -rw-r--r-- | netfs/fuse/Jamfile.jam | 3 | ||||
| -rw-r--r-- | netfs/fuse/fuseApp.cpp | 27 | ||||
| -rw-r--r-- | netfs/fuse/fuseApp.h | 4 | ||||
| -rw-r--r-- | 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 : : <name>fuse ; +lib Glacier2 : : <name>Glacier2 ;  cpp-pch pch : pch.hpp :  	<define>_FILE_OFFSET_BITS=64 @@ -43,6 +44,7 @@ lib netfsClient :  	<library>..//boost_thread  	<library>..//boost_system  	<library>..//Ice +	<library>Glacier2  	<library>..//IceUtil  	<library>..//pthread  	<library>..//slicer @@ -52,6 +54,7 @@ lib netfsClient :  	<include>.  	<include>../../libfusepp  	<library>../ice//netfsComms +	<library>Glacier2  	<implicit-dependency>../ice//netfsComms  	<library>netfsClientConfiguration  	<implicit-dependency>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 <pch.hpp> +#include <Glacier2/Router.h>  #include <string.h>  #include "fuseApp.h"  #include "lockHelpers.h" @@ -13,6 +14,7 @@ template class OptimisticCallCacheable<struct stat, std::string, IceUtil::Shared  NetFS::FuseApp::FuseApp(int & argc, char ** argv) :  	_argc(argc),  	_argv(argv), +	sessionOpened(false),  	openDirID(0),  	openFileID(0)  { @@ -29,6 +31,9 @@ NetFS::FuseApp::~FuseApp()  	if (volume) {  		volume->disconnect();  	} +	if (session) { +		session->destroy(); +	}  	if (ic) {  		ic->destroy();  	} @@ -74,6 +79,17 @@ NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *)  }  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()  {  	if (!service) { @@ -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<const Ice::ObjectNotExistException *>(&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 <boost/thread/shared_mutex.hpp>  #include <Ice/Ice.h> +#include <Glacier2/Session.h>  #include <service.h>  #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 <boost/test/unit_test.hpp>  #include <boost/filesystem/operations.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/scope_exit.hpp>  #include <Ice/ObjectAdapter.h>  #include <Ice/Service.h>  #include <daemon.h> @@ -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)); +	} +} +  | 
