summaryrefslogtreecommitdiffstats
path: root/lib/libgeom
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
committersjg <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
commitb137080f19736ee33fede2e88bb54438604cf86b (patch)
tree377ac0ac449528621eb192cd245adadb5fd53668 /lib/libgeom
parentab21a29eb607d4dfe389b965fbdee27558e791aa (diff)
parent4a8d07956d121238d006d34ffe7d6269744e8b1a (diff)
downloadFreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.zip
FreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.tar.gz
Merge from head@274682
Diffstat (limited to 'lib/libgeom')
-rw-r--r--lib/libgeom/geom_getxml.c41
-rw-r--r--lib/libgeom/geom_stats.c4
2 files changed, 36 insertions, 9 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);
}
diff --git a/lib/libgeom/geom_stats.c b/lib/libgeom/geom_stats.c
index 14f9b22..48f7160 100644
--- a/lib/libgeom/geom_stats.c
+++ b/lib/libgeom/geom_stats.c
@@ -68,7 +68,7 @@ geom_stats_resync(void)
return;
for (;;) {
p = mmap(statp, (npages + 1) * pagesize,
- PROT_READ, 0, statsfd, 0);
+ PROT_READ, MAP_SHARED, statsfd, 0);
if (p == MAP_FAILED)
break;
else
@@ -90,7 +90,7 @@ geom_stats_open(void)
return (errno);
pagesize = getpagesize();
spp = pagesize / sizeof(struct devstat);
- p = mmap(NULL, pagesize, PROT_READ, 0, statsfd, 0);
+ p = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, statsfd, 0);
if (p == MAP_FAILED) {
error = errno;
close(statsfd);
OpenPOWER on IntegriCloud