super.c 21 KB

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