super.c 23 KB

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