Skip to contentSkip to conversation

multipath-tools: beautify path_latency.c code

PATCH In review Xose Vazquez Perez 4 participants 8 messages Jun 22, 2017 – Aug 5, 2017 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multipath-tools: beautify path_latency.c code

Mainly running scripts/Lindent, from kernel dir, to replace indent spaces by tabs.

Cc Yang Feng <[email protected]>
Cc Christophe Varoqui <[email protected]>
Cc device-mapper development <[email protected]>
---
 libmultipath/prioritizers/path_latency.c | 354 +++++++++++++++----------------
 1 file changed, 177 insertions(+), 177 deletions(-)
libmultipath/prioritizers/path_latency.c +177 -177
index 34b734b..9fc2dfc 100644
@@ -17,8 +17,8 @@
  * Author(s): Yang Feng <[email protected]>
  *
  * This file is released under the GPL version 2, or any later version.
- *
  */
+
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>
@@ -31,27 +31,28 @@
 
 #define pp_pl_log(prio, fmt, args...) condlog(prio, "path_latency prio: " fmt, ##args)
 
-#define MAX_IO_NUM              200
-#define MIN_IO_NUM              2
+#define MAX_IO_NUM		200
+#define MIN_IO_NUM		2
 
-#define MAX_BASE_NUM            10
-#define MIN_BASE_NUM            2
+#define MAX_BASE_NUM		10
+#define MIN_BASE_NUM		2
 
-#define MAX_AVG_LATENCY         100000000.  /*Unit: us*/
-#define MIN_AVG_LATENCY         1.          /*Unit: us*/
+#define MAX_AVG_LATENCY		100000000.	/* Unit: us */
+#define MIN_AVG_LATENCY		1.		/* Unit: us */
 
-#define DEFAULT_PRIORITY        0
+#define DEFAULT_PRIORITY	0
 
-#define MAX_CHAR_SIZE           30
+#define MAX_CHAR_SIZE		30
 
-#define USEC_PER_SEC            1000000LL
-#define NSEC_PER_USEC           1000LL
+#define USEC_PER_SEC		1000000LL
+#define NSEC_PER_USEC		1000LL
 
 static long long path_latency[MAX_IO_NUM];
 
 static inline long long timeval_to_us(const struct timespec *tv)
 {
-	return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv->tv_nsec / NSEC_PER_USEC);
+	return ((long long)tv->tv_sec * USEC_PER_SEC) +
+	    (tv->tv_nsec / NSEC_PER_USEC);
 }
 
 static int do_readsector0(int fd, unsigned int timeout)
@@ -60,198 +61,197 @@ static int do_readsector0(int fd, unsigned int timeout)
 	unsigned char sbuf[SENSE_BUFF_LEN];
 	int ret;
 
-	ret = sg_read(fd, &buf[0], 4096, &sbuf[0],
-		      SENSE_BUFF_LEN, timeout);
+	ret = sg_read(fd, &buf[0], 4096, &sbuf[0], SENSE_BUFF_LEN, timeout);
 
 	return ret;
 }
 
 int check_args_valid(int io_num, int base_num)
 {
-    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
-    {
-        pp_pl_log(0, "args io_num is outside the valid range");
-        return 0;
-    }
-
-    if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM))
-    {
-        pp_pl_log(0, "args base_num is outside the valid range");
-        return 0;
-    }
-
-    return 1;
+	if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM)) {
+		pp_pl_log(0, "args io_num is outside the valid range");
+		return 0;
+	}
+
+	if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM)) {
+		pp_pl_log(0, "args base_num is outside the valid range");
+		return 0;
+	}
+
+	return 1;
 }
 
-/* In multipath.conf, args form: io_num|base_num. For example,
-*  args is "20|10", this function can get io_num value 20, and
-   base_num value 10.
-*/
-static int get_ionum_and_basenum(char *args,
-                                 int *ionum,
-                                 int *basenum)
+/*
+ * In multipath.conf, args form: io_num|base_num. For example,
+ * args is "20|10", this function can get io_num value 20, and
+ * base_num value 10.
+ */
+static int get_ionum_and_basenum(char *args, int *ionum, int *basenum)
 {
-    char source[MAX_CHAR_SIZE];
-    char vertica = '|';
-    char *endstrbefore = NULL;
-    char *endstrafter = NULL;
-    unsigned int size = strlen(args);
-
-    if ((args == NULL) || (ionum == NULL) || (basenum == NULL))
-    {
-        pp_pl_log(0, "args string is NULL");
-        return 0;
-    }
-
-    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
-    {
-        pp_pl_log(0, "args string's size is too long");
-        return 0;
-    }
-
-    memcpy(source, args, size+1);
-
-    if (!isdigit(source[0]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *ionum = (int)strtoul(source, &endstrbefore, 10);
-    if (endstrbefore[0] != vertica)
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    if (!isdigit(endstrbefore[1]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
-    if (check_args_valid(*ionum, *basenum) == 0)
-    {
-        return 0;
-    }
-
-    return 1;
+	char source[MAX_CHAR_SIZE];
+	char vertica = '|';
+	char *endstrbefore = NULL;
+	char *endstrafter = NULL;
+	unsigned int size = strlen(args);
+
+	if ((args == NULL) || (ionum == NULL) || (basenum == NULL)) {
+		pp_pl_log(0, "args string is NULL");
+		return 0;
+	}
+
+	if ((size < 1) || (size > MAX_CHAR_SIZE - 1)) {
+		pp_pl_log(0, "args string's size is too long");
+		return 0;
+	}
+
+	memcpy(source, args, size + 1);
+
+	if (!isdigit(source[0])) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	*ionum = (int)strtoul(source, &endstrbefore, 10);
+	if (endstrbefore[0] != vertica) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	if (!isdigit(endstrbefore[1])) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	*basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
+	if (check_args_valid(*ionum, *basenum) == 0) {
+		return 0;
+	}
+
+	return 1;
 }
 
-long long calc_standard_deviation(long long *path_latency, int size, long long avglatency)
+long long calc_standard_deviation(long long *path_latency, int size,
+				  long long avglatency)
 {
-    int index;
-    long long total = 0;
+	int index;
+	long long total = 0;
 
-    for (index = 0; index < size; index++)
-    {
-        total += (path_latency[index] - avglatency) * (path_latency[index] - avglatency);
-    }
+	for (index = 0; index < size; index++) {
+		total +=
+		    (path_latency[index] - avglatency) * (path_latency[index] -
+							  avglatency);
+	}
 
-    total /= (size-1);
+	total /= (size - 1);
 
-    return (long long)sqrt((double)total);
+	return (long long)sqrt((double)total);
 }
 
-int calcPrio(double avglatency, double max_avglatency, double min_avglatency, double base_num)
+int calcPrio(double avglatency, double max_avglatency, double min_avglatency,
+	     double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
+	double lavglatency = log(avglatency) / log(base_num);
+	double lmax_avglatency = log(max_avglatency) / log(base_num);
+	double lmin_avglatency = log(min_avglatency) / log(base_num);
 
-    if (lavglatency <= lmin_avglatency)
-        return (int)(lmax_avglatency + 1.);
+	if (lavglatency <= lmin_avglatency)
+		return (int)(lmax_avglatency + 1.);
 
-    if (lavglatency > lmax_avglatency)
-        return 0;
+	if (lavglatency > lmax_avglatency)
+		return 0;
 
-    return (int)(lmax_avglatency - lavglatency + 1.);
+	return (int)(lmax_avglatency - lavglatency + 1.);
 }
 
 /* Calc the latency interval corresponding to the average latency */
 long long calc_latency_interval(double avglatency, double max_avglatency,
-                                double min_avglatency, double base_num)
+				double min_avglatency, double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
-
-    if ((lavglatency <= lmin_avglatency)
-        || (lavglatency > lmax_avglatency))
-        return 0;/* Invalid value */
-
-    if ((double)((int)lavglatency) == lavglatency)
-        return (long long)(avglatency - (avglatency / base_num));
-    else
-        return (long long)(pow(base_num, (double)((int)lavglatency + 1))
-            - pow(base_num, (double)((int)lavglatency)));
+	double lavglatency = log(avglatency) / log(base_num);
+	double lmax_avglatency = log(max_avglatency) / log(base_num);
+	double lmin_avglatency = log(min_avglatency) / log(base_num);
+
+	if ((lavglatency <= lmin_avglatency)
+	    || (lavglatency > lmax_avglatency))
+		return 0;	/* Invalid value */
+
+	if ((double)((int)lavglatency) == lavglatency)
+		return (long long)(avglatency - (avglatency / base_num));
+	else
+		return (long long)(pow(base_num, (double)((int)lavglatency + 1))
+				   - pow(base_num, (double)((int)lavglatency)));
 }
 
-int getprio (struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, char *args, unsigned int timeout)
 {
-    int rc, temp;
-    int index = 0;
-    int io_num;
-    int base_num;
-    long long avglatency;
-    long long latency_interval;
-    long long standard_deviation;
-    long long toldelay = 0;
-    long long before, after;
-    struct timespec tv;
-
-    if (pp->fd < 0)
-        return -1;
-
-    if (get_ionum_and_basenum(args, &io_num, &base_num) == 0)
-    {
-        pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
-        return DEFAULT_PRIORITY;
-    }
-
-    memset(path_latency, 0, sizeof(path_latency));
-
-    temp = io_num;
-    while (temp-- > 0)
-    {
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        before = timeval_to_us(&tv);
-
-        if (do_readsector0(pp->fd, timeout) == 2)
-        {
-            pp_pl_log(0, "%s: path down", pp->dev);
-            return -1;
-        }
-
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        after = timeval_to_us(&tv);
-
-        path_latency[index] = after - before;
-        toldelay += path_latency[index++];
-    }
-
-    avglatency = toldelay/(long long)io_num;
-    pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
-
-    if (avglatency > MAX_AVG_LATENCY)
-    {
-        pp_pl_log(0, "%s: average latency (%lld us) is outside the thresold (%lld us)",
-            pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
-        return DEFAULT_PRIORITY;
-    }
-
-    /* Min average latency and max average latency are constant, the args base_num
-    set can change latency_interval value corresponding to avglatency and is not constant.
-    Warn the user if latency_interval is smaller than (2 * standard_deviation), or equal */
-    standard_deviation = calc_standard_deviation(path_latency, index, avglatency);
-    latency_interval = calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    if ((latency_interval!= 0)
-        && (latency_interval <= (2 * standard_deviation)))
-        pp_pl_log(3, "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
-            "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
-            pp->dev, latency_interval, avglatency, standard_deviation, base_num);
-
-    rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    return rc;
+	int rc, temp;
+	int index = 0;
+	int io_num;
+	int base_num;
+	long long avglatency;
+	long long latency_interval;
+	long long standard_deviation;
+	long long toldelay = 0;
+	long long before, after;
+	struct timespec tv;
+
+	if (pp->fd < 0)
+		return -1;
+
+	if (get_ionum_and_basenum(args, &io_num, &base_num) == 0) {
+		pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
+		return DEFAULT_PRIORITY;
+	}
+
+	memset(path_latency, 0, sizeof(path_latency));
+
+	temp = io_num;
+	while (temp-- > 0) {
+		(void)clock_gettime(CLOCK_MONOTONIC, &tv);
+		before = timeval_to_us(&tv);
+
+		if (do_readsector0(pp->fd, timeout) == 2) {
+			pp_pl_log(0, "%s: path down", pp->dev);
+			return -1;
+		}
+
+		(void)clock_gettime(CLOCK_MONOTONIC, &tv);
+		after = timeval_to_us(&tv);
+
+		path_latency[index] = after - before;
+		toldelay += path_latency[index++];
+	}
+
+	avglatency = toldelay / (long long)io_num;
+	pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
+
+	if (avglatency > MAX_AVG_LATENCY) {
+		pp_pl_log(0,
+			  "%s: average latency (%lld us) is outside the thresold (%lld us)",
+			  pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
+		return DEFAULT_PRIORITY;
+	}
+
+	/*
+	 * Min average latency and max average latency are constant, the args
+	 * base_num set can change latency_interval value corresponding to
+	 * avglatency and is not constant.
+	 * Warn the user if latency_interval is smaller than (2 * standard_deviation),
+	 * or equal.
+	 */
+	standard_deviation =
+	    calc_standard_deviation(path_latency, index, avglatency);
+	latency_interval =
+	    calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,
+				  base_num);
+	if ((latency_interval != 0)
+	    && (latency_interval <= (2 * standard_deviation)))
+		pp_pl_log(3,
+			  "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
+			  "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
+			  pp->dev, latency_interval, avglatency,
+			  standard_deviation, base_num);
+
+	rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
+	return rc;
 }
Signature · 1 line
2.13.1
#1 lore raw
Quoted 2 lines · Xose Vazquez Perez

Mainly running scripts/Lindent, from kernel dir, to replace indent spaces by tabs.

Hello Xose,

Why do you think this kind of changes is useful? Are you aware that whitespace-only changes are very annoying to anyone else who is preparing changes on the same file because such changes result in a huge number of annoying rebase conflicts?

Bart.

#2 lore raw
Quoted 4 lines · Bart Van Assche

Why do you think this kind of changes is useful? Are you aware that whitespace-only changes are very annoying to anyone else who is preparing changes on the same file because such changes result in a huge number of annoying rebase conflicts?

Be consistent with the rest of the multipath-tools code. Have do you seen the original and the patched file?
Cleanings like this were done before without troubles.

#3 lore raw
In reply to Xose Vazquez Perez

Hi Xose,
Thanks for your work.

ACK
-Yang

Quoted 429 lines · Xose Vazquez Perez

Mainly running scripts/Lindent, from kernel dir, to replace indent spaces by tabs.

Cc Yang Feng <[email protected]>
Cc Christophe Varoqui <[email protected]>
Cc device-mapper development <[email protected]>
---
 libmultipath/prioritizers/path_latency.c | 354 +++++++++++++++----------------
 1 file changed, 177 insertions(+), 177 deletions(-)
libmultipath/prioritizers/path_latency.c +177 -177
index 34b734b..9fc2dfc 100644
@@ -17,8 +17,8 @@
  * Author(s): Yang Feng <[email protected]>
  *
  * This file is released under the GPL version 2, or any later version.
- *
  */
+
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>
@@ -31,27 +31,28 @@
 
 #define pp_pl_log(prio, fmt, args...) condlog(prio, "path_latency prio: " fmt, ##args)
 
-#define MAX_IO_NUM              200
-#define MIN_IO_NUM              2
+#define MAX_IO_NUM		200
+#define MIN_IO_NUM		2
 
-#define MAX_BASE_NUM            10
-#define MIN_BASE_NUM            2
+#define MAX_BASE_NUM		10
+#define MIN_BASE_NUM		2
 
-#define MAX_AVG_LATENCY         100000000.  /*Unit: us*/
-#define MIN_AVG_LATENCY         1.          /*Unit: us*/
+#define MAX_AVG_LATENCY		100000000.	/* Unit: us */
+#define MIN_AVG_LATENCY		1.		/* Unit: us */
 
-#define DEFAULT_PRIORITY        0
+#define DEFAULT_PRIORITY	0
 
-#define MAX_CHAR_SIZE           30
+#define MAX_CHAR_SIZE		30
 
-#define USEC_PER_SEC            1000000LL
-#define NSEC_PER_USEC           1000LL
+#define USEC_PER_SEC		1000000LL
+#define NSEC_PER_USEC		1000LL
 
 static long long path_latency[MAX_IO_NUM];
 
 static inline long long timeval_to_us(const struct timespec *tv)
 {
-	return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv->tv_nsec / NSEC_PER_USEC);
+	return ((long long)tv->tv_sec * USEC_PER_SEC) +
+	    (tv->tv_nsec / NSEC_PER_USEC);
 }
 
 static int do_readsector0(int fd, unsigned int timeout)
@@ -60,198 +61,197 @@ static int do_readsector0(int fd, unsigned int timeout)
 	unsigned char sbuf[SENSE_BUFF_LEN];
 	int ret;
 
-	ret = sg_read(fd, &buf[0], 4096, &sbuf[0],
-		      SENSE_BUFF_LEN, timeout);
+	ret = sg_read(fd, &buf[0], 4096, &sbuf[0], SENSE_BUFF_LEN, timeout);
 
 	return ret;
 }
 
 int check_args_valid(int io_num, int base_num)
 {
-    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
-    {
-        pp_pl_log(0, "args io_num is outside the valid range");
-        return 0;
-    }
-
-    if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM))
-    {
-        pp_pl_log(0, "args base_num is outside the valid range");
-        return 0;
-    }
-
-    return 1;
+	if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM)) {
+		pp_pl_log(0, "args io_num is outside the valid range");
+		return 0;
+	}
+
+	if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM)) {
+		pp_pl_log(0, "args base_num is outside the valid range");
+		return 0;
+	}
+
+	return 1;
 }
 
