mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Add zfs_nicebytes() to print human-readable sizes
* Add zfs_nicebytes() to print human-readable sizes Some 'zfs', 'zpool' and 'zdb' output strings can be confusing to the user when no units are specified. This add a new zfs_nicenum_format "ZFS_NICENUM_BYTES" used to print bytes in their human-readable form. Additionally, update some test cases to use machine-parsable 'zfs get'. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: loli10K <ezomori.nozomu@gmail.com> Closes #2414 Closes #3185 Closes #3594 Closes #6032
This commit is contained in:
@@ -58,11 +58,7 @@ function get_used_prop
|
||||
typeset ds=$1
|
||||
typeset used
|
||||
|
||||
used=`zfs list -H -o used $ds`
|
||||
used=${used%[m|M]}
|
||||
if [[ $used == *K ]]; then
|
||||
used=0
|
||||
fi
|
||||
used=`zfs list -H -p -o used $ds`
|
||||
echo $used
|
||||
}
|
||||
|
||||
@@ -79,7 +75,7 @@ function check_used
|
||||
typeset -i cfactor
|
||||
typeset -i fsize=${FILESIZE%[m|M]}
|
||||
|
||||
((used = ${charged_spc%[m|M]}))
|
||||
((used = $charged_spc / 1024 / 1024))
|
||||
((cfactor = used / fsize))
|
||||
if ((cfactor != expected_cfactor)); then
|
||||
log_fail "The space is not charged correctly while setting" \
|
||||
|
||||
@@ -88,20 +88,22 @@ else
|
||||
fi
|
||||
for val in 1 2 3; do
|
||||
blks=`ls -ls /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
|
||||
(( used = blks * $blksize / (1024 * 1024) ))
|
||||
(( used = blks * $blksize )) # bytes
|
||||
check_used $used $val
|
||||
done
|
||||
|
||||
log_note "Verify df(1M) can corectly display the space charged."
|
||||
for val in 1 2 3; do
|
||||
used=`df -F zfs -h /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \
|
||||
used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \
|
||||
| awk '{print $3}'`
|
||||
(( used = used * 1024 )) # kb -> bytes
|
||||
check_used $used $val
|
||||
done
|
||||
|
||||
log_note "Verify du(1) can correctly display the space charged."
|
||||
for val in 1 2 3; do
|
||||
used=`du -h /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
|
||||
used=`du -k /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
|
||||
(( used = used * 1024 )) # kb -> bytes
|
||||
check_used $used $val
|
||||
done
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
|
||||
#
|
||||
|
||||
set -A RW_FS_PROP "quota=512M" \
|
||||
"reservation=512M" \
|
||||
"recordsize=256K" \
|
||||
set -A RW_FS_PROP "quota=536870912" \
|
||||
"reservation=536870912" \
|
||||
"recordsize=262144" \
|
||||
"mountpoint=/tmp/mnt$$" \
|
||||
"checksum=fletcher2" \
|
||||
"compression=lzjb" \
|
||||
@@ -43,7 +43,7 @@ set -A RW_FS_PROP "quota=512M" \
|
||||
"canmount=off" \
|
||||
"local:department=123"
|
||||
|
||||
set -A RW_VOL_PROP "volblocksize=16K" \
|
||||
set -A RW_VOL_PROP "volblocksize=16384" \
|
||||
"checksum=fletcher2" \
|
||||
"compression=lzjb" \
|
||||
"readonly=on" \
|
||||
@@ -54,8 +54,8 @@ set -A RW_VOL_CLONE_PROP "checksum=fletcher2" \
|
||||
"readonly=on" \
|
||||
"local:department=123"
|
||||
|
||||
set -A FS_ONLY_PROP "quota=512M" \
|
||||
"recordsize=64K" \
|
||||
set -A FS_ONLY_PROP "quota=536870912" \
|
||||
"recordsize=65536" \
|
||||
"mountpoint=/tmp/mnt$$" \
|
||||
"atime=off" \
|
||||
"devices=off" \
|
||||
@@ -66,4 +66,4 @@ set -A FS_ONLY_PROP "quota=512M" \
|
||||
"canmount=off" \
|
||||
"version=1"
|
||||
|
||||
set -A VOL_ONLY_PROP "volblocksize=16K" "volsize=512M"
|
||||
set -A VOL_ONLY_PROP "volblocksize=16384" "volsize=536870912"
|
||||
|
||||
@@ -43,7 +43,7 @@ function propertycheck
|
||||
|
||||
typeset prop=$(echo $propstr | awk -F= '{print $1}')
|
||||
typeset expect_value=$(echo $propstr | awk -F= '{print $2}')
|
||||
typeset value=$(zfs get -H -o value $prop $dtst)
|
||||
typeset value=$(zfs get -H -p -o value $prop $dtst)
|
||||
|
||||
|
||||
if [[ "$expect_value" == "$value" ]]; then
|
||||
|
||||
@@ -56,9 +56,9 @@ log_onexit cleanup
|
||||
log_assert "'zpool create -O property=value pool' can successfully create a pool \
|
||||
with correct filesystem property set."
|
||||
|
||||
set -A RW_FS_PROP "quota=512M" \
|
||||
"reservation=512M" \
|
||||
"recordsize=64K" \
|
||||
set -A RW_FS_PROP "quota=536870912" \
|
||||
"reservation=536870912" \
|
||||
"recordsize=262144" \
|
||||
"mountpoint=/tmp/mnt$$" \
|
||||
"checksum=fletcher2" \
|
||||
"compression=lzjb" \
|
||||
|
||||
@@ -56,9 +56,9 @@ log_onexit cleanup
|
||||
log_assert "'zpool create -O property=value pool' can successfully create a pool \
|
||||
with multiple filesystem properties set."
|
||||
|
||||
set -A RW_FS_PROP "quota=512M" \
|
||||
"reservation=512M" \
|
||||
"recordsize=64K" \
|
||||
set -A RW_FS_PROP "quota=536870912" \
|
||||
"reservation=536870912" \
|
||||
"recordsize=262144" \
|
||||
"mountpoint=/tmp/mnt$$" \
|
||||
"checksum=fletcher2" \
|
||||
"compression=lzjb" \
|
||||
|
||||
@@ -53,6 +53,7 @@ log_assert "Check the basic function of {user|group} used"
|
||||
sync_pool
|
||||
typeset user_used=$(get_value "userused@$QUSER1" $QFS)
|
||||
typeset group_used=$(get_value "groupused@$QGROUP" $QFS)
|
||||
typeset file_size='100m'
|
||||
|
||||
if [[ $user_used != 0 ]]; then
|
||||
log_fail "FAIL: userused is $user_used, should be 0"
|
||||
@@ -62,15 +63,17 @@ if [[ $group_used != 0 ]]; then
|
||||
fi
|
||||
|
||||
mkmount_writable $QFS
|
||||
log_must user_run $QUSER1 mkfile 100m $QFILE
|
||||
log_must user_run $QUSER1 mkfile $file_size $QFILE
|
||||
sync_pool
|
||||
|
||||
user_used=$(get_value "userused@$QUSER1" $QFS)
|
||||
group_used=$(get_value "groupused@$QGROUP" $QFS)
|
||||
|
||||
if [[ $user_used != "100M" ]]; then
|
||||
# get_value() reads the exact byte value which is slightly more than 100m
|
||||
if [[ "$(($user_used/1024/1024))m" != "$file_size" ]]; then
|
||||
log_note "user $QUSER1 used is $user_used"
|
||||
log_fail "userused for user $QUSER1 expected to be 50.0M, not $user_used"
|
||||
log_fail "userused for user $QUSER1 expected to be $file_size, " \
|
||||
"not $user_used"
|
||||
fi
|
||||
|
||||
if [[ $user_used != $group_used ]]; then
|
||||
|
||||
@@ -111,7 +111,7 @@ function get_value # property dataset
|
||||
typeset prop=$1
|
||||
typeset dataset=$2
|
||||
|
||||
prop_val=$(zfs get -H -o value $prop $dataset 2>/dev/null)
|
||||
prop_val=$(zfs get -H -p -o value $prop $dataset 2>/dev/null)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
log_note "Unable to get $prop property for dataset " \
|
||||
"$dataset"
|
||||
|
||||
Reference in New Issue
Block a user