mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
qemu: hotplug: Reuse qemuDomainAttachDiskGeneric in qemuDomainAttachUSBMassStorageDevice
Apart from killing a lot of code this also "implements" authentication and encryption for USB disks.
This commit is contained in:
parent
4e6ac368a5
commit
05d4323989
@ -656,94 +656,24 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
|
qemuDomainAttachUSBMassStorageDevice(virConnectPtr conn,
|
||||||
|
virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainDiskDefPtr disk)
|
virDomainDiskDefPtr disk)
|
||||||
{
|
{
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virErrorPtr orig_err;
|
|
||||||
int ret = -1;
|
|
||||||
char *drivealias = NULL;
|
|
||||||
char *drivestr = NULL;
|
|
||||||
char *devstr = NULL;
|
|
||||||
bool driveAdded = false;
|
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
|
||||||
bool releaseaddr = false;
|
|
||||||
|
|
||||||
if (priv->usbaddrs) {
|
if (priv->usbaddrs) {
|
||||||
if (virDomainUSBAddressEnsure(priv->usbaddrs, &disk->info) < 0)
|
if (virDomainUSBAddressEnsure(priv->usbaddrs, &disk->info) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
releaseaddr = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
|
if (qemuDomainAttachDiskGeneric(conn, driver, vm, disk) < 0) {
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (qemuDomainPrepareDiskSourceTLS(disk->src, disk->info.alias, cfg) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (disk->src->haveTLS &&
|
|
||||||
qemuDomainAddDiskSrcTLSObject(driver, vm, disk->src,
|
|
||||||
disk->info.alias) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(drivestr = qemuBuildDriveStr(disk, cfg, false, priv->qemuCaps)))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(drivealias = qemuAliasFromDisk(disk)))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
|
||||||
|
|
||||||
if (qemuMonitorAddDrive(priv->mon, drivestr) < 0)
|
|
||||||
goto exit_monitor;
|
|
||||||
driveAdded = true;
|
|
||||||
|
|
||||||
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
|
|
||||||
goto exit_monitor;
|
|
||||||
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
|
|
||||||
|
|
||||||
virDomainDiskInsertPreAlloced(vm->def, disk);
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (ret < 0 && releaseaddr)
|
|
||||||
virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
|
virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
|
||||||
VIR_FREE(devstr);
|
return -1;
|
||||||
VIR_FREE(drivealias);
|
|
||||||
VIR_FREE(drivestr);
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
exit_monitor:
|
|
||||||
virErrorPreserveLast(&orig_err);
|
|
||||||
if (driveAdded && qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
|
|
||||||
VIR_WARN("Unable to remove drive %s (%s) after failed "
|
|
||||||
"qemuMonitorAddDevice", drivealias, drivestr);
|
|
||||||
}
|
}
|
||||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
|
||||||
virErrorRestore(&orig_err);
|
|
||||||
|
|
||||||
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
return 0;
|
||||||
|
|
||||||
error:
|
|
||||||
qemuDomainDelDiskSrcTLSObject(driver, vm, disk->src);
|
|
||||||
|
|
||||||
ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -813,7 +743,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
|
|||||||
_("disk device='lun' is not supported for usb bus"));
|
_("disk device='lun' is not supported for usb bus"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ret = qemuDomainAttachUSBMassStorageDevice(driver, vm, disk);
|
ret = qemuDomainAttachUSBMassStorageDevice(conn, driver, vm, disk);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_DISK_BUS_VIRTIO:
|
case VIR_DOMAIN_DISK_BUS_VIRTIO:
|
||||||
|
Loading…
Reference in New Issue
Block a user