summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbenno <benno@FreeBSD.org>2014-09-04 03:31:48 +0000
committerbenno <benno@FreeBSD.org>2014-09-04 03:31:48 +0000
commit420e85e546db714ae4f711b4a7affb378325545f (patch)
treeff85432eb8515df786908895d9c8fd8dd45748f2 /lib
parenta5645731d20064ece00afd48686fde8cf720f5f0 (diff)
downloadFreeBSD-src-420e85e546db714ae4f711b4a7affb378325545f.zip
FreeBSD-src-420e85e546db714ae4f711b4a7affb378325545f.tar.gz
Systems with lots of geom providers can end up with a kern.geom.confxml
value too large for the buffer allocated. Work around this by retrying a few times with larger buffer sizes. Submitted by: Scott Ferris <scott.ferris@isilon.com> Reviewed by: mlaier, ngie Sponsored by: EMC Isilon Storage Division
Diffstat (limited to 'lib')
-rw-r--r--lib/libgeom/geom_getxml.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/lib/libgeom/geom_getxml.c b/lib/libgeom/geom_getxml.c
index 17e0476..3fe1e72 100644
--- a/lib/libgeom/geom_getxml.c
+++ b/lib/libgeom/geom_getxml.c
@@ -31,10 +31,23 @@
#include <sys/types.h>
#include <sys/sysctl.h>
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "libgeom.h"
+/*
+ * Amount of extra space we allocate to try and anticipate the size of
+ * confxml.
+ */
+#define GEOM_GETXML_SLACK 4096
+
+/*
+ * Number of times to retry in the face of the size of confxml exceeding
+ * that of our buffer.
+ */
+#define GEOM_GETXML_RETRIES 4
+
char *
geom_getxml(void)
{
@@ -42,19 +55,33 @@ geom_getxml(void)
size_t l = 0;
int mib[3];
size_t sizep;
+ int retries;
sizep = sizeof(mib) / sizeof(*mib);
if (sysctlnametomib("kern.geom.confxml", mib, &sizep) != 0)
return (NULL);
if (sysctl(mib, sizep, NULL, &l, NULL, 0) != 0)
return (NULL);
- l += 4096;
- p = malloc(l);
- if (p == NULL)
- return (NULL);
- if (sysctl(mib, sizep, p, &l, NULL, 0) != 0) {
+ l += GEOM_GETXML_SLACK;
+
+ for (retries = 0; retries < GEOM_GETXML_RETRIES; retries++) {
+ p = malloc(l);
+ if (p == NULL)
+ return (NULL);
+ if (sysctl(mib, sizep, p, &l, NULL, 0) == 0)
+ return (reallocf(p, strlen(p) + 1));
+
free(p);
- return (NULL);
+
+ if (errno != ENOMEM)
+ return (NULL);
+
+ /*
+ * Our buffer wasn't big enough. Make it bigger and
+ * try again.
+ */
+ l *= 2;
}
- return (reallocf(p, strlen(p) + 1));
+
+ return (NULL);
}
OpenPOWER on IntegriCloud