aboutsummaryrefslogtreecommitdiff
path: root/lib/libbe
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libbe')
-rw-r--r--lib/libbe/be.c64
-rw-r--r--lib/libbe/be.h1
-rw-r--r--lib/libbe/libbe.39
-rw-r--r--lib/libbe/tests/Makefile2
-rwxr-xr-xlib/libbe/tests/be_create.sh9
-rw-r--r--lib/libbe/tests/target_prog.c11
6 files changed, 76 insertions, 20 deletions
diff --git a/lib/libbe/be.c b/lib/libbe/be.c
index 4a7c2e43b2c1..2147435ebf9b 100644
--- a/lib/libbe/be.c
+++ b/lib/libbe/be.c
@@ -891,6 +891,54 @@ be_create_from_existing(libbe_handle_t *lbh, const char *bename, const char *old
return (set_error(lbh, err));
}
+/*
+ * Create a zfs dataset and map the return to libbe error.
+ */
+static int
+be_zfs_create(libzfs_handle_t *lzh, const char *buf, zfs_type_t t,
+ nvlist_t *props)
+{
+ int err;
+
+ if ((err = zfs_create(lzh, buf, t, props)) != 0) {
+ switch (err) {
+ case EZFS_EXISTS:
+ return (BE_ERR_EXISTS);
+ case EZFS_NOENT:
+ return (BE_ERR_NOENT);
+ case EZFS_BADTYPE:
+ case EZFS_BADVERSION:
+ return (BE_ERR_NOPOOL);
+ case EZFS_BADPROP:
+ default:
+ /* We set something up wrong, probably... */
+ return (BE_ERR_UNKNOWN);
+ }
+ }
+
+ return (BE_ERR_SUCCESS);
+}
+
+
+/*
+ * Create an empty boot environment.
+ */
+int
+be_create_empty(libbe_handle_t *lbh, const char *bename)
+{
+ char buf[BE_MAXPATHLEN];
+ int err;
+
+ if ((err = be_validate_name(lbh, bename)) != 0)
+ return (set_error(lbh, err));
+
+ if ((err = be_root_concat(lbh, bename, buf)) != 0)
+ return (set_error(lbh, err));
+
+ err = be_zfs_create(lbh->lzh, buf, ZFS_TYPE_FILESYSTEM, NULL);
+ return (set_error(lbh, err));
+}
+
/*
* Verifies that a snapshot has a valid name, exists, and has a mountpoint of
@@ -1118,21 +1166,9 @@ be_create_child_noent(libbe_handle_t *lbh, const char *active,
nvlist_add_string(props, "mountpoint", child_path);
/* Create */
- if ((err = zfs_create(lbh->lzh, active, ZFS_TYPE_DATASET,
+ if ((err = be_zfs_create(lbh->lzh, active, ZFS_TYPE_DATASET,
props)) != 0) {
- switch (err) {
- case EZFS_EXISTS:
- return (set_error(lbh, BE_ERR_EXISTS));
- case EZFS_NOENT:
- return (set_error(lbh, BE_ERR_NOENT));
- case EZFS_BADTYPE:
- case EZFS_BADVERSION:
- return (set_error(lbh, BE_ERR_NOPOOL));
- case EZFS_BADPROP:
- default:
- /* We set something up wrong, probably... */
- return (set_error(lbh, BE_ERR_UNKNOWN));
- }
+ return (set_error(lbh, err));
}
nvlist_free(props);
diff --git a/lib/libbe/be.h b/lib/libbe/be.h
index d3f47c0604fe..18be067c4410 100644
--- a/lib/libbe/be.h
+++ b/lib/libbe/be.h
@@ -65,6 +65,7 @@ bool be_is_auto_snapshot_name(libbe_handle_t *, const char *);
/* Bootenv creation functions */
int be_create(libbe_handle_t *, const char *);
int be_create_depth(libbe_handle_t *, const char *, const char *, int);
+int be_create_empty(libbe_handle_t *, const char *);
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 *);
diff --git a/lib/libbe/libbe.3 b/lib/libbe/libbe.3
index 4331713e9227..f65da5ef1090 100644
--- a/lib/libbe/libbe.3
+++ b/lib/libbe/libbe.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 11, 2025
+.Dd February 4, 2026
.Dt LIBBE 3
.Os
.Sh NAME
@@ -69,6 +69,9 @@
.Fn be_create_depth "libbe_handle_t *hdl" "const char *be_name" "const char *snap" "int depth"
.Pp
.Ft int
+.Fn be_create_empty "libbe_handle_t *hdl" "const char *be_name"
+.Pp
+.Ft int
.Fn be_create_from_existing "libbe_handle_t *hdl" "const char *be_name" "const char *be_origin"
.Pp
.Ft int
@@ -282,6 +285,10 @@ A depth of '0' is no recursion and '-1' is unlimited (i.e., a recursive boot
environment).
.Pp
The
+.Fn be_create_empty
+function creates an empty boot environment with the given name.
+.Pp
+The
.Fn be_create_from_existing
function creates a boot environment with the given name from the name of an
existing boot environment.
diff --git a/lib/libbe/tests/Makefile b/lib/libbe/tests/Makefile
index dfe49bd7f3e5..57e33b75aabc 100644
--- a/lib/libbe/tests/Makefile
+++ b/lib/libbe/tests/Makefile
@@ -20,6 +20,6 @@ CFLAGS+= -I${ZFSTOP}/lib/libspl/include/os/freebsd
CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
CFLAGS+= -include ${ZFSTOP}/include/os/freebsd/spl/sys/ccompile.h
-CFLAGS+= -DHAVE_ISSETUGID
+CFLAGS+= -DHAVE_ISSETUGID -DHAVE_STRLCAT -DHAVE_STRLCPY
.include <bsd.test.mk>
diff --git a/lib/libbe/tests/be_create.sh b/lib/libbe/tests/be_create.sh
index e1342368995d..e39ce1a0ccb4 100755
--- a/lib/libbe/tests/be_create.sh
+++ b/lib/libbe/tests/be_create.sh
@@ -174,6 +174,15 @@ libbe_create_body()
# the child dataset should exist
atf_check -o not-empty \
zfs list "${zpool}/ROOT/relative-snap/usr"
+
+ # test empty BE creation.
+ atf_check $prog "${zpool}/ROOT" \
+ empty \
+ ignored \
+ 0
+ # the dataset should exist
+ atf_check -o not-empty \
+ zfs list "${zpool}/ROOT/empty"
}
libbe_create_cleanup()
diff --git a/lib/libbe/tests/target_prog.c b/lib/libbe/tests/target_prog.c
index 4c79d1a30714..83ef68ab2890 100644
--- a/lib/libbe/tests/target_prog.c
+++ b/lib/libbe/tests/target_prog.c
@@ -27,6 +27,7 @@
#include <sys/cdefs.h>
#include <be.h>
+#include <string.h>
/*
* argv[1] = root boot environment (e.g. zroot/ROOT),
@@ -36,15 +37,17 @@
*/
int main(int argc, char *argv[]) {
- libbe_handle_t *lbh;
+ libbe_handle_t *lbh;
if (argc != 5)
- return -1;
+ return (-1);
- if ((lbh = libbe_init(argv[1])) == NULL)
- return -1;
+ if ((lbh = libbe_init(argv[1])) == NULL)
+ return (-1);
libbe_print_on_error(lbh, true);
+ if (strcmp(argv[2], "empty") == 0)
+ return (be_create_empty(lbh, argv[2]));
return (be_create_depth(lbh, argv[2], argv[3], atoi(argv[4])));
}