[libvirt] [PATCH 0/2] Refactor virMutexInit virRWLockInit and virCondInit

Implement virMutexInitInternal, virRWLockInitInternal and virCondInitInternal which include error message reporting. int virMutexInitInternal(virMutexPtr mutex, bool recursive, bool quite, const char *filename, const char *funcname, size_t linenr) virMutexInit calls virMutexInitInternal with quite == false; virMutexInitQuite calls virMutexInitInternal with quite == true. Same for virRWLockInit and virCondInit. And remove redundant error messages after virMutexInit from other source files. Jincheng Miao (2): Refactor virMutexInit virRWLockInit and virCondInit remove error message when virMutexInit and virCondInit failed daemon/remote.c | 1 - src/conf/interface_conf.c | 2 - src/conf/network_conf.c | 2 - src/conf/node_device_conf.c | 2 - src/conf/nwfilter_conf.c | 2 - src/conf/object_event.c | 2 - src/conf/storage_conf.c | 2 - src/conf/virchrdev.c | 2 - src/esx/esx_vi.c | 15 ++---- src/fdstream.c | 2 - src/libvirt_private.syms | 7 ++- src/libxl/libxl_driver.c | 2 - src/locking/lock_daemon.c | 5 -- src/node_device/node_device_udev.c | 1 - src/nwfilter/nwfilter_learnipaddr.c | 2 - src/parallels/parallels_driver.c | 5 +- src/qemu/qemu_agent.c | 2 - src/qemu/qemu_capabilities.c | 2 - src/qemu/qemu_driver.c | 1 - src/qemu/qemu_monitor.c | 6 +-- src/remote/remote_driver.c | 2 - src/rpc/virnetclient.c | 5 +- src/test/test_driver.c | 4 -- src/util/vireventpoll.c | 5 +- src/util/virlockspace.c | 4 -- src/util/virobject.c | 2 - src/util/virthread.c | 95 ++++++++++++++++++------------------- src/util/virthread.h | 57 +++++++++++++++++----- src/xen/xen_driver.c | 2 - tests/commandtest.c | 4 +- tests/qemumonitortestutils.c | 2 - 31 files changed, 103 insertions(+), 144 deletions(-) -- 1.8.3.1

