f2fs.h 36 KB

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