[PATCH blktests 1/2] common/nvme: introduce _have_nvme_cli_with_json_support()

Shin'ichiro Kawasaki shinichiro.kawasaki at wdc.com
Mon May 19 23:18:18 PDT 2025


To check if the nvme command supports json output format, introduce the
helper function _have_nvme_cli_with_json_support(), which verifies the
option "--output-format=" works. While at it, replace the short option
"-o" in _nvme_connect_subsys() with the long option "--output-format=".

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
 common/nvme | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/common/nvme b/common/nvme
index ac1bbe7..04d167b 100644
--- a/common/nvme
+++ b/common/nvme
@@ -62,6 +62,16 @@ _require_nvme_trtype_is_fabrics() {
 	return 0
 }
 
+_have_nvme_cli_with_json_support() {
+	_have_program nvme || return $?
+
+	if ! nvme list --output-format=json &> /dev/null; then
+		SKIP_REASONS+=("nvme-cli does not support json output format")
+		return 1
+	fi
+	return 0
+}
+
 _nvme_fcloop_add_rport() {
 	local local_wwnn="$1"
 	local local_wwpn="$2"
@@ -415,7 +425,7 @@ _nvme_connect_subsys() {
 	if [[ ${concat} = true ]]; then
 		ARGS+=(--concat)
 	fi
-	ARGS+=(-o json)
+	ARGS+=(--output-format=json)
 	connect=$(nvme connect "${ARGS[@]}" 2> /dev/null)
 
 	# Wait until device file and sysfs attributes get ready
-- 
2.49.0




More information about the Linux-nvme mailing list