From patchwork Tue Aug 23 13:03:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12952247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9255AC3F6B0 for ; Tue, 23 Aug 2022 16:32:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244719AbiHWQcP (ORCPT ); Tue, 23 Aug 2022 12:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244225AbiHWQb5 (ORCPT ); Tue, 23 Aug 2022 12:31:57 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93261FE352 for ; Tue, 23 Aug 2022 06:03:45 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id s23so7165619wmj.4 for ; Tue, 23 Aug 2022 06:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=fon4TV/aWInSnIdeE9yS/MSfxyJMThj9u67iYXJxQS0=; b=ItmXgfPoKYC0fLdFtM2X/ifpG20S9P5J21a8ebxHAke0aIlaU70rDfeiDF4PKoJ7U1 ZuJ70TsD0ao7aL6KGX4d6eCVC1nTXaxZAjzFVCAH7VdRafESg8uwoV2WOrRMtqmiVjpD J9DIQYGCvq/7K86CJT8xYoiI40+bBaA+7xJh9+nurDKO0E0YUuNK5m5xKznzXj1z0GZ1 akQ1eWf/8Q6PDegt6BjOAXS4slq27nOExm9xWgTPAJJokQIUU7T0qIyF7H+AAZ79onVx KJHCb/4HA6GTHH4M9IhE0BBjkbtp4eX0nMWAqGrr9pYX7/v8kpoLfKbrVQs/Zdt1xq5O JRkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=fon4TV/aWInSnIdeE9yS/MSfxyJMThj9u67iYXJxQS0=; b=4z4P7vC1ra8tWqDbZjSCCDso5ALGJ55t7sUEhxz/JcnKpL5uhvXrBT3HCUSnCEI0YL SHWN4mdkIJqAXvrsOIDu8KP/Rr1bY8C2fipzNibCAn7Zb2zZdSNyD7fYqlzSwUr/+vGP 8VEYGvIiLC1eqCNDbTw8ntoWvSiFP5ZxcOy7ARum8+jtQhkwaI9X8RvpPK59pLBAYI9n eEHAbrn4uIManGfbyVIgUczcM5yrBx0kBivpaxjHNtr71IO/JZIBY/0RimU2pxEKlvwA REyAnzevey8/fjxf65LCBhO8hMM/x0Sl4A4DpdvUQTx4N/Zqt6b6sW9T4uKOnIaTddR5 7i9A== X-Gm-Message-State: ACgBeo3uCiF4INnF6rW5Qux0z/UZShaK61CuNheG205sHXCKI0yjHPTd Qpg3LzH70eo8OKnZBjUzCmZKExR2ip0= X-Google-Smtp-Source: AA6agR4dMUtMrQCe1+g4O93IqHGuAAWcoXQIuLWtdzn+7IRnW7vUwo24OWz9mdAXig7+z5l22W8Ptg== X-Received: by 2002:a05:600c:384f:b0:3a6:603c:4338 with SMTP id s15-20020a05600c384f00b003a6603c4338mr2147016wmr.192.1661259823506; Tue, 23 Aug 2022 06:03:43 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t14-20020a05600c198e00b003a4f08495b7sm22652850wmq.34.2022.08.23.06.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 06:03:43 -0700 (PDT) Message-Id: <40ce21e85c970953d57e16f70073fbc2d7aa918d.1661259820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 23 Aug 2022 13:03:37 +0000 Subject: [PATCH v2 1/4] fsmonitor: option to allow fsmonitor to run against network-mounted repos Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Though perhaps not common, there are use 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. Signed-off-by: Eric DeCosta --- compat/fsmonitor/fsm-settings-win32.c | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c index 907655720bb..e5ec5b0a9f7 100644 --- a/compat/fsmonitor/fsm-settings-win32.c +++ b/compat/fsmonitor/fsm-settings-win32.c @@ -24,6 +24,59 @@ 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 + * disabled. 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)) + return allow; + + return -1; /* fsmonitor.allowremote not set */ +} + +/* + * Check remote working directory protocol. + * + * Error if client machine cannot get remote protocol information. + */ +static int 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); + + if (h == INVALID_HANDLE_VALUE) { + error(_("[GLE %ld] unable to open for read '%ls'"), + GetLastError(), wpath); + return -1; + } + + if (!GetFileInformationByHandleEx(h, FileRemoteProtocolInfo, + &proto_info, sizeof(proto_info))) { + error(_("[GLE %ld] unable to get protocol information for '%ls'"), + GetLastError(), wpath); + CloseHandle(h); + return -1; + } + + CloseHandle(h); + + trace_printf_key(&trace_fsmonitor, + "check_remote_protocol('%ls') remote protocol %#8.8lx", + wpath, proto_info.Protocol); + + return 0; +} + /* * Remote working directories are problematic for FSMonitor. * @@ -76,6 +129,7 @@ static enum fsmonitor_reason check_vfs4git(struct repository *r) */ static enum fsmonitor_reason check_remote(struct repository *r) { + int ret; wchar_t wpath[MAX_PATH]; wchar_t wfullpath[MAX_PATH]; size_t wlen; @@ -115,6 +169,20 @@ static enum fsmonitor_reason check_remote(struct repository *r) trace_printf_key(&trace_fsmonitor, "check_remote('%s') true", r->worktree); + + ret = check_remote_protocol(wfullpath); + if (ret < 0) + return FSMONITOR_REASON_ERROR; + + 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; } From patchwork Tue Aug 23 13:03:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12952248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 075E9C32772 for ; Tue, 23 Aug 2022 16:32:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244757AbiHWQcQ (ORCPT ); Tue, 23 Aug 2022 12:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244745AbiHWQb6 (ORCPT ); Tue, 23 Aug 2022 12:31:58 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75975FE37E for ; Tue, 23 Aug 2022 06:03:46 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id m10-20020a05600c3b0a00b003a603fc3f81so7709707wms.0 for ; Tue, 23 Aug 2022 06:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=/zzF2jGn0GacHZ51T7NWmhYhY7TMlOeRLghvEMcULuM=; b=BIsCjWo/T8FVLkLcVonGME+2Se0LgMqakXu8NMCNDY+2wU+jqS4py980XNzbd7w0Ro 9uReYruQ3CNYQt5qwEWSmGXW+yTl0w6NodYI8AJ54KHmJCJqnjVmAzhdHKEQsZ4x31UQ DlbHuUYNSlgLnac6q5sdzj8IiOC8Xrsr61ztNRhR/F8mu1zbIsRgAABZuAKz8LwnFLkp MSw7D/MgySBp8FJOBawiz5jTkIpk/HgGkbx1M0PdRRp60n12qWl3ws9JzhuuB7vuUo2i rhhZXMmsCacnKDDgRgfSVzUnHe3moW58ieHKDBg/+UOwHewbsszAAktcOf3jRnljdNqs MYdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=/zzF2jGn0GacHZ51T7NWmhYhY7TMlOeRLghvEMcULuM=; b=iWSbtVhKufMhmuMpLqnpr/ThQ+bl1md3QDpwIvjHbVEu041H8UDU50Y/MM+9nXN4gR AX3UjO18H87ViT3iMcG/F9iIdvKSIIV5t7ohjw4GEi4yBMnGHnxP+Rx/iQj03udG50KK 0kCHfoLWEvjbnisNTxfSDhdVm73VuNaW44uLsp7zvX7cm0FaIJmpBClnYkEizllG1G8s SmEAbTtY1VuxqAhbyde+roVHkSM2SshmPiGjyPSiu0gHt3J+DmQ+JZ1dDSGZNhMdrdjK P1ibcLu6qPpxWKH5CldwXVhLTJaYQMGMQ3qXLcFQakgSNk7TQbUFaUUBt2em2RtVJsdX AqpA== X-Gm-Message-State: ACgBeo2DqxLfe9FIv78WSwUIuRNZMy8xwL4B/IDy17EX1sU4xq6nLv9r VPBPTEWhOL6eZe2ZT0sf+JBGIR5/518= X-Google-Smtp-Source: AA6agR5zSPjhukbFwBN7BBzc2GkS0+YF/GvZEI2ITQzHidWujUyPMvxx0y+AASesN180S2jErqz5VQ== X-Received: by 2002:a05:600c:3516:b0:3a5:c28a:f01d with SMTP id h22-20020a05600c351600b003a5c28af01dmr2245999wmq.165.1661259824572; Tue, 23 Aug 2022 06:03:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v8-20020a05600c214800b003a5c244fc13sm22375198wml.2.2022.08.23.06.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 06:03:44 -0700 (PDT) Message-Id: <46b4efd96ccf69db1525130efc1d34f13b649159.1661259820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 23 Aug 2022 13:03:38 +0000 Subject: [PATCH v2 2/4] fsmonitor: macOS: allow fsmonitor to run against network-mounted repos Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , Eric DeCosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric DeCosta From: Eric DeCosta Follow-on to the work done to allow Windows to work against network-mounted repos. Have macOS take advantage of the same configuration option, 'fsmonitor.allowRemote' that was introduced for Windows. Setting this option to true will override the default behavior (erroring-out) when a network-mounted repo is detected by fsmonitor. The added wrinkle being that the Unix domain socket (UDS) file used for IPC cannot be created in a network location; instead $HOME is used if 'fsmonitor.allowRemote' is true. If $HOME is in a network location, allow the user to override this via the 'fsmonitor.socketDir' configuration option. There the user can specify any local directory for the location of the UDS file. Signed-off-by: Eric DeCosta --- fsmonitor-ipc.c | 40 ++++++++++++++++++++++++-- fsmonitor-ipc.h | 6 ++++ fsmonitor-settings.c | 67 ++++++++++++++++++++++++++++++++++++++++++-- fsmonitor-settings.h | 4 +++ 4 files changed, 112 insertions(+), 5 deletions(-) diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c index 789e7397baa..1e3f0a6cf48 100644 --- a/fsmonitor-ipc.c +++ b/fsmonitor-ipc.c @@ -1,7 +1,6 @@ #include "cache.h" -#include "fsmonitor.h" -#include "simple-ipc.h" #include "fsmonitor-ipc.h" +#include "fsmonitor-settings.h" #include "run-command.h" #include "strbuf.h" #include "trace2.h" @@ -47,7 +46,42 @@ int fsmonitor_ipc__is_supported(void) return 1; } -GIT_PATH_FUNC(fsmonitor_ipc__get_path, "fsmonitor--daemon.ipc") +GIT_PATH_FUNC(fsmonitor_ipc__get_default_path, "fsmonitor--daemon.ipc") + +const char *fsmonitor_ipc__get_path(void) +{ +#ifdef WIN32 + return fsmonitor_ipc__get_default_path(); +#else + char *retval; + SHA_CTX sha1ctx; + const char *git_dir; + const char *sock_dir; + struct strbuf ipc_file = STRBUF_INIT; + unsigned char hash[SHA_DIGEST_LENGTH]; + + if (fsm_settings__get_allow_remote(the_repository) < 1) + return fsmonitor_ipc__get_default_path(); + + git_dir = get_git_dir(); + sock_dir = fsm_settings__get_socket_dir(the_repository); + + SHA1_Init(&sha1ctx); + SHA1_Update(&sha1ctx, git_dir, strlen(git_dir)); + SHA1_Final(hash, &sha1ctx); + + if (sock_dir && *sock_dir) + strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s", + sock_dir, hash_to_hex(hash)); + else + strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash)); + retval = interpolate_path(ipc_file.buf, 1); + if (!retval) + die(_("Invalid path: %s"), ipc_file.buf); + strbuf_release(&ipc_file); + return retval; +#endif +} enum ipc_active_state fsmonitor_ipc__get_state(void) { diff --git a/fsmonitor-ipc.h b/fsmonitor-ipc.h index b6a7067c3af..4d27223c2a6 100644 --- a/fsmonitor-ipc.h +++ b/fsmonitor-ipc.h @@ -18,6 +18,12 @@ int fsmonitor_ipc__is_supported(void); */ const char *fsmonitor_ipc__get_path(void); +/* + * Returns the pathname to the default IPC named pipe or Unix domain + * socket. + */ +const char *fsmonitor_ipc__get_default_path(void); + /* * Try to determine whether there is a `git-fsmonitor--daemon` process * listening on the IPC pipe/socket. diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c index 464424a1e92..a15eeecebf4 100644 --- a/fsmonitor-settings.c +++ b/fsmonitor-settings.c @@ -10,7 +10,9 @@ struct fsmonitor_settings { enum fsmonitor_mode mode; enum fsmonitor_reason reason; + int allow_remote; char *hook_path; + char *sock_dir; }; static enum fsmonitor_reason check_for_incompatible(struct repository *r) @@ -43,6 +45,7 @@ static struct fsmonitor_settings *alloc_settings(void) CALLOC_ARRAY(s, 1); s->mode = FSMONITOR_MODE_DISABLED; s->reason = FSMONITOR_REASON_UNTESTED; + s->allow_remote = -1; return s; } @@ -90,6 +93,26 @@ static void lookup_fsmonitor_settings(struct repository *r) fsm_settings__set_disabled(r); } +int fsm_settings__get_allow_remote(struct repository *r) +{ + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + lookup_fsmonitor_settings(r); + + return r->settings.fsmonitor->allow_remote; +} + +const char *fsm_settings__get_socket_dir(struct repository *r) +{ + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + lookup_fsmonitor_settings(r); + + return r->settings.fsmonitor->sock_dir; +} + enum fsmonitor_mode fsm_settings__get_mode(struct repository *r) { if (!r) @@ -100,6 +123,7 @@ enum fsmonitor_mode fsm_settings__get_mode(struct repository *r) return r->settings.fsmonitor->mode; } + const char *fsm_settings__get_hook_path(struct repository *r) { if (!r) @@ -110,9 +134,44 @@ const char *fsm_settings__get_hook_path(struct repository *r) return r->settings.fsmonitor->hook_path; } +void fsm_settings__set_allow_remote(struct repository *r) +{ + int allow; + + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + r->settings.fsmonitor = alloc_settings(); + if (!repo_config_get_bool(r, "fsmonitor.allowremote", &allow)) + r->settings.fsmonitor->allow_remote = allow; + + return; +} + +void fsm_settings__set_socket_dir(struct repository *r) +{ + const char *path; + + if (!r) + r = the_repository; + if (!r->settings.fsmonitor) + r->settings.fsmonitor = alloc_settings(); + + if (!repo_config_get_pathname(r, "fsmonitor.socketdir", &path)) { + FREE_AND_NULL(r->settings.fsmonitor->sock_dir); + r->settings.fsmonitor->sock_dir = strdup(path); + } + + return; +} + void fsm_settings__set_ipc(struct repository *r) { - enum fsmonitor_reason reason = check_for_incompatible(r); + enum fsmonitor_reason reason; + + fsm_settings__set_allow_remote(r); + fsm_settings__set_socket_dir(r); + reason = check_for_incompatible(r); if (reason != FSMONITOR_REASON_OK) { fsm_settings__set_incompatible(r, reason); @@ -135,7 +194,11 @@ void fsm_settings__set_ipc(struct repository *r) void fsm_settings__set_hook(struct repository *r, const char *path) { - enum fsmonitor_reason reason = check_for_incompatible(r); + enum fsmonitor_reason reason; + + fsm_settings__set_allow_remote(r); + fsm_settings__set_socket_dir(r); + reason = check_for_incompatible(r); if (reason != FSMONITOR_REASON_OK) { fsm_settings__set_incompatible(r, reason); diff --git a/fsmonitor-settings.h b/fsmonitor-settings.h index d9c2605197f..2de54c85e94 100644 --- a/fsmonitor-settings.h +++ b/fsmonitor-settings.h @@ -23,12 +23,16 @@ enum fsmonitor_reason { FSMONITOR_REASON_NOSOCKETS, /* NTFS,FAT32 do not support Unix sockets */ }; +void fsm_settings__set_allow_remote(struct repository *r); +void fsm_settings__set_socket_dir(struct repository *r); void fsm_settings__set_ipc(struct repository *r); void fsm_settings__set_hook(struct repository *r, const char *path); void fsm_settings__set_disabled(struct repository *r); void fsm_settings__set_incompatible(struct repository *r, enum fsmonitor_reason reason); +int fsm_settings__get_allow_remote(struct repository *r); +const char *fsm_settings__get_socket_dir(struct repository *r); enum fsmonitor_mode fsm_settings__get_mode(struct repository *r); const char *fsm_settings__get_hook_path(struct repository *r); From patchwork Tue Aug 23 13:03:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12952249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51D0EC32772 for ; Tue, 23 Aug 2022 16:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244821AbiHWQcW (ORCPT ); Tue, 23 Aug 2022 12:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242860AbiHWQcA (ORCPT ); Tue, 23 Aug 2022 12:32:00 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A36FEC6F for ; Tue, 23 Aug 2022 06:03:47 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id n23-20020a7bc5d7000000b003a62f19b453so6457474wmk.3 for ; Tue, 23 Aug 2022 06:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=1DXuvdwjfUb9+x0G0jwK0PdicjVVYpDtZrgZUeeuj2k=; b=XJgCgbW2p+rV5+sDDa7KI9o5Uh+pWO8cQ9bFSCX+Bn7fW/6RNtD6o1nyV60mhNIoEG 1W4txIx0roWLrM7KMYJp+aAXosiRvv4dlLC2YZwzGs3ln6BewBLCb9828ihUR297He7A PYJ5Ovdz5yyTRzvlDE+6sxuDHTU2KnSvLmZDat4lhsEn3DvW7gUQmnFyyqUjnztxQRnu 5Ljfs2V6EjjdUy/C0groPV7QtmXLjK0BGTd1srBz71NDsGLmN88Mloa5YO/OFVLImmKL vZTXC4IiY+ex7lpRlLz5vBL39gCVQb/6QSWu31T4MSoaZ+pZuD6jwVnp4mJgJjN3DX7C FLGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=1DXuvdwjfUb9+x0G0jwK0PdicjVVYpDtZrgZUeeuj2k=; b=eYgTbRdPFqW1EZBE+VGudyj5oM1EgH9K59xp+XAHsXtfp/zR/szFCRlBNu4ez6+xX8 hglrL3LJD5eenKllbp45ZQZYTVyOqHkKy+Nh/v/VbCLLEjtLxO3zKcArjwVIZD7B3Ift 4/SBlCho81QeYsNqZlF6iAqBm4Dk50rGjQvXK81xT1u6lcW4GBF8bRFfbMBvA2gVPmOK K+27Ob/NLM4LgcF/vk2RY48JVMi6mCszaJfMPELwVZc1JYgc8oslLURS5Ch2WEOWjbxD 7+hcRnlUFac/M/VIUtxqCMKMuFCcUMYRBJgiCppIrY63pEIFhztUkBjnZuRb706PEMQp iVwA== X-Gm-Message-State: ACgBeo2M72ePTZSChGX6X4yCibcs3GdqjBN2wadwGw3IWjbz3D4qP4h8 LzztUWnCSdONJZaO5jAqUyPLkkKO3bs= X-Google-Smtp-Source: AA6agR7uoWkiSewKNqd6QOlW2KXUJ5cR+bjcwveaMaKnuwP8os4ggFLd2DgrwQHIsv7II6riLhlSlg== X-Received: by 2002:a05:600c:1f0c:b0:3a5:d744:f837 with SMTP id bd12-20020a05600c1f0c00b003a5d744f837mr2237822wmb.40.1661259825968; Tue, 23 Aug 2022 06:03:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x4-20020a5d6b44000000b002252d897876sm10525668wrw.32.2022.08.23.06.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 06:03:45 -0700 (PDT) Message-Id: <9b128a981494f5aa7f60062caecc24ee6ea802ec.1661259820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 23 Aug 2022 13:03:39 +0000 Subject: [PATCH v2 3/4] Check working directory and Unix domain socket file for compatability Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , edecosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: edecosta From: edecosta Perform separate checks for the working directory and Unix domain socket (UDS) file location. The working directory may be located on a network-mounted file system if 'fsmonitor.allowRemote' is true. The UDS file may never be located on a network-mounted file system; additionally it may not be located on FAT32 or NTFS file systems. Signed-off-by: edecosta --- compat/fsmonitor/fsm-settings-darwin.c | 72 +++++++++++++++++++------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c index efc732c0f31..dc79538607f 100644 --- a/compat/fsmonitor/fsm-settings-darwin.c +++ b/compat/fsmonitor/fsm-settings-darwin.c @@ -3,11 +3,12 @@ #include "repository.h" #include "fsmonitor-settings.h" #include "fsmonitor.h" +#include "fsmonitor-ipc.h" #include #include /* - * [1] Remote working directories are problematic for FSMonitor. + * Remote working directories are problematic for FSMonitor. * * The underlying file system on the server machine and/or the remote * mount type (NFS, SAMBA, etc.) dictates whether notification events @@ -27,26 +28,8 @@ * In theory, the above issues need to be addressed whether we are * using the Hook or IPC API. * - * For the builtin FSMonitor, we create the Unix domain socket for the - * IPC in the .git directory. If the working directory is remote, - * then the socket will be created on the remote file system. This - * can fail if the remote file system does not support UDS file types - * (e.g. smbfs to a Windows server) or if the remote kernel does not - * allow a non-local process to bind() the socket. (These problems - * could be fixed by moving the UDS out of the .git directory and to a - * well-known local directory on the client machine, but care should - * be taken to ensure that $HOME is actually local and not a managed - * file share.) - * * So (for now at least), mark remote working directories as - * incompatible. - * - * - * [2] FAT32 and NTFS working directories are problematic too. - * - * The builtin FSMonitor uses a Unix domain socket in the .git - * directory for IPC. These Windows drive formats do not support - * Unix domain sockets, so mark them as incompatible for the daemon. + * incompatible unless fsmonitor.allowRemote is true. * */ static enum fsmonitor_reason check_volume(struct repository *r) @@ -65,6 +48,51 @@ static enum fsmonitor_reason check_volume(struct repository *r) "statfs('%s') [type 0x%08x][flags 0x%08x] '%s'", r->worktree, fs.f_type, fs.f_flags, fs.f_fstypename); + if (!(fs.f_flags & MNT_LOCAL) + && (fsm_settings__get_allow_remote(r) < 1)) + return FSMONITOR_REASON_REMOTE; + + return FSMONITOR_REASON_OK; +} + +/* + * For the builtin FSMonitor, we create the Unix domain socket (UDS) + * for the IPC in the .git directory by default or $HOME if + * fsmonitor.allowRemote is true. If the directory is remote, + * then the socket will be created on the remote file system. This + * can fail if the remote file system does not support UDS file types + * (e.g. smbfs to a Windows server) or if the remote kernel does not + * allow a non-local process to bind() the socket. + * + * Therefore remote UDS locations are marked as incompatible. + * + * FAT32 and NTFS working directories are problematic too. + * + * These Windows drive formats do not support Unix domain sockets, so + * mark them as incompatible for the location of the UDS file. + * + */ +static enum fsmonitor_reason check_uds_volume(void) +{ + struct statfs fs; + struct strbuf path = STRBUF_INIT; + const char *ipc_path = fsmonitor_ipc__get_path(); + strbuf_add(&path, ipc_path, strlen(ipc_path)); + + if (statfs(dirname(path.buf), &fs) == -1) { + int saved_errno = errno; + trace_printf_key(&trace_fsmonitor, "statfs('%s') failed: %s", + path.buf, strerror(saved_errno)); + errno = saved_errno; + strbuf_release(&path); + return FSMONITOR_REASON_ERROR; + } + + trace_printf_key(&trace_fsmonitor, + "statfs('%s') [type 0x%08x][flags 0x%08x] '%s'", + path.buf, fs.f_type, fs.f_flags, fs.f_fstypename); + strbuf_release(&path); + if (!(fs.f_flags & MNT_LOCAL)) return FSMONITOR_REASON_REMOTE; @@ -85,5 +113,9 @@ enum fsmonitor_reason fsm_os__incompatible(struct repository *r) if (reason != FSMONITOR_REASON_OK) return reason; + reason = check_uds_volume(); + if (reason != FSMONITOR_REASON_OK) + return reason; + return FSMONITOR_REASON_OK; } From patchwork Tue Aug 23 13:03:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeCosta X-Patchwork-Id: 12952250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86EFEC32772 for ; Tue, 23 Aug 2022 16:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244839AbiHWQce (ORCPT ); Tue, 23 Aug 2022 12:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244765AbiHWQcB (ORCPT ); Tue, 23 Aug 2022 12:32:01 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45833103C5F for ; Tue, 23 Aug 2022 06:03:49 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id h5so16121997wru.7 for ; Tue, 23 Aug 2022 06:03:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=BnY0GYMcF2398tLi6yUu5KZFqOOfqDd/0vxGpV5R1BI=; b=hgVpZbNeqLKPVRxjQ0XOUiT0lZI+jNdPsQTQTk0vgHvCti5cUDGFv3Fo+394lL5tRw 8DkSuLiaB2E9quvpDLUhET6Gx/EeDv2UHKTkVB1CpJiTRcHoZIvIXtanErqXXtNMOR// iMqqIJysp04jOq5dChcpa7P7IZMZG3DzgoJa+jsRvAz63bH3npHlgUK7y+90UaFbY5uL qdxKA0LKWr8h8A9FFChFBRwpYtkYbb/CGO8DA5jTqC1IH+NAVs1g5EXHQw6l6lWZxIq7 cdzDC1BPqn+hwTNYs3Y36qNl1jCJqqOPw9gQCpnyHfP+9skN3McLcuNcjZZXfmzIKhLL 8ObQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=BnY0GYMcF2398tLi6yUu5KZFqOOfqDd/0vxGpV5R1BI=; b=VANL1ubnsychk7vDx6ZuwFGVmOZ2o0frckkFs9mUXw16F+tAfx1i6/v2qxe8KY8zVT yL+EQgX2aIUPWCYtH8JpuJYz9BRmSOMB5QoSB2l7Mjj2BukQgUHb3X2z09xUr5nZs/gR 0N+tQ8Syg+t5MbMddG3oNPjP8Tt8vKtR3AD1EGQx8fSGATaLbto7rIvJ4XkSxD/ap8on 7D6Rs7FDwiVPUDUE8SeHjlxzPoG42bnhord5s7wg46ZyrqazTPwuYIPab+hqMa7V+GTW RVdegrDh5N6Cnql1ZLq1Cqlrc/C5VIpy48zf+7wtvAJCqKblLzkkkwIrnn4rYfEtTIr9 U6DA== X-Gm-Message-State: ACgBeo2ZlMf8890o10E3OEPUTrtegTyJUFghQ/4v5Jz7RMgTS3wLrS3B kT27qKT3XtU/jzPdJV102scYILmhNAc= X-Google-Smtp-Source: AA6agR6mkTxYSokLrgmDMofVPew/tDbUrLAfvoQPjJuF31o9RvmAaDtFvgX+h+n4SqvG1j1EP5MNHg== X-Received: by 2002:adf:fc8b:0:b0:225:5a71:be1a with SMTP id g11-20020adffc8b000000b002255a71be1amr5073678wrr.651.1661259827169; Tue, 23 Aug 2022 06:03:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a54d610e5fsm16316305wmq.26.2022.08.23.06.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 06:03:46 -0700 (PDT) Message-Id: <15c965801f81d8b5c42223aa422b23302cb9210b.1661259820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 23 Aug 2022 13:03:40 +0000 Subject: [PATCH v2 4/4] Minor refactoring and simplification of Windows settings checks Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Eric DeCosta , edecosta Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: edecosta From: edecosta Read the value of 'fsmonitor.allowRemote' from fsmonitor_settings via fsm_settings__get_allow_remote getter. Remove check_config_allowremote. Replace switch statement with a simpler if statement. Move the check for 'fsmonitor.allowRemote' above the remote protocol check. Signed-off-by: edecosta --- compat/fsmonitor/fsm-settings-win32.c | 31 ++++----------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c index e5ec5b0a9f7..34635e6c849 100644 --- a/compat/fsmonitor/fsm-settings-win32.c +++ b/compat/fsmonitor/fsm-settings-win32.c @@ -24,23 +24,6 @@ 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 - * disabled. 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)) - return allow; - - return -1; /* fsmonitor.allowremote not set */ -} - /* * Check remote working directory protocol. * @@ -170,20 +153,14 @@ static enum fsmonitor_reason check_remote(struct repository *r) "check_remote('%s') true", r->worktree); + if (fsm_settings__get_allow_remote(r) < 1) + return FSMONITOR_REASON_REMOTE; + ret = check_remote_protocol(wfullpath); if (ret < 0) return FSMONITOR_REASON_ERROR; - 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; } return FSMONITOR_REASON_OK;