2 .\" SPDX-License-Identifier: BSD-2-Clause
4 .\" Copyright (c) 2017 Kyle Kneitinger
5 .\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .Nd library for creating, destroying and modifying ZFS boot environments
38 .Ft "libbe_handle_t *hdl" Ns
39 .Fn libbe_init "const char *be_root"
42 .Fn libbe_close "libbe_handle_t *hdl"
45 .Fn be_active_name "libbe_handle_t *hdl"
48 .Fn be_active_path "libbe_handle_t *hdl"
51 .Fn be_nextboot_name "libbe_handle_t *hdl"
54 .Fn be_nextboot_path "libbe_handle_t *hdl"
57 .Fn be_root_path "libbe_handle_t *hdl"
60 .Fn be_snapshot "libbe_handle_t *hdl" "const char *be_name" "const char *snap_name" "bool recursive" "char *result"
63 .Fn be_is_auto_snapshot_name "libbe_handle_t *hdl" "const char *snap"
66 .Fn be_create "libbe_handle_t *hdl" "const char *be_name"
69 .Fn be_create_depth "libbe_handle_t *hdl" "const char *be_name" "const char *snap" "int depth"
72 .Fn be_create_from_existing "libbe_handle_t *hdl" "const char *be_name" "const char *be_origin"
75 .Fn be_create_from_existing_snap "libbe_handle_t *hdl" "const char *be_name" "const char *snap"
78 .Fn be_rename "libbe_handle_t *hdl" "const char *be_old" "const char *be_new"
81 .Fn be_activate "libbe_handle_t *hdl" "const char *be_name" "bool temporary"
84 .Fn be_deactivate "libbe_handle_t *hdl" "const char *be_name" "bool temporary"
87 .Fn be_destroy "libbe_handle_t *hdl" "const char *be_name" "int options"
90 .Fn be_nicenum "uint64_t num" "char *buf" "size_t bufsz"
92 .\" TODO: Write up of mount options
94 .\" BE_MNT_FORCE = 1 << 0,
95 .\" BE_MNT_DEEP = 1 << 1,
98 .Fn be_mount "libbe_handle_t *hdl" "const char *be_name" "const char *mntpoint" "int flags" "char *result"
101 .Fn be_mounted_at "libbe_handle_t *hdl" "const char *path" "nvlist_t *details"
104 .Fn be_unmount "libbe_handle_t *hdl" "const char *be_name" "int flags"
107 .Fn libbe_errno "libbe_handle_t *hdl"
110 .Fn libbe_error_description "libbe_handle_t *hdl"
113 .Fn libbe_print_on_error "libbe_handle_t *hdl" "bool doprint"
116 .Fn be_root_concat "libbe_handle_t *hdl" "const char *be_name" "char *result"
119 .Fn be_validate_name "libbe_handle_t *hdl" "const char *be_name"
122 .Fn be_validate_snap "libbe_handle_t *hdl" "const char *snap"
125 .Fn be_exists "libbe_handle_t *hdl" "const char *be_name"
128 .Fn be_export "libbe_handle_t *hdl" "const char *be_name" "int fd"
131 .Fn be_import "libbe_handle_t *hdl" "const char *be_name" "int fd"
134 .Fn be_prop_list_alloc "nvlist_t **prop_list"
137 .Fn be_get_bootenv_props "libbe_handle_t *hdl" "nvlist_t *be_list"
140 .Fn be_get_dataset_props "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *props"
143 .Fn be_get_dataset_snapshots "libbe_handle_t *hdl" "const char *ds_name" "nvlist_t *snap_list"
146 .Fn be_prop_list_free "nvlist_t *prop_list"
149 interfaces with libzfs to provide a set of functions for various operations
150 regarding ZFS boot environments, including "deep" boot environments in which
151 a boot environment has child datasets.
153 A context structure is passed to each function, allowing for a small amount
154 of state to be retained, such as errors from previous operations.
156 may be configured to print the corresponding error message to
158 when an error is encountered with
159 .Fn libbe_print_on_error .
161 All functions returning an
163 return 0 on success, or a
165 errno otherwise as described in
170 function takes an optional BE root and initializes
173 .Vt "libbe_handle_t *"
177 If a BE root is supplied,
179 will only operate out of that pool and BE root.
180 An error may occur if:
182 .It /boot and / are not on the same filesystem and device,
183 .It libzfs fails to initialize,
184 .It The system has not been properly booted with a ZFS boot
187 fails to open the zpool the active boot environment resides on, or
189 fails to locate the boot environment that is currently mounted.
194 function frees all resources previously acquired in
196 invalidating the handle in the process.
200 function returns the name of the currently booted boot environment.
201 This boot environment may not belong to the same BE root as the root libbe
206 function returns the full path of the currently booted boot environment.
207 This boot environment may not belong to the same BE root as the root libbe
212 function returns the name of the boot environment that will be active on reboot.
216 function returns the full path of the boot environment that will be
221 function returns the boot environment root path.
225 function creates a snapshot of
232 may be used, indicating that
234 should derive the snapshot name from the current date and time.
239 will recursively snapshot the dataset.
244 then it will be populated with the final
245 .Dq Fa be_name Ns @ Ns Fa snap_name .
248 .Fn be_is_auto_snapshot_name
249 function is used to determine if the given snapshot name matches the format that
252 function will use by default if it is not given a snapshot name to use.
255 if the name matches the format, and
261 function creates a boot environment with the given name.
262 The new boot environment will be created from a recursive snapshot of the
263 currently booted boot environment.
267 function creates a boot environment with the given name from an existing
269 The depth parameter specifies the depth of recursion that will be cloned from
270 the existing snapshot.
271 A depth of '0' is no recursion and '-1' is unlimited (i.e., a recursive boot
275 .Fn be_create_from_existing
276 function creates a boot environment with the given name from the name of an
277 existing boot environment.
278 A recursive snapshot will be made of the origin boot environment, and the new
279 boot environment will be created from that.
282 .Fn be_create_from_existing_snap
283 function creates a recursive boot environment with the given name from an
288 function renames a boot environment without unmounting it, as if renamed with
291 argument were passed to
297 function makes a boot environment active on the next boot.
300 flag is set, then it will be active for the next boot only, as done by
305 function deactivates a boot environment.
308 flag is set, then it will cause removal of boot once configuration, set by
316 function will set zfs
323 function will recursively destroy the given boot environment.
324 It will not destroy a mounted boot environment unless the
329 .Dv BE_DESTROY_ORIGIN
334 function will destroy the origin snapshot to this boot environment as well.
340 in a traditional ZFS humanized format, similar to
341 .Xr humanize_number 3 .
342 This function effectively proxies
348 function will mount the given boot environment.
353 a mount point will be generated in
361 it should be large enough to accommodate
363 including the null terminator.
364 the final mount point will be copied into it.
375 function will check if there is a boot environment mounted at the given
381 it will be populated with a list of the mounted dataset's properties.
382 This list of properties matches the properties collected by
383 .Fn be_get_bootenv_props .
387 function will unmount the given boot environment.
403 .Fn libbe_error_description
404 function returns a string description of the currently set
409 .Fn libbe_print_on_error
410 function will change whether or not
412 prints the description of any encountered error to
419 function will concatenate the boot environment root and the given boot
420 environment name into
425 function will validate the given boot environment name for both length
426 restrictions as well as valid character restrictions.
427 This function does not set the internal library error state.
431 function will validate the given snapshot name.
432 The snapshot must have a valid name, exist, and have a mountpoint of
434 This function does not set the internal library error state.
438 function will check whether the given boot environment exists and has a
441 This function does not set the internal library error state, but will return
442 the appropriate error.
446 function will export the given boot environment to the file specified by
448 A snapshot will be created of the boot environment prior to export.
452 function will import the boot environment in the file specified by
458 .Fn be_prop_list_alloc
459 function allocates a property list suitable for passing to
460 .Fn be_get_bootenv_props ,
461 .Fn be_get_dataset_props ,
463 .Fn be_get_dataset_snapshots .
464 It should be freed later by
465 .Fa be_prop_list_free .
468 .Fn be_get_bootenv_props
469 function will populate
473 of boot environment names paired with an
476 The following properties are currently collected as appropriate:
477 .Bl -column "Returned name"
478 .It Sy Returned name Ta Sy Description
480 .It name Ta Boot environment name
481 .It mounted Ta Current mount point
482 .It mountpoint Ta Do mountpoint Dc property
483 .It origin Ta Do origin Dc property
484 .It creation Ta Do creation Dc property
485 .It active Ta Currently booted environment
486 .It used Ta Literal Do used Dc property
487 .It usedds Ta Literal Do usedds Dc property
488 .It usedsnap Ta Literal Do usedrefreserv Dc property
489 .It referenced Ta Literal Do referenced Dc property
490 .It nextboot Ta Active on next boot
499 returned values will always be present.
500 All other properties may be omitted if not available.
503 .Fn be_get_dataset_props
504 function will get properties of the specified dataset.
506 is populated directly with a list of the properties as returned by
507 .Fn be_get_bootenv_props .
510 .Fn be_get_dataset_snapshots
511 function will retrieve all snapshots of the given dataset.
513 will be populated with a list of
515 exactly as specified by
516 .Fn be_get_bootenv_props .
519 .Fn be_prop_list_free
520 function will free the property list.
522 Upon error, one of the following values will be returned:
523 .Bl -dash -offset indent -compact
571 and its corresponding command,
573 were written as a 2017 Google Summer of Code project with Allan Jude serving
575 Later work was done by
576 .An Kyle Evans Aq Mt kevans@FreeBSD.org .