mirror of https://gitee.com/openkylin/libvirt.git
conf: Move and optimize disk target duplicity checking
Move the logic from virDomainDiskDefDstDuplicates into virDomainDiskDefCheckDuplicateInfo so that we don't have to loop multiple times through the array of disks. Since the original function was called in qemuBuildDriveDevStr, it was actually called for every single disk which was quite wasteful. Additionally the target uniqueness check needed to be duplicated in the disk hotplug case, since the disk was inserted into the domain definition after the device string was formatted and thus virDomainDiskDefDstDuplicates didn't do anything in that case.
This commit is contained in:
parent
6d04f0592e
commit
e84ab7938d
|
@ -12992,31 +12992,6 @@ virDomainDiskControllerMatch(int controller_type, int disk_bus)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Return true if there's a duplicate disk[]->dst name for the same bus */
|
||||
bool
|
||||
virDomainDiskDefDstDuplicates(virDomainDefPtr def)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
/* optimization */
|
||||
if (def->ndisks <= 1)
|
||||
return false;
|
||||
|
||||
for (i = 1; i < def->ndisks; i++) {
|
||||
for (j = 0; j < i; j++) {
|
||||
if (STREQ(def->disks[i]->dst, def->disks[j]->dst)) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("target '%s' duplicated for disk sources "
|
||||
"'%s' and '%s'"),
|
||||
def->disks[i]->dst,
|
||||
NULLSTR(virDomainDiskGetSource(def->disks[i])),
|
||||
NULLSTR(virDomainDiskGetSource(def->disks[j])));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
virDomainDiskIndexByAddress(virDomainDefPtr def,
|
||||
|
@ -23992,6 +23967,15 @@ int
|
|||
virDomainDiskDefCheckDuplicateInfo(virDomainDiskDefPtr a,
|
||||
virDomainDiskDefPtr b)
|
||||
{
|
||||
if (STREQ(a->dst, b->dst)) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("target '%s' duplicated for disk sources '%s' and '%s'"),
|
||||
a->dst,
|
||||
NULLSTR(virDomainDiskGetSource(a)),
|
||||
NULLSTR(virDomainDiskGetSource(b)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (a->wwn && b->wwn && STREQ(a->wwn, b->wwn)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Disks '%s' and '%s' have identical WWN"),
|
||||
|
@ -24017,12 +24001,10 @@ virDomainDefCheckDuplicateDiskInfo(virDomainDefPtr def)
|
|||
size_t j;
|
||||
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
if (def->disks[i]->wwn || def->disks[i]->serial) {
|
||||
for (j = i + 1; j < def->ndisks; j++) {
|
||||
if (virDomainDiskDefCheckDuplicateInfo(def->disks[i],
|
||||
def->disks[j]) < 0)
|
||||
return -1;
|
||||
}
|
||||
for (j = i + 1; j < def->ndisks; j++) {
|
||||
if (virDomainDiskDefCheckDuplicateInfo(def->disks[i],
|
||||
def->disks[j]) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2770,7 +2770,6 @@ int virDomainDefCompatibleDevice(virDomainDefPtr def,
|
|||
|
||||
void virDomainRNGDefFree(virDomainRNGDefPtr def);
|
||||
|
||||
bool virDomainDiskDefDstDuplicates(virDomainDefPtr def);
|
||||
int virDomainDiskIndexByAddress(virDomainDefPtr def,
|
||||
virDevicePCIAddressPtr pci_controller,
|
||||
unsigned int bus, unsigned int target,
|
||||
|
|
|
@ -258,7 +258,6 @@ virDomainDiskCacheTypeFromString;
|
|||
virDomainDiskCacheTypeToString;
|
||||
virDomainDiskDefAssignAddress;
|
||||
virDomainDiskDefCheckDuplicateInfo;
|
||||
virDomainDiskDefDstDuplicates;
|
||||
virDomainDiskDefForeachPath;
|
||||
virDomainDiskDefFree;
|
||||
virDomainDiskDefNew;
|
||||
|
|
|
@ -4228,9 +4228,6 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
|
|||
const char *contAlias;
|
||||
int controllerModel;
|
||||
|
||||
if (virDomainDiskDefDstDuplicates(def))
|
||||
goto error;
|
||||
|
||||
if (qemuCheckDiskConfig(disk) < 0)
|
||||
goto error;
|
||||
|
||||
|
|
|
@ -7278,6 +7278,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
|||
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator)))
|
||||
goto cleanup;
|
||||
|
||||
if (qemuProcessStartValidate(def, qemuCaps, false, false) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Since we're just exporting args, we can't do bridge/network/direct
|
||||
* setups, since libvirt will normally create TAP/macvtap devices
|
||||
* directly. We convert those configs into generic 'ethernet'
|
||||
|
|
|
@ -794,12 +794,6 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
|
|||
case VIR_DOMAIN_DISK_DEVICE_DISK:
|
||||
case VIR_DOMAIN_DISK_DEVICE_LUN:
|
||||
for (i = 0; i < vm->def->ndisks; i++) {
|
||||
if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("target %s already exists"), disk->dst);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virDomainDiskDefCheckDuplicateInfo(vm->def->disks[i], disk) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue