mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-08 16:54:49 +00:00
Refactor disk unplugging
We can reuse some of the code for other purposes. Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
This commit is contained in:
parent
2de2d525fc
commit
dc1a2fcce6
@ -7866,6 +7866,36 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline int qemudFindDisk(virDomainDefPtr def, char *dst)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0 ; i < def->ndisks ; i++) {
|
||||||
|
if (STREQ(def->disks[i]->dst, dst)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void qemudShrinkDisks(virDomainDefPtr def, int i)
|
||||||
|
{
|
||||||
|
if (def->ndisks > 1) {
|
||||||
|
memmove(def->disks + i,
|
||||||
|
def->disks + i + 1,
|
||||||
|
sizeof(*def->disks) *
|
||||||
|
(def->ndisks - (i + 1)));
|
||||||
|
def->ndisks--;
|
||||||
|
if (VIR_REALLOC_N(def->disks, def->ndisks) < 0) {
|
||||||
|
/* ignore, harmless */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
VIR_FREE(def->disks);
|
||||||
|
def->ndisks = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int qemudDomainDetachPciDiskDevice(struct qemud_driver *driver,
|
static int qemudDomainDetachPciDiskDevice(struct qemud_driver *driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainDeviceDefPtr dev,
|
virDomainDeviceDefPtr dev,
|
||||||
@ -7875,19 +7905,16 @@ static int qemudDomainDetachPciDiskDevice(struct qemud_driver *driver,
|
|||||||
virDomainDiskDefPtr detach = NULL;
|
virDomainDiskDefPtr detach = NULL;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
|
||||||
for (i = 0 ; i < vm->def->ndisks ; i++) {
|
i = qemudFindDisk(vm->def, dev->data.disk->dst);
|
||||||
if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) {
|
|
||||||
detach = vm->def->disks[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!detach) {
|
if (i < 0) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("disk %s not found"), dev->data.disk->dst);
|
_("disk %s not found"), dev->data.disk->dst);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detach = vm->def->disks[i];
|
||||||
|
|
||||||
if (!virDomainDeviceAddressIsValid(&detach->info,
|
if (!virDomainDeviceAddressIsValid(&detach->info,
|
||||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) {
|
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
@ -7910,19 +7937,8 @@ static int qemudDomainDetachPciDiskDevice(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
|
|
||||||
if (vm->def->ndisks > 1) {
|
qemudShrinkDisks(vm->def, i);
|
||||||
memmove(vm->def->disks + i,
|
|
||||||
vm->def->disks + i + 1,
|
|
||||||
sizeof(*vm->def->disks) *
|
|
||||||
(vm->def->ndisks - (i + 1)));
|
|
||||||
vm->def->ndisks--;
|
|
||||||
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks) < 0) {
|
|
||||||
/* ignore, harmless */
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
VIR_FREE(vm->def->disks);
|
|
||||||
vm->def->ndisks = 0;
|
|
||||||
}
|
|
||||||
virDomainDiskDefFree(detach);
|
virDomainDiskDefFree(detach);
|
||||||
|
|
||||||
if (driver->securityDriver &&
|
if (driver->securityDriver &&
|
||||||
|
Loading…
Reference in New Issue
Block a user