super.c 23 KB

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