super.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. /*
  2. * super.c - NILFS module and super block management.
  3. *
  4. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * Written by Ryusuke Konishi <ryusuke@osrg.net>
  21. */
  22. /*
  23. * linux/fs/ext2/super.c
  24. *
  25. * Copyright (C) 1992, 1993, 1994, 1995
  26. * Remy Card (card@masi.ibp.fr)
  27. * Laboratoire MASI - Institut Blaise Pascal
  28. * Universite Pierre et Marie Curie (Paris VI)
  29. *
  30. * from
  31. *
  32. * linux/fs/minix/inode.c
  33. *
  34. * Copyright (C) 1991, 1992 Linus Torvalds
  35. *
  36. * Big-endian to little-endian byte-swapping/bitmaps by
  37. * David S. Miller (davem@caip.rutgers.edu), 1995
  38. */
  39. #include <linux/module.h>
  40. #include <linux/string.h>
  41. #include <linux/slab.h>
  42. #include <linux/init.h>
  43. #include <linux/blkdev.h>
  44. #include <linux/parser.h>
  45. #include <linux/random.h>
  46. #include <linux/crc32.h>
  47. #include <linux/smp_lock.h>
  48. #include <linux/vfs.h>
  49. #include <linux/writeback.h>
  50. #include <linux/kobject.h>
  51. #include <linux/exportfs.h>
  52. #include "nilfs.h"
  53. #include "mdt.h"
  54. #include "alloc.h"
  55. #include "page.h"
  56. #include "cpfile.h"
  57. #include "ifile.h"
  58. #include "dat.h"
  59. #include "segment.h"
  60. #include "segbuf.h"
  61. MODULE_AUTHOR("NTT Corp.");
  62. MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem "
  63. "(NILFS)");
  64. MODULE_LICENSE("GPL");
  65. static void nilfs_write_super(struct super_block *sb);
  66. static int nilfs_remount(struct super_block *sb, int *flags, char *data);
  67. /**
  68. * nilfs_error() - report failure condition on a filesystem
  69. *
  70. * nilfs_error() sets an ERROR_FS flag on the superblock as well as
  71. * reporting an error message. It should be called when NILFS detects
  72. * incoherences or defects of meta data on disk. As for sustainable
  73. * errors such as a single-shot I/O error, nilfs_warning() or the printk()
  74. * function should be used instead.
  75. *
  76. * The segment constructor must not call this function because it can
  77. * kill itself.
  78. */
  79. void nilfs_error(struct super_block *sb, const char *function,
  80. const char *fmt, ...)
  81. {
  82. struct nilfs_sb_info *sbi = NILFS_SB(sb);
  83. va_list args;
  84. va_start(args, fmt);
  85. printk(KERN_CRIT "NILFS error (device %s): %s: ", sb->s_id, function);
  86. vprintk(fmt, args);
  87. printk("\n");
  88. va_end(args);
  89. if (!(sb->s_flags & MS_RDONLY)) {
  90. struct the_nilfs *nilfs = sbi->s_nilfs;
  91. if (!nilfs_test_opt(sbi, ERRORS_CONT))
  92. nilfs_detach_segment_constructor(sbi);
  93. down_write(&nilfs->ns_sem);
  94. if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) {
  95. nilfs->ns_mount_state |= NILFS_ERROR_FS;
  96. nilfs->ns_sbp[0]->s_state |=
  97. cpu_to_le16(NILFS_ERROR_FS);
  98. nilfs_commit_super(sbi, 1);
  99. }
  100. up_write(&nilfs->ns_sem);
  101. if (nilfs_test_opt(sbi, ERRORS_RO)) {
  102. printk(KERN_CRIT "Remounting filesystem read-only\n");
  103. sb->s_flags |= MS_RDONLY;
  104. }
  105. }
  106. if (nilfs_test_opt(sbi, ERRORS_PANIC))
  107. panic("NILFS (device %s): panic forced after error\n",
  108. sb->s_id);
  109. }
  110. void nilfs_warning(struct super_block *sb, const char *function,
  111. const char *fmt, ...)
  112. {
  113. va_list args;
  114. va_start(args, fmt);
  115. printk(KERN_WARNING "NILFS warning (device %s): %s: ",
  116. sb->s_id, function);
  117. vprintk(fmt, args);
  118. printk("\n");
  119. va_end(args);
  120. }
  121. static struct kmem_cache *nilfs_inode_cachep;
  122. struct inode *nilfs_alloc_inode(struct super_block *sb)
  123. {
  124. struct nilfs_inode_info *ii;
  125. ii = kmem_cache_alloc(nilfs_inode_cachep, GFP_NOFS);
  126. if (!ii)
  127. return NULL;
  128. ii->i_bh = NULL;
  129. ii->i_state = 0;
  130. ii->vfs_inode.i_version = 1;
  131. nilfs_btnode_cache_init(&ii->i_btnode_cache);
  132. return &ii->vfs_inode;
  133. }
  134. void nilfs_destroy_inode(struct inode *inode)
  135. {
  136. kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode));
  137. }
  138. static void init_once(void *obj)
  139. {
  140. struct nilfs_inode_info *ii = obj;
  141. INIT_LIST_HEAD(&ii->i_dirty);
  142. #ifdef CONFIG_NILFS_XATTR
  143. init_rwsem(&ii->xattr_sem);
  144. #endif
  145. nilfs_btnode_cache_init_once(&ii->i_btnode_cache);
  146. ii->i_bmap = (struct nilfs_bmap *)&ii->i_bmap_union;
  147. inode_init_once(&ii->vfs_inode);
  148. }
  149. static int nilfs_init_inode_cache(void)
  150. {
  151. nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache",
  152. sizeof(struct nilfs_inode_info),
  153. 0, SLAB_RECLAIM_ACCOUNT,
  154. init_once);
  155. return (nilfs_inode_cachep == NULL) ? -ENOMEM : 0;
  156. }
  157. static inline void nilfs_destroy_inode_cache(void)
  158. {
  159. kmem_cache_destroy(nilfs_inode_cachep);
  160. }
  161. static void nilfs_clear_inode(struct inode *inode)
  162. {
  163. struct nilfs_inode_info *ii = NILFS_I(inode);
  164. #ifdef CONFIG_NILFS_POSIX_ACL
  165. if (ii->i_acl && ii->i_acl != NILFS_ACL_NOT_CACHED) {
  166. posix_acl_release(ii->i_acl);
  167. ii->i_acl = NILFS_ACL_NOT_CACHED;
  168. }
  169. if (ii->i_default_acl && ii->i_default_acl != NILFS_ACL_NOT_CACHED) {
  170. posix_acl_release(ii->i_default_acl);
  171. ii->i_default_acl = NILFS_ACL_NOT_CACHED;
  172. }
  173. #endif
  174. /*
  175. * Free resources allocated in nilfs_read_inode(), here.
  176. */
  177. BUG_ON(!list_empty(&ii->i_dirty));
  178. brelse(ii->i_bh);
  179. ii->i_bh = NULL;
  180. if (test_bit(NILFS_I_BMAP, &ii->i_state))
  181. nilfs_bmap_clear(ii->i_bmap);
  182. nilfs_btnode_cache_clear(&ii->i_btnode_cache);
  183. }
  184. static int nilfs_sync_super(struct nilfs_sb_info *sbi, int dupsb)
  185. {
  186. struct the_nilfs *nilfs = sbi->s_nilfs;
  187. int err;
  188. int barrier_done = 0;
  189. if (nilfs_test_opt(sbi, BARRIER)) {
  190. set_buffer_ordered(nilfs->ns_sbh[0]);
  191. barrier_done = 1;
  192. }
  193. retry:
  194. set_buffer_dirty(nilfs->ns_sbh[0]);
  195. err = sync_dirty_buffer(nilfs->ns_sbh[0]);
  196. if (err == -EOPNOTSUPP && barrier_done) {
  197. nilfs_warning(sbi->s_super, __func__,
  198. "barrier-based sync failed. "
  199. "disabling barriers\n");
  200. nilfs_clear_opt(sbi, BARRIER);
  201. barrier_done = 0;
  202. clear_buffer_ordered(nilfs->ns_sbh[0]);
  203. goto retry;
  204. }
  205. if (unlikely(err)) {
  206. printk(KERN_ERR
  207. "NILFS: unable to write superblock (err=%d)\n", err);
  208. if (err == -EIO && nilfs->ns_sbh[1]) {
  209. nilfs_fall_back_super_block(nilfs);
  210. goto retry;
  211. }
  212. } else {
  213. struct nilfs_super_block *sbp = nilfs->ns_sbp[0];
  214. /*
  215. * The latest segment becomes trailable from the position
  216. * written in superblock.
  217. */
  218. clear_nilfs_discontinued(nilfs);
  219. /* update GC protection for recent segments */
  220. if (nilfs->ns_sbh[1]) {
  221. sbp = NULL;
  222. if (dupsb) {
  223. set_buffer_dirty(nilfs->ns_sbh[1]);
  224. if (!sync_dirty_buffer(nilfs->ns_sbh[1]))
  225. sbp = nilfs->ns_sbp[1];
  226. }
  227. }
  228. if (sbp) {
  229. spin_lock(&nilfs->ns_last_segment_lock);
  230. nilfs->ns_prot_seq = le64_to_cpu(sbp->s_last_seq);
  231. spin_unlock(&nilfs->ns_last_segment_lock);
  232. }
  233. }
  234. return err;
  235. }
  236. int nilfs_commit_super(struct nilfs_sb_info *sbi, int dupsb)
  237. {
  238. struct the_nilfs *nilfs = sbi->s_nilfs;
  239. struct nilfs_super_block **sbp = nilfs->ns_sbp;
  240. sector_t nfreeblocks;
  241. time_t t;
  242. int err;
  243. /* nilfs->sem must be locked by the caller. */
  244. if (sbp[0]->s_magic != NILFS_SUPER_MAGIC) {
  245. if (sbp[1] && sbp[1]->s_magic == NILFS_SUPER_MAGIC)
  246. nilfs_swap_super_block(nilfs);
  247. else {
  248. printk(KERN_CRIT "NILFS: superblock broke on dev %s\n",
  249. sbi->s_super->s_id);
  250. return -EIO;
  251. }
  252. }
  253. err = nilfs_count_free_blocks(nilfs, &nfreeblocks);
  254. if (unlikely(err)) {
  255. printk(KERN_ERR "NILFS: failed to count free blocks\n");
  256. return err;
  257. }
  258. spin_lock(&nilfs->ns_last_segment_lock);
  259. sbp[0]->s_last_seq = cpu_to_le64(nilfs->ns_last_seq);
  260. sbp[0]->s_last_pseg = cpu_to_le64(nilfs->ns_last_pseg);
  261. sbp[0]->s_last_cno = cpu_to_le64(nilfs->ns_last_cno);
  262. spin_unlock(&nilfs->ns_last_segment_lock);
  263. t = get_seconds();
  264. nilfs->ns_sbwtime[0] = t;
  265. sbp[0]->s_free_blocks_count = cpu_to_le64(nfreeblocks);
  266. sbp[0]->s_wtime = cpu_to_le64(t);
  267. sbp[0]->s_sum = 0;
  268. sbp[0]->s_sum = cpu_to_le32(crc32_le(nilfs->ns_crc_seed,
  269. (unsigned char *)sbp[0],
  270. nilfs->ns_sbsize));
  271. if (dupsb && sbp[1]) {
  272. memcpy(sbp[1], sbp[0], nilfs->ns_sbsize);
  273. nilfs->ns_sbwtime[1] = t;
  274. }
  275. sbi->s_super->s_dirt = 0;
  276. return nilfs_sync_super(sbi, dupsb);
  277. }
  278. static void nilfs_put_super(struct super_block *sb)
  279. {
  280. struct nilfs_sb_info *sbi = NILFS_SB(sb);
  281. struct the_nilfs *nilfs = sbi->s_nilfs;
  282. lock_kernel();
  283. if (sb->s_dirt)
  284. nilfs_write_super(sb);
  285. nilfs_detach_segment_constructor(sbi);
  286. if (!(sb->s_flags & MS_RDONLY)) {
  287. down_write(&nilfs->ns_sem);
  288. nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state);
  289. nilfs_commit_super(sbi, 1);
  290. up_write(&nilfs->ns_sem);
  291. }
  292. down_write(&nilfs->ns_sem);
  293. if (nilfs->ns_current == sbi)
  294. nilfs->ns_current = NULL;
  295. up_write(&nilfs->ns_sem);
  296. nilfs_detach_checkpoint(sbi);
  297. put_nilfs(sbi->s_nilfs);
  298. sbi->s_super = NULL;
  299. sb->s_fs_info = NULL;
  300. nilfs_put_sbinfo(sbi);
  301. unlock_kernel();
  302. }
  303. /**
  304. * nilfs_write_super - write super block(s) of NILFS
  305. * @sb: super_block
  306. *
  307. * nilfs_write_super() gets a fs-dependent lock, writes super block(s), and
  308. * clears s_dirt. This function is called in the section protected by
  309. * lock_super().
  310. *
  311. * The s_dirt flag is managed by each filesystem and we protect it by ns_sem
  312. * of the struct the_nilfs. Lock order must be as follows:
  313. *
  314. * 1. lock_super()
  315. * 2. down_write(&nilfs->ns_sem)
  316. *
  317. * Inside NILFS, locking ns_sem is enough to protect s_dirt and the buffer
  318. * of the super block (nilfs->ns_sbp[]).
  319. *
  320. * In most cases, VFS functions call lock_super() before calling these
  321. * methods. So we must be careful not to bring on deadlocks when using
  322. * lock_super(); see generic_shutdown_super(), write_super(), and so on.
  323. *
  324. * Note that order of lock_kernel() and lock_super() depends on contexts
  325. * of VFS. We should also note that lock_kernel() can be used in its
  326. * protective section and only the outermost one has an effect.
  327. */
  328. static void nilfs_write_super(struct super_block *sb)
  329. {
  330. struct nilfs_sb_info *sbi = NILFS_SB(sb);
  331. struct the_nilfs *nilfs = sbi->s_nilfs;
  332. down_write(&nilfs->ns_sem);
  333. if (!(sb->s_flags & MS_RDONLY)) {
  334. struct nilfs_super_block **sbp = nilfs->ns_sbp;
  335. u64 t = get_seconds();
  336. int dupsb;
  337. if (!nilfs_discontinued(nilfs) && t >= nilfs->ns_sbwtime[0] &&
  338. t < nilfs->ns_sbwtime[0] + NILFS_SB_FREQ) {
  339. up_write(&nilfs->ns_sem);
  340. return;
  341. }
  342. dupsb = sbp[1] && t > nilfs->ns_sbwtime[1] + NILFS_ALTSB_FREQ;
  343. nilfs_commit_super(sbi, dupsb);
  344. }
  345. sb->s_dirt = 0;
  346. up_write(&nilfs->ns_sem);
  347. }
  348. static int nilfs_sync_fs(struct super_block *sb, int wait)
  349. {
  350. int err = 0;
  351. nilfs_write_super(sb);
  352. /* This function is called when super block should be written back */
  353. if (wait)
  354. err = nilfs_construct_segment(sb);
  355. return err;
  356. }
  357. int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno)
  358. {
  359. struct the_nilfs *nilfs = sbi->s_nilfs;
  360. struct nilfs_checkpoint *raw_cp;
  361. struct buffer_head *bh_cp;
  362. int err;
  363. down_write(&nilfs->ns_sem);
  364. list_add(&sbi->s_list, &nilfs->ns_supers);
  365. up_write(&nilfs->ns_sem);
  366. sbi->s_ifile = nilfs_mdt_new(
  367. nilfs, sbi->s_super, NILFS_IFILE_INO, NILFS_IFILE_GFP);
  368. if (!sbi->s_ifile)
  369. return -ENOMEM;
  370. err = nilfs_palloc_init_blockgroup(sbi->s_ifile, nilfs->ns_inode_size);
  371. if (unlikely(err))
  372. goto failed;
  373. err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, cno, 0, &raw_cp,
  374. &bh_cp);
  375. if (unlikely(err)) {
  376. if (err == -ENOENT || err == -EINVAL) {
  377. printk(KERN_ERR
  378. "NILFS: Invalid checkpoint "
  379. "(checkpoint number=%llu)\n",
  380. (unsigned long long)cno);
  381. err = -EINVAL;
  382. }
  383. goto failed;
  384. }
  385. err = nilfs_read_inode_common(sbi->s_ifile, &raw_cp->cp_ifile_inode);
  386. if (unlikely(err))
  387. goto failed_bh;
  388. atomic_set(&sbi->s_inodes_count, le64_to_cpu(raw_cp->cp_inodes_count));
  389. atomic_set(&sbi->s_blocks_count, le64_to_cpu(raw_cp->cp_blocks_count));
  390. nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, cno, bh_cp);
  391. return 0;
  392. failed_bh:
  393. nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, cno, bh_cp);
  394. failed:
  395. nilfs_mdt_destroy(sbi->s_ifile);
  396. sbi->s_ifile = NULL;
  397. down_write(&nilfs->ns_sem);
  398. list_del_init(&sbi->s_list);
  399. up_write(&nilfs->ns_sem);
  400. return err;
  401. }
  402. void nilfs_detach_checkpoint(struct nilfs_sb_info *sbi)
  403. {
  404. struct the_nilfs *nilfs = sbi->s_nilfs;
  405. nilfs_mdt_clear(sbi->s_ifile);
  406. nilfs_mdt_destroy(sbi->s_ifile);
  407. sbi->s_ifile = NULL;
  408. down_write(&nilfs->ns_sem);
  409. list_del_init(&sbi->s_list);
  410. up_write(&nilfs->ns_sem);
  411. }
  412. static int nilfs_mark_recovery_complete(struct nilfs_sb_info *sbi)
  413. {
  414. struct the_nilfs *nilfs = sbi->s_nilfs;
  415. int err = 0;
  416. down_write(&nilfs->ns_sem);
  417. if (!(nilfs->ns_mount_state & NILFS_VALID_FS)) {
  418. nilfs->ns_mount_state |= NILFS_VALID_FS;
  419. err = nilfs_commit_super(sbi, 1);
  420. if (likely(!err))
  421. printk(KERN_INFO "NILFS: recovery complete.\n");
  422. }
  423. up_write(&nilfs->ns_sem);
  424. return err;
  425. }
  426. static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  427. {
  428. struct super_block *sb = dentry->d_sb;
  429. struct nilfs_sb_info *sbi = NILFS_SB(sb);
  430. struct the_nilfs *nilfs = sbi->s_nilfs;
  431. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  432. unsigned long long blocks;
  433. unsigned long overhead;
  434. unsigned long nrsvblocks;
  435. sector_t nfreeblocks;
  436. int err;
  437. /*
  438. * Compute all of the segment blocks
  439. *
  440. * The blocks before first segment and after last segment
  441. * are excluded.
  442. */
  443. blocks = nilfs->ns_blocks_per_segment * nilfs->ns_nsegments
  444. - nilfs->ns_first_data_block;
  445. nrsvblocks = nilfs->ns_nrsvsegs * nilfs->ns_blocks_per_segment;
  446. /*
  447. * Compute the overhead
  448. *
  449. * When distributing meta data blocks outside semgent structure,
  450. * We must count them as the overhead.
  451. */
  452. overhead = 0;
  453. err = nilfs_count_free_blocks(nilfs, &nfreeblocks);
  454. if (unlikely(err))
  455. return err;
  456. buf->f_type = NILFS_SUPER_MAGIC;
  457. buf->f_bsize = sb->s_blocksize;
  458. buf->f_blocks = blocks - overhead;
  459. buf->f_bfree = nfreeblocks;
  460. buf->f_bavail = (buf->f_bfree >= nrsvblocks) ?
  461. (buf->f_bfree - nrsvblocks) : 0;
  462. buf->f_files = atomic_read(&sbi->s_inodes_count);
  463. buf->f_ffree = 0; /* nilfs_count_free_inodes(sb); */
  464. buf->f_namelen = NILFS_NAME_LEN;
  465. buf->f_fsid.val[0] = (u32)id;
  466. buf->f_fsid.val[1] = (u32)(id >> 32);
  467. return 0;
  468. }
  469. static struct super_operations nilfs_sops = {
  470. .alloc_inode = nilfs_alloc_inode,
  471. .destroy_inode = nilfs_destroy_inode,
  472. .dirty_inode = nilfs_dirty_inode,
  473. /* .write_inode = nilfs_write_inode, */
  474. /* .put_inode = nilfs_put_inode, */
  475. /* .drop_inode = nilfs_drop_inode, */
  476. .delete_inode = nilfs_delete_inode,
  477. .put_super = nilfs_put_super,
  478. .write_super = nilfs_write_super,
  479. .sync_fs = nilfs_sync_fs,
  480. /* .write_super_lockfs */
  481. /* .unlockfs */
  482. .statfs = nilfs_statfs,
  483. .remount_fs = nilfs_remount,
  484. .clear_inode = nilfs_clear_inode,
  485. /* .umount_begin */
  486. /* .show_options */
  487. };
  488. static struct inode *
  489. nilfs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation)
  490. {
  491. struct inode *inode;
  492. if (ino < NILFS_FIRST_INO(sb) && ino != NILFS_ROOT_INO &&
  493. ino != NILFS_SKETCH_INO)
  494. return ERR_PTR(-ESTALE);
  495. inode = nilfs_iget(sb, ino);
  496. if (IS_ERR(inode))
  497. return ERR_CAST(inode);
  498. if (generation && inode->i_generation != generation) {
  499. iput(inode);
  500. return ERR_PTR(-ESTALE);
  501. }
  502. return inode;
  503. }
  504. static struct dentry *
  505. nilfs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
  506. int fh_type)
  507. {
  508. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  509. nilfs_nfs_get_inode);
  510. }
  511. static struct dentry *
  512. nilfs_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len,
  513. int fh_type)
  514. {
  515. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  516. nilfs_nfs_get_inode);
  517. }
  518. static struct export_operations nilfs_export_ops = {
  519. .fh_to_dentry = nilfs_fh_to_dentry,
  520. .fh_to_parent = nilfs_fh_to_parent,
  521. .get_parent = nilfs_get_parent,
  522. };
  523. enum {
  524. Opt_err_cont, Opt_err_panic, Opt_err_ro,
  525. Opt_barrier, Opt_snapshot, Opt_order,
  526. Opt_err,
  527. };
  528. static match_table_t tokens = {
  529. {Opt_err_cont, "errors=continue"},
  530. {Opt_err_panic, "errors=panic"},
  531. {Opt_err_ro, "errors=remount-ro"},
  532. {Opt_barrier, "barrier=%s"},
  533. {Opt_snapshot, "cp=%u"},
  534. {Opt_order, "order=%s"},
  535. {Opt_err, NULL}
  536. };
  537. static int match_bool(substring_t *s, int *result)
  538. {
  539. int len = s->to - s->from;
  540. if (strncmp(s->from, "on", len) == 0)
  541. *result = 1;
  542. else if (strncmp(s->from, "off", len) == 0)
  543. *result = 0;
  544. else
  545. return 1;
  546. return 0;
  547. }
  548. static int parse_options(char *options, struct super_block *sb)
  549. {
  550. struct nilfs_sb_info *sbi = NILFS_SB(sb);
  551. char *p;
  552. substring_t args[MAX_OPT_ARGS];
  553. int option;
  554. if (!options)
  555. return 1;
  556. while ((p = strsep(&options, ",")) != NULL) {
  557. int token;
  558. if (!*p)
  559. continue;
  560. token = match_token(p, tokens, args);
  561. switch (token) {
  562. case Opt_barrier:
  563. if (match_bool(&args[0], &option))
  564. return 0;
  565. if (option)
  566. nilfs_set_opt(sbi, BARRIER);
  567. else
  568. nilfs_clear_opt(sbi, BARRIER);
  569. break;
  570. case Opt_order:
  571. if (strcmp(args[0].from, "relaxed") == 0)
  572. /* Ordered data semantics */
  573. nilfs_clear_opt(sbi, STRICT_ORDER);
  574. else if (strcmp(args[0].from, "strict") == 0)
  575. /* Strict in-order semantics */
  576. nilfs_set_opt(sbi, STRICT_ORDER);
  577. else
  578. return 0;
  579. break;
  580. case Opt_err_panic:
  581. nilfs_write_opt(sbi, ERROR_MODE, ERRORS_PANIC);
  582. break;
  583. case Opt_err_ro:
  584. nilfs_write_opt(sbi, ERROR_MODE, ERRORS_RO);
  585. break;
  586. case Opt_err_cont:
  587. nilfs_write_opt(sbi, ERROR_MODE, ERRORS_CONT);
  588. break;
  589. case Opt_snapshot:
  590. if (match_int(&args[0], &option) || option <= 0)
  591. return 0;
  592. if (!(sb->s_flags & MS_RDONLY))
  593. return 0;
  594. sbi->s_snapshot_cno = option;
  595. nilfs_set_opt(sbi, SNAPSHOT);
  596. break;
  597. default:
  598. printk(KERN_ERR
  599. "NILFS: Unrecognized mount option \"%s\"\n", p);
  600. return 0;
  601. }
  602. }
  603. return 1;
  604. }
  605. static inline void
  606. nilfs_set_default_options(struct nilfs_sb_info *sbi,
  607. struct nilfs_super_block *sbp)
  608. {
  609. sbi->s_mount_opt =
  610. NILFS_MOUNT_ERRORS_CONT | NILFS_MOUNT_BARRIER;
  611. }
  612. static int nilfs_setup_super(struct nilfs_sb_info *sbi)
  613. {
  614. struct the_nilfs *nilfs = sbi->s_nilfs;
  615. struct nilfs_super_block *sbp = nilfs->ns_sbp[0];
  616. int max_mnt_count = le16_to_cpu(sbp->s_max_mnt_count);
  617. int mnt_count = le16_to_cpu(sbp->s_mnt_count);
  618. /* nilfs->sem must be locked by the caller. */
  619. if (!(nilfs->ns_mount_state & NILFS_VALID_FS)) {
  620. printk(KERN_WARNING "NILFS warning: mounting unchecked fs\n");
  621. } else if (nilfs->ns_mount_state & NILFS_ERROR_FS) {
  622. printk(KERN_WARNING
  623. "NILFS warning: mounting fs with errors\n");
  624. #if 0
  625. } else if (max_mnt_count >= 0 && mnt_count >= max_mnt_count) {
  626. printk(KERN_WARNING
  627. "NILFS warning: maximal mount count reached\n");
  628. #endif
  629. }
  630. if (!max_mnt_count)
  631. sbp->s_max_mnt_count = cpu_to_le16(NILFS_DFL_MAX_MNT_COUNT);
  632. sbp->s_mnt_count = cpu_to_le16(mnt_count + 1);
  633. sbp->s_state = cpu_to_le16(le16_to_cpu(sbp->s_state) & ~NILFS_VALID_FS);
  634. sbp->s_mtime = cpu_to_le64(get_seconds());
  635. return nilfs_commit_super(sbi, 1);
  636. }
  637. struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb,
  638. u64 pos, int blocksize,
  639. struct buffer_head **pbh)
  640. {
  641. unsigned long long sb_index = pos;
  642. unsigned long offset;
  643. offset = do_div(sb_index, blocksize);
  644. *pbh = sb_bread(sb, sb_index);
  645. if (!*pbh)
  646. return NULL;
  647. return (struct nilfs_super_block *)((char *)(*pbh)->b_data + offset);
  648. }
  649. int nilfs_store_magic_and_option(struct super_block *sb,
  650. struct nilfs_super_block *sbp,
  651. char *data)
  652. {
  653. struct nilfs_sb_info *sbi = NILFS_SB(sb);
  654. sb->s_magic = le16_to_cpu(sbp->s_magic);
  655. /* FS independent flags */
  656. #ifdef NILFS_ATIME_DISABLE
  657. sb->s_flags |= MS_NOATIME;
  658. #endif
  659. nilfs_set_default_options(sbi, sbp);
  660. sbi->s_resuid = le16_to_cpu(sbp->s_def_resuid);
  661. sbi->s_resgid = le16_to_cpu(sbp->s_def_resgid);
  662. sbi->s_interval = le32_to_cpu(sbp->s_c_interval);
  663. sbi->s_watermark = le32_to_cpu(sbp->s_c_block_max);
  664. return !parse_options(data, sb) ? -EINVAL : 0 ;
  665. }
  666. /**
  667. * nilfs_fill_super() - initialize a super block instance
  668. * @sb: super_block
  669. * @data: mount options
  670. * @silent: silent mode flag
  671. * @nilfs: the_nilfs struct
  672. *
  673. * This function is called exclusively by bd_mount_mutex.
  674. * So, the recovery process is protected from other simultaneous mounts.
  675. */
  676. static int
  677. nilfs_fill_super(struct super_block *sb, void *data, int silent,
  678. struct the_nilfs *nilfs)
  679. {
  680. struct nilfs_sb_info *sbi;
  681. struct inode *root;
  682. __u64 cno;
  683. int err;
  684. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  685. if (!sbi)
  686. return -ENOMEM;
  687. sb->s_fs_info = sbi;
  688. get_nilfs(nilfs);
  689. sbi->s_nilfs = nilfs;
  690. sbi->s_super = sb;
  691. atomic_set(&sbi->s_count, 1);
  692. err = init_nilfs(nilfs, sbi, (char *)data);
  693. if (err)
  694. goto failed_sbi;
  695. spin_lock_init(&sbi->s_inode_lock);
  696. INIT_LIST_HEAD(&sbi->s_dirty_files);
  697. INIT_LIST_HEAD(&sbi->s_list);
  698. /*
  699. * Following initialization is overlapped because
  700. * nilfs_sb_info structure has been cleared at the beginning.
  701. * But we reserve them to keep our interest and make ready
  702. * for the future change.
  703. */
  704. get_random_bytes(&sbi->s_next_generation,
  705. sizeof(sbi->s_next_generation));
  706. spin_lock_init(&sbi->s_next_gen_lock);
  707. sb->s_op = &nilfs_sops;
  708. sb->s_export_op = &nilfs_export_ops;
  709. sb->s_root = NULL;
  710. sb->s_time_gran = 1;
  711. if (!nilfs_loaded(nilfs)) {
  712. err = load_nilfs(nilfs, sbi);
  713. if (err)
  714. goto failed_sbi;
  715. }
  716. cno = nilfs_last_cno(nilfs);
  717. if (sb->s_flags & MS_RDONLY) {
  718. if (nilfs_test_opt(sbi, SNAPSHOT)) {
  719. err = nilfs_cpfile_is_snapshot(nilfs->ns_cpfile,
  720. sbi->s_snapshot_cno);
  721. if (err < 0)
  722. goto failed_sbi;
  723. if (!err) {
  724. printk(KERN_ERR
  725. "NILFS: The specified checkpoint is "
  726. "not a snapshot "
  727. "(checkpoint number=%llu).\n",
  728. (unsigned long long)sbi->s_snapshot_cno);
  729. err = -EINVAL;
  730. goto failed_sbi;
  731. }
  732. cno = sbi->s_snapshot_cno;
  733. } else
  734. /* Read-only mount */
  735. sbi->s_snapshot_cno = cno;
  736. }
  737. err = nilfs_attach_checkpoint(sbi, cno);
  738. if (err) {
  739. printk(KERN_ERR "NILFS: error loading a checkpoint"
  740. " (checkpoint number=%llu).\n", (unsigned long long)cno);
  741. goto failed_sbi;
  742. }
  743. if (!(sb->s_flags & MS_RDONLY)) {
  744. err = nilfs_attach_segment_constructor(sbi);
  745. if (err)
  746. goto failed_checkpoint;
  747. }
  748. root = nilfs_iget(sb, NILFS_ROOT_INO);
  749. if (IS_ERR(root)) {
  750. printk(KERN_ERR "NILFS: get root inode failed\n");
  751. err = PTR_ERR(root);
  752. goto failed_segctor;
  753. }
  754. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  755. iput(root);
  756. printk(KERN_ERR "NILFS: corrupt root inode.\n");
  757. err = -EINVAL;
  758. goto failed_segctor;
  759. }
  760. sb->s_root = d_alloc_root(root);
  761. if (!sb->s_root) {
  762. iput(root);
  763. printk(KERN_ERR "NILFS: get root dentry failed\n");
  764. err = -ENOMEM;
  765. goto failed_segctor;
  766. }
  767. if (!(sb->s_flags & MS_RDONLY)) {
  768. down_write(&nilfs->ns_sem);
  769. nilfs_setup_super(sbi);
  770. up_write(&nilfs->ns_sem);
  771. }
  772. err = nilfs_mark_recovery_complete(sbi);
  773. if (unlikely(err)) {
  774. printk(KERN_ERR "NILFS: recovery failed.\n");
  775. goto failed_root;
  776. }
  777. down_write(&nilfs->ns_sem);
  778. if (!nilfs_test_opt(sbi, SNAPSHOT))
  779. nilfs->ns_current = sbi;
  780. up_write(&nilfs->ns_sem);
  781. return 0;
  782. failed_root:
  783. dput(sb->s_root);
  784. sb->s_root = NULL;
  785. failed_segctor:
  786. nilfs_detach_segment_constructor(sbi);
  787. failed_checkpoint:
  788. nilfs_detach_checkpoint(sbi);
  789. failed_sbi:
  790. put_nilfs(nilfs);
  791. sb->s_fs_info = NULL;
  792. nilfs_put_sbinfo(sbi);
  793. return err;
  794. }
  795. static int nilfs_remount(struct super_block *sb, int *flags, char *data)
  796. {
  797. struct nilfs_sb_info *sbi = NILFS_SB(sb);
  798. struct nilfs_super_block *sbp;
  799. struct the_nilfs *nilfs = sbi->s_nilfs;
  800. unsigned long old_sb_flags;
  801. struct nilfs_mount_options old_opts;
  802. int err;
  803. lock_kernel();
  804. old_sb_flags = sb->s_flags;
  805. old_opts.mount_opt = sbi->s_mount_opt;
  806. old_opts.snapshot_cno = sbi->s_snapshot_cno;
  807. if (!parse_options(data, sb)) {
  808. err = -EINVAL;
  809. goto restore_opts;
  810. }
  811. sb->s_flags = (sb->s_flags & ~MS_POSIXACL);
  812. if ((*flags & MS_RDONLY) &&
  813. sbi->s_snapshot_cno != old_opts.snapshot_cno) {
  814. printk(KERN_WARNING "NILFS (device %s): couldn't "
  815. "remount to a different snapshot. \n",
  816. sb->s_id);
  817. err = -EINVAL;
  818. goto restore_opts;
  819. }
  820. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  821. goto out;
  822. if (*flags & MS_RDONLY) {
  823. /* Shutting down the segment constructor */
  824. nilfs_detach_segment_constructor(sbi);
  825. sb->s_flags |= MS_RDONLY;
  826. sbi->s_snapshot_cno = nilfs_last_cno(nilfs);
  827. /* nilfs_set_opt(sbi, SNAPSHOT); */
  828. /*
  829. * Remounting a valid RW partition RDONLY, so set
  830. * the RDONLY flag and then mark the partition as valid again.
  831. */
  832. down_write(&nilfs->ns_sem);
  833. sbp = nilfs->ns_sbp[0];
  834. if (!(sbp->s_state & le16_to_cpu(NILFS_VALID_FS)) &&
  835. (nilfs->ns_mount_state & NILFS_VALID_FS))
  836. sbp->s_state = cpu_to_le16(nilfs->ns_mount_state);
  837. sbp->s_mtime = cpu_to_le64(get_seconds());
  838. nilfs_commit_super(sbi, 1);
  839. up_write(&nilfs->ns_sem);
  840. } else {
  841. /*
  842. * Mounting a RDONLY partition read-write, so reread and
  843. * store the current valid flag. (It may have been changed
  844. * by fsck since we originally mounted the partition.)
  845. */
  846. down(&sb->s_bdev->bd_mount_sem);
  847. down_read(&nilfs->ns_sem);
  848. if (nilfs->ns_current && nilfs->ns_current != sbi) {
  849. printk(KERN_WARNING "NILFS (device %s): couldn't "
  850. "remount because an RW-mount exists.\n",
  851. sb->s_id);
  852. up_read(&nilfs->ns_sem);
  853. err = -EBUSY;
  854. goto rw_remount_failed;
  855. }
  856. up_read(&nilfs->ns_sem);
  857. if (sbi->s_snapshot_cno != nilfs_last_cno(nilfs)) {
  858. printk(KERN_WARNING "NILFS (device %s): couldn't "
  859. "remount because the current RO-mount is not "
  860. "the latest one.\n",
  861. sb->s_id);
  862. err = -EINVAL;
  863. goto rw_remount_failed;
  864. }
  865. sb->s_flags &= ~MS_RDONLY;
  866. nilfs_clear_opt(sbi, SNAPSHOT);
  867. sbi->s_snapshot_cno = 0;
  868. err = nilfs_attach_segment_constructor(sbi);
  869. if (err)
  870. goto rw_remount_failed;
  871. down_write(&nilfs->ns_sem);
  872. nilfs_setup_super(sbi);
  873. nilfs->ns_current = sbi;
  874. up_write(&nilfs->ns_sem);
  875. up(&sb->s_bdev->bd_mount_sem);
  876. }
  877. out:
  878. unlock_kernel();
  879. return 0;
  880. rw_remount_failed:
  881. up(&sb->s_bdev->bd_mount_sem);
  882. restore_opts:
  883. sb->s_flags = old_sb_flags;
  884. sbi->s_mount_opt = old_opts.mount_opt;
  885. sbi->s_snapshot_cno = old_opts.snapshot_cno;
  886. unlock_kernel();
  887. return err;
  888. }
  889. struct nilfs_super_data {
  890. struct block_device *bdev;
  891. struct nilfs_sb_info *sbi;
  892. __u64 cno;
  893. int flags;
  894. };
  895. /**
  896. * nilfs_identify - pre-read mount options needed to identify mount instance
  897. * @data: mount options
  898. * @sd: nilfs_super_data
  899. */
  900. static int nilfs_identify(char *data, struct nilfs_super_data *sd)
  901. {
  902. char *p, *options = data;
  903. substring_t args[MAX_OPT_ARGS];
  904. int option, token;
  905. int ret = 0;
  906. do {
  907. p = strsep(&options, ",");
  908. if (p != NULL && *p) {
  909. token = match_token(p, tokens, args);
  910. if (token == Opt_snapshot) {
  911. if (!(sd->flags & MS_RDONLY))
  912. ret++;
  913. else {
  914. ret = match_int(&args[0], &option);
  915. if (!ret) {
  916. if (option > 0)
  917. sd->cno = option;
  918. else
  919. ret++;
  920. }
  921. }
  922. }
  923. if (ret)
  924. printk(KERN_ERR
  925. "NILFS: invalid mount option: %s\n", p);
  926. }
  927. if (!options)
  928. break;
  929. BUG_ON(options == data);
  930. *(options - 1) = ',';
  931. } while (!ret);
  932. return ret;
  933. }
  934. static int nilfs_set_bdev_super(struct super_block *s, void *data)
  935. {
  936. struct nilfs_super_data *sd = data;
  937. s->s_bdev = sd->bdev;
  938. s->s_dev = s->s_bdev->bd_dev;
  939. return 0;
  940. }
  941. static int nilfs_test_bdev_super(struct super_block *s, void *data)
  942. {
  943. struct nilfs_super_data *sd = data;
  944. return sd->sbi && s->s_fs_info == (void *)sd->sbi;
  945. }
  946. static int
  947. nilfs_get_sb(struct file_system_type *fs_type, int flags,
  948. const char *dev_name, void *data, struct vfsmount *mnt)
  949. {
  950. struct nilfs_super_data sd;
  951. struct super_block *s;
  952. struct the_nilfs *nilfs;
  953. int err, need_to_close = 1;
  954. sd.bdev = open_bdev_exclusive(dev_name, flags, fs_type);
  955. if (IS_ERR(sd.bdev))
  956. return PTR_ERR(sd.bdev);
  957. /*
  958. * To get mount instance using sget() vfs-routine, NILFS needs
  959. * much more information than normal filesystems to identify mount
  960. * instance. For snapshot mounts, not only a mount type (ro-mount
  961. * or rw-mount) but also a checkpoint number is required.
  962. */
  963. sd.cno = 0;
  964. sd.flags = flags;
  965. if (nilfs_identify((char *)data, &sd)) {
  966. err = -EINVAL;
  967. goto failed;
  968. }
  969. nilfs = find_or_create_nilfs(sd.bdev);
  970. if (!nilfs) {
  971. err = -ENOMEM;
  972. goto failed;
  973. }
  974. down(&sd.bdev->bd_mount_sem);
  975. if (!sd.cno) {
  976. /*
  977. * Check if an exclusive mount exists or not.
  978. * Snapshot mounts coexist with a current mount
  979. * (i.e. rw-mount or ro-mount), whereas rw-mount and
  980. * ro-mount are mutually exclusive.
  981. */
  982. down_read(&nilfs->ns_sem);
  983. if (nilfs->ns_current &&
  984. ((nilfs->ns_current->s_super->s_flags ^ flags)
  985. & MS_RDONLY)) {
  986. up_read(&nilfs->ns_sem);
  987. err = -EBUSY;
  988. goto failed_unlock;
  989. }
  990. up_read(&nilfs->ns_sem);
  991. }
  992. /*
  993. * Find existing nilfs_sb_info struct
  994. */
  995. sd.sbi = nilfs_find_sbinfo(nilfs, !(flags & MS_RDONLY), sd.cno);
  996. if (!sd.cno)
  997. /* trying to get the latest checkpoint. */
  998. sd.cno = nilfs_last_cno(nilfs);
  999. /*
  1000. * Get super block instance holding the nilfs_sb_info struct.
  1001. * A new instance is allocated if no existing mount is present or
  1002. * existing instance has been unmounted.
  1003. */
  1004. s = sget(fs_type, nilfs_test_bdev_super, nilfs_set_bdev_super, &sd);
  1005. if (sd.sbi)
  1006. nilfs_put_sbinfo(sd.sbi);
  1007. if (IS_ERR(s)) {
  1008. err = PTR_ERR(s);
  1009. goto failed_unlock;
  1010. }
  1011. if (!s->s_root) {
  1012. char b[BDEVNAME_SIZE];
  1013. /* New superblock instance created */
  1014. s->s_flags = flags;
  1015. strlcpy(s->s_id, bdevname(sd.bdev, b), sizeof(s->s_id));
  1016. sb_set_blocksize(s, block_size(sd.bdev));
  1017. err = nilfs_fill_super(s, data, flags & MS_VERBOSE, nilfs);
  1018. if (err)
  1019. goto cancel_new;
  1020. s->s_flags |= MS_ACTIVE;
  1021. need_to_close = 0;
  1022. }
  1023. up(&sd.bdev->bd_mount_sem);
  1024. put_nilfs(nilfs);
  1025. if (need_to_close)
  1026. close_bdev_exclusive(sd.bdev, flags);
  1027. simple_set_mnt(mnt, s);
  1028. return 0;
  1029. failed_unlock:
  1030. up(&sd.bdev->bd_mount_sem);
  1031. put_nilfs(nilfs);
  1032. failed:
  1033. close_bdev_exclusive(sd.bdev, flags);
  1034. return err;
  1035. cancel_new:
  1036. /* Abandoning the newly allocated superblock */
  1037. up(&sd.bdev->bd_mount_sem);
  1038. put_nilfs(nilfs);
  1039. up_write(&s->s_umount);
  1040. deactivate_super(s);
  1041. /*
  1042. * deactivate_super() invokes close_bdev_exclusive().
  1043. * We must finish all post-cleaning before this call;
  1044. * put_nilfs() and unlocking bd_mount_sem need the block device.
  1045. */
  1046. return err;
  1047. }
  1048. struct file_system_type nilfs_fs_type = {
  1049. .owner = THIS_MODULE,
  1050. .name = "nilfs2",
  1051. .get_sb = nilfs_get_sb,
  1052. .kill_sb = kill_block_super,
  1053. .fs_flags = FS_REQUIRES_DEV,
  1054. };
  1055. static int __init init_nilfs_fs(void)
  1056. {
  1057. int err;
  1058. err = nilfs_init_inode_cache();
  1059. if (err)
  1060. goto failed;
  1061. err = nilfs_init_transaction_cache();
  1062. if (err)
  1063. goto failed_inode_cache;
  1064. err = nilfs_init_segbuf_cache();
  1065. if (err)
  1066. goto failed_transaction_cache;
  1067. err = nilfs_btree_path_cache_init();
  1068. if (err)
  1069. goto failed_segbuf_cache;
  1070. err = register_filesystem(&nilfs_fs_type);
  1071. if (err)
  1072. goto failed_btree_path_cache;
  1073. return 0;
  1074. failed_btree_path_cache:
  1075. nilfs_btree_path_cache_destroy();
  1076. failed_segbuf_cache:
  1077. nilfs_destroy_segbuf_cache();
  1078. failed_transaction_cache:
  1079. nilfs_destroy_transaction_cache();
  1080. failed_inode_cache:
  1081. nilfs_destroy_inode_cache();
  1082. failed:
  1083. return err;
  1084. }
  1085. static void __exit exit_nilfs_fs(void)
  1086. {
  1087. nilfs_destroy_segbuf_cache();
  1088. nilfs_destroy_transaction_cache();
  1089. nilfs_destroy_inode_cache();
  1090. nilfs_btree_path_cache_destroy();
  1091. unregister_filesystem(&nilfs_fs_type);
  1092. }
  1093. module_init(init_nilfs_fs)
  1094. module_exit(exit_nilfs_fs)