mirror of https://gitee.com/openkylin/libvirt.git
logical: Use VIR_APPEND_ELEMENT instead of VIR_REALLOC_N
Rather than preallocating a set number of elements, then walking through the extents and adjusting the specific element in place, use the APPEND macros to handle that chore. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
0d0e41a719
commit
69267756d0
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue