From patchwork Tue Feb 20 13:26:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10230079 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 0BAD1602B1 for ; Tue, 20 Feb 2018 13:28:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F099F28508 for ; Tue, 20 Feb 2018 13:28:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E537028511; Tue, 20 Feb 2018 13:28:18 +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 5A72528508 for ; Tue, 20 Feb 2018 13:28:18 +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 9AE847F755; Tue, 20 Feb 2018 13:28:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C4D760A9D; Tue, 20 Feb 2018 13:28:17 +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 37D7218033F2; Tue, 20 Feb 2018 13:28:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1KDRue3020714 for ; Tue, 20 Feb 2018 08:27:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id B3FED5D75C; Tue, 20 Feb 2018 13:27:56 +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 AC78F5D793; Tue, 20 Feb 2018 13:27:56 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E80777853C; Tue, 20 Feb 2018 13:27:54 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 20 Feb 2018 14:27:52 +0100 Received: from apollon.suse.de.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 20 Feb 2018 13:27:20 +0000 From: Martin Wilck To: Christophe Varoqui , Hannes Reinecke Date: Tue, 20 Feb 2018 14:26:52 +0100 Message-Id: <20180220132658.22295-15-mwilck@suse.com> In-Reply-To: <20180220132658.22295-1-mwilck@suse.com> References: <20180220132658.22295-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 20 Feb 2018 13:27:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 20 Feb 2018 13:27:55 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [RFC PATCH 14/20] libmultipath: print: use generic API for get_x_layout() 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: , MIME-Version: 1.0 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.27]); Tue, 20 Feb 2018 13:28:18 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Introduce new functions _get_path_layout and _get_multipath_layout using the new "generic" API to determine field widths, and map the old API to them. Furthermore, replace the boolean "header" by an enum with 3 possible values. The new value LAYOUT_RESET_NOT allows calling the get_x_layout function several times and determine the overall field width. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/print.c | 73 ++++++++++++++++++++++++++++++++++++++++------------ libmultipath/print.h | 8 ++++++ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/libmultipath/print.c b/libmultipath/print.c index 8846765066ef..9a5a6a2f4ad6 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -698,20 +698,48 @@ snprint_wildcards (char * buff, int len) } void -get_path_layout (vector pathvec, int header) +get_path_layout(vector pathvec, int header) +{ + vector gpvec = vector_convert(NULL, pathvec, struct path, + dm_path_to_gen); + _get_path_layout(gpvec, + header ? LAYOUT_RESET_HEADER : LAYOUT_RESET_ZERO); + vector_free(gpvec); +} + +static void +reset_width(int *width, enum layout_reset reset, const char *header) +{ + switch (reset) { + case LAYOUT_RESET_HEADER: + *width = strlen(header); + break; + case LAYOUT_RESET_ZERO: + *width = 0; + break; + default: + /* don't reset */ + break; + } +} + +void +_get_path_layout (const struct _vector *gpvec, enum layout_reset reset) { int i, j; char buff[MAX_FIELD_LEN]; - struct path * pp; + const struct gen_path *gp; for (j = 0; pd[j].header; j++) { - if (header) - pd[j].width = strlen(pd[j].header); - else - pd[j].width = 0; - vector_foreach_slot (pathvec, pp, i) { - pd[j].snprint(buff, MAX_FIELD_LEN, pp); + reset_width(&pd[j].width, reset, pd[j].header); + + if (gpvec == NULL) + continue; + + vector_foreach_slot (gpvec, gp, i) { + gp->ops->snprint(gp, buff, MAX_FIELD_LEN, + pd[j].wildcard); pd[j].width = MAX(pd[j].width, strlen(buff)); } } @@ -727,22 +755,35 @@ reset_multipath_layout (void) } void -get_multipath_layout (vector mpvec, int header) +get_multipath_layout (vector mpvec, int header) { + vector gmvec = vector_convert(NULL, mpvec, struct multipath, + dm_multipath_to_gen); + _get_multipath_layout(gmvec, + header ? LAYOUT_RESET_HEADER : LAYOUT_RESET_ZERO); + vector_free(gmvec); +} + +void +_get_multipath_layout (const struct _vector *gmvec, + enum layout_reset reset) { int i, j; char buff[MAX_FIELD_LEN]; - struct multipath * mpp; + const struct gen_multipath * gm; for (j = 0; mpd[j].header; j++) { - if (header) - mpd[j].width = strlen(mpd[j].header); - else - mpd[j].width = 0; - vector_foreach_slot (mpvec, mpp, i) { - mpd[j].snprint(buff, MAX_FIELD_LEN, mpp); + reset_width(&mpd[j].width, reset, mpd[j].header); + + if (gmvec == NULL) + continue; + + vector_foreach_slot (gmvec, gm, i) { + gm->ops->snprint(gm, buff, MAX_FIELD_LEN, + mpd[j].wildcard); mpd[j].width = MAX(mpd[j].width, strlen(buff)); } + condlog(4, "%s: width %d", mpd[j].header, mpd[j].width); } } diff --git a/libmultipath/print.h b/libmultipath/print.h index e71f87722315..1ba364ac19ac 100644 --- a/libmultipath/print.h +++ b/libmultipath/print.h @@ -93,7 +93,15 @@ struct pathgroup_data { int (*snprint)(char * buff, size_t len, const struct pathgroup * pgp); }; +enum layout_reset { + LAYOUT_RESET_NOT, + LAYOUT_RESET_ZERO, + LAYOUT_RESET_HEADER, +}; + +void _get_path_layout (const struct _vector *gpvec, enum layout_reset); void get_path_layout (vector pathvec, int header); +void _get_multipath_layout (const struct _vector *gmvec, enum layout_reset); void get_multipath_layout (vector mpvec, int header); int snprint_path_header (char *, int, const char *); int snprint_multipath_header (char *, int, const char *);