]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - fs/jfs/super.c
/home/lenb/src/to-linus branch 'acpi-2.6.12'
[linux-3.10.git] / fs / jfs / super.c
1 /*
2  *   Copyright (C) International Business Machines Corp., 2000-2004
3  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or 
8  *   (at your option) any later version.
9  * 
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software 
17  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19
20 #include <linux/fs.h>
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/parser.h>
24 #include <linux/completion.h>
25 #include <linux/vfs.h>
26 #include <linux/moduleparam.h>
27 #include <linux/posix_acl.h>
28 #include <asm/uaccess.h>
29
30 #include "jfs_incore.h"
31 #include "jfs_filsys.h"
32 #include "jfs_inode.h"
33 #include "jfs_metapage.h"
34 #include "jfs_superblock.h"
35 #include "jfs_dmap.h"
36 #include "jfs_imap.h"
37 #include "jfs_acl.h"
38 #include "jfs_debug.h"
39
40 MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
41 MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
42 MODULE_LICENSE("GPL");
43
44 static kmem_cache_t * jfs_inode_cachep;
45
46 static struct super_operations jfs_super_operations;
47 static struct export_operations jfs_export_operations;
48 static struct file_system_type jfs_fs_type;
49
50 #define MAX_COMMIT_THREADS 64
51 static int commit_threads = 0;
52 module_param(commit_threads, int, 0);
53 MODULE_PARM_DESC(commit_threads, "Number of commit threads");
54
55 int jfs_stop_threads;
56 static pid_t jfsIOthread;
57 static pid_t jfsCommitThread[MAX_COMMIT_THREADS];
58 static pid_t jfsSyncThread;
59 DECLARE_COMPLETION(jfsIOwait);
60
61 #ifdef CONFIG_JFS_DEBUG
62 int jfsloglevel = JFS_LOGLEVEL_WARN;
63 module_param(jfsloglevel, int, 0644);
64 MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)");
65 #endif
66
67 static void jfs_handle_error(struct super_block *sb)
68 {
69         struct jfs_sb_info *sbi = JFS_SBI(sb);
70
71         if (sb->s_flags & MS_RDONLY)
72                 return;
73
74         updateSuper(sb, FM_DIRTY);
75
76         if (sbi->flag & JFS_ERR_PANIC)
77                 panic("JFS (device %s): panic forced after error\n",
78                         sb->s_id);
79         else if (sbi->flag & JFS_ERR_REMOUNT_RO) {
80                 jfs_err("ERROR: (device %s): remounting filesystem "
81                         "as read-only\n",
82                         sb->s_id);
83                 sb->s_flags |= MS_RDONLY;
84         } 
85
86         /* nothing is done for continue beyond marking the superblock dirty */
87 }
88
89 void jfs_error(struct super_block *sb, const char * function, ...)
90 {
91         static char error_buf[256];
92         va_list args;
93
94         va_start(args, function);
95         vsprintf(error_buf, function, args);
96         va_end(args);
97
98         printk(KERN_ERR "ERROR: (device %s): %s\n", sb->s_id, error_buf);
99
100         jfs_handle_error(sb);
101 }
102
103 static struct inode *jfs_alloc_inode(struct super_block *sb)
104 {
105         struct jfs_inode_info *jfs_inode;
106
107         jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS);
108         if (!jfs_inode)
109                 return NULL;
110         return &jfs_inode->vfs_inode;
111 }
112
113 static void jfs_destroy_inode(struct inode *inode)
114 {
115         struct jfs_inode_info *ji = JFS_IP(inode);
116
117         spin_lock_irq(&ji->ag_lock);
118         if (ji->active_ag != -1) {
119                 struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
120                 atomic_dec(&bmap->db_active[ji->active_ag]);
121                 ji->active_ag = -1;
122         }
123         spin_unlock_irq(&ji->ag_lock);
124
125 #ifdef CONFIG_JFS_POSIX_ACL
126         if (ji->i_acl != JFS_ACL_NOT_CACHED) {
127                 posix_acl_release(ji->i_acl);
128                 ji->i_acl = JFS_ACL_NOT_CACHED;
129         }
130         if (ji->i_default_acl != JFS_ACL_NOT_CACHED) {
131                 posix_acl_release(ji->i_default_acl);
132                 ji->i_default_acl = JFS_ACL_NOT_CACHED;
133         }
134 #endif
135
136         kmem_cache_free(jfs_inode_cachep, ji);
137 }
138
139 static int jfs_statfs(struct super_block *sb, struct kstatfs *buf)
140 {
141         struct jfs_sb_info *sbi = JFS_SBI(sb);
142         s64 maxinodes;
143         struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap;
144
145         jfs_info("In jfs_statfs");
146         buf->f_type = JFS_SUPER_MAGIC;
147         buf->f_bsize = sbi->bsize;
148         buf->f_blocks = sbi->bmap->db_mapsize;
149         buf->f_bfree = sbi->bmap->db_nfree;
150         buf->f_bavail = sbi->bmap->db_nfree;
151         /*
152          * If we really return the number of allocated & free inodes, some
153          * applications will fail because they won't see enough free inodes.
154          * We'll try to calculate some guess as to how may inodes we can
155          * really allocate
156          *
157          * buf->f_files = atomic_read(&imap->im_numinos);
158          * buf->f_ffree = atomic_read(&imap->im_numfree);
159          */
160         maxinodes = min((s64) atomic_read(&imap->im_numinos) +
161                         ((sbi->bmap->db_nfree >> imap->im_l2nbperiext)
162                          << L2INOSPEREXT), (s64) 0xffffffffLL);
163         buf->f_files = maxinodes;
164         buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
165                                     atomic_read(&imap->im_numfree));
166
167         buf->f_namelen = JFS_NAME_MAX;
168         return 0;
169 }
170
171 static void jfs_put_super(struct super_block *sb)
172 {
173         struct jfs_sb_info *sbi = JFS_SBI(sb);
174         int rc;
175
176         jfs_info("In jfs_put_super");
177         rc = jfs_umount(sb);
178         if (rc)
179                 jfs_err("jfs_umount failed with return code %d", rc);
180         if (sbi->nls_tab)
181                 unload_nls(sbi->nls_tab);
182         sbi->nls_tab = NULL;
183
184         truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
185         iput(sbi->direct_inode);
186         sbi->direct_inode = NULL;
187
188         kfree(sbi);
189 }
190
191 enum {
192         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
193         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err,
194 };
195
196 static match_table_t tokens = {
197         {Opt_integrity, "integrity"},
198         {Opt_nointegrity, "nointegrity"},
199         {Opt_iocharset, "iocharset=%s"},
200         {Opt_resize, "resize=%u"},
201         {Opt_resize_nosize, "resize"},
202         {Opt_errors, "errors=%s"},
203         {Opt_ignore, "noquota"},
204         {Opt_ignore, "quota"},
205         {Opt_ignore, "usrquota"},
206         {Opt_ignore, "grpquota"},
207         {Opt_err, NULL}
208 };
209
210 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
211                          int *flag)
212 {
213         void *nls_map = (void *)-1;     /* -1: no change;  NULL: none */
214         char *p;
215         struct jfs_sb_info *sbi = JFS_SBI(sb);
216
217         *newLVSize = 0;
218
219         if (!options)
220                 return 1;
221
222         while ((p = strsep(&options, ",")) != NULL) {
223                 substring_t args[MAX_OPT_ARGS];
224                 int token;
225                 if (!*p)
226                         continue;
227
228                 token = match_token(p, tokens, args);
229                 switch (token) {
230                 case Opt_integrity:
231                         *flag &= ~JFS_NOINTEGRITY;
232                         break;
233                 case Opt_nointegrity:
234                         *flag |= JFS_NOINTEGRITY;
235                         break;
236                 case Opt_ignore:
237                         /* Silently ignore the quota options */
238                         /* Don't do anything ;-) */
239                         break;
240                 case Opt_iocharset:
241                         if (nls_map && nls_map != (void *) -1)
242                                 unload_nls(nls_map);
243                         if (!strcmp(args[0].from, "none"))
244                                 nls_map = NULL;
245                         else {
246                                 nls_map = load_nls(args[0].from);
247                                 if (!nls_map) {
248                                         printk(KERN_ERR
249                                                "JFS: charset not found\n");
250                                         goto cleanup;
251                                 }
252                         }
253                         break;
254                 case Opt_resize:
255                 {
256                         char *resize = args[0].from;
257                         *newLVSize = simple_strtoull(resize, &resize, 0);
258                         break;
259                 }
260                 case Opt_resize_nosize:
261                 {
262                         *newLVSize = sb->s_bdev->bd_inode->i_size >>
263                                 sb->s_blocksize_bits;
264                         if (*newLVSize == 0)
265                                 printk(KERN_ERR
266                                        "JFS: Cannot determine volume size\n");
267                         break;
268                 }
269                 case Opt_errors:
270                 {
271                         char *errors = args[0].from;
272                         if (!errors || !*errors)
273                                 goto cleanup;
274                         if (!strcmp(errors, "continue")) {
275                                 *flag &= ~JFS_ERR_REMOUNT_RO;
276                                 *flag &= ~JFS_ERR_PANIC;
277                                 *flag |= JFS_ERR_CONTINUE;
278                         } else if (!strcmp(errors, "remount-ro")) {
279                                 *flag &= ~JFS_ERR_CONTINUE;
280                                 *flag &= ~JFS_ERR_PANIC;
281                                 *flag |= JFS_ERR_REMOUNT_RO;
282                         } else if (!strcmp(errors, "panic")) {
283                                 *flag &= ~JFS_ERR_CONTINUE;
284                                 *flag &= ~JFS_ERR_REMOUNT_RO;
285                                 *flag |= JFS_ERR_PANIC;
286                         } else {
287                                 printk(KERN_ERR
288                                        "JFS: %s is an invalid error handler\n",
289                                        errors);
290                                 goto cleanup;
291                         }
292                         break;
293                 }
294                 default:
295                         printk("jfs: Unrecognized mount option \"%s\" "
296                                         " or missing value\n", p);
297                         goto cleanup;
298                 }
299         }
300
301         if (nls_map != (void *) -1) {
302                 /* Discard old (if remount) */
303                 if (sbi->nls_tab)
304                         unload_nls(sbi->nls_tab);
305                 sbi->nls_tab = nls_map;
306         }
307         return 1;
308
309 cleanup:
310         if (nls_map && nls_map != (void *) -1)
311                 unload_nls(nls_map);
312         return 0;
313 }
314
315 static int jfs_remount(struct super_block *sb, int *flags, char *data)
316 {
317         s64 newLVSize = 0;
318         int rc = 0;
319         int flag = JFS_SBI(sb)->flag;
320
321         if (!parse_options(data, sb, &newLVSize, &flag)) {
322                 return -EINVAL;
323         }
324         if (newLVSize) {
325                 if (sb->s_flags & MS_RDONLY) {
326                         printk(KERN_ERR
327                   "JFS: resize requires volume to be mounted read-write\n");
328                         return -EROFS;
329                 }
330                 rc = jfs_extendfs(sb, newLVSize, 0);
331                 if (rc)
332                         return rc;
333         }
334
335         if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
336                 /*
337                  * Invalidate any previously read metadata.  fsck may have
338                  * changed the on-disk data since we mounted r/o
339                  */
340                 truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
341
342                 JFS_SBI(sb)->flag = flag;
343                 return jfs_mount_rw(sb, 1);
344         }
345         if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
346                 rc = jfs_umount_rw(sb);
347                 JFS_SBI(sb)->flag = flag;
348                 return rc;
349         }
350         if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
351                 if (!(sb->s_flags & MS_RDONLY)) {
352                         rc = jfs_umount_rw(sb);
353                         if (rc)
354                                 return rc;
355                         JFS_SBI(sb)->flag = flag;
356                         return jfs_mount_rw(sb, 1);
357                 }
358         JFS_SBI(sb)->flag = flag;
359
360         return 0;
361 }
362
363 static int jfs_fill_super(struct super_block *sb, void *data, int silent)
364 {
365         struct jfs_sb_info *sbi;
366         struct inode *inode;
367         int rc;
368         s64 newLVSize = 0;
369         int flag;
370
371         jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
372
373         if (!new_valid_dev(sb->s_bdev->bd_dev))
374                 return -EOVERFLOW;
375
376         sbi = kmalloc(sizeof (struct jfs_sb_info), GFP_KERNEL);
377         if (!sbi)
378                 return -ENOSPC;
379         memset(sbi, 0, sizeof (struct jfs_sb_info));
380         sb->s_fs_info = sbi;
381         sbi->sb = sb;
382
383         /* initialize the mount flag and determine the default error handler */
384         flag = JFS_ERR_REMOUNT_RO;
385
386         if (!parse_options((char *) data, sb, &newLVSize, &flag)) {
387                 kfree(sbi);
388                 return -EINVAL;
389         }
390         sbi->flag = flag;
391
392 #ifdef CONFIG_JFS_POSIX_ACL
393         sb->s_flags |= MS_POSIXACL;
394 #endif
395
396         if (newLVSize) {
397                 printk(KERN_ERR "resize option for remount only\n");
398                 return -EINVAL;
399         }
400
401         /*
402          * Initialize blocksize to 4K.
403          */
404         sb_set_blocksize(sb, PSIZE);
405
406         /*
407          * Set method vectors.
408          */
409         sb->s_op = &jfs_super_operations;
410         sb->s_export_op = &jfs_export_operations;
411
412         /*
413          * Initialize direct-mapping inode/address-space
414          */
415         inode = new_inode(sb);
416         if (inode == NULL)
417                 goto out_kfree;
418         inode->i_ino = 0;
419         inode->i_nlink = 1;
420         inode->i_size = sb->s_bdev->bd_inode->i_size;
421         inode->i_mapping->a_ops = &jfs_metapage_aops;
422         mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
423
424         sbi->direct_inode = inode;
425
426         rc = jfs_mount(sb);
427         if (rc) {
428                 if (!silent) {
429                         jfs_err("jfs_mount failed w/return code = %d", rc);
430                 }
431                 goto out_mount_failed;
432         }
433         if (sb->s_flags & MS_RDONLY)
434                 sbi->log = NULL;
435         else {
436                 rc = jfs_mount_rw(sb, 0);
437                 if (rc) {
438                         if (!silent) {
439                                 jfs_err("jfs_mount_rw failed, return code = %d",
440                                         rc);
441                         }
442                         goto out_no_rw;
443                 }
444         }
445
446         sb->s_magic = JFS_SUPER_MAGIC;
447
448         inode = iget(sb, ROOT_I);
449         if (!inode || is_bad_inode(inode))
450                 goto out_no_root;
451         sb->s_root = d_alloc_root(inode);
452         if (!sb->s_root)
453                 goto out_no_root;
454
455         if (sbi->mntflag & JFS_OS2)
456                 sb->s_root->d_op = &jfs_ci_dentry_operations;
457
458         /* logical blocks are represented by 40 bits in pxd_t, etc. */
459         sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
460 #if BITS_PER_LONG == 32
461         /*
462          * Page cache is indexed by long.
463          * I would use MAX_LFS_FILESIZE, but it's only half as big
464          */
465         sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, sb->s_maxbytes);
466 #endif
467         sb->s_time_gran = 1;
468         return 0;
469
470 out_no_root:
471         jfs_err("jfs_read_super: get root inode failed");
472         if (inode)
473                 iput(inode);
474
475 out_no_rw:
476         rc = jfs_umount(sb);
477         if (rc) {
478                 jfs_err("jfs_umount failed with return code %d", rc);
479         }
480 out_mount_failed:
481         filemap_fdatawrite(sbi->direct_inode->i_mapping);
482         filemap_fdatawait(sbi->direct_inode->i_mapping);
483         truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
484         make_bad_inode(sbi->direct_inode);
485         iput(sbi->direct_inode);
486         sbi->direct_inode = NULL;
487 out_kfree:
488         if (sbi->nls_tab)
489                 unload_nls(sbi->nls_tab);
490         kfree(sbi);
491         return -EINVAL;
492 }
493
494 static void jfs_write_super_lockfs(struct super_block *sb)
495 {
496         struct jfs_sb_info *sbi = JFS_SBI(sb);
497         struct jfs_log *log = sbi->log;
498
499         if (!(sb->s_flags & MS_RDONLY)) {
500                 txQuiesce(sb);
501                 lmLogShutdown(log);
502                 updateSuper(sb, FM_CLEAN);
503         }
504 }
505
506 static void jfs_unlockfs(struct super_block *sb)
507 {
508         struct jfs_sb_info *sbi = JFS_SBI(sb);
509         struct jfs_log *log = sbi->log;
510         int rc = 0;
511
512         if (!(sb->s_flags & MS_RDONLY)) {
513                 updateSuper(sb, FM_MOUNT);
514                 if ((rc = lmLogInit(log)))
515                         jfs_err("jfs_unlock failed with return code %d", rc);
516                 else
517                         txResume(sb);
518         }
519 }
520
521 static struct super_block *jfs_get_sb(struct file_system_type *fs_type, 
522         int flags, const char *dev_name, void *data)
523 {
524         return get_sb_bdev(fs_type, flags, dev_name, data, jfs_fill_super);
525 }
526
527 static int jfs_sync_fs(struct super_block *sb, int wait)
528 {
529         struct jfs_log *log = JFS_SBI(sb)->log;
530
531         /* log == NULL indicates read-only mount */
532         if (log) {
533                 jfs_flush_journal(log, wait);
534                 jfs_syncpt(log);
535         }
536
537         return 0;
538 }
539
540 static struct super_operations jfs_super_operations = {
541         .alloc_inode    = jfs_alloc_inode,
542         .destroy_inode  = jfs_destroy_inode,
543         .read_inode     = jfs_read_inode,
544         .dirty_inode    = jfs_dirty_inode,
545         .write_inode    = jfs_write_inode,
546         .delete_inode   = jfs_delete_inode,
547         .put_super      = jfs_put_super,
548         .sync_fs        = jfs_sync_fs,
549         .write_super_lockfs = jfs_write_super_lockfs,
550         .unlockfs       = jfs_unlockfs,
551         .statfs         = jfs_statfs,
552         .remount_fs     = jfs_remount,
553 };
554
555 static struct export_operations jfs_export_operations = {
556         .get_parent     = jfs_get_parent,
557 };
558
559 static struct file_system_type jfs_fs_type = {
560         .owner          = THIS_MODULE,
561         .name           = "jfs",
562         .get_sb         = jfs_get_sb,
563         .kill_sb        = kill_block_super,
564         .fs_flags       = FS_REQUIRES_DEV,
565 };
566
567 static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags)
568 {
569         struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
570
571         if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
572             SLAB_CTOR_CONSTRUCTOR) {
573                 memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
574                 INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
575                 init_rwsem(&jfs_ip->rdwrlock);
576                 init_MUTEX(&jfs_ip->commit_sem);
577                 init_rwsem(&jfs_ip->xattr_sem);
578                 spin_lock_init(&jfs_ip->ag_lock);
579                 jfs_ip->active_ag = -1;
580 #ifdef CONFIG_JFS_POSIX_ACL
581                 jfs_ip->i_acl = JFS_ACL_NOT_CACHED;
582                 jfs_ip->i_default_acl = JFS_ACL_NOT_CACHED;
583 #endif
584                 inode_init_once(&jfs_ip->vfs_inode);
585         }
586 }
587
588 static int __init init_jfs_fs(void)
589 {
590         int i;
591         int rc;
592
593         jfs_inode_cachep =
594             kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0, 
595                             SLAB_RECLAIM_ACCOUNT, init_once, NULL);
596         if (jfs_inode_cachep == NULL)
597                 return -ENOMEM;
598
599         /*
600          * Metapage initialization
601          */
602         rc = metapage_init();
603         if (rc) {
604                 jfs_err("metapage_init failed w/rc = %d", rc);
605                 goto free_slab;
606         }
607
608         /*
609          * Transaction Manager initialization
610          */
611         rc = txInit();
612         if (rc) {
613                 jfs_err("txInit failed w/rc = %d", rc);
614                 goto free_metapage;
615         }
616
617         /*
618          * I/O completion thread (endio)
619          */
620         jfsIOthread = kernel_thread(jfsIOWait, NULL, CLONE_KERNEL);
621         if (jfsIOthread < 0) {
622                 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsIOthread);
623                 goto end_txmngr;
624         }
625         wait_for_completion(&jfsIOwait);        /* Wait until thread starts */
626
627         if (commit_threads < 1)
628                 commit_threads = num_online_cpus();
629         if (commit_threads > MAX_COMMIT_THREADS)
630                 commit_threads = MAX_COMMIT_THREADS;
631
632         for (i = 0; i < commit_threads; i++) {
633                 jfsCommitThread[i] = kernel_thread(jfs_lazycommit, NULL,
634                                                    CLONE_KERNEL);
635                 if (jfsCommitThread[i] < 0) {
636                         jfs_err("init_jfs_fs: fork failed w/rc = %d",
637                                 jfsCommitThread[i]);
638                         commit_threads = i;
639                         goto kill_committask;
640                 }
641                 /* Wait until thread starts */
642                 wait_for_completion(&jfsIOwait);
643         }
644
645         jfsSyncThread = kernel_thread(jfs_sync, NULL, CLONE_KERNEL);
646         if (jfsSyncThread < 0) {
647                 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsSyncThread);
648                 goto kill_committask;
649         }
650         wait_for_completion(&jfsIOwait);        /* Wait until thread starts */
651
652 #ifdef PROC_FS_JFS
653         jfs_proc_init();
654 #endif
655
656         return register_filesystem(&jfs_fs_type);
657
658 kill_committask:
659         jfs_stop_threads = 1;
660         wake_up_all(&jfs_commit_thread_wait);
661         for (i = 0; i < commit_threads; i++)
662                 wait_for_completion(&jfsIOwait);
663
664         wake_up(&jfs_IO_thread_wait);
665         wait_for_completion(&jfsIOwait);        /* Wait for thread exit */
666 end_txmngr:
667         txExit();
668 free_metapage:
669         metapage_exit();
670 free_slab:
671         kmem_cache_destroy(jfs_inode_cachep);
672         return rc;
673 }
674
675 static void __exit exit_jfs_fs(void)
676 {
677         int i;
678
679         jfs_info("exit_jfs_fs called");
680
681         jfs_stop_threads = 1;
682         txExit();
683         metapage_exit();
684         wake_up(&jfs_IO_thread_wait);
685         wait_for_completion(&jfsIOwait);        /* Wait until IO thread exits */
686         wake_up_all(&jfs_commit_thread_wait);
687         for (i = 0; i < commit_threads; i++)
688                 wait_for_completion(&jfsIOwait);
689         wake_up(&jfs_sync_thread_wait);
690         wait_for_completion(&jfsIOwait);        /* Wait until Sync thread exits */
691 #ifdef PROC_FS_JFS
692         jfs_proc_clean();
693 #endif
694         unregister_filesystem(&jfs_fs_type);
695         kmem_cache_destroy(jfs_inode_cachep);
696 }
697
698 module_init(init_jfs_fs)
699 module_exit(exit_jfs_fs)