-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add V2/INVALIDATE_PATH socket message for cache invalidation #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,23 @@ static int openVFSfuse_removexattr(const char *orig_path, const char *name) | |
| return Xattr::removexattr(path, name); | ||
| } | ||
|
|
||
| void openvfsfuse_invalidate_path(const std::string &path) | ||
| { | ||
| if (_fuseInstance) { | ||
| // Prepend "/" if not absolute (internal paths are relative) | ||
| std::string fusePath = path; | ||
| if (!fusePath.empty() && fusePath[0] != '/') { | ||
| fusePath = "/" + fusePath; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can use |
||
| int res = fuse_invalidate_path(_fuseInstance, fusePath.c_str()); | ||
| if (res == 0 || res == -ENOENT) { | ||
| openvfsfuse_log(fusePath, "invalidate", 0, "path invalidated"); | ||
| } else { | ||
| openvfsfuse_log(fusePath, "invalidate", res, "invalidate failed"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int initializeOpenVFSFuse(openVFSfuse_Args &openVFSArgs) | ||
| { | ||
| const auto contextInstance = std::make_unique<VFSFuseContext>(openVFSArgs); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<string>(); | ||
| cout << "Invalidating path: " << path << endl; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
| openvfsfuse_invalidate_path(path); | ||
| } catch (json::exception &e) { | ||
| std::cerr << "Invalid INVALIDATE_PATH message: " << msgAttr << e.what() << std::endl; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| } | ||
| } else if (msgType == "VERSION") { | ||
| vector<string> attribs = StrTools::split(msgAttr, ':'); | ||
| if (attribs.size() == 3) { | ||
|
|
||
There was a problem hiding this comment.
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
_fuseInstancevar by callingfuse_get_context()->fuse?