super.c 21 KB

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