History log of /freebsd-current/stand/libsa/zfs/zfsimpl.c
Revision Date Author Comments
# 525e6d6c 26-Feb-2024 Warner Losh <imp@FreeBSD.org>

loader/zfs: Fix to actually return the last error

The last fix, to try to return the last error, really returns the first
return code after the last error, which could be zero. Instead, return
the last error. Also, change rc to err to make it visually distinct from
rv, which is the cause of my error in e54bb0ad8058.

Reported by: Bill Sommerfeld <sommerfeld@hamachi.org>
Fixes: e54bb0ad8058
Sponsored by: Netflix


# 3e15b01d 22-Feb-2024 Warner Losh <imp@FreeBSD.org>

libsa: Remove redundant sys/cdefs.h

Sponsored by: Netflix


# e54bb0ad 22-Feb-2024 Warner Losh <imp@FreeBSD.org>

loader: return errors from writing ZFS labels

vdev_write_bootenv_impl can only return success. Instead, return the
last error. This will make any write errors more visible. The old code
masked kboot's inability to write bootenv.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D44018


# c2588f5e 04-Nov-2023 Alexander Motin <mav@FreeBSD.org>

stand/zfs: Remove one more read-compatible feature

This feature is marked as ZFEATURE_FLAG_READONLY_COMPAT and so
irrelevant for read-only pool imports by the loader:

"com.delphix:spacemap_v2"

This should cause no functional changes, just a code cleanup.

I'm sorry, missed it in previous commit.

MFC after: 2 months


# 939a62d6 03-Nov-2023 Alexander Motin <mav@FreeBSD.org>

stand/zfs: Remove read-compatible features

These features are marked as ZFEATURE_FLAG_READONLY_COMPAT and so
irrelevant for read-only pool imports by the loader:

"com.datto:resilver_defer",
"com.delphix:obsolete_counts",
"com.delphix:spacemap_histogram",
"com.delphix:zpool_checkpoint",
"com.intel:allocation_classes",
"org.zfsonlinux:allocation_classes"

This should cause no functional changes, just a code cleanup.

MFC after: 2 months


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 5fd34912 04-May-2023 Warner Losh <imp@FreeBSD.org>

stand: Fix oversight in updating OpenZFS: Add com.klarasystems:vdev_zaps_v2

com.klarasystems:vdev_zaps_v2 is a new feature that the last OpenZFS
import brought in. It needs to be on the list of supported features, but
that update didn't happen so I woke up to a mailbox with multiple
complaints.

CirrusCI test to boot twice with a zpool update inbetween coming later
today.

Sponsored by: Netflix


# b765cfa3 01-May-2023 Warner Losh <imp@FreeBSD.org>

stand/zfs: Refactor zfs_get_bootonce

Lookup the spa and pass it into zfs_get_bootonce_spa to process the boot
once protocol.

Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D39411


# 4dcae288 01-May-2023 Warner Losh <imp@FreeBSD.org>

stand/zfs: Refactor zfs_set_bootenv

Refactor zfs_set_bootenv to split out the lookup of spa from the
rest. zfs_set_bootenv_spa flushes the benv to the vdevs and updates the
cached benv.

Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D39410


# 6479bd1b 01-May-2023 Warner Losh <imp@FreeBSD.org>

stand/zfs: Refactor zfs_get_bootenv

Create a new interface to zfs_get_bootenv called zfs_get_bootenv_spa
which takes a spa instead of a void * (effectively a devdesc *). Use
that in zfs_get_bootenv.

Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D39409


# 439a9766 01-May-2023 Warner Losh <imp@FreeBSD.org>

stand/zfs: Move spa_find_by_dev from zfsimpl.c to zfs.c

zfsimpl.c doesn't know about devdesc at all, but zfs.c does. Move it to
zfs.c, which is the only user. Keep it static for now, but it could be
exposed later if something else were to need it.

Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D39408


# 66095010 20-Apr-2023 Gordon Bergling <gbe@FreeBSD.org>

stand: Remove a double word in a source code comment

- s/value value/value/

MFC after: 3 days


# c3fbd9c6 18-Apr-2023 Gordon Bergling <gbe@FreeBSD.org>

Revert "stand: Remove double words in source code comments"

The sentence, "The base address that we the boot0 code to to run it."
is correct.

Reported by: jrtc27

This reverts commit b12ccd0bb1b37f32e972bb3e945e4025fe409e2f.


# b12ccd0b 17-Apr-2023 Gordon Bergling <gbe@FreeBSD.org>

