mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
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
This commit is contained in:
parent
f214250a17
commit
39a8d9f3f0
1 changed files with 34 additions and 7 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue