diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index f1dc62b11548f4352d9ebea7bbc56b74679cd967..31b45be04f9acbadd233accea17ade75552b317e 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -50,7 +50,7 @@ struct _virStorageVolSourceExtent { typedef struct _virStorageVolSource virStorageVolSource; typedef virStorageVolSource *virStorageVolSourcePtr; struct _virStorageVolSource { - int nextent; + size_t nextent; virStorageVolSourceExtentPtr extents; int partType; /* virStorageVolTypeDisk, only used by disk diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 7c05b6ad7d501d8399b00a74dd8c877a7b2050ce..bb02d8af4b104e17db28475ab4827f6d3c3767e7 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -84,6 +84,9 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol, size_t i; int err, nvars; unsigned long long offset, size, length; + virStorageVolSourceExtent extent; + + memset(&extent, 0, sizeof(extent)); nextents = 1; if (STREQ(groups[4], VIR_STORAGE_VOL_LOGICAL_SEGTYPE_STRIPED)) { @@ -94,11 +97,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol, } } - /* Allocate and fill in extents information */ - if (VIR_REALLOC_N(vol->source.extents, - vol->source.nextent + nextents) < 0) - goto cleanup; - if (virStrToLong_ull(groups[6], NULL, 10, &length) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent length value")); @@ -162,7 +160,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol, len = vars[j].rm_eo - vars[j].rm_so; p[vars[j].rm_eo] = '\0'; - if (VIR_STRNDUP(vol->source.extents[vol->source.nextent].path, + if (VIR_STRNDUP(extent.path, p + vars[j].rm_so, len) < 0) goto cleanup; @@ -176,12 +174,13 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol, VIR_FREE(offset_str); goto cleanup; } - VIR_FREE(offset_str); + extent.start = offset * size; + extent.end = (offset * size) + length; - vol->source.extents[vol->source.nextent].start = offset * size; - vol->source.extents[vol->source.nextent].end = (offset * size) + length; - vol->source.nextent++; + if (VIR_APPEND_ELEMENT(vol->source.extents, vol->source.nextent, + extent) < 0) + goto cleanup; } ret = 0; @@ -190,6 +189,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol, VIR_FREE(regex); VIR_FREE(reg); VIR_FREE(vars); + VIR_FREE(extent.path); return ret; }