File 0024-nvme-cli-ctrl-loss-tmo-should-accept-1-as-value.patch of Package nvme-cli.22025

From: Maurizio Lombardi <mlombard@redhat.com>
Date: Mon, 8 Nov 2021 14:26:56 +0100
Subject: nvme-cli: ctrl-loss-tmo should accept -1 as value
References: bsc#1192348
Git-commit: 166f7453d7874dec25314c5148543e0577dd4e25

When passing the parameter --ctrl-loss-tmo=-1
nvme-cli silently drops it and replaces its value with the
default one (600) despite the fact that -1 is valid
and accepted by the kernel.
ctrl_loss_tmo < 0 means that it will try to reconnect forever

This is due to the fact that -1 is treated like "variable unset"
by nvme-cli and the add_int_argument() function ignores
all arguments with such a value if allow_zero is true (the latter seems
to be completely unintended).

This patch fixes the bug by:

1) removing the "arg == -1" condition from add_int_argument() and letting
   the caller take care of checking if -1 is an acceptable value
   for a particular argument.

2) initializing ctrl_loss_tmo to its default value instead of -1.

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
[dwagner: updated context, dropped hunks which depends missing code]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 fabrics.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/fabrics.c
+++ b/fabrics.c
@@ -818,7 +818,7 @@ add_int_argument(char **argstr, int *max
 {
 	int len;
 
-	if ((arg && !allow_zero) || (arg != -1 && allow_zero)) {
+	if (arg || allow_zero) {
 		len = snprintf(*argstr, *max_len, ",%s=%d", arg_str, arg);
 		if (len < 0)
 			return -EINVAL;
@@ -892,8 +892,9 @@ static int build_options(char *argstr, i
 				cfg.reconnect_delay, false) ||
 	    add_int_argument(&argstr, &max_len, "ctrl_loss_tmo",
 				cfg.ctrl_loss_tmo, false) ||
+	    (cfg.tos != -1 &&
 	    add_int_argument(&argstr, &max_len, "tos",
-				cfg.tos, true) ||
+				cfg.tos, true)) ||
 	    add_bool_argument(&argstr, &max_len, "duplicate_connect",
 				cfg.duplicate_connect) ||
 	    add_bool_argument(&argstr, &max_len, "disable_sqflow",
openSUSE Build Service is sponsored by