Skip to contentSkip to conversation

fstests: btrfs: test setting compression via xattr on nodatacow files

PATCH Superseded Chung-Chiang Cheng 4 participants 7 messages Apr 18, 2022 – Apr 22, 2022 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fstests: btrfs: test setting compression via xattr on nodatacow files

Compression and nodatacow are mutually exclusive. Besides ioctl, there is another way to setting compression via xattrs, and shouldn't produce invalid combinations.

---
 tests/btrfs/264     | 76 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/264.out | 15 +++++++++
 2 files changed, 91 insertions(+)
 create mode 100755 tests/btrfs/264
 create mode 100644 tests/btrfs/264.out
tests/btrfs/264 new file +76 -0
new file mode 100755
index 000000000000..42bfcd4f93a0
@@ -0,0 +1,76 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Synology Inc. All Rights Reserved.
+#
+# FS QA Test No. 264
+#
+# Compression and nodatacow are mutually exclusive. Besides ioctl, there
+# is another way to setting compression via xattrs, and shouldn't produce
+# invalid combinations.
+#
+# To prevent mix any compression-related options with nodatacow, FS_NOCOMP_FL
+# is also rejected by ioctl as well as FS_COMPR_FL on nodatacow files. To
+# align with it, no and none are also unacceptable in this test.
+#
+# The regression is fixed by a patch with the following subject:
+#   btrfs: do not allow compression on nodatacow files
+#
+. ./common/preamble
+_begin_fstest auto quick compress attr
+
+# Import common functions.
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+
+_supported_fs btrfs
+_require_scratch
+_require_chattr C
+_require_chattr c
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+#
+# DATACOW
+#
+test_file="$SCRATCH_MNT/foo"
+touch "$test_file"
+$CHATTR_PROG -C "$test_file"
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+$SETFATTR_PROG -n "btrfs.compression" -v zlib "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v no   "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v lzo  "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v none "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v zstd "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+
+#
+# NODATACOW
+#
+test_file="$SCRATCH_MNT/bar"
+touch "$test_file"
+$CHATTR_PROG +C "$test_file"
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# all valid compression type are not allowed on nodatacow files
+$SETFATTR_PROG -n "btrfs.compression" -v zlib "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v lzo  "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v zstd "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# no/none are also not allowed on nodatacow files
+$SETFATTR_PROG -n "btrfs.compression" -v no   "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v none "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# success, all done
+status=0
+exit
tests/btrfs/264.out new file +15 -0
new file mode 100644
index 000000000000..82c551411411
@@ -0,0 +1,15 @@
+QA output created by 264
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/bar No_COW
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+SCRATCH_MNT/bar No_COW
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+SCRATCH_MNT/bar No_COW
Signature · 1 line
2.34.1
#1 lore raw
Quoted 51 lines · Chung-Chiang Cheng

Compression and nodatacow are mutually exclusive. Besides ioctl, there is another way to setting compression via xattrs, and shouldn't produce invalid combinations.

---
  tests/btrfs/264     | 76 +++++++++++++++++++++++++++++++++++++++++++++
  tests/btrfs/264.out | 15 +++++++++
  2 files changed, 91 insertions(+)

create mode 100755 tests/btrfs/264
create mode 100644 tests/btrfs/264.out

tests/btrfs/264 new file +33 -0
new file mode 100755
index 000000000000..42bfcd4f93a0
@@ -0,0 +1,76 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Synology Inc. All Rights Reserved.
+#
+# FS QA Test No. 264
+#
+# Compression and nodatacow are mutually exclusive. Besides ioctl, there
+# is another way to setting compression via xattrs, and shouldn't produce
+# invalid combinations.
+#
+# To prevent mix any compression-related options with nodatacow, FS_NOCOMP_FL
+# is also rejected by ioctl as well as FS_COMPR_FL on nodatacow files. To
+# align with it, no and none are also unacceptable in this test.
+#
+# The regression is fixed by a patch with the following subject:
+#   btrfs: do not allow compression on nodatacow files
+#
+. ./common/preamble
+_begin_fstest auto quick compress attr
+
+# Import common functions.
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+
+_supported_fs btrfs
+_require_scratch
+_require_chattr C
+_require_chattr c
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount

tests/btrfs/264 line 43

