diff mbox series

btrfs/242: test case to fstrim on a degraded filesystem

Message ID a70c9f6b4e45d9bcdc5c2f19182f89ef8e22c074.1625237782.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs/242: test case to fstrim on a degraded filesystem | expand

Commit Message

Anand Jain July 4, 2021, 11:20 a.m. UTC
Create a degraded btrfs filesystem and run fstrim on it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 tests/btrfs/242     | 49 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/242.out |  2 ++
 2 files changed, 51 insertions(+)
 create mode 100755 tests/btrfs/242
 create mode 100644 tests/btrfs/242.out

Comments

Qu Wenruo July 5, 2021, 12:17 a.m. UTC | #1
On 2021/7/4 下午7:20, Anand Jain wrote:
> Create a degraded btrfs filesystem and run fstrim on it.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>   tests/btrfs/242     | 49 +++++++++++++++++++++++++++++++++++++++++++++
>   tests/btrfs/242.out |  2 ++
>   2 files changed, 51 insertions(+)
>   create mode 100755 tests/btrfs/242
>   create mode 100644 tests/btrfs/242.out
>
> diff --git a/tests/btrfs/242 b/tests/btrfs/242
> new file mode 100755
> index 000000000000..e946ee6ac7c2
> --- /dev/null
> +++ b/tests/btrfs/242
> @@ -0,0 +1,49 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2021 Oracle. All Rights Reserved.
> +#
> +# FS QA Test 242
> +#
> +# Test that fstrim can run on the degraded filesystem
> +#   Kernel requires fix for the null pointer deref in btrfs_trim_fs()
> +#     [patch] btrfs: check for missing device in btrfs_trim_fs
> +
> +
> +. ./common/preamble
> +_begin_fstest auto quick replace trim
> +
> +# Import common functions.
> +. ./common/filter
> +
> +# real QA test starts here
> +_supported_fs btrfs
> +_require_btrfs_forget_or_module_loadable

Since you have wipefs requirement commented out, I guess you're also
unsure which is the better way.

Personally speaking, I think wipefs is better.
As it's more generic and needs no kernel support.

Despite that it looks good to me.

Thanks,
Qu

> +_require_scratch_dev_pool 2
> +#_require_command "$WIPEFS_PROG" wipefs
> +
> +_scratch_dev_pool_get 2
> +dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
> +
> +_scratch_pool_mkfs "-m raid1 -d raid1"
> +_scratch_mount
> +_require_batched_discard $SCRATCH_MNT
> +
> +# Add a test file with some data.
> +$XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo > /dev/null
> +
> +# Unmount the filesystem.
> +_scratch_unmount
> +
> +# Mount the filesystem in degraded mode
> +_btrfs_forget_or_module_reload
> +_mount -o degraded $dev1 $SCRATCH_MNT
> +
> +# Run fstrim
> +$FSTRIM_PROG $SCRATCH_MNT
> +
> +_scratch_dev_pool_put
> +
> +echo Silence is golden
> +
> +status=0
> +exit
> diff --git a/tests/btrfs/242.out b/tests/btrfs/242.out
> new file mode 100644
> index 000000000000..a46d77702f23
> --- /dev/null
> +++ b/tests/btrfs/242.out
> @@ -0,0 +1,2 @@
> +QA output created by 242
> +Silence is golden
>
Filipe Manana July 5, 2021, 8:45 a.m. UTC | #2
On Sun, Jul 4, 2021 at 12:24 PM Anand Jain <anand.jain@oracle.com> wrote:
>
> Create a degraded btrfs filesystem and run fstrim on it.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  tests/btrfs/242     | 49 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/242.out |  2 ++
>  2 files changed, 51 insertions(+)
>  create mode 100755 tests/btrfs/242
>  create mode 100644 tests/btrfs/242.out
>
> diff --git a/tests/btrfs/242 b/tests/btrfs/242
> new file mode 100755
> index 000000000000..e946ee6ac7c2
> --- /dev/null
> +++ b/tests/btrfs/242
> @@ -0,0 +1,49 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2021 Oracle. All Rights Reserved.
> +#
> +# FS QA Test 242
> +#
> +# Test that fstrim can run on the degraded filesystem
> +#   Kernel requires fix for the null pointer deref in btrfs_trim_fs()
> +#     [patch] btrfs: check for missing device in btrfs_trim_fs
> +
> +
> +. ./common/preamble
> +_begin_fstest auto quick replace trim
> +
> +# Import common functions.
> +. ./common/filter
> +
> +# real QA test starts here
> +_supported_fs btrfs
> +_require_btrfs_forget_or_module_loadable
> +_require_scratch_dev_pool 2
> +#_require_command "$WIPEFS_PROG" wipefs
> +
> +_scratch_dev_pool_get 2
> +dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
> +
> +_scratch_pool_mkfs "-m raid1 -d raid1"
> +_scratch_mount
> +_require_batched_discard $SCRATCH_MNT
> +
> +# Add a test file with some data.
> +$XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo > /dev/null

