提交 bed879ae 编写于 作者: P Philipp Reisner

drbd: Moved the thread name into the data structure

Signed-off-by: NPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: NLars Ellenberg <lars.ellenberg@linbit.com>
上级 b8907339
...@@ -119,13 +119,9 @@ static void __bm_print_lock_info(struct drbd_conf *mdev, const char *func) ...@@ -119,13 +119,9 @@ static void __bm_print_lock_info(struct drbd_conf *mdev, const char *func)
if (!__ratelimit(&drbd_ratelimit_state)) if (!__ratelimit(&drbd_ratelimit_state))
return; return;
dev_err(DEV, "FIXME %s in %s, bitmap locked for '%s' by %s\n", dev_err(DEV, "FIXME %s in %s, bitmap locked for '%s' by %s\n",
current == mdev->tconn->receiver.task ? "receiver" : drbd_task_to_thread_name(mdev, current),
current == mdev->tconn->asender.task ? "asender" : func, b->bm_why ?: "?",
current == mdev->tconn->worker.task ? "worker" : current->comm, drbd_task_to_thread_name(mdev, b->bm_task));
func, b->bm_why ?: "?",
b->bm_task == mdev->tconn->receiver.task ? "receiver" :
b->bm_task == mdev->tconn->asender.task ? "asender" :
b->bm_task == mdev->tconn->worker.task ? "worker" : "?");
} }
void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags) void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags)
...@@ -142,13 +138,9 @@ void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags) ...@@ -142,13 +138,9 @@ void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags)
if (trylock_failed) { if (trylock_failed) {
dev_warn(DEV, "%s going to '%s' but bitmap already locked for '%s' by %s\n", dev_warn(DEV, "%s going to '%s' but bitmap already locked for '%s' by %s\n",
current == mdev->tconn->receiver.task ? "receiver" : drbd_task_to_thread_name(mdev, current),
current == mdev->tconn->asender.task ? "asender" : why, b->bm_why ?: "?",
current == mdev->tconn->worker.task ? "worker" : current->comm, drbd_task_to_thread_name(mdev, b->bm_task));
why, b->bm_why ?: "?",
b->bm_task == mdev->tconn->receiver.task ? "receiver" :
b->bm_task == mdev->tconn->asender.task ? "asender" :
b->bm_task == mdev->tconn->worker.task ? "worker" : "?");
mutex_lock(&b->bm_change); mutex_lock(&b->bm_change);
} }
if (BM_LOCKED_MASK & b->bm_flags) if (BM_LOCKED_MASK & b->bm_flags)
......
...@@ -616,6 +616,7 @@ struct drbd_thread { ...@@ -616,6 +616,7 @@ struct drbd_thread {
int (*function) (struct drbd_thread *); int (*function) (struct drbd_thread *);
struct drbd_conf *mdev; struct drbd_conf *mdev;
int reset_cpu_mask; int reset_cpu_mask;
char name[9];
}; };
static inline enum drbd_thread_state get_t_state(struct drbd_thread *thi) static inline enum drbd_thread_state get_t_state(struct drbd_thread *thi)
...@@ -1130,6 +1131,7 @@ enum dds_flags { ...@@ -1130,6 +1131,7 @@ enum dds_flags {
extern void drbd_init_set_defaults(struct drbd_conf *mdev); extern void drbd_init_set_defaults(struct drbd_conf *mdev);
extern int drbd_thread_start(struct drbd_thread *thi); extern int drbd_thread_start(struct drbd_thread *thi);
extern void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait); extern void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait);
extern char *drbd_task_to_thread_name(struct drbd_conf *mdev, struct task_struct *task);
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
extern void drbd_thread_current_set_cpu(struct drbd_conf *mdev); extern void drbd_thread_current_set_cpu(struct drbd_conf *mdev);
extern void drbd_calc_cpu_mask(struct drbd_conf *mdev); extern void drbd_calc_cpu_mask(struct drbd_conf *mdev);
......
...@@ -462,7 +462,7 @@ static int drbd_thread_setup(void *arg) ...@@ -462,7 +462,7 @@ static int drbd_thread_setup(void *arg)
*/ */
if (thi->t_state == RESTARTING) { if (thi->t_state == RESTARTING) {
dev_info(DEV, "Restarting %s\n", current->comm); dev_info(DEV, "Restarting %s thread\n", thi->name);
thi->t_state = RUNNING; thi->t_state = RUNNING;
spin_unlock_irqrestore(&thi->t_lock, flags); spin_unlock_irqrestore(&thi->t_lock, flags);
goto restart; goto restart;
...@@ -482,13 +482,14 @@ static int drbd_thread_setup(void *arg) ...@@ -482,13 +482,14 @@ static int drbd_thread_setup(void *arg)
} }
static void drbd_thread_init(struct drbd_conf *mdev, struct drbd_thread *thi, static void drbd_thread_init(struct drbd_conf *mdev, struct drbd_thread *thi,
int (*func) (struct drbd_thread *)) int (*func) (struct drbd_thread *), char *name)
{ {
spin_lock_init(&thi->t_lock); spin_lock_init(&thi->t_lock);
thi->task = NULL; thi->task = NULL;
thi->t_state = NONE; thi->t_state = NONE;
thi->function = func; thi->function = func;
thi->mdev = mdev; thi->mdev = mdev;
strncpy(thi->name, name, ARRAY_SIZE(thi->name));
} }
int drbd_thread_start(struct drbd_thread *thi) int drbd_thread_start(struct drbd_thread *thi)
...@@ -497,11 +498,6 @@ int drbd_thread_start(struct drbd_thread *thi) ...@@ -497,11 +498,6 @@ int drbd_thread_start(struct drbd_thread *thi)
struct task_struct *nt; struct task_struct *nt;
unsigned long flags; unsigned long flags;
const char *me =
thi == &mdev->tconn->receiver ? "receiver" :
thi == &mdev->tconn->asender ? "asender" :
thi == &mdev->tconn->worker ? "worker" : "NONSENSE";
/* is used from state engine doing drbd_thread_stop_nowait, /* is used from state engine doing drbd_thread_stop_nowait,
* while holding the req lock irqsave */ * while holding the req lock irqsave */
spin_lock_irqsave(&thi->t_lock, flags); spin_lock_irqsave(&thi->t_lock, flags);
...@@ -509,7 +505,7 @@ int drbd_thread_start(struct drbd_thread *thi) ...@@ -509,7 +505,7 @@ int drbd_thread_start(struct drbd_thread *thi)
switch (thi->t_state) { switch (thi->t_state) {
case NONE: case NONE:
dev_info(DEV, "Starting %s thread (from %s [%d])\n", dev_info(DEV, "Starting %s thread (from %s [%d])\n",
me, current->comm, current->pid); thi->name, current->comm, current->pid);
/* Get ref on module for thread - this is released when thread exits */ /* Get ref on module for thread - this is released when thread exits */
if (!try_module_get(THIS_MODULE)) { if (!try_module_get(THIS_MODULE)) {
...@@ -526,7 +522,7 @@ int drbd_thread_start(struct drbd_thread *thi) ...@@ -526,7 +522,7 @@ int drbd_thread_start(struct drbd_thread *thi)
flush_signals(current); /* otherw. may get -ERESTARTNOINTR */ flush_signals(current); /* otherw. may get -ERESTARTNOINTR */
nt = kthread_create(drbd_thread_setup, (void *) thi, nt = kthread_create(drbd_thread_setup, (void *) thi,
"drbd%d_%s", mdev_to_minor(mdev), me); "drbd%d_%s", mdev_to_minor(mdev), thi->name);
if (IS_ERR(nt)) { if (IS_ERR(nt)) {
dev_err(DEV, "Couldn't start thread\n"); dev_err(DEV, "Couldn't start thread\n");
...@@ -543,7 +539,7 @@ int drbd_thread_start(struct drbd_thread *thi) ...@@ -543,7 +539,7 @@ int drbd_thread_start(struct drbd_thread *thi)
case EXITING: case EXITING:
thi->t_state = RESTARTING; thi->t_state = RESTARTING;
dev_info(DEV, "Restarting %s thread (from %s [%d])\n", dev_info(DEV, "Restarting %s thread (from %s [%d])\n",
me, current->comm, current->pid); thi->name, current->comm, current->pid);
/* fall through */ /* fall through */
case RUNNING: case RUNNING:
case RESTARTING: case RESTARTING:
...@@ -592,6 +588,23 @@ void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait) ...@@ -592,6 +588,23 @@ void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait)
wait_for_completion(&thi->stop); wait_for_completion(&thi->stop);
} }
static struct drbd_thread *drbd_task_to_thread(struct drbd_conf *mdev, struct task_struct *task)
{
struct drbd_tconn *tconn = mdev->tconn;
struct drbd_thread *thi =
task == tconn->receiver.task ? &tconn->receiver :
task == tconn->asender.task ? &tconn->asender :
task == tconn->worker.task ? &tconn->worker : NULL;
return thi;
}
char *drbd_task_to_thread_name(struct drbd_conf *mdev, struct task_struct *task)
{
struct drbd_thread *thi = drbd_task_to_thread(mdev, task);
return thi ? thi->name : task->comm;
}
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
/** /**
* drbd_calc_cpu_mask() - Generate CPU masks, spread over all CPUs * drbd_calc_cpu_mask() - Generate CPU masks, spread over all CPUs
...@@ -629,11 +642,8 @@ void drbd_calc_cpu_mask(struct drbd_conf *mdev) ...@@ -629,11 +642,8 @@ void drbd_calc_cpu_mask(struct drbd_conf *mdev)
void drbd_thread_current_set_cpu(struct drbd_conf *mdev) void drbd_thread_current_set_cpu(struct drbd_conf *mdev)
{ {
struct task_struct *p = current; struct task_struct *p = current;
struct drbd_thread *thi = struct drbd_thread *thi = drbd_task_to_thread(mdev, p);
p == mdev->tconn->asender.task ? &mdev->tconn->asender :
p == mdev->tconn->receiver.task ? &mdev->tconn->receiver :
p == mdev->tconn->worker.task ? &mdev->tconn->worker :
NULL;
if (!expect(thi != NULL)) if (!expect(thi != NULL))
return; return;
if (!thi->reset_cpu_mask) if (!thi->reset_cpu_mask)
...@@ -1848,9 +1858,9 @@ void drbd_init_set_defaults(struct drbd_conf *mdev) ...@@ -1848,9 +1858,9 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
init_waitqueue_head(&mdev->al_wait); init_waitqueue_head(&mdev->al_wait);
init_waitqueue_head(&mdev->seq_wait); init_waitqueue_head(&mdev->seq_wait);
drbd_thread_init(mdev, &mdev->tconn->receiver, drbdd_init); drbd_thread_init(mdev, &mdev->tconn->receiver, drbdd_init, "receiver");
drbd_thread_init(mdev, &mdev->tconn->worker, drbd_worker); drbd_thread_init(mdev, &mdev->tconn->worker, drbd_worker, "worker");
drbd_thread_init(mdev, &mdev->tconn->asender, drbd_asender); drbd_thread_init(mdev, &mdev->tconn->asender, drbd_asender, "asender");
/* mdev->tconn->agreed_pro_version gets initialized in drbd_connect() */ /* mdev->tconn->agreed_pro_version gets initialized in drbd_connect() */
mdev->write_ordering = WO_bdev_flush; mdev->write_ordering = WO_bdev_flush;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册