f2fs.h 36 KB

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