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 int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  113. {
  114. struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb);
  115. s64 maxinodes;
  116. struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap;
  117. jfs_info("In jfs_statfs");
  118. buf->f_type = JFS_SUPER_MAGIC;
  119. buf->f_bsize = sbi->bsize;
  120. buf->f_blocks = sbi->bmap->db_mapsize;
  121. buf->f_bfree = sbi->bmap->db_nfree;
  122. buf->f_bavail = sbi->bmap->db_nfree;
  123. /*
  124. * If we really return the number of allocated & free inodes, some
  125. * applications will fail because they won't see enough free inodes.
  126. * We'll try to calculate some guess as to how may inodes we can
  127. * really allocate
  128. *
  129. * buf->f_files = atomic_read(&imap->im_numinos);
  130. * buf->f_ffree = atomic_read(&imap->im_numfree);
  131. */
  132. maxinodes = min((s64) atomic_read(&imap->im_numinos) +
  133. ((sbi->bmap->db_nfree >> imap->im_l2nbperiext)
  134. << L2INOSPEREXT), (s64) 0xffffffffLL);
  135. buf->f_files = maxinodes;
  136. buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
  137. atomic_read(&imap->im_numfree));
  138. buf->f_fsid.val[0] = (u32)crc32_le(0, sbi->uuid, sizeof(sbi->uuid)/2);
  139. buf->f_fsid.val[1] = (u32)crc32_le(0, sbi->uuid + sizeof(sbi->uuid)/2,
  140. sizeof(sbi->uuid)/2);
  141. buf->f_namelen = JFS_NAME_MAX;
  142. return 0;
  143. }
  144. static void jfs_put_super(struct super_block *sb)
  145. {
  146. struct jfs_sb_info *sbi = JFS_SBI(sb);
  147. int rc;
  148. jfs_info("In jfs_put_super");
  149. dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
  150. lock_kernel();
  151. rc = jfs_umount(sb);
  152. if (rc)
  153. jfs_err("jfs_umount failed with return code %d", rc);
  154. unload_nls(sbi->nls_tab);
  155. truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
  156. iput(sbi->direct_inode);
  157. kfree(sbi);
  158. unlock_kernel();
  159. }
  160. enum {
  161. Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
  162. Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
  163. Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
  164. };
  165. static const match_table_t tokens = {
  166. {Opt_integrity, "integrity"},
  167. {Opt_nointegrity, "nointegrity"},
  168. {Opt_iocharset, "iocharset=%s"},
  169. {Opt_resize, "resize=%u"},
  170. {Opt_resize_nosize, "resize"},
  171. {Opt_errors, "errors=%s"},
  172. {Opt_ignore, "noquota"},
  173. {Opt_ignore, "quota"},
  174. {Opt_usrquota, "usrquota"},
  175. {Opt_grpquota, "grpquota"},
  176. {Opt_uid, "uid=%u"},
  177. {Opt_gid, "gid=%u"},
  178. {Opt_umask, "umask=%u"},
  179. {Opt_err, NULL}
  180. };
  181. static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
  182. int *flag)
  183. {
  184. void *nls_map = (void *)-1; /* -1: no change; NULL: none */
  185. char *p;
  186. struct jfs_sb_info *sbi = JFS_SBI(sb);
  187. *newLVSize = 0;
  188. if (!options)
  189. return 1;
  190. while ((p = strsep(&options, ",")) != NULL) {
  191. substring_t args[MAX_OPT_ARGS];
  192. int token;
  193. if (!*p)
  194. continue;
  195. token = match_token(p, tokens, args);
  196. switch (token) {
  197. case Opt_integrity:
  198. *flag &= ~JFS_NOINTEGRITY;
  199. break;
  200. case Opt_nointegrity:
  201. *flag |= JFS_NOINTEGRITY;
  202. break;
  203. case Opt_ignore:
  204. /* Silently ignore the quota options */
  205. /* Don't do anything ;-) */
  206. break;
  207. case Opt_iocharset:
  208. if (nls_map && nls_map != (void *) -1)
  209. unload_nls(nls_map);
  210. if (!strcmp(args[0].from, "none"))
  211. nls_map = NULL;
  212. else {
  213. nls_map = load_nls(args[0].from);
  214. if (!nls_map) {
  215. printk(KERN_ERR
  216. "JFS: charset not found\n");
  217. goto cleanup;
  218. }
  219. }
  220. break;
  221. case Opt_resize:
  222. {
  223. char *resize = args[0].from;
  224. *newLVSize = simple_strtoull(resize, &resize, 0);
  225. break;
  226. }
  227. case Opt_resize_nosize:
  228. {
  229. *newLVSize = sb->s_bdev->bd_inode->i_size >>
  230. sb->s_blocksize_bits;
  231. if (*newLVSize == 0)
  232. printk(KERN_ERR
  233. "JFS: Cannot determine volume size\n");
  234. break;
  235. }
  236. case Opt_errors:
  237. {
  238. char *errors = args[0].from;
  239. if (!errors || !*errors)
  240. goto cleanup;
  241. if (!strcmp(errors, "continue")) {
  242. *flag &= ~JFS_ERR_REMOUNT_RO;
  243. *flag &= ~JFS_ERR_PANIC;
  244. *flag |= JFS_ERR_CONTINUE;
  245. } else if (!strcmp(errors, "remount-ro")) {
  246. *flag &= ~JFS_ERR_CONTINUE;
  247. *flag &= ~JFS_ERR_PANIC;
  248. *flag |= JFS_ERR_REMOUNT_RO;
  249. } else if (!strcmp(errors, "panic")) {
  250. *flag &= ~JFS_ERR_CONTINUE;
  251. *flag &= ~JFS_ERR_REMOUNT_RO;
  252. *flag |= JFS_ERR_PANIC;
  253. } else {
  254. printk(KERN_ERR
  255. "JFS: %s is an invalid error handler\n",
  256. errors);
  257. goto cleanup;
  258. }
  259. break;
  260. }
  261. #ifdef CONFIG_QUOTA
  262. case Opt_quota:
  263. case Opt_usrquota:
  264. *flag |= JFS_USRQUOTA;
  265. break;
  266. case Opt_grpquota:
  267. *flag |= JFS_GRPQUOTA;
  268. break;
  269. #else
  270. case Opt_usrquota:
  271. case Opt_grpquota:
  272. case Opt_quota:
  273. printk(KERN_ERR
  274. "JFS: quota operations not supported\n");
  275. break;
  276. #endif
  277. case Opt_uid:
  278. {
  279. char *uid = args[0].from;
  280. sbi->uid = simple_strtoul(uid, &uid, 0);
  281. break;
  282. }
  283. case Opt_gid:
  284. {
  285. char *gid = args[0].from;
  286. sbi->gid = simple_strtoul(gid, &gid, 0);
  287. break;
  288. }
  289. case Opt_umask:
  290. {
  291. char *umask = args[0].from;
  292. sbi->umask = simple_strtoul(umask, &umask, 8);
  293. if (sbi->umask & ~0777) {
  294. printk(KERN_ERR
  295. "JFS: Invalid value of umask\n");
  296. goto cleanup;
  297. }
  298. break;
  299. }
  300. default:
  301. printk("jfs: Unrecognized mount option \"%s\" "
  302. " or missing value\n", p);
  303. goto cleanup;
  304. }
  305. }
  306. if (nls_map != (void *) -1) {
  307. /* Discard old (if remount) */
  308. unload_nls(sbi->nls_tab);
  309. sbi->nls_tab = nls_map;
  310. }
  311. return 1;
  312. cleanup:
  313. if (nls_map && nls_map != (void *) -1)
  314. unload_nls(nls_map);
  315. return 0;
  316. }
  317. static int jfs_remount(struct super_block *sb, int *flags, char *data)
  318. {
  319. s64 newLVSize = 0;
  320. int rc = 0;
  321. int flag = JFS_SBI(sb)->flag;
  322. int ret;
  323. if (!parse_options(data, sb, &newLVSize, &flag)) {
  324. return -EINVAL;
  325. }
  326. lock_kernel();
  327. if (newLVSize) {
  328. if (sb->s_flags & MS_RDONLY) {
  329. printk(KERN_ERR
  330. "JFS: resize requires volume to be mounted read-write\n");
  331. unlock_kernel();
  332. return -EROFS;
  333. }
  334. rc = jfs_extendfs(sb, newLVSize, 0);
  335. if (rc) {
  336. unlock_kernel();
  337. return rc;
  338. }
  339. }
  340. if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
  341. /*
  342. * Invalidate any previously read metadata. fsck may have
  343. * changed the on-disk data since we mounted r/o
  344. */
  345. truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
  346. JFS_SBI(sb)->flag = flag;
  347. ret = jfs_mount_rw(sb, 1);
  348. /* mark the fs r/w for quota activity */
  349. sb->s_flags &= ~MS_RDONLY;
  350. unlock_kernel();
  351. dquot_resume(sb, -1);
  352. return ret;
  353. }
  354. if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
  355. rc = dquot_suspend(sb, -1);
  356. if (rc < 0) {
  357. unlock_kernel();
  358. return rc;
  359. }
  360. rc = jfs_umount_rw(sb);
  361. JFS_SBI(sb)->flag = flag;
  362. unlock_kernel();
  363. return rc;
  364. }
  365. if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
  366. if (!(sb->s_flags & MS_RDONLY)) {
  367. rc = jfs_umount_rw(sb);
  368. if (rc) {
  369. unlock_kernel();
  370. return rc;
  371. }
  372. JFS_SBI(sb)->flag = flag;
  373. ret = jfs_mount_rw(sb, 1);
  374. unlock_kernel();
  375. return ret;
  376. }
  377. JFS_SBI(sb)->flag = flag;
  378. unlock_kernel();
  379. return 0;
  380. }
  381. static int jfs_fill_super(struct super_block *sb, void *data, int silent)
  382. {
  383. struct jfs_sb_info *sbi;
  384. struct inode *inode;
  385. int rc;
  386. s64 newLVSize = 0;
  387. int flag, ret = -EINVAL;
  388. jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
  389. if (!new_valid_dev(sb->s_bdev->bd_dev))
  390. return -EOVERFLOW;
  391. sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL);
  392. if (!sbi)
  393. return -ENOMEM;
  394. sb->s_fs_info = sbi;
  395. sbi->sb = sb;
  396. sbi->uid = sbi->gid = sbi->umask = -1;
  397. /* initialize the mount flag and determine the default error handler */
  398. flag = JFS_ERR_REMOUNT_RO;
  399. if (!parse_options((char *) data, sb, &newLVSize, &flag))
  400. goto out_kfree;
  401. sbi->flag = flag;
  402. #ifdef CONFIG_JFS_POSIX_ACL
  403. sb->s_flags |= MS_POSIXACL;
  404. #endif
  405. if (newLVSize) {
  406. printk(KERN_ERR "resize option for remount only\n");
  407. goto out_kfree;
  408. }
  409. /*
  410. * Initialize blocksize to 4K.
  411. */
  412. sb_set_blocksize(sb, PSIZE);
  413. /*
  414. * Set method vectors.
  415. */
  416. sb->s_op = &jfs_super_operations;
  417. sb->s_export_op = &jfs_export_operations;
  418. #ifdef CONFIG_QUOTA
  419. sb->dq_op = &dquot_operations;
  420. sb->s_qcop = &dquot_quotactl_ops;
  421. #endif
  422. /*
  423. * Initialize direct-mapping inode/address-space
  424. */
  425. inode = new_inode(sb);
  426. if (inode == NULL) {
  427. ret = -ENOMEM;
  428. goto out_unload;
  429. }
  430. inode->i_ino = 0;
  431. inode->i_nlink = 1;
  432. inode->i_size = sb->s_bdev->bd_inode->i_size;
  433. inode->i_mapping->a_ops = &jfs_metapage_aops;
  434. insert_inode_hash(inode);
  435. mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
  436. sbi->direct_inode = inode;
  437. rc = jfs_mount(sb);
  438. if (rc) {
  439. if (!silent) {
  440. jfs_err("jfs_mount failed w/return code = %d", rc);
  441. }
  442. goto out_mount_failed;
  443. }
  444. if (sb->s_flags & MS_RDONLY)
  445. sbi->log = NULL;
  446. else {
  447. rc = jfs_mount_rw(sb, 0);
  448. if (rc) {
  449. if (!silent) {
  450. jfs_err("jfs_mount_rw failed, return code = %d",
  451. rc);
  452. }
  453. goto out_no_rw;
  454. }
  455. }
  456. sb->s_magic = JFS_SUPER_MAGIC;
  457. inode = jfs_iget(sb, ROOT_I);
  458. if (IS_ERR(inode)) {
  459. ret = PTR_ERR(inode);
  460. goto out_no_rw;
  461. }
  462. sb->s_root = d_alloc_root(inode);
  463. if (!sb->s_root)
  464. goto out_no_root;
  465. if (sbi->mntflag & JFS_OS2)
  466. sb->s_root->d_op = &jfs_ci_dentry_operations;
  467. /* logical blocks are represented by 40 bits in pxd_t, etc. */
  468. sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
  469. #if BITS_PER_LONG == 32
  470. /*
  471. * Page cache is indexed by long.
  472. * I would use MAX_LFS_FILESIZE, but it's only half as big
  473. */
  474. sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes);
  475. #endif
  476. sb->s_time_gran = 1;
  477. return 0;
  478. out_no_root:
  479. jfs_err("jfs_read_super: get root dentry failed");
  480. iput(inode);
  481. out_no_rw:
  482. rc = jfs_umount(sb);
  483. if (rc) {
  484. jfs_err("jfs_umount failed with return code %d", rc);
  485. }
  486. out_mount_failed:
  487. filemap_write_and_wait(sbi->direct_inode->i_mapping);
  488. truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
  489. make_bad_inode(sbi->direct_inode);
  490. iput(sbi->direct_inode);
  491. sbi->direct_inode = NULL;
  492. out_unload:
  493. if (sbi->nls_tab)
  494. unload_nls(sbi->nls_tab);
  495. out_kfree:
  496. kfree(sbi);
  497. return ret;
  498. }
  499. static int jfs_freeze(struct super_block *sb)
  500. {
  501. struct jfs_sb_info *sbi = JFS_SBI(sb);
  502. struct jfs_log *log = sbi->log;
  503. if (!(sb->s_flags & MS_RDONLY)) {
  504. txQuiesce(sb);
  505. lmLogShutdown(log);
  506. updateSuper(sb, FM_CLEAN);
  507. }
  508. return 0;
  509. }
  510. static int jfs_unfreeze(struct super_block *sb)
  511. {
  512. struct jfs_sb_info *sbi = JFS_SBI(sb);
  513. struct jfs_log *log = sbi->log;
  514. int rc = 0;
  515. if (!(sb->s_flags & MS_RDONLY)) {
  516. updateSuper(sb, FM_MOUNT);
  517. if ((rc = lmLogInit(log)))
  518. jfs_err("jfs_unlock failed with return code %d", rc);
  519. else
  520. txResume(sb);
  521. }
  522. return 0;
  523. }
  524. static int jfs_get_sb(struct file_system_type *fs_type,
  525. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  526. {
  527. return get_sb_bdev(fs_type, flags, dev_name, data, jfs_fill_super,
  528. mnt);
  529. }
  530. static int jfs_sync_fs(struct super_block *sb, int wait)
  531. {
  532. struct jfs_log *log = JFS_SBI(sb)->log;
  533. /* log == NULL indicates read-only mount */
  534. if (log) {
  535. jfs_flush_journal(log, wait);
  536. jfs_syncpt(log, 0);
  537. }
  538. return 0;
  539. }
  540. static int jfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
  541. {
  542. struct jfs_sb_info *sbi = JFS_SBI(vfs->mnt_sb);
  543. if (sbi->uid != -1)
  544. seq_printf(seq, ",uid=%d", sbi->uid);
  545. if (sbi->gid != -1)
  546. seq_printf(seq, ",gid=%d", sbi->gid);
  547. if (sbi->umask != -1)
  548. seq_printf(seq, ",umask=%03o", sbi->umask);
  549. if (sbi->flag & JFS_NOINTEGRITY)
  550. seq_puts(seq, ",nointegrity");
  551. if (sbi->nls_tab)
  552. seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
  553. if (sbi->flag & JFS_ERR_CONTINUE)
  554. seq_printf(seq, ",errors=continue");
  555. if (sbi->flag & JFS_ERR_PANIC)
  556. seq_printf(seq, ",errors=panic");
  557. #ifdef CONFIG_QUOTA
  558. if (sbi->flag & JFS_USRQUOTA)
  559. seq_puts(seq, ",usrquota");
  560. if (sbi->flag & JFS_GRPQUOTA)
  561. seq_puts(seq, ",grpquota");
  562. #endif
  563. return 0;
  564. }
  565. #ifdef CONFIG_QUOTA
  566. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  567. * acquiring the locks... As quota files are never truncated and quota code
  568. * itself serializes the operations (and noone else should touch the files)
  569. * we don't have to be afraid of races */
  570. static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
  571. size_t len, loff_t off)
  572. {
  573. struct inode *inode = sb_dqopt(sb)->files[type];
  574. sector_t blk = off >> sb->s_blocksize_bits;
  575. int err = 0;
  576. int offset = off & (sb->s_blocksize - 1);
  577. int tocopy;
  578. size_t toread;
  579. struct buffer_head tmp_bh;
  580. struct buffer_head *bh;
  581. loff_t i_size = i_size_read(inode);
  582. if (off > i_size)
  583. return 0;
  584. if (off+len > i_size)
  585. len = i_size-off;
  586. toread = len;
  587. while (toread > 0) {
  588. tocopy = sb->s_blocksize - offset < toread ?
  589. sb->s_blocksize - offset : toread;
  590. tmp_bh.b_state = 0;
  591. tmp_bh.b_size = 1 << inode->i_blkbits;
  592. err = jfs_get_block(inode, blk, &tmp_bh, 0);
  593. if (err)
  594. return err;
  595. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  596. memset(data, 0, tocopy);
  597. else {
  598. bh = sb_bread(sb, tmp_bh.b_blocknr);
  599. if (!bh)
  600. return -EIO;
  601. memcpy(data, bh->b_data+offset, tocopy);
  602. brelse(bh);
  603. }
  604. offset = 0;
  605. toread -= tocopy;
  606. data += tocopy;
  607. blk++;
  608. }
  609. return len;
  610. }
  611. /* Write to quotafile */
  612. static ssize_t jfs_quota_write(struct super_block *sb, int type,
  613. const char *data, size_t len, loff_t off)
  614. {
  615. struct inode *inode = sb_dqopt(sb)->files[type];
  616. sector_t blk = off >> sb->s_blocksize_bits;
  617. int err = 0;
  618. int offset = off & (sb->s_blocksize - 1);
  619. int tocopy;
  620. size_t towrite = len;
  621. struct buffer_head tmp_bh;
  622. struct buffer_head *bh;
  623. mutex_lock(&inode->i_mutex);
  624. while (towrite > 0) {
  625. tocopy = sb->s_blocksize - offset < towrite ?
  626. sb->s_blocksize - offset : towrite;
  627. tmp_bh.b_state = 0;
  628. tmp_bh.b_size = 1 << inode->i_blkbits;
  629. err = jfs_get_block(inode, blk, &tmp_bh, 1);
  630. if (err)
  631. goto out;
  632. if (offset || tocopy != sb->s_blocksize)
  633. bh = sb_bread(sb, tmp_bh.b_blocknr);
  634. else
  635. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  636. if (!bh) {
  637. err = -EIO;
  638. goto out;
  639. }
  640. lock_buffer(bh);
  641. memcpy(bh->b_data+offset, data, tocopy);
  642. flush_dcache_page(bh->b_page);
  643. set_buffer_uptodate(bh);
  644. mark_buffer_dirty(bh);
  645. unlock_buffer(bh);
  646. brelse(bh);
  647. offset = 0;
  648. towrite -= tocopy;
  649. data += tocopy;
  650. blk++;
  651. }
  652. out:
  653. if (len == towrite) {
  654. mutex_unlock(&inode->i_mutex);
  655. return err;
  656. }
  657. if (inode->i_size < off+len-towrite)
  658. i_size_write(inode, off+len-towrite);
  659. inode->i_version++;
  660. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  661. mark_inode_dirty(inode);
  662. mutex_unlock(&inode->i_mutex);
  663. return len - towrite;
  664. }
  665. #endif
  666. static const struct super_operations jfs_super_operations = {
  667. .alloc_inode = jfs_alloc_inode,
  668. .destroy_inode = jfs_destroy_inode,
  669. .dirty_inode = jfs_dirty_inode,
  670. .write_inode = jfs_write_inode,
  671. .evict_inode = jfs_evict_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)