zfs_main: create, clone, rename: accept -pp for non-mountable parents

Teach `zfs {create,clone,rename}` to accept a doubled `-p` flag (`-pp`)
to create non-existing ancestor datasets with `canmount=off`.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rob Norris <robn@despairlabs.com>
Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Closes #17000
This commit is contained in:
Ivan Shapovalov
2025-01-28 12:11:18 +04:00
committed by Brian Behlendorf
parent 2f3f1ab1ba
commit 8531621aba
11 changed files with 373 additions and 23 deletions
+23 -2
View File
@@ -1171,6 +1171,22 @@ function datasetnonexists
return 0
}
# Check if the specified dataset property has the expected value or fail
function dataset_has_prop # property expected_value dataset
{
typeset prop=$1
typeset expected=$2
typeset dataset=$3
typeset value=""
value="$(get_prop "$prop" "$dataset")"
[[ "$value" == "$expected" ]] || {
log_note "dataset $dataset: property $prop == $value (!= $expected)"
return 1
}
}
# FreeBSD breaks exports(5) at whitespace and doesn't process escapes
# Solaris just breaks
#
@@ -2629,11 +2645,16 @@ function verify_opt_p_ops
typeset datatype=$2
typeset dataset=$3
typeset newdataset=$4
typeset popt=$5
if [[ $datatype != "fs" && $datatype != "vol" ]]; then
log_fail "$datatype is not supported."
fi
if [[ -z "$popt" ]]; then
popt=-p
fi
# check parameters accordingly
case $ops in
create)
@@ -2671,7 +2692,7 @@ function verify_opt_p_ops
log_mustnot datasetexists $newdataset ${newdataset%/*}
# with -p option, operation should succeed
log_must zfs $ops -p $dataset $newdataset
log_must zfs $ops $popt $dataset $newdataset
block_device_wait
if ! datasetexists $newdataset ; then
@@ -2680,7 +2701,7 @@ function verify_opt_p_ops
# when $ops is create or clone, redo the operation still return zero
if [[ $ops != "rename" ]]; then
log_must zfs $ops -p $dataset $newdataset
log_must zfs $ops $popt $dataset $newdataset
fi
return 0