History log of /freebsd-current/lib/libbe/be_info.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 5086b6ec 26-Jan-2024 R. Christian McDonald <rcm@FreeBSD.org>

libbe: handle destroying/renaming temporary/bootonce boot environments

When a temporary/bootonce boot environment is renamed, we need to also
update the bootenv nvlist on-disk to reflect the new name. Additionally,
when a temporary/bootonce boot environment is destroyed, we also need to
clear out the on-disk state.

Reviewed by: kevans
Approved by: kp
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D43591


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

Remove $FreeBSD$: one-line .c pattern

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


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 15f0b8c3 25-Jan-2023 Martin Matuska <mm@FreeBSD.org>

zfs: merge openzfs/zfs@9cd71c860 (master)

Notable upstream pull request merges:
#13805 Configure zed's diagnosis engine with vdev properties
#14110 zfs list: Allow more fields in ZFS_ITER_SIMPLE mode
#14121 Batch enqueue/dequeue for bqueue
#14123 arc_read()/arc_access() refactoring and cleanup
#14159 Bypass metaslab throttle for removal allocations
#14243 Implement uncached prefetch
#14251 Cache dbuf_hash() calculation
#14253 Allow reciever to override encryption property in case of replication
#14254 Restrict visibility of per-dataset kstats inside FreeBSD jails
#14255 Zero end of embedded block buffer in dump_write_embedded()
#14263 Cleanups identified by CodeQL and Coverity
#14264 Miscellaneous fixes
#14272 Change ZEVENT_POOL_GUID to ZEVENT_POOL to display pool names
#14287 FreeBSD: Remove stray debug printf
#14288 Colorize zfs diff output
#14289 deadlock between spa_errlog_lock and dp_config_rwlock
#14291 FreeBSD: Fix potential boot panic with bad label
#14292 Add tunable to allow changing micro ZAP's max size
#14293 Turn default_bs and default_ibs into ZFS_MODULE_PARAMs
#14295 zed: add hotplug support for spare vdevs
#14304 Activate filesystem features only in syncing context
#14311 zpool: do guid-based comparison in is_vdev_cb()
#14317 Pack zrlock_t by 8 bytes
#14320 Update arc_summary and arcstat outputs
#14328 FreeBSD: catch up to 1400077
#14376 Use setproctitle to report progress of zfs send
#14340 Remove some dead ARC code
#14358 Wait for txg sync if the last DRR_FREEOBJECTS might result in a hole
#14360 libzpool: fix ddi_strtoull to update nptr
#14364 Fix unprotected zfs_znode_dmu_fini
#14379 zfs_receive_one: Check for the more likely error first
#14380 Cleanup of dead code suggested by Clang Static Analyzer
#14397 Avoid passing an uninitialized index to dsl_prop_known_index
#14404 Fix reading uninitialized variable in receive_read
#14407 free_blocks(): Fix reports from 2016 PVS Studio FreeBSD report
#14418 Introduce minimal ZIL block commit delay
#14422 x86 assembly: fix .size placement and replace .align with .balign

Obtained from: OpenZFS
OpenZFS commit: 9cd71c8604d52def22ffaddc35755712f0fb9349


# 5773e924 18-Oct-2020 Kyle Evans <kevans@FreeBSD.org>

libbe(3): const'ify a couple arguments

libbe will never need to mutate these as we either process them into a local
buffer or we just don't touch them and write to a separate out argument.

MFC after: 1 week

# 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

# 6966ac05 23-Jan-2020 Kyle Evans <kevans@FreeBSD.org>

Drop "All Rights Reserved" from all libbe/bectl files

I sent out an e-mail on 2020/01/21 with a plan to do this to Kyle, Rob, and
Wes; all parties have responded in the affirmative that it's OK to drop it
from these files.

# 485172f5 06-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

libbe: fix build against sysutils/openzfs, part 1

This is the half of the changes required that work as-is with both in-tree
ZFS and the new hotness, sysutils/openzfs. Highlights are less dependency
on header pollution (from somewhere) and using 'mnttab' instead of
'extmnttab'. In the in-tree ZFS, the latter is a #define for the former,
but in the port extmnttab is actually a distinct struct that's a super-set
of mnttab. We really want mnttab here anyways, so just use it.

# cefbdf3e 26-Oct-2019 Alan Somers <asomers@FreeBSD.org>

Commit missing file from r354116

Pointy-hat-to: Me
Reported by: Dan Mack
MFC after: 2 weeks
MFC-With: 354116

# cc624025 18-Nov-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(3)/libbe(3): Allow BE root to be specified

Add an undocumented -r option preceding the bectl subcommand to specify a BE
root to operate out of. This will remain undocumented for now, as some
caveats apply:

