f2fs.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /*
  2. * fs/f2fs/f2fs.h
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef _LINUX_F2FS_H
  12. #define _LINUX_F2FS_H
  13. #include <linux/types.h>
  14. #include <linux/page-flags.h>
  15. #include <linux/buffer_head.h>
  16. #include <linux/slab.h>
  17. #include <linux/crc32.h>
  18. #include <linux/magic.h>
  19. /*
  20. * For mount options
  21. */
  22. #define F2FS_MOUNT_BG_GC 0x00000001
  23. #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
  24. #define F2FS_MOUNT_DISCARD 0x00000004
  25. #define F2FS_MOUNT_NOHEAP 0x00000008
  26. #define F2FS_MOUNT_XATTR_USER 0x00000010
  27. #define F2FS_MOUNT_POSIX_ACL 0x00000020
  28. #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
  29. #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
  30. #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
  31. #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
  32. #define ver_after(a, b) (typecheck(unsigned long long, a) && \
  33. typecheck(unsigned long long, b) && \
  34. ((long long)((a) - (b)) > 0))
  35. typedef u32 block_t; /*
  36. * should not change u32, since it is the on-disk block
  37. * address format, __le32.
  38. */
  39. typedef u32 nid_t;
  40. struct f2fs_mount_info {
  41. unsigned int opt;
  42. };
  43. #define CRCPOLY_LE 0xedb88320
  44. static inline __u32 f2fs_crc32(void *buf, size_t len)
  45. {
  46. unsigned char *p = (unsigned char *)buf;
  47. __u32 crc = F2FS_SUPER_MAGIC;
  48. int i;
  49. while (len--) {
  50. crc ^= *p++;
  51. for (i = 0; i < 8; i++)
  52. crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
  53. }
  54. return crc;
  55. }
  56. static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
  57. {
  58. return f2fs_crc32(buf, buf_size) == blk_crc;
  59. }
  60. /*
  61. * For checkpoint manager
  62. */
  63. enum {
  64. NAT_BITMAP,
  65. SIT_BITMAP
  66. };
  67. /* for the list of orphan inodes */
  68. struct orphan_inode_entry {
  69. struct list_head list; /* list head */
  70. nid_t ino; /* inode number */
  71. };
  72. /* for the list of directory inodes */
  73. struct dir_inode_entry {
  74. struct list_head list; /* list head */
  75. struct inode *inode; /* vfs inode pointer */
  76. };
  77. /* for the list of fsync inodes, used only during recovery */
  78. struct fsync_inode_entry {
  79. struct list_head list; /* list head */
  80. struct inode *inode; /* vfs inode pointer */
  81. block_t blkaddr; /* block address locating the last inode */
  82. };
  83. #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
  84. #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
  85. #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
  86. #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
  87. #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
  88. #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
  89. static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
  90. {
  91. int before = nats_in_cursum(rs);
  92. rs->n_nats = cpu_to_le16(before + i);
  93. return before;
  94. }
  95. static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
  96. {
  97. int before = sits_in_cursum(rs);
  98. rs->n_sits = cpu_to_le16(before + i);
  99. return before;
  100. }
  101. /*
  102. * ioctl commands
  103. */
  104. #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
  105. #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
  106. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  107. /*
  108. * ioctl commands in 32 bit emulation
  109. */
  110. #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  111. #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  112. #endif
  113. /*
  114. * For INODE and NODE manager
  115. */
  116. #define XATTR_NODE_OFFSET (-1) /*
  117. * store xattrs to one node block per
  118. * file keeping -1 as its node offset to
  119. * distinguish from index node blocks.
  120. */
  121. enum {
  122. ALLOC_NODE, /* allocate a new node page if needed */
  123. LOOKUP_NODE, /* look up a node without readahead */
  124. LOOKUP_NODE_RA, /*
  125. * look up a node with readahead called
  126. * by get_datablock_ro.
  127. */
  128. };
  129. #define F2FS_LINK_MAX 32000 /* maximum link count per file */
  130. /* for in-memory extent cache entry */
  131. struct extent_info {
  132. rwlock_t ext_lock; /* rwlock for consistency */
  133. unsigned int fofs; /* start offset in a file */
  134. u32 blk_addr; /* start block address of the extent */
  135. unsigned int len; /* length of the extent */
  136. };
  137. /*
  138. * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
  139. */
  140. #define FADVISE_COLD_BIT 0x01
  141. #define FADVISE_LOST_PINO_BIT 0x02
  142. struct f2fs_inode_info {
  143. struct inode vfs_inode; /* serve a vfs inode */
  144. unsigned long i_flags; /* keep an inode flags for ioctl */
  145. unsigned char i_advise; /* use to give file attribute hints */
  146. unsigned int i_current_depth; /* use only in directory structure */
  147. unsigned int i_pino; /* parent inode number */
  148. umode_t i_acl_mode; /* keep file acl mode temporarily */
  149. /* Use below internally in f2fs*/
  150. unsigned long flags; /* use to pass per-file flags */
  151. atomic_t dirty_dents; /* # of dirty dentry pages */
  152. f2fs_hash_t chash; /* hash value of given file name */
  153. unsigned int clevel; /* maximum level of given file name */
  154. nid_t i_xattr_nid; /* node id that contains xattrs */
  155. struct extent_info ext; /* in-memory extent cache entry */
  156. };
  157. static inline void get_extent_info(struct extent_info *ext,
  158. struct f2fs_extent i_ext)
  159. {
  160. write_lock(&ext->ext_lock);
  161. ext->fofs = le32_to_cpu(i_ext.fofs);
  162. ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
  163. ext->len = le32_to_cpu(i_ext.len);
  164. write_unlock(&ext->ext_lock);
  165. }
  166. static inline void set_raw_extent(struct extent_info *ext,
  167. struct f2fs_extent *i_ext)
  168. {
  169. read_lock(&ext->ext_lock);
  170. i_ext->fofs = cpu_to_le32(ext->fofs);
  171. i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
  172. i_ext->len = cpu_to_le32(ext->len);
  173. read_unlock(&ext->ext_lock);
  174. }
  175. struct f2fs_nm_info {
  176. block_t nat_blkaddr; /* base disk address of NAT */
  177. nid_t max_nid; /* maximum possible node ids */
  178. nid_t next_scan_nid; /* the next nid to be scanned */
  179. /* NAT cache management */
  180. struct radix_tree_root nat_root;/* root of the nat entry cache */
  181. rwlock_t nat_tree_lock; /* protect nat_tree_lock */
  182. unsigned int nat_cnt; /* the # of cached nat entries */
  183. struct list_head nat_entries; /* cached nat entry list (clean) */
  184. struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
  185. /* free node ids management */
  186. struct list_head free_nid_list; /* a list for free nids */
  187. spinlock_t free_nid_list_lock; /* protect free nid list */
  188. unsigned int fcnt; /* the number of free node id */
  189. struct mutex build_lock; /* lock for build free nids */
  190. /* for checkpoint */
  191. char *nat_bitmap; /* NAT bitmap pointer */
  192. int bitmap_size; /* bitmap size */
  193. };
  194. /*
  195. * this structure is used as one of function parameters.
  196. * all the information are dedicated to a given direct node block determined
  197. * by the data offset in a file.
  198. */
  199. struct dnode_of_data {
  200. struct inode *inode; /* vfs inode pointer */
  201. struct page *inode_page; /* its inode page, NULL is possible */
  202. struct page *node_page; /* cached direct node page */
  203. nid_t nid; /* node id of the direct node block */
  204. unsigned int ofs_in_node; /* data offset in the node page */
  205. bool inode_page_locked; /* inode page is locked or not */
  206. block_t data_blkaddr; /* block address of the node block */
  207. };
  208. static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  209. struct page *ipage, struct page *npage, nid_t nid)
  210. {
  211. memset(dn, 0, sizeof(*dn));
  212. dn->inode = inode;
  213. dn->inode_page = ipage;
  214. dn->node_page = npage;
  215. dn->nid = nid;
  216. }
  217. /*
  218. * For SIT manager
  219. *
  220. * By default, there are 6 active log areas across the whole main area.
  221. * When considering hot and cold data separation to reduce cleaning overhead,
  222. * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
  223. * respectively.
  224. * In the current design, you should not change the numbers intentionally.
  225. * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
  226. * logs individually according to the underlying devices. (default: 6)
  227. * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
  228. * data and 8 for node logs.
  229. */
  230. #define NR_CURSEG_DATA_TYPE (3)
  231. #define NR_CURSEG_NODE_TYPE (3)
  232. #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  233. enum {
  234. CURSEG_HOT_DATA = 0, /* directory entry blocks */
  235. CURSEG_WARM_DATA, /* data blocks */
  236. CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
  237. CURSEG_HOT_NODE, /* direct node blocks of directory files */
  238. CURSEG_WARM_NODE, /* direct node blocks of normal files */
  239. CURSEG_COLD_NODE, /* indirect node blocks */
  240. NO_CHECK_TYPE
  241. };
  242. struct f2fs_sm_info {
  243. struct sit_info *sit_info; /* whole segment information */
  244. struct free_segmap_info *free_info; /* free segment information */
  245. struct dirty_seglist_info *dirty_info; /* dirty segment information */
  246. struct curseg_info *curseg_array; /* active segment information */
  247. struct list_head wblist_head; /* list of under-writeback pages */
  248. spinlock_t wblist_lock; /* lock for checkpoint */
  249. block_t seg0_blkaddr; /* block address of 0'th segment */
  250. block_t main_blkaddr; /* start block address of main area */
  251. block_t ssa_blkaddr; /* start block address of SSA area */
  252. unsigned int segment_count; /* total # of segments */
  253. unsigned int main_segments; /* # of segments in main area */
  254. unsigned int reserved_segments; /* # of reserved segments */
  255. unsigned int ovp_segments; /* # of overprovision segments */
  256. };
  257. /*
  258. * For directory operation
  259. */
  260. #define NODE_DIR1_BLOCK (ADDRS_PER_INODE + 1)
  261. #define NODE_DIR2_BLOCK (ADDRS_PER_INODE + 2)
  262. #define NODE_IND1_BLOCK (ADDRS_PER_INODE + 3)
  263. #define NODE_IND2_BLOCK (ADDRS_PER_INODE + 4)
  264. #define NODE_DIND_BLOCK (ADDRS_PER_INODE + 5)
  265. /*
  266. * For superblock
  267. */
  268. /*
  269. * COUNT_TYPE for monitoring
  270. *
  271. * f2fs monitors the number of several block types such as on-writeback,
  272. * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
  273. */
  274. enum count_type {
  275. F2FS_WRITEBACK,
  276. F2FS_DIRTY_DENTS,
  277. F2FS_DIRTY_NODES,
  278. F2FS_DIRTY_META,
  279. NR_COUNT_TYPE,
  280. };
  281. /*
  282. * Uses as sbi->fs_lock[NR_GLOBAL_LOCKS].
  283. * The checkpoint procedure blocks all the locks in this fs_lock array.
  284. * Some FS operations grab free locks, and if there is no free lock,
  285. * then wait to grab a lock in a round-robin manner.
  286. */
  287. #define NR_GLOBAL_LOCKS 8
  288. /*
  289. * The below are the page types of bios used in submti_bio().
  290. * The available types are:
  291. * DATA User data pages. It operates as async mode.
  292. * NODE Node pages. It operates as async mode.
  293. * META FS metadata pages such as SIT, NAT, CP.
  294. * NR_PAGE_TYPE The number of page types.
  295. * META_FLUSH Make sure the previous pages are written
  296. * with waiting the bio's completion
  297. * ... Only can be used with META.
  298. */
  299. enum page_type {
  300. DATA,
  301. NODE,
  302. META,
  303. NR_PAGE_TYPE,
  304. META_FLUSH,
  305. };
  306. struct f2fs_sb_info {
  307. struct super_block *sb; /* pointer to VFS super block */
  308. struct proc_dir_entry *s_proc; /* proc entry */
  309. struct buffer_head *raw_super_buf; /* buffer head of raw sb */
  310. struct f2fs_super_block *raw_super; /* raw super block pointer */
  311. int s_dirty; /* dirty flag for checkpoint */
  312. /* for node-related operations */
  313. struct f2fs_nm_info *nm_info; /* node manager */
  314. struct inode *node_inode; /* cache node blocks */
  315. /* for segment-related operations */
  316. struct f2fs_sm_info *sm_info; /* segment manager */
  317. struct bio *bio[NR_PAGE_TYPE]; /* bios to merge */
  318. sector_t last_block_in_bio[NR_PAGE_TYPE]; /* last block number */
  319. struct rw_semaphore bio_sem; /* IO semaphore */
  320. /* for checkpoint */
  321. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  322. struct inode *meta_inode; /* cache meta blocks */
  323. struct mutex cp_mutex; /* checkpoint procedure lock */
  324. struct mutex fs_lock[NR_GLOBAL_LOCKS]; /* blocking FS operations */
  325. struct mutex node_write; /* locking node writes */
  326. struct mutex writepages; /* mutex for writepages() */
  327. unsigned char next_lock_num; /* round-robin global locks */
  328. int por_doing; /* recovery is doing or not */
  329. int on_build_free_nids; /* build_free_nids is doing */
  330. /* for orphan inode management */
  331. struct list_head orphan_inode_list; /* orphan inode list */
  332. struct mutex orphan_inode_mutex; /* for orphan inode list */
  333. unsigned int n_orphans; /* # of orphan inodes */
  334. /* for directory inode management */
  335. struct list_head dir_inode_list; /* dir inode list */
  336. spinlock_t dir_inode_lock; /* for dir inode list lock */
  337. /* basic file system units */
  338. unsigned int log_sectors_per_block; /* log2 sectors per block */
  339. unsigned int log_blocksize; /* log2 block size */
  340. unsigned int blocksize; /* block size */
  341. unsigned int root_ino_num; /* root inode number*/
  342. unsigned int node_ino_num; /* node inode number*/
  343. unsigned int meta_ino_num; /* meta inode number*/
  344. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  345. unsigned int blocks_per_seg; /* blocks per segment */
  346. unsigned int segs_per_sec; /* segments per section */
  347. unsigned int secs_per_zone; /* sections per zone */
  348. unsigned int total_sections; /* total section count */
  349. unsigned int total_node_count; /* total node block count */
  350. unsigned int total_valid_node_count; /* valid node block count */
  351. unsigned int total_valid_inode_count; /* valid inode count */
  352. int active_logs; /* # of active logs */
  353. block_t user_block_count; /* # of user blocks */
  354. block_t total_valid_block_count; /* # of valid blocks */
  355. block_t alloc_valid_block_count; /* # of allocated blocks */
  356. block_t last_valid_block_count; /* for recovery */
  357. u32 s_next_generation; /* for NFS support */
  358. atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
  359. struct f2fs_mount_info mount_opt; /* mount options */
  360. /* for cleaning operations */
  361. struct mutex gc_mutex; /* mutex for GC */
  362. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  363. unsigned int cur_victim_sec; /* current victim section num */
  364. /*
  365. * for stat information.
  366. * one is for the LFS mode, and the other is for the SSR mode.
  367. */
  368. #ifdef CONFIG_F2FS_STAT_FS
  369. struct f2fs_stat_info *stat_info; /* FS status information */
  370. unsigned int segment_count[2]; /* # of allocated segments */
  371. unsigned int block_count[2]; /* # of allocated blocks */
  372. int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
  373. int bg_gc; /* background gc calls */
  374. unsigned int n_dirty_dirs; /* # of dir inodes */
  375. #endif
  376. unsigned int last_victim[2]; /* last victim segment # */
  377. spinlock_t stat_lock; /* lock for stat operations */
  378. };
  379. /*
  380. * Inline functions
  381. */
  382. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  383. {
  384. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  385. }
  386. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  387. {
  388. return sb->s_fs_info;
  389. }
  390. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  391. {
  392. return (struct f2fs_super_block *)(sbi->raw_super);
  393. }
  394. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  395. {
  396. return (struct f2fs_checkpoint *)(sbi->ckpt);
  397. }
  398. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  399. {
  400. return (struct f2fs_nm_info *)(sbi->nm_info);
  401. }
  402. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  403. {
  404. return (struct f2fs_sm_info *)(sbi->sm_info);
  405. }
  406. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  407. {
  408. return (struct sit_info *)(SM_I(sbi)->sit_info);
  409. }
  410. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  411. {
  412. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  413. }
  414. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  415. {
  416. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  417. }
  418. static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
  419. {
  420. sbi->s_dirty = 1;
  421. }
  422. static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
  423. {
  424. sbi->s_dirty = 0;
  425. }
  426. static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  427. {
  428. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  429. return ckpt_flags & f;
  430. }
  431. static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  432. {
  433. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  434. ckpt_flags |= f;
  435. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  436. }
  437. static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  438. {
  439. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  440. ckpt_flags &= (~f);
  441. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  442. }
  443. static inline void mutex_lock_all(struct f2fs_sb_info *sbi)
  444. {
  445. int i;
  446. for (i = 0; i < NR_GLOBAL_LOCKS; i++) {
  447. /*
  448. * This is the only time we take multiple fs_lock[]
  449. * instances; the order is immaterial since we
  450. * always hold cp_mutex, which serializes multiple
  451. * such operations.
  452. */
  453. mutex_lock_nest_lock(&sbi->fs_lock[i], &sbi->cp_mutex);
  454. }
  455. }
  456. static inline void mutex_unlock_all(struct f2fs_sb_info *sbi)
  457. {
  458. int i = 0;
  459. for (; i < NR_GLOBAL_LOCKS; i++)
  460. mutex_unlock(&sbi->fs_lock[i]);
  461. }
  462. static inline int mutex_lock_op(struct f2fs_sb_info *sbi)
  463. {
  464. unsigned char next_lock = sbi->next_lock_num % NR_GLOBAL_LOCKS;
  465. int i = 0;
  466. for (; i < NR_GLOBAL_LOCKS; i++)
  467. if (mutex_trylock(&sbi->fs_lock[i]))
  468. return i;
  469. mutex_lock(&sbi->fs_lock[next_lock]);
  470. sbi->next_lock_num++;
  471. return next_lock;
  472. }
  473. static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, int ilock)
  474. {
  475. if (ilock < 0)
  476. return;
  477. BUG_ON(ilock >= NR_GLOBAL_LOCKS);
  478. mutex_unlock(&sbi->fs_lock[ilock]);
  479. }
  480. /*
  481. * Check whether the given nid is within node id range.
  482. */
  483. static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
  484. {
  485. WARN_ON((nid >= NM_I(sbi)->max_nid));
  486. if (nid >= NM_I(sbi)->max_nid)
  487. return -EINVAL;
  488. return 0;
  489. }
  490. #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
  491. /*
  492. * Check whether the inode has blocks or not
  493. */
  494. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  495. {
  496. if (F2FS_I(inode)->i_xattr_nid)
  497. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1);
  498. else
  499. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS);
  500. }
  501. static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
  502. struct inode *inode, blkcnt_t count)
  503. {
  504. block_t valid_block_count;
  505. spin_lock(&sbi->stat_lock);
  506. valid_block_count =
  507. sbi->total_valid_block_count + (block_t)count;
  508. if (valid_block_count > sbi->user_block_count) {
  509. spin_unlock(&sbi->stat_lock);
  510. return false;
  511. }
  512. inode->i_blocks += count;
  513. sbi->total_valid_block_count = valid_block_count;
  514. sbi->alloc_valid_block_count += (block_t)count;
  515. spin_unlock(&sbi->stat_lock);
  516. return true;
  517. }
  518. static inline int dec_valid_block_count(struct f2fs_sb_info *sbi,
  519. struct inode *inode,
  520. blkcnt_t count)
  521. {
  522. spin_lock(&sbi->stat_lock);
  523. BUG_ON(sbi->total_valid_block_count < (block_t) count);
  524. BUG_ON(inode->i_blocks < count);
  525. inode->i_blocks -= count;
  526. sbi->total_valid_block_count -= (block_t)count;
  527. spin_unlock(&sbi->stat_lock);
  528. return 0;
  529. }
  530. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  531. {
  532. atomic_inc(&sbi->nr_pages[count_type]);
  533. F2FS_SET_SB_DIRT(sbi);
  534. }
  535. static inline void inode_inc_dirty_dents(struct inode *inode)
  536. {
  537. atomic_inc(&F2FS_I(inode)->dirty_dents);
  538. }
  539. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  540. {
  541. atomic_dec(&sbi->nr_pages[count_type]);
  542. }
  543. static inline void inode_dec_dirty_dents(struct inode *inode)
  544. {
  545. atomic_dec(&F2FS_I(inode)->dirty_dents);
  546. }
  547. static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
  548. {
  549. return atomic_read(&sbi->nr_pages[count_type]);
  550. }
  551. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  552. {
  553. unsigned int pages_per_sec = sbi->segs_per_sec *
  554. (1 << sbi->log_blocks_per_seg);
  555. return ((get_pages(sbi, block_type) + pages_per_sec - 1)
  556. >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
  557. }
  558. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  559. {
  560. block_t ret;
  561. spin_lock(&sbi->stat_lock);
  562. ret = sbi->total_valid_block_count;
  563. spin_unlock(&sbi->stat_lock);
  564. return ret;
  565. }
  566. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  567. {
  568. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  569. /* return NAT or SIT bitmap */
  570. if (flag == NAT_BITMAP)
  571. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  572. else if (flag == SIT_BITMAP)
  573. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  574. return 0;
  575. }
  576. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  577. {
  578. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  579. int offset = (flag == NAT_BITMAP) ?
  580. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  581. return &ckpt->sit_nat_version_bitmap + offset;
  582. }
  583. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  584. {
  585. block_t start_addr;
  586. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  587. unsigned long long ckpt_version = le64_to_cpu(ckpt->checkpoint_ver);
  588. start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  589. /*
  590. * odd numbered checkpoint should at cp segment 0
  591. * and even segent must be at cp segment 1
  592. */
  593. if (!(ckpt_version & 1))
  594. start_addr += sbi->blocks_per_seg;
  595. return start_addr;
  596. }
  597. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  598. {
  599. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  600. }
  601. static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
  602. struct inode *inode,
  603. unsigned int count)
  604. {
  605. block_t valid_block_count;
  606. unsigned int valid_node_count;
  607. spin_lock(&sbi->stat_lock);
  608. valid_block_count = sbi->total_valid_block_count + (block_t)count;
  609. sbi->alloc_valid_block_count += (block_t)count;
  610. valid_node_count = sbi->total_valid_node_count + count;
  611. if (valid_block_count > sbi->user_block_count) {
  612. spin_unlock(&sbi->stat_lock);
  613. return false;
  614. }
  615. if (valid_node_count > sbi->total_node_count) {
  616. spin_unlock(&sbi->stat_lock);
  617. return false;
  618. }
  619. if (inode)
  620. inode->i_blocks += count;
  621. sbi->total_valid_node_count = valid_node_count;
  622. sbi->total_valid_block_count = valid_block_count;
  623. spin_unlock(&sbi->stat_lock);
  624. return true;
  625. }
  626. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  627. struct inode *inode,
  628. unsigned int count)
  629. {
  630. spin_lock(&sbi->stat_lock);
  631. BUG_ON(sbi->total_valid_block_count < count);
  632. BUG_ON(sbi->total_valid_node_count < count);
  633. BUG_ON(inode->i_blocks < count);
  634. inode->i_blocks -= count;
  635. sbi->total_valid_node_count -= count;
  636. sbi->total_valid_block_count -= (block_t)count;
  637. spin_unlock(&sbi->stat_lock);
  638. }
  639. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  640. {
  641. unsigned int ret;
  642. spin_lock(&sbi->stat_lock);
  643. ret = sbi->total_valid_node_count;
  644. spin_unlock(&sbi->stat_lock);
  645. return ret;
  646. }
  647. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  648. {
  649. spin_lock(&sbi->stat_lock);
  650. BUG_ON(sbi->total_valid_inode_count == sbi->total_node_count);
  651. sbi->total_valid_inode_count++;
  652. spin_unlock(&sbi->stat_lock);
  653. }
  654. static inline int dec_valid_inode_count(struct f2fs_sb_info *sbi)
  655. {
  656. spin_lock(&sbi->stat_lock);
  657. BUG_ON(!sbi->total_valid_inode_count);
  658. sbi->total_valid_inode_count--;
  659. spin_unlock(&sbi->stat_lock);
  660. return 0;
  661. }
  662. static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
  663. {
  664. unsigned int ret;
  665. spin_lock(&sbi->stat_lock);
  666. ret = sbi->total_valid_inode_count;
  667. spin_unlock(&sbi->stat_lock);
  668. return ret;
  669. }
  670. static inline void f2fs_put_page(struct page *page, int unlock)
  671. {
  672. if (!page || IS_ERR(page))
  673. return;
  674. if (unlock) {
  675. BUG_ON(!PageLocked(page));
  676. unlock_page(page);
  677. }
  678. page_cache_release(page);
  679. }
  680. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  681. {
  682. if (dn->node_page)
  683. f2fs_put_page(dn->node_page, 1);
  684. if (dn->inode_page && dn->node_page != dn->inode_page)
  685. f2fs_put_page(dn->inode_page, 0);
  686. dn->node_page = NULL;
  687. dn->inode_page = NULL;
  688. }
  689. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  690. size_t size, void (*ctor)(void *))
  691. {
  692. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
  693. }
  694. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  695. static inline bool IS_INODE(struct page *page)
  696. {
  697. struct f2fs_node *p = (struct f2fs_node *)page_address(page);
  698. return RAW_IS_INODE(p);
  699. }
  700. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  701. {
  702. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  703. }
  704. static inline block_t datablock_addr(struct page *node_page,
  705. unsigned int offset)
  706. {
  707. struct f2fs_node *raw_node;
  708. __le32 *addr_array;
  709. raw_node = (struct f2fs_node *)page_address(node_page);
  710. addr_array = blkaddr_in_node(raw_node);
  711. return le32_to_cpu(addr_array[offset]);
  712. }
  713. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  714. {
  715. int mask;
  716. addr += (nr >> 3);
  717. mask = 1 << (7 - (nr & 0x07));
  718. return mask & *addr;
  719. }
  720. static inline int f2fs_set_bit(unsigned int nr, char *addr)
  721. {
  722. int mask;
  723. int ret;
  724. addr += (nr >> 3);
  725. mask = 1 << (7 - (nr & 0x07));
  726. ret = mask & *addr;
  727. *addr |= mask;
  728. return ret;
  729. }
  730. static inline int f2fs_clear_bit(unsigned int nr, char *addr)
  731. {
  732. int mask;
  733. int ret;
  734. addr += (nr >> 3);
  735. mask = 1 << (7 - (nr & 0x07));
  736. ret = mask & *addr;
  737. *addr &= ~mask;
  738. return ret;
  739. }
  740. /* used for f2fs_inode_info->flags */
  741. enum {
  742. FI_NEW_INODE, /* indicate newly allocated inode */
  743. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  744. FI_INC_LINK, /* need to increment i_nlink */
  745. FI_ACL_MODE, /* indicate acl mode */
  746. FI_NO_ALLOC, /* should not allocate any blocks */
  747. FI_UPDATE_DIR, /* should update inode block for consistency */
  748. FI_DELAY_IPUT, /* used for the recovery */
  749. };
  750. static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
  751. {
  752. set_bit(flag, &fi->flags);
  753. }
  754. static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
  755. {
  756. return test_bit(flag, &fi->flags);
  757. }
  758. static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  759. {
  760. clear_bit(flag, &fi->flags);
  761. }
  762. static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
  763. {
  764. fi->i_acl_mode = mode;
  765. set_inode_flag(fi, FI_ACL_MODE);
  766. }
  767. static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  768. {
  769. if (is_inode_flag_set(fi, FI_ACL_MODE)) {
  770. clear_inode_flag(fi, FI_ACL_MODE);
  771. return 1;
  772. }
  773. return 0;
  774. }
  775. static inline int f2fs_readonly(struct super_block *sb)
  776. {
  777. return sb->s_flags & MS_RDONLY;
  778. }
  779. /*
  780. * file.c
  781. */
  782. int f2fs_sync_file(struct file *, loff_t, loff_t, int);
  783. void truncate_data_blocks(struct dnode_of_data *);
  784. void f2fs_truncate(struct inode *);
  785. int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  786. int f2fs_setattr(struct dentry *, struct iattr *);
  787. int truncate_hole(struct inode *, pgoff_t, pgoff_t);
  788. int truncate_data_blocks_range(struct dnode_of_data *, int);
  789. long f2fs_ioctl(struct file *, unsigned int, unsigned long);
  790. long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
  791. /*
  792. * inode.c
  793. */
  794. void f2fs_set_inode_flags(struct inode *);
  795. struct inode *f2fs_iget(struct super_block *, unsigned long);
  796. void update_inode(struct inode *, struct page *);
  797. int update_inode_page(struct inode *);
  798. int f2fs_write_inode(struct inode *, struct writeback_control *);
  799. void f2fs_evict_inode(struct inode *);
  800. /*
  801. * namei.c
  802. */
  803. struct dentry *f2fs_get_parent(struct dentry *child);
  804. /*
  805. * dir.c
  806. */
  807. struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
  808. struct page **);
  809. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
  810. ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
  811. void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
  812. struct page *, struct inode *);
  813. int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
  814. void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
  815. int f2fs_make_empty(struct inode *, struct inode *);
  816. bool f2fs_empty_dir(struct inode *);
  817. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  818. {
  819. return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
  820. inode);
  821. }
  822. /*
  823. * super.c
  824. */
  825. int f2fs_sync_fs(struct super_block *, int);
  826. extern __printf(3, 4)
  827. void f2fs_msg(struct super_block *, const char *, const char *, ...);
  828. /*
  829. * hash.c
  830. */
  831. f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
  832. /*
  833. * node.c
  834. */
  835. struct dnode_of_data;
  836. struct node_info;
  837. int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
  838. void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
  839. int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
  840. int truncate_inode_blocks(struct inode *, pgoff_t);
  841. int remove_inode_page(struct inode *);
  842. struct page *new_inode_page(struct inode *, const struct qstr *);
  843. struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
  844. void ra_node_page(struct f2fs_sb_info *, nid_t);
  845. struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
  846. struct page *get_node_page_ra(struct page *, int);
  847. void sync_inode_page(struct dnode_of_data *);
  848. int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
  849. bool alloc_nid(struct f2fs_sb_info *, nid_t *);
  850. void alloc_nid_done(struct f2fs_sb_info *, nid_t);
  851. void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
  852. void recover_node_page(struct f2fs_sb_info *, struct page *,
  853. struct f2fs_summary *, struct node_info *, block_t);
  854. int recover_inode_page(struct f2fs_sb_info *, struct page *);
  855. int restore_node_summary(struct f2fs_sb_info *, unsigned int,
  856. struct f2fs_summary_block *);
  857. void flush_nat_entries(struct f2fs_sb_info *);
  858. int build_node_manager(struct f2fs_sb_info *);
  859. void destroy_node_manager(struct f2fs_sb_info *);
  860. int __init create_node_manager_caches(void);
  861. void destroy_node_manager_caches(void);
  862. /*
  863. * segment.c
  864. */
  865. void f2fs_balance_fs(struct f2fs_sb_info *);
  866. void invalidate_blocks(struct f2fs_sb_info *, block_t);
  867. void clear_prefree_segments(struct f2fs_sb_info *);
  868. int npages_for_summary_flush(struct f2fs_sb_info *);
  869. void allocate_new_segments(struct f2fs_sb_info *);
  870. struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
  871. struct bio *f2fs_bio_alloc(struct block_device *, int);
  872. void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool sync);
  873. void write_meta_page(struct f2fs_sb_info *, struct page *);
  874. void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
  875. block_t, block_t *);
  876. void write_data_page(struct inode *, struct page *, struct dnode_of_data*,
  877. block_t, block_t *);
  878. void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t);
  879. void recover_data_page(struct f2fs_sb_info *, struct page *,
  880. struct f2fs_summary *, block_t, block_t);
  881. void rewrite_node_page(struct f2fs_sb_info *, struct page *,
  882. struct f2fs_summary *, block_t, block_t);
  883. void write_data_summaries(struct f2fs_sb_info *, block_t);
  884. void write_node_summaries(struct f2fs_sb_info *, block_t);
  885. int lookup_journal_in_cursum(struct f2fs_summary_block *,
  886. int, unsigned int, int);
  887. void flush_sit_entries(struct f2fs_sb_info *);
  888. int build_segment_manager(struct f2fs_sb_info *);
  889. void destroy_segment_manager(struct f2fs_sb_info *);
  890. /*
  891. * checkpoint.c
  892. */
  893. struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
  894. struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
  895. long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
  896. int check_orphan_space(struct f2fs_sb_info *);
  897. void add_orphan_inode(struct f2fs_sb_info *, nid_t);
  898. void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
  899. int recover_orphan_inodes(struct f2fs_sb_info *);
  900. int get_valid_checkpoint(struct f2fs_sb_info *);
  901. void set_dirty_dir_page(struct inode *, struct page *);
  902. void add_dirty_dir_inode(struct inode *);
  903. void remove_dirty_dir_inode(struct inode *);
  904. struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
  905. void sync_dirty_dir_inodes(struct f2fs_sb_info *);
  906. void write_checkpoint(struct f2fs_sb_info *, bool);
  907. void init_orphan_info(struct f2fs_sb_info *);
  908. int __init create_checkpoint_caches(void);
  909. void destroy_checkpoint_caches(void);
  910. /*
  911. * data.c
  912. */
  913. int reserve_new_block(struct dnode_of_data *);
  914. void update_extent_cache(block_t, struct dnode_of_data *);
  915. struct page *find_data_page(struct inode *, pgoff_t, bool);
  916. struct page *get_lock_data_page(struct inode *, pgoff_t);
  917. struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
  918. int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
  919. int do_write_data_page(struct page *);
  920. /*
  921. * gc.c
  922. */
  923. int start_gc_thread(struct f2fs_sb_info *);
  924. void stop_gc_thread(struct f2fs_sb_info *);
  925. block_t start_bidx_of_node(unsigned int);
  926. int f2fs_gc(struct f2fs_sb_info *);
  927. void build_gc_manager(struct f2fs_sb_info *);
  928. int __init create_gc_caches(void);
  929. void destroy_gc_caches(void);
  930. /*
  931. * recovery.c
  932. */
  933. int recover_fsync_data(struct f2fs_sb_info *);
  934. bool space_for_roll_forward(struct f2fs_sb_info *);
  935. /*
  936. * debug.c
  937. */
  938. #ifdef CONFIG_F2FS_STAT_FS
  939. struct f2fs_stat_info {
  940. struct list_head stat_list;
  941. struct f2fs_sb_info *sbi;
  942. struct mutex stat_lock;
  943. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  944. int main_area_segs, main_area_sections, main_area_zones;
  945. int hit_ext, total_ext;
  946. int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
  947. int nats, sits, fnids;
  948. int total_count, utilization;
  949. int bg_gc;
  950. unsigned int valid_count, valid_node_count, valid_inode_count;
  951. unsigned int bimodal, avg_vblocks;
  952. int util_free, util_valid, util_invalid;
  953. int rsvd_segs, overp_segs;
  954. int dirty_count, node_pages, meta_pages;
  955. int prefree_count, call_count;
  956. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  957. int tot_blks, data_blks, node_blks;
  958. int curseg[NR_CURSEG_TYPE];
  959. int cursec[NR_CURSEG_TYPE];
  960. int curzone[NR_CURSEG_TYPE];
  961. unsigned int segment_count[2];
  962. unsigned int block_count[2];
  963. unsigned base_mem, cache_mem;
  964. };
  965. #define stat_inc_call_count(si) ((si)->call_count++)
  966. #define stat_inc_seg_count(sbi, type) \
  967. do { \
  968. struct f2fs_stat_info *si = sbi->stat_info; \
  969. (si)->tot_segs++; \
  970. if (type == SUM_TYPE_DATA) \
  971. si->data_segs++; \
  972. else \
  973. si->node_segs++; \
  974. } while (0)
  975. #define stat_inc_tot_blk_count(si, blks) \
  976. (si->tot_blks += (blks))
  977. #define stat_inc_data_blk_count(sbi, blks) \
  978. do { \
  979. struct f2fs_stat_info *si = sbi->stat_info; \
  980. stat_inc_tot_blk_count(si, blks); \
  981. si->data_blks += (blks); \
  982. } while (0)
  983. #define stat_inc_node_blk_count(sbi, blks) \
  984. do { \
  985. struct f2fs_stat_info *si = sbi->stat_info; \
  986. stat_inc_tot_blk_count(si, blks); \
  987. si->node_blks += (blks); \
  988. } while (0)
  989. int f2fs_build_stats(struct f2fs_sb_info *);
  990. void f2fs_destroy_stats(struct f2fs_sb_info *);
  991. void __init f2fs_create_root_stats(void);
  992. void f2fs_destroy_root_stats(void);
  993. #else
  994. #define stat_inc_call_count(si)
  995. #define stat_inc_seg_count(si, type)
  996. #define stat_inc_tot_blk_count(si, blks)
  997. #define stat_inc_data_blk_count(si, blks)
  998. #define stat_inc_node_blk_count(sbi, blks)
  999. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  1000. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  1001. static inline void __init f2fs_create_root_stats(void) { }
  1002. static inline void f2fs_destroy_root_stats(void) { }
  1003. #endif
  1004. extern const struct file_operations f2fs_dir_operations;
  1005. extern const struct file_operations f2fs_file_operations;
  1006. extern const struct inode_operations f2fs_file_inode_operations;
  1007. extern const struct address_space_operations f2fs_dblock_aops;
  1008. extern const struct address_space_operations f2fs_node_aops;
  1009. extern const struct address_space_operations f2fs_meta_aops;
  1010. extern const struct inode_operations f2fs_dir_inode_operations;
  1011. extern const struct inode_operations f2fs_symlink_inode_operations;
  1012. extern const struct inode_operations f2fs_special_inode_operations;
  1013. #endif