super.c 21 KB

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