super.c 31 KB

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