super.c 17 KB

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