-/* In multipath.conf, args form: io_num|base_num. For example,
-*  args is "20|10", this function can get io_num value 20, and
-   base_num value 10.
-*/
-static int get_ionum_and_basenum(char *args,
-                                 int *ionum,
-                                 int *basenum)
+/*
+ * In multipath.conf, args form: io_num|base_num. For example,
+ * args is "20|10", this function can get io_num value 20, and
+ * base_num value 10.
+ */
+static int get_ionum_and_basenum(char *args, int *ionum, int *basenum)
 {
-    char source[MAX_CHAR_SIZE];
-    char vertica = '|';
-    char *endstrbefore = NULL;
-    char *endstrafter = NULL;
-    unsigned int size = strlen(args);
-
-    if ((args == NULL) || (ionum == NULL) || (basenum == NULL))
-    {
-        pp_pl_log(0, "args string is NULL");
-        return 0;
-    }
-
-    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
-    {
-        pp_pl_log(0, "args string's size is too long");
-        return 0;
-    }
-
-    memcpy(source, args, size+1);
-
-    if (!isdigit(source[0]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *ionum = (int)strtoul(source, &endstrbefore, 10);
-    if (endstrbefore[0] != vertica)
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    if (!isdigit(endstrbefore[1]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
-    if (check_args_valid(*ionum, *basenum) == 0)
-    {
-        return 0;
-    }
-
-    return 1;
+	char source[MAX_CHAR_SIZE];
+	char vertica = '|';
+	char *endstrbefore = NULL;
+	char *endstrafter = NULL;
+	unsigned int size = strlen(args);
+
+	if ((args == NULL) || (ionum == NULL) || (basenum == NULL)) {
+		pp_pl_log(0, "args string is NULL");
+		return 0;
+	}
+
+	if ((size < 1) || (size > MAX_CHAR_SIZE - 1)) {
+		pp_pl_log(0, "args string's size is too long");
+		return 0;
+	}
+
+	memcpy(source, args, size + 1);
+
+	if (!isdigit(source[0])) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	*ionum = (int)strtoul(source, &endstrbefore, 10);
+	if (endstrbefore[0] != vertica) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	if (!isdigit(endstrbefore[1])) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	*basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
+	if (check_args_valid(*ionum, *basenum) == 0) {
+		return 0;
+	}
+
+	return 1;
 }
 
-long long calc_standard_deviation(long long *path_latency, int size, long long avglatency)
+long long calc_standard_deviation(long long *path_latency, int size,
+				  long long avglatency)
 {
-    int index;
-    long long total = 0;
+	int index;
+	long long total = 0;
 
-    for (index = 0; index < size; index++)
-    {
-        total += (path_latency[index] - avglatency) * (path_latency[index] - avglatency);
-    }
+	for (index = 0; index < size; index++) {
+		total +=
+		    (path_latency[index] - avglatency) * (path_latency[index] -
+							  avglatency);
+	}
 
-    total /= (size-1);
+	total /= (size - 1);
 
-    return (long long)sqrt((double)total);
+	return (long long)sqrt((double)total);
 }
 
-int calcPrio(double avglatency, double max_avglatency, double min_avglatency, double base_num)
+int calcPrio(double avglatency, double max_avglatency, double min_avglatency,
+	     double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
+	double lavglatency = log(avglatency) / log(base_num);
+	double lmax_avglatency = log(max_avglatency) / log(base_num);
+	double lmin_avglatency = log(min_avglatency) / log(base_num);
 
-    if (lavglatency <= lmin_avglatency)
-        return (int)(lmax_avglatency + 1.);
+	if (lavglatency <= lmin_avglatency)
+		return (int)(lmax_avglatency + 1.);
 
-    if (lavglatency > lmax_avglatency)
-        return 0;
+	if (lavglatency > lmax_avglatency)
+		return 0;
 
-    return (int)(lmax_avglatency - lavglatency + 1.);
+	return (int)(lmax_avglatency - lavglatency + 1.);
 }
 
 /* Calc the latency interval corresponding to the average latency */
 long long calc_latency_interval(double avglatency, double max_avglatency,
-                                double min_avglatency, double base_num)
+				double min_avglatency, double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
-
-    if ((lavglatency <= lmin_avglatency)
-        || (lavglatency > lmax_avglatency))
-        return 0;/* Invalid value */
-
-    if ((double)((int)lavglatency) == lavglatency)
-        return (long long)(avglatency - (avglatency / base_num));
-    else
-        return (long long)(pow(base_num, (double)((int)lavglatency + 1))
-            - pow(base_num, (double)((int)lavglatency)));
+	double lavglatency = log(avglatency) / log(base_num);
+	double lmax_avglatency = log(max_avglatency) / log(base_num);
+	double lmin_avglatency = log(min_avglatency) / log(base_num);
+
+	if ((lavglatency <= lmin_avglatency)
+	    || (lavglatency > lmax_avglatency))
+		return 0;	/* Invalid value */
+
+	if ((double)((int)lavglatency) == lavglatency)
+		return (long long)(avglatency - (avglatency / base_num));
+	else
+		return (long long)(pow(base_num, (double)((int)lavglatency + 1))
+				   - pow(base_num, (double)((int)lavglatency)));
 }
 
-int getprio (struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, char *args, unsigned int timeout)
 {
-    int rc, temp;
-    int index = 0;
-    int io_num;
-    int base_num;
-    long long avglatency;
-    long long latency_interval;
-    long long standard_deviation;
-    long long toldelay = 0;
-    long long before, after;
-    struct timespec tv;
-
-    if (pp->fd < 0)
-        return -1;
-
-    if (get_ionum_and_basenum(args, &io_num, &base_num) == 0)
-    {
-        pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
-        return DEFAULT_PRIORITY;
-    }
-
-    memset(path_latency, 0, sizeof(path_latency));
-
-    temp = io_num;
-    while (temp-- > 0)
-    {
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        before = timeval_to_us(&tv);
-
-        if (do_readsector0(pp->fd, timeout) == 2)
-        {
-            pp_pl_log(0, "%s: path down", pp->dev);
-            return -1;
-        }
-
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        after = timeval_to_us(&tv);
-
-        path_latency[index] = after - before;
-        toldelay += path_latency[index++];
-    }
-
-    avglatency = toldelay/(long long)io_num;
-    pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
-
-    if (avglatency > MAX_AVG_LATENCY)
-    {
-        pp_pl_log(0, "%s: average latency (%lld us) is outside the thresold (%lld us)",
-            pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
-        return DEFAULT_PRIORITY;
-    }
-
-    /* Min average latency and max average latency are constant, the args base_num
-    set can change latency_interval value corresponding to avglatency and is not constant.
-    Warn the user if latency_interval is smaller than (2 * standard_deviation), or equal */
-    standard_deviation = calc_standard_deviation(path_latency, index, avglatency);
-    latency_interval = calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    if ((latency_interval!= 0)
-        && (latency_interval <= (2 * standard_deviation)))
-        pp_pl_log(3, "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
-            "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
-            pp->dev, latency_interval, avglatency, standard_deviation, base_num);
-
-    rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    return rc;
+	int rc, temp;
+	int index = 0;
+	int io_num;
+	int base_num;
+	long long avglatency;
+	long long latency_interval;
+	long long standard_deviation;
+	long long toldelay = 0;
+	long long before, after;
+	struct timespec tv;
+
+	if (pp->fd < 0)
+		return -1;
+
+	if (get_ionum_and_basenum(args, &io_num, &base_num) == 0) {
+		pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
+		return DEFAULT_PRIORITY;
+	}
+
+	memset(path_latency, 0, sizeof(path_latency));
+
+	temp = io_num;
+	while (temp-- > 0) {
+		(void)clock_gettime(CLOCK_MONOTONIC, &tv);
+		before = timeval_to_us(&tv);
+
+		if (do_readsector0(pp->fd, timeout) == 2) {
+			pp_pl_log(0, "%s: path down", pp->dev);
+			return -1;
+		}
+
+		(void)clock_gettime(CLOCK_MONOTONIC, &tv);
+		after = timeval_to_us(&tv);
+
+		path_latency[index] = after - before;
+		toldelay += path_latency[index++];
+	}
+
+	avglatency = toldelay / (long long)io_num;
+	pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
+
+	if (avglatency > MAX_AVG_LATENCY) {
+		pp_pl_log(0,
+			  "%s: average latency (%lld us) is outside the thresold (%lld us)",
+			  pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
+		return DEFAULT_PRIORITY;
+	}
+
+	/*
+	 * Min average latency and max average latency are constant, the args
+	 * base_num set can change latency_interval value corresponding to
+	 * avglatency and is not constant.
+	 * Warn the user if latency_interval is smaller than (2 * standard_deviation),
+	 * or equal.
+	 */
+	standard_deviation =
+	    calc_standard_deviation(path_latency, index, avglatency);
+	latency_interval =
+	    calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,
+				  base_num);
+	if ((latency_interval != 0)
+	    && (latency_interval <= (2 * standard_deviation)))
+		pp_pl_log(3,
+			  "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
+			  "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
+			  pp->dev, latency_interval, avglatency,
+			  standard_deviation, base_num);
+
+	rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
+	return rc;
 }
#4 lore raw
In reply to Xose Vazquez Perez
Quoted 2 lines · Xose Vazquez Perez

Mainly running scripts/Lindent, from kernel dir, to replace indent spaces by tabs.

Patch missing in last merge.

Quoted 426 lines
Cc Yang Feng <[email protected]>
Cc Christophe Varoqui <[email protected]>
Cc device-mapper development <[email protected]>
---
 libmultipath/prioritizers/path_latency.c | 354 +++++++++++++++----------------
 1 file changed, 177 insertions(+), 177 deletions(-)
libmultipath/prioritizers/path_latency.c +177 -177
index 34b734b..9fc2dfc 100644
@@ -17,8 +17,8 @@
  * Author(s): Yang Feng <[email protected]>
  *
  * This file is released under the GPL version 2, or any later version.
- *
  */
+
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>
@@ -31,27 +31,28 @@
 
 #define pp_pl_log(prio, fmt, args...) condlog(prio, "path_latency prio: " fmt, ##args)
 
-#define MAX_IO_NUM              200
-#define MIN_IO_NUM              2
+#define MAX_IO_NUM		200
+#define MIN_IO_NUM		2
 
-#define MAX_BASE_NUM            10
-#define MIN_BASE_NUM            2
+#define MAX_BASE_NUM		10
+#define MIN_BASE_NUM		2
 
-#define MAX_AVG_LATENCY         100000000.  /*Unit: us*/
-#define MIN_AVG_LATENCY         1.          /*Unit: us*/
+#define MAX_AVG_LATENCY		100000000.	/* Unit: us */
+#define MIN_AVG_LATENCY		1.		/* Unit: us */
 
-#define DEFAULT_PRIORITY        0
+#define DEFAULT_PRIORITY	0
 
-#define MAX_CHAR_SIZE           30
+#define MAX_CHAR_SIZE		30
 
-#define USEC_PER_SEC            1000000LL
-#define NSEC_PER_USEC           1000LL
+#define USEC_PER_SEC		1000000LL
+#define NSEC_PER_USEC		1000LL
 
 static long long path_latency[MAX_IO_NUM];
 
 static inline long long timeval_to_us(const struct timespec *tv)
 {
-	return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv->tv_nsec / NSEC_PER_USEC);
+	return ((long long)tv->tv_sec * USEC_PER_SEC) +
+	    (tv->tv_nsec / NSEC_PER_USEC);
 }
 
 static int do_readsector0(int fd, unsigned int timeout)
@@ -60,198 +61,197 @@ static int do_readsector0(int fd, unsigned int timeout)
 	unsigned char sbuf[SENSE_BUFF_LEN];
 	int ret;
 
-	ret = sg_read(fd, &buf[0], 4096, &sbuf[0],
-		      SENSE_BUFF_LEN, timeout);
+	ret = sg_read(fd, &buf[0], 4096, &sbuf[0], SENSE_BUFF_LEN, timeout);
 
 	return ret;
 }
 
 int check_args_valid(int io_num, int base_num)
 {
-    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
-    {
-        pp_pl_log(0, "args io_num is outside the valid range");
-        return 0;
-    }
-
-    if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM))
-    {
-        pp_pl_log(0, "args base_num is outside the valid range");
-        return 0;
-    }
-
-    return 1;
+	if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM)) {
+		pp_pl_log(0, "args io_num is outside the valid range");
+		return 0;
+	}
+
+	if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM)) {
+		pp_pl_log(0, "args base_num is outside the valid range");
+		return 0;
+	}
+
+	return 1;
 }
 