What's the point of adding this file (which you copied exactly from
btrfs/223) if it's not needed to trigger the bug and it's not used
anywhere in the test?
Or at the very least, check that reading it after the fstrim returns
the correct data, as it might help prevent some regression in the
future.

Thanks.

> +
> +# Unmount the filesystem.
> +_scratch_unmount
> +
> +# Mount the filesystem in degraded mode
> +_btrfs_forget_or_module_reload
> +_mount -o degraded $dev1 $SCRATCH_MNT
> +
> +# Run fstrim
> +$FSTRIM_PROG $SCRATCH_MNT
> +
> +_scratch_dev_pool_put
> +
> +echo Silence is golden
> +
> +status=0
> +exit
> diff --git a/tests/btrfs/242.out b/tests/btrfs/242.out
> new file mode 100644
> index 000000000000..a46d77702f23
> --- /dev/null
> +++ b/tests/btrfs/242.out
> @@ -0,0 +1,2 @@
> +QA output created by 242
> +Silence is golden
> --
> 2.27.0
>
Filipe Manana July 5, 2021, 8:50 a.m. UTC | #3
On Sun, Jul 4, 2021 at 12:24 PM Anand Jain <anand.jain@oracle.com> wrote:
>
> Create a degraded btrfs filesystem and run fstrim on it.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  tests/btrfs/242     | 49 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/242.out |  2 ++
>  2 files changed, 51 insertions(+)
>  create mode 100755 tests/btrfs/242
>  create mode 100644 tests/btrfs/242.out
>
> diff --git a/tests/btrfs/242 b/tests/btrfs/242
> new file mode 100755
> index 000000000000..e946ee6ac7c2
> --- /dev/null
> +++ b/tests/btrfs/242
> @@ -0,0 +1,49 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2021 Oracle. All Rights Reserved.
> +#
> +# FS QA Test 242
> +#
> +# Test that fstrim can run on the degraded filesystem
> +#   Kernel requires fix for the null pointer deref in btrfs_trim_fs()
> +#     [patch] btrfs: check for missing device in btrfs_trim_fs
> +
> +
> +. ./common/preamble
> +_begin_fstest auto quick replace trim

Also, this does not belong to the 'replace' group (again copied from
btrfs/223 it seems).

Thanks.

