diff options
| author | Christoph Hellwig <hch@lst.de> | 2006-02-15 13:49:04 -0500 |
|---|---|---|
| committer | Dave Kleikamp <shaggy@austin.ibm.com> | 2006-02-15 13:49:04 -0500 |
| commit | 91dbb4deb30e817efc8d6bed89b1190a489ca776 (patch) | |
| tree | d3742a35be49da1ab785ac398459d7a71a64a765 | |
| parent | 4837c672fd4d43c519d6b53308ee68d45b91b872 (diff) | |
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: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Kleikamp <shaggy@austin.ibm.com>
| -rw-r--r-- | fs/jfs/jfs_logmgr.c | 20 | ||||
| -rw-r--r-- | fs/jfs/jfs_superblock.h | 9 | ||||
| -rw-r--r-- | fs/jfs/jfs_txnmgr.c | 26 | ||||
| -rw-r--r-- | fs/jfs/super.c | 55 |
4 files changed, 38 insertions, 72 deletions
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index 06bded6c12b9..3113ff53bd55 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c | |||
| @@ -64,6 +64,7 @@ | |||
| 64 | #include <linux/interrupt.h> | 64 | #include <linux/interrupt.h> |
| 65 | #include <linux/smp_lock.h> | 65 | #include <linux/smp_lock.h> |
| 66 | #include <linux/completion.h> | 66 | #include <linux/completion.h> |
| 67 | #include <linux/kthread.h> | ||
| 67 | #include <linux/buffer_head.h> /* for sync_blockdev() */ | 68 | #include <linux/buffer_head.h> /* for sync_blockdev() */ |
| 68 | #include <linux/bio.h> | 69 | #include <linux/bio.h> |
| 69 | #include <linux/suspend.h> | 70 | #include <linux/suspend.h> |
| @@ -81,7 +82,6 @@ | |||
| 81 | */ | 82 | */ |
| 82 | static struct lbuf *log_redrive_list; | 83 | static struct lbuf *log_redrive_list; |
| 83 | static DEFINE_SPINLOCK(log_redrive_lock); | 84 | static DEFINE_SPINLOCK(log_redrive_lock); |
| 84 | DECLARE_WAIT_QUEUE_HEAD(jfs_IO_thread_wait); | ||
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | /* | 87 | /* |
| @@ -1980,7 +1980,7 @@ static inline void lbmRedrive(struct lbuf *bp) | |||
| 1980 | log_redrive_list = bp; | 1980 | log_redrive_list = bp; |
| 1981 | spin_unlock_irqrestore(&log_redrive_lock, flags); | 1981 | spin_unlock_irqrestore(&log_redrive_lock, flags); |
| 1982 | 1982 | ||
| 1983 | wake_up(&jfs_IO_thread_wait); | 1983 | wake_up_process(jfsIOthread); |
| 1984 | } | 1984 | } |
| 1985 | 1985 | ||
| 1986 | 1986 | ||
| @@ -2347,13 +2347,7 @@ int jfsIOWait(void *arg) | |||
| 2347 | { | 2347 | { |
| 2348 | struct lbuf *bp; | 2348 | struct lbuf *bp; |
| 2349 | 2349 | ||
| 2350 | daemonize("jfsIO"); | ||
| 2351 | |||
| 2352 | complete(&jfsIOwait); | ||
| 2353 | |||
| 2354 | do { | 2350 | do { |
| 2355 | DECLARE_WAITQUEUE(wq, current); | ||
| 2356 | |||
| 2357 | spin_lock_irq(&log_redrive_lock); | 2351 | spin_lock_irq(&log_redrive_lock); |
| 2358 | while ((bp = log_redrive_list) != 0) { | 2352 | while ((bp = log_redrive_list) != 0) { |
| 2359 | log_redrive_list = bp->l_redrive_next; | 2353 | log_redrive_list = bp->l_redrive_next; |
| @@ -2362,21 +2356,19 @@ int jfsIOWait(void *arg) | |||
| 2362 | lbmStartIO(bp); | 2356 | lbmStartIO(bp); |
| 2363 | spin_lock_irq(&log_redrive_lock); | 2357 | spin_lock_irq(&log_redrive_lock); |
| 2364 | } | 2358 | } |
| 2359 | spin_unlock_irq(&log_redrive_lock); | ||
| 2360 | |||
| 2365 | if (freezing(current)) { | 2361 | if (freezing(current)) { |
| 2366 | spin_unlock_irq(&log_redrive_lock); | ||
| 2367 | refrigerator(); | 2362 | refrigerator(); |
| 2368 | } else { | 2363 | } else { |
| 2369 | add_wait_queue(&jfs_IO_thread_wait, &wq); | ||
| 2370 | set_current_state(TASK_INTERRUPTIBLE); | 2364 | set_current_state(TASK_INTERRUPTIBLE); |
| 2371 | spin_unlock_irq(&log_redrive_lock); | ||
| 2372 | schedule(); | 2365 | schedule(); |
| 2373 | current->state = TASK_RUNNING; | 2366 | current->state = TASK_RUNNING; |
| 2374 | remove_wait_queue(&jfs_IO_thread_wait, &wq); | ||
| 2375 | } | 2367 | } |
| 2376 | } while (!jfs_stop_threads); | 2368 | } while (!kthread_should_stop()); |
| 2377 | 2369 | ||
| 2378 | jfs_info("jfsIOWait being killed!"); | 2370 | jfs_info("jfsIOWait being killed!"); |
| 2379 | complete_and_exit(&jfsIOwait, 0); | 2371 | return 0; |
| 2380 | } | 2372 | } |
| 2381 | 2373 | ||
| 2382 | /* | 2374 | /* |
diff --git a/fs/jfs/jfs_superblock.h b/fs/jfs/jfs_superblock.h index fcf781bf31cb..682cf1a68a18 100644 --- a/fs/jfs/jfs_superblock.h +++ b/fs/jfs/jfs_superblock.h | |||
| @@ -113,12 +113,9 @@ extern int jfs_mount(struct super_block *); | |||
| 113 | extern int jfs_mount_rw(struct super_block *, int); | 113 | extern int jfs_mount_rw(struct super_block *, int); |
| 114 | extern int jfs_umount(struct super_block *); | 114 | extern int jfs_umount(struct super_block *); |
| 115 | extern int jfs_umount_rw(struct super_block *); | 115 | extern int jfs_umount_rw(struct super_block *); |
| 116 | |||
| 117 | extern int jfs_stop_threads; | ||
| 118 | extern struct completion jfsIOwait; | ||
| 119 | extern wait_queue_head_t jfs_IO_thread_wait; | ||
| 120 | extern wait_queue_head_t jfs_commit_thread_wait; | ||
| 121 | extern wait_queue_head_t jfs_sync_thread_wait; | ||
| 122 | extern int jfs_extendfs(struct super_block *, s64, int); | 116 | extern int jfs_extendfs(struct super_block *, s64, int); |
| 123 | 117 | ||
| 118 | extern struct task_struct *jfsIOthread; | ||
| 119 | extern struct task_struct *jfsSyncThread; | ||
| 120 | |||
| 124 | #endif /*_H_JFS_SUPERBLOCK */ | 121 | #endif /*_H_JFS_SUPERBLOCK */ |
diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index d38f605d9481..ac3d66948e8c 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c | |||
| @@ -49,6 +49,7 @@ | |||
| 49 | #include <linux/suspend.h> | 49 | #include <linux/suspend.h> |
| 50 | #include <linux/module.h> | 50 | #include <linux/module.h> |
| 51 | #include <linux/moduleparam.h> | 51 | #include <linux/moduleparam.h> |
| 52 | #include <linux/kthread.h> | ||
| 52 | #include "jfs_incore.h" | 53 | #include "jfs_incore.h" |
| 53 | #include "jfs_inode.h" | 54 | #include "jfs_inode.h" |
| 54 | #include "jfs_filsys.h" | 55 | #include "jfs_filsys.h" |
| @@ -121,8 +122,7 @@ static DEFINE_SPINLOCK(jfsTxnLock); | |||
| 121 | #define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags) | 122 | #define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags) |
| 122 | #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags) | 123 | #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags) |
| 123 | 124 | ||
| 124 | DECLARE_WAIT_QUEUE_HEAD(jfs_sync_thread_wait); | 125 | static DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait); |
| 125 | DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait); | ||
| 126 | static int jfs_commit_thread_waking; | 126 | static int jfs_commit_thread_waking; |
| 127 | 127 | ||
| 128 | /* | 128 | /* |
| @@ -207,7 +207,7 @@ static lid_t txLockAlloc(void) | |||
| 207 | if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) { | 207 | if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) { |
| 208 | jfs_info("txLockAlloc tlocks low"); | 208 | jfs_info("txLockAlloc tlocks low"); |
| 209 | jfs_tlocks_low = 1; | 209 | jfs_tlocks_low = 1; |
| 210 | wake_up(&jfs_sync_thread_wait); | 210 | wake_up_process(jfsSyncThread); |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | return lid; | 213 | return lid; |
| @@ -2743,10 +2743,6 @@ int jfs_lazycommit(void *arg) | |||
| 2743 | unsigned long flags; | 2743 | unsigned long flags; |
| 2744 | struct jfs_sb_info *sbi; | 2744 | struct jfs_sb_info *sbi; |
| 2745 | 2745 | ||
| 2746 | daemonize("jfsCommit"); | ||
| 2747 | |||
| 2748 | complete(&jfsIOwait); | ||
| 2749 | |||
| 2750 | do { | 2746 | do { |
| 2751 | LAZY_LOCK(flags); | 2747 | LAZY_LOCK(flags); |
| 2752 | jfs_commit_thread_waking = 0; /* OK to wake another thread */ | 2748 | jfs_commit_thread_waking = 0; /* OK to wake another thread */ |
| @@ -2806,13 +2802,13 @@ int jfs_lazycommit(void *arg) | |||
| 2806 | current->state = TASK_RUNNING; | 2802 | current->state = TASK_RUNNING; |
| 2807 | remove_wait_queue(&jfs_commit_thread_wait, &wq); | 2803 | remove_wait_queue(&jfs_commit_thread_wait, &wq); |
| 2808 | } | 2804 | } |
| 2809 | } while (!jfs_stop_threads); | 2805 | } while (!kthread_should_stop()); |
| 2810 | 2806 | ||
| 2811 | if (!list_empty(&TxAnchor.unlock_queue)) | 2807 | if (!list_empty(&TxAnchor.unlock_queue)) |
| 2812 | jfs_err("jfs_lazycommit being killed w/pending transactions!"); | 2808 | jfs_err("jfs_lazycommit being killed w/pending transactions!"); |
| 2813 | else | 2809 | else |
| 2814 | jfs_info("jfs_lazycommit being killed\n"); | 2810 | jfs_info("jfs_lazycommit being killed\n"); |
| 2815 | complete_and_exit(&jfsIOwait, 0); | 2811 | return 0; |
| 2816 | } | 2812 | } |
| 2817 | 2813 | ||
| 2818 | void txLazyUnlock(struct tblock * tblk) | 2814 | void txLazyUnlock(struct tblock * tblk) |
| @@ -2932,10 +2928,6 @@ int jfs_sync(void *arg) | |||
| 2932 | int rc; | 2928 | int rc; |
| 2933 | tid_t tid; | 2929 | tid_t tid; |
| 2934 | 2930 | ||
| 2935 | daemonize("jfsSync"); | ||
| 2936 | |||
| 2937 | complete(&jfsIOwait); | ||
| 2938 | |||
| 2939 | do { | 2931 | do { |
| 2940 | /* | 2932 | /* |
| 2941 | * write each inode on the anonymous inode list | 2933 | * write each inode on the anonymous inode list |
| @@ -2996,19 +2988,15 @@ int jfs_sync(void *arg) | |||
| 2996 | TXN_UNLOCK(); | 2988 | TXN_UNLOCK(); |
| 2997 | refrigerator(); | 2989 | refrigerator(); |
| 2998 | } else { | 2990 | } else { |
| 2999 | DECLARE_WAITQUEUE(wq, current); | ||
| 3000 | |||
| 3001 | add_wait_queue(&jfs_sync_thread_wait, &wq); | ||
| 3002 | set_current_state(TASK_INTERRUPTIBLE); | 2991 | set_current_state(TASK_INTERRUPTIBLE); |
| 3003 | TXN_UNLOCK(); | 2992 | TXN_UNLOCK(); |
| 3004 | schedule(); | 2993 | schedule(); |
| 3005 | current->state = TASK_RUNNING; | 2994 | current->state = TASK_RUNNING; |
| 3006 | remove_wait_queue(&jfs_sync_thread_wait, &wq); | ||
| 3007 | } | 2995 | } |
| 3008 | } while (!jfs_stop_threads); | 2996 | } while (!kthread_should_stop()); |
| 3009 | 2997 | ||
| 3010 | jfs_info("jfs_sync being killed"); | 2998 | jfs_info("jfs_sync being killed"); |
| 3011 | complete_and_exit(&jfsIOwait, 0); | 2999 | return 0; |
| 3012 | } | 3000 | } |
| 3013 | 3001 | ||
| 3014 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG) | 3002 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG) |
diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 1639d2cd371f..bd6720d807a6 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | #include <linux/vfs.h> | 25 | #include <linux/vfs.h> |
| 26 | #include <linux/mount.h> | 26 | #include <linux/mount.h> |
| 27 | #include <linux/moduleparam.h> | 27 | #include <linux/moduleparam.h> |
| 28 | #include <linux/kthread.h> | ||
| 28 | #include <linux/posix_acl.h> | 29 | #include <linux/posix_acl.h> |
| 29 | #include <asm/uaccess.h> | 30 | #include <asm/uaccess.h> |
| 30 | #include <linux/seq_file.h> | 31 | #include <linux/seq_file.h> |
| @@ -54,11 +55,9 @@ static int commit_threads = 0; | |||
| 54 | module_param(commit_threads, int, 0); | 55 | module_param(commit_threads, int, 0); |
| 55 | MODULE_PARM_DESC(commit_threads, "Number of commit threads"); | 56 | MODULE_PARM_DESC(commit_threads, "Number of commit threads"); |
| 56 | 57 | ||
| 57 | int jfs_stop_threads; | 58 | static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS]; |
| 58 | static pid_t jfsIOthread; | 59 | struct task_struct *jfsIOthread; |
| 59 | static pid_t jfsCommitThread[MAX_COMMIT_THREADS]; | 60 | struct task_struct *jfsSyncThread; |
| 60 | static pid_t jfsSyncThread; | ||
| 61 | DECLARE_COMPLETION(jfsIOwait); | ||
| 62 | 61 | ||
| 63 | #ifdef CONFIG_JFS_DEBUG | 62 | #ifdef CONFIG_JFS_DEBUG |
| 64 | int jfsloglevel = JFS_LOGLEVEL_WARN; | 63 | int jfsloglevel = JFS_LOGLEVEL_WARN; |
| @@ -661,12 +660,12 @@ static int __init init_jfs_fs(void) | |||
| 661 | /* | 660 | /* |
| 662 | * I/O completion thread (endio) | 661 | * I/O completion thread (endio) |
| 663 | */ | 662 | */ |
| 664 | jfsIOthread = kernel_thread(jfsIOWait, NULL, CLONE_KERNEL); | 663 | jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO"); |
| 665 | if (jfsIOthread < 0) { | 664 | if (IS_ERR(jfsIOthread)) { |
| 666 | jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsIOthread); | 665 | rc = PTR_ERR(jfsIOthread); |
| 666 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); | ||
| 667 | goto end_txmngr; | 667 | goto end_txmngr; |
| 668 | } | 668 | } |
| 669 | wait_for_completion(&jfsIOwait); /* Wait until thread starts */ | ||
| 670 | 669 | ||
| 671 | if (commit_threads < 1) | 670 | if (commit_threads < 1) |
| 672 | commit_threads = num_online_cpus(); | 671 | commit_threads = num_online_cpus(); |
| @@ -674,24 +673,21 @@ static int __init init_jfs_fs(void) | |||
| 674 | commit_threads = MAX_COMMIT_THREADS; | 673 | commit_threads = MAX_COMMIT_THREADS; |
| 675 | 674 | ||
| 676 | for (i = 0; i < commit_threads; i++) { | 675 | for (i = 0; i < commit_threads; i++) { |
| 677 | jfsCommitThread[i] = kernel_thread(jfs_lazycommit, NULL, | 676 | jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit"); |
| 678 | CLONE_KERNEL); | 677 | if (IS_ERR(jfsCommitThread[i])) { |
| 679 | if (jfsCommitThread[i] < 0) { | 678 | rc = PTR_ERR(jfsCommitThread[i]); |
| 680 | jfs_err("init_jfs_fs: fork failed w/rc = %d", | 679 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); |
| 681 | jfsCommitThread[i]); | ||
| 682 | commit_threads = i; | 680 | commit_threads = i; |
| 683 | goto kill_committask; | 681 | goto kill_committask; |
| 684 | } | 682 | } |
| 685 | /* Wait until thread starts */ | ||
| 686 | wait_for_completion(&jfsIOwait); | ||
| 687 | } | 683 | } |
| 688 | 684 | ||
| 689 | jfsSyncThread = kernel_thread(jfs_sync, NULL, CLONE_KERNEL); | 685 | jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync"); |
| 690 | if (jfsSyncThread < 0) { | 686 | if (IS_ERR(jfsSyncThread)) { |
| 691 | jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsSyncThread); | 687 | rc = PTR_ERR(jfsSyncThread); |
| 688 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); | ||
| 692 | goto kill_committask; | 689 | goto kill_committask; |
| 693 | } | 690 | } |
| 694 | wait_for_completion(&jfsIOwait); /* Wait until thread starts */ | ||
| 695 | 691 | ||
| 696 | #ifdef PROC_FS_JFS | 692 | #ifdef PROC_FS_JFS |
| 697 | jfs_proc_init(); | 693 | jfs_proc_init(); |
| @@ -700,13 +696,9 @@ static int __init init_jfs_fs(void) | |||
| 700 | return register_filesystem(&jfs_fs_type); | 696 | return register_filesystem(&jfs_fs_type); |
| 701 | 697 | ||
| 702 | kill_committask: | 698 | kill_committask: |
| 703 | jfs_stop_threads = 1; | ||
| 704 | wake_up_all(&jfs_commit_thread_wait); | ||
| 705 | for (i = 0; i < commit_threads; i++) | 699 | for (i = 0; i < commit_threads; i++) |
| 706 | wait_for_completion(&jfsIOwait); | 700 | kthread_stop(jfsCommitThread[i]); |
| 707 | 701 | kthread_stop(jfsIOthread); | |
| 708 | wake_up(&jfs_IO_thread_wait); | ||
| 709 | wait_for_completion(&jfsIOwait); /* Wait for thread exit */ | ||
| 710 | end_txmngr: | 702 | end_txmngr: |
| 711 | txExit(); | 703 | txExit(); |
| 712 | free_metapage: | 704 | free_metapage: |
| @@ -722,16 +714,13 @@ static void __exit exit_jfs_fs(void) | |||
| 722 | 714 | ||
| 723 | jfs_info("exit_jfs_fs called"); | 715 | jfs_info("exit_jfs_fs called"); |
| 724 | 716 | ||
| 725 | jfs_stop_threads = 1; | ||
| 726 | txExit(); | 717 | txExit(); |
| 727 | metapage_exit(); | 718 | metapage_exit(); |
| 728 | wake_up(&jfs_IO_thread_wait); | 719 | |
| 729 | wait_for_completion(&jfsIOwait); /* Wait until IO thread exits */ | 720 | kthread_stop(jfsIOthread); |
| 730 | wake_up_all(&jfs_commit_thread_wait); | ||
| 731 | for (i = 0; i < commit_threads; i++) | 721 | for (i = 0; i < commit_threads; i++) |
| 732 | wait_for_completion(&jfsIOwait); | 722 | kthread_stop(jfsCommitThread[i]); |
| 733 | wake_up(&jfs_sync_thread_wait); | 723 | kthread_stop(jfsSyncThread); |
| 734 | wait_for_completion(&jfsIOwait); /* Wait until Sync thread exits */ | ||
| 735 | #ifdef PROC_FS_JFS | 724 | #ifdef PROC_FS_JFS |
| 736 | jfs_proc_clean(); | 725 | jfs_proc_clean(); |
| 737 | #endif | 726 | #endif |