- BEs cannot be activated in the pool that doesn't contain the rootfs
- bectl create cannot work out of the box without the -e option right now,
since it defaults to the rootfs and cross-pool cloning doesn't work like
that (IIRC)

Plumb the BE root through to libbe(3) so that some things -can- be done to
it, e.g.

bectl -r tank/ROOT create -e default upgrade
bectl -r tank/ROOT mount upgrade /mnt

this aides in some upgrade setups where rootfs is not necessarily ZFS, and
also makes it easier/possible to regression-test bectl when combined with a
file-backed zpool.

MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D18029

# 51aecc89 17-Nov-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): rewrite init to support chroot usage

libbe(3) currently uses zfs_be_root and locates which of its children is
currently mounted at "/". This is reasonable, but not correct in the case of
a chroot, for two reasons:

- chroot root may be of a different zpool than zfs_be_root
- chroot root will not show up as mounted at "/"

Fix both of these by rewriting libbe_init to work from the rootfs down.
zfs_path_to_zhandle on / will resolve to the dataset mounted at the new
root, rather than the real root. From there, we can derive the BE root/pool
and grab the bootfs off of the new pool. This does no harm in the average
case, and opens up bectl to operating on different pools for scenarios where
one may be, for instance, updating a pool that generally gets re-rooted into
from a separate UFS root or zfs bootpool.

While here, I've also:
- Eliminated the check for /boot and / to be on the same partition. This
leaves one open to a setup where /boot (and consequently, kernel/modules)
are not included in the boot environment. This may very well be an
intentional setup done by someone that knows what they're doing, we should
not kill BE usage because of it.

- Eliminated the validation bits of BEs and snapshots that enforced
'mountpoint' to be "/" -- this broke when trying to operate on an imported
pool with an altroot, but we need not be this picky.

Reported by: philip
Reviewed by: philip, allanjude (previous version)
Tested by: philip
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D18012

# 162ec569 31-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Fix error handling with respect to be_exists

Some paths through be_exists will set the error state, others will not
There are multiple reasons that a call can fail, so clean it up a bit: all
paths now return an appropriate error code so the caller can attempt to
distinguish between a BE legitimately not existing and just having the wrong
mountpoint. The caller is expected to bubble the error through to the
internal error handler as needed.

This fixes some unfriendliness with bectl(8)'s activate subcommand, where
it might fail due to a bad mountpoint but the only message output is a
generic "failed to activate" message.

Approved by: re (gjb)

# b6e7c421 07-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/bectl(8): Standardize $FreeBSD$ IDs

# b179da01 07-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/bectl(8): Standardize copyright headers

- File names don't necessarily need to be repeated
- Add SPDX tags
- Add a missing copyright for Kyle Kneitinger in bectl.8, originally written
by him in GSoC 2017; his standard copyright notice has been copied from
other files within the same directory to remain consistent with how he
clearly wished to portray it

# 709b553c 06-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Check that dataset is to be mounted at / for be_exists

This makes the be_exists behavior match the comments that assert that we've
already checked that the dataset derived from the BE name is set to mount at
/.

Other changes of note:
- bectl_list sees another change; changing mountpoint based on mount status
turns out to be a bad idea, so instead make the mounted property of the
returned nvlist the path that it's mounted at

- Always return the "mountpoint" property in "mountpoint" if it's ste

# 5468566e 06-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Rename prop_list_builder and snapshot_prop_list_builder

# 96c5db58 05-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(8): Implement `bectl list -s`

be_get_dataset_snapshots has been added to libbe(3), effectively returning
the same information as be_get_bootenv_props but for snapshots of the given
dataset. The assumption is that one will have the BE dataset name before
wanting to grab snapshots.

# 9b1662e6 04-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

bectl: Implement -D ("space if origin datasets were deleted")

This also accomplishes the following:

- Proxy through zfs_nicenum as be_nicenum, because it looks better than
humanize_number and would presumably be useful to other libbe consumers.

- Rename be_get_snapshot_props to be_get_dataset_props, make it more useful

# 4146029b 02-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(8): Take origin snapshot into account when calculating used space

This more closely matches the behavior for beadm. The associated libbe(3)
API is still getting worked out a little bit.

# 513044c1 02-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Fix checking of zfs_prop_get's return value

Rather than a boolean_t, it returns an int != 0 for error or 0 for OK.

# 843e39ce 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Add be_mounted_at to check a mount point

At a bare minimum, this function will return 0 if a BE is mounted at the
given path or non-zero otherwise. If the optional 'details' nvlist is
supplied, it is filled with an nvpair containing just the information about
the BE mounted at the path. This nvpair is structured just as it is for
be_get_bootenv_props, except limited to just the single mount point.