> +
> +# Import common functions.
> +. ./common/filter
> +
> +# real QA test starts here
> +_supported_fs btrfs
> +_require_btrfs_forget_or_module_loadable
> +_require_scratch_dev_pool 2
> +#_require_command "$WIPEFS_PROG" wipefs
> +
> +_scratch_dev_pool_get 2
> +dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
> +
> +_scratch_pool_mkfs "-m raid1 -d raid1"
> +_scratch_mount
> +_require_batched_discard $SCRATCH_MNT
> +
> +# Add a test file with some data.
> +$XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo > /dev/null
> +
> +# Unmount the filesystem.
> +_scratch_unmount
> +
> +# Mount the filesystem in degraded mode
> +_btrfs_forget_or_module_reload
> +_mount -o degraded $dev1 $SCRATCH_MNT
> +
> +# Run fstrim
> +$FSTRIM_PROG $SCRATCH_MNT
> +
> +_scratch_dev_pool_put
> +
> +echo Silence is golden
> +
> +status=0
> +exit
> diff --git a/tests/btrfs/242.out b/tests/btrfs/242.out
> new file mode 100644
> index 000000000000..a46d77702f23
> --- /dev/null
> +++ b/tests/btrfs/242.out
> @@ -0,0 +1,2 @@
> +QA output created by 242
> +Silence is golden
> --
> 2.27.0
>
Anand Jain July 5, 2021, 10:04 a.m. UTC | #4
On 05/07/2021 16:50, Filipe Manana wrote:
> On Sun, Jul 4, 2021 at 12:24 PM Anand Jain <anand.jain@oracle.com> wrote:
>>
>> Create a degraded btrfs filesystem and run fstrim on it.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   tests/btrfs/242     | 49 +++++++++++++++++++++++++++++++++++++++++++++
>>   tests/btrfs/242.out |  2 ++
>>   2 files changed, 51 insertions(+)
>>   create mode 100755 tests/btrfs/242
>>   create mode 100644 tests/btrfs/242.out
>>
>> diff --git a/tests/btrfs/242 b/tests/btrfs/242
>> new file mode 100755
>> index 000000000000..e946ee6ac7c2
>> --- /dev/null
>> +++ b/tests/btrfs/242
>> @@ -0,0 +1,49 @@
>> +#! /bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +# Copyright (C) 2021 Oracle. All Rights Reserved.
>> +#
>> +# FS QA Test 242
>> +#
>> +# Test that fstrim can run on the degraded filesystem
>> +#   Kernel requires fix for the null pointer deref in btrfs_trim_fs()
>> +#     [patch] btrfs: check for missing device in btrfs_trim_fs
>> +
>> +
>> +. ./common/preamble
>> +_begin_fstest auto quick replace trim
> 
> Also, this does not belong to the 'replace' group (again copied from
> btrfs/223 it seems).

  Oh no. Will fix it. Thanks.

- Anand

> 
> Thanks.
> 
>> +
>> +# Import common functions.
>> +. ./common/filter
>> +
>> +# real QA test starts here
>> +_supported_fs btrfs
>> +_require_btrfs_forget_or_module_loadable
>> +_require_scratch_dev_pool 2
>> +#_require_command "$WIPEFS_PROG" wipefs
>> +
>> +_scratch_dev_pool_get 2
>> +dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
>> +
>> +_scratch_pool_mkfs "-m raid1 -d raid1"
>> +_scratch_mount
>> +_require_batched_discard $SCRATCH_MNT
>> +
>> +# Add a test file with some data.
>> +$XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo > /dev/null
>> +
>> +# Unmount the filesystem.
>> +_scratch_unmount
>> +
>> +# Mount the filesystem in degraded mode
>> +_btrfs_forget_or_module_reload
>> +_mount -o degraded $dev1 $SCRATCH_MNT
>> +
>> +# Run fstrim
>> +$FSTRIM_PROG $SCRATCH_MNT
>> +
>> +_scratch_dev_pool_put
>> +
>> +echo Silence is golden
>> +
>> +status=0
>> +exit
>> diff --git a/tests/btrfs/242.out b/tests/btrfs/242.out
>> new file mode 100644
>> index 000000000000..a46d77702f23
>> --- /dev/null
>> +++ b/tests/btrfs/242.out
>> @@ -0,0 +1,2 @@
>> +QA output created by 242
>> +Silence is golden
>> --
>> 2.27.0
>>
> 
>
Anand Jain July 5, 2021, 10:20 a.m. UTC | #5
On 05/07/2021 16:45, Filipe Manana wrote:
> On Sun, Jul 4, 2021 at 12:24 PM Anand Jain <anand.jain@oracle.com> wrote:
>>
>> Create a degraded btrfs filesystem and run fstrim on it.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   tests/btrfs/242     | 49 +++++++++++++++++++++++++++++++++++++++++++++
>>   tests/btrfs/242.out |  2 ++
>>   2 files changed, 51 insertions(+)
>>   create mode 100755 tests/btrfs/242
>>   create mode 100644 tests/btrfs/242.out
>>
>> diff --git a/tests/btrfs/242 b/tests/btrfs/242
>> new file mode 100755
>> index 000000000000..e946ee6ac7c2
>> --- /dev/null
>> +++ b/tests/btrfs/242
>> @@ -0,0 +1,49 @@
>> +#! /bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +# Copyright (C) 2021 Oracle. All Rights Reserved.
>> +#
>> +# FS QA Test 242
>> +#
>> +# Test that fstrim can run on the degraded filesystem
>> +#   Kernel requires fix for the null pointer deref in btrfs_trim_fs()
>> +#     [patch] btrfs: check for missing device in btrfs_trim_fs
>> +
>> +
>> +. ./common/preamble
>> +_begin_fstest auto quick replace trim
>> +
>> +# Import common functions.
>> +. ./common/filter
>> +
>> +# real QA test starts here
>> +_supported_fs btrfs
>> +_require_btrfs_forget_or_module_loadable
>> +_require_scratch_dev_pool 2
>> +#_require_command "$WIPEFS_PROG" wipefs
>> +
>> +_scratch_dev_pool_get 2
>> +dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
>> +
>> +_scratch_pool_mkfs "-m raid1 -d raid1"
>> +_scratch_mount
>> +_require_batched_discard $SCRATCH_MNT
>> +
>> +# Add a test file with some data.
>> +$XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo > /dev/null
> 
> What's the point of adding this file (which you copied exactly from
> btrfs/223) if it's not needed to trigger the bug and it's not used
> anywhere in the test?
> Or at the very least, check that reading it after the fstrim returns
> the correct data, as it might help prevent some regression in the
> future.

