Skip to content

Commit 7f82b0b

Browse files
DmitryLitvintsevmksahakyan
authored andcommitted
dcache cli: fix issue with printing pool size when max diskspace is set in percentage
Motivation: ----------- patch 8c71927 introduced ability to specify max disk space in percentage of partition space like so: set max diskspace 98% unfortunately it breaks dcache pool ls command like so: 98% is not an integer. Modification: ------------ Calculate pool size based on partition size and percentage Result: ------ No error when running "dcache pool ls" and pool size properly reported Ticket: #8014 Patch: https://rb.dcache.org/r/14618/ Acked-by: Marina Request: trunk Target: 11.x Require-book: no Require-notes: yes
1 parent d1241e7 commit 7f82b0b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

skel/share/lib/pool.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ getSizeOfPool() # in $1 = pool path
2525
local size
2626

2727
size=$(getPoolSetting "$path" "set max diskspace" max)
28+
2829
if [ -z "$size" ]; then
2930
size=$(getProperty pool.size "$domain" "$cell")
3031
fi
@@ -38,6 +39,13 @@ getSizeOfPool() # in $1 = pool path
3839
"")
3940
echo "-"
4041
;;
42+
*%)
43+
total=$(getTotalSpace "$path")
44+
percent=$(echo "${size}" | tr -d "%")
45+
size=$((${total}*${percent}/100))
46+
stringToGiB "${size}G" size
47+
echo "${size}G"
48+
;;
4149
*)
4250
stringToGiB "$size" size
4351
echo "${size}G"

skel/share/lib/utils.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ getFreeSpace() # in $1 = path
305305
[ -d "$1" ] && ( df -k "${1}" | awk 'NR == 2 { if (NF < 4) { getline; x = $3 } else { x = $4 }; printf "%d", x / (1024 * 1024)}' )
306306
}
307307

308+
# Extracts the amount of free space in GiB.
309+
getTotalSpace() # in $1 = path
310+
{
311+
[ -d "$1" ] && ( df -k "${1}" | awk 'NR == 2 { if (NF < 4) { getline; x = $1 } else { x = $2 }; printf "%d", x / (1024 * 1024)}' )
312+
}
313+
308314
# Reads configuration file into shell variables. The shell variable
309315
# names can optionally be prefixed. Returns 1 if file does not exist.
310316
readconf() # in $1 = file in $2 = prefix

0 commit comments

Comments
 (0)