Quoted 10 lines
tests/btrfs/264 new file +10 -0
+
+#
+# DATACOW
+#
+test_file="$SCRATCH_MNT/foo"
+touch "$test_file"
+$CHATTR_PROG -C "$test_file"
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+$SETFATTR_PROG -n "btrfs.compression" -v zlib "$test_file" |& _filter_scratch

In my testing setfattr doesn't produce any output, so why the _filter_scratch ?

tests/btrfs/264 line 44

Quoted 1 line
tests/btrfs/264 new file +1 -0
+$LSATTR_PROG -l "$test_file" | _filter_scratch

This (as all other lsattr lines) fail for me because of difference in output - in your golden file there is a single space char between the filename and its state whilst lsattr produces a number of spaces. So in addition to filter_scratch this needs _filter_spaces as well :

+$LSATTR_PROG -l "$test_file" | _filter_scratch | _filter_spaces

Quoted 53 lines
tests/btrfs/264 new file +32 -0
+$SETFATTR_PROG -n "btrfs.compression" -v no   "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v lzo  "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v none "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v zstd "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+
+#
+# NODATACOW
+#
+test_file="$SCRATCH_MNT/bar"
+touch "$test_file"
+$CHATTR_PROG +C "$test_file"
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# all valid compression type are not allowed on nodatacow files
+$SETFATTR_PROG -n "btrfs.compression" -v zlib "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v lzo  "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v zstd "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# no/none are also not allowed on nodatacow files
+$SETFATTR_PROG -n "btrfs.compression" -v no   "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v none "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# success, all done
+status=0
+exit
tests/btrfs/264.out new file +15 -0
new file mode 100644
index 000000000000..82c551411411
@@ -0,0 +1,15 @@
+QA output created by 264
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/bar No_COW
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+SCRATCH_MNT/bar No_COW
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+SCRATCH_MNT/bar No_COW
#2 lore raw
Quoted 62 lines · Nikolay Borisov
Quoted 59 lines · Chung-Chiang Cheng

Compression and nodatacow are mutually exclusive. Besides ioctl, there is another way to setting compression via xattrs, and shouldn't produce invalid combinations.

---
  tests/btrfs/264     | 76 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/264.out | 15 +++++++++

  2 files changed, 91 insertions(+)

  create mode 100755 tests/btrfs/264
  create mode 100644 tests/btrfs/264.out

tests/btrfs/264 new file +8 -0
new file mode 100755
index 000000000000..42bfcd4f93a0
@@ -0,0 +1,76 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Synology Inc. All Rights Reserved.
+#
+# FS QA Test No. 264
+#
+# Compression and nodatacow are mutually exclusive. Besides ioctl, there
+# is another way to setting compression via xattrs, and shouldn't 

produce

tests/btrfs/264 new file +3 -0
+# invalid combinations.
+#
+# To prevent mix any compression-related options with nodatacow, 

FS_NOCOMP_FL
+# is also rejected by ioctl as well as FS_COMPR_FL on nodatacow files. To

tests/btrfs/264 new file +26 -0
+# align with it, no and none are also unacceptable in this test.
+#
+# The regression is fixed by a patch with the following subject:
+#   btrfs: do not allow compression on nodatacow files
+#
+. ./common/preamble
+_begin_fstest auto quick compress attr
+
+# Import common functions.
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+
+_supported_fs btrfs
+_require_scratch
+_require_chattr C
+_require_chattr c
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+#
+# DATACOW
+#
+test_file="$SCRATCH_MNT/foo"
Quoted 8 lines
Quoted 6 lines
tests/btrfs/264 new file +5 -0
+touch "$test_file"
+$CHATTR_PROG -C "$test_file"
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+$SETFATTR_PROG -n "btrfs.compression" -v zlib "$test_file" |& 

_filter_scratch

In my testing setfattr doesn't produce any output, so why the _filter_scratch ?

nit: Ah right, that applies to those setfattr calls that are expected to fail when doing the nodatacow ops. So perhaps you could only do |& on the setfattr calls which are expected to fail.

<snip>

SO the main thing which remains to fix is calling the _filter_spaces to ensure the test succeeds.

#3 lore raw
In reply to Nikolay Borisov

Hi Nikolay,

Quoted 7 lines

This (as all other lsattr lines) fail for me because of difference in output - in your golden file there is a single space char between the filename and its state whilst lsattr produces a number of spaces. So in addition to filter_scratch this needs _filter_spaces as well :

