f2fs.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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. * Uses as sbi->fs_lock[NR_GLOBAL_LOCKS].
  280. * The checkpoint procedure blocks all the locks in this fs_lock array.
  281. * Some FS operations grab free locks, and if there is no free lock,
  282. * then wait to grab a lock in a round-robin manner.
  283. */
  284. #define NR_GLOBAL_LOCKS 8
  285. /*
  286. * The below are the page types of bios used in submti_bio().
  287. * The available types are:
  288. * DATA User data pages. It operates as async mode.
  289. * NODE Node pages. It operates as async mode.
  290. * META FS metadata pages such as SIT, NAT, CP.
  291. * NR_PAGE_TYPE The number of page types.
  292. * META_FLUSH Make sure the previous pages are written
  293. * with waiting the bio's completion
  294. * ... Only can be used with META.
  295. */
  296. enum page_type {
  297. DATA,
  298. NODE,
  299. META,
  300. NR_PAGE_TYPE,
  301. META_FLUSH,
  302. };
  303. struct f2fs_sb_info {
  304. struct super_block *sb; /* pointer to VFS super block */
  305. struct proc_dir_entry *s_proc; /* proc entry */
  306. struct buffer_head *raw_super_buf; /* buffer head of raw sb */
  307. struct f2fs_super_block *raw_super; /* raw super block pointer */
  308. int s_dirty; /* dirty flag for checkpoint */
  309. /* for node-related operations */
  310. struct f2fs_nm_info *nm_info; /* node manager */
  311. struct inode *node_inode; /* cache node blocks */
  312. /* for segment-related operations */
  313. struct f2fs_sm_info *sm_info; /* segment manager */
  314. struct bio *bio[NR_PAGE_TYPE]; /* bios to merge */
  315. sector_t last_block_in_bio[NR_PAGE_TYPE]; /* last block number */
  316. struct rw_semaphore bio_sem; /* IO semaphore */
  317. /* for checkpoint */
  318. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  319. struct inode *meta_inode; /* cache meta blocks */
  320. struct mutex cp_mutex; /* checkpoint procedure lock */
  321. struct mutex fs_lock[NR_GLOBAL_LOCKS]; /* blocking FS operations */
  322. struct mutex node_write; /* locking node writes */
  323. struct mutex writepages; /* mutex for writepages() */
  324. unsigned char next_lock_num; /* round-robin global locks */
  325. int por_doing; /* recovery is doing or not */
  326. int on_build_free_nids; /* build_free_nids is doing */
  327. /* for orphan inode management */
  328. struct list_head orphan_inode_list; /* orphan inode list */
  329. struct mutex orphan_inode_mutex; /* for orphan inode list */
  330. unsigned int n_orphans; /* # of orphan inodes */
  331. /* for directory inode management */
  332. struct list_head dir_inode_list; /* dir inode list */
  333. spinlock_t dir_inode_lock; /* for dir inode list lock */
  334. /* basic file system units */
  335. unsigned int log_sectors_per_block; /* log2 sectors per block */
  336. unsigned int log_blocksize; /* log2 block size */
  337. unsigned int blocksize; /* block size */
  338. unsigned int root_ino_num; /* root inode number*/
  339. unsigned int node_ino_num; /* node inode number*/
  340. unsigned int meta_ino_num; /* meta inode number*/
  341. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  342. unsigned int blocks_per_seg; /* blocks per segment */
  343. unsigned int segs_per_sec; /* segments per section */
  344. unsigned int secs_per_zone; /* sections per zone */
  345. unsigned int total_sections; /* total section count */
  346. unsigned int total_node_count; /* total node block count */
  347. unsigned int total_valid_node_count; /* valid node block count */
  348. unsigned int total_valid_inode_count; /* valid inode count */
  349. int active_logs; /* # of active logs */
  350. block_t user_block_count; /* # of user blocks */
  351. block_t total_valid_block_count; /* # of valid blocks */
  352. block_t alloc_valid_block_count; /* # of allocated blocks */
  353. block_t last_valid_block_count; /* for recovery */
  354. u32 s_next_generation; /* for NFS support */
  355. atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
  356. struct f2fs_mount_info mount_opt; /* mount options */
  357. /* for cleaning operations */
  358. struct mutex gc_mutex; /* mutex for GC */
  359. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  360. unsigned int cur_victim_sec; /* current victim section num */
  361. /*
  362. * for stat information.
  363. * one is for the LFS mode, and the other is for the SSR mode.
  364. */
  365. #ifdef CONFIG_F2FS_STAT_FS
  366. struct f2fs_stat_info *stat_info; /* FS status information */
  367. unsigned int segment_count[2]; /* # of allocated segments */
  368. unsigned int block_count[2]; /* # of allocated blocks */
  369. int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
  370. int bg_gc; /* background gc calls */
  371. unsigned int n_dirty_dirs; /* # of dir inodes */
  372. #endif
  373. unsigned int last_victim[2]; /* last victim segment # */
  374. spinlock_t stat_lock; /* lock for stat operations */
  375. /* For sysfs suppport */
  376. struct kobject s_kobj;
  377. struct completion s_kobj_unregister;
  378. };
  379. /*
  380. * Inline functions
  381. */
  382. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  383. {
  384. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  385. }
  386. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  387. {
  388. return sb->s_fs_info;
  389. }
  390. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  391. {
  392. return (struct f2fs_super_block *)(sbi->raw_super);
  393. }
  394. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  395. {
  396. return (struct f2fs_checkpoint *)(sbi->ckpt);
  397. }
  398. static inline struct f2fs_node *F2FS_NODE(struct page *page)
  399. {
  400. return (struct f2fs_node *)page_address(page);
  401. }
  402. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  403. {
  404. return (struct f2fs_nm_info *)(sbi->nm_info);
  405. }
  406. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  407. {
  408. return (struct f2fs_sm_info *)(sbi->sm_info);
  409. }
  410. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  411. {
  412. return (struct sit_info *)(SM_I(sbi)->sit_info);
  413. }
  414. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  415. {
  416. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  417. }
  418. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  419. {
  420. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  421. }
  422. static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
  423. {
  424. sbi->s_dirty = 1;
  425. }
  426. static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
  427. {
  428. sbi->s_dirty = 0;
  429. }
  430. static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
  431. {
  432. return le64_to_cpu(cp->checkpoint_ver);
  433. }
  434. static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  435. {
  436. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  437. return ckpt_flags & f;
  438. }
  439. static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  440. {
  441. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  442. ckpt_flags |= f;
  443. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  444. }
  445. static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  446. {
  447. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  448. ckpt_flags &= (~f);
  449. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  450. }
  451. static inline void mutex_lock_all(struct f2fs_sb_info *sbi)
  452. {
  453. int i;
  454. for (i = 0; i < NR_GLOBAL_LOCKS; i++) {
  455. /*
  456. * This is the only time we take multiple fs_lock[]
  457. * instances; the order is immaterial since we
  458. * always hold cp_mutex, which serializes multiple
  459. * such operations.
  460. */
  461. mutex_lock_nest_lock(&sbi->fs_lock[i], &sbi->cp_mutex);
  462. }
  463. }
  464. static inline void mutex_unlock_all(struct f2fs_sb_info *sbi)
  465. {
  466. int i = 0;
  467. for (; i < NR_GLOBAL_LOCKS; i++)
  468. mutex_unlock(&sbi->fs_lock[i]);
  469. }
  470. static inline int mutex_lock_op(struct f2fs_sb_info *sbi)
  471. {
  472. unsigned char next_lock = sbi->next_lock_num % NR_GLOBAL_LOCKS;
  473. int i = 0;
  474. for (; i < NR_GLOBAL_LOCKS; i++)
  475. if (mutex_trylock(&sbi->fs_lock[i]))
  476. return i;
  477. mutex_lock(&sbi->fs_lock[next_lock]);
  478. sbi->next_lock_num++;
  479. return next_lock;
  480. }
  481. static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, int ilock)
  482. {
  483. if (ilock < 0)
  484. return;
  485. BUG_ON(ilock >= NR_GLOBAL_LOCKS);
  486. mutex_unlock(&sbi->fs_lock[ilock]);
  487. }
  488. /*
  489. * Check whether the given nid is within node id range.
  490. */
  491. static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
  492. {
  493. WARN_ON((nid >= NM_I(sbi)->max_nid));
  494. if (nid >= NM_I(sbi)->max_nid)
  495. return -EINVAL;
  496. return 0;
  497. }
  498. #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
  499. /*
  500. * Check whether the inode has blocks or not
  501. */
  502. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  503. {
  504. if (F2FS_I(inode)->i_xattr_nid)
  505. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1);
  506. else
  507. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS);
  508. }
  509. static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
  510. struct inode *inode, blkcnt_t count)
  511. {
  512. block_t valid_block_count;
  513. spin_lock(&sbi->stat_lock);
  514. valid_block_count =
  515. sbi->total_valid_block_count + (block_t)count;
  516. if (valid_block_count > sbi->user_block_count) {
  517. spin_unlock(&sbi->stat_lock);
  518. return false;
  519. }
  520. inode->i_blocks += count;
  521. sbi->total_valid_block_count = valid_block_count;
  522. sbi->alloc_valid_block_count += (block_t)count;
  523. spin_unlock(&sbi->stat_lock);
  524. return true;
  525. }
  526. static inline int dec_valid_block_count(struct f2fs_sb_info *sbi,
  527. struct inode *inode,
  528. blkcnt_t count)
  529. {
  530. spin_lock(&sbi->stat_lock);
  531. BUG_ON(sbi->total_valid_block_count < (block_t) count);
  532. BUG_ON(inode->i_blocks < count);
  533. inode->i_blocks -= count;
  534. sbi->total_valid_block_count -= (block_t)count;
  535. spin_unlock(&sbi->stat_lock);
  536. return 0;
  537. }
  538. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  539. {
  540. atomic_inc(&sbi->nr_pages[count_type]);
  541. F2FS_SET_SB_DIRT(sbi);
  542. }
  543. static inline void inode_inc_dirty_dents(struct inode *inode)
  544. {
  545. atomic_inc(&F2FS_I(inode)->dirty_dents);
  546. }
  547. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  548. {
  549. atomic_dec(&sbi->nr_pages[count_type]);
  550. }
  551. static inline void inode_dec_dirty_dents(struct inode *inode)
  552. {
  553. atomic_dec(&F2FS_I(inode)->dirty_dents);
  554. }
  555. static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
  556. {
  557. return atomic_read(&sbi->nr_pages[count_type]);
  558. }
  559. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  560. {
  561. unsigned int pages_per_sec = sbi->segs_per_sec *
  562. (1 << sbi->log_blocks_per_seg);
  563. return ((get_pages(sbi, block_type) + pages_per_sec - 1)
  564. >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
  565. }
  566. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  567. {
  568. block_t ret;
  569. spin_lock(&sbi->stat_lock);
  570. ret = sbi->total_valid_block_count;
  571. spin_unlock(&sbi->stat_lock);
  572. return ret;
  573. }
  574. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  575. {
  576. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  577. /* return NAT or SIT bitmap */
  578. if (flag == NAT_BITMAP)
  579. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  580. else if (flag == SIT_BITMAP)
  581. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  582. return 0;
  583. }
  584. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  585. {
  586. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  587. int offset = (flag == NAT_BITMAP) ?
  588. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  589. return &ckpt->sit_nat_version_bitmap + offset;
  590. }
  591. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  592. {
  593. block_t start_addr;
  594. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  595. unsigned long long ckpt_version = cur_cp_version(ckpt);
  596. start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  597. /*
  598. * odd numbered checkpoint should at cp segment 0
  599. * and even segent must be at cp segment 1
  600. */
  601. if (!(ckpt_version & 1))
  602. start_addr += sbi->blocks_per_seg;
  603. return start_addr;
  604. }
  605. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  606. {
  607. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  608. }
  609. static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
  610. struct inode *inode,
  611. unsigned int count)
  612. {
  613. block_t valid_block_count;
  614. unsigned int valid_node_count;
  615. spin_lock(&sbi->stat_lock);
  616. valid_block_count = sbi->total_valid_block_count + (block_t)count;
  617. sbi->alloc_valid_block_count += (block_t)count;
  618. valid_node_count = sbi->total_valid_node_count + count;
  619. if (valid_block_count > sbi->user_block_count) {
  620. spin_unlock(&sbi->stat_lock);
  621. return false;
  622. }
  623. if (valid_node_count > sbi->total_node_count) {
  624. spin_unlock(&sbi->stat_lock);
  625. return false;
  626. }
  627. if (inode)
  628. inode->i_blocks += count;
  629. sbi->total_valid_node_count = valid_node_count;
  630. sbi->total_valid_block_count = valid_block_count;
  631. spin_unlock(&sbi->stat_lock);
  632. return true;
  633. }
  634. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  635. struct inode *inode,
  636. unsigned int count)
  637. {
  638. spin_lock(&sbi->stat_lock);
  639. BUG_ON(sbi->total_valid_block_count < count);
  640. BUG_ON(sbi->total_valid_node_count < count);
  641. BUG_ON(inode->i_blocks < count);
  642. inode->i_blocks -= count;
  643. sbi->total_valid_node_count -= count;
  644. sbi->total_valid_block_count -= (block_t)count;
  645. spin_unlock(&sbi->stat_lock);
  646. }
  647. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  648. {
  649. unsigned int ret;
  650. spin_lock(&sbi->stat_lock);
  651. ret = sbi->total_valid_node_count;
  652. spin_unlock(&sbi->stat_lock);
  653. return ret;
  654. }
  655. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  656. {
  657. spin_lock(&sbi->stat_lock);
  658. BUG_ON(sbi->total_valid_inode_count == sbi->total_node_count);
  659. sbi->total_valid_inode_count++;
  660. spin_unlock(&sbi->stat_lock);
  661. }
  662. static inline int dec_valid_inode_count(struct f2fs_sb_info *sbi)
  663. {
  664. spin_lock(&sbi->stat_lock);
  665. BUG_ON(!sbi->total_valid_inode_count);
  666. sbi->total_valid_inode_count--;
  667. spin_unlock(&sbi->stat_lock);
  668. return 0;
  669. }
  670. static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
  671. {
  672. unsigned int ret;
  673. spin_lock(&sbi->stat_lock);
  674. ret = sbi->total_valid_inode_count;
  675. spin_unlock(&sbi->stat_lock);
  676. return ret;
  677. }
  678. static inline void f2fs_put_page(struct page *page, int unlock)
  679. {
  680. if (!page || IS_ERR(page))
  681. return;
  682. if (unlock) {
  683. BUG_ON(!PageLocked(page));
  684. unlock_page(page);
  685. }
  686. page_cache_release(page);
  687. }
  688. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  689. {
  690. if (dn->node_page)
  691. f2fs_put_page(dn->node_page, 1);
  692. if (dn->inode_page && dn->node_page != dn->inode_page)
  693. f2fs_put_page(dn->inode_page, 0);
  694. dn->node_page = NULL;
  695. dn->inode_page = NULL;
  696. }
  697. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  698. size_t size, void (*ctor)(void *))
  699. {
  700. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
  701. }
  702. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  703. static inline bool IS_INODE(struct page *page)
  704. {
  705. struct f2fs_node *p = F2FS_NODE(page);
  706. return RAW_IS_INODE(p);
  707. }
  708. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  709. {
  710. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  711. }
  712. static inline block_t datablock_addr(struct page *node_page,
  713. unsigned int offset)
  714. {
  715. struct f2fs_node *raw_node;
  716. __le32 *addr_array;
  717. raw_node = F2FS_NODE(node_page);
  718. addr_array = blkaddr_in_node(raw_node);
  719. return le32_to_cpu(addr_array[offset]);
  720. }
  721. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  722. {
  723. int mask;
  724. addr += (nr >> 3);
  725. mask = 1 << (7 - (nr & 0x07));
  726. return mask & *addr;
  727. }
  728. static inline int f2fs_set_bit(unsigned int nr, char *addr)
  729. {
  730. int mask;
  731. int ret;
  732. addr += (nr >> 3);
  733. mask = 1 << (7 - (nr & 0x07));
  734. ret = mask & *addr;
  735. *addr |= mask;
  736. return ret;
  737. }
  738. static inline int f2fs_clear_bit(unsigned int nr, char *addr)
  739. {
  740. int mask;
  741. int ret;
  742. addr += (nr >> 3);
  743. mask = 1 << (7 - (nr & 0x07));
  744. ret = mask & *addr;
  745. *addr &= ~mask;
  746. return ret;
  747. }
  748. /* used for f2fs_inode_info->flags */
  749. enum {
  750. FI_NEW_INODE, /* indicate newly allocated inode */
  751. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  752. FI_INC_LINK, /* need to increment i_nlink */
  753. FI_ACL_MODE, /* indicate acl mode */
  754. FI_NO_ALLOC, /* should not allocate any blocks */
  755. FI_UPDATE_DIR, /* should update inode block for consistency */
  756. FI_DELAY_IPUT, /* used for the recovery */
  757. FI_INLINE_XATTR, /* used for inline xattr */
  758. };
  759. static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
  760. {
  761. set_bit(flag, &fi->flags);
  762. }
  763. static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
  764. {
  765. return test_bit(flag, &fi->flags);
  766. }
  767. static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  768. {
  769. clear_bit(flag, &fi->flags);
  770. }
  771. static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
  772. {
  773. fi->i_acl_mode = mode;
  774. set_inode_flag(fi, FI_ACL_MODE);
  775. }
  776. static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  777. {
  778. if (is_inode_flag_set(fi, FI_ACL_MODE)) {
  779. clear_inode_flag(fi, FI_ACL_MODE);
  780. return 1;
  781. }
  782. return 0;
  783. }
  784. static inline void get_inline_info(struct f2fs_inode_info *fi,
  785. struct f2fs_inode *ri)
  786. {
  787. if (ri->i_inline & F2FS_INLINE_XATTR)
  788. set_inode_flag(fi, FI_INLINE_XATTR);
  789. }
  790. static inline void set_raw_inline(struct f2fs_inode_info *fi,
  791. struct f2fs_inode *ri)
  792. {
  793. ri->i_inline = 0;
  794. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  795. ri->i_inline |= F2FS_INLINE_XATTR;
  796. }
  797. static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
  798. {
  799. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  800. return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
  801. return DEF_ADDRS_PER_INODE;
  802. }
  803. static inline void *inline_xattr_addr(struct page *page)
  804. {
  805. struct f2fs_inode *ri;
  806. ri = (struct f2fs_inode *)page_address(page);
  807. return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
  808. F2FS_INLINE_XATTR_ADDRS]);
  809. }
  810. static inline int inline_xattr_size(struct inode *inode)
  811. {
  812. if (is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR))
  813. return F2FS_INLINE_XATTR_ADDRS << 2;
  814. else
  815. return 0;
  816. }
  817. static inline int f2fs_readonly(struct super_block *sb)
  818. {
  819. return sb->s_flags & MS_RDONLY;
  820. }
  821. /*
  822. * file.c
  823. */
  824. int f2fs_sync_file(struct file *, loff_t, loff_t, int);
  825. void truncate_data_blocks(struct dnode_of_data *);
  826. void f2fs_truncate(struct inode *);
  827. int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  828. int f2fs_setattr(struct dentry *, struct iattr *);
  829. int truncate_hole(struct inode *, pgoff_t, pgoff_t);
  830. int truncate_data_blocks_range(struct dnode_of_data *, int);
  831. long f2fs_ioctl(struct file *, unsigned int, unsigned long);
  832. long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
  833. /*
  834. * inode.c
  835. */
  836. void f2fs_set_inode_flags(struct inode *);
  837. struct inode *f2fs_iget(struct super_block *, unsigned long);
  838. void update_inode(struct inode *, struct page *);
  839. int update_inode_page(struct inode *);
  840. int f2fs_write_inode(struct inode *, struct writeback_control *);
  841. void f2fs_evict_inode(struct inode *);
  842. /*
  843. * namei.c
  844. */
  845. struct dentry *f2fs_get_parent(struct dentry *child);
  846. /*
  847. * dir.c
  848. */
  849. struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
  850. struct page **);
  851. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
  852. ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
  853. void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
  854. struct page *, struct inode *);
  855. int update_dent_inode(struct inode *, const struct qstr *);
  856. int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
  857. void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
  858. int f2fs_make_empty(struct inode *, struct inode *);
  859. bool f2fs_empty_dir(struct inode *);
  860. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  861. {
  862. return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
  863. inode);
  864. }
  865. /*
  866. * super.c
  867. */
  868. int f2fs_sync_fs(struct super_block *, int);
  869. extern __printf(3, 4)
  870. void f2fs_msg(struct super_block *, const char *, const char *, ...);
  871. /*
  872. * hash.c
  873. */
  874. f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
  875. /*
  876. * node.c
  877. */
  878. struct dnode_of_data;
  879. struct node_info;
  880. int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
  881. void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
  882. int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
  883. int truncate_inode_blocks(struct inode *, pgoff_t);
  884. int truncate_xattr_node(struct inode *, struct page *);
  885. int remove_inode_page(struct inode *);
  886. struct page *new_inode_page(struct inode *, const struct qstr *);
  887. struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
  888. void ra_node_page(struct f2fs_sb_info *, nid_t);
  889. struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
  890. struct page *get_node_page_ra(struct page *, int);
  891. void sync_inode_page(struct dnode_of_data *);
  892. int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
  893. bool alloc_nid(struct f2fs_sb_info *, nid_t *);
  894. void alloc_nid_done(struct f2fs_sb_info *, nid_t);
  895. void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
  896. void recover_node_page(struct f2fs_sb_info *, struct page *,
  897. struct f2fs_summary *, struct node_info *, block_t);
  898. int recover_inode_page(struct f2fs_sb_info *, struct page *);
  899. int restore_node_summary(struct f2fs_sb_info *, unsigned int,
  900. struct f2fs_summary_block *);
  901. void flush_nat_entries(struct f2fs_sb_info *);
  902. int build_node_manager(struct f2fs_sb_info *);
  903. void destroy_node_manager(struct f2fs_sb_info *);
  904. int __init create_node_manager_caches(void);
  905. void destroy_node_manager_caches(void);
  906. /*
  907. * segment.c
  908. */
  909. void f2fs_balance_fs(struct f2fs_sb_info *);
  910. void invalidate_blocks(struct f2fs_sb_info *, block_t);
  911. void clear_prefree_segments(struct f2fs_sb_info *);
  912. int npages_for_summary_flush(struct f2fs_sb_info *);
  913. void allocate_new_segments(struct f2fs_sb_info *);
  914. struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
  915. struct bio *f2fs_bio_alloc(struct block_device *, int);
  916. void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool);
  917. void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
  918. void write_meta_page(struct f2fs_sb_info *, struct page *);
  919. void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
  920. block_t, block_t *);
  921. void write_data_page(struct inode *, struct page *, struct dnode_of_data*,
  922. block_t, block_t *);
  923. void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t);
  924. void recover_data_page(struct f2fs_sb_info *, struct page *,
  925. struct f2fs_summary *, block_t, block_t);
  926. void rewrite_node_page(struct f2fs_sb_info *, struct page *,
  927. struct f2fs_summary *, block_t, block_t);
  928. void write_data_summaries(struct f2fs_sb_info *, block_t);
  929. void write_node_summaries(struct f2fs_sb_info *, block_t);
  930. int lookup_journal_in_cursum(struct f2fs_summary_block *,
  931. int, unsigned int, int);
  932. void flush_sit_entries(struct f2fs_sb_info *);
  933. int build_segment_manager(struct f2fs_sb_info *);
  934. void destroy_segment_manager(struct f2fs_sb_info *);
  935. /*
  936. * checkpoint.c
  937. */
  938. struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
  939. struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
  940. long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
  941. int acquire_orphan_inode(struct f2fs_sb_info *);
  942. void release_orphan_inode(struct f2fs_sb_info *);
  943. void add_orphan_inode(struct f2fs_sb_info *, nid_t);
  944. void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
  945. int recover_orphan_inodes(struct f2fs_sb_info *);
  946. int get_valid_checkpoint(struct f2fs_sb_info *);
  947. void set_dirty_dir_page(struct inode *, struct page *);
  948. void add_dirty_dir_inode(struct inode *);
  949. void remove_dirty_dir_inode(struct inode *);
  950. struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
  951. void sync_dirty_dir_inodes(struct f2fs_sb_info *);
  952. void write_checkpoint(struct f2fs_sb_info *, bool);
  953. void init_orphan_info(struct f2fs_sb_info *);
  954. int __init create_checkpoint_caches(void);
  955. void destroy_checkpoint_caches(void);
  956. /*
  957. * data.c
  958. */
  959. int reserve_new_block(struct dnode_of_data *);
  960. void update_extent_cache(block_t, struct dnode_of_data *);
  961. struct page *find_data_page(struct inode *, pgoff_t, bool);
  962. struct page *get_lock_data_page(struct inode *, pgoff_t);
  963. struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
  964. int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
  965. int do_write_data_page(struct page *);
  966. /*
  967. * gc.c
  968. */
  969. int start_gc_thread(struct f2fs_sb_info *);
  970. void stop_gc_thread(struct f2fs_sb_info *);
  971. block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
  972. int f2fs_gc(struct f2fs_sb_info *);
  973. void build_gc_manager(struct f2fs_sb_info *);
  974. int __init create_gc_caches(void);
  975. void destroy_gc_caches(void);
  976. /*
  977. * recovery.c
  978. */
  979. int recover_fsync_data(struct f2fs_sb_info *);
  980. bool space_for_roll_forward(struct f2fs_sb_info *);
  981. /*
  982. * debug.c
  983. */
  984. #ifdef CONFIG_F2FS_STAT_FS
  985. struct f2fs_stat_info {
  986. struct list_head stat_list;
  987. struct f2fs_sb_info *sbi;
  988. struct mutex stat_lock;
  989. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  990. int main_area_segs, main_area_sections, main_area_zones;
  991. int hit_ext, total_ext;
  992. int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
  993. int nats, sits, fnids;
  994. int total_count, utilization;
  995. int bg_gc;
  996. unsigned int valid_count, valid_node_count, valid_inode_count;
  997. unsigned int bimodal, avg_vblocks;
  998. int util_free, util_valid, util_invalid;
  999. int rsvd_segs, overp_segs;
  1000. int dirty_count, node_pages, meta_pages;
  1001. int prefree_count, call_count;
  1002. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  1003. int tot_blks, data_blks, node_blks;
  1004. int curseg[NR_CURSEG_TYPE];
  1005. int cursec[NR_CURSEG_TYPE];
  1006. int curzone[NR_CURSEG_TYPE];
  1007. unsigned int segment_count[2];
  1008. unsigned int block_count[2];
  1009. unsigned base_mem, cache_mem;
  1010. };
  1011. static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
  1012. {
  1013. return (struct f2fs_stat_info*)sbi->stat_info;
  1014. }
  1015. #define stat_inc_call_count(si) ((si)->call_count++)
  1016. #define stat_inc_seg_count(sbi, type) \
  1017. do { \
  1018. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1019. (si)->tot_segs++; \
  1020. if (type == SUM_TYPE_DATA) \
  1021. si->data_segs++; \
  1022. else \
  1023. si->node_segs++; \
  1024. } while (0)
  1025. #define stat_inc_tot_blk_count(si, blks) \
  1026. (si->tot_blks += (blks))
  1027. #define stat_inc_data_blk_count(sbi, blks) \
  1028. do { \
  1029. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1030. stat_inc_tot_blk_count(si, blks); \
  1031. si->data_blks += (blks); \
  1032. } while (0)
  1033. #define stat_inc_node_blk_count(sbi, blks) \
  1034. do { \
  1035. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1036. stat_inc_tot_blk_count(si, blks); \
  1037. si->node_blks += (blks); \
  1038. } while (0)
  1039. int f2fs_build_stats(struct f2fs_sb_info *);
  1040. void f2fs_destroy_stats(struct f2fs_sb_info *);
  1041. void __init f2fs_create_root_stats(void);
  1042. void f2fs_destroy_root_stats(void);
  1043. #else
  1044. #define stat_inc_call_count(si)
  1045. #define stat_inc_seg_count(si, type)
  1046. #define stat_inc_tot_blk_count(si, blks)
  1047. #define stat_inc_data_blk_count(si, blks)
  1048. #define stat_inc_node_blk_count(sbi, blks)
  1049. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  1050. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  1051. static inline void __init f2fs_create_root_stats(void) { }
  1052. static inline void f2fs_destroy_root_stats(void) { }
  1053. #endif
  1054. extern const struct file_operations f2fs_dir_operations;
  1055. extern const struct file_operations f2fs_file_operations;
  1056. extern const struct inode_operations f2fs_file_inode_operations;
  1057. extern const struct address_space_operations f2fs_dblock_aops;
  1058. extern const struct address_space_operations f2fs_node_aops;
  1059. extern const struct address_space_operations f2fs_meta_aops;
  1060. extern const struct inode_operations f2fs_dir_inode_operations;
  1061. extern const struct inode_operations f2fs_symlink_inode_operations;
  1062. extern const struct inode_operations f2fs_special_inode_operations;
  1063. #endif