Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/openvfsfuse/openvfsfuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};


Expand Down Expand Up @@ -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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you completely get rid of the _fuseInstance var by calling fuse_get_context()->fuse ?

}

return NULL;
}

Expand Down Expand Up @@ -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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please put that behind a function getFusePath() similar to the other two? That way we can properly document the difference between the three pathes.

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<VFSFuseContext>(openVFSArgs);
Expand Down
1 change: 1 addition & 0 deletions src/openvfsfuse/openvfsfuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
10 changes: 10 additions & 0 deletions src/openvfsfuse/socketthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "socketthread.h"
#include "openvfsfuse.h"
#include "sharedmap.h"
#include "strtools.h"

Expand Down Expand Up @@ -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<string>();
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<string> attribs = StrTools::split(msgAttr, ':');
if (attribs.size() == 3) {
Expand Down