2018-08-07 13:46:06 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
2018-07-24 13:17:40 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2018-08-07 14:02:41 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
2018-07-24 13:17:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBBE_H
|
|
|
|
#define _LIBBE_H
|
|
|
|
|
2018-07-25 14:30:47 +00:00
|
|
|
#include <libnvpair.h>
|
2018-07-24 13:17:40 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#define BE_MAXPATHLEN 512
|
|
|
|
|
|
|
|
typedef struct libbe_handle libbe_handle_t;
|
|
|
|
|
|
|
|
typedef enum be_error {
|
|
|
|
BE_ERR_SUCCESS = 0, /* No error */
|
|
|
|
BE_ERR_INVALIDNAME, /* invalid boot env name */
|
|
|
|
BE_ERR_EXISTS, /* boot env name already taken */
|
|
|
|
BE_ERR_NOENT, /* boot env doesn't exist */
|
|
|
|
BE_ERR_PERMS, /* insufficient permissions */
|
|
|
|
BE_ERR_DESTROYACT, /* cannot destroy active boot env */
|
|
|
|
BE_ERR_DESTROYMNT, /* destroying a mounted be requires force */
|
2018-08-07 03:25:28 +00:00
|
|
|
BE_ERR_BADPATH, /* path not suitable for operation */
|
|
|
|
BE_ERR_PATHBUSY, /* requested path is busy */
|
2018-07-24 13:17:40 +00:00
|
|
|
BE_ERR_PATHLEN, /* provided name exceeds maximum length limit */
|
2018-09-01 02:22:26 +00:00
|
|
|
BE_ERR_BADMOUNT, /* mountpoint is not '/' */
|
2018-07-24 13:17:40 +00:00
|
|
|
BE_ERR_NOORIGIN, /* could not open snapshot's origin */
|
|
|
|
BE_ERR_MOUNTED, /* boot environment is already mounted */
|
|
|
|
BE_ERR_NOMOUNT, /* boot environment is not mounted */
|
|
|
|
BE_ERR_ZFSOPEN, /* calling zfs_open() failed */
|
|
|
|
BE_ERR_ZFSCLONE, /* error when calling zfs_clone to create be */
|
2018-08-07 03:25:28 +00:00
|
|
|
BE_ERR_IO, /* error when doing some I/O operation */
|
2018-08-08 03:25:10 +00:00
|
|
|
BE_ERR_NOPOOL, /* operation not supported on this pool */
|
2018-08-10 21:23:56 +00:00
|
|
|
BE_ERR_NOMEM, /* insufficient memory */
|
2018-07-24 13:17:40 +00:00
|
|
|
BE_ERR_UNKNOWN, /* unknown error */
|
2019-02-13 04:19:08 +00:00
|
|
|
BE_ERR_INVORIGIN, /* invalid origin */
|
2020-01-02 18:46:33 +00:00
|
|
|
BE_ERR_HASCLONES, /* snapshot has clones */
|
2018-07-24 13:17:40 +00:00
|
|
|
} be_error_t;
|
|
|
|
|
|
|
|
|
|
|
|
/* Library handling functions: be.c */
|
2018-11-19 02:12:08 +00:00
|
|
|
libbe_handle_t *libbe_init(const char *root);
|
2018-07-24 13:17:40 +00:00
|
|
|
void libbe_close(libbe_handle_t *);
|
|
|
|
|
|
|
|
/* Bootenv information functions: be_info.c */
|
|
|
|
const char *be_active_name(libbe_handle_t *);
|
|
|
|
const char *be_active_path(libbe_handle_t *);
|
2018-07-25 14:45:00 +00:00
|
|
|
const char *be_nextboot_name(libbe_handle_t *);
|
|
|
|
const char *be_nextboot_path(libbe_handle_t *);
|
2018-07-24 13:17:40 +00:00
|
|
|
const char *be_root_path(libbe_handle_t *);
|
|
|
|
|
2018-07-25 14:30:47 +00:00
|
|
|
int be_get_bootenv_props(libbe_handle_t *, nvlist_t *);
|
2018-08-05 04:40:13 +00:00
|
|
|
int be_get_dataset_props(libbe_handle_t *, const char *, nvlist_t *);
|
2018-08-05 19:38:56 +00:00
|
|
|
int be_get_dataset_snapshots(libbe_handle_t *, const char *, nvlist_t *);
|
2018-07-25 16:00:48 +00:00
|
|
|
int be_prop_list_alloc(nvlist_t **be_list);
|
2018-07-25 15:14:35 +00:00
|
|
|
void be_prop_list_free(nvlist_t *be_list);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
2018-08-10 04:01:40 +00:00
|
|
|
int be_activate(libbe_handle_t *, const char *, bool);
|
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
2020-09-21 09:01:10 +00:00
|
|
|
int be_deactivate(libbe_handle_t *, const char *, bool);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
2019-10-16 14:43:05 +00:00
|
|
|
bool be_is_auto_snapshot_name(libbe_handle_t *, const char *);
|
|
|
|
|
2018-07-24 13:17:40 +00:00
|
|
|
/* Bootenv creation functions */
|
2018-08-10 04:01:40 +00:00
|
|
|
int be_create(libbe_handle_t *, const char *);
|
2019-04-22 13:43:38 +00:00
|
|
|
int be_create_depth(libbe_handle_t *, const char *, const char *, int);
|
2018-07-25 15:14:35 +00:00
|
|
|
int be_create_from_existing(libbe_handle_t *, const char *, const char *);
|
|
|
|
int be_create_from_existing_snap(libbe_handle_t *, const char *, const char *);
|
|
|
|
int be_snapshot(libbe_handle_t *, const char *, const char *, bool, char *);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
|
|
|
/* Bootenv manipulation functions */
|
2018-08-10 04:01:40 +00:00
|
|
|
int be_rename(libbe_handle_t *, const char *, const char *);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
|
|
|
/* Bootenv removal functions */
|
|
|
|
|
|
|
|
typedef enum {
|
2019-02-10 21:19:09 +00:00
|
|
|
BE_DESTROY_FORCE = 1 << 0,
|
|
|
|
BE_DESTROY_ORIGIN = 1 << 1,
|
2019-10-16 14:43:05 +00:00
|
|
|
BE_DESTROY_AUTOORIGIN = 1 << 2,
|
2018-07-24 13:17:40 +00:00
|
|
|
} be_destroy_opt_t;
|
|
|
|
|
2018-08-10 04:01:40 +00:00
|
|
|
int be_destroy(libbe_handle_t *, const char *, int);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
|
|
|
/* Bootenv mounting functions: be_access.c */
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BE_MNT_FORCE = 1 << 0,
|
2019-02-10 21:19:09 +00:00
|
|
|
BE_MNT_DEEP = 1 << 1,
|
2018-07-24 13:17:40 +00:00
|
|
|
} be_mount_opt_t;
|
|
|
|
|
2020-10-18 23:32:47 +00:00
|
|
|
int be_mount(libbe_handle_t *, const char *, const char *, int, char *);
|
|
|
|
int be_unmount(libbe_handle_t *, const char *, int);
|
2018-07-26 03:13:07 +00:00
|
|
|
int be_mounted_at(libbe_handle_t *, const char *path, nvlist_t *);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
|
|
|
/* Error related functions: be_error.c */
|
|
|
|
int libbe_errno(libbe_handle_t *);
|
|
|
|
const char *libbe_error_description(libbe_handle_t *);
|
|
|
|
void libbe_print_on_error(libbe_handle_t *, bool);
|
|
|
|
|
|
|
|
/* Utility Functions */
|
2018-07-25 15:14:35 +00:00
|
|
|
int be_root_concat(libbe_handle_t *, const char *, char *);
|
|
|
|
int be_validate_name(libbe_handle_t * __unused, const char *);
|
|
|
|
int be_validate_snap(libbe_handle_t *, const char *);
|
2020-10-18 23:32:47 +00:00
|
|
|
int be_exists(libbe_handle_t *, const char *);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
2018-08-10 04:01:40 +00:00
|
|
|
int be_export(libbe_handle_t *, const char *, int fd);
|
|
|
|
int be_import(libbe_handle_t *, const char *, int fd);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
2018-08-11 01:02:27 +00:00
|
|
|
#if SOON
|
2018-08-10 04:01:40 +00:00
|
|
|
int be_add_child(libbe_handle_t *, const char *, bool);
|
2018-08-11 01:02:27 +00:00
|
|
|
#endif
|
2018-08-05 04:40:13 +00:00
|
|
|
void be_nicenum(uint64_t num, char *buf, size_t buflen);
|
2018-07-24 13:17:40 +00:00
|
|
|
|
|
|
|
#endif /* _LIBBE_H */
|