[6/8] xfstests: generic/311: add a few more test cases
diff mbox

Message ID 1382120790-31060-6-git-send-email-jbacik@fusionio.com
State Not Applicable
Headers show

Commit Message

Josef Bacik Oct. 18, 2013, 6:26 p.m. UTC
Btrfs had some issues with fsync()'ing directories and fsync()'ing after
renames.  These three new tests cover the 3 different issues we were seeing.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
---
 tests/generic/311     | 89 +++++++++++++++++++++++++++++++++++++++++++++++++--
 tests/generic/311.out |  8 +++++
 2 files changed, 95 insertions(+), 2 deletions(-)

Comments

Eric Sandeen Oct. 21, 2013, 3:37 p.m. UTC | #1
On 10/18/13 1:26 PM, Josef Bacik wrote:
> Btrfs had some issues with fsync()'ing directories and fsync()'ing after
> renames.  These three new tests cover the 3 different issues we were seeing.
> Thanks,
> 
> Signed-off-by: Josef Bacik <jbacik@fusionio.com>

I'd prefer that you copy 311 to a new test w/ just this case.

Adding potentially-failing new cases to old tests makes it harder
to keep track of when/if/how/what code regressed...

-Eric

> ---
>  tests/generic/311     | 89 +++++++++++++++++++++++++++++++++++++++++++++++++--
>  tests/generic/311.out |  8 +++++
>  2 files changed, 95 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/generic/311 b/tests/generic/311
> index 675d927..002ad57 100644
> --- a/tests/generic/311
> +++ b/tests/generic/311
> @@ -70,6 +70,8 @@ testfile=$SCRATCH_MNT/$seq.fsync
>  FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0"
>  FLAKEY_TABLE_DROP="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 drop_writes"
>  _TEST_OPTIONS=""
> +allow_writes=0
> +drop_writes=1
>  
>  _mount_flakey()
>  {
> @@ -104,8 +106,6 @@ _load_flakey_table()
>  _run_test()
>  {
>  	# _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
> -	allow_writes=0
> -	drop_writes=1
>  	test_num=$1
>  
>  	direct_opt=""
> @@ -131,6 +131,83 @@ _run_test()
>  	_mount_flakey
>  }
>  
> +_clean_working_dir()
> +{
> +	_mount_flakey
> +	rm -rf $SCRATCH_MNT/*
> +	_unmount_flakey
> +}
> +
> +# Btrfs wasn't making sure the directory survived fsync
> +_directory_test()
> +{
> +	echo "fsync new directory"
> +	_mount_flakey
> +	mkdir $SCRATCH_MNT/bar
> +	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
> +	_load_flakey_table $drop_writes
> +	_unmount_flakey
> +
> +	_load_flakey_table $allow_writes
> +	_mount_flakey
> +	_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
> +	_unmount_flakey
> +	_check_scratch_fs $FLAKEY_DEV
> +	[ $? -ne 0 ] && _fatal "fsck failed"
> +}
> +
> +# Btrfs was losing a rename into a new directory
> +_rename_test()
> +{
> +	echo "rename fsync test"
> +	_mount_flakey
> +	touch $SCRATCH_MNT/foo
> +	mkdir $SCRATCH_MNT/bar
> +	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
> +	mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
> +	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
> +	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
> +	_load_flakey_table $drop_writes
> +	_unmount_flakey
> +
> +	_load_flakey_table $allow_writes
> +	_mount_flakey
> +	_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
> +	_ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
> +	_unmount_flakey
> +	_check_scratch_fs $FLAKEY_DEV
> +	[ $? -ne 0 ] && _fatal "fsck failed"
> +}
> +
> +# Btrfs was failing to replay a log when we had a inode with a smaller inode
> +# number that is renamed into a directory with a higher inode number
> +_replay_rename_test()
> +{
> +	echo "replay rename fsync test"
> +	_mount_flakey
> +	touch $SCRATCH_MNT/foo
> +	mkdir $SCRATCH_MNT/bar
> +	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
> +	mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
> +	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
> +
> +	# This is to force btrfs to relog the entire inode including the ref so
> +	# we are sure to try and replay the ref along with the dir_index item
> +	setfattr -n user.foo -v blah $SCRATCH_MNT/bar/foo >> $seqres.full 2>&1
> +
> +	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
> +	_load_flakey_table $drop_writes
> +	_unmount_flakey
> +
> +	_load_flakey_table $allow_writes
> +	_mount_flakey
> +	_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
> +	_ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
> +	_unmount_flakey
> +	_check_scratch_fs $FLAKEY_DEV
> +	[ $? -ne 0 ] && _fatal "fsck failed"
> +}
> +
>  _scratch_mkfs >> $seqres.full 2>&1
>  
>  # Create a basic flakey device that will never error out
> @@ -157,5 +234,13 @@ for i in $(seq 1 20); do
>  	_run_test $i $direct
>  done
>  
> +rm -rf $SCRATCH_MNT/*
> +_unmount_flakey
> +_directory_test
> +_clean_working_dir
> +_rename_test
> +_clean_working_dir
> +_replay_rename_test
> +
>  status=0
>  exit
> diff --git a/tests/generic/311.out b/tests/generic/311.out
> index 5bad6a7..8a0d5c8 100644
> --- a/tests/generic/311.out
> +++ b/tests/generic/311.out
> @@ -319,3 +319,11 @@ Running test 20 direct, nolockfs
>  Random seed is 20
>  a16ac2b84456d41a15a1a4cc1202179f
>  a16ac2b84456d41a15a1a4cc1202179f
> +fsync new directory
> +drwxr-xr-x bar
> +rename fsync test
> +drwxr-xr-x bar
> +-rw-r--r-- foo
> +replay rename fsync test
> +drwxr-xr-x bar
> +-rw-r--r-- foo
> 

--
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

Patch
diff mbox

diff --git a/tests/generic/311 b/tests/generic/311
index 675d927..002ad57 100644
--- a/tests/generic/311
+++ b/tests/generic/311
@@ -70,6 +70,8 @@  testfile=$SCRATCH_MNT/$seq.fsync
 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0"
 FLAKEY_TABLE_DROP="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 drop_writes"
 _TEST_OPTIONS=""
+allow_writes=0
+drop_writes=1
 
 _mount_flakey()
 {
@@ -104,8 +106,6 @@  _load_flakey_table()
 _run_test()
 {
 	# _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
-	allow_writes=0
-	drop_writes=1
 	test_num=$1
 
 	direct_opt=""
@@ -131,6 +131,83 @@  _run_test()
 	_mount_flakey
 }
 
+_clean_working_dir()
+{
+	_mount_flakey
+	rm -rf $SCRATCH_MNT/*
+	_unmount_flakey
+}
+
+# Btrfs wasn't making sure the directory survived fsync
+_directory_test()
+{
+	echo "fsync new directory"
+	_mount_flakey
+	mkdir $SCRATCH_MNT/bar
+	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
+	_load_flakey_table $drop_writes
+	_unmount_flakey
+
+	_load_flakey_table $allow_writes
+	_mount_flakey
+	_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
+	_unmount_flakey
+	_check_scratch_fs $FLAKEY_DEV
+	[ $? -ne 0 ] && _fatal "fsck failed"
+}
+
+# Btrfs was losing a rename into a new directory
+_rename_test()
+{
+	echo "rename fsync test"
+	_mount_flakey
+	touch $SCRATCH_MNT/foo
+	mkdir $SCRATCH_MNT/bar
+	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
+	mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
+	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
+	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
+	_load_flakey_table $drop_writes
+	_unmount_flakey
+
+	_load_flakey_table $allow_writes
+	_mount_flakey
+	_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
+	_ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
+	_unmount_flakey
+	_check_scratch_fs $FLAKEY_DEV
+	[ $? -ne 0 ] && _fatal "fsck failed"
+}
+
+# Btrfs was failing to replay a log when we had a inode with a smaller inode
+# number that is renamed into a directory with a higher inode number
+_replay_rename_test()
+{
+	echo "replay rename fsync test"
+	_mount_flakey
+	touch $SCRATCH_MNT/foo
+	mkdir $SCRATCH_MNT/bar
+	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
+	mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar/foo
+	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
+
+	# This is to force btrfs to relog the entire inode including the ref so
+	# we are sure to try and replay the ref along with the dir_index item
+	setfattr -n user.foo -v blah $SCRATCH_MNT/bar/foo >> $seqres.full 2>&1
+
+	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar/foo
+	_load_flakey_table $drop_writes
+	_unmount_flakey
+
+	_load_flakey_table $allow_writes
+	_mount_flakey
+	_ls_l $SCRATCH_MNT | tail -n +2 | awk '{ print $1, $9 }'
+	_ls_l $SCRATCH_MNT/bar | tail -n +2 | awk '{ print $1, $9 }'
+	_unmount_flakey
+	_check_scratch_fs $FLAKEY_DEV
+	[ $? -ne 0 ] && _fatal "fsck failed"
+}
+
 _scratch_mkfs >> $seqres.full 2>&1
 
 # Create a basic flakey device that will never error out
@@ -157,5 +234,13 @@  for i in $(seq 1 20); do
 	_run_test $i $direct
 done
 
+rm -rf $SCRATCH_MNT/*
+_unmount_flakey
+_directory_test
+_clean_working_dir
+_rename_test
+_clean_working_dir
+_replay_rename_test
+
 status=0
 exit
diff --git a/tests/generic/311.out b/tests/generic/311.out
index 5bad6a7..8a0d5c8 100644
--- a/tests/generic/311.out
+++ b/tests/generic/311.out
@@ -319,3 +319,11 @@  Running test 20 direct, nolockfs
 Random seed is 20
 a16ac2b84456d41a15a1a4cc1202179f
 a16ac2b84456d41a15a1a4cc1202179f
+fsync new directory
+drwxr-xr-x bar
+rename fsync test
+drwxr-xr-x bar
+-rw-r--r-- foo
+replay rename fsync test
+drwxr-xr-x bar
+-rw-r--r-- foo