Move afs_pthread_setname_self to opr 55/13655/2
authorAndrew Deason <adeason@sinenomine.net>
Wed, 26 Jun 2019 16:47:21 +0000 (11:47 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 28 Jun 2019 15:37:32 +0000 (11:37 -0400)
Move the functionality in afs_pthread_setname_self from libutil to
opr, in a new function opr_threadname_set. This allows us to more
easily use the routine in more subsystems, since most code already
uses opr.

Change-Id: I79d49617a19cd292a3b09ccfd9c9f319355a184e
Reviewed-on: https://gerrit.openafs.org/13655
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

18 files changed:
src/budb/dbs_dump.c
src/butc/dbentries.c
src/butc/dump.c
src/butc/lwps.c
src/butc/recoverDb.c
src/butc/tcudbprocs.c
src/opr/Makefile.in
src/opr/liboafs_opr.la.sym
src/opr/opr.h
src/opr/threadname.c [moved from src/util/pthread_threadname.c with 75% similarity]
src/ubik/beacon.c
src/ubik/recovery.c
src/util/Makefile.in
src/util/afsutil_prototypes.h
src/util/liboafs_util.la.sym
src/viced/viced.c
src/vol/fssync-server.c
src/volser/volmain.c

index b1e4003..0d70837 100644 (file)
@@ -61,7 +61,7 @@ setupDbDump(void *param)
     int writeFid = (intptr_t)param;
     afs_int32 code = 0;
 
-    afs_pthread_setname_self("Database Dumper");
+    opr_threadname_set("Database Dumper");
     code = InitRPC(&dumpSyncPtr->ut, LOCKREAD, 1);
     if (code)
        goto error_exit;
@@ -327,7 +327,7 @@ dumpWatcher(void *unused)
 {
     afs_int32 code;
 
-    afs_pthread_setname_self("Database Dump Watchdog");
+    opr_threadname_set("Database Dump Watchdog");
     while (1) {                        /*w */
 
        /* printf("dumpWatcher\n"); */
index 37b35d3..762105b 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <roken.h>
 
+#include <afs/opr.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <lwp.h>
@@ -328,7 +329,7 @@ dbWatcher(void *unused)
     afs_int32 code = 0;
     int i, c, addedDump;
 
-    afs_pthread_setname_self("dbWatcher");
+    opr_threadname_set("dbWatcher");
     dlqInit(&entries_to_flush);
     dlqInit(&savedEntries);
 
index 1f4eb9b..92c1078 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <roken.h>
 
+#include <afs/opr.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <lwp.h>
@@ -1116,7 +1117,7 @@ Dumper(void *param)
     extern struct deviceSyncNode *deviceLatch;
     extern struct tapeConfig globalTapeConfig;
 
-    afs_pthread_setname_self("dumper");
+    opr_threadname_set("dumper");
     taskId = nodePtr->taskID;  /* Get task Id */
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
@@ -2033,7 +2034,7 @@ DeleteDump(void *param)
     dumpid = ptr->dumpID;
     taskId = ptr->taskId;      /* Get task Id */
 
-    afs_pthread_setname_self("deletedump");
+    opr_threadname_set("deletedump");
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
     clearStatus(taskId, DRIVE_WAIT);
index d262991..82b61be 100644 (file)
@@ -1636,7 +1636,7 @@ Restorer(void *param) {
     time_t startTime, endTime;
     afs_int32 goodrestore = 0;
 
-    afs_pthread_setname_self("restorer");
+    opr_threadname_set("restorer");
     taskId = newNode->taskID;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
@@ -2102,7 +2102,7 @@ Labeller(void *param)
     afs_uint32 taskId;
     afs_int32 code = 0;
 
-    afs_pthread_setname_self("labeller");
+    opr_threadname_set("labeller");
     taskId = labelIfPtr->taskId;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
index b1f5c90..073fa24 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <roken.h>
 
+#include <afs/opr.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <lwp.h>
@@ -706,7 +707,7 @@ ScanDumps(void *param)
     afs_uint32 taskId;
     afs_int32 code = 0;
 
-    afs_pthread_setname_self("scandump");
+    opr_threadname_set("scandump");
     taskId = ptr->taskId;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
index b9ecf49..5cd6c32 100644 (file)
@@ -641,7 +641,7 @@ saveDbToTape(void *param)
     extern struct deviceSyncNode *deviceLatch;
     extern struct tapeConfig globalTapeConfig;
 
-    afs_pthread_setname_self("Db save");
+    opr_threadname_set("Db save");
     expires = (saveDbIfPtr->archiveTime ? NEVERDATE : 0);
     taskId = saveDbIfPtr->taskId;
     dumpEntry.id = 0;
@@ -1022,7 +1022,7 @@ restoreDbFromTape(void *param)
     extern struct tapeConfig globalTapeConfig;
     extern struct deviceSyncNode *deviceLatch;
 
-    afs_pthread_setname_self("Db restore");
+    opr_threadname_set("Db restore");
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);     /* lock tape device */
     clearStatus(taskId, DRIVE_WAIT);
@@ -1120,7 +1120,7 @@ KeepAlive(void *unused)
 
     extern struct udbHandleS udbHandle;
 
-    afs_pthread_setname_self("Keep-alive");
+    opr_threadname_set("Keep-alive");
     while (1) {
 #ifdef AFS_PTHREAD_ENV
        sleep(5);
index 1067117..968f6e5 100644 (file)
@@ -3,7 +3,8 @@ include @TOP_OBJDIR@/src/config/Makefile.config
 include @TOP_OBJDIR@/src/config/Makefile.pthread
 include @TOP_OBJDIR@/src/config/Makefile.libtool
 
-LT_objs = assert.lo casestrcpy.lo dict.lo fmt.lo proc.lo rbtree.lo softsig.lo uuid.lo
+LT_objs = assert.lo casestrcpy.lo dict.lo fmt.lo proc.lo rbtree.lo \
+         softsig.lo threadname.lo uuid.lo
 LT_libs = $(LIB_hcrypto) $(LIB_roken)
 
 HEADERS = $(TOP_INCDIR)/afs/opr.h \
index bf24b60..2a0cc2c 100644 (file)
@@ -14,6 +14,7 @@ opr_rbtree_replace
 opr_stolower
 opr_stoupper
 opr_strcompose
+opr_threadname_set
 opr_ucstring
 opr_softsig_Init
 opr_softsig_Register
index bf4b817..d39ca87 100644 (file)
@@ -74,4 +74,16 @@ extern void opr_stolower(char *s) AFS_NONNULL((1));
 extern void opr_stoupper(char *s) AFS_NONNULL((1));
 extern char *opr_strcompose(char *buf, size_t len, ...) AFS_NONNULL((1));
 
+/* threadname.c */
+
+#ifdef AFS_PTHREAD_ENV
+extern void opr_threadname_set(const char *threadname);
+#else
+static_inline void
+opr_threadname_set(const char *threadname)
+{
+    /* noop */
+}
+#endif
+
 #endif
similarity index 75%
rename from src/util/pthread_threadname.c
rename to src/opr/threadname.c
index b085b4a..c963cbf 100644 (file)
@@ -26,7 +26,7 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-#include "afsutil.h"
+#include <afs/opr.h>
 
 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
 # include <pthread.h>
 # endif
 
 void
-afs_pthread_setname_self(const char *threadname)
+opr_threadname_set(const char *threadname)
 {
 # if defined(HAVE_PTHREAD_SET_NAME_NP)
-       /* FreeBSD style */
-       pthread_set_name_np(pthread_self(), threadname);
+    /* FreeBSD style */
+    pthread_set_name_np(pthread_self(), threadname);
 # elif defined(HAVE_PTHREAD_SETNAME_NP)
 #  if PTHREAD_SETNAME_NP_ARGS == 3
-       /* DECthreads style */
-       pthread_setname_np(pthread_self(), threadname, (void *)0);
+    /* DECthreads style */
+    pthread_setname_np(pthread_self(), threadname, (void *)0);
 #  elif PTHREAD_SETNAME_NP_ARGS == 2
-       /* GNU libc on Linux style */
-       pthread_setname_np(pthread_self(), threadname);
+    /* GNU libc on Linux style */
+    pthread_setname_np(pthread_self(), threadname);
 #  elif PTHREAD_SETNAME_NP_ARGS == 1
-       /* Mac OS style */
-       pthread_setname_np(threadname);
+    /* Mac OS style */
+    pthread_setname_np(threadname);
 #  else
-#    error "Could not identify your pthread_setname_np() implementation"
-#  endif
-# endif
+#   error "Could not identify your pthread_setname_np() implementation"
+#  endif /* PTHREAD_SETNAME_NP_ARGS */
+# endif /* HAVE_PTHREAD_SETNAME_NP */
 }
-#endif
+#endif /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
index fb6dafb..1642f22 100644 (file)
@@ -445,7 +445,7 @@ ubeacon_Interact(void *dummy)
     struct ubik_version tversion;
     afs_int32 startTime;
 
-    afs_pthread_setname_self("beacon");
+    opr_threadname_set("beacon");
 
     /* loop forever getting votes */
     lastWakeupTime = 0;                /* keep track of time we last started a vote collection */
index 1936d5d..5e42b54 100644 (file)
@@ -460,7 +460,7 @@ urecovery_Interact(void *dummy)
     int fd = -1;
     afs_int32 pass;
 
-    afs_pthread_setname_self("recovery");
+    opr_threadname_set("recovery");
 
     /* otherwise, begin interaction */
     urecovery_state = 0;
index 5509e6f..d1fcbae 100644 (file)
@@ -19,7 +19,7 @@ LT_objs =$(LT_rpc_objs) \
         hputil.lo kreltime.lo uuid.lo serverLog.lo \
         dirpath.lo fileutil.lo flipbase64.lo fstab.lo \
         afs_atomlist.lo afs_lhash.lo pthread_glock.lo tabular_output.lo \
-        pthread_threadname.lo ${REGEX_OBJ}
+        ${REGEX_OBJ}
 
 LT_deps = $(top_builddir)/src/opr/liboafs_opr.la
 LT_libs = $(LIB_roken) $(MT_LIBS)
index d2ea5a9..bea842c 100644 (file)
@@ -105,16 +105,6 @@ extern afs_int32 ktime_InterpretDate(struct ktime_date *akdate);
 /* pthread_glock.c */
 
 
-/* pthread_threadname.c */
-#if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
-extern void afs_pthread_setname_self(const char *threadname);
-#else
-/* Allow unconditional references to afs_pthread_setname_self to
- * reduce #ifdef spaghetti.
- */
-#define afs_pthread_setname_self(threadname) (void)0
-#endif
-
 /* readdir_nt.c */
 
 
index 07a280d..1d2de7c 100644 (file)
@@ -19,7 +19,6 @@ afsUUID_to_string
 afs_htonuuid
 afs_inet_ntoa_r
 afs_ntohuuid
-afs_pthread_setname_self
 afs_uuid_create
 afs_uuid_equal
 afs_uuid_hash
index 55c35df..a8c8712 100644 (file)
@@ -377,7 +377,7 @@ setThreadId(char *s)
 
     /* set our 'thread-id' so that the host hold table works */
     threadId = rx_SetThreadNum();
-    afs_pthread_setname_self(s);
+    opr_threadname_set(s);
     ViceLog(0, ("Set thread id 0x%x for '%s'\n", threadId, s));
 #endif
 }
@@ -682,7 +682,7 @@ PrintCounters(void)
 static void *
 ShutdownWatchdogLWP(void *unused)
 {
-    afs_pthread_setname_self("ShutdownWatchdog");
+    opr_threadname_set("ShutdownWatchdog");
     sleep(panic_timeout);
     ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
                          "within %d seconds; forcing panic\n",
index 2d7cd60..bd39366 100644 (file)
@@ -261,7 +261,7 @@ FSYNC_sync(void * args)
     /* set our 'thread-id' so that the host hold table works */
     tid = rx_SetThreadNum();
     Log("Set thread id %d for FSYNC_sync\n", tid);
-    afs_pthread_setname_self("FSYNC_sync");
+    opr_threadname_set("FSYNC_sync");
 #endif /* AFS_PTHREAD_ENV */
 
     VOL_LOCK;
index ed69bd2..d275659 100644 (file)
@@ -134,7 +134,7 @@ BKGLoop(void *unused)
     struct timeval tv;
     int loop = 0;
 
-    afs_pthread_setname_self("vol bkg");
+    opr_threadname_set("vol bkg");
     while (1) {
        tv.tv_sec = GCWAKEUP;
        tv.tv_usec = 0;