super.c 17 KB

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