virStorageBackendLogicalParseVolExtents: Move 'extents' inside the loop

It's used only inside the loop filling the extents, move it there and
restructure the code so that 'extent.path' doesn't have to be freed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-08-04 12:18:38 +02:00
parent bbd89d7894
commit e03e54c9a2

View File

@ -128,11 +128,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
unsigned long long offset;
unsigned long long size;
unsigned long long length;
virStorageVolSourceExtent extent;
g_autofree char *regex = NULL;
memset(&extent, 0, sizeof(extent));
/* Assume 1 extent (the regex for 'devices' is "(\\S+)") and only
* check the 'stripes' field if we have a striped, mirror, or one of
* the raid (raid1, raid4, raid5*, raid6*, or raid10) segtypes in which
@ -189,11 +186,12 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
* is the whole matched string.
*/
for (i = 0; i < nextents; i++) {
size_t j;
g_autofree char *offset_str = NULL;
virStorageVolSourceExtent extent;
size_t j = (i * 2) + 1;
memset(&extent, 0, sizeof(extent));
j = (i * 2) + 1;
extent.path = g_match_info_fetch(info, j);
offset_str = g_match_info_fetch(info, j + 1);
if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) {
@ -201,6 +199,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
_("malformed volume extent offset value"));
goto cleanup;
}
extent.path = g_match_info_fetch(info, j);
extent.start = offset * size;
extent.end = (offset * size) + length;
@ -210,7 +210,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
ret = 0;
cleanup:
VIR_FREE(extent.path);
return ret;
}