Repository navigation
fsmanifest: add a tool that generates and checks manifests - #10
Merged
Merged
Conversation
Currently, the only way to get the manifest of a directory is to write a
program against the library. Let's add a command-line tool for that. It
lives in a new crate, src/fsmanifest, and builds the binary fsmanifest:
fsmanifest generate [OPTIONS] DIR [MANIFEST]
generate walks DIR and writes its manifest to the new file MANIFEST.
Without MANIFEST, or with "-" for it, the manifest goes to standard
output.
The tool only puts a command line in front of ManifestOptions. It calls
generate_at() for a file and generate() for standard output. So a new
file appears only once the manifest is complete, and a MANIFEST that
exists already is refused. A file is always synced before it gets its
name, and standard output is never synced.
Note that the walk passes over a MANIFEST inside DIR. A file inside DIR
that standard output is redirected to is a file of the tree like any
other, so the manifest lists it, with the size it has while DIR is
walked. --help says to give MANIFEST instead.
Standard output is written through a descriptor of its own and not
through std's Stdout. That one takes a write that fails with EBADF for a
success. So with a standard output that is open for reading the manifest
would be lost, and the tool would still exit with 0. An error of
standard output says that it is one, also where the library passes it
on.
--features=LIST takes the names of the features to record, as the
specification has them. "default" stands for the default features, so
--features=default,mtime,user-xattr works. "none" stands for no
features, so --features=none makes a manifest whose list of features is
empty. An empty LIST is an error. --features=help lists the names with
a mark behind the default ones, and says that the gpt-* ones are for
manifests of partitions, which generate refuses for a tree.
--cross-mounts walks into mount points and --graceful leaves out files
whose names a manifest can't hold. They are AddFlags::CROSS_MOUNTS and
AddFlags::GRACEFUL. -h is short for --help, and --version has no short
form.
generate prints nothing on success. It says on standard error how many
files and fields the manifest leaves out, which the report of the
library counts.
The exit status is 0 on success and 2 for every failure, a command line
the tool doesn't take included. That is what diff and cmp exit with for
trouble. Their 1, for a difference, is not used.
Note that the tool opens DIR and the directory MANIFEST goes into with a
slash at the end of their path. The kernel then opens a directory and
nothing else, as with O_DIRECTORY, whose constant std doesn't have. So a
FIFO fails with ENOTDIR instead of blocking.
The time and the memory generate takes are those of the builder. On one
CPU a tree of ten million small files takes 32 s, ten times as long as
one of a million, and memory peaks at 39 MiB for a manifest of 1.5 GB.
What doesn't fit into that memory goes to disk while the manifest is
built: next to MANIFEST, and for standard output into the directory
TMPDIR names, or into /var/tmp without it. --help says so, and that
TMPDIR has to be trusted.
The command line is parsed with lexopt. The jobs of the workflow build,
test and lint the whole workspace, so they cover the new crate as they
are. The list of the dependency job needs lexopt added. The package job
now runs cargo package --workspace as well, since the tool can't be
packaged on its own before uapi16 is on crates.io. With --workspace
cargo builds the packaged tool against the packaged library.
The crate names the version of uapi16 next to its path, since cargo
refuses to package a crate whose dependency has a path and no version.
Like src/uapi16 it has keywords and categories for crates.io and a copy
of LICENSE.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a command that checks a manifest:
fsmanifest check [OPTIONS] MANIFEST
check reads MANIFEST, or standard input for "-", once and as a stream.
It runs the Reader of the library to the end of the manifest. That
checks the root file object, every file object and where it comes, the
fields against the features the manifest records, the signature objects
and the trailer. A manifest that declares an order has to keep it. The
reader enforces that itself, so check doesn't call require_order().
Note that the reader checks each object on its own and against the one
before it. So a name that comes twice is only sure to be found where the
manifest declares an order, and file objects that share an inode token
aren't compared with each other. --help says so.
Then check asks the root file object whether the manifest may be used
now, with check_validity() and the current time. So a manifest that is
revoked, expired or not valid yet fails. Only the validity of the root
is looked at. Whether a single file object may be used is for the
consumer of the manifest to honour. What is wrong with the manifest
itself is reported first.
check prints nothing for a valid manifest and exits with 0. For any
other manifest, and for one it can't read, it exits with 2 and says on
standard error what is wrong. Where a record is wrong the message names
it. Most sentences of the library do that themselves, and the tool puts
the record in front of those that don't:
fsmanifest: esp.manifest: manifest object 2 (a): comes after 'b',
which it sorts before in the code point ordering
fsmanifest: esp.manifest: record 3: manifest contains data after
the trailer object
Note that check verifies no signature cryptographically, since the
library has no such verification. --help says so. Comparing a tree with
its manifest isn't part of check yet either. That needs the file objects
of a tree as a stream, which the library doesn't hand out so far.
The reader keeps one record in memory, so check's memory doesn't grow
with the manifest. A manifest of ten million file objects, 1.5 GB, read
from a pipe takes 8 s on one CPU, and memory peaks at 1.2 MB, as it does
for a manifest of a thousand file objects.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add src/fsmanifest/README.md. It says what generate and check do, what the tool exits with and what it needs. cargo takes the README.md of a package directory for the package, so this is also the page crates.io shows for the crate once it is published. The README of the repository names the new file in its introduction and gets a section that says how to build the tool, as it has for the library. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Currently, the tarballs of a release hold the C library and nothing else. So whoever wants fsmanifest has to build it, and needs a Rust toolchain for that. Let's ship it prebuilt next to the library. The build job builds fsmanifest right after the library, with the same rustc and in the same container, so against glibc 2.34 as well. The binary goes into the directory of the tarball as bin/fsmanifest. fsmanifest links lexopt, which the library doesn't. The license step now asks cargo tree for the crates of both. So the license text of lexopt lands in share/licenses/uapi16/crates next to the others, and a crate of the tool without a license file fails the job like one of the library. The tarball is named after the version of the library, and fsmanifest has a version of its own. So the Version step now fails unless the two are the same. Note that a version in [workspace.package] would tie them together as well, but install.sh reads the version of the library from src/uapi16/Cargo.toml, and with version.workspace = true it finds none there. The check of the layout expects bin/fsmanifest, as a regular file that can be executed. It also runs the binary of the unpacked tarball, which has to say the version of the tarball, and has it write and check the manifest of a small tree. The check for glibc symbols newer than GLIBC_2.34 runs over the binary as well as over the shared library. The check of the exported functions stays with the shared library, since a binary exports none. The README now says that the tarballs have the tool, and where it ends up. Its section on them is called "Release tarballs" now, since they hold more than the C library. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add a man page for fsmanifest, written by hand with the man macros. It covers both commands and says what their --help and the README say, in the same sentences where they fit a man page. The examples are the ones of the README. The title line has no date and no version, since both would go stale with every release. The page lives in src/fsmanifest, so the crate that gets published carries it, and packagers can install it from there. The documentation job renders the page with groff and all warnings turned on. groff exits with 0 no matter what it warns about, so the job fails if groff prints anything at all. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Add completions of fsmanifest for bash, zsh and fish to src/fsmanifest/completions. They complete the commands and their options, a directory for DIR and a file for MANIFEST, and the names of the features in the list of --features, behind the = and behind a comma. zsh and fish also show what each command and option does, in the words of --help and the man page. The names aren't written into the scripts. When a list is completed they come from fsmanifest generate --features=help, where each line up to the first empty one starts with the name of a feature. So a feature that gets added later completes without a change to the scripts. Next to the names the scripts offer default and none, and help as long as the list is empty. A name that is in the list already isn't offered again. The bash script works without bash-completion. bash splits a word at the characters of COMP_WORDBREAKS, so --features=LIST arrives split at the =, and a path with a = or : in it is split there as well. The script joins the parts again before it counts the arguments, and leaves the names of files and directories to readline. fish 4.0 deprecated commandline -o in favor of -x, which an older fish doesn't have. So the fish script tries -x first and falls back to -o. tests/completions.py tests the completion of a shell in that shell, against a built fsmanifest. bash and zsh run in a terminal of their own, where one key puts all matches of the word in front of the cursor into the line and another one writes the line to a file. fish lists the matches itself with complete -C. A new CI job checks the syntax of the scripts and runs the test for each shell. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
The tarballs of a release have fsmanifest in bin, but neither its man
page nor its completions. Let's install them next to it:
share/man/man1/fsmanifest.1
share/bash-completion/completions/fsmanifest
share/zsh/site-functions/_fsmanifest
share/fish/vendor_completions.d/fsmanifest.fish
install.sh stays the installer of the C library and doesn't install
them, as it doesn't install fsmanifest either. The build job installs
them itself, right after the binary.
The check of the layout expects them as regular files, and the
directories they are in. The README now says that the tarballs have
them.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
A contents object can say that the data of a file is at an http or https URL. Currently the library doesn't fetch such data, and FileObject::data_location() fails for an object that has its data only at a URL. Add an entry so we don't forget that the library needs to learn to download it. The entry gets a section of its own, since it isn't about the manifest builder or the C API. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
A manifest can carry signature objects. Currently the library reads them and tells the caller how much of the manifest they sign, but it doesn't verify any signature. Add an entry for that as well. The entry gets a section of its own next to the one for the data, since a signature is over the manifest and not over the data of a file. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Currently fsmanifest check validates a manifest by itself: its form, the order it declares and whether it may be used now. It should learn to validate a manifest against what it describes as well: a directory tree, an image and the data next to the manifest. Add an entry for that. The entry gets a section for the tool. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Currently the reader checks a file object by itself and against the one before it. It doesn't notice a name that comes twice in a manifest without a declared order, objects that share an inode token but differ in their type or their fields, or tokens that don't count from 1. Add an entry for these checks. The entry gets a section for the reader since that's where the checks belong. fsmanifest check gets them once the reader has them. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds fsmanifest, a command-line tool that generates and checks
manifests. Currently, the only way to get the manifest of a directory
is to write a program against the library. The tool lives in a new
crate, src/fsmanifest, and has the commands generate and check:
generate walks DIR and writes its manifest to the new file MANIFEST.
Without MANIFEST, or with "-" for it, the manifest goes to standard
output. The tool only puts a command line in front of ManifestOptions.
So a new file appears only once the manifest is complete, and a
MANIFEST that exists already is refused.
Note that the walk passes over a MANIFEST inside DIR. A file inside DIR
that standard output is redirected to is a file of the tree like any
other, so the manifest lists it. --help says to give MANIFEST instead.
--features=LIST takes the names of the features to record, as the
specification has them. "default" stands for the default features, so
--features=default,mtime,user-xattr works, and "none" for no features.
--features=help lists the names. --cross-mounts walks into mount points
and --graceful leaves out files whose names a manifest can't hold.
The time and the memory generate takes are those of the builder. On one
CPU a tree of ten million small files takes 32 s, ten times as long as
one of a million, and memory peaks at 39 MiB for a manifest of 1.5 GB.
What doesn't fit into that memory goes to disk while the manifest is
built, next to MANIFEST, and for standard output into the directory
TMPDIR names, or into /var/tmp without it. --help says so, and that
TMPDIR has to be trusted.
check reads MANIFEST, or standard input for "-", once and as a stream.
It runs the Reader of the library to the end of the manifest. That
checks the root file object, every file object and where it comes, the
fields against the features the manifest records, the signature objects
and the trailer. A manifest that declares an order has to keep it. Then
check asks the root file object whether the manifest may be used now,
so a manifest that is revoked, expired or not valid yet fails. Only the
validity of the root is looked at.
Note that the reader checks each object on its own and against the one
before it. So a name that comes twice is only sure to be found where the
manifest declares an order, and file objects that share an inode token
aren't compared with each other. check also verifies no signature
cryptographically, since the library has no such verification. --help
says so for both.
check's memory doesn't grow with the manifest. A manifest of ten million
file objects, 1.5 GB, read from a pipe takes 8 s on one CPU, and memory
peaks at 1.2 MB, as it does for a manifest of a thousand file objects.
fsmanifest exits with 0 on success and with 2 for every failure, a
command line it doesn't take included. That's what diff and cmp exit
with for trouble. check prints nothing for a valid manifest. For any
other, and for one it can't read, it says on standard error what is
wrong, and where a record is wrong the message names it.
src/fsmanifest/README.md says what the commands do, what the tool exits
with and what it needs. It's also the page crates.io shows for the crate
once it is published. The man page covers both commands in the words of
--help and the README. It lives in src/fsmanifest, so the published
crate carries it and packagers can install it from there.
The completions for bash, zsh and fish complete the commands, their
options, a directory for DIR, a file for MANIFEST and the names of the
features in the list of --features. They take the names from fsmanifest
itself, so a feature that gets added later completes without a change to
the scripts.
uapi16 and fsmanifest both go to crates.io at the 0.1.0 release.
fsmanifest names uapi16 by its path and its version, since cargo refuses
to package a crate whose dependency has a path and no version. So the
tool can't be packaged on its own before uapi16 is on crates.io, and
uapi16 goes first. The package job now runs cargo package --workspace as
well, which builds the packaged tool against the packaged library.
Currently, the tarballs of a release hold the C library and nothing
else. So whoever wants fsmanifest has to build it, and needs a Rust
toolchain for that. Let's ship it prebuilt next to the library, with its
man page and its completions:
The release job builds fsmanifest right after the library, with the same
rustc and in the same container, so against glibc 2.34 as well.
install.sh stays the installer of the C library and installs none of
these. The tarball is named after the version of the library, so the job
fails unless fsmanifest has the same version. It runs the binary of the
unpacked tarball, which has to say that version, and has it write and
check the manifest of a small tree. The check for glibc symbols newer
than GLIBC_2.34 covers the binary as well. And since fsmanifest links
lexopt, which the library doesn't, the license text of lexopt is in the
tarball now.
The TODO entries at the end are for what we left for later:
directory tree, an image and the data next to the manifest
has them
In CI, the jobs that build, test and lint the workspace cover the new
crate as they are. The documentation job renders the man page with groff
and all warnings turned on, and fails if groff prints anything. A new
job checks the syntax of the completions and tests each of them in its
shell against a built fsmanifest.
TODO: add entry for reader checks across file objects
TODO: add entry for checking against tree, image and data
TODO: add entry for verifying signatures
TODO: add entry for http and https downloads
ci: ship the man page and the completions in the release tarballs
fsmanifest: add completions for bash, zsh and fish
fsmanifest: add a man page
ci: ship fsmanifest in the release tarballs
fsmanifest: add a README
fsmanifest: add the check command
fsmanifest: add a tool that generates manifests