Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/node_device_event.c | 9 +++-----
src/conf/node_device_util.c | 4 ++--
src/conf/virnodedeviceobj.c | 10 ++++++--
src/datatypes.c | 44 ++++++++++++++++++++++--------------
src/datatypes.h | 14 +++++++-----
src/libvirt-nodedev.c | 6 ++---
src/libvirt_private.syms | 1 -
src/libxl/libxl_driver.c | 9 +++-----
src/qemu/qemu_driver.c | 9 +++-----
src/remote/remote_driver.c | 4 ++--
src/rpc/gendispatch.pl | 2 +-
src/test/test_driver.c | 2 +-
12 files changed, 61 insertions(+), 53 deletions(-)
diff --git a/src/conf/node_device_event.c b/src/conf/node_device_event.c
index c6915be593..cc2cdd9352 100644
--- a/src/conf/node_device_event.c
+++ b/src/conf/node_device_event.c
@@ -110,7 +110,7 @@ virNodeDeviceEventDispatchDefaultFunc(virConnectPtr conn,
virConnectObjectEventGenericCallback cb,
void *cbopaque)
{
- virNodeDevicePtr dev = virGetNodeDevice(conn,
+ g_autoptr(virNodeDevice) dev = virGetNodeDevice(conn,
event->meta.name);
if (!dev)
@@ -126,23 +126,20 @@ virNodeDeviceEventDispatchDefaultFunc(virConnectPtr conn,
nodeDeviceLifecycleEvent->type,
nodeDeviceLifecycleEvent->detail,
cbopaque);
- goto cleanup;
+ return;
}
case VIR_NODE_DEVICE_EVENT_ID_UPDATE:
{
((virConnectNodeDeviceEventGenericCallback)cb)(conn, dev,
cbopaque);
- goto cleanup;
+ return;
}
case VIR_NODE_DEVICE_EVENT_ID_LAST:
break;
}
VIR_WARN("Unexpected event ID %d", event->eventID);
-
- cleanup:
- virObjectUnref(dev);
}
diff --git a/src/conf/node_device_util.c b/src/conf/node_device_util.c
index 5e80422d7f..0b9292ffd3 100644
--- a/src/conf/node_device_util.c
+++ b/src/conf/node_device_util.c
@@ -20,6 +20,7 @@
#include "internal.h"
+#include "datatypes.h"
#include "node_device_util.h"
#include "virlog.h"
#include "virscsihost.h"
@@ -45,7 +46,7 @@ char *
virNodeDeviceGetParentName(virConnectPtr conn,
const char *nodedev_name)
{
- virNodeDevicePtr device = NULL;
+ g_autoptr(virNodeDevice) device = NULL;
char *parent;
if (!(device = virNodeDeviceLookupByName(conn, nodedev_name))) {
@@ -56,7 +57,6 @@ virNodeDeviceGetParentName(virConnectPtr conn,
}
parent = g_strdup(virNodeDeviceGetParent(device));
- virObjectUnref(device);
return parent;
}
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 3a34a324ca..5ee2db8b01 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -866,7 +866,6 @@ virNodeDeviceObjListExportCallback(void *payload,
virNodeDeviceObjMatch(obj, data->flags)) {
if (data->devices) {
if (!(device = virGetNodeDevice(data->conn, def->name))) {
- virObjectUnref(device);
data->error = true;
goto cleanup;
}
@@ -914,7 +913,14 @@ virNodeDeviceObjListExport(virConnectPtr conn,
return data.ndevices;
cleanup:
- virObjectListFree(data.devices);
+ if (data.devices) {
+ while (data.ndevices--) {
+ if (data.devices[data.ndevices])
+ g_object_unref(data.devices[data.ndevices]);
+ }
+ }
+ VIR_FREE(data.devices);
+
return -1;
}
diff --git a/src/datatypes.c b/src/datatypes.c
index 1f811e5f5e..43767b9fb5 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -36,14 +36,12 @@ VIR_LOG_INIT("datatypes");
virClassPtr virConnectClass;
virClassPtr virConnectCloseCallbackDataClass;
virClassPtr virDomainClass;
-virClassPtr virNodeDeviceClass;
virClassPtr virSecretClass;
virClassPtr virStreamClass;
static void virConnectDispose(void *obj);
static void virConnectCloseCallbackDataDispose(void *obj);
static void virDomainDispose(void *obj);
-static void virNodeDeviceDispose(void *obj);
static void virSecretDispose(void *obj);
static void virStreamDispose(void *obj);
@@ -127,6 +125,22 @@ vir_network_port_class_init(virNetworkPortClass *klass)
obj->finalize = virNetworkPortFinalize;
}
+G_DEFINE_TYPE(virNodeDevice, vir_node_device, G_TYPE_OBJECT);
+static void virNodeDeviceFinalize(GObject *obj);
+
+static void
+vir_node_device_init(virNodeDevice *dev G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_node_device_class_init(virNodeDeviceClass *klass)
+{
+ GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+ obj->finalize = virNodeDeviceFinalize;
+}
+
G_DEFINE_TYPE(virNWFilter, vir_nw_filter, G_TYPE_OBJECT);
static void virNWFilterFinalize(GObject *obj);
@@ -243,7 +257,6 @@ virDataTypesOnceInit(void)
DECLARE_CLASS_LOCKABLE(virConnect);
DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
DECLARE_CLASS(virDomain);
- DECLARE_CLASS(virNodeDevice);
DECLARE_CLASS(virSecret);
DECLARE_CLASS(virStream);
@@ -794,37 +807,32 @@ virStorageVolFinalize(GObject *obj)
* @name: device name (unique on node)
*
* Allocates a new node device 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 node device object, or NULL on error.
*/
virNodeDevicePtr
virGetNodeDevice(virConnectPtr conn, const char *name)
{
- virNodeDevicePtr ret = NULL;
+ g_autoptr(virNodeDevice) ret = NULL;
if (virDataTypesInitialize() < 0)
return NULL;
- virCheckConnectGoto(conn, error);
- virCheckNonNullArgGoto(name, error);
+ virCheckConnectReturn(conn, NULL);
+ virCheckNonNullArgReturn(name, NULL);
- if (!(ret = virObjectNew(virNodeDeviceClass)))
- goto error;
+ ret = VIR_NODE_DEVICE(g_object_new(VIR_TYPE_NODE_DEVICE, NULL));
ret->name = g_strdup(name);
ret->conn = virObjectRef(conn);
- return ret;
-
- error:
- virObjectUnref(ret);
- return NULL;
+ return g_steal_pointer(&ret);
}
/**
- * virNodeDeviceDispose:
+ * virNodeDeviceFinalize:
* @obj: the node device to release
*
* Unconditionally release all memory associated with a device.
@@ -834,15 +842,17 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
* which may also be released if its ref count hits zero.
*/
static void
-virNodeDeviceDispose(void *obj)
+virNodeDeviceFinalize(GObject *obj)
{
- virNodeDevicePtr dev = obj;
+ virNodeDevicePtr dev = VIR_NODE_DEVICE(obj);
VIR_DEBUG("release dev %p %s", dev, dev->name);
VIR_FREE(dev->name);
VIR_FREE(dev->parentName);
virObjectUnref(dev->conn);
+
+ G_OBJECT_CLASS(vir_node_device_parent_class)->finalize(obj);
}
diff --git a/src/datatypes.h b/src/datatypes.h
index 7fab565a7c..3b9a31920b 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -32,7 +32,6 @@
extern virClassPtr virConnectClass;
extern virClassPtr virDomainClass;
-extern virClassPtr virNodeDeviceClass;
extern virClassPtr virSecretClass;
extern virClassPtr virStreamClass;
@@ -60,6 +59,9 @@ G_DECLARE_FINAL_TYPE(virNetwork, vir_network, VIR, NETWORK, GObject);
#define VIR_TYPE_NETWORK_PORT vir_network_port_get_type()
G_DECLARE_FINAL_TYPE(virNetworkPort, vir_network_port, VIR, NETWORK_PORT, GObject);
+#define VIR_TYPE_NODE_DEVICE vir_node_device_get_type()
+G_DECLARE_FINAL_TYPE(virNodeDevice, vir_node_device, VIR, NODE_DEVICE, GObject);
+
#define VIR_TYPE_NW_FILTER vir_nw_filter_get_type()
G_DECLARE_FINAL_TYPE(virNWFilter, vir_nw_filter, VIR, NW_FILTER, GObject);
@@ -249,8 +251,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
#define virCheckNodeDeviceReturn(obj, retval) \
do { \
- virNodeDevicePtr _node = (obj); \
- if (!virObjectIsClass(_node, virNodeDeviceClass) || \
+ virNodeDevicePtr _node = VIR_NODE_DEVICE(obj); \
+ if (!G_IS_OBJECT(_node) || !(G_OBJECT_TYPE(_node) == VIR_TYPE_NODE_DEVICE) || \
!virObjectIsClass(_node->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_NODEDEV, \
VIR_ERR_INVALID_NODE_DEVICE, \
@@ -263,8 +265,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT,
GObject);
#define virCheckNodeDeviceGoto(obj, label) \
do { \
- virNodeDevicePtr _dev= (obj); \
- if (!virObjectIsClass(_dev, virNodeDeviceClass) || \
+ virNodeDevicePtr _dev= VIR_NODE_DEVICE(obj); \
+ if (!G_IS_OBJECT(_dev) || !(G_OBJECT_TYPE(_dev) == VIR_TYPE_NODE_DEVICE) || \
!virObjectIsClass(_dev->conn, virConnectClass)) { \
virReportErrorHelper(VIR_FROM_NODEDEV, \
VIR_ERR_INVALID_NODE_DEVICE, \
@@ -731,7 +733,7 @@ struct _virStorageVol {
* Internal structure associated with a node device
*/
struct _virNodeDevice {
- virObject parent;
+ GObject parent;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* device name (unique on node) */
char *parentName; /* parent device name */
diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c
index dce46b7181..98db5e9813 100644
--- a/src/libvirt-nodedev.c
+++ b/src/libvirt-nodedev.c
@@ -452,7 +452,7 @@ virNodeDeviceFree(virNodeDevicePtr dev)
virCheckNodeDeviceReturn(dev, -1);
- virObjectUnref(dev);
+ g_object_unref(dev);
return 0;
}
@@ -477,13 +477,13 @@ virNodeDeviceFree(virNodeDevicePtr dev)
int
virNodeDeviceRef(virNodeDevicePtr dev)
{
- VIR_DEBUG("dev=%p refs=%d", dev, dev ? dev->parent.u.s.refs : 0);
+ VIR_DEBUG("dev=%p", dev);
virResetLastError();
virCheckNodeDeviceReturn(dev, -1);
- virObjectRef(dev);
+ g_object_ref(dev);
return 0;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7bee97f2dc..f2187b7cce 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1365,7 +1365,6 @@ virGetStoragePool;
virGetStorageVol;
virGetStream;
virNewConnectCloseCallbackData;
-virNodeDeviceClass;
virSecretClass;
virStreamClass;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 6564b45ee4..bd43f3310e 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5788,7 +5788,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
libxlDriverPrivatePtr driver = dev->conn->privateData;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virConnectPtr nodeconn = NULL;
- virNodeDevicePtr nodedev = NULL;
+ g_autoptr(virNodeDevice) nodedev = NULL;
virCheckFlags(0, -1);
@@ -5838,7 +5838,6 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
cleanup:
virPCIDeviceFree(pci);
virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
virObjectUnref(nodeconn);
VIR_FREE(xml);
return ret;
@@ -5861,7 +5860,7 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
libxlDriverPrivatePtr driver = dev->conn->privateData;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virConnectPtr nodeconn = NULL;
- virNodeDevicePtr nodedev = NULL;
+ g_autoptr(virNodeDevice) nodedev = NULL;
if (!(nodeconn = virGetConnectNodeDev()))
goto cleanup;
@@ -5902,7 +5901,6 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
cleanup:
virPCIDeviceFree(pci);
virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
virObjectUnref(nodeconn);
VIR_FREE(xml);
return ret;
@@ -5919,7 +5917,7 @@ libxlNodeDeviceReset(virNodeDevicePtr dev)
libxlDriverPrivatePtr driver = dev->conn->privateData;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virConnectPtr nodeconn = NULL;
- virNodeDevicePtr nodedev = NULL;
+ g_autoptr(virNodeDevice) nodedev = NULL;
if (!(nodeconn = virGetConnectNodeDev()))
goto cleanup;
@@ -5960,7 +5958,6 @@ libxlNodeDeviceReset(virNodeDevicePtr dev)
cleanup:
virPCIDeviceFree(pci);
virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
virObjectUnref(nodeconn);
VIR_FREE(xml);
return ret;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 864158fd9d..bc28f65a3a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12963,7 +12963,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virConnectPtr nodeconn = NULL;
- virNodeDevicePtr nodedev = NULL;
+ g_autoptr(virNodeDevice) nodedev = NULL;
virCheckFlags(0, -1);
@@ -13024,7 +13024,6 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
cleanup:
virPCIDeviceFree(pci);
virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
virObjectUnref(nodeconn);
return ret;
}
@@ -13046,7 +13045,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
g_autofree char *xml = NULL;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virConnectPtr nodeconn = NULL;
- virNodeDevicePtr nodedev = NULL;
+ g_autoptr(virNodeDevice) nodedev = NULL;
if (!(nodeconn = virGetConnectNodeDev()))
goto cleanup;
@@ -13084,7 +13083,6 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
virPCIDeviceFree(pci);
cleanup:
virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
virObjectUnref(nodeconn);
return ret;
}
@@ -13100,7 +13098,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
g_autofree char *xml = NULL;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
virConnectPtr nodeconn = NULL;
- virNodeDevicePtr nodedev = NULL;
+ g_autoptr(virNodeDevice) nodedev = NULL;
if (!(nodeconn = virGetConnectNodeDev()))
goto cleanup;
@@ -13138,7 +13136,6 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
virPCIDeviceFree(pci);
cleanup:
virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
virObjectUnref(nodeconn);
return ret;
}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index f5d7842104..a3f05563d4 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5536,7 +5536,7 @@ remoteNodeDeviceBuildEventLifecycle(virNetClientProgramPtr prog
G_GNUC_UNUSED,
event = virNodeDeviceEventLifecycleNew(dev->name, msg->event,
msg->detail);
- virObjectUnref(dev);
+ g_object_unref(dev);
virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
}
@@ -5557,7 +5557,7 @@ remoteNodeDeviceBuildEventUpdate(virNetClientProgramPtr prog
G_GNUC_UNUSED,
return;
event = virNodeDeviceEventUpdateNew(dev->name);
- virObjectUnref(dev);
+ g_object_unref(dev);
virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackID);
}
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 0b2ae59910..3187a0b798 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -575,7 +575,7 @@ elsif ($mode eq "server") {
" goto cleanup;\n");
push(@args_list, "dev");
push(@free_list,
- " virObjectUnref(dev);");
+ " g_object_unref(dev);");
}
foreach my $args_member (@{$call->{args_members}}) {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 1696b956fe..5195ccbb61 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -7496,7 +7496,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
cleanup:
virNodeDeviceObjEndAPI(&obj);
virNodeDeviceDefFree(def);
- virObjectUnref(dev);
+ g_object_unref(dev);
return ret;
}
--
2.25.1