f2fs.h 43 KB

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