mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
qemu: Use qemuAliasFromHostdev
When building the command line alias and for SCSI Host Device deletion, use the common API to build the alias
This commit is contained in:
parent
647bc753d4
commit
8527a25b32
@ -4712,6 +4712,7 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
char *source = NULL;
|
||||
char *drivealias = NULL;
|
||||
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
|
||||
|
||||
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
|
||||
@ -4723,9 +4724,12 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev)
|
||||
goto error;
|
||||
virBufferAsprintf(&buf, "file=/dev/%s,if=none", source);
|
||||
}
|
||||
virBufferAsprintf(&buf, ",id=%s-%s",
|
||||
virDomainDeviceAddressTypeToString(dev->info->type),
|
||||
dev->info->alias);
|
||||
VIR_FREE(source);
|
||||
|
||||
if (!(drivealias = qemuAliasFromHostdev(dev)))
|
||||
goto error;
|
||||
virBufferAsprintf(&buf, ",id=%s", drivealias);
|
||||
VIR_FREE(drivealias);
|
||||
|
||||
if (dev->readonly)
|
||||
virBufferAddLit(&buf, ",readonly=on");
|
||||
@ -4733,10 +4737,8 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev)
|
||||
if (virBufferCheckError(&buf) < 0)
|
||||
goto error;
|
||||
|
||||
VIR_FREE(source);
|
||||
return virBufferContentAndReset(&buf);
|
||||
error:
|
||||
VIR_FREE(source);
|
||||
virBufferFreeAndReset(&buf);
|
||||
return NULL;
|
||||
}
|
||||
@ -4748,6 +4750,7 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
int model = -1;
|
||||
char *driveAlias;
|
||||
const char *contAlias;
|
||||
|
||||
model = virDomainDeviceFindControllerModel(def, dev->info,
|
||||
@ -4791,9 +4794,10 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
|
||||
dev->info->addr.drive.unit);
|
||||
}
|
||||
|
||||
virBufferAsprintf(&buf, ",drive=%s-%s,id=%s",
|
||||
virDomainDeviceAddressTypeToString(dev->info->type),
|
||||
dev->info->alias, dev->info->alias);
|
||||
if (!(driveAlias = qemuAliasFromHostdev(dev)))
|
||||
goto error;
|
||||
virBufferAsprintf(&buf, ",drive=%s,id=%s", driveAlias, dev->info->alias);
|
||||
VIR_FREE(driveAlias);
|
||||
|
||||
if (dev->info->bootIndex)
|
||||
virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
|
||||
|
@ -3184,7 +3184,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
char *drivestr = NULL;
|
||||
char *drivealias = NULL;
|
||||
bool is_vfio = false;
|
||||
|
||||
VIR_DEBUG("Removing host device %s from domain %p %s",
|
||||
@ -3196,15 +3196,11 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
}
|
||||
|
||||
if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
|
||||
/* build the actual drive id string as generated during
|
||||
* qemuBuildSCSIHostdevDrvStr that is passed to qemu */
|
||||
if (virAsprintf(&drivestr, "%s-%s",
|
||||
virDomainDeviceAddressTypeToString(hostdev->info->type),
|
||||
hostdev->info->alias) < 0)
|
||||
if (!(drivealias = qemuAliasFromHostdev(hostdev)))
|
||||
goto cleanup;
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
qemuMonitorDriveDel(priv->mon, drivestr);
|
||||
qemuMonitorDriveDel(priv->mon, drivealias);
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
@ -3268,7 +3264,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(drivestr);
|
||||
VIR_FREE(drivealias);
|
||||
virObjectUnref(cfg);
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user