From c285acf172d42271d87eb069045ea70bce97b0b1 Mon Sep 17 00:00:00 2001
From: Pranith Kumar K <pkarampu@redhat.com>
Date: Mon, 23 Apr 2018 21:04:58 +0530
Subject: [PATCH 428/444] libglusterfs/syncop: Handle barrier_{init/destroy} in
error cases
> Upstream: https://review.gluster.org/19927
> BUG: 1568521
> Change-Id: I53e60cfcaa7f8edfa5eca47307fa99f10ee64505
Change-Id: I53e60cfcaa7f8edfa5eca47307fa99f10ee64505
BUG: 1520882
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/154862
Tested-by: Krutika Dhananjay <kdhananj@redhat.com>
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Xavi Hernandez <xhernandez@redhat.com>
Tested-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
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 ac40a1d..81d73b2 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 5b5ad4e..9ab5ee8 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 */
--
1.8.3.1