Skip to contentSkip to conversation

common/rc: Remove impossible check

PATCH New Nikolay Borisov 2 participants 5 messages Nov 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/rc: Remove impossible check

config_ndevs is guaranteed to be defined in _scratch_dev_pool_get irrespective of whether SCRATCH_DEV_POOL is defined or not. If it's not then wc -w will simply return 0 which simply sets config_ndevs to 0. This causes 'typeset -p config_ndevs' to always succeeds and return 0 so the check for the return value of typeset is effectively a noop. Just remove it.

---
 common/rc | 5 -----
 1 file changed, 5 deletions(-)
common/rc +0 -5
index 7f693d3922e8..6f7467b574c2 100644
@@ -921,11 +921,6 @@ _scratch_dev_pool_get()
 	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
 	local -a devs="( $SCRATCH_DEV_POOL )"
 
-	typeset -p config_ndevs >/dev/null 2>&1
-	if [ $? -ne 0 ]; then
-		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
-	fi
-
 	if [ $config_ndevs -lt $test_ndevs ]; then
 		_notrun "Need at least test requested number of ndevs $test_ndevs"
 	fi
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 common/rc: Fix check for SCRATCH_DEV_POOL presence in _scratch_dev_pool_get

Current check is buggy because it can never trigger as even if SCRATCH_DEV_POOL is not defined config_ndevs will get a value of 0 from 'wc -w', this in turn makes 'typeset -p config_ndevs' always return 0, triggering the existing check a noop.

Fix this by explicitly checking for the presence of SCHRATC_DEV_POOL

---

Eryu,

Please use this patch as it's a more proper fix

 common/rc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
common/rc +5 -5
index 7f693d3922e8..07b69880eea6 100644
@@ -917,15 +917,15 @@ _scratch_dev_pool_get()
 		_fail "Usage: _scratch_dev_pool_get ndevs"
 	fi
 
-	local test_ndevs=$1
-	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
-	local -a devs="( $SCRATCH_DEV_POOL )"
-
-	typeset -p config_ndevs >/dev/null 2>&1
+	typeset -p SCRATCH_DEV_POOL >/dev/null 2>&1
 	if [ $? -ne 0 ]; then
 		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
 	fi
 
+	local test_ndevs=$1
+	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local -a devs="( $SCRATCH_DEV_POOL )"
+
 	if [ $config_ndevs -lt $test_ndevs ]; then
 		_notrun "Need at least test requested number of ndevs $test_ndevs"
 	fi

--
2.17.1

Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] common/rc: Fix check for SCRATCH_DEV_POOL presence in _scratch_dev_pool_get

Quoted 28 lines · Nikolay Borisov

Current check is buggy because it can never trigger as even if SCRATCH_DEV_POOL is not defined config_ndevs will get a value of 0 from 'wc -w', this in turn makes 'typeset -p config_ndevs' always return 0, triggering the existing check a noop.

Fix this by explicitly checking for the presence of SCHRATC_DEV_POOL

---

Eryu,

Please use this patch as it's a more proper fix

 common/rc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
common/rc +0 -3
index 7f693d3922e8..07b69880eea6 100644
@@ -917,15 +917,15 @@ _scratch_dev_pool_get()
 		_fail "Usage: _scratch_dev_pool_get ndevs"
 	fi
 
-	local test_ndevs=$1
-	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
-	local -a devs="( $SCRATCH_DEV_POOL )"

common/rc _scratch_dev_pool_get() · line 927

Quoted 10 lines
common/rc +4 -2
-
-	typeset -p config_ndevs >/dev/null 2>&1
+	typeset -p SCRATCH_DEV_POOL >/dev/null 2>&1
 	if [ $? -ne 0 ]; then
 		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
 	fi
 
+	local test_ndevs=$1
+	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local -a devs="( $SCRATCH_DEV_POOL )"

Yes, the logic of:
"local config_ndevs=echo $SCRATCH_DEV_POOL| wc -w
typeset -p config_ndevs >/dev/null 2>&1"
looks weird.

Checking SCRATCH_DEV_POOL makes sense to me.

Quoted 7 lines
common/rc +1 -1
+
 	if [ $config_ndevs -lt $test_ndevs ]; then
 		_notrun "Need at least test requested number of ndevs $test_ndevs"
 	fi
--

2.17.1

#3 lore raw

Re: [PATCH] common/rc: Fix check for SCRATCH_DEV_POOL presence in _scratch_dev_pool_get

