mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
lib: Prefer g_autoptr() declaration of virQEMUDriverConfigPtr
In the past we had to declare @cfg and then explicitly unref it. But now, with glib we can use g_autoptr() which will do the unref automatically and thus is more bulletproof. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
5befe4ee18
commit
d92c2bbc65
@ -64,13 +64,9 @@ typedef virQEMUDriverConfig *virQEMUDriverConfigPtr;
|
||||
* being released while they use it.
|
||||
*
|
||||
* eg
|
||||
* qemuDriverLock(driver);
|
||||
* virQEMUDriverConfigPtr cfg = virObjectRef(driver->config);
|
||||
* qemuDriverUnlock(driver);
|
||||
* g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
*
|
||||
* ...do stuff with 'cfg'..
|
||||
*
|
||||
* virObjectUnref(cfg);
|
||||
*/
|
||||
struct _virQEMUDriverConfig {
|
||||
virObject parent;
|
||||
|
@ -405,14 +405,12 @@ qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver,
|
||||
virDomainHostdevDefPtr *hostdevs,
|
||||
int nhostdevs)
|
||||
{
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
const char *oldStateDir = cfg->stateDir;
|
||||
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||
|
||||
virHostdevReAttachPCIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name,
|
||||
hostdevs, nhostdevs, oldStateDir);
|
||||
|
||||
virObjectUnref(cfg);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -261,7 +261,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def,
|
||||
{
|
||||
int ret = -1;
|
||||
char *res_ifname = NULL;
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
|
||||
|
||||
if (qemuInterfaceIsVnetCompatModel(net))
|
||||
@ -290,7 +290,6 @@ qemuInterfaceDirectConnect(virDomainDefPtr def,
|
||||
while (tapfdSize--)
|
||||
VIR_FORCE_CLOSE(tapfd[tapfdSize]);
|
||||
}
|
||||
virObjectUnref(cfg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -413,7 +412,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
|
||||
int ret = -1;
|
||||
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
||||
bool template_ifname = false;
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
const char *tunpath = "/dev/net/tun";
|
||||
const char *auditdev = tunpath;
|
||||
|
||||
@ -514,7 +513,6 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
|
||||
if (template_ifname)
|
||||
VIR_FREE(net->ifname);
|
||||
}
|
||||
virObjectUnref(cfg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -542,7 +540,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
|
||||
int ret = -1;
|
||||
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
||||
bool template_ifname = false;
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
const char *tunpath = "/dev/net/tun";
|
||||
|
||||
if (net->backend.tap) {
|
||||
@ -633,7 +631,6 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
|
||||
if (template_ifname)
|
||||
VIR_FREE(net->ifname);
|
||||
}
|
||||
virObjectUnref(cfg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -3205,11 +3205,9 @@ qemuMigrationSrcConfirm(virQEMUDriverPtr driver,
|
||||
int cancelled)
|
||||
{
|
||||
qemuMigrationJobPhase phase;
|
||||
virQEMUDriverConfigPtr cfg = NULL;
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
int ret = -1;
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
|
||||
if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_OUT))
|
||||
goto cleanup;
|
||||
|
||||
@ -3237,7 +3235,6 @@ qemuMigrationSrcConfirm(virQEMUDriverPtr driver,
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
virObjectUnref(cfg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -4091,7 +4088,7 @@ qemuMigrationSrcPerformTunnel(virQEMUDriverPtr driver,
|
||||
{
|
||||
int ret = -1;
|
||||
qemuMigrationSpec spec;
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
int fds[2] = { -1, -1 };
|
||||
|
||||
VIR_DEBUG("driver=%p, vm=%p, st=%p, cookiein=%s, cookieinlen=%d, "
|
||||
@ -4132,7 +4129,6 @@ qemuMigrationSrcPerformTunnel(virQEMUDriverPtr driver,
|
||||
VIR_FORCE_CLOSE(spec.dest.fd.qemu);
|
||||
VIR_FORCE_CLOSE(spec.dest.fd.local);
|
||||
|
||||
virObjectUnref(cfg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ qemuMigrationCookieGraphicsSpiceAlloc(virQEMUDriverPtr driver,
|
||||
{
|
||||
qemuMigrationCookieGraphicsPtr mig = NULL;
|
||||
const char *listenAddr;
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
|
||||
if (VIR_ALLOC(mig) < 0)
|
||||
goto error;
|
||||
@ -215,12 +215,10 @@ qemuMigrationCookieGraphicsSpiceAlloc(virQEMUDriverPtr driver,
|
||||
|
||||
mig->listen = g_strdup(listenAddr);
|
||||
|
||||
virObjectUnref(cfg);
|
||||
return mig;
|
||||
|
||||
error:
|
||||
qemuMigrationCookieGraphicsFree(mig);
|
||||
virObjectUnref(cfg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,7 @@ mymain(void)
|
||||
#endif
|
||||
|
||||
#if WITH_QEMU
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverConfigNew(false, NULL);
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverConfigNew(false, NULL);
|
||||
|
||||
if (!cfg)
|
||||
return EXIT_FAILURE;
|
||||
@ -453,8 +453,6 @@ mymain(void)
|
||||
* file has been added, run "VIR_TEST_REGENERATE_OUTPUT=1 ninja test".
|
||||
*/
|
||||
|
||||
virObjectUnref(cfg);
|
||||
|
||||
virFileWrapperClearPrefixes();
|
||||
|
||||
#endif /* WITH_QEMU */
|
||||
|
@ -132,7 +132,7 @@ mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
g_autofree char *fakerootdir = NULL;
|
||||
virQEMUDriverConfigPtr cfg = NULL;
|
||||
g_autoptr(virQEMUDriverConfig) cfg = NULL;
|
||||
g_autoptr(virHashTable) capslatest = NULL;
|
||||
g_autoptr(virConnect) conn = NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user