git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fsmonitor: option to allow fsmonitor to run against network-mounted repos
@ 2022-08-09 17:44 Eric DeCosta via GitGitGadget
  2022-08-10 16:49 ` Junio C Hamano
  2022-08-11 15:57 ` [PATCH v2 0/2] Option to allow fsmonitor to run against repos on network file systems Eric DeCosta via GitGitGadget
  0 siblings, 2 replies; 20+ messages in thread
From: Eric DeCosta via GitGitGadget @ 2022-08-09 17:44 UTC (permalink / raw)
  To: git; +Cc: Eric DeCosta, Eric DeCosta

From: Eric DeCosta <edecosta@mathworks.com>

Though perhaps not common, there are uses cases where users have large,
network-mounted repos. Having the ability to run fsmonitor against
network paths would benefit those users.

Most modern Samba-based filers have the necessary support to enable
fsmonitor on network-mounted repos. As a first step towards enabling
fsmonitor to work against network-mounted repos, introduce a
configuration option, 'fsmonitor.allowRemote'. Setting this option to
true will override the default behavior (erroring-out) when a
network-mounted repo is detected by fsmonitor.

Additionally, as part of this first step, monitoring of network-mounted
repos will be restricted to those mounted over SMB regardless of the
value of 'fsmonitor.allowRemote' until more extensive testing can be
performed.

Signed-off-by: Eric DeCosta <edecosta@mathworks.com>
---
    Option to allow fsmonitor to run against repos on network file systems

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1317%2Fedecosta-mw%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1317/edecosta-mw/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1317

 compat/fsmonitor/fsm-settings-win32.c | 59 ++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index 907655720bb..d120e4710cf 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -24,6 +24,58 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r)
 	return FSMONITOR_REASON_OK;
 }
 
+/*
+ * 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)
+{
+	int allow;
+
+	if (repo_config_get_bool(r, "fsmonitor.allowremote", &allow) || !allow)
+		return FSMONITOR_REASON_REMOTE;
+
+	return FSMONITOR_REASON_OK;
+}
+
+/*
+ * Check if the remote working directory is mounted via SMB
+ *
+ * For now, remote working directories are only supported via SMB mounts
+*/
+static enum fsmonitor_reason check_smb(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);
+
+	if (h == INVALID_HANDLE_VALUE) {
+		error(_("[GLE %ld] unable to open for read '%ls'"),
+		      GetLastError(), wpath);
+		return FSMONITOR_REASON_ERROR;
+	}
+
+	if (!GetFileInformationByHandleEx(h, FileRemoteProtocolInfo,
+									&proto_info, sizeof(proto_info))) {
+		error(_("[GLE %ld] unable to get protocol information for '%ls'"),
+		      GetLastError(), wpath);
+		CloseHandle(h);
+		return FSMONITOR_REASON_ERROR;
+	}
+
+	CloseHandle(h);
+
+	if (proto_info.Protocol == WNNC_NET_SMB)
+		return FSMONITOR_REASON_OK;
+
+	return FSMONITOR_REASON_ERROR;
+}
+
 /*
  * Remote working directories are problematic for FSMonitor.
  *
@@ -76,6 +128,7 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r)
  */
 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;
@@ -115,7 +168,11 @@ static enum fsmonitor_reason check_remote(struct repository *r)
 		trace_printf_key(&trace_fsmonitor,
 				 "check_remote('%s') true",
 				 r->worktree);
-		return FSMONITOR_REASON_REMOTE;
+
+		reason = check_smb(wfullpath);
+		if (reason != FSMONITOR_REASON_OK)
+			return reason;
+		return check_allow_remote(r);
 	}
 
 	return FSMONITOR_REASON_OK;

base-commit: c50926e1f48891e2671e1830dbcd2912a4563450
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-08-15 17:33 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 17:44 [PATCH] fsmonitor: option to allow fsmonitor to run against network-mounted repos Eric DeCosta via GitGitGadget
2022-08-10 16:49 ` Junio C Hamano
2022-08-10 18:49   ` Eric D
2022-08-10 19:50     ` Junio C Hamano
2022-08-10 20:36       ` Eric D
2022-08-10 21:30         ` Eric D
2022-08-10 21:41           ` Junio C Hamano
2022-08-11 15:57 ` [PATCH v2 0/2] Option to allow fsmonitor to run against repos on network file systems Eric DeCosta via GitGitGadget
2022-08-11 15:57   ` [PATCH v2 1/2] fsmonitor: option to allow fsmonitor to run against network-mounted repos Eric DeCosta via GitGitGadget
2022-08-11 15:57   ` [PATCH v2 2/2] fsmonitor.allowRemote now overrides default behavior Eric DeCosta via GitGitGadget
2022-08-11 16:53     ` Junio C Hamano
2022-08-11 17:49       ` Eric D
2022-08-11 17:53         ` Junio C Hamano
2022-08-11 17:58           ` Eric D
2022-08-11 18:32   ` [PATCH v3] fsmonitor: option to allow fsmonitor to run against network-mounted repos Eric DeCosta via GitGitGadget
2022-08-11 19:33     ` Junio C Hamano
2022-08-11 23:57     ` [PATCH v4] " Eric DeCosta via GitGitGadget
2022-08-12 18:23       ` Junio C Hamano
2022-08-15 16:01       ` Jeff Hostetler
2022-08-15 17:33         ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).