# 734e362f 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/bectl(8): Provide and use proper alloc/free for property lists

# 4831c931 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Use zfs_is_mounted to check mounted and mountpoint

# b29bf2f8 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/be(8): Drop WARNS overrides, fix all fallout

Based on the idea that we shouldn't have all-new library and utility going
into base that need WARNS=1...

- Decent amount of constification
- Lots of parentheses
- Minor other nits

# ff8676cc 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Add nextboot flag to returned BE information

# 3682d5e9 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(8): Start dumping out BE information with `bectl list`

For the moment, this is a primitive nvlist dump of what we get back from
be_get_bootenv_props as a proof-of-concept and to make sure that we're
getting back the kind of information we want to see from list.

# bfe0869c 24-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): make style consistent with what I'll use going forward

# c3a34c08 24-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Disambiguate 'active' a little bit, add 'bootfs'

- Rename 'active' to 'rootfs', which is used in other places to describe the
currently booted (or about to be booted) BE.

- Add 'bootfs', which indicates the next boot environment to be booted. This
is pulled from the BOOTFS zpool property.

- Go ahead and keep an open handle to the active zpool. We might need to
enumerate datasets, get properties, and set properties (e.g. bootfs)
throughout other libbe bits, and a single handle isn't overly expensive.

# 28f16a0f 24-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

Import libbe(3)/be(1) from socsvn/soc2017/kneitinger/libbe-head

# 5773e924 18-Oct-2020 Kyle Evans <kevans@FreeBSD.org>

libbe(3): const'ify a couple arguments

libbe will never need to mutate these as we either process them into a local
buffer or we just don't touch them and write to a separate out argument.

MFC after: 1 week


# 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


# 6966ac05 23-Jan-2020 Kyle Evans <kevans@FreeBSD.org>

Drop "All Rights Reserved" from all libbe/bectl files

I sent out an e-mail on 2020/01/21 with a plan to do this to Kyle, Rob, and
Wes; all parties have responded in the affirmative that it's OK to drop it
from these files.


# 485172f5 06-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

libbe: fix build against sysutils/openzfs, part 1

This is the half of the changes required that work as-is with both in-tree
ZFS and the new hotness, sysutils/openzfs. Highlights are less dependency
on header pollution (from somewhere) and using 'mnttab' instead of
'extmnttab'. In the in-tree ZFS, the latter is a #define for the former,
but in the port extmnttab is actually a distinct struct that's a super-set
of mnttab. We really want mnttab here anyways, so just use it.


# cefbdf3e 26-Oct-2019 Alan Somers <asomers@FreeBSD.org>

Commit missing file from r354116

Pointy-hat-to: Me
Reported by: Dan Mack
MFC after: 2 weeks
MFC-With: 354116


# cc624025 18-Nov-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(3)/libbe(3): Allow BE root to be specified

Add an undocumented -r option preceding the bectl subcommand to specify a BE
root to operate out of. This will remain undocumented for now, as some
caveats apply:

- BEs cannot be activated in the pool that doesn't contain the rootfs
- bectl create cannot work out of the box without the -e option right now,
since it defaults to the rootfs and cross-pool cloning doesn't work like
that (IIRC)

Plumb the BE root through to libbe(3) so that some things -can- be done to
it, e.g.

bectl -r tank/ROOT create -e default upgrade
bectl -r tank/ROOT mount upgrade /mnt

this aides in some upgrade setups where rootfs is not necessarily ZFS, and
also makes it easier/possible to regression-test bectl when combined with a
file-backed zpool.

MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D18029


# 51aecc89 17-Nov-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): rewrite init to support chroot usage

libbe(3) currently uses zfs_be_root and locates which of its children is
currently mounted at "/". This is reasonable, but not correct in the case of
a chroot, for two reasons:

- chroot root may be of a different zpool than zfs_be_root
- chroot root will not show up as mounted at "/"

Fix both of these by rewriting libbe_init to work from the rootfs down.
zfs_path_to_zhandle on / will resolve to the dataset mounted at the new
root, rather than the real root. From there, we can derive the BE root/pool
and grab the bootfs off of the new pool. This does no harm in the average
case, and opens up bectl to operating on different pools for scenarios where
one may be, for instance, updating a pool that generally gets re-rooted into
from a separate UFS root or zfs bootpool.

While here, I've also:
- Eliminated the check for /boot and / to be on the same partition. This
leaves one open to a setup where /boot (and consequently, kernel/modules)
are not included in the boot environment. This may very well be an
intentional setup done by someone that knows what they're doing, we should
not kill BE usage because of it.

