Commit 73e0c116 authored by Mike Christie's avatar Mike Christie Committed by Christian Brauner (Microsoft)

kthread: Pass in the thread's name during creation

This has us pass in the thread's name during creation in kernel_thread.
Signed-off-by: default avatarMike Christie <michael.christie@oracle.com>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
parent cf587db2
...@@ -38,6 +38,7 @@ struct task_struct *kthreadd_task; ...@@ -38,6 +38,7 @@ struct task_struct *kthreadd_task;
struct kthread_create_info struct kthread_create_info
{ {
/* Information passed to kthread() from kthreadd. */ /* Information passed to kthread() from kthreadd. */
char *full_name;
int (*threadfn)(void *data); int (*threadfn)(void *data);
void *data; void *data;
int node; int node;
...@@ -343,10 +344,12 @@ static int kthread(void *_create) ...@@ -343,10 +344,12 @@ static int kthread(void *_create)
/* Release the structure when caller killed by a fatal signal. */ /* Release the structure when caller killed by a fatal signal. */
done = xchg(&create->done, NULL); done = xchg(&create->done, NULL);
if (!done) { if (!done) {
kfree(create->full_name);
kfree(create); kfree(create);
kthread_exit(-EINTR); kthread_exit(-EINTR);
} }
self->full_name = create->full_name;
self->threadfn = threadfn; self->threadfn = threadfn;
self->data = data; self->data = data;
...@@ -396,12 +399,13 @@ static void create_kthread(struct kthread_create_info *create) ...@@ -396,12 +399,13 @@ static void create_kthread(struct kthread_create_info *create)
current->pref_node_fork = create->node; current->pref_node_fork = create->node;
#endif #endif
/* We want our own signal handler (we take no signals by default). */ /* We want our own signal handler (we take no signals by default). */
pid = kernel_thread(kthread, create, NULL, pid = kernel_thread(kthread, create, create->full_name,
CLONE_FS | CLONE_FILES | SIGCHLD); CLONE_FS | CLONE_FILES | SIGCHLD);
if (pid < 0) { if (pid < 0) {
/* Release the structure when caller killed by a fatal signal. */ /* Release the structure when caller killed by a fatal signal. */
struct completion *done = xchg(&create->done, NULL); struct completion *done = xchg(&create->done, NULL);
kfree(create->full_name);
if (!done) { if (!done) {
kfree(create); kfree(create);
return; return;
...@@ -428,6 +432,11 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), ...@@ -428,6 +432,11 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
create->data = data; create->data = data;
create->node = node; create->node = node;
create->done = &done; create->done = &done;
create->full_name = kvasprintf(GFP_KERNEL, namefmt, args);
if (!create->full_name) {
task = ERR_PTR(-ENOMEM);
goto free_create;
}
spin_lock(&kthread_create_lock); spin_lock(&kthread_create_lock);
list_add_tail(&create->list, &kthread_create_list); list_add_tail(&create->list, &kthread_create_list);
...@@ -454,26 +463,7 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), ...@@ -454,26 +463,7 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
wait_for_completion(&done); wait_for_completion(&done);
} }
task = create->result; task = create->result;
if (!IS_ERR(task)) { free_create:
char name[TASK_COMM_LEN];
va_list aq;
int len;
/*
* task is already visible to other tasks, so updating
* COMM must be protected.
*/
va_copy(aq, args);
len = vsnprintf(name, sizeof(name), namefmt, aq);
va_end(aq);
if (len >= TASK_COMM_LEN) {
struct kthread *kthread = to_kthread(task);
/* leave it truncated when out of memory. */
kthread->full_name = kvasprintf(GFP_KERNEL, namefmt, args);
}
set_task_comm(task, name);
}
kfree(create); kfree(create);
return task; return task;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment