f2fs.h 43 KB

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