super.c 18 KB

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