Skip to content

feat(mount): an /etc/fstab mount helper for -t objectfs (#136) - #530

Merged
scttfrdmn merged 9 commits into
mainfrom
fix/136-fstab-mount-helper
Sep 18, 2026
Merged

scttfrdmn merged 9 commits into
mainfrom
fix/136-fstab-mount-helper

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

Closes #136.

mount -t objectfs s3://bucket /mnt/objectfs -o _netdev,config=… and the equivalent /etc/fstab
line both work now. Before this, an fstab entry failed with unknown filesystem type 'objectfs' and
no other information.

How it is registered

mount(8) resolves a type it does not know by exec'ing /sbin/mount.TYPE. That path is compiled
into util-linux — not searched on PATH, no configuration for it — so the filename is the
registration
. The binary is packaged to /usr/bin/mount.objectfs, because nfpm has one bindir
per package and /usr/bin is where objectfs must be; scripts/postinstall.sh creates the
/sbin symlink and scripts/preremove.sh removes it. A packaged file under /sbin would be
dpkg's aliased-directory problem on a usrmerged system, and creating the link at /sbin covers
both layouts with one command, since the kernel resolves /sbin to /usr/sbin where they are
merged.

The scriptlets are conservative in both directions: postinstall leaves a symlink pointing somewhere
else or a real file alone (with a warning naming the ln -s an operator can run), never creates a
dangling link, and is idempotent; preremove only unlinks a symlink whose target is
/usr/bin/mount.objectfs, and does nothing at all on an upgrade.

Why it daemonizes instead of exec'ing

#136 specifies exec objectfs mount … --foreground. That would hang mount -a forever, at boot,
before anything else in fstab was mounted — objectfs mount blocks for the lifetime of the mount
and its --foreground flag is accepted and ignored. Re-verified against the current tree rather
than assumed.

So the helper starts the mount in a session of its own (setsid, so a Ctrl-C or SIGHUP to whatever
ran mount does not take the filesystem down with it), polls /proc/self/mountinfo until a new
entry names the mount point, and exits 0. Entries are counted rather than tested for zero,
because mounts stack: "something is mounted here" would report a mount the helper never made. Where
there is no /proc, the fallback is the mount point's st_dev changing — weaker, since it cannot
say what was mounted, but it cannot report a mount that did not happen.

The child's output goes to /var/log/objectfs/mount-<mountpoint>.log and the tail of this
attempt's output is relayed on failure, so a broken fstab entry says what objectfs mount said
instead of mount: exit status 32. A mount that has not appeared within -o mount-timeout=
(default 60s) is terminated — SIGTERM to the process group, then SIGKILL — because reporting failure
while the mount quietly came up a moment later would leave mount -a believing the filesystem is
absent and the kernel believing it is present, and the next mount -a would stack a second one.

mount -f is under the same deadline, and enforcing it took three lines rather than one. A test,
not a reading of the docs, found that a 300ms deadline took the full 30 seconds: CommandContext's
cancel signals only the direct child, so a grandchild survived, and because stdout is an io.Writer
rather than an *os.File, exec copies through a pipe and Wait blocks until every holder of the
write end closes it. The kill now goes to the process group and WaitDelay bounds the pipe wait;
both are asserted, the second by a subtest whose descendant calls setsid and so is in no group the
helper can signal.

Options: a table, and four refusals

Anything not in the table is refused, not passed through and not dropped. config=,
cache-size=, log-level=, max-concurrency=, debug translate to flags; _netdev, auto,
noauto, nofail, defaults, rw, user/users/nouser, owner, group, comment= and any
x-/X- option are accepted and ignored because mount(8) or systemd handles them. -s softens
an unrecognised option to a warning, which is what sloppy means — but deliberately does not soften
these four, which are refused for a reason rather than for being unknown:

  • ro — there is no read-only mount in ObjectFS today. Accepting it would hand an operator a
    filesystem that is writable when their fstab says it is not. (Worth its own issue.)
  • uid= / gid= — ownership is not remapped; DefaultUID/DefaultGID exist on the FUSE config
    struct but nothing reaches them from configuration, so honouring these would be a silent no-op on
    the option most likely to be added for a shared mount.
  • bind — mount(8) handles a bind mount itself and never reaches a helper.

Each refusal names the remedy. This is the second departure from #136's spec: its ro, uid= and
gid= translations have no flags to translate into.

Testing

cmd/mount.objectfs is at ~93% locally with a floor of 85 in .coverage-floors (deliberately not
ratcheted to the measurement, per #438's reasoning). Both new areas were verified by mutation — 16
effective mutations across the scriptlets, .goreleaser.yml and main.go, each caught by the
assertion intended to catch it, with clean controls between runs.

The packaging tests are behavioural: they run the shipped scripts/postinstall.sh and
scripts/preremove.sh against a staged root through OBJECTFS_ROOT, rather than asserting on their
text. TestThePackagesShipTheMountHelper closes a gap the previous assertions left wide open —
dropping mount-helper from nfpms.ids and deleting its build together satisfied every one of
them, since what remained was one id resolving to a build supplying objectfs.

Not in this PR, and each now filed: #532 for a real --read-only mount option, which is what removes
the ro refusal, and #533 for the release tarball and scripts/install.sh, which have the same gap
the packages no longer do.

mount(8) resolves an unknown filesystem type to /sbin/mount.TYPE and hands it the
whole invocation. This is that program: it translates mount(8)'s calling convention
into an `objectfs mount` command line and does nothing else.

    s3://my-bucket  /mnt/data  objectfs  _netdev,config=/etc/objectfs/data.yaml  0  0

Two places where #136's specification could not be implemented as written, both
verified against the code rather than assumed:

It specified `exec objectfs mount ... --foreground`. `objectfs mount` blocks for the
lifetime of the mount — --foreground is accepted and ignored because foreground is
the only mode there is, and `grep f.foreground` finds exactly one line, its own
definition. So an exec'd helper never returns and `mount -a` hangs at boot forever.
The mount is started detached with Setsid instead, and the helper waits for the mount
point to appear in /proc/self/mountinfo before reporting success. Polling the kernel
rather than the child is the contract: a child that is alive is not yet a mount, and
exiting 0 at fork would make every failure look like a success that broke a moment
later. Entries are counted, not tested for zero, because mounts stack — "something is
mounted here" would report a mount this program never made.

It also specified translations for ro, uid= and gid=. None has anywhere to go:
newMountFlagSet defines config, foreground, mount-point, log-level, cache-size,
max-concurrency, dry-run and debug, with no --read-only among them, and ownership is
not remappable — internal/fuse reports the uid of the process that made the request,
falling back to the one that ran the mount, with DefaultUID/DefaultGID unreachable
from the YAML config. So all three are refused with a reason naming the remedy. An
operator who writes `ro` and gets a read-write mount has been told something untrue
about the filesystem's most consequential property; a mount that does not come up is
a problem they can see, and one that came up meaning something else is not.

Anything absent from optionTable is refused too, by the same argument generalized.
-s downgrades *that* to a warning, which is what -s is for, and deliberately does not
reach the three above: "ignore options you do not recognize" is not "ignore options
you recognize and cannot honor".

The rest follows mount(8): exit 1 for a bad invocation and 32 for a failed mount, -f
as --dry-run run in the foreground, -n and -t accepted and ignored, the positionals
first and the short flags combined (-sfnv), and the options mount(8), `mount -a` and
systemd read for themselves dropped rather than passed on. Startup output goes to a
named, appended /var/log/objectfs/mount-<point>.log and its tail is relayed on
failure from this attempt's offset — without it a failed fstab mount reports an exit
status and nothing about why, which sends an operator to check the network.

No build tags, so the translation logic and its tests compile on darwin too; the
mount-table reader is a pure function over an io.Reader with a fixture, and st_dev is
the fallback where there is no /proc.
The binary goes to /usr/bin/mount.objectfs — nfpm has one bindir per package and /usr/bin is
where `objectfs` must be — and scripts/postinstall.sh links /sbin/mount.objectfs to it, which is
the path mount(8) execs for an unknown `-t objectfs`. A scriptlet symlink rather than a packaged
file under /sbin: on a usrmerged system that is dpkg's aliased-directory problem, and creating the
link *at* /sbin covers both layouts with one command since the kernel resolves /sbin to /usr/sbin
where they are merged.

scripts/preremove.sh removes it, because the package manager cannot: the link is not in dpkg's or
rpm's file list. Only on a real removal, and only if it is a symlink pointing where postinstall.sh
would have pointed it. Left behind after the binary it names is deleted, it is a dangling
/sbin/mount.objectfs, and an fstab entry that worked before the removal then fails with mount(8)'s
own "no such file or directory" against a helper path.

.goreleaser.yml gets a third build rather than a second `main:` on the packages build, since
goreleaser builds one binary per entry. Deliberately not in `archives:`: a tarball install goes
through scripts/install.sh, which knows one binary and renames it, and adding a second would need
install.sh to learn about /sbin — a root-only operation it does not otherwise require.

internal/config/packaging_test.go runs both scriptlets against a scratch root for all of it: the
link is created pointing at the *unprefixed* target (a scriptlet interpolating its ROOT would
install a link into nowhere), a second run is silent as well as harmless, a foreign symlink and a
real file are both reported and left on the way in and on the way out, a missing helper binary
warns and creates no dangling link, and the removal happens on `remove`/`purge`/`0` and not on
`upgrade`/`1`.

TestThePackagedBinaryIsOnThePathAsObjectfs no longer counts nfpms.ids. The count was a proxy that
went stale the moment a legitimate second build was added; it now asserts the property instead —
every id resolves to a build, no packaged binary name is a platform template, and exactly one
build produces `objectfs`.
…136)

TestThePackagedBinaryIsOnThePathAsObjectfs asserts properties of whatever `nfpms.ids` names, so
dropping `mount-helper` from `ids:` and deleting its build together leaves it satisfied: one id,
resolving to a build, supplying `objectfs`. What would be gone is fstab support, in a package that
installs and exits 0.

Asserts the main, the exact binary name (with the dot — mount(8) exec's /sbin/mount.$TYPE, so the
filename is the whole registration), linux-only goos, that nfpms names the id, and that bindir is
the /usr/bin scripts/postinstall.sh links to by literal path.
`mount -f` ran `objectfs mount --dry-run` with no deadline at all, and a dry
run resolves the bucket — DNS and credentials — so it can hang for the same
reasons a real mount can. A `mount -a -f` that hangs at boot is the failure
this program is shaped to avoid, fake mount or not.

A test found that the deadline is not self-enforcing, and that two separate
mechanisms were missing rather than one: `exec.CommandContext`'s default cancel
signals only the direct child, so a grandchild survived; and because stdout
here is an `io.Writer` rather than an `*os.File`, exec copies through a pipe
and `Wait` blocks until every holder of the write end closes it, which the
survivor did not. Measured against a dry run that slept 30 seconds with a
300ms timeout: 30.05s with all three lines absent, 5.3s with only `WaitDelay`.

So the kill goes to the process group and `WaitDelay` bounds the wait for the
pipe instead of trusting it to close. Both lines are load-bearing and both are
asserted: the second new subtest forks a `setsid` descendant, which is in no
group the helper can signal, so `WaitDelay` is the only bound left — removing
it took 30.15s.

A timed-out `-f` names the deadline and `-o mount-timeout=`, rather than the
`signal: killed` a canceled `CommandContext` reports, which says nothing about
who killed the child or why.

Also here: the linter findings in this package's new files, each with a reason
rather than a blanket suppression, and the CHANGELOG paragraph for the above.
@scttfrdmn scttfrdmn added type: enhancement New feature or improvement to existing functionality priority: high Important issue that should be addressed soon area: cli Command-line interface area: build Build system, compilation, packaging effort: medium Medium effort - 1-2 days labels Sep 18, 2026
`uint64(st.Dev)` cannot be written to satisfy both: st.Dev is uint64 on linux,
so the conversion is redundant and `unconvert` fires, and int32 on darwin, so it
is a signed widening and gosec's G115 fires. Which linter objects depends on the
GOOS the lint ran under, and CI lints linux — a local darwin run reporting 0
issues said nothing about the required check, which is how this reached a push.

Both suppressed, with the reason, rather than splitting one expression across two
platform files.
)

The floor opened at 85 because 93.2 was a local darwin number and a floor set
from a local run is the mistake .coverage-floors was rewritten to stop making
(#438). Two things could plausibly have differed on the linux runner — the
darwin and linux halves of the st_dev fallback, and the `os.Getuid() == 0`
skips in the log-directory tests. Neither did: the coverage job measured 93.4,
two tenths *above* the local figure.

So the eight points of reserve were being held against a difference that does
not exist. 92 keeps 1.4, which absorbs a swing the size of the 0.7 that made
internal/fuse flake.
…tall (#136)

The mount helper's tests run scripts/postinstall.sh against a staged root
through OBJECTFS_ROOT, which covers its branches but cannot see the two things
only a real install decides: whether nfpm put the binary where the scriptlet
looks for it, and whether dpkg runs the scriptlet at all. And nothing in this
repository can prove mount(8) finds the helper except mount(8) finding it —
/sbin/mount.TYPE is compiled into util-linux.

So the packaging job now installs the deb, asserts /sbin/mount.objectfs
resolves to a runnable file (`-L` plus a readlink comparison is satisfied by a
dangling link), and runs `mount -t objectfs` with an option the helper refuses,
so nothing forks and no bucket or credential is touched.

Both arms were measured against real util-linux 2.38.1 in a container rather
than reasoned about, because what mount(8) does with an unknown source before
reaching a helper is not something the man page settles:

  no helper:  rc=32, "mount: /mnt/...: unknown filesystem type 'objectfs'."
  helper:     rc=1,  "mount.objectfs: unrecognized option ..."

s3://bucket reaches the helper untouched, and the option string with it. The
assertion is on the message and not the exit code alone, since every failure
here is also nonzero; each of the two is diagnosed separately, and a third
outcome says the step is no longer testing what it claims to.

Removal asserts the symlink is gone as well. dpkg cannot take it — the package
contains no path under /sbin by design — so only preremove can, and a miss
leaves a dangling /sbin/mount.TYPE on a machine with no ObjectFS installed.

Also: the job's fast pre-check no longer filters with a `-run` list of test
names. `TestThePackagesShipTheMountHelper` matches none of the seven
alternatives it had — `TestPackag` is not a substring of `TestThePackages` — so
the packaging job would not have run the one test asserting the helper has a
build and an nfpm id. The package takes 1.5 seconds; the filter bought nothing
and cost the property that a new packaging test is picked up for free.
@scttfrdmn
scttfrdmn merged commit 5cb12e1 into main Sep 18, 2026
42 checks passed
@scttfrdmn
scttfrdmn deleted the fix/136-fstab-mount-helper branch September 18, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build system, compilation, packaging area: cli Command-line interface effort: medium Medium effort - 1-2 days priority: high Important issue that should be addressed soon type: enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

B1-3: Add /sbin/mount.objectfs fstab helper

1 participant