mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-07 18:35:46 +00:00
Change virConnectPtr into virObjectLocklable
It already had a virMutex inside, so this is just a cleanup. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
6dfbaca7b7
commit
fae5b555c8
@ -73,7 +73,7 @@ virDataTypesOnceInit(void)
|
|||||||
#define DECLARE_CLASS_LOCKABLE(basename) \
|
#define DECLARE_CLASS_LOCKABLE(basename) \
|
||||||
DECLARE_CLASS_COMMON(basename, virClassForObjectLockable())
|
DECLARE_CLASS_COMMON(basename, virClassForObjectLockable())
|
||||||
|
|
||||||
DECLARE_CLASS(virConnect);
|
DECLARE_CLASS_LOCKABLE(virConnect);
|
||||||
DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
|
DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
|
||||||
DECLARE_CLASS(virDomain);
|
DECLARE_CLASS(virDomain);
|
||||||
DECLARE_CLASS(virDomainSnapshot);
|
DECLARE_CLASS(virDomainSnapshot);
|
||||||
@ -110,15 +110,12 @@ virGetConnect(void)
|
|||||||
if (virDataTypesInitialize() < 0)
|
if (virDataTypesInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ret = virObjectNew(virConnectClass)))
|
if (!(ret = virObjectLockableNew(virConnectClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ret->closeCallback = virObjectLockableNew(virConnectCloseCallbackDataClass)))
|
if (!(ret->closeCallback = virObjectLockableNew(virConnectCloseCallbackDataClass)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virMutexInit(&ret->lock) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -141,8 +138,6 @@ virConnectDispose(void *obj)
|
|||||||
if (conn->driver)
|
if (conn->driver)
|
||||||
conn->driver->connectClose(conn);
|
conn->driver->connectClose(conn);
|
||||||
|
|
||||||
virMutexLock(&conn->lock);
|
|
||||||
|
|
||||||
virResetError(&conn->err);
|
virResetError(&conn->err);
|
||||||
|
|
||||||
virURIFree(conn->uri);
|
virURIFree(conn->uri);
|
||||||
@ -154,9 +149,6 @@ virConnectDispose(void *obj)
|
|||||||
|
|
||||||
virObjectUnref(conn->closeCallback);
|
virObjectUnref(conn->closeCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&conn->lock);
|
|
||||||
virMutexDestroy(&conn->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* datatypes.h: management of structs for public data types
|
* datatypes.h: management of structs for public data types
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2014 Red Hat, Inc.
|
* Copyright (C) 2006-2015 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -328,10 +328,12 @@ struct _virConnectCloseCallbackData {
|
|||||||
* Internal structure associated to a connection
|
* Internal structure associated to a connection
|
||||||
*/
|
*/
|
||||||
struct _virConnect {
|
struct _virConnect {
|
||||||
virObject object;
|
virObjectLockable object;
|
||||||
/* All the variables from here, until the 'lock' declaration
|
|
||||||
* are setup at time of connection open, and never changed
|
/* All the variables from here, until declared otherwise in one of
|
||||||
* since. Thus no need to lock when accessing them
|
* the following comments, are setup at time of connection open
|
||||||
|
* and never changed since. Thus no need to lock when accessing
|
||||||
|
* them.
|
||||||
*/
|
*/
|
||||||
unsigned int flags; /* a set of connection flags */
|
unsigned int flags; /* a set of connection flags */
|
||||||
virURIPtr uri; /* connection URI */
|
virURIPtr uri; /* connection URI */
|
||||||
@ -352,12 +354,10 @@ struct _virConnect {
|
|||||||
void * privateData;
|
void * privateData;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The lock mutex must be acquired before accessing/changing
|
* Object lock must be acquired before accessing/changing any of
|
||||||
* any of members following this point, or changing the ref
|
* members following this point, or changing the ref count of any
|
||||||
* count of any virDomain/virNetwork object associated with
|
* virDomain/virNetwork object associated with this connection.
|
||||||
* this connection
|
|
||||||
*/
|
*/
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
/* Per-connection error. */
|
/* Per-connection error. */
|
||||||
virError err; /* the last error */
|
virError err; /* the last error */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* libvirt-host.c: entry points for vir{Connect,Node}Ptr APIs
|
* libvirt-host.c: entry points for vir{Connect,Node}Ptr APIs
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2014 Red Hat, Inc.
|
* Copyright (C) 2006-2015 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -51,7 +51,7 @@ VIR_LOG_INIT("libvirt.host");
|
|||||||
int
|
int
|
||||||
virConnectRef(virConnectPtr conn)
|
virConnectRef(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
VIR_DEBUG("conn=%p refs=%d", conn, conn ? conn->object.u.s.refs : 0);
|
VIR_DEBUG("conn=%p refs=%d", conn, conn ? conn->object.parent.u.s.refs : 0);
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
@ -1219,7 +1219,7 @@ virConnectRegisterCloseCallback(virConnectPtr conn,
|
|||||||
|
|
||||||
virObjectRef(conn);
|
virObjectRef(conn);
|
||||||
|
|
||||||
virMutexLock(&conn->lock);
|
virObjectLock(conn);
|
||||||
virObjectLock(conn->closeCallback);
|
virObjectLock(conn->closeCallback);
|
||||||
|
|
||||||
virCheckNonNullArgGoto(cb, error);
|
virCheckNonNullArgGoto(cb, error);
|
||||||
@ -1236,13 +1236,13 @@ virConnectRegisterCloseCallback(virConnectPtr conn,
|
|||||||
conn->closeCallback->freeCallback = freecb;
|
conn->closeCallback->freeCallback = freecb;
|
||||||
|
|
||||||
virObjectUnlock(conn->closeCallback);
|
virObjectUnlock(conn->closeCallback);
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectUnlock(conn->closeCallback);
|
virObjectUnlock(conn->closeCallback);
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
virDispatchError(conn);
|
virDispatchError(conn);
|
||||||
virObjectUnref(conn);
|
virObjectUnref(conn);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1272,7 +1272,7 @@ virConnectUnregisterCloseCallback(virConnectPtr conn,
|
|||||||
|
|
||||||
virCheckConnectReturn(conn, -1);
|
virCheckConnectReturn(conn, -1);
|
||||||
|
|
||||||
virMutexLock(&conn->lock);
|
virObjectLock(conn);
|
||||||
virObjectLock(conn->closeCallback);
|
virObjectLock(conn->closeCallback);
|
||||||
|
|
||||||
virCheckNonNullArgGoto(cb, error);
|
virCheckNonNullArgGoto(cb, error);
|
||||||
@ -1288,15 +1288,15 @@ virConnectUnregisterCloseCallback(virConnectPtr conn,
|
|||||||
conn->closeCallback->freeCallback(conn->closeCallback->opaque);
|
conn->closeCallback->freeCallback(conn->closeCallback->opaque);
|
||||||
conn->closeCallback->freeCallback = NULL;
|
conn->closeCallback->freeCallback = NULL;
|
||||||
|
|
||||||
virObjectUnref(conn);
|
|
||||||
virObjectUnlock(conn->closeCallback);
|
virObjectUnlock(conn->closeCallback);
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
|
virObjectUnref(conn);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectUnlock(conn->closeCallback);
|
virObjectUnlock(conn->closeCallback);
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
virDispatchError(conn);
|
virDispatchError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virerror.c: error handling and reporting code for libvirt
|
* virerror.c: error handling and reporting code for libvirt
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006, 2008-2014 Red Hat, Inc.
|
* Copyright (C) 2006, 2008-2015 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -460,12 +460,12 @@ virConnCopyLastError(virConnectPtr conn, virErrorPtr to)
|
|||||||
|
|
||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
virMutexLock(&conn->lock);
|
virObjectLock(conn);
|
||||||
if (conn->err.code == VIR_ERR_OK)
|
if (conn->err.code == VIR_ERR_OK)
|
||||||
virResetError(to);
|
virResetError(to);
|
||||||
else
|
else
|
||||||
virCopyError(&conn->err, to);
|
virCopyError(&conn->err, to);
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
return to->code;
|
return to->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,9 +483,9 @@ virConnResetLastError(virConnectPtr conn)
|
|||||||
{
|
{
|
||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return;
|
return;
|
||||||
virMutexLock(&conn->lock);
|
virObjectLock(conn);
|
||||||
virResetError(&conn->err);
|
virResetError(&conn->err);
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -520,10 +520,10 @@ virConnSetErrorFunc(virConnectPtr conn, void *userData,
|
|||||||
{
|
{
|
||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return;
|
return;
|
||||||
virMutexLock(&conn->lock);
|
virObjectLock(conn);
|
||||||
conn->handler = handler;
|
conn->handler = handler;
|
||||||
conn->userData = userData;
|
conn->userData = userData;
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -600,14 +600,14 @@ virDispatchError(virConnectPtr conn)
|
|||||||
|
|
||||||
/* Copy the global error to per-connection error if needed */
|
/* Copy the global error to per-connection error if needed */
|
||||||
if (conn) {
|
if (conn) {
|
||||||
virMutexLock(&conn->lock);
|
virObjectLock(conn);
|
||||||
virCopyError(err, &conn->err);
|
virCopyError(err, &conn->err);
|
||||||
|
|
||||||
if (conn->handler != NULL) {
|
if (conn->handler != NULL) {
|
||||||
handler = conn->handler;
|
handler = conn->handler;
|
||||||
userData = conn->userData;
|
userData = conn->userData;
|
||||||
}
|
}
|
||||||
virMutexUnlock(&conn->lock);
|
virObjectUnlock(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invoke the error callback functions */
|
/* Invoke the error callback functions */
|
||||||
|
Loading…
Reference in New Issue
Block a user