Skip to contentSkip to conversation

nvme/039: check for sector size of test device

PATCH Superseded Bryan Gurney 2 participants 5 messages Nov 25, 2024 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme/039: check for sector size of test device

This test has hard-coded 512 byte values for the dd commands, which will fail on 4096-byte block devices. Create a SECT_SZ global variable that is populated with the result of the command "blockdev --getss <dev>", and use that result for the block size of the write commands.

Also use this variable for the "--data-len" command of the "nvme admin-passthru" and "nvme io-passthru" tests. (On a test with a 4096-byte namespace, leaving these with the hardcoded values still passed, but update them for the sake of consistency.)

---
 tests/nvme/039 | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tests/nvme/039 +7 -5
index e8020a7..f1abf8b 100755
@@ -37,7 +37,7 @@ inject_unrec_read_on_read()
 	# Inject a 'Unrecovered Read Error' (0x281) status error on a READ
 	_nvme_enable_err_inject "$1" 0 100 1 0x281 1
 
-	dd if=/dev/"$1" of=/dev/null bs=512 count=1 iflag=direct \
+	dd if=/dev/"$1" of=/dev/null bs="${SECT_SZ}" count=1 iflag=direct \
 	    2> /dev/null 1>&2
 
 	_nvme_disable_err_inject "$1"
@@ -57,7 +57,7 @@ inject_invalid_status_on_read()
 	# Inject an invalid status (0x375) on a READ
 	_nvme_enable_err_inject "$1" 0 100 1 0x375 1
 
-	dd if=/dev/"$1" of=/dev/null bs=512 count=1 iflag=direct \
+	dd if=/dev/"$1" of=/dev/null bs="${SECT_SZ}" count=1 iflag=direct \
 	    2> /dev/null 1>&2
 
 	_nvme_disable_err_inject "$1"
@@ -77,7 +77,7 @@ inject_write_fault_on_write()
 	# Inject a 'Write Fault' 0x280 status error on a WRITE
 	_nvme_enable_err_inject "$1" 0 100 1 0x280 1
 
-	dd if=/dev/zero of=/dev/"$1" bs=512 count=1 oflag=direct \
+	dd if=/dev/zero of=/dev/"$1" bs="${SECT_SZ}" count=1 oflag=direct \
 	    2> /dev/null 1>&2
 
 	_nvme_disable_err_inject "$1"
@@ -119,7 +119,7 @@ inject_invalid_admin_cmd()
 	# Inject a 'Invalid Command Opcode' (0x1) on an invalid command (0x96)
 	 _nvme_enable_err_inject "$1" 0 100 1 0x1 1
 
-	nvme admin-passthru /dev/"$1" --opcode=0x96 --data-len=4096 \
+	nvme admin-passthru /dev/"$1" --opcode=0x96 --data-len="${SECT_SZ}" \
 	    --cdw10=1 -r 2> /dev/null 1>&2
 
 	_nvme_disable_err_inject "$1"
@@ -145,7 +145,7 @@ inject_invalid_io_cmd_passthru()
 	_nvme_enable_err_inject "$ns_dev" 0 100 1 0x1 1
 
 	nvme io-passthru /dev/"$1" --opcode=0x02 --namespace-id="$ns" \
-		--data-len=512 --read --cdw10=0 --cdw11=0 --cdw12="$2" 2> /dev/null 1>&2
+		--data-len="${SECT_SZ}" --read --cdw10=0 --cdw11=0 --cdw12="$2" 2> /dev/null 1>&2
 
 	_nvme_disable_err_inject "$1"
 	if ${nvme_verbose_errors}; then
@@ -174,6 +174,8 @@ test_device() {
 	ns_dev=${TEST_DEV##*/}
 	ctrl_dev=${ns_dev%n*}
 
+	SECT_SZ=$(blockdev --getss "${TEST_DEV}")
+
 	_nvme_err_inject_setup "${ns_dev}" "${ctrl_dev}"
 
 	# wait DEFAULT_RATELIMIT_INTERVAL=5 seconds to ensure errors are printed
Signature · 1 line
2.47.0
#1 lore raw

tests/nvme/039 test_device() { · line 177

Quoted 1 line · Bryan Gurney
tests/nvme/039 +1 -0
+	SECT_SZ=$(blockdev --getss "${TEST_DEV}")

As far as I know the terminology "sector size" does not occur anywhere in the NVMe specification. How about changing the variable name SECT_SZ into something that is an abbreviation of "logical block size" since that is what blockdev --getss reports?

Thanks,

Bart.

#2 lore raw
Quoted 5 lines · Bart Van Assche
Quoted 1 line · Bryan Gurney

+ SECT_SZ=$(blockdev --getss "${TEST_DEV}")

Quoted 10 lines

As far as I know the terminology "sector size" does not occur anywhere in the NVMe specification. How about changing the variable name SECT_SZ into something that is an abbreviation of "logical block size" since that is what blockdev --getss reports?

Thanks,

Bart.

Yes, I can do that. Does "LB_SZ" work?

Thanks,

Bryan

#3 lore raw
Quoted 1 line · Bryan Gurney

Yes, I can do that. Does "LB_SZ" work?

That sounds good to me :-)

Thanks,

Bart.

#4 lore raw
Quoted 10 lines · Bart Van Assche
Quoted 1 line · Bryan Gurney

Yes, I can do that. Does "LB_SZ" work?

That sounds good to me :-)

Thanks,

Bart.

OK; I'll send a v2 patch with an updated description.

Thanks,

Bryan