schfs: several snapshots at once, and unmount gives the slot back

Two loose ends from the mount-by-name commit, both closed.

A slot is a device number, so supporting more than one snapshot is a
small array rather than a redesign: SCHFS_SNAP_DEV through
SCHFS_SNAP_DEV + SCHFS_SNAP_SLOTS - 1, each with its own volume and its
own scratch pages, allocated on first use. Four of them -- "one at a
time" is an odd thing to have to explain, and the cost is two pages per
slot. Not many, because each one is a device number and those are a
small fixed space.

The leak mattered more. umount removed the mount table entry and left the
slot marked in use, so a snapshot could be unmounted and then never
mounted again until reboot. sys_umount2 releases it now, keyed off the
device it already has in hand.

Verified in the running system: two snapshots mounted at once, both
readable, both unmounted, and a third mount afterwards succeeds and reads
correctly -- which is the case that failed before.

schfs-check passes; bootcheck 108 [ok].

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Nexoniarz 2026-08-10 21:30:28 +02:00
commit b34779111a
6 changed files with 75 additions and 47 deletions

View file

@ -284,7 +284,7 @@ extern const struct fs_ops procfs_ops;
int
fs_readonly(uint dev)
{
return dev == SCHFS_SNAP_DEV;
return SCHFS_IS_SNAP_DEV(dev);
}
static const struct fs_ops *
@ -293,7 +293,7 @@ ops_for(uint dev)
if (dev == SCHFS_DEV) return &schfs_ops;
// A mounted snapshot is the same filesystem seen through an older root, so it
// is the same operations; they dispatch on the device themselves.
if (dev == SCHFS_SNAP_DEV) return &schfs_ops;
if (SCHFS_IS_SNAP_DEV(dev)) return &schfs_ops;
if (dev == PROCFS_DEV) return &procfs_ops;
return &v1_ops;
}