git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] fsmonitor.allowRemote now overrides default behavior

From
Eric DeCosta via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 11, 2022, 15:57 UTC
Message-ID
<7a071c9e6be68b58306582dbac5952a5b1bcbc6a.1660233432.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1317.v2.git.1660233432.gitgitgadget@gmail.com>
From: Eric DeCosta <edecosta@mathworks.com>

Reworked the logic around fsmonitor.allowRemote such that if allowRemote is set it will determine if monitoring the remote worktree is allowed.

Get remote protocoal information; if this fails report an error else print it if tracing is enabled.

Fixed fomratting issues.
Signed-off-by: Eric DeCosta <edecosta@mathworks.com>
---
 compat/fsmonitor/fsm-settings-win32.c | 57 ++++++++++++++++-----------
 1 file changed, 33 insertions(+), 24 deletions(-)
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index d120e4710cf..32c0695c6c1 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -27,53 +27,55 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r)
 /*
  * Check if monitoring remote working directories is allowed.
  *
- * By default monitoring remote working directories is not allowed,
- * but users may override this behavior in enviroments where they
- * have proper support.
-*/
-static enum fsmonitor_reason check_allow_remote(struct repository *r)
+ * By default, monitoring remote working directories is
+ * disabled unless on a network filesystem that is known to
+ * behave well.  Users may override this behavior in enviroments where
+ * they have proper support.
+ */
+static int check_config_allowremote(struct repository *r)
 {
 	int allow;
 
-	if (repo_config_get_bool(r, "fsmonitor.allowremote", &allow) || !allow)
-		return FSMONITOR_REASON_REMOTE;
+	if (!repo_config_get_bool(r, "fsmonitor.allowremote", &allow))
+		return allow;
 
-	return FSMONITOR_REASON_OK;
+	return -1; /* fsmonitor.allowremote not set */
 }
 
 /*
- * Check if the remote working directory is mounted via SMB
+ * Check remote working directory protocol.
  *
- * For now, remote working directories are only supported via SMB mounts
-*/
-static enum fsmonitor_reason check_smb(wchar_t *wpath)
+ * Error if client machine cannot get remote protocol information.
+ */
+static void check_remote_protocol(wchar_t *wpath)
 {
 	HANDLE h;
 	FILE_REMOTE_PROTOCOL_INFO proto_info;
 
 	h = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
-					FILE_FLAG_BACKUP_SEMANTICS, NULL);
+			FILE_FLAG_BACKUP_SEMANTICS, NULL);
 
 	if (h == INVALID_HANDLE_VALUE) {
 		error(_("[GLE %ld] unable to open for read '%ls'"),
 		      GetLastError(), wpath);
-		return FSMONITOR_REASON_ERROR;
+		return;
 	}
 
 	if (!GetFileInformationByHandleEx(h, FileRemoteProtocolInfo,
-									&proto_info, sizeof(proto_info))) {
+		&proto_info, sizeof(proto_info))) {
 		error(_("[GLE %ld] unable to get protocol information for '%ls'"),
 		      GetLastError(), wpath);
 		CloseHandle(h);
-		return FSMONITOR_REASON_ERROR;
+		return;
 	}
 
 	CloseHandle(h);
 
-	if (proto_info.Protocol == WNNC_NET_SMB)
-		return FSMONITOR_REASON_OK;
+	trace_printf_key(&trace_fsmonitor,
+				"check_remote_protocol('%ls') remote protocol %#8.8lx",
+				wpath, proto_info.Protocol);
 
-	return FSMONITOR_REASON_ERROR;
+	return;
 }
 
 /*
@@ -128,7 +130,6 @@ static enum fsmonitor_reason check_smb(wchar_t *wpath)
  */
 static enum fsmonitor_reason check_remote(struct repository *r)
 {
-	enum fsmonitor_reason reason;
 	wchar_t wpath[MAX_PATH];
 	wchar_t wfullpath[MAX_PATH];
 	size_t wlen;
@@ -169,10 +170,18 @@ static enum fsmonitor_reason check_remote(struct repository *r)
 				 "check_remote('%s') true",
 				 r->worktree);
 
-		reason = check_smb(wfullpath);
-		if (reason != FSMONITOR_REASON_OK)
-			return reason;
-		return check_allow_remote(r);
+		check_remote_protocol(wfullpath);
+
+		switch (check_config_allowremote(r)) {
+		case 0: /* config overrides and disables */
+			return FSMONITOR_REASON_REMOTE;
+		case 1: /* config overrides and enables */
+			return FSMONITOR_REASON_OK;
+		default:
+			break; /* config has no opinion */
+		}
+
+		return FSMONITOR_REASON_REMOTE;
 	}
 
 	return FSMONITOR_REASON_OK;
-- 
gitgitgadget
Previous: Eric DeCosta via GitGitGadgetNext: Junio C Hamano
Message 10 of 20 in “fsmonitor: option to allow fsmonitor to run against network-mounted repos”
  1. fsmonitor: option to allow fsmonitor to run against network-mounted reposEric DeCosta via GitGitGadget, Aug 9, 2022
  2. Junio C HamanoAug 10, 2022
  3. Eric DAug 10, 2022
  4. Junio C HamanoAug 10, 2022
  5. Eric DAug 10, 2022
  6. Eric DAug 10, 2022
  7. Junio C HamanoAug 10, 2022
  8. 0/2 Option to allow fsmonitor to run against repos on network file systemsEric DeCosta via GitGitGadget, Aug 11, 2022
  9. 1/2 fsmonitor: option to allow fsmonitor to run against network-mounted reposEric DeCosta via GitGitGadget, Aug 11, 2022
  10. 2/2 fsmonitor.allowRemote now overrides default behaviorEric DeCosta via GitGitGadget, Aug 11, 2022
  11. Junio C HamanoAug 11, 2022
  12. Eric DAug 11, 2022
  13. Junio C HamanoAug 11, 2022
  14. Eric DAug 11, 2022
  15. fsmonitor: option to allow fsmonitor to run against network-mounted reposEric DeCosta via GitGitGadget, Aug 11, 2022
  16. Junio C HamanoAug 11, 2022
  17. fsmonitor: option to allow fsmonitor to run against network-mounted reposEric DeCosta via GitGitGadget, Aug 11, 2022
  18. Junio C HamanoAug 12, 2022
  19. Jeff HostetlerAug 15, 2022
  20. Junio C HamanoAug 15, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.