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 f7d7e01 commit a77b983
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
32 changes: 27 additions & 5 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 All @@ -212,7 +227,7 @@ std::string name_to_use = std::string(name);
}
#endif
if (!get_full_path(name_to_use.c_str(), rpath)) {
printf("%s: get_full_path error: %lu\n", name);
printf("%s: get_full_path error\n", name);
return -1;
}
#ifndef _WIN32
Expand Down Expand Up @@ -307,16 +322,23 @@ 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;
}
}
#endif

gCurrentMaster = sd;
return sd;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/recursive_remove.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::string name_to_use = std::string(file_name);
}
#endif
if (!get_full_path(name_to_use.c_str(), path_buf)) {
printf("%s: get_full_path error: %lu\n", file_name);
printf("%s: get_full_path error\n", file_name);
return -1;
}
std::string parent_path(path_buf);
Expand Down
10 changes: 4 additions & 6 deletions src/tools/snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static int snapshot(const char *dstname, char *const *srcnames, uint32_t srcelem
return -1;
}
if (!get_full_path(dir, to)) {
printf("%s: get_full_path error: %lu\n", dir);
printf("%s: get_full_path error\n", dir);
return -1;
}
if (bsd_basename(dstname, base) < 0) {
Expand All @@ -204,7 +204,7 @@ static int snapshot(const char *dstname, char *const *srcnames, uint32_t srcelem
return make_snapshot(to, base, srcnames[0], sst.st_ino, canowerwrite, long_wait, ignore_missing_src, initial_batch_size);
} else { // dst exists
if (!get_full_path(dstname, to)) {
printf("%s: get_full_path error: %lu\n", dstname);
printf("%s: get_full_path error\n", dstname);
return -1;
}
if (!S_ISDIR(dst.st_mode)) { // dst id not a directory
Expand Down Expand Up @@ -266,8 +266,7 @@ static int snapshot(const char *dstname, char *const *srcnames, uint32_t srcelem
if (!S_ISDIR(sst.st_mode)) { // src is not a directory
if (!S_ISLNK(sst.st_mode)) { // src is not a symbolic link
if (!get_full_path(srcnames[i], src)) {
printf("%s: get_full_path error: %lu\n", src,
GetLastError());
printf("%s: get_full_path error\n", src);
status = -1;
continue;
}
Expand Down Expand Up @@ -300,8 +299,7 @@ static int snapshot(const char *dstname, char *const *srcnames, uint32_t srcelem
srcnames[i][l - 1] !=
'/') { // src is a directory and name has trailing slash
if (!get_full_path(srcnames[i], src)) {
printf("%s: get_full_path error: %lu\n", src,
GetLastError());
printf("%s: get_full_path error\n", src);
status = -1;
continue;
}
Expand Down

0 comments on commit a77b983

Please sign in to comment.