Allow stopping the filesystem
This commit is contained in:
parent
5efc5c5537
commit
ead8b5b97f
@ -7,6 +7,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <messmer/cpp-utils/assert/assert.h>
|
#include <messmer/cpp-utils/assert/assert.h>
|
||||||
#include <messmer/cpp-utils/logging/logging.h>
|
#include <messmer/cpp-utils/logging/logging.h>
|
||||||
|
#include <csignal>
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::string;
|
using std::string;
|
||||||
@ -212,11 +213,12 @@ Fuse::~Fuse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Fuse::Fuse(Filesystem *fs)
|
Fuse::Fuse(Filesystem *fs)
|
||||||
:_fs(fs), _running(false) {
|
:_fs(fs), _mountdir(), _running(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fuse::run(int argc, char **argv) {
|
void Fuse::run(int argc, char **argv) {
|
||||||
vector<char*> _argv(argv, argv + argc);
|
vector<char*> _argv(argv, argv + argc);
|
||||||
|
_mountdir = argv[1];
|
||||||
fuse_main(_argv.size(), _argv.data(), operations(), (void*)this);
|
fuse_main(_argv.size(), _argv.data(), operations(), (void*)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +226,14 @@ bool Fuse::running() const {
|
|||||||
return _running;
|
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) {
|
int Fuse::getattr(const bf::path &path, struct stat *stbuf) {
|
||||||
#ifdef FSPP_LOG
|
#ifdef FSPP_LOG
|
||||||
LOG(DEBUG) << "getattr(" << path << ", _, _)";
|
LOG(DEBUG) << "getattr(" << path << ", _, _)";
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
|
|
||||||
void run(int argc, char **argv);
|
void run(int argc, char **argv);
|
||||||
bool running() const;
|
bool running() const;
|
||||||
|
void stop();
|
||||||
|
|
||||||
int getattr(const boost::filesystem::path &path, struct stat *stbuf);
|
int getattr(const boost::filesystem::path &path, struct stat *stbuf);
|
||||||
int fgetattr(const boost::filesystem::path &path, struct stat *stbuf, fuse_file_info *fileinfo);
|
int fgetattr(const boost::filesystem::path &path, struct stat *stbuf, fuse_file_info *fileinfo);
|
||||||
@ -57,6 +58,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Filesystem *_fs;
|
Filesystem *_fs;
|
||||||
|
boost::filesystem::path _mountdir;
|
||||||
bool _running;
|
bool _running;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Fuse);
|
DISALLOW_COPY_AND_ASSIGN(Fuse);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user