mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 13:35:17 +00:00
conf: Refactor virDomainDiskSourcePoolDefParse
For some strange reason virDomainDiskSourcePoolDefParse accessed def of the disk and allocated the pool object in it. To avoid the need to carry over the disk definition object, refactor this function to return the allocated object instead.
This commit is contained in:
parent
adb44955c4
commit
6e037015a4
@ -4683,49 +4683,48 @@ cleanup:
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainDiskSourcePoolDefParse(xmlNodePtr node,
|
virDomainDiskSourcePoolDefParse(xmlNodePtr node,
|
||||||
virDomainDiskDefPtr def)
|
virDomainDiskSourcePoolDefPtr *srcpool)
|
||||||
{
|
{
|
||||||
char *pool = NULL;
|
|
||||||
char *volume = NULL;
|
|
||||||
char *mode = NULL;
|
char *mode = NULL;
|
||||||
|
virDomainDiskSourcePoolDefPtr source;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
pool = virXMLPropString(node, "pool");
|
*srcpool = NULL;
|
||||||
volume = virXMLPropString(node, "volume");
|
|
||||||
|
if (VIR_ALLOC(source) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
source->pool = virXMLPropString(node, "pool");
|
||||||
|
source->volume = virXMLPropString(node, "volume");
|
||||||
mode = virXMLPropString(node, "mode");
|
mode = virXMLPropString(node, "mode");
|
||||||
|
|
||||||
/* CD-ROM and Floppy allows no source */
|
/* CD-ROM and Floppy allows no source */
|
||||||
if (!pool && !volume)
|
if (!source->pool && !source->volume) {
|
||||||
return 0;
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pool || !volume) {
|
if (!source->pool || !source->volume) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("'pool' and 'volume' must be specified together "
|
_("'pool' and 'volume' must be specified together "
|
||||||
"for 'pool' type source"));
|
"for 'pool' type source"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(def->srcpool) < 0)
|
if (mode &&
|
||||||
goto cleanup;
|
(source->mode = virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) {
|
||||||
|
|
||||||
if (mode && (def->srcpool->mode =
|
|
||||||
virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("unknown source mode '%s' for volume type disk"),
|
_("unknown source mode '%s' for volume type disk"),
|
||||||
mode);
|
mode);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
def->srcpool->pool = pool;
|
*srcpool = source;
|
||||||
pool = NULL;
|
source = NULL;
|
||||||
def->srcpool->volume = volume;
|
|
||||||
volume = NULL;
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(pool);
|
virDomainDiskSourcePoolDefFree(source);
|
||||||
VIR_FREE(volume);
|
|
||||||
VIR_FREE(mode);
|
VIR_FREE(mode);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -4916,7 +4915,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_DISK_TYPE_VOLUME:
|
case VIR_DOMAIN_DISK_TYPE_VOLUME:
|
||||||
if (virDomainDiskSourcePoolDefParse(cur, def) < 0)
|
if (virDomainDiskSourcePoolDefParse(cur, &def->srcpool) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user