- Eliminated the validation bits of BEs and snapshots that enforced
'mountpoint' to be "/" -- this broke when trying to operate on an imported
pool with an altroot, but we need not be this picky.

Reported by: philip
Reviewed by: philip, allanjude (previous version)
Tested by: philip
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D18012


# 162ec569 31-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Fix error handling with respect to be_exists

Some paths through be_exists will set the error state, others will not
There are multiple reasons that a call can fail, so clean it up a bit: all
paths now return an appropriate error code so the caller can attempt to
distinguish between a BE legitimately not existing and just having the wrong
mountpoint. The caller is expected to bubble the error through to the
internal error handler as needed.

This fixes some unfriendliness with bectl(8)'s activate subcommand, where
it might fail due to a bad mountpoint but the only message output is a
generic "failed to activate" message.

Approved by: re (gjb)


# b6e7c421 07-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/bectl(8): Standardize $FreeBSD$ IDs


# b179da01 07-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/bectl(8): Standardize copyright headers

- File names don't necessarily need to be repeated
- Add SPDX tags
- Add a missing copyright for Kyle Kneitinger in bectl.8, originally written
by him in GSoC 2017; his standard copyright notice has been copied from
other files within the same directory to remain consistent with how he
clearly wished to portray it


# 709b553c 06-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Check that dataset is to be mounted at / for be_exists

This makes the be_exists behavior match the comments that assert that we've
already checked that the dataset derived from the BE name is set to mount at
/.

Other changes of note:
- bectl_list sees another change; changing mountpoint based on mount status
turns out to be a bad idea, so instead make the mounted property of the
returned nvlist the path that it's mounted at

- Always return the "mountpoint" property in "mountpoint" if it's ste


# 5468566e 06-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Rename prop_list_builder and snapshot_prop_list_builder


# 96c5db58 05-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(8): Implement `bectl list -s`

be_get_dataset_snapshots has been added to libbe(3), effectively returning
the same information as be_get_bootenv_props but for snapshots of the given
dataset. The assumption is that one will have the BE dataset name before
wanting to grab snapshots.


# 9b1662e6 04-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

bectl: Implement -D ("space if origin datasets were deleted")

This also accomplishes the following:

- Proxy through zfs_nicenum as be_nicenum, because it looks better than
humanize_number and would presumably be useful to other libbe consumers.

- Rename be_get_snapshot_props to be_get_dataset_props, make it more useful


# 4146029b 02-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(8): Take origin snapshot into account when calculating used space

This more closely matches the behavior for beadm. The associated libbe(3)
API is still getting worked out a little bit.


# 513044c1 02-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Fix checking of zfs_prop_get's return value

Rather than a boolean_t, it returns an int != 0 for error or 0 for OK.


# 843e39ce 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Add be_mounted_at to check a mount point

At a bare minimum, this function will return 0 if a BE is mounted at the
given path or non-zero otherwise. If the optional 'details' nvlist is
supplied, it is filled with an nvpair containing just the information about
the BE mounted at the path. This nvpair is structured just as it is for
be_get_bootenv_props, except limited to just the single mount point.


# 734e362f 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/bectl(8): Provide and use proper alloc/free for property lists


# 4831c931 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Use zfs_is_mounted to check mounted and mountpoint


# b29bf2f8 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3)/be(8): Drop WARNS overrides, fix all fallout

Based on the idea that we shouldn't have all-new library and utility going
into base that need WARNS=1...

- Decent amount of constification
- Lots of parentheses
- Minor other nits


# ff8676cc 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Add nextboot flag to returned BE information


# 3682d5e9 25-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

bectl(8): Start dumping out BE information with `bectl list`

For the moment, this is a primitive nvlist dump of what we get back from
be_get_bootenv_props as a proof-of-concept and to make sure that we're
getting back the kind of information we want to see from list.


# bfe0869c 24-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): make style consistent with what I'll use going forward


# c3a34c08 24-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

libbe(3): Disambiguate 'active' a little bit, add 'bootfs'

- Rename 'active' to 'rootfs', which is used in other places to describe the
currently booted (or about to be booted) BE.

- Add 'bootfs', which indicates the next boot environment to be booted. This
is pulled from the BOOTFS zpool property.

- Go ahead and keep an open handle to the active zpool. We might need to
enumerate datasets, get properties, and set properties (e.g. bootfs)
throughout other libbe bits, and a single handle isn't overly expensive.


# 28f16a0f 24-Jul-2018 Kyle Evans <kevans@FreeBSD.org>

Import libbe(3)/be(1) from socsvn/soc2017/kneitinger/libbe-head