Implement InitInternal functions for Mutex, RWLock and Cond, these functions contain error report using virReportSystemErrorFull, it is controlled by an argument 'quite'. The related macros are Init and InitQuite, they call InitInternal function by passing 'false' or 'true' to quite argument. Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/libvirt_private.syms | 7 ++-- src/util/virthread.c | 95 ++++++++++++++++++++++++------------------------ src/util/virthread.h | 57 ++++++++++++++++++++++------- 3 files changed, 94 insertions(+), 65 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8d3671c..b1c05d3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2015,18 +2015,17 @@ virSystemdTerminateMachine; # util/virthread.h virCondBroadcast; virCondDestroy; -virCondInit; +virCondInitInternal; virCondSignal; virCondWait; virCondWaitUntil; virMutexDestroy; -virMutexInit; -virMutexInitRecursive; +virMutexInitInternal; virMutexLock; virMutexUnlock; virOnce; virRWLockDestroy; -virRWLockInit; +virRWLockInitInternal; virRWLockRead; virRWLockUnlock; virRWLockWrite; diff --git a/src/util/virthread.c b/src/util/virthread.c index 7e841d1..ceed1bf 100644 --- a/src/util/virthread.c +++ b/src/util/virthread.c @@ -31,6 +31,16 @@ #include "viralloc.h" +#define VIR_THREAD_ERR_EXIT(str) do { \ + errno = ret; \ + if (!quite) { \ + virReportSystemErrorFull(VIR_FROM_NONE, errno, \ + filename, funcname, linenr, \ + "%s", _(str)); \ + } \ + return -1; \ + } while (0) + /* Nothing special required for pthreads */ int virThreadInitialize(void) @@ -48,92 +58,81 @@ int virOnce(virOnceControlPtr once, virOnceFunc init) } -int virMutexInit(virMutexPtr m) +int virMutexInitInternal(virMutexPtr mutex, bool recursive, bool quite, + const char *filename, const char *funcname, + size_t linenr) { int ret; pthread_mutexattr_t attr; + int type = recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL; pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); - ret = pthread_mutex_init(&m->lock, &attr); + pthread_mutexattr_settype(&attr, type); + ret = pthread_mutex_init(&mutex->lock, &attr); pthread_mutexattr_destroy(&attr); - if (ret != 0) { - errno = ret; - return -1; - } - return 0; -} -int virMutexInitRecursive(virMutexPtr m) -{ - int ret; - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - ret = pthread_mutex_init(&m->lock, &attr); - pthread_mutexattr_destroy(&attr); - if (ret != 0) { - errno = ret; - return -1; - } + if (ret != 0) + VIR_THREAD_ERR_EXIT("unable to init Mutex"); + return 0; } -void virMutexDestroy(virMutexPtr m) +void virMutexDestroy(virMutexPtr mutex) { - pthread_mutex_destroy(&m->lock); + pthread_mutex_destroy(&mutex->lock); } -void virMutexLock(virMutexPtr m) +void virMutexLock(virMutexPtr mutex) { - pthread_mutex_lock(&m->lock); + pthread_mutex_lock(&mutex->lock); } -void virMutexUnlock(virMutexPtr m) +void virMutexUnlock(virMutexPtr mutex) { - pthread_mutex_unlock(&m->lock); + pthread_mutex_unlock(&mutex->lock); } -int virRWLockInit(virRWLockPtr m) +int virRWLockInitInternal(virRWLockPtr rwlock, bool quite, + const char *filename, const char *funcname, + size_t linenr) { - int ret; - ret = pthread_rwlock_init(&m->lock, NULL); - if (ret != 0) { - errno = ret; - return -1; - } + int ret = pthread_rwlock_init(&rwlock->lock, NULL); + if (ret != 0) + VIR_THREAD_ERR_EXIT("unable to init RWLock"); + return 0; } -void virRWLockDestroy(virRWLockPtr m) +void virRWLockDestroy(virRWLockPtr rwlock) { - pthread_rwlock_destroy(&m->lock); + pthread_rwlock_destroy(&rwlock->lock); } -void virRWLockRead(virRWLockPtr m) +void virRWLockRead(virRWLockPtr rwlock) { - pthread_rwlock_rdlock(&m->lock); + pthread_rwlock_rdlock(&rwlock->lock); } -void virRWLockWrite(virRWLockPtr m) +void virRWLockWrite(virRWLockPtr rwlock) { - pthread_rwlock_wrlock(&m->lock); + pthread_rwlock_wrlock(&rwlock->lock); } -void virRWLockUnlock(virRWLockPtr m) +void virRWLockUnlock(virRWLockPtr rwlock) { - pthread_rwlock_unlock(&m->lock); + pthread_rwlock_unlock(&rwlock->lock); } -int virCondInit(virCondPtr c) +int virCondInitInternal(virCondPtr cond, bool quite, + const char *filename, const char *funcname, + size_t linenr) { - int ret; - if ((ret = pthread_cond_init(&c->cond, NULL)) != 0) { - errno = ret; - return -1; - } + int ret = pthread_cond_init(&cond->cond, NULL); + if (ret != 0) + VIR_THREAD_ERR_EXIT("unable to init Cond"); + return 0; } diff --git a/src/util/virthread.h b/src/util/virthread.h index 4b92a43..99c16f3 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -122,24 +122,54 @@ unsigned long long virThreadID(virThreadPtr thread); int virOnce(virOnceControlPtr once, virOnceFunc init) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; -int virMutexInit(virMutexPtr m) ATTRIBUTE_RETURN_CHECK; -int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETURN_CHECK; -void virMutexDestroy(virMutexPtr m); +int virMutexInitInternal(virMutexPtr mutex, bool recursive, bool quite, + const char *filename, const char *funcname, + size_t linenr) + ATTRIBUTE_RETURN_CHECK; -void virMutexLock(virMutexPtr m); -void virMutexUnlock(virMutexPtr m); +# define virMutexInit(mutex) \ + virMutexInitInternal(mutex, false, false, __FILE__, __FUNCTION__, __LINE__) +# define virMutexInitQuite(mutex) \ + virMutexInitInternal(mutex, false, true, __FILE__, __FUNCTION__, __LINE__) +# define virMutexInitRecursive(mutex) \ + virMutexInitInternal(mutex, true, false, __FILE__, __FUNCTION__, __LINE__) +# define virMutexInitRecursiveQuite(mutex) \ + virMutexInitInternal(mutex, true, true, __FILE__, __FUNCTION__, __LINE__) +void virMutexDestroy(virMutexPtr mutex); -int virRWLockInit(virRWLockPtr m) ATTRIBUTE_RETURN_CHECK; -void virRWLockDestroy(virRWLockPtr m); +void virMutexLock(virMutexPtr mutex); +void virMutexUnlock(virMutexPtr mutex); -void virRWLockRead(virRWLockPtr m); -void virRWLockWrite(virRWLockPtr m); -void virRWLockUnlock(virRWLockPtr m); +int virRWLockInitInternal(virRWLockPtr rwlock, bool quite, + const char *filename, const char *funcname, + size_t linenr) + ATTRIBUTE_RETURN_CHECK; -int virCondInit(virCondPtr c) ATTRIBUTE_RETURN_CHECK; -int virCondDestroy(virCondPtr c); +# define virRWLockInit(rwlock) \ + virRWLockInitInternal(rwlock, false, __FILE__, __FUNCTION__, __LINE__) +# define virRWLockInitQuite(rwlock) \ + virRWLockInitInternal(rwlock, true, __FILE__, __FUNCTION__, __LINE__) + +void virRWLockDestroy(virRWLockPtr rwlock); + +void virRWLockRead(virRWLockPtr rwlock); +void virRWLockWrite(virRWLockPtr rwlock); +void virRWLockUnlock(virRWLockPtr rwlock); + + +int virCondInitInternal(virCondPtr cond, bool quite, + const char *filename, const char *funcname, + size_t linenr) + ATTRIBUTE_RETURN_CHECK; + +# define virCondInit(cond) \ + virCondInitInternal(cond, false, __FILE__, __FUNCTION__, __LINE__) +# define virCondInitQuite(cond) \ + virCondInitInternal(cond, true, __FILE__, __FUNCTION__, __LINE__) + +int virCondDestroy(virCondPtr cond); /* virCondWait, virCondWaitUntil: * These functions can return without the associated predicate @@ -147,7 +177,8 @@ int virCondDestroy(virCondPtr c); * should be enclosed in a while loop that checks the predicate. */ int virCondWait(virCondPtr c, virMutexPtr m) ATTRIBUTE_RETURN_CHECK; -int virCondWaitUntil(virCondPtr c, virMutexPtr m, unsigned long long whenms) ATTRIBUTE_RETURN_CHECK; +int virCondWaitUntil(virCondPtr c, virMutexPtr m, unsigned long long whenms) + ATTRIBUTE_RETURN_CHECK; void virCondSignal(virCondPtr c); void virCondBroadcast(virCondPtr c); -- 1.8.3.1

