super.c 17 KB

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