From c28bbc2c15ee0bcba3203c3b5011c3e86213bffd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 16:13:47 +0000 Subject: Refactor to make more testable --- libfusepp/Jamfile.jam | 5 -- libfusepp/fuseAppBase.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++++++ libfusepp/fuseAppBase.h | 162 +++++++++++++++++++++++++++++++++++ libfusepp/fuseapp.cpp | 214 ---------------------------------------------- libfusepp/fuseapp.h | 162 ----------------------------------- netfs/Jamfile.jam | 1 - netfs/fuse/Jamfile.jam | 22 ++++- netfs/fuse/fuse.cpp | 176 -------------------------------------- netfs/fuse/fuse.h | 115 ------------------------- netfs/fuse/fuseApp.cpp | 170 ++++++++++++++++++++++++++++++++++++ netfs/fuse/fuseApp.h | 115 +++++++++++++++++++++++++ netfs/fuse/fuseDirs.cpp | 2 +- netfs/fuse/fuseFiles.cpp | 2 +- netfs/fuse/fuseMisc.cpp | 2 +- netfs/fuse/fuseSystem.cpp | 2 +- netfs/fuse/netfs.cpp | 8 ++ netfs/fuse/pch.hpp | 4 +- 17 files changed, 692 insertions(+), 684 deletions(-) delete mode 100644 libfusepp/Jamfile.jam create mode 100644 libfusepp/fuseAppBase.cpp create mode 100644 libfusepp/fuseAppBase.h delete mode 100644 libfusepp/fuseapp.cpp delete mode 100644 libfusepp/fuseapp.h delete mode 100644 netfs/fuse/fuse.cpp delete mode 100644 netfs/fuse/fuse.h create mode 100644 netfs/fuse/fuseApp.cpp create mode 100644 netfs/fuse/fuseApp.h create mode 100644 netfs/fuse/netfs.cpp diff --git a/libfusepp/Jamfile.jam b/libfusepp/Jamfile.jam deleted file mode 100644 index 1ba4a26..0000000 --- a/libfusepp/Jamfile.jam +++ /dev/null @@ -1,5 +0,0 @@ -project - : usage-requirements - . - ; - diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp new file mode 100644 index 0000000..4d9ca97 --- /dev/null +++ b/libfusepp/fuseAppBase.cpp @@ -0,0 +1,214 @@ +#include "fuseAppBase.h" +#include +#include +#include +#include +#include +#include + +FuseAppBase * FuseAppBase::fuseApp; + +FuseAppBase::FuseAppBase() +{ +} +FuseAppBase::~FuseAppBase() +{ +} +void * FuseAppBase::init(fuse_conn_info*) +{ + return NULL; +} +int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) +{ + return 1; +} +int FuseAppBase::access(const char *, int) +{ + return -ENOSYS; +} +int FuseAppBase::chmod(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::chown(const char *, uid_t, gid_t) +{ + return -ENOSYS; +} +int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flush(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::getattr(const char *, struct stat *) +{ + return -ENOSYS; +} +int FuseAppBase::getxattr(const char *, const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::link(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::listxattr(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::mkdir(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::mknod(const char *, mode_t, dev_t) +{ + return -ENOSYS; +} +int FuseAppBase::open(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::opendir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readlink(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::release(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::releasedir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::removexattr(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rename(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rmdir(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) +{ + return -ENOSYS; +} +int FuseAppBase::statfs(const char *, struct statvfs *) +{ + return -ENOSYS; +} +int FuseAppBase::symlink(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::truncate(const char *, off_t) +{ + return -ENOSYS; +} +int FuseAppBase::unlink(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) +{ + return -ENOSYS; +} +int FuseAppBase::utimens(const char *, const struct timespec[2]) +{ + return -ENOSYS; +} +int FuseAppBase::bmap(const char *, size_t, uint64_t *) +{ + return -ENOSYS; +} +int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) +{ + return -ENOSYS; +} +int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) +{ + return -ENOSYS; +} +int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +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; +} + +void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) +{ + return fuseApp->init(conn); +} +void FuseAppBase::fuseDestroy(void *) +{ + delete fuseApp; +} + +struct fuse_args +FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) +{ + struct fuse_opt fuse_opts[] = { + { NULL, 0, 0 } + }; + fuseApp = fa; + 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 args; +} + diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h new file mode 100644 index 0000000..a320d36 --- /dev/null +++ b/libfusepp/fuseAppBase.h @@ -0,0 +1,162 @@ +#ifndef FUSEAPP_H +#define FUSEAPP_H + +#define FUSE_USE_VERSION 26 +#include +#include +#include +#include +#include + +class FuseAppBase { + public: + FuseAppBase(); + virtual ~FuseAppBase() = 0; + virtual void * init (struct fuse_conn_info * info); + virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); + virtual int access(const char *, int); + virtual int chmod(const char *, mode_t); + virtual int chown(const char *, uid_t, gid_t); + virtual int create(const char *, mode_t, struct fuse_file_info *); + virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); + virtual int flush(const char *, struct fuse_file_info *); + virtual int fsync(const char *, int, struct fuse_file_info *); + virtual int fsyncdir(const char *, int, struct fuse_file_info *); + virtual int ftruncate(const char *, off_t, struct fuse_file_info *); + virtual int getattr(const char *, struct stat *); + virtual int getxattr(const char *, const char *, char *, size_t); + virtual int link(const char *, const char *); + virtual int listxattr(const char *, char *, size_t); + virtual int mkdir(const char *, mode_t); + virtual int mknod(const char *, mode_t, dev_t); + virtual int open(const char *, struct fuse_file_info *); + virtual int opendir(const char *, struct fuse_file_info *); + virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); + virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); + virtual int readlink(const char *, char *, size_t); + virtual int release(const char *, struct fuse_file_info *); + virtual int releasedir(const char *, struct fuse_file_info *); + virtual int removexattr(const char *, const char *); + virtual int rename(const char *, const char *); + virtual int rmdir(const char *); + virtual int setxattr(const char *, const char *, const char *, size_t, int); + virtual int statfs(const char *, struct statvfs *); + virtual int symlink(const char *, const char *); + virtual int truncate(const char *, off_t); + virtual int unlink(const char *); + virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); + virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); + virtual int utimens(const char *, const struct timespec tv[2]); + 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 fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); + virtual int onError(const std::exception & err) throw(); + +#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) + template + static int run(int & argc, char** & argv, FuseApp * fa) + { + auto args = runint(argc, argv, fa); + struct fuse_operations operations = { + fuseCall::GetHelper(getattr), + fuseCall::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), + 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), + fuseInit, + fuseDestroy, + fuseCall::GetHelper(access), + fuseCall::GetHelper(create), + fuseCall::GetHelper(ftruncate), + fuseCall::GetHelper(fgetattr), +#if (FUSE_MINOR_VERSION >= 6) + fuseCall::GetHelper(lock), + fuseCall::GetHelper(utimens), + fuseCall::GetHelper(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::GetHelper(ioctl), + fuseCall::GetHelper(poll), +#if (FUSE_MINOR_VERSION >= 9) + fuseCall::GetHelper(write_buf), + fuseCall::GetHelper(read_buf), + fuseCall::GetHelper(flock), + fuseCall::GetHelper(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: + typedef int (*WrapperFunc)(Args...); + template + static WrapperFunc getHelper(bool implemented) + { + auto func = &helper; + return implemented ? func : NULL; + } + 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/libfusepp/fuseapp.cpp b/libfusepp/fuseapp.cpp deleted file mode 100644 index 1a6494a..0000000 --- a/libfusepp/fuseapp.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include "fuseapp.h" -#include -#include -#include -#include -#include -#include - -FuseAppBase * FuseAppBase::fuseApp; - -FuseAppBase::FuseAppBase() -{ -} -FuseAppBase::~FuseAppBase() -{ -} -void * FuseAppBase::init(fuse_conn_info*) -{ - return NULL; -} -int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) -{ - return 1; -} -int FuseAppBase::access(const char *, int) -{ - return -ENOSYS; -} -int FuseAppBase::chmod(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::chown(const char *, uid_t, gid_t) -{ - return -ENOSYS; -} -int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flush(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::getattr(const char *, struct stat *) -{ - return -ENOSYS; -} -int FuseAppBase::getxattr(const char *, const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::link(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::listxattr(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::mkdir(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::mknod(const char *, mode_t, dev_t) -{ - return -ENOSYS; -} -int FuseAppBase::open(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::opendir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readlink(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::release(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::releasedir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::removexattr(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rename(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rmdir(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) -{ - return -ENOSYS; -} -int FuseAppBase::statfs(const char *, struct statvfs *) -{ - return -ENOSYS; -} -int FuseAppBase::symlink(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::truncate(const char *, off_t) -{ - return -ENOSYS; -} -int FuseAppBase::unlink(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) -{ - return -ENOSYS; -} -int FuseAppBase::utimens(const char *, const struct timespec[2]) -{ - return -ENOSYS; -} -int FuseAppBase::bmap(const char *, size_t, uint64_t *) -{ - return -ENOSYS; -} -int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) -{ - return -ENOSYS; -} -int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) -{ - return -ENOSYS; -} -int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -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; -} - -void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) -{ - return fuseApp->init(conn); -} -void FuseAppBase::fuseDestroy(void *) -{ - delete fuseApp; -} - -struct fuse_args -FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) -{ - struct fuse_opt fuse_opts[] = { - { NULL, 0, 0 } - }; - fuseApp = fa; - 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 args; -} - diff --git a/libfusepp/fuseapp.h b/libfusepp/fuseapp.h deleted file mode 100644 index a320d36..0000000 --- a/libfusepp/fuseapp.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef FUSEAPP_H -#define FUSEAPP_H - -#define FUSE_USE_VERSION 26 -#include -#include -#include -#include -#include - -class FuseAppBase { - public: - FuseAppBase(); - virtual ~FuseAppBase() = 0; - virtual void * init (struct fuse_conn_info * info); - virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); - virtual int access(const char *, int); - virtual int chmod(const char *, mode_t); - virtual int chown(const char *, uid_t, gid_t); - virtual int create(const char *, mode_t, struct fuse_file_info *); - virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); - virtual int flush(const char *, struct fuse_file_info *); - virtual int fsync(const char *, int, struct fuse_file_info *); - virtual int fsyncdir(const char *, int, struct fuse_file_info *); - virtual int ftruncate(const char *, off_t, struct fuse_file_info *); - virtual int getattr(const char *, struct stat *); - virtual int getxattr(const char *, const char *, char *, size_t); - virtual int link(const char *, const char *); - virtual int listxattr(const char *, char *, size_t); - virtual int mkdir(const char *, mode_t); - virtual int mknod(const char *, mode_t, dev_t); - virtual int open(const char *, struct fuse_file_info *); - virtual int opendir(const char *, struct fuse_file_info *); - virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); - virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); - virtual int readlink(const char *, char *, size_t); - virtual int release(const char *, struct fuse_file_info *); - virtual int releasedir(const char *, struct fuse_file_info *); - virtual int removexattr(const char *, const char *); - virtual int rename(const char *, const char *); - virtual int rmdir(const char *); - virtual int setxattr(const char *, const char *, const char *, size_t, int); - virtual int statfs(const char *, struct statvfs *); - virtual int symlink(const char *, const char *); - virtual int truncate(const char *, off_t); - virtual int unlink(const char *); - virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); - virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); - virtual int utimens(const char *, const struct timespec tv[2]); - 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 fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); - virtual int onError(const std::exception & err) throw(); - -#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) - template - static int run(int & argc, char** & argv, FuseApp * fa) - { - auto args = runint(argc, argv, fa); - struct fuse_operations operations = { - fuseCall::GetHelper(getattr), - fuseCall::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), - 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), - fuseInit, - fuseDestroy, - fuseCall::GetHelper(access), - fuseCall::GetHelper(create), - fuseCall::GetHelper(ftruncate), - fuseCall::GetHelper(fgetattr), -#if (FUSE_MINOR_VERSION >= 6) - fuseCall::GetHelper(lock), - fuseCall::GetHelper(utimens), - fuseCall::GetHelper(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::GetHelper(ioctl), - fuseCall::GetHelper(poll), -#if (FUSE_MINOR_VERSION >= 9) - fuseCall::GetHelper(write_buf), - fuseCall::GetHelper(read_buf), - fuseCall::GetHelper(flock), - fuseCall::GetHelper(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: - typedef int (*WrapperFunc)(Args...); - template - static WrapperFunc getHelper(bool implemented) - { - auto func = &helper; - return implemented ? func : NULL; - } - 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/Jamfile.jam b/netfs/Jamfile.jam index dd8865e..70cd2d9 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -13,7 +13,6 @@ lib Ice : : Ice ; lib IceUtil : : IceUtil ; lib IceBox : : IceBox ; lib pthread : : pthread ; -lib fuse : : fuse ; lib slicer : : : : /usr/include/slicer ; lib slicer-xml : : : : /usr/include/slicer ; diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index e7558f6..acf757d 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -1,3 +1,4 @@ +lib fuse : : fuse ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -6,7 +7,7 @@ cpp-pch pch : pch.hpp : ../ice//netfsComms ../ice//netfsComms ..//boost_thread - ..//fuse + fuse ..//Ice ; @@ -25,10 +26,10 @@ obj configuration : ..//slicer ; -exe netfs : +lib netfsClient : pch configuration - [ glob *.cpp ] + [ glob *.cpp : netfs.cpp ] [ glob ../../libfusepp/fuse*.cpp ] : _FILE_OFFSET_BITS=64 @@ -40,12 +41,25 @@ exe netfs : ../lib//netfsCommon ..//boost_thread ..//boost_system - ..//fuse + fuse ..//Ice ..//IceUtil ..//pthread ..//slicer ..//libxmlpp ..//slicer-xml + : : + . + ../../libfusepp + ../ice//netfsComms + ../ice//netfsComms + configuration + _FILE_OFFSET_BITS=64 + fuse + ; + +exe netfs : + netfs.cpp : + netfsClient ; diff --git a/netfs/fuse/fuse.cpp b/netfs/fuse/fuse.cpp deleted file mode 100644 index 7f90710..0000000 --- a/netfs/fuse/fuse.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "pch.hpp" -#include -#include "fuse.h" -#include "lockHelpers.h" -#include "cache.impl.h" -#include -#include -#include - -template class Cache>>; -template class OptimisticCallCacheable; - -NetFS::FuseApp::FuseApp(int & argc, char ** argv) : - _argc(argc), - _argv(argv), - openDirID(0), - openFileID(0) -{ -} - -NetFS::FuseApp::~FuseApp() -{ - for (const OpenDirs::value_type & of : openDirs) { - of.second->remote->close(); - } - for (const OpenFiles::value_type & of : openFiles) { - of.second->remote->close(); - } - if (volume) { - volume->disconnect(); - } - if (ic) { - ic->destroy(); - } -} - -void * -NetFS::FuseApp::init(struct fuse_conn_info *) -{ - ic = Ice::initialize(_argc, _argv); - fc = Slicer::Deserialize(configPath); - return NULL; -} - -int -NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) -{ - if (strncmp(arg, "--Ice.", 6) == 0) { - return 0; - } - else if (strncmp(arg, "_netdev", 7) == 0) { - return 0; - } - else if (arg[0] == '-') { - return 1; - } - else if (resourceName.empty()) { - const char * colon = strchr(arg, ':'); - resourceName = colon + 1; - configPath.assign(arg, colon); - return 0; - } - else if (mountPoint.empty()) { - mountPoint = arg; - return 1; - } - return 1; -} - -void -NetFS::FuseApp::connectToService() -{ - if (!service) { - Lock(_lock); - auto e = fc->Resources.find(resourceName); - if (e == fc->Resources.end()) { - throw std::runtime_error("No such resource: " + resourceName); - } - - auto proxyAddr = e->second->ServiceIdentity; - for (const auto & ep : e->second->Endpoints) { - proxyAddr += ":" + ep; - } - service = NetFS::ServicePrx::checkedCast(ic->stringToProxy(proxyAddr)); - if (!service) { - throw std::runtime_error("Invalid service proxy: " + proxyAddr); - } - } -} - -void -NetFS::FuseApp::connectToVolume() -{ - if (!volume) { - auto e = fc->Resources.find(resourceName); - if (e == fc->Resources.end()) { - throw std::runtime_error("No such export: " + resourceName); - } - volume = service->connect(e->second->ExportName, "bar"); - if (!volume) { - throw "Invalid filesystem proxy"; - } - } -} - -void -NetFS::FuseApp::connectHandles() -{ - for (const OpenFiles::value_type & of : openFiles) { - try { - of.second->remote->ice_ping(); - } - catch (const Ice::ObjectNotExistException &) { - of.second->remote = volume->open(reqEnv(), of.second->path, of.second->flags); - } - } - for (const OpenDirs::value_type & of : openDirs) { - try { - of.second->remote->ice_ping(); - } - catch (const Ice::ObjectNotExistException &) { - of.second->remote = volume->opendir(reqEnv(), of.second->path); - } - } -} - -void -NetFS::FuseApp::verifyConnection() -{ - Lock(_lock); - if (service) { - try { - service->ice_ping(); - } - catch (const Ice::Exception &) { - service = NULL; - } - } - if (volume) { - try { - volume->ice_ping(); - } - catch (const Ice::Exception &) { - volume = NULL; - } - } -} - -int -NetFS::FuseApp::onError(const std::exception & e) throw() -{ - if (dynamic_cast(&e)) { - verifyConnection(); - connectToService(); - connectToVolume(); - connectHandles(); - return 0; - } - return FuseAppBase::onError(e); -} - -NetFS::ReqEnv -NetFS::FuseApp::reqEnv() -{ - connectToService(); - connectToVolume(); - struct fuse_context * c = fuse_get_context(); - return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; -} - -int -main(int argc, char* argv[]) -{ - return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); -} - diff --git a/netfs/fuse/fuse.h b/netfs/fuse/fuse.h deleted file mode 100644 index 3821285..0000000 --- a/netfs/fuse/fuse.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef NETFS_FUSE_H -#define NETFS_FUSE_H - -#include -#include -#include -#include "fuseapp.h" -#include "configuration.h" -#include "cache.h" - -namespace NetFS { - class FuseApp : public FuseAppBase { - private: - class OpenDir : public IceUtil::Shared { - public: - OpenDir(DirectoryPrx remote, const std::string & path); - - DirectoryPrx remote; - const std::string path; - }; - typedef IceUtil::Handle OpenDirPtr; - typedef std::map OpenDirs; - - class OpenFile : public IceUtil::Shared { - public: - OpenFile(FilePrx remote, const std::string & path, int flags); - - FilePrx remote; - const std::string path; - const int flags; - }; - typedef IceUtil::Handle OpenFilePtr; - typedef std::map OpenFiles; - - public: - FuseApp(int & argc, char ** argv); - ~FuseApp(); - - private: - void * init (struct fuse_conn_info * info); - int opt_parse(void *, const char * arg, int key, struct fuse_args *); - - void connectToService(); - void connectToVolume(); - void connectHandles(); - void verifyConnection(); - - public: - // misc - int access(const char * p, int a); - int getattr(const char * p, struct stat * s); - int fgetattr(const char *, struct stat *, struct fuse_file_info *); - int chmod(const char *, mode_t); - int chown(const char *, uid_t, gid_t); - int link(const char *, const char *); - int readlink(const char *, char *, size_t); - int rename(const char *, const char *); - int symlink(const char *, const char *); - int unlink(const char *); - int utimens(const char *, const struct timespec tv[2]); - int mknod(const char *, mode_t, dev_t); - // dirs - int opendir(const char * p, struct fuse_file_info * fi); - int releasedir(const char *, struct fuse_file_info * fi); - int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi); - int mkdir(const char *, mode_t); - int rmdir(const char *); - // files - int open(const char * p, struct fuse_file_info * fi); - int create(const char *, mode_t, struct fuse_file_info *); - int release(const char *, struct fuse_file_info * fi); - int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi); - int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi); - int truncate(const char *, off_t); - int ftruncate(const char *, off_t, struct fuse_file_info *); - // fs - int statfs(const char *, struct statvfs *); - // stuff - int onError(const std::exception & err) throw(); - - private: - void setProxy(OpenFilePtr, uint64_t & fh); - OpenFilePtr getFileProxy(uint64_t localID) const; - void clearFileProxy(uint64_t localID); - - void setProxy(OpenDirPtr, uint64_t & fh); - OpenDirPtr getDirProxy(uint64_t localID) const; - void clearDirProxy(uint64_t localID); - - ReqEnv reqEnv(); - - int & _argc; - char ** _argv; - Ice::CommunicatorPtr ic; - Client::ConfigurationPtr fc; - mutable boost::shared_mutex _lock; - - NetFS::VolumePrx volume; - NetFS::ServicePrx service; - - std::string mountPoint; - std::string resourceName; - std::string configPath; - - OpenDirs openDirs; - int openDirID; - OpenFiles openFiles; - int openFileID; - - typedef Cache>> StatCache; - StatCache statCache; - }; -} - -#endif diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp new file mode 100644 index 0000000..841d670 --- /dev/null +++ b/netfs/fuse/fuseApp.cpp @@ -0,0 +1,170 @@ +#include "pch.hpp" +#include +#include "fuseApp.h" +#include "lockHelpers.h" +#include "cache.impl.h" +#include +#include +#include + +template class Cache>>; +template class OptimisticCallCacheable; + +NetFS::FuseApp::FuseApp(int & argc, char ** argv) : + _argc(argc), + _argv(argv), + openDirID(0), + openFileID(0) +{ +} + +NetFS::FuseApp::~FuseApp() +{ + for (const OpenDirs::value_type & of : openDirs) { + of.second->remote->close(); + } + for (const OpenFiles::value_type & of : openFiles) { + of.second->remote->close(); + } + if (volume) { + volume->disconnect(); + } + if (ic) { + ic->destroy(); + } +} + +void * +NetFS::FuseApp::init(struct fuse_conn_info *) +{ + ic = Ice::initialize(_argc, _argv); + fc = Slicer::Deserialize(configPath); + return NULL; +} + +int +NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) +{ + if (strncmp(arg, "--Ice.", 6) == 0) { + return 0; + } + else if (strncmp(arg, "_netdev", 7) == 0) { + return 0; + } + else if (arg[0] == '-') { + return 1; + } + else if (resourceName.empty()) { + const char * colon = strchr(arg, ':'); + resourceName = colon + 1; + configPath.assign(arg, colon); + return 0; + } + else if (mountPoint.empty()) { + mountPoint = arg; + return 1; + } + return 1; +} + +void +NetFS::FuseApp::connectToService() +{ + if (!service) { + Lock(_lock); + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such resource: " + resourceName); + } + + auto proxyAddr = e->second->ServiceIdentity; + for (const auto & ep : e->second->Endpoints) { + proxyAddr += ":" + ep; + } + service = NetFS::ServicePrx::checkedCast(ic->stringToProxy(proxyAddr)); + if (!service) { + throw std::runtime_error("Invalid service proxy: " + proxyAddr); + } + } +} + +void +NetFS::FuseApp::connectToVolume() +{ + if (!volume) { + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such export: " + resourceName); + } + volume = service->connect(e->second->ExportName, "bar"); + if (!volume) { + throw "Invalid filesystem proxy"; + } + } +} + +void +NetFS::FuseApp::connectHandles() +{ + for (const OpenFiles::value_type & of : openFiles) { + try { + of.second->remote->ice_ping(); + } + catch (const Ice::ObjectNotExistException &) { + of.second->remote = volume->open(reqEnv(), of.second->path, of.second->flags); + } + } + for (const OpenDirs::value_type & of : openDirs) { + try { + of.second->remote->ice_ping(); + } + catch (const Ice::ObjectNotExistException &) { + of.second->remote = volume->opendir(reqEnv(), of.second->path); + } + } +} + +void +NetFS::FuseApp::verifyConnection() +{ + Lock(_lock); + if (service) { + try { + service->ice_ping(); + } + catch (const Ice::Exception &) { + service = NULL; + } + } + if (volume) { + try { + volume->ice_ping(); + } + catch (const Ice::Exception &) { + volume = NULL; + } + } +} + +int +NetFS::FuseApp::onError(const std::exception & e) throw() +{ + if (dynamic_cast(&e)) { + verifyConnection(); + connectToService(); + connectToVolume(); + connectHandles(); + return 0; + } + return FuseAppBase::onError(e); +} + +NetFS::ReqEnv +NetFS::FuseApp::reqEnv() +{ + connectToService(); + connectToVolume(); + struct fuse_context * c = fuse_get_context(); + return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; +} + diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h new file mode 100644 index 0000000..f438910 --- /dev/null +++ b/netfs/fuse/fuseApp.h @@ -0,0 +1,115 @@ +#ifndef NETFS_FUSE_H +#define NETFS_FUSE_H + +#include +#include +#include +#include "fuseAppBase.h" +#include "configuration.h" +#include "cache.h" + +namespace NetFS { + class FuseApp : public FuseAppBase { + private: + class OpenDir : public IceUtil::Shared { + public: + OpenDir(DirectoryPrx remote, const std::string & path); + + DirectoryPrx remote; + const std::string path; + }; + typedef IceUtil::Handle OpenDirPtr; + typedef std::map OpenDirs; + + class OpenFile : public IceUtil::Shared { + public: + OpenFile(FilePrx remote, const std::string & path, int flags); + + FilePrx remote; + const std::string path; + const int flags; + }; + typedef IceUtil::Handle OpenFilePtr; + typedef std::map OpenFiles; + + public: + FuseApp(int & argc, char ** argv); + ~FuseApp(); + + private: + void * init (struct fuse_conn_info * info); + int opt_parse(void *, const char * arg, int key, struct fuse_args *); + + void connectToService(); + void connectToVolume(); + void connectHandles(); + void verifyConnection(); + + public: + // misc + int access(const char * p, int a); + int getattr(const char * p, struct stat * s); + int fgetattr(const char *, struct stat *, struct fuse_file_info *); + int chmod(const char *, mode_t); + int chown(const char *, uid_t, gid_t); + int link(const char *, const char *); + int readlink(const char *, char *, size_t); + int rename(const char *, const char *); + int symlink(const char *, const char *); + int unlink(const char *); + int utimens(const char *, const struct timespec tv[2]); + int mknod(const char *, mode_t, dev_t); + // dirs + int opendir(const char * p, struct fuse_file_info * fi); + int releasedir(const char *, struct fuse_file_info * fi); + int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi); + int mkdir(const char *, mode_t); + int rmdir(const char *); + // files + int open(const char * p, struct fuse_file_info * fi); + int create(const char *, mode_t, struct fuse_file_info *); + int release(const char *, struct fuse_file_info * fi); + int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi); + int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi); + int truncate(const char *, off_t); + int ftruncate(const char *, off_t, struct fuse_file_info *); + // fs + int statfs(const char *, struct statvfs *); + // stuff + int onError(const std::exception & err) throw(); + + private: + void setProxy(OpenFilePtr, uint64_t & fh); + OpenFilePtr getFileProxy(uint64_t localID) const; + void clearFileProxy(uint64_t localID); + + void setProxy(OpenDirPtr, uint64_t & fh); + OpenDirPtr getDirProxy(uint64_t localID) const; + void clearDirProxy(uint64_t localID); + + ReqEnv reqEnv(); + + int & _argc; + char ** _argv; + Ice::CommunicatorPtr ic; + Client::ConfigurationPtr fc; + mutable boost::shared_mutex _lock; + + NetFS::VolumePrx volume; + NetFS::ServicePrx service; + + std::string mountPoint; + std::string resourceName; + std::string configPath; + + OpenDirs openDirs; + int openDirID; + OpenFiles openFiles; + int openFileID; + + typedef Cache>> StatCache; + StatCache statCache; + }; +} + +#endif diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index 75cb5a5..ad3d017 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -1,5 +1,5 @@ #include "pch.hpp" -#include "fuse.h" +#include "fuseApp.h" #include "misc.h" #include "lockHelpers.h" #include diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index 9ce260c..b6cf8db 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -1,7 +1,7 @@ #include "pch.hpp" #include #include -#include "fuse.h" +#include "fuseApp.h" #include "lockHelpers.h" #include diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index 0e366be..f6c5976 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -1,5 +1,5 @@ #include "pch.hpp" -#include "fuse.h" +#include "fuseApp.h" #include #include #include diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp index 0b29d86..36c6af5 100644 --- a/netfs/fuse/fuseSystem.cpp +++ b/netfs/fuse/fuseSystem.cpp @@ -1,6 +1,6 @@ #include "pch.hpp" #include -#include "fuse.h" +#include "fuseApp.h" int NetFS::FuseApp::statfs(const char * p, struct statvfs * vfs) diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp new file mode 100644 index 0000000..de89660 --- /dev/null +++ b/netfs/fuse/netfs.cpp @@ -0,0 +1,8 @@ +#include "fuseApp.h" + +int +main(int argc, char* argv[]) +{ + return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); +} + diff --git a/netfs/fuse/pch.hpp b/netfs/fuse/pch.hpp index 7cb79ed..b2a0908 100644 --- a/netfs/fuse/pch.hpp +++ b/netfs/fuse/pch.hpp @@ -3,11 +3,9 @@ #define NETFS_FUSE_PCH #include "../lib/pch.hpp" -#include "../../libfusepp/fuseapp.h" +#include "../../libfusepp/fuseAppBase.h" #include #endif #endif - - -- cgit v1.2.3