From: Martin Wilck <mwilck@suse.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [PATCH v2 14/23] libmultipath: print: use generic API for get_x_layout()
Date: Tue, 6 Mar 2018 00:14:58 +0100 [thread overview]
Message-ID: <20180305231507.10386-15-mwilck@suse.com> (raw)
In-Reply-To: <20180305231507.10386-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>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.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 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 *);
--
2.16.1
next prev parent reply other threads:[~2018-03-05 23:14 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-05 23:14 [PATCH v2 00/23] "Foreign" NVMe support for multipath-tools Martin Wilck
2018-03-05 23:14 ` [PATCH v2 01/23] multipath(d)/Makefile: add explicit dependency on libraries Martin Wilck
2018-03-06 7:04 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 02/23] libmultipath: remove unused "stdout helpers" Martin Wilck
2018-03-06 7:04 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 03/23] libmultipath: get rid of selector "hack" in print.c Martin Wilck
2018-03-06 7:05 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 04/23] libmultipath: parser: use call-by-value for "snprint" methods Martin Wilck
2018-03-06 7:05 ` Hannes Reinecke
2018-03-15 14:25 ` Bart Van Assche
2018-03-05 23:14 ` [PATCH v2 05/23] libmultipath: don't update path groups when printing Martin Wilck
2018-03-06 7:06 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 06/23] libmultipath/print: use "const" where appropriate Martin Wilck
2018-03-06 7:07 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 07/23] libmultipath: use "const" in devmapper code Martin Wilck
2018-03-06 7:07 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 09/23] multipath-tools: Makefile.inc: use -Werror=cast-qual Martin Wilck
2018-03-06 7:08 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 10/23] libmultipath: add vector_free_const() Martin Wilck
2018-03-06 1:01 ` Bart Van Assche
2018-03-06 7:08 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 11/23] libmultipath: add vector_convert() Martin Wilck
2018-03-06 7:10 ` Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 12/23] libmultipath: "generic multipath" interface Martin Wilck
2018-03-06 7:10 ` Hannes Reinecke
2018-03-07 19:01 ` Benjamin Marzinski
2018-03-05 23:14 ` [PATCH v2 13/23] libmultipath: print: convert API to generic data type Martin Wilck
2018-03-06 7:11 ` Hannes Reinecke
2018-03-07 19:02 ` Benjamin Marzinski
2018-03-05 23:14 ` Martin Wilck [this message]
2018-03-06 7:12 ` [PATCH v2 14/23] libmultipath: print: use generic API for get_x_layout() Hannes Reinecke
2018-03-05 23:14 ` [PATCH v2 15/23] libmultipath: API for foreign multipath handling Martin Wilck
2018-03-06 7:12 ` Hannes Reinecke
2018-03-07 19:08 ` Benjamin Marzinski
2018-03-05 23:15 ` [PATCH v2 16/23] libmultipath/print: add "%G - foreign" wildcard Martin Wilck
2018-03-06 7:13 ` Hannes Reinecke
2018-03-05 23:15 ` [PATCH v2 17/23] libmultipath/foreign: nvme foreign library Martin Wilck
2018-03-06 7:13 ` Hannes Reinecke
2018-03-07 19:09 ` Benjamin Marzinski
2018-03-05 23:15 ` [PATCH v2 18/23] libmultipath: pathinfo: call into " Martin Wilck
2018-03-06 7:14 ` Hannes Reinecke
2018-03-07 19:10 ` Benjamin Marzinski
2018-03-05 23:15 ` [PATCH v2 19/23] multipath: use foreign API Martin Wilck
2018-03-06 7:14 ` Hannes Reinecke
2018-03-07 19:11 ` Benjamin Marzinski
2018-03-05 23:15 ` [PATCH v2 20/23] multipathd: " Martin Wilck
2018-03-06 7:15 ` Hannes Reinecke
2018-03-07 19:25 ` Benjamin Marzinski
2018-03-05 23:15 ` [PATCH v2 21/23] libmultipath: foreign/nvme: implement path display Martin Wilck
2018-03-06 7:15 ` Hannes Reinecke
2018-03-07 19:27 ` Benjamin Marzinski
2018-03-05 23:15 ` [PATCH v2 22/23] multipathd: update path group prio in check_path Martin Wilck
2018-03-06 7:16 ` Hannes Reinecke
2018-03-07 20:01 ` Benjamin Marzinski
2018-03-05 23:15 ` [PATCH v2 23/23] multipathd: fix signal blocking logic Martin Wilck
2018-03-06 7:16 ` Hannes Reinecke
2018-03-06 8:55 ` Martin Wilck
2018-03-07 20:24 ` Benjamin Marzinski
[not found] ` <20180305231507.10386-9-mwilck@suse.com>
2018-03-06 7:08 ` [PATCH v2 08/23] libmultipath: fix compiler warnings for -Wcast-qual Hannes Reinecke
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=20180305231507.10386-15-mwilck@suse.com \
--to=mwilck@suse.com \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.com \
/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