[PATCH v2 24/40] datatypes: convert virStoragePool to GObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/storage_event.c            | 15 +++----
 src/conf/virstorageobj.c            |  2 +-
 src/datatypes.c                     | 70 ++++++++++++++++++++---------
 src/datatypes.h                     | 15 ++++---
 src/libvirt-storage.c               |  6 +--
 src/libvirt_private.syms            |  2 +-
 src/qemu/qemu_migration.c           |  3 +-
 src/remote/remote_daemon_dispatch.c |  3 +-
 src/remote/remote_driver.c          |  6 +--
 src/rpc/gendispatch.pl              |  1 +
 src/vz/vz_sdk.c                     |  3 +-
 11 files changed, 73 insertions(+), 53 deletions(-)

diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c
index de36ec3af9..e18069f718 100644
--- a/src/conf/storage_event.c
+++ b/src/conf/storage_event.c
@@ -110,10 +110,10 @@ virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn,
                                        virConnectObjectEventGenericCallback cb,
                                        void *cbopaque)
 {
-    virStoragePoolPtr pool = virGetStoragePool(conn,
-                                               event->meta.name,
-                                               event->meta.uuid,
-                                               NULL, NULL);
+    g_autoptr(virStoragePool) pool = virGetStoragePool(conn,
+                                                       event->meta.name,
+                                                       event->meta.uuid,
+                                                       NULL, NULL);
     if (!pool)
         return;
 
@@ -127,23 +127,20 @@ virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn,
                                                               storagePoolLifecycleEvent->type,
                                                               storagePoolLifecycleEvent->detail,
                                                               cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_STORAGE_POOL_EVENT_ID_REFRESH:
         {
             ((virConnectStoragePoolEventGenericCallback)cb)(conn, pool,
                                                             cbopaque);
-            goto cleanup;
+            return;
         }
 
     case VIR_STORAGE_POOL_EVENT_ID_LAST:
         break;
     }
     VIR_WARN("Unexpected event ID %d", event->eventID);
-
- cleanup:
-    virObjectUnref(pool);
 }
 
 
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 5cbd30f93c..4c25c9a9f8 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -2095,6 +2095,6 @@ virStoragePoolObjListExport(virConnectPtr conn,
     return data.nPools;
 
  error:
-    virObjectListFree(data.pools);
+    virGObjectListFreeCount(data.pools, data.nPools);
     return -1;
 }
diff --git a/src/datatypes.c b/src/datatypes.c
index 455bcd70ef..a9a942b3a6 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -40,7 +40,6 @@ virClassPtr virNodeDeviceClass;
 virClassPtr virSecretClass;
 virClassPtr virStreamClass;
 virClassPtr virStorageVolClass;
-virClassPtr virStoragePoolClass;
 
 static void virConnectDispose(void *obj);
 static void virConnectCloseCallbackDataDispose(void *obj);
@@ -49,7 +48,6 @@ static void virNodeDeviceDispose(void *obj);
 static void virSecretDispose(void *obj);
 static void virStreamDispose(void *obj);
 static void virStorageVolDispose(void *obj);
-static void virStoragePoolDispose(void *obj);
 
 G_DEFINE_TYPE(virDomainCheckpoint, vir_domain_checkpoint, G_TYPE_OBJECT);
 static void virDomainCheckpointDispose(GObject *obj);
@@ -177,6 +175,24 @@ vir_nw_filter_binding_class_init(virNWFilterBindingClass *klass)
     obj->finalize = virNWFilterBindingFinalize;
 }
 
