super.c 21 KB

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