Quoted 36 lines · Zorro Lang
Quoted 35 lines · Nikolay Borisov

Current check is buggy because it can never trigger as even if SCRATCH_DEV_POOL is not defined config_ndevs will get a value of 0 from 'wc -w', this in turn makes 'typeset -p config_ndevs' always return 0, triggering the existing check a noop.

Fix this by explicitly checking for the presence of SCHRATC_DEV_POOL

---

Eryu,

Please use this patch as it's a more proper fix

 common/rc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
common/rc +1 -5
index 7f693d3922e8..07b69880eea6 100644
@@ -917,15 +917,15 @@ _scratch_dev_pool_get()
 		_fail "Usage: _scratch_dev_pool_get ndevs"
 	fi
 
-	local test_ndevs=$1
-	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
-	local -a devs="( $SCRATCH_DEV_POOL )"
-
-	typeset -p config_ndevs >/dev/null 2>&1
+	typeset -p SCRATCH_DEV_POOL >/dev/null 2>&1
 	if [ $? -ne 0 ]; then
 		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
 	fi
 
Quoted 8 lines

common/rc _scratch_dev_pool_get() · line 927

Quoted 3 lines
common/rc +3 -0
+	local test_ndevs=$1
+	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local -a devs="( $SCRATCH_DEV_POOL )"

Yes, the logic of:
"local config_ndevs=echo $SCRATCH_DEV_POOL| wc -w
typeset -p config_ndevs >/dev/null 2>&1"
looks weird.

I can only speculate the idea was that echo $SCRATCH_DEV_POOL| wc -w would fail to declare config_ndevs hence typeset -p config_ndevs would return != 0, however that's not what is happening.

Quoted 14 lines

Checking SCRATCH_DEV_POOL makes sense to me.

Quoted 7 lines
common/rc +1 -1
+
 	if [ $config_ndevs -lt $test_ndevs ]; then
 		_notrun "Need at least test requested number of ndevs $test_ndevs"
 	fi
--

2.17.1

#4 lore raw

Re: [PATCH] common/rc: Fix check for SCRATCH_DEV_POOL presence in _scratch_dev_pool_get

Quoted 48 lines · Nikolay Borisov
Quoted 36 lines · Zorro Lang
Quoted 35 lines · Nikolay Borisov

Current check is buggy because it can never trigger as even if SCRATCH_DEV_POOL is not defined config_ndevs will get a value of 0 from 'wc -w', this in turn makes 'typeset -p config_ndevs' always return 0, triggering the existing check a noop.

Fix this by explicitly checking for the presence of SCHRATC_DEV_POOL

---

Eryu,

Please use this patch as it's a more proper fix

 common/rc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
common/rc +1 -5
index 7f693d3922e8..07b69880eea6 100644
@@ -917,15 +917,15 @@ _scratch_dev_pool_get()
 		_fail "Usage: _scratch_dev_pool_get ndevs"
 	fi
 
-	local test_ndevs=$1
-	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
-	local -a devs="( $SCRATCH_DEV_POOL )"
-
-	typeset -p config_ndevs >/dev/null 2>&1
+	typeset -p SCRATCH_DEV_POOL >/dev/null 2>&1
 	if [ $? -ne 0 ]; then
 		_fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
 	fi
 
Quoted 8 lines

common/rc _scratch_dev_pool_get() · line 927

Quoted 3 lines
common/rc +3 -0
+	local test_ndevs=$1
+	local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
+	local -a devs="( $SCRATCH_DEV_POOL )"

Yes, the logic of:
"local config_ndevs=echo $SCRATCH_DEV_POOL| wc -w
typeset -p config_ndevs >/dev/null 2>&1"
looks weird.

Quoted 3 lines

I can only speculate the idea was that echo $SCRATCH_DEV_POOL| wc -w would fail to declare config_ndevs hence typeset -p config_ndevs would return != 0, however that's not what is happening.

Yes, "typeset -p $var" can help to check if a variable is declared, the original logic "typeset -p config_ndevs" always return 0. I think they might want to check if [ $config_ndevs -eq 0 ], or check "typeset -p SCRATCH_DEV_POOL" as you did above.

Thanks,
Zorro

Quoted 16 lines
Quoted 15 lines

Checking SCRATCH_DEV_POOL makes sense to me.

Quoted 7 lines
common/rc +1 -1
+
 	if [ $config_ndevs -lt $test_ndevs ]; then
 		_notrun "Need at least test requested number of ndevs $test_ndevs"
 	fi
--

2.17.1