xref: /freebsd/lib/libbe/libbe.3 (revision f446c9482cbcd1235ed05597e7c8a0bb320d71fe)
128f16a0fSKyle Evans.\"
24d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause
3b179da01SKyle Evans.\"
428f16a0fSKyle Evans.\" Copyright (c) 2017 Kyle Kneitinger
57c2cc9b2SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
628f16a0fSKyle Evans.\"
728f16a0fSKyle Evans.\" Redistribution and use in source and binary forms, with or without
828f16a0fSKyle Evans.\" modification, are permitted provided that the following conditions
928f16a0fSKyle Evans.\" are met:
1028f16a0fSKyle Evans.\" 1. Redistributions of source code must retain the above copyright
1128f16a0fSKyle Evans.\"    notice, this list of conditions and the following disclaimer.
1228f16a0fSKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright
1328f16a0fSKyle Evans.\"    notice, this list of conditions and the following disclaimer in the
1428f16a0fSKyle Evans.\"    documentation and/or other materials provided with the distribution.
1528f16a0fSKyle Evans.\"
1628f16a0fSKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1728f16a0fSKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1828f16a0fSKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1928f16a0fSKyle Evans.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2028f16a0fSKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2128f16a0fSKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2228f16a0fSKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2328f16a0fSKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2428f16a0fSKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2528f16a0fSKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2628f16a0fSKyle Evans.\" SUCH DAMAGE.
2728f16a0fSKyle Evans.\"
285773e924SKyle Evans.Dd August 18, 2020
2928f16a0fSKyle Evans.Dt LIBBE 3
3028f16a0fSKyle Evans.Os
3128f16a0fSKyle Evans.Sh NAME
3228f16a0fSKyle Evans.Nm libbe
3384e61219SKyle Evans.Nd library for creating, destroying and modifying ZFS boot environments
3484e61219SKyle Evans.Sh LIBRARY
357c2cc9b2SKyle Evans.Lb libbe
3628f16a0fSKyle Evans.Sh SYNOPSIS
3728f16a0fSKyle Evans.In be.h
387c2cc9b2SKyle Evans.Ft "libbe_handle_t *hdl" Ns
39cc624025SKyle Evans.Fn libbe_init "const char *be_root"
4028f16a0fSKyle Evans.Pp
417c2cc9b2SKyle Evans.Ft void
427c2cc9b2SKyle Evans.Fn libbe_close "libbe_handle_t *hdl"
4328f16a0fSKyle Evans.Pp
447c2cc9b2SKyle Evans.Ft const char * Ns
457c2cc9b2SKyle Evans.Fn be_active_name "libbe_handle_t *hdl"
467c2cc9b2SKyle Evans.Pp
477c2cc9b2SKyle Evans.Ft const char * Ns
487c2cc9b2SKyle Evans.Fn be_active_path "libbe_handle_t *hdl"
497c2cc9b2SKyle Evans.Pp
507c2cc9b2SKyle Evans.Ft const char * Ns
517c2cc9b2SKyle Evans.Fn be_nextboot_name "libbe_handle_t *hdl"
527c2cc9b2SKyle Evans.Pp
537c2cc9b2SKyle Evans.Ft const char * Ns
547c2cc9b2SKyle Evans.Fn be_nextboot_path "libbe_handle_t *hdl"
557c2cc9b2SKyle Evans.Pp
567c2cc9b2SKyle Evans.Ft const char * Ns
577c2cc9b2SKyle Evans.Fn be_root_path "libbe_handle_t *hdl"
587c2cc9b2SKyle Evans.Pp
59513bd2fcSKyle Evans.Ft int Ns
60513bd2fcSKyle Evans.Fn be_snapshot "libbe_handle_t *hdl" "const char *be_name" "const char *snap_name" "bool recursive" "char *result"
61513bd2fcSKyle Evans.Pp
62455d8009SKyle Evans.Ft bool Ns
63455d8009SKyle Evans.Fn be_is_auto_snapshot_name "libbe_handle_t *hdl" "const char *snap"
64455d8009SKyle 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"
82e307eb94SToomas Soome.Pp
83e307eb94SToomas Soome.Ft int
84e307eb94SToomas Soome.Fn be_deactivate "libbe_handle_t *hdl" "const char *be_name" "bool temporary"
85e307eb94SToomas Soome.Pp
867c2cc9b2SKyle Evans.Ft int
877c2cc9b2SKyle Evans.Fn be_destroy "libbe_handle_t *hdl" "const char *be_name" "int options"
887c2cc9b2SKyle Evans.Pp
897c2cc9b2SKyle Evans.Ft void
907c2cc9b2SKyle Evans.Fn be_nicenum "uint64_t num" "char *buf" "size_t bufsz"
917c2cc9b2SKyle Evans.Pp
927c2cc9b2SKyle Evans.\" TODO: Write up of mount options
937c2cc9b2SKyle Evans.\" typedef enum {
947c2cc9b2SKyle Evans.\"	BE_MNT_FORCE		= 1 << 0,
957c2cc9b2SKyle Evans.\"	BE_MNT_DEEP		= 1 << 1,
967c2cc9b2SKyle Evans.\" } be_mount_opt_t
977c2cc9b2SKyle Evans.Ft int
985773e924SKyle Evans.Fn be_mount "libbe_handle_t *hdl" "const char *be_name" "const char *mntpoint" "int flags" "char *result"
997c2cc9b2SKyle Evans.Pp
1007c2cc9b2SKyle Evans.Ft int
1017c2cc9b2SKyle Evans.Fn be_mounted_at "libbe_handle_t *hdl" "const char *path" "nvlist_t *details"
1027c2cc9b2SKyle Evans.Pp
1037c2cc9b2SKyle Evans.Ft int
1045773e924SKyle Evans.Fn be_unmount "libbe_handle_t *hdl" "const char *be_name" "int flags"
1057c2cc9b2SKyle Evans.Pp
1067c2cc9b2SKyle Evans.Ft int
1077c2cc9b2SKyle Evans.Fn libbe_errno "libbe_handle_t *hdl"
1087c2cc9b2SKyle Evans.Pp
1097c2cc9b2SKyle Evans.Ft const char * Ns
1107c2cc9b2SKyle Evans.Fn libbe_error_description "libbe_handle_t *hdl"
1117c2cc9b2SKyle Evans.Pp
1127c2cc9b2SKyle Evans.Ft void
1137c2cc9b2SKyle Evans.Fn libbe_print_on_error "libbe_handle_t *hdl" "bool doprint"
1147c2cc9b2SKyle Evans.Pp
1157c2cc9b2SKyle Evans.Ft int
1167c2cc9b2SKyle Evans.Fn be_root_concat "libbe_handle_t *hdl" "const char *be_name" "char *result"
1177c2cc9b2SKyle Evans.Pp
1187c2cc9b2SKyle Evans.Ft int
1197c2cc9b2SKyle Evans.Fn be_validate_name "libbe_handle_t *hdl" "const char *be_name"
1207c2cc9b2SKyle Evans.Pp
1217c2cc9b2SKyle Evans.Ft int
1227c2cc9b2SKyle Evans.Fn be_validate_snap "libbe_handle_t *hdl" "const char *snap"
1237c2cc9b2SKyle Evans.Pp
124162ec569SKyle Evans.Ft int
1255773e924SKyle Evans.Fn be_exists "libbe_handle_t *hdl" "const char *be_name"
1267c2cc9b2SKyle Evans.Pp
1277c2cc9b2SKyle Evans.Ft int
1287c2cc9b2SKyle Evans.Fn be_export "libbe_handle_t *hdl" "const char *be_name" "int fd"
1297c2cc9b2SKyle Evans.Pp
1307c2cc9b2SKyle Evans.Ft int
1317c2cc9b2SKyle Evans.Fn be_import "libbe_handle_t *hdl" "const char *be_name" "int fd"
1327c2cc9b2SKyle Evans.Pp
1337c2cc9b2SKyle Evans.Ft int
1347c2cc9b2SKyle Evans.Fn be_prop_list_alloc "nvlist_t **prop_list"
1357c2cc9b2SKyle Evans.Pp
1367c2cc9b2SKyle Evans.Ft int
1377c2cc9b2SKyle Evans.Fn be_get_bootenv_props "libbe_handle_t *hdl" "nvlist_t *be_list"
1387c2cc9b2SKyle Evans.Pp
1397c2cc9b2SKyle Evans.Ft int
1407c2cc9b2SKyle Evans.Fn be_get_dataset_props "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *props"
1417c2cc9b2SKyle Evans.Pp
1427c2cc9b2SKyle Evans.Ft int
1437c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *snap_list"
1447c2cc9b2SKyle Evans.Pp
1457c2cc9b2SKyle Evans.Ft void
1467c2cc9b2SKyle Evans.Fn be_prop_list_free "nvlist_t *prop_list"
14728f16a0fSKyle Evans.Sh DESCRIPTION
14828f16a0fSKyle Evans.Nm
14928f16a0fSKyle Evansinterfaces with libzfs to provide a set of functions for various operations
150*f446c948SCheng-Yuan Wuregarding ZFS boot environments, including "deep" boot environments in which
151*f446c948SCheng-Yuan Wua boot environment has child datasets.
15228f16a0fSKyle Evans.Pp
15328f16a0fSKyle EvansA context structure is passed to each function, allowing for a small amount
15428f16a0fSKyle Evansof state to be retained, such as errors from previous operations.
1557c2cc9b2SKyle Evans.Nm
1567c2cc9b2SKyle Evansmay be configured to print the corresponding error message to
1577c2cc9b2SKyle Evans.Dv stderr
1587c2cc9b2SKyle Evanswhen an error is encountered with
1597c2cc9b2SKyle Evans.Fn libbe_print_on_error .
16028f16a0fSKyle Evans.Pp
1617c2cc9b2SKyle EvansAll functions returning an
1627c2cc9b2SKyle Evans.Vt int
1637c2cc9b2SKyle Evansreturn 0 on success, or a
1647c2cc9b2SKyle Evans.Nm
1657c2cc9b2SKyle Evanserrno otherwise as described in
1667c2cc9b2SKyle Evans.Sx DIAGNOSTICS .
16728f16a0fSKyle Evans.Pp
1687c2cc9b2SKyle EvansThe
1697c2cc9b2SKyle Evans.Fn libbe_init
170cc624025SKyle Evansfunction takes an optional BE root and initializes
1717c2cc9b2SKyle Evans.Nm ,
1727c2cc9b2SKyle Evansreturning a
1737c2cc9b2SKyle Evans.Vt "libbe_handle_t *"
1747c2cc9b2SKyle Evanson success, or
1757c2cc9b2SKyle Evans.Dv NULL
1767c2cc9b2SKyle Evanson error.
177cc624025SKyle EvansIf a BE root is supplied,
178cc624025SKyle Evans.Nm
179cc624025SKyle Evanswill only operate out of that pool and BE root.
1807c2cc9b2SKyle EvansAn error may occur if:
1817c2cc9b2SKyle Evans.Bl -column
1827c2cc9b2SKyle Evans.It /boot and / are not on the same filesystem and device,
1837c2cc9b2SKyle Evans.It libzfs fails to initialize,
1847c2cc9b2SKyle Evans.It The system has not been properly booted with a ZFS boot
1857c2cc9b2SKyle Evansenvironment,
186d2a6bc9fSKyle Evans.It Nm
1877c2cc9b2SKyle Evansfails to open the zpool the active boot environment resides on, or
188d2a6bc9fSKyle Evans.It Nm
1897c2cc9b2SKyle Evansfails to locate the boot environment that is currently mounted.
1907c2cc9b2SKyle Evans.El
19128f16a0fSKyle Evans.Pp
1927c2cc9b2SKyle EvansThe
1937c2cc9b2SKyle Evans.Fn libbe_close
1947c2cc9b2SKyle Evansfunction frees all resources previously acquired in
1957c2cc9b2SKyle Evans.Fn libbe_init ,
1967c2cc9b2SKyle Evansinvalidating the handle in the process.
19728f16a0fSKyle Evans.Pp
1987c2cc9b2SKyle EvansThe
1997c2cc9b2SKyle Evans.Fn be_active_name
200cc624025SKyle Evansfunction returns the name of the currently booted boot environment.
201cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe
202cc624025SKyle Evansis operating on!
20384e61219SKyle Evans.Pp
2047c2cc9b2SKyle EvansThe
2057c2cc9b2SKyle Evans.Fn be_active_path
2067c2cc9b2SKyle Evansfunction returns the full path of the currently booted boot environment.
207cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe
208cc624025SKyle Evansis operating on!
20984e61219SKyle Evans.Pp
2107c2cc9b2SKyle EvansThe
2117c2cc9b2SKyle Evans.Fn be_nextboot_name
2127c2cc9b2SKyle Evansfunction returns the name of the boot environment that will be active on reboot.
21328f16a0fSKyle Evans.Pp
2147c2cc9b2SKyle EvansThe
2157c2cc9b2SKyle Evans.Fn be_nextboot_path
2167c2cc9b2SKyle Evansfunction returns the full path of the boot environment that will be
2177c2cc9b2SKyle Evansactive on reboot.
21828f16a0fSKyle Evans.Pp
2197c2cc9b2SKyle EvansThe
2207c2cc9b2SKyle Evans.Fn be_root_path
2217c2cc9b2SKyle Evansfunction returns the boot environment root path.
22228f16a0fSKyle Evans.Pp
2237c2cc9b2SKyle EvansThe
224513bd2fcSKyle Evans.Fn be_snapshot
225513bd2fcSKyle Evansfunction creates a snapshot of
226513bd2fcSKyle Evans.Fa be_name
227513bd2fcSKyle Evansnamed
228513bd2fcSKyle Evans.Fa snap_name .
229513bd2fcSKyle EvansA
230513bd2fcSKyle Evans.Dv NULL
231513bd2fcSKyle Evans.Fa snap_name
232513bd2fcSKyle Evansmay be used, indicating that
233513bd2fcSKyle Evans.Fn be_snaphot
234513bd2fcSKyle Evansshould derive the snapshot name from the current date and time.
235513bd2fcSKyle EvansIf
236513bd2fcSKyle Evans.Fa recursive
237513bd2fcSKyle Evansis set, then
238513bd2fcSKyle Evans.Fn be_snapshot
239513bd2fcSKyle Evanswill recursively snapshot the dataset.
240513bd2fcSKyle EvansIf
241513bd2fcSKyle Evans.Fa result
242513bd2fcSKyle Evansis not
243513bd2fcSKyle Evans.Dv NULL ,
244513bd2fcSKyle Evansthen it will be populated with the final
245513bd2fcSKyle Evans.Dq Fa be_name Ns @ Ns Fa snap_name .
246513bd2fcSKyle Evans.Pp
247513bd2fcSKyle EvansThe
248455d8009SKyle Evans.Fn be_is_auto_snapshot_name
249455d8009SKyle Evansfunction is used to determine if the given snapshot name matches the format that
250455d8009SKyle Evansthe
251455d8009SKyle Evans.Fn be_snapshot
252455d8009SKyle Evansfunction will use by default if it is not given a snapshot name to use.
253455d8009SKyle EvansIt returns
254455d8009SKyle Evans.Dv true
255455d8009SKyle Evansif the name matches the format, and
256455d8009SKyle Evans.Dv false
257455d8009SKyle Evansif it does not.
258455d8009SKyle Evans.Pp
259455d8009SKyle EvansThe
2607c2cc9b2SKyle Evans.Fn be_create
2617c2cc9b2SKyle Evansfunction creates a boot environment with the given name.
262fa30d9edSKyle EvansThe new boot environment will be created from a recursive snapshot of the
263fa30d9edSKyle Evanscurrently booted boot environment.
264fa30d9edSKyle Evans.Pp
265fa30d9edSKyle EvansThe
266fa30d9edSKyle Evans.Fn be_create_depth
267fa30d9edSKyle Evansfunction creates a boot environment with the given name from an existing
268fa30d9edSKyle Evanssnapshot.
269fa30d9edSKyle EvansThe depth parameter specifies the depth of recursion that will be cloned from
270fa30d9edSKyle Evansthe existing snapshot.
271fa30d9edSKyle EvansA depth of '0' is no recursion and '-1' is unlimited (i.e., a recursive boot
272fa30d9edSKyle Evansenvironment).
27328f16a0fSKyle Evans.Pp
2747c2cc9b2SKyle EvansThe
2757c2cc9b2SKyle Evans.Fn be_create_from_existing
2767c2cc9b2SKyle Evansfunction creates a boot environment with the given name from the name of an
2777c2cc9b2SKyle Evansexisting boot environment.
278fa30d9edSKyle EvansA recursive snapshot will be made of the origin boot environment, and the new
279fa30d9edSKyle Evansboot environment will be created from that.
28028f16a0fSKyle Evans.Pp
2817c2cc9b2SKyle EvansThe
2827c2cc9b2SKyle Evans.Fn be_create_from_existing_snap
283fa30d9edSKyle Evansfunction creates a recursive boot environment with the given name from an
284fa30d9edSKyle Evansexisting snapshot.
28528f16a0fSKyle Evans.Pp
2867c2cc9b2SKyle EvansThe
2877c2cc9b2SKyle Evans.Fn be_rename
2888369ba42SKyle Evansfunction renames a boot environment without unmounting it, as if renamed with
2898369ba42SKyle Evansthe
2908369ba42SKyle Evans.Fl u
2918369ba42SKyle Evansargument were passed to
2928369ba42SKyle Evans.Nm zfs
2938369ba42SKyle Evans.Cm rename
2949b1662e6SKyle Evans.Pp
2957c2cc9b2SKyle EvansThe
2967c2cc9b2SKyle Evans.Fn be_activate
2977c2cc9b2SKyle Evansfunction makes a boot environment active on the next boot.
2987c2cc9b2SKyle EvansIf the
2997c2cc9b2SKyle Evans.Fa temporary
3007c2cc9b2SKyle Evansflag is set, then it will be active for the next boot only, as done by
3017c2cc9b2SKyle Evans.Xr zfsbootcfg 8 .
302e307eb94SToomas Soome.Pp
303e307eb94SToomas SoomeThe
304e307eb94SToomas Soome.Fn be_deactivate
305e307eb94SToomas Soomefunction deactivates a boot environment.
306e307eb94SToomas SoomeIf the
307e307eb94SToomas Soome.Fa temporary
308e307eb94SToomas Soomeflag is set, then it will cause removal of boot once configuration, set by
309e307eb94SToomas Soome.Fn be_activate
310e307eb94SToomas Soomefunction or by
311e307eb94SToomas Soome.Xr zfsbootcfg 8 .
312e307eb94SToomas SoomeIf the
313e307eb94SToomas Soome.Fa temporary
314e307eb94SToomas Soomeflag is not set,
315e307eb94SToomas Soome.Fn be_deactivate
316e307eb94SToomas Soomefunction will set zfs
317e307eb94SToomas Soome.Dv canmount
318e307eb94SToomas Soomeproperty to
319e307eb94SToomas Soome.Dv noauto .
32028f16a0fSKyle Evans.Pp
3217c2cc9b2SKyle EvansThe
3227c2cc9b2SKyle Evans.Fn be_destroy
3237c2cc9b2SKyle Evansfunction will recursively destroy the given boot environment.
3247c2cc9b2SKyle EvansIt will not destroy a mounted boot environment unless the
3257c2cc9b2SKyle Evans.Dv BE_DESTROY_FORCE
3267c2cc9b2SKyle Evansoption is set in
3277c2cc9b2SKyle Evans.Fa options .
328446ae812SKyle EvansIf the
329446ae812SKyle Evans.Dv BE_DESTROY_ORIGIN
330446ae812SKyle Evansoption is set in
331446ae812SKyle Evans.Fa options ,
332446ae812SKyle Evansthe
333446ae812SKyle Evans.Fn be_destroy
334446ae812SKyle Evansfunction will destroy the origin snapshot to this boot environment as well.
335843e39ceSKyle Evans.Pp
3367c2cc9b2SKyle EvansThe
3377c2cc9b2SKyle Evans.Fn be_nicenum
3387c2cc9b2SKyle Evansfunction will format
3397c2cc9b2SKyle Evans.Fa name
3407c2cc9b2SKyle Evansin a traditional ZFS humanized format, similar to
3417c2cc9b2SKyle Evans.Xr humanize_number 3 .
3427c2cc9b2SKyle EvansThis function effectively proxies
3437c2cc9b2SKyle Evans.Fn zfs_nicenum
3447c2cc9b2SKyle Evansfrom libzfs.
34528f16a0fSKyle Evans.Pp
3467c2cc9b2SKyle EvansThe
3477c2cc9b2SKyle Evans.Fn be_mount
3487c2cc9b2SKyle Evansfunction will mount the given boot environment.
3497c2cc9b2SKyle EvansIf
3507c2cc9b2SKyle Evans.Fa mountpoint
3517c2cc9b2SKyle Evansis
3527c2cc9b2SKyle Evans.Dv NULL ,
3537c2cc9b2SKyle Evansa mount point will be generated in
3547c2cc9b2SKyle Evans.Pa /tmp
3557c2cc9b2SKyle Evansusing
3567c2cc9b2SKyle Evans.Xr mkdtemp 3 .
3577c2cc9b2SKyle EvansIf
3587c2cc9b2SKyle Evans.Fa result
3597c2cc9b2SKyle Evansis not
3607c2cc9b2SKyle Evans.Dv NULL ,
361a8e44f4dSKyle Evansit should be large enough to accommodate
362a8e44f4dSKyle Evans.Dv BE_MAXPATHLEN
363a8e44f4dSKyle Evansincluding the null terminator.
3647c2cc9b2SKyle Evansthe final mount point will be copied into it.
3657c2cc9b2SKyle EvansSetting the
3667c2cc9b2SKyle Evans.Dv BE_MNT_FORCE
3677c2cc9b2SKyle Evansflag will pass
3687c2cc9b2SKyle Evans.Dv MNT_FORCE
3697c2cc9b2SKyle Evansto the underlying
3707c2cc9b2SKyle Evans.Xr mount 2
3717c2cc9b2SKyle Evanscall.
37228f16a0fSKyle Evans.Pp
3737c2cc9b2SKyle EvansThe
3747c2cc9b2SKyle Evans.Fn be_mounted_at
3757c2cc9b2SKyle Evansfunction will check if there is a boot environment mounted at the given
3767c2cc9b2SKyle Evans.Fa path .
3777c2cc9b2SKyle EvansIf
3787c2cc9b2SKyle Evans.Fa details
3797c2cc9b2SKyle Evansis not
3807c2cc9b2SKyle Evans.Dv NULL ,
3817c2cc9b2SKyle Evansit will be populated with a list of the mounted dataset's properties.
3827c2cc9b2SKyle EvansThis list of properties matches the properties collected by
3837c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
38428f16a0fSKyle Evans.Pp
3857c2cc9b2SKyle EvansThe
3867c2cc9b2SKyle Evans.Fn be_unmount
3877c2cc9b2SKyle Evansfunction will unmount the given boot environment.
3887c2cc9b2SKyle EvansSetting the
3897c2cc9b2SKyle Evans.Dv BE_MNT_FORCE
3907c2cc9b2SKyle Evansflag will pass
3917c2cc9b2SKyle Evans.Dv MNT_FORCE
3927c2cc9b2SKyle Evansto the underlying
3937c2cc9b2SKyle Evans.Xr mount 2
3947c2cc9b2SKyle Evanscall.
39528f16a0fSKyle Evans.Pp
3967c2cc9b2SKyle EvansThe
3977c2cc9b2SKyle Evans.Fn libbe_errno
3987c2cc9b2SKyle Evansfunction returns the
3997c2cc9b2SKyle Evans.Nm
4007c2cc9b2SKyle Evanserrno.
40128f16a0fSKyle Evans.Pp
4027c2cc9b2SKyle EvansThe
4037c2cc9b2SKyle Evans.Fn libbe_error_description
4047c2cc9b2SKyle Evansfunction returns a string description of the currently set
4057c2cc9b2SKyle Evans.Nm
4067c2cc9b2SKyle Evanserrno.
40728f16a0fSKyle Evans.Pp
4087c2cc9b2SKyle EvansThe
4097c2cc9b2SKyle Evans.Fn libbe_print_on_error
4107c2cc9b2SKyle Evansfunction will change whether or not
4117c2cc9b2SKyle Evans.Nm
4127c2cc9b2SKyle Evansprints the description of any encountered error to
4137c2cc9b2SKyle Evans.Dv stderr ,
4147c2cc9b2SKyle Evansbased on
4157c2cc9b2SKyle Evans.Fa doprint .
41628f16a0fSKyle Evans.Pp
4177c2cc9b2SKyle EvansThe
4187c2cc9b2SKyle Evans.Fn be_root_concat
4197c2cc9b2SKyle Evansfunction will concatenate the boot environment root and the given boot
4207c2cc9b2SKyle Evansenvironment name into
4217c2cc9b2SKyle Evans.Fa result .
42228f16a0fSKyle Evans.Pp
4237c2cc9b2SKyle EvansThe
4247c2cc9b2SKyle Evans.Fn be_validate_name
4255b7803a9SKyle Evansfunction will validate the given boot environment name for both length
4265b7803a9SKyle Evansrestrictions as well as valid character restrictions.
4275b7803a9SKyle EvansThis function does not set the internal library error state.
42828f16a0fSKyle Evans.Pp
4297c2cc9b2SKyle EvansThe
4307c2cc9b2SKyle Evans.Fn be_validate_snap
4317c2cc9b2SKyle Evansfunction will validate the given snapshot name.
4327c2cc9b2SKyle EvansThe snapshot must have a valid name, exist, and have a mountpoint of
4337c2cc9b2SKyle Evans.Pa / .
4347c2cc9b2SKyle EvansThis function does not set the internal library error state.
43528f16a0fSKyle Evans.Pp
4367c2cc9b2SKyle EvansThe
4377c2cc9b2SKyle Evans.Fn be_exists
4387c2cc9b2SKyle Evansfunction will check whether the given boot environment exists and has a
4397c2cc9b2SKyle Evansmountpoint of
4407c2cc9b2SKyle Evans.Pa / .
441162ec569SKyle EvansThis function does not set the internal library error state, but will return
442162ec569SKyle Evansthe appropriate error.
443734e362fSKyle Evans.Pp
4447c2cc9b2SKyle EvansThe
4457c2cc9b2SKyle Evans.Fn be_export
4467c2cc9b2SKyle Evansfunction will export the given boot environment to the file specified by
4477c2cc9b2SKyle Evans.Fa fd .
4487c2cc9b2SKyle EvansA snapshot will be created of the boot environment prior to export.
449734e362fSKyle Evans.Pp
4507c2cc9b2SKyle EvansThe
4517c2cc9b2SKyle Evans.Fn be_import
4527c2cc9b2SKyle Evansfunction will import the boot environment in the file specified by
4537c2cc9b2SKyle Evans.Fa fd ,
4547c2cc9b2SKyle Evansand give it the name
4557c2cc9b2SKyle Evans.Fa be_name .
4564146029bSKyle Evans.Pp
4577c2cc9b2SKyle EvansThe
4587c2cc9b2SKyle Evans.Fn be_prop_list_alloc
4597c2cc9b2SKyle Evansfunction allocates a property list suitable for passing to
4607c2cc9b2SKyle Evans.Fn be_get_bootenv_props ,
4617c2cc9b2SKyle Evans.Fn be_get_dataset_props ,
4627c2cc9b2SKyle Evansor
4637c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots .
4647c2cc9b2SKyle EvansIt should be freed later by
4657c2cc9b2SKyle Evans.Fa be_prop_list_free .
46696c5db58SKyle Evans.Pp
4677c2cc9b2SKyle EvansThe
4687c2cc9b2SKyle Evans.Fn be_get_bootenv_props
4697c2cc9b2SKyle Evansfunction will populate
4707c2cc9b2SKyle Evans.Fa be_list
4717c2cc9b2SKyle Evanswith
4727c2cc9b2SKyle Evans.Vt nvpair_t
4737c2cc9b2SKyle Evansof boot environment names paired with an
4747c2cc9b2SKyle Evans.Vt nvlist_t
4757c2cc9b2SKyle Evansof their properties.
4767c2cc9b2SKyle EvansThe following properties are currently collected as appropriate:
4777c2cc9b2SKyle Evans.Bl -column "Returned name"
4787c2cc9b2SKyle Evans.It Sy Returned name Ta Sy Description
4797c2cc9b2SKyle Evans.It dataset Ta -
4807c2cc9b2SKyle Evans.It name Ta Boot environment name
4817c2cc9b2SKyle Evans.It mounted Ta Current mount point
4827c2cc9b2SKyle Evans.It mountpoint Ta Do mountpoint Dc property
4837c2cc9b2SKyle Evans.It origin Ta Do origin Dc property
4847c2cc9b2SKyle Evans.It creation Ta Do creation Dc property
4857c2cc9b2SKyle Evans.It active Ta Currently booted environment
4867c2cc9b2SKyle Evans.It used Ta Literal Do used Dc property
4877c2cc9b2SKyle Evans.It usedds Ta Literal Do usedds Dc property
4887c2cc9b2SKyle Evans.It usedsnap Ta Literal Do usedrefreserv Dc property
4897c2cc9b2SKyle Evans.It referenced Ta Literal Do referenced Dc property
4907c2cc9b2SKyle Evans.It nextboot Ta Active on next boot
4917c2cc9b2SKyle Evans.El
4927c2cc9b2SKyle Evans.Pp
4937c2cc9b2SKyle EvansOnly the
4947c2cc9b2SKyle Evans.Dq dataset ,
4957c2cc9b2SKyle Evans.Dq name ,
4967c2cc9b2SKyle Evans.Dq active ,
4977c2cc9b2SKyle Evansand
4987c2cc9b2SKyle Evans.Dq nextboot
4997c2cc9b2SKyle Evansreturned values will always be present.
5007c2cc9b2SKyle EvansAll other properties may be omitted if not available.
5017c2cc9b2SKyle Evans.Pp
5027c2cc9b2SKyle EvansThe
5037c2cc9b2SKyle Evans.Fn be_get_dataset_props
5047c2cc9b2SKyle Evansfunction will get properties of the specified dataset.
5057c2cc9b2SKyle Evans.Fa props
5067c2cc9b2SKyle Evansis populated directly with a list of the properties as returned by
5077c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
5087c2cc9b2SKyle Evans.Pp
5097c2cc9b2SKyle EvansThe
5107c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots
5117c2cc9b2SKyle Evansfunction will retrieve all snapshots of the given dataset.
5127c2cc9b2SKyle Evans.Fa snap_list
5137c2cc9b2SKyle Evanswill be populated with a list of
5147c2cc9b2SKyle Evans.Vt nvpair_t
5157c2cc9b2SKyle Evansexactly as specified by
5167c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
5177c2cc9b2SKyle Evans.Pp
5187c2cc9b2SKyle EvansThe
5197c2cc9b2SKyle Evans.Fn be_prop_list_free
5207c2cc9b2SKyle Evansfunction will free the property list.
52128f16a0fSKyle Evans.Sh DIAGNOSTICS
522cc58f749SMateusz PiotrowskiUpon error, one of the following values will be returned:
523cc58f749SMateusz Piotrowski.Bl -dash -offset indent -compact
524cc58f749SMateusz Piotrowski.It
525cc58f749SMateusz PiotrowskiBE_ERR_SUCCESS
526cc58f749SMateusz Piotrowski.It
527cc58f749SMateusz PiotrowskiBE_ERR_INVALIDNAME
528cc58f749SMateusz Piotrowski.It
529cc58f749SMateusz PiotrowskiBE_ERR_EXISTS
530cc58f749SMateusz Piotrowski.It
531cc58f749SMateusz PiotrowskiBE_ERR_NOENT
532cc58f749SMateusz Piotrowski.It
533cc58f749SMateusz PiotrowskiBE_ERR_PERMS
534cc58f749SMateusz Piotrowski.It
535cc58f749SMateusz PiotrowskiBE_ERR_DESTROYACT
536cc58f749SMateusz Piotrowski.It
537cc58f749SMateusz PiotrowskiBE_ERR_DESTROYMNT
538cc58f749SMateusz Piotrowski.It
539cc58f749SMateusz PiotrowskiBE_ERR_BADPATH
540cc58f749SMateusz Piotrowski.It
541cc58f749SMateusz PiotrowskiBE_ERR_PATHBUSY
542cc58f749SMateusz Piotrowski.It
543cc58f749SMateusz PiotrowskiBE_ERR_PATHLEN
544cc58f749SMateusz Piotrowski.It
545cc58f749SMateusz PiotrowskiBE_ERR_BADMOUNT
546cc58f749SMateusz Piotrowski.It
547cc58f749SMateusz PiotrowskiBE_ERR_NOORIGIN
548cc58f749SMateusz Piotrowski.It
549cc58f749SMateusz PiotrowskiBE_ERR_MOUNTED
550cc58f749SMateusz Piotrowski.It
551cc58f749SMateusz PiotrowskiBE_ERR_NOMOUNT
552cc58f749SMateusz Piotrowski.It
553cc58f749SMateusz PiotrowskiBE_ERR_ZFSOPEN
554cc58f749SMateusz Piotrowski.It
555cc58f749SMateusz PiotrowskiBE_ERR_ZFSCLONE
556cc58f749SMateusz Piotrowski.It
557cc58f749SMateusz PiotrowskiBE_ERR_IO
558cc58f749SMateusz Piotrowski.It
559cc58f749SMateusz PiotrowskiBE_ERR_NOPOOL
560cc58f749SMateusz Piotrowski.It
561cc58f749SMateusz PiotrowskiBE_ERR_NOMEM
562cc58f749SMateusz Piotrowski.It
56328f16a0fSKyle EvansBE_ERR_UNKNOWN
564be7dd423SKyle Evans.It
565be7dd423SKyle EvansBE_ERR_INVORIGIN
566cc58f749SMateusz Piotrowski.El
56728f16a0fSKyle Evans.Sh SEE ALSO
568f5c8cb4cSMateusz Piotrowski.Xr bectl 8
56928f16a0fSKyle Evans.Sh HISTORY
57028f16a0fSKyle Evans.Nm
57184e61219SKyle Evansand its corresponding command,
57284e61219SKyle Evans.Xr bectl 8 ,
57328f16a0fSKyle Evanswere written as a 2017 Google Summer of Code project with Allan Jude serving
57428f16a0fSKyle Evansas a mentor.
5757c2cc9b2SKyle EvansLater work was done by
5767c2cc9b2SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org .
577