-/* In multipath.conf, args form: io_num|base_num. For example,
-*  args is "20|10", this function can get io_num value 20, and
-   base_num value 10.
-*/
-static int get_ionum_and_basenum(char *args,
-                                 int *ionum,
-                                 int *basenum)
+/*
+ * In multipath.conf, args form: io_num|base_num. For example,
+ * args is "20|10", this function can get io_num value 20, and
+ * base_num value 10.
+ */
+static int get_ionum_and_basenum(char *args, int *ionum, int *basenum)
 {
-    char source[MAX_CHAR_SIZE];
-    char vertica = '|';
-    char *endstrbefore = NULL;
-    char *endstrafter = NULL;
-    unsigned int size = strlen(args);
-
-    if ((args == NULL) || (ionum == NULL) || (basenum == NULL))
-    {
-        pp_pl_log(0, "args string is NULL");
-        return 0;
-    }
-
-    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
-    {
-        pp_pl_log(0, "args string's size is too long");
-        return 0;
-    }
-
-    memcpy(source, args, size+1);
-
-    if (!isdigit(source[0]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *ionum = (int)strtoul(source, &endstrbefore, 10);
-    if (endstrbefore[0] != vertica)
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    if (!isdigit(endstrbefore[1]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
-    if (check_args_valid(*ionum, *basenum) == 0)
-    {
-        return 0;
-    }
-
-    return 1;
+	char source[MAX_CHAR_SIZE];
+	char vertica = '|';
+	char *endstrbefore = NULL;
+	char *endstrafter = NULL;
+	unsigned int size = strlen(args);
+
+	if ((args == NULL) || (ionum == NULL) || (basenum == NULL)) {
+		pp_pl_log(0, "args string is NULL");
+		return 0;
+	}
+
+	if ((size < 1) || (size > MAX_CHAR_SIZE - 1)) {
+		pp_pl_log(0, "args string's size is too long");
+		return 0;
+	}
+
+	memcpy(source, args, size + 1);
+
+	if (!isdigit(source[0])) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	*ionum = (int)strtoul(source, &endstrbefore, 10);
+	if (endstrbefore[0] != vertica) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	if (!isdigit(endstrbefore[1])) {
+		pp_pl_log(0, "invalid prio_args format: %s", source);
+		return 0;
+	}
+
+	*basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
+	if (check_args_valid(*ionum, *basenum) == 0) {
+		return 0;
+	}
+
+	return 1;
 }
 
-long long calc_standard_deviation(long long *path_latency, int size, long long avglatency)
+long long calc_standard_deviation(long long *path_latency, int size,
+				  long long avglatency)
 {
-    int index;
-    long long total = 0;
+	int index;
+	long long total = 0;
 
-    for (index = 0; index < size; index++)
-    {
-        total += (path_latency[index] - avglatency) * (path_latency[index] - avglatency);
-    }
+	for (index = 0; index < size; index++) {
+		total +=
+		    (path_latency[index] - avglatency) * (path_latency[index] -
+							  avglatency);
+	}
 
-    total /= (size-1);
+	total /= (size - 1);
 
-    return (long long)sqrt((double)total);
+	return (long long)sqrt((double)total);
 }
 
-int calcPrio(double avglatency, double max_avglatency, double min_avglatency, double base_num)
+int calcPrio(double avglatency, double max_avglatency, double min_avglatency,
+	     double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
+	double lavglatency = log(avglatency) / log(base_num);
+	double lmax_avglatency = log(max_avglatency) / log(base_num);
+	double lmin_avglatency = log(min_avglatency) / log(base_num);
 
-    if (lavglatency <= lmin_avglatency)
-        return (int)(lmax_avglatency + 1.);
+	if (lavglatency <= lmin_avglatency)
+		return (int)(lmax_avglatency + 1.);
 
-    if (lavglatency > lmax_avglatency)
-        return 0;
+	if (lavglatency > lmax_avglatency)
+		return 0;
 
-    return (int)(lmax_avglatency - lavglatency + 1.);
+	return (int)(lmax_avglatency - lavglatency + 1.);
 }
 
 /* Calc the latency interval corresponding to the average latency */
 long long calc_latency_interval(double avglatency, double max_avglatency,
-                                double min_avglatency, double base_num)
+				double min_avglatency, double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
-
-    if ((lavglatency <= lmin_avglatency)
-        || (lavglatency > lmax_avglatency))
-        return 0;/* Invalid value */
-
-    if ((double)((int)lavglatency) == lavglatency)
-        return (long long)(avglatency - (avglatency / base_num));
-    else
-        return (long long)(pow(base_num, (double)((int)lavglatency + 1))
-            - pow(base_num, (double)((int)lavglatency)));
+	double lavglatency = log(avglatency) / log(base_num);
+	double lmax_avglatency = log(max_avglatency) / log(base_num);
+	double lmin_avglatency = log(min_avglatency) / log(base_num);
+
+	if ((lavglatency <= lmin_avglatency)
+	    || (lavglatency > lmax_avglatency))
+		return 0;	/* Invalid value */
+
+	if ((double)((int)lavglatency) == lavglatency)
+		return (long long)(avglatency - (avglatency / base_num));
+	else
+		return (long long)(pow(base_num, (double)((int)lavglatency + 1))
+				   - pow(base_num, (double)((int)lavglatency)));
 }
 
-int getprio (struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, char *args, unsigned int timeout)
 {
-    int rc, temp;
-    int index = 0;
-    int io_num;
-    int base_num;
-    long long avglatency;
-    long long latency_interval;
-    long long standard_deviation;
-    long long toldelay = 0;
-    long long before, after;
-    struct timespec tv;
-
-    if (pp->fd < 0)
-        return -1;
-
-    if (get_ionum_and_basenum(args, &io_num, &base_num) == 0)
-    {
-        pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
-        return DEFAULT_PRIORITY;
-    }
-
-    memset(path_latency, 0, sizeof(path_latency));
-
-    temp = io_num;
-    while (temp-- > 0)
-    {
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        before = timeval_to_us(&tv);
-
-        if (do_readsector0(pp->fd, timeout) == 2)
-        {
-            pp_pl_log(0, "%s: path down", pp->dev);
-            return -1;
-        }
-
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        after = timeval_to_us(&tv);
-
-        path_latency[index] = after - before;
-        toldelay += path_latency[index++];
-    }
-
-    avglatency = toldelay/(long long)io_num;
-    pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
-
-    if (avglatency > MAX_AVG_LATENCY)
-    {
-        pp_pl_log(0, "%s: average latency (%lld us) is outside the thresold (%lld us)",
-            pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
-        return DEFAULT_PRIORITY;
-    }
-
-    /* Min average latency and max average latency are constant, the args base_num
-    set can change latency_interval value corresponding to avglatency and is not constant.
-    Warn the user if latency_interval is smaller than (2 * standard_deviation), or equal */
-    standard_deviation = calc_standard_deviation(path_latency, index, avglatency);
-    latency_interval = calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    if ((latency_interval!= 0)
-        && (latency_interval <= (2 * standard_deviation)))
-        pp_pl_log(3, "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
-            "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
-            pp->dev, latency_interval, avglatency, standard_deviation, base_num);
-
-    rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    return rc;
+	int rc, temp;
+	int index = 0;
+	int io_num;
+	int base_num;
+	long long avglatency;
+	long long latency_interval;
+	long long standard_deviation;
+	long long toldelay = 0;
+	long long before, after;
+	struct timespec tv;
+
+	if (pp->fd < 0)
+		return -1;
+
+	if (get_ionum_and_basenum(args, &io_num, &base_num) == 0) {
+		pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
+		return DEFAULT_PRIORITY;
+	}
+
+	memset(path_latency, 0, sizeof(path_latency));
+
+	temp = io_num;
+	while (temp-- > 0) {
+		(void)clock_gettime(CLOCK_MONOTONIC, &tv);
+		before = timeval_to_us(&tv);
+
+		if (do_readsector0(pp->fd, timeout) == 2) {
+			pp_pl_log(0, "%s: path down", pp->dev);
+			return -1;
+		}
+
+		(void)clock_gettime(CLOCK_MONOTONIC, &tv);
+		after = timeval_to_us(&tv);
+
+		path_latency[index] = after - before;
+		toldelay += path_latency[index++];
+	}
+
+	avglatency = toldelay / (long long)io_num;
+	pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
+
+	if (avglatency > MAX_AVG_LATENCY) {
+		pp_pl_log(0,
+			  "%s: average latency (%lld us) is outside the thresold (%lld us)",
+			  pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
+		return DEFAULT_PRIORITY;
+	}
+
+	/*
+	 * Min average latency and max average latency are constant, the args
+	 * base_num set can change latency_interval value corresponding to
+	 * avglatency and is not constant.
+	 * Warn the user if latency_interval is smaller than (2 * standard_deviation),
+	 * or equal.
+	 */
+	standard_deviation =
+	    calc_standard_deviation(path_latency, index, avglatency);
+	latency_interval =
+	    calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,
+				  base_num);
+	if ((latency_interval != 0)
+	    && (latency_interval <= (2 * standard_deviation)))
+		pp_pl_log(3,
+			  "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
+			  "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
+			  pp->dev, latency_interval, avglatency,
+			  standard_deviation, base_num);
+
+	rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
+	return rc;
 }
#5 lore raw

Bart,

Do you have pending patches on this file you'd like to submit before I merge this l'indentation patch ?

Regards,
Christophe

Le 4 août 2017 18:39, "Xose Vazquez Perez" <[email protected]> a écrit :

Quoted 468 lines · Xose Vazquez Perez
Quoted 3 lines

Mainly running scripts/Lindent, from kernel dir, to replace indent spaces by tabs.

Patch missing in last merge.

Quoted 6 lines
Cc Yang Feng <[email protected]>
Cc Christophe Varoqui <[email protected]>
Cc device-mapper development <[email protected]>
---
 libmultipath/prioritizers/path_latency.c | 354

+++++++++++++++----------------

Review

Quoted 3 lines
 1 file changed, 177 insertions(+), 177 deletions(-)
(quoted diff) +0 -0

b/libmultipath/prioritizers/path_latency.c

Quoted 14 lines

index 34b734b..9fc2dfc 100644

libmultipath/prioritizers/path_latency.c +1 -1
@@ -17,8 +17,8 @@
  * Author(s): Yang Feng <[email protected]>
  *
  * This file is released under the GPL version 2, or any later version.
- *
  */
+
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>

libmultipath/prioritizers/path_latency.c line 32

Quoted 2 lines
libmultipath/prioritizers/path_latency.c +0 -0
@@ -31,27 +31,28 @@
 
 #define pp_pl_log(prio, fmt, args...) condlog(prio, "path_latency prio:

" fmt, ##args)

Quoted 22 lines
libmultipath/prioritizers/path_latency.c +8 -8
-#define MAX_IO_NUM              200
-#define MIN_IO_NUM              2
+#define MAX_IO_NUM           200
+#define MIN_IO_NUM           2
 
-#define MAX_BASE_NUM            10
-#define MIN_BASE_NUM            2
+#define MAX_BASE_NUM         10
+#define MIN_BASE_NUM         2
 
-#define MAX_AVG_LATENCY         100000000.  /*Unit: us*/
-#define MIN_AVG_LATENCY         1.          /*Unit: us*/
+#define MAX_AVG_LATENCY              100000000.      /* Unit: us */
+#define MIN_AVG_LATENCY              1.              /* Unit: us */
 
-#define DEFAULT_PRIORITY        0
+#define DEFAULT_PRIORITY     0
 
-#define MAX_CHAR_SIZE           30
+#define MAX_CHAR_SIZE                30
 

libmultipath/prioritizers/path_latency.c

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +2 -3
-#define USEC_PER_SEC            1000000LL
-#define NSEC_PER_USEC           1000LL
+#define USEC_PER_SEC         1000000LL
+#define NSEC_PER_USEC                1000LL
 
 static long long path_latency[MAX_IO_NUM];
 
 static inline long long timeval_to_us(const struct timespec *tv)
 {
-     return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv->tv_nsec /

NSEC_PER_USEC);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +2 -0
+     return ((long long)tv->tv_sec * USEC_PER_SEC) +
+         (tv->tv_nsec / NSEC_PER_USEC);
 }
 
 static int do_readsector0(int fd, unsigned int timeout)
@@ -60,198 +61,197 @@ static int do_readsector0(int fd, unsigned int

timeout)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +1 -2
      unsigned char sbuf[SENSE_BUFF_LEN];
      int ret;
 
-     ret = sg_read(fd, &buf[0], 4096, &sbuf[0],
-                   SENSE_BUFF_LEN, timeout);
+     ret = sg_read(fd, &buf[0], 4096, &sbuf[0], SENSE_BUFF_LEN,

timeout);

Quoted 125 lines
libmultipath/prioritizers/path_latency.c +50 -66
      return ret;
 }
 
 int check_args_valid(int io_num, int base_num)
 {
-    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
-    {
-        pp_pl_log(0, "args io_num is outside the valid range");
-        return 0;
-    }
-
-    if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM))
-    {
-        pp_pl_log(0, "args base_num is outside the valid range");
-        return 0;
-    }
-
-    return 1;
+     if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM)) {
+             pp_pl_log(0, "args io_num is outside the valid range");
+             return 0;
+     }
+
+     if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM)) {
+             pp_pl_log(0, "args base_num is outside the valid range");
+             return 0;
+     }
+
+     return 1;
 }
 
-/* In multipath.conf, args form: io_num|base_num. For example,
-*  args is "20|10", this function can get io_num value 20, and
-   base_num value 10.
-*/
-static int get_ionum_and_basenum(char *args,
-                                 int *ionum,
-                                 int *basenum)
+/*
+ * In multipath.conf, args form: io_num|base_num. For example,
+ * args is "20|10", this function can get io_num value 20, and
+ * base_num value 10.
+ */
+static int get_ionum_and_basenum(char *args, int *ionum, int *basenum)
 {
-    char source[MAX_CHAR_SIZE];
-    char vertica = '|';
-    char *endstrbefore = NULL;
-    char *endstrafter = NULL;
-    unsigned int size = strlen(args);
-
-    if ((args == NULL) || (ionum == NULL) || (basenum == NULL))
-    {
-        pp_pl_log(0, "args string is NULL");
-        return 0;
-    }
-
-    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
-    {
-        pp_pl_log(0, "args string's size is too long");
-        return 0;
-    }
-
-    memcpy(source, args, size+1);
-
-    if (!isdigit(source[0]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *ionum = (int)strtoul(source, &endstrbefore, 10);
-    if (endstrbefore[0] != vertica)
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    if (!isdigit(endstrbefore[1]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
-    if (check_args_valid(*ionum, *basenum) == 0)
-    {
-        return 0;
-    }
-
-    return 1;
+     char source[MAX_CHAR_SIZE];
+     char vertica = '|';
+     char *endstrbefore = NULL;
+     char *endstrafter = NULL;
+     unsigned int size = strlen(args);
+
+     if ((args == NULL) || (ionum == NULL) || (basenum == NULL)) {
+             pp_pl_log(0, "args string is NULL");
+             return 0;
+     }
+
+     if ((size < 1) || (size > MAX_CHAR_SIZE - 1)) {
+             pp_pl_log(0, "args string's size is too long");
+             return 0;
+     }
+
+     memcpy(source, args, size + 1);
+
+     if (!isdigit(source[0])) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }
+
+     *ionum = (int)strtoul(source, &endstrbefore, 10);
+     if (endstrbefore[0] != vertica) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }
+
+     if (!isdigit(endstrbefore[1])) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +7 -1
+
+     *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
+     if (check_args_valid(*ionum, *basenum) == 0) {
+             return 0;
+     }
+
+     return 1;
 }
 
-long long calc_standard_deviation(long long *path_latency, int size,

long long avglatency)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 11 lines
libmultipath/prioritizers/path_latency.c +4 -5
+long long calc_standard_deviation(long long *path_latency, int size,
+                               long long avglatency)
 {
-    int index;
-    long long total = 0;
+     int index;
+     long long total = 0;
 
-    for (index = 0; index < size; index++)
-    {
-        total += (path_latency[index] - avglatency) *

(path_latency[index] - avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +3 -1
-    }
+     for (index = 0; index < size; index++) {
+             total +=
+                 (path_latency[index] - avglatency) *

(path_latency[index] -

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 11 lines
libmultipath/prioritizers/path_latency.c +4 -3
+                                                       avglatency);
+     }
 
-    total /= (size-1);
+     total /= (size - 1);
 
-    return (long long)sqrt((double)total);
+     return (long long)sqrt((double)total);
 }
 
-int calcPrio(double avglatency, double max_avglatency, double

min_avglatency, double base_num)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 149

Quoted 1 line
libmultipath/prioritizers/path_latency.c +1 -0
+int calcPrio(double avglatency, double max_avglatency, double

min_avglatency,

Quoted 15 lines
libmultipath/prioritizers/path_latency.c +6 -6
+          double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
+     double lavglatency = log(avglatency) / log(base_num);
+     double lmax_avglatency = log(max_avglatency) / log(base_num);
+     double lmin_avglatency = log(min_avglatency) / log(base_num);
 
-    if (lavglatency <= lmin_avglatency)
-        return (int)(lmax_avglatency + 1.);
+     if (lavglatency <= lmin_avglatency)
+             return (int)(lmax_avglatency + 1.);
 
-    if (lavglatency > lmax_avglatency)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +3 -2
-        return 0;
+     if (lavglatency > lmax_avglatency)
+             return 0;
 
-    return (int)(lmax_avglatency - lavglatency + 1.);
+     return (int)(lmax_avglatency - lavglatency + 1.);
 }
 
 /* Calc the latency interval corresponding to the average latency */
 long long calc_latency_interval(double avglatency, double

max_avglatency,

Quoted 18 lines
libmultipath/prioritizers/path_latency.c +3 -14
-                                double min_avglatency, double base_num)
+                             double min_avglatency, double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
-
-    if ((lavglatency <= lmin_avglatency)
-        || (lavglatency > lmax_avglatency))
-        return 0;/* Invalid value */
-
-    if ((double)((int)lavglatency) == lavglatency)
-        return (long long)(avglatency - (avglatency / base_num));
-    else
-        return (long long)(pow(base_num, (double)((int)lavglatency + 1))
-            - pow(base_num, (double)((int)lavglatency)));
+     double lavglatency = log(avglatency) / log(base_num);
+     double lmax_avglatency = log(max_avglatency) / log(base_num);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +10 -0
+     double lmin_avglatency = log(min_avglatency) / log(base_num);
+
+     if ((lavglatency <= lmin_avglatency)
+         || (lavglatency > lmax_avglatency))
+             return 0;       /* Invalid value */
+
+     if ((double)((int)lavglatency) == lavglatency)
+             return (long long)(avglatency - (avglatency / base_num));
+     else
+             return (long long)(pow(base_num, (double)((int)lavglatency

+ 1))

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 181

Quoted 1 line
libmultipath/prioritizers/path_latency.c +1 -0
+                                - pow(base_num,

(double)((int)lavglatency)));

Quoted 38 lines
libmultipath/prioritizers/path_latency.c +1 -34
 }
 
-int getprio (struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, char *args, unsigned int timeout)
 {
-    int rc, temp;
-    int index = 0;
-    int io_num;
-    int base_num;
-    long long avglatency;
-    long long latency_interval;
-    long long standard_deviation;
-    long long toldelay = 0;
-    long long before, after;
-    struct timespec tv;
-
-    if (pp->fd < 0)
-        return -1;
-
-    if (get_ionum_and_basenum(args, &io_num, &base_num) == 0)
-    {
-        pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
-        return DEFAULT_PRIORITY;
-    }
-
-    memset(path_latency, 0, sizeof(path_latency));
-
-    temp = io_num;
-    while (temp-- > 0)
-    {
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        before = timeval_to_us(&tv);
-
-        if (do_readsector0(pp->fd, timeout) == 2)
-        {
-            pp_pl_log(0, "%s: path down", pp->dev);
-            return -1;
-        }

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +0 -10
-
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        after = timeval_to_us(&tv);
-
-        path_latency[index] = after - before;
-        toldelay += path_latency[index++];
-    }
-
-    avglatency = toldelay/(long long)io_num;
-    pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev,

avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +0 -4
-
-    if (avglatency > MAX_AVG_LATENCY)
-    {
-        pp_pl_log(0, "%s: average latency (%lld us) is outside the

thresold (%lld us)",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 5 lines
libmultipath/prioritizers/path_latency.c +0 -5
-            pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
-        return DEFAULT_PRIORITY;
-    }
-
-    /* Min average latency and max average latency are constant, the

args base_num

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 244

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    set can change latency_interval value corresponding to avglatency

and is not constant.

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 245

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    Warn the user if latency_interval is smaller than (2 *

standard_deviation), or equal */

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 246

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    standard_deviation = calc_standard_deviation(path_latency, index,

avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 247

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    latency_interval = calc_latency_interval(avglatency,

MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 3 lines
libmultipath/prioritizers/path_latency.c +0 -3
-    if ((latency_interval!= 0)
-        && (latency_interval <= (2 * standard_deviation)))
-        pp_pl_log(3, "%s: latency interval (%lld) according to average

latency (%lld us) is smaller than "

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 251

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-            "2 * standard deviation (%lld us), or equal, args base_num

(%d) needs to be set bigger value",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 252

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-            pp->dev, latency_interval, avglatency, standard_deviation,

base_num);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 254

Quoted 2 lines
libmultipath/prioritizers/path_latency.c +0 -2
-
-    rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,

base_num);

Quoted 31 lines
libmultipath/prioritizers/path_latency.c +30 -1
-    return rc;
+     int rc, temp;
+     int index = 0;
+     int io_num;
+     int base_num;
+     long long avglatency;
+     long long latency_interval;
+     long long standard_deviation;
+     long long toldelay = 0;
+     long long before, after;
+     struct timespec tv;
+
+     if (pp->fd < 0)
+             return -1;
+
+     if (get_ionum_and_basenum(args, &io_num, &base_num) == 0) {
+             pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
+             return DEFAULT_PRIORITY;
+     }
+
+     memset(path_latency, 0, sizeof(path_latency));
+
+     temp = io_num;
+     while (temp-- > 0) {
+             (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+             before = timeval_to_us(&tv);
+
+             if (do_readsector0(pp->fd, timeout) == 2) {
+                     pp_pl_log(0, "%s: path down", pp->dev);
+                     return -1;
+             }

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +10 -0
+
+             (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+             after = timeval_to_us(&tv);
+
+             path_latency[index] = after - before;
+             toldelay += path_latency[index++];
+     }
+
+     avglatency = toldelay / (long long)io_num;
+     pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev,

avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +4 -0
+
+     if (avglatency > MAX_AVG_LATENCY) {
+             pp_pl_log(0,
+                       "%s: average latency (%lld us) is outside the

thresold (%lld us)",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +6 -0
+                       pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
+             return DEFAULT_PRIORITY;
+     }
+
+     /*
+      * Min average latency and max average latency are constant, the

args

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 3 lines
libmultipath/prioritizers/path_latency.c +3 -0
+      * base_num set can change latency_interval value corresponding to
+      * avglatency and is not constant.
+      * Warn the user if latency_interval is smaller than (2 *

standard_deviation),

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +6 -0
+      * or equal.
+      */
+     standard_deviation =
+         calc_standard_deviation(path_latency, index, avglatency);
+     latency_interval =
+         calc_latency_interval(avglatency, MAX_AVG_LATENCY,

MIN_AVG_LATENCY,

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 5 lines
libmultipath/prioritizers/path_latency.c +5 -0
+                               base_num);
+     if ((latency_interval != 0)
+         && (latency_interval <= (2 * standard_deviation)))
+             pp_pl_log(3,
+                       "%s: latency interval (%lld) according to

average latency (%lld us) is smaller than "

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 250

Quoted 1 line
libmultipath/prioritizers/path_latency.c +1 -0
+                       "2 * standard deviation (%lld us), or equal,

args base_num (%d) needs to be set bigger value",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +4 -0
+                       pp->dev, latency_interval, avglatency,
+                       standard_deviation, base_num);
+
+     rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,

base_num);

Quoted 3 lines
libmultipath/prioritizers/path_latency.c +1 -0
+     return rc;
 }
 
#6 lore raw

Hello Christophe,

Thanks for asking. I have one pending patch for which I have not yet had the time to post it on the dm-devel mailing list but it does not affect the libmultipath/prioritizers/path_latency.c source file. So please proceed with merging Xose's patch.

Bart.

On Fri, 2017-08-04 at 19:18 +0200, Christophe Varoqui wrote:
Bart,

Do you have pending patches on this file you'd like to submit before I merge this l'indentation patch ?

Regards,
Christophe

Le 4 août 2017 18:39, "Xose Vazquez Perez" <[email protected]<mailto:[email protected]>> a écrit :

Quoted 2 lines · Xose Vazquez Perez

Mainly running scripts/Lindent, from kernel dir, to replace indent spaces by tabs.

Patch missing in last merge.

Quoted 426 lines
---
 libmultipath/prioritizers/path_latency.c | 354 +++++++++++++++----------------
 1 file changed, 177 insertions(+), 177 deletions(-)
libmultipath/prioritizers/path_latency.c +177 -177
index 34b734b..9fc2dfc 100644
@@ -17,8 +17,8 @@
  * Author(s): Yang Feng <[email protected]<mailto:[email protected]>>
  *
  * This file is released under the GPL version 2, or any later version.
- *
  */
+
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>
@@ -31,27 +31,28 @@
 
 #define pp_pl_log(prio, fmt, args...) condlog(prio, "path_latency prio: " fmt, ##args)
 
-#define MAX_IO_NUM              200
-#define MIN_IO_NUM              2
+#define MAX_IO_NUM           200
+#define MIN_IO_NUM           2
 
-#define MAX_BASE_NUM            10
-#define MIN_BASE_NUM            2
+#define MAX_BASE_NUM         10
+#define MIN_BASE_NUM         2
 
-#define MAX_AVG_LATENCY         100000000.  /*Unit: us*/
-#define MIN_AVG_LATENCY         1.          /*Unit: us*/
+#define MAX_AVG_LATENCY              100000000.      /* Unit: us */
+#define MIN_AVG_LATENCY              1.              /* Unit: us */
 
-#define DEFAULT_PRIORITY        0
+#define DEFAULT_PRIORITY     0
 
-#define MAX_CHAR_SIZE           30
+#define MAX_CHAR_SIZE                30
 
-#define USEC_PER_SEC            1000000LL
-#define NSEC_PER_USEC           1000LL
+#define USEC_PER_SEC         1000000LL
+#define NSEC_PER_USEC                1000LL
 
 static long long path_latency[MAX_IO_NUM];
 
 static inline long long timeval_to_us(const struct timespec *tv)
 {
-     return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv->tv_nsec / NSEC_PER_USEC);
+     return ((long long)tv->tv_sec * USEC_PER_SEC) +
+         (tv->tv_nsec / NSEC_PER_USEC);
 }
 
 static int do_readsector0(int fd, unsigned int timeout)
@@ -60,198 +61,197 @@ static int do_readsector0(int fd, unsigned int timeout)
      unsigned char sbuf[SENSE_BUFF_LEN];
      int ret;
 
-     ret = sg_read(fd, &buf[0], 4096, &sbuf[0],
-                   SENSE_BUFF_LEN, timeout);
+     ret = sg_read(fd, &buf[0], 4096, &sbuf[0], SENSE_BUFF_LEN, timeout);
 
      return ret;
 }
 
 int check_args_valid(int io_num, int base_num)
 {
-    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
-    {
-        pp_pl_log(0, "args io_num is outside the valid range");
-        return 0;
-    }
-
-    if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM))
-    {
-        pp_pl_log(0, "args base_num is outside the valid range");
-        return 0;
-    }
-
-    return 1;
+     if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM)) {
+             pp_pl_log(0, "args io_num is outside the valid range");
+             return 0;
+     }
+
+     if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM)) {
+             pp_pl_log(0, "args base_num is outside the valid range");
+             return 0;
+     }
+
+     return 1;
 }
 
