diff mbox

[v2,2/4] btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild

Message ID d5c6fc74720d36f78e378a8bfa50aea164751991.1440997237.git.zhaolei@cn.fujitsu.com (mailing list archive)
State Superseded
Headers show

Commit Message

Zhaolei Aug. 31, 2015, 5:04 a.m. UTC
When using loop device for test, fsck-tests/013-extent-tree-rebuild
failed with following error message:
  # ./fsck-tests.sh
  ...
    [TEST]   013-extent-tree-rebuild
  failed: mount /data/btrfsprogs/tests/test.img /data/btrfsprogs/tests/mnt
  test failed for case 013-extent-tree-rebuild
  #

Considering that $TEST_DEV can be block or loop device, we need determine
our mount option in a condition for both case.

This patch make above request to a common function, to solve current
problem in 013-extent-tree-rebuild, and support similar request in future.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 tests/common                                     | 23 +++++++++++++++++++++++
 tests/fsck-tests/013-extent-tree-rebuild/test.sh |  4 ++--
 2 files changed, 25 insertions(+), 2 deletions(-)

Comments

David Sterba Aug. 31, 2015, 2:48 p.m. UTC | #1
On Mon, Aug 31, 2015 at 01:04:37PM +0800, Zhao Lei wrote:
> +mount_test_dev()
> +{
> +	local loop_opt
> +	if [[ -b "$TEST_DEV" ]]; then
> +		loop_opt=()
> +	elif [[ -f "$TEST_DEV" ]]; then
> +		loop_opt=(-o loop)
> +	else
> +		_fail "Invalid \$TEST_DEV: $TEST_DEV"
> +	fi
> +
> +	[[ -d "$TEST_MNT" ]] || {
> +		_fail "Invalid \$TEST_MNT: $TEST_MNT"
> +	}
> +
> +	mount "${loop_opt[@]}" "$TEST_DEV" "$TEST_MNT" || _fail "mount $TEST_DEV to $TEST_MNT failed"

This needs the root helper, besides I don't see a reason why to use the
array to pass the loop options.

On newer systems the option 'loop' is not necessary and mount works with
that but I don't mind adding support for systems where this does not
work. However, this should not break current behaviour.

One thing that I find important is that the full commands are logged via
the run_check helpers. So I suggest to add run_check_mount_test_dev
helper that would wrapp all the commands. The combination of shell
functions does not work in all cases.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Zhaolei Sept. 1, 2015, 7:34 a.m. UTC | #2
Hi, David Sterba

Thanks for review.

> -----Original Message-----
> From: David Sterba [mailto:dsterba@suse.cz]
> Sent: Monday, August 31, 2015 10:48 PM
> To: Zhao Lei <zhaolei@cn.fujitsu.com>
> Cc: linux-btrfs@vger.kernel.org
> Subject: Re: [PATCH v2 2/4] btrfs-progs: tests: Fix mount fail of
> 013-extent-tree-rebuild
> 
> On Mon, Aug 31, 2015 at 01:04:37PM +0800, Zhao Lei wrote:
> > +mount_test_dev()
> > +{
> > +	local loop_opt
> > +	if [[ -b "$TEST_DEV" ]]; then
> > +		loop_opt=()
> > +	elif [[ -f "$TEST_DEV" ]]; then
> > +		loop_opt=(-o loop)
> > +	else
> > +		_fail "Invalid \$TEST_DEV: $TEST_DEV"
> > +	fi
> > +
> > +	[[ -d "$TEST_MNT" ]] || {
> > +		_fail "Invalid \$TEST_MNT: $TEST_MNT"
> > +	}
> > +
> > +	mount "${loop_opt[@]}" "$TEST_DEV" "$TEST_MNT" || _fail "mount
> $TEST_DEV to $TEST_MNT failed"
> 
> This needs the root helper,
>
> besides I don't see a reason why to use the array to
> pass the loop options.
> 
Only personal habit, will not use it in v2.

> On newer systems the option 'loop' is not necessary and mount works with that
> 
Glad to hear it.

> but I don't mind adding support for systems where this does not work. However,
> this should not break current behaviour.
> 
> One thing that I find important is that the full commands are logged via the
> run_check helpers. So I suggest to add run_check_mount_test_dev helper that
> would wrapp all the commands. The combination of shell functions does not
> work in all cases.
>
Ok.

Thanks
Zhaolei


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tests/common b/tests/common
index c597915..eae6b2b 100644
--- a/tests/common
+++ b/tests/common
@@ -178,3 +178,26 @@  init_env()
 	mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; }
 }
 init_env
+
+mount_test_dev()
+{
+	local loop_opt
+	if [[ -b "$TEST_DEV" ]]; then
+		loop_opt=()
+	elif [[ -f "$TEST_DEV" ]]; then
+		loop_opt=(-o loop)
+	else
+		_fail "Invalid \$TEST_DEV: $TEST_DEV"
+	fi
+
+	[[ -d "$TEST_MNT" ]] || {
+		_fail "Invalid \$TEST_MNT: $TEST_MNT"
+	}
+
+	mount "${loop_opt[@]}" "$TEST_DEV" "$TEST_MNT" || _fail "mount $TEST_DEV to $TEST_MNT failed"
+}
+
+umount_test_dev()
+{
+	umount "$TEST_DEV"
+}
diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh
index b7909d2..ff3c922 100755
--- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh
+++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh
@@ -12,14 +12,14 @@  test_extent_tree_rebuild()
 {
 	run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV
 
-	run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT
+	run_check $SUDO_HELPER mount_test_dev
 	run_check $SUDO_HELPER cp -aR /lib/modules/`uname -r`/ $TEST_MNT
 
 	for i in `seq 1 100`;do
 		run_check $SUDO_HELPER $TOP/btrfs sub snapshot $TEST_MNT \
 			$TEST_MNT/snapaaaaaaa_$i
 	done
-	run_check $SUDO_HELPER umount $TEST_DEV
+	run_check $SUDO_HELPER umount_test_dev
 
 	# get extent root bytenr
 	extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree -r $TEST_DEV | \