super.c 17 KB

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