vz: add validation callbacks

This patch fixes a bug which occurs when we check a bus and unit number
for a new attached disk. We should do this check in ValidadionCallback,
not in PostParse callback. Because in PostParse we have not initialized
disk->info.addr.drive struct yet.
Move part of code from domainPostParseCallback to domainValidateCallback
and part from devicesPostParseCallback to deviceValidateCallback.
PostParse callbacks are for modification data.
ValidateCallbacks are only for checks.
This commit is contained in:
Mikhail Feoktistov 2016-08-18 07:43:09 -04:00 committed by Maxim Nestratov
parent b880ff42dd
commit 72abe56448
3 changed files with 23 additions and 4 deletions

View File

@ -232,6 +232,7 @@ vzConnectGetCapabilities(virConnectPtr conn)
xml = virCapabilitiesFormatXML(privconn->driver->caps); xml = virCapabilitiesFormatXML(privconn->driver->caps);
return xml; return xml;
} }
static int static int
vzDomainDefAddDefaultInputDevices(virDomainDefPtr def) vzDomainDefAddDefaultInputDevices(virDomainDefPtr def)
{ {
@ -258,11 +259,19 @@ static int
vzDomainDefPostParse(virDomainDefPtr def, vzDomainDefPostParse(virDomainDefPtr def,
virCapsPtr caps ATTRIBUTE_UNUSED, virCapsPtr caps ATTRIBUTE_UNUSED,
unsigned int parseFlags ATTRIBUTE_UNUSED, unsigned int parseFlags ATTRIBUTE_UNUSED,
void *opaque) void *opaque ATTRIBUTE_UNUSED)
{ {
if (vzDomainDefAddDefaultInputDevices(def) < 0) if (vzDomainDefAddDefaultInputDevices(def) < 0)
return -1; return -1;
return 0;
}
static int
vzDomainDefValidate(const virDomainDef *def,
virCapsPtr caps ATTRIBUTE_UNUSED,
void *opaque)
{
if (vzCheckUnsupportedControllers(def, opaque) < 0) if (vzCheckUnsupportedControllers(def, opaque) < 0)
return -1; return -1;
@ -284,6 +293,14 @@ vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
VIR_STRDUP(dev->data.net->model, "e1000") < 0) VIR_STRDUP(dev->data.net->model, "e1000") < 0)
return -1; return -1;
return 0;
}
static int
vzDomainDeviceDefValidate(const virDomainDeviceDef *dev,
const virDomainDef *def,
void *opaque ATTRIBUTE_UNUSED)
{
if (dev->type == VIR_DOMAIN_DEVICE_DISK) if (dev->type == VIR_DOMAIN_DEVICE_DISK)
return vzCheckUnsupportedDisk(def, dev->data.disk, opaque); return vzCheckUnsupportedDisk(def, dev->data.disk, opaque);
else if (dev->type == VIR_DOMAIN_DEVICE_GRAPHICS) else if (dev->type == VIR_DOMAIN_DEVICE_GRAPHICS)
@ -299,8 +316,10 @@ static virDomainXMLPrivateDataCallbacks vzDomainXMLPrivateDataCallbacksPtr = {
static virDomainDefParserConfig vzDomainDefParserConfig = { static virDomainDefParserConfig vzDomainDefParserConfig = {
.macPrefix = {0x42, 0x1C, 0x00}, .macPrefix = {0x42, 0x1C, 0x00},
.devicesPostParseCallback = vzDomainDeviceDefPostParse,
.domainPostParseCallback = vzDomainDefPostParse, .domainPostParseCallback = vzDomainDefPostParse,
.devicesPostParseCallback = vzDomainDeviceDefPostParse,
.domainValidateCallback = vzDomainDefValidate,
.deviceValidateCallback = vzDomainDeviceDefValidate,
}; };
static vzDriverPtr static vzDriverPtr

View File

@ -463,7 +463,7 @@ vzCheckUnsupportedDisk(const virDomainDef *def,
} }
int int
vzCheckUnsupportedControllers(virDomainDefPtr def, vzCapabilitiesPtr vzCaps) vzCheckUnsupportedControllers(const virDomainDef *def, vzCapabilitiesPtr vzCaps)
{ {
size_t i, j; size_t i, j;
virDomainControllerDefPtr controller; virDomainControllerDefPtr controller;

View File

@ -137,7 +137,7 @@ vzCheckUnsupportedDisk(const virDomainDef *def,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
vzCapabilitiesPtr vzCaps); vzCapabilitiesPtr vzCaps);
int int
vzCheckUnsupportedControllers(virDomainDefPtr def, vzCheckUnsupportedControllers(const virDomainDef *def,
vzCapabilitiesPtr vzCaps); vzCapabilitiesPtr vzCaps);
int int
vzGetDefaultSCSIModel(vzDriverPtr driver, vzGetDefaultSCSIModel(vzDriverPtr driver,