stand: Remove double words in source code comments

- s/to to/to/
- s/value value/value/

MFC after: 5 days


# a849842f 26-Nov-2022 Allan Jude <allanjude@FreeBSD.org>

loader: Add support for booting from a ZFS snapshot

When booting from a snapshot we need to follow a different code path
to turn the objset ID into the name, and for forward lookups we need
to walk the parent's snapnames_zap.

With this, it is possible to set the pools BOOTFS property to a
snapshot and boot with a read-only filesystem of that snapshot.

Reviewed by: tsoome, rew, imp
Sponsored By: Beckhoff Automation GmbH & Co. KG
Sponsored By: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38600


# f993fff6 10-Nov-2022 Alexander Leidinger <netchild@FreeBSD.org>

Sort list of supported features for more easy handling
in the future.

Reviewed by: imp


# 75ad2477 08-Jul-2022 Warner Losh <imp@FreeBSD.org>

stand: Add blake3 support to boot loader

Add the necessary glue to get blake3 building for the boot loaded as
well as connected to the ZFS system so it is useful.

On some platforms, we create references to blake3_sse2_impl and
blake3_sse41_impl ops structs to utilize SIMD. These aren't present on
x86 (since we dind't ask for them), but are on aarch64 with no
implementation. Since we don't want SIMD in the boot loader, have these
all return 'unsupported' always. This should be fixed upstream to allow
more flexibility in this selection, but for now we use this hack to not
modify the sys/contrib/openzfs with difficult to maintain hacks while
an upstreamable solution is found.

tsoome@ did the implementation bits in sys/cddl/boot, and I did the
Makefile work and the aweful blake3_impl_hack.c.

Co-author: tsoome@freebsd.org
Sponsored by: Netflix
Reviewed by: kevans (earlier version)
Differential Revision: https://reviews.freebsd.org/D35750


# 9cd45772 20-May-2022 Toomas Soome <tsoome@FreeBSD.org>

libsa: mark head_errlog feature supported.

head_errlog is new format for errlog, but we do not really
use errlog, so we can just mark it supported, to enable reading
from pool.

MFC after: 1 week


# 914dc91d 21-Apr-2022 Kyle Evans <kevans@FreeBSD.org>

stand: zfs: handle holes at the tail end correctly

This mirrors dmu_read_impl(), zeroing out the tail end of the buffer and
clipping the read to what's contained by the block that exists.

This fixes an issue that arose during the 13.1 release process; in
13.1-RC1 and later, setting up GELI+ZFS will result in a failure to
boot. The culprit is this, which causes us to fail to load geom_eli.ko
as there's a residual portion after the single datablk that should be
zeroed out.

PR: 263407
Reviewed by: tsoome
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D35019


# b4cb3fe0 11-Aug-2021 Toomas Soome <tsoome@FreeBSD.org>

loader: implement mount/unmount rootfs

We want to keep our root file system open to preserve bcache segment
between file accesses, thus reducing physical disk IO.

Reviewed by: imp, allanjude, kevans (previous version)
Differential Revision: https://reviews.freebsd.org/D30848
MFC after: 1 month


# d36341f7 02-Apr-2021 Toomas Soome <tsoome@FreeBSD.org>

loader: we should support pools without features

nvlist_check_features_for_read() does return error when there
are no features for read.

MFC after: 5 days


# d3eae375 15-Dec-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: allow loader to accept zfs feature com.delphix:bookmark_written

We do not need to actually read bookmarks, just whitelist this feature.

Reported by: mjg


# eba724f3 15-Dec-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: allow loader to accept zfs feature com.datto:bookmark_v2

We do not need to actually read bookmarks, just whitelist this feature

Reported by: jpaetzel


# df13933e 12-Oct-2020 Warner Losh <imp@FreeBSD.org>

Add back org.freebsd:zstd_compress to features_for_read

This list is the of features that are allowed on the whole pool,
not the list of features that are implemented.


# 9257c69b 12-Oct-2020 Warner Losh <imp@FreeBSD.org>

Turn off zstd on aarch64

loader support for zstd and zfs doesn't work for aarch64. Disable it
to unbreak the build.


# 2fec3ae8 12-Oct-2020 Warner Losh <imp@FreeBSD.org>

Add zstd support to the boot loader.

Add support to the _STANDALONE environment enough bits of the kernel
that we can compile it. We still have a small zstd_shim.c since there
were 3 items that were a bit hard to nail down and may be cleaned up
in the future. These go hand in hand with a number of commits to
sys/sys in the past weeks, should this need be MFCd.

Discussed with: mmacy (in review and on IRC/Slack)
Reviewed by: freqlabs (on openzfs repo)
Differential Revision: https://reviews.freebsd.org/D26218


# e307eb94 21-Sep-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: zfs should support bootonce an nextboot

bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.

By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.

By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.

bootonce dataset name is recorded in boot pool labels, bootenv area.

in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.

bootonce and nextboot features are usable in both UEFI and BIOS boot.

To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).

