f2fs.h 41 KB

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