mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu_conf: Use more of VIR_AUTOFREE()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
4ba7e5b4ed
commit
dd7a5dcec7
@ -181,37 +181,25 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
|
|||||||
virGetGroupID("tss", &cfg->swtpm_group) < 0)
|
virGetGroupID("tss", &cfg->swtpm_group) < 0)
|
||||||
cfg->swtpm_group = 0; /* fall back to root */
|
cfg->swtpm_group = 0; /* fall back to root */
|
||||||
} else {
|
} else {
|
||||||
char *rundir;
|
VIR_AUTOFREE(char *) rundir = NULL;
|
||||||
char *cachedir;
|
VIR_AUTOFREE(char *) cachedir = NULL;
|
||||||
|
|
||||||
cachedir = virGetUserCacheDirectory();
|
cachedir = virGetUserCacheDirectory();
|
||||||
if (!cachedir)
|
if (!cachedir)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virAsprintf(&cfg->logDir,
|
if (virAsprintf(&cfg->logDir, "%s/qemu/log", cachedir) < 0)
|
||||||
"%s/qemu/log", cachedir) < 0) {
|
|
||||||
VIR_FREE(cachedir);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
if (virAsprintf(&cfg->swtpmLogDir, "%s/qemu/log", cachedir) < 0)
|
||||||
if (virAsprintf(&cfg->swtpmLogDir,
|
|
||||||
"%s/qemu/log", cachedir) < 0) {
|
|
||||||
VIR_FREE(cachedir);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0)
|
||||||
if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0) {
|
|
||||||
VIR_FREE(cachedir);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
VIR_FREE(cachedir);
|
|
||||||
|
|
||||||
rundir = virGetUserRuntimeDirectory();
|
rundir = virGetUserRuntimeDirectory();
|
||||||
if (!rundir)
|
if (!rundir)
|
||||||
goto error;
|
goto error;
|
||||||
if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0) {
|
if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0)
|
||||||
VIR_FREE(rundir);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
VIR_FREE(rundir);
|
|
||||||
|
|
||||||
if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm", cfg->stateDir) < 0)
|
if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm", cfg->stateDir) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -1265,7 +1253,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
|
|||||||
{
|
{
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
virCapsPtr caps;
|
virCapsPtr caps;
|
||||||
virSecurityManagerPtr *sec_managers = NULL;
|
VIR_AUTOFREE(virSecurityManagerPtr) *sec_managers = NULL;
|
||||||
/* Security driver data */
|
/* Security driver data */
|
||||||
const char *doi, *model, *lbl, *type;
|
const char *doi, *model, *lbl, *type;
|
||||||
const int virtTypes[] = {VIR_DOMAIN_VIRT_KVM,
|
const int virtTypes[] = {VIR_DOMAIN_VIRT_KVM,
|
||||||
@ -1312,12 +1300,10 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
|
|||||||
VIR_DEBUG("Initialized caps for security driver \"%s\" with "
|
VIR_DEBUG("Initialized caps for security driver \"%s\" with "
|
||||||
"DOI \"%s\"", model, doi);
|
"DOI \"%s\"", model, doi);
|
||||||
}
|
}
|
||||||
VIR_FREE(sec_managers);
|
|
||||||
|
|
||||||
return caps;
|
return caps;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(sec_managers);
|
|
||||||
virObjectUnref(caps);
|
virObjectUnref(caps);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1489,31 +1475,26 @@ qemuCheckUnprivSGIO(virHashTablePtr sharedDevices,
|
|||||||
const char *device_path,
|
const char *device_path,
|
||||||
int sgio)
|
int sgio)
|
||||||
{
|
{
|
||||||
char *sysfs_path = NULL;
|
VIR_AUTOFREE(char *) sysfs_path = NULL;
|
||||||
char *key = NULL;
|
VIR_AUTOFREE(char *) key = NULL;
|
||||||
int val;
|
int val;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL)))
|
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* It can't be conflict if unpriv_sgio is not supported by kernel. */
|
/* It can't be conflict if unpriv_sgio is not supported by kernel. */
|
||||||
if (!virFileExists(sysfs_path)) {
|
if (!virFileExists(sysfs_path))
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(key = qemuGetSharedDeviceKey(device_path)))
|
if (!(key = qemuGetSharedDeviceKey(device_path)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* It can't be conflict if no other domain is sharing it. */
|
/* It can't be conflict if no other domain is sharing it. */
|
||||||
if (!(virHashLookup(sharedDevices, key))) {
|
if (!(virHashLookup(sharedDevices, key)))
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
|
if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* Error message on failure needs to be handled in caller
|
/* Error message on failure needs to be handled in caller
|
||||||
* since there is more specific knowledge of device
|
* since there is more specific knowledge of device
|
||||||
@ -1523,16 +1504,10 @@ qemuCheckUnprivSGIO(virHashTablePtr sharedDevices,
|
|||||||
sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
|
sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
|
||||||
(val == 1 &&
|
(val == 1 &&
|
||||||
sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
|
sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
|
||||||
ret = -2;
|
return -2;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(sysfs_path);
|
|
||||||
VIR_FREE(key);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1678,7 +1653,7 @@ qemuSharedDiskAddRemoveInternal(virQEMUDriverPtr driver,
|
|||||||
const char *name,
|
const char *name,
|
||||||
bool addDisk)
|
bool addDisk)
|
||||||
{
|
{
|
||||||
char *key = NULL;
|
VIR_AUTOFREE(char *) key = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (virStorageSourceIsEmpty(disk->src) ||
|
if (virStorageSourceIsEmpty(disk->src) ||
|
||||||
@ -1705,7 +1680,6 @@ qemuSharedDiskAddRemoveInternal(virQEMUDriverPtr driver,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
qemuDriverUnlock(driver);
|
qemuDriverUnlock(driver);
|
||||||
VIR_FREE(key);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1743,7 +1717,7 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev)
|
|||||||
{
|
{
|
||||||
virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
|
virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
|
||||||
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
|
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
|
||||||
char *dev_name = NULL;
|
VIR_AUTOFREE(char *) dev_name = NULL;
|
||||||
char *dev_path = NULL;
|
char *dev_path = NULL;
|
||||||
|
|
||||||
if (!(dev_name = virSCSIDeviceGetDevName(NULL,
|
if (!(dev_name = virSCSIDeviceGetDevName(NULL,
|
||||||
@ -1751,12 +1725,9 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev)
|
|||||||
scsihostsrc->bus,
|
scsihostsrc->bus,
|
||||||
scsihostsrc->target,
|
scsihostsrc->target,
|
||||||
scsihostsrc->unit)))
|
scsihostsrc->unit)))
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
ignore_value(virAsprintf(&dev_path, "/dev/%s", dev_name));
|
ignore_value(virAsprintf(&dev_path, "/dev/%s", dev_name));
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(dev_name);
|
|
||||||
return dev_path;
|
return dev_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1767,18 +1738,16 @@ qemuSharedHostdevAddRemoveInternal(virQEMUDriverPtr driver,
|
|||||||
const char *name,
|
const char *name,
|
||||||
bool addDevice)
|
bool addDevice)
|
||||||
{
|
{
|
||||||
char *dev_path = NULL;
|
VIR_AUTOFREE(char *) dev_path = NULL;
|
||||||
char *key = NULL;
|
VIR_AUTOFREE(char *) key = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!qemuIsSharedHostdev(hostdev))
|
if (!qemuIsSharedHostdev(hostdev))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(dev_path = qemuGetHostdevPath(hostdev)))
|
if (!(dev_path = qemuGetHostdevPath(hostdev)) ||
|
||||||
goto cleanup;
|
!(key = qemuGetSharedDeviceKey(dev_path)))
|
||||||
|
return -1;
|
||||||
if (!(key = qemuGetSharedDeviceKey(dev_path)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
|
|
||||||
@ -1789,11 +1758,7 @@ qemuSharedHostdevAddRemoveInternal(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
qemuDriverUnlock(driver);
|
qemuDriverUnlock(driver);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(dev_path);
|
|
||||||
VIR_FREE(key);
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1867,10 +1832,9 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
|||||||
{
|
{
|
||||||
virDomainDiskDefPtr disk = NULL;
|
virDomainDiskDefPtr disk = NULL;
|
||||||
virDomainHostdevDefPtr hostdev = NULL;
|
virDomainHostdevDefPtr hostdev = NULL;
|
||||||
char *sysfs_path = NULL;
|
VIR_AUTOFREE(char *) sysfs_path = NULL;
|
||||||
const char *path = NULL;
|
const char *path = NULL;
|
||||||
int val = -1;
|
int val = -1;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
/* "sgio" is only valid for block disk; cdrom
|
/* "sgio" is only valid for block disk; cdrom
|
||||||
* and floopy disk can have empty source.
|
* and floopy disk can have empty source.
|
||||||
@ -1893,7 +1857,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("'sgio' is not supported for SCSI "
|
_("'sgio' is not supported for SCSI "
|
||||||
"generic device yet "));
|
"generic device yet "));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1902,7 +1866,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
|
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0. */
|
/* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0. */
|
||||||
val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
|
val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
|
||||||
@ -1913,13 +1877,9 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
|||||||
*/
|
*/
|
||||||
if ((virFileExists(sysfs_path) || val == 1) &&
|
if ((virFileExists(sysfs_path) || val == 1) &&
|
||||||
virSetDeviceUnprivSGIO(path, NULL, val) < 0)
|
virSetDeviceUnprivSGIO(path, NULL, val) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(sysfs_path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemuDriverAllocateID(virQEMUDriverPtr driver)
|
int qemuDriverAllocateID(virQEMUDriverPtr driver)
|
||||||
@ -1955,14 +1915,12 @@ char *
|
|||||||
qemuGetDomainHugepagePath(const virDomainDef *def,
|
qemuGetDomainHugepagePath(const virDomainDef *def,
|
||||||
virHugeTLBFSPtr hugepage)
|
virHugeTLBFSPtr hugepage)
|
||||||
{
|
{
|
||||||
char *base = qemuGetBaseHugepagePath(hugepage);
|
VIR_AUTOFREE(char *) base = qemuGetBaseHugepagePath(hugepage);
|
||||||
char *domPath = virDomainDefGetShortName(def);
|
VIR_AUTOFREE(char *) domPath = virDomainDefGetShortName(def);
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
if (base && domPath)
|
if (base && domPath)
|
||||||
ignore_value(virAsprintf(&ret, "%s/%s", base, domPath));
|
ignore_value(virAsprintf(&ret, "%s/%s", base, domPath));
|
||||||
VIR_FREE(domPath);
|
|
||||||
VIR_FREE(base);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2023,20 +1981,15 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
|
|||||||
virQEMUDriverConfigPtr cfg,
|
virQEMUDriverConfigPtr cfg,
|
||||||
char **path)
|
char **path)
|
||||||
{
|
{
|
||||||
char *shortName = NULL;
|
VIR_AUTOFREE(char *) shortName = NULL;
|
||||||
char *base = NULL;
|
VIR_AUTOFREE(char *) base = NULL;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!(shortName = virDomainDefGetShortName(def)) ||
|
if (!(shortName = virDomainDefGetShortName(def)) ||
|
||||||
qemuGetMemoryBackingBasePath(cfg, &base) < 0 ||
|
qemuGetMemoryBackingBasePath(cfg, &base) < 0 ||
|
||||||
virAsprintf(path, "%s/%s", base, shortName) < 0)
|
virAsprintf(path, "%s/%s", base, shortName) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
VIR_FREE(base);
|
|
||||||
VIR_FREE(shortName);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2058,22 +2011,18 @@ qemuGetMemoryBackingPath(const virDomainDef *def,
|
|||||||
const char *alias,
|
const char *alias,
|
||||||
char **memPath)
|
char **memPath)
|
||||||
{
|
{
|
||||||
char *domainPath = NULL;
|
VIR_AUTOFREE(char *) domainPath = NULL;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!alias) {
|
if (!alias) {
|
||||||
/* This should never happen (TM) */
|
/* This should never happen (TM) */
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("memory device alias is not assigned"));
|
_("memory device alias is not assigned"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0 ||
|
if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0 ||
|
||||||
virAsprintf(memPath, "%s/%s", domainPath, alias) < 0)
|
virAsprintf(memPath, "%s/%s", domainPath, alias) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
VIR_FREE(domainPath);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user