mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-27 07:22:07 +03:00
qemu: hotplug: Use VIR_AUTOFREE() instead VIR_FREE for strings
Cleanup labels are also dropped where possible. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
15340ff583
commit
87ecf62d4c
@ -136,20 +136,15 @@ static int
|
||||
qemuDomainAttachZPCIDevice(qemuMonitorPtr mon,
|
||||
virDomainDeviceInfoPtr info)
|
||||
{
|
||||
char *devstr_zpci = NULL;
|
||||
int ret = -1;
|
||||
VIR_AUTOFREE(char *) devstr_zpci = NULL;
|
||||
|
||||
if (!(devstr_zpci = qemuBuildZPCIDevStr(info)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (qemuMonitorAddDevice(mon, devstr_zpci) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(devstr_zpci);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -157,20 +152,15 @@ static int
|
||||
qemuDomainDetachZPCIDevice(qemuMonitorPtr mon,
|
||||
virDomainDeviceInfoPtr info)
|
||||
{
|
||||
char *zpciAlias = NULL;
|
||||
int ret = -1;
|
||||
VIR_AUTOFREE(char *) zpciAlias = NULL;
|
||||
|
||||
if (virAsprintf(&zpciAlias, "zpci%d", info->addr.pci.zpci.uid) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (qemuMonitorDelDevice(mon, zpciAlias) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(zpciAlias);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -517,31 +507,30 @@ qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
|
||||
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
||||
VIR_AUTOPTR(qemuBlockStorageSourceChainData) newbackend = NULL;
|
||||
VIR_AUTOPTR(qemuBlockStorageSourceChainData) oldbackend = NULL;
|
||||
char *nodename = NULL;
|
||||
VIR_AUTOFREE(char *) nodename = NULL;
|
||||
int rc;
|
||||
int ret = -1;
|
||||
|
||||
if (!virStorageSourceIsEmpty(oldsrc) &&
|
||||
!(oldbackend = qemuBlockStorageSourceChainDetachPrepareBlockdev(oldsrc)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (!virStorageSourceIsEmpty(newsrc)) {
|
||||
if (!(newbackend = qemuBuildStorageSourceChainAttachPrepareBlockdev(newsrc,
|
||||
priv->qemuCaps)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (qemuDomainDiskGetBackendAlias(disk, priv->qemuCaps, &nodename) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (diskPriv->tray && disk->tray_status != VIR_DOMAIN_DISK_TRAY_OPEN) {
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
rc = qemuMonitorBlockdevTrayOpen(priv->mon, diskPriv->qomName, force);
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (!force && qemuHotplugWaitForTrayEject(vm, disk) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
@ -567,13 +556,9 @@ qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
|
||||
qemuBlockStorageSourceChainDetach(priv->mon, newbackend);
|
||||
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(nodename);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -823,7 +808,7 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
|
||||
{
|
||||
int ret = -1;
|
||||
const char* type = virDomainControllerTypeToString(controller->type);
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_CONTROLLER,
|
||||
{ .controller = controller } };
|
||||
@ -890,7 +875,6 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
|
||||
if (ret != 0 && releaseaddr)
|
||||
qemuDomainReleaseDeviceAddress(vm, &controller->info);
|
||||
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1156,8 +1140,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
||||
int *vhostfd = NULL;
|
||||
size_t vhostfdSize = 0;
|
||||
size_t queueSize = 0;
|
||||
char *nicstr = NULL;
|
||||
char *netstr = NULL;
|
||||
VIR_AUTOFREE(char *) nicstr = NULL;
|
||||
VIR_AUTOFREE(char *) netstr = NULL;
|
||||
int ret = -1;
|
||||
bool releaseaddr = false;
|
||||
bool iface_connected = false;
|
||||
@ -1166,10 +1150,10 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||
virDomainCCWAddressSetPtr ccwaddrs = NULL;
|
||||
size_t i;
|
||||
char *charDevAlias = NULL;
|
||||
VIR_AUTOFREE(char *) charDevAlias = NULL;
|
||||
bool charDevPlugged = false;
|
||||
bool netdevPlugged = false;
|
||||
char *netdev_name;
|
||||
VIR_AUTOFREE(char *) netdev_name = NULL;
|
||||
virConnectPtr conn = NULL;
|
||||
virErrorPtr save_err = NULL;
|
||||
|
||||
@ -1499,8 +1483,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
||||
virErrorRestore(&save_err);
|
||||
}
|
||||
|
||||
VIR_FREE(nicstr);
|
||||
VIR_FREE(netstr);
|
||||
for (i = 0; tapfd && i < tapfdSize; i++) {
|
||||
VIR_FORCE_CLOSE(tapfd[i]);
|
||||
if (tapfdName)
|
||||
@ -1515,7 +1497,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
||||
}
|
||||
VIR_FREE(vhostfd);
|
||||
VIR_FREE(vhostfdName);
|
||||
VIR_FREE(charDevAlias);
|
||||
virObjectUnref(conn);
|
||||
virDomainCCWAddressSetFree(ccwaddrs);
|
||||
VIR_FORCE_CLOSE(slirpfd);
|
||||
@ -1539,7 +1520,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
||||
VIR_WARN("Failed to remove network backend for netdev %s",
|
||||
netdev_name);
|
||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
||||
VIR_FREE(netdev_name);
|
||||
}
|
||||
virErrorRestore(&originalError);
|
||||
goto cleanup;
|
||||
@ -1556,7 +1536,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
|
||||
{ .hostdev = hostdev } };
|
||||
virDomainDeviceInfoPtr info = hostdev->info;
|
||||
int ret;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
bool releaseaddr = false;
|
||||
bool teardowncgroup = false;
|
||||
bool teardownlabel = false;
|
||||
@ -1658,8 +1638,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
|
||||
|
||||
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
|
||||
|
||||
VIR_FREE(devstr);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@ -1679,8 +1657,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
|
||||
|
||||
qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
|
||||
|
||||
VIR_FREE(devstr);
|
||||
|
||||
cleanup:
|
||||
return -1;
|
||||
}
|
||||
@ -1726,7 +1702,7 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver,
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virErrorPtr orig_err;
|
||||
char *secAlias = NULL;
|
||||
VIR_AUTOFREE(char *) secAlias = NULL;
|
||||
|
||||
if (!tlsProps && !secProps)
|
||||
return 0;
|
||||
@ -1742,8 +1718,6 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver,
|
||||
qemuMonitorAddObject(priv->mon, tlsProps, NULL) < 0)
|
||||
goto error;
|
||||
|
||||
VIR_FREE(secAlias);
|
||||
|
||||
return qemuDomainObjExitMonitor(driver, vm);
|
||||
|
||||
error:
|
||||
@ -1751,7 +1725,6 @@ qemuDomainAddTLSObjects(virQEMUDriverPtr driver,
|
||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
||||
virErrorRestore(&orig_err);
|
||||
qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, NULL);
|
||||
VIR_FREE(secAlias);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -1850,20 +1823,18 @@ qemuDomainDelChardevTLSObjects(virQEMUDriverPtr driver,
|
||||
virDomainChrSourceDefPtr dev,
|
||||
const char *inAlias)
|
||||
{
|
||||
int ret = -1;
|
||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
char *tlsAlias = NULL;
|
||||
char *secAlias = NULL;
|
||||
VIR_AUTOFREE(char *) tlsAlias = NULL;
|
||||
VIR_AUTOFREE(char *) secAlias = NULL;
|
||||
|
||||
if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP ||
|
||||
dev->data.tcp.haveTLS != VIR_TRISTATE_BOOL_YES) {
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(tlsAlias = qemuAliasTLSObjFromSrcAlias(inAlias)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
/* Best shot at this as the secinfo is destroyed after process launch
|
||||
* and this path does not recreate it. Thus, if the config has the
|
||||
@ -1871,7 +1842,7 @@ qemuDomainDelChardevTLSObjects(virQEMUDriverPtr driver,
|
||||
* secAlias which we'll attempt to destroy. */
|
||||
if (cfg->chardevTLSx509secretUUID &&
|
||||
!(secAlias = qemuDomainGetSecretAESAlias(inAlias, false)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
|
||||
@ -1880,14 +1851,9 @@ qemuDomainDelChardevTLSObjects(virQEMUDriverPtr driver,
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, secAlias));
|
||||
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(tlsAlias);
|
||||
VIR_FREE(secAlias);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1898,10 +1864,10 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virDomainDefPtr def = vm->def;
|
||||
char *charAlias = NULL;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) charAlias = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
bool chardevAdded = false;
|
||||
char *tlsAlias = NULL;
|
||||
VIR_AUTOFREE(char *) tlsAlias = NULL;
|
||||
const char *secAlias = NULL;
|
||||
bool need_release = false;
|
||||
virErrorPtr orig_err;
|
||||
@ -1948,9 +1914,6 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
|
||||
cleanup:
|
||||
if (ret < 0 && need_release)
|
||||
qemuDomainReleaseDeviceAddress(vm, &redirdev->info);
|
||||
VIR_FREE(tlsAlias);
|
||||
VIR_FREE(charAlias);
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
|
||||
exit_monitor:
|
||||
@ -2134,14 +2097,14 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virErrorPtr orig_err;
|
||||
virDomainDefPtr vmdef = vm->def;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
virDomainChrSourceDefPtr dev = chr->source;
|
||||
char *charAlias = NULL;
|
||||
VIR_AUTOFREE(char *)charAlias = NULL;
|
||||
bool chardevAttached = false;
|
||||
bool teardowncgroup = false;
|
||||
bool teardowndevice = false;
|
||||
bool teardownlabel = false;
|
||||
char *tlsAlias = NULL;
|
||||
VIR_AUTOFREE(char *) tlsAlias = NULL;
|
||||
const char *secAlias = NULL;
|
||||
bool need_release = false;
|
||||
bool guestfwd = false;
|
||||
@ -2222,9 +2185,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
|
||||
if (teardowndevice && qemuDomainNamespaceTeardownChardev(vm, chr) < 0)
|
||||
VIR_WARN("Unable to remove chr device from /dev");
|
||||
}
|
||||
VIR_FREE(tlsAlias);
|
||||
VIR_FREE(charAlias);
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
|
||||
exit_monitor:
|
||||
@ -2249,10 +2209,10 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_RNG, { .rng = rng } };
|
||||
virErrorPtr orig_err;
|
||||
char *devstr = NULL;
|
||||
char *charAlias = NULL;
|
||||
char *objAlias = NULL;
|
||||
char *tlsAlias = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
VIR_AUTOFREE(char *) charAlias = NULL;
|
||||
VIR_AUTOFREE(char *) objAlias = NULL;
|
||||
VIR_AUTOFREE(char *) tlsAlias = NULL;
|
||||
const char *secAlias = NULL;
|
||||
bool releaseaddr = false;
|
||||
bool teardowncgroup = false;
|
||||
@ -2338,10 +2298,6 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
|
||||
VIR_WARN("Unable to remove chr device from /dev");
|
||||
}
|
||||
|
||||
VIR_FREE(tlsAlias);
|
||||
VIR_FREE(charAlias);
|
||||
VIR_FREE(objAlias);
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
|
||||
exit_monitor:
|
||||
@ -2380,8 +2336,8 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||
unsigned long long oldmem = virDomainDefGetMemoryTotal(vm->def);
|
||||
unsigned long long newmem = oldmem + mem->size;
|
||||
char *devstr = NULL;
|
||||
char *objalias = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
VIR_AUTOFREE(char *) objalias = NULL;
|
||||
bool objAdded = false;
|
||||
bool teardownlabel = false;
|
||||
bool teardowncgroup = false;
|
||||
@ -2478,8 +2434,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
||||
}
|
||||
|
||||
virJSONValueFree(props);
|
||||
VIR_FREE(devstr);
|
||||
VIR_FREE(objalias);
|
||||
virDomainMemoryDefFree(mem);
|
||||
return ret;
|
||||
|
||||
@ -2518,7 +2472,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
|
||||
virDomainHostdevDefPtr hostdev)
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
bool added = false;
|
||||
bool teardowncgroup = false;
|
||||
bool teardownlabel = false;
|
||||
@ -2580,7 +2534,6 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
|
||||
qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1);
|
||||
virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info);
|
||||
}
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2594,10 +2547,10 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virErrorPtr orig_err;
|
||||
char *devstr = NULL;
|
||||
char *drvstr = NULL;
|
||||
char *drivealias = NULL;
|
||||
char *secobjAlias = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
VIR_AUTOFREE(char *) drvstr = NULL;
|
||||
VIR_AUTOFREE(char *) drivealias = NULL;
|
||||
VIR_AUTOFREE(char *) secobjAlias = NULL;
|
||||
bool teardowncgroup = false;
|
||||
bool teardownlabel = false;
|
||||
bool teardowndevice = false;
|
||||
@ -2699,10 +2652,6 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
|
||||
}
|
||||
qemuDomainSecretHostdevDestroy(hostdev);
|
||||
virJSONValueFree(secobjProps);
|
||||
VIR_FREE(secobjAlias);
|
||||
VIR_FREE(drivealias);
|
||||
VIR_FREE(drvstr);
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
|
||||
exit_monitor:
|
||||
@ -2732,9 +2681,9 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr driver,
|
||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_HOSTDEV,
|
||||
{ .hostdev = hostdev } };
|
||||
virDomainCCWAddressSetPtr ccwaddrs = NULL;
|
||||
char *vhostfdName = NULL;
|
||||
VIR_AUTOFREE(char *) vhostfdName = NULL;
|
||||
int vhostfd = -1;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
bool teardowncgroup = false;
|
||||
bool teardownlabel = false;
|
||||
bool teardowndevice = false;
|
||||
@ -2830,8 +2779,6 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr driver,
|
||||
virDomainCCWAddressSetFree(ccwaddrs);
|
||||
|
||||
VIR_FORCE_CLOSE(vhostfd);
|
||||
VIR_FREE(vhostfdName);
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2842,7 +2789,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriverPtr driver,
|
||||
virDomainHostdevDefPtr hostdev)
|
||||
{
|
||||
int ret = -1;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
bool added = false;
|
||||
bool teardowncgroup = false;
|
||||
bool teardownlabel = false;
|
||||
@ -2927,7 +2874,6 @@ qemuDomainAttachMediatedDevice(virQEMUDriverPtr driver,
|
||||
1);
|
||||
qemuDomainReleaseDeviceAddress(vm, hostdev->info);
|
||||
}
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2992,9 +2938,9 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
|
||||
virDomainShmemDefPtr shmem)
|
||||
{
|
||||
int ret = -1;
|
||||
char *shmstr = NULL;
|
||||
char *charAlias = NULL;
|
||||
char *memAlias = NULL;
|
||||
VIR_AUTOFREE(char *) shmstr = NULL;
|
||||
VIR_AUTOFREE(char *) charAlias = NULL;
|
||||
VIR_AUTOFREE(char *) memAlias = NULL;
|
||||
bool release_backing = false;
|
||||
bool release_address = true;
|
||||
virErrorPtr orig_err = NULL;
|
||||
@ -3083,9 +3029,6 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainReleaseDeviceAddress(vm, &shmem->info);
|
||||
|
||||
virJSONValueFree(props);
|
||||
VIR_FREE(memAlias);
|
||||
VIR_FREE(charAlias);
|
||||
VIR_FREE(shmstr);
|
||||
|
||||
return ret;
|
||||
|
||||
@ -3117,7 +3060,7 @@ qemuDomainAttachWatchdog(virQEMUDriverPtr driver,
|
||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_WATCHDOG, { .watchdog = watchdog } };
|
||||
virDomainWatchdogAction actualAction = watchdog->action;
|
||||
const char *actionStr = NULL;
|
||||
char *watchdogstr = NULL;
|
||||
VIR_AUTOFREE(char *) watchdogstr = NULL;
|
||||
bool releaseAddress = false;
|
||||
int rv;
|
||||
|
||||
@ -3174,7 +3117,6 @@ qemuDomainAttachWatchdog(virQEMUDriverPtr driver,
|
||||
cleanup:
|
||||
if (releaseAddress)
|
||||
qemuDomainReleaseDeviceAddress(vm, &watchdog->info);
|
||||
VIR_FREE(watchdogstr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -3185,7 +3127,7 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
|
||||
virDomainInputDefPtr input)
|
||||
{
|
||||
int ret = -1;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_INPUT,
|
||||
{ .input = input } };
|
||||
@ -3269,7 +3211,6 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
|
||||
virErrorRestore(&originalError);
|
||||
}
|
||||
|
||||
VIR_FREE(devstr);
|
||||
return ret;
|
||||
|
||||
exit_monitor:
|
||||
@ -3293,8 +3234,8 @@ qemuDomainAttachVsockDevice(virQEMUDriverPtr driver,
|
||||
virErrorPtr originalError = NULL;
|
||||
const char *fdprefix = "vsockfd";
|
||||
bool releaseaddr = false;
|
||||
char *fdname = NULL;
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOFREE(char *) fdname = NULL;
|
||||
VIR_AUTOFREE(char *) devstr = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (vm->def->vsock) {
|
||||
@ -3345,8 +3286,6 @@ qemuDomainAttachVsockDevice(virQEMUDriverPtr driver,
|
||||
virErrorRestore(&originalError);
|
||||
}
|
||||
|
||||
VIR_FREE(devstr);
|
||||
VIR_FREE(fdname);
|
||||
return ret;
|
||||
|
||||
exit_monitor:
|
||||
@ -4026,22 +3965,21 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
time_t now = time(NULL);
|
||||
const char *expire;
|
||||
char *validTo = NULL;
|
||||
VIR_AUTOFREE(char *) validTo = NULL;
|
||||
const char *connected = NULL;
|
||||
const char *password;
|
||||
int ret = -1;
|
||||
|
||||
if (!auth->passwd && !defaultPasswd) {
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
if (!auth->passwd && !defaultPasswd)
|
||||
return 0;
|
||||
|
||||
password = auth->passwd ? auth->passwd : defaultPasswd;
|
||||
|
||||
if (auth->connected)
|
||||
connected = virDomainGraphicsAuthConnectedTypeToString(auth->connected);
|
||||
|
||||
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
||||
goto cleanup;
|
||||
return ret;
|
||||
ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
|
||||
|
||||
if (ret != 0)
|
||||
@ -4063,8 +4001,7 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
|
||||
end_job:
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
ret = -1;
|
||||
cleanup:
|
||||
VIR_FREE(validTo);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -4402,7 +4339,7 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
unsigned long long oldmem = virDomainDefGetMemoryTotal(vm->def);
|
||||
unsigned long long newmem = oldmem - mem->size;
|
||||
char *backendAlias = NULL;
|
||||
VIR_AUTOFREE(char *) backendAlias = NULL;
|
||||
int rc;
|
||||
int idx;
|
||||
|
||||
@ -4417,8 +4354,6 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
rc = -1;
|
||||
|
||||
VIR_FREE(backendAlias);
|
||||
|
||||
virDomainAuditMemory(vm, oldmem, newmem, "update", rc == 0);
|
||||
if (rc < 0)
|
||||
return -1;
|
||||
@ -4502,10 +4437,9 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
{
|
||||
virDomainNetDefPtr net = NULL;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
char *drivealias = NULL;
|
||||
char *objAlias = NULL;
|
||||
VIR_AUTOFREE(char *) drivealias = NULL;
|
||||
VIR_AUTOFREE(char *) objAlias = NULL;
|
||||
bool is_vfio = false;
|
||||
|
||||
VIR_DEBUG("Removing host device %s from domain %p %s",
|
||||
@ -4521,7 +4455,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
|
||||
|
||||
if (!(drivealias = qemuAliasFromHostdev(hostdev)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
/* Look for the markers that the iSCSI hostdev was added with a
|
||||
* secret object to manage the username/password. If present, let's
|
||||
@ -4530,7 +4464,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_ISCSI_PASSWORD_SECRET) &&
|
||||
qemuDomainStorageSourceHasAuth(iscsisrc->src)) {
|
||||
if (!(objAlias = qemuDomainGetSecretAESAlias(hostdev->info->alias, false)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
@ -4541,7 +4475,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, objAlias));
|
||||
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hostdev->parentnet) {
|
||||
@ -4612,12 +4546,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
|
||||
virDomainNetDefFree(net);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(drivealias);
|
||||
VIR_FREE(objAlias);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -4628,17 +4557,15 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
|
||||
{
|
||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
char *hostnet_name = NULL;
|
||||
char *charDevAlias = NULL;
|
||||
VIR_AUTOFREE(char *) hostnet_name = NULL;
|
||||
VIR_AUTOFREE(char *) charDevAlias = NULL;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
int actualType = virDomainNetGetActualType(net);
|
||||
|
||||
if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
|
||||
/* this function handles all hostdev and netdev cleanup */
|
||||
ret = qemuDomainRemoveHostDevice(driver, vm,
|
||||
virDomainNetGetActualHostdev(net));
|
||||
goto cleanup;
|
||||
return qemuDomainRemoveHostDevice(driver, vm,
|
||||
virDomainNetGetActualHostdev(net));
|
||||
}
|
||||
|
||||
VIR_DEBUG("Removing network interface %s from domain %p %s",
|
||||
@ -4646,7 +4573,7 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
|
||||
|
||||
if (virAsprintf(&hostnet_name, "host%s", net->info.alias) < 0 ||
|
||||
!(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (virDomainNetGetActualBandwidth(net) &&
|
||||
virNetDevSupportBandwidth(virDomainNetGetActualType(net)) &&
|
||||
@ -4663,9 +4590,9 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
if (qemuMonitorRemoveNetdev(priv->mon, hostnet_name) < 0) {
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
virDomainAuditNet(vm, net, NULL, "detach", false);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
||||
@ -4679,7 +4606,7 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
|
||||
}
|
||||
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp)
|
||||
qemuSlirpStop(QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp, vm, driver, net, true);
|
||||
@ -4723,12 +4650,7 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
|
||||
}
|
||||
}
|
||||
virDomainNetDefFree(net);
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(charDevAlias);
|
||||
VIR_FREE(hostnet_name);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -4739,32 +4661,31 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
|
||||
bool monitor)
|
||||
{
|
||||
virObjectEventPtr event;
|
||||
char *charAlias = NULL;
|
||||
VIR_AUTOFREE(char *) charAlias = NULL;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
int ret = -1;
|
||||
int rc = 0;
|
||||
|
||||
VIR_DEBUG("Removing character device %s from domain %p %s",
|
||||
chr->info.alias, vm, vm->def->name);
|
||||
|
||||
if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (monitor) {
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
rc = qemuMonitorDetachCharDev(priv->mon, charAlias);
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc == 0 &&
|
||||
qemuDomainDelChardevTLSObjects(driver, vm, chr->source, charAlias) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
virDomainAuditChardev(vm, chr, NULL, "detach", rc == 0);
|
||||
|
||||
if (rc < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (qemuTeardownChardevCgroup(vm, chr) < 0)
|
||||
VIR_WARN("Failed to remove chr device cgroup ACL");
|
||||
@ -4786,11 +4707,7 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
|
||||
virObjectEventStateQueue(driver->domainEventState, event);
|
||||
|
||||
virDomainChrDefFree(chr);
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(charAlias);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -4799,11 +4716,10 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virDomainRNGDefPtr rng)
|
||||
{
|
||||
char *charAlias = NULL;
|
||||
char *objAlias = NULL;
|
||||
VIR_AUTOFREE(char *) charAlias = NULL;
|
||||
VIR_AUTOFREE(char *) objAlias = NULL;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
ssize_t idx;
|
||||
int ret = -1;
|
||||
int rc = 0;
|
||||
|
||||
VIR_DEBUG("Removing RNG device %s from domain %p %s",
|
||||
@ -4811,10 +4727,10 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
|
||||
|
||||
|
||||
if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (!(charAlias = qemuAliasChardevFromDevAlias(rng->info.alias)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
|
||||
@ -4828,7 +4744,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
|
||||
rc = -1;
|
||||
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (rng->backend == VIR_DOMAIN_RNG_BACKEND_EGD &&
|
||||
rc == 0 &&
|
||||
@ -4839,7 +4755,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
|
||||
virDomainAuditRNG(vm, rng, NULL, "detach", rc == 0);
|
||||
|
||||
if (rc < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (qemuTeardownRNGCgroup(vm, rng) < 0)
|
||||
VIR_WARN("Failed to remove RNG device cgroup ACL");
|
||||
@ -4851,12 +4767,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
|
||||
virDomainRNGRemove(vm->def, idx);
|
||||
qemuDomainReleaseDeviceAddress(vm, &rng->info);
|
||||
virDomainRNGDefFree(rng);
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(charAlias);
|
||||
VIR_FREE(objAlias);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -4866,10 +4777,9 @@ qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver,
|
||||
virDomainShmemDefPtr shmem)
|
||||
{
|
||||
int rc;
|
||||
int ret = -1;
|
||||
ssize_t idx = -1;
|
||||
char *charAlias = NULL;
|
||||
char *memAlias = NULL;
|
||||
VIR_AUTOFREE(char *) charAlias = NULL;
|
||||
VIR_AUTOFREE(char *) memAlias = NULL;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
|
||||
VIR_DEBUG("Removing shmem device %s from domain %p %s",
|
||||
@ -4891,24 +4801,19 @@ qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver,
|
||||
rc = qemuMonitorDelObject(priv->mon, memAlias);
|
||||
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
virDomainAuditShmem(vm, shmem, "detach", rc == 0);
|
||||
|
||||
if (rc < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if ((idx = virDomainShmemDefFind(vm->def, shmem)) >= 0)
|
||||
virDomainShmemDefRemove(vm->def, idx);
|
||||
qemuDomainReleaseDeviceAddress(vm, &shmem->info);
|
||||
virDomainShmemDefFree(shmem);
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(charAlias);
|
||||
VIR_FREE(memAlias);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -4975,15 +4880,14 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr driver,
|
||||
virDomainRedirdevDefPtr dev)
|
||||
{
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
char *charAlias = NULL;
|
||||
VIR_AUTOFREE(char *) charAlias = NULL;
|
||||
ssize_t idx;
|
||||
int ret = -1;
|
||||
|
||||
VIR_DEBUG("Removing redirdev device %s from domain %p %s",
|
||||
dev->info.alias, vm, vm->def->name);
|
||||
|
||||
if (!(charAlias = qemuAliasChardevFromDevAlias(dev->info.alias)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
qemuDomainObjEnterMonitor(driver, vm);
|
||||
/* DeviceDel from Detach may remove chardev,
|
||||
@ -4992,10 +4896,10 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr driver,
|
||||
ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias));
|
||||
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (qemuDomainDelChardevTLSObjects(driver, vm, dev->source, charAlias) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
virDomainAuditRedirdev(vm, dev, "detach", true);
|
||||
|
||||
@ -5004,11 +4908,7 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainReleaseDeviceAddress(vm, &dev->info);
|
||||
virDomainRedirdevDefFree(dev);
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(charAlias);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user