f2fs.h 42 KB

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