diff options
Diffstat (limited to 'netfs')
-rw-r--r-- | netfs/fuse/Jamfile.jam | 3 | ||||
-rw-r--r-- | netfs/fuse/fuseAppBase.cpp | 226 | ||||
-rw-r--r-- | netfs/fuse/fuseAppBase.h | 172 | ||||
-rw-r--r-- | netfs/fuse/netfs.cpp | 4 | ||||
-rw-r--r-- | netfs/unittests/mockFuse.cpp | 4 | ||||
-rw-r--r-- | netfs/unittests/mockFuse.h | 2 |
6 files changed, 403 insertions, 8 deletions
diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index 4340687..d0ad9b7 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -22,10 +22,8 @@ lib netfsClientConfiguration : lib netfsClient : netfsClientConfiguration [ glob *.cpp : netfs.cpp ] - [ glob ../../libfusepp/fuse*.cpp ] : <define>_FILE_OFFSET_BITS=64 - <include>../../libfusepp <implicit-dependency>../ice//netfsComms <library>netfsClientConfiguration <implicit-dependency>netfsClientConfiguration @@ -44,7 +42,6 @@ lib netfsClient : <library>..//slicer-xml : : <include>. - <include>../../libfusepp <library>../ice//netfsComms <library>Glacier2 <implicit-dependency>../ice//netfsComms diff --git a/netfs/fuse/fuseAppBase.cpp b/netfs/fuse/fuseAppBase.cpp new file mode 100644 index 0000000..4653efb --- /dev/null +++ b/netfs/fuse/fuseAppBase.cpp @@ -0,0 +1,226 @@ +#include "fuseAppBase.h" +#include <errno.h> +#include <assert.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <typeinfo> + +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; +} +void FuseAppBase::log(int level, const char * message) const throw() +{ + logf(level, "%s", message); +} +void FuseAppBase::logf(int level, const char * fmt, ...) const throw() +{ + va_list args; + va_start(args, fmt); + vlogf(level, fmt, args); + va_end(args); +} + +int FuseAppBase::onError(const std::exception & e) throw() +{ + logf(LOG_ERR, "Unknown exception (what: %s)", 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) +{ + struct fuse_opt fuse_opts[] = { + { NULL, 0, 0 } + }; + fuseApp = this; + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + if (fuse_opt_parse(&args, fuseApp, fuse_opts, + fuseCall<void *, const char *, int, struct fuse_args *>::helper<&FuseAppBase::opt_parse>) == -1) { + exit(1); + } + return args; +} + diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h new file mode 100644 index 0000000..388ac5b --- /dev/null +++ b/netfs/fuse/fuseAppBase.h @@ -0,0 +1,172 @@ +#ifndef FUSEAPP_H +#define FUSEAPP_H + +#define FUSE_USE_VERSION 26 +#include <fuse.h> +#include <typeinfo> +#include <exception> +#include <stdio.h> +#include <errno.h> +#include <syslog.h> +#include <visibility.h> +#include <buffer.h> + +class DLL_PUBLIC 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(); + void log(int level, const char * message) const throw(); + void logf(int level, const char * fmt, ...) const throw() __attribute__ ((__format__ (__printf__, 3, 4))); + virtual void vlogf(int level, const char * fmt, va_list) const throw() __attribute__ ((__format__ (__printf__, 3, 0))) = 0; + + 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)) + template <typename FuseApp> + static int run(int argc, char ** argv, FuseApp * fa) + { + auto args = fa->runint(argc, argv); + struct fuse_operations operations = { + fuseCall<const char *, struct stat *>::GetHelper(getattr), + fuseCall<const char *, char *, size_t>::GetHelper(readlink), + NULL, // getdir deprecated + fuseCall<const char *, mode_t, dev_t>::GetHelper(mknod), + fuseCall<const char *, mode_t>::GetHelper(mkdir), + fuseCall<const char *>::GetHelper(unlink), + fuseCall<const char *>::GetHelper(rmdir), + fuseCall<const char *, const char *>::GetHelper(symlink), + fuseCall<const char *, const char *>::GetHelper(rename), + fuseCall<const char *, const char *>::GetHelper(link), + fuseCall<const char *, mode_t>::GetHelper(chmod), + fuseCall<const char *, uid_t, gid_t>::GetHelper(chown), + fuseCall<const char *, off_t>::GetHelper(truncate), + NULL, // utime deprecated + fuseCall<const char *, struct fuse_file_info *>::GetHelper(open), + fuseCall<const char *, char *, size_t, off_t, struct fuse_file_info *>::GetHelper(read), + fuseCall<const char *, const char *, size_t, off_t, struct fuse_file_info *>::GetHelper(write), + fuseCall<const char *, struct statvfs *>::GetHelper(statfs), + fuseCall<const char *, struct fuse_file_info *>::GetHelper(flush), + fuseCall<const char *, struct fuse_file_info *>::GetHelper(release), + fuseCall<const char *, int, struct fuse_file_info *>::GetHelper(fsync), + fuseCall<const char *, const char *, const char *, size_t, int>::GetHelper(setxattr), + fuseCall<const char *, const char *, char *, size_t>::GetHelper(getxattr), + fuseCall<const char *, char *, size_t>::GetHelper(listxattr), + fuseCall<const char *, const char *>::GetHelper(removexattr), + fuseCall<const char *, struct fuse_file_info *>::GetHelper(opendir), + fuseCall<const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *>::GetHelper(readdir), + fuseCall<const char *, struct fuse_file_info *>::GetHelper(releasedir), + fuseCall<const char *, int, struct fuse_file_info *>::GetHelper(fsyncdir), + fuseInit, + fuseDestroy, + fuseCall<const char *, int>::GetHelper(access), + fuseCall<const char *, mode_t, struct fuse_file_info *>::GetHelper(create), + fuseCall<const char *, off_t, struct fuse_file_info *>::GetHelper(ftruncate), + fuseCall<const char *, struct stat *, struct fuse_file_info *>::GetHelper(fgetattr), +#if (FUSE_MINOR_VERSION >= 6) + fuseCall<const char *, struct fuse_file_info *, int, struct flock *>::GetHelper(lock), + fuseCall<const char *, const struct timespec [2]>::GetHelper(utimens), + fuseCall<const char *, size_t, uint64_t *>::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<const char *, int, void *, struct fuse_file_info *, unsigned int, void *>::GetHelper(ioctl), + fuseCall<const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *>::GetHelper(poll), +#if (FUSE_MINOR_VERSION >= 9) + fuseCall<const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *>::GetHelper(write_buf), + fuseCall<const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *>::GetHelper(read_buf), + fuseCall<const char *, struct fuse_file_info *, int>::GetHelper(flock), + fuseCall<const char *, int, off_t, off_t, struct fuse_file_info *>::GetHelper(fallocate), +#endif +#endif +#endif + }; + return fa->main(args.argc, args.argv, &operations); + } + struct fuse_args runint(int, char **); + + private: + static void * fuseInit(struct fuse_conn_info *conn); + static void fuseDestroy(void *); + + template <typename... Args> + class DLL_PRIVATE fuseCall { + public: + typedef int (*WrapperFunc)(Args...); + template <int (FuseAppBase::*b)(Args...)> + static WrapperFunc getHelper(bool implemented) + { + auto func = &helper<b>; + return implemented ? func : NULL; + } + template <int (FuseAppBase::*f)(Args...)> + 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<f>(a...); + } + catch (...) { + fuseApp->logf(LOG_ERR, "Unknown exception calling %s", typeid(f).name()); + return -ENOSYS; + } + } + }; + + static FuseAppBase * fuseApp; +}; + +#endif + diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp index 945c599..2039eed 100644 --- a/netfs/fuse/netfs.cpp +++ b/netfs/fuse/netfs.cpp @@ -29,9 +29,9 @@ class FuseImpl : public NetFS::FuseApp { return ::fuse_main(argc, argv, ops, this); } - void log(int priority, const std::string & message) const throw() override + void vlogf(int priority, const char * fmt, va_list args) const throw() override { - syslog(priority, "%s", message.c_str()); + vsyslog(priority, fmt, args); } }; diff --git a/netfs/unittests/mockFuse.cpp b/netfs/unittests/mockFuse.cpp index 1a3b0ce..1dca70b 100644 --- a/netfs/unittests/mockFuse.cpp +++ b/netfs/unittests/mockFuse.cpp @@ -47,9 +47,9 @@ FuseMock::ReadConfiguration(const boost::filesystem::path & path) const } void -FuseMock::log(int, const std::string & message) const throw() +FuseMock::vlogf(int, const char * fmt, va_list args) const throw() { - BOOST_TEST_MESSAGE(message); + BOOST_TEST_MESSAGE(vstringf(fmt, args)); } FuseMockHost::FuseMockHost(const std::string & ep, const Ice::StringSeq & a) : diff --git a/netfs/unittests/mockFuse.h b/netfs/unittests/mockFuse.h index 4002dab..fa3a92b 100644 --- a/netfs/unittests/mockFuse.h +++ b/netfs/unittests/mockFuse.h @@ -11,7 +11,7 @@ class DLL_PUBLIC FuseMock : public NetFS::FuseApp { struct fuse_context * fuse_get_context() override; int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) override; int main(int, char **, const struct fuse_operations * o) override; - void log(int, const std::string &) const throw() override; + void vlogf(int, const char *, va_list) const throw() override; fuse_operations ops; |