At this time, only lua loader is updated.

Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512


# 96261907 27-Aug-2020 Matt Macy <mmacy@FreeBSD.org>

ZFS: remove duplicate "com.datto:encryption" from loader


# 3e147077 25-Aug-2020 Matt Macy <mmacy@FreeBSD.org>

ZFS: whitelist zstd and encryption in the loader

Please note that neither zstd nor encryption is
supported by the loader at this instant. This
change makes it safe to use those features in
one's root pool, but not in one's root dataset.


# 277f38ab 18-Aug-2020 Mariusz Zaborski <oshogbo@FreeBSD.org>

zfs: add an option to the bootloader to rewind the ZFS checkpoint

The checkpoints are another way of keeping the state of ZFS.
During the rewind, the pool has to be exported.
This makes checkpoints unusable when using ZFS as root.
Add the option to rewind the ZFS checkpoint at the boot time.
If checkpoint exists, a new option for rewinding a checkpoint will appear in
the bootloader menu.
We fully support boot environments.
If the rewind option is selected, the boot loader will show a list of
boot environments that existed before the checkpoint.

Reviewed by: tsoome, allanjude, kevans (ok with high-level overview)
Differential Revision: https://reviews.freebsd.org/D24920


# 1a4b982e 09-Jul-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: setting vdev size based on label asize is not working

Because we need to read asize from vdev_tree. We also need to consider
different vdev type difference.

Reviewed by: allanjude
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25586


# 771f100c 02-Jul-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: zfs reader does not need BOOT2 bits

After switching zfsloader to use full libsa, we do not need
spa_get_primary() and spa_get_primary_vdev() any more.

Sponsored by: Netflix, Klara Inc.


# 045f497c 02-Jul-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: potential memory leak and check return values

Need to free nvlist before return from vdev_from_nvlist().

Sponsored by: Netflix, Klara Inc.


# b93b14dc 26-Jun-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: can not read zfs pool with slog removed

The vdev_init() does check for "known" vdev types, the [log] device removal will create "hole"
device, but vdev_init() does not allow it.

Obtained from: illumos
MFC after: 1 week


# 3830659e 20-Jun-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: create single zfs nextboot implementation

We should have nextboot feature implemented in libsa zfs code.
To get there, I have created zfs_nextboot() implementation based on
two sources, our current simple textual string based approach with added
structured boot label PAD structure from OpenZFS.

Secondly, all nvlist details are moved to separate source file and
restructured a bit. This is done to provide base support to add nvlist
add/update feature in followup updates.

And finally, the zfsboot/gptzfsboot disk access functions are swapped to use
libi386 and libsa.

Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25324


# aba2397e 17-Jun-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: r362262 did miss the pathlen check

While we are checking the "/dev/" prefix, we can skip the paths shorter than
this prefix.

Sponsored by: Netflix, Klara Inc.


# c98740b5 17-Jun-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: strings in nvlist are counted strings, not c-strings

We need to fetch both string size and data, then handle the data.

Reviewed by: allanjude
Sponsored by: Netflix, Klara Inc.


# c1c4c81f 26-Feb-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: replace zfs_alloc/zfs_free with malloc/free

Use common memory management.


# 380977d5 05-Feb-2020 Toomas Soome <tsoome@FreeBSD.org>

followup on r357497: clean obsolete comment and use shift instead of multiplication

Based on illumos review feedback: leftover comment, but also
have consistent block size calculation and add missing else leg to if
statement.


# 4d297e70 04-Feb-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: rewrite zfs reader zap code to use malloc

First step on removing zfs_alloc.

Reviewed by: delphij
Differential Revision: https://reviews.freebsd.org/D23433


# 653c3383 06-Jan-2020 Toomas Soome <tsoome@FreeBSD.org>

loader: update zfsimpl.c from illumos review suggestions

Add extra comments and update error handling.

MFH: 1 week