On 07/17/2014 10:49 PM, Jincheng Miao wrote:
Implement InitInternal functions for Mutex, RWLock and Cond, these functions contain error report using virReportSystemErrorFull, it is controlled by an argument 'quite'.
s/quite/quiet/
The related macros are Init and InitQuite, they call InitInternal function
s/InitQuite/InitQuiet/ - looks like you need to respin, as it's rather pervasive.
by passing 'false' or 'true' to quite argument.
Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/libvirt_private.syms | 7 ++-- src/util/virthread.c | 95 ++++++++++++++++++++++++------------------------ src/util/virthread.h | 57 ++++++++++++++++++++++------- 3 files changed, 94 insertions(+), 65 deletions(-)
-void virMutexDestroy(virMutexPtr m) +void virMutexDestroy(virMutexPtr mutex) { - pthread_mutex_destroy(&m->lock); + pthread_mutex_destroy(&mutex->lock); }
Please separate trivial renamings into its own patch, so that this patch can focus on the meat of new additions rather than having to hunt for the real changes amidst the noise. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 07/17/2014 10:49 PM, Jincheng Miao wrote:
Implement InitInternal functions for Mutex, RWLock and Cond, these functions contain error report using virReportSystemErrorFull, it is controlled by an argument 'quite'. The related macros are Init and InitQuite, they call InitInternal function by passing 'false' or 'true' to quite argument.
After your patch 2, do we really have any callers that use the quiet version? This seems like the sort of patch where ALL callers should be noisy (especially since the failure is so rare, but also means we are quite hosed if it happens). What are the callers that you intend to be quiet, and what is the justification for them being quiet? -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

