From 0334fad13f0c7566fbb9f8a0829b9c95d861ee57 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 4 Jan 2016 22:22:36 +0000 Subject: Improve error handling around unavailable daemon --- netfs/fuse/fuseApp.cpp | 58 +++++++++++++++++++++++++++++---------- netfs/unittests/testEdgeCases.cpp | 41 +++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 14 deletions(-) diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index d37d40c..4766360 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -23,16 +23,36 @@ NetFS::FuseApp::FuseApp(const Ice::StringSeq & a) : NetFS::FuseApp::~FuseApp() { for (const OpenDirs::value_type & of : openDirs) { - of.second->remote->close(); + try { + of.second->remote->close(); + } + catch (...) { + // Can't do anything useful here + } } for (const OpenFiles::value_type & of : openFiles) { - of.second->remote->close(); + try { + of.second->remote->close(); + } + catch (...) { + // Can't do anything useful here + } } if (volume) { - volume->disconnect(); + try { + volume->disconnect(); + } + catch (...) { + // Can't do anything useful here + } } if (session) { - session->destroy(); + try { + session->destroy(); + } + catch (...) { + // Can't do anything useful here + } } if (ic) { ic->destroy(); @@ -183,18 +203,28 @@ NetFS::FuseApp::onError(const std::exception & e) throw() { if (dynamic_cast(&e) || dynamic_cast(&e)) { log(LOG_ERR, e.what()); - verifyConnection(); - connectSession(); - connectToService(); - connectToVolume(); - connectHandles(); - return 0; + try { + verifyConnection(); + connectSession(); + connectToService(); + connectToVolume(); + connectHandles(); + return 0; + } + catch (...) { + return -ENOSYS; + } } if (dynamic_cast(&e)) { - volume = NULL; - connectToVolume(); - connectHandles(); - return 0; + try { + volume = NULL; + connectToVolume(); + connectHandles(); + return 0; + } + catch (...) { + return -ENOSYS; + } } if (dynamic_cast(&e)) { return -EPERM; diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp index b1b7a44..7bf543c 100644 --- a/netfs/unittests/testEdgeCases.cpp +++ b/netfs/unittests/testEdgeCases.cpp @@ -58,3 +58,44 @@ BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh)); } +BOOST_AUTO_TEST_CASE( noDaemonAtStartUp ) +{ + FuseMockHost fuse(testEndpoint, { + (RootDir / "defaultFuse.xml:testvol").string(), + (RootDir / "test").string() + }); + + struct statvfs s; + BOOST_REQUIRE_EQUAL(-ENOSYS, fuse.fuse->statfs("/", &s)); + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); +} + +BOOST_AUTO_TEST_CASE ( daemonUnavailableAfterUse ) +{ + FuseMockHost fuse(testEndpoint, { + (RootDir / "defaultFuse.xml:testvol").string(), + (RootDir / "test").string() + }); + struct statvfs s; + { + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + } + BOOST_REQUIRE_EQUAL(-ENOSYS, fuse.fuse->statfs("/", &s)); + { + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + } + BOOST_REQUIRE_EQUAL(-ENOSYS, fuse.fuse->statfs("/", &s)); +} + -- cgit v1.2.3