From: Benjamin Marzinski <bmarzins@redhat.com>
To: device-mapper development <dm-devel@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@gmail.com>
Subject: [PATCH 03/16] Fix print_multipath_topology for large outputs
Date: Thu, 2 May 2013 16:46:24 -0500 [thread overview]
Message-ID: <1367531197-8987-4-git-send-email-bmarzins@redhat.com> (raw)
In-Reply-To: <1367531197-8987-1-git-send-email-bmarzins@redhat.com>
print_multipath_topology had a hard size limit. With a large number
of LUNs and a large number of paths, it was possible to go over
this limit, and have some of the output cut off.
print_multipath_topology now checks for this, and resizes the
buffer if necessary.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/print.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/libmultipath/print.c b/libmultipath/print.c
index 0e2c680..274f5e7 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -8,6 +8,8 @@
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
+#include <string.h>
+#include <errno.h>
#include "checkers.h"
#include "vector.h"
@@ -24,6 +26,7 @@
#include "switchgroup.h"
#include "devmapper.h"
#include "uevent.h"
+#include "debug.h"
#define MAX(x,y) (x > y) ? x : y
#define TAIL (line + len - 1 - c)
@@ -754,11 +757,30 @@ snprint_pathgroup (char * line, int len, char * format,
extern void
print_multipath_topology (struct multipath * mpp, int verbosity)
{
- char buff[MAX_LINE_LEN * MAX_LINES] = {};
+ int resize;
+ char *buff = NULL;
+ char *old = NULL;
+ int len, maxlen = MAX_LINE_LEN * MAX_LINES;
+
+ buff = MALLOC(maxlen);
+ do {
+ if (!buff) {
+ if (old)
+ FREE(old);
+ condlog(0, "couldn't allocate memory for list: %s\n",
+ strerror(errno));
+ return;
+ }
+
+ len = snprint_multipath_topology(buff, maxlen, mpp, verbosity);
+ resize = (len == maxlen - 1);
- memset(&buff[0], 0, MAX_LINE_LEN * MAX_LINES);
- snprint_multipath_topology(&buff[0], MAX_LINE_LEN * MAX_LINES,
- mpp, verbosity);
+ if (resize) {
+ maxlen *= 2;
+ old = buff;
+ buff = REALLOC(buff, maxlen);
+ }
+ } while (resize);
printf("%s", buff);
}
--
1.8.2
next prev parent reply other threads:[~2013-05-02 21:46 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-02 21:46 [PATCH 00/16] multipath-tools: miscellaneous multipath patches Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 01/16] Make kpartx advise modprobe instead of insmod Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 02/16] Make kpartx correctly handle non-512 byte GPT Benjamin Marzinski
2013-05-02 21:46 ` Benjamin Marzinski [this message]
2013-05-02 21:46 ` [PATCH 04/16] Don't print checker messages for ghost paths Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 05/16] Fix a couple of signal issues Benjamin Marzinski
2013-05-03 6:36 ` Bart Van Assche
2013-05-03 20:24 ` Benjamin Marzinski
2013-05-04 7:19 ` Bart Van Assche
2013-05-02 21:46 ` [PATCH 06/16] Fix hardware entry matching code Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 07/16] Fix some socket issues Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 08/16] Avoid race between ueventloop and uevqloop Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 09/16] Add existing multipath devices to wwids file on Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 10/16] add wwids file cleanup options Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 11/16] Fix max path checker timing Benjamin Marzinski
2013-05-03 6:59 ` Hannes Reinecke
2013-05-03 15:44 ` Benjamin Marzinski
2013-05-03 17:59 ` [PATCH v2 " Benjamin Marzinski
2013-05-06 5:42 ` Hannes Reinecke
2013-05-02 21:46 ` [PATCH 12/16] Make set_multipath_wwid actually do something Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 13/16] Make multipathd deal better with uninitialized paths Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 14/16] Stop annoying prio_lookup warning messages Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 15/16] make multipathd disable queue_without_daemon by default Benjamin Marzinski
2013-05-02 21:46 ` [PATCH 16/16] Use mapname to choose kpartx delimiter Benjamin Marzinski
2013-05-06 19:45 ` [PATCH 00/16] multipath-tools: miscellaneous multipath patches Christophe Varoqui
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=1367531197-8987-4-git-send-email-bmarzins@redhat.com \
--to=bmarzins@redhat.com \
--cc=christophe.varoqui@gmail.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