-/* In multipath.conf, args form: io_num|base_num. For example,
-*  args is "20|10", this function can get io_num value 20, and
-   base_num value 10.
-*/
-static int get_ionum_and_basenum(char *args,
-                                 int *ionum,
-                                 int *basenum)
+/*
+ * In multipath.conf, args form: io_num|base_num. For example,
+ * args is "20|10", this function can get io_num value 20, and
+ * base_num value 10.
+ */
+static int get_ionum_and_basenum(char *args, int *ionum, int *basenum)
 {
-    char source[MAX_CHAR_SIZE];
-    char vertica = '|';
-    char *endstrbefore = NULL;
-    char *endstrafter = NULL;
-    unsigned int size = strlen(args);
-
-    if ((args == NULL) || (ionum == NULL) || (basenum == NULL))
-    {
-        pp_pl_log(0, "args string is NULL");
-        return 0;
-    }
-
-    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
-    {
-        pp_pl_log(0, "args string's size is too long");
-        return 0;
-    }
-
-    memcpy(source, args, size+1);
-
-    if (!isdigit(source[0]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *ionum = (int)strtoul(source, &endstrbefore, 10);
-    if (endstrbefore[0] != vertica)
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    if (!isdigit(endstrbefore[1]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
-    if (check_args_valid(*ionum, *basenum) == 0)
-    {
-        return 0;
-    }
-
-    return 1;
+     char source[MAX_CHAR_SIZE];
+     char vertica = '|';
+     char *endstrbefore = NULL;
+     char *endstrafter = NULL;
+     unsigned int size = strlen(args);
+
+     if ((args == NULL) || (ionum == NULL) || (basenum == NULL)) {
+             pp_pl_log(0, "args string is NULL");
+             return 0;
+     }
+
+     if ((size < 1) || (size > MAX_CHAR_SIZE - 1)) {
+             pp_pl_log(0, "args string's size is too long");
+             return 0;
+     }
+
+     memcpy(source, args, size + 1);
+
+     if (!isdigit(source[0])) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }
+
+     *ionum = (int)strtoul(source, &endstrbefore, 10);
+     if (endstrbefore[0] != vertica) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }
+
+     if (!isdigit(endstrbefore[1])) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }
+
+     *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
+     if (check_args_valid(*ionum, *basenum) == 0) {
+             return 0;
+     }
+
+     return 1;
 }
 
-long long calc_standard_deviation(long long *path_latency, int size, long long avglatency)
+long long calc_standard_deviation(long long *path_latency, int size,
+                               long long avglatency)
 {
-    int index;
-    long long total = 0;
+     int index;
+     long long total = 0;
 
-    for (index = 0; index < size; index++)
-    {
-        total += (path_latency[index] - avglatency) * (path_latency[index] - avglatency);
-    }
+     for (index = 0; index < size; index++) {
+             total +=
+                 (path_latency[index] - avglatency) * (path_latency[index] -
+                                                       avglatency);
+     }
 
-    total /= (size-1);
+     total /= (size - 1);
 
-    return (long long)sqrt((double)total);
+     return (long long)sqrt((double)total);
 }
 
-int calcPrio(double avglatency, double max_avglatency, double min_avglatency, double base_num)
+int calcPrio(double avglatency, double max_avglatency, double min_avglatency,
+          double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
+     double lavglatency = log(avglatency) / log(base_num);
+     double lmax_avglatency = log(max_avglatency) / log(base_num);
+     double lmin_avglatency = log(min_avglatency) / log(base_num);
 
-    if (lavglatency <= lmin_avglatency)
-        return (int)(lmax_avglatency + 1.);
+     if (lavglatency <= lmin_avglatency)
+             return (int)(lmax_avglatency + 1.);
 
-    if (lavglatency > lmax_avglatency)
-        return 0;
+     if (lavglatency > lmax_avglatency)
+             return 0;
 
-    return (int)(lmax_avglatency - lavglatency + 1.);
+     return (int)(lmax_avglatency - lavglatency + 1.);
 }
 
 /* Calc the latency interval corresponding to the average latency */
 long long calc_latency_interval(double avglatency, double max_avglatency,
-                                double min_avglatency, double base_num)
+                             double min_avglatency, double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
-
-    if ((lavglatency <= lmin_avglatency)
-        || (lavglatency > lmax_avglatency))
-        return 0;/* Invalid value */
-
-    if ((double)((int)lavglatency) == lavglatency)
-        return (long long)(avglatency - (avglatency / base_num));
-    else
-        return (long long)(pow(base_num, (double)((int)lavglatency + 1))
-            - pow(base_num, (double)((int)lavglatency)));
+     double lavglatency = log(avglatency) / log(base_num);
+     double lmax_avglatency = log(max_avglatency) / log(base_num);
+     double lmin_avglatency = log(min_avglatency) / log(base_num);
+
+     if ((lavglatency <= lmin_avglatency)
+         || (lavglatency > lmax_avglatency))
+             return 0;       /* Invalid value */
+
+     if ((double)((int)lavglatency) == lavglatency)
+             return (long long)(avglatency - (avglatency / base_num));
+     else
+             return (long long)(pow(base_num, (double)((int)lavglatency + 1))
+                                - pow(base_num, (double)((int)lavglatency)));
 }
 