----- Original Message -----
After your patch 2, do we really have any callers that use the quiet version? This seems like the sort of patch where ALL callers should be noisy (especially since the failure is so rare, but also means we are quite hosed if it happens). What are the callers that you intend to be quiet, and what is the justification for them being quiet?
Eric, yes, if mutex initialization fails, it is very fatal to libvirt, and I can't give an example for quiet version used. Maybe the 'quiet' is not useful, and I will depart quiet from my next patch. Thanks for your review.
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Fri, Jul 18, 2014 at 07:30:38AM -0600, Eric Blake wrote:
On 07/17/2014 10:49 PM, Jincheng Miao wrote:
Implement InitInternal functions for Mutex, RWLock and Cond, these functions contain error report using virReportSystemErrorFull, it is controlled by an argument 'quite'. The related macros are Init and InitQuite, they call InitInternal function by passing 'false' or 'true' to quite argument.
After your patch 2, do we really have any callers that use the quiet version? This seems like the sort of patch where ALL callers should be noisy (especially since the failure is so rare, but also means we are quite hosed if it happens). What are the callers that you intend to be quiet, and what is the justification for them being quiet?
I think there are few callers that error out with VIR_ERROR(), but most of them just return -1 with no apparent reason. I'm not sure about few class initializations (virOnceInit) and driver initializations. Do we want to be loud on that front as well? Martin

