mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
qemu: hotplug: extract disk hotplug worker code
This horrible piece of spaghetti code is copy-past(ae)d in the SCSI and USB disk hotplug code with minimal changes. Extract it for further reuse.
This commit is contained in:
parent
3c437ebf40
commit
5b0dc7fdfd
@ -345,21 +345,24 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuDomainAttachDiskGeneric:
|
||||||
|
*
|
||||||
|
* Attaches disk to a VM. This function aggregates common code for all bus types.
|
||||||
|
* In cases when the VM crashed while adding the disk, -2 is returned. */
|
||||||
static int
|
static int
|
||||||
qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
|
qemuDomainAttachDiskGeneric(virConnectPtr conn,
|
||||||
virQEMUDriverPtr driver,
|
virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainDiskDefPtr disk)
|
virDomainDiskDefPtr disk)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rv;
|
int rv;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_DISK, { .disk = disk } };
|
|
||||||
virErrorPtr orig_err;
|
virErrorPtr orig_err;
|
||||||
char *devstr = NULL;
|
char *devstr = NULL;
|
||||||
char *drivestr = NULL;
|
char *drivestr = NULL;
|
||||||
char *drivealias = NULL;
|
char *drivealias = NULL;
|
||||||
bool releaseaddr = false;
|
|
||||||
bool driveAdded = false;
|
bool driveAdded = false;
|
||||||
bool secobjAdded = false;
|
bool secobjAdded = false;
|
||||||
bool encobjAdded = false;
|
bool encobjAdded = false;
|
||||||
@ -373,9 +376,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
|
|||||||
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
|
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, disk->dst) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
|
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -441,7 +441,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
|
|||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
|
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
|
||||||
releaseaddr = false;
|
ret = -2;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,22 +471,42 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
|
|||||||
if (encobjAdded)
|
if (encobjAdded)
|
||||||
ignore_value(qemuMonitorDelObject(priv->mon, encinfo->s.aes.alias));
|
ignore_value(qemuMonitorDelObject(priv->mon, encinfo->s.aes.alias));
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
releaseaddr = false;
|
ret = -2;
|
||||||
virErrorRestore(&orig_err);
|
virErrorRestore(&orig_err);
|
||||||
|
|
||||||
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
qemuDomainDelDiskSrcTLSObject(driver, vm, disk->src);
|
qemuDomainDelDiskSrcTLSObject(driver, vm, disk->src);
|
||||||
|
|
||||||
if (releaseaddr)
|
|
||||||
qemuDomainReleaseDeviceAddress(vm, &disk->info, disk->dst);
|
|
||||||
|
|
||||||
ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
|
ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
|
||||||
|
virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
virDomainDiskDefPtr disk)
|
||||||
|
{
|
||||||
|
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_DISK, { .disk = disk } };
|
||||||
|
bool releaseaddr = false;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, disk->dst) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ((rv = qemuDomainAttachDiskGeneric(conn, driver, vm, disk)) < 0) {
|
||||||
|
if (rv == -1 && releaseaddr)
|
||||||
|
qemuDomainReleaseDeviceAddress(vm, &disk->info, disk->dst);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
|
int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainControllerDefPtr controller)
|
virDomainControllerDefPtr controller)
|
||||||
|
Loading…
Reference in New Issue
Block a user