All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH v3 02/18] fsadm: Make all internal math in kilobytes
Date: Tue, 27 Sep 2011 15:42:35 +0200	[thread overview]
Message-ID: <1317130971-24173-3-git-send-email-lczerner@redhat.com> (raw)
In-Reply-To: <1317130971-24173-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 |   79 ++++++++++++++++++++++++++---------------------------
 1 files changed, 39 insertions(+), 40 deletions(-)

diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index f0da586..58ff0ab 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -188,15 +188,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"
@@ -217,11 +216,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)
 }
 
@@ -247,11 +246,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
@@ -278,21 +277,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%%.*}
 }
 
@@ -428,8 +426,8 @@ resize_ext() {
 		esac
 	fi
 
-	verbose "Resizing filesystem on device \"$VOLUME\" to $NEWSIZE bytes ($BLOCKCOUNT -> $NEWBLOCKCOUNT blocks of $BLOCKSIZE bytes)"
-	dry "$RESIZE_EXT" "$FSFORCE" "$VOLUME" "$NEWBLOCKCOUNT"
+	verbose "Resizing filesystem on device \"$VOLUME\" to $NEWSIZE KiB ($BLOCKCOUNT -> $NEWBLOCKCOUNT blocks of $BLOCKSIZE bytes)"
+	dry "$RESIZE_EXT" $FSFORCE "$VOLUME" "$NEWBLOCKCOUNT"
 }
 
 #############################
@@ -449,11 +447,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
 }
 
@@ -547,9 +545,10 @@ 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
@@ -719,8 +718,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)
@@ -903,7 +902,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
@@ -920,7 +919,7 @@ remove() {
 list_filesystems() {
 	local 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
@@ -1003,11 +1002,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
-	for line in $(cat "$PROCPARTITIONS" | tail -n +3 | sed -e 's/^  *//' | "$GREP" -v -e "^$dmnumber"); do
+	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)"
@@ -1086,7 +1085,7 @@ list_devices() {
 list_pool() {
 	local 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



  parent reply	other threads:[~2011-09-27 13:42 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-27 13:42 [RFC][PATCH v3 00/16] fsadm update Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 01/18] fsadm: Add new commands create, list, add and remove Lukas Czerner
2011-10-04  9:41   ` Zdenek Kabelac
2011-10-04 12:13     ` Lukas Czerner
2011-10-04 17:09       ` Zdenek Kabelac
2011-10-05  8:02         ` Lukas Czerner
2011-10-05  9:06           ` Zdenek Kabelac
2011-10-05  9:46             ` Lukas Czerner
2011-10-05 10:27               ` Alasdair G Kergon
2011-10-05 11:21                 ` Lukas Czerner
2011-10-05 11:26                   ` Lukas Czerner
2011-10-05 11:28                   ` Ric Wheeler
2011-10-05 11:49                   ` Alasdair G Kergon
2011-10-05 12:15                     ` Lukas Czerner
2011-09-27 13:42 ` Lukas Czerner [this message]
2011-09-27 15:41   ` [PATCH v3 02/18] fsadm: Make all internal math in kilobytes Zdenek Kabelac
2011-10-03 16:13     ` Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 03/18] fsadm: Add simple configuration file Lukas Czerner
2011-09-27 15:39   ` Zdenek Kabelac
2011-10-03 16:44     ` Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 04/18] fsadm: Use DEFAULT_DEVICE_POOL when creating volume group Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 05/18] fsadm: Add LVOL_PREFIX configuration option Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 06/18] fsadm: Fsck extN before resize only if it is not mounted Lukas Czerner
2011-10-04  8:09   ` Zdenek Kabelac
2011-09-27 13:42 ` [PATCH v3 07/18] fsadm: Only use readlink if link is provided Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 08/18] fsadm: Remove unnecessary modification of PATH variable Lukas Czerner
2011-10-04  8:12   ` Zdenek Kabelac
2011-10-04  8:17     ` Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 09/18] fsadm: Allow to specify lv in vg/lv format Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 10/18] fsadm: Umount ext2 file system prior resize Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 11/18] fsadm: Add help for new commands and update man page Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 12/18] lvresize: Specify --resize-fs-only when going to use fsadm resize Lukas Czerner
2011-09-27 15:44   ` Zdenek Kabelac
2011-10-03 16:20     ` Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 13/18] fsadm: remove -y (YES) option Lukas Czerner
2011-09-27 15:38   ` Zdenek Kabelac
2011-10-03 16:39     ` Lukas Czerner
2011-10-03 18:18       ` Zdenek Kabelac
2011-10-04  6:29         ` Lukas Czerner
2011-10-04  8:07           ` Zdenek Kabelac
2011-09-27 13:42 ` [PATCH v3 14/18] test: add helper to compute aligned lv size Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 15/18] test: Add test for fsadm add command Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 16/18] test: Add test for fsadm create command Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 17/18] test: Add test for fsadm resize command Lukas Czerner
2011-09-27 13:42 ` [PATCH v3 18/18] test: Add test for fsadm remove command Lukas Czerner
2011-09-27 13:50 ` [RFC][PATCH v3 00/16] fsadm update 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=1317130971-24173-3-git-send-email-lczerner@redhat.com \
    --to=lczerner@redhat.com \
    --cc=lvm-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.