super.c 21 KB

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