On Wed, Jul 23, 2014 at 07:27:24AM +0200, Martin Kletzander wrote:
On Fri, Jul 18, 2014 at 07:30:38AM -0600, Eric Blake wrote:
On 07/17/2014 10:49 PM, Jincheng Miao wrote:
Implement InitInternal functions for Mutex, RWLock and Cond, these functions contain error report using virReportSystemErrorFull, it is controlled by an argument 'quite'. The related macros are Init and InitQuite, they call InitInternal function by passing 'false' or 'true' to quite argument.
After your patch 2, do we really have any callers that use the quiet version? This seems like the sort of patch where ALL callers should be noisy (especially since the failure is so rare, but also means we are quite hosed if it happens). What are the callers that you intend to be quiet, and what is the justification for them being quiet?
I think there are few callers that error out with VIR_ERROR(), but most of them just return -1 with no apparent reason. I'm not sure about few class initializations (virOnceInit) and driver initializations. Do we want to be loud on that front as well?
Yes, global initializers must always report proper errors - these are captured & reported on every call even though the initializer is only run once. So yes, I think everything should be noisy in this case - there's no legitimate reason with these fnuctions why you would want to be quiet and/or ignore failure. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- daemon/remote.c | 1 - src/conf/interface_conf.c | 2 -- src/conf/network_conf.c | 2 -- src/conf/node_device_conf.c | 2 -- src/conf/nwfilter_conf.c | 2 -- src/conf/object_event.c | 2 -- src/conf/storage_conf.c | 2 -- src/conf/virchrdev.c | 2 -- src/esx/esx_vi.c | 15 +++------------ src/fdstream.c | 2 -- src/libxl/libxl_driver.c | 2 -- src/locking/lock_daemon.c | 5 ----- src/node_device/node_device_udev.c | 1 - src/nwfilter/nwfilter_learnipaddr.c | 2 -- src/parallels/parallels_driver.c | 5 +---- src/qemu/qemu_agent.c | 2 -- src/qemu/qemu_capabilities.c | 2 -- src/qemu/qemu_driver.c | 1 - src/qemu/qemu_monitor.c | 6 ++---- src/remote/remote_driver.c | 2 -- src/rpc/virnetclient.c | 5 +---- src/test/test_driver.c | 4 ---- src/util/vireventpoll.c | 5 +---- src/util/virlockspace.c | 4 ---- src/util/virobject.c | 2 -- src/xen/xen_driver.c | 2 -- tests/commandtest.c | 4 +--- tests/qemumonitortestutils.c | 2 -- 28 files changed, 9 insertions(+), 79 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index ea16789..d3cf8a8 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1164,7 +1164,6 @@ void *remoteClientInitHook(virNetServerClientPtr client, if (virMutexInit(&priv->lock) < 0) { VIR_FREE(priv); - virReportSystemError(errno, "%s", _("unable to init mutex")); return NULL; } diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 103e878..87dc79e 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -1250,8 +1250,6 @@ virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces, if (VIR_ALLOC(iface) < 0) return NULL; if (virMutexInit(&iface->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); VIR_FREE(iface); return NULL; } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index ce4d4d8..574727a 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -388,8 +388,6 @@ virNetworkAssignDef(virNetworkObjListPtr nets, if (VIR_ALLOC(network) < 0) return NULL; if (virMutexInit(&network->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); VIR_FREE(network); return NULL; } diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 30aa477..ed4cd2a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -183,8 +183,6 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, return NULL; if (virMutexInit(&device->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); VIR_FREE(device); return NULL; } diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 52f24e4..b662e02 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -3104,8 +3104,6 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters, return NULL; if (virMutexInitRecursive(&nwfilter->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); VIR_FREE(nwfilter); return NULL; } diff --git a/src/conf/object_event.c b/src/conf/object_event.c index beef3e1..86d0eb8 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -577,8 +577,6 @@ virObjectEventStateNew(void) goto error; if (virMutexInit(&state->lock) < 0) { - virReportSystemError(errno, "%s", - _("unable to initialize state mutex")); VIR_FREE(state); goto error; } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 69333f5..1e8edff 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1694,8 +1694,6 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, return NULL; if (virMutexInit(&pool->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot initialize mutex")); VIR_FREE(pool); return NULL; } diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 022fe71..a659b62 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -272,8 +272,6 @@ virChrdevsPtr virChrdevAlloc(void) return NULL; if (virMutexInit(&devs->lock) < 0) { - virReportSystemError(errno, "%s", - _("Unable to init device stream mutex")); VIR_FREE(devs); return NULL; } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index c02a293..d8026c2 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -364,11 +364,8 @@ esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri *parsedUri) parsedUri->proxy_port); } - if (virMutexInit(&curl->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not initialize CURL mutex")); + if (virMutexInit(&curl->lock) < 0) return -1; - } return 0; } @@ -602,11 +599,8 @@ esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_CURL *curl) CURL_LOCK_DATA_DNS); for (i = 0; i < ARRAY_CARDINALITY(shared->locks); ++i) { - if (virMutexInit(&shared->locks[i]) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not initialize a CURL (share) mutex")); + if (virMutexInit(&shared->locks[i]) < 0) return -1; - } } } @@ -810,11 +804,8 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, if (VIR_ALLOC(ctx->sessionLock) < 0) return -1; - if (virMutexInit(ctx->sessionLock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not initialize session mutex")); + if (virMutexInit(ctx->sessionLock) < 0) return -1; - } if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) { return -1; diff --git a/src/fdstream.c b/src/fdstream.c index fd576ef..31d93f3 100644 --- a/src/fdstream.c +++ b/src/fdstream.c @@ -490,8 +490,6 @@ static int virFDStreamOpenInternal(virStreamPtr st, fdst->length = length; if (virMutexInit(&fdst->lock) < 0) { VIR_FREE(fdst); - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize mutex")); return -1; } diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 5fbff1c..278fa94 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -291,8 +291,6 @@ libxlStateInitialize(bool privileged, return -1; if (virMutexInit(&libxl_driver->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); VIR_FREE(libxl_driver); return -1; } diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 3379f29..9c68877 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -140,8 +140,6 @@ virLockDaemonNew(virLockDaemonConfigPtr config, bool privileged) return NULL; if (virMutexInit(&lockd->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize mutex")); VIR_FREE(lockd); return NULL; } @@ -183,8 +181,6 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged) return NULL; if (virMutexInit(&lockd->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize mutex")); VIR_FREE(lockd); return NULL; } @@ -783,7 +779,6 @@ virLockDaemonClientNew(virNetServerClientPtr client, if (virMutexInit(&priv->lock) < 0) { VIR_FREE(priv); - virReportSystemError(errno, "%s", _("unable to init mutex")); return NULL; } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 28d2953..0ed1792 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1754,7 +1754,6 @@ static int nodeStateInitialize(bool privileged, } if (virMutexInit(&driverState->lock) < 0) { - VIR_ERROR(_("Failed to initialize mutex for driverState")); VIR_FREE(priv); VIR_FREE(driverState); ret = -1; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 4cea9cf..c3ab3a1 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -150,8 +150,6 @@ virNWFilterLockIface(const char *ifname) goto err_exit; if (virMutexInitRecursive(&ifaceLock->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("mutex initialization failed")); VIR_FREE(ifaceLock); goto err_exit; } diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index a503dea..a2af295 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -926,11 +926,8 @@ parallelsOpenDefault(virConnectPtr conn) if (VIR_ALLOC(privconn) < 0) return VIR_DRV_OPEN_ERROR; - if (virMutexInit(&privconn->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot initialize mutex")); + if (virMutexInit(&privconn->lock) < 0) goto error; - } if (!(privconn->caps = parallelsBuildCapabilities())) goto error; diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 0421733..12db835 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -728,8 +728,6 @@ qemuAgentOpen(virDomainObjPtr vm, mon->fd = -1; if (virCondInit(&mon->notify) < 0) { - virReportSystemError(errno, "%s", - _("cannot initialize monitor condition")); virObjectUnref(mon); return NULL; } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 07306e5..15d9b92 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3418,8 +3418,6 @@ virQEMUCapsCacheNew(const char *libDir, return NULL; if (virMutexInit(&cache->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize mutex")); VIR_FREE(cache); return NULL; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 33541d3..b46b2de 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -587,7 +587,6 @@ qemuStateInitialize(bool privileged, return -1; if (virMutexInit(&qemu_driver->lock) < 0) { - VIR_ERROR(_("cannot initialize mutex")); VIR_FREE(qemu_driver); return -1; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 3d9f87b..00337ec 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -781,11 +781,9 @@ qemuMonitorOpenInternal(virDomainObjPtr vm, mon->fd = -1; mon->logfd = -1; - if (virCondInit(&mon->notify) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot initialize monitor condition")); + if (virCondInit(&mon->notify) < 0) goto cleanup; - } + mon->fd = fd; mon->hasSendFD = hasSendFD; mon->vm = virObjectRef(vm); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 9a1d78f..5dfbb39 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1100,8 +1100,6 @@ remoteAllocPrivateData(void) return NULL; if (virMutexInit(&priv->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot initialize mutex")); VIR_FREE(priv); return NULL; } diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index a156fe1..7dbb90b 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1880,11 +1880,8 @@ virNetClientCallNew(virNetMessagePtr msg, if (VIR_ALLOC(call) < 0) goto error; - if (virCondInit(&call->cond) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot initialize condition variable")); + if (virCondInit(&call->cond) < 0) goto error; - } msg->donefds = 0; if (msg->bufferLength) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 42af231..35e7a9c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -711,8 +711,6 @@ testOpenDefault(virConnectPtr conn) } if (virMutexInit(&privconn->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); defaultConnections--; virMutexUnlock(&defaultLock); return VIR_DRV_OPEN_ERROR; @@ -1408,8 +1406,6 @@ testOpenFromFile(virConnectPtr conn, const char *file) if (VIR_ALLOC(privconn) < 0) return VIR_DRV_OPEN_ERROR; if (virMutexInit(&privconn->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); VIR_FREE(privconn); return VIR_DRV_OPEN_ERROR; } diff --git a/src/util/vireventpoll.c b/src/util/vireventpoll.c index 13f40dc..31ddc28 100644 --- a/src/util/vireventpoll.c +++ b/src/util/vireventpoll.c @@ -689,11 +689,8 @@ static void virEventPollHandleWakeup(int watch ATTRIBUTE_UNUSED, int virEventPollInit(void) { - if (virMutexInit(&eventLoop.lock) < 0) { - virReportSystemError(errno, "%s", - _("Unable to initialize mutex")); + if (virMutexInit(&eventLoop.lock) < 0) return -1; - } if (pipe2(eventLoop.wakeupfd, O_CLOEXEC | O_NONBLOCK) < 0) { virReportSystemError(errno, "%s", diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 8969ab0..70d40a9 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -249,8 +249,6 @@ virLockSpacePtr virLockSpaceNew(const char *directory) return NULL; if (virMutexInit(&lockspace->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize lockspace mutex")); VIR_FREE(lockspace); return NULL; } @@ -302,8 +300,6 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object) return NULL; if (virMutexInit(&lockspace->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize lockspace mutex")); VIR_FREE(lockspace); return NULL; } diff --git a/src/util/virobject.c b/src/util/virobject.c index 6cb84b4..d1980ac 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -220,8 +220,6 @@ void *virObjectLockableNew(virClassPtr klass) return NULL; if (virMutexInit(&obj->lock) < 0) { - virReportSystemError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize mutex")); virObjectUnref(obj); return NULL; } diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 79df3ee..cbe7f22 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -460,8 +460,6 @@ xenUnifiedConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int f if (VIR_ALLOC(priv) < 0) return VIR_DRV_OPEN_ERROR; if (virMutexInit(&priv->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); VIR_FREE(priv); return VIR_DRV_OPEN_ERROR; } diff --git a/tests/commandtest.c b/tests/commandtest.c index 7d2161c..c471fdc 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1121,10 +1121,8 @@ mymain(void) if (VIR_ALLOC(test) < 0) goto cleanup; - if (virMutexInit(&test->lock) < 0) { - printf("Unable to init mutex: %d\n", errno); + if (virMutexInit(&test->lock) < 0) goto cleanup; - } virMutexLock(&test->lock); diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 8155a69..8d7b1f6 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -768,8 +768,6 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, goto error; if (virMutexInit(&test->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "Cannot initialize mutex"); VIR_FREE(test); return NULL; } -- 1.8.3.1
participants (4)
-
Daniel P. Berrange
-
Eric Blake
-
Jincheng Miao
-
Martin Kletzander