From: Patrick Steinhardt <ps@pks.im>
To: Paul Tarjan via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Paul Tarjan <github@paulisageek.com>
Subject: Re: [PATCH v7 07/10] fsmonitor: implement filesystem change listener for Linux
Date: Wed, 4 Mar 2026 08:43:07 +0100 [thread overview]
Message-ID: <aafii97SoHS96rkA@pks.im> (raw)
In-Reply-To: <adac7964cce28d237ef09574858be240fe3269fc.1772065643.git.gitgitgadget@gmail.com>
On Thu, Feb 26, 2026 at 12:27:20AM +0000, Paul Tarjan via GitGitGadget wrote:
> From: Paul Tarjan <github@paulisageek.com>
>
> Implement the built-in fsmonitor daemon for Linux using the inotify
> API, bringing it to feature parity with the existing Windows and macOS
> implementations.
>
> The implementation uses inotify rather than fanotify because fanotify
> requires either CAP_SYS_ADMIN or CAP_PERFMON capabilities, making it
> unsuitable for an unprivileged user-space daemon. While inotify has
> the limitation of requiring a separate watch on every directory (unlike
> macOS's FSEvents, which can monitor an entire directory tree with a
> single watch), it operates without elevated privileges and provides
> the per-file event granularity needed for fsmonitor.
Thanks for adding this explanation, makes sense.
> diff --git a/compat/fsmonitor/fsm-path-utils-linux.c b/compat/fsmonitor/fsm-path-utils-linux.c
> new file mode 100644
> index 0000000000..b4c19e0655
> --- /dev/null
> +++ b/compat/fsmonitor/fsm-path-utils-linux.c
> @@ -0,0 +1,220 @@
> +#include "git-compat-util.h"
> +#include "fsmonitor-ll.h"
> +#include "fsmonitor-path-utils.h"
> +#include "gettext.h"
> +#include "trace.h"
> +
> +#include <sys/statfs.h>
> +
> +#ifdef HAVE_LINUX_MAGIC_H
I saw that this define is only wired up for CMake. I guess we should
also add it to our Makefile (probably via config.mak.uname) and Meson
(probably via compiler.has_header()).
[snip]
> +/*
> + * Get the filesystem type name for logging purposes.
> + */
> +static const char *get_fs_typename(unsigned long f_type)
> +{
> + switch (f_type) {
> + case CIFS_SUPER_MAGIC:
> + return "cifs";
> + case SMB_SUPER_MAGIC:
> + return "smb";
> + case SMB2_SUPER_MAGIC:
> + return "smb2";
> + case NFS_SUPER_MAGIC:
> + return "nfs";
> + case AFS_SUPER_MAGIC:
> + return "afs";
> + case CODA_SUPER_MAGIC:
> + return "coda";
> + case V9FS_MAGIC:
> + return "9p";
> + case FUSE_SUPER_MAGIC:
> + return "fuse";
> + default:
> + return "unknown";
> + }
> +}
This selection looks rather interesting to me. Why wouldn't we include
common filesystems like ext4 and the like? Certainly hints that the
function needs better documentation, and potentially a better name.
> +/*
> + * Find the mount point for a given path by reading /proc/mounts.
> + * Returns the filesystem type for the longest matching mount point.
> + */
> +static char *find_mount(const char *path, struct statfs *fs)
> +{
> + FILE *fp;
> + struct strbuf line = STRBUF_INIT;
> + struct strbuf match = STRBUF_INIT;
> + struct strbuf fstype = STRBUF_INIT;
> + char *result = NULL;
> + struct statfs path_fs;
> +
> + if (statfs(path, &path_fs) < 0)
> + return NULL;
> +
> + fp = fopen("/proc/mounts", "r");
> + if (!fp)
> + return NULL;
> +
> + while (strbuf_getline(&line, fp) != EOF) {
> + char *fields[6];
> + char *p = line.buf;
> + int i;
> +
> + /* Parse mount entry: device mountpoint fstype options dump pass */
> + for (i = 0; i < 6 && p; i++) {
> + fields[i] = p;
> + p = strchr(p, ' ');
> + if (p)
> + *p++ = '\0';
> + }
> +
> + if (i >= 3) {
> + const char *mountpoint = fields[1];
> + const char *type = fields[2];
> + struct statfs mount_fs;
> +
> + /* Check if this mount point is a prefix of our path */
> + if (starts_with(path, mountpoint) &&
> + (path[strlen(mountpoint)] == '/' ||
> + path[strlen(mountpoint)] == '\0')) {
> + /* Check if filesystem ID matches */
> + if (statfs(mountpoint, &mount_fs) == 0 &&
> + !memcmp(&mount_fs.f_fsid, &path_fs.f_fsid,
> + sizeof(mount_fs.f_fsid))) {
> + /* Keep the longest matching mount point */
> + if (strlen(mountpoint) > match.len) {
> + strbuf_reset(&match);
> + strbuf_addstr(&match, mountpoint);
> + strbuf_reset(&fstype);
> + strbuf_addstr(&fstype, type);
> + *fs = mount_fs;
> + }
> + }
> + }
> + }
> + }
> +
> + fclose(fp);
> + strbuf_release(&line);
> + strbuf_release(&match);
> +
> + if (fstype.len)
> + result = strbuf_detach(&fstype, NULL);
> + else
> + strbuf_release(&fstype);
> +
> + return result;
> +}
Sorry, but I still don't quite understand what we're doing here. Isn't
the longest matching mount point always the one that statfs(3p) gave us?
Why do we have to scan "/proc/mounts"?
Patrick
next prev parent reply other threads:[~2026-03-04 7:43 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 8:14 [PATCH] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2025-12-30 11:38 ` Junio C Hamano
2025-12-30 12:08 ` [PATCH v2] " Paul Tarjan via GitGitGadget
2025-12-30 12:55 ` [PATCH v3] " Paul Tarjan via GitGitGadget
2025-12-31 17:41 ` [PATCH v4] " Paul Tarjan via GitGitGadget
2026-01-05 12:07 ` Patrick Steinhardt
2026-02-20 22:18 ` Junio C Hamano
2026-02-21 16:15 ` Paul Tarjan
2026-02-21 17:07 ` Junio C Hamano
2026-02-23 6:34 ` Patrick Steinhardt
2026-02-23 15:42 ` Junio C Hamano
2026-02-23 15:46 ` Patrick Steinhardt
2026-02-24 1:34 ` Paul Tarjan
2026-02-24 8:03 ` Patrick Steinhardt
2026-02-24 1:31 ` [PATCH v5] " Paul Tarjan via GitGitGadget
2026-02-24 8:03 ` Patrick Steinhardt
2026-02-25 20:17 ` [PATCH v6 00/10] " Paul Tarjan via GitGitGadget
2026-02-25 20:17 ` [PATCH v6 01/10] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-02-25 21:01 ` Junio C Hamano
2026-02-25 20:17 ` [PATCH v6 02/10] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-02-25 20:17 ` [PATCH v6 03/10] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-02-25 20:17 ` [PATCH v6 04/10] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-02-25 21:13 ` Junio C Hamano
2026-02-27 6:31 ` Paul Tarjan
2026-02-27 16:44 ` Junio C Hamano
2026-02-28 0:28 ` Paul Tarjan
2026-02-25 21:17 ` Junio C Hamano
2026-02-27 6:31 ` Paul Tarjan
2026-02-25 20:17 ` [PATCH v6 05/10] fsmonitor: deduplicate IPC path logic for Unix platforms Paul Tarjan via GitGitGadget
2026-02-25 21:30 ` Junio C Hamano
2026-02-27 6:31 ` Paul Tarjan
2026-02-25 20:17 ` [PATCH v6 06/10] fsmonitor: deduplicate settings " Paul Tarjan via GitGitGadget
2026-02-25 21:31 ` Junio C Hamano
2026-02-27 6:31 ` Paul Tarjan
2026-02-25 20:17 ` [PATCH v6 07/10] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-02-25 20:17 ` [PATCH v6 08/10] fsmonitor: add tests " Paul Tarjan via GitGitGadget
2026-02-25 20:17 ` [PATCH v6 09/10] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-02-25 21:41 ` Junio C Hamano
2026-02-25 20:17 ` [PATCH v6 10/10] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-02-26 0:27 ` [PATCH v7 00/10] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-02-26 0:27 ` [PATCH v7 01/10] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-04 7:42 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 02/10] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-04 7:42 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 03/10] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-04 7:42 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 04/10] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-04 7:42 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 05/10] fsmonitor: deduplicate IPC path logic for Unix platforms Paul Tarjan via GitGitGadget
2026-03-04 7:42 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 06/10] fsmonitor: deduplicate settings " Paul Tarjan via GitGitGadget
2026-03-04 7:43 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 07/10] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-04 7:43 ` Patrick Steinhardt [this message]
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 08/10] fsmonitor: add tests " Paul Tarjan via GitGitGadget
2026-03-04 7:43 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 0:27 ` [PATCH v7 09/10] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-02-26 0:27 ` [PATCH v7 10/10] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-04 7:43 ` Patrick Steinhardt
2026-03-04 18:17 ` Paul Tarjan
2026-02-26 15:34 ` [PATCH v7 00/10] fsmonitor: implement filesystem change listener for Linux Junio C Hamano
2026-03-04 18:15 ` [PATCH v8 00/12] " Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 08/12] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-03-04 20:51 ` Junio C Hamano
2026-03-05 0:49 ` [PATCH v8 09/12] " Paul Tarjan
2026-03-05 4:13 ` Junio C Hamano
2026-03-05 6:38 ` [PATCH v9 09/12] run-command: add pre-exec callback for child processes Paul Tarjan
2026-03-04 18:15 ` [PATCH v8 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-04 18:15 ` [PATCH v8 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 00/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 08/12] run-command: add pre-exec callback for child processes Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-05 0:51 ` [PATCH v9 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-05 0:52 ` [PATCH v9 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 00/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 08/12] run-command: add pre-exec callback for child processes Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-05 1:16 ` [PATCH v10 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 00/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 08/12] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-05 6:55 ` [PATCH v11 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05 7:37 ` [PATCH v11 00/12] fsmonitor: implement filesystem change listener for Linux Patrick Steinhardt
2026-03-05 14:15 ` Paul Tarjan
2026-03-25 20:00 ` Junio C Hamano
2025-12-30 15:37 ` [PATCH v2] " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aafii97SoHS96rkA@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=github@paulisageek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox