super.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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 <asm/uaccess.h>
  32. #include <linux/seq_file.h>
  33. #include "jfs_incore.h"
  34. #include "jfs_filsys.h"
  35. #include "jfs_inode.h"
  36. #include "jfs_metapage.h"
  37. #include "jfs_superblock.h"
  38. #include "jfs_dmap.h"
  39. #include "jfs_imap.h"
  40. #include "jfs_acl.h"
  41. #include "jfs_debug.h"
  42. MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
  43. MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
  44. MODULE_LICENSE("GPL");
  45. static struct kmem_cache * jfs_inode_cachep;
  46. static const struct super_operations jfs_super_operations;
  47. static const struct export_operations jfs_export_operations;
  48. static struct file_system_type jfs_fs_type;
  49. #define MAX_COMMIT_THREADS 64
  50. static int commit_threads = 0;
  51. module_param(commit_threads, int, 0);
  52. MODULE_PARM_DESC(commit_threads, "Number of commit threads");
  53. static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS];
  54. struct task_struct *jfsIOthread;
  55. struct task_struct *jfsSyncThread;
  56. #ifdef CONFIG_JFS_DEBUG
  57. int jfsloglevel = JFS_LOGLEVEL_WARN;
  58. module_param(jfsloglevel, int, 0644);
  59. MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)");
  60. #endif
  61. static void jfs_handle_error(struct super_block *sb)
  62. {
  63. struct jfs_sb_info *sbi = JFS_SBI(sb);
  64. if (sb->s_flags & MS_RDONLY)
  65. return;
  66. updateSuper(sb, FM_DIRTY);
  67. if (sbi->flag & JFS_ERR_PANIC)
  68. panic("JFS (device %s): panic forced after error\n",
  69. sb->s_id);
  70. else if (sbi->flag & JFS_ERR_REMOUNT_RO) {
  71. jfs_err("ERROR: (device %s): remounting filesystem "
  72. "as read-only\n",
  73. sb->s_id);
  74. sb->s_flags |= MS_RDONLY;
  75. }
  76. /* nothing is done for continue beyond marking the superblock dirty */
  77. }
  78. void jfs_error(struct super_block *sb, const char * function, ...)
  79. {
  80. static char error_buf[256];
  81. va_list args;
  82. va_start(args, function);
  83. vsnprintf(error_buf, sizeof(error_buf), function, args);
  84. va_end(args);
  85. printk(KERN_ERR "ERROR: (device %s): %s\n", sb->s_id, error_buf);
  86. jfs_handle_error(sb);
  87. }
  88. static struct inode *jfs_alloc_inode(struct super_block *sb)
  89. {
  90. struct jfs_inode_info *jfs_inode;
  91. jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS);
  92. if (!jfs_inode)
  93. return NULL;
  94. return &jfs_inode->vfs_inode;
  95. }
  96. static void jfs_destroy_inode(struct inode *inode)
  97. {
  98. struct jfs_inode_info *ji = JFS_IP(inode);
  99. BUG_ON(!list_empty(&ji->anon_inode_list));
  100. spin_lock_irq(&ji->ag_lock);
  101. if (ji->active_ag != -1) {
  102. struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
  103. atomic_dec(&bmap->db_active[ji->active_ag]);
  104. ji->active_ag = -1;
  105. }
  106. spin_unlock_irq(&ji->ag_lock);
  107. #ifdef CONFIG_JFS_POSIX_ACL
  108. if (ji->i_acl != JFS_ACL_NOT_CACHED) {
  109. posix_acl_release(ji->i_acl);
  110. ji->i_acl = JFS_ACL_NOT_CACHED;
  111. }
  112. if (ji->i_default_acl != JFS_ACL_NOT_CACHED) {
  113. posix_acl_release(ji->i_default_acl);
  114. ji->i_default_acl = JFS_ACL_NOT_CACHED;
  115. }
  116. #endif
  117. kmem_cache_free(jfs_inode_cachep, ji);
  118. }
  119. static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  120. {
  121. struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb);
  122. s64 maxinodes;
  123. struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap;
  124. jfs_info("In jfs_statfs");
  125. buf->f_type = JFS_SUPER_MAGIC;
  126. buf->f_bsize = sbi->bsize;
  127. buf->f_blocks = sbi->bmap->db_mapsize;
  128. buf->f_bfree = sbi->bmap->db_nfree;
  129. buf->f_bavail = sbi->bmap->db_nfree;
  130. /*
  131. * If we really return the number of allocated & free inodes, some
  132. * applications will fail because they won't see enough free inodes.
  133. * We'll try to calculate some guess as to how may inodes we can
  134. * really allocate
  135. *
  136. * buf->f_files = atomic_read(&imap->im_numinos);
  137. * buf->f_ffree = atomic_read(&imap->im_numfree);
  138. */
  139. maxinodes = min((s64) atomic_read(&imap->im_numinos) +
  140. ((sbi->bmap->db_nfree >> imap->im_l2nbperiext)
  141. << L2INOSPEREXT), (s64) 0xffffffffLL);
  142. buf->f_files = maxinodes;
  143. buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
  144. atomic_read(&imap->im_numfree));
  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. rc = jfs_umount(sb);
  154. if (rc)
  155. jfs_err("jfs_umount failed with return code %d", rc);
  156. if (sbi->nls_tab)
  157. unload_nls(sbi->nls_tab);
  158. sbi->nls_tab = NULL;
  159. truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
  160. iput(sbi->direct_inode);
  161. sbi->direct_inode = NULL;
  162. kfree(sbi);
  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. if (sbi->nls_tab)
  313. unload_nls(sbi->nls_tab);
  314. sbi->nls_tab = nls_map;
  315. }
  316. return 1;
  317. cleanup:
  318. if (nls_map && nls_map != (void *) -1)
  319. unload_nls(nls_map);
  320. return 0;
  321. }
  322. static int jfs_remount(struct super_block *sb, int *flags, char *data)
  323. {
  324. s64 newLVSize = 0;
  325. int rc = 0;
  326. int flag = JFS_SBI(sb)->flag;
  327. if (!parse_options(data, sb, &newLVSize, &flag)) {
  328. return -EINVAL;
  329. }
  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. return -EROFS;
  335. }
  336. rc = jfs_extendfs(sb, newLVSize, 0);
  337. if (rc)
  338. return rc;
  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. return jfs_mount_rw(sb, 1);
  348. }
  349. if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
  350. rc = jfs_umount_rw(sb);
  351. JFS_SBI(sb)->flag = flag;
  352. return rc;
  353. }
  354. if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
  355. if (!(sb->s_flags & MS_RDONLY)) {
  356. rc = jfs_umount_rw(sb);
  357. if (rc)
  358. return rc;
  359. JFS_SBI(sb)->flag = flag;
  360. return jfs_mount_rw(sb, 1);
  361. }
  362. JFS_SBI(sb)->flag = flag;
  363. return 0;
  364. }
  365. static int jfs_fill_super(struct super_block *sb, void *data, int silent)
  366. {
  367. struct jfs_sb_info *sbi;
  368. struct inode *inode;
  369. int rc;
  370. s64 newLVSize = 0;
  371. int flag, ret = -EINVAL;
  372. jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
  373. if (!new_valid_dev(sb->s_bdev->bd_dev))
  374. return -EOVERFLOW;
  375. sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL);
  376. if (!sbi)
  377. return -ENOMEM;
  378. sb->s_fs_info = sbi;
  379. sbi->sb = sb;
  380. sbi->uid = sbi->gid = sbi->umask = -1;
  381. /* initialize the mount flag and determine the default error handler */
  382. flag = JFS_ERR_REMOUNT_RO;
  383. if (!parse_options((char *) data, sb, &newLVSize, &flag)) {
  384. kfree(sbi);
  385. return -EINVAL;
  386. }
  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. return -EINVAL;
  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. /*
  405. * Initialize direct-mapping inode/address-space
  406. */
  407. inode = new_inode(sb);
  408. if (inode == NULL) {
  409. ret = -ENOMEM;
  410. goto out_kfree;
  411. }
  412. inode->i_ino = 0;
  413. inode->i_nlink = 1;
  414. inode->i_size = sb->s_bdev->bd_inode->i_size;
  415. inode->i_mapping->a_ops = &jfs_metapage_aops;
  416. insert_inode_hash(inode);
  417. mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
  418. sbi->direct_inode = inode;
  419. rc = jfs_mount(sb);
  420. if (rc) {
  421. if (!silent) {
  422. jfs_err("jfs_mount failed w/return code = %d", rc);
  423. }
  424. goto out_mount_failed;
  425. }
  426. if (sb->s_flags & MS_RDONLY)
  427. sbi->log = NULL;
  428. else {
  429. rc = jfs_mount_rw(sb, 0);
  430. if (rc) {
  431. if (!silent) {
  432. jfs_err("jfs_mount_rw failed, return code = %d",
  433. rc);
  434. }
  435. goto out_no_rw;
  436. }
  437. }
  438. sb->s_magic = JFS_SUPER_MAGIC;
  439. inode = jfs_iget(sb, ROOT_I);
  440. if (IS_ERR(inode)) {
  441. ret = PTR_ERR(inode);
  442. goto out_no_rw;
  443. }
  444. sb->s_root = d_alloc_root(inode);
  445. if (!sb->s_root)
  446. goto out_no_root;
  447. if (sbi->mntflag & JFS_OS2)
  448. sb->s_root->d_op = &jfs_ci_dentry_operations;
  449. /* logical blocks are represented by 40 bits in pxd_t, etc. */
  450. sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
  451. #if BITS_PER_LONG == 32
  452. /*
  453. * Page cache is indexed by long.
  454. * I would use MAX_LFS_FILESIZE, but it's only half as big
  455. */
  456. sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, sb->s_maxbytes);
  457. #endif
  458. sb->s_time_gran = 1;
  459. return 0;
  460. out_no_root:
  461. jfs_err("jfs_read_super: get root dentry failed");
  462. iput(inode);
  463. out_no_rw:
  464. rc = jfs_umount(sb);
  465. if (rc) {
  466. jfs_err("jfs_umount failed with return code %d", rc);
  467. }
  468. out_mount_failed:
  469. filemap_write_and_wait(sbi->direct_inode->i_mapping);
  470. truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
  471. make_bad_inode(sbi->direct_inode);
  472. iput(sbi->direct_inode);
  473. sbi->direct_inode = NULL;
  474. out_kfree:
  475. if (sbi->nls_tab)
  476. unload_nls(sbi->nls_tab);
  477. kfree(sbi);
  478. return ret;
  479. }
  480. static void jfs_write_super_lockfs(struct super_block *sb)
  481. {
  482. struct jfs_sb_info *sbi = JFS_SBI(sb);
  483. struct jfs_log *log = sbi->log;
  484. if (!(sb->s_flags & MS_RDONLY)) {
  485. txQuiesce(sb);
  486. lmLogShutdown(log);
  487. updateSuper(sb, FM_CLEAN);
  488. }
  489. }
  490. static void jfs_unlockfs(struct super_block *sb)
  491. {
  492. struct jfs_sb_info *sbi = JFS_SBI(sb);
  493. struct jfs_log *log = sbi->log;
  494. int rc = 0;
  495. if (!(sb->s_flags & MS_RDONLY)) {
  496. updateSuper(sb, FM_MOUNT);
  497. if ((rc = lmLogInit(log)))
  498. jfs_err("jfs_unlock failed with return code %d", rc);
  499. else
  500. txResume(sb);
  501. }
  502. }
  503. static int jfs_get_sb(struct file_system_type *fs_type,
  504. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  505. {
  506. return get_sb_bdev(fs_type, flags, dev_name, data, jfs_fill_super,
  507. mnt);
  508. }
  509. static int jfs_sync_fs(struct super_block *sb, int wait)
  510. {
  511. struct jfs_log *log = JFS_SBI(sb)->log;
  512. /* log == NULL indicates read-only mount */
  513. if (log) {
  514. jfs_flush_journal(log, wait);
  515. jfs_syncpt(log, 0);
  516. }
  517. return 0;
  518. }
  519. static int jfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
  520. {
  521. struct jfs_sb_info *sbi = JFS_SBI(vfs->mnt_sb);
  522. if (sbi->uid != -1)
  523. seq_printf(seq, ",uid=%d", sbi->uid);
  524. if (sbi->gid != -1)
  525. seq_printf(seq, ",gid=%d", sbi->gid);
  526. if (sbi->umask != -1)
  527. seq_printf(seq, ",umask=%03o", sbi->umask);
  528. if (sbi->flag & JFS_NOINTEGRITY)
  529. seq_puts(seq, ",nointegrity");
  530. if (sbi->nls_tab)
  531. seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
  532. if (sbi->flag & JFS_ERR_CONTINUE)
  533. seq_printf(seq, ",errors=continue");
  534. if (sbi->flag & JFS_ERR_PANIC)
  535. seq_printf(seq, ",errors=panic");
  536. #ifdef CONFIG_QUOTA
  537. if (sbi->flag & JFS_USRQUOTA)
  538. seq_puts(seq, ",usrquota");
  539. if (sbi->flag & JFS_GRPQUOTA)
  540. seq_puts(seq, ",grpquota");
  541. #endif
  542. return 0;
  543. }
  544. #ifdef CONFIG_QUOTA
  545. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  546. * acquiring the locks... As quota files are never truncated and quota code
  547. * itself serializes the operations (and noone else should touch the files)
  548. * we don't have to be afraid of races */
  549. static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
  550. size_t len, loff_t off)
  551. {
  552. struct inode *inode = sb_dqopt(sb)->files[type];
  553. sector_t blk = off >> sb->s_blocksize_bits;
  554. int err = 0;
  555. int offset = off & (sb->s_blocksize - 1);
  556. int tocopy;
  557. size_t toread;
  558. struct buffer_head tmp_bh;
  559. struct buffer_head *bh;
  560. loff_t i_size = i_size_read(inode);
  561. if (off > i_size)
  562. return 0;
  563. if (off+len > i_size)
  564. len = i_size-off;
  565. toread = len;
  566. while (toread > 0) {
  567. tocopy = sb->s_blocksize - offset < toread ?
  568. sb->s_blocksize - offset : toread;
  569. tmp_bh.b_state = 0;
  570. tmp_bh.b_size = 1 << inode->i_blkbits;
  571. err = jfs_get_block(inode, blk, &tmp_bh, 0);
  572. if (err)
  573. return err;
  574. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  575. memset(data, 0, tocopy);
  576. else {
  577. bh = sb_bread(sb, tmp_bh.b_blocknr);
  578. if (!bh)
  579. return -EIO;
  580. memcpy(data, bh->b_data+offset, tocopy);
  581. brelse(bh);
  582. }
  583. offset = 0;
  584. toread -= tocopy;
  585. data += tocopy;
  586. blk++;
  587. }
  588. return len;
  589. }
  590. /* Write to quotafile */
  591. static ssize_t jfs_quota_write(struct super_block *sb, int type,
  592. const char *data, size_t len, loff_t off)
  593. {
  594. struct inode *inode = sb_dqopt(sb)->files[type];
  595. sector_t blk = off >> sb->s_blocksize_bits;
  596. int err = 0;
  597. int offset = off & (sb->s_blocksize - 1);
  598. int tocopy;
  599. size_t towrite = len;
  600. struct buffer_head tmp_bh;
  601. struct buffer_head *bh;
  602. mutex_lock(&inode->i_mutex);
  603. while (towrite > 0) {
  604. tocopy = sb->s_blocksize - offset < towrite ?
  605. sb->s_blocksize - offset : towrite;
  606. tmp_bh.b_state = 0;
  607. tmp_bh.b_size = 1 << inode->i_blkbits;
  608. err = jfs_get_block(inode, blk, &tmp_bh, 1);
  609. if (err)
  610. goto out;
  611. if (offset || tocopy != sb->s_blocksize)
  612. bh = sb_bread(sb, tmp_bh.b_blocknr);
  613. else
  614. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  615. if (!bh) {
  616. err = -EIO;
  617. goto out;
  618. }
  619. lock_buffer(bh);
  620. memcpy(bh->b_data+offset, data, tocopy);
  621. flush_dcache_page(bh->b_page);
  622. set_buffer_uptodate(bh);
  623. mark_buffer_dirty(bh);
  624. unlock_buffer(bh);
  625. brelse(bh);
  626. offset = 0;
  627. towrite -= tocopy;
  628. data += tocopy;
  629. blk++;
  630. }
  631. out:
  632. if (len == towrite)
  633. return err;
  634. if (inode->i_size < off+len-towrite)
  635. i_size_write(inode, off+len-towrite);
  636. inode->i_version++;
  637. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  638. mark_inode_dirty(inode);
  639. mutex_unlock(&inode->i_mutex);
  640. return len - towrite;
  641. }
  642. #endif
  643. static const struct super_operations jfs_super_operations = {
  644. .alloc_inode = jfs_alloc_inode,
  645. .destroy_inode = jfs_destroy_inode,
  646. .dirty_inode = jfs_dirty_inode,
  647. .write_inode = jfs_write_inode,
  648. .delete_inode = jfs_delete_inode,
  649. .put_super = jfs_put_super,
  650. .sync_fs = jfs_sync_fs,
  651. .write_super_lockfs = jfs_write_super_lockfs,
  652. .unlockfs = jfs_unlockfs,
  653. .statfs = jfs_statfs,
  654. .remount_fs = jfs_remount,
  655. .show_options = jfs_show_options,
  656. #ifdef CONFIG_QUOTA
  657. .quota_read = jfs_quota_read,
  658. .quota_write = jfs_quota_write,
  659. #endif
  660. };
  661. static const struct export_operations jfs_export_operations = {
  662. .fh_to_dentry = jfs_fh_to_dentry,
  663. .fh_to_parent = jfs_fh_to_parent,
  664. .get_parent = jfs_get_parent,
  665. };
  666. static struct file_system_type jfs_fs_type = {
  667. .owner = THIS_MODULE,
  668. .name = "jfs",
  669. .get_sb = jfs_get_sb,
  670. .kill_sb = kill_block_super,
  671. .fs_flags = FS_REQUIRES_DEV,
  672. };
  673. static void init_once(void *foo)
  674. {
  675. struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
  676. memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
  677. INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
  678. init_rwsem(&jfs_ip->rdwrlock);
  679. mutex_init(&jfs_ip->commit_mutex);
  680. init_rwsem(&jfs_ip->xattr_sem);
  681. spin_lock_init(&jfs_ip->ag_lock);
  682. jfs_ip->active_ag = -1;
  683. #ifdef CONFIG_JFS_POSIX_ACL
  684. jfs_ip->i_acl = JFS_ACL_NOT_CACHED;
  685. jfs_ip->i_default_acl = JFS_ACL_NOT_CACHED;
  686. #endif
  687. inode_init_once(&jfs_ip->vfs_inode);
  688. }
  689. static int __init init_jfs_fs(void)
  690. {
  691. int i;
  692. int rc;
  693. jfs_inode_cachep =
  694. kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
  695. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
  696. init_once);
  697. if (jfs_inode_cachep == NULL)
  698. return -ENOMEM;
  699. /*
  700. * Metapage initialization
  701. */
  702. rc = metapage_init();
  703. if (rc) {
  704. jfs_err("metapage_init failed w/rc = %d", rc);
  705. goto free_slab;
  706. }
  707. /*
  708. * Transaction Manager initialization
  709. */
  710. rc = txInit();
  711. if (rc) {
  712. jfs_err("txInit failed w/rc = %d", rc);
  713. goto free_metapage;
  714. }
  715. /*
  716. * I/O completion thread (endio)
  717. */
  718. jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO");
  719. if (IS_ERR(jfsIOthread)) {
  720. rc = PTR_ERR(jfsIOthread);
  721. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  722. goto end_txmngr;
  723. }
  724. if (commit_threads < 1)
  725. commit_threads = num_online_cpus();
  726. if (commit_threads > MAX_COMMIT_THREADS)
  727. commit_threads = MAX_COMMIT_THREADS;
  728. for (i = 0; i < commit_threads; i++) {
  729. jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit");
  730. if (IS_ERR(jfsCommitThread[i])) {
  731. rc = PTR_ERR(jfsCommitThread[i]);
  732. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  733. commit_threads = i;
  734. goto kill_committask;
  735. }
  736. }
  737. jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync");
  738. if (IS_ERR(jfsSyncThread)) {
  739. rc = PTR_ERR(jfsSyncThread);
  740. jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
  741. goto kill_committask;
  742. }
  743. #ifdef PROC_FS_JFS
  744. jfs_proc_init();
  745. #endif
  746. return register_filesystem(&jfs_fs_type);
  747. kill_committask:
  748. for (i = 0; i < commit_threads; i++)
  749. kthread_stop(jfsCommitThread[i]);
  750. kthread_stop(jfsIOthread);
  751. end_txmngr:
  752. txExit();
  753. free_metapage:
  754. metapage_exit();
  755. free_slab:
  756. kmem_cache_destroy(jfs_inode_cachep);
  757. return rc;
  758. }
  759. static void __exit exit_jfs_fs(void)
  760. {
  761. int i;
  762. jfs_info("exit_jfs_fs called");
  763. txExit();
  764. metapage_exit();
  765. kthread_stop(jfsIOthread);
  766. for (i = 0; i < commit_threads; i++)
  767. kthread_stop(jfsCommitThread[i]);
  768. kthread_stop(jfsSyncThread);
  769. #ifdef PROC_FS_JFS
  770. jfs_proc_clean();
  771. #endif
  772. unregister_filesystem(&jfs_fs_type);
  773. kmem_cache_destroy(jfs_inode_cachep);
  774. }
  775. module_init(init_jfs_fs)
  776. module_exit(exit_jfs_fs)