Skip to content

Commit

Permalink
ZFS Tests: Simplified the implementation and corrected errors in the …
Browse files Browse the repository at this point in the history
…new tests

- zfs_mount_all_002_pos.ksh
- zfs_unmount_all_002_pos.ksh

Signed-off-by: QORTEC <[email protected]>
  • Loading branch information
QORTEC committed Sep 28, 2023
1 parent e93a38c commit 2cc23a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,8 @@ set -A fs "$TESTFS" "$TESTFS1"
set -A ctr "" "$TESTCTR" "$TESTCTR/$TESTCTR1" "$TESTCTR1"
set -A vol "$TESTVOL" "$TESTVOL1"

# Test the mounted state of fs0
typeset fs0=${fs[0]}

# Ensure that fs1 remains unmounted
set -A fs1
typeset -i fs1_index=0
for element in ${fs[@]}; do
if [[ "$element" != "$fs0" ]]; then
fs1[fs1_index++]="$element"
fi
done

fs0=$TESTPOOL/$fs0
# Test the mounted state of root dataset (testpool/testctr)
typeset mnt=$TESTCTR

function setup_all
{
Expand Down Expand Up @@ -145,8 +134,8 @@ function cleanup_all

#
# This function takes a single true/false argument:
# - true: it verifies that the fs0 file system is mounted.
# - false: it verifies that the fs0 file system is unmounted.
# - true: it verifies that the $mnt file system is mounted.
# - false: it verifies that the $mnt file system is unmounted.
#
# In both scenarios, it ensures that the file systems in fs1 remain unmounted.
#
Expand All @@ -157,14 +146,14 @@ function verify_related
typeset path
typeset logfunc

if $1; then
logfunc=log_must
else
logfunc=log_mustnot
fi

while (( i < ${#ctr[*]} )); do

if $1 && { [[ ${ctr[i]} == $mnt ]] || [[ ${ctr[i]} == $mnt/* ]] }; then
logfunc=log_must
else
logfunc=log_mustnot
fi

path=$TESTPOOL
[[ -n ${ctr[i]} ]] && \
path=$path/${ctr[i]}
Expand All @@ -177,13 +166,9 @@ function verify_related
done
fi

# Verify that filesystems in fs0 are mounted according to $1
$logfunc mounted "$path/$fs0"

# Verify that filesystems in fs1 remain unmounted
j=0
while (( j < ${#fs1[*]} )); do
log_mustnot mounted "$path/${fs1[j]}"
while (( j < ${#fs[*]} )); do
$logfunc mounted "$path/${fs[j]}"
((j = j + 1))
done

Expand All @@ -210,13 +195,13 @@ unset __ZFS_POOL_RESTRICT
verify_related false

export __ZFS_POOL_RESTRICT="$TESTPOOL"
log_must zfs $mountall $fs0
log_must zfs $mountall $TESTPOOL/$mnt
unset __ZFS_POOL_RESTRICT

verify_related true

log_note "Verify that 'zfs $mountcmd' will display " \
"all ZFS filesystems related to '$fs0' are currently mounted."
"all ZFS filesystems related to '$TESTPOOL/$mnt' are currently mounted."

verify_mount_display

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,8 @@ set -A fs "$TESTFS" "$TESTFS1"
set -A ctr "" "$TESTCTR" "$TESTCTR1" "$TESTCTR/$TESTCTR1"
set -A vol "$TESTVOL" "$TESTVOL1"

# Test the mounted state of fs0
typeset fs0=${fs[0]}

# Ensure that fs1 remains mounted
set -A fs1
typeset -i fs1_index=0
for element in ${fs[@]}; do
if [[ "$element" != "$fs0" ]]; then
fs1[fs1_index++]="$element"
fi
done
fs0=$TESTPOOL/$fs0
# Test the mounted state of root dataset (testpool/testctr)
typeset mnt=$TESTCTR

function setup_all
{
Expand Down Expand Up @@ -141,8 +131,8 @@ function cleanup_all
}

#
# This function verifies that the file systems in $fs0 are unmounted.
# Next, it also ensures that the file systems in $fs1 remain mounted.
# This function verifies that the file systems in $mnt are unmounted.
# Next, it ensures that all other file systems in remain mounted.
#
function verify_related
{
Expand All @@ -152,6 +142,12 @@ function verify_related

while (( i < ${#ctr[*]} )); do

if { [[ ${ctr[i]} == $mnt ]] || [[ ${ctr[i]} == $mnt/* ]] }; then
logfunc=log_must
else
logfunc=log_mustnot
fi

path=$TESTPOOL
[[ -n ${ctr[i]} ]] && \
path=$path/${ctr[i]}
Expand All @@ -164,17 +160,13 @@ function verify_related
done
fi

# Verify that filesystems in fs0 are unmounted
log_must unmounted "$path/$fs0"

# Verify that filesystems in fs1 remain mounted
j=0
while (( j < ${#fs1[*]} )); do
log_mustnot unmounted "$path/${fs1[j]}"
while (( j < ${#fs[*]} )); do
$logfunc unmounted "$path/${fs[j]}"
((j = j + 1))
done

log_must unmounted "$path"
$logfunc unmounted "$path"

((i = i + 1))
done
Expand All @@ -197,12 +189,12 @@ for opt in "-a" "-fa"; do
unset __ZFS_POOL_RESTRICT

export __ZFS_POOL_RESTRICT="$TESTPOOL"
log_must zfs unmount $opt $fs0
log_must zfs unmount $opt $TESTPOOL/$mnt
unset __ZFS_POOL_RESTRICT

log_must verify_related
log_note "Verify that 'zfs $mountcmd' will display " \
"all ZFS filesystems related to '$fs0' are currently unmounted."
"all ZFS filesystems related to '$TESTPOOL/$mnt' are currently unmounted."
log_must verify_mount_display

done
Expand Down

0 comments on commit 2cc23a4

Please sign in to comment.