1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

util: remove virObjectUnref() adapters

These wrapper functions were used to adapt the virObjectUnref() function
signature for different callbacks. But in commit 0d184072, the
virObjectUnref() function was changed to return a void instead of a
bool, so these adapters are no longer necessary.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Jonathon Jongsma 2022-07-13 15:26:51 -05:00
parent d531b9c724
commit 62ca300530
28 changed files with 43 additions and 81 deletions

View File

@ -165,7 +165,7 @@ remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
virObjectRef(conn->closeCallback); virObjectRef(conn->closeCallback);
virNetClientSetCloseCallback(priv->client, remoteAdminClientCloseFunc, virNetClientSetCloseCallback(priv->client, remoteAdminClientCloseFunc,
conn->closeCallback, conn->closeCallback,
virObjectFreeCallback); virObjectUnref);
if (call(conn, 0, ADMIN_PROC_CONNECT_OPEN, if (call(conn, 0, ADMIN_PROC_CONNECT_OPEN,
(xdrproc_t)xdr_admin_connect_open_args, (char *)&args, (xdrproc_t)xdr_admin_connect_open_args, (char *)&args,
@ -195,7 +195,7 @@ remoteAdminConnectClose(virAdmConnectPtr conn)
} }
virNetClientSetCloseCallback(priv->client, NULL, conn->closeCallback, virNetClientSetCloseCallback(priv->client, NULL, conn->closeCallback,
virObjectFreeCallback); virObjectUnref);
virNetClientClose(priv->client); virNetClientClose(priv->client);
rv = 0; rv = 0;

View File

@ -82,7 +82,7 @@ bhyveMonitorRegister(bhyveMonitor *mon)
VIR_EVENT_HANDLE_HANGUP, VIR_EVENT_HANDLE_HANGUP,
bhyveMonitorIO, bhyveMonitorIO,
mon, mon,
virObjectFreeCallback); virObjectUnref);
if (mon->watch < 0) { if (mon->watch < 0) {
VIR_DEBUG("failed to add event handle for mon %p", mon); VIR_DEBUG("failed to add event handle for mon %p", mon);
virObjectUnref(mon); virObjectUnref(mon);

View File

@ -876,7 +876,7 @@ virObjectEventStateRegisterID(virConnectPtr conn,
if ((state->timer = virEventAddTimeout(-1, if ((state->timer = virEventAddTimeout(-1,
virObjectEventTimer, virObjectEventTimer,
state, state,
virObjectFreeCallback)) < 0) { virObjectUnref)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("could not initialize domain event timer")); _("could not initialize domain event timer"));
goto cleanup; goto cleanup;

View File

@ -73,8 +73,8 @@ virDomainObjList *virDomainObjListNew(void)
if (!(doms = virObjectRWLockableNew(virDomainObjListClass))) if (!(doms = virObjectRWLockableNew(virDomainObjListClass)))
return NULL; return NULL;
doms->objs = virHashNew(virObjectFreeHashData); doms->objs = virHashNew(virObjectUnref);
doms->objsName = virHashNew(virObjectFreeHashData); doms->objsName = virHashNew(virObjectUnref);
return doms; return doms;
} }
@ -217,7 +217,7 @@ virDomainObjListFindByName(virDomainObjList *doms,
* tables. Once successfully added into a table, increase the * tables. Once successfully added into a table, increase the
* reference count since upon removal in virHashRemoveEntry * reference count since upon removal in virHashRemoveEntry
* the virObjectUnref will be called since the hash tables were * the virObjectUnref will be called since the hash tables were
* configured to call virObjectFreeHashData when the object is * configured to call virObjectUnref when the object is
* removed from the hash table. * removed from the hash table.
* *
* Returns 0 on success with 3 references and locked * Returns 0 on success with 3 references and locked
@ -453,7 +453,7 @@ virDomainObjListRename(virDomainObjList *doms,
/* Increment the refcnt for @new_name. We're about to remove /* Increment the refcnt for @new_name. We're about to remove
* the @old_name which will cause the refcnt to be decremented * the @old_name which will cause the refcnt to be decremented
* via the virObjectUnref call made during the virObjectFreeHashData * via the virObjectUnref call made during the virObjectUnref
* as a result of removing something from the object list hash * as a result of removing something from the object list hash
* table as set up during virDomainObjListNew. */ * table as set up during virDomainObjListNew. */
virObjectRef(dom); virObjectRef(dom);

View File

@ -140,7 +140,7 @@ virInterfaceObjListNew(void)
if (!(interfaces = virObjectRWLockableNew(virInterfaceObjListClass))) if (!(interfaces = virObjectRWLockableNew(virInterfaceObjListClass)))
return NULL; return NULL;
interfaces->objsName = virHashNew(virObjectFreeHashData); interfaces->objsName = virHashNew(virObjectUnref);
return interfaces; return interfaces;
} }

View File

@ -326,7 +326,7 @@ virNetworkObjListNew(void)
if (!(nets = virObjectRWLockableNew(virNetworkObjListClass))) if (!(nets = virObjectRWLockableNew(virNetworkObjListClass)))
return NULL; return NULL;
nets->objs = virHashNew(virObjectFreeHashData); nets->objs = virHashNew(virObjectUnref);
return nets; return nets;
} }

