thread: Use not malloc'ed but fixed size string for thread name
256 bytes will be enough but not too large for the name of SPDK thread. Use fixed size string for the name of SPDK thread and reduce the potential malloc failure. If the length of passed name is longer then 256, it will be cut off without error. Change-Id: I13a24997a73a8365c8bf5e093f2bd78861ba6660 Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459720 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
parent
404d27263f
commit
09013306c3
@ -43,6 +43,7 @@
|
|||||||
#include "spdk_internal/thread.h"
|
#include "spdk_internal/thread.h"
|
||||||
|
|
||||||
#define SPDK_MSG_BATCH_SIZE 8
|
#define SPDK_MSG_BATCH_SIZE 8
|
||||||
|
#define SPDK_MAX_THREAD_NAME_LEN 256
|
||||||
|
|
||||||
static pthread_mutex_t g_devlist_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t g_devlist_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ struct spdk_poller {
|
|||||||
struct spdk_thread {
|
struct spdk_thread {
|
||||||
TAILQ_HEAD(, spdk_io_channel) io_channels;
|
TAILQ_HEAD(, spdk_io_channel) io_channels;
|
||||||
TAILQ_ENTRY(spdk_thread) tailq;
|
TAILQ_ENTRY(spdk_thread) tailq;
|
||||||
char *name;
|
char name[SPDK_MAX_THREAD_NAME_LEN + 1];
|
||||||
|
|
||||||
bool exit;
|
bool exit;
|
||||||
|
|
||||||
@ -227,7 +228,6 @@ _free_thread(struct spdk_thread *thread)
|
|||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
pthread_mutex_unlock(&g_devlist_mutex);
|
||||||
|
|
||||||
spdk_cpuset_free(thread->cpumask);
|
spdk_cpuset_free(thread->cpumask);
|
||||||
free(thread->name);
|
|
||||||
|
|
||||||
msg = SLIST_FIRST(&thread->msg_cache);
|
msg = SLIST_FIRST(&thread->msg_cache);
|
||||||
while (msg != NULL) {
|
while (msg != NULL) {
|
||||||
@ -300,9 +300,9 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
thread->name = strdup(name);
|
snprintf(thread->name, sizeof(thread->name), "%s", name);
|
||||||
} else {
|
} else {
|
||||||
thread->name = spdk_sprintf_alloc("%p", thread);
|
snprintf(thread->name, sizeof(thread->name), "%p", thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Allocating new thread %s\n", thread->name);
|
SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Allocating new thread %s\n", thread->name);
|
||||||
|
Loading…
Reference in New Issue
Block a user