Skip to content

Commit

Permalink
[SCSI] sas_scsi_host: Convert to use the kthread API
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
  • Loading branch information
Christoph Hellwig authored and James Bottomley committed May 6, 2007
1 parent 4797547 commit d7a54e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
36 changes: 13 additions & 23 deletions drivers/scsi/libsas/sas_scsi_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*
*/

#include <linux/kthread.h>

#include "sas_internal.h"

#include <scsi/scsi_host.h>
Expand Down Expand Up @@ -184,7 +186,7 @@ static int sas_queue_up(struct sas_task *task)
list_add_tail(&task->list, &core->task_queue);
core->task_queue_size += 1;
spin_unlock_irqrestore(&core->task_queue_lock, flags);
up(&core->queue_thread_sema);
wake_up_process(core->queue_thread);

return 0;
}
Expand Down Expand Up @@ -819,7 +821,7 @@ static void sas_queue(struct sas_ha_struct *sas_ha)
struct sas_internal *i = to_sas_internal(core->shost->transportt);

spin_lock_irqsave(&core->task_queue_lock, flags);
while (!core->queue_thread_kill &&
while (!kthread_should_stop() &&
!list_empty(&core->task_queue)) {

can_queue = sas_ha->lldd_queue_size - core->task_queue_size;
Expand Down Expand Up @@ -858,49 +860,40 @@ static void sas_queue(struct sas_ha_struct *sas_ha)
spin_unlock_irqrestore(&core->task_queue_lock, flags);
}

static DECLARE_COMPLETION(queue_th_comp);

/**
* sas_queue_thread -- The Task Collector thread
* @_sas_ha: pointer to struct sas_ha
*/
static int sas_queue_thread(void *_sas_ha)
{
struct sas_ha_struct *sas_ha = _sas_ha;
struct scsi_core *core = &sas_ha->core;

daemonize("sas_queue_%d", core->shost->host_no);
current->flags |= PF_NOFREEZE;

complete(&queue_th_comp);

while (1) {
down_interruptible(&core->queue_thread_sema);
set_current_state(TASK_INTERRUPTIBLE);
schedule();
sas_queue(sas_ha);
if (core->queue_thread_kill)
if (kthread_should_stop())
break;
}

complete(&queue_th_comp);

return 0;
}

int sas_init_queue(struct sas_ha_struct *sas_ha)
{
int res;
struct scsi_core *core = &sas_ha->core;

spin_lock_init(&core->task_queue_lock);
core->task_queue_size = 0;
INIT_LIST_HEAD(&core->task_queue);
init_MUTEX_LOCKED(&core->queue_thread_sema);

res = kernel_thread(sas_queue_thread, sas_ha, 0);
if (res >= 0)
wait_for_completion(&queue_th_comp);

return res < 0 ? res : 0;
core->queue_thread = kthread_run(sas_queue_thread, sas_ha,
"sas_queue_%d", core->shost->host_no);
if (IS_ERR(core->queue_thread))
return PTR_ERR(core->queue_thread);
return 0;
}

void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
Expand All @@ -909,10 +902,7 @@ void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
struct scsi_core *core = &sas_ha->core;
struct sas_task *task, *n;

init_completion(&queue_th_comp);
core->queue_thread_kill = 1;
up(&core->queue_thread_sema);
wait_for_completion(&queue_th_comp);
kthread_stop(core->queue_thread);

if (!list_empty(&core->task_queue))
SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
Expand Down
3 changes: 1 addition & 2 deletions include/scsi/libsas.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ struct scsi_core {
struct list_head task_queue;
int task_queue_size;

struct semaphore queue_thread_sema;
int queue_thread_kill;
struct task_struct *queue_thread;
};

struct sas_ha_event {
Expand Down

0 comments on commit d7a54e3

Please sign in to comment.