From 4674678951a1315975d66016fb55c49100b7819f Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Thu, 24 Jan 2019 18:31:10 +0100 Subject: core: make gf_thread_create() easier to use This patch creates a specific function to set the thread name using a string format and a variable argument list, like printf(). This function is used to set the thread name from gf_thread_create(), which now accepts a variable argument list to create the full name. It's not necessary anymore to use a local array to build the name of the thread. This is done automatically. Change-Id: Idd8d01fd462c227359b96e98699f8c6d962dc17c Updates: bz#1193929 Signed-off-by: Xavi Hernandez --- xlators/cluster/dht/src/dht-rebalance.c | 7 +------ xlators/features/changelog/lib/src/gf-history-changelog.c | 7 +------ xlators/features/changelog/src/changelog-rpc.c | 7 ++----- xlators/performance/io-threads/src/io-threads.c | 7 +------ 4 files changed, 5 insertions(+), 23 deletions(-) (limited to 'xlators') diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index 46acc77c4b0..e0f25b1d080 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -4436,9 +4436,6 @@ gf_defrag_parallel_migration_init(xlator_t *this, gf_defrag_info_t *defrag, int thread_spawn_count = 0; int index = 0; pthread_t *tid = NULL; - char thread_name[GF_THREAD_NAMEMAX] = { - 0, - }; if (!defrag) goto out; @@ -4472,10 +4469,8 @@ gf_defrag_parallel_migration_init(xlator_t *this, gf_defrag_info_t *defrag, /*Spawn Threads Here*/ while (index < thread_spawn_count) { - snprintf(thread_name, sizeof(thread_name), "dhtmig%d", - ((index + 1) & 0x3ff)); ret = gf_thread_create(&(tid[index]), NULL, &gf_defrag_task, - (void *)defrag, thread_name); + (void *)defrag, "dhtmig%d", (index + 1) & 0x3ff); if (ret != 0) { gf_msg("DHT", GF_LOG_ERROR, ret, 0, "Thread[%d] creation failed. ", index); diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c index 3e384ea0784..3d5fc8c8573 100644 --- a/xlators/features/changelog/lib/src/gf-history-changelog.c +++ b/xlators/features/changelog/lib/src/gf-history-changelog.c @@ -564,9 +564,6 @@ gf_history_consume(void *data) {0}, }; gf_changelog_consume_data_t *curr = NULL; - char thread_name[GF_THREAD_NAMEMAX] = { - 0, - }; hist_data = (gf_changelog_history_data_t *)data; if (hist_data == NULL) { @@ -612,12 +609,10 @@ gf_history_consume(void *data) curr->retval = 0; memset(curr->changelog, '\0', PATH_MAX); - snprintf(thread_name, sizeof(thread_name), "clogc%03hx", - ((iter + 1) & 0x3ff)); ret = gf_thread_create(&th_id[iter], NULL, gf_changelog_consume_wrap, curr, - thread_name); + "clogc%03hx", (iter + 1) & 0x3ff); if (ret) { gf_msg(this->name, GF_LOG_ERROR, ret, CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED, diff --git a/xlators/features/changelog/src/changelog-rpc.c b/xlators/features/changelog/src/changelog-rpc.c index 28974fe0999..c29c8ea345a 100644 --- a/xlators/features/changelog/src/changelog-rpc.c +++ b/xlators/features/changelog/src/changelog-rpc.c @@ -69,9 +69,6 @@ changelog_init_rpc_threads(xlator_t *this, changelog_priv_t *priv, rbuf_t *rbuf, int j = 0; int ret = 0; changelog_clnt_t *conn = NULL; - char thread_name[GF_THREAD_NAMEMAX] = { - 0, - }; conn = &priv->connections; @@ -111,9 +108,9 @@ changelog_init_rpc_threads(xlator_t *this, changelog_priv_t *priv, rbuf_t *rbuf, /* spawn dispatcher threads */ for (; j < nr_dispatchers; j++) { - snprintf(thread_name, sizeof(thread_name), "clogd%03hx", (j & 0x3ff)); ret = gf_thread_create(&priv->ev_dispatcher[j], NULL, - changelog_ev_dispatch, conn, thread_name); + changelog_ev_dispatch, conn, "clogd%03hx", + j & 0x3ff); if (ret != 0) { changelog_cleanup_dispatchers(this, priv, j); break; diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index dbf8e8f6a70..bf75015eda8 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -813,9 +813,6 @@ __iot_workers_scale(iot_conf_t *conf) pthread_t thread; int ret = 0; int i = 0; - char thread_name[GF_THREAD_NAMEMAX] = { - 0, - }; for (i = 0; i < GF_FOP_PRI_MAX; i++) scale += min(conf->queue_sizes[i], conf->ac_iot_limit[i]); @@ -833,10 +830,8 @@ __iot_workers_scale(iot_conf_t *conf) while (diff) { diff--; - snprintf(thread_name, sizeof(thread_name), "iotwr%03hx", - (conf->curr_count & 0x3ff)); ret = gf_thread_create(&thread, &conf->w_attr, iot_worker, conf, - thread_name); + "iotwr%03hx", conf->curr_count & 0x3ff); if (ret == 0) { conf->curr_count++; gf_msg_debug(conf->this->name, 0, -- cgit