From a9dc04d6aa70bcbf20d28ed8cb9631afa7434a9e Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 22 Aug 2013 01:13:45 +0000 Subject: Only bind fuse wrappers into fuse_operations for functions that have overrides in a deriving class --- libfusepp/fuseapp.cpp | 98 +++++------------------------------------------ libfusepp/fuseapp.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++-- netfs/fuse.h | 6 ++- 3 files changed, 114 insertions(+), 94 deletions(-) diff --git a/libfusepp/fuseapp.cpp b/libfusepp/fuseapp.cpp index 196d72d..1a6494a 100644 --- a/libfusepp/fuseapp.cpp +++ b/libfusepp/fuseapp.cpp @@ -6,7 +6,7 @@ #include #include -static FuseAppBase * fuseApp; +FuseAppBase * FuseAppBase::fuseApp; FuseAppBase::FuseAppBase() { @@ -178,115 +178,37 @@ int FuseAppBase::flock(const char *, struct fuse_file_info *, int) { return -ENOSYS; } +int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} int FuseAppBase::onError(const std::exception & e) throw() { fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); return -ENOSYS; } -template -class fuseCall { - public: - template - static int helper(Args ... a) - { - try { - return (fuseApp->*f)(a...); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return helper(a...); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } - } -}; -static void * fuseInit (struct fuse_conn_info *conn) +void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) { return fuseApp->init(conn); } -static void fuseDestroy(void *) +void FuseAppBase::fuseDestroy(void *) { delete fuseApp; } -int -FuseAppBase::run(int & argc, char** & argv, FuseAppBase * fa) +struct fuse_args +FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) { struct fuse_opt fuse_opts[] = { { NULL, 0, 0 } }; fuseApp = fa; - struct fuse_operations operations = { - fuseCall::helper<&FuseAppBase::getattr>, - fuseCall::helper<&FuseAppBase::readlink>, - NULL, // getdir deprecated - fuseCall::helper<&FuseAppBase::mknod>, - fuseCall::helper<&FuseAppBase::mkdir>, - fuseCall::helper<&FuseAppBase::unlink>, - fuseCall::helper<&FuseAppBase::rmdir>, - fuseCall::helper<&FuseAppBase::symlink>, - fuseCall::helper<&FuseAppBase::rename>, - fuseCall::helper<&FuseAppBase::link>, - fuseCall::helper<&FuseAppBase::chmod>, - fuseCall::helper<&FuseAppBase::chown>, - fuseCall::helper<&FuseAppBase::truncate>, - NULL, // utime deprecated - fuseCall::helper<&FuseAppBase::open>, - fuseCall::helper<&FuseAppBase::read>, - fuseCall::helper<&FuseAppBase::write>, - fuseCall::helper<&FuseAppBase::statfs>, - fuseCall::helper<&FuseAppBase::flush>, - fuseCall::helper<&FuseAppBase::release>, - fuseCall::helper<&FuseAppBase::fsync>, - fuseCall::helper<&FuseAppBase::setxattr>, - fuseCall::helper<&FuseAppBase::getxattr>, - fuseCall::helper<&FuseAppBase::listxattr>, - fuseCall::helper<&FuseAppBase::removexattr>, - fuseCall::helper<&FuseAppBase::opendir>, - fuseCall::helper<&FuseAppBase::readdir>, - fuseCall::helper<&FuseAppBase::releasedir>, - fuseCall::helper<&FuseAppBase::fsyncdir>, - fuseInit, - fuseDestroy, - fuseCall::helper<&FuseAppBase::access>, - fuseCall::helper<&FuseAppBase::create>, - fuseCall::helper<&FuseAppBase::ftruncate>, - fuseCall::helper<&FuseAppBase::fgetattr> -#if (FUSE_MINOR_VERSION >= 6) - , - fuseCall::helper<&FuseAppBase::lock>, - fuseCall::helper<&FuseAppBase::utimens>, - fuseCall::helper<&FuseAppBase::bmap> -#if (FUSE_MINOR_VERSION >= 8) - , - 0, // flag_nullpath_ok -#if (FUSE_MINOR_VERSION >= 9) - 0, // flag_nopath - 0, // flag_utime_omit_ok -#endif - 0, // flag_reserved - fuseCall::helper<&FuseAppBase::ioctl>, - fuseCall::helper<&FuseAppBase::poll> -#if (FUSE_MINOR_VERSION >= 9) - , - 0, //fuseCall::helper<&FuseAppBase::write_buf>, - 0, //fuseCall::helper<&FuseAppBase::read_buf>, - fuseCall::helper<&FuseAppBase::flock>, - NULL // fallocate -#endif -#endif -#endif - }; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); if (fuse_opt_parse(&args, fuseApp, fuse_opts, fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { exit(1); } - return fuse_main(args.argc, args.argv, &operations, fa); + return args; } diff --git a/libfusepp/fuseapp.h b/libfusepp/fuseapp.h index 1c94f13..bb18c02 100644 --- a/libfusepp/fuseapp.h +++ b/libfusepp/fuseapp.h @@ -3,7 +3,10 @@ #define FUSE_USE_VERSION 26 #include +#include #include +#include +#include class FuseAppBase { public: @@ -47,12 +50,105 @@ class FuseAppBase { virtual int bmap(const char *, size_t blocksize, uint64_t *idx); virtual int ioctl(const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void * data); virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *); - virtual int write_buf (const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); - virtual int read_buf (const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); - virtual int flock (const char *, struct fuse_file_info *, int op); + virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); + virtual int read_buf(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); + virtual int flock(const char *, struct fuse_file_info *, int op); + virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); virtual int onError(const std::exception & err) throw(); - static int run(int &, char ** &, FuseAppBase *); +#define IFIMPL(func) typeid(&FuseAppBase::func) == typeid(&FuseApp::func) ? NULL : + template + static int run(int & argc, char** & argv, FuseApp * fa) + { + auto args = runint(argc, argv, fa); + struct fuse_operations operations = { + IFIMPL(getattr) fuseCall::helper<&FuseAppBase::getattr>, + IFIMPL(readlink) fuseCall::helper<&FuseAppBase::readlink>, + NULL, // getdir deprecated + IFIMPL(mknod) fuseCall::helper<&FuseAppBase::mknod>, + IFIMPL(mkdir) fuseCall::helper<&FuseAppBase::mkdir>, + IFIMPL(unlink) fuseCall::helper<&FuseAppBase::unlink>, + IFIMPL(rmdir) fuseCall::helper<&FuseAppBase::rmdir>, + IFIMPL(symlink) fuseCall::helper<&FuseAppBase::symlink>, + IFIMPL(rename) fuseCall::helper<&FuseAppBase::rename>, + IFIMPL(link) fuseCall::helper<&FuseAppBase::link>, + IFIMPL(chmod) fuseCall::helper<&FuseAppBase::chmod>, + IFIMPL(chown) fuseCall::helper<&FuseAppBase::chown>, + IFIMPL(truncate) fuseCall::helper<&FuseAppBase::truncate>, + NULL, // utime deprecated + IFIMPL(open) fuseCall::helper<&FuseAppBase::open>, + IFIMPL(read) fuseCall::helper<&FuseAppBase::read>, + IFIMPL(write) fuseCall::helper<&FuseAppBase::write>, + IFIMPL(statfs) fuseCall::helper<&FuseAppBase::statfs>, + IFIMPL(flush) fuseCall::helper<&FuseAppBase::flush>, + IFIMPL(release) fuseCall::helper<&FuseAppBase::release>, + IFIMPL(fsync) fuseCall::helper<&FuseAppBase::fsync>, + IFIMPL(setxattr) fuseCall::helper<&FuseAppBase::setxattr>, + IFIMPL(getxattr) fuseCall::helper<&FuseAppBase::getxattr>, + IFIMPL(listxattr) fuseCall::helper<&FuseAppBase::listxattr>, + IFIMPL(removexattr) fuseCall::helper<&FuseAppBase::removexattr>, + IFIMPL(opendir) fuseCall::helper<&FuseAppBase::opendir>, + IFIMPL(readdir) fuseCall::helper<&FuseAppBase::readdir>, + IFIMPL(releasedir) fuseCall::helper<&FuseAppBase::releasedir>, + IFIMPL(fsyncdir) fuseCall::helper<&FuseAppBase::fsyncdir>, + fuseInit, + fuseDestroy, + IFIMPL(access) fuseCall::helper<&FuseAppBase::access>, + IFIMPL(create) fuseCall::helper<&FuseAppBase::create>, + IFIMPL(fgetattr) fuseCall::helper<&FuseAppBase::ftruncate>, + IFIMPL(fgetattr) fuseCall::helper<&FuseAppBase::fgetattr>, +#if (FUSE_MINOR_VERSION >= 6) + IFIMPL(lock) fuseCall::helper<&FuseAppBase::lock>, + IFIMPL(utimens) fuseCall::helper<&FuseAppBase::utimens>, + IFIMPL(bmap) fuseCall::helper<&FuseAppBase::bmap>, +#if (FUSE_MINOR_VERSION >= 8) + 0, // flag_nullpath_ok +#if (FUSE_MINOR_VERSION >= 9) + 0, // flag_nopath + 0, // flag_utime_omit_ok +#endif + 0, // flag_reserved + IFIMPL(ioctl) fuseCall::helper<&FuseAppBase::ioctl>, + IFIMPL(poll) fuseCall::helper<&FuseAppBase::poll>, +#if (FUSE_MINOR_VERSION >= 9) + IFIMPL(write_buf) fuseCall::helper<&FuseAppBase::write_buf>, + IFIMPL(read_buf) fuseCall::helper<&FuseAppBase::read_buf>, + IFIMPL(flock) fuseCall::helper<&FuseAppBase::flock>, + IFIMPL(fallocate) fuseCall::helper<&FuseAppBase::fallocate>, +#endif +#endif +#endif + }; + return fuse_main(args.argc, args.argv, &operations, fa); + } + private: + static struct fuse_args runint(int &, char ** &, FuseAppBase *); + static void * fuseInit(struct fuse_conn_info *conn); + static void fuseDestroy(void *); + + template + class fuseCall { + public: + template + static int helper(Args ... a) + { + try { + return (fuseApp->*f)(a...); + } + catch (const std::exception & ex) { + if (int rtn = fuseApp->onError(ex)) { + return rtn; + } + return helper(a...); + } + catch (...) { + fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); + return -ENOSYS; + } + } + }; + + static FuseAppBase * fuseApp; }; #endif diff --git a/netfs/fuse.h b/netfs/fuse.h index 0b25ad7..4a0abfd 100644 --- a/netfs/fuse.h +++ b/netfs/fuse.h @@ -9,7 +9,7 @@ #include "entCache.h" #include "intrusivePtrBase.h" -#define LOCK boost::unique_lock _lck(lock) +#define LOCK boost::unique_lock _lck(_lock) class NetFS : public FuseAppBase { @@ -48,6 +48,7 @@ class NetFS : public FuseAppBase int opt_parse(void *, const char * arg, int key, struct fuse_args *); void connect(); void connect_nl(); + public: // misc int access(const char * p, int a); int getattr(const char * p, struct stat * s); @@ -78,6 +79,7 @@ class NetFS : public FuseAppBase int statfs(const char *, struct statvfs *); // stuff int onError(const std::exception & err) throw(); + private: int getNextFileID(); Ice::Int getRemoteIDforFile(int localID) const; int getNextDirID(); @@ -89,7 +91,7 @@ class NetFS : public FuseAppBase char ** _argv; Ice::CommunicatorPtr ic; FuseConfigPtr fc; - mutable boost::mutex lock; + mutable boost::mutex _lock; NetFSComms::FileSystemPrx filesystem; NetFSComms::ServicePrx service; -- cgit v1.2.3