From patchwork Thu Sep 21 13:23:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan Junxiong X-Patchwork-Id: 9964041 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 732D9600C5 for ; Thu, 21 Sep 2017 14:17:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A67C2953F for ; Thu, 21 Sep 2017 14:17:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D7FB2954B; Thu, 21 Sep 2017 14:17:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0F7372953F for ; Thu, 21 Sep 2017 14:17:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15991267F5; Thu, 21 Sep 2017 14:16:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 15991267F5 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 15991267F5 Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 90B146E51D; Thu, 21 Sep 2017 14:16:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A15D83FACE; Thu, 21 Sep 2017 14:16:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8LDRD0m029621 for ; Thu, 21 Sep 2017 09:27:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 840335D984; Thu, 21 Sep 2017 13:27:13 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EAF35D988 for ; Thu, 21 Sep 2017 13:27:11 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1 with cipher RC4-SHA (112/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA7887EA9A for ; Thu, 21 Sep 2017 13:27:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA7887EA9A Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=guanjunxiong@huawei.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BA7887EA9A Received: from 172.30.72.58 (EHLO DGGEMS410-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHR58037; Thu, 21 Sep 2017 21:23:52 +0800 (CST) Received: from huawei.com (10.169.94.217) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.301.0; Thu, 21 Sep 2017 21:23:45 +0800 From: Guan Junxiong To: , , Date: Thu, 21 Sep 2017 21:23:18 +0800 Message-ID: <1506000199-9644-4-git-send-email-guanjunxiong@huawei.com> In-Reply-To: <1506000199-9644-1-git-send-email-guanjunxiong@huawei.com> References: <1506000199-9644-1-git-send-email-guanjunxiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.169.94.217] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.59C3BD69.0151, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 9d264b2eeacd2c7f0b6246df13ec5f11 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 21 Sep 2017 13:27:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 21 Sep 2017 13:27:10 +0000 (UTC) for IP:'45.249.212.190' DOMAIN:'szxga04-in.huawei.com' HELO:'szxga04-in.huawei.com' FROM:'guanjunxiong@huawei.com' RCPT:'' X-RedHat-Spam-Score: -0.002 (RP_MATCHES_RCVD, SPF_PASS) 45.249.212.190 szxga04-in.huawei.com 45.249.212.190 szxga04-in.huawei.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: xose.vazquez@gmail.com, guanjunxiong@huawei.com, chengjike.cheng@huawei.com, shenhong09@huawei.com, niuhaoxin@huawei.com, mwilck@suse.com Subject: [dm-devel] [PATCH V2 3/4] multipath-tools: use user-friendly prio_args for path-latency X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 21 Sep 2017 14:16:54 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The original prio_args for prioritizer is like this: 20|10 which is somewhat unconvenient for user. This patch drops it and use a syntax that similar to other prioritizers, for example : "base_num=5 io_num=10". Signed-off-by: Junxiong Guan --- libmultipath/prioritizers/path_latency.c | 71 +++++++++++++++++--------------- multipath/multipath.conf.5 | 2 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/libmultipath/prioritizers/path_latency.c b/libmultipath/prioritizers/path_latency.c index c75ae03f..69c9bd65 100644 --- a/libmultipath/prioritizers/path_latency.c +++ b/libmultipath/prioritizers/path_latency.c @@ -15,6 +15,7 @@ * scale, the priority "rc" of each path can be provided. * * Author(s): Yang Feng + * Revised: Guan Junxiong * * This file is released under the GPL version 2, or any later version. */ @@ -32,6 +33,7 @@ #include "debug.h" #include "prio.h" #include "structs.h" +#include "util.h" #define pp_pl_log(prio, fmt, args...) condlog(prio, "path_latency prio: " fmt, ##args) @@ -46,8 +48,6 @@ #define DEFAULT_PRIORITY 0 -#define MAX_CHAR_SIZE 30 - #define USEC_PER_SEC 1000000LL #define NSEC_PER_USEC 1000LL @@ -145,52 +145,55 @@ int check_args_valid(int io_num, int base_num) } /* - * In multipath.conf, args form: io_num|base_num. For example, - * args is "20|10", this function can get io_num value 20, and + * In multipath.conf, args form: io_num=n base_num=m. For example, args are + * "io_num=20 base_num=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); + char split_char[] = " \t"; + char *arg, *temp; + char *str, *str_inval; + int i; + int flag_io = 0, flag_base = 0; 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); + arg = temp = STRDUP(args); + if (!arg) 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; + for (i = 0; i < 2; i++) { + str = get_next_string(&temp, split_char); + if (!str) + goto out; + if (!strncmp(str, "io_num=", 7) && strlen(str) > 7) { + *ionum = (int)strtoul(str + 7, &str_inval, 10); + if (str == str_inval) + goto out; + flag_io = 1; + } + else if (!strncmp(str, "base_num=", 9) && strlen(str) > 9) { + *basenum = (int)strtol(str + 9, &str_inval, 10); + if (str == str_inval) + goto out; + flag_base = 1; + } } - *basenum = (long long)strtol(&endstrbefore[1], &endstrafter, 10); - if (check_args_valid(*ionum, *basenum) == 0) { - return 0; - } + if (!flag_io || !flag_base) + goto out; + if (check_args_valid(*ionum, *basenum) == 0) + goto out; + FREE(arg); return 1; +out: + FREE(arg); + return 0; } long long calc_standard_deviation(long long *path_latency, int size, @@ -249,8 +252,8 @@ int getprio(struct path *pp, char *args, unsigned int timeout) { int rc, temp; int index = 0; - int io_num; - int base_num; + int io_num = 0; + int base_num = 0; long long avglatency; long long latency_interval; long long standard_deviation; diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5 index 5b6dde71..ad1b8eba 100644 --- a/multipath/multipath.conf.5 +++ b/multipath/multipath.conf.5 @@ -351,7 +351,7 @@ these values can be looked up through sysfs or by running \fImultipathd show pat .RE .TP 12 .I path_latency -Needs a value of the form \fI"|"\fR +Needs a value of the form "io_num=\fI<20>\fR base_num=\fI<10>\fR" .RS .TP 8 .I io_num