[libvirt] [PATCH V2 0/3] refactor virMutexInit virRWLockInit and virCondInit

This patchset refactors vir{Mutex,RWLock,Cond}Init by calling a Initernal function, which has the error reporting. So that the caller no longer to write a redundant error message after them. V2: removed quiet argument of vir{Mutex,RWLock,Cond}Internal. separated argument renaming patch. Jincheng Miao (3): rename arguments of virthread functions add error report for virMutexInit virRWLockInit and virCondInit remove error message after virMutexInit virRWLockInit virCondInit 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 | 109 +++++++++++++++++------------------- src/util/virthread.h | 50 +++++++++++------ src/xen/xen_driver.c | 2 - tests/qemumonitortestutils.c | 2 - 30 files changed, 97 insertions(+), 153 deletions(-) -- 1.8.3.1

For keeping consistence of other functions in virthread.c, rename arguments 'm', 'c' to 'mutex', 'rwlock' and 'cond'. Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/util/virthread.c | 65 ++++++++++++++++++++++++++-------------------------- src/util/virthread.h | 33 +++++++++++++------------- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/util/virthread.c b/src/util/virthread.c index 7e841d1..e22cadd 100644 --- a/src/util/virthread.c +++ b/src/util/virthread.c @@ -48,13 +48,13 @@ int virOnce(virOnceControlPtr once, virOnceFunc init) } -int virMutexInit(virMutexPtr m) +int virMutexInit(virMutexPtr mutex) { int ret; pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); - ret = pthread_mutex_init(&m->lock, &attr); + ret = pthread_mutex_init(&mutex->lock, &attr); pthread_mutexattr_destroy(&attr); if (ret != 0) { errno = ret; @@ -63,13 +63,13 @@ int virMutexInit(virMutexPtr m) return 0; } -int virMutexInitRecursive(virMutexPtr m) +int virMutexInitRecursive(virMutexPtr mutex) { int ret; pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - ret = pthread_mutex_init(&m->lock, &attr); + ret = pthread_mutex_init(&mutex->lock, &attr); pthread_mutexattr_destroy(&attr); if (ret != 0) { errno = ret; @@ -78,26 +78,26 @@ int virMutexInitRecursive(virMutexPtr m) 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 virRWLockInit(virRWLockPtr rwlock) { int ret; - ret = pthread_rwlock_init(&m->lock, NULL); + ret = pthread_rwlock_init(&rwlock->lock, NULL); if (ret != 0) { errno = ret; return -1; @@ -105,59 +105,60 @@ int virRWLockInit(virRWLockPtr m) 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 virCondInit(virCondPtr cond) { int ret; - if ((ret = pthread_cond_init(&c->cond, NULL)) != 0) { + if ((ret = pthread_cond_init(&cond->cond, NULL)) != 0) { errno = ret; return -1; } return 0; } -int virCondDestroy(virCondPtr c) +int virCondDestroy(virCondPtr cond) { int ret; - if ((ret = pthread_cond_destroy(&c->cond)) != 0) { + if ((ret = pthread_cond_destroy(&cond->cond)) != 0) { errno = ret; return -1; } return 0; } -int virCondWait(virCondPtr c, virMutexPtr m) +int virCondWait(virCondPtr cond, virMutexPtr mutex) { int ret; - if ((ret = pthread_cond_wait(&c->cond, &m->lock)) != 0) { + if ((ret = pthread_cond_wait(&cond->cond, &mutex->lock)) != 0) { errno = ret; return -1; } return 0; } -int virCondWaitUntil(virCondPtr c, virMutexPtr m, unsigned long long whenms) +int virCondWaitUntil(virCondPtr cond, virMutexPtr mutex, + unsigned long long whenms) { int ret; struct timespec ts; @@ -165,21 +166,21 @@ int virCondWaitUntil(virCondPtr c, virMutexPtr m, unsigned long long whenms) ts.tv_sec = whenms / 1000; ts.tv_nsec = (whenms % 1000) * 1000; - if ((ret = pthread_cond_timedwait(&c->cond, &m->lock, &ts)) != 0) { + if ((ret = pthread_cond_timedwait(&cond->cond, &mutex->lock, &ts)) != 0) { errno = ret; return -1; } return 0; } -void virCondSignal(virCondPtr c) +void virCondSignal(virCondPtr cond) { - pthread_cond_signal(&c->cond); + pthread_cond_signal(&cond->cond); } -void virCondBroadcast(virCondPtr c) +void virCondBroadcast(virCondPtr cond) { - pthread_cond_broadcast(&c->cond); + pthread_cond_broadcast(&cond->cond); } struct virThreadArgs { diff --git a/src/util/virthread.h b/src/util/virthread.h index 4b92a43..7c71c6b 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -122,35 +122,36 @@ 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 virMutexInit(virMutexPtr mutex) ATTRIBUTE_RETURN_CHECK; +int virMutexInitRecursive(virMutexPtr mutex) ATTRIBUTE_RETURN_CHECK; +void virMutexDestroy(virMutexPtr mutex); -void virMutexLock(virMutexPtr m); -void virMutexUnlock(virMutexPtr m); +void virMutexLock(virMutexPtr mutex); +void virMutexUnlock(virMutexPtr mutex); -int virRWLockInit(virRWLockPtr m) ATTRIBUTE_RETURN_CHECK; -void virRWLockDestroy(virRWLockPtr m); +int virRWLockInit(virRWLockPtr rwlock) ATTRIBUTE_RETURN_CHECK; +void virRWLockDestroy(virRWLockPtr rwlock); -void virRWLockRead(virRWLockPtr m); -void virRWLockWrite(virRWLockPtr m); -void virRWLockUnlock(virRWLockPtr m); +void virRWLockRead(virRWLockPtr rwlock); +void virRWLockWrite(virRWLockPtr rwlock); +void virRWLockUnlock(virRWLockPtr rwlock); -int virCondInit(virCondPtr c) ATTRIBUTE_RETURN_CHECK; -int virCondDestroy(virCondPtr c); +int virCondInit(virCondPtr cond) ATTRIBUTE_RETURN_CHECK; +int virCondDestroy(virCondPtr cond); /* virCondWait, virCondWaitUntil: * These functions can return without the associated predicate * changing value. Therefore in nearly all cases they * 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 virCondWait(virCondPtr cond, virMutexPtr mutex) ATTRIBUTE_RETURN_CHECK; +int virCondWaitUntil(virCondPtr cond, virMutexPtr mutex, + unsigned long long whenms) ATTRIBUTE_RETURN_CHECK; -void virCondSignal(virCondPtr c); -void virCondBroadcast(virCondPtr c); +void virCondSignal(virCondPtr cond); +void virCondBroadcast(virCondPtr cond); typedef void (*virThreadLocalCleanup)(void *); -- 1.8.3.1

Implement vir{Mutex,RWLock,Cond}InitInternal functions which have related error report when failure, and vir{Mutex,RWLock,Cond}Init as macros. So that the caller no longer to print error message explicitly. Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/libvirt_private.syms | 7 +++--- src/util/virthread.c | 56 +++++++++++++++++++++--------------------------- src/util/virthread.h | 25 +++++++++++++++++---- 3 files changed, 49 insertions(+), 39 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 e22cadd..36044eb 100644 --- a/src/util/virthread.c +++ b/src/util/virthread.c @@ -31,6 +31,13 @@ #include "viralloc.h" +#define VIR_THREAD_ERR_EXIT(str) do { \ + errno = ret; \ + virReportSystemErrorFull(VIR_FROM_NONE, errno, \ + filename, funcname, linenr, \ + "%s", _(str)); \ + return -1; \ + } while (0) /* Nothing special required for pthreads */ int virThreadInitialize(void) @@ -48,33 +55,20 @@ int virOnce(virOnceControlPtr once, virOnceFunc init) } -int virMutexInit(virMutexPtr mutex) +int virMutexInitInternal(virMutexPtr mutex, bool recursive, + 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); + 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; -} + if (ret != 0) + VIR_THREAD_ERR_EXIT("unable to init Mutex"); -int virMutexInitRecursive(virMutexPtr mutex) -{ - int ret; - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - ret = pthread_mutex_init(&mutex->lock, &attr); - pthread_mutexattr_destroy(&attr); - if (ret != 0) { - errno = ret; - return -1; - } return 0; } @@ -94,14 +88,14 @@ void virMutexUnlock(virMutexPtr mutex) } -int virRWLockInit(virRWLockPtr rwlock) +int virRWLockInitInternal(virRWLockPtr rwlock, const char *filename, + const char *funcname, size_t linenr) { int ret; ret = pthread_rwlock_init(&rwlock->lock, NULL); - if (ret != 0) { - errno = ret; - return -1; - } + if (ret != 0) + VIR_THREAD_ERR_EXIT("unable to init RWLock"); + return 0; } @@ -127,13 +121,13 @@ void virRWLockUnlock(virRWLockPtr rwlock) pthread_rwlock_unlock(&rwlock->lock); } -int virCondInit(virCondPtr cond) +int virCondInitInternal(virCondPtr cond, const char *filename, + const char *funcname, size_t linenr) { - int ret; - if ((ret = pthread_cond_init(&cond->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 Condition"); + return 0; } diff --git a/src/util/virthread.h b/src/util/virthread.h index 7c71c6b..280294b 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -122,15 +122,27 @@ unsigned long long virThreadID(virThreadPtr thread); int virOnce(virOnceControlPtr once, virOnceFunc init) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; -int virMutexInit(virMutexPtr mutex) ATTRIBUTE_RETURN_CHECK; -int virMutexInitRecursive(virMutexPtr mutex) ATTRIBUTE_RETURN_CHECK; +int virMutexInitInternal(virMutexPtr mutex, bool recursive, + const char *filename, const char *funcname, + size_t linenr) + ATTRIBUTE_RETURN_CHECK; +# define virMutexInit(mutex) \ + virMutexInitInternal(mutex, false, __FILE__, __FUNCTION__, __LINE__) +# define virMutexInitRecursive(mutex) \ + virMutexInitInternal(mutex, true, __FILE__, __FUNCTION__, __LINE__) + void virMutexDestroy(virMutexPtr mutex); void virMutexLock(virMutexPtr mutex); void virMutexUnlock(virMutexPtr mutex); -int virRWLockInit(virRWLockPtr rwlock) ATTRIBUTE_RETURN_CHECK; +int virRWLockInitInternal(virRWLockPtr rwlock, const char *filename, + const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK; +# define virRWLockInit(rwlock) \ + virRWLockInitInternal(rwlock, __FILE__, __FUNCTION__, __LINE__) + void virRWLockDestroy(virRWLockPtr rwlock); void virRWLockRead(virRWLockPtr rwlock); @@ -138,7 +150,12 @@ void virRWLockWrite(virRWLockPtr rwlock); void virRWLockUnlock(virRWLockPtr rwlock); -int virCondInit(virCondPtr cond) ATTRIBUTE_RETURN_CHECK; +int virCondInitInternal(virCondPtr cond, const char *filename, + const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK; +# define virCondInit(cond) \ + virCondInitInternal(cond, __FILE__, __FUNCTION__, __LINE__) + int virCondDestroy(virCondPtr cond); /* virCondWait, virCondWaitUntil: -- 1.8.3.1

On Mon, Jul 21, 2014 at 06:13:36PM +0800, Jincheng Miao wrote:
Implement vir{Mutex,RWLock,Cond}InitInternal functions which have related error report when failure, and vir{Mutex,RWLock,Cond}Init as macros. So that the caller no longer to print error message explicitly.
Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/libvirt_private.syms | 7 +++--- src/util/virthread.c | 56 +++++++++++++++++++++--------------------------- src/util/virthread.h | 25 +++++++++++++++++---- 3 files changed, 49 insertions(+), 39 deletions(-)
+#define VIR_THREAD_ERR_EXIT(str) do { \ + errno = ret; \ + virReportSystemErrorFull(VIR_FROM_NONE, errno, \ + filename, funcname, linenr, \ + "%s", _(str)); \ + return -1; \ + } while (0)
Using '_(...)' here isn't going to work for translations because xgettext won't find the strings.
-} + if (ret != 0) + VIR_THREAD_ERR_EXIT("unable to init Mutex");
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 :|

On Mon, Jul 21, 2014 at 06:13:36PM +0800, Jincheng Miao wrote:
Implement vir{Mutex,RWLock,Cond}InitInternal functions which have related error report when failure, and vir{Mutex,RWLock,Cond}Init as macros. So that the caller no longer to print error message explicitly.
Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/libvirt_private.syms | 7 +++--- src/util/virthread.c | 56 +++++++++++++++++++++--------------------------- src/util/virthread.h | 25 +++++++++++++++++---- 3 files changed, 49 insertions(+), 39 deletions(-)
+#define VIR_THREAD_ERR_EXIT(str) do { \ + errno = ret; \ + virReportSystemErrorFull(VIR_FROM_NONE, errno, \ + filename, funcname, linenr, \ + "%s", _(str)); \ + return -1; \ + } while (0)
[snip]
-int virCondInit(virCondPtr cond) +int virCondInitInternal(virCondPtr cond, const char *filename, + const char *funcname, size_t linenr) { - int ret; - if ((ret = pthread_cond_init(&cond->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 Condition"); + return 0; }
[snip]
-int virCondInit(virCondPtr cond) ATTRIBUTE_RETURN_CHECK; +int virCondInitInternal(virCondPtr cond, const char *filename, + const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK; +# define virCondInit(cond) \ + virCondInitInternal(cond, __FILE__, __FUNCTION__, __LINE__) +
I can see what you're trying todo here by passing in __FILE__, __FUNCTION__, __LINE__ through from the calling site, but I don't really think this is beneficial and is not the way we deal with error reporting in any other similar helper APIs. IMHO just remove all this passing around of source location and let it do the default thing. In fact the default behaviour is probably better since if we want to search for any thread related error messages, we can query the journald for the virthread.c file directly. 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 :|

----- Original Message -----
On Mon, Jul 21, 2014 at 06:13:36PM +0800, Jincheng Miao wrote:
Implement vir{Mutex,RWLock,Cond}InitInternal functions which have related error report when failure, and vir{Mutex,RWLock,Cond}Init as macros. So that the caller no longer to print error message explicitly.
Signed-off-by: Jincheng Miao <jmiao@redhat.com> --- src/libvirt_private.syms | 7 +++--- src/util/virthread.c | 56 +++++++++++++++++++++--------------------------- src/util/virthread.h | 25 +++++++++++++++++---- 3 files changed, 49 insertions(+), 39 deletions(-)
+#define VIR_THREAD_ERR_EXIT(str) do { \ + errno = ret; \ + virReportSystemErrorFull(VIR_FROM_NONE, errno, \ + filename, funcname, linenr, \ + "%s", _(str)); \ + return -1; \ + } while (0)
[snip]
-int virCondInit(virCondPtr cond) +int virCondInitInternal(virCondPtr cond, const char *filename, + const char *funcname, size_t linenr) { - int ret; - if ((ret = pthread_cond_init(&cond->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 Condition"); + return 0; }
[snip]
-int virCondInit(virCondPtr cond) ATTRIBUTE_RETURN_CHECK; +int virCondInitInternal(virCondPtr cond, const char *filename, + const char *funcname, size_t linenr) + ATTRIBUTE_RETURN_CHECK; +# define virCondInit(cond) \ + virCondInitInternal(cond, __FILE__, __FUNCTION__, __LINE__) +
I can see what you're trying todo here by passing in __FILE__, __FUNCTION__, __LINE__ through from the calling site, but I don't really think this is beneficial and is not the way we deal with error reporting in any other similar helper APIs. IMHO just remove all this passing around of source location and let it do the default thing. In fact the default behaviour is probably better since if we want to search for any thread related error messages, we can query the journald for the virthread.c file directly.
OK, it's fine to drop them, and thanks for your review.
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/qemumonitortestutils.c | 2 -- 27 files changed, 8 insertions(+), 76 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 3096688..7cb0794 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/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 (2)
-
Daniel P. Berrange
-
Jincheng Miao