f2fs.h 40 KB

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