-int getprio (struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, char *args, unsigned int timeout)
 {
-    int rc, temp;
-    int index = 0;
-    int io_num;
-    int base_num;
-    long long avglatency;
-    long long latency_interval;
-    long long standard_deviation;
-    long long toldelay = 0;
-    long long before, after;
-    struct timespec tv;
-
-    if (pp->fd < 0)
-        return -1;
-
-    if (get_ionum_and_basenum(args, &io_num, &base_num) == 0)
-    {
-        pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
-        return DEFAULT_PRIORITY;
-    }
-
-    memset(path_latency, 0, sizeof(path_latency));
-
-    temp = io_num;
-    while (temp-- > 0)
-    {
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        before = timeval_to_us(&tv);
-
-        if (do_readsector0(pp->fd, timeout) == 2)
-        {
-            pp_pl_log(0, "%s: path down", pp->dev);
-            return -1;
-        }
-
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        after = timeval_to_us(&tv);
-
-        path_latency[index] = after - before;
-        toldelay += path_latency[index++];
-    }
-
-    avglatency = toldelay/(long long)io_num;
-    pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
-
-    if (avglatency > MAX_AVG_LATENCY)
-    {
-        pp_pl_log(0, "%s: average latency (%lld us) is outside the thresold (%lld us)",
-            pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
-        return DEFAULT_PRIORITY;
-    }
-
-    /* Min average latency and max average latency are constant, the args base_num
-    set can change latency_interval value corresponding to avglatency and is not constant.
-    Warn the user if latency_interval is smaller than (2 * standard_deviation), or equal */
-    standard_deviation = calc_standard_deviation(path_latency, index, avglatency);
-    latency_interval = calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    if ((latency_interval!= 0)
-        && (latency_interval <= (2 * standard_deviation)))
-        pp_pl_log(3, "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
-            "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
-            pp->dev, latency_interval, avglatency, standard_deviation, base_num);
-
-    rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
-    return rc;
+     int rc, temp;
+     int index = 0;
+     int io_num;
+     int base_num;
+     long long avglatency;
+     long long latency_interval;
+     long long standard_deviation;
+     long long toldelay = 0;
+     long long before, after;
+     struct timespec tv;
+
+     if (pp->fd < 0)
+             return -1;
+
+     if (get_ionum_and_basenum(args, &io_num, &base_num) == 0) {
+             pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
+             return DEFAULT_PRIORITY;
+     }
+
+     memset(path_latency, 0, sizeof(path_latency));
+
+     temp = io_num;
+     while (temp-- > 0) {
+             (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+             before = timeval_to_us(&tv);
+
+             if (do_readsector0(pp->fd, timeout) == 2) {
+                     pp_pl_log(0, "%s: path down", pp->dev);
+                     return -1;
+             }
+
+             (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+             after = timeval_to_us(&tv);
+
+             path_latency[index] = after - before;
+             toldelay += path_latency[index++];
+     }
+
+     avglatency = toldelay / (long long)io_num;
+     pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev, avglatency);
+
+     if (avglatency > MAX_AVG_LATENCY) {
+             pp_pl_log(0,
+                       "%s: average latency (%lld us) is outside the thresold (%lld us)",
+                       pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
+             return DEFAULT_PRIORITY;
+     }
+
+     /*
+      * Min average latency and max average latency are constant, the args
+      * base_num set can change latency_interval value corresponding to
+      * avglatency and is not constant.
+      * Warn the user if latency_interval is smaller than (2 * standard_deviation),
+      * or equal.
+      */
+     standard_deviation =
+         calc_standard_deviation(path_latency, index, avglatency);
+     latency_interval =
+         calc_latency_interval(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,
+                               base_num);
+     if ((latency_interval != 0)
+         && (latency_interval <= (2 * standard_deviation)))
+             pp_pl_log(3,
+                       "%s: latency interval (%lld) according to average latency (%lld us) is smaller than "
+                       "2 * standard deviation (%lld us), or equal, args base_num (%d) needs to be set bigger value",
+                       pp->dev, latency_interval, avglatency,
+                       standard_deviation, base_num);
+
+     rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);
+     return rc;
 }
#7 lore raw

Ok, done.

Quoted 491 lines · Bart Van Assche

Hello Christophe,

Thanks for asking. I have one pending patch for which I have not yet had the time to post it on the dm-devel mailing list but it does not affect the libmultipath/prioritizers/path_latency.c source file. So please proceed with merging Xose's patch.

Bart.

On Fri, 2017-08-04 at 19:18 +0200, Christophe Varoqui wrote:

Bart,

Do you have pending patches on this file you'd like to submit before I merge this l'indentation patch ?

Regards,
Christophe

Le 4 août 2017 18:39, "Xose Vazquez Perez" <[email protected]> a écrit :

Quoted 2 lines · Xose Vazquez Perez

Mainly running scripts/Lindent, from kernel dir, to replace indent spaces by tabs.

Patch missing in last merge.

Quoted 6 lines
Cc Yang Feng <[email protected]>
Cc Christophe Varoqui <[email protected]>
Cc device-mapper development <[email protected]>
---
 libmultipath/prioritizers/path_latency.c | 354

+++++++++++++++----------------

Review

Quoted 3 lines
 1 file changed, 177 insertions(+), 177 deletions(-)
(quoted diff) +0 -0

b/libmultipath/prioritizers/path_latency.c

Quoted 14 lines

index 34b734b..9fc2dfc 100644

libmultipath/prioritizers/path_latency.c +1 -1
@@ -17,8 +17,8 @@
  * Author(s): Yang Feng <[email protected]>
  *
  * This file is released under the GPL version 2, or any later version.
- *
  */
+
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>

libmultipath/prioritizers/path_latency.c line 32

Quoted 2 lines
libmultipath/prioritizers/path_latency.c +0 -0
@@ -31,27 +31,28 @@
 
 #define pp_pl_log(prio, fmt, args...) condlog(prio, "path_latency prio:

" fmt, ##args)

Quoted 22 lines
libmultipath/prioritizers/path_latency.c +8 -8
-#define MAX_IO_NUM              200
-#define MIN_IO_NUM              2
+#define MAX_IO_NUM           200
+#define MIN_IO_NUM           2
 
-#define MAX_BASE_NUM            10
-#define MIN_BASE_NUM            2
+#define MAX_BASE_NUM         10
+#define MIN_BASE_NUM         2
 
-#define MAX_AVG_LATENCY         100000000.  /*Unit: us*/
-#define MIN_AVG_LATENCY         1.          /*Unit: us*/
+#define MAX_AVG_LATENCY              100000000.      /* Unit: us */
+#define MIN_AVG_LATENCY              1.              /* Unit: us */
 
-#define DEFAULT_PRIORITY        0
+#define DEFAULT_PRIORITY     0
 
-#define MAX_CHAR_SIZE           30
+#define MAX_CHAR_SIZE                30
 

libmultipath/prioritizers/path_latency.c

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +2 -3
-#define USEC_PER_SEC            1000000LL
-#define NSEC_PER_USEC           1000LL
+#define USEC_PER_SEC         1000000LL
+#define NSEC_PER_USEC                1000LL
 
 static long long path_latency[MAX_IO_NUM];
 
 static inline long long timeval_to_us(const struct timespec *tv)
 {
-     return ((long long) tv->tv_sec * USEC_PER_SEC) + (tv->tv_nsec /

NSEC_PER_USEC);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +2 -0
+     return ((long long)tv->tv_sec * USEC_PER_SEC) +
+         (tv->tv_nsec / NSEC_PER_USEC);
 }
 
 static int do_readsector0(int fd, unsigned int timeout)
@@ -60,198 +61,197 @@ static int do_readsector0(int fd, unsigned int

timeout)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +1 -2
      unsigned char sbuf[SENSE_BUFF_LEN];
      int ret;
 
-     ret = sg_read(fd, &buf[0], 4096, &sbuf[0],
-                   SENSE_BUFF_LEN, timeout);
+     ret = sg_read(fd, &buf[0], 4096, &sbuf[0], SENSE_BUFF_LEN,

timeout);

Quoted 125 lines
libmultipath/prioritizers/path_latency.c +50 -66
      return ret;
 }
 
 int check_args_valid(int io_num, int base_num)
 {
-    if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM))
-    {
-        pp_pl_log(0, "args io_num is outside the valid range");
-        return 0;
-    }
-
-    if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM))
-    {
-        pp_pl_log(0, "args base_num is outside the valid range");
-        return 0;
-    }
-
-    return 1;
+     if ((io_num < MIN_IO_NUM) || (io_num > MAX_IO_NUM)) {
+             pp_pl_log(0, "args io_num is outside the valid range");
+             return 0;
+     }
+
+     if ((base_num < MIN_BASE_NUM) || (base_num > MAX_BASE_NUM)) {
+             pp_pl_log(0, "args base_num is outside the valid range");
+             return 0;
+     }
+
+     return 1;
 }
 