+$LSATTR_PROG -l "$test_file" | _filter_scratch | _filter_spaces

Thanks for your comment. I did not notice the space issue before. From the output of Filipe's test, there is also only one space between filename and its state. This is the same as my test results. I have no idea which procedure these space were eliminated, but I think it is reasonable to add a space filter here.

Thanks.

#4 lore raw
In reply to Chung-Chiang Cheng
Quoted 3 lines · Chung-Chiang Cheng

Compression and nodatacow are mutually exclusive. Besides ioctl, there is another way to setting compression via xattrs, and shouldn't produce invalid combinations.

Hi Chung-Chiang,

Thanks for taking the time to write and submit the test. Some inlined comments below.

Quoted 35 lines
---
 tests/btrfs/264     | 76 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/264.out | 15 +++++++++
 2 files changed, 91 insertions(+)
 create mode 100755 tests/btrfs/264
 create mode 100644 tests/btrfs/264.out
tests/btrfs/264 new file +20 -0
new file mode 100755
index 000000000000..42bfcd4f93a0
@@ -0,0 +1,76 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Synology Inc. All Rights Reserved.
+#
+# FS QA Test No. 264
+#
+# Compression and nodatacow are mutually exclusive. Besides ioctl, there
+# is another way to setting compression via xattrs, and shouldn't produce
+# invalid combinations.
+#
+# To prevent mix any compression-related options with nodatacow, FS_NOCOMP_FL
+# is also rejected by ioctl as well as FS_COMPR_FL on nodatacow files. To
+# align with it, no and none are also unacceptable in this test.
+#
+# The regression is fixed by a patch with the following subject:
+#   btrfs: do not allow compression on nodatacow files
+#
+. ./common/preamble
+_begin_fstest auto quick compress attr
+

tests/btrfs/264 line 30

Quoted 10 lines
tests/btrfs/264 new file +10 -0
+# Import common functions.
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+
+_supported_fs btrfs
+_require_scratch
+_require_chattr C
+_require_chattr c

This require, for chattr c, is not needed, since the test never calls chattr with +c or -c.

It also misses a call to:

_require_attrs

Due to the calls to setfattr and lsattr.

Quoted 57 lines
tests/btrfs/264 new file +46 -0
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+#
+# DATACOW
+#
+test_file="$SCRATCH_MNT/foo"
+touch "$test_file"
+$CHATTR_PROG -C "$test_file"
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+$SETFATTR_PROG -n "btrfs.compression" -v zlib "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v no   "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v lzo  "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v none "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v zstd "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+
+#
+# NODATACOW
+#
+test_file="$SCRATCH_MNT/bar"
+touch "$test_file"
+$CHATTR_PROG +C "$test_file"
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# all valid compression type are not allowed on nodatacow files
+$SETFATTR_PROG -n "btrfs.compression" -v zlib "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v lzo  "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v zstd "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# no/none are also not allowed on nodatacow files
+$SETFATTR_PROG -n "btrfs.compression" -v no   "$test_file" |& _filter_scratch
+$SETFATTR_PROG -n "btrfs.compression" -v none "$test_file" |& _filter_scratch
+$LSATTR_PROG -l "$test_file" | _filter_scratch
+
+# success, all done
+status=0
+exit
tests/btrfs/264.out new file +5 -0
new file mode 100644
index 000000000000..82c551411411
@@ -0,0 +1,15 @@
+QA output created by 264
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested

tests/btrfs/264.out line 15

Quoted 10 lines
tests/btrfs/264.out new file +10 -0
+SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Compression_Requested
+SCRATCH_MNT/bar No_COW
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+SCRATCH_MNT/bar No_COW
+setfattr: SCRATCH_MNT/bar: Invalid argument
+setfattr: SCRATCH_MNT/bar: Invalid argument
+SCRATCH_MNT/bar No_COW

This is all fine, and I appreciate that you had special care to make sure the test works even if one runs the test with "-o compress" or "-o nodatacow" set in MOUNT_OPTIONS.

However the test is based on some pre-5.14 kernel, presumably one of the Synology forks, and because of that it fails even after applying the btrfs fix on a recent kernel:

root 15:43:45 /home/fdmanana/git/hub/xfstests (master)> ./check btrfs/264