View File

@ -465,7 +465,7 @@ virNodeDeviceObjListNew(void)
if (!(devs = virObjectRWLockableNew(virNodeDeviceObjListClass))) if (!(devs = virObjectRWLockableNew(virNodeDeviceObjListClass)))
return NULL; return NULL;
devs->objs = virHashNew(virObjectFreeHashData); devs->objs = virHashNew(virObjectUnref);
return devs; return devs;
} }

View File

@ -66,7 +66,7 @@ virNWFilterBindingObjListNew(void)
if (!(bindings = virObjectRWLockableNew(virNWFilterBindingObjListClass))) if (!(bindings = virObjectRWLockableNew(virNWFilterBindingObjListClass)))
return NULL; return NULL;
bindings->objs = virHashNew(virObjectFreeHashData); bindings->objs = virHashNew(virObjectUnref);
return bindings; return bindings;
} }
@ -131,7 +131,7 @@ virNWFilterBindingObjListFindByPortDev(virNWFilterBindingObjList *bindings,
* tables. Once successfully added into a table, increase the * tables. Once successfully added into a table, increase the
* reference count since upon removal in virHashRemoveEntry * reference count since upon removal in virHashRemoveEntry
* the virObjectUnref will be called since the hash tables were * the virObjectUnref will be called since the hash tables were
* configured to call virObjectFreeHashData when the object is * configured to call virObjectUnref when the object is
* removed from the hash table. * removed from the hash table.
* *
* Returns 0 on success with 2 references and locked * Returns 0 on success with 2 references and locked

View File

@ -118,7 +118,7 @@ virSecretObjListNew(void)
if (!(secrets = virObjectRWLockableNew(virSecretObjListClass))) if (!(secrets = virObjectRWLockableNew(virSecretObjListClass)))
return NULL; return NULL;
if (!(secrets->objs = virHashNew(virObjectFreeHashData))) { if (!(secrets->objs = virHashNew(virObjectUnref))) {
virObjectUnref(secrets); virObjectUnref(secrets);
return NULL; return NULL;
} }

View File

@ -151,9 +151,9 @@ virStorageVolObjListNew(void)
if (!(vols = virObjectRWLockableNew(virStorageVolObjListClass))) if (!(vols = virObjectRWLockableNew(virStorageVolObjListClass)))
return NULL; return NULL;
vols->objsKey = virHashNew(virObjectFreeHashData); vols->objsKey = virHashNew(virObjectUnref);
vols->objsName = virHashNew(virObjectFreeHashData); vols->objsName = virHashNew(virObjectUnref);
vols->objsPath = virHashNew(virObjectFreeHashData); vols->objsPath = virHashNew(virObjectUnref);
return vols; return vols;
} }
@ -378,8 +378,8 @@ virStoragePoolObjListNew(void)
if (!(pools = virObjectRWLockableNew(virStoragePoolObjListClass))) if (!(pools = virObjectRWLockableNew(virStoragePoolObjListClass)))
return NULL; return NULL;
pools->objs = virHashNew(virObjectFreeHashData); pools->objs = virHashNew(virObjectUnref);
pools->objsName = virHashNew(virObjectFreeHashData); pools->objsName = virHashNew(virObjectUnref);
return pools; return pools;
} }

View File

@ -2978,8 +2978,6 @@ virClassForObjectRWLockable;
virClassIsDerivedFrom; virClassIsDerivedFrom;
virClassName; virClassName;
virClassNew; virClassNew;
virObjectFreeCallback;
virObjectFreeHashData;
virObjectIsClass; virObjectIsClass;
virObjectListFree; virObjectListFree;
virObjectListFreeCount; virObjectListFreeCount;

