super.c 21 KB

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