diff --git a/src/openvfsfuse/openvfsfuse.cpp b/src/openvfsfuse/openvfsfuse.cpp index 470ab80..96c091e 100644 --- a/src/openvfsfuse/openvfsfuse.cpp +++ b/src/openvfsfuse/openvfsfuse.cpp @@ -147,6 +147,9 @@ std::string getcallername(fuse_context *context) static SharedMap _jobs; static SocketThread _socketThread("SocketThread", _jobs); +// Global fuse pointer for invalidation from socket thread +static struct fuse *_fuseInstance = nullptr; + static int _transfer_id{12}; @@ -178,6 +181,12 @@ static void *openVFSfuse_init(struct fuse_conn_info *, fuse_config *) { openvfsfuse_log("/path", "_init", 1, "**** INIT called"); + // Store fuse instance for invalidation from socket thread + auto *ctx = fuse_get_context(); + if (ctx) { + _fuseInstance = ctx->fuse; + } + return NULL; } @@ -725,6 +734,22 @@ static int openVFSfuse_removexattr(const char *orig_path, const char *name) return Xattr::removexattr(path, name); } +void openvfsfuse_invalidate_path(const std::string &path) +{ + auto *ctx = fuse_get_context(); + if (!ctx || !ctx->fuse) { + return; + } + const auto fusePath = getInternalPath(path); + std::string fuseStr = "/" + fusePath.string(); + int res = fuse_invalidate_path(ctx->fuse, fuseStr.c_str()); + if (res == 0 || res == -ENOENT) { + openvfsfuse_log(fuseStr, "invalidate", 0, "path invalidated"); + } else { + openvfsfuse_log(fuseStr, "invalidate", res, "invalidate failed"); + } +} + int initializeOpenVFSFuse(openVFSfuse_Args &openVFSArgs) { const auto contextInstance = std::make_unique(openVFSArgs); diff --git a/src/openvfsfuse/openvfsfuse.h b/src/openvfsfuse/openvfsfuse.h index bdd0deb..8a0a812 100644 --- a/src/openvfsfuse/openvfsfuse.h +++ b/src/openvfsfuse/openvfsfuse.h @@ -26,4 +26,5 @@ struct openVFSfuse_Args }; int initializeOpenVFSFuse(openVFSfuse_Args &openVFSArgs); +void openvfsfuse_invalidate_path(const std::string &path); void openvfsfuse_log(const std::string &path, const char *action, int returncode, const char *format, ...); diff --git a/src/openvfsfuse/socketthread.cpp b/src/openvfsfuse/socketthread.cpp index 8d74f83..1d5c168 100644 --- a/src/openvfsfuse/socketthread.cpp +++ b/src/openvfsfuse/socketthread.cpp @@ -21,6 +21,7 @@ */ #include "socketthread.h" +#include "openvfsfuse.h" #include "sharedmap.h" #include "strtools.h" @@ -230,6 +231,15 @@ void SocketThread::handleReceivedMsg(const std::string &rawmsg) cout << "Setting Job ID " << id << " to result " << res << endl; } } + } else if (msgType == "V2/INVALIDATE_PATH") { + try { + const auto j = json::parse(msgAttr); + const auto path = j["arguments"]["path"].get(); + openvfsfuse_log(path, "invalidate_path", 0, "received via socket"); + openvfsfuse_invalidate_path(path); + } catch (json::exception &e) { + openvfsfuse_log("", "invalidate_path", -1, "invalid message: %s %s", msgAttr.c_str(), e.what()); + } } else if (msgType == "VERSION") { vector attribs = StrTools::split(msgAttr, ':'); if (attribs.size() == 3) {