Skip to content

Commit

Permalink
fix(tools): Fix saunafs for sfsmountingsubfolder
Browse files Browse the repository at this point in the history
Previous version of saunafs tool was not properly resolving a given
inode from a path when using it in a Windows client mountpoint with the
`sfsmountingsubfolder` option enabled. This commit fixes that issue.

Signed-off-by: rolysr <[email protected]>
  • Loading branch information
rolysr committed Feb 18, 2025
1 parent 94b335c commit 3d8551c
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/tools/master_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ int get_inode_by_path(int sd, std::string path, uint32_t &inode) {
}
#endif

void get_next_path_iteration(std::string &path) {
size_t pos = path.find_first_of('/');
if (pos != std::string::npos) {
path = path.substr(pos + 1);
pos = path.find_first_of('/');
if (pos != std::string::npos) {
path = path.substr(pos);
} else {
path.clear();
}
} else {
path.clear();
}
}

int open_master_conn(const char *name, uint32_t *inode, mode_t *mode,
[[maybe_unused]] bool needrwfs) {
char rpath[PATH_MAX + 1];
Expand Down Expand Up @@ -307,10 +322,18 @@ std::string name_to_use = std::string(name);
if (lookup_rpath == "/") {
*inode = SPECIAL_INODE_ROOT;
} else {
auto err = get_inode_by_path(sd, lookup_rpath, *inode);
if (err != SAUNAFS_STATUS_OK) {
std::string iteration_lookup_rpath = lookup_rpath;
int inode_by_path_result = SAUNAFS_ERROR_EPERM;
while (!iteration_lookup_rpath.empty() ||
inode_by_path_result != SAUNAFS_STATUS_OK) {
inode_by_path_result =
get_inode_by_path(sd, iteration_lookup_rpath, *inode);

get_next_path_iteration(iteration_lookup_rpath);
}
if (inode_by_path_result != SAUNAFS_STATUS_OK) {
printf("%s: can't get inode from path: %s\n", name,
saunafs_error_string(err));
saunafs_error_string(inode_by_path_result));
tcpclose(sd);
return -1;
}
Expand Down

0 comments on commit 3d8551c

Please sign in to comment.