# 3c2db0ef 15-Dec-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: rewrite zfs vdev initialization

In some cases the pool discovery will get stuck in infinite loop while setting
up the vdev children.

To fix, we split the vdev setup into two parts, first we create vdevs based on
configuration we do get from pool label, then, we process pool config from MOS
and update the pool config if needed.

Testing done: confirm previously hung loader is not hung any more.

MFC after: 1 week


# 2e6bb655 15-Dec-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: zfsimpl.c cstyle cleanup

No functional changes intended.

MFC after: 1 week


# c527e920 13-Dec-2019 Andriy Gapon <avg@FreeBSD.org>

zfs boot: fix a crash in a rarely taken path in fzap_lookup

Instead of passing NULL to fzap_name_equal and crashing, just return
ENOENT. This happened when higher bits of a hash of the searched key
(its hash prefix) matched a hash prefix of some key in the ZAP, but the
full hash value of the searched key did not match any key in the ZAP.

I observerved this problem when loader tried to look up
"features_for_read" in a particular old pool that predates pool
features.

MFC after: 2 weeks
Sponsored by: Panzura


# c082b391 12-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

reverting r354594

In our case the structure is more complex and simple static initializer
will upset compiler diagnostics - using memset is still better than building
more complext initializer.


# e5d9d079 10-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: use struct initializer in vdev_probe().

Hopefully it is a bit more clear this way.


# 3cac32d1 10-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: memory leak in vdev_label_read_config()

We need to free the allocated buffer for label.


# ae3f74e7 05-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: clean up the noise around log device

We are ignoring log device but we also do want to have clean code.


# 9a3ea759 05-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: populate nvl with data even when label_txg is 0

We actually do not use that data, at least not now, but we want to
avoid possible surprises.


# 79a4bf89 03-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: factor out label and uberblock load from vdev_probe, add MMP checks

Clean up the label read.


# 0c0a882c 03-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: we do not support booting from pool with log device

If pool has log device, stop there and tell about it.


# abca0bd5 03-Nov-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: calculate physical vdev psize from asize

Since physical device asize is calculated from psize and the asize is stored
in pool label, we can use asize to set the value of psize, which is used to
calculate the location of the pool labels.

MFC after: 1 week


# 4efce32a 26-Oct-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: rs_alloc() may return NULL

rs_alloc() in zfs reader code may return NULL, so we need to check the return value and error out if needed.
MFC after: 1 week


# 6e5555ad 09-Aug-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: add error check for vdev_indirect calls

We can error out due to memory allocation errors, we can not recover from
those and need to get out.


# b1b93268 08-Aug-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: support com.delphix:removing

We should support removing vdev from boot pool. Update loader zfs reader
to support com.delphix:removing.

Reviewed by: allanjude
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D18901


# 6459a61e 19-Jun-2019 Matt Macy <mmacy@FreeBSD.org>

Tell loader to ignore newer features enabled on the root pool.

There are many new features in ZoF. Most, if not all, do not effect read only usage.
Encryption in particular is enabled at the pool level but used at the dataset level.
The loader obviously will not be able to boot if the boot dataset is encrypted, but
should not care if some other dataset in the root pool is encrypted.

Reviewed by: allanjude
MFC after: 1 week


# 12d62cc2 29-May-2019 Xin LI <delphij@FreeBSD.org>

Unexpand be32dec().

MFC after: 2 weeks


# 93a2d4c9 29-May-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: malloc+memset is calloc in spa_create

Replace malloc + memset pair with calloc.


# 51e5c6b8 29-May-2019 Toomas Soome <tsoome@FreeBSD.org>

loader: zfs_alloc and zfs_free should use panic

The zfs alloc and free code print out the error and get stuck in infinite loop; use panic() instead.


# 7c52f914 17-Jan-2019 Toomas Soome <tsoome@FreeBSD.org>

loader should ignore active multi_vdev_crash_dump feature on zpool

Since the loader zfs reader does not need to read the dump zvol, we can
just enable the feature.

illumos issue #9051 https://www.illumos.org/issues/9051

MFC after: 2 weeks


# b8902de1 08-Jul-2018 Warner Losh <imp@FreeBSD.org>

Move ZFS files into libsa

Move the libzfs stuff into libsa. There's no need for it to be a
separate library. The separate library adds to the issues of build
ordering that we see from time to time. Move the filesystem support
into libsa, like all the other filesystem support rather than making
zfs the odd-duck out.

Discussed with: allanjude@