Skip to contentSkip to conversation

common/btrfs: avoid reinitialization of unsupported profile array

PATCH In review David Disseldorp 3 participants 3 messages Jan 11, 2023 – Feb 9, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/btrfs: avoid reinitialization of unsupported profile array

The _btrfs_get_profile_configs() unsupported array doesn't change between configs, so avoid reinitializing it on each loop iteration.

---
 common/btrfs | 66 ++++++++++++++++++++++++++--------------------------
 1 file changed, 33 insertions(+), 33 deletions(-)
common/btrfs +33 -33
index ee673a93..9531c914 100644
@@ -201,6 +201,39 @@ _btrfs_get_profile_configs()
 		return
 	fi
 
+	local unsupported=()
+	if [ "$1" == "replace" ]; then
+		# We can't do replace with these profiles because they
+		# imply only one device ($SCRATCH_DEV), and we need to
+		# keep $SCRATCH_DEV around for _scratch_mount
+		# and _check_scratch_fs.
+		unsupported+=(
+			"dup"
+		)
+	elif [ "$1" == "replace-missing" ]; then
+		# We can't replace missing devices with these profiles
+		# because there isn't enough redundancy.
+		unsupported+=(
+			"single"
+			"dup"
+			"raid0"
+		)
+	fi
+
+	if _scratch_btrfs_is_zoned; then
+		# Zoned btrfs only supports SINGLE profile
+		unsupported+=(
+			"dup"
+			"raid0"
+			"raid1"
+			"raid1c3"
+			"raid1c4"
+			"raid10"
+			"raid5"
+			"raid6"
+		)
+	fi
+
 	if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
 		# Default configurations to test.
 		local configs=(
@@ -222,39 +255,6 @@ _btrfs_get_profile_configs()
 	for cfg in "${configs[@]}"; do
 		local supported=true
 		local profiles=(${cfg/:/ })
-		if [ "$1" == "replace" ]; then
-			# We can't do replace with these profiles because they
-			# imply only one device ($SCRATCH_DEV), and we need to
-			# keep $SCRATCH_DEV around for _scratch_mount
-			# and _check_scratch_fs.
-			local unsupported=(
-				"dup"
-			)
-		elif [ "$1" == "replace-missing" ]; then
-			# We can't replace missing devices with these profiles
-			# because there isn't enough redundancy.
-			local unsupported=(
-				"single"
-				"dup"
-				"raid0"
-			)
-		else
-			local unsupported=()
-		fi
-
-		if _scratch_btrfs_is_zoned; then
-			# Zoned btrfs only supports SINGLE profile
-			unsupported+=(
-				"dup"
-				"raid0"
-				"raid1"
-				"raid1c3"
-				"raid1c4"
-				"raid10"
-				"raid5"
-				"raid6"
-			)
-		fi
 
 		for unsupp in "${unsupported[@]}"; do
 			if [ "${profiles[0]}" == "$unsupp" -o "${profiles[1]}" == "$unsupp" ]; then
Signature · 1 line
2.35.3
#1 lore raw

Am 11.01.23 um 11:58 schrieb David Disseldorp:

Quoted 82 lines

The _btrfs_get_profile_configs() unsupported array doesn't change between configs, so avoid reinitializing it on each loop iteration.

---
  common/btrfs | 66 ++++++++++++++++++++++++++--------------------------
  1 file changed, 33 insertions(+), 33 deletions(-)
common/btrfs +33 -26
index ee673a93..9531c914 100644
@@ -201,6 +201,39 @@ _btrfs_get_profile_configs()
  		return
  	fi
 
+	local unsupported=()
+	if [ "$1" == "replace" ]; then
+		# We can't do replace with these profiles because they
+		# imply only one device ($SCRATCH_DEV), and we need to
+		# keep $SCRATCH_DEV around for _scratch_mount
+		# and _check_scratch_fs.
+		unsupported+=(
+			"dup"
+		)
+	elif [ "$1" == "replace-missing" ]; then
+		# We can't replace missing devices with these profiles
+		# because there isn't enough redundancy.
+		unsupported+=(
+			"single"
+			"dup"
+			"raid0"
+		)
+	fi
+
+	if _scratch_btrfs_is_zoned; then
+		# Zoned btrfs only supports SINGLE profile
+		unsupported+=(
+			"dup"
+			"raid0"
+			"raid1"
+			"raid1c3"
+			"raid1c4"
+			"raid10"
+			"raid5"
+			"raid6"
+		)
+	fi
+
  	if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
  		# Default configurations to test.
  		local configs=(
@@ -222,39 +255,6 @@ _btrfs_get_profile_configs()
  	for cfg in "${configs[@]}"; do
  		local supported=true
  		local profiles=(${cfg/:/ })
-		if [ "$1" == "replace" ]; then
-			# We can't do replace with these profiles because they
-			# imply only one device ($SCRATCH_DEV), and we need to
-			# keep $SCRATCH_DEV around for _scratch_mount
-			# and _check_scratch_fs.
-			local unsupported=(
-				"dup"
-			)
-		elif [ "$1" == "replace-missing" ]; then
-			# We can't replace missing devices with these profiles
-			# because there isn't enough redundancy.
-			local unsupported=(
-				"single"
-				"dup"
-				"raid0"
-			)
-		else
-			local unsupported=()
-		fi
-
-		if _scratch_btrfs_is_zoned; then
-			# Zoned btrfs only supports SINGLE profile
-			unsupported+=(
-				"dup"
-				"raid0"
-				"raid1"

common/btrfs _btrfs_get_profile_configs() · line 260

Quoted 10 lines
common/btrfs +0 -7
-				"raid1c3"
-				"raid1c4"
-				"raid10"
-				"raid5"
-				"raid6"
-			)
-		fi
 
  		for unsupp in "${unsupported[@]}"; do
  			if [ "${profiles[0]}" == "$unsupp" -o "${profiles[1]}" == "$unsupp" ]; then

This seems like a good change.

It only makes sense and in my local testing it reduced btrfs test run time by 10-17 seconds overall.

Not a huge amount, but every little helps.

Signature · 8 lines
Gabriel Niebler (he/him/his)
Senior Full-Stack Web Developer

SUSE

[email protected]

www.suse.com
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Disseldorp
Quoted 5 lines · David Disseldorp

The _btrfs_get_profile_configs() unsupported array doesn't change between configs, so avoid reinitializing it on each loop iteration.

---

Good to me,

Quoted 90 lines
 common/btrfs | 66 ++++++++++++++++++++++++++--------------------------
 1 file changed, 33 insertions(+), 33 deletions(-)
common/btrfs +33 -33
index ee673a93..9531c914 100644
@@ -201,6 +201,39 @@ _btrfs_get_profile_configs()
 		return
 	fi
 
+	local unsupported=()
+	if [ "$1" == "replace" ]; then
+		# We can't do replace with these profiles because they
+		# imply only one device ($SCRATCH_DEV), and we need to
+		# keep $SCRATCH_DEV around for _scratch_mount
+		# and _check_scratch_fs.
+		unsupported+=(
+			"dup"
+		)
+	elif [ "$1" == "replace-missing" ]; then
+		# We can't replace missing devices with these profiles
+		# because there isn't enough redundancy.
+		unsupported+=(
+			"single"
+			"dup"
+			"raid0"
+		)
+	fi
+
+	if _scratch_btrfs_is_zoned; then
+		# Zoned btrfs only supports SINGLE profile
+		unsupported+=(
+			"dup"
+			"raid0"
+			"raid1"
+			"raid1c3"
+			"raid1c4"
+			"raid10"
+			"raid5"
+			"raid6"
+		)
+	fi
+
 	if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
 		# Default configurations to test.
 		local configs=(
@@ -222,39 +255,6 @@ _btrfs_get_profile_configs()
 	for cfg in "${configs[@]}"; do
 		local supported=true
 		local profiles=(${cfg/:/ })
-		if [ "$1" == "replace" ]; then
-			# We can't do replace with these profiles because they
-			# imply only one device ($SCRATCH_DEV), and we need to
-			# keep $SCRATCH_DEV around for _scratch_mount
-			# and _check_scratch_fs.
-			local unsupported=(
-				"dup"
-			)
-		elif [ "$1" == "replace-missing" ]; then
-			# We can't replace missing devices with these profiles
-			# because there isn't enough redundancy.
-			local unsupported=(
-				"single"
-				"dup"
-				"raid0"
-			)
-		else
-			local unsupported=()
-		fi
-
-		if _scratch_btrfs_is_zoned; then
-			# Zoned btrfs only supports SINGLE profile
-			unsupported+=(
-				"dup"
-				"raid0"
-				"raid1"
-				"raid1c3"
-				"raid1c4"
-				"raid10"
-				"raid5"
-				"raid6"
-			)
-		fi
 
 		for unsupp in "${unsupported[@]}"; do
 			if [ "${profiles[0]}" == "$unsupp" -o "${profiles[1]}" == "$unsupp" ]; then
Signature · 1 line
2.35.3