Skip to content
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

Add saunafs command on Windows #298

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Conversation

rolysr
Copy link
Collaborator

@rolysr rolysr commented Feb 12, 2025

This PR is related to the corresponding integration of the saunafs tool on a Windows environment. The main changes were:

  • Fix related dependencies and added Windows specific code to make the tools submodule to be compiled on Windows.
  • Fix the open_master_conn function in order to correctly get the corresponding inode from a given Windows file system path.
  • Add Windows specific code for making the commands makesnapshot and rremove to work on Windows.

@rolysr rolysr force-pushed the add-saunafs-command-on-windows branch 2 times, most recently from 20157eb to 34eaa8d Compare February 12, 2025 14:40
For making the saunafs command available on Windows, this commit adds
the necessary changes to compile the saunafs command on Windows.

Signed-off-by: rolysr <[email protected]>
The `open_master_conn` function was not working properly on Windows
when using it with the saunafs tool because it was not properly
resolving the inode by a given path on the file system. This commit
fixes that issue.

Signed-off-by: rolysr <[email protected]>
The makesnapshot command was failing on saunafs tool on Windows because
of not correctly resolving the source inode from which the snapshot
was going to be created. This commit fixes that issue.

Signed-off-by: rolysr <[email protected]>
The previous implementation of recursive remove was not correctly
delimiting the path separator for a parent path from a given full path
when using the saunafs tool on Windows. This commit fixes that issue.

Signed-off-by: rolysr <[email protected]>
@rolysr rolysr force-pushed the add-saunafs-command-on-windows branch from 34eaa8d to add65ff Compare February 12, 2025 22:17
Copy link
Collaborator

@dmga44 dmga44 left a comment

Choose a reason for hiding this comment

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

Great work! 👍

As a general comment, I think the changes would have looked better if they were ordered like:

  • enough to be able to compile in Windows
  • fixes on open_master_conn function, including the changes in the protocol.
  • fixes on each of the tools, single commit or multiple commits, as you see fit.
    Though it would be a chore to make it that way now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should also move the file quota_database.cc file to make the change more consistent.


#else
#include <signal.h>
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please notice the missing endline.

@@ -25,6 +25,8 @@
#include <utility>
#include "protocol/quota.h"
#include <master/filesystem_node_types.h>
#include "common/quota_database.h"
#include "master/filesystem_freenode.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should come to an agreement on whether to use quotes or angular in these kind of includes.

inode = current_inode;
return SAUNAFS_STATUS_OK;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there are some permission checks missing here.

You could think of this function as several fs_lookup calls one on top of the other. There are things which are there that are not present here, to mention some:

  • call to verify_session
  • call to fsnodes_get_node_for_operation (I think this is the one doing the permission check)
  • checks on the implicit entries (. and ..)
  • call to fsnodes_namecheck
  • entry in gFsStatsArray and increasing its count.

Consider the approach to partition the path and call severall fs_lookup (ignoring the gFsStatsArray update).

Also notice that some of these add-ups could be applied in fs_full_path_by_inode.

uint32_t uid = getuid();
uint32_t gid = getgid();
#endif
Client::Context *ret = new Client::Context(uid, gid,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change required? I don't think we are building the this client in Windows.

int srcname_len = strlen(srcnames[i]);
if (srcnames[i][srcname_len - 1] == '/' ||
srcnames[i][srcname_len - 1] == '\\') {
srcnames[i][srcname_len - 1] = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider writing
srcnames[i][srcname_len - 1] = '\0';
to make clearer you are setting the end of the string.

Comment on lines +283 to +297
#ifdef _WIN32
if (GetFullPathName(srcnames[i], PATH_MAX, src, NULL) ==
0) {
printf("%s: GetFullPathName error: %lu\n",
srcnames[i], GetLastError());
return -1;
}
#else
if (realpath(srcnames[i], src) == NULL) {
printf("%s: realpath error on %s: %s\n", srcnames[i], src,
strerr(errno));
status = -1;
continue;
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it correct that the Windows code is directly returning while the Linux analogous one is setting up status and continuing?

Comment on lines +326 to +340
#ifdef _WIN32
if (GetFullPathName(srcnames[i], PATH_MAX, src, NULL) ==
0) {
printf("%s: GetFullPathName error: %lu\n",
srcnames[i], GetLastError());
return -1;
}
#else
if (realpath(srcnames[i], src) == NULL) {
printf("%s: realpath error on %s: %s\n", srcnames[i], src,
strerr(errno));
status = -1;
continue;
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same concern here.

Comment on lines +184 to +194
#ifdef _WIN32
if (GetFullPathName(dir, PATH_MAX, to, NULL) == 0) {
printf("%s: GetFullPathName error: %lu\n", dir, GetLastError());
return -1;
}
#else
if (realpath(dir, to) == NULL) {
printf("%s: realpath error on %s: %s\n", dir, to, strerr(errno));
return -1;
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider finding a way to try to not repeat code (and preprocessor directives) in the GetFullPathName and realpath consecutive calls.

if (endp == path) {
if ((endp - path) == 2 && path[1] == ':' && path[2] == '\\') {
path[3] = '.';
path[4] = '\0';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please consider the case of mountpoints in subfolders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants