f2fs.h 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  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(sbi, condition) BUG_ON(condition)
  23. #define f2fs_down_write(x, y) down_write_nest_lock(x, y)
  24. #else
  25. #define f2fs_bug_on(sbi, condition) \
  26. do { \
  27. if (unlikely(condition)) { \
  28. WARN_ON(1); \
  29. set_sbi_flag(sbi, SBI_NEED_FSCK); \
  30. } \
  31. } while (0)
  32. #define f2fs_down_write(x, y) down_write(x)
  33. #endif
  34. /*
  35. * For mount options
  36. */
  37. #define F2FS_MOUNT_BG_GC 0x00000001
  38. #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
  39. #define F2FS_MOUNT_DISCARD 0x00000004
  40. #define F2FS_MOUNT_NOHEAP 0x00000008
  41. #define F2FS_MOUNT_XATTR_USER 0x00000010
  42. #define F2FS_MOUNT_POSIX_ACL 0x00000020
  43. #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
  44. #define F2FS_MOUNT_INLINE_XATTR 0x00000080
  45. #define F2FS_MOUNT_INLINE_DATA 0x00000100
  46. #define F2FS_MOUNT_INLINE_DENTRY 0x00000200
  47. #define F2FS_MOUNT_FLUSH_MERGE 0x00000400
  48. #define F2FS_MOUNT_NOBARRIER 0x00000800
  49. #define F2FS_MOUNT_FASTBOOT 0x00001000
  50. #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
  51. #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
  52. #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
  53. #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
  54. #define ver_after(a, b) (typecheck(unsigned long long, a) && \
  55. typecheck(unsigned long long, b) && \
  56. ((long long)((a) - (b)) > 0))
  57. typedef u32 block_t; /*
  58. * should not change u32, since it is the on-disk block
  59. * address format, __le32.
  60. */
  61. typedef u32 nid_t;
  62. struct f2fs_mount_info {
  63. unsigned int opt;
  64. };
  65. #define CRCPOLY_LE 0xedb88320
  66. static inline __u32 f2fs_crc32(void *buf, size_t len)
  67. {
  68. unsigned char *p = (unsigned char *)buf;
  69. __u32 crc = F2FS_SUPER_MAGIC;
  70. int i;
  71. while (len--) {
  72. crc ^= *p++;
  73. for (i = 0; i < 8; i++)
  74. crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
  75. }
  76. return crc;
  77. }
  78. static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
  79. {
  80. return f2fs_crc32(buf, buf_size) == blk_crc;
  81. }
  82. /*
  83. * For checkpoint manager
  84. */
  85. enum {
  86. NAT_BITMAP,
  87. SIT_BITMAP
  88. };
  89. enum {
  90. CP_UMOUNT,
  91. CP_FASTBOOT,
  92. CP_SYNC,
  93. CP_RECOVERY,
  94. CP_DISCARD,
  95. };
  96. #define DEF_BATCHED_TRIM_SECTIONS 32
  97. #define BATCHED_TRIM_SEGMENTS(sbi) \
  98. (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
  99. struct cp_control {
  100. int reason;
  101. __u64 trim_start;
  102. __u64 trim_end;
  103. __u64 trim_minlen;
  104. __u64 trimmed;
  105. };
  106. /*
  107. * For CP/NAT/SIT/SSA readahead
  108. */
  109. enum {
  110. META_CP,
  111. META_NAT,
  112. META_SIT,
  113. META_SSA,
  114. META_POR,
  115. };
  116. /* for the list of ino */
  117. enum {
  118. ORPHAN_INO, /* for orphan ino list */
  119. APPEND_INO, /* for append ino list */
  120. UPDATE_INO, /* for update ino list */
  121. MAX_INO_ENTRY, /* max. list */
  122. };
  123. struct ino_entry {
  124. struct list_head list; /* list head */
  125. nid_t ino; /* inode number */
  126. };
  127. /*
  128. * for the list of directory inodes or gc inodes.
  129. * NOTE: there are two slab users for this structure, if we add/modify/delete
  130. * fields in structure for one of slab users, it may affect fields or size of
  131. * other one, in this condition, it's better to split both of slab and related
  132. * data structure.
  133. */
  134. struct inode_entry {
  135. struct list_head list; /* list head */
  136. struct inode *inode; /* vfs inode pointer */
  137. };
  138. /* for the list of blockaddresses to be discarded */
  139. struct discard_entry {
  140. struct list_head list; /* list head */
  141. block_t blkaddr; /* block address to be discarded */
  142. int len; /* # of consecutive blocks of the discard */
  143. };
  144. /* for the list of fsync inodes, used only during recovery */
  145. struct fsync_inode_entry {
  146. struct list_head list; /* list head */
  147. struct inode *inode; /* vfs inode pointer */
  148. block_t blkaddr; /* block address locating the last fsync */
  149. block_t last_dentry; /* block address locating the last dentry */
  150. block_t last_inode; /* block address locating the last inode */
  151. };
  152. #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
  153. #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
  154. #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
  155. #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
  156. #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
  157. #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
  158. #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum))
  159. #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum))
  160. static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
  161. {
  162. int before = nats_in_cursum(rs);
  163. rs->n_nats = cpu_to_le16(before + i);
  164. return before;
  165. }
  166. static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
  167. {
  168. int before = sits_in_cursum(rs);
  169. rs->n_sits = cpu_to_le16(before + i);
  170. return before;
  171. }
  172. static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,
  173. int type)
  174. {
  175. if (type == NAT_JOURNAL)
  176. return size <= MAX_NAT_JENTRIES(sum);
  177. return size <= MAX_SIT_JENTRIES(sum);
  178. }
  179. /*
  180. * ioctl commands
  181. */
  182. #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
  183. #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
  184. #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
  185. #define F2FS_IOCTL_MAGIC 0xf5
  186. #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
  187. #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
  188. #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
  189. #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
  190. #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
  191. /*
  192. * should be same as XFS_IOC_GOINGDOWN.
  193. * Flags for going down operation used by FS_IOC_GOINGDOWN
  194. */
  195. #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
  196. #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
  197. #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
  198. #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
  199. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  200. /*
  201. * ioctl commands in 32 bit emulation
  202. */
  203. #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  204. #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  205. #endif
  206. /*
  207. * For INODE and NODE manager
  208. */
  209. /* for directory operations */
  210. struct f2fs_dentry_ptr {
  211. const void *bitmap;
  212. struct f2fs_dir_entry *dentry;
  213. __u8 (*filename)[F2FS_SLOT_LEN];
  214. int max;
  215. };
  216. static inline void make_dentry_ptr(struct f2fs_dentry_ptr *d,
  217. void *src, int type)
  218. {
  219. if (type == 1) {
  220. struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
  221. d->max = NR_DENTRY_IN_BLOCK;
  222. d->bitmap = &t->dentry_bitmap;
  223. d->dentry = t->dentry;
  224. d->filename = t->filename;
  225. } else {
  226. struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
  227. d->max = NR_INLINE_DENTRY;
  228. d->bitmap = &t->dentry_bitmap;
  229. d->dentry = t->dentry;
  230. d->filename = t->filename;
  231. }
  232. }
  233. /*
  234. * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
  235. * as its node offset to distinguish from index node blocks.
  236. * But some bits are used to mark the node block.
  237. */
  238. #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
  239. >> OFFSET_BIT_SHIFT)
  240. enum {
  241. ALLOC_NODE, /* allocate a new node page if needed */
  242. LOOKUP_NODE, /* look up a node without readahead */
  243. LOOKUP_NODE_RA, /*
  244. * look up a node with readahead called
  245. * by get_data_block.
  246. */
  247. };
  248. #define F2FS_LINK_MAX 32000 /* maximum link count per file */
  249. #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
  250. /* vector size for gang look-up from extent cache that consists of radix tree */
  251. #define EXT_TREE_VEC_SIZE 64
  252. /* for in-memory extent cache entry */
  253. #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
  254. /* number of extent info in extent cache we try to shrink */
  255. #define EXTENT_CACHE_SHRINK_NUMBER 128
  256. struct extent_info {
  257. unsigned int fofs; /* start offset in a file */
  258. u32 blk; /* start block address of the extent */
  259. unsigned int len; /* length of the extent */
  260. };
  261. struct extent_node {
  262. struct rb_node rb_node; /* rb node located in rb-tree */
  263. struct list_head list; /* node in global extent list of sbi */
  264. struct extent_info ei; /* extent info */
  265. };
  266. struct extent_tree {
  267. nid_t ino; /* inode number */
  268. struct rb_root root; /* root of extent info rb-tree */
  269. struct extent_node *cached_en; /* recently accessed extent node */
  270. rwlock_t lock; /* protect extent info rb-tree */
  271. atomic_t refcount; /* reference count of rb-tree */
  272. unsigned int count; /* # of extent node in rb-tree*/
  273. };
  274. /*
  275. * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
  276. */
  277. #define FADVISE_COLD_BIT 0x01
  278. #define FADVISE_LOST_PINO_BIT 0x02
  279. #define DEF_DIR_LEVEL 0
  280. struct f2fs_inode_info {
  281. struct inode vfs_inode; /* serve a vfs inode */
  282. unsigned long i_flags; /* keep an inode flags for ioctl */
  283. unsigned char i_advise; /* use to give file attribute hints */
  284. unsigned char i_dir_level; /* use for dentry level for large dir */
  285. unsigned int i_current_depth; /* use only in directory structure */
  286. unsigned int i_pino; /* parent inode number */
  287. umode_t i_acl_mode; /* keep file acl mode temporarily */
  288. /* Use below internally in f2fs*/
  289. unsigned long flags; /* use to pass per-file flags */
  290. struct rw_semaphore i_sem; /* protect fi info */
  291. atomic_t dirty_pages; /* # of dirty pages */
  292. f2fs_hash_t chash; /* hash value of given file name */
  293. unsigned int clevel; /* maximum level of given file name */
  294. nid_t i_xattr_nid; /* node id that contains xattrs */
  295. unsigned long long xattr_ver; /* cp version of xattr modification */
  296. struct extent_info ext; /* in-memory extent cache entry */
  297. rwlock_t ext_lock; /* rwlock for single extent cache */
  298. struct inode_entry *dirty_dir; /* the pointer of dirty dir */
  299. struct radix_tree_root inmem_root; /* radix tree for inmem pages */
  300. struct list_head inmem_pages; /* inmemory pages managed by f2fs */
  301. struct mutex inmem_lock; /* lock for inmemory pages */
  302. };
  303. static inline void get_extent_info(struct extent_info *ext,
  304. struct f2fs_extent i_ext)
  305. {
  306. ext->fofs = le32_to_cpu(i_ext.fofs);
  307. ext->blk = le32_to_cpu(i_ext.blk);
  308. ext->len = le32_to_cpu(i_ext.len);
  309. }
  310. static inline void set_raw_extent(struct extent_info *ext,
  311. struct f2fs_extent *i_ext)
  312. {
  313. i_ext->fofs = cpu_to_le32(ext->fofs);
  314. i_ext->blk = cpu_to_le32(ext->blk);
  315. i_ext->len = cpu_to_le32(ext->len);
  316. }
  317. static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
  318. u32 blk, unsigned int len)
  319. {
  320. ei->fofs = fofs;
  321. ei->blk = blk;
  322. ei->len = len;
  323. }
  324. static inline bool __is_extent_same(struct extent_info *ei1,
  325. struct extent_info *ei2)
  326. {
  327. return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk &&
  328. ei1->len == ei2->len);
  329. }
  330. static inline bool __is_extent_mergeable(struct extent_info *back,
  331. struct extent_info *front)
  332. {
  333. return (back->fofs + back->len == front->fofs &&
  334. back->blk + back->len == front->blk);
  335. }
  336. static inline bool __is_back_mergeable(struct extent_info *cur,
  337. struct extent_info *back)
  338. {
  339. return __is_extent_mergeable(back, cur);
  340. }
  341. static inline bool __is_front_mergeable(struct extent_info *cur,
  342. struct extent_info *front)
  343. {
  344. return __is_extent_mergeable(cur, front);
  345. }
  346. struct f2fs_nm_info {
  347. block_t nat_blkaddr; /* base disk address of NAT */
  348. nid_t max_nid; /* maximum possible node ids */
  349. nid_t available_nids; /* maximum available node ids */
  350. nid_t next_scan_nid; /* the next nid to be scanned */
  351. unsigned int ram_thresh; /* control the memory footprint */
  352. /* NAT cache management */
  353. struct radix_tree_root nat_root;/* root of the nat entry cache */
  354. struct radix_tree_root nat_set_root;/* root of the nat set cache */
  355. struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
  356. struct list_head nat_entries; /* cached nat entry list (clean) */
  357. unsigned int nat_cnt; /* the # of cached nat entries */
  358. unsigned int dirty_nat_cnt; /* total num of nat entries in set */
  359. /* free node ids management */
  360. struct radix_tree_root free_nid_root;/* root of the free_nid cache */
  361. struct list_head free_nid_list; /* a list for free nids */
  362. spinlock_t free_nid_list_lock; /* protect free nid list */
  363. unsigned int fcnt; /* the number of free node id */
  364. struct mutex build_lock; /* lock for build free nids */
  365. /* for checkpoint */
  366. char *nat_bitmap; /* NAT bitmap pointer */
  367. int bitmap_size; /* bitmap size */
  368. };
  369. /*
  370. * this structure is used as one of function parameters.
  371. * all the information are dedicated to a given direct node block determined
  372. * by the data offset in a file.
  373. */
  374. struct dnode_of_data {
  375. struct inode *inode; /* vfs inode pointer */
  376. struct page *inode_page; /* its inode page, NULL is possible */
  377. struct page *node_page; /* cached direct node page */
  378. nid_t nid; /* node id of the direct node block */
  379. unsigned int ofs_in_node; /* data offset in the node page */
  380. bool inode_page_locked; /* inode page is locked or not */
  381. block_t data_blkaddr; /* block address of the node block */
  382. };
  383. static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  384. struct page *ipage, struct page *npage, nid_t nid)
  385. {
  386. memset(dn, 0, sizeof(*dn));
  387. dn->inode = inode;
  388. dn->inode_page = ipage;
  389. dn->node_page = npage;
  390. dn->nid = nid;
  391. }
  392. /*
  393. * For SIT manager
  394. *
  395. * By default, there are 6 active log areas across the whole main area.
  396. * When considering hot and cold data separation to reduce cleaning overhead,
  397. * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
  398. * respectively.
  399. * In the current design, you should not change the numbers intentionally.
  400. * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
  401. * logs individually according to the underlying devices. (default: 6)
  402. * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
  403. * data and 8 for node logs.
  404. */
  405. #define NR_CURSEG_DATA_TYPE (3)
  406. #define NR_CURSEG_NODE_TYPE (3)
  407. #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  408. enum {
  409. CURSEG_HOT_DATA = 0, /* directory entry blocks */
  410. CURSEG_WARM_DATA, /* data blocks */
  411. CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
  412. CURSEG_HOT_NODE, /* direct node blocks of directory files */
  413. CURSEG_WARM_NODE, /* direct node blocks of normal files */
  414. CURSEG_COLD_NODE, /* indirect node blocks */
  415. NO_CHECK_TYPE,
  416. CURSEG_DIRECT_IO, /* to use for the direct IO path */
  417. };
  418. struct flush_cmd {
  419. struct completion wait;
  420. struct llist_node llnode;
  421. int ret;
  422. };
  423. struct flush_cmd_control {
  424. struct task_struct *f2fs_issue_flush; /* flush thread */
  425. wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
  426. struct llist_head issue_list; /* list for command issue */
  427. struct llist_node *dispatch_list; /* list for command dispatch */
  428. };
  429. struct f2fs_sm_info {
  430. struct sit_info *sit_info; /* whole segment information */
  431. struct free_segmap_info *free_info; /* free segment information */
  432. struct dirty_seglist_info *dirty_info; /* dirty segment information */
  433. struct curseg_info *curseg_array; /* active segment information */
  434. block_t seg0_blkaddr; /* block address of 0'th segment */
  435. block_t main_blkaddr; /* start block address of main area */
  436. block_t ssa_blkaddr; /* start block address of SSA area */
  437. unsigned int segment_count; /* total # of segments */
  438. unsigned int main_segments; /* # of segments in main area */
  439. unsigned int reserved_segments; /* # of reserved segments */
  440. unsigned int ovp_segments; /* # of overprovision segments */
  441. /* a threshold to reclaim prefree segments */
  442. unsigned int rec_prefree_segments;
  443. /* for small discard management */
  444. struct list_head discard_list; /* 4KB discard list */
  445. int nr_discards; /* # of discards in the list */
  446. int max_discards; /* max. discards to be issued */
  447. /* for batched trimming */
  448. unsigned int trim_sections; /* # of sections to trim */
  449. struct list_head sit_entry_set; /* sit entry set list */
  450. unsigned int ipu_policy; /* in-place-update policy */
  451. unsigned int min_ipu_util; /* in-place-update threshold */
  452. unsigned int min_fsync_blocks; /* threshold for fsync */
  453. /* for flush command control */
  454. struct flush_cmd_control *cmd_control_info;
  455. };
  456. /*
  457. * For superblock
  458. */
  459. /*
  460. * COUNT_TYPE for monitoring
  461. *
  462. * f2fs monitors the number of several block types such as on-writeback,
  463. * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
  464. */
  465. enum count_type {
  466. F2FS_WRITEBACK,
  467. F2FS_DIRTY_DENTS,
  468. F2FS_DIRTY_NODES,
  469. F2FS_DIRTY_META,
  470. F2FS_INMEM_PAGES,
  471. NR_COUNT_TYPE,
  472. };
  473. /*
  474. * The below are the page types of bios used in submit_bio().
  475. * The available types are:
  476. * DATA User data pages. It operates as async mode.
  477. * NODE Node pages. It operates as async mode.
  478. * META FS metadata pages such as SIT, NAT, CP.
  479. * NR_PAGE_TYPE The number of page types.
  480. * META_FLUSH Make sure the previous pages are written
  481. * with waiting the bio's completion
  482. * ... Only can be used with META.
  483. */
  484. #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
  485. enum page_type {
  486. DATA,
  487. NODE,
  488. META,
  489. NR_PAGE_TYPE,
  490. META_FLUSH,
  491. INMEM, /* the below types are used by tracepoints only. */
  492. INMEM_DROP,
  493. IPU,
  494. OPU,
  495. };
  496. struct f2fs_io_info {
  497. enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
  498. int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
  499. block_t blk_addr; /* block address to be written */
  500. };
  501. #define is_read_io(rw) (((rw) & 1) == READ)
  502. struct f2fs_bio_info {
  503. struct f2fs_sb_info *sbi; /* f2fs superblock */
  504. struct bio *bio; /* bios to merge */
  505. sector_t last_block_in_bio; /* last block number */
  506. struct f2fs_io_info fio; /* store buffered io info. */
  507. struct rw_semaphore io_rwsem; /* blocking op for bio */
  508. };
  509. /* for inner inode cache management */
  510. struct inode_management {
  511. struct radix_tree_root ino_root; /* ino entry array */
  512. spinlock_t ino_lock; /* for ino entry lock */
  513. struct list_head ino_list; /* inode list head */
  514. unsigned long ino_num; /* number of entries */
  515. };
  516. /* For s_flag in struct f2fs_sb_info */
  517. enum {
  518. SBI_IS_DIRTY, /* dirty flag for checkpoint */
  519. SBI_IS_CLOSE, /* specify unmounting */
  520. SBI_NEED_FSCK, /* need fsck.f2fs to fix */
  521. SBI_POR_DOING, /* recovery is doing or not */
  522. };
  523. struct f2fs_sb_info {
  524. struct super_block *sb; /* pointer to VFS super block */
  525. struct proc_dir_entry *s_proc; /* proc entry */
  526. struct buffer_head *raw_super_buf; /* buffer head of raw sb */
  527. struct f2fs_super_block *raw_super; /* raw super block pointer */
  528. int s_flag; /* flags for sbi */
  529. /* for node-related operations */
  530. struct f2fs_nm_info *nm_info; /* node manager */
  531. struct inode *node_inode; /* cache node blocks */
  532. /* for segment-related operations */
  533. struct f2fs_sm_info *sm_info; /* segment manager */
  534. /* for bio operations */
  535. struct f2fs_bio_info read_io; /* for read bios */
  536. struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
  537. /* for checkpoint */
  538. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  539. struct inode *meta_inode; /* cache meta blocks */
  540. struct mutex cp_mutex; /* checkpoint procedure lock */
  541. struct rw_semaphore cp_rwsem; /* blocking FS operations */
  542. struct rw_semaphore node_write; /* locking node writes */
  543. struct mutex writepages; /* mutex for writepages() */
  544. wait_queue_head_t cp_wait;
  545. struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
  546. /* for orphan inode, use 0'th array */
  547. unsigned int max_orphans; /* max orphan inodes */
  548. /* for directory inode management */
  549. struct list_head dir_inode_list; /* dir inode list */
  550. spinlock_t dir_inode_lock; /* for dir inode list lock */
  551. /* for extent tree cache */
  552. struct radix_tree_root extent_tree_root;/* cache extent cache entries */
  553. struct rw_semaphore extent_tree_lock; /* locking extent radix tree */
  554. struct list_head extent_list; /* lru list for shrinker */
  555. spinlock_t extent_lock; /* locking extent lru list */
  556. int total_ext_tree; /* extent tree count */
  557. atomic_t total_ext_node; /* extent info count */
  558. /* basic filesystem units */
  559. unsigned int log_sectors_per_block; /* log2 sectors per block */
  560. unsigned int log_blocksize; /* log2 block size */
  561. unsigned int blocksize; /* block size */
  562. unsigned int root_ino_num; /* root inode number*/
  563. unsigned int node_ino_num; /* node inode number*/
  564. unsigned int meta_ino_num; /* meta inode number*/
  565. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  566. unsigned int blocks_per_seg; /* blocks per segment */
  567. unsigned int segs_per_sec; /* segments per section */
  568. unsigned int secs_per_zone; /* sections per zone */
  569. unsigned int total_sections; /* total section count */
  570. unsigned int total_node_count; /* total node block count */
  571. unsigned int total_valid_node_count; /* valid node block count */
  572. unsigned int total_valid_inode_count; /* valid inode count */
  573. int active_logs; /* # of active logs */
  574. int dir_level; /* directory level */
  575. block_t user_block_count; /* # of user blocks */
  576. block_t total_valid_block_count; /* # of valid blocks */
  577. block_t alloc_valid_block_count; /* # of allocated blocks */
  578. block_t last_valid_block_count; /* for recovery */
  579. u32 s_next_generation; /* for NFS support */
  580. atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
  581. struct f2fs_mount_info mount_opt; /* mount options */
  582. /* for cleaning operations */
  583. struct mutex gc_mutex; /* mutex for GC */
  584. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  585. unsigned int cur_victim_sec; /* current victim section num */
  586. /* maximum # of trials to find a victim segment for SSR and GC */
  587. unsigned int max_victim_search;
  588. /*
  589. * for stat information.
  590. * one is for the LFS mode, and the other is for the SSR mode.
  591. */
  592. #ifdef CONFIG_F2FS_STAT_FS
  593. struct f2fs_stat_info *stat_info; /* FS status information */
  594. unsigned int segment_count[2]; /* # of allocated segments */
  595. unsigned int block_count[2]; /* # of allocated blocks */
  596. atomic_t inplace_count; /* # of inplace update */
  597. int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
  598. atomic_t inline_inode; /* # of inline_data inodes */
  599. atomic_t inline_dir; /* # of inline_dentry inodes */
  600. int bg_gc; /* background gc calls */
  601. unsigned int n_dirty_dirs; /* # of dir inodes */
  602. #endif
  603. unsigned int last_victim[2]; /* last victim segment # */
  604. spinlock_t stat_lock; /* lock for stat operations */
  605. /* For sysfs suppport */
  606. struct kobject s_kobj;
  607. struct completion s_kobj_unregister;
  608. };
  609. /*
  610. * Inline functions
  611. */
  612. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  613. {
  614. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  615. }
  616. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  617. {
  618. return sb->s_fs_info;
  619. }
  620. static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
  621. {
  622. return F2FS_SB(inode->i_sb);
  623. }
  624. static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
  625. {
  626. return F2FS_I_SB(mapping->host);
  627. }
  628. static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
  629. {
  630. return F2FS_M_SB(page->mapping);
  631. }
  632. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  633. {
  634. return (struct f2fs_super_block *)(sbi->raw_super);
  635. }
  636. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  637. {
  638. return (struct f2fs_checkpoint *)(sbi->ckpt);
  639. }
  640. static inline struct f2fs_node *F2FS_NODE(struct page *page)
  641. {
  642. return (struct f2fs_node *)page_address(page);
  643. }
  644. static inline struct f2fs_inode *F2FS_INODE(struct page *page)
  645. {
  646. return &((struct f2fs_node *)page_address(page))->i;
  647. }
  648. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  649. {
  650. return (struct f2fs_nm_info *)(sbi->nm_info);
  651. }
  652. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  653. {
  654. return (struct f2fs_sm_info *)(sbi->sm_info);
  655. }
  656. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  657. {
  658. return (struct sit_info *)(SM_I(sbi)->sit_info);
  659. }
  660. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  661. {
  662. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  663. }
  664. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  665. {
  666. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  667. }
  668. static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
  669. {
  670. return sbi->meta_inode->i_mapping;
  671. }
  672. static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
  673. {
  674. return sbi->node_inode->i_mapping;
  675. }
  676. static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  677. {
  678. return sbi->s_flag & (0x01 << type);
  679. }
  680. static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  681. {
  682. sbi->s_flag |= (0x01 << type);
  683. }
  684. static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  685. {
  686. sbi->s_flag &= ~(0x01 << type);
  687. }
  688. static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
  689. {
  690. return le64_to_cpu(cp->checkpoint_ver);
  691. }
  692. static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  693. {
  694. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  695. return ckpt_flags & f;
  696. }
  697. static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  698. {
  699. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  700. ckpt_flags |= f;
  701. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  702. }
  703. static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  704. {
  705. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  706. ckpt_flags &= (~f);
  707. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  708. }
  709. static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
  710. {
  711. down_read(&sbi->cp_rwsem);
  712. }
  713. static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
  714. {
  715. up_read(&sbi->cp_rwsem);
  716. }
  717. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  718. {
  719. f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
  720. }
  721. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  722. {
  723. up_write(&sbi->cp_rwsem);
  724. }
  725. static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
  726. {
  727. int reason = CP_SYNC;
  728. if (test_opt(sbi, FASTBOOT))
  729. reason = CP_FASTBOOT;
  730. if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
  731. reason = CP_UMOUNT;
  732. return reason;
  733. }
  734. static inline bool __remain_node_summaries(int reason)
  735. {
  736. return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
  737. }
  738. static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
  739. {
  740. return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
  741. is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG));
  742. }
  743. /*
  744. * Check whether the given nid is within node id range.
  745. */
  746. static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
  747. {
  748. if (unlikely(nid < F2FS_ROOT_INO(sbi)))
  749. return -EINVAL;
  750. if (unlikely(nid >= NM_I(sbi)->max_nid))
  751. return -EINVAL;
  752. return 0;
  753. }
  754. #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
  755. /*
  756. * Check whether the inode has blocks or not
  757. */
  758. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  759. {
  760. if (F2FS_I(inode)->i_xattr_nid)
  761. return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
  762. else
  763. return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
  764. }
  765. static inline bool f2fs_has_xattr_block(unsigned int ofs)
  766. {
  767. return ofs == XATTR_NODE_OFFSET;
  768. }
  769. static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
  770. struct inode *inode, blkcnt_t count)
  771. {
  772. block_t valid_block_count;
  773. spin_lock(&sbi->stat_lock);
  774. valid_block_count =
  775. sbi->total_valid_block_count + (block_t)count;
  776. if (unlikely(valid_block_count > sbi->user_block_count)) {
  777. spin_unlock(&sbi->stat_lock);
  778. return false;
  779. }
  780. inode->i_blocks += count;
  781. sbi->total_valid_block_count = valid_block_count;
  782. sbi->alloc_valid_block_count += (block_t)count;
  783. spin_unlock(&sbi->stat_lock);
  784. return true;
  785. }
  786. static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
  787. struct inode *inode,
  788. blkcnt_t count)
  789. {
  790. spin_lock(&sbi->stat_lock);
  791. f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
  792. f2fs_bug_on(sbi, inode->i_blocks < count);
  793. inode->i_blocks -= count;
  794. sbi->total_valid_block_count -= (block_t)count;
  795. spin_unlock(&sbi->stat_lock);
  796. }
  797. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  798. {
  799. atomic_inc(&sbi->nr_pages[count_type]);
  800. set_sbi_flag(sbi, SBI_IS_DIRTY);
  801. }
  802. static inline void inode_inc_dirty_pages(struct inode *inode)
  803. {
  804. atomic_inc(&F2FS_I(inode)->dirty_pages);
  805. if (S_ISDIR(inode->i_mode))
  806. inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
  807. }
  808. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  809. {
  810. atomic_dec(&sbi->nr_pages[count_type]);
  811. }
  812. static inline void inode_dec_dirty_pages(struct inode *inode)
  813. {
  814. if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode))
  815. return;
  816. atomic_dec(&F2FS_I(inode)->dirty_pages);
  817. if (S_ISDIR(inode->i_mode))
  818. dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
  819. }
  820. static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
  821. {
  822. return atomic_read(&sbi->nr_pages[count_type]);
  823. }
  824. static inline int get_dirty_pages(struct inode *inode)
  825. {
  826. return atomic_read(&F2FS_I(inode)->dirty_pages);
  827. }
  828. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  829. {
  830. unsigned int pages_per_sec = sbi->segs_per_sec *
  831. (1 << sbi->log_blocks_per_seg);
  832. return ((get_pages(sbi, block_type) + pages_per_sec - 1)
  833. >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
  834. }
  835. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  836. {
  837. return sbi->total_valid_block_count;
  838. }
  839. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  840. {
  841. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  842. /* return NAT or SIT bitmap */
  843. if (flag == NAT_BITMAP)
  844. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  845. else if (flag == SIT_BITMAP)
  846. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  847. return 0;
  848. }
  849. static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
  850. {
  851. return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
  852. }
  853. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  854. {
  855. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  856. int offset;
  857. if (__cp_payload(sbi) > 0) {
  858. if (flag == NAT_BITMAP)
  859. return &ckpt->sit_nat_version_bitmap;
  860. else
  861. return (unsigned char *)ckpt + F2FS_BLKSIZE;
  862. } else {
  863. offset = (flag == NAT_BITMAP) ?
  864. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  865. return &ckpt->sit_nat_version_bitmap + offset;
  866. }
  867. }
  868. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  869. {
  870. block_t start_addr;
  871. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  872. unsigned long long ckpt_version = cur_cp_version(ckpt);
  873. start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  874. /*
  875. * odd numbered checkpoint should at cp segment 0
  876. * and even segment must be at cp segment 1
  877. */
  878. if (!(ckpt_version & 1))
  879. start_addr += sbi->blocks_per_seg;
  880. return start_addr;
  881. }
  882. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  883. {
  884. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  885. }
  886. static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
  887. struct inode *inode)
  888. {
  889. block_t valid_block_count;
  890. unsigned int valid_node_count;
  891. spin_lock(&sbi->stat_lock);
  892. valid_block_count = sbi->total_valid_block_count + 1;
  893. if (unlikely(valid_block_count > sbi->user_block_count)) {
  894. spin_unlock(&sbi->stat_lock);
  895. return false;
  896. }
  897. valid_node_count = sbi->total_valid_node_count + 1;
  898. if (unlikely(valid_node_count > sbi->total_node_count)) {
  899. spin_unlock(&sbi->stat_lock);
  900. return false;
  901. }
  902. if (inode)
  903. inode->i_blocks++;
  904. sbi->alloc_valid_block_count++;
  905. sbi->total_valid_node_count++;
  906. sbi->total_valid_block_count++;
  907. spin_unlock(&sbi->stat_lock);
  908. return true;
  909. }
  910. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  911. struct inode *inode)
  912. {
  913. spin_lock(&sbi->stat_lock);
  914. f2fs_bug_on(sbi, !sbi->total_valid_block_count);
  915. f2fs_bug_on(sbi, !sbi->total_valid_node_count);
  916. f2fs_bug_on(sbi, !inode->i_blocks);
  917. inode->i_blocks--;
  918. sbi->total_valid_node_count--;
  919. sbi->total_valid_block_count--;
  920. spin_unlock(&sbi->stat_lock);
  921. }
  922. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  923. {
  924. return sbi->total_valid_node_count;
  925. }
  926. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  927. {
  928. spin_lock(&sbi->stat_lock);
  929. f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
  930. sbi->total_valid_inode_count++;
  931. spin_unlock(&sbi->stat_lock);
  932. }
  933. static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
  934. {
  935. spin_lock(&sbi->stat_lock);
  936. f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
  937. sbi->total_valid_inode_count--;
  938. spin_unlock(&sbi->stat_lock);
  939. }
  940. static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
  941. {
  942. return sbi->total_valid_inode_count;
  943. }
  944. static inline void f2fs_put_page(struct page *page, int unlock)
  945. {
  946. if (!page)
  947. return;
  948. if (unlock) {
  949. f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
  950. unlock_page(page);
  951. }
  952. page_cache_release(page);
  953. }
  954. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  955. {
  956. if (dn->node_page)
  957. f2fs_put_page(dn->node_page, 1);
  958. if (dn->inode_page && dn->node_page != dn->inode_page)
  959. f2fs_put_page(dn->inode_page, 0);
  960. dn->node_page = NULL;
  961. dn->inode_page = NULL;
  962. }
  963. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  964. size_t size)
  965. {
  966. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
  967. }
  968. static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
  969. gfp_t flags)
  970. {
  971. void *entry;
  972. retry:
  973. entry = kmem_cache_alloc(cachep, flags);
  974. if (!entry) {
  975. cond_resched();
  976. goto retry;
  977. }
  978. return entry;
  979. }
  980. static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
  981. unsigned long index, void *item)
  982. {
  983. while (radix_tree_insert(root, index, item))
  984. cond_resched();
  985. }
  986. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  987. static inline bool IS_INODE(struct page *page)
  988. {
  989. struct f2fs_node *p = F2FS_NODE(page);
  990. return RAW_IS_INODE(p);
  991. }
  992. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  993. {
  994. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  995. }
  996. static inline block_t datablock_addr(struct page *node_page,
  997. unsigned int offset)
  998. {
  999. struct f2fs_node *raw_node;
  1000. __le32 *addr_array;
  1001. raw_node = F2FS_NODE(node_page);
  1002. addr_array = blkaddr_in_node(raw_node);
  1003. return le32_to_cpu(addr_array[offset]);
  1004. }
  1005. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  1006. {
  1007. int mask;
  1008. addr += (nr >> 3);
  1009. mask = 1 << (7 - (nr & 0x07));
  1010. return mask & *addr;
  1011. }
  1012. static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
  1013. {
  1014. int mask;
  1015. int ret;
  1016. addr += (nr >> 3);
  1017. mask = 1 << (7 - (nr & 0x07));
  1018. ret = mask & *addr;
  1019. *addr |= mask;
  1020. return ret;
  1021. }
  1022. static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
  1023. {
  1024. int mask;
  1025. int ret;
  1026. addr += (nr >> 3);
  1027. mask = 1 << (7 - (nr & 0x07));
  1028. ret = mask & *addr;
  1029. *addr &= ~mask;
  1030. return ret;
  1031. }
  1032. static inline void f2fs_change_bit(unsigned int nr, char *addr)
  1033. {
  1034. int mask;
  1035. addr += (nr >> 3);
  1036. mask = 1 << (7 - (nr & 0x07));
  1037. *addr ^= mask;
  1038. }
  1039. /* used for f2fs_inode_info->flags */
  1040. enum {
  1041. FI_NEW_INODE, /* indicate newly allocated inode */
  1042. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  1043. FI_DIRTY_DIR, /* indicate directory has dirty pages */
  1044. FI_INC_LINK, /* need to increment i_nlink */
  1045. FI_ACL_MODE, /* indicate acl mode */
  1046. FI_NO_ALLOC, /* should not allocate any blocks */
  1047. FI_UPDATE_DIR, /* should update inode block for consistency */
  1048. FI_DELAY_IPUT, /* used for the recovery */
  1049. FI_NO_EXTENT, /* not to use the extent cache */
  1050. FI_INLINE_XATTR, /* used for inline xattr */
  1051. FI_INLINE_DATA, /* used for inline data*/
  1052. FI_INLINE_DENTRY, /* used for inline dentry */
  1053. FI_APPEND_WRITE, /* inode has appended data */
  1054. FI_UPDATE_WRITE, /* inode has in-place-update data */
  1055. FI_NEED_IPU, /* used for ipu per file */
  1056. FI_ATOMIC_FILE, /* indicate atomic file */
  1057. FI_VOLATILE_FILE, /* indicate volatile file */
  1058. FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
  1059. FI_DROP_CACHE, /* drop dirty page cache */
  1060. FI_DATA_EXIST, /* indicate data exists */
  1061. FI_INLINE_DOTS, /* indicate inline dot dentries */
  1062. };
  1063. static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
  1064. {
  1065. if (!test_bit(flag, &fi->flags))
  1066. set_bit(flag, &fi->flags);
  1067. }
  1068. static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
  1069. {
  1070. return test_bit(flag, &fi->flags);
  1071. }
  1072. static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  1073. {
  1074. if (test_bit(flag, &fi->flags))
  1075. clear_bit(flag, &fi->flags);
  1076. }
  1077. static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
  1078. {
  1079. fi->i_acl_mode = mode;
  1080. set_inode_flag(fi, FI_ACL_MODE);
  1081. }
  1082. static inline void get_inline_info(struct f2fs_inode_info *fi,
  1083. struct f2fs_inode *ri)
  1084. {
  1085. if (ri->i_inline & F2FS_INLINE_XATTR)
  1086. set_inode_flag(fi, FI_INLINE_XATTR);
  1087. if (ri->i_inline & F2FS_INLINE_DATA)
  1088. set_inode_flag(fi, FI_INLINE_DATA);
  1089. if (ri->i_inline & F2FS_INLINE_DENTRY)
  1090. set_inode_flag(fi, FI_INLINE_DENTRY);
  1091. if (ri->i_inline & F2FS_DATA_EXIST)
  1092. set_inode_flag(fi, FI_DATA_EXIST);
  1093. if (ri->i_inline & F2FS_INLINE_DOTS)
  1094. set_inode_flag(fi, FI_INLINE_DOTS);
  1095. }
  1096. static inline void set_raw_inline(struct f2fs_inode_info *fi,
  1097. struct f2fs_inode *ri)
  1098. {
  1099. ri->i_inline = 0;
  1100. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  1101. ri->i_inline |= F2FS_INLINE_XATTR;
  1102. if (is_inode_flag_set(fi, FI_INLINE_DATA))
  1103. ri->i_inline |= F2FS_INLINE_DATA;
  1104. if (is_inode_flag_set(fi, FI_INLINE_DENTRY))
  1105. ri->i_inline |= F2FS_INLINE_DENTRY;
  1106. if (is_inode_flag_set(fi, FI_DATA_EXIST))
  1107. ri->i_inline |= F2FS_DATA_EXIST;
  1108. if (is_inode_flag_set(fi, FI_INLINE_DOTS))
  1109. ri->i_inline |= F2FS_INLINE_DOTS;
  1110. }
  1111. static inline int f2fs_has_inline_xattr(struct inode *inode)
  1112. {
  1113. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
  1114. }
  1115. static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
  1116. {
  1117. if (f2fs_has_inline_xattr(&fi->vfs_inode))
  1118. return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
  1119. return DEF_ADDRS_PER_INODE;
  1120. }
  1121. static inline void *inline_xattr_addr(struct page *page)
  1122. {
  1123. struct f2fs_inode *ri = F2FS_INODE(page);
  1124. return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
  1125. F2FS_INLINE_XATTR_ADDRS]);
  1126. }
  1127. static inline int inline_xattr_size(struct inode *inode)
  1128. {
  1129. if (f2fs_has_inline_xattr(inode))
  1130. return F2FS_INLINE_XATTR_ADDRS << 2;
  1131. else
  1132. return 0;
  1133. }
  1134. static inline int f2fs_has_inline_data(struct inode *inode)
  1135. {
  1136. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
  1137. }
  1138. static inline void f2fs_clear_inline_inode(struct inode *inode)
  1139. {
  1140. clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
  1141. clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
  1142. }
  1143. static inline int f2fs_exist_data(struct inode *inode)
  1144. {
  1145. return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST);
  1146. }
  1147. static inline int f2fs_has_inline_dots(struct inode *inode)
  1148. {
  1149. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS);
  1150. }
  1151. static inline bool f2fs_is_atomic_file(struct inode *inode)
  1152. {
  1153. return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE);
  1154. }
  1155. static inline bool f2fs_is_volatile_file(struct inode *inode)
  1156. {
  1157. return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE);
  1158. }
  1159. static inline bool f2fs_is_first_block_written(struct inode *inode)
  1160. {
  1161. return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
  1162. }
  1163. static inline bool f2fs_is_drop_cache(struct inode *inode)
  1164. {
  1165. return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE);
  1166. }
  1167. static inline void *inline_data_addr(struct page *page)
  1168. {
  1169. struct f2fs_inode *ri = F2FS_INODE(page);
  1170. return (void *)&(ri->i_addr[1]);
  1171. }
  1172. static inline int f2fs_has_inline_dentry(struct inode *inode)
  1173. {
  1174. return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY);
  1175. }
  1176. static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
  1177. {
  1178. if (!f2fs_has_inline_dentry(dir))
  1179. kunmap(page);
  1180. }
  1181. static inline int f2fs_readonly(struct super_block *sb)
  1182. {
  1183. return sb->s_flags & MS_RDONLY;
  1184. }
  1185. static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
  1186. {
  1187. return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
  1188. }
  1189. static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
  1190. {
  1191. set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
  1192. sbi->sb->s_flags |= MS_RDONLY;
  1193. }
  1194. #define get_inode_mode(i) \
  1195. ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
  1196. (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
  1197. /* get offset of first page in next direct node */
  1198. #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \
  1199. ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \
  1200. (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \
  1201. ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi))
  1202. /*
  1203. * file.c
  1204. */
  1205. int f2fs_sync_file(struct file *, loff_t, loff_t, int);
  1206. void truncate_data_blocks(struct dnode_of_data *);
  1207. int truncate_blocks(struct inode *, u64, bool);
  1208. void f2fs_truncate(struct inode *);
  1209. int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  1210. int f2fs_setattr(struct dentry *, struct iattr *);
  1211. int truncate_hole(struct inode *, pgoff_t, pgoff_t);
  1212. int truncate_data_blocks_range(struct dnode_of_data *, int);
  1213. long f2fs_ioctl(struct file *, unsigned int, unsigned long);
  1214. long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
  1215. /*
  1216. * inode.c
  1217. */
  1218. void f2fs_set_inode_flags(struct inode *);
  1219. struct inode *f2fs_iget(struct super_block *, unsigned long);
  1220. int try_to_free_nats(struct f2fs_sb_info *, int);
  1221. void update_inode(struct inode *, struct page *);
  1222. void update_inode_page(struct inode *);
  1223. int f2fs_write_inode(struct inode *, struct writeback_control *);
  1224. void f2fs_evict_inode(struct inode *);
  1225. void handle_failed_inode(struct inode *);
  1226. /*
  1227. * namei.c
  1228. */
  1229. struct dentry *f2fs_get_parent(struct dentry *child);
  1230. /*
  1231. * dir.c
  1232. */
  1233. extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
  1234. void set_de_type(struct f2fs_dir_entry *, umode_t);
  1235. struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *,
  1236. struct f2fs_dentry_ptr *);
  1237. bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
  1238. unsigned int);
  1239. void do_make_empty_dir(struct inode *, struct inode *,
  1240. struct f2fs_dentry_ptr *);
  1241. struct page *init_inode_metadata(struct inode *, struct inode *,
  1242. const struct qstr *, struct page *);
  1243. void update_parent_metadata(struct inode *, struct inode *, unsigned int);
  1244. int room_for_filename(const void *, int, int);
  1245. void f2fs_drop_nlink(struct inode *, struct inode *, struct page *);
  1246. struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
  1247. struct page **);
  1248. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
  1249. ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
  1250. void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
  1251. struct page *, struct inode *);
  1252. int update_dent_inode(struct inode *, const struct qstr *);
  1253. void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *,
  1254. const struct qstr *, f2fs_hash_t , unsigned int);
  1255. int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t,
  1256. umode_t);
  1257. void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
  1258. struct inode *);
  1259. int f2fs_do_tmpfile(struct inode *, struct inode *);
  1260. int f2fs_make_empty(struct inode *, struct inode *);
  1261. bool f2fs_empty_dir(struct inode *);
  1262. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  1263. {
  1264. return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
  1265. inode, inode->i_ino, inode->i_mode);
  1266. }
  1267. /*
  1268. * super.c
  1269. */
  1270. int f2fs_sync_fs(struct super_block *, int);
  1271. extern __printf(3, 4)
  1272. void f2fs_msg(struct super_block *, const char *, const char *, ...);
  1273. /*
  1274. * hash.c
  1275. */
  1276. f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
  1277. /*
  1278. * node.c
  1279. */
  1280. struct dnode_of_data;
  1281. struct node_info;
  1282. bool available_free_memory(struct f2fs_sb_info *, int);
  1283. bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
  1284. bool has_fsynced_inode(struct f2fs_sb_info *, nid_t);
  1285. bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
  1286. void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
  1287. int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
  1288. int truncate_inode_blocks(struct inode *, pgoff_t);
  1289. int truncate_xattr_node(struct inode *, struct page *);
  1290. int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
  1291. void remove_inode_page(struct inode *);
  1292. struct page *new_inode_page(struct inode *);
  1293. struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
  1294. void ra_node_page(struct f2fs_sb_info *, nid_t);
  1295. struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
  1296. struct page *get_node_page_ra(struct page *, int);
  1297. void sync_inode_page(struct dnode_of_data *);
  1298. int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
  1299. bool alloc_nid(struct f2fs_sb_info *, nid_t *);
  1300. void alloc_nid_done(struct f2fs_sb_info *, nid_t);
  1301. void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
  1302. void recover_inline_xattr(struct inode *, struct page *);
  1303. void recover_xattr_data(struct inode *, struct page *, block_t);
  1304. int recover_inode_page(struct f2fs_sb_info *, struct page *);
  1305. int restore_node_summary(struct f2fs_sb_info *, unsigned int,
  1306. struct f2fs_summary_block *);
  1307. void flush_nat_entries(struct f2fs_sb_info *);
  1308. int build_node_manager(struct f2fs_sb_info *);
  1309. void destroy_node_manager(struct f2fs_sb_info *);
  1310. int __init create_node_manager_caches(void);
  1311. void destroy_node_manager_caches(void);
  1312. /*
  1313. * segment.c
  1314. */
  1315. void register_inmem_page(struct inode *, struct page *);
  1316. void commit_inmem_pages(struct inode *, bool);
  1317. void f2fs_balance_fs(struct f2fs_sb_info *);
  1318. void f2fs_balance_fs_bg(struct f2fs_sb_info *);
  1319. int f2fs_issue_flush(struct f2fs_sb_info *);
  1320. int create_flush_cmd_control(struct f2fs_sb_info *);
  1321. void destroy_flush_cmd_control(struct f2fs_sb_info *);
  1322. void invalidate_blocks(struct f2fs_sb_info *, block_t);
  1323. void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
  1324. void clear_prefree_segments(struct f2fs_sb_info *);
  1325. void release_discard_addrs(struct f2fs_sb_info *);
  1326. void discard_next_dnode(struct f2fs_sb_info *, block_t);
  1327. int npages_for_summary_flush(struct f2fs_sb_info *, bool);
  1328. void allocate_new_segments(struct f2fs_sb_info *);
  1329. int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
  1330. struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
  1331. void write_meta_page(struct f2fs_sb_info *, struct page *);
  1332. void write_node_page(struct f2fs_sb_info *, struct page *,
  1333. unsigned int, struct f2fs_io_info *);
  1334. void write_data_page(struct page *, struct dnode_of_data *,
  1335. struct f2fs_io_info *);
  1336. void rewrite_data_page(struct page *, struct f2fs_io_info *);
  1337. void recover_data_page(struct f2fs_sb_info *, struct page *,
  1338. struct f2fs_summary *, block_t, block_t);
  1339. void allocate_data_block(struct f2fs_sb_info *, struct page *,
  1340. block_t, block_t *, struct f2fs_summary *, int);
  1341. void f2fs_wait_on_page_writeback(struct page *, enum page_type);
  1342. void write_data_summaries(struct f2fs_sb_info *, block_t);
  1343. void write_node_summaries(struct f2fs_sb_info *, block_t);
  1344. int lookup_journal_in_cursum(struct f2fs_summary_block *,
  1345. int, unsigned int, int);
  1346. void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
  1347. int build_segment_manager(struct f2fs_sb_info *);
  1348. void destroy_segment_manager(struct f2fs_sb_info *);
  1349. int __init create_segment_manager_caches(void);
  1350. void destroy_segment_manager_caches(void);
  1351. /*
  1352. * checkpoint.c
  1353. */
  1354. struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
  1355. struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
  1356. int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
  1357. void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
  1358. long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
  1359. void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
  1360. void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
  1361. void release_dirty_inode(struct f2fs_sb_info *);
  1362. bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
  1363. int acquire_orphan_inode(struct f2fs_sb_info *);
  1364. void release_orphan_inode(struct f2fs_sb_info *);
  1365. void add_orphan_inode(struct f2fs_sb_info *, nid_t);
  1366. void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
  1367. void recover_orphan_inodes(struct f2fs_sb_info *);
  1368. int get_valid_checkpoint(struct f2fs_sb_info *);
  1369. void update_dirty_page(struct inode *, struct page *);
  1370. void add_dirty_dir_inode(struct inode *);
  1371. void remove_dirty_dir_inode(struct inode *);
  1372. void sync_dirty_dir_inodes(struct f2fs_sb_info *);
  1373. void write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
  1374. void init_ino_entry_info(struct f2fs_sb_info *);
  1375. int __init create_checkpoint_caches(void);
  1376. void destroy_checkpoint_caches(void);
  1377. /*
  1378. * data.c
  1379. */
  1380. void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
  1381. int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *,
  1382. struct f2fs_io_info *);
  1383. void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *,
  1384. struct f2fs_io_info *);
  1385. void set_data_blkaddr(struct dnode_of_data *);
  1386. int reserve_new_block(struct dnode_of_data *);
  1387. int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
  1388. void f2fs_shrink_extent_tree(struct f2fs_sb_info *, int);
  1389. void f2fs_destroy_extent_tree(struct inode *);
  1390. void f2fs_init_extent_cache(struct inode *, struct f2fs_extent *);
  1391. void f2fs_update_extent_cache(struct dnode_of_data *);
  1392. void f2fs_preserve_extent_tree(struct inode *);
  1393. struct page *find_data_page(struct inode *, pgoff_t, bool);
  1394. struct page *get_lock_data_page(struct inode *, pgoff_t);
  1395. struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
  1396. int do_write_data_page(struct page *, struct f2fs_io_info *);
  1397. int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
  1398. void init_extent_cache_info(struct f2fs_sb_info *);
  1399. int __init create_extent_cache(void);
  1400. void destroy_extent_cache(void);
  1401. void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
  1402. int f2fs_release_page(struct page *, gfp_t);
  1403. /*
  1404. * gc.c
  1405. */
  1406. int start_gc_thread(struct f2fs_sb_info *);
  1407. void stop_gc_thread(struct f2fs_sb_info *);
  1408. block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
  1409. int f2fs_gc(struct f2fs_sb_info *);
  1410. void build_gc_manager(struct f2fs_sb_info *);
  1411. /*
  1412. * recovery.c
  1413. */
  1414. int recover_fsync_data(struct f2fs_sb_info *);
  1415. bool space_for_roll_forward(struct f2fs_sb_info *);
  1416. /*
  1417. * debug.c
  1418. */
  1419. #ifdef CONFIG_F2FS_STAT_FS
  1420. struct f2fs_stat_info {
  1421. struct list_head stat_list;
  1422. struct f2fs_sb_info *sbi;
  1423. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  1424. int main_area_segs, main_area_sections, main_area_zones;
  1425. int hit_ext, total_ext, ext_tree, ext_node;
  1426. int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
  1427. int nats, dirty_nats, sits, dirty_sits, fnids;
  1428. int total_count, utilization;
  1429. int bg_gc, inline_inode, inline_dir, inmem_pages, wb_pages;
  1430. unsigned int valid_count, valid_node_count, valid_inode_count;
  1431. unsigned int bimodal, avg_vblocks;
  1432. int util_free, util_valid, util_invalid;
  1433. int rsvd_segs, overp_segs;
  1434. int dirty_count, node_pages, meta_pages;
  1435. int prefree_count, call_count, cp_count;
  1436. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  1437. int bg_node_segs, bg_data_segs;
  1438. int tot_blks, data_blks, node_blks;
  1439. int bg_data_blks, bg_node_blks;
  1440. int curseg[NR_CURSEG_TYPE];
  1441. int cursec[NR_CURSEG_TYPE];
  1442. int curzone[NR_CURSEG_TYPE];
  1443. unsigned int segment_count[2];
  1444. unsigned int block_count[2];
  1445. unsigned int inplace_count;
  1446. unsigned base_mem, cache_mem, page_mem;
  1447. };
  1448. static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
  1449. {
  1450. return (struct f2fs_stat_info *)sbi->stat_info;
  1451. }
  1452. #define stat_inc_cp_count(si) ((si)->cp_count++)
  1453. #define stat_inc_call_count(si) ((si)->call_count++)
  1454. #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
  1455. #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++)
  1456. #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--)
  1457. #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++)
  1458. #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++)
  1459. #define stat_inc_inline_inode(inode) \
  1460. do { \
  1461. if (f2fs_has_inline_data(inode)) \
  1462. (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
  1463. } while (0)
  1464. #define stat_dec_inline_inode(inode) \
  1465. do { \
  1466. if (f2fs_has_inline_data(inode)) \
  1467. (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
  1468. } while (0)
  1469. #define stat_inc_inline_dir(inode) \
  1470. do { \
  1471. if (f2fs_has_inline_dentry(inode)) \
  1472. (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
  1473. } while (0)
  1474. #define stat_dec_inline_dir(inode) \
  1475. do { \
  1476. if (f2fs_has_inline_dentry(inode)) \
  1477. (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
  1478. } while (0)
  1479. #define stat_inc_seg_type(sbi, curseg) \
  1480. ((sbi)->segment_count[(curseg)->alloc_type]++)
  1481. #define stat_inc_block_count(sbi, curseg) \
  1482. ((sbi)->block_count[(curseg)->alloc_type]++)
  1483. #define stat_inc_inplace_blocks(sbi) \
  1484. (atomic_inc(&(sbi)->inplace_count))
  1485. #define stat_inc_seg_count(sbi, type, gc_type) \
  1486. do { \
  1487. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1488. (si)->tot_segs++; \
  1489. if (type == SUM_TYPE_DATA) { \
  1490. si->data_segs++; \
  1491. si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
  1492. } else { \
  1493. si->node_segs++; \
  1494. si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
  1495. } \
  1496. } while (0)
  1497. #define stat_inc_tot_blk_count(si, blks) \
  1498. (si->tot_blks += (blks))
  1499. #define stat_inc_data_blk_count(sbi, blks, gc_type) \
  1500. do { \
  1501. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1502. stat_inc_tot_blk_count(si, blks); \
  1503. si->data_blks += (blks); \
  1504. si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \
  1505. } while (0)
  1506. #define stat_inc_node_blk_count(sbi, blks, gc_type) \
  1507. do { \
  1508. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1509. stat_inc_tot_blk_count(si, blks); \
  1510. si->node_blks += (blks); \
  1511. si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \
  1512. } while (0)
  1513. int f2fs_build_stats(struct f2fs_sb_info *);
  1514. void f2fs_destroy_stats(struct f2fs_sb_info *);
  1515. void __init f2fs_create_root_stats(void);
  1516. void f2fs_destroy_root_stats(void);
  1517. #else
  1518. #define stat_inc_cp_count(si)
  1519. #define stat_inc_call_count(si)
  1520. #define stat_inc_bggc_count(si)
  1521. #define stat_inc_dirty_dir(sbi)
  1522. #define stat_dec_dirty_dir(sbi)
  1523. #define stat_inc_total_hit(sb)
  1524. #define stat_inc_read_hit(sb)
  1525. #define stat_inc_inline_inode(inode)
  1526. #define stat_dec_inline_inode(inode)
  1527. #define stat_inc_inline_dir(inode)
  1528. #define stat_dec_inline_dir(inode)
  1529. #define stat_inc_seg_type(sbi, curseg)
  1530. #define stat_inc_block_count(sbi, curseg)
  1531. #define stat_inc_inplace_blocks(sbi)
  1532. #define stat_inc_seg_count(sbi, type, gc_type)
  1533. #define stat_inc_tot_blk_count(si, blks)
  1534. #define stat_inc_data_blk_count(sbi, blks, gc_type)
  1535. #define stat_inc_node_blk_count(sbi, blks, gc_type)
  1536. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  1537. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  1538. static inline void __init f2fs_create_root_stats(void) { }
  1539. static inline void f2fs_destroy_root_stats(void) { }
  1540. #endif
  1541. extern const struct file_operations f2fs_dir_operations;
  1542. extern const struct file_operations f2fs_file_operations;
  1543. extern const struct inode_operations f2fs_file_inode_operations;
  1544. extern const struct address_space_operations f2fs_dblock_aops;
  1545. extern const struct address_space_operations f2fs_node_aops;
  1546. extern const struct address_space_operations f2fs_meta_aops;
  1547. extern const struct inode_operations f2fs_dir_inode_operations;
  1548. extern const struct inode_operations f2fs_symlink_inode_operations;
  1549. extern const struct inode_operations f2fs_special_inode_operations;
  1550. extern struct kmem_cache *inode_entry_slab;
  1551. /*
  1552. * inline.c
  1553. */
  1554. bool f2fs_may_inline(struct inode *);
  1555. void read_inline_data(struct page *, struct page *);
  1556. bool truncate_inline_inode(struct page *, u64);
  1557. int f2fs_read_inline_data(struct inode *, struct page *);
  1558. int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
  1559. int f2fs_convert_inline_inode(struct inode *);
  1560. int f2fs_write_inline_data(struct inode *, struct page *);
  1561. bool recover_inline_data(struct inode *, struct page *);
  1562. struct f2fs_dir_entry *find_in_inline_dir(struct inode *, struct qstr *,
  1563. struct page **);
  1564. struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
  1565. int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
  1566. int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *,
  1567. nid_t, umode_t);
  1568. void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
  1569. struct inode *, struct inode *);
  1570. bool f2fs_empty_inline_dir(struct inode *);
  1571. int f2fs_read_inline_dir(struct file *, struct dir_context *);
  1572. #endif