diff options
author | Richard Elling <[email protected]> | 2019-06-05 16:13:57 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-06-10 09:19:32 -0700 |
commit | 2ff615b2bf2bcbff90fe7b79de0eceee365a7a5a (patch) | |
tree | a0e29dd5605b712c059e4e4549d72f274d8faae9 /tests/zfs-tests/include | |
parent | 215e4fe4d2d38a095ea99c537f395e00d51d3995 (diff) |
Fix logic error in setpartition function
Reviewed by: John Kennedy <[email protected]>
Reviewed-by: Giuseppe Di Natale <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Elling <[email protected]>
Closes #8839
Diffstat (limited to 'tests/zfs-tests/include')
-rw-r--r-- | tests/zfs-tests/include/libtest.shlib | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 57d0880cc..b3893c2c3 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -861,7 +861,8 @@ function zero_partitions #<whole_disk_name> # best to retire this interface and replace it with something more flexible. # At the moment a best effort is made. # -function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk_name> +# arguments: <slice_num> <slice_start> <size_plus_units> <whole_disk_name> +function set_partition { typeset -i slicenum=$1 typeset start=$2 @@ -872,6 +873,7 @@ function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk if [[ -z $size || -z $disk ]]; then log_fail "The size or disk name is unspecified." fi + [[ -n $DEV_DSKDIR ]] && disk=$DEV_DSKDIR/$disk typeset size_mb=${size%%[mMgG]} size_mb=${size_mb%%[mMgG][bB]} @@ -881,10 +883,10 @@ function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk # Create GPT partition table when setting slice 0 or # when the device doesn't already contain a GPT label. - parted $DEV_DSKDIR/$disk -s -- print 1 >/dev/null + parted $disk -s -- print 1 >/dev/null typeset ret_val=$? if [[ $slicenum -eq 0 || $ret_val -ne 0 ]]; then - parted $DEV_DSKDIR/$disk -s -- mklabel gpt + parted $disk -s -- mklabel gpt if [[ $? -ne 0 ]]; then log_note "Failed to create GPT partition table on $disk" return 1 @@ -899,20 +901,21 @@ function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk # Determine the cylinder size for the device and using # that calculate the end offset in cylinders. typeset -i cly_size_kb=0 - cly_size_kb=$(parted -m $DEV_DSKDIR/$disk -s -- \ + cly_size_kb=$(parted -m $disk -s -- \ unit cyl print | head -3 | tail -1 | \ awk -F '[:k.]' '{print $4}') ((end = (size_mb * 1024 / cly_size_kb) + start)) - parted $DEV_DSKDIR/$disk -s -- \ + parted $disk -s -- \ mkpart part$slicenum ${start}cyl ${end}cyl - if [[ $? -ne 0 ]]; then + typeset ret_val=$? + if [[ $ret_val -ne 0 ]]; then log_note "Failed to create partition $slicenum on $disk" return 1 fi - blockdev --rereadpt $DEV_DSKDIR/$disk 2>/dev/null - block_device_wait + blockdev --rereadpt $disk 2>/dev/null + block_device_wait $disk else if [[ -z $slicenum || -z $size || -z $disk ]]; then log_fail "The slice, size or disk name is unspecified." @@ -932,9 +935,10 @@ function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk echo "q" >> $format_file format -e -s -d $disk -f $format_file + typeset ret_val=$? + rm -f $format_file fi - typeset ret_val=$? rm -f $format_file if [[ $ret_val -ne 0 ]]; then log_note "Unable to format $disk slice $slicenum to $size" |