generic/312: fix dev_blocks calculation

Current calculation fails when there are many same type of devices
with the testing device, eg sda1 sda2 ... sda10, sda11, sda12 ..
$(grep sda1 /proc/partitions) gets multiple numbers.

$ grep ram1 /proc/partitions
   1        1   10485760 ram1
   1       10   10485760 ram10
   1       11   10485760 ram11
   1       12   10485760 ram12
   1       13   10485760 ram13
   1       14   10485760 ram14
   1       15   10485760 ram15
$ grep -w ram1 /proc/partitions
   1        1   10485760 ram1

Fix this by adding the -w option to grep to match the block device
exactly.

Signed-off-by: Xiong Zhou <xzhou@redhat.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
Xiong Zhou
2015-11-02 11:00:51 +11:00
committed by Dave Chinner
parent 17f7ca2c11
commit 8deb635098
+1 -1
View File
@@ -52,7 +52,7 @@ _require_scratch
# 5G in byte
fssize=$((2**30 * 5))
required_blocks=$(($fssize / 1024))
dev_blocks=$(grep $(_short_dev $SCRATCH_DEV) /proc/partitions | $AWK_PROG '{print $3}')
dev_blocks=$(grep -w $(_short_dev $SCRATCH_DEV) /proc/partitions | $AWK_PROG '{print $3}')
if [ $required_blocks -gt $dev_blocks ];then
_notrun "this test requires \$SCRATCH_DEV has ${fssize}B space"
fi