FSTYP         -- btrfs
PLATFORM      -- Linux/x86_64 debian9 5.18.0-rc2-btrfs-next-115 #1 SMP PREEMPT_DYNAMIC Wed Apr 13 09:17:09 WEST 2022
MKFS_OPTIONS  -- /dev/sdc

MOUNT_OPTIONS -- /dev/sdc /home/fdmanana/btrfs-tests/scratch_1

btrfs/264 - output mismatch (see /home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad)

    --- tests/btrfs/264.out	2022-04-19 14:49:03.845696283 +0100
    +++ /home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad	2022-04-19 15:43:50.413816742 +0100
    @@ -1,9 +1,9 @@
     QA output created by 264
     SCRATCH_MNT/foo ---
     SCRATCH_MNT/foo Compression_Requested
    -SCRATCH_MNT/foo ---
    +SCRATCH_MNT/foo Dont_Compress
     SCRATCH_MNT/foo Compression_Requested
    -SCRATCH_MNT/foo ---
    ...
    (Run 'diff -u /home/fdmanana/git/hub/xfstests/tests/btrfs/264.out /home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad'  to see the entire diff)

Ran: btrfs/264
Failures: btrfs/264
Failed 1 of 1 tests

root 15:43:50 /home/fdmanana/git/hub/xfstests (master)> diff -u /home/fdmanana/git/hub/xfstests/tests/btrfs/264.out /home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad

home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad renamed from home/fdmanana/git/hub/xfstests/tests/btrfs/264.out +2 -2
@@ -1,9 +1,9 @@
 QA output created by 264
 SCRATCH_MNT/foo ---
 SCRATCH_MNT/foo Compression_Requested
-SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Dont_Compress
 SCRATCH_MNT/foo Compression_Requested
-SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Dont_Compress
 SCRATCH_MNT/foo Compression_Requested
 SCRATCH_MNT/bar No_COW
 setfattr: SCRATCH_MNT/bar: Invalid argument

root 15:43:52 /home/fdmanana/git/hub/xfstests (master)>

The reason is that the test is expecting that setting "no" for the compression property removes the compression flag only, but does not set the NOCOMPRESS flag.

After 5.14, setting 'no' or 'none' clears the COMPRESS bit and sets the NOCOMPRESS bit. The change happened in this commit:

	commit 5548c8c6f55bf0097075b3720e14857e3272429f
	Author: David Sterba <[email protected]>
	Date:   Mon Jun 14 18:10:04 2021 +0200

	    btrfs: props: change how empty value is interpreted

So the test needs to be updated and tested on a recent kernel. Other than that, it looks fine to me.

Thanks.

Quoted 3 lines
Signature · 1 line
2.34.1
#5 lore raw

Hi Filipe,

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+_require_scratch
+_require_chattr C
+_require_chattr c

This require, for chattr c, is not needed, since the test never calls chattr with +c or -c.

Quoted 5 lines

It also misses a call to:

_require_attrs

Due to the calls to setfattr and lsattr.

Thanks for your notification. I'll fix these issues.

Quoted 17 lines

root 15:43:50 /home/fdmanana/git/hub/xfstests (master)> diff -u /home/fdmanana/git/hub/xfstests/tests/btrfs/264.out /home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad

home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad 2022-04-19 15:43:50.413816742 +0100 renamed from home/fdmanana/git/hub/xfstests/tests/btrfs/264.out 2022-04-19 14:49:03.845696283 +0100 +2 -2
@@ -1,9 +1,9 @@
 QA output created by 264
 SCRATCH_MNT/foo ---
 SCRATCH_MNT/foo Compression_Requested
-SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Dont_Compress
 SCRATCH_MNT/foo Compression_Requested
-SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Dont_Compress
 SCRATCH_MNT/foo Compression_Requested
 SCRATCH_MNT/bar No_COW
 setfattr: SCRATCH_MNT/bar: Invalid argument

root 15:43:52 /home/fdmanana/git/hub/xfstests (master)>

Quoted 2 lines

So the test needs to be updated and tested on a recent kernel. Other than that, it looks fine to me.

I can see why my output is different from yours. I tested this item with the latest upstream kernel, but my chattr comes from e2fsprogs-1.45.5, which does not yet support Dont_Compress. This test relies on a recent chattr, but _require_attrs does not check its version. In any case, I will send a v2 patch based on the latest chattr.

