f2fs.h 35 KB

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