f2fs.h 43 KB

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