f2fs.h 35 KB

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