From patchwork Mon Mar 5 23:14:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10260245 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 F3F6C60134 for ; Mon, 5 Mar 2018 23:16:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6D8A28A1D for ; Mon, 5 Mar 2018 23:16:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB74F28A6B; Mon, 5 Mar 2018 23:16:23 +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 7657328B58 for ; Mon, 5 Mar 2018 23:16:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C52F92D1B7; Mon, 5 Mar 2018 23:16:20 +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 9DA0A182F8; Mon, 5 Mar 2018 23:16:20 +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 69CB418033F1; Mon, 5 Mar 2018 23:16:20 +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 w25NFqEh017325 for ; Mon, 5 Mar 2018 18:15:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id B3AD15D9CD; Mon, 5 Mar 2018 23:15:52 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB6825D9CA; Mon, 5 Mar 2018 23:15:50 +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 6FC4B356CC; Mon, 5 Mar 2018 23:15:48 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 06 Mar 2018 00:15:46 +0100 Received: from apollon.suse.de.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Mon, 05 Mar 2018 23:15:40 +0000 From: Martin Wilck To: Christophe Varoqui Date: Tue, 6 Mar 2018 00:14:58 +0100 Message-Id: <20180305231507.10386-15-mwilck@suse.com> In-Reply-To: <20180305231507.10386-1-mwilck@suse.com> References: <20180305231507.10386-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.30]); Mon, 05 Mar 2018 23:15:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Mar 2018 23:15:49 +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.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 14/23] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 05 Mar 2018 23:16:21 +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 Reviewed-by: Hannes Reinecke --- 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 8701a3584859..01e7483e3e44 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -697,20 +697,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)); } } @@ -726,22 +754,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 b8b9ecbd204f..7ba643892579 100644 --- a/libmultipath/print.h +++ b/libmultipath/print.h @@ -94,7 +94,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 *);