]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: add support for g_autoptr with virObject instances
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 4 Oct 2019 16:14:10 +0000 (17:14 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Mon, 14 Oct 2019 09:54:42 +0000 (10:54 +0100)
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.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
21 files changed:
docs/hacking.html.in
src/conf/capabilities.h
src/conf/domain_capabilities.h
src/conf/domain_conf.h
src/conf/snapshot_conf.h
src/conf/storage_capabilities.h
src/datatypes.h
src/libxl/libxl_conf.h
src/qemu/qemu_blockjob.h
src/qemu/qemu_capabilities.h
src/qemu/qemu_conf.h
src/util/virhostdev.h
src/util/viridentity.h
src/util/virmdev.h
src/util/virobject.h
src/util/virpci.h
src/util/virresctrl.h
src/util/virscsi.h
src/util/virscsivhost.h
src/util/virstoragefile.h
src/util/virusb.h

index d12b246ef993bc3f64ccd8e71ed99d70e5307017..a7a0c7c3cc84f6bd9c1b6a07925f3c40854754c8 100644 (file)
@@ -1046,6 +1046,11 @@ BAD:
         g_autoptr, g_auto on an object whose cleanup function
         is declared with the libvirt macros and vice-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>
index d6a4e79d77b395e1053403e5b1e79240c5e2b478..4abd3dcabd0754e8f24bc98526c0e3297ff5f16e 100644 (file)
@@ -195,6 +195,9 @@ struct _virCaps {
     virCapsStoragePoolPtr *pools;
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCaps, virObjectUnref);
+
+
 struct _virCapsDomainData {
     int ostype;
     int arch;
index 4756af38e9a9742148dfb76b2eee9f4a0c5ab65d..f5571b218807f49325b587b7dbb1cca721cdfe4e 100644 (file)
@@ -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,
index b7ae57aa9d2c6525075c3e1232c16505eb500e31..f7404b814f39b93d870b4fd8ce6b18d81421dca7 100644 (file)
@@ -2594,6 +2594,9 @@ struct _virDomainObj {
                                           * restore will be required later */
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainObj, virObjectUnref);
+
+
 typedef bool (*virDomainObjListACLFilter)(virConnectPtr conn,
                                           virDomainDefPtr def);
 
index 17d614a7e12119639aa2880b18016f3bad6c616a..7e2ffa9d606b5760cca6a9442810fda384fcf94d 100644 (file)
@@ -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,
index 948e5bed5bfef930cbb240148ec1f791ff51462f..788ea227ea54d67abfc3a48c5dc3ed2e5eb41c62 100644 (file)
@@ -30,6 +30,9 @@ struct _virStoragePoolCaps {
     virCapsPtr driverCaps;
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolCaps, virObjectUnref);
+
+
 virStoragePoolCapsPtr
 virStoragePoolCapsNew(virCapsPtr driverCaps);
 
index 87e77fff790f68131a5aeb5ff18ecb699abf44be..16ab5b728277f52a7b6369ccbb9c6f35614b5fcc 100644 (file)
@@ -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:
  *
index 27badfb2928f912ebda16bc04dcacaa768648c21..80be791b7c2619eb1a90b0c0f644142011e8429c 100644 (file)
@@ -102,6 +102,8 @@ struct _libxlDriverConfig {
     size_t nfirmwares;
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(libxlDriverConfig, virObjectUnref);
+
 
 struct _libxlDriverPrivate {
     virMutex lock;
index 41a5cd91f801f657de4cd9bdd159844adb2fc8c2..417f253e313109d1b9d44f66fe69932740de5986 100644 (file)
@@ -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,
index ea45edb9a4659555f4e835b2e668b118ce7ffc62..10f0ce2654ac83d7d18c18966bb39e49b16300f0 100644 (file)
@@ -535,6 +535,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,
index 8473d6d4ca0f21cbf16c8ad2e90b173f0544abba..7247199d3edc6d600a0056165ba1f50547c4ba65 100644 (file)
@@ -218,6 +218,9 @@ struct _virQEMUDriverConfig {
     char **capabilityfilters;
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref);
+
+
 /* Main driver state */
 struct _virQEMUDriver {
     virMutex lock;
index 88501e27432d59f7b94e47029e3bd3344fa4654c..b19a9c3f453eadc0a70a52d659c5c2c8102de26a 100644 (file)
@@ -55,6 +55,9 @@ struct _virHostdevManager {
     virMediatedDeviceListPtr activeMediatedHostdevs;
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virHostdevManager, virObjectUnref);
+
+
 virHostdevManagerPtr virHostdevManagerGetDefault(void);
 int
 virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
index 861ecca7365235b938fb9aed031a9205b95299e1..7513dd4e3598ae351ee3741d109d8965e72ce2eb 100644 (file)
@@ -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);
 
index fb125e70564256a10a94110aee3508884b59ad6f..7f442b571f7af120f17f2023c9a46b0ea292e4e6 100644 (file)
@@ -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 {
index fe5dbe7326fb1829998e24d365f3647bfb1983a5..773a009f5e13b6755701dd9f60e23c156f7d65e4 100644 (file)
@@ -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);
 
index dc20f9171025e891ec175c8b7ff1a59686dd0adb..f3226f1f1b9b55207989d8f779b5e7e62e542ae2 100644 (file)
@@ -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
 
index 216a7302cd042c1309fabf47bb85abf49cbea8bc..3dd7c9634825bf314960fc93c187b4b35614464b 100644 (file)
@@ -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,
index 6cc68835b75faacf32a684861939830fed1dc061..8c2c84e07b341c60511714cb1d4c2015c88fb456 100644 (file)
@@ -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,
index a1a0ea561866c5585986c1cae89f9ae9ea587403..334eb81af6cbd848e69d1131f159f889e9e6d08d 100644 (file)
@@ -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);
 
index d84dad052d87074d065452df6cead994812f3435..cfee047e6f8990654fe44946f901cf79c27adda0 100644 (file)
@@ -344,6 +344,8 @@ struct _virStorageSource {
     bool hostcdrom; /* backing device is a cdrom */
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref);
+
 
 #ifndef DEV_BSIZE
 # define DEV_BSIZE 512
index c95514ed3d0537ff1bde46ed1a77941db45a359d..33ddb6c84e220003e319a8fb3979d5a5d1133774 100644 (file)
@@ -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);