mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00: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.
|
* being released while they use it.
|
||||||
*
|
*
|
||||||
* eg
|
* eg
|
||||||
* qemuDriverLock(driver);
|
* g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
* virQEMUDriverConfigPtr cfg = virObjectRef(driver->config);
|
|
||||||
* qemuDriverUnlock(driver);
|
|
||||||
*
|
*
|
||||||
* ...do stuff with 'cfg'..
|
* ...do stuff with 'cfg'..
|
||||||
*
|
|
||||||
* virObjectUnref(cfg);
|
|
||||||
*/
|
*/
|
||||||
struct _virQEMUDriverConfig {
|
struct _virQEMUDriverConfig {
|
||||||
virObject parent;
|
virObject parent;
|
||||||
|
@ -405,14 +405,12 @@ qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver,
|
|||||||
virDomainHostdevDefPtr *hostdevs,
|
virDomainHostdevDefPtr *hostdevs,
|
||||||
int nhostdevs)
|
int nhostdevs)
|
||||||
{
|
{
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
const char *oldStateDir = cfg->stateDir;
|
const char *oldStateDir = cfg->stateDir;
|
||||||
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||||
|
|
||||||
virHostdevReAttachPCIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name,
|
virHostdevReAttachPCIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name,
|
||||||
hostdevs, nhostdevs, oldStateDir);
|
hostdevs, nhostdevs, oldStateDir);
|
||||||
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -261,7 +261,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *res_ifname = NULL;
|
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;
|
unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
|
||||||
|
|
||||||
if (qemuInterfaceIsVnetCompatModel(net))
|
if (qemuInterfaceIsVnetCompatModel(net))
|
||||||
@ -290,7 +290,6 @@ qemuInterfaceDirectConnect(virDomainDefPtr def,
|
|||||||
while (tapfdSize--)
|
while (tapfdSize--)
|
||||||
VIR_FORCE_CLOSE(tapfd[tapfdSize]);
|
VIR_FORCE_CLOSE(tapfd[tapfdSize]);
|
||||||
}
|
}
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +412,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
||||||
bool template_ifname = false;
|
bool template_ifname = false;
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
const char *tunpath = "/dev/net/tun";
|
const char *tunpath = "/dev/net/tun";
|
||||||
const char *auditdev = tunpath;
|
const char *auditdev = tunpath;
|
||||||
|
|
||||||
@ -514,7 +513,6 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
|
|||||||
if (template_ifname)
|
if (template_ifname)
|
||||||
VIR_FREE(net->ifname);
|
VIR_FREE(net->ifname);
|
||||||
}
|
}
|
||||||
virObjectUnref(cfg);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -542,7 +540,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
||||||
bool template_ifname = false;
|
bool template_ifname = false;
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
const char *tunpath = "/dev/net/tun";
|
const char *tunpath = "/dev/net/tun";
|
||||||
|
|
||||||
if (net->backend.tap) {
|
if (net->backend.tap) {
|
||||||
@ -633,7 +631,6 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
|
|||||||
if (template_ifname)
|
if (template_ifname)
|
||||||
VIR_FREE(net->ifname);
|
VIR_FREE(net->ifname);
|
||||||
}
|
}
|
||||||
virObjectUnref(cfg);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -3205,11 +3205,9 @@ qemuMigrationSrcConfirm(virQEMUDriverPtr driver,
|
|||||||
int cancelled)
|
int cancelled)
|
||||||
{
|
{
|
||||||
qemuMigrationJobPhase phase;
|
qemuMigrationJobPhase phase;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
cfg = virQEMUDriverGetConfig(driver);
|
|
||||||
|
|
||||||
if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_OUT))
|
if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_OUT))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -3237,7 +3235,6 @@ qemuMigrationSrcConfirm(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4091,7 +4088,7 @@ qemuMigrationSrcPerformTunnel(virQEMUDriverPtr driver,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
qemuMigrationSpec spec;
|
qemuMigrationSpec spec;
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
int fds[2] = { -1, -1 };
|
int fds[2] = { -1, -1 };
|
||||||
|
|
||||||
VIR_DEBUG("driver=%p, vm=%p, st=%p, cookiein=%s, cookieinlen=%d, "
|
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.qemu);
|
||||||
VIR_FORCE_CLOSE(spec.dest.fd.local);
|
VIR_FORCE_CLOSE(spec.dest.fd.local);
|
||||||
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ qemuMigrationCookieGraphicsSpiceAlloc(virQEMUDriverPtr driver,
|
|||||||
{
|
{
|
||||||
qemuMigrationCookieGraphicsPtr mig = NULL;
|
qemuMigrationCookieGraphicsPtr mig = NULL;
|
||||||
const char *listenAddr;
|
const char *listenAddr;
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
|
||||||
if (VIR_ALLOC(mig) < 0)
|
if (VIR_ALLOC(mig) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -215,12 +215,10 @@ qemuMigrationCookieGraphicsSpiceAlloc(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
mig->listen = g_strdup(listenAddr);
|
mig->listen = g_strdup(listenAddr);
|
||||||
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
return mig;
|
return mig;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
qemuMigrationCookieGraphicsFree(mig);
|
qemuMigrationCookieGraphicsFree(mig);
|
||||||
virObjectUnref(cfg);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ mymain(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WITH_QEMU
|
#if WITH_QEMU
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverConfigNew(false, NULL);
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverConfigNew(false, NULL);
|
||||||
|
|
||||||
if (!cfg)
|
if (!cfg)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -453,8 +453,6 @@ mymain(void)
|
|||||||
* file has been added, run "VIR_TEST_REGENERATE_OUTPUT=1 ninja test".
|
* file has been added, run "VIR_TEST_REGENERATE_OUTPUT=1 ninja test".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
|
|
||||||
virFileWrapperClearPrefixes();
|
virFileWrapperClearPrefixes();
|
||||||
|
|
||||||
#endif /* WITH_QEMU */
|
#endif /* WITH_QEMU */
|
||||||
|
@ -132,7 +132,7 @@ mymain(void)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
g_autofree char *fakerootdir = NULL;
|
g_autofree char *fakerootdir = NULL;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
g_autoptr(virQEMUDriverConfig) cfg = NULL;
|
||||||
g_autoptr(virHashTable) capslatest = NULL;
|
g_autoptr(virHashTable) capslatest = NULL;
|
||||||
g_autoptr(virConnect) conn = NULL;
|
g_autoptr(virConnect) conn = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user