diff --git a/lib/libbe/be.c b/lib/libbe/be.c --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -1266,12 +1266,27 @@ return (0); } +static int +be_zfs_promote(zfs_handle_t *zhp, void *data) +{ + char origin[BE_MAXPATHLEN]; + int *origin_count = (int *) data; + + if (zfs_prop_get(zhp, ZFS_PROP_ORIGIN, origin, sizeof(origin), + NULL, NULL, 0, 1) == 0) { + (*origin_count)++; + return (zfs_promote(zhp)); + } + + return (zfs_iter_filesystems(zhp, be_zfs_promote, origin_count)); +} + 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; + int err, origin_count; be_root_concat(lbh, bootenv, be_path); @@ -1297,19 +1312,16 @@ 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; - } + origin_count = 0; + err = be_zfs_promote(zhp, &origin_count); - err = zfs_promote(zhp); zfs_close(zhp); - if (err) + if (origin_count == 0) break; + if (err) + return (err); } - if (err) return (-1); } diff --git a/sbin/bectl/tests/bectl_test.sh b/sbin/bectl/tests/bectl_test.sh --- a/sbin/bectl/tests/bectl_test.sh +++ b/sbin/bectl/tests/bectl_test.sh @@ -528,7 +528,6 @@ atf_test_case bectl_promotion cleanup bectl_promotion_head() { - atf_set "descr" "Check bectl promotion upon activation" atf_set "require.user" root } @@ -550,7 +549,7 @@ 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, @@ -560,23 +559,22 @@ # 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) }