Libvirt currently uses the VIR_AUTOUNREF macro for auto cleanup of
virObject instances. GLib approaches things differently with GObject,
reusing their g_autoptr() concept.
This introduces support for g_autoptr() with virObject, to facilitate
the conversion to GObject.
Only virObject classes which are currently used with VIR_AUTOREF are
updated. Any others should be converted to GObject before introducing
use of autocleanup.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
docs/hacking.html.in | 5 +++++
src/conf/capabilities.h | 3 +++
src/conf/domain_capabilities.h | 3 +++
src/conf/domain_conf.h | 3 +++
src/conf/snapshot_conf.h | 3 +++
src/conf/storage_capabilities.h | 3 +++
src/datatypes.h | 15 +++++++++++++++
src/libxl/libxl_conf.h | 2 ++
src/qemu/qemu_blockjob.h | 1 +
src/qemu/qemu_capabilities.h | 2 ++
src/qemu/qemu_conf.h | 3 +++
src/util/virhostdev.h | 3 +++
src/util/viridentity.h | 2 ++
src/util/virmdev.h | 3 +++
src/util/virobject.h | 4 ++++
src/util/virpci.h | 3 +++
src/util/virresctrl.h | 4 ++++
src/util/virscsi.h | 3 +++
src/util/virscsivhost.h | 3 +++
src/util/virstoragefile.h | 2 ++
src/util/virusb.h | 3 +++
21 files changed, 73 insertions(+)
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index 40a3c60573..0d04270699 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -1046,6 +1046,11 @@ BAD:
g_autoptr, g_auto on an object whose cleanup function
is declared with the libvirt macros and vica-verca.
</dd>
+
+ <dt>VIR_AUTOUNREF</dt>
+ <dd>The GLib macros g_autoptr and G_DEFINE_AUTOPTR_CLEANUP_FUNC
+ should be used to manage autoclean of virObject classes.
+ This matches usage with GObject classes.</dd>
</dl>
<h2><a id="file_handling">File handling</a></h2>
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index d6a4e79d77..4abd3dcabd 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -195,6 +195,9 @@ struct _virCaps {
virCapsStoragePoolPtr *pools;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCaps, virObjectUnref);
+
+
struct _virCapsDomainData {
int ostype;
int arch;
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 4756af38e9..f5571b2188 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -185,6 +185,9 @@ struct _virDomainCaps {
/* add new domain features here */
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCaps, virObjectUnref);
+
+
virDomainCapsPtr virDomainCapsNew(const char *path,
const char *machine,
virArch arch,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2884af49d8..db4de1a7f5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2592,6 +2592,9 @@ struct _virDomainObj {
* restore will be required later */
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainObj, virObjectUnref);
+
+
typedef bool (*virDomainObjListACLFilter)(virConnectPtr conn,
virDomainDefPtr def);
diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
index 17d614a7e1..7e2ffa9d60 100644
--- a/src/conf/snapshot_conf.h
+++ b/src/conf/snapshot_conf.h
@@ -87,6 +87,9 @@ struct _virDomainSnapshotDef {
virObjectPtr cookie;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSnapshotDef, virObjectUnref);
+
+
typedef enum {
VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE = 1 << 0,
VIR_DOMAIN_SNAPSHOT_PARSE_DISKS = 1 << 1,
diff --git a/src/conf/storage_capabilities.h b/src/conf/storage_capabilities.h
index 948e5bed5b..788ea227ea 100644
--- a/src/conf/storage_capabilities.h
+++ b/src/conf/storage_capabilities.h
@@ -30,6 +30,9 @@ struct _virStoragePoolCaps {
virCapsPtr driverCaps;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolCaps, virObjectUnref);
+
+
virStoragePoolCapsPtr
virStoragePoolCapsNew(virCapsPtr driverCaps);
diff --git a/src/datatypes.h b/src/datatypes.h
index 87e77fff79..16ab5b7282 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -548,6 +548,9 @@ struct _virConnect {
void *userData; /* the user data */
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virConnect, virObjectUnref);
+
+
/**
* _virAdmConnect:
*
@@ -616,6 +619,9 @@ struct _virNetwork {
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier */
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetwork, virObjectUnref);
+
+
/**
* _virNetworkPort:
*
@@ -627,6 +633,9 @@ struct _virNetworkPort {
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier */
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkPort, virObjectUnref);
+
+
/**
* _virInterface:
*
@@ -658,6 +667,9 @@ struct _virStoragePool {
virFreeCallback privateDataFreeFunc;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virObjectUnref);
+
+
/**
* _virStorageVol:
*
@@ -678,6 +690,9 @@ struct _virStorageVol {
virFreeCallback privateDataFreeFunc;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVol, virObjectUnref);
+
+
/**
* _virNodeDevice:
*
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 27badfb292..80be791b7c 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -102,6 +102,8 @@ struct _libxlDriverConfig {
size_t nfirmwares;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(libxlDriverConfig, virObjectUnref);
+
struct _libxlDriverPrivate {
virMutex lock;
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index 41a5cd91f8..417f253e31 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -134,6 +134,7 @@ struct _qemuBlockJobData {
bool invalidData; /* the job data (except name) is not valid */
bool reconnected; /* internal field for tracking whether job is live after reconnect
to qemu */
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuBlockJobData, virObjectUnref);
int
qemuBlockJobRegister(qemuBlockJobDataPtr job,
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 72da3691f2..a1045b436e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -533,6 +533,8 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check
*/
typedef struct _virQEMUCaps virQEMUCaps;
typedef virQEMUCaps *virQEMUCapsPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUCaps, virObjectUnref);
+
virQEMUCapsPtr virQEMUCapsNew(void);
void virQEMUCapsSet(virQEMUCapsPtr qemuCaps,
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 8473d6d4ca..7247199d3e 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -218,6 +218,9 @@ struct _virQEMUDriverConfig {
char **capabilityfilters;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref);
+
+
/* Main driver state */
struct _virQEMUDriver {
virMutex lock;
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 88501e2743..b19a9c3f45 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -55,6 +55,9 @@ struct _virHostdevManager {
virMediatedDeviceListPtr activeMediatedHostdevs;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virHostdevManager, virObjectUnref);
+
+
virHostdevManagerPtr virHostdevManagerGetDefault(void);
int
virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
diff --git a/src/util/viridentity.h b/src/util/viridentity.h
index 861ecca736..7513dd4e35 100644
--- a/src/util/viridentity.h
+++ b/src/util/viridentity.h
@@ -26,6 +26,8 @@
typedef struct _virIdentity virIdentity;
typedef virIdentity *virIdentityPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virIdentity, virObjectUnref);
+
virIdentityPtr virIdentityGetCurrent(void);
int virIdentitySetCurrent(virIdentityPtr ident);
diff --git a/src/util/virmdev.h b/src/util/virmdev.h
index fb125e7056..7f442b571f 100644
--- a/src/util/virmdev.h
+++ b/src/util/virmdev.h
@@ -40,6 +40,9 @@ typedef virMediatedDevice *virMediatedDevicePtr;
typedef struct _virMediatedDeviceList virMediatedDeviceList;
typedef virMediatedDeviceList *virMediatedDeviceListPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceList, virObjectUnref);
+
+
typedef struct _virMediatedDeviceType virMediatedDeviceType;
typedef virMediatedDeviceType *virMediatedDeviceTypePtr;
struct _virMediatedDeviceType {
diff --git a/src/util/virobject.h b/src/util/virobject.h
index fe5dbe7326..773a009f5e 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -116,12 +116,16 @@ virObjectAutoUnref(void *objptr);
* VIR_AUTOUNREF:
* @type: type of an virObject subclass to be unref'd automatically
*
+ * DEPRECATED: Use g_autoptr(type) instead
+ *
* Declares a variable of @type which will be automatically unref'd when
* control goes out of the scope.
*/
#define VIR_AUTOUNREF(type) \
__attribute__((cleanup(virObjectAutoUnref))) type
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virObject, virObjectUnref);
+
void *
virObjectRef(void *obj);
diff --git a/src/util/virpci.h b/src/util/virpci.h
index dc20f91710..f3226f1f1b 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -34,6 +34,9 @@ typedef virPCIDeviceAddress *virPCIDeviceAddressPtr;
typedef struct _virPCIDeviceList virPCIDeviceList;
typedef virPCIDeviceList *virPCIDeviceListPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIDeviceList, virObjectUnref);
+
+
#define VIR_DOMAIN_DEVICE_ZPCI_MAX_UID UINT16_MAX
#define VIR_DOMAIN_DEVICE_ZPCI_MAX_FID UINT32_MAX
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index 216a7302cd..3dd7c96348 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -20,6 +20,7 @@
#include "internal.h"
+#include "virobject.h"
#include "virbitmap.h"
#include "virutil.h"
#include "virenum.h"
@@ -114,6 +115,9 @@ virResctrlInfoGetMemoryBandwidth(virResctrlInfoPtr resctrl,
typedef struct _virResctrlAlloc virResctrlAlloc;
typedef virResctrlAlloc *virResctrlAllocPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virResctrlAlloc, virObjectUnref);
+
+
typedef int virResctrlAllocForeachCacheCallback(unsigned int level,
virCacheType type,
unsigned int cache,
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
index 6cc68835b7..8c2c84e07b 100644
--- a/src/util/virscsi.h
+++ b/src/util/virscsi.h
@@ -30,6 +30,9 @@ typedef virSCSIDevice *virSCSIDevicePtr;
typedef struct _virSCSIDeviceList virSCSIDeviceList;
typedef virSCSIDeviceList *virSCSIDeviceListPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSCSIDeviceList, virObjectUnref);
+
+
char *virSCSIDeviceGetSgName(const char *sysfs_prefix,
const char *adapter,
unsigned int bus,
diff --git a/src/util/virscsivhost.h b/src/util/virscsivhost.h
index a1a0ea5618..334eb81af6 100644
--- a/src/util/virscsivhost.h
+++ b/src/util/virscsivhost.h
@@ -30,6 +30,9 @@ typedef virSCSIVHostDevice *virSCSIVHostDevicePtr;
typedef struct _virSCSIVHostDeviceList virSCSIVHostDeviceList;
typedef virSCSIVHostDeviceList *virSCSIVHostDeviceListPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSCSIVHostDeviceList, virObjectUnref);
+
+
typedef int (*virSCSIVHostDeviceFileActor)(virSCSIVHostDevicePtr dev,
const char *name, void *opaque);
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 81b83a53ef..5b01f9303b 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -339,6 +339,8 @@ struct _virStorageSource {
bool hostcdrom; /* backing device is a cdrom */
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref);
+
#ifndef DEV_BSIZE
# define DEV_BSIZE 512
diff --git a/src/util/virusb.h b/src/util/virusb.h
index c95514ed3d..33ddb6c84e 100644
--- a/src/util/virusb.h
+++ b/src/util/virusb.h
@@ -31,6 +31,9 @@ typedef virUSBDevice *virUSBDevicePtr;
typedef struct _virUSBDeviceList virUSBDeviceList;
typedef virUSBDeviceList *virUSBDeviceListPtr;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virUSBDeviceList, virObjectUnref);
+
+
virUSBDevicePtr virUSBDeviceNew(unsigned int bus,
unsigned int devno,
const char *vroot);
--
2.21.0