diff mbox series

[v2,2/3] common/attr: fix MAX_ATTRVAL_SIZE for XFS, UDF, Btrfs and NFS

Message ID 20220412105001.14325-3-ddiss@suse.de (mailing list archive)
State New, archived
Headers show
Series : generic/020: fix MAX_ATTRVAL_SIZE values | expand

Commit Message

David Disseldorp April 12, 2022, 10:50 a.m. UTC
As found by Dave Chinner, fff4359d ("020: make this xattr test generic")
unintentionally changed the long attribute value length from 100K to 64
*bytes* for XFS, UDF and Btrfs.
Update XFS and UDF to use 64K MAX_ATTRVAL_SIZE value. For Btrfs, use the
nodesize, xattr length and tree entry overhead sizes to calculate the
maximum.
NFS doesn't provide a way to find out the MAX_ATTRVAL_SIZE for the
underlying filesystem on the server, so just use a rough 1K limit.

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 common/attr | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/common/attr b/common/attr
index a80b10a1..1e1c8f6e 100644
--- a/common/attr
+++ b/common/attr
@@ -328,20 +328,32 @@  _attr_get_max()
 
 	export MAX_ATTRS
 
-	# Set max attr value size based on fs type
+	# Set max attr value size in bytes based on fs type
 	case "$FSTYP" in
-	xfs|udf|btrfs)
-		MAX_ATTRVAL_SIZE=64
+	btrfs)
+		_require_btrfs_command inspect-internal dump-super
+		local ns=$($BTRFS_UTIL_PROG inspect-internal dump-super \
+				$TEST_DEV | sed -n 's/nodesize\s*\(.*\)/\1/p')
+		[ -n "$ns" ] || _fail "failed to obtain nodesize"
+		# max == nodesize - sizeof(struct btrfs_header)
+		#		- sizeof(struct btrfs_item)
+		#		- sizeof(struct btrfs_dir_item) - name_len
+		MAX_ATTRVAL_SIZE=$(( $ns - 156 - $max_attrval_namelen ))
 		;;
 	pvfs2)
 		MAX_ATTRVAL_SIZE=8192
 		;;
-	9p|ceph|nfs)
+	xfs|udf|9p|ceph)
 		MAX_ATTRVAL_SIZE=65536
 		;;
 	bcachefs)
 		MAX_ATTRVAL_SIZE=1024
 		;;
+	nfs)
+		# NFS doesn't provide a way to find out the MAX_ATTRVAL_SIZE for
+		# the underlying filesystem, so just use the lowest value above.
+		MAX_ATTRVAL_SIZE=1024
+		;;
 	*)
 		# Assume max ~1 block of attrs
 		BLOCK_SIZE=`_get_block_size $TEST_DIR`