Fix for setting '0' to fast_io_fail
authorJun'ichi Nomura <j-nomura@ce.jp.nec.com>
Mon, 12 Mar 2012 11:43:55 +0000 (20:43 +0900)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Mon, 12 Mar 2012 20:09:29 +0000 (21:09 +0100)
Hi Christophe,

In kernel, '0' is valid value for fast_io_fail, meaning immediate
termination of ios on rport delete.
However, '0' is treated as 'not-configured' in various places of
multipath-tools and it is not possible to set 0 to fast_io_fail.

Attached patch fixes that by introducing MP_FAST_IO_FAIL_ZERO
as internal representation of zero value.

--
Jun'ichi Nomura, NEC Corporation

libmultipath/config.h
libmultipath/dict.c
libmultipath/discovery.c
libmultipath/propsel.c

index 234e7e6..6fcd45e 100644 (file)
@@ -7,6 +7,13 @@
 #define ORIGIN_DEFAULT 0
 #define ORIGIN_CONFIG  1
 
+/*
+ * In kernel, fast_io_fail == 0 means immediate failure on rport delete.
+ * OTOH '0' means not-configured in various places in multipath-tools.
+ */
+#define MP_FAST_IO_FAIL_OFF (-1)
+#define MP_FAST_IO_FAIL_ZERO (-2)
+
 enum devtypes {
        DEV_NONE,
        DEV_DEVT,
index dd567bd..4df3d9b 100644 (file)
@@ -44,10 +44,12 @@ def_fast_io_fail_handler(vector strvec)
 
        buff = set_value(strvec);
        if (strlen(buff) == 3 && !strcmp(buff, "off"))
-               conf->fast_io_fail = -1;
+               conf->fast_io_fail = MP_FAST_IO_FAIL_OFF;
        else if (sscanf(buff, "%d", &conf->fast_io_fail) != 1 ||
-                conf->fast_io_fail < -1)
+                conf->fast_io_fail < MP_FAST_IO_FAIL_ZERO)
                conf->fast_io_fail = 0;
+       else if (conf->fast_io_fail == 0)
+               conf->fast_io_fail = MP_FAST_IO_FAIL_ZERO;
 
        FREE(buff);
        return 0;
@@ -873,10 +875,12 @@ hw_fast_io_fail_handler(vector strvec)
 
        buff = set_value(strvec);
        if (strlen(buff) == 3 && !strcmp(buff, "off"))
-               hwe->fast_io_fail = -1;
+               hwe->fast_io_fail = MP_FAST_IO_FAIL_OFF;
        else if (sscanf(buff, "%d", &hwe->fast_io_fail) != 1 ||
-                hwe->fast_io_fail < -1)
+                hwe->fast_io_fail < MP_FAST_IO_FAIL_ZERO)
                hwe->fast_io_fail = 0;
+       else if (hwe->fast_io_fail == 0)
+               hwe->fast_io_fail = MP_FAST_IO_FAIL_ZERO;
 
        FREE(buff);
        return 0;
@@ -1900,8 +1904,10 @@ snprint_hw_fast_io_fail(char * buff, int len, void * data)
                return 0;
        if (hwe->fast_io_fail == conf->fast_io_fail)
                return 0;
-       if (hwe->fast_io_fail == -1)
+       if (hwe->fast_io_fail == MP_FAST_IO_FAIL_OFF)
                return snprintf(buff, len, "off");
+       if (hwe->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
+               return snprintf(buff, len, "0");
        return snprintf(buff, len, "%d", hwe->fast_io_fail);
 }
 
@@ -2190,8 +2196,10 @@ snprint_def_fast_io_fail(char * buff, int len, void * data)
 {
        if (!conf->fast_io_fail)
                return 0;
-       if (conf->fast_io_fail == -1)
+       if (conf->fast_io_fail == MP_FAST_IO_FAIL_OFF)
                return snprintf(buff, len, "off");
+       if (conf->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
+               return snprintf(buff, len, "0");
        return snprintf(buff, len, "%d", conf->fast_io_fail);
 }
 
index 16f786d..ff011c3 100644 (file)
@@ -334,7 +334,7 @@ sysfs_set_scsi_tmo (struct multipath *mpp)
                        if (sysfs_attr_set_value(attr_path, "dev_loss_tmo",
                                                 value, 11) < 0) {
                                int err = 1;
-                               if (mpp->fast_io_fail <= 0 && mpp->dev_loss > 600) {
+                               if ((!mpp->fast_io_fail || mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF) && mpp->dev_loss > 600) {
                                        strncpy(value, "600", 4);
                                        condlog(3, "%s: limiting dev_loss_tmo to 600, since fast_io_fail is not set", mpp->alias);
                                        if (sysfs_attr_set_value(attr_path, "dev_loss_tmo", value, 11) >= 0)
@@ -347,8 +347,10 @@ sysfs_set_scsi_tmo (struct multipath *mpp)
                        }
                }
                if (mpp->fast_io_fail){
-                       if (mpp->fast_io_fail == -1)
+                       if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
                                sprintf(value, "off");
+                       else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
+                               sprintf(value, "0");
                        else
                                snprintf(value, 11, "%u", mpp->fast_io_fail);
                        if (sysfs_attr_set_value(attr_path, "fast_io_fail_tmo",
index b241ecb..10aec29 100644 (file)
@@ -550,18 +550,20 @@ select_fast_io_fail(struct multipath *mp)
 {
        if (mp->hwe && mp->hwe->fast_io_fail) {
                mp->fast_io_fail = mp->hwe->fast_io_fail;
-               if (mp->fast_io_fail == -1)
+               if (mp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
                        condlog(3, "%s: fast_io_fail_tmo = off (controller default)", mp->alias);
                else
-                       condlog(3, "%s: fast_io_fail_tmo = %d (controller default)", mp->alias, mp->fast_io_fail);
+                       condlog(3, "%s: fast_io_fail_tmo = %d (controller default)", mp->alias,
+                               mp->fast_io_fail == MP_FAST_IO_FAIL_ZERO ? 0 : mp->fast_io_fail);
                return 0;
        }
        if (conf->fast_io_fail) {
                mp->fast_io_fail = conf->fast_io_fail;
-               if (mp->fast_io_fail == -1)
+               if (mp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
                        condlog(3, "%s: fast_io_fail_tmo = off (config file default)", mp->alias);
                else
-                       condlog(3, "%s: fast_io_fail_tmo = %d (config file default)", mp->alias, mp->fast_io_fail);
+                       condlog(3, "%s: fast_io_fail_tmo = %d (config file default)", mp->alias,
+                               mp->fast_io_fail == MP_FAST_IO_FAIL_ZERO ? 0 : mp->fast_io_fail);
                return 0;
        }
        mp->fast_io_fail = 0;