From: Martin Wilck <mwilck@suse.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>,
Hannes Reinecke <hare@suse.de>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [RFC PATCH 14/20] libmultipath: print: use generic API for get_x_layout()
Date: Tue, 20 Feb 2018 14:26:52 +0100 [thread overview]
Message-ID: <20180220132658.22295-15-mwilck@suse.com> (raw)
In-Reply-To: <20180220132658.22295-1-mwilck@suse.com>
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 <mwilck@suse.com>
---
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 *);
--
2.16.1
next prev parent reply other threads:[~2018-02-20 13:26 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 13:26 [RFC PATCH 00/20] "Foreign" NVMe support for multipath-tools Martin Wilck
2018-02-20 13:26 ` [RFC PATCH 01/20] multipath(d)/Makefile: add explicit dependency on libraries Martin Wilck
2018-03-01 5:35 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 02/20] libmultipath: remove unused "stdout helpers" Martin Wilck
2018-03-01 5:36 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 03/20] libmultipath: get rid of selector "hack" in print.c Martin Wilck
2018-03-01 5:36 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 04/20] libmultipath: parser: use call-by-value for "snprint" methods Martin Wilck
2018-03-01 5:37 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 05/20] libmultipath: don't update path groups when printing Martin Wilck
2018-02-28 23:40 ` Benjamin Marzinski
2018-03-02 13:59 ` Martin Wilck
2018-03-02 15:31 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 06/20] libmultipath/print: use "const" where appropriate Martin Wilck
2018-03-01 5:37 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 07/20] libmultipath: use "const" in devmapper code Martin Wilck
2018-03-01 5:39 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 08/20] libmultipath: fix compiler warnings for -Wcast-qual Martin Wilck
2018-03-01 5:39 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 09/20] multipath-tools: Makefile.inc: use -Werror=cast-qual Martin Wilck
2018-03-01 5:59 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 10/20] libmultipath: add vector_free_const() Martin Wilck
2018-03-01 6:00 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 11/20] libmultipath: add vector_convert() Martin Wilck
2018-03-01 6:02 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 12/20] libmultipath: "generic multipath" interface Martin Wilck
2018-02-28 23:47 ` Benjamin Marzinski
2018-03-01 8:51 ` Martin Wilck
2018-02-20 13:26 ` [RFC PATCH 13/20] libmultipath: print: convert API to generic data type Martin Wilck
2018-02-28 23:55 ` Benjamin Marzinski
2018-02-20 13:26 ` Martin Wilck [this message]
2018-03-01 6:03 ` [RFC PATCH 14/20] libmultipath: print: use generic API for get_x_layout() Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 15/20] libmultipath: API for foreign multipath handling Martin Wilck
2018-03-01 3:01 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 16/20] libmultipath/print: add "%G - foreign" wildcard Martin Wilck
2018-03-01 6:04 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 17/20] libmultipath/foreign: nvme foreign library Martin Wilck
2018-03-01 3:14 ` Benjamin Marzinski
2018-03-02 16:04 ` Martin Wilck
2018-03-02 18:30 ` Benjamin Marzinski
2018-02-20 13:26 ` [RFC PATCH 18/20] multipath: use foreign API Martin Wilck
2018-03-01 3:55 ` Benjamin Marzinski
2018-03-02 16:36 ` Martin Wilck
2018-02-20 13:26 ` [RFC PATCH 19/20] multipathd: " Martin Wilck
2018-03-01 5:13 ` Benjamin Marzinski
2018-03-02 17:04 ` Martin Wilck
2018-03-02 18:42 ` Benjamin Marzinski
2018-03-02 19:19 ` Martin Wilck
2018-03-02 20:00 ` Benjamin Marzinski
2018-03-02 21:18 ` [PATCH] multipathd: fix inverted signal blocking logic Martin Wilck
2018-03-02 21:35 ` Bart Van Assche
2018-03-02 22:15 ` Martin Wilck
2018-03-02 22:23 ` Bart Van Assche
2018-03-02 23:16 ` Martin Wilck
2018-03-02 23:27 ` Bart Van Assche
2018-03-03 0:31 ` Martin Wilck
2018-03-05 16:27 ` Bart Van Assche
2018-03-05 17:28 ` Martin Wilck
2018-03-06 0:46 ` Benjamin Marzinski
2018-03-06 8:48 ` Martin Wilck
2018-03-02 21:00 ` [RFC PATCH 19/20] multipathd: use foreign API Bart Van Assche
2018-02-20 13:26 ` [RFC PATCH 20/20] libmultipath: foreign/nvme: implement path display Martin Wilck
2018-03-01 5:19 ` Benjamin Marzinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180220132658.22295-15-mwilck@suse.com \
--to=mwilck@suse.com \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.com \
--cc=hare@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox