aboutsummaryrefslogtreecommitdiff
path: root/lib/libbe
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libbe')
-rw-r--r--lib/libbe/Makefile7
-rw-r--r--lib/libbe/Makefile.depend5
-rw-r--r--lib/libbe/be.c142
-rw-r--r--lib/libbe/be.h27
-rw-r--r--lib/libbe/be_access.c69
-rw-r--r--lib/libbe/be_error.c27
-rw-r--r--lib/libbe/be_impl.h28
-rw-r--r--lib/libbe/be_info.c34
-rw-r--r--lib/libbe/libbe.364
-rw-r--r--lib/libbe/tests/Makefile2
-rw-r--r--lib/libbe/tests/Makefile.depend17
-rwxr-xr-xlib/libbe/tests/be_create.sh3
-rw-r--r--lib/libbe/tests/target_prog.c4
13 files changed, 209 insertions, 220 deletions
diff --git a/lib/libbe/Makefile b/lib/libbe/Makefile
index 3c66ea9f1cf0..b04becc38d74 100644
--- a/lib/libbe/Makefile
+++ b/lib/libbe/Makefile
@@ -1,10 +1,8 @@
-# $FreeBSD$
-
SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
+PACKAGE= zfs
LIB= be
SHLIB_MAJOR= 1
SHLIB_MINOR= 0
@@ -59,10 +57,11 @@ CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd
CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include
CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzfs
+CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
-CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -DHAVE_ISSETUGID -DHAVE_STRLCAT -DHAVE_STRLCPY
CFLAGS.be.c= -Wno-cast-qual
CFLAGS.be_access.c= -Wno-cast-qual
CFLAGS.be_error.c= -Wno-cast-qual
diff --git a/lib/libbe/Makefile.depend b/lib/libbe/Makefile.depend
index dba0e55ed69d..a171ee51c662 100644
--- a/lib/libbe/Makefile.depend
+++ b/lib/libbe/Makefile.depend
@@ -1,16 +1,15 @@
-# $FreeBSD$
# Autogenerated - do NOT edit!
DIRDEPS = \
cddl/lib/libnvpair \
+ cddl/lib/libspl \
cddl/lib/libzfs \
- cddl/lib/libzfs_core \
+ cddl/lib/libzfsbootenv \
include \
include/xlocale \
lib/${CSU_DIR} \
lib/libc \
lib/libcompiler_rt \
- lib/msun \
.include <dirdeps.mk>
diff --git a/lib/libbe/be.c b/lib/libbe/be.c
index 13f7a59d5215..613235d5e908 100644
--- a/lib/libbe/be.c
+++ b/lib/libbe/be.c
@@ -1,34 +1,11 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
+/*
* 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.
+ * SPDX-License-Identifier: BSD-2-Clause
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
+#include <sys/module.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/ucred.h>
@@ -119,6 +96,16 @@ libbe_init(const char *root)
lbh = NULL;
poolname = pos = NULL;
+ /*
+ * If the zfs kmod's not loaded then the later libzfs_init() will load
+ * the module for us, but that's not desirable for a couple reasons. If
+ * the module's not loaded, there's no pool imported and we're going to
+ * fail anyways. We also don't really want libbe consumers to have that
+ * kind of side-effect (module loading) in the general case.
+ */
+ if (modfind("zfs") < 0)
+ goto err;
+
if ((lbh = calloc(1, sizeof(libbe_handle_t))) == NULL)
goto err;
@@ -167,6 +154,9 @@ libbe_init(const char *root)
strcmp(altroot, "-") != 0)
lbh->altroot_len = strlen(altroot);
+ (void) lzbe_get_boot_device(zpool_get_name(lbh->active_phandle),
+ &lbh->bootonce);
+
return (lbh);
err:
if (lbh != NULL) {
@@ -191,6 +181,8 @@ libbe_close(libbe_handle_t *lbh)
if (lbh->active_phandle != NULL)
zpool_close(lbh->active_phandle);
libzfs_fini(lbh->lzh);
+
+ free(lbh->bootonce);
free(lbh);
}
@@ -237,7 +229,7 @@ be_dependent_clone_cb(zfs_handle_t *zfs_hdl, void *data)
{
int err;
bool found;
- char *name;
+ const char *name;
struct nvlist *nvl;
struct nvpair *nvp;
struct be_destroy_data *bdd;
@@ -435,6 +427,12 @@ be_destroy_internal(libbe_handle_t *lbh, const char *name, int options,
return (set_error(lbh, BE_ERR_DESTROYMNT));
}
}
+
+ /* Handle destroying bootonce */
+ if (lbh->bootonce != NULL &&
+ strcmp(path, lbh->bootonce) == 0)
+ (void) lzbe_set_boot_device(
+ zpool_get_name(lbh->active_phandle), lzbe_add, NULL);
} else {
/*
* If we're initially destroying a snapshot, origin options do
@@ -661,8 +659,20 @@ be_deep_clone_prop(int prop, void *cb)
dccb = cb;
/* Skip some properties we don't want to touch */
- if (prop == ZFS_PROP_CANMOUNT)
+ switch (prop) {
+ /*
+ * libzfs insists on these being naturally inherited in the
+ * cloning process.
+ */
+ case ZFS_PROP_KEYFORMAT:
+ case ZFS_PROP_KEYLOCATION:
+ case ZFS_PROP_ENCRYPTION:
+ case ZFS_PROP_PBKDF2_ITERS:
+
+ /* FALLTHROUGH */
+ case ZFS_PROP_CANMOUNT: /* Forced by libbe */
return (ZPROP_CONT);
+ }
/* Don't copy readonly properties */
if (zfs_prop_readonly(prop))
@@ -745,11 +755,11 @@ be_clone_cb(zfs_handle_t *ds, void *data)
/* construct the boot environment path from the dataset we're cloning */
if (be_get_path(ldc, dspath, be_path, sizeof(be_path)) != BE_ERR_SUCCESS)
- return (set_error(ldc->lbh, BE_ERR_UNKNOWN));
+ return (BE_ERR_UNKNOWN);
/* the dataset to be created (i.e. the boot environment) already exists */
if (zfs_dataset_exists(ldc->lbh->lzh, be_path, ZFS_TYPE_DATASET))
- return (set_error(ldc->lbh, BE_ERR_EXISTS));
+ return (BE_ERR_EXISTS);
/* no snapshot found for this dataset, silently skip it */
if (!zfs_dataset_exists(ldc->lbh->lzh, snap_path, ZFS_TYPE_SNAPSHOT))
@@ -757,7 +767,7 @@ be_clone_cb(zfs_handle_t *ds, void *data)
if ((snap_hdl =
zfs_open(ldc->lbh->lzh, snap_path, ZFS_TYPE_SNAPSHOT)) == NULL)
- return (set_error(ldc->lbh, BE_ERR_ZFSOPEN));
+ return (BE_ERR_ZFSOPEN);
nvlist_alloc(&props, NV_UNIQUE_NAME, KM_SLEEP);
nvlist_add_string(props, "canmount", "noauto");
@@ -770,7 +780,7 @@ be_clone_cb(zfs_handle_t *ds, void *data)
return (-1);
if ((err = zfs_clone(snap_hdl, be_path, props)) != 0)
- return (set_error(ldc->lbh, BE_ERR_ZFSCLONE));
+ return (BE_ERR_ZFSCLONE);
nvlist_free(props);
zfs_close(snap_hdl);
@@ -781,7 +791,7 @@ be_clone_cb(zfs_handle_t *ds, void *data)
ldc->depth--;
}
- return (set_error(ldc->lbh, err));
+ return (err);
}
/*
@@ -1013,11 +1023,17 @@ be_rename(libbe_handle_t *lbh, const char *old, const char *new)
.nounmount = 1,
};
err = zfs_rename(zfs_hdl, full_new, flags);
+ if (err != 0)
+ goto error;
+
+ /* handle renaming bootonce */
+ if (lbh->bootonce != NULL &&
+ strcmp(full_old, lbh->bootonce) == 0)
+ err = be_activate(lbh, new, true);
+error:
zfs_close(zfs_hdl);
- if (err != 0)
- return (set_error(lbh, BE_ERR_UNKNOWN));
- return (0);
+ return (set_error(lbh, err));
}
@@ -1142,7 +1158,7 @@ be_create_child_noent(libbe_handle_t *lbh, const char *active,
static int
be_create_child_cloned(libbe_handle_t *lbh, const char *active)
{
- char buf[BE_MAXPATHLEN], tmp[BE_MAXPATHLEN];;
+ char buf[BE_MAXPATHLEN], tmp[BE_MAXPATHLEN];
zfs_handle_t *zfs;
int err;
@@ -1255,14 +1271,38 @@ be_deactivate(libbe_handle_t *lbh, const char *ds, bool temporary)
return (0);
}
+static int
+be_zfs_promote_cb(zfs_handle_t *zhp, void *data)
+{
+ char origin[BE_MAXPATHLEN];
+ bool *found_origin = (bool *)data;
+ int err;
+
+ if (zfs_prop_get(zhp, ZFS_PROP_ORIGIN, origin, sizeof(origin),
+ NULL, NULL, 0, true) == 0) {
+ *found_origin = true;
+ err = zfs_promote(zhp);
+ if (err)
+ return (err);
+ }
+
+ return (zfs_iter_filesystems(zhp, be_zfs_promote_cb, data));
+}
+
+static int
+be_zfs_promote(zfs_handle_t *zhp, bool *found_origin)
+{
+ *found_origin = false;
+ return (be_zfs_promote_cb(zhp, (void *)found_origin));
+}
+
int
be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary)
{
char be_path[BE_MAXPATHLEN];
- nvlist_t *dsprops;
- char *origin;
zfs_handle_t *zhp;
int err;
+ bool found_origin;
be_root_concat(lbh, bootenv, be_path);
@@ -1283,24 +1323,20 @@ be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary)
if (err)
return (-1);
- zhp = zfs_open(lbh->lzh, be_path, ZFS_TYPE_FILESYSTEM);
- if (zhp == NULL)
- return (-1);
+ for (;;) {
+ zhp = zfs_open(lbh->lzh, be_path, ZFS_TYPE_FILESYSTEM);
+ if (zhp == NULL)
+ return (-1);
- if (be_prop_list_alloc(&dsprops) != 0)
- return (-1);
+ err = be_zfs_promote(zhp, &found_origin);
- if (be_get_dataset_props(lbh, be_path, dsprops) != 0) {
- nvlist_free(dsprops);
- return (-1);
+ zfs_close(zhp);
+ if (!found_origin)
+ break;
+ if (err)
+ return (err);
}
- if (nvlist_lookup_string(dsprops, "origin", &origin) == 0)
- err = zfs_promote(zhp);
- nvlist_free(dsprops);
-
- zfs_close(zhp);
-
if (err)
return (-1);
}
diff --git a/lib/libbe/be.h b/lib/libbe/be.h
index 87285f2d10af..01ee94fd03ca 100644
--- a/lib/libbe/be.h
+++ b/lib/libbe/be.h
@@ -1,30 +1,7 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
+/*
* 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.
- *
- * $FreeBSD$
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#ifndef _LIBBE_H
diff --git a/lib/libbe/be_access.c b/lib/libbe/be_access.c
index ec966bc85fb7..a7eb6b703cda 100644
--- a/lib/libbe/be_access.c
+++ b/lib/libbe/be_access.c
@@ -1,40 +1,19 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
+/*
* Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
* Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
* Copyright (c) 2019 Wes Maag <wes@jwmaag.org>
*
- * 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.
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/mntent.h>
#include "be.h"
#include "be_impl.h"
+#define LIBBE_MOUNT_PREFIX "be_mount."
+
struct be_mountcheck_info {
const char *path;
char *name;
@@ -166,7 +145,11 @@ be_umount_iter(zfs_handle_t *zfs_hdl, void *data)
if (!zfs_is_mounted(zfs_hdl, &mountpoint)) {
return (0);
}
- free(mountpoint);
+
+ if (info->depth == 0 && info->mountpoint == NULL)
+ info->mountpoint = mountpoint;
+ else
+ free(mountpoint);
if (zfs_unmount(zfs_hdl, NULL, info->mntflags) != 0) {
switch (errno) {
@@ -257,7 +240,17 @@ be_mount(libbe_handle_t *lbh, const char *bootenv, const char *mountpoint,
/* Create mountpoint if it is not specified */
if (mountpoint == NULL) {
- strlcpy(mnt_temp, "/tmp/be_mount.XXXX", sizeof(mnt_temp));
+ const char *tmpdir;
+
+ tmpdir = getenv("TMPDIR");
+ if (tmpdir == NULL)
+ tmpdir = _PATH_TMP;
+
+ if (snprintf(mnt_temp, sizeof(mnt_temp), "%s%s%sXXXX", tmpdir,
+ tmpdir[strlen(tmpdir) - 1] == '/' ? "" : "/",
+ LIBBE_MOUNT_PREFIX) >= (int)sizeof(mnt_temp))
+ return (set_error(lbh, BE_ERR_PATHLEN));
+
if (mkdtemp(mnt_temp) == NULL)
return (set_error(lbh, BE_ERR_IO));
}
@@ -309,10 +302,32 @@ be_unmount(libbe_handle_t *lbh, const char *bootenv, int flags)
info.depth = 0;
if ((err = be_umount_iter(root_hdl, &info)) != 0) {
+ free(__DECONST(char *, info.mountpoint));
zfs_close(root_hdl);
return (err);
}
+ /*
+ * We'll attempt to remove the directory if we created it on a
+ * best-effort basis. rmdir(2) failure will not be reported.
+ */
+ if (info.mountpoint != NULL) {
+ const char *mdir;
+
+ mdir = strrchr(info.mountpoint, '/');
+ if (mdir == NULL)
+ mdir = info.mountpoint;
+ else
+ mdir++;
+
+ if (strncmp(mdir, LIBBE_MOUNT_PREFIX,
+ sizeof(LIBBE_MOUNT_PREFIX) - 1) == 0) {
+ (void)rmdir(info.mountpoint);
+ }
+ }
+
+ free(__DECONST(char *, info.mountpoint));
+
zfs_close(root_hdl);
return (BE_ERR_SUCCESS);
}
diff --git a/lib/libbe/be_error.c b/lib/libbe/be_error.c
index b625092addac..bb1e1ed88c5d 100644
--- a/lib/libbe/be_error.c
+++ b/lib/libbe/be_error.c
@@ -1,33 +1,10 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
+/*
* 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.
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "be.h"
#include "be_impl.h"
diff --git a/lib/libbe/be_impl.h b/lib/libbe/be_impl.h
index 0b0f0db3cb5c..11d1e0ddca28 100644
--- a/lib/libbe/be_impl.h
+++ b/lib/libbe/be_impl.h
@@ -1,30 +1,7 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
+/*
* 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.
- *
- * $FreeBSD$
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#ifndef _LIBBE_IMPL_H
@@ -38,6 +15,7 @@ struct libbe_handle {
char root[BE_MAXPATHLEN];
char rootfs[BE_MAXPATHLEN];
char bootfs[BE_MAXPATHLEN];
+ char *bootonce;
size_t altroot_len;
zpool_handle_t *active_phandle;
libzfs_handle_t *lzh;
diff --git a/lib/libbe/be_info.c b/lib/libbe/be_info.c
index 81f3d46a7208..4b0f611ce421 100644
--- a/lib/libbe/be_info.c
+++ b/lib/libbe/be_info.c
@@ -1,34 +1,11 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
+/*
* Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
* Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
*
- * 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.
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/zfs_context.h>
#include <libzfsbootenv.h>
@@ -183,8 +160,8 @@ prop_list_builder_cb(zfs_handle_t *zfs_hdl, void *data_p)
dataset = zfs_get_name(zfs_hdl);
nvlist_add_string(props, "dataset", dataset);
- if (data->bootonce != NULL &&
- strcmp(dataset, data->bootonce) == 0)
+ if (data->lbh->bootonce != NULL &&
+ strcmp(dataset, data->lbh->bootonce) == 0)
nvlist_add_boolean_value(props, "bootonce", true);
name = strrchr(dataset, '/') + 1;
@@ -254,9 +231,6 @@ be_proplist_update(prop_data_t *data)
ZFS_TYPE_FILESYSTEM)) == NULL)
return (BE_ERR_ZFSOPEN);
- (void) lzbe_get_boot_device(zpool_get_name(data->lbh->active_phandle),
- &data->bootonce);
-
/* XXX TODO: some error checking here */
zfs_iter_filesystems(root_hdl, prop_list_builder_cb, data);
diff --git a/lib/libbe/libbe.3 b/lib/libbe/libbe.3
index 2989aa9daa5c..3b10711dd0f9 100644
--- a/lib/libbe/libbe.3
+++ b/lib/libbe/libbe.3
@@ -1,5 +1,5 @@
.\"
-.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+.\" SPDX-License-Identifier: BSD-2-Clause
.\"
.\" Copyright (c) 2017 Kyle Kneitinger
.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
@@ -25,9 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
-.Dd August 18, 2020
+.Dd April 20, 2025
.Dt LIBBE 3
.Os
.Sh NAME
@@ -149,8 +147,8 @@
.Sh DESCRIPTION
.Nm
interfaces with libzfs to provide a set of functions for various operations
-regarding ZFS boot environments including "deep" boot environments in which
-a boot environments has child datasets.
+regarding ZFS boot environments, including "deep" boot environments in which
+a boot environment has child datasets.
.Pp
A context structure is passed to each function, allowing for a small amount
of state to be retained, such as errors from previous operations.
@@ -180,14 +178,22 @@ If a BE root is supplied,
.Nm
will only operate out of that pool and BE root.
An error may occur if:
-.Bl -column
-.It /boot and / are not on the same filesystem and device,
-.It libzfs fails to initialize,
-.It The system has not been properly booted with a ZFS boot
+.Bl -bullet
+.It
+.Pa /boot
+and
+.Pa /
+are not on the same filesystem and device,
+.It
+libzfs fails to initialize,
+.It
+The system has not been properly booted with a ZFS boot
environment,
-.It Nm
+.It
+.Nm
fails to open the zpool the active boot environment resides on, or
-.It Nm
+.It
+.Nm
fails to locate the boot environment that is currently mounted.
.El
.Pp
@@ -228,9 +234,8 @@ function creates a snapshot of
.Fa be_name
named
.Fa snap_name .
-A
+A value of
.Dv NULL
-.Fa snap_name
may be used, indicating that
.Fn be_snaphot
should derive the snapshot name from the current date and time.
@@ -353,6 +358,10 @@ If
is
.Dv NULL ,
a mount point will be generated in
+.Ev TMPDIR
+or, if
+.Ev TMPDIR
+is not set,
.Pa /tmp
using
.Xr mkdtemp 3 .
@@ -387,6 +396,13 @@ This list of properties matches the properties collected by
The
.Fn be_unmount
function will unmount the given boot environment.
+If the mount point looks like it was created by
+.Fn be_mount ,
+then
+.Fn be_unmount
+will attempt to
+.Xr rmdir 2
+the mountpoint after a successful unmount.
Setting the
.Dv BE_MNT_FORCE
flag will pass
@@ -522,7 +538,7 @@ The
function will free the property list.
.Sh DIAGNOSTICS
Upon error, one of the following values will be returned:
-.Bl -dash -offset indent -compact
+.Bl -bullet -offset indent -compact
.It
BE_ERR_SUCCESS
.It
@@ -569,10 +585,16 @@ BE_ERR_INVORIGIN
.Sh SEE ALSO
.Xr bectl 8
.Sh HISTORY
+.Xr bectl 8
+and
.Nm
-and its corresponding command,
-.Xr bectl 8 ,
-were written as a 2017 Google Summer of Code project with Allan Jude serving
-as a mentor.
-Later work was done by
-.An Kyle Evans Aq Mt kevans@FreeBSD.org .
+were written by
+.An Kyle Kneitinger (kneitinger) Aq Mt kyle@kneit.in
+as a 2017 Google Summer of Code project, with
+.An Allan Jude (allanjude) Aq Mt allanjude@freebsd.org
+as mentor.
+.Sh AUTHORS
+Kyle Kneitinger, mentored as above.
+.Pp
+Post-GSoC changes were written by
+.An Kyle Evans (kevans) Aq Mt kevans@freebsd.org .
diff --git a/lib/libbe/tests/Makefile b/lib/libbe/tests/Makefile
index fc5691bbe6f8..20a4e1ddfeb7 100644
--- a/lib/libbe/tests/Makefile
+++ b/lib/libbe/tests/Makefile
@@ -1,5 +1,3 @@
-# $FreeBSD$
-
PACKAGE= tests
ATF_TESTS_SH+= be_create
diff --git a/lib/libbe/tests/Makefile.depend b/lib/libbe/tests/Makefile.depend
new file mode 100644
index 000000000000..670634e1722a
--- /dev/null
+++ b/lib/libbe/tests/Makefile.depend
@@ -0,0 +1,17 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ cddl/lib/libnvpair \
+ cddl/lib/libspl \
+ cddl/lib/libzfs \
+ lib/${CSU_DIR} \
+ lib/libbe \
+ lib/libc \
+ lib/libcompiler_rt \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libbe/tests/be_create.sh b/lib/libbe/tests/be_create.sh
index ef64628a4de8..e1342368995d 100755
--- a/lib/libbe/tests/be_create.sh
+++ b/lib/libbe/tests/be_create.sh
@@ -1,5 +1,5 @@
#
-# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2019 Rob Wing
#
@@ -24,7 +24,6 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $FreeBSD$
# The code for the following tests was copied from the
# bectl tests found in src/sbin/bectl/tests, modified as needed.
diff --git a/lib/libbe/tests/target_prog.c b/lib/libbe/tests/target_prog.c
index f51768a253da..4c79d1a30714 100644
--- a/lib/libbe/tests/target_prog.c
+++ b/lib/libbe/tests/target_prog.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2019 Rob Wing
*
@@ -26,8 +26,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <be.h>
/*