diff options
Diffstat (limited to 'lib/libbe/be.c')
-rw-r--r-- | lib/libbe/be.c | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/lib/libbe/be.c b/lib/libbe/be.c index 38e5e44abb53..613235d5e908 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -1,31 +1,9 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * +/* * 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> #include <sys/param.h> #include <sys/module.h> #include <sys/mount.h> @@ -176,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) { @@ -200,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); } @@ -444,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 @@ -670,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)) @@ -1022,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)); } @@ -1151,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; |