super.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  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 many 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. uid_t val = simple_strtoul(uid, &uid, 0);
  285. sbi->uid = make_kuid(current_user_ns(), val);
  286. if (!uid_valid(sbi->uid))
  287. goto cleanup;
  288. break;
  289. }
  290. case Opt_gid:
  291. {
  292. char *gid = args[0].from;
  293. gid_t val = simple_strtoul(gid, &gid, 0);
  294. sbi->gid = make_kgid(current_user_ns(), val);
  295. if (!gid_valid(sbi->gid))
  296. goto cleanup;
  297. break;
  298. }
  299. case Opt_umask:
  300. {
  301. char *umask = args[0].from;
  302. sbi->umask = simple_strtoul(umask, &umask, 8);
  303. if (sbi->umask & ~0777) {
  304. pr_err("JFS: Invalid value of umask\n");
  305. goto cleanup;
  306. }
  307. break;
  308. }
  309. case Opt_discard:
  310. {
  311. struct request_queue *q = bdev_get_queue(sb->s_bdev);
  312. /* if set to 1, even copying files will cause
  313. * trimming :O
  314. * -> user has more control over the online trimming
  315. */
  316. sbi->minblks_trim = 64;
  317. if (blk_queue_discard(q)) {
  318. *flag |= JFS_DISCARD;
  319. } else {
  320. pr_err("JFS: discard option " \
  321. "not supported on device\n");
  322. }
  323. break;
  324. }
  325. case Opt_nodiscard:
  326. *flag &= ~JFS_DISCARD;
  327. break;
  328. case Opt_discard_minblk:
  329. {
  330. struct request_queue *q = bdev_get_queue(sb->s_bdev);
  331. char *minblks_trim = args[0].from;
  332. if (blk_queue_discard(q)) {
  333. *flag |= JFS_DISCARD;
  334. sbi->minblks_trim = simple_strtoull(
  335. minblks_trim, &minblks_trim, 0);
  336. } else {
  337. pr_err("JFS: discard option " \
  338. "not supported on device\n");
  339. }
  340. break;
  341. }
  342. default:
  343. printk("jfs: Unrecognized mount option \"%s\" "
  344. " or missing value\n", p);
  345. goto cleanup;
  346. }
  347. }
  348. if (nls_map != (void *) -1) {
  349. /* Discard old (if remount) */
  350. unload_nls(sbi->nls_tab);
  351. sbi->nls_tab = nls_map;
  352. }
  353. return 1;
  354. cleanup:
  355. if (nls_map && nls_map != (void *) -1)
  356. unload_nls(nls_map);
  357. return 0;
  358. }
  359. static int jfs_remount(struct super_block *sb, int *flags, char *data)
  360. {
  361. s64 newLVSize = 0;
  362. int rc = 0;
  363. int flag = JFS_SBI(sb)->flag;
  364. int ret;
  365. if (!parse_options(data, sb, &newLVSize, &flag)) {
  366. return -EINVAL;
  367. }
  368. if (newLVSize) {
  369. if (sb->s_flags & MS_RDONLY) {
  370. pr_err("JFS: resize requires volume" \
  371. " to be mounted read-write\n");
  372. return -EROFS;
  373. }
  374. rc = jfs_extendfs(sb, newLVSize, 0);
  375. if (rc)
  376. return rc;
  377. }
  378. if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
  379. /*
  380. * Invalidate any previously read metadata. fsck may have
  381. * changed the on-disk data since we mounted r/o
  382. */
  383. truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
  384. JFS_SBI(sb)->flag = flag;
  385. ret = jfs_mount_rw(sb, 1);
  386. /* mark the fs r/w for quota activity */
  387. sb->s_flags &= ~MS_RDONLY;
  388. dquot_resume(sb, -1);
  389. return ret;
  390. }
  391. if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
  392. rc = dquot_suspend(sb, -1);
  393. if (rc < 0) {
  394. return rc;
  395. }
  396. rc = jfs_umount_rw(sb);
  397. JFS_SBI(sb)->flag = flag;
  398. return rc;
  399. }
  400. if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
  401. if (!(sb->s_flags & MS_RDONLY)) {
  402. rc = jfs_umount_rw(sb);
  403. if (rc)
  404. return rc;
  405. JFS_SBI(sb)->flag = flag;
  406. ret = jfs_mount_rw(sb, 1);
  407. return ret;
  408. }
  409. JFS_SBI(sb)->flag = flag;
  410. return 0;
  411. }
  412. static int jfs_fill_super(struct super_block *sb, void *data, int silent)
  413. {
  414. struct jfs_sb_info *sbi;
  415. struct inode *inode;
  416. int rc;
  417. s64 newLVSize = 0;
  418. int flag, ret = -EINVAL;
  419. jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
  420. if (!new_valid_dev(sb->s_bdev->bd_dev))
  421. return -EOVERFLOW;
  422. sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL);
  423. if (!sbi)
  424. return -ENOMEM;
  425. sb->s_fs_info = sbi;
  426. sb->s_max_links = JFS_LINK_MAX;
  427. sbi->sb = sb;
  428. sbi->uid = INVALID_UID;
  429. sbi->gid = INVALID_GID;
  430. sbi->umask = -1;
  431. /* initialize the mount flag and determine the default error handler */
  432. flag = JFS_ERR_REMOUNT_RO;
  433. if (!parse_options((char *) data, sb, &newLVSize, &flag))
  434. goto out_kfree;
  435. sbi->flag = flag;
  436. #ifdef CONFIG_JFS_POSIX_ACL
  437. sb->s_flags |= MS_POSIXACL;
  438. #endif
  439. if (newLVSize) {
  440. pr_err("resize option for remount only\n");
  441. goto out_kfree;
  442. }
  443. /*
  444. * Initialize blocksize to 4K.
  445. */
  446. sb_set_blocksize(sb, PSIZE);
  447. /*
  448. * Set method vectors.
  449. */
  450. sb->s_op = &jfs_super_operations;
  451. sb->s_export_op = &jfs_export_operations;
  452. #ifdef CONFIG_QUOTA
  453. sb->dq_op = &dquot_operations;
  454. sb->s_qcop = &dquot_quotactl_ops;
  455. #endif
  456. /*
  457. * Initialize direct-mapping inode/address-space
  458. */
  459. inode = new_inode(sb);
  460. if (inode == NULL) {
  461. ret = -ENOMEM;
  462. goto out_unload;
  463. }
  464. inode->i_ino = 0;
  465. inode->i_size = sb->s_bdev->bd_inode->i_size;
  466. inode->i_mapping->a_ops = &jfs_metapage_aops;
  467. insert_inode_hash(inode);
  468. mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
  469. sbi->direct_inode = inode;
  470. rc = jfs_mount(sb);
  471. if (rc) {
  472. if (!silent) {
  473. jfs_err("jfs_mount failed w/return code = %d", rc);
  474. }
  475. goto out_mount_failed;
  476. }
  477. if (sb->s_flags & MS_RDONLY)
  478. sbi->log = NULL;
  479. else {
  480. rc = jfs_mount_rw(sb, 0);
  481. if (rc) {
  482. if (!silent) {
  483. jfs_err("jfs_mount_rw failed, return code = %d",
  484. rc);
  485. }
  486. goto out_no_rw;
  487. }
  488. }
  489. sb->s_magic = JFS_SUPER_MAGIC;
  490. if (sbi->mntflag & JFS_OS2)
  491. sb->s_d_op = &jfs_ci_dentry_operations;
  492. inode = jfs_iget(sb, ROOT_I);
  493. if (IS_ERR(inode)) {
  494. ret = PTR_ERR(inode);
  495. goto out_no_rw;
  496. }
  497. sb->s_root = d_make_root(inode);
  498. if (!sb->s_root)
  499. goto out_no_root;
  500. /* logical blocks are represented by 40 bits in pxd_t, etc. */
  501. sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
  502. #if BITS_PER_LONG == 32
  503. /*
  504. * Page cache is indexed by long.
  505. * I would use MAX_LFS_FILESIZE, but it's only half as big
  506. */
  507. sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes);
  508. #endif
  509. sb->s_time_gran = 1;
  510. return 0;
  511. out_no_root:
  512. jfs_err("jfs_read_super: get root dentry failed");
  513. out_no_rw:
  514. rc = jfs_umount(sb);
  515. if (rc) {
  516. jfs_err("jfs_umount failed with return code %d", rc);
  517. }
  518. out_mount_failed:
  519. filemap_write_and_wait(sbi->direct_inode->i_mapping);
  520. truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
  521. make_bad_inode(sbi->direct_inode);
  522. iput(sbi->direct_inode);
  523. sbi->direct_inode = NULL;
  524. out_unload:
  525. if (sbi->nls_tab)
  526. unload_nls(sbi->nls_tab);
  527. out_kfree:
  528. kfree(sbi);
  529. return ret;
  530. }
  531. static int jfs_freeze(struct super_block *sb)
  532. {
  533. struct jfs_sb_info *sbi = JFS_SBI(sb);
  534. struct jfs_log *log = sbi->log;
  535. if (!(sb->s_flags & MS_RDONLY)) {
  536. txQuiesce(sb);
  537. lmLogShutdown(log);
  538. updateSuper(sb, FM_CLEAN);
  539. }
  540. return 0;
  541. }
  542. static int jfs_unfreeze(struct super_block *sb)
  543. {
  544. struct jfs_sb_info *sbi = JFS_SBI(sb);
  545. struct jfs_log *log = sbi->log;
  546. int rc = 0;
  547. if (!(sb->s_flags & MS_RDONLY)) {
  548. updateSuper(sb, FM_MOUNT);
  549. if ((rc = lmLogInit(log)))
  550. jfs_err("jfs_unlock failed with return code %d", rc);
  551. else
  552. txResume(sb);
  553. }
  554. return 0;
  555. }
  556. static struct dentry *jfs_do_mount(struct file_system_type *fs_type,
  557. int flags, const char *dev_name, void *data)
  558. {
  559. return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super);
  560. }
  561. static int jfs_sync_fs(struct super_block *sb, int wait)
  562. {
  563. struct jfs_log *log = JFS_SBI(sb)->log;
  564. /* log == NULL indicates read-only mount */
  565. if (log) {
  566. /*
  567. * Write quota structures to quota file, sync_blockdev() will
  568. * write them to disk later
  569. */
  570. dquot_writeback_dquots(sb, -1);
  571. jfs_flush_journal(log, wait);
  572. jfs_syncpt(log, 0);
  573. }
  574. return 0;
  575. }
  576. static int jfs_show_options(struct seq_file *seq, struct dentry *root)
  577. {
  578. struct jfs_sb_info *sbi = JFS_SBI(root->d_sb);
  579. if (uid_valid(sbi->uid))
  580. seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid));
  581. if (gid_valid(sbi->gid))
  582. seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid));
  583. if (sbi->umask != -1)
  584. seq_printf(seq, ",umask=%03o", sbi->umask);
  585. if (sbi->flag & JFS_NOINTEGRITY)
  586. seq_puts(seq, ",nointegrity");
  587. if (sbi->flag & JFS_DISCARD)
  588. seq_printf(seq, ",discard=%u", sbi->minblks_trim);
  589. if (sbi->nls_tab)
  590. seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
  591. if (sbi->flag & JFS_ERR_CONTINUE)
  592. seq_printf(seq, ",errors=continue");
  593. if (sbi->flag & JFS_ERR_PANIC)
  594. seq_printf(seq, ",errors=panic");
  595. #ifdef CONFIG_QUOTA
  596. if (sbi->flag & JFS_USRQUOTA)
  597. seq_puts(seq, ",usrquota");
  598. if (sbi->flag & JFS_GRPQUOTA)
  599. seq_puts(seq, ",grpquota");
  600. #endif
  601. return 0;
  602. }
  603. #ifdef CONFIG_QUOTA
  604. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  605. * acquiring the locks... As quota files are never truncated and quota code
  606. * itself serializes the operations (and no one else should touch the files)
  607. * we don't have to be afraid of races */
  608. static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
  609. size_t len, loff_t off)
  610. {
  611. struct inode *inode = sb_dqopt(sb)->files[type];
  612. sector_t blk = off >> sb->s_blocksize_bits;
  613. int err = 0;
  614. int offset = off & (sb->s_blocksize - 1);
  615. int tocopy;
  616. size_t toread;
  617. struct buffer_head tmp_bh;
  618. struct buffer_head *bh;
  619. loff_t i_size = i_size_read(inode);
  620. if (off > i_size)
  621. return 0;
  622. if (off+len > i_size)
  623. len = i_size-off;
  624. toread = len;
  625. while (toread > 0) {
  626. tocopy = sb->s_blocksize - offset < toread ?
  627. sb->s_blocksize - offset : toread;
  628. tmp_bh.b_state = 0;
  629. tmp_bh.b_size = 1 << inode->i_blkbits;
  630. err = jfs_get_block(inode, blk, &tmp_bh, 0);
  631. if (err)
  632. return err;
  633. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  634. memset(data, 0, tocopy);
  635. else {
  636. bh = sb_bread(sb, tmp_bh.b_blocknr);
  637. if (!bh)
  638. return -EIO;
  639. memcpy(data, bh->b_data+offset, tocopy);
  640. brelse(bh);
  641. }
  642. offset = 0;
  643. toread -= tocopy;
  644. data += tocopy;
  645. blk++;
  646. }
  647. return len;
  648. }
  649. /* Write to quotafile */
  650. static ssize_t jfs_quota_write(struct super_block *sb, int type,
  651. const char *data, size_t len, loff_t off)
  652. {
  653. struct inode *inode = sb_dqopt(sb)->files[type];
  654. sector_t blk = off >> sb->s_blocksize_bits;
  655. int err = 0;
  656. int offset = off & (sb->s_blocksize - 1);
  657. int tocopy;
  658. size_t towrite = len;
  659. struct buffer_head tmp_bh;
  660. struct buffer_head *bh;
  661. mutex_lock(&inode->i_mutex);
  662. while (towrite > 0) {
  663. tocopy = sb->s_blocksize - offset < towrite ?
  664. sb->s_blocksize - offset : towrite;
  665. tmp_bh.b_state = 0;
  666. tmp_bh.b_size = 1 << inode->i_blkbits;
  667. err = jfs_get_block(inode, blk, &tmp_bh, 1);
  668. if (err)
  669. goto out;
  670. if (offset || tocopy != sb->s_blocksize)
  671. bh = sb_bread(sb, tmp_bh.b_blocknr);
  672. else
  673. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  674. if (!bh) {
  675. err = -EIO;
  676. goto out;
  677. }
  678. lock_buffer(bh);
  679. memcpy(bh->b_data+offset, data, tocopy);
  680. flush_dcache_page(bh->b_page);
  681. set_buffer_uptodate(bh);
  682. mark_buffer_dirty(bh);
  683. unlock_buffer(bh);
  684. brelse(bh);
  685. offset = 0;
  686. towrite -= tocopy;
  687. data += tocopy;
  688. blk++;
  689. }
  690. out:
  691. if (len == towrite) {
  692. mutex_unlock(&inode->i_mutex);
  693. return err;
  694. }
  695. if (inode->i_size < off+len-towrite)
  696. i_size_write(inode, off+len-towrite);
  697. inode->i_version++;
  698. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  699. mark_inode_dirty(inode);
  700. mutex_unlock(&inode->i_mutex);
  701. return len - towrite;
  702. }
  703. #endif
  704. static const struct super_operations jfs_super_operations = {
  705. .alloc_inode = jfs_alloc_inode,
  706. .destroy_inode = jfs_destroy_inode,
  707. .dirty_inode = jfs_dirty_inode,
  708. .write_inode = jfs_write_inode,
  709. .evict_inode = jfs_evict_inode,
  710. .put_super = jfs_put_super,
  711. .sync_fs = jfs_sync_fs,
  712. .freeze_fs = jfs_freeze,
  713. .unfreeze_fs = jfs_unfreeze,
  714. .statfs = jfs_statfs,
  715. .remount_fs = jfs_remount,
  716. .show_options = jfs_show_options,
  717. #ifdef CONFIG_QUOTA
  718. .quota_read = jfs_quota_read,
  719. .quota_write = jfs_quota_write,
  720. #endif
  721. };
  722. static const struct export_operations jfs_export_operations = {
  723. .fh_to_dentry = jfs_fh_to_dentry,
  724. .fh_to_parent = jfs_fh_to_parent,
  725. .get_parent = jfs_get_parent,
  726. };
  727. static struct file_system_type jfs_fs_type = {
  728. .owner = THIS_MODULE,
  729. .name = "jfs",
  730. .mount = jfs_do_mount,
  731. .kill_sb = kill_block_super,
  732. .fs_flags = FS_REQUIRES_DEV,
  733. };
  734. MODULE_ALIAS_FS("jfs");
  735. static void init_once(void *foo)
  736. {
  737. struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
  738. memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
  739. INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
  740. init_rwsem(&jfs_ip->rdwrlock);
  741. mutex_init(&jfs_ip->commit_mutex);
  742. init_rwsem(&jfs_ip->xattr_sem);
  743. spin_lock_init(&jfs_ip->ag_lock);
  744. jfs_ip->active_ag = -1;
  745. inode_init_once(&jfs_ip->vfs_inode);
  746. }
  747. static int __init init_jfs_fs(void)
  748. {
  749. int i;
  750. int rc;
  751. jfs_inode_cachep =
  752. kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
  753. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
  754. init_once);
  755. if (jfs_inode_cachep == NULL)
  756. return -ENOMEM;
  757. /*
  758. * Metapage initialization
  759. */
  760. rc = metapage_init();
  761. if (rc) {
  762. jfs_err("metapage_init failed w/rc = %d", rc);
  763. goto free_slab;
  764. }
  765. /*
  766. * Transaction Manager initialization
  767. */
  768. rc = txInit();
  769. if (rc) {
  770. jfs_err("txInit failed w/rc = %d", rc);
  771. goto free_metapage;
  772. }
  773. /*
  774. * I/O completion thread (endio)
  775. */
  776. jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO");
  777. if (IS_ERR(jfsIOthread)) {
  778. rc = PTR_ERR(jfsIOthread);
  779. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  780. goto end_txmngr;
  781. }
  782. if (commit_threads < 1)
  783. commit_threads = num_online_cpus();
  784. if (commit_threads > MAX_COMMIT_THREADS)
  785. commit_threads = MAX_COMMIT_THREADS;
  786. for (i = 0; i < commit_threads; i++) {
  787. jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit");
  788. if (IS_ERR(jfsCommitThread[i])) {
  789. rc = PTR_ERR(jfsCommitThread[i]);
  790. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  791. commit_threads = i;
  792. goto kill_committask;
  793. }
  794. }
  795. jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync");
  796. if (IS_ERR(jfsSyncThread)) {
  797. rc = PTR_ERR(jfsSyncThread);
  798. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  799. goto kill_committask;
  800. }
  801. #ifdef PROC_FS_JFS
  802. jfs_proc_init();
  803. #endif
  804. rc = register_filesystem(&jfs_fs_type);
  805. if (!rc)
  806. return 0;
  807. #ifdef PROC_FS_JFS
  808. jfs_proc_clean();
  809. #endif
  810. kthread_stop(jfsSyncThread);
  811. kill_committask:
  812. for (i = 0; i < commit_threads; i++)
  813. kthread_stop(jfsCommitThread[i]);
  814. kthread_stop(jfsIOthread);
  815. end_txmngr:
  816. txExit();
  817. free_metapage:
  818. metapage_exit();
  819. free_slab:
  820. kmem_cache_destroy(jfs_inode_cachep);
  821. return rc;
  822. }
  823. static void __exit exit_jfs_fs(void)
  824. {
  825. int i;
  826. jfs_info("exit_jfs_fs called");
  827. txExit();
  828. metapage_exit();
  829. kthread_stop(jfsIOthread);
  830. for (i = 0; i < commit_threads; i++)
  831. kthread_stop(jfsCommitThread[i]);
  832. kthread_stop(jfsSyncThread);
  833. #ifdef PROC_FS_JFS
  834. jfs_proc_clean();
  835. #endif
  836. unregister_filesystem(&jfs_fs_type);
  837. /*
  838. * Make sure all delayed rcu free inodes are flushed before we
  839. * destroy cache.
  840. */
  841. rcu_barrier();
  842. kmem_cache_destroy(jfs_inode_cachep);
  843. }
  844. module_init(init_jfs_fs)
  845. module_exit(exit_jfs_fs)