super.c 20 KB

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