mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-29 00:55:22 +00:00
Convert virLXCMonitor to use virObject
Remove custom reference counting from virLXCMonitor, using
virObject instead
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 09e0cb4218
)
This commit is contained in:
parent
a05d4ca932
commit
df2b4be5cb
@ -35,9 +35,9 @@
|
|||||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
struct _virLXCMonitor {
|
struct _virLXCMonitor {
|
||||||
int refs;
|
virObject parent;
|
||||||
|
|
||||||
virMutex lock; /* also used to protect refs */
|
virMutex lock;
|
||||||
|
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virLXCMonitorCallbacksPtr cb;
|
virLXCMonitorCallbacksPtr cb;
|
||||||
@ -46,7 +46,21 @@ struct _virLXCMonitor {
|
|||||||
virNetClientProgramPtr program;
|
virNetClientProgramPtr program;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void virLXCMonitorFree(virLXCMonitorPtr mon);
|
static virClassPtr virLXCMonitorClass;
|
||||||
|
static void virLXCMonitorDispose(void *obj);
|
||||||
|
|
||||||
|
static int virLXCMonitorOnceInit(void)
|
||||||
|
{
|
||||||
|
if (!(virLXCMonitorClass = virClassNew("virLXCMonitor",
|
||||||
|
sizeof(virLXCMonitor),
|
||||||
|
virLXCMonitorDispose)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIR_ONCE_GLOBAL_INIT(virLXCMonitor)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virLXCMonitorHandleEventExit(virNetClientProgramPtr prog,
|
virLXCMonitorHandleEventExit(virNetClientProgramPtr prog,
|
||||||
virNetClientPtr client,
|
virNetClientPtr client,
|
||||||
@ -95,9 +109,7 @@ static void virLXCMonitorEOFNotify(virNetClientPtr client ATTRIBUTE_UNUSED,
|
|||||||
static void virLXCMonitorCloseFreeCallback(void *opaque)
|
static void virLXCMonitorCloseFreeCallback(void *opaque)
|
||||||
{
|
{
|
||||||
virLXCMonitorPtr mon = opaque;
|
virLXCMonitorPtr mon = opaque;
|
||||||
virLXCMonitorLock(mon);
|
virObjectUnref(mon);;
|
||||||
if (virLXCMonitorUnref(mon) > 0)
|
|
||||||
virLXCMonitorUnlock(mon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,12 +120,11 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm,
|
|||||||
virLXCMonitorPtr mon;
|
virLXCMonitorPtr mon;
|
||||||
char *sockpath = NULL;
|
char *sockpath = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(mon) < 0) {
|
if (virLXCMonitorInitialize() < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
mon->refs = 1;
|
if (!(mon = virObjectNew(virLXCMonitorClass)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (virMutexInit(&mon->lock) < 0) {
|
if (virMutexInit(&mon->lock) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -146,7 +157,7 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm,
|
|||||||
mon->vm = vm;
|
mon->vm = vm;
|
||||||
mon->cb = cb;
|
mon->cb = cb;
|
||||||
|
|
||||||
virLXCMonitorRef(mon);
|
virObjectRef(mon);
|
||||||
virNetClientSetCloseCallback(mon->client, virLXCMonitorEOFNotify, mon,
|
virNetClientSetCloseCallback(mon->client, virLXCMonitorEOFNotify, mon,
|
||||||
virLXCMonitorCloseFreeCallback);
|
virLXCMonitorCloseFreeCallback);
|
||||||
|
|
||||||
@ -157,43 +168,21 @@ cleanup:
|
|||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
error:
|
error:
|
||||||
virLXCMonitorFree(mon);
|
virObjectUnref(mon);
|
||||||
mon = NULL;
|
mon = NULL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void virLXCMonitorFree(virLXCMonitorPtr mon)
|
static void virLXCMonitorDispose(void *opaque)
|
||||||
{
|
{
|
||||||
VIR_DEBUG("mon=%p", mon);
|
virLXCMonitorPtr mon = opaque;
|
||||||
if (mon->client)
|
|
||||||
virLXCMonitorClose(mon);
|
|
||||||
|
|
||||||
|
VIR_DEBUG("mon=%p", mon);
|
||||||
if (mon->cb && mon->cb->destroy)
|
if (mon->cb && mon->cb->destroy)
|
||||||
(mon->cb->destroy)(mon, mon->vm);
|
(mon->cb->destroy)(mon, mon->vm);
|
||||||
virMutexDestroy(&mon->lock);
|
virMutexDestroy(&mon->lock);
|
||||||
virObjectUnref(mon->program);
|
virObjectUnref(mon->program);
|
||||||
VIR_FREE(mon);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int virLXCMonitorRef(virLXCMonitorPtr mon)
|
|
||||||
{
|
|
||||||
mon->refs++;
|
|
||||||
return mon->refs;
|
|
||||||
}
|
|
||||||
|
|
||||||
int virLXCMonitorUnref(virLXCMonitorPtr mon)
|
|
||||||
{
|
|
||||||
mon->refs--;
|
|
||||||
|
|
||||||
if (mon->refs == 0) {
|
|
||||||
virLXCMonitorUnlock(mon);
|
|
||||||
virLXCMonitorFree(mon);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mon->refs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#ifndef __LXC_MONITOR_H__
|
#ifndef __LXC_MONITOR_H__
|
||||||
# define __LXC_MONITOR_H__
|
# define __LXC_MONITOR_H__
|
||||||
|
|
||||||
|
# include "virobject.h"
|
||||||
# include "domain_conf.h"
|
# include "domain_conf.h"
|
||||||
# include "lxc_protocol.h"
|
# include "lxc_protocol.h"
|
||||||
|
|
||||||
@ -54,7 +55,4 @@ void virLXCMonitorClose(virLXCMonitorPtr mon);
|
|||||||
void virLXCMonitorLock(virLXCMonitorPtr mon);
|
void virLXCMonitorLock(virLXCMonitorPtr mon);
|
||||||
void virLXCMonitorUnlock(virLXCMonitorPtr mon);
|
void virLXCMonitorUnlock(virLXCMonitorPtr mon);
|
||||||
|
|
||||||
int virLXCMonitorRef(virLXCMonitorPtr mon);
|
|
||||||
int virLXCMonitorUnref(virLXCMonitorPtr mon);
|
|
||||||
|
|
||||||
#endif /* __LXC_MONITOR_H__ */
|
#endif /* __LXC_MONITOR_H__ */
|
||||||
|
@ -238,9 +238,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
if (priv->monitor) {
|
if (priv->monitor) {
|
||||||
virLXCMonitorClose(priv->monitor);
|
virLXCMonitorClose(priv->monitor);
|
||||||
virLXCMonitorLock(priv->monitor);
|
virObjectUnref(priv->monitor);
|
||||||
if (virLXCMonitorUnref(priv->monitor) > 0)
|
|
||||||
virLXCMonitorUnlock(priv->monitor);
|
|
||||||
priv->monitor = NULL;
|
priv->monitor = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,8 +673,7 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) {
|
if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) {
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
virLXCMonitorLock(monitor);
|
virObjectUnref(monitor);
|
||||||
virLXCMonitorUnref(monitor);
|
|
||||||
monitor = NULL;
|
monitor = NULL;
|
||||||
}
|
}
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1198,9 +1195,7 @@ cleanup:
|
|||||||
}
|
}
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
if (priv->monitor) {
|
if (priv->monitor) {
|
||||||
virLXCMonitorLock(priv->monitor);
|
virObjectUnref(priv->monitor);
|
||||||
if (virLXCMonitorUnref(priv->monitor) > 0)
|
|
||||||
virLXCMonitorUnlock(priv->monitor);
|
|
||||||
priv->monitor = NULL;
|
priv->monitor = NULL;
|
||||||
}
|
}
|
||||||
virDomainConfVMNWFilterTeardown(vm);
|
virDomainConfVMNWFilterTeardown(vm);
|
||||||
|
Loading…
Reference in New Issue
Block a user