Commit 91dbb4de authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Dave Kleikamp

JFS: Use the kthread_ API

Use the kthread_ API instead of opencoding lots of hairy code for kernel
thread creation and teardown.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDave Kleikamp <shaggy@austin.ibm.com>
parent 4837c672
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/kthread.h>
#include <linux/buffer_head.h> /* for sync_blockdev() */ #include <linux/buffer_head.h> /* for sync_blockdev() */
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/suspend.h> #include <linux/suspend.h>
...@@ -81,7 +82,6 @@ ...@@ -81,7 +82,6 @@
*/ */
static struct lbuf *log_redrive_list; static struct lbuf *log_redrive_list;
static DEFINE_SPINLOCK(log_redrive_lock); static DEFINE_SPINLOCK(log_redrive_lock);
DECLARE_WAIT_QUEUE_HEAD(jfs_IO_thread_wait);
/* /*
...@@ -1980,7 +1980,7 @@ static inline void lbmRedrive(struct lbuf *bp) ...@@ -1980,7 +1980,7 @@ static inline void lbmRedrive(struct lbuf *bp)
log_redrive_list = bp; log_redrive_list = bp;
spin_unlock_irqrestore(&log_redrive_lock, flags); spin_unlock_irqrestore(&log_redrive_lock, flags);
wake_up(&jfs_IO_thread_wait); wake_up_process(jfsIOthread);
} }
...@@ -2347,13 +2347,7 @@ int jfsIOWait(void *arg) ...@@ -2347,13 +2347,7 @@ int jfsIOWait(void *arg)
{ {
struct lbuf *bp; struct lbuf *bp;
daemonize("jfsIO");
complete(&jfsIOwait);
do { do {
DECLARE_WAITQUEUE(wq, current);
spin_lock_irq(&log_redrive_lock); spin_lock_irq(&log_redrive_lock);
while ((bp = log_redrive_list) != 0) { while ((bp = log_redrive_list) != 0) {
log_redrive_list = bp->l_redrive_next; log_redrive_list = bp->l_redrive_next;
...@@ -2362,21 +2356,19 @@ int jfsIOWait(void *arg) ...@@ -2362,21 +2356,19 @@ int jfsIOWait(void *arg)
lbmStartIO(bp); lbmStartIO(bp);
spin_lock_irq(&log_redrive_lock); spin_lock_irq(&log_redrive_lock);
} }
if (freezing(current)) {
spin_unlock_irq(&log_redrive_lock); spin_unlock_irq(&log_redrive_lock);
if (freezing(current)) {
refrigerator(); refrigerator();
} else { } else {
add_wait_queue(&jfs_IO_thread_wait, &wq);
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
spin_unlock_irq(&log_redrive_lock);
schedule(); schedule();
current->state = TASK_RUNNING; current->state = TASK_RUNNING;
remove_wait_queue(&jfs_IO_thread_wait, &wq);
} }
} while (!jfs_stop_threads); } while (!kthread_should_stop());
jfs_info("jfsIOWait being killed!"); jfs_info("jfsIOWait being killed!");
complete_and_exit(&jfsIOwait, 0); return 0;
} }
/* /*
......
...@@ -113,12 +113,9 @@ extern int jfs_mount(struct super_block *); ...@@ -113,12 +113,9 @@ extern int jfs_mount(struct super_block *);
extern int jfs_mount_rw(struct super_block *, int); extern int jfs_mount_rw(struct super_block *, int);
extern int jfs_umount(struct super_block *); extern int jfs_umount(struct super_block *);
extern int jfs_umount_rw(struct super_block *); extern int jfs_umount_rw(struct super_block *);
extern int jfs_stop_threads;
extern struct completion jfsIOwait;
extern wait_queue_head_t jfs_IO_thread_wait;
extern wait_queue_head_t jfs_commit_thread_wait;
extern wait_queue_head_t jfs_sync_thread_wait;
extern int jfs_extendfs(struct super_block *, s64, int); extern int jfs_extendfs(struct super_block *, s64, int);
extern struct task_struct *jfsIOthread;
extern struct task_struct *jfsSyncThread;
#endif /*_H_JFS_SUPERBLOCK */ #endif /*_H_JFS_SUPERBLOCK */
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/kthread.h>
#include "jfs_incore.h" #include "jfs_incore.h"
#include "jfs_inode.h" #include "jfs_inode.h"
#include "jfs_filsys.h" #include "jfs_filsys.h"
...@@ -121,8 +122,7 @@ static DEFINE_SPINLOCK(jfsTxnLock); ...@@ -121,8 +122,7 @@ static DEFINE_SPINLOCK(jfsTxnLock);
#define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags) #define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags)
#define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags) #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags)
DECLARE_WAIT_QUEUE_HEAD(jfs_sync_thread_wait); static DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
static int jfs_commit_thread_waking; static int jfs_commit_thread_waking;
/* /*
...@@ -207,7 +207,7 @@ static lid_t txLockAlloc(void) ...@@ -207,7 +207,7 @@ static lid_t txLockAlloc(void)
if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) { if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) {
jfs_info("txLockAlloc tlocks low"); jfs_info("txLockAlloc tlocks low");
jfs_tlocks_low = 1; jfs_tlocks_low = 1;
wake_up(&jfs_sync_thread_wait); wake_up_process(jfsSyncThread);
} }
return lid; return lid;
...@@ -2743,10 +2743,6 @@ int jfs_lazycommit(void *arg) ...@@ -2743,10 +2743,6 @@ int jfs_lazycommit(void *arg)
unsigned long flags; unsigned long flags;
struct jfs_sb_info *sbi; struct jfs_sb_info *sbi;
daemonize("jfsCommit");
complete(&jfsIOwait);
do { do {
LAZY_LOCK(flags); LAZY_LOCK(flags);
jfs_commit_thread_waking = 0; /* OK to wake another thread */ jfs_commit_thread_waking = 0; /* OK to wake another thread */
...@@ -2806,13 +2802,13 @@ int jfs_lazycommit(void *arg) ...@@ -2806,13 +2802,13 @@ int jfs_lazycommit(void *arg)
current->state = TASK_RUNNING; current->state = TASK_RUNNING;
remove_wait_queue(&jfs_commit_thread_wait, &wq); remove_wait_queue(&jfs_commit_thread_wait, &wq);
} }
} while (!jfs_stop_threads); } while (!kthread_should_stop());
if (!list_empty(&TxAnchor.unlock_queue)) if (!list_empty(&TxAnchor.unlock_queue))
jfs_err("jfs_lazycommit being killed w/pending transactions!"); jfs_err("jfs_lazycommit being killed w/pending transactions!");
else else
jfs_info("jfs_lazycommit being killed\n"); jfs_info("jfs_lazycommit being killed\n");
complete_and_exit(&jfsIOwait, 0); return 0;
} }
void txLazyUnlock(struct tblock * tblk) void txLazyUnlock(struct tblock * tblk)
...@@ -2932,10 +2928,6 @@ int jfs_sync(void *arg) ...@@ -2932,10 +2928,6 @@ int jfs_sync(void *arg)
int rc; int rc;
tid_t tid; tid_t tid;
daemonize("jfsSync");
complete(&jfsIOwait);
do { do {
/* /*
* write each inode on the anonymous inode list * write each inode on the anonymous inode list
...@@ -2996,19 +2988,15 @@ int jfs_sync(void *arg) ...@@ -2996,19 +2988,15 @@ int jfs_sync(void *arg)
TXN_UNLOCK(); TXN_UNLOCK();
refrigerator(); refrigerator();
} else { } else {
DECLARE_WAITQUEUE(wq, current);
add_wait_queue(&jfs_sync_thread_wait, &wq);
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
TXN_UNLOCK(); TXN_UNLOCK();
schedule(); schedule();
current->state = TASK_RUNNING; current->state = TASK_RUNNING;
remove_wait_queue(&jfs_sync_thread_wait, &wq);
} }
} while (!jfs_stop_threads); } while (!kthread_should_stop());
jfs_info("jfs_sync being killed"); jfs_info("jfs_sync being killed");
complete_and_exit(&jfsIOwait, 0); return 0;
} }
#if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG) #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/vfs.h> #include <linux/vfs.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/kthread.h>
#include <linux/posix_acl.h> #include <linux/posix_acl.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
...@@ -54,11 +55,9 @@ static int commit_threads = 0; ...@@ -54,11 +55,9 @@ static int commit_threads = 0;
module_param(commit_threads, int, 0); module_param(commit_threads, int, 0);
MODULE_PARM_DESC(commit_threads, "Number of commit threads"); MODULE_PARM_DESC(commit_threads, "Number of commit threads");
int jfs_stop_threads; static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS];
static pid_t jfsIOthread; struct task_struct *jfsIOthread;
static pid_t jfsCommitThread[MAX_COMMIT_THREADS]; struct task_struct *jfsSyncThread;
static pid_t jfsSyncThread;
DECLARE_COMPLETION(jfsIOwait);
#ifdef CONFIG_JFS_DEBUG #ifdef CONFIG_JFS_DEBUG
int jfsloglevel = JFS_LOGLEVEL_WARN; int jfsloglevel = JFS_LOGLEVEL_WARN;
...@@ -661,12 +660,12 @@ static int __init init_jfs_fs(void) ...@@ -661,12 +660,12 @@ static int __init init_jfs_fs(void)
/* /*
* I/O completion thread (endio) * I/O completion thread (endio)
*/ */
jfsIOthread = kernel_thread(jfsIOWait, NULL, CLONE_KERNEL); jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO");
if (jfsIOthread < 0) { if (IS_ERR(jfsIOthread)) {
jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsIOthread); rc = PTR_ERR(jfsIOthread);
jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
goto end_txmngr; goto end_txmngr;
} }
wait_for_completion(&jfsIOwait); /* Wait until thread starts */
if (commit_threads < 1) if (commit_threads < 1)
commit_threads = num_online_cpus(); commit_threads = num_online_cpus();
...@@ -674,24 +673,21 @@ static int __init init_jfs_fs(void) ...@@ -674,24 +673,21 @@ static int __init init_jfs_fs(void)
commit_threads = MAX_COMMIT_THREADS; commit_threads = MAX_COMMIT_THREADS;
for (i = 0; i < commit_threads; i++) { for (i = 0; i < commit_threads; i++) {
jfsCommitThread[i] = kernel_thread(jfs_lazycommit, NULL, jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit");
CLONE_KERNEL); if (IS_ERR(jfsCommitThread[i])) {
if (jfsCommitThread[i] < 0) { rc = PTR_ERR(jfsCommitThread[i]);
jfs_err("init_jfs_fs: fork failed w/rc = %d", jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
jfsCommitThread[i]);
commit_threads = i; commit_threads = i;
goto kill_committask; goto kill_committask;
} }
/* Wait until thread starts */
wait_for_completion(&jfsIOwait);
} }
jfsSyncThread = kernel_thread(jfs_sync, NULL, CLONE_KERNEL); jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync");
if (jfsSyncThread < 0) { if (IS_ERR(jfsSyncThread)) {
jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsSyncThread); rc = PTR_ERR(jfsSyncThread);
jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
goto kill_committask; goto kill_committask;
} }
wait_for_completion(&jfsIOwait); /* Wait until thread starts */
#ifdef PROC_FS_JFS #ifdef PROC_FS_JFS
jfs_proc_init(); jfs_proc_init();
...@@ -700,13 +696,9 @@ static int __init init_jfs_fs(void) ...@@ -700,13 +696,9 @@ static int __init init_jfs_fs(void)
return register_filesystem(&jfs_fs_type); return register_filesystem(&jfs_fs_type);
kill_committask: kill_committask:
jfs_stop_threads = 1;
wake_up_all(&jfs_commit_thread_wait);
for (i = 0; i < commit_threads; i++) for (i = 0; i < commit_threads; i++)
wait_for_completion(&jfsIOwait); kthread_stop(jfsCommitThread[i]);
kthread_stop(jfsIOthread);
wake_up(&jfs_IO_thread_wait);
wait_for_completion(&jfsIOwait); /* Wait for thread exit */
end_txmngr: end_txmngr:
txExit(); txExit();
free_metapage: free_metapage:
...@@ -722,16 +714,13 @@ static void __exit exit_jfs_fs(void) ...@@ -722,16 +714,13 @@ static void __exit exit_jfs_fs(void)
jfs_info("exit_jfs_fs called"); jfs_info("exit_jfs_fs called");
jfs_stop_threads = 1;
txExit(); txExit();
metapage_exit(); metapage_exit();
wake_up(&jfs_IO_thread_wait);
wait_for_completion(&jfsIOwait); /* Wait until IO thread exits */ kthread_stop(jfsIOthread);
wake_up_all(&jfs_commit_thread_wait);
for (i = 0; i < commit_threads; i++) for (i = 0; i < commit_threads; i++)
wait_for_completion(&jfsIOwait); kthread_stop(jfsCommitThread[i]);
wake_up(&jfs_sync_thread_wait); kthread_stop(jfsSyncThread);
wait_for_completion(&jfsIOwait); /* Wait until Sync thread exits */
#ifdef PROC_FS_JFS #ifdef PROC_FS_JFS
jfs_proc_clean(); jfs_proc_clean();
#endif #endif
......
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