super.c 17 KB

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