Skip to content

Commit

Permalink
libbe: recursively promote deep BE datasets
Browse files Browse the repository at this point in the history
beadm will recursively promote deep BE datasets. In order to match the
beadm behavior, we need to recursively iterate over child filesystems
and promote them along the way.

This patch further refines the work from D40903, completing the fix for
promotion.

Reviewed by:	kevans, rew
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D40972
  • Loading branch information
rcmcdonald91 authored and kevans91 committed Jul 17, 2023
1 parent 89f361f commit 4b426cf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
40 changes: 31 additions & 9 deletions lib/libbe/be.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,12 +1266,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], origin[BE_MAXPATHLEN];
char be_path[BE_MAXPATHLEN];
zfs_handle_t *zhp;
int err;
bool found_origin;

be_root_concat(lbh, bootenv, be_path);

Expand All @@ -1297,19 +1323,15 @@ be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary)
if (zhp == NULL)
return (-1);

if (zfs_prop_get(zhp, ZFS_PROP_ORIGIN, origin, sizeof(origin),
NULL, NULL, 0, 1) != 0) {
zfs_close(zhp);
break;
}
err = be_zfs_promote(zhp, &found_origin);

err = zfs_promote(zhp);
zfs_close(zhp);
if (err)
if (!found_origin)
break;
if (err)
return (err);
}


if (err)
return (-1);
}
Expand Down
12 changes: 5 additions & 7 deletions sbin/bectl/tests/bectl_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ bectl_jail_cleanup()
atf_test_case bectl_promotion cleanup
bectl_promotion_head()
{

atf_set "descr" "Check bectl promotion upon activation"
atf_set "require.user" root
}
Expand All @@ -550,7 +549,7 @@ bectl_promotion_body()
mount=${cwd}/mnt
root=${mount}/root

bectl_create_setup ${zpool} ${disk} ${mount}
bectl_create_deep_setup ${zpool} ${disk} ${mount}
atf_check mkdir -p ${root}

# Sleeps interspersed to workaround some naming quirks; notably,
Expand All @@ -560,23 +559,22 @@ bectl_promotion_body()
# with the same name, and the promotion will fail.
atf_check bectl -r ${zpool}/ROOT rename default A
sleep 1
atf_check bectl -r ${zpool}/ROOT create -e A B
atf_check bectl -r ${zpool}/ROOT create -r -e A B
sleep 1
atf_check bectl -r ${zpool}/ROOT create -e B C
atf_check bectl -r ${zpool}/ROOT create -r -e B C

# C should be a clone of B to start with
atf_check -o not-inline:"-" zfs list -H -o origin ${zpool}/ROOT/C
atf_check -o not-inline:"-" zfs list -Hr -o origin ${zpool}/ROOT/C

# Activating it should then promote it all the way out of clone-hood.
# This entails two promotes internally, as the first would promote it to
# a snapshot of A before finally promoting it the second time out of
# clone status.
atf_check -o not-empty bectl -r ${zpool}/ROOT activate C
atf_check -o inline:"-\n" zfs list -H -o origin ${zpool}/ROOT/C
atf_check -o inline:"-\n-\n" zfs list -Hr -o origin ${zpool}/ROOT/C
}
bectl_promotion_cleanup()
{

bectl_cleanup $(get_zpool_name)
}

Expand Down

0 comments on commit 4b426cf

Please sign in to comment.