f2fs.h 57 KB

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