View File

@ -1764,7 +1764,7 @@ qemuDomainObjPrivateAlloc(void *opaque)
if (!(priv->devs = virChrdevAlloc())) if (!(priv->devs = virChrdevAlloc()))
return NULL; return NULL;
priv->blockjobs = virHashNew(virObjectFreeHashData); priv->blockjobs = virHashNew(virObjectUnref);
/* agent commands block by default, user can choose different behavior */ /* agent commands block by default, user can choose different behavior */
priv->agentTimeout = VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK; priv->agentTimeout = VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK;

View File

@ -440,7 +440,7 @@ int daemonAddClientStream(virNetServerClient *client,
if (virStreamEventAddCallback(stream->st, 0, if (virStreamEventAddCallback(stream->st, 0,
daemonStreamEvent, client, daemonStreamEvent, client,
virObjectFreeCallback) < 0) virObjectUnref) < 0)
return -1; return -1;
virObjectRef(client); virObjectRef(client);

View File

@ -1096,7 +1096,7 @@ doRemoteOpen(virConnectPtr conn,
virObjectRef(priv->closeCallback); virObjectRef(priv->closeCallback);
virNetClientSetCloseCallback(priv->client, virNetClientSetCloseCallback(priv->client,
remoteClientCloseFunc, remoteClientCloseFunc,
priv->closeCallback, virObjectFreeCallback); priv->closeCallback, virObjectUnref);
if (!(priv->remoteProgram = virNetClientProgramNew(REMOTE_PROGRAM, if (!(priv->remoteProgram = virNetClientProgramNew(REMOTE_PROGRAM,
REMOTE_PROTOCOL_VERSION, REMOTE_PROTOCOL_VERSION,
@ -1301,7 +1301,7 @@ doRemoteClose(virConnectPtr conn, struct private_data *priv)
virNetClientSetCloseCallback(priv->client, virNetClientSetCloseCallback(priv->client,
NULL, NULL,
priv->closeCallback, virObjectFreeCallback); priv->closeCallback, virObjectUnref);
virNetClientClose(priv->client); virNetClientClose(priv->client);
g_clear_pointer(&priv->client, virObjectUnref); g_clear_pointer(&priv->client, virObjectUnref);
@ -6142,7 +6142,7 @@ remoteDomainMigratePrepareTunnel3(virConnectPtr dconn,
st->driver = &remoteStreamDrv; st->driver = &remoteStreamDrv;
st->privateData = netst; st->privateData = netst;
st->ff = virObjectFreeCallback; st->ff = virObjectUnref;
args.cookie_in.cookie_in_val = (char *)cookiein; args.cookie_in.cookie_in_val = (char *)cookiein;
args.cookie_in.cookie_in_len = cookieinlen; args.cookie_in.cookie_in_len = cookieinlen;
@ -7082,7 +7082,7 @@ remoteDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
st->driver = &remoteStreamDrv; st->driver = &remoteStreamDrv;
st->privateData = netst; st->privateData = netst;
st->ff = virObjectFreeCallback; st->ff = virObjectUnref;
if (call(dconn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL3_PARAMS, if (call(dconn, priv, 0, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL3_PARAMS,
(xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_params_args, (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_params_args,

View File

@ -1837,7 +1837,7 @@ elsif ($mode eq "client") {
print "\n"; print "\n";
print " st->driver = &remoteStreamDrv;\n"; print " st->driver = &remoteStreamDrv;\n";
print " st->privateData = netst;\n"; print " st->privateData = netst;\n";
print " st->ff = virObjectFreeCallback;\n"; print " st->ff = virObjectUnref;\n";
} }
if ($call->{ProcName} eq "SupportsFeature") { if ($call->{ProcName} eq "SupportsFeature") {

View File

@ -275,7 +275,7 @@ virKeepAliveStart(virKeepAlive *ka,
timeout = ka->interval - delay; timeout = ka->interval - delay;
ka->intervalStart = now - (ka->interval - timeout); ka->intervalStart = now - (ka->interval - timeout);
ka->timer = virEventAddTimeout(timeout * 1000, virKeepAliveTimer, ka->timer = virEventAddTimeout(timeout * 1000, virKeepAliveTimer,
ka, virObjectFreeCallback); ka, virObjectUnref);
if (ka->timer < 0) if (ka->timer < 0)
goto cleanup; goto cleanup;

View File

@ -658,7 +658,7 @@ int virNetClientRegisterAsyncIO(virNetClient *client)
VIR_EVENT_HANDLE_READABLE, VIR_EVENT_HANDLE_READABLE,
virNetClientIncomingEvent, virNetClientIncomingEvent,
client, client,
virObjectFreeCallback) < 0) { virObjectUnref) < 0) {
virObjectUnref(client); virObjectUnref(client);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to register async IO callback")); _("Unable to register async IO callback"));
@ -688,7 +688,7 @@ int virNetClientRegisterKeepAlive(virNetClient *client)
if (!(ka = virKeepAliveNew(-1, 0, client, if (!(ka = virKeepAliveNew(-1, 0, client,
virNetClientKeepAliveSendCB, virNetClientKeepAliveSendCB,
virNetClientKeepAliveDeadCB, virNetClientKeepAliveDeadCB,
virObjectFreeCallback))) virObjectUnref)))
return -1; return -1;
/* keepalive object has a reference to client */ /* keepalive object has a reference to client */

View File

@ -727,7 +727,7 @@ int virNetClientStreamEventAddCallback(virNetClientStream *st,
virEventAddTimeout(-1, virEventAddTimeout(-1,
virNetClientStreamEventTimer, virNetClientStreamEventTimer,
st, st,
virObjectFreeCallback)) < 0) { virObjectUnref)) < 0) {
virObjectUnref(st); virObjectUnref(st);
goto cleanup; goto cleanup;
} }

View File

@ -142,7 +142,7 @@ virNetDaemonNew(void)
if (!(dmn = virObjectLockableNew(virNetDaemonClass))) if (!(dmn = virObjectLockableNew(virNetDaemonClass)))
return NULL; return NULL;
dmn->servers = virHashNew(virObjectFreeHashData); dmn->servers = virHashNew(virObjectUnref);
#ifndef WIN32 #ifndef WIN32
dmn->sigwrite = dmn->sigread = -1; dmn->sigwrite = dmn->sigread = -1;

View File

@ -202,7 +202,7 @@ static int virNetServerClientRegisterEvent(virNetServerClient *client)
mode, mode,
virNetServerClientDispatchEvent, virNetServerClientDispatchEvent,
client, client,
virObjectFreeCallback) < 0) { virObjectUnref) < 0) {
virObjectUnref(client); virObjectUnref(client);
return -1; return -1;
} }
@ -1521,7 +1521,7 @@ virNetServerClientInitKeepAlive(virNetServerClient *client,
if (!(ka = virKeepAliveNew(interval, count, client, if (!(ka = virKeepAliveNew(interval, count, client,
virNetServerClientKeepAliveSendCB, virNetServerClientKeepAliveSendCB,
virNetServerClientKeepAliveDeadCB, virNetServerClientKeepAliveDeadCB,
virObjectFreeCallback))) virObjectUnref)))
return -1; return -1;
/* keepalive object has a reference to client */ /* keepalive object has a reference to client */

View File

@ -152,7 +152,7 @@ virNetServerServiceNewSocket(virNetSocket **socks,
virObjectRef(svc); virObjectRef(svc);
svc->timer = virEventAddTimeout(-1, virNetServerServiceTimerFunc, svc->timer = virEventAddTimeout(-1, virNetServerServiceTimerFunc,
svc, virObjectFreeCallback); svc, virObjectUnref);
if (svc->timer < 0) { if (svc->timer < 0) {
virObjectUnref(svc); virObjectUnref(svc);
goto error; goto error;
@ -169,7 +169,7 @@ virNetServerServiceNewSocket(virNetSocket **socks,
0, 0,
virNetServerServiceAccept, virNetServerServiceAccept,
svc, svc,
virObjectFreeCallback) < 0) { virObjectUnref) < 0) {
virObjectUnref(svc); virObjectUnref(svc);
goto error; goto error;
} }
@ -361,7 +361,7 @@ virNetServerService *virNetServerServiceNewPostExecRestart(virJSONValue *object)
0, 0,
virNetServerServiceAccept, virNetServerServiceAccept,
svc, svc,
virObjectFreeCallback) < 0) { virObjectUnref) < 0) {
virObjectUnref(svc); virObjectUnref(svc);
goto error; goto error;
} }

View File

@ -239,7 +239,7 @@ virFileCacheNew(const char *dir,
if (!(cache = virObjectNew(virFileCacheClass))) if (!(cache = virObjectNew(virFileCacheClass)))
return NULL; return NULL;
cache->table = virHashNew(virObjectFreeHashData); cache->table = virHashNew(virObjectUnref);
cache->dir = g_strdup(dir); cache->dir = g_strdup(dir);

View File

@ -598,36 +598,6 @@ virClassName(virClass *klass)
} }
/**
* virObjectFreeCallback:
* @opaque: a pointer to a virObject instance
*
* Provides identical functionality to virObjectUnref,
* but with the signature matching the virFreeCallback
* typedef.
*/
void virObjectFreeCallback(void *opaque)
{
virObjectUnref(opaque);
}
/**
* virObjectFreeHashData:
* @opaque: a pointer to a virObject instance
* @name: ignored, name of the hash key being deleted
*
* Provides identical functionality to virObjectUnref,
* but with the signature matching the GDestroyNotify
* typedef used with hash tables.
*/
void
virObjectFreeHashData(void *opaque)
{
virObjectUnref(opaque);
}
/** /**
* virObjectListFree: * virObjectListFree:
* @list: A pointer to a NULL-terminated list of object pointers to free * @list: A pointer to a NULL-terminated list of object pointers to free

View File

@ -104,12 +104,6 @@ virObjectIsClass(void *obj,
virClass *klass) virClass *klass)
ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(2);
void
virObjectFreeCallback(void *opaque);
void
virObjectFreeHashData(void *opaque);
void * void *
virObjectLockableNew(virClass *klass) virObjectLockableNew(virClass *klass)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);

View File

@ -78,7 +78,7 @@ mymain(void)
int ret = 0; int ret = 0;
g_autofree char *fakerootdir = NULL; g_autofree char *fakerootdir = NULL;
g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps(); g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData); g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
g_autoptr(virConnect) conn = NULL; g_autoptr(virConnect) conn = NULL;
struct testQemuConf testConf = { .capslatest = capslatest, struct testQemuConf testConf = { .capslatest = capslatest,
.capscache = capscache, .capscache = capscache,

View File

@ -835,7 +835,7 @@ mymain(void)
g_autofree char *fakerootdir = NULL; g_autofree char *fakerootdir = NULL;
g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps(); g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) g_hash_table_unref); g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) g_hash_table_unref);
g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData); g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
struct testQemuConf testConf = { .capslatest = capslatest, struct testQemuConf testConf = { .capslatest = capslatest,
.capscache = capscache, .capscache = capscache,
.qapiSchemaCache = qapiSchemaCache }; .qapiSchemaCache = qapiSchemaCache };

View File

@ -122,7 +122,7 @@ mymain(void)
g_autofree char *fakerootdir = NULL; g_autofree char *fakerootdir = NULL;
g_autoptr(virQEMUDriverConfig) cfg = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL;
g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps(); g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData); g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
g_autoptr(virConnect) conn = NULL; g_autoptr(virConnect) conn = NULL;
struct testQemuConf testConf = { .capslatest = capslatest, struct testQemuConf testConf = { .capslatest = capslatest,
.capscache = capscache, .capscache = capscache,

View File

@ -451,7 +451,7 @@ virshRunConsole(vshControl *ctl,
VIR_EVENT_HANDLE_READABLE, VIR_EVENT_HANDLE_READABLE,
virConsoleEventOnStdin, virConsoleEventOnStdin,
con, con,
virObjectFreeCallback)) < 0) { virObjectUnref)) < 0) {
virObjectUnref(con); virObjectUnref(con);
goto cleanup; goto cleanup;
} }
@ -461,7 +461,7 @@ virshRunConsole(vshControl *ctl,
0, 0,
virConsoleEventOnStdout, virConsoleEventOnStdout,
con, con,
virObjectFreeCallback)) < 0) { virObjectUnref)) < 0) {
virObjectUnref(con); virObjectUnref(con);
goto cleanup; goto cleanup;
} }
@ -471,7 +471,7 @@ virshRunConsole(vshControl *ctl,
VIR_STREAM_EVENT_READABLE, VIR_STREAM_EVENT_READABLE,
virConsoleEventOnStream, virConsoleEventOnStream,
con, con,
virObjectFreeCallback) < 0) { virObjectUnref) < 0) {
virObjectUnref(con); virObjectUnref(con);
goto cleanup; goto cleanup;
} }