usr.sbin/makefs: Add HAMMER2 offline bulkfree support
commita63188c81886f62d9f7d45b8fad235eef99b7c05
authorTomohiro Kusumi <tkusumi@netbsd.org>
Sat, 3 Jun 2023 07:12:15 +0000 (3 00:12 -0700)
committerTomohiro Kusumi <tkusumi@netbsd.org>
Sun, 4 Jun 2023 06:20:54 +0000 (3 23:20 -0700)
treec7855d135f9ff64e6c593a26bccdc84f52af1c9a
parent01a24a934a5d6fd384584e1d72f1f9dd25bb98d3
usr.sbin/makefs: Add HAMMER2 offline bulkfree support

Since makefs HAMMER2 implements the entire HAMMER2 logic in userspace
with selected vops using single threaded xops, it's actually trivial
to support other operations, e.g. HAMMER2 ioctls.

This commit adds bulkfree (free unreferenced blocks by scanning the
entire data chains from vchain) option to makefs. Unlike the existing
hammer2(8) "bulkfree" directive which requires live filesystem, this
option enables offline bulkfree against unmounted HAMMER2 image.

The offline bulkfree takes HAMMER2 specific "-o B" option. When this
option is specified, makefs runs offline bulkfree against `image-file`
argument instead of creating one, hence it must be a valid HAMMER2
image. `image-file` can be either a regular file or block device.
Unlike normal use case, `directory` argument is unused, but it's
still required. It can be any valid path or simply "--".

e.g.
$ makefs -t hammer2 -o B /dev/adx --
$ makefs -t hammer2 -o B /path/to/hammer2.img --

Technically, all HAMMER2 ioctls can be implemented in makefs as
offline version, but "bulkfree" and "growfs" are probably the only
hammer2(8) directives that make sense to exist as offline version.

Note that the limitation regarding OOM mentioned in 2d60b848f2 also
applies to bulkfree, i.e. makefs(8) could fail with partially written
`image-file` if it contains insane number of files or directories.
usr.sbin/makefs/hammer2.c
usr.sbin/makefs/hammer2.h
usr.sbin/makefs/hammer2/Makefile.inc
usr.sbin/makefs/hammer2/hammer2.h
usr.sbin/makefs/hammer2/hammer2_bulkfree.c [new file with mode: 0644]
usr.sbin/makefs/hammer2/hammer2_ioctl.c [new file with mode: 0644]
usr.sbin/makefs/hammer2/hammer2_ondisk.c
usr.sbin/makefs/hammer2/hammer2_subr.c
usr.sbin/makefs/makefs.8
usr.sbin/makefs/makefs.c
usr.sbin/makefs/walk.c