xref: /freebsd/lib/libbe/libbe.3 (revision c7c3ef8949021696029fb73a513678578a9f8a46)
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.\"
2804610d66SGraham Perrin.Dd April 9, 2024
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
150f446c948SCheng-Yuan Wuregarding ZFS boot environments, including "deep" boot environments in which
151f446c948SCheng-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:
181ad99fea9SDag-Erling Smørgrav.Bl -bullet
182ad99fea9SDag-Erling Smørgrav.It
183ad99fea9SDag-Erling Smørgrav.Pa /boot
184ad99fea9SDag-Erling Smørgravand
185ad99fea9SDag-Erling Smørgrav.Pa /
186ad99fea9SDag-Erling Smørgravare not on the same filesystem and device,
187ad99fea9SDag-Erling Smørgrav.It
188ad99fea9SDag-Erling Smørgravlibzfs fails to initialize,
189ad99fea9SDag-Erling Smørgrav.It
190ad99fea9SDag-Erling SmørgravThe system has not been properly booted with a ZFS boot
1917c2cc9b2SKyle Evansenvironment,
192ad99fea9SDag-Erling Smørgrav.It
193ad99fea9SDag-Erling Smørgrav.Nm
1947c2cc9b2SKyle Evansfails to open the zpool the active boot environment resides on, or
195ad99fea9SDag-Erling Smørgrav.It
196ad99fea9SDag-Erling Smørgrav.Nm
1977c2cc9b2SKyle Evansfails to locate the boot environment that is currently mounted.
1987c2cc9b2SKyle Evans.El
19928f16a0fSKyle Evans.Pp
2007c2cc9b2SKyle EvansThe
2017c2cc9b2SKyle Evans.Fn libbe_close
2027c2cc9b2SKyle Evansfunction frees all resources previously acquired in
2037c2cc9b2SKyle Evans.Fn libbe_init ,
2047c2cc9b2SKyle Evansinvalidating the handle in the process.
20528f16a0fSKyle Evans.Pp
2067c2cc9b2SKyle EvansThe
2077c2cc9b2SKyle Evans.Fn be_active_name
208cc624025SKyle Evansfunction returns the name of the currently booted boot environment.
209cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe
210cc624025SKyle Evansis operating on!
21184e61219SKyle Evans.Pp
2127c2cc9b2SKyle EvansThe
2137c2cc9b2SKyle Evans.Fn be_active_path
2147c2cc9b2SKyle Evansfunction returns the full path of the currently booted boot environment.
215cc624025SKyle EvansThis boot environment may not belong to the same BE root as the root libbe
216cc624025SKyle Evansis operating on!
21784e61219SKyle Evans.Pp
2187c2cc9b2SKyle EvansThe
2197c2cc9b2SKyle Evans.Fn be_nextboot_name
2207c2cc9b2SKyle Evansfunction returns the name of the boot environment that will be active on reboot.
22128f16a0fSKyle Evans.Pp
2227c2cc9b2SKyle EvansThe
2237c2cc9b2SKyle Evans.Fn be_nextboot_path
2247c2cc9b2SKyle Evansfunction returns the full path of the boot environment that will be
2257c2cc9b2SKyle Evansactive on reboot.
22628f16a0fSKyle Evans.Pp
2277c2cc9b2SKyle EvansThe
2287c2cc9b2SKyle Evans.Fn be_root_path
2297c2cc9b2SKyle Evansfunction returns the boot environment root path.
23028f16a0fSKyle Evans.Pp
2317c2cc9b2SKyle EvansThe
232513bd2fcSKyle Evans.Fn be_snapshot
233513bd2fcSKyle Evansfunction creates a snapshot of
234513bd2fcSKyle Evans.Fa be_name
235513bd2fcSKyle Evansnamed
236513bd2fcSKyle Evans.Fa snap_name .
237ad99fea9SDag-Erling SmørgravA value of
238513bd2fcSKyle Evans.Dv NULL
239513bd2fcSKyle Evansmay be used, indicating that
240513bd2fcSKyle Evans.Fn be_snaphot
241513bd2fcSKyle Evansshould derive the snapshot name from the current date and time.
242513bd2fcSKyle EvansIf
243513bd2fcSKyle Evans.Fa recursive
244513bd2fcSKyle Evansis set, then
245513bd2fcSKyle Evans.Fn be_snapshot
246513bd2fcSKyle Evanswill recursively snapshot the dataset.
247513bd2fcSKyle EvansIf
248513bd2fcSKyle Evans.Fa result
249513bd2fcSKyle Evansis not
250513bd2fcSKyle Evans.Dv NULL ,
251513bd2fcSKyle Evansthen it will be populated with the final
252513bd2fcSKyle Evans.Dq Fa be_name Ns @ Ns Fa snap_name .
253513bd2fcSKyle Evans.Pp
254513bd2fcSKyle EvansThe
255455d8009SKyle Evans.Fn be_is_auto_snapshot_name
256455d8009SKyle Evansfunction is used to determine if the given snapshot name matches the format that
257455d8009SKyle Evansthe
258455d8009SKyle Evans.Fn be_snapshot
259455d8009SKyle Evansfunction will use by default if it is not given a snapshot name to use.
260455d8009SKyle EvansIt returns
261455d8009SKyle Evans.Dv true
262455d8009SKyle Evansif the name matches the format, and
263455d8009SKyle Evans.Dv false
264455d8009SKyle Evansif it does not.
265455d8009SKyle Evans.Pp
266455d8009SKyle EvansThe
2677c2cc9b2SKyle Evans.Fn be_create
2687c2cc9b2SKyle Evansfunction creates a boot environment with the given name.
269fa30d9edSKyle EvansThe new boot environment will be created from a recursive snapshot of the
270fa30d9edSKyle Evanscurrently booted boot environment.
271fa30d9edSKyle Evans.Pp
272fa30d9edSKyle EvansThe
273fa30d9edSKyle Evans.Fn be_create_depth
274fa30d9edSKyle Evansfunction creates a boot environment with the given name from an existing
275fa30d9edSKyle Evanssnapshot.
276fa30d9edSKyle EvansThe depth parameter specifies the depth of recursion that will be cloned from
277fa30d9edSKyle Evansthe existing snapshot.
278fa30d9edSKyle EvansA depth of '0' is no recursion and '-1' is unlimited (i.e., a recursive boot
279fa30d9edSKyle Evansenvironment).
28028f16a0fSKyle Evans.Pp
2817c2cc9b2SKyle EvansThe
2827c2cc9b2SKyle Evans.Fn be_create_from_existing
2837c2cc9b2SKyle Evansfunction creates a boot environment with the given name from the name of an
2847c2cc9b2SKyle Evansexisting boot environment.
285fa30d9edSKyle EvansA recursive snapshot will be made of the origin boot environment, and the new
286fa30d9edSKyle Evansboot environment will be created from that.
28728f16a0fSKyle Evans.Pp
2887c2cc9b2SKyle EvansThe
2897c2cc9b2SKyle Evans.Fn be_create_from_existing_snap
290fa30d9edSKyle Evansfunction creates a recursive boot environment with the given name from an
291fa30d9edSKyle Evansexisting snapshot.
29228f16a0fSKyle Evans.Pp
2937c2cc9b2SKyle EvansThe
2947c2cc9b2SKyle Evans.Fn be_rename
2958369ba42SKyle Evansfunction renames a boot environment without unmounting it, as if renamed with
2968369ba42SKyle Evansthe
2978369ba42SKyle Evans.Fl u
2988369ba42SKyle Evansargument were passed to
2998369ba42SKyle Evans.Nm zfs
3008369ba42SKyle Evans.Cm rename
3019b1662e6SKyle Evans.Pp
3027c2cc9b2SKyle EvansThe
3037c2cc9b2SKyle Evans.Fn be_activate
3047c2cc9b2SKyle Evansfunction makes a boot environment active on the next boot.
3057c2cc9b2SKyle EvansIf the
3067c2cc9b2SKyle Evans.Fa temporary
3077c2cc9b2SKyle Evansflag is set, then it will be active for the next boot only, as done by
3087c2cc9b2SKyle Evans.Xr zfsbootcfg 8 .
309e307eb94SToomas Soome.Pp
310e307eb94SToomas SoomeThe
311e307eb94SToomas Soome.Fn be_deactivate
312e307eb94SToomas Soomefunction deactivates a boot environment.
313e307eb94SToomas SoomeIf the
314e307eb94SToomas Soome.Fa temporary
315e307eb94SToomas Soomeflag is set, then it will cause removal of boot once configuration, set by
316e307eb94SToomas Soome.Fn be_activate
317e307eb94SToomas Soomefunction or by
318e307eb94SToomas Soome.Xr zfsbootcfg 8 .
319e307eb94SToomas SoomeIf the
320e307eb94SToomas Soome.Fa temporary
321e307eb94SToomas Soomeflag is not set,
322e307eb94SToomas Soome.Fn be_deactivate
323e307eb94SToomas Soomefunction will set zfs
324e307eb94SToomas Soome.Dv canmount
325e307eb94SToomas Soomeproperty to
326e307eb94SToomas Soome.Dv noauto .
32728f16a0fSKyle Evans.Pp
3287c2cc9b2SKyle EvansThe
3297c2cc9b2SKyle Evans.Fn be_destroy
3307c2cc9b2SKyle Evansfunction will recursively destroy the given boot environment.
3317c2cc9b2SKyle EvansIt will not destroy a mounted boot environment unless the
3327c2cc9b2SKyle Evans.Dv BE_DESTROY_FORCE
3337c2cc9b2SKyle Evansoption is set in
3347c2cc9b2SKyle Evans.Fa options .
335446ae812SKyle EvansIf the
336446ae812SKyle Evans.Dv BE_DESTROY_ORIGIN
337446ae812SKyle Evansoption is set in
338446ae812SKyle Evans.Fa options ,
339446ae812SKyle Evansthe
340446ae812SKyle Evans.Fn be_destroy
341446ae812SKyle Evansfunction will destroy the origin snapshot to this boot environment as well.
342843e39ceSKyle Evans.Pp
3437c2cc9b2SKyle EvansThe
3447c2cc9b2SKyle Evans.Fn be_nicenum
3457c2cc9b2SKyle Evansfunction will format
3467c2cc9b2SKyle Evans.Fa name
3477c2cc9b2SKyle Evansin a traditional ZFS humanized format, similar to
3487c2cc9b2SKyle Evans.Xr humanize_number 3 .
3497c2cc9b2SKyle EvansThis function effectively proxies
3507c2cc9b2SKyle Evans.Fn zfs_nicenum
3517c2cc9b2SKyle Evansfrom libzfs.
35228f16a0fSKyle Evans.Pp
3537c2cc9b2SKyle EvansThe
3547c2cc9b2SKyle Evans.Fn be_mount
3557c2cc9b2SKyle Evansfunction will mount the given boot environment.
3567c2cc9b2SKyle EvansIf
3577c2cc9b2SKyle Evans.Fa mountpoint
3587c2cc9b2SKyle Evansis
3597c2cc9b2SKyle Evans.Dv NULL ,
3607c2cc9b2SKyle Evansa mount point will be generated in
3617c2cc9b2SKyle Evans.Pa /tmp
3627c2cc9b2SKyle Evansusing
3637c2cc9b2SKyle Evans.Xr mkdtemp 3 .
3647c2cc9b2SKyle EvansIf
3657c2cc9b2SKyle Evans.Fa result
3667c2cc9b2SKyle Evansis not
3677c2cc9b2SKyle Evans.Dv NULL ,
368a8e44f4dSKyle Evansit should be large enough to accommodate
369a8e44f4dSKyle Evans.Dv BE_MAXPATHLEN
370a8e44f4dSKyle Evansincluding the null terminator.
3717c2cc9b2SKyle Evansthe final mount point will be copied into it.
3727c2cc9b2SKyle EvansSetting the
3737c2cc9b2SKyle Evans.Dv BE_MNT_FORCE
3747c2cc9b2SKyle Evansflag will pass
3757c2cc9b2SKyle Evans.Dv MNT_FORCE
3767c2cc9b2SKyle Evansto the underlying
3777c2cc9b2SKyle Evans.Xr mount 2
3787c2cc9b2SKyle Evanscall.
37928f16a0fSKyle Evans.Pp
3807c2cc9b2SKyle EvansThe
3817c2cc9b2SKyle Evans.Fn be_mounted_at
3827c2cc9b2SKyle Evansfunction will check if there is a boot environment mounted at the given
3837c2cc9b2SKyle Evans.Fa path .
3847c2cc9b2SKyle EvansIf
3857c2cc9b2SKyle Evans.Fa details
3867c2cc9b2SKyle Evansis not
3877c2cc9b2SKyle Evans.Dv NULL ,
3887c2cc9b2SKyle Evansit will be populated with a list of the mounted dataset's properties.
3897c2cc9b2SKyle EvansThis list of properties matches the properties collected by
3907c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
39128f16a0fSKyle Evans.Pp
3927c2cc9b2SKyle EvansThe
3937c2cc9b2SKyle Evans.Fn be_unmount
3947c2cc9b2SKyle Evansfunction will unmount the given boot environment.
3957c2cc9b2SKyle EvansSetting the
3967c2cc9b2SKyle Evans.Dv BE_MNT_FORCE
3977c2cc9b2SKyle Evansflag will pass
3987c2cc9b2SKyle Evans.Dv MNT_FORCE
3997c2cc9b2SKyle Evansto the underlying
4007c2cc9b2SKyle Evans.Xr mount 2
4017c2cc9b2SKyle Evanscall.
40228f16a0fSKyle Evans.Pp
4037c2cc9b2SKyle EvansThe
4047c2cc9b2SKyle Evans.Fn libbe_errno
4057c2cc9b2SKyle Evansfunction returns the
4067c2cc9b2SKyle Evans.Nm
4077c2cc9b2SKyle Evanserrno.
40828f16a0fSKyle Evans.Pp
4097c2cc9b2SKyle EvansThe
4107c2cc9b2SKyle Evans.Fn libbe_error_description
4117c2cc9b2SKyle Evansfunction returns a string description of the currently set
4127c2cc9b2SKyle Evans.Nm
4137c2cc9b2SKyle Evanserrno.
41428f16a0fSKyle Evans.Pp
4157c2cc9b2SKyle EvansThe
4167c2cc9b2SKyle Evans.Fn libbe_print_on_error
4177c2cc9b2SKyle Evansfunction will change whether or not
4187c2cc9b2SKyle Evans.Nm
4197c2cc9b2SKyle Evansprints the description of any encountered error to
4207c2cc9b2SKyle Evans.Dv stderr ,
4217c2cc9b2SKyle Evansbased on
4227c2cc9b2SKyle Evans.Fa doprint .
42328f16a0fSKyle Evans.Pp
4247c2cc9b2SKyle EvansThe
4257c2cc9b2SKyle Evans.Fn be_root_concat
4267c2cc9b2SKyle Evansfunction will concatenate the boot environment root and the given boot
4277c2cc9b2SKyle Evansenvironment name into
4287c2cc9b2SKyle Evans.Fa result .
42928f16a0fSKyle Evans.Pp
4307c2cc9b2SKyle EvansThe
4317c2cc9b2SKyle Evans.Fn be_validate_name
4325b7803a9SKyle Evansfunction will validate the given boot environment name for both length
4335b7803a9SKyle Evansrestrictions as well as valid character restrictions.
4345b7803a9SKyle EvansThis function does not set the internal library error state.
43528f16a0fSKyle Evans.Pp
4367c2cc9b2SKyle EvansThe
4377c2cc9b2SKyle Evans.Fn be_validate_snap
4387c2cc9b2SKyle Evansfunction will validate the given snapshot name.
4397c2cc9b2SKyle EvansThe snapshot must have a valid name, exist, and have a mountpoint of
4407c2cc9b2SKyle Evans.Pa / .
4417c2cc9b2SKyle EvansThis function does not set the internal library error state.
44228f16a0fSKyle Evans.Pp
4437c2cc9b2SKyle EvansThe
4447c2cc9b2SKyle Evans.Fn be_exists
4457c2cc9b2SKyle Evansfunction will check whether the given boot environment exists and has a
4467c2cc9b2SKyle Evansmountpoint of
4477c2cc9b2SKyle Evans.Pa / .
448162ec569SKyle EvansThis function does not set the internal library error state, but will return
449162ec569SKyle Evansthe appropriate error.
450734e362fSKyle Evans.Pp
4517c2cc9b2SKyle EvansThe
4527c2cc9b2SKyle Evans.Fn be_export
4537c2cc9b2SKyle Evansfunction will export the given boot environment to the file specified by
4547c2cc9b2SKyle Evans.Fa fd .
4557c2cc9b2SKyle EvansA snapshot will be created of the boot environment prior to export.
456734e362fSKyle Evans.Pp
4577c2cc9b2SKyle EvansThe
4587c2cc9b2SKyle Evans.Fn be_import
4597c2cc9b2SKyle Evansfunction will import the boot environment in the file specified by
4607c2cc9b2SKyle Evans.Fa fd ,
4617c2cc9b2SKyle Evansand give it the name
4627c2cc9b2SKyle Evans.Fa be_name .
4634146029bSKyle Evans.Pp
4647c2cc9b2SKyle EvansThe
4657c2cc9b2SKyle Evans.Fn be_prop_list_alloc
4667c2cc9b2SKyle Evansfunction allocates a property list suitable for passing to
4677c2cc9b2SKyle Evans.Fn be_get_bootenv_props ,
4687c2cc9b2SKyle Evans.Fn be_get_dataset_props ,
4697c2cc9b2SKyle Evansor
4707c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots .
4717c2cc9b2SKyle EvansIt should be freed later by
4727c2cc9b2SKyle Evans.Fa be_prop_list_free .
47396c5db58SKyle Evans.Pp
4747c2cc9b2SKyle EvansThe
4757c2cc9b2SKyle Evans.Fn be_get_bootenv_props
4767c2cc9b2SKyle Evansfunction will populate
4777c2cc9b2SKyle Evans.Fa be_list
4787c2cc9b2SKyle Evanswith
4797c2cc9b2SKyle Evans.Vt nvpair_t
4807c2cc9b2SKyle Evansof boot environment names paired with an
4817c2cc9b2SKyle Evans.Vt nvlist_t
4827c2cc9b2SKyle Evansof their properties.
4837c2cc9b2SKyle EvansThe following properties are currently collected as appropriate:
4847c2cc9b2SKyle Evans.Bl -column "Returned name"
4857c2cc9b2SKyle Evans.It Sy Returned name Ta Sy Description
4867c2cc9b2SKyle Evans.It dataset Ta -
4877c2cc9b2SKyle Evans.It name Ta Boot environment name
4887c2cc9b2SKyle Evans.It mounted Ta Current mount point
4897c2cc9b2SKyle Evans.It mountpoint Ta Do mountpoint Dc property
4907c2cc9b2SKyle Evans.It origin Ta Do origin Dc property
4917c2cc9b2SKyle Evans.It creation Ta Do creation Dc property
4927c2cc9b2SKyle Evans.It active Ta Currently booted environment
4937c2cc9b2SKyle Evans.It used Ta Literal Do used Dc property
4947c2cc9b2SKyle Evans.It usedds Ta Literal Do usedds Dc property
4957c2cc9b2SKyle Evans.It usedsnap Ta Literal Do usedrefreserv Dc property
4967c2cc9b2SKyle Evans.It referenced Ta Literal Do referenced Dc property
4977c2cc9b2SKyle Evans.It nextboot Ta Active on next boot
4987c2cc9b2SKyle Evans.El
4997c2cc9b2SKyle Evans.Pp
5007c2cc9b2SKyle EvansOnly the
5017c2cc9b2SKyle Evans.Dq dataset ,
5027c2cc9b2SKyle Evans.Dq name ,
5037c2cc9b2SKyle Evans.Dq active ,
5047c2cc9b2SKyle Evansand
5057c2cc9b2SKyle Evans.Dq nextboot
5067c2cc9b2SKyle Evansreturned values will always be present.
5077c2cc9b2SKyle EvansAll other properties may be omitted if not available.
5087c2cc9b2SKyle Evans.Pp
5097c2cc9b2SKyle EvansThe
5107c2cc9b2SKyle Evans.Fn be_get_dataset_props
5117c2cc9b2SKyle Evansfunction will get properties of the specified dataset.
5127c2cc9b2SKyle Evans.Fa props
5137c2cc9b2SKyle Evansis populated directly with a list of the properties as returned by
5147c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
5157c2cc9b2SKyle Evans.Pp
5167c2cc9b2SKyle EvansThe
5177c2cc9b2SKyle Evans.Fn be_get_dataset_snapshots
5187c2cc9b2SKyle Evansfunction will retrieve all snapshots of the given dataset.
5197c2cc9b2SKyle Evans.Fa snap_list
5207c2cc9b2SKyle Evanswill be populated with a list of
5217c2cc9b2SKyle Evans.Vt nvpair_t
5227c2cc9b2SKyle Evansexactly as specified by
5237c2cc9b2SKyle Evans.Fn be_get_bootenv_props .
5247c2cc9b2SKyle Evans.Pp
5257c2cc9b2SKyle EvansThe
5267c2cc9b2SKyle Evans.Fn be_prop_list_free
5277c2cc9b2SKyle Evansfunction will free the property list.
52828f16a0fSKyle Evans.Sh DIAGNOSTICS
529cc58f749SMateusz PiotrowskiUpon error, one of the following values will be returned:
530ad99fea9SDag-Erling Smørgrav.Bl -bullet -offset indent -compact
531cc58f749SMateusz Piotrowski.It
532cc58f749SMateusz PiotrowskiBE_ERR_SUCCESS
533cc58f749SMateusz Piotrowski.It
534cc58f749SMateusz PiotrowskiBE_ERR_INVALIDNAME
535cc58f749SMateusz Piotrowski.It
536cc58f749SMateusz PiotrowskiBE_ERR_EXISTS
537cc58f749SMateusz Piotrowski.It
538cc58f749SMateusz PiotrowskiBE_ERR_NOENT
539cc58f749SMateusz Piotrowski.It
540cc58f749SMateusz PiotrowskiBE_ERR_PERMS
541cc58f749SMateusz Piotrowski.It
542cc58f749SMateusz PiotrowskiBE_ERR_DESTROYACT
543cc58f749SMateusz Piotrowski.It
544cc58f749SMateusz PiotrowskiBE_ERR_DESTROYMNT
545cc58f749SMateusz Piotrowski.It
546cc58f749SMateusz PiotrowskiBE_ERR_BADPATH
547cc58f749SMateusz Piotrowski.It
548cc58f749SMateusz PiotrowskiBE_ERR_PATHBUSY
549cc58f749SMateusz Piotrowski.It
550cc58f749SMateusz PiotrowskiBE_ERR_PATHLEN
551cc58f749SMateusz Piotrowski.It
552cc58f749SMateusz PiotrowskiBE_ERR_BADMOUNT
553cc58f749SMateusz Piotrowski.It
554cc58f749SMateusz PiotrowskiBE_ERR_NOORIGIN
555cc58f749SMateusz Piotrowski.It
556cc58f749SMateusz PiotrowskiBE_ERR_MOUNTED
557cc58f749SMateusz Piotrowski.It
558cc58f749SMateusz PiotrowskiBE_ERR_NOMOUNT
559cc58f749SMateusz Piotrowski.It
560cc58f749SMateusz PiotrowskiBE_ERR_ZFSOPEN
561cc58f749SMateusz Piotrowski.It
562cc58f749SMateusz PiotrowskiBE_ERR_ZFSCLONE
563cc58f749SMateusz Piotrowski.It
564cc58f749SMateusz PiotrowskiBE_ERR_IO
565cc58f749SMateusz Piotrowski.It
566cc58f749SMateusz PiotrowskiBE_ERR_NOPOOL
567cc58f749SMateusz Piotrowski.It
568cc58f749SMateusz PiotrowskiBE_ERR_NOMEM
569cc58f749SMateusz Piotrowski.It
57028f16a0fSKyle EvansBE_ERR_UNKNOWN
571be7dd423SKyle Evans.It
572be7dd423SKyle EvansBE_ERR_INVORIGIN
573cc58f749SMateusz Piotrowski.El
57428f16a0fSKyle Evans.Sh SEE ALSO
575f5c8cb4cSMateusz Piotrowski.Xr bectl 8
57628f16a0fSKyle Evans.Sh HISTORY
577*763f5da9SGraham Perrin.Xr bectl 8
57804610d66SGraham Perrinand
579*763f5da9SGraham Perrin.Nm
58004610d66SGraham Perrinwere written by
58104610d66SGraham Perrin.An Kyle Kneitinger (kneitinger) Aq Mt kyle@kneit.in
58204610d66SGraham Perrinas a 2017 Google Summer of Code project, with
58304610d66SGraham Perrin.An Allan Jude (allanjude) Aq Mt allanjude@freebsd.org
58404610d66SGraham Perrinas mentor.
58504610d66SGraham Perrin.Sh AUTHORS
58604610d66SGraham PerrinKyle Kneitinger, mentored as above.
58704610d66SGraham Perrin.Pp
58804610d66SGraham PerrinPost-GSoC changes were written by
58904610d66SGraham Perrin.An Kyle Evans (kevans) Aq Mt kevans@freebsd.org .
590