Thanks.

#6 lore raw
Quoted 35 lines · Chung-Chiang Cheng

Hi Filipe,

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+_require_scratch
+_require_chattr C
+_require_chattr c

This require, for chattr c, is not needed, since the test never calls chattr with +c or -c.

Quoted 5 lines

It also misses a call to:

_require_attrs

Due to the calls to setfattr and lsattr.

Thanks for your notification. I'll fix these issues.

Quoted 17 lines

root 15:43:50 /home/fdmanana/git/hub/xfstests (master)> diff -u /home/fdmanana/git/hub/xfstests/tests/btrfs/264.out /home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad

home/fdmanana/git/hub/xfstests/results//btrfs/264.out.bad 2022-04-19 15:43:50.413816742 +0100 renamed from home/fdmanana/git/hub/xfstests/tests/btrfs/264.out 2022-04-19 14:49:03.845696283 +0100 +2 -2
@@ -1,9 +1,9 @@
 QA output created by 264
 SCRATCH_MNT/foo ---
 SCRATCH_MNT/foo Compression_Requested
-SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Dont_Compress
 SCRATCH_MNT/foo Compression_Requested
-SCRATCH_MNT/foo ---
+SCRATCH_MNT/foo Dont_Compress
 SCRATCH_MNT/foo Compression_Requested
 SCRATCH_MNT/bar No_COW
 setfattr: SCRATCH_MNT/bar: Invalid argument

root 15:43:52 /home/fdmanana/git/hub/xfstests (master)>

Quoted 8 lines
Quoted 2 lines

So the test needs to be updated and tested on a recent kernel. Other than that, it looks fine to me.

I can see why my output is different from yours. I tested this item with the latest upstream kernel, but my chattr comes from e2fsprogs-1.45.5, which does not yet support Dont_Compress. This test relies on a recent chattr, but _require_attrs does not check its version. In any case, I will send a v2 patch based on the latest chattr.

Ah, that's interesting.
Indeed, I tested on a box with e2fsprogs 1.46.5. Switching to 1.45.5, the test passes after the btrfs fix is applied.

Looking at the e2fsprogs git history the behaviour changed in 1.46.2:

	commit 1f4a5aba59f39a33a84152b5ae3ec0a5657b12a1
	Author: Lennart Poettering <[email protected]>
	Date:   Thu Feb 25 12:33:35 2021 -0500

	    chattr/lsattr: expose FS_NOCOMP_FL (aka EXT2_NOCOMPR_FL)

Before that, lsattr never printed anything if the 'no compress' bit was set.

So generally test cases for fstests are written such that the test passes with any version of a particular tool, or it requires a minimum version to run (and is skipped on older versions).

We do the former approach using filters on the output of a tool, converting the output from an older version to match the output of a new version. Though in this case it would be tricky, because we really want to distinguish between having the 'no compress' bit set versus not having it set. And setting the value 'no' or 'none' for the btrfs.compression xattr, means setting the 'no compress' bit, therefore we want to verify it's set.

Making the test require e2fsprogs 1.46.2+, is tricky: lsattr has no '--version' flag to query the version, the only way would be to use distro specific commands to check the e2fsprogs version (e.g. "apt-cache policy e2fsprogs" on debian for example). The only way I can think of now is to add a require helper that tests the output of lsattr after setting 'no compress' - if it ouputs 'Dont_Compress', then it's 1.46.2+, otherwise something older.

That's complex, so a simple way would be to make the test fail if compression is still set after the setfattr, instead of relying on the exact output of lsattr. Something like this:

  $SETFATTR_PROG -n btrfs.compression -v no "$test_file" |& _filter_scratch
  $LSATTR_PROG -l "$test_file" | grep -q 'Compression_Requested'
  [ $? -eq 0 ] && echo "Compression is still set in the file"

With a comment somewhere before mentioning the behaviour change in e2fsprogs 1.46.2, and removing the lsattr output from the golden output file (264.out).

This way the test serves its purpose, to test we can not set both compress and nodatacow, and runs with any version of e2fsprogs. 1.46.2 is about 1 year old, and most enterprise distros are very likely using an older version - we want the test to be able to run on them.

Thanks.

Quoted 2 lines

Thanks.