From: Lukas Czerner <lczerner@redhat.com>
To: zkabelac@redhat.com
Cc: Lukas Czerner <lczerner@redhat.com>,
dchinner@redhat.com, rwheeler@redhat.com, linux-lvm@redhat.com
Subject: [linux-lvm] [PATCH 15/35] fsadm: Make all internal math in kilobytes
Date: Wed, 21 Sep 2011 18:45:34 +0200 [thread overview]
Message-ID: <1316623554-28975-16-git-send-email-lczerner@redhat.com> (raw)
In-Reply-To: <1316623554-28975-1-git-send-email-lczerner@redhat.com>
We should make all math in fsadm to count with kilobytes (if possible)
because it will bypass the problem of having too big numbers. Also the
smaller granularity might have troubles with 512B alignment.
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
scripts/fsadm.sh | 74 ++++++++++++++++++++++++++---------------------------
1 files changed, 36 insertions(+), 38 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 028bc04..233b4fc 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -181,15 +181,14 @@ humanize_size() {
count=$(($count+1))
done
case $count in
- 0) unit="B" ;;
- 1) unit="KiB" ;;
- 2) unit="MiB" ;;
- 3) unit="GiB" ;;
- 4) unit="TiB" ;;
- 5) unit="PiB" ;;
- 6) unit="EiB" ;;
- 7) unit="ZiB" ;;
- 8) unit="YiB" ;;
+ 0) unit="KiB" ;;
+ 1) unit="MiB" ;;
+ 2) unit="GiB" ;;
+ 3) unit="TiB" ;;
+ 4) unit="PiB" ;;
+ 5) unit="EiB" ;;
+ 6) unit="ZiB" ;;
+ 7) unit="YiB" ;;
*) unit="???" ;;
esac
echo "$size $unit"
@@ -210,11 +209,11 @@ get_ext_size() {
esac
done
- total=$(($bcount*$bsize))
+ total=$(($bcount*$bsize/1024))
TOTAL=$(humanize_size $total)
- used=$((($bcount-$fbcount)*$bsize))
+ used=$((($bcount-$fbcount)*$bsize/1024))
USED=$(humanize_size $used)
- free=$((($fbcount-$rbcount)*$bsize))
+ free=$((($fbcount-$rbcount)*$bsize/1024))
FREE=$(humanize_size $free)
IFS=$IFS_OLD
}
@@ -241,11 +240,11 @@ get_xfs_size() {
bcount=$(($bcount-$lbcount))
fbcount=$(($fbcount-(4+(4*$agcount))))
- total=$(($bcount*$bsize))
+ total=$(($bcount*$bsize/1024))
TOTAL=$(humanize_size $total)
- used=$((($bcount-$fbcount)*$bsize))
+ used=$((($bcount-$fbcount)*$bsize/1024))
USED=$(humanize_size $used)
- free=$(($fbcount*$bsize))
+ free=$(($fbcount*$bsize/1024))
FREE=$(humanize_size $free)
return
fi
@@ -273,21 +272,20 @@ detect_fs_size() {
}
# convert parameter from Exa/Peta/Tera/Giga/Mega/Kilo/Bytes and blocks
-# (2^(60/50/40/30/20/10/0))
+# (2^(60/50/40/30/20/10/0)) into Kilobytes (KiB)
decode_size() {
case "$1" in
- *[eE]) NEWSIZE=$(float_math "${1%[eE]} * 1152921504606846976") ;;
- *[pP]) NEWSIZE=$(float_math "${1%[pP]} * 1125899906842624") ;;
- *[tT]) NEWSIZE=$(float_math "${1%[tT]} * 1099511627776") ;;
- *[gG]) NEWSIZE=$(float_math "${1%[gG]} * 1073741824") ;;
- *[mM]) NEWSIZE=$(float_math "${1%[mM]} * 1048576") ;;
- *[kK]) NEWSIZE=$(float_math "${1%[kK]} * 1024") ;;
- *[bB]) NEWSIZE=${1%[bB]} ;;
- *) NEWSIZE=$(( $1 * $2 )) ;;
+ *[eE]) NEWSIZE=$(float_math "${1%[eE]} * 1125899906842624") ;;
+ *[pP]) NEWSIZE=$(float_math "${1%[pP]} * 1099511627776") ;;
+ *[tT]) NEWSIZE=$(float_math "${1%[tT]} * 1073741824") ;;
+ *[gG]) NEWSIZE=$(float_math "${1%[gG]} * 1048576") ;;
+ *[mM]) NEWSIZE=$(float_math "${1%[mM]} * 1024") ;;
+ *[kK]) NEWSIZE=${1%[kK]} ;;
+ *[bB]) NEWSIZE=$(float_math "${1%[bB]} / 1024") ;;
esac
NEWSIZE=${NEWSIZE%%.*}
- NEWBLOCKCOUNT=$(float_math "$NEWSIZE / $2")
+ NEWBLOCKCOUNT=$(float_math "($NEWSIZE / $2) * 1024")
NEWBLOCKCOUNT=${NEWBLOCKCOUNT%%.*}
}
@@ -423,7 +421,7 @@ resize_ext() {
esac
fi
- verbose "Resizing filesystem on device \"$VOLUME\" to $NEWSIZE bytes ($BLOCKCOUNT -> $NEWBLOCKCOUNT blocks of $BLOCKSIZE bytes)"
+ verbose "Resizing filesystem on device \"$VOLUME\" to $NEWSIZE KiB ($BLOCKCOUNT -> $NEWBLOCKCOUNT blocks of $BLOCKSIZE bytes)"
dry "$RESIZE_EXT" $FSFORCE "$VOLUME" $NEWBLOCKCOUNT
}
@@ -444,11 +442,11 @@ resize_reiser() {
done
validate_parsing "$TUNE_REISER"
decode_size $1 $BLOCKSIZE
- verbose "Resizing \"$VOLUME\" $BLOCKCOUNT -> $NEWBLOCKCOUNT blocks ($NEWSIZE bytes, bs: $NEWBLOCKCOUNT)"
+ verbose "Resizing \"$VOLUME\" $BLOCKCOUNT -> $NEWBLOCKCOUNT blocks ($NEWSIZE KiB, bs: $NEWBLOCKCOUNT)"
if [ -n "$YES" ]; then
- echo y | dry "$RESIZE_REISER" -s $NEWSIZE "$VOLUME"
+ echo y | dry "$RESIZE_REISER" -s ${NEWSIZE}K "$VOLUME"
else
- dry "$RESIZE_REISER" -s $NEWSIZE "$VOLUME"
+ dry "$RESIZE_REISER" -s ${NEWSIZE}K "$VOLUME"
fi
}
@@ -552,9 +550,9 @@ resize_fs() {
resize_lvolume() {
lvname=$1
newsize=$2
- lvsize=$(LANG=C $LVM lvs -o lv_size --separator ' ' --noheadings --nosuffix --units b $lvname 2> /dev/null | sed -e 's/^ *//')
+ lvsize=$(LANG=C $LVM lvs -o lv_size --separator ' ' --noheadings --nosuffix --units k $lvname 2> /dev/null | sed -e 's/^ *//')
if [ $lvsize != $newsize ]; then
- dry $LVM lvresize $VERB $FORCE -L${newsize}b $lvname
+ dry $LVM lvresize $VERB $FORCE -L${newsize}k $lvname
else
verbose "Logical volume already is of the size you're trying to resize it to"
fi
@@ -740,8 +738,8 @@ create() {
# there is only one vgroup, or use the one with enough
# free space in it
if [ -z "$vgname" ]; then
- vgroups=$($LVM vgs -o vg_name,vg_free --separator ' ' --noheadings --units b 2> /dev/null)
- lines=$($LVM vgs -o vg_name,vg_free --separator ' ' --noheadings --units b 2> /dev/null | wc -l)
+ vgroups=$($LVM vgs -o vg_name,vg_free --separator ' ' --noheadings --units k 2> /dev/null)
+ lines=$($LVM vgs -o vg_name,vg_free --separator ' ' --noheadings --units k 2> /dev/null | wc -l)
if [ $lines -eq 1 ]; then
vgname=$(echo $vgroups | sed -e 's/^ *//' | cut -d' ' -f1)
@@ -935,7 +933,7 @@ remove() {
echo "Usage: $TOOL remove [mount point | dm device | voulume group | device | --all]"
exit 0
elif [ "$1" == "--all" ]; then
- list="$(LANG=C $LVM vgs -o vg_name --separator ' ' --noheadings --nosuffix --units b 2> /dev/null)"
+ list="$(LANG=C $LVM vgs -o vg_name --separator ' ' --noheadings --nosuffix --units k 2> /dev/null)"
else
list=$@
fi
@@ -957,7 +955,7 @@ remove() {
list_filesystems() {
IFS=$NL
local c=0
- for line in $(LANG=C $LVM lvs -o lv_path,lv_size,segtype --noheadings --separator ' ' --nosuffix --units b 2> /dev/null); do
+ for line in $(LANG=C $LVM lvs -o lv_path,lv_size,segtype --noheadings --separator ' ' --nosuffix --units k 2> /dev/null); do
line=$(echo $line | sed -e 's/^ *\//\//')
volume=$(echo $line | cut -d' ' -f1)
[ "$volume" == "$last_volume" ] && continue
@@ -1041,11 +1039,11 @@ list_devices() {
c=0
dmnumber=$(cat $PROCDEVICES | grep device-mapper | sed -e 's/^ *//')
dmnumber=${dmnumber%% *}
- LANG=C $LVM pvs -o pv_name,vg_name,pv_size,pv_free,pv_used --separator ' ' --noheadings --nosuffix --units b > $tmp
+ LANG=C $LVM pvs -o pv_name,vg_name,pv_size,pv_free,pv_used --separator ' ' --noheadings --nosuffix --units k > $tmp
for line in $(cat $PROCPARTITIONS | tail -n +3 | sed -e 's/^ *//' | grep -v -e "^$dmnumber"); do
c=$((c+1))
line=$(echo $line | sed -e 's/ */ /g')
- _total=$(($(echo $line | cut -d' ' -f3)*1024))
+ _total=$(echo $line | cut -d' ' -f3)
local total[$c]=$(humanize_size ${_total%%.*})
VOLUME=$(echo $line | cut -d' ' -f4)
RVOLUME="/dev/$(echo $line | cut -d' ' -f4)"
@@ -1125,7 +1123,7 @@ list_devices() {
list_pool() {
IFS=$NL
c=0
- for line in $(LANG=C $LVM vgs -o vg_name,pv_count,vg_size,vg_free --separator ' ' --noheadings --nosuffix --units b 2> /dev/null); do
+ for line in $(LANG=C $LVM vgs -o vg_name,pv_count,vg_size,vg_free --separator ' ' --noheadings --nosuffix --units k 2> /dev/null); do
c=$((c+1))
line=$(echo $line | sed -e 's/^ *//')
local group[$c]=$(echo $line | cut -d' ' -f1)
--
1.7.4.4
next prev parent reply other threads:[~2011-09-21 16:45 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-21 16:45 [linux-lvm] [RFC][PATCH 00/35] fsadm update Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 01/35] fsadm: Add "create" command Lukas Czerner
2011-09-21 19:00 ` Stephane Chazelas
2011-09-22 9:28 ` Lukas Czerner
2011-09-22 10:01 ` Zdenek Kabelac
2011-09-22 10:27 ` Lukas Czerner
2011-09-22 10:56 ` Stephane Chazelas
2011-09-21 16:45 ` [linux-lvm] [PATCH 02/35] fsadm: Add "destroy" command Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 03/35] fsadm: Add "list" command Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 04/35] fsadm: Make "create" command more vg aware Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 05/35] fsadm: Teach "destroy" command to take more arguments Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 06/35] fsadm: Simple cleanup and comment update Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 07/35] fsadm: Create "add" command Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 08/35] fsadm: Update "list" command for better alignment Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 09/35] fsadm: Specify number of stripes when no device is given Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 10/35] fsadm: Print type of the volume in filesystem listing Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 11/35] fsadm: Add "remove" command Lukas Czerner
2011-09-22 10:06 ` Zdenek Kabelac
2011-09-22 10:36 ` Lukas Czerner
2011-09-22 10:43 ` Zdenek Kabelac
2011-09-22 10:52 ` Lukas Czerner
2011-09-22 11:41 ` Zdenek Kabelac
2011-09-21 16:45 ` [linux-lvm] [PATCH 12/35] fsadm: Try to avoid calling LVM in the loops Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 13/35] fsadm: Merge "destroy" and "remove" into one command Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 14/35] fsadm: Allow to remove all volume groups Lukas Czerner
2011-09-21 16:45 ` Lukas Czerner [this message]
2011-09-21 16:45 ` [linux-lvm] [PATCH 16/35] fsadm: Use warn for warnings in list command Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 17/35] fsadm: Handle resize if there is no file system Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 18/35] fsadm: Fsck extN before resize only if it is not mounted Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 19/35] fsadm: Align numbers to the decimal point Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 20/35] fsadm: Add simple configuration file Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 21/35] fsadm: Use DEFAULT_POOL when creating volume group Lukas Czerner
2011-09-22 10:09 ` Zdenek Kabelac
2011-09-21 16:45 ` [linux-lvm] [PATCH 22/35] fsadm: Add LVOL_PREFIX configuration option Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 23/35] fsadm: Only use readlink if link is provided Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 24/35] fsadm: Remove unnecessary modification of PATH variable Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 25/35] fsadm: Allow to specify size without "size=" prefix in "resize" Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 26/35] fsadm: Allow to specify lv in vg/lv format Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 27/35] fsadm: error out when no size is provided in resize Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 28/35] fsadm: Umount ext2 file system prior resize Lukas Czerner
2011-09-22 10:28 ` Zdenek Kabelac
2011-09-21 16:45 ` [linux-lvm] [PATCH 29/35] lvresize: Specify --resize-fs-only when going to use fsadm resize Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 30/35] test: add helper to compute aligned lv size Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 31/35] fsadm: Add help for new commands and update man page Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 32/35] fsadm: Update authorship of the fsadm Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 33/35] test: Add test for fsadm add command Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 34/35] test: Add test for fsadm create command Lukas Czerner
2011-09-21 16:45 ` [linux-lvm] [PATCH 35/35] test: Add test for fsadm resize command Lukas Czerner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1316623554-28975-16-git-send-email-lczerner@redhat.com \
--to=lczerner@redhat.com \
--cc=dchinner@redhat.com \
--cc=linux-lvm@redhat.com \
--cc=rwheeler@redhat.com \
--cc=zkabelac@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).