Skip to content

reversesshfs: add ExpectRemove - #119

Draft
sylvinus wants to merge 2 commits into
lima-vm:masterfrom
sylvinus:expect-remove
Draft

sylvinus wants to merge 2 commits into
lima-vm:masterfrom
sylvinus:expect-remove

Conversation

@sylvinus

Copy link
Copy Markdown

Depends on #118 (this branch includes its commit; only the last commit is new).

Needed for lima-vm/lima#5530

ExpectRemove(hostPath) makes the next Remove/Rmdir of that path from the guest, within 5 seconds, succeed without touching the host. Lima uses it to relay host deletions to the guest: the guest removes the path so that it emits IN_DELETE, and the host keeps the file if it was created again meanwhile.

Returns false when unsupported (not the rooted builtin server).

Tested with unit tests and the sshfs e2e test (deletion cases, including a file recreated before the guest's removal arrives).

Assisted-by: Claude Opus 5.5 (1M context)

The builtin driver used sftp.NewServer, which serves the whole host file
system to the guest. On Linux and macOS hosts, it now uses
sftp.NewRequestServer with handlers rooted at LocalPath: reads go
through os.Root, and writes open each parent directory with O_NOFOLLOW,
so they never follow a symlink. A path outside the root gets EACCES.
Windows keeps sftp.NewServer.

Setting the mode fails on a symlink, on macOS as on Linux. On Linux
kernels without fchmodat2 (< 6.6), it goes through /proc/self/fd of an
O_PATH fd, as glibc does, so it needs no read permission.

ReadonlyNames makes a path read-only when any of its components matches
one of these names, compared case-insensitively and ignoring the code
points that HFS+ ignores, as git does. For example, [".git"] keeps the
working tree writable while hooks and config stay read-only. Setting
ReadonlyNames selects the builtin driver in auto mode, and fails with
the OpenSSH driver or on Windows.

Setting the times of a read-only name to its current mtime is a no-op
that succeeds, because this is how the Lima guest agent triggers
IN_ATTRIB for host changes (mountInotify).

Addresses lima-vm#6 for Linux and macOS hosts.

Assisted-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Sylvain Zimmer <sylvain@sylvainzimmer.com>
ExpectRemove(hostPath) makes the next Remove or Rmdir of hostPath from
the guest succeed without touching the host, if it arrives within 5
seconds. It lets the caller relay a deletion done on the host: the guest
removes the path in the mount, so the guest kernel emits IN_DELETE,
while the host keeps the path if it was created again in the meantime.

It returns false when unsupported, i.e. without the rooted builtin
server of Linux and macOS hosts.

Assisted-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Sylvain Zimmer <sylvain@sylvainzimmer.com>
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.

1 participant