From ead8b5b97ffc2300d96b2ea35d8ea6443a1019b6 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 12 Nov 2015 15:03:22 -0800 Subject: [PATCH] Allow stopping the filesystem --- fuse/Fuse.cpp | 12 +++++++++++- fuse/Fuse.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fuse/Fuse.cpp b/fuse/Fuse.cpp index f625950e..54878397 100644 --- a/fuse/Fuse.cpp +++ b/fuse/Fuse.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using std::vector; using std::string; @@ -212,11 +213,12 @@ Fuse::~Fuse() { } Fuse::Fuse(Filesystem *fs) - :_fs(fs), _running(false) { + :_fs(fs), _mountdir(), _running(false) { } void Fuse::run(int argc, char **argv) { vector _argv(argv, argv + argc); + _mountdir = argv[1]; fuse_main(_argv.size(), _argv.data(), operations(), (void*)this); } @@ -224,6 +226,14 @@ bool Fuse::running() const { return _running; } +void Fuse::stop() { + //TODO Find better way to unmount (i.e. don't use external fusermount). Unmounting by kill(getpid(), SIGINT) worked, but left the mount directory transport endpoint as not connected. + int ret = system(("fusermount -z -u " + _mountdir.native()).c_str()); // "-z" takes care that if the filesystem can't be unmounted right now because something is opened, it will be unmounted as soon as it can be. + if (ret != 0) { + LOG(ERROR) << "Could not unmount filesystem"; + } +} + int Fuse::getattr(const bf::path &path, struct stat *stbuf) { #ifdef FSPP_LOG LOG(DEBUG) << "getattr(" << path << ", _, _)"; diff --git a/fuse/Fuse.h b/fuse/Fuse.h index 3d2803f2..40080480 100644 --- a/fuse/Fuse.h +++ b/fuse/Fuse.h @@ -23,6 +23,7 @@ public: void run(int argc, char **argv); bool running() const; + void stop(); int getattr(const boost::filesystem::path &path, struct stat *stbuf); int fgetattr(const boost::filesystem::path &path, struct stat *stbuf, fuse_file_info *fileinfo); @@ -57,6 +58,7 @@ public: private: Filesystem *_fs; + boost::filesystem::path _mountdir; bool _running; DISALLOW_COPY_AND_ASSIGN(Fuse);