super.c 23 KB

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