-/* In multipath.conf, args form: io_num|base_num. For example,
-*  args is "20|10", this function can get io_num value 20, and
-   base_num value 10.
-*/
-static int get_ionum_and_basenum(char *args,
-                                 int *ionum,
-                                 int *basenum)
+/*
+ * In multipath.conf, args form: io_num|base_num. For example,
+ * args is "20|10", this function can get io_num value 20, and
+ * base_num value 10.
+ */
+static int get_ionum_and_basenum(char *args, int *ionum, int *basenum)
 {
-    char source[MAX_CHAR_SIZE];
-    char vertica = '|';
-    char *endstrbefore = NULL;
-    char *endstrafter = NULL;
-    unsigned int size = strlen(args);
-
-    if ((args == NULL) || (ionum == NULL) || (basenum == NULL))
-    {
-        pp_pl_log(0, "args string is NULL");
-        return 0;
-    }
-
-    if ((size < 1) || (size > MAX_CHAR_SIZE-1))
-    {
-        pp_pl_log(0, "args string's size is too long");
-        return 0;
-    }
-
-    memcpy(source, args, size+1);
-
-    if (!isdigit(source[0]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *ionum = (int)strtoul(source, &endstrbefore, 10);
-    if (endstrbefore[0] != vertica)
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    if (!isdigit(endstrbefore[1]))
-    {
-        pp_pl_log(0, "invalid prio_args format: %s", source);
-        return 0;
-    }
-
-    *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
-    if (check_args_valid(*ionum, *basenum) == 0)
-    {
-        return 0;
-    }
-
-    return 1;
+     char source[MAX_CHAR_SIZE];
+     char vertica = '|';
+     char *endstrbefore = NULL;
+     char *endstrafter = NULL;
+     unsigned int size = strlen(args);
+
+     if ((args == NULL) || (ionum == NULL) || (basenum == NULL)) {
+             pp_pl_log(0, "args string is NULL");
+             return 0;
+     }
+
+     if ((size < 1) || (size > MAX_CHAR_SIZE - 1)) {
+             pp_pl_log(0, "args string's size is too long");
+             return 0;
+     }
+
+     memcpy(source, args, size + 1);
+
+     if (!isdigit(source[0])) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }
+
+     *ionum = (int)strtoul(source, &endstrbefore, 10);
+     if (endstrbefore[0] != vertica) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }
+
+     if (!isdigit(endstrbefore[1])) {
+             pp_pl_log(0, "invalid prio_args format: %s", source);
+             return 0;
+     }

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +7 -1
+
+     *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10);
+     if (check_args_valid(*ionum, *basenum) == 0) {
+             return 0;
+     }
+
+     return 1;
 }
 
