Author: benno Date: Thu Sep 4 03:31:48 2014 New Revision: 271085 URL: http://svnweb.freebsd.org/changeset/base/271085
Log: 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.fer...@isilon.com> Reviewed by: mlaier, ngie Sponsored by: EMC Isilon Storage Division Modified: head/lib/libgeom/geom_getxml.c Modified: head/lib/libgeom/geom_getxml.c ============================================================================== --- head/lib/libgeom/geom_getxml.c Thu Sep 4 03:04:37 2014 (r271084) +++ head/lib/libgeom/geom_getxml.c Thu Sep 4 03:31:48 2014 (r271085) @@ -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); } _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"