From 93464ffd6dcbe2a2f91c0e35f933f814f523e9be Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Mon, 23 Apr 2018 21:04:58 +0530 Subject: libglusterfs/syncop: Handle barrier_{init/destroy} in error cases BUG: 1568521 updates: bz#1568521 Change-Id: I53e60cfcaa7f8edfa5eca47307fa99f10ee64505 Signed-off-by: Pranith Kumar K --- libglusterfs/src/syncop.c | 30 ++++++++++++++++++++++++++---- libglusterfs/src/syncop.h | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 5cae4fbb3a0..58477770368 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -1087,30 +1087,52 @@ synclock_unlock (synclock_t *lock) int syncbarrier_init (struct syncbarrier *barrier) { + int ret = 0; if (!barrier) { errno = EINVAL; return -1; } - pthread_cond_init (&barrier->cond, 0); + ret = pthread_cond_init (&barrier->cond, 0); + if (ret) { + errno = ret; + return -1; + } barrier->count = 0; barrier->waitfor = 0; INIT_LIST_HEAD (&barrier->waitq); - return pthread_mutex_init (&barrier->guard, 0); + ret = pthread_mutex_init (&barrier->guard, 0); + if (ret) { + (void)pthread_cond_destroy (&barrier->cond); + errno = ret; + return -1; + } + barrier->initialized = _gf_true; + return 0; } int syncbarrier_destroy (struct syncbarrier *barrier) { + int ret = 0; + int ret1 = 0; if (!barrier) { errno = EINVAL; return -1; } - pthread_cond_destroy (&barrier->cond); - return pthread_mutex_destroy (&barrier->guard); + if (barrier->initialized) { + ret = pthread_cond_destroy (&barrier->cond); + ret1 = pthread_mutex_destroy (&barrier->guard); + barrier->initialized = _gf_false; + } + if (ret || ret1) { + errno = ret?ret:ret1; + return -1; + } + return 0; } diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h index 682191f0243..367204d05b7 100644 --- a/libglusterfs/src/syncop.h +++ b/libglusterfs/src/syncop.h @@ -134,6 +134,7 @@ typedef struct synclock synclock_t; struct syncbarrier { + gf_boolean_t initialized; /*Set on successful initialization*/ pthread_mutex_t guard; /* guard the remaining members, pair @cond */ pthread_cond_t cond; /* waiting non-synctasks */ struct list_head waitq; /* waiting synctasks */ -- cgit roup: System Environment/Libraries Obsoletes: glusterfs-libs <= 2.0.0 Provides: glusterfs-libs = %{version}-%{release} %description common GlusterFS is a clustered file-system capable of scaling to several peta-bytes. It aggregates various storage bricks over Infiniband RDMA or TCP/IP interconnect into one large parallel network file system. GlusterFS is one of the most sophisticated file system in terms of features and extensibility. It borrows a powerful concept called Translators from GNU Hurd kernel. Much of the code in GlusterFS is in userspace and easily manageable. This package includes the glusterfs binary, libglusterfs and glusterfs translator modules common to both GlusterFS server and client framework. %package client Summary: GlusterFS Client Group: Applications/File Requires: fuse Requires: %{name}-common = %{version}-%{release} %description client GlusterFS is a clustered file-system capable of scaling to several peta-bytes. It aggregates various storage bricks over Infiniband RDMA or TCP/IP interconnect into one large parallel network file system. GlusterFS is one of the most sophisticated file system in terms of features and extensi