super.c 21 KB

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