There is no need for data to trigger the bug. I wanted some data as 
practically it is. I like the idea to prevent some regression in the 
future- I will add code to check if data is correct after fstrim.

Thanks, Anand

> 
> Thanks.
> 
>> +
>> +# Unmount the filesystem.
>> +_scratch_unmount
>> +
>> +# Mount the filesystem in degraded mode
>> +_btrfs_forget_or_module_reload
>> +_mount -o degraded $dev1 $SCRATCH_MNT
>> +
>> +# Run fstrim
>> +$FSTRIM_PROG $SCRATCH_MNT
>> +
>> +_scratch_dev_pool_put
>> +
>> +echo Silence is golden
>> +
>> +status=0
>> +exit
>> diff --git a/tests/btrfs/242.out b/tests/btrfs/242.out
>> new file mode 100644
>> index 000000000000..a46d77702f23
>> --- /dev/null
>> +++ b/tests/btrfs/242.out
>> @@ -0,0 +1,2 @@
>> +QA output created by 242
>> +Silence is golden
>> --
>> 2.27.0
>>
> 
>
diff mbox series

Patch

diff --git a/tests/btrfs/242 b/tests/btrfs/242
new file mode 100755
index 000000000000..e946ee6ac7c2
--- /dev/null
+++ b/tests/btrfs/242
@@ -0,0 +1,49 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021 Oracle. All Rights Reserved.
+#
+# FS QA Test 242
+#
+# Test that fstrim can run on the degraded filesystem
+#   Kernel requires fix for the null pointer deref in btrfs_trim_fs()
+#     [patch] btrfs: check for missing device in btrfs_trim_fs
+
+
+. ./common/preamble
+_begin_fstest auto quick replace trim
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+_supported_fs btrfs
+_require_btrfs_forget_or_module_loadable
+_require_scratch_dev_pool 2
+#_require_command "$WIPEFS_PROG" wipefs
+
+_scratch_dev_pool_get 2
+dev1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{ print $1 }')
+
+_scratch_pool_mkfs "-m raid1 -d raid1"
+_scratch_mount
+_require_batched_discard $SCRATCH_MNT
+
+# Add a test file with some data.
+$XFS_IO_PROG -f -c "pwrite -S 0xab 0 10M" $SCRATCH_MNT/foo > /dev/null
+
+# Unmount the filesystem.
+_scratch_unmount
+
+# Mount the filesystem in degraded mode 
+_btrfs_forget_or_module_reload
+_mount -o degraded $dev1 $SCRATCH_MNT
+
+# Run fstrim
+$FSTRIM_PROG $SCRATCH_MNT
+
+_scratch_dev_pool_put
+
+echo Silence is golden
+
+status=0
+exit
diff --git a/tests/btrfs/242.out b/tests/btrfs/242.out
new file mode 100644
index 000000000000..a46d77702f23
--- /dev/null
+++ b/tests/btrfs/242.out
@@ -0,0 +1,2 @@ 
+QA output created by 242
+Silence is golden