-long long calc_standard_deviation(long long *path_latency, int size,

long long avglatency)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 11 lines
libmultipath/prioritizers/path_latency.c +4 -5
+long long calc_standard_deviation(long long *path_latency, int size,
+                               long long avglatency)
 {
-    int index;
-    long long total = 0;
+     int index;
+     long long total = 0;
 
-    for (index = 0; index < size; index++)
-    {
-        total += (path_latency[index] - avglatency) *

(path_latency[index] - avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +3 -1
-    }
+     for (index = 0; index < size; index++) {
+             total +=
+                 (path_latency[index] - avglatency) *

(path_latency[index] -

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 11 lines
libmultipath/prioritizers/path_latency.c +4 -3
+                                                       avglatency);
+     }
 
-    total /= (size-1);
+     total /= (size - 1);
 
-    return (long long)sqrt((double)total);
+     return (long long)sqrt((double)total);
 }
 
-int calcPrio(double avglatency, double max_avglatency, double

min_avglatency, double base_num)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 149

Quoted 1 line
libmultipath/prioritizers/path_latency.c +1 -0
+int calcPrio(double avglatency, double max_avglatency, double

min_avglatency,

Quoted 15 lines
libmultipath/prioritizers/path_latency.c +6 -6
+          double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
+     double lavglatency = log(avglatency) / log(base_num);
+     double lmax_avglatency = log(max_avglatency) / log(base_num);
+     double lmin_avglatency = log(min_avglatency) / log(base_num);
 
-    if (lavglatency <= lmin_avglatency)
-        return (int)(lmax_avglatency + 1.);
+     if (lavglatency <= lmin_avglatency)
+             return (int)(lmax_avglatency + 1.);
 
-    if (lavglatency > lmax_avglatency)

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +3 -2
-        return 0;
+     if (lavglatency > lmax_avglatency)
+             return 0;
 
-    return (int)(lmax_avglatency - lavglatency + 1.);
+     return (int)(lmax_avglatency - lavglatency + 1.);
 }
 
 /* Calc the latency interval corresponding to the average latency */
 long long calc_latency_interval(double avglatency, double

max_avglatency,

Quoted 18 lines
libmultipath/prioritizers/path_latency.c +3 -14
-                                double min_avglatency, double base_num)
+                             double min_avglatency, double base_num)
 {
-    double lavglatency = log(avglatency)/log(base_num);
-    double lmax_avglatency = log(max_avglatency)/log(base_num);
-    double lmin_avglatency = log(min_avglatency)/log(base_num);
-
-    if ((lavglatency <= lmin_avglatency)
-        || (lavglatency > lmax_avglatency))
-        return 0;/* Invalid value */
-
-    if ((double)((int)lavglatency) == lavglatency)
-        return (long long)(avglatency - (avglatency / base_num));
-    else
-        return (long long)(pow(base_num, (double)((int)lavglatency + 1))
-            - pow(base_num, (double)((int)lavglatency)));
+     double lavglatency = log(avglatency) / log(base_num);
+     double lmax_avglatency = log(max_avglatency) / log(base_num);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +10 -0
+     double lmin_avglatency = log(min_avglatency) / log(base_num);
+
+     if ((lavglatency <= lmin_avglatency)
+         || (lavglatency > lmax_avglatency))
+             return 0;       /* Invalid value */
+
+     if ((double)((int)lavglatency) == lavglatency)
+             return (long long)(avglatency - (avglatency / base_num));
+     else
+             return (long long)(pow(base_num, (double)((int)lavglatency

+ 1))

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 181

Quoted 1 line
libmultipath/prioritizers/path_latency.c +1 -0
+                                - pow(base_num,

(double)((int)lavglatency)));

Quoted 38 lines
libmultipath/prioritizers/path_latency.c +1 -34
 }
 
-int getprio (struct path *pp, char *args, unsigned int timeout)
+int getprio(struct path *pp, char *args, unsigned int timeout)
 {
-    int rc, temp;
-    int index = 0;
-    int io_num;
-    int base_num;
-    long long avglatency;
-    long long latency_interval;
-    long long standard_deviation;
-    long long toldelay = 0;
-    long long before, after;
-    struct timespec tv;
-
-    if (pp->fd < 0)
-        return -1;
-
-    if (get_ionum_and_basenum(args, &io_num, &base_num) == 0)
-    {
-        pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
-        return DEFAULT_PRIORITY;
-    }
-
-    memset(path_latency, 0, sizeof(path_latency));
-
-    temp = io_num;
-    while (temp-- > 0)
-    {
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        before = timeval_to_us(&tv);
-
-        if (do_readsector0(pp->fd, timeout) == 2)
-        {
-            pp_pl_log(0, "%s: path down", pp->dev);
-            return -1;
-        }

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +0 -10
-
-        (void)clock_gettime(CLOCK_MONOTONIC, &tv);
-        after = timeval_to_us(&tv);
-
-        path_latency[index] = after - before;
-        toldelay += path_latency[index++];
-    }
-
-    avglatency = toldelay/(long long)io_num;
-    pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev,

avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +0 -4
-
-    if (avglatency > MAX_AVG_LATENCY)
-    {
-        pp_pl_log(0, "%s: average latency (%lld us) is outside the

thresold (%lld us)",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 5 lines
libmultipath/prioritizers/path_latency.c +0 -5
-            pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
-        return DEFAULT_PRIORITY;
-    }
-
-    /* Min average latency and max average latency are constant, the

args base_num

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 244

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    set can change latency_interval value corresponding to avglatency

and is not constant.

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 245

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    Warn the user if latency_interval is smaller than (2 *

standard_deviation), or equal */

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 246

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    standard_deviation = calc_standard_deviation(path_latency, index,

avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 247

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-    latency_interval = calc_latency_interval(avglatency,

MAX_AVG_LATENCY, MIN_AVG_LATENCY, base_num);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 3 lines
libmultipath/prioritizers/path_latency.c +0 -3
-    if ((latency_interval!= 0)
-        && (latency_interval <= (2 * standard_deviation)))
-        pp_pl_log(3, "%s: latency interval (%lld) according to average

latency (%lld us) is smaller than "

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 251

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-            "2 * standard deviation (%lld us), or equal, args base_num

(%d) needs to be set bigger value",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 252

Quoted 1 line
libmultipath/prioritizers/path_latency.c +0 -1
-            pp->dev, latency_interval, avglatency, standard_deviation,

base_num);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 254

Quoted 2 lines
libmultipath/prioritizers/path_latency.c +0 -2
-
-    rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,

base_num);

Quoted 31 lines
libmultipath/prioritizers/path_latency.c +30 -1
-    return rc;
+     int rc, temp;
+     int index = 0;
+     int io_num;
+     int base_num;
+     long long avglatency;
+     long long latency_interval;
+     long long standard_deviation;
+     long long toldelay = 0;
+     long long before, after;
+     struct timespec tv;
+
+     if (pp->fd < 0)
+             return -1;
+
+     if (get_ionum_and_basenum(args, &io_num, &base_num) == 0) {
+             pp_pl_log(0, "%s: get path_latency args fail", pp->dev);
+             return DEFAULT_PRIORITY;
+     }
+
+     memset(path_latency, 0, sizeof(path_latency));
+
+     temp = io_num;
+     while (temp-- > 0) {
+             (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+             before = timeval_to_us(&tv);
+
+             if (do_readsector0(pp->fd, timeout) == 2) {
+                     pp_pl_log(0, "%s: path down", pp->dev);
+                     return -1;
+             }

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 10 lines
libmultipath/prioritizers/path_latency.c +10 -0
+
+             (void)clock_gettime(CLOCK_MONOTONIC, &tv);
+             after = timeval_to_us(&tv);
+
+             path_latency[index] = after - before;
+             toldelay += path_latency[index++];
+     }
+
+     avglatency = toldelay / (long long)io_num;
+     pp_pl_log(4, "%s: average latency is (%lld us)", pp->dev,

avglatency);

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +4 -0
+
+     if (avglatency > MAX_AVG_LATENCY) {
+             pp_pl_log(0,
+                       "%s: average latency (%lld us) is outside the

thresold (%lld us)",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +6 -0
+                       pp->dev, avglatency, (long long)MAX_AVG_LATENCY);
+             return DEFAULT_PRIORITY;
+     }
+
+     /*
+      * Min average latency and max average latency are constant, the

args

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 3 lines
libmultipath/prioritizers/path_latency.c +3 -0
+      * base_num set can change latency_interval value corresponding to
+      * avglatency and is not constant.
+      * Warn the user if latency_interval is smaller than (2 *

standard_deviation),

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 6 lines
libmultipath/prioritizers/path_latency.c +6 -0
+      * or equal.
+      */
+     standard_deviation =
+         calc_standard_deviation(path_latency, index, avglatency);
+     latency_interval =
+         calc_latency_interval(avglatency, MAX_AVG_LATENCY,

MIN_AVG_LATENCY,

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 5 lines
libmultipath/prioritizers/path_latency.c +5 -0
+                               base_num);
+     if ((latency_interval != 0)
+         && (latency_interval <= (2 * standard_deviation)))
+             pp_pl_log(3,
+                       "%s: latency interval (%lld) according to

average latency (%lld us) is smaller than "

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int · line 250

Quoted 1 line
libmultipath/prioritizers/path_latency.c +1 -0
+                       "2 * standard deviation (%lld us), or equal,

args base_num (%d) needs to be set bigger value",

libmultipath/prioritizers/path_latency.c static int do_readsector0(int fd, unsigned int timeout)

Quoted 4 lines
libmultipath/prioritizers/path_latency.c +4 -0
+                       pp->dev, latency_interval, avglatency,
+                       standard_deviation, base_num);
+
+     rc = calcPrio(avglatency, MAX_AVG_LATENCY, MIN_AVG_LATENCY,

base_num);

Quoted 3 lines
libmultipath/prioritizers/path_latency.c +1 -0
+     return rc;
 }