+G_DEFINE_TYPE(virStoragePool, vir_storage_pool, G_TYPE_OBJECT);
+static void virStoragePoolDispose(GObject *obj);
+static void virStoragePoolFinalize(GObject *obj);
+
+static void
+vir_storage_pool_init(virStoragePool *pool G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_storage_pool_class_init(virStoragePoolClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->dispose = virStoragePoolDispose;
+    obj->finalize = virStoragePoolFinalize;
+}
+
 virClassPtr virAdmConnectClass;
 virClassPtr virAdmConnectCloseCallbackDataClass;
 
@@ -235,7 +251,6 @@ virDataTypesOnceInit(void)
     DECLARE_CLASS(virSecret);
     DECLARE_CLASS(virStream);
     DECLARE_CLASS(virStorageVol);
-    DECLARE_CLASS(virStoragePool);
 
     DECLARE_CLASS_LOCKABLE(virAdmConnect);
     DECLARE_CLASS_LOCKABLE(virAdmConnectCloseCallbackData);
@@ -681,7 +696,7 @@ virInterfaceFinalize(GObject *obj)
  * @freeFunc: private data cleanup function pointer specific to driver
  *
  * Allocates a new storage pool object. When the object is no longer needed,
- * virObjectUnref() must be called in order to not leak data.
+ * g_object_unref() must be called in order to not leak data.
  *
  * Returns a pointer to the storage pool object, or NULL on error.
  */
@@ -690,17 +705,16 @@ virGetStoragePool(virConnectPtr conn, const char *name,
                   const unsigned char *uuid,
                   void *privateData, virFreeCallback freeFunc)
 {
-    virStoragePoolPtr ret = NULL;
+    g_autoptr(virStoragePool) ret = NULL;
 
     if (virDataTypesInitialize() < 0)
         return NULL;
 
-    virCheckConnectGoto(conn, error);
-    virCheckNonNullArgGoto(name, error);
-    virCheckNonNullArgGoto(uuid, error);
+    virCheckConnectReturn(conn, NULL);
+    virCheckNonNullArgReturn(name, NULL);
+    virCheckNonNullArgReturn(uuid, NULL);
 
-    if (!(ret = virObjectNew(virStoragePoolClass)))
-        goto error;
+    ret = VIR_STORAGE_POOL(g_object_new(VIR_TYPE_STORAGE_POOL, NULL));
 
     ret->name = g_strdup(name);
 
@@ -711,11 +725,7 @@ virGetStoragePool(virConnectPtr conn, const char *name,
     ret->privateData = privateData;
     ret->privateDataFreeFunc = freeFunc;
 
-    return ret;
-
- error:
-    virObjectUnref(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 
@@ -723,16 +733,31 @@ virGetStoragePool(virConnectPtr conn, const char *name,
  * virStoragePoolDispose:
  * @obj: the storage pool to release
  *
- * Unconditionally release all memory associated with a pool.
- * The pool object must not be used once this method returns.
+ * Unreferences the associated connection object, which may also be
+ * released if its ref count hits zero.
+ */
+static void
+virStoragePoolDispose(GObject *obj)
+{
+    virStoragePoolPtr pool = VIR_STORAGE_POOL(obj);
+
+    virObjectUnref(pool->conn);
+    pool->conn = NULL;
+
+    G_OBJECT_CLASS(vir_storage_pool_parent_class)->dispose(obj);
+}
+
+/**
+ * virStoragePoolFinalize:
+ * @obj: the storage pool to release
  *
- * It will also unreference the associated connection object,
- * which may also be released if its ref count hits zero.
+ * Unconditionally releases all memory associated with a pool.
+ * The pool object must not be used once this method returns.
  */
 static void
-virStoragePoolDispose(void *obj)
+virStoragePoolFinalize(GObject *obj)
 {
-    virStoragePoolPtr pool = obj;
+    virStoragePoolPtr pool = VIR_STORAGE_POOL(obj);
     char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     virUUIDFormat(pool->uuid, uuidstr);
@@ -742,7 +767,8 @@ virStoragePoolDispose(void *obj)
         pool->privateDataFreeFunc(pool->privateData);
 
     VIR_FREE(pool->name);
-    virObjectUnref(pool->conn);
+
+    G_OBJECT_CLASS(vir_storage_pool_parent_class)->finalize(obj);
 }
 
 
diff --git a/src/datatypes.h b/src/datatypes.h
index e9bc1574e7..2c8256388c 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -36,7 +36,6 @@ extern virClassPtr virNodeDeviceClass;
 extern virClassPtr virSecretClass;
 extern virClassPtr virStreamClass;
 extern virClassPtr virStorageVolClass;
-extern virClassPtr virStoragePoolClass;
 
 #define VIR_TYPE_DOMAIN_CHECKPOINT vir_domain_checkpoint_get_type()
 G_DECLARE_FINAL_TYPE(virDomainCheckpoint,
@@ -71,6 +70,9 @@ G_DECLARE_FINAL_TYPE(virNWFilterBinding,
                      NW_FILTER_BINDING,
                      GObject);
 
+#define VIR_TYPE_STORAGE_POOL vir_storage_pool_get_type()
+G_DECLARE_FINAL_TYPE(virStoragePool, vir_storage_pool, VIR, STORAGE_POOL, GObject);
+
 extern virClassPtr virAdmConnectClass;
 
 #define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
@@ -191,8 +193,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 
 #define virCheckStoragePoolReturn(obj, retval) \
     do { \
-        virStoragePoolPtr _pool = (obj); \
-        if (!virObjectIsClass(_pool, virStoragePoolClass) || \
+        virStoragePoolPtr _pool = VIR_STORAGE_POOL(obj); \
+        if (_pool == NULL || \
             !virObjectIsClass(_pool->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STORAGE, \
                                  VIR_ERR_INVALID_STORAGE_POOL, \
@@ -205,8 +207,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 
 #define virCheckStoragePoolGoto(obj, label) \
     do { \
-        virStoragePoolPtr _pool= (obj); \
-        if (!virObjectIsClass(_pool, virStoragePoolClass) || \
+        virStoragePoolPtr _pool= VIR_STORAGE_POOL(obj); \
+        if (_pool == NULL || \
             !virObjectIsClass(_pool->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_STORAGE, \
                                  VIR_ERR_INVALID_STORAGE_POOL, \
@@ -683,7 +685,7 @@ struct _virInterface {
 * Internal structure associated to a storage pool
 */
 struct _virStoragePool {
-    virObject parent;
+    GObject parent;
     virConnectPtr conn;                  /* pointer back to the connection */
     char *name;                          /* the storage pool external name */
     unsigned char uuid[VIR_UUID_BUFLEN]; /* the storage pool unique identifier */
@@ -696,7 +698,6 @@ struct _virStoragePool {
     virFreeCallback privateDataFreeFunc;
 };
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virObjectUnref);
 
 
 /**
diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c
index 0406fe84d3..b88b2162de 100644
--- a/src/libvirt-storage.c
+++ b/src/libvirt-storage.c
@@ -846,7 +846,7 @@ virStoragePoolFree(virStoragePoolPtr pool)
 
     virCheckStoragePoolReturn(pool, -1);
 
-    virObjectUnref(pool);
+    g_object_unref(pool);
     return 0;
 
 }
@@ -872,13 +872,13 @@ virStoragePoolFree(virStoragePoolPtr pool)
 int
 virStoragePoolRef(virStoragePoolPtr pool)
 {
-    VIR_DEBUG("pool=%p refs=%d", pool, pool ? pool->parent.u.s.refs : 0);
+    VIR_DEBUG("pool=%p", pool);
 
     virResetLastError();
 
     virCheckStoragePoolReturn(pool, -1);
 
-    virObjectRef(pool);
+    g_object_ref(pool);
     return 0;
 }
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1549a85133..94009505bc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1353,6 +1353,7 @@ vir_network_get_type;
 vir_network_port_get_type;
 vir_nw_filter_binding_get_type;
 vir_nw_filter_get_type;
+vir_storage_pool_get_type;
 virConnectClass;
 virConnectCloseCallbackDataCall;
 virConnectCloseCallbackDataClass;
@@ -1377,7 +1378,6 @@ virGetStream;
 virNewConnectCloseCallbackData;
 virNodeDeviceClass;
 virSecretClass;
-virStoragePoolClass;
 virStorageVolClass;
 virStreamClass;
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index bc280e856a..de65c730f7 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -174,7 +174,7 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn,
                               unsigned long long capacity)
 {
     int ret = -1;
-    virStoragePoolPtr pool = NULL;
+    g_autoptr(virStoragePool) pool = NULL;
     virStorageVolPtr vol = NULL;
     char *volName = NULL, *basePath = NULL;
     char *volStr = NULL;
@@ -269,7 +269,6 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn,
     VIR_FREE(basePath);
     VIR_FREE(volStr);
     virObjectUnref(vol);
-    virObjectUnref(pool);
     return ret;
 }
 
diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index 2e4e1a65db..e7b2a5f363 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -6136,7 +6136,7 @@ remoteDispatchConnectStoragePoolEventRegisterAny(virNetServerPtr server G_GNUC_U
     daemonClientEventCallbackPtr ref;
     struct daemonClientPrivate *priv =
         virNetServerClientGetPrivateData(client);
-    virStoragePoolPtr  pool = NULL;
+    g_autoptr(virStoragePool)  pool = NULL;
     virConnectPtr conn = remoteGetStorageConn(client);
 
     virMutexLock(&priv->lock);
@@ -6194,7 +6194,6 @@ remoteDispatchConnectStoragePoolEventRegisterAny(virNetServerPtr server G_GNUC_U
     remoteEventCallbackFree(callback);
     if (rv < 0)
         virNetMessageSaveError(rerr);
-    virObjectUnref(pool);
     return rv;
 }
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 9373ba78b7..745033befb 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5477,7 +5477,7 @@ remoteStoragePoolBuildEventLifecycle(virNetClientProgramPtr prog G_GNUC_UNUSED,
     virConnectPtr conn = opaque;
     struct private_data *priv = conn->privateData;
     remote_storage_pool_event_lifecycle_msg *msg = evdata;
-    virStoragePoolPtr pool;
+    g_autoptr(virStoragePool) pool = NULL;
     virObjectEventPtr event = NULL;
 
     pool = get_nonnull_storage_pool(conn, msg->pool);
@@ -5486,7 +5486,6 @@ remoteStoragePoolBuildEventLifecycle(virNetClientProgramPtr prog G_GNUC_UNUSED,
 
     event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid, msg->event,
                                             msg->detail);
-    virObjectUnref(pool);
 
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
@@ -5499,7 +5498,7 @@ remoteStoragePoolBuildEventRefresh(virNetClientProgramPtr prog G_GNUC_UNUSED,
     virConnectPtr conn = opaque;
     struct private_data *priv = conn->privateData;
     remote_storage_pool_event_refresh_msg *msg = evdata;
-    virStoragePoolPtr pool;
+    g_autoptr(virStoragePool) pool = NULL;
     virObjectEventPtr event = NULL;
 
     pool = get_nonnull_storage_pool(conn, msg->pool);
@@ -5507,7 +5506,6 @@ remoteStoragePoolBuildEventRefresh(virNetClientProgramPtr prog G_GNUC_UNUSED,
         return;
 
     event = virStoragePoolEventRefreshNew(pool->name, pool->uuid);
-    virObjectUnref(pool);
 
     virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
 }
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 0f16ca89c2..8d19651367 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -203,6 +203,7 @@ my %gobject_impl = (
     virNetworkPort => 1,
     virNWFilter => 1,
     virNWFilterBinding => 1,
+    virStoragePool => 1,
 );
 
 sub use_gobject {
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 9cee6f1fde..ed3d5ee2c0 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -4081,7 +4081,7 @@ prlsdkCreateVm(vzDriverPtr driver, virDomainDefPtr def)
 static int
 virStorageTranslatePoolLocal(virConnectPtr conn, virStorageSourcePtr src)
 {
-    virStoragePoolPtr pool = NULL;
+    g_autoptr(virStoragePool) pool = NULL;
     virStorageVolPtr vol = NULL;
     virStorageVolInfo info;
     int ret = -1;
@@ -4115,7 +4115,6 @@ virStorageTranslatePoolLocal(virConnectPtr conn, virStorageSourcePtr src)
     ret = 0;
 
  cleanup:
-    virObjectUnref(pool);
     virObjectUnref(vol);
     return ret;
 }
-- 
2.25.3






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux