xref: /freebsd/lib/libbe/libbe.3 (revision 455d8009b468669020eb5dd2a209e9094eeda503)
128f16a0fSKyle Evans.\"
2b179da01SKyle Evans.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3b179da01SKyle Evans.\"
428f16a0fSKyle Evans.\" Copyright (c) 2017 Kyle Kneitinger
528f16a0fSKyle Evans.\" All rights reserved.
67c2cc9b2SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
728f16a0fSKyle Evans.\"
828f16a0fSKyle Evans.\" Redistribution and use in source and binary forms, with or without
928f16a0fSKyle Evans.\" modification, are permitted provided that the following conditions
1028f16a0fSKyle Evans.\" are met:
1128f16a0fSKyle Evans.\" 1. Redistributions of source code must retain the above copyright
1228f16a0fSKyle Evans.\"    notice, this list of conditions and the following disclaimer.
1328f16a0fSKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright
1428f16a0fSKyle Evans.\"    notice, this list of conditions and the following disclaimer in the
1528f16a0fSKyle Evans.\"    documentation and/or other materials provided with the distribution.
1628f16a0fSKyle Evans.\"
1728f16a0fSKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1828f16a0fSKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1928f16a0fSKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2028f16a0fSKyle Evans.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2128f16a0fSKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2228f16a0fSKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2328f16a0fSKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2428f16a0fSKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2528f16a0fSKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2628f16a0fSKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2728f16a0fSKyle Evans.\" SUCH DAMAGE.
2828f16a0fSKyle Evans.\"
2928f16a0fSKyle Evans.\" $FreeBSD$
3028f16a0fSKyle Evans.\"
31*455d8009SKyle Evans.Dd October 16, 2019
3228f16a0fSKyle Evans.Dt LIBBE 3
3328f16a0fSKyle Evans.Os
3428f16a0fSKyle Evans.Sh NAME
3528f16a0fSKyle Evans.Nm libbe
3684e61219SKyle Evans.Nd library for creating, destroying and modifying ZFS boot environments
3784e61219SKyle Evans.Sh LIBRARY
387c2cc9b2SKyle Evans.Lb libbe
3928f16a0fSKyle Evans.Sh SYNOPSIS
4028f16a0fSKyle Evans.In be.h
417c2cc9b2SKyle Evans.Ft "libbe_handle_t *hdl" Ns
42cc624025SKyle Evans.Fn libbe_init "const char *be_root"
4328f16a0fSKyle Evans.Pp
447c2cc9b2SKyle Evans.Ft void
457c2cc9b2SKyle Evans.Fn libbe_close "libbe_handle_t *hdl"
4628f16a0fSKyle Evans.Pp
477c2cc9b2SKyle Evans.Ft const char * Ns
487c2cc9b2SKyle Evans.Fn be_active_name "libbe_handle_t *hdl"
497c2cc9b2SKyle Evans.Pp
507c2cc9b2SKyle Evans.Ft const char * Ns
517c2cc9b2SKyle Evans.Fn be_active_path "libbe_handle_t *hdl"
527c2cc9b2SKyle Evans.Pp
537c2cc9b2SKyle Evans.Ft const char * Ns
547c2cc9b2SKyle Evans.Fn be_nextboot_name "libbe_handle_t *hdl"
557c2cc9b2SKyle Evans.Pp
567c2cc9b2SKyle Evans.Ft const char * Ns
577c2cc9b2SKyle Evans.Fn be_nextboot_path "libbe_handle_t *hdl"
587c2cc9b2SKyle Evans.Pp
597c2cc9b2SKyle Evans.Ft const char * Ns
607c2cc9b2SKyle Evans.Fn be_root_path "libbe_handle_t *hdl"
617c2cc9b2SKyle Evans.Pp
62*455d8009SKyle Evans.Ft bool Ns
63*455d8009SKyle Evans.Fn be_is_auto_snapshot_name "libbe_handle_t *hdl" "const char *snap"
64*455d8009SKyle Evans.Pp
657c2cc9b2SKyle Evans.Ft int
667c2cc9b2SKyle Evans.Fn be_create "libbe_handle_t *hdl" "const char *be_name"
677c2cc9b2SKyle Evans.Pp
687c2cc9b2SKyle Evans.Ft int
69fa30d9edSKyle Evans.Fn be_create_depth "libbe_handle_t *hdl" "const char *be_name" "const char *snap" "int depth"
70fa30d9edSKyle Evans.Pp
71fa30d9edSKyle Evans.Ft int
727c2cc9b2SKyle Evans.Fn be_create_from_existing "libbe_handle_t *hdl" "const char *be_name" "const char *be_origin"
737c2cc9b2SKyle Evans.Pp
747c2cc9b2SKyle Evans.Ft int
757c2cc9b2SKyle Evans.Fn be_create_from_existing_snap "libbe_handle_t *hdl" "const char *be_name" "const char *snap"
767c2cc9b2SKyle Evans.Pp
777c2cc9b2SKyle Evans.Ft int
787c2cc9b2SKyle Evans.Fn be_rename "libbe_handle_t *hdl" "const char *be_old" "const char *be_new"
797c2cc9b2SKyle Evans.Pp
807c2cc9b2SKyle Evans.Ft int
817c2cc9b2SKyle Evans.Fn be_activate "libbe_handle_t *hdl" "const char *be_name" "bool temporary"
827c2cc9b2SKyle Evans.Ft int
837c2cc9b2SKyle Evans.Fn be_destroy "libbe_handle_t *hdl" "const char *be_name" "int options"
847c2cc9b2SKyle Evans.Pp
857c2cc9b2SKyle Evans.Ft void
867c2cc9b2SKyle Evans.Fn be_nicenum "uint64_t num" "char *buf" "size_t bufsz"
877c2cc9b2SKyle Evans.Pp
887c2cc9b2SKyle Evans.\" TODO: Write up of mount options
897c2cc9b2SKyle Evans.\" typedef enum {
907c2cc9b2SKyle Evans.\"	BE_MNT_FORCE		= 1 << 0,
917c2cc9b2SKyle Evans.\"	BE_MNT_DEEP		= 1 << 1,
927c2cc9b2SKyle Evans.\" } be_mount_opt_t
937c2cc9b2SKyle Evans.Ft int
947c2cc9b2SKyle Evans.Fn be_mount "libbe_handle_t *hdl" "char *be_name" "char *mntpoint" "int flags" "char *result"
957c2cc9b2SKyle Evans.Pp
967c2cc9b2SKyle Evans.Ft int
977c2cc9b2SKyle Evans.Fn be_mounted_at "libbe_handle_t *hdl" "const char *path" "nvlist_t *details"
987c2cc9b2SKyle Evans.Pp
997c2cc9b2SKyle Evans.Ft int
1007c2cc9b2SKyle Evans.Fn be_unmount "libbe_handle_t *hdl" "char *be_name" "int flags"
1017c2cc9b2SKyle Evans.Pp
1027c2cc9b2SKyle Evans.Ft int
1037c2cc9b2SKyle Evans.Fn libbe_errno "libbe_handle_t *hdl"
1047c2cc9b2SKyle Evans.Pp
1057c2cc9b2SKyle Evans.Ft const char * Ns
1067c2cc9b2SKyle Evans.Fn libbe_error_description "libbe_handle_t *hdl"
1077c2cc9b2SKyle Evans.Pp
1087c2cc9b2SKyle Evans.Ft void
1097c2cc9b2SKyle Evans.Fn libbe_print_on_error "libbe_handle_t *hdl" "bool doprint"
1107c2cc9b2SKyle Evans.Pp
1117c2cc9b2SKyle Evans.Ft int
1127c2cc9b2SKyle Evans.Fn be_root_concat "libbe_handle_t *hdl" "const char *be_name" "char *result"
1137c2cc9b2SKyle Evans.Pp
1147c2cc9b2SKyle Evans.Ft int
1157c2cc9b2SKyle Evans.Fn be_validate_name "libbe_handle_t *hdl" "const char *be_name"
1167c2cc9b2SKyle Evans.Pp
1177c2cc9b2SKyle Evans.Ft int
1187c2cc9b2SKyle Evans.Fn be_validate_snap "libbe_handle_t *hdl" "const char *snap"
1197c2cc9b2SKyle Evans.Pp
120162ec569SKyle Evans.Ft int
1217c2cc9b2SKyle Evans.Fn be_exists "libbe_handle_t *hdl" "char *be_name"
1227c2cc9b2SKyle Evans.Pp
1237c2cc9b2SKyle Evans.Ft int
1247c2cc9b2SKyle Evans.Fn be_export "libbe_handle_t *hdl" "const char *be_name" "int fd"
1257c2cc9b2SKyle Evans.Pp
1267c2cc9b2SKyle Evans.Ft int
1277c2cc9b2SKyle Evans.Fn be_import "libbe_handle_t *hdl" "const char *be_name" "int fd"
1287c2cc9b2SKyle Evans.Pp
1297c2cc9b2SKyle Evans.Ft int
1307c2cc9b2SKyle Evans.Fn be_prop_list_alloc "nvlist_t **prop_list"
1317c2cc9b2SKyle Evans.Pp
1327c2cc9b2SKyle Evans.Ft int
1337c2cc9b2SKyle Evans.Fn be_get_bootenv_props "libbe_handle_t *hdl" "nvlist_t *be_list"
1347c2cc9b2SKyle Evans.Pp
1357c2cc9b2SKyle Evans.Ft int
1367c2cc9b2SKyle Evans.Fn be_get_dataset_props "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *props"
1377c2cc9b2SKyle Evans.Pp
1387c2cc9b2SKyle Evans.Ft int
1397c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *snap_list"
1407c2cc9b2SKyle Evans.Pp
1417c2cc9b2SKyle Evans.Ft void
1427c2cc9b2SKyle Evans.Fn be_prop_list_free "nvlist_t *prop_list"
14328f16a0fSKyle Evans.Sh DESCRIPTION
14428f16a0fSKyle Evans.Nm
14528f16a0fSKyle Evansinterfaces with libzfs to provide a set of functions for various operations
14628f16a0fSKyle Evansregarding ZFS boot environments including "deep" boot environments in which
14728f16a0fSKyle Evansa boot environments has child datasets.
14828f16a0fSKyle Evans.Pp
14928f16a0fSKyle EvansA context structure is passed to each function, allowing for a small amount
15028f16a0fSKyle Evansof state to be retained, such as errors from previous operations.
1517c2cc9b2SKyle Evans.Nm
1527c2cc9b2SKyle Evansmay be configured to print the corresponding error message to
1537c2cc9b2SKyle Evans.Dv stderr
1547c2cc9b2SKyle Evanswhen an error is encountered with
1557c2cc9b2SKyle Evans.Fn libbe_print_on_error .
15628f16a0fSKyle Evans.Pp
1577c2cc9b2SKyle EvansAll functions returning an
1587c2cc9b2SKyle Evans.Vt int
1597c2cc9b2SKyle Evansreturn 0 on success, or a
1607c2cc9b2SKyle Evans.Nm
1617c2cc9b2SKyle Evanserrno otherwise as described in
1627c2cc9b2SKyle Evans.Sx DIAGNOSTICS .
16328f16a0fSKyle Evans.Pp
1647c2cc9b2SKyle EvansThe
1657c2cc9b2SKyle Evans.Fn libbe_init
166cc624025SKyle Evansfunction takes an optional BE root and initializes
1677c2cc9b2SKyle Evans.Nm ,
1687c2cc9b2SKyle Evansreturning a
1697c2cc9b2SKyle Evans.Vt "libbe_handle_t *"
1707c2cc9b2SKyle Evanson success, or
1717c2cc9b2SKyle Evans.Dv NULL
1727c2cc9b2SKyle Evanson error.
173cc624025SKyle EvansIf a BE root is supplied,
174cc624025SKyle Evans.Nm
175cc624025SKyle Evanswill only operate out of that pool and BE root.
1767c2cc9b2SKyle EvansAn error may occur if:
1777c2cc9b2SKyle Evans.Bl -column
1787c2cc9b2SKyle Evans.It /boot and / are not on the same filesystem and device,
1797c2cc9b2SKyle Evans.It libzfs fails to initialize,
1807c2cc9b2SKyle Evans.It The system has not been properly booted with a ZFS boot
1817c2cc9b2SKyle Evansenvironment,
182d2a6bc9fSKyle Evans.It Nm
1837c2cc9b2SKyle Evansfails to open the zpool the active boot environment resides on, or
184d2a6bc9fSKyle Evans.It Nm
1857c2cc9b2SKyle Evansfails to locate the boot environment that is currently mounted.
1867c2cc9b2SKyle Evans.El
18728f16a0fSKyle Evans.Pp
1887c2cc9b2SKyle EvansThe
1897c2cc9b2SKyle Evans.Fn libbe_close
1907c2cc9b2SKyle Evansfunction frees all resources previously acquired in
1917c2cc9b2SKyle Evans.Fn libbe_init ,
1927c2cc9b2SKyle Evansinvalidating the handle in the process.
19328f16a0fSKyle Evans.Pp
1947c2cc9b2SKyle EvansThe
1957c2cc9b2SKyle Evans.Fn be_active_name
196cc624025SKyle Evansfunction returns the name of the currently booted boot environment.
197cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe
198cc624025SKyle Evansis operating on!
19984e61219SKyle Evans.Pp
2007c2cc9b2SKyle EvansThe
2017c2cc9b2SKyle Evans.Fn be_active_path
2027c2cc9b2SKyle Evansfunction returns the full path of the currently booted boot environment.
203cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe
204cc624025SKyle Evansis operating on!
20584e61219SKyle Evans.Pp
2067c2cc9b2SKyle EvansThe
2077c2cc9b2SKyle Evans.Fn be_nextboot_name
2087c2cc9b2SKyle Evansfunction returns the name of the boot environment that will be active on reboot.
20928f16a0fSKyle Evans.Pp
2107c2cc9b2SKyle EvansThe
2117c2cc9b2SKyle Evans.Fn be_nextboot_path
2127c2cc9b2SKyle Evansfunction returns the full path of the boot environment that will be
2137c2cc9b2SKyle Evansactive on reboot.
21428f16a0fSKyle Evans.Pp
2157c2cc9b2SKyle EvansThe
2167c2cc9b2SKyle Evans.Fn be_root_path
2177c2cc9b2SKyle Evansfunction returns the boot environment root path.
21828f16a0fSKyle Evans.Pp
2197c2cc9b2SKyle EvansThe
220*455d8009SKyle Evans.Fn be_is_auto_snapshot_name
221*455d8009SKyle Evansfunction is used to determine if the given snapshot name matches the format that
222*455d8009SKyle Evansthe
223*455d8009SKyle Evans.Fn be_snapshot
224*455d8009SKyle Evansfunction will use by default if it is not given a snapshot name to use.
225*455d8009SKyle EvansIt returns
226*455d8009SKyle Evans.Dv true
227*455d8009SKyle Evansif the name matches the format, and
228*455d8009SKyle Evans.Dv false
229*455d8009SKyle Evansif it does not.
230*455d8009SKyle Evans.Pp
231*455d8009SKyle EvansThe
2327c2cc9b2SKyle Evans.Fn be_create
2337c2cc9b2SKyle Evansfunction creates a boot environment with the given name.
234fa30d9edSKyle EvansThe new boot environment will be created from a recursive snapshot of the
235fa30d9edSKyle Evanscurrently booted boot environment.
236fa30d9edSKyle Evans.Pp
237fa30d9edSKyle EvansThe
238fa30d9edSKyle Evans.Fn be_create_depth
239fa30d9edSKyle Evansfunction creates a boot environment with the given name from an existing
240fa30d9edSKyle Evanssnapshot.
241fa30d9edSKyle EvansThe depth parameter specifies the depth of recursion that will be cloned from
242fa30d9edSKyle Evansthe existing snapshot.
243fa30d9edSKyle EvansA depth of '0' is no recursion and '-1' is unlimited (i.e., a recursive boot
244fa30d9edSKyle Evansenvironment).
24528f16a0fSKyle Evans.Pp
2467c2cc9b2SKyle EvansThe
2477c2cc9b2SKyle Evans.Fn be_create_from_existing
2487c2cc9b2SKyle Evansfunction creates a boot environment with the given name from the name of an
2497c2cc9b2SKyle Evansexisting boot environment.
250fa30d9edSKyle EvansA recursive snapshot will be made of the origin boot environment, and the new
251fa30d9edSKyle Evansboot environment will be created from that.
25228f16a0fSKyle Evans.Pp
2537c2cc9b2SKyle EvansThe
2547c2cc9b2SKyle Evans.Fn be_create_from_existing_snap
255fa30d9edSKyle Evansfunction creates a recursive boot environment with the given name from an
256fa30d9edSKyle Evansexisting snapshot.
25728f16a0fSKyle Evans.Pp
2587c2cc9b2SKyle EvansThe
2597c2cc9b2SKyle Evans.Fn be_rename
2608369ba42SKyle Evansfunction renames a boot environment without unmounting it, as if renamed with
2618369ba42SKyle Evansthe
2628369ba42SKyle Evans.Fl u
2638369ba42SKyle Evansargument were passed to
2648369ba42SKyle Evans.Nm zfs
2658369ba42SKyle Evans.Cm rename
2669b1662e6SKyle Evans.Pp
2677c2cc9b2SKyle EvansThe
2687c2cc9b2SKyle Evans.Fn be_activate
2697c2cc9b2SKyle Evansfunction makes a boot environment active on the next boot.
2707c2cc9b2SKyle EvansIf the
2717c2cc9b2SKyle Evans.Fa temporary
2727c2cc9b2SKyle Evansflag is set, then it will be active for the next boot only, as done by
2737c2cc9b2SKyle Evans.Xr zfsbootcfg 8 .
2747c2cc9b2SKyle EvansNext boot functionality is currently only available when booting in x86 BIOS
2757c2cc9b2SKyle Evansmode.
27628f16a0fSKyle Evans.Pp
2777c2cc9b2SKyle EvansThe
2787c2cc9b2SKyle Evans.Fn be_destroy
2797c2cc9b2SKyle Evansfunction will recursively destroy the given boot environment.
2807c2cc9b2SKyle EvansIt will not destroy a mounted boot environment unless the
2817c2cc9b2SKyle Evans.Dv BE_DESTROY_FORCE
2827c2cc9b2SKyle Evansoption is set in
2837c2cc9b2SKyle Evans.Fa options .
284446ae812SKyle EvansIf the
285446ae812SKyle Evans.Dv BE_DESTROY_ORIGIN
286446ae812SKyle Evansoption is set in
287446ae812SKyle Evans.Fa options ,
288446ae812SKyle Evansthe
289446ae812SKyle Evans.Fn be_destroy
290446ae812SKyle Evansfunction will destroy the origin snapshot to this boot environment as well.
291843e39ceSKyle Evans.Pp
2927c2cc9b2SKyle EvansThe
2937c2cc9b2SKyle Evans.Fn be_nicenum
2947c2cc9b2SKyle Evansfunction will format
2957c2cc9b2SKyle Evans.Fa name
2967c2cc9b2SKyle Evansin a traditional ZFS humanized format, similar to
2977c2cc9b2SKyle Evans.Xr humanize_number 3 .
2987c2cc9b2SKyle EvansThis function effectively proxies
2997c2cc9b2SKyle Evans.Fn zfs_nicenum
3007c2cc9b2SKyle Evansfrom libzfs.
30128f16a0fSKyle Evans.Pp
3027c2cc9b2SKyle EvansThe
3037c2cc9b2SKyle Evans.Fn be_mount
3047c2cc9b2SKyle Evansfunction will mount the given boot environment.
3057c2cc9b2SKyle EvansIf
3067c2cc9b2SKyle Evans.Fa mountpoint
3077c2cc9b2SKyle Evansis
3087c2cc9b2SKyle Evans.Dv NULL ,
3097c2cc9b2SKyle Evansa mount point will be generated in
3107c2cc9b2SKyle Evans.Pa /tmp
3117c2cc9b2SKyle Evansusing
3127c2cc9b2SKyle Evans.Xr mkdtemp 3 .
3137c2cc9b2SKyle EvansIf
3147c2cc9b2SKyle Evans.Fa result
3157c2cc9b2SKyle Evansis not
3167c2cc9b2SKyle Evans.Dv NULL ,
317a8e44f4dSKyle Evansit should be large enough to accommodate
318a8e44f4dSKyle Evans.Dv BE_MAXPATHLEN
319a8e44f4dSKyle Evansincluding the null terminator.
3207c2cc9b2SKyle Evansthe final mount point will be copied into it.
3217c2cc9b2SKyle EvansSetting the
3227c2cc9b2SKyle Evans.Dv BE_MNT_FORCE
3237c2cc9b2SKyle Evansflag will pass
3247c2cc9b2SKyle Evans.Dv MNT_FORCE
3257c2cc9b2SKyle Evansto the underlying
3267c2cc9b2SKyle Evans.Xr mount 2
3277c2cc9b2SKyle Evanscall.
32828f16a0fSKyle Evans.Pp
3297c2cc9b2SKyle EvansThe
3307c2cc9b2SKyle Evans.Fn be_mounted_at
3317c2cc9b2SKyle Evansfunction will check if there is a boot environment mounted at the given
3327c2cc9b2SKyle Evans.Fa path .
3337c2cc9b2SKyle EvansIf
3347c2cc9b2SKyle Evans.Fa details
3357c2cc9b2SKyle Evansis not
3367c2cc9b2SKyle Evans.Dv NULL ,
3377c2cc9b2SKyle Evansit will be populated with a list of the mounted dataset's properties.
3387c2cc9b2SKyle EvansThis list of properties matches the properties collected by
3397c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
34028f16a0fSKyle Evans.Pp
3417c2cc9b2SKyle EvansThe
3427c2cc9b2SKyle Evans.Fn be_unmount
3437c2cc9b2SKyle Evansfunction will unmount the given boot environment.
3447c2cc9b2SKyle EvansSetting the
3457c2cc9b2SKyle Evans.Dv BE_MNT_FORCE
3467c2cc9b2SKyle Evansflag will pass
3477c2cc9b2SKyle Evans.Dv MNT_FORCE
3487c2cc9b2SKyle Evansto the underlying
3497c2cc9b2SKyle Evans.Xr mount 2
3507c2cc9b2SKyle Evanscall.
35128f16a0fSKyle Evans.Pp
3527c2cc9b2SKyle EvansThe
3537c2cc9b2SKyle Evans.Fn libbe_errno
3547c2cc9b2SKyle Evansfunction returns the
3557c2cc9b2SKyle Evans.Nm
3567c2cc9b2SKyle Evanserrno.
35728f16a0fSKyle Evans.Pp
3587c2cc9b2SKyle EvansThe
3597c2cc9b2SKyle Evans.Fn libbe_error_description
3607c2cc9b2SKyle Evansfunction returns a string description of the currently set
3617c2cc9b2SKyle Evans.Nm
3627c2cc9b2SKyle Evanserrno.
36328f16a0fSKyle Evans.Pp
3647c2cc9b2SKyle EvansThe
3657c2cc9b2SKyle Evans.Fn libbe_print_on_error
3667c2cc9b2SKyle Evansfunction will change whether or not
3677c2cc9b2SKyle Evans.Nm
3687c2cc9b2SKyle Evansprints the description of any encountered error to
3697c2cc9b2SKyle Evans.Dv stderr ,
3707c2cc9b2SKyle Evansbased on
3717c2cc9b2SKyle Evans.Fa doprint .
37228f16a0fSKyle Evans.Pp
3737c2cc9b2SKyle EvansThe
3747c2cc9b2SKyle Evans.Fn be_root_concat
3757c2cc9b2SKyle Evansfunction will concatenate the boot environment root and the given boot
3767c2cc9b2SKyle Evansenvironment name into
3777c2cc9b2SKyle Evans.Fa result .
37828f16a0fSKyle Evans.Pp
3797c2cc9b2SKyle EvansThe
3807c2cc9b2SKyle Evans.Fn be_validate_name
3815b7803a9SKyle Evansfunction will validate the given boot environment name for both length
3825b7803a9SKyle Evansrestrictions as well as valid character restrictions.
3835b7803a9SKyle EvansThis function does not set the internal library error state.
38428f16a0fSKyle Evans.Pp
3857c2cc9b2SKyle EvansThe
3867c2cc9b2SKyle Evans.Fn be_validate_snap
3877c2cc9b2SKyle Evansfunction will validate the given snapshot name.
3887c2cc9b2SKyle EvansThe snapshot must have a valid name, exist, and have a mountpoint of
3897c2cc9b2SKyle Evans.Pa / .
3907c2cc9b2SKyle EvansThis function does not set the internal library error state.
39128f16a0fSKyle Evans.Pp
3927c2cc9b2SKyle EvansThe
3937c2cc9b2SKyle Evans.Fn be_exists
3947c2cc9b2SKyle Evansfunction will check whether the given boot environment exists and has a
3957c2cc9b2SKyle Evansmountpoint of
3967c2cc9b2SKyle Evans.Pa / .
397162ec569SKyle EvansThis function does not set the internal library error state, but will return
398162ec569SKyle Evansthe appropriate error.
399734e362fSKyle Evans.Pp
4007c2cc9b2SKyle EvansThe
4017c2cc9b2SKyle Evans.Fn be_export
4027c2cc9b2SKyle Evansfunction will export the given boot environment to the file specified by
4037c2cc9b2SKyle Evans.Fa fd .
4047c2cc9b2SKyle EvansA snapshot will be created of the boot environment prior to export.
405734e362fSKyle Evans.Pp
4067c2cc9b2SKyle EvansThe
4077c2cc9b2SKyle Evans.Fn be_import
4087c2cc9b2SKyle Evansfunction will import the boot environment in the file specified by
4097c2cc9b2SKyle Evans.Fa fd ,
4107c2cc9b2SKyle Evansand give it the name
4117c2cc9b2SKyle Evans.Fa be_name .
4124146029bSKyle Evans.Pp
4137c2cc9b2SKyle EvansThe
4147c2cc9b2SKyle Evans.Fn be_prop_list_alloc
4157c2cc9b2SKyle Evansfunction allocates a property list suitable for passing to
4167c2cc9b2SKyle Evans.Fn be_get_bootenv_props ,
4177c2cc9b2SKyle Evans.Fn be_get_dataset_props ,
4187c2cc9b2SKyle Evansor
4197c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots .
4207c2cc9b2SKyle EvansIt should be freed later by
4217c2cc9b2SKyle Evans.Fa be_prop_list_free .
42296c5db58SKyle Evans.Pp
4237c2cc9b2SKyle EvansThe
4247c2cc9b2SKyle Evans.Fn be_get_bootenv_props
4257c2cc9b2SKyle Evansfunction will populate
4267c2cc9b2SKyle Evans.Fa be_list
4277c2cc9b2SKyle Evanswith
4287c2cc9b2SKyle Evans.Vt nvpair_t
4297c2cc9b2SKyle Evansof boot environment names paired with an
4307c2cc9b2SKyle Evans.Vt nvlist_t
4317c2cc9b2SKyle Evansof their properties.
4327c2cc9b2SKyle EvansThe following properties are currently collected as appropriate:
4337c2cc9b2SKyle Evans.Bl -column "Returned name"
4347c2cc9b2SKyle Evans.It Sy Returned name Ta Sy Description
4357c2cc9b2SKyle Evans.It dataset Ta -
4367c2cc9b2SKyle Evans.It name Ta Boot environment name
4377c2cc9b2SKyle Evans.It mounted Ta Current mount point
4387c2cc9b2SKyle Evans.It mountpoint Ta Do mountpoint Dc property
4397c2cc9b2SKyle Evans.It origin Ta Do origin Dc property
4407c2cc9b2SKyle Evans.It creation Ta Do creation Dc property
4417c2cc9b2SKyle Evans.It active Ta Currently booted environment
4427c2cc9b2SKyle Evans.It used Ta Literal Do used Dc property
4437c2cc9b2SKyle Evans.It usedds Ta Literal Do usedds Dc property
4447c2cc9b2SKyle Evans.It usedsnap Ta Literal Do usedrefreserv Dc property
4457c2cc9b2SKyle Evans.It referenced Ta Literal Do referenced Dc property
4467c2cc9b2SKyle Evans.It nextboot Ta Active on next boot
4477c2cc9b2SKyle Evans.El
4487c2cc9b2SKyle Evans.Pp
4497c2cc9b2SKyle EvansOnly the
4507c2cc9b2SKyle Evans.Dq dataset ,
4517c2cc9b2SKyle Evans.Dq name ,
4527c2cc9b2SKyle Evans.Dq active ,
4537c2cc9b2SKyle Evansand
4547c2cc9b2SKyle Evans.Dq nextboot
4557c2cc9b2SKyle Evansreturned values will always be present.
4567c2cc9b2SKyle EvansAll other properties may be omitted if not available.
4577c2cc9b2SKyle Evans.Pp
4587c2cc9b2SKyle EvansThe
4597c2cc9b2SKyle Evans.Fn be_get_dataset_props
4607c2cc9b2SKyle Evansfunction will get properties of the specified dataset.
4617c2cc9b2SKyle Evans.Fa props
4627c2cc9b2SKyle Evansis populated directly with a list of the properties as returned by
4637c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
4647c2cc9b2SKyle Evans.Pp
4657c2cc9b2SKyle EvansThe
4667c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots
4677c2cc9b2SKyle Evansfunction will retrieve all snapshots of the given dataset.
4687c2cc9b2SKyle Evans.Fa snap_list
4697c2cc9b2SKyle Evanswill be populated with a list of
4707c2cc9b2SKyle Evans.Vt nvpair_t
4717c2cc9b2SKyle Evansexactly as specified by
4727c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
4737c2cc9b2SKyle Evans.Pp
4747c2cc9b2SKyle EvansThe
4757c2cc9b2SKyle Evans.Fn be_prop_list_free
4767c2cc9b2SKyle Evansfunction will free the property list.
47728f16a0fSKyle Evans.Sh DIAGNOSTICS
478cc58f749SMateusz PiotrowskiUpon error, one of the following values will be returned:
479cc58f749SMateusz Piotrowski.Bl -dash -offset indent -compact
480cc58f749SMateusz Piotrowski.It
481cc58f749SMateusz PiotrowskiBE_ERR_SUCCESS
482cc58f749SMateusz Piotrowski.It
483cc58f749SMateusz PiotrowskiBE_ERR_INVALIDNAME
484cc58f749SMateusz Piotrowski.It
485cc58f749SMateusz PiotrowskiBE_ERR_EXISTS
486cc58f749SMateusz Piotrowski.It
487cc58f749SMateusz PiotrowskiBE_ERR_NOENT
488cc58f749SMateusz Piotrowski.It
489cc58f749SMateusz PiotrowskiBE_ERR_PERMS
490cc58f749SMateusz Piotrowski.It
491cc58f749SMateusz PiotrowskiBE_ERR_DESTROYACT
492cc58f749SMateusz Piotrowski.It
493cc58f749SMateusz PiotrowskiBE_ERR_DESTROYMNT
494cc58f749SMateusz Piotrowski.It
495cc58f749SMateusz PiotrowskiBE_ERR_BADPATH
496cc58f749SMateusz Piotrowski.It
497cc58f749SMateusz PiotrowskiBE_ERR_PATHBUSY
498cc58f749SMateusz Piotrowski.It
499cc58f749SMateusz PiotrowskiBE_ERR_PATHLEN
500cc58f749SMateusz Piotrowski.It
501cc58f749SMateusz PiotrowskiBE_ERR_BADMOUNT
502cc58f749SMateusz Piotrowski.It
503cc58f749SMateusz PiotrowskiBE_ERR_NOORIGIN
504cc58f749SMateusz Piotrowski.It
505cc58f749SMateusz PiotrowskiBE_ERR_MOUNTED
506cc58f749SMateusz Piotrowski.It
507cc58f749SMateusz PiotrowskiBE_ERR_NOMOUNT
508cc58f749SMateusz Piotrowski.It
509cc58f749SMateusz PiotrowskiBE_ERR_ZFSOPEN
510cc58f749SMateusz Piotrowski.It
511cc58f749SMateusz PiotrowskiBE_ERR_ZFSCLONE
512cc58f749SMateusz Piotrowski.It
513cc58f749SMateusz PiotrowskiBE_ERR_IO
514cc58f749SMateusz Piotrowski.It
515cc58f749SMateusz PiotrowskiBE_ERR_NOPOOL
516cc58f749SMateusz Piotrowski.It
517cc58f749SMateusz PiotrowskiBE_ERR_NOMEM
518cc58f749SMateusz Piotrowski.It
51928f16a0fSKyle EvansBE_ERR_UNKNOWN
520be7dd423SKyle Evans.It
521be7dd423SKyle EvansBE_ERR_INVORIGIN
522cc58f749SMateusz Piotrowski.El
52328f16a0fSKyle Evans.Sh SEE ALSO
524f5c8cb4cSMateusz Piotrowski.Xr bectl 8
52528f16a0fSKyle Evans.Sh HISTORY
52628f16a0fSKyle Evans.Nm
52784e61219SKyle Evansand its corresponding command,
52884e61219SKyle Evans.Xr bectl 8 ,
52928f16a0fSKyle Evanswere written as a 2017 Google Summer of Code project with Allan Jude serving
53028f16a0fSKyle Evansas a mentor.
5317c2cc9b2SKyle EvansLater work was done by
5327c2cc9b2SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org .
533