diff options
Diffstat (limited to 'libglusterfs/src')
| -rw-r--r-- | libglusterfs/src/common-utils.c | 27 | ||||
| -rw-r--r-- | libglusterfs/src/common-utils.h | 11 | ||||
| -rw-r--r-- | libglusterfs/src/event-epoll.c | 18 | ||||
| -rw-r--r-- | libglusterfs/src/libglusterfs-messages.h | 11 | ||||
| -rw-r--r-- | libglusterfs/src/mem-pool.c | 5 | ||||
| -rw-r--r-- | libglusterfs/src/syncop.c | 12 | ||||
| -rw-r--r-- | libglusterfs/src/throttle-tbf.c | 2 | ||||
| -rw-r--r-- | libglusterfs/src/timer.c | 2 | 
8 files changed, 71 insertions, 17 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 1adb0bd5a81..ec1d5c4823c 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3725,10 +3725,15 @@ gf_thread_cleanup_xint (pthread_t thread)  int  gf_thread_create (pthread_t *thread, const pthread_attr_t *attr, -                  void *(*start_routine)(void *), void *arg) +                  void *(*start_routine)(void *), void *arg, const char *name)  {          sigset_t set, old;          int ret; +        char thread_name[GF_THREAD_NAMEMAX+GF_THREAD_NAME_PREFIX_LEN] = {0,}; +        /* Max name on Linux is 16 and on NetBSD is 32 +         * All Gluster threads have a set prefix of gluster and hence the limit +         * of 9 on GF_THREAD_NAMEMAX including the null character. +         */          sigemptyset (&old);          sigfillset (&set); @@ -3742,6 +3747,21 @@ gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,          pthread_sigmask (SIG_BLOCK, &set, &old);          ret = pthread_create (thread, attr, start_routine, arg); +        snprintf (thread_name, sizeof(thread_name), "%s%s", +                  GF_THREAD_NAME_PREFIX, name); + +        if (0 == ret && name) { +                #ifdef GF_LINUX_HOST_OS +                        pthread_setname_np(*thread, thread_name); +                #elif defined(__NetBSD__) +                        pthread_setname_np(*thread, thread_name, NULL); +                #else +                        gf_msg (THIS->name, GF_LOG_WARNING, 0, +                                LG_MSG_PTHREAD_NAMING_FAILED, +                                "Thread names not implemented on this ", +                                "platform"); +                #endif +        }          pthread_sigmask (SIG_SETMASK, &old, NULL); @@ -3750,7 +3770,8 @@ gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,  int  gf_thread_create_detached (pthread_t *thread, -                         void *(*start_routine)(void *), void *arg) +                         void *(*start_routine)(void *), void *arg, +                         const char *name)  {          pthread_attr_t attr;          int ret = -1; @@ -3765,7 +3786,7 @@ gf_thread_create_detached (pthread_t *thread,          pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); -        ret = gf_thread_create (thread, &attr, start_routine, arg); +        ret = gf_thread_create (thread, &attr, start_routine, arg, name);          if (ret) {                  gf_msg (THIS->name, GF_LOG_ERROR, ret,                          LG_MSG_PTHREAD_FAILED, diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index f1625e446cb..1d7f09dbc82 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -130,6 +130,11 @@ void trap (void);  #define GF_PERCENTAGE(val, total) (((val)*100)/(total)) +/* pthread related */ +#define GF_THREAD_NAMEMAX 9 +#define GF_THREAD_NAME_PREFIX "gluster" +#define GF_THREAD_NAME_PREFIX_LEN 7 +  enum _gf_boolean  {  	_gf_false = 0, @@ -832,9 +837,11 @@ void gf_xxh64_wrapper(const unsigned char *data, size_t len,  int gf_set_timestamp  (const char *src, const char* dest);  int gf_thread_create (pthread_t *thread, const pthread_attr_t *attr, -                      void *(*start_routine)(void *), void *arg); +                      void *(*start_routine)(void *), void *arg, +                      const char *name);  int gf_thread_create_detached (pthread_t *thread, -                      void *(*start_routine)(void *), void *arg); +                      void *(*start_routine)(void *), void *arg, +                      const char *name);  gf_boolean_t  gf_is_pid_running (int pid);  gf_boolean_t diff --git a/libglusterfs/src/event-epoll.c b/libglusterfs/src/event-epoll.c index eac1f058b15..d32f1dda9d0 100644 --- a/libglusterfs/src/event-epoll.c +++ b/libglusterfs/src/event-epoll.c @@ -663,6 +663,7 @@ event_dispatch_epoll (struct event_pool *event_pool)          int                       pollercount = 0;  	int                       ret = -1;          struct event_thread_data *ev_data = NULL; +        char                      thread_name[GF_THREAD_NAMEMAX] = {0,};          /* Start the configured number of pollers */          pthread_mutex_lock (&event_pool->mutex); @@ -697,9 +698,11 @@ event_dispatch_epoll (struct event_pool *event_pool)                          ev_data->event_pool = event_pool;                          ev_data->event_index = i + 1; -                        ret = pthread_create (&t_id, NULL, -                                              event_dispatch_epoll_worker, -                                              ev_data); +                        snprintf (thread_name, sizeof(thread_name), +                                  "%s%d", "epoll", i); +                        ret = gf_thread_create (&t_id, NULL, +                                                event_dispatch_epoll_worker, +                                                ev_data, thread_name);                          if (!ret) {                                  event_pool->pollers[i] = t_id; @@ -765,6 +768,7 @@ event_reconfigure_threads_epoll (struct event_pool *event_pool, int value)          pthread_t                        t_id;          int                              oldthreadcount;          struct event_thread_data        *ev_data = NULL; +        char                             thread_name[GF_THREAD_NAMEMAX] = {0,};          pthread_mutex_lock (&event_pool->mutex);          { @@ -805,9 +809,13 @@ event_reconfigure_threads_epoll (struct event_pool *event_pool, int value)                                          ev_data->event_pool = event_pool;                                          ev_data->event_index = i + 1; -                                        ret = pthread_create (&t_id, NULL, +                                        snprintf (thread_name, +                                                  sizeof(thread_name), +                                                  "%s%d", +                                                  "epoll", i); +                                        ret = gf_thread_create (&t_id, NULL,                                                  event_dispatch_epoll_worker, -                                                ev_data); +                                                ev_data, thread_name);                                          if (ret) {                                                  gf_msg ("epoll", GF_LOG_WARNING,                                                          0, diff --git a/libglusterfs/src/libglusterfs-messages.h b/libglusterfs/src/libglusterfs-messages.h index 23ed7b727d3..dd657013257 100644 --- a/libglusterfs/src/libglusterfs-messages.h +++ b/libglusterfs/src/libglusterfs-messages.h @@ -37,7 +37,7 @@  #define GLFS_LG_BASE            GLFS_MSGID_COMP_LIBGLUSTERFS -#define GLFS_LG_NUM_MESSAGES    210 +#define GLFS_LG_NUM_MESSAGES    211  #define GLFS_LG_MSGID_END       (GLFS_LG_BASE + GLFS_LG_NUM_MESSAGES + 1)  /* Messaged with message IDs */ @@ -1800,6 +1800,15 @@   * @recommendedaction   *   */ + +#define LG_MSG_PTHREAD_NAMING_FAILED                     (GLFS_LG_BASE + 211) + +/*! + * @messageid + * @diagnosis + * @recommendedaction + * + */  /*------------*/  #define glfs_msg_end_lg GLFS_LG_MSGID_END, "Invalid: End of messages" diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 456eb68c060..343771e38a1 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -551,7 +551,8 @@ mem_pools_init (void)  {          pthread_mutex_lock (&init_mutex);          if ((init_count++) == 0) { -                (void) pthread_create (&sweeper_tid, NULL, pool_sweeper, NULL); +                (void) gf_thread_create (&sweeper_tid, NULL, pool_sweeper, +                                         NULL, "memsweep");          }          pthread_mutex_unlock (&init_mutex);  } @@ -586,7 +587,7 @@ mem_pools_fini (void)  void mem_pools_init (void) {}  void mem_pools_fini (void) {}  #endif -  +  struct mem_pool *  mem_pool_new_fn (unsigned long sizeof_type,                   unsigned long count, char *name) diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 544cfdc011a..b36c88dc829 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -712,6 +712,7 @@ syncenv_scale (struct syncenv *env)          int  scale = 0;          int  i = 0;          int  ret = 0; +        char thread_name[GF_THREAD_NAMEMAX] = {0,};          pthread_mutex_lock (&env->mutex);          { @@ -731,8 +732,11 @@ syncenv_scale (struct syncenv *env)                          }                          env->proc[i].env = env; +                        snprintf (thread_name, sizeof(thread_name), +                                  "%s%d", "sproc", env->procs);                          ret = gf_thread_create (&env->proc[i].processor, NULL, -						syncenv_processor, &env->proc[i]); +                                                syncenv_processor, +                                                &env->proc[i], thread_name);                          if (ret)                                  break;                          env->procs++; @@ -796,6 +800,7 @@ syncenv_new (size_t stacksize, int procmin, int procmax)          struct syncenv *newenv = NULL;          int             ret = 0;          int             i = 0; +        char            thread_name[GF_THREAD_NAMEMAX] = {0,};  	if (!procmin || procmin < 0)  		procmin = SYNCENV_PROC_MIN; @@ -824,8 +829,11 @@ syncenv_new (size_t stacksize, int procmin, int procmax)          for (i = 0; i < newenv->procmin; i++) {                  newenv->proc[i].env = newenv; +                snprintf (thread_name, sizeof(thread_name), +                          "%s%d", "sproc", (newenv->procs));                  ret = gf_thread_create (&newenv->proc[i].processor, NULL, -					syncenv_processor, &newenv->proc[i]); +                                        syncenv_processor, &newenv->proc[i], +                                        thread_name);                  if (ret)                          break;                  newenv->procs++; diff --git a/libglusterfs/src/throttle-tbf.c b/libglusterfs/src/throttle-tbf.c index 16630a243c2..a425166b681 100644 --- a/libglusterfs/src/throttle-tbf.c +++ b/libglusterfs/src/throttle-tbf.c @@ -150,7 +150,7 @@ tbf_init_bucket (tbf_t *tbf, tbf_opspec_t *spec)          curr->token_gen_interval = spec->token_gen_interval;          ret = gf_thread_create (&curr->tokener, -                                NULL, tbf_tokengenerator, curr); +                                NULL, tbf_tokengenerator, curr, "tbfclock");          if (ret != 0)                  goto freemem; diff --git a/libglusterfs/src/timer.c b/libglusterfs/src/timer.c index a24a07804a8..3d69a9f7160 100644 --- a/libglusterfs/src/timer.c +++ b/libglusterfs/src/timer.c @@ -217,7 +217,7 @@ gf_timer_registry_init (glusterfs_ctx_t *ctx)                  INIT_LIST_HEAD (®->active);          }          UNLOCK (&ctx->lock); -        gf_thread_create (®->th, NULL, gf_timer_proc, reg); +        gf_thread_create (®->th, NULL, gf_timer_proc, reg, "timer");  out:          return reg;  }  | 
