Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] sas_scsi_host: Convert to use the kthread API

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by

Christoph Hellwig and committed by
James Bottomley
d7a54e30 47975477

+14 -25
+13 -23
drivers/scsi/libsas/sas_scsi_host.c
··· 23 23 * 24 24 */ 25 25 26 + #include <linux/kthread.h> 27 + 26 28 #include "sas_internal.h" 27 29 28 30 #include <scsi/scsi_host.h> ··· 186 184 list_add_tail(&task->list, &core->task_queue); 187 185 core->task_queue_size += 1; 188 186 spin_unlock_irqrestore(&core->task_queue_lock, flags); 189 - up(&core->queue_thread_sema); 187 + wake_up_process(core->queue_thread); 190 188 191 189 return 0; 192 190 } ··· 821 819 struct sas_internal *i = to_sas_internal(core->shost->transportt); 822 820 823 821 spin_lock_irqsave(&core->task_queue_lock, flags); 824 - while (!core->queue_thread_kill && 822 + while (!kthread_should_stop() && 825 823 !list_empty(&core->task_queue)) { 826 824 827 825 can_queue = sas_ha->lldd_queue_size - core->task_queue_size; ··· 860 858 spin_unlock_irqrestore(&core->task_queue_lock, flags); 861 859 } 862 860 863 - static DECLARE_COMPLETION(queue_th_comp); 864 - 865 861 /** 866 862 * sas_queue_thread -- The Task Collector thread 867 863 * @_sas_ha: pointer to struct sas_ha ··· 867 867 static int sas_queue_thread(void *_sas_ha) 868 868 { 869 869 struct sas_ha_struct *sas_ha = _sas_ha; 870 - struct scsi_core *core = &sas_ha->core; 871 870 872 - daemonize("sas_queue_%d", core->shost->host_no); 873 871 current->flags |= PF_NOFREEZE; 874 872 875 - complete(&queue_th_comp); 876 - 877 873 while (1) { 878 - down_interruptible(&core->queue_thread_sema); 874 + set_current_state(TASK_INTERRUPTIBLE); 875 + schedule(); 879 876 sas_queue(sas_ha); 880 - if (core->queue_thread_kill) 877 + if (kthread_should_stop()) 881 878 break; 882 879 } 883 - 884 - complete(&queue_th_comp); 885 880 886 881 return 0; 887 882 } 888 883 889 884 int sas_init_queue(struct sas_ha_struct *sas_ha) 890 885 { 891 - int res; 892 886 struct scsi_core *core = &sas_ha->core; 893 887 894 888 spin_lock_init(&core->task_queue_lock); 895 889 core->task_queue_size = 0; 896 890 INIT_LIST_HEAD(&core->task_queue); 897 - init_MUTEX_LOCKED(&core->queue_thread_sema); 898 891 899 - res = kernel_thread(sas_queue_thread, sas_ha, 0); 900 - if (res >= 0) 901 - wait_for_completion(&queue_th_comp); 902 - 903 - return res < 0 ? res : 0; 892 + core->queue_thread = kthread_run(sas_queue_thread, sas_ha, 893 + "sas_queue_%d", core->shost->host_no); 894 + if (IS_ERR(core->queue_thread)) 895 + return PTR_ERR(core->queue_thread); 896 + return 0; 904 897 } 905 898 906 899 void sas_shutdown_queue(struct sas_ha_struct *sas_ha) ··· 902 909 struct scsi_core *core = &sas_ha->core; 903 910 struct sas_task *task, *n; 904 911 905 - init_completion(&queue_th_comp); 906 - core->queue_thread_kill = 1; 907 - up(&core->queue_thread_sema); 908 - wait_for_completion(&queue_th_comp); 912 + kthread_stop(core->queue_thread); 909 913 910 914 if (!list_empty(&core->task_queue)) 911 915 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
+1 -2
include/scsi/libsas.h
··· 314 314 struct list_head task_queue; 315 315 int task_queue_size; 316 316 317 - struct semaphore queue_thread_sema; 318 - int queue_thread_kill; 317 + struct task_struct *queue_thread; 319 318 }; 320 319 321 320 struct sas_ha_event {