Skip to contentSkip to conversation

common: fix _count_extents and _count_holes

PATCH In review Eryu Guan 2 participants 2 messages Jul 28, 2015 – Jul 29, 2015

lore
Share & tools
lore

Eryu Guan

author
#0 lore raw

PATCH 1/1 common: fix _count_extents and _count_holes

In _count_extents and _count_holes, the output of 'xfs_io -c "fiemap"' is saved in var res, but the following "echo $res" will merge the original output into one line. e.g.

	0: [0..63]: 96..159
	1: [64..127]: hole

will be

	0: [0..63]: 96..159 1: [64..127]: hole

so the extent count is always 0 if there's a hole.

This makes generic/046 fail occasionally. (Seems it's easier to reproduce when the system is under some presure, e.g. with fsstress running.)

Tested the new _count_extents and _count_holes with generic/04[3-9] and tests all passed as expect.

---
 common/rc | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
common/rc +2 -4
index 15e7795..0d3570f 100644
@@ -2434,14 +2434,12 @@ _require_fiemap()
 
 _count_extents()
 {
-	res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
-	echo $res | grep -v hole | wc -l | $AWK_PROG '{print $1}'
+	$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
 }
 
 _count_holes()
 {
-	res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
-	echo $res | grep hole | wc -l | $AWK_PROG '{print $1}'
+	$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
 }
 
 # arg 1 is dev to remove and is output of the below eg.
Signature · 1 line
2.4.3
#1 lore raw

----- 原始邮件 -----

Quoted 37 lines

发件人: "Eryu Guan" <[email protected]>
收件人: [email protected]
抄送: [email protected], "Eryu Guan" <[email protected]> 发送时间: 星期二, 2015年 7 月 28日 下午 10:25:04
主题: [PATCH] common: fix _count_extents and _count_holes

In _count_extents and _count_holes, the output of 'xfs_io -c "fiemap"' is saved in var res, but the following "echo $res" will merge the original output into one line. e.g.

	0: [0..63]: 96..159
	1: [64..127]: hole

will be

	0: [0..63]: 96..159 1: [64..127]: hole

so the extent count is always 0 if there's a hole.

This makes generic/046 fail occasionally. (Seems it's easier to reproduce when the system is under some presure, e.g. with fsstress running.)

Tested the new _count_extents and _count_holes with generic/04[3-9] and tests all passed as expect.

---
 common/rc | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
common/rc +0 -0
index 15e7795..0d3570f 100644

common/rc _require_fiemap() · line 2437

Quoted 6 lines
common/rc +1 -2
@@ -2434,14 +2434,12 @@ _require_fiemap()
 
 _count_extents()
 {
-	res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
-	echo $res | grep -v hole | wc -l | $AWK_PROG '{print $1}'
+	$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l

Maybe just give quotation marks to $res will be ok, likes echo "$res"|....

And I think $AWK_PROG '{print $1}' try to ensure no blank at the end. So keep it will be better, although I haven't seen "wc -l" print blank after number;)

Quoted 14 lines
common/rc +1 -3
 }
 
 _count_holes()
 {
-	res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
-	echo $res | grep hole | wc -l | $AWK_PROG '{print $1}'
+	$XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
 }
 
 # arg 1 is dev to remove and is output of the below eg.
--

2.4.3