d2787b
From 1491b33007e84be0a0a74354e89deca8a21ed198 Mon Sep 17 00:00:00 2001
d2787b
From: Vinayak hariharmath <65405035+VHariharmath-rh@users.noreply.github.com>
d2787b
Date: Tue, 19 Jan 2021 15:39:35 +0530
d2787b
Subject: [PATCH 572/584] locks: remove unused conditional switch to spin_lock
d2787b
 code
d2787b
d2787b
use of spin_locks is depend on the variable use_spinlocks
d2787b
but the same is commented in the current code base through
d2787b
https://review.gluster.org/#/c/glusterfs/+/14763/. So it is
d2787b
of no use to have conditional switching to spin_lock or
d2787b
mutex. Removing the dead code as part of the patch
d2787b
d2787b
Backport of:
d2787b
> Upstream-patch: https://github.com/gluster/glusterfs/pull/2007
d2787b
> Fixes: #1996
d2787b
> Change-Id: Ib005dd86969ce33d3409164ef3e1011bb3169129
d2787b
> Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>
d2787b
d2787b
BUG: 1925425
d2787b
Change-Id: Ib005dd86969ce33d3409164ef3e1011bb3169129
d2787b
Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>
d2787b
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/244965
d2787b
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d2787b
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
d2787b
---
d2787b
 configure.ac                         |  7 -----
d2787b
 libglusterfs/src/Makefile.am         |  2 +-
d2787b
 libglusterfs/src/common-utils.c      |  5 ----
d2787b
 libglusterfs/src/glusterfs/locking.h | 51 ------------------------------------
d2787b
 libglusterfs/src/locking.c           | 27 -------------------
d2787b
 5 files changed, 1 insertion(+), 91 deletions(-)
d2787b
 delete mode 100644 libglusterfs/src/locking.c
d2787b
d2787b
diff --git a/configure.ac b/configure.ac
d2787b
index 6138a59..3d99f6a 100644
d2787b
--- a/configure.ac
d2787b
+++ b/configure.ac
d2787b
@@ -585,13 +585,6 @@ AC_CHECK_HEADERS([linux/falloc.h])
d2787b
 
d2787b
 AC_CHECK_HEADERS([linux/oom.h], AC_DEFINE(HAVE_LINUX_OOM_H, 1, [have linux/oom.h]))
d2787b
 
d2787b
-dnl Mac OS X does not have spinlocks
d2787b
-AC_CHECK_FUNC([pthread_spin_init], [have_spinlock=yes])
d2787b
-if test "x${have_spinlock}" = "xyes"; then
d2787b
-   AC_DEFINE(HAVE_SPINLOCK, 1, [define if found spinlock])
d2787b
-fi
d2787b
-AC_SUBST(HAVE_SPINLOCK)
d2787b
-
d2787b
 dnl some os may not have GNU defined strnlen function
d2787b
 AC_CHECK_FUNC([strnlen], [have_strnlen=yes])
d2787b
 if test "x${have_strnlen}" = "xyes"; then
d2787b
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
d2787b
index 970f4b7..830a0c3 100644
d2787b
--- a/libglusterfs/src/Makefile.am
d2787b
+++ b/libglusterfs/src/Makefile.am
d2787b
@@ -35,7 +35,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \
d2787b
 	strfd.c parse-utils.c $(CONTRIBDIR)/mount/mntent.c \
d2787b
 	$(CONTRIBDIR)/libexecinfo/execinfo.c quota-common-utils.c rot-buffs.c \
d2787b
 	$(CONTRIBDIR)/timer-wheel/timer-wheel.c \
d2787b
-	$(CONTRIBDIR)/timer-wheel/find_last_bit.c default-args.c locking.c \
d2787b
+	$(CONTRIBDIR)/timer-wheel/find_last_bit.c default-args.c \
d2787b
 	$(CONTRIBDIR)/xxhash/xxhash.c \
d2787b
 	compound-fop-utils.c throttle-tbf.c monitoring.c
d2787b
 
d2787b
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
d2787b
index d351b93..c2dfe28 100644
d2787b
--- a/libglusterfs/src/common-utils.c
d2787b
+++ b/libglusterfs/src/common-utils.c
d2787b
@@ -860,11 +860,6 @@ gf_dump_config_flags()
d2787b
     gf_msg_plain_nomem(GF_LOG_ALERT, "setfsid 1");
d2787b
 #endif
d2787b
 
d2787b
-/* define if found spinlock */
d2787b
-#ifdef HAVE_SPINLOCK
d2787b
-    gf_msg_plain_nomem(GF_LOG_ALERT, "spinlock 1");
d2787b
-#endif
d2787b
-
d2787b
 /* Define to 1 if you have the <sys/epoll.h> header file. */
d2787b
 #ifdef HAVE_SYS_EPOLL_H
d2787b
     gf_msg_plain_nomem(GF_LOG_ALERT, "epoll.h 1");
d2787b
diff --git a/libglusterfs/src/glusterfs/locking.h b/libglusterfs/src/glusterfs/locking.h
d2787b
index 43cc877..63097bb 100644
d2787b
--- a/libglusterfs/src/glusterfs/locking.h
d2787b
+++ b/libglusterfs/src/glusterfs/locking.h
d2787b
@@ -22,55 +22,6 @@
d2787b
 #define pthread_spin_init(l, v) (*l = v)
d2787b
 #endif
d2787b
 
d2787b
-#if defined(HAVE_SPINLOCK)
d2787b
-
d2787b
-typedef union {
d2787b
-    pthread_spinlock_t spinlock;
d2787b
-    pthread_mutex_t mutex;
d2787b
-} gf_lock_t;
d2787b
-
d2787b
-#if !defined(LOCKING_IMPL)
d2787b
-extern int use_spinlocks;
d2787b
-
d2787b
-/*
d2787b
- * Using a dispatch table would be unpleasant because we're dealing with two
d2787b
- * different types.  If the dispatch contains direct pointers to pthread_xx
d2787b
- * or mutex_xxx then we have to hope that every possible union alternative
d2787b
- * starts at the same address as the union itself.  I'm old enough to remember
d2787b
- * compilers where this was not the case (for alignment reasons) so I'm a bit
d2787b
- * paranoid about that.  Also, I don't like casting arguments through "void *"
d2787b
- * which we'd also have to do to avoid type errors.  The other alternative would
d2787b
- * be to define actual functions which pick out the right union member, and put
d2787b
- * those in the dispatch tables.  Now we have a pointer dereference through the
d2787b
- * dispatch table plus a function call, which is likely to be worse than the
d2787b
- * branching here from the ?: construct.  If it were a clear win it might be
d2787b
- * worth the extra complexity, but for now this way seems preferable.
d2787b
- */
d2787b
-
d2787b
-#define LOCK_INIT(x)                                                           \
d2787b
-    (use_spinlocks ? pthread_spin_init(&((x)->spinlock), 0)                    \
d2787b
-                   : pthread_mutex_init(&((x)->mutex), 0))
d2787b
-
d2787b
-#define LOCK(x)                                                                \
d2787b
-    (use_spinlocks ? pthread_spin_lock(&((x)->spinlock))                       \
d2787b
-                   : pthread_mutex_lock(&((x)->mutex)))
d2787b
-
d2787b
-#define TRY_LOCK(x)                                                            \
d2787b
-    (use_spinlocks ? pthread_spin_trylock(&((x)->spinlock))                    \
d2787b
-                   : pthread_mutex_trylock(&((x)->mutex)))
d2787b
-
d2787b
-#define UNLOCK(x)                                                              \
d2787b
-    (use_spinlocks ? pthread_spin_unlock(&((x)->spinlock))                     \
d2787b
-                   : pthread_mutex_unlock(&((x)->mutex)))
d2787b
-
d2787b
-#define LOCK_DESTROY(x)                                                        \
d2787b
-    (use_spinlocks ? pthread_spin_destroy(&((x)->spinlock))                    \
d2787b
-                   : pthread_mutex_destroy(&((x)->mutex)))
d2787b
-
d2787b
-#endif
d2787b
-
d2787b
-#else
d2787b
-
d2787b
 typedef pthread_mutex_t gf_lock_t;
d2787b
 
d2787b
 #define LOCK_INIT(x) pthread_mutex_init(x, 0)
d2787b
@@ -79,6 +30,4 @@ typedef pthread_mutex_t gf_lock_t;
d2787b
 #define UNLOCK(x) pthread_mutex_unlock(x)
d2787b
 #define LOCK_DESTROY(x) pthread_mutex_destroy(x)
d2787b
 
d2787b
-#endif /* HAVE_SPINLOCK */
d2787b
-
d2787b
 #endif /* _LOCKING_H */
d2787b
diff --git a/libglusterfs/src/locking.c b/libglusterfs/src/locking.c
d2787b
deleted file mode 100644
d2787b
index 7577054..0000000
d2787b
--- a/libglusterfs/src/locking.c
d2787b
+++ /dev/null
d2787b
@@ -1,27 +0,0 @@
d2787b
-/*
d2787b
-  Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com>
d2787b
-  This file is part of GlusterFS.
d2787b
-
d2787b
-  This file is licensed to you under your choice of the GNU Lesser
d2787b
-  General Public License, version 3 or any later version (LGPLv3 or
d2787b
-  later), or the GNU General Public License, version 2 (GPLv2), in all
d2787b
-  cases as published by the Free Software Foundation.
d2787b
-*/
d2787b
-
d2787b
-#if defined(HAVE_SPINLOCK)
d2787b
-/* None of this matters otherwise. */
d2787b
-
d2787b
-#include <pthread.h>
d2787b
-#include <unistd.h>
d2787b
-
d2787b
-#define LOCKING_IMPL
d2787b
-#include "glusterfs/locking.h"
d2787b
-
d2787b
-int use_spinlocks = 0;
d2787b
-
d2787b
-static void __attribute__((constructor)) gf_lock_setup(void)
d2787b
-{
d2787b
-    // use_spinlocks = (sysconf(_SC_NPROCESSORS_ONLN) > 1);
d2787b
-}
d2787b
-
d2787b
-#endif
d2787b
-- 
d2787b
1.8.3.1
d2787b