super.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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/module.h>
  21. #include <linux/parser.h>
  22. #include <linux/completion.h>
  23. #include <linux/vfs.h>
  24. #include <linux/quotaops.h>
  25. #include <linux/mount.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/kthread.h>
  28. #include <linux/posix_acl.h>
  29. #include <linux/buffer_head.h>
  30. #include <linux/exportfs.h>
  31. #include <linux/crc32.h>
  32. #include <linux/slab.h>
  33. #include <asm/uaccess.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/blkdev.h>
  36. #include "jfs_incore.h"
  37. #include "jfs_filsys.h"
  38. #include "jfs_inode.h"
  39. #include "jfs_metapage.h"
  40. #include "jfs_superblock.h"
  41. #include "jfs_dmap.h"
  42. #include "jfs_imap.h"
  43. #include "jfs_acl.h"
  44. #include "jfs_debug.h"
  45. MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
  46. MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
  47. MODULE_LICENSE("GPL");
  48. static struct kmem_cache * jfs_inode_cachep;
  49. static const struct super_operations jfs_super_operations;
  50. static const struct export_operations jfs_export_operations;
  51. static struct file_system_type jfs_fs_type;
  52. #define MAX_COMMIT_THREADS 64
  53. static int commit_threads = 0;
  54. module_param(commit_threads, int, 0);
  55. MODULE_PARM_DESC(commit_threads, "Number of commit threads");
  56. static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS];
  57. struct task_struct *jfsIOthread;
  58. struct task_struct *jfsSyncThread;
  59. #ifdef CONFIG_JFS_DEBUG
  60. int jfsloglevel = JFS_LOGLEVEL_WARN;
  61. module_param(jfsloglevel, int, 0644);
  62. MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)");
  63. #endif
  64. static void jfs_handle_error(struct super_block *sb)
  65. {
  66. struct jfs_sb_info *sbi = JFS_SBI(sb);
  67. if (sb->s_flags & MS_RDONLY)
  68. return;
  69. updateSuper(sb, FM_DIRTY);
  70. if (sbi->flag & JFS_ERR_PANIC)
  71. panic("JFS (device %s): panic forced after error\n",
  72. sb->s_id);
  73. else if (sbi->flag & JFS_ERR_REMOUNT_RO) {
  74. jfs_err("ERROR: (device %s): remounting filesystem "
  75. "as read-only\n",
  76. sb->s_id);
  77. sb->s_flags |= MS_RDONLY;
  78. }
  79. /* nothing is done for continue beyond marking the superblock dirty */
  80. }
  81. void jfs_error(struct super_block *sb, const char * function, ...)
  82. {
  83. static char error_buf[256];
  84. va_list args;
  85. va_start(args, function);
  86. vsnprintf(error_buf, sizeof(error_buf), function, args);
  87. va_end(args);
  88. pr_err("ERROR: (device %s): %s\n", sb->s_id, error_buf);
  89. jfs_handle_error(sb);
  90. }
  91. static struct inode *jfs_alloc_inode(struct super_block *sb)
  92. {
  93. struct jfs_inode_info *jfs_inode;
  94. jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS);
  95. if (!jfs_inode)
  96. return NULL;
  97. return &jfs_inode->vfs_inode;
  98. }
  99. static void jfs_i_callback(struct rcu_head *head)
  100. {
  101. struct inode *inode = container_of(head, struct inode, i_rcu);
  102. struct jfs_inode_info *ji = JFS_IP(inode);
  103. kmem_cache_free(jfs_inode_cachep, ji);
  104. }
  105. static void jfs_destroy_inode(struct inode *inode)
  106. {
  107. struct jfs_inode_info *ji = JFS_IP(inode);
  108. BUG_ON(!list_empty(&ji->anon_inode_list));
  109. spin_lock_irq(&ji->ag_lock);
  110. if (ji->active_ag != -1) {
  111. struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
  112. atomic_dec(&bmap->db_active[ji->active_ag]);
  113. ji->active_ag = -1;
  114. }
  115. spin_unlock_irq(&ji->ag_lock);
  116. call_rcu(&inode->i_rcu, jfs_i_callback);
  117. }
  118. static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  119. {
  120. struct jfs_sb_info *sbi = JFS_SBI(dentry->d_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_fsid.val[0] = (u32)crc32_le(0, sbi->uuid, sizeof(sbi->uuid)/2);
  145. buf->f_fsid.val[1] = (u32)crc32_le(0, sbi->uuid + sizeof(sbi->uuid)/2,
  146. sizeof(sbi->uuid)/2);
  147. buf->f_namelen = JFS_NAME_MAX;
  148. return 0;
  149. }
  150. static void jfs_put_super(struct super_block *sb)
  151. {
  152. struct jfs_sb_info *sbi = JFS_SBI(sb);
  153. int rc;
  154. jfs_info("In jfs_put_super");
  155. dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
  156. rc = jfs_umount(sb);
  157. if (rc)
  158. jfs_err("jfs_umount failed with return code %d", rc);
  159. unload_nls(sbi->nls_tab);
  160. truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
  161. iput(sbi->direct_inode);
  162. kfree(sbi);
  163. }
  164. enum {
  165. Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
  166. Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
  167. Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
  168. Opt_discard, Opt_nodiscard, Opt_discard_minblk
  169. };
  170. static const match_table_t tokens = {
  171. {Opt_integrity, "integrity"},
  172. {Opt_nointegrity, "nointegrity"},
  173. {Opt_iocharset, "iocharset=%s"},
  174. {Opt_resize, "resize=%u"},
  175. {Opt_resize_nosize, "resize"},
  176. {Opt_errors, "errors=%s"},
  177. {Opt_ignore, "noquota"},
  178. {Opt_ignore, "quota"},
  179. {Opt_usrquota, "usrquota"},
  180. {Opt_grpquota, "grpquota"},
  181. {Opt_uid, "uid=%u"},
  182. {Opt_gid, "gid=%u"},
  183. {Opt_umask, "umask=%u"},
  184. {Opt_discard, "discard"},
  185. {Opt_nodiscard, "nodiscard"},
  186. {Opt_discard_minblk, "discard=%u"},
  187. {Opt_err, NULL}
  188. };
  189. static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
  190. int *flag)
  191. {
  192. void *nls_map = (void *)-1; /* -1: no change; NULL: none */
  193. char *p;
  194. struct jfs_sb_info *sbi = JFS_SBI(sb);
  195. *newLVSize = 0;
  196. if (!options)
  197. return 1;
  198. while ((p = strsep(&options, ",")) != NULL) {
  199. substring_t args[MAX_OPT_ARGS];
  200. int token;
  201. if (!*p)
  202. continue;
  203. token = match_token(p, tokens, args);
  204. switch (token) {
  205. case Opt_integrity:
  206. *flag &= ~JFS_NOINTEGRITY;
  207. break;
  208. case Opt_nointegrity:
  209. *flag |= JFS_NOINTEGRITY;
  210. break;
  211. case Opt_ignore:
  212. /* Silently ignore the quota options */
  213. /* Don't do anything ;-) */
  214. break;
  215. case Opt_iocharset:
  216. if (nls_map && nls_map != (void *) -1)
  217. unload_nls(nls_map);
  218. if (!strcmp(args[0].from, "none"))
  219. nls_map = NULL;
  220. else {
  221. nls_map = load_nls(args[0].from);
  222. if (!nls_map) {
  223. pr_err("JFS: charset not found\n");
  224. goto cleanup;
  225. }
  226. }
  227. break;
  228. case Opt_resize:
  229. {
  230. char *resize = args[0].from;
  231. *newLVSize = simple_strtoull(resize, &resize, 0);
  232. break;
  233. }
  234. case Opt_resize_nosize:
  235. {
  236. *newLVSize = sb->s_bdev->bd_inode->i_size >>
  237. sb->s_blocksize_bits;
  238. if (*newLVSize == 0)
  239. pr_err("JFS: Cannot determine volume size\n");
  240. break;
  241. }
  242. case Opt_errors:
  243. {
  244. char *errors = args[0].from;
  245. if (!errors || !*errors)
  246. goto cleanup;
  247. if (!strcmp(errors, "continue")) {
  248. *flag &= ~JFS_ERR_REMOUNT_RO;
  249. *flag &= ~JFS_ERR_PANIC;
  250. *flag |= JFS_ERR_CONTINUE;
  251. } else if (!strcmp(errors, "remount-ro")) {
  252. *flag &= ~JFS_ERR_CONTINUE;
  253. *flag &= ~JFS_ERR_PANIC;
  254. *flag |= JFS_ERR_REMOUNT_RO;
  255. } else if (!strcmp(errors, "panic")) {
  256. *flag &= ~JFS_ERR_CONTINUE;
  257. *flag &= ~JFS_ERR_REMOUNT_RO;
  258. *flag |= JFS_ERR_PANIC;
  259. } else {
  260. pr_err("JFS: %s is an invalid error handler\n",
  261. errors);
  262. goto cleanup;
  263. }
  264. break;
  265. }
  266. #ifdef CONFIG_QUOTA
  267. case Opt_quota:
  268. case Opt_usrquota:
  269. *flag |= JFS_USRQUOTA;
  270. break;
  271. case Opt_grpquota:
  272. *flag |= JFS_GRPQUOTA;
  273. break;
  274. #else
  275. case Opt_usrquota:
  276. case Opt_grpquota:
  277. case Opt_quota:
  278. pr_err("JFS: quota operations not supported\n");
  279. break;
  280. #endif
  281. case Opt_uid:
  282. {
  283. char *uid = args[0].from;
  284. sbi->uid = simple_strtoul(uid, &uid, 0);
  285. break;
  286. }
  287. case Opt_gid:
  288. {
  289. char *gid = args[0].from;
  290. sbi->gid = simple_strtoul(gid, &gid, 0);
  291. break;
  292. }
  293. case Opt_umask:
  294. {
  295. char *umask = args[0].from;
  296. sbi->umask = simple_strtoul(umask, &umask, 8);
  297. if (sbi->umask & ~0777) {
  298. pr_err("JFS: Invalid value of umask\n");
  299. goto cleanup;
  300. }
  301. break;
  302. }
  303. case Opt_discard:
  304. {
  305. struct request_queue *q = bdev_get_queue(sb->s_bdev);
  306. /* if set to 1, even copying files will cause
  307. * trimming :O
  308. * -> user has more control over the online trimming
  309. */
  310. sbi->minblks_trim = 64;
  311. if (blk_queue_discard(q)) {
  312. *flag |= JFS_DISCARD;
  313. } else {
  314. pr_err("JFS: discard option " \
  315. "not supported on device\n");
  316. }
  317. break;
  318. }
  319. case Opt_nodiscard:
  320. *flag &= ~JFS_DISCARD;
  321. break;
  322. case Opt_discard_minblk:
  323. {
  324. struct request_queue *q = bdev_get_queue(sb->s_bdev);
  325. char *minblks_trim = args[0].from;
  326. if (blk_queue_discard(q)) {
  327. *flag |= JFS_DISCARD;
  328. sbi->minblks_trim = simple_strtoull(
  329. minblks_trim, &minblks_trim, 0);
  330. } else {
  331. pr_err("JFS: discard option " \
  332. "not supported on device\n");
  333. }
  334. break;
  335. }
  336. default:
  337. printk("jfs: Unrecognized mount option \"%s\" "
  338. " or missing value\n", p);
  339. goto cleanup;
  340. }
  341. }
  342. if (nls_map != (void *) -1) {
  343. /* Discard old (if remount) */
  344. unload_nls(sbi->nls_tab);
  345. sbi->nls_tab = nls_map;
  346. }
  347. return 1;
  348. cleanup:
  349. if (nls_map && nls_map != (void *) -1)
  350. unload_nls(nls_map);
  351. return 0;
  352. }
  353. static int jfs_remount(struct super_block *sb, int *flags, char *data)
  354. {
  355. s64 newLVSize = 0;
  356. int rc = 0;
  357. int flag = JFS_SBI(sb)->flag;
  358. int ret;
  359. if (!parse_options(data, sb, &newLVSize, &flag)) {
  360. return -EINVAL;
  361. }
  362. if (newLVSize) {
  363. if (sb->s_flags & MS_RDONLY) {
  364. pr_err("JFS: resize requires volume" \
  365. " to be mounted read-write\n");
  366. return -EROFS;
  367. }
  368. rc = jfs_extendfs(sb, newLVSize, 0);
  369. if (rc)
  370. return rc;
  371. }
  372. if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
  373. /*
  374. * Invalidate any previously read metadata. fsck may have
  375. * changed the on-disk data since we mounted r/o
  376. */
  377. truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
  378. JFS_SBI(sb)->flag = flag;
  379. ret = jfs_mount_rw(sb, 1);
  380. /* mark the fs r/w for quota activity */
  381. sb->s_flags &= ~MS_RDONLY;
  382. dquot_resume(sb, -1);
  383. return ret;
  384. }
  385. if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
  386. rc = dquot_suspend(sb, -1);
  387. if (rc < 0) {
  388. return rc;
  389. }
  390. rc = jfs_umount_rw(sb);
  391. JFS_SBI(sb)->flag = flag;
  392. return rc;
  393. }
  394. if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
  395. if (!(sb->s_flags & MS_RDONLY)) {
  396. rc = jfs_umount_rw(sb);
  397. if (rc)
  398. return rc;
  399. JFS_SBI(sb)->flag = flag;
  400. ret = jfs_mount_rw(sb, 1);
  401. return ret;
  402. }
  403. JFS_SBI(sb)->flag = flag;
  404. return 0;
  405. }
  406. static int jfs_fill_super(struct super_block *sb, void *data, int silent)
  407. {
  408. struct jfs_sb_info *sbi;
  409. struct inode *inode;
  410. int rc;
  411. s64 newLVSize = 0;
  412. int flag, ret = -EINVAL;
  413. jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
  414. if (!new_valid_dev(sb->s_bdev->bd_dev))
  415. return -EOVERFLOW;
  416. sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL);
  417. if (!sbi)
  418. return -ENOMEM;
  419. sb->s_fs_info = sbi;
  420. sb->s_max_links = JFS_LINK_MAX;
  421. sbi->sb = sb;
  422. sbi->uid = sbi->gid = sbi->umask = -1;
  423. /* initialize the mount flag and determine the default error handler */
  424. flag = JFS_ERR_REMOUNT_RO;
  425. if (!parse_options((char *) data, sb, &newLVSize, &flag))
  426. goto out_kfree;
  427. sbi->flag = flag;
  428. #ifdef CONFIG_JFS_POSIX_ACL
  429. sb->s_flags |= MS_POSIXACL;
  430. #endif
  431. if (newLVSize) {
  432. pr_err("resize option for remount only\n");
  433. goto out_kfree;
  434. }
  435. /*
  436. * Initialize blocksize to 4K.
  437. */
  438. sb_set_blocksize(sb, PSIZE);
  439. /*
  440. * Set method vectors.
  441. */
  442. sb->s_op = &jfs_super_operations;
  443. sb->s_export_op = &jfs_export_operations;
  444. #ifdef CONFIG_QUOTA
  445. sb->dq_op = &dquot_operations;
  446. sb->s_qcop = &dquot_quotactl_ops;
  447. #endif
  448. /*
  449. * Initialize direct-mapping inode/address-space
  450. */
  451. inode = new_inode(sb);
  452. if (inode == NULL) {
  453. ret = -ENOMEM;
  454. goto out_unload;
  455. }
  456. inode->i_ino = 0;
  457. inode->i_size = sb->s_bdev->bd_inode->i_size;
  458. inode->i_mapping->a_ops = &jfs_metapage_aops;
  459. insert_inode_hash(inode);
  460. mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
  461. sbi->direct_inode = inode;
  462. rc = jfs_mount(sb);
  463. if (rc) {
  464. if (!silent) {
  465. jfs_err("jfs_mount failed w/return code = %d", rc);
  466. }
  467. goto out_mount_failed;
  468. }
  469. if (sb->s_flags & MS_RDONLY)
  470. sbi->log = NULL;
  471. else {
  472. rc = jfs_mount_rw(sb, 0);
  473. if (rc) {
  474. if (!silent) {
  475. jfs_err("jfs_mount_rw failed, return code = %d",
  476. rc);
  477. }
  478. goto out_no_rw;
  479. }
  480. }
  481. sb->s_magic = JFS_SUPER_MAGIC;
  482. if (sbi->mntflag & JFS_OS2)
  483. sb->s_d_op = &jfs_ci_dentry_operations;
  484. inode = jfs_iget(sb, ROOT_I);
  485. if (IS_ERR(inode)) {
  486. ret = PTR_ERR(inode);
  487. goto out_no_rw;
  488. }
  489. sb->s_root = d_make_root(inode);
  490. if (!sb->s_root)
  491. goto out_no_root;
  492. /* logical blocks are represented by 40 bits in pxd_t, etc. */
  493. sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
  494. #if BITS_PER_LONG == 32
  495. /*
  496. * Page cache is indexed by long.
  497. * I would use MAX_LFS_FILESIZE, but it's only half as big
  498. */
  499. sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes);
  500. #endif
  501. sb->s_time_gran = 1;
  502. return 0;
  503. out_no_root:
  504. jfs_err("jfs_read_super: get root dentry failed");
  505. out_no_rw:
  506. rc = jfs_umount(sb);
  507. if (rc) {
  508. jfs_err("jfs_umount failed with return code %d", rc);
  509. }
  510. out_mount_failed:
  511. filemap_write_and_wait(sbi->direct_inode->i_mapping);
  512. truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
  513. make_bad_inode(sbi->direct_inode);
  514. iput(sbi->direct_inode);
  515. sbi->direct_inode = NULL;
  516. out_unload:
  517. if (sbi->nls_tab)
  518. unload_nls(sbi->nls_tab);
  519. out_kfree:
  520. kfree(sbi);
  521. return ret;
  522. }
  523. static int jfs_freeze(struct super_block *sb)
  524. {
  525. struct jfs_sb_info *sbi = JFS_SBI(sb);
  526. struct jfs_log *log = sbi->log;
  527. if (!(sb->s_flags & MS_RDONLY)) {
  528. txQuiesce(sb);
  529. lmLogShutdown(log);
  530. updateSuper(sb, FM_CLEAN);
  531. }
  532. return 0;
  533. }
  534. static int jfs_unfreeze(struct super_block *sb)
  535. {
  536. struct jfs_sb_info *sbi = JFS_SBI(sb);
  537. struct jfs_log *log = sbi->log;
  538. int rc = 0;
  539. if (!(sb->s_flags & MS_RDONLY)) {
  540. updateSuper(sb, FM_MOUNT);
  541. if ((rc = lmLogInit(log)))
  542. jfs_err("jfs_unlock failed with return code %d", rc);
  543. else
  544. txResume(sb);
  545. }
  546. return 0;
  547. }
  548. static struct dentry *jfs_do_mount(struct file_system_type *fs_type,
  549. int flags, const char *dev_name, void *data)
  550. {
  551. return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super);
  552. }
  553. static int jfs_sync_fs(struct super_block *sb, int wait)
  554. {
  555. struct jfs_log *log = JFS_SBI(sb)->log;
  556. /* log == NULL indicates read-only mount */
  557. if (log) {
  558. /*
  559. * Write quota structures to quota file, sync_blockdev() will
  560. * write them to disk later
  561. */
  562. dquot_writeback_dquots(sb, -1);
  563. jfs_flush_journal(log, wait);
  564. jfs_syncpt(log, 0);
  565. }
  566. return 0;
  567. }
  568. static int jfs_show_options(struct seq_file *seq, struct dentry *root)
  569. {
  570. struct jfs_sb_info *sbi = JFS_SBI(root->d_sb);
  571. if (sbi->uid != -1)
  572. seq_printf(seq, ",uid=%d", sbi->uid);
  573. if (sbi->gid != -1)
  574. seq_printf(seq, ",gid=%d", sbi->gid);
  575. if (sbi->umask != -1)
  576. seq_printf(seq, ",umask=%03o", sbi->umask);
  577. if (sbi->flag & JFS_NOINTEGRITY)
  578. seq_puts(seq, ",nointegrity");
  579. if (sbi->flag & JFS_DISCARD)
  580. seq_printf(seq, ",discard=%u", sbi->minblks_trim);
  581. if (sbi->nls_tab)
  582. seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
  583. if (sbi->flag & JFS_ERR_CONTINUE)
  584. seq_printf(seq, ",errors=continue");
  585. if (sbi->flag & JFS_ERR_PANIC)
  586. seq_printf(seq, ",errors=panic");
  587. #ifdef CONFIG_QUOTA
  588. if (sbi->flag & JFS_USRQUOTA)
  589. seq_puts(seq, ",usrquota");
  590. if (sbi->flag & JFS_GRPQUOTA)
  591. seq_puts(seq, ",grpquota");
  592. #endif
  593. return 0;
  594. }
  595. #ifdef CONFIG_QUOTA
  596. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  597. * acquiring the locks... As quota files are never truncated and quota code
  598. * itself serializes the operations (and no one else should touch the files)
  599. * we don't have to be afraid of races */
  600. static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
  601. size_t len, loff_t off)
  602. {
  603. struct inode *inode = sb_dqopt(sb)->files[type];
  604. sector_t blk = off >> sb->s_blocksize_bits;
  605. int err = 0;
  606. int offset = off & (sb->s_blocksize - 1);
  607. int tocopy;
  608. size_t toread;
  609. struct buffer_head tmp_bh;
  610. struct buffer_head *bh;
  611. loff_t i_size = i_size_read(inode);
  612. if (off > i_size)
  613. return 0;
  614. if (off+len > i_size)
  615. len = i_size-off;
  616. toread = len;
  617. while (toread > 0) {
  618. tocopy = sb->s_blocksize - offset < toread ?
  619. sb->s_blocksize - offset : toread;
  620. tmp_bh.b_state = 0;
  621. tmp_bh.b_size = 1 << inode->i_blkbits;
  622. err = jfs_get_block(inode, blk, &tmp_bh, 0);
  623. if (err)
  624. return err;
  625. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  626. memset(data, 0, tocopy);
  627. else {
  628. bh = sb_bread(sb, tmp_bh.b_blocknr);
  629. if (!bh)
  630. return -EIO;
  631. memcpy(data, bh->b_data+offset, tocopy);
  632. brelse(bh);
  633. }
  634. offset = 0;
  635. toread -= tocopy;
  636. data += tocopy;
  637. blk++;
  638. }
  639. return len;
  640. }
  641. /* Write to quotafile */
  642. static ssize_t jfs_quota_write(struct super_block *sb, int type,
  643. const char *data, size_t len, loff_t off)
  644. {
  645. struct inode *inode = sb_dqopt(sb)->files[type];
  646. sector_t blk = off >> sb->s_blocksize_bits;
  647. int err = 0;
  648. int offset = off & (sb->s_blocksize - 1);
  649. int tocopy;
  650. size_t towrite = len;
  651. struct buffer_head tmp_bh;
  652. struct buffer_head *bh;
  653. mutex_lock(&inode->i_mutex);
  654. while (towrite > 0) {
  655. tocopy = sb->s_blocksize - offset < towrite ?
  656. sb->s_blocksize - offset : towrite;
  657. tmp_bh.b_state = 0;
  658. tmp_bh.b_size = 1 << inode->i_blkbits;
  659. err = jfs_get_block(inode, blk, &tmp_bh, 1);
  660. if (err)
  661. goto out;
  662. if (offset || tocopy != sb->s_blocksize)
  663. bh = sb_bread(sb, tmp_bh.b_blocknr);
  664. else
  665. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  666. if (!bh) {
  667. err = -EIO;
  668. goto out;
  669. }
  670. lock_buffer(bh);
  671. memcpy(bh->b_data+offset, data, tocopy);
  672. flush_dcache_page(bh->b_page);
  673. set_buffer_uptodate(bh);
  674. mark_buffer_dirty(bh);
  675. unlock_buffer(bh);
  676. brelse(bh);
  677. offset = 0;
  678. towrite -= tocopy;
  679. data += tocopy;
  680. blk++;
  681. }
  682. out:
  683. if (len == towrite) {
  684. mutex_unlock(&inode->i_mutex);
  685. return err;
  686. }
  687. if (inode->i_size < off+len-towrite)
  688. i_size_write(inode, off+len-towrite);
  689. inode->i_version++;
  690. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  691. mark_inode_dirty(inode);
  692. mutex_unlock(&inode->i_mutex);
  693. return len - towrite;
  694. }
  695. #endif
  696. static const struct super_operations jfs_super_operations = {
  697. .alloc_inode = jfs_alloc_inode,
  698. .destroy_inode = jfs_destroy_inode,
  699. .dirty_inode = jfs_dirty_inode,
  700. .write_inode = jfs_write_inode,
  701. .evict_inode = jfs_evict_inode,
  702. .put_super = jfs_put_super,
  703. .sync_fs = jfs_sync_fs,
  704. .freeze_fs = jfs_freeze,
  705. .unfreeze_fs = jfs_unfreeze,
  706. .statfs = jfs_statfs,
  707. .remount_fs = jfs_remount,
  708. .show_options = jfs_show_options,
  709. #ifdef CONFIG_QUOTA
  710. .quota_read = jfs_quota_read,
  711. .quota_write = jfs_quota_write,
  712. #endif
  713. };
  714. static const struct export_operations jfs_export_operations = {
  715. .fh_to_dentry = jfs_fh_to_dentry,
  716. .fh_to_parent = jfs_fh_to_parent,
  717. .get_parent = jfs_get_parent,
  718. };
  719. static struct file_system_type jfs_fs_type = {
  720. .owner = THIS_MODULE,
  721. .name = "jfs",
  722. .mount = jfs_do_mount,
  723. .kill_sb = kill_block_super,
  724. .fs_flags = FS_REQUIRES_DEV,
  725. };
  726. static void init_once(void *foo)
  727. {
  728. struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
  729. memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
  730. INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
  731. init_rwsem(&jfs_ip->rdwrlock);
  732. mutex_init(&jfs_ip->commit_mutex);
  733. init_rwsem(&jfs_ip->xattr_sem);
  734. spin_lock_init(&jfs_ip->ag_lock);
  735. jfs_ip->active_ag = -1;
  736. inode_init_once(&jfs_ip->vfs_inode);
  737. }
  738. static int __init init_jfs_fs(void)
  739. {
  740. int i;
  741. int rc;
  742. jfs_inode_cachep =
  743. kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
  744. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
  745. init_once);
  746. if (jfs_inode_cachep == NULL)
  747. return -ENOMEM;
  748. /*
  749. * Metapage initialization
  750. */
  751. rc = metapage_init();
  752. if (rc) {
  753. jfs_err("metapage_init failed w/rc = %d", rc);
  754. goto free_slab;
  755. }
  756. /*
  757. * Transaction Manager initialization
  758. */
  759. rc = txInit();
  760. if (rc) {
  761. jfs_err("txInit failed w/rc = %d", rc);
  762. goto free_metapage;
  763. }
  764. /*
  765. * I/O completion thread (endio)
  766. */
  767. jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO");
  768. if (IS_ERR(jfsIOthread)) {
  769. rc = PTR_ERR(jfsIOthread);
  770. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  771. goto end_txmngr;
  772. }
  773. if (commit_threads < 1)
  774. commit_threads = num_online_cpus();
  775. if (commit_threads > MAX_COMMIT_THREADS)
  776. commit_threads = MAX_COMMIT_THREADS;
  777. for (i = 0; i < commit_threads; i++) {
  778. jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit");
  779. if (IS_ERR(jfsCommitThread[i])) {
  780. rc = PTR_ERR(jfsCommitThread[i]);
  781. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  782. commit_threads = i;
  783. goto kill_committask;
  784. }
  785. }
  786. jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync");
  787. if (IS_ERR(jfsSyncThread)) {
  788. rc = PTR_ERR(jfsSyncThread);
  789. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  790. goto kill_committask;
  791. }
  792. #ifdef PROC_FS_JFS
  793. jfs_proc_init();
  794. #endif
  795. rc = register_filesystem(&jfs_fs_type);
  796. if (!rc)
  797. return 0;
  798. #ifdef PROC_FS_JFS
  799. jfs_proc_clean();
  800. #endif
  801. kthread_stop(jfsSyncThread);
  802. kill_committask:
  803. for (i = 0; i < commit_threads; i++)
  804. kthread_stop(jfsCommitThread[i]);
  805. kthread_stop(jfsIOthread);
  806. end_txmngr:
  807. txExit();
  808. free_metapage:
  809. metapage_exit();
  810. free_slab:
  811. kmem_cache_destroy(jfs_inode_cachep);
  812. return rc;
  813. }
  814. static void __exit exit_jfs_fs(void)
  815. {
  816. int i;
  817. jfs_info("exit_jfs_fs called");
  818. txExit();
  819. metapage_exit();
  820. kthread_stop(jfsIOthread);
  821. for (i = 0; i < commit_threads; i++)
  822. kthread_stop(jfsCommitThread[i]);
  823. kthread_stop(jfsSyncThread);
  824. #ifdef PROC_FS_JFS
  825. jfs_proc_clean();
  826. #endif
  827. unregister_filesystem(&jfs_fs_type);
  828. kmem_cache_destroy(jfs_inode_cachep);
  829. }
  830. module_init(init_jfs_fs)
  831. module_exit(exit_jfs_fs)