From 3bd7165aba79f098d96e7fed292c12002d807d0f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 25 Oct 2017 17:40:22 +0100 Subject: Greatly simplify the mess of fuse_operations initialisation and remove the now redundent fuseCall wrapper --- netfs/fuse/fuseAppBase.cpp | 2 +- netfs/fuse/fuseAppBase.h | 143 +++++++++++++++++++++---------------------- netfs/unittests/testCore.cpp | 12 +++- 3 files changed, 83 insertions(+), 74 deletions(-) diff --git a/netfs/fuse/fuseAppBase.cpp b/netfs/fuse/fuseAppBase.cpp index 87275c6..fc6fa14 100644 --- a/netfs/fuse/fuseAppBase.cpp +++ b/netfs/fuse/fuseAppBase.cpp @@ -224,7 +224,7 @@ FuseAppBase::runint(int argc, char ** argv) fuseApp = this; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); if (fuse_opt_parse(&args, fuseApp, fuse_opts, - fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { + &helper) == -1) { exit(1); } return args; diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h index 63763d9..4128c6b 100644 --- a/netfs/fuse/fuseAppBase.h +++ b/netfs/fuse/fuseAppBase.h @@ -65,51 +65,51 @@ class DLL_PUBLIC FuseAppBase { virtual int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc) = 0; virtual int main(int, char **, const struct fuse_operations *) = 0; -#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) +#define GetHelper(func) getHelper(&FuseAppBase::func) template static int run(int argc, char ** argv, FuseApp * fa) { auto args = fa->runint(argc, argv); struct fuse_operations operations = { - fuseCall::GetHelper(getattr), - fuseCall::GetHelper(readlink), + GetHelper(getattr), + GetHelper(readlink), NULL, // getdir deprecated - fuseCall::GetHelper(mknod), - fuseCall::GetHelper(mkdir), - fuseCall::GetHelper(unlink), - fuseCall::GetHelper(rmdir), - fuseCall::GetHelper(symlink), - fuseCall::GetHelper(rename), - fuseCall::GetHelper(link), - fuseCall::GetHelper(chmod), - fuseCall::GetHelper(chown), - fuseCall::GetHelper(truncate), + GetHelper(mknod), + GetHelper(mkdir), + GetHelper(unlink), + GetHelper(rmdir), + GetHelper(symlink), + GetHelper(rename), + GetHelper(link), + GetHelper(chmod), + GetHelper(chown), + GetHelper(truncate), NULL, // utime deprecated - fuseCall::GetHelper(open), - fuseCall::GetHelper(read), - fuseCall::GetHelper(write), - fuseCall::GetHelper(statfs), - fuseCall::GetHelper(flush), - fuseCall::GetHelper(release), - fuseCall::GetHelper(fsync), - fuseCall::GetHelper(setxattr), - fuseCall::GetHelper(getxattr), - fuseCall::GetHelper(listxattr), - fuseCall::GetHelper(removexattr), - fuseCall::GetHelper(opendir), - fuseCall::GetHelper(readdir), - fuseCall::GetHelper(releasedir), - fuseCall::GetHelper(fsyncdir), + GetHelper(open), + GetHelper(read), + GetHelper(write), + GetHelper(statfs), + GetHelper(flush), + GetHelper(release), + GetHelper(fsync), + GetHelper(setxattr), + GetHelper(getxattr), + GetHelper(listxattr), + GetHelper(removexattr), + GetHelper(opendir), + GetHelper(readdir), + GetHelper(releasedir), + GetHelper(fsyncdir), fuseInit, fuseDestroy, - fuseCall::GetHelper(access), - fuseCall::GetHelper(create), - fuseCall::GetHelper(ftruncate), - fuseCall::GetHelper(fgetattr), + GetHelper(access), + GetHelper(create), + GetHelper(ftruncate), + GetHelper(fgetattr), #if (FUSE_MINOR_VERSION >= 6) - fuseCall::GetHelper(lock), - fuseCall::GetHelper(utimens), - fuseCall::GetHelper(bmap), + GetHelper(lock), + GetHelper(utimens), + GetHelper(bmap), #if (FUSE_MINOR_VERSION >= 8) 0, // flag_nullpath_ok #if (FUSE_MINOR_VERSION >= 9) @@ -117,13 +117,13 @@ class DLL_PUBLIC FuseAppBase { 0, // flag_utime_omit_ok #endif 0, // flag_reserved - fuseCall::GetHelper(ioctl), - fuseCall::GetHelper(poll), + GetHelper(ioctl), + GetHelper(poll), #if (FUSE_MINOR_VERSION >= 9) - fuseCall::GetHelper(write_buf), - fuseCall::GetHelper(read_buf), - fuseCall::GetHelper(flock), - fuseCall::GetHelper(fallocate), + GetHelper(write_buf), + GetHelper(read_buf), + GetHelper(flock), + GetHelper(fallocate), #endif #endif #endif @@ -136,41 +136,40 @@ class DLL_PUBLIC FuseAppBase { static void * fuseInit(struct fuse_conn_info *conn); static void fuseDestroy(void *); - template - class DLL_PRIVATE fuseCall { - public: - typedef int (*WrapperFunc)(Args...); - template - static WrapperFunc getHelper(bool implemented) - { - auto func = &helper; - return implemented ? func : NULL; + template + static typename std::enable_if::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...)) + { + return &helper; + } + template + static typename std::enable_if::value, int(*)(Args...)>::type getHelper(int(FuseAppBase::*)(Args...)) + { + return nullptr; + } + template + static int helper(Args ... a) + { + for (int t = 0; ; ++t) { + try { + return (fuseApp->*f)(a...); } - template - static int helper(Args ... a) - { - for (int t = 0; ; ++t) { - try { - return (fuseApp->*f)(a...); - } - catch (const std::exception & ex) { - if (t < 10) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - } - else { - fuseApp->logf(LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(f).name()); - return -EIO; - } - } - catch (...) { - fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(f).name()); - return -EIO; + catch (const std::exception & ex) { + if (t < 10) { + if (int rtn = fuseApp->onError(ex)) { + return rtn; } } + else { + fuseApp->logf(LOG_ERR, "Retries expired with %s calling %s", ex.what(), typeid(f).name()); + return -EIO; + } } - }; + catch (...) { + fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(f).name()); + return -EIO; + } + } + } static FuseAppBase * fuseApp; }; diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index ff5a352..880a503 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -51,7 +51,17 @@ class Core { const fuse_operations * fuse; }; -BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) +BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ); + +BOOST_AUTO_TEST_CASE(fuse_operations_correct) +{ + // open should be defined + BOOST_REQUIRE(fuse->open); + // getdir should not be defined (Not supported) + BOOST_REQUIRE(!fuse->getdir); + // fsync should not be defined (Not implemented) + BOOST_REQUIRE(!fuse->fsync); +} BOOST_AUTO_TEST_CASE ( daemonInitialised ) { -- cgit v1.2.3