f2fs.h 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636
  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. #include <linux/vmalloc.h>
  22. #include <linux/bio.h>
  23. #include <linux/blkdev.h>
  24. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  25. #include <linux/fscrypt_supp.h>
  26. #else
  27. #include <linux/fscrypt_notsupp.h>
  28. #endif
  29. #include <crypto/hash.h>
  30. #ifdef CONFIG_F2FS_CHECK_FS
  31. #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
  32. #else
  33. #define f2fs_bug_on(sbi, condition) \
  34. do { \
  35. if (unlikely(condition)) { \
  36. WARN_ON(1); \
  37. set_sbi_flag(sbi, SBI_NEED_FSCK); \
  38. } \
  39. } while (0)
  40. #endif
  41. #ifdef CONFIG_F2FS_FAULT_INJECTION
  42. enum {
  43. FAULT_KMALLOC,
  44. FAULT_PAGE_ALLOC,
  45. FAULT_ALLOC_NID,
  46. FAULT_ORPHAN,
  47. FAULT_BLOCK,
  48. FAULT_DIR_DEPTH,
  49. FAULT_EVICT_INODE,
  50. FAULT_IO,
  51. FAULT_CHECKPOINT,
  52. FAULT_MAX,
  53. };
  54. struct f2fs_fault_info {
  55. atomic_t inject_ops;
  56. unsigned int inject_rate;
  57. unsigned int inject_type;
  58. };
  59. extern char *fault_name[FAULT_MAX];
  60. #define IS_FAULT_SET(fi, type) (fi->inject_type & (1 << (type)))
  61. #endif
  62. /*
  63. * For mount options
  64. */
  65. #define F2FS_MOUNT_BG_GC 0x00000001
  66. #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
  67. #define F2FS_MOUNT_DISCARD 0x00000004
  68. #define F2FS_MOUNT_NOHEAP 0x00000008
  69. #define F2FS_MOUNT_XATTR_USER 0x00000010
  70. #define F2FS_MOUNT_POSIX_ACL 0x00000020
  71. #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
  72. #define F2FS_MOUNT_INLINE_XATTR 0x00000080
  73. #define F2FS_MOUNT_INLINE_DATA 0x00000100
  74. #define F2FS_MOUNT_INLINE_DENTRY 0x00000200
  75. #define F2FS_MOUNT_FLUSH_MERGE 0x00000400
  76. #define F2FS_MOUNT_NOBARRIER 0x00000800
  77. #define F2FS_MOUNT_FASTBOOT 0x00001000
  78. #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
  79. #define F2FS_MOUNT_FORCE_FG_GC 0x00004000
  80. #define F2FS_MOUNT_DATA_FLUSH 0x00008000
  81. #define F2FS_MOUNT_FAULT_INJECTION 0x00010000
  82. #define F2FS_MOUNT_ADAPTIVE 0x00020000
  83. #define F2FS_MOUNT_LFS 0x00040000
  84. #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
  85. #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
  86. #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
  87. #define ver_after(a, b) (typecheck(unsigned long long, a) && \
  88. typecheck(unsigned long long, b) && \
  89. ((long long)((a) - (b)) > 0))
  90. typedef u32 block_t; /*
  91. * should not change u32, since it is the on-disk block
  92. * address format, __le32.
  93. */
  94. typedef u32 nid_t;
  95. struct f2fs_mount_info {
  96. unsigned int opt;
  97. };
  98. #define F2FS_FEATURE_ENCRYPT 0x0001
  99. #define F2FS_FEATURE_BLKZONED 0x0002
  100. #define F2FS_HAS_FEATURE(sb, mask) \
  101. ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
  102. #define F2FS_SET_FEATURE(sb, mask) \
  103. (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask))
  104. #define F2FS_CLEAR_FEATURE(sb, mask) \
  105. (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask))
  106. /*
  107. * For checkpoint manager
  108. */
  109. enum {
  110. NAT_BITMAP,
  111. SIT_BITMAP
  112. };
  113. enum {
  114. CP_UMOUNT,
  115. CP_FASTBOOT,
  116. CP_SYNC,
  117. CP_RECOVERY,
  118. CP_DISCARD,
  119. };
  120. #define DEF_BATCHED_TRIM_SECTIONS 2048
  121. #define BATCHED_TRIM_SEGMENTS(sbi) \
  122. (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
  123. #define BATCHED_TRIM_BLOCKS(sbi) \
  124. (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
  125. #define MAX_DISCARD_BLOCKS(sbi) \
  126. ((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec)
  127. #define DISCARD_ISSUE_RATE 8
  128. #define DEF_CP_INTERVAL 60 /* 60 secs */
  129. #define DEF_IDLE_INTERVAL 5 /* 5 secs */
  130. struct cp_control {
  131. int reason;
  132. __u64 trim_start;
  133. __u64 trim_end;
  134. __u64 trim_minlen;
  135. __u64 trimmed;
  136. };
  137. /*
  138. * For CP/NAT/SIT/SSA readahead
  139. */
  140. enum {
  141. META_CP,
  142. META_NAT,
  143. META_SIT,
  144. META_SSA,
  145. META_POR,
  146. };
  147. /* for the list of ino */
  148. enum {
  149. ORPHAN_INO, /* for orphan ino list */
  150. APPEND_INO, /* for append ino list */
  151. UPDATE_INO, /* for update ino list */
  152. MAX_INO_ENTRY, /* max. list */
  153. };
  154. struct ino_entry {
  155. struct list_head list; /* list head */
  156. nid_t ino; /* inode number */
  157. };
  158. /* for the list of inodes to be GCed */
  159. struct inode_entry {
  160. struct list_head list; /* list head */
  161. struct inode *inode; /* vfs inode pointer */
  162. };
  163. /* for the list of blockaddresses to be discarded */
  164. struct discard_entry {
  165. struct list_head list; /* list head */
  166. block_t blkaddr; /* block address to be discarded */
  167. int len; /* # of consecutive blocks of the discard */
  168. };
  169. enum {
  170. D_PREP,
  171. D_SUBMIT,
  172. D_DONE,
  173. };
  174. struct discard_cmd {
  175. struct list_head list; /* command list */
  176. struct completion wait; /* compleation */
  177. block_t lstart; /* logical start address */
  178. block_t len; /* length */
  179. struct bio *bio; /* bio */
  180. int state; /* state */
  181. };
  182. struct discard_cmd_control {
  183. struct task_struct *f2fs_issue_discard; /* discard thread */
  184. struct list_head discard_entry_list; /* 4KB discard entry list */
  185. int nr_discards; /* # of discards in the list */
  186. struct list_head discard_cmd_list; /* discard cmd list */
  187. wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */
  188. struct mutex cmd_lock;
  189. int max_discards; /* max. discards to be issued */
  190. atomic_t submit_discard; /* # of issued discard */
  191. };
  192. /* for the list of fsync inodes, used only during recovery */
  193. struct fsync_inode_entry {
  194. struct list_head list; /* list head */
  195. struct inode *inode; /* vfs inode pointer */
  196. block_t blkaddr; /* block address locating the last fsync */
  197. block_t last_dentry; /* block address locating the last dentry */
  198. };
  199. #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats))
  200. #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits))
  201. #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne)
  202. #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid)
  203. #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se)
  204. #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno)
  205. #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
  206. #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
  207. static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
  208. {
  209. int before = nats_in_cursum(journal);
  210. journal->n_nats = cpu_to_le16(before + i);
  211. return before;
  212. }
  213. static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
  214. {
  215. int before = sits_in_cursum(journal);
  216. journal->n_sits = cpu_to_le16(before + i);
  217. return before;
  218. }
  219. static inline bool __has_cursum_space(struct f2fs_journal *journal,
  220. int size, int type)
  221. {
  222. if (type == NAT_JOURNAL)
  223. return size <= MAX_NAT_JENTRIES(journal);
  224. return size <= MAX_SIT_JENTRIES(journal);
  225. }
  226. /*
  227. * ioctl commands
  228. */
  229. #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
  230. #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
  231. #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
  232. #define F2FS_IOCTL_MAGIC 0xf5
  233. #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
  234. #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
  235. #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
  236. #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
  237. #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
  238. #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6)
  239. #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7)
  240. #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8)
  241. #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \
  242. struct f2fs_move_range)
  243. #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
  244. #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
  245. #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT
  246. /*
  247. * should be same as XFS_IOC_GOINGDOWN.
  248. * Flags for going down operation used by FS_IOC_GOINGDOWN
  249. */
  250. #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
  251. #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
  252. #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
  253. #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
  254. #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */
  255. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  256. /*
  257. * ioctl commands in 32 bit emulation
  258. */
  259. #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  260. #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  261. #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION
  262. #endif
  263. struct f2fs_defragment {
  264. u64 start;
  265. u64 len;
  266. };
  267. struct f2fs_move_range {
  268. u32 dst_fd; /* destination fd */
  269. u64 pos_in; /* start position in src_fd */
  270. u64 pos_out; /* start position in dst_fd */
  271. u64 len; /* size to move */
  272. };
  273. /*
  274. * For INODE and NODE manager
  275. */
  276. /* for directory operations */
  277. struct f2fs_dentry_ptr {
  278. struct inode *inode;
  279. const void *bitmap;
  280. struct f2fs_dir_entry *dentry;
  281. __u8 (*filename)[F2FS_SLOT_LEN];
  282. int max;
  283. };
  284. static inline void make_dentry_ptr(struct inode *inode,
  285. struct f2fs_dentry_ptr *d, void *src, int type)
  286. {
  287. d->inode = inode;
  288. if (type == 1) {
  289. struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
  290. d->max = NR_DENTRY_IN_BLOCK;
  291. d->bitmap = &t->dentry_bitmap;
  292. d->dentry = t->dentry;
  293. d->filename = t->filename;
  294. } else {
  295. struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
  296. d->max = NR_INLINE_DENTRY;
  297. d->bitmap = &t->dentry_bitmap;
  298. d->dentry = t->dentry;
  299. d->filename = t->filename;
  300. }
  301. }
  302. /*
  303. * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
  304. * as its node offset to distinguish from index node blocks.
  305. * But some bits are used to mark the node block.
  306. */
  307. #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
  308. >> OFFSET_BIT_SHIFT)
  309. enum {
  310. ALLOC_NODE, /* allocate a new node page if needed */
  311. LOOKUP_NODE, /* look up a node without readahead */
  312. LOOKUP_NODE_RA, /*
  313. * look up a node with readahead called
  314. * by get_data_block.
  315. */
  316. };
  317. #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */
  318. #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
  319. /* vector size for gang look-up from extent cache that consists of radix tree */
  320. #define EXT_TREE_VEC_SIZE 64
  321. /* for in-memory extent cache entry */
  322. #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
  323. /* number of extent info in extent cache we try to shrink */
  324. #define EXTENT_CACHE_SHRINK_NUMBER 128
  325. struct extent_info {
  326. unsigned int fofs; /* start offset in a file */
  327. u32 blk; /* start block address of the extent */
  328. unsigned int len; /* length of the extent */
  329. };
  330. struct extent_node {
  331. struct rb_node rb_node; /* rb node located in rb-tree */
  332. struct list_head list; /* node in global extent list of sbi */
  333. struct extent_info ei; /* extent info */
  334. struct extent_tree *et; /* extent tree pointer */
  335. };
  336. struct extent_tree {
  337. nid_t ino; /* inode number */
  338. struct rb_root root; /* root of extent info rb-tree */
  339. struct extent_node *cached_en; /* recently accessed extent node */
  340. struct extent_info largest; /* largested extent info */
  341. struct list_head list; /* to be used by sbi->zombie_list */
  342. rwlock_t lock; /* protect extent info rb-tree */
  343. atomic_t node_cnt; /* # of extent node in rb-tree*/
  344. };
  345. /*
  346. * This structure is taken from ext4_map_blocks.
  347. *
  348. * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
  349. */
  350. #define F2FS_MAP_NEW (1 << BH_New)
  351. #define F2FS_MAP_MAPPED (1 << BH_Mapped)
  352. #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten)
  353. #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
  354. F2FS_MAP_UNWRITTEN)
  355. struct f2fs_map_blocks {
  356. block_t m_pblk;
  357. block_t m_lblk;
  358. unsigned int m_len;
  359. unsigned int m_flags;
  360. pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */
  361. };
  362. /* for flag in get_data_block */
  363. #define F2FS_GET_BLOCK_READ 0
  364. #define F2FS_GET_BLOCK_DIO 1
  365. #define F2FS_GET_BLOCK_FIEMAP 2
  366. #define F2FS_GET_BLOCK_BMAP 3
  367. #define F2FS_GET_BLOCK_PRE_DIO 4
  368. #define F2FS_GET_BLOCK_PRE_AIO 5
  369. /*
  370. * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
  371. */
  372. #define FADVISE_COLD_BIT 0x01
  373. #define FADVISE_LOST_PINO_BIT 0x02
  374. #define FADVISE_ENCRYPT_BIT 0x04
  375. #define FADVISE_ENC_NAME_BIT 0x08
  376. #define FADVISE_KEEP_SIZE_BIT 0x10
  377. #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
  378. #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
  379. #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT)
  380. #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT)
  381. #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT)
  382. #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT)
  383. #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT)
  384. #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT)
  385. #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
  386. #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT)
  387. #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
  388. #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT)
  389. #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
  390. #define DEF_DIR_LEVEL 0
  391. struct f2fs_inode_info {
  392. struct inode vfs_inode; /* serve a vfs inode */
  393. unsigned long i_flags; /* keep an inode flags for ioctl */
  394. unsigned char i_advise; /* use to give file attribute hints */
  395. unsigned char i_dir_level; /* use for dentry level for large dir */
  396. unsigned int i_current_depth; /* use only in directory structure */
  397. unsigned int i_pino; /* parent inode number */
  398. umode_t i_acl_mode; /* keep file acl mode temporarily */
  399. /* Use below internally in f2fs*/
  400. unsigned long flags; /* use to pass per-file flags */
  401. struct rw_semaphore i_sem; /* protect fi info */
  402. atomic_t dirty_pages; /* # of dirty pages */
  403. f2fs_hash_t chash; /* hash value of given file name */
  404. unsigned int clevel; /* maximum level of given file name */
  405. struct task_struct *task; /* lookup and create consistency */
  406. nid_t i_xattr_nid; /* node id that contains xattrs */
  407. loff_t last_disk_size; /* lastly written file size */
  408. struct list_head dirty_list; /* dirty list for dirs and files */
  409. struct list_head gdirty_list; /* linked in global dirty list */
  410. struct list_head inmem_pages; /* inmemory pages managed by f2fs */
  411. struct mutex inmem_lock; /* lock for inmemory pages */
  412. struct extent_tree *extent_tree; /* cached extent_tree entry */
  413. struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */
  414. };
  415. static inline void get_extent_info(struct extent_info *ext,
  416. struct f2fs_extent *i_ext)
  417. {
  418. ext->fofs = le32_to_cpu(i_ext->fofs);
  419. ext->blk = le32_to_cpu(i_ext->blk);
  420. ext->len = le32_to_cpu(i_ext->len);
  421. }
  422. static inline void set_raw_extent(struct extent_info *ext,
  423. struct f2fs_extent *i_ext)
  424. {
  425. i_ext->fofs = cpu_to_le32(ext->fofs);
  426. i_ext->blk = cpu_to_le32(ext->blk);
  427. i_ext->len = cpu_to_le32(ext->len);
  428. }
  429. static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
  430. u32 blk, unsigned int len)
  431. {
  432. ei->fofs = fofs;
  433. ei->blk = blk;
  434. ei->len = len;
  435. }
  436. static inline bool __is_extent_mergeable(struct extent_info *back,
  437. struct extent_info *front)
  438. {
  439. return (back->fofs + back->len == front->fofs &&
  440. back->blk + back->len == front->blk);
  441. }
  442. static inline bool __is_back_mergeable(struct extent_info *cur,
  443. struct extent_info *back)
  444. {
  445. return __is_extent_mergeable(back, cur);
  446. }
  447. static inline bool __is_front_mergeable(struct extent_info *cur,
  448. struct extent_info *front)
  449. {
  450. return __is_extent_mergeable(cur, front);
  451. }
  452. extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync);
  453. static inline void __try_update_largest_extent(struct inode *inode,
  454. struct extent_tree *et, struct extent_node *en)
  455. {
  456. if (en->ei.len > et->largest.len) {
  457. et->largest = en->ei;
  458. f2fs_mark_inode_dirty_sync(inode, true);
  459. }
  460. }
  461. enum nid_list {
  462. FREE_NID_LIST,
  463. ALLOC_NID_LIST,
  464. MAX_NID_LIST,
  465. };
  466. struct f2fs_nm_info {
  467. block_t nat_blkaddr; /* base disk address of NAT */
  468. nid_t max_nid; /* maximum possible node ids */
  469. nid_t available_nids; /* # of available node ids */
  470. nid_t next_scan_nid; /* the next nid to be scanned */
  471. unsigned int ram_thresh; /* control the memory footprint */
  472. unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */
  473. unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */
  474. /* NAT cache management */
  475. struct radix_tree_root nat_root;/* root of the nat entry cache */
  476. struct radix_tree_root nat_set_root;/* root of the nat set cache */
  477. struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
  478. struct list_head nat_entries; /* cached nat entry list (clean) */
  479. unsigned int nat_cnt; /* the # of cached nat entries */
  480. unsigned int dirty_nat_cnt; /* total num of nat entries in set */
  481. unsigned int nat_blocks; /* # of nat blocks */
  482. /* free node ids management */
  483. struct radix_tree_root free_nid_root;/* root of the free_nid cache */
  484. struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */
  485. unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */
  486. spinlock_t nid_list_lock; /* protect nid lists ops */
  487. struct mutex build_lock; /* lock for build free nids */
  488. unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
  489. unsigned char *nat_block_bitmap;
  490. /* for checkpoint */
  491. char *nat_bitmap; /* NAT bitmap pointer */
  492. unsigned int nat_bits_blocks; /* # of nat bits blocks */
  493. unsigned char *nat_bits; /* NAT bits blocks */
  494. unsigned char *full_nat_bits; /* full NAT pages */
  495. unsigned char *empty_nat_bits; /* empty NAT pages */
  496. #ifdef CONFIG_F2FS_CHECK_FS
  497. char *nat_bitmap_mir; /* NAT bitmap mirror */
  498. #endif
  499. int bitmap_size; /* bitmap size */
  500. };
  501. /*
  502. * this structure is used as one of function parameters.
  503. * all the information are dedicated to a given direct node block determined
  504. * by the data offset in a file.
  505. */
  506. struct dnode_of_data {
  507. struct inode *inode; /* vfs inode pointer */
  508. struct page *inode_page; /* its inode page, NULL is possible */
  509. struct page *node_page; /* cached direct node page */
  510. nid_t nid; /* node id of the direct node block */
  511. unsigned int ofs_in_node; /* data offset in the node page */
  512. bool inode_page_locked; /* inode page is locked or not */
  513. bool node_changed; /* is node block changed */
  514. char cur_level; /* level of hole node page */
  515. char max_level; /* level of current page located */
  516. block_t data_blkaddr; /* block address of the node block */
  517. };
  518. static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  519. struct page *ipage, struct page *npage, nid_t nid)
  520. {
  521. memset(dn, 0, sizeof(*dn));
  522. dn->inode = inode;
  523. dn->inode_page = ipage;
  524. dn->node_page = npage;
  525. dn->nid = nid;
  526. }
  527. /*
  528. * For SIT manager
  529. *
  530. * By default, there are 6 active log areas across the whole main area.
  531. * When considering hot and cold data separation to reduce cleaning overhead,
  532. * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
  533. * respectively.
  534. * In the current design, you should not change the numbers intentionally.
  535. * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
  536. * logs individually according to the underlying devices. (default: 6)
  537. * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
  538. * data and 8 for node logs.
  539. */
  540. #define NR_CURSEG_DATA_TYPE (3)
  541. #define NR_CURSEG_NODE_TYPE (3)
  542. #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  543. enum {
  544. CURSEG_HOT_DATA = 0, /* directory entry blocks */
  545. CURSEG_WARM_DATA, /* data blocks */
  546. CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
  547. CURSEG_HOT_NODE, /* direct node blocks of directory files */
  548. CURSEG_WARM_NODE, /* direct node blocks of normal files */
  549. CURSEG_COLD_NODE, /* indirect node blocks */
  550. NO_CHECK_TYPE,
  551. };
  552. struct flush_cmd {
  553. struct completion wait;
  554. struct llist_node llnode;
  555. int ret;
  556. };
  557. struct flush_cmd_control {
  558. struct task_struct *f2fs_issue_flush; /* flush thread */
  559. wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
  560. atomic_t submit_flush; /* # of issued flushes */
  561. struct llist_head issue_list; /* list for command issue */
  562. struct llist_node *dispatch_list; /* list for command dispatch */
  563. };
  564. struct f2fs_sm_info {
  565. struct sit_info *sit_info; /* whole segment information */
  566. struct free_segmap_info *free_info; /* free segment information */
  567. struct dirty_seglist_info *dirty_info; /* dirty segment information */
  568. struct curseg_info *curseg_array; /* active segment information */
  569. block_t seg0_blkaddr; /* block address of 0'th segment */
  570. block_t main_blkaddr; /* start block address of main area */
  571. block_t ssa_blkaddr; /* start block address of SSA area */
  572. unsigned int segment_count; /* total # of segments */
  573. unsigned int main_segments; /* # of segments in main area */
  574. unsigned int reserved_segments; /* # of reserved segments */
  575. unsigned int ovp_segments; /* # of overprovision segments */
  576. /* a threshold to reclaim prefree segments */
  577. unsigned int rec_prefree_segments;
  578. /* for batched trimming */
  579. unsigned int trim_sections; /* # of sections to trim */
  580. struct list_head sit_entry_set; /* sit entry set list */
  581. unsigned int ipu_policy; /* in-place-update policy */
  582. unsigned int min_ipu_util; /* in-place-update threshold */
  583. unsigned int min_fsync_blocks; /* threshold for fsync */
  584. /* for flush command control */
  585. struct flush_cmd_control *fcc_info;
  586. /* for discard command control */
  587. struct discard_cmd_control *dcc_info;
  588. };
  589. /*
  590. * For superblock
  591. */
  592. /*
  593. * COUNT_TYPE for monitoring
  594. *
  595. * f2fs monitors the number of several block types such as on-writeback,
  596. * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
  597. */
  598. #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
  599. enum count_type {
  600. F2FS_DIRTY_DENTS,
  601. F2FS_DIRTY_DATA,
  602. F2FS_DIRTY_NODES,
  603. F2FS_DIRTY_META,
  604. F2FS_INMEM_PAGES,
  605. F2FS_DIRTY_IMETA,
  606. F2FS_WB_CP_DATA,
  607. F2FS_WB_DATA,
  608. NR_COUNT_TYPE,
  609. };
  610. /*
  611. * The below are the page types of bios used in submit_bio().
  612. * The available types are:
  613. * DATA User data pages. It operates as async mode.
  614. * NODE Node pages. It operates as async mode.
  615. * META FS metadata pages such as SIT, NAT, CP.
  616. * NR_PAGE_TYPE The number of page types.
  617. * META_FLUSH Make sure the previous pages are written
  618. * with waiting the bio's completion
  619. * ... Only can be used with META.
  620. */
  621. #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
  622. enum page_type {
  623. DATA,
  624. NODE,
  625. META,
  626. NR_PAGE_TYPE,
  627. META_FLUSH,
  628. INMEM, /* the below types are used by tracepoints only. */
  629. INMEM_DROP,
  630. INMEM_REVOKE,
  631. IPU,
  632. OPU,
  633. };
  634. struct f2fs_io_info {
  635. struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
  636. enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
  637. int op; /* contains REQ_OP_ */
  638. int op_flags; /* req_flag_bits */
  639. block_t new_blkaddr; /* new block address to be written */
  640. block_t old_blkaddr; /* old block address before Cow */
  641. struct page *page; /* page to be written */
  642. struct page *encrypted_page; /* encrypted page */
  643. bool submitted; /* indicate IO submission */
  644. };
  645. #define is_read_io(rw) (rw == READ)
  646. struct f2fs_bio_info {
  647. struct f2fs_sb_info *sbi; /* f2fs superblock */
  648. struct bio *bio; /* bios to merge */
  649. sector_t last_block_in_bio; /* last block number */
  650. struct f2fs_io_info fio; /* store buffered io info. */
  651. struct rw_semaphore io_rwsem; /* blocking op for bio */
  652. };
  653. #define FDEV(i) (sbi->devs[i])
  654. #define RDEV(i) (raw_super->devs[i])
  655. struct f2fs_dev_info {
  656. struct block_device *bdev;
  657. char path[MAX_PATH_LEN];
  658. unsigned int total_segments;
  659. block_t start_blk;
  660. block_t end_blk;
  661. #ifdef CONFIG_BLK_DEV_ZONED
  662. unsigned int nr_blkz; /* Total number of zones */
  663. u8 *blkz_type; /* Array of zones type */
  664. #endif
  665. };
  666. enum inode_type {
  667. DIR_INODE, /* for dirty dir inode */
  668. FILE_INODE, /* for dirty regular/symlink inode */
  669. DIRTY_META, /* for all dirtied inode metadata */
  670. NR_INODE_TYPE,
  671. };
  672. /* for inner inode cache management */
  673. struct inode_management {
  674. struct radix_tree_root ino_root; /* ino entry array */
  675. spinlock_t ino_lock; /* for ino entry lock */
  676. struct list_head ino_list; /* inode list head */
  677. unsigned long ino_num; /* number of entries */
  678. };
  679. /* For s_flag in struct f2fs_sb_info */
  680. enum {
  681. SBI_IS_DIRTY, /* dirty flag for checkpoint */
  682. SBI_IS_CLOSE, /* specify unmounting */
  683. SBI_NEED_FSCK, /* need fsck.f2fs to fix */
  684. SBI_POR_DOING, /* recovery is doing or not */
  685. SBI_NEED_SB_WRITE, /* need to recover superblock */
  686. SBI_NEED_CP, /* need to checkpoint */
  687. };
  688. enum {
  689. CP_TIME,
  690. REQ_TIME,
  691. MAX_TIME,
  692. };
  693. struct f2fs_sb_info {
  694. struct super_block *sb; /* pointer to VFS super block */
  695. struct proc_dir_entry *s_proc; /* proc entry */
  696. struct f2fs_super_block *raw_super; /* raw super block pointer */
  697. int valid_super_block; /* valid super block no */
  698. unsigned long s_flag; /* flags for sbi */
  699. #ifdef CONFIG_BLK_DEV_ZONED
  700. unsigned int blocks_per_blkz; /* F2FS blocks per zone */
  701. unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */
  702. #endif
  703. /* for node-related operations */
  704. struct f2fs_nm_info *nm_info; /* node manager */
  705. struct inode *node_inode; /* cache node blocks */
  706. /* for segment-related operations */
  707. struct f2fs_sm_info *sm_info; /* segment manager */
  708. /* for bio operations */
  709. struct f2fs_bio_info read_io; /* for read bios */
  710. struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
  711. struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */
  712. int write_io_size_bits; /* Write IO size bits */
  713. mempool_t *write_io_dummy; /* Dummy pages */
  714. /* for checkpoint */
  715. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  716. int cur_cp_pack; /* remain current cp pack */
  717. spinlock_t cp_lock; /* for flag in ckpt */
  718. struct inode *meta_inode; /* cache meta blocks */
  719. struct mutex cp_mutex; /* checkpoint procedure lock */
  720. struct rw_semaphore cp_rwsem; /* blocking FS operations */
  721. struct rw_semaphore node_write; /* locking node writes */
  722. wait_queue_head_t cp_wait;
  723. unsigned long last_time[MAX_TIME]; /* to store time in jiffies */
  724. long interval_time[MAX_TIME]; /* to store thresholds */
  725. struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
  726. /* for orphan inode, use 0'th array */
  727. unsigned int max_orphans; /* max orphan inodes */
  728. /* for inode management */
  729. struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */
  730. spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */
  731. /* for extent tree cache */
  732. struct radix_tree_root extent_tree_root;/* cache extent cache entries */
  733. struct mutex extent_tree_lock; /* locking extent radix tree */
  734. struct list_head extent_list; /* lru list for shrinker */
  735. spinlock_t extent_lock; /* locking extent lru list */
  736. atomic_t total_ext_tree; /* extent tree count */
  737. struct list_head zombie_list; /* extent zombie tree list */
  738. atomic_t total_zombie_tree; /* extent zombie tree count */
  739. atomic_t total_ext_node; /* extent info count */
  740. /* basic filesystem units */
  741. unsigned int log_sectors_per_block; /* log2 sectors per block */
  742. unsigned int log_blocksize; /* log2 block size */
  743. unsigned int blocksize; /* block size */
  744. unsigned int root_ino_num; /* root inode number*/
  745. unsigned int node_ino_num; /* node inode number*/
  746. unsigned int meta_ino_num; /* meta inode number*/
  747. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  748. unsigned int blocks_per_seg; /* blocks per segment */
  749. unsigned int segs_per_sec; /* segments per section */
  750. unsigned int secs_per_zone; /* sections per zone */
  751. unsigned int total_sections; /* total section count */
  752. unsigned int total_node_count; /* total node block count */
  753. unsigned int total_valid_node_count; /* valid node block count */
  754. loff_t max_file_blocks; /* max block index of file */
  755. int active_logs; /* # of active logs */
  756. int dir_level; /* directory level */
  757. block_t user_block_count; /* # of user blocks */
  758. block_t total_valid_block_count; /* # of valid blocks */
  759. block_t discard_blks; /* discard command candidats */
  760. block_t last_valid_block_count; /* for recovery */
  761. u32 s_next_generation; /* for NFS support */
  762. /* # of pages, see count_type */
  763. atomic_t nr_pages[NR_COUNT_TYPE];
  764. /* # of allocated blocks */
  765. struct percpu_counter alloc_valid_block_count;
  766. /* valid inode count */
  767. struct percpu_counter total_valid_inode_count;
  768. struct f2fs_mount_info mount_opt; /* mount options */
  769. /* for cleaning operations */
  770. struct mutex gc_mutex; /* mutex for GC */
  771. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  772. unsigned int cur_victim_sec; /* current victim section num */
  773. /* threshold for converting bg victims for fg */
  774. u64 fggc_threshold;
  775. /* maximum # of trials to find a victim segment for SSR and GC */
  776. unsigned int max_victim_search;
  777. /*
  778. * for stat information.
  779. * one is for the LFS mode, and the other is for the SSR mode.
  780. */
  781. #ifdef CONFIG_F2FS_STAT_FS
  782. struct f2fs_stat_info *stat_info; /* FS status information */
  783. unsigned int segment_count[2]; /* # of allocated segments */
  784. unsigned int block_count[2]; /* # of allocated blocks */
  785. atomic_t inplace_count; /* # of inplace update */
  786. atomic64_t total_hit_ext; /* # of lookup extent cache */
  787. atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */
  788. atomic64_t read_hit_largest; /* # of hit largest extent node */
  789. atomic64_t read_hit_cached; /* # of hit cached extent node */
  790. atomic_t inline_xattr; /* # of inline_xattr inodes */
  791. atomic_t inline_inode; /* # of inline_data inodes */
  792. atomic_t inline_dir; /* # of inline_dentry inodes */
  793. atomic_t aw_cnt; /* # of atomic writes */
  794. atomic_t max_aw_cnt; /* max # of atomic writes */
  795. int bg_gc; /* background gc calls */
  796. unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */
  797. #endif
  798. unsigned int last_victim[2]; /* last victim segment # */
  799. spinlock_t stat_lock; /* lock for stat operations */
  800. /* For sysfs suppport */
  801. struct kobject s_kobj;
  802. struct completion s_kobj_unregister;
  803. /* For shrinker support */
  804. struct list_head s_list;
  805. int s_ndevs; /* number of devices */
  806. struct f2fs_dev_info *devs; /* for device list */
  807. struct mutex umount_mutex;
  808. unsigned int shrinker_run_no;
  809. /* For write statistics */
  810. u64 sectors_written_start;
  811. u64 kbytes_written;
  812. /* Reference to checksum algorithm driver via cryptoapi */
  813. struct crypto_shash *s_chksum_driver;
  814. /* For fault injection */
  815. #ifdef CONFIG_F2FS_FAULT_INJECTION
  816. struct f2fs_fault_info fault_info;
  817. #endif
  818. };
  819. #ifdef CONFIG_F2FS_FAULT_INJECTION
  820. #define f2fs_show_injection_info(type) \
  821. printk("%sF2FS-fs : inject %s in %s of %pF\n", \
  822. KERN_INFO, fault_name[type], \
  823. __func__, __builtin_return_address(0))
  824. static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
  825. {
  826. struct f2fs_fault_info *ffi = &sbi->fault_info;
  827. if (!ffi->inject_rate)
  828. return false;
  829. if (!IS_FAULT_SET(ffi, type))
  830. return false;
  831. atomic_inc(&ffi->inject_ops);
  832. if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
  833. atomic_set(&ffi->inject_ops, 0);
  834. return true;
  835. }
  836. return false;
  837. }
  838. #endif
  839. /* For write statistics. Suppose sector size is 512 bytes,
  840. * and the return value is in kbytes. s is of struct f2fs_sb_info.
  841. */
  842. #define BD_PART_WRITTEN(s) \
  843. (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \
  844. s->sectors_written_start) >> 1)
  845. static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
  846. {
  847. sbi->last_time[type] = jiffies;
  848. }
  849. static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
  850. {
  851. struct timespec ts = {sbi->interval_time[type], 0};
  852. unsigned long interval = timespec_to_jiffies(&ts);
  853. return time_after(jiffies, sbi->last_time[type] + interval);
  854. }
  855. static inline bool is_idle(struct f2fs_sb_info *sbi)
  856. {
  857. struct block_device *bdev = sbi->sb->s_bdev;
  858. struct request_queue *q = bdev_get_queue(bdev);
  859. struct request_list *rl = &q->root_rl;
  860. if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
  861. return 0;
  862. return f2fs_time_over(sbi, REQ_TIME);
  863. }
  864. /*
  865. * Inline functions
  866. */
  867. static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
  868. unsigned int length)
  869. {
  870. SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver);
  871. u32 *ctx = (u32 *)shash_desc_ctx(shash);
  872. int err;
  873. shash->tfm = sbi->s_chksum_driver;
  874. shash->flags = 0;
  875. *ctx = F2FS_SUPER_MAGIC;
  876. err = crypto_shash_update(shash, address, length);
  877. BUG_ON(err);
  878. return *ctx;
  879. }
  880. static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
  881. void *buf, size_t buf_size)
  882. {
  883. return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
  884. }
  885. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  886. {
  887. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  888. }
  889. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  890. {
  891. return sb->s_fs_info;
  892. }
  893. static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
  894. {
  895. return F2FS_SB(inode->i_sb);
  896. }
  897. static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
  898. {
  899. return F2FS_I_SB(mapping->host);
  900. }
  901. static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
  902. {
  903. return F2FS_M_SB(page->mapping);
  904. }
  905. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  906. {
  907. return (struct f2fs_super_block *)(sbi->raw_super);
  908. }
  909. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  910. {
  911. return (struct f2fs_checkpoint *)(sbi->ckpt);
  912. }
  913. static inline struct f2fs_node *F2FS_NODE(struct page *page)
  914. {
  915. return (struct f2fs_node *)page_address(page);
  916. }
  917. static inline struct f2fs_inode *F2FS_INODE(struct page *page)
  918. {
  919. return &((struct f2fs_node *)page_address(page))->i;
  920. }
  921. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  922. {
  923. return (struct f2fs_nm_info *)(sbi->nm_info);
  924. }
  925. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  926. {
  927. return (struct f2fs_sm_info *)(sbi->sm_info);
  928. }
  929. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  930. {
  931. return (struct sit_info *)(SM_I(sbi)->sit_info);
  932. }
  933. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  934. {
  935. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  936. }
  937. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  938. {
  939. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  940. }
  941. static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
  942. {
  943. return sbi->meta_inode->i_mapping;
  944. }
  945. static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
  946. {
  947. return sbi->node_inode->i_mapping;
  948. }
  949. static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  950. {
  951. return test_bit(type, &sbi->s_flag);
  952. }
  953. static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  954. {
  955. set_bit(type, &sbi->s_flag);
  956. }
  957. static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  958. {
  959. clear_bit(type, &sbi->s_flag);
  960. }
  961. static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
  962. {
  963. return le64_to_cpu(cp->checkpoint_ver);
  964. }
  965. static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
  966. {
  967. size_t crc_offset = le32_to_cpu(cp->checksum_offset);
  968. return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
  969. }
  970. static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  971. {
  972. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  973. return ckpt_flags & f;
  974. }
  975. static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
  976. {
  977. return __is_set_ckpt_flags(F2FS_CKPT(sbi), f);
  978. }
  979. static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  980. {
  981. unsigned int ckpt_flags;
  982. ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  983. ckpt_flags |= f;
  984. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  985. }
  986. static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
  987. {
  988. spin_lock(&sbi->cp_lock);
  989. __set_ckpt_flags(F2FS_CKPT(sbi), f);
  990. spin_unlock(&sbi->cp_lock);
  991. }
  992. static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  993. {
  994. unsigned int ckpt_flags;
  995. ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  996. ckpt_flags &= (~f);
  997. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  998. }
  999. static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
  1000. {
  1001. spin_lock(&sbi->cp_lock);
  1002. __clear_ckpt_flags(F2FS_CKPT(sbi), f);
  1003. spin_unlock(&sbi->cp_lock);
  1004. }
  1005. static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
  1006. {
  1007. set_sbi_flag(sbi, SBI_NEED_FSCK);
  1008. if (lock)
  1009. spin_lock(&sbi->cp_lock);
  1010. __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
  1011. kfree(NM_I(sbi)->nat_bits);
  1012. NM_I(sbi)->nat_bits = NULL;
  1013. if (lock)
  1014. spin_unlock(&sbi->cp_lock);
  1015. }
  1016. static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
  1017. struct cp_control *cpc)
  1018. {
  1019. bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
  1020. return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set;
  1021. }
  1022. static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
  1023. {
  1024. down_read(&sbi->cp_rwsem);
  1025. }
  1026. static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
  1027. {
  1028. up_read(&sbi->cp_rwsem);
  1029. }
  1030. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  1031. {
  1032. down_write(&sbi->cp_rwsem);
  1033. }
  1034. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  1035. {
  1036. up_write(&sbi->cp_rwsem);
  1037. }
  1038. static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
  1039. {
  1040. int reason = CP_SYNC;
  1041. if (test_opt(sbi, FASTBOOT))
  1042. reason = CP_FASTBOOT;
  1043. if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
  1044. reason = CP_UMOUNT;
  1045. return reason;
  1046. }
  1047. static inline bool __remain_node_summaries(int reason)
  1048. {
  1049. return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
  1050. }
  1051. static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
  1052. {
  1053. return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) ||
  1054. is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG));
  1055. }
  1056. /*
  1057. * Check whether the given nid is within node id range.
  1058. */
  1059. static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
  1060. {
  1061. if (unlikely(nid < F2FS_ROOT_INO(sbi)))
  1062. return -EINVAL;
  1063. if (unlikely(nid >= NM_I(sbi)->max_nid))
  1064. return -EINVAL;
  1065. return 0;
  1066. }
  1067. #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
  1068. /*
  1069. * Check whether the inode has blocks or not
  1070. */
  1071. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  1072. {
  1073. if (F2FS_I(inode)->i_xattr_nid)
  1074. return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
  1075. else
  1076. return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
  1077. }
  1078. static inline bool f2fs_has_xattr_block(unsigned int ofs)
  1079. {
  1080. return ofs == XATTR_NODE_OFFSET;
  1081. }
  1082. static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool);
  1083. static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
  1084. struct inode *inode, blkcnt_t *count)
  1085. {
  1086. blkcnt_t diff;
  1087. #ifdef CONFIG_F2FS_FAULT_INJECTION
  1088. if (time_to_inject(sbi, FAULT_BLOCK)) {
  1089. f2fs_show_injection_info(FAULT_BLOCK);
  1090. return false;
  1091. }
  1092. #endif
  1093. /*
  1094. * let's increase this in prior to actual block count change in order
  1095. * for f2fs_sync_file to avoid data races when deciding checkpoint.
  1096. */
  1097. percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
  1098. spin_lock(&sbi->stat_lock);
  1099. sbi->total_valid_block_count += (block_t)(*count);
  1100. if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) {
  1101. diff = sbi->total_valid_block_count - sbi->user_block_count;
  1102. *count -= diff;
  1103. sbi->total_valid_block_count = sbi->user_block_count;
  1104. if (!*count) {
  1105. spin_unlock(&sbi->stat_lock);
  1106. percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
  1107. return false;
  1108. }
  1109. }
  1110. spin_unlock(&sbi->stat_lock);
  1111. f2fs_i_blocks_write(inode, *count, true);
  1112. return true;
  1113. }
  1114. static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
  1115. struct inode *inode,
  1116. blkcnt_t count)
  1117. {
  1118. spin_lock(&sbi->stat_lock);
  1119. f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
  1120. f2fs_bug_on(sbi, inode->i_blocks < count);
  1121. sbi->total_valid_block_count -= (block_t)count;
  1122. spin_unlock(&sbi->stat_lock);
  1123. f2fs_i_blocks_write(inode, count, false);
  1124. }
  1125. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  1126. {
  1127. atomic_inc(&sbi->nr_pages[count_type]);
  1128. if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES ||
  1129. count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA)
  1130. return;
  1131. set_sbi_flag(sbi, SBI_IS_DIRTY);
  1132. }
  1133. static inline void inode_inc_dirty_pages(struct inode *inode)
  1134. {
  1135. atomic_inc(&F2FS_I(inode)->dirty_pages);
  1136. inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
  1137. F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
  1138. }
  1139. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  1140. {
  1141. atomic_dec(&sbi->nr_pages[count_type]);
  1142. }
  1143. static inline void inode_dec_dirty_pages(struct inode *inode)
  1144. {
  1145. if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
  1146. !S_ISLNK(inode->i_mode))
  1147. return;
  1148. atomic_dec(&F2FS_I(inode)->dirty_pages);
  1149. dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
  1150. F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
  1151. }
  1152. static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
  1153. {
  1154. return atomic_read(&sbi->nr_pages[count_type]);
  1155. }
  1156. static inline int get_dirty_pages(struct inode *inode)
  1157. {
  1158. return atomic_read(&F2FS_I(inode)->dirty_pages);
  1159. }
  1160. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  1161. {
  1162. unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
  1163. unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >>
  1164. sbi->log_blocks_per_seg;
  1165. return segs / sbi->segs_per_sec;
  1166. }
  1167. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  1168. {
  1169. return sbi->total_valid_block_count;
  1170. }
  1171. static inline block_t discard_blocks(struct f2fs_sb_info *sbi)
  1172. {
  1173. return sbi->discard_blks;
  1174. }
  1175. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  1176. {
  1177. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  1178. /* return NAT or SIT bitmap */
  1179. if (flag == NAT_BITMAP)
  1180. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  1181. else if (flag == SIT_BITMAP)
  1182. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  1183. return 0;
  1184. }
  1185. static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
  1186. {
  1187. return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
  1188. }
  1189. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  1190. {
  1191. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  1192. int offset;
  1193. if (__cp_payload(sbi) > 0) {
  1194. if (flag == NAT_BITMAP)
  1195. return &ckpt->sit_nat_version_bitmap;
  1196. else
  1197. return (unsigned char *)ckpt + F2FS_BLKSIZE;
  1198. } else {
  1199. offset = (flag == NAT_BITMAP) ?
  1200. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  1201. return &ckpt->sit_nat_version_bitmap + offset;
  1202. }
  1203. }
  1204. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  1205. {
  1206. block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  1207. if (sbi->cur_cp_pack == 2)
  1208. start_addr += sbi->blocks_per_seg;
  1209. return start_addr;
  1210. }
  1211. static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
  1212. {
  1213. block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  1214. if (sbi->cur_cp_pack == 1)
  1215. start_addr += sbi->blocks_per_seg;
  1216. return start_addr;
  1217. }
  1218. static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
  1219. {
  1220. sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
  1221. }
  1222. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  1223. {
  1224. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  1225. }
  1226. static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
  1227. struct inode *inode)
  1228. {
  1229. block_t valid_block_count;
  1230. unsigned int valid_node_count;
  1231. spin_lock(&sbi->stat_lock);
  1232. valid_block_count = sbi->total_valid_block_count + 1;
  1233. if (unlikely(valid_block_count > sbi->user_block_count)) {
  1234. spin_unlock(&sbi->stat_lock);
  1235. return false;
  1236. }
  1237. valid_node_count = sbi->total_valid_node_count + 1;
  1238. if (unlikely(valid_node_count > sbi->total_node_count)) {
  1239. spin_unlock(&sbi->stat_lock);
  1240. return false;
  1241. }
  1242. if (inode)
  1243. f2fs_i_blocks_write(inode, 1, true);
  1244. sbi->total_valid_node_count++;
  1245. sbi->total_valid_block_count++;
  1246. spin_unlock(&sbi->stat_lock);
  1247. percpu_counter_inc(&sbi->alloc_valid_block_count);
  1248. return true;
  1249. }
  1250. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  1251. struct inode *inode)
  1252. {
  1253. spin_lock(&sbi->stat_lock);
  1254. f2fs_bug_on(sbi, !sbi->total_valid_block_count);
  1255. f2fs_bug_on(sbi, !sbi->total_valid_node_count);
  1256. f2fs_bug_on(sbi, !inode->i_blocks);
  1257. f2fs_i_blocks_write(inode, 1, false);
  1258. sbi->total_valid_node_count--;
  1259. sbi->total_valid_block_count--;
  1260. spin_unlock(&sbi->stat_lock);
  1261. }
  1262. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  1263. {
  1264. return sbi->total_valid_node_count;
  1265. }
  1266. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  1267. {
  1268. percpu_counter_inc(&sbi->total_valid_inode_count);
  1269. }
  1270. static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
  1271. {
  1272. percpu_counter_dec(&sbi->total_valid_inode_count);
  1273. }
  1274. static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
  1275. {
  1276. return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
  1277. }
  1278. static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
  1279. pgoff_t index, bool for_write)
  1280. {
  1281. #ifdef CONFIG_F2FS_FAULT_INJECTION
  1282. struct page *page = find_lock_page(mapping, index);
  1283. if (page)
  1284. return page;
  1285. if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
  1286. f2fs_show_injection_info(FAULT_PAGE_ALLOC);
  1287. return NULL;
  1288. }
  1289. #endif
  1290. if (!for_write)
  1291. return grab_cache_page(mapping, index);
  1292. return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
  1293. }
  1294. static inline void f2fs_copy_page(struct page *src, struct page *dst)
  1295. {
  1296. char *src_kaddr = kmap(src);
  1297. char *dst_kaddr = kmap(dst);
  1298. memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
  1299. kunmap(dst);
  1300. kunmap(src);
  1301. }
  1302. static inline void f2fs_put_page(struct page *page, int unlock)
  1303. {
  1304. if (!page)
  1305. return;
  1306. if (unlock) {
  1307. f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
  1308. unlock_page(page);
  1309. }
  1310. put_page(page);
  1311. }
  1312. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  1313. {
  1314. if (dn->node_page)
  1315. f2fs_put_page(dn->node_page, 1);
  1316. if (dn->inode_page && dn->node_page != dn->inode_page)
  1317. f2fs_put_page(dn->inode_page, 0);
  1318. dn->node_page = NULL;
  1319. dn->inode_page = NULL;
  1320. }
  1321. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  1322. size_t size)
  1323. {
  1324. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
  1325. }
  1326. static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
  1327. gfp_t flags)
  1328. {
  1329. void *entry;
  1330. entry = kmem_cache_alloc(cachep, flags);
  1331. if (!entry)
  1332. entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
  1333. return entry;
  1334. }
  1335. static inline struct bio *f2fs_bio_alloc(int npages)
  1336. {
  1337. struct bio *bio;
  1338. /* No failure on bio allocation */
  1339. bio = bio_alloc(GFP_NOIO, npages);
  1340. if (!bio)
  1341. bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
  1342. return bio;
  1343. }
  1344. static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
  1345. unsigned long index, void *item)
  1346. {
  1347. while (radix_tree_insert(root, index, item))
  1348. cond_resched();
  1349. }
  1350. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  1351. static inline bool IS_INODE(struct page *page)
  1352. {
  1353. struct f2fs_node *p = F2FS_NODE(page);
  1354. return RAW_IS_INODE(p);
  1355. }
  1356. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  1357. {
  1358. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  1359. }
  1360. static inline block_t datablock_addr(struct page *node_page,
  1361. unsigned int offset)
  1362. {
  1363. struct f2fs_node *raw_node;
  1364. __le32 *addr_array;
  1365. raw_node = F2FS_NODE(node_page);
  1366. addr_array = blkaddr_in_node(raw_node);
  1367. return le32_to_cpu(addr_array[offset]);
  1368. }
  1369. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  1370. {
  1371. int mask;
  1372. addr += (nr >> 3);
  1373. mask = 1 << (7 - (nr & 0x07));
  1374. return mask & *addr;
  1375. }
  1376. static inline void f2fs_set_bit(unsigned int nr, char *addr)
  1377. {
  1378. int mask;
  1379. addr += (nr >> 3);
  1380. mask = 1 << (7 - (nr & 0x07));
  1381. *addr |= mask;
  1382. }
  1383. static inline void f2fs_clear_bit(unsigned int nr, char *addr)
  1384. {
  1385. int mask;
  1386. addr += (nr >> 3);
  1387. mask = 1 << (7 - (nr & 0x07));
  1388. *addr &= ~mask;
  1389. }
  1390. static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
  1391. {
  1392. int mask;
  1393. int ret;
  1394. addr += (nr >> 3);
  1395. mask = 1 << (7 - (nr & 0x07));
  1396. ret = mask & *addr;
  1397. *addr |= mask;
  1398. return ret;
  1399. }
  1400. static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
  1401. {
  1402. int mask;
  1403. int ret;
  1404. addr += (nr >> 3);
  1405. mask = 1 << (7 - (nr & 0x07));
  1406. ret = mask & *addr;
  1407. *addr &= ~mask;
  1408. return ret;
  1409. }
  1410. static inline void f2fs_change_bit(unsigned int nr, char *addr)
  1411. {
  1412. int mask;
  1413. addr += (nr >> 3);
  1414. mask = 1 << (7 - (nr & 0x07));
  1415. *addr ^= mask;
  1416. }
  1417. /* used for f2fs_inode_info->flags */
  1418. enum {
  1419. FI_NEW_INODE, /* indicate newly allocated inode */
  1420. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  1421. FI_AUTO_RECOVER, /* indicate inode is recoverable */
  1422. FI_DIRTY_DIR, /* indicate directory has dirty pages */
  1423. FI_INC_LINK, /* need to increment i_nlink */
  1424. FI_ACL_MODE, /* indicate acl mode */
  1425. FI_NO_ALLOC, /* should not allocate any blocks */
  1426. FI_FREE_NID, /* free allocated nide */
  1427. FI_NO_EXTENT, /* not to use the extent cache */
  1428. FI_INLINE_XATTR, /* used for inline xattr */
  1429. FI_INLINE_DATA, /* used for inline data*/
  1430. FI_INLINE_DENTRY, /* used for inline dentry */
  1431. FI_APPEND_WRITE, /* inode has appended data */
  1432. FI_UPDATE_WRITE, /* inode has in-place-update data */
  1433. FI_NEED_IPU, /* used for ipu per file */
  1434. FI_ATOMIC_FILE, /* indicate atomic file */
  1435. FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */
  1436. FI_VOLATILE_FILE, /* indicate volatile file */
  1437. FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
  1438. FI_DROP_CACHE, /* drop dirty page cache */
  1439. FI_DATA_EXIST, /* indicate data exists */
  1440. FI_INLINE_DOTS, /* indicate inline dot dentries */
  1441. FI_DO_DEFRAG, /* indicate defragment is running */
  1442. FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */
  1443. FI_NO_PREALLOC, /* indicate skipped preallocated blocks */
  1444. };
  1445. static inline void __mark_inode_dirty_flag(struct inode *inode,
  1446. int flag, bool set)
  1447. {
  1448. switch (flag) {
  1449. case FI_INLINE_XATTR:
  1450. case FI_INLINE_DATA:
  1451. case FI_INLINE_DENTRY:
  1452. if (set)
  1453. return;
  1454. case FI_DATA_EXIST:
  1455. case FI_INLINE_DOTS:
  1456. f2fs_mark_inode_dirty_sync(inode, true);
  1457. }
  1458. }
  1459. static inline void set_inode_flag(struct inode *inode, int flag)
  1460. {
  1461. if (!test_bit(flag, &F2FS_I(inode)->flags))
  1462. set_bit(flag, &F2FS_I(inode)->flags);
  1463. __mark_inode_dirty_flag(inode, flag, true);
  1464. }
  1465. static inline int is_inode_flag_set(struct inode *inode, int flag)
  1466. {
  1467. return test_bit(flag, &F2FS_I(inode)->flags);
  1468. }
  1469. static inline void clear_inode_flag(struct inode *inode, int flag)
  1470. {
  1471. if (test_bit(flag, &F2FS_I(inode)->flags))
  1472. clear_bit(flag, &F2FS_I(inode)->flags);
  1473. __mark_inode_dirty_flag(inode, flag, false);
  1474. }
  1475. static inline void set_acl_inode(struct inode *inode, umode_t mode)
  1476. {
  1477. F2FS_I(inode)->i_acl_mode = mode;
  1478. set_inode_flag(inode, FI_ACL_MODE);
  1479. f2fs_mark_inode_dirty_sync(inode, false);
  1480. }
  1481. static inline void f2fs_i_links_write(struct inode *inode, bool inc)
  1482. {
  1483. if (inc)
  1484. inc_nlink(inode);
  1485. else
  1486. drop_nlink(inode);
  1487. f2fs_mark_inode_dirty_sync(inode, true);
  1488. }
  1489. static inline void f2fs_i_blocks_write(struct inode *inode,
  1490. blkcnt_t diff, bool add)
  1491. {
  1492. bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
  1493. bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
  1494. inode->i_blocks = add ? inode->i_blocks + diff :
  1495. inode->i_blocks - diff;
  1496. f2fs_mark_inode_dirty_sync(inode, true);
  1497. if (clean || recover)
  1498. set_inode_flag(inode, FI_AUTO_RECOVER);
  1499. }
  1500. static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
  1501. {
  1502. bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
  1503. bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
  1504. if (i_size_read(inode) == i_size)
  1505. return;
  1506. i_size_write(inode, i_size);
  1507. f2fs_mark_inode_dirty_sync(inode, true);
  1508. if (clean || recover)
  1509. set_inode_flag(inode, FI_AUTO_RECOVER);
  1510. }
  1511. static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
  1512. {
  1513. F2FS_I(inode)->i_current_depth = depth;
  1514. f2fs_mark_inode_dirty_sync(inode, true);
  1515. }
  1516. static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid)
  1517. {
  1518. F2FS_I(inode)->i_xattr_nid = xnid;
  1519. f2fs_mark_inode_dirty_sync(inode, true);
  1520. }
  1521. static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino)
  1522. {
  1523. F2FS_I(inode)->i_pino = pino;
  1524. f2fs_mark_inode_dirty_sync(inode, true);
  1525. }
  1526. static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
  1527. {
  1528. struct f2fs_inode_info *fi = F2FS_I(inode);
  1529. if (ri->i_inline & F2FS_INLINE_XATTR)
  1530. set_bit(FI_INLINE_XATTR, &fi->flags);
  1531. if (ri->i_inline & F2FS_INLINE_DATA)
  1532. set_bit(FI_INLINE_DATA, &fi->flags);
  1533. if (ri->i_inline & F2FS_INLINE_DENTRY)
  1534. set_bit(FI_INLINE_DENTRY, &fi->flags);
  1535. if (ri->i_inline & F2FS_DATA_EXIST)
  1536. set_bit(FI_DATA_EXIST, &fi->flags);
  1537. if (ri->i_inline & F2FS_INLINE_DOTS)
  1538. set_bit(FI_INLINE_DOTS, &fi->flags);
  1539. }
  1540. static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
  1541. {
  1542. ri->i_inline = 0;
  1543. if (is_inode_flag_set(inode, FI_INLINE_XATTR))
  1544. ri->i_inline |= F2FS_INLINE_XATTR;
  1545. if (is_inode_flag_set(inode, FI_INLINE_DATA))
  1546. ri->i_inline |= F2FS_INLINE_DATA;
  1547. if (is_inode_flag_set(inode, FI_INLINE_DENTRY))
  1548. ri->i_inline |= F2FS_INLINE_DENTRY;
  1549. if (is_inode_flag_set(inode, FI_DATA_EXIST))
  1550. ri->i_inline |= F2FS_DATA_EXIST;
  1551. if (is_inode_flag_set(inode, FI_INLINE_DOTS))
  1552. ri->i_inline |= F2FS_INLINE_DOTS;
  1553. }
  1554. static inline int f2fs_has_inline_xattr(struct inode *inode)
  1555. {
  1556. return is_inode_flag_set(inode, FI_INLINE_XATTR);
  1557. }
  1558. static inline unsigned int addrs_per_inode(struct inode *inode)
  1559. {
  1560. if (f2fs_has_inline_xattr(inode))
  1561. return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
  1562. return DEF_ADDRS_PER_INODE;
  1563. }
  1564. static inline void *inline_xattr_addr(struct page *page)
  1565. {
  1566. struct f2fs_inode *ri = F2FS_INODE(page);
  1567. return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
  1568. F2FS_INLINE_XATTR_ADDRS]);
  1569. }
  1570. static inline int inline_xattr_size(struct inode *inode)
  1571. {
  1572. if (f2fs_has_inline_xattr(inode))
  1573. return F2FS_INLINE_XATTR_ADDRS << 2;
  1574. else
  1575. return 0;
  1576. }
  1577. static inline int f2fs_has_inline_data(struct inode *inode)
  1578. {
  1579. return is_inode_flag_set(inode, FI_INLINE_DATA);
  1580. }
  1581. static inline void f2fs_clear_inline_inode(struct inode *inode)
  1582. {
  1583. clear_inode_flag(inode, FI_INLINE_DATA);
  1584. clear_inode_flag(inode, FI_DATA_EXIST);
  1585. }
  1586. static inline int f2fs_exist_data(struct inode *inode)
  1587. {
  1588. return is_inode_flag_set(inode, FI_DATA_EXIST);
  1589. }
  1590. static inline int f2fs_has_inline_dots(struct inode *inode)
  1591. {
  1592. return is_inode_flag_set(inode, FI_INLINE_DOTS);
  1593. }
  1594. static inline bool f2fs_is_atomic_file(struct inode *inode)
  1595. {
  1596. return is_inode_flag_set(inode, FI_ATOMIC_FILE);
  1597. }
  1598. static inline bool f2fs_is_commit_atomic_write(struct inode *inode)
  1599. {
  1600. return is_inode_flag_set(inode, FI_ATOMIC_COMMIT);
  1601. }
  1602. static inline bool f2fs_is_volatile_file(struct inode *inode)
  1603. {
  1604. return is_inode_flag_set(inode, FI_VOLATILE_FILE);
  1605. }
  1606. static inline bool f2fs_is_first_block_written(struct inode *inode)
  1607. {
  1608. return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN);
  1609. }
  1610. static inline bool f2fs_is_drop_cache(struct inode *inode)
  1611. {
  1612. return is_inode_flag_set(inode, FI_DROP_CACHE);
  1613. }
  1614. static inline void *inline_data_addr(struct page *page)
  1615. {
  1616. struct f2fs_inode *ri = F2FS_INODE(page);
  1617. return (void *)&(ri->i_addr[1]);
  1618. }
  1619. static inline int f2fs_has_inline_dentry(struct inode *inode)
  1620. {
  1621. return is_inode_flag_set(inode, FI_INLINE_DENTRY);
  1622. }
  1623. static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
  1624. {
  1625. if (!f2fs_has_inline_dentry(dir))
  1626. kunmap(page);
  1627. }
  1628. static inline int is_file(struct inode *inode, int type)
  1629. {
  1630. return F2FS_I(inode)->i_advise & type;
  1631. }
  1632. static inline void set_file(struct inode *inode, int type)
  1633. {
  1634. F2FS_I(inode)->i_advise |= type;
  1635. f2fs_mark_inode_dirty_sync(inode, true);
  1636. }
  1637. static inline void clear_file(struct inode *inode, int type)
  1638. {
  1639. F2FS_I(inode)->i_advise &= ~type;
  1640. f2fs_mark_inode_dirty_sync(inode, true);
  1641. }
  1642. static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
  1643. {
  1644. if (dsync) {
  1645. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  1646. bool ret;
  1647. spin_lock(&sbi->inode_lock[DIRTY_META]);
  1648. ret = list_empty(&F2FS_I(inode)->gdirty_list);
  1649. spin_unlock(&sbi->inode_lock[DIRTY_META]);
  1650. return ret;
  1651. }
  1652. if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
  1653. file_keep_isize(inode) ||
  1654. i_size_read(inode) & PAGE_MASK)
  1655. return false;
  1656. return F2FS_I(inode)->last_disk_size == i_size_read(inode);
  1657. }
  1658. static inline int f2fs_readonly(struct super_block *sb)
  1659. {
  1660. return sb->s_flags & MS_RDONLY;
  1661. }
  1662. static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
  1663. {
  1664. return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
  1665. }
  1666. static inline bool is_dot_dotdot(const struct qstr *str)
  1667. {
  1668. if (str->len == 1 && str->name[0] == '.')
  1669. return true;
  1670. if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
  1671. return true;
  1672. return false;
  1673. }
  1674. static inline bool f2fs_may_extent_tree(struct inode *inode)
  1675. {
  1676. if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
  1677. is_inode_flag_set(inode, FI_NO_EXTENT))
  1678. return false;
  1679. return S_ISREG(inode->i_mode);
  1680. }
  1681. static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
  1682. size_t size, gfp_t flags)
  1683. {
  1684. #ifdef CONFIG_F2FS_FAULT_INJECTION
  1685. if (time_to_inject(sbi, FAULT_KMALLOC)) {
  1686. f2fs_show_injection_info(FAULT_KMALLOC);
  1687. return NULL;
  1688. }
  1689. #endif
  1690. return kmalloc(size, flags);
  1691. }
  1692. static inline void *f2fs_kvmalloc(size_t size, gfp_t flags)
  1693. {
  1694. void *ret;
  1695. ret = kmalloc(size, flags | __GFP_NOWARN);
  1696. if (!ret)
  1697. ret = __vmalloc(size, flags, PAGE_KERNEL);
  1698. return ret;
  1699. }
  1700. static inline void *f2fs_kvzalloc(size_t size, gfp_t flags)
  1701. {
  1702. void *ret;
  1703. ret = kzalloc(size, flags | __GFP_NOWARN);
  1704. if (!ret)
  1705. ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
  1706. return ret;
  1707. }
  1708. #define get_inode_mode(i) \
  1709. ((is_inode_flag_set(i, FI_ACL_MODE)) ? \
  1710. (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
  1711. /* get offset of first page in next direct node */
  1712. #define PGOFS_OF_NEXT_DNODE(pgofs, inode) \
  1713. ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \
  1714. (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \
  1715. ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode))
  1716. /*
  1717. * file.c
  1718. */
  1719. int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
  1720. void truncate_data_blocks(struct dnode_of_data *dn);
  1721. int truncate_blocks(struct inode *inode, u64 from, bool lock);
  1722. int f2fs_truncate(struct inode *inode);
  1723. int f2fs_getattr(const struct path *path, struct kstat *stat,
  1724. u32 request_mask, unsigned int flags);
  1725. int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
  1726. int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
  1727. int truncate_data_blocks_range(struct dnode_of_data *dn, int count);
  1728. long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  1729. long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1730. /*
  1731. * inode.c
  1732. */
  1733. void f2fs_set_inode_flags(struct inode *inode);
  1734. struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
  1735. struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
  1736. int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
  1737. int update_inode(struct inode *inode, struct page *node_page);
  1738. int update_inode_page(struct inode *inode);
  1739. int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
  1740. void f2fs_evict_inode(struct inode *inode);
  1741. void handle_failed_inode(struct inode *inode);
  1742. /*
  1743. * namei.c
  1744. */
  1745. struct dentry *f2fs_get_parent(struct dentry *child);
  1746. /*
  1747. * dir.c
  1748. */
  1749. void set_de_type(struct f2fs_dir_entry *de, umode_t mode);
  1750. unsigned char get_de_type(struct f2fs_dir_entry *de);
  1751. struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname,
  1752. f2fs_hash_t namehash, int *max_slots,
  1753. struct f2fs_dentry_ptr *d);
  1754. int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
  1755. unsigned int start_pos, struct fscrypt_str *fstr);
  1756. void do_make_empty_dir(struct inode *inode, struct inode *parent,
  1757. struct f2fs_dentry_ptr *d);
  1758. struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
  1759. const struct qstr *new_name,
  1760. const struct qstr *orig_name, struct page *dpage);
  1761. void update_parent_metadata(struct inode *dir, struct inode *inode,
  1762. unsigned int current_depth);
  1763. int room_for_filename(const void *bitmap, int slots, int max_slots);
  1764. void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
  1765. struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
  1766. struct fscrypt_name *fname, struct page **res_page);
  1767. struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
  1768. const struct qstr *child, struct page **res_page);
  1769. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p);
  1770. ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
  1771. struct page **page);
  1772. void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
  1773. struct page *page, struct inode *inode);
  1774. int update_dent_inode(struct inode *inode, struct inode *to,
  1775. const struct qstr *name);
  1776. void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
  1777. const struct qstr *name, f2fs_hash_t name_hash,
  1778. unsigned int bit_pos);
  1779. int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
  1780. const struct qstr *orig_name,
  1781. struct inode *inode, nid_t ino, umode_t mode);
  1782. int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname,
  1783. struct inode *inode, nid_t ino, umode_t mode);
  1784. int __f2fs_add_link(struct inode *dir, const struct qstr *name,
  1785. struct inode *inode, nid_t ino, umode_t mode);
  1786. void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
  1787. struct inode *dir, struct inode *inode);
  1788. int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
  1789. bool f2fs_empty_dir(struct inode *dir);
  1790. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  1791. {
  1792. return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
  1793. inode, inode->i_ino, inode->i_mode);
  1794. }
  1795. /*
  1796. * super.c
  1797. */
  1798. int f2fs_inode_dirtied(struct inode *inode, bool sync);
  1799. void f2fs_inode_synced(struct inode *inode);
  1800. int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
  1801. int f2fs_sync_fs(struct super_block *sb, int sync);
  1802. extern __printf(3, 4)
  1803. void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
  1804. int sanity_check_ckpt(struct f2fs_sb_info *sbi);
  1805. /*
  1806. * hash.c
  1807. */
  1808. f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info);
  1809. /*
  1810. * node.c
  1811. */
  1812. struct dnode_of_data;
  1813. struct node_info;
  1814. bool available_free_memory(struct f2fs_sb_info *sbi, int type);
  1815. int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
  1816. bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
  1817. bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino);
  1818. void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni);
  1819. pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
  1820. int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
  1821. int truncate_inode_blocks(struct inode *inode, pgoff_t from);
  1822. int truncate_xattr_node(struct inode *inode, struct page *page);
  1823. int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino);
  1824. int remove_inode_page(struct inode *inode);
  1825. struct page *new_inode_page(struct inode *inode);
  1826. struct page *new_node_page(struct dnode_of_data *dn,
  1827. unsigned int ofs, struct page *ipage);
  1828. void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
  1829. struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
  1830. struct page *get_node_page_ra(struct page *parent, int start);
  1831. void move_node_page(struct page *node_page, int gc_type);
  1832. int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
  1833. struct writeback_control *wbc, bool atomic);
  1834. int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc);
  1835. void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
  1836. bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
  1837. void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
  1838. void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
  1839. int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
  1840. void recover_inline_xattr(struct inode *inode, struct page *page);
  1841. int recover_xattr_data(struct inode *inode, struct page *page,
  1842. block_t blkaddr);
  1843. int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
  1844. int restore_node_summary(struct f2fs_sb_info *sbi,
  1845. unsigned int segno, struct f2fs_summary_block *sum);
  1846. void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  1847. int build_node_manager(struct f2fs_sb_info *sbi);
  1848. void destroy_node_manager(struct f2fs_sb_info *sbi);
  1849. int __init create_node_manager_caches(void);
  1850. void destroy_node_manager_caches(void);
  1851. /*
  1852. * segment.c
  1853. */
  1854. void register_inmem_page(struct inode *inode, struct page *page);
  1855. void drop_inmem_pages(struct inode *inode);
  1856. int commit_inmem_pages(struct inode *inode);
  1857. void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need);
  1858. void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi);
  1859. int f2fs_issue_flush(struct f2fs_sb_info *sbi);
  1860. int create_flush_cmd_control(struct f2fs_sb_info *sbi);
  1861. void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free);
  1862. void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
  1863. bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
  1864. void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new);
  1865. void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr);
  1866. void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  1867. void release_discard_addrs(struct f2fs_sb_info *sbi);
  1868. int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
  1869. void allocate_new_segments(struct f2fs_sb_info *sbi);
  1870. int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
  1871. bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  1872. struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno);
  1873. void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr);
  1874. void write_meta_page(struct f2fs_sb_info *sbi, struct page *page);
  1875. void write_node_page(unsigned int nid, struct f2fs_io_info *fio);
  1876. void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio);
  1877. void rewrite_data_page(struct f2fs_io_info *fio);
  1878. void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
  1879. block_t old_blkaddr, block_t new_blkaddr,
  1880. bool recover_curseg, bool recover_newaddr);
  1881. void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
  1882. block_t old_addr, block_t new_addr,
  1883. unsigned char version, bool recover_curseg,
  1884. bool recover_newaddr);
  1885. void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
  1886. block_t old_blkaddr, block_t *new_blkaddr,
  1887. struct f2fs_summary *sum, int type);
  1888. void f2fs_wait_on_page_writeback(struct page *page,
  1889. enum page_type type, bool ordered);
  1890. void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi,
  1891. block_t blkaddr);
  1892. void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
  1893. void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
  1894. int lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
  1895. unsigned int val, int alloc);
  1896. void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  1897. int build_segment_manager(struct f2fs_sb_info *sbi);
  1898. void destroy_segment_manager(struct f2fs_sb_info *sbi);
  1899. int __init create_segment_manager_caches(void);
  1900. void destroy_segment_manager_caches(void);
  1901. /*
  1902. * checkpoint.c
  1903. */
  1904. void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
  1905. struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
  1906. struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
  1907. struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
  1908. bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type);
  1909. int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
  1910. int type, bool sync);
  1911. void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index);
  1912. long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
  1913. long nr_to_write);
  1914. void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
  1915. void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
  1916. void release_ino_entry(struct f2fs_sb_info *sbi, bool all);
  1917. bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode);
  1918. int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi);
  1919. int acquire_orphan_inode(struct f2fs_sb_info *sbi);
  1920. void release_orphan_inode(struct f2fs_sb_info *sbi);
  1921. void add_orphan_inode(struct inode *inode);
  1922. void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
  1923. int recover_orphan_inodes(struct f2fs_sb_info *sbi);
  1924. int get_valid_checkpoint(struct f2fs_sb_info *sbi);
  1925. void update_dirty_page(struct inode *inode, struct page *page);
  1926. void remove_dirty_inode(struct inode *inode);
  1927. int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type);
  1928. int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  1929. void init_ino_entry_info(struct f2fs_sb_info *sbi);
  1930. int __init create_checkpoint_caches(void);
  1931. void destroy_checkpoint_caches(void);
  1932. /*
  1933. * data.c
  1934. */
  1935. void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type,
  1936. int rw);
  1937. void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi,
  1938. struct inode *inode, nid_t ino, pgoff_t idx,
  1939. enum page_type type, int rw);
  1940. void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi);
  1941. int f2fs_submit_page_bio(struct f2fs_io_info *fio);
  1942. int f2fs_submit_page_mbio(struct f2fs_io_info *fio);
  1943. struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
  1944. block_t blk_addr, struct bio *bio);
  1945. int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
  1946. void set_data_blkaddr(struct dnode_of_data *dn);
  1947. void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr);
  1948. int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count);
  1949. int reserve_new_block(struct dnode_of_data *dn);
  1950. int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index);
  1951. int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from);
  1952. int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index);
  1953. struct page *get_read_data_page(struct inode *inode, pgoff_t index,
  1954. int op_flags, bool for_write);
  1955. struct page *find_data_page(struct inode *inode, pgoff_t index);
  1956. struct page *get_lock_data_page(struct inode *inode, pgoff_t index,
  1957. bool for_write);
  1958. struct page *get_new_data_page(struct inode *inode,
  1959. struct page *ipage, pgoff_t index, bool new_i_size);
  1960. int do_write_data_page(struct f2fs_io_info *fio);
  1961. int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
  1962. int create, int flag);
  1963. int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  1964. u64 start, u64 len);
  1965. void f2fs_set_page_dirty_nobuffers(struct page *page);
  1966. void f2fs_invalidate_page(struct page *page, unsigned int offset,
  1967. unsigned int length);
  1968. int f2fs_release_page(struct page *page, gfp_t wait);
  1969. #ifdef CONFIG_MIGRATION
  1970. int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
  1971. struct page *page, enum migrate_mode mode);
  1972. #endif
  1973. /*
  1974. * gc.c
  1975. */
  1976. int start_gc_thread(struct f2fs_sb_info *sbi);
  1977. void stop_gc_thread(struct f2fs_sb_info *sbi);
  1978. block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
  1979. int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background);
  1980. void build_gc_manager(struct f2fs_sb_info *sbi);
  1981. /*
  1982. * recovery.c
  1983. */
  1984. int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only);
  1985. bool space_for_roll_forward(struct f2fs_sb_info *sbi);
  1986. /*
  1987. * debug.c
  1988. */
  1989. #ifdef CONFIG_F2FS_STAT_FS
  1990. struct f2fs_stat_info {
  1991. struct list_head stat_list;
  1992. struct f2fs_sb_info *sbi;
  1993. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  1994. int main_area_segs, main_area_sections, main_area_zones;
  1995. unsigned long long hit_largest, hit_cached, hit_rbtree;
  1996. unsigned long long hit_total, total_ext;
  1997. int ext_tree, zombie_tree, ext_node;
  1998. int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta;
  1999. int inmem_pages;
  2000. unsigned int ndirty_dirs, ndirty_files, ndirty_all;
  2001. int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids;
  2002. int total_count, utilization;
  2003. int bg_gc, nr_wb_cp_data, nr_wb_data, nr_flush, nr_discard;
  2004. int inline_xattr, inline_inode, inline_dir, append, update, orphans;
  2005. int aw_cnt, max_aw_cnt;
  2006. unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
  2007. unsigned int bimodal, avg_vblocks;
  2008. int util_free, util_valid, util_invalid;
  2009. int rsvd_segs, overp_segs;
  2010. int dirty_count, node_pages, meta_pages;
  2011. int prefree_count, call_count, cp_count, bg_cp_count;
  2012. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  2013. int bg_node_segs, bg_data_segs;
  2014. int tot_blks, data_blks, node_blks;
  2015. int bg_data_blks, bg_node_blks;
  2016. int curseg[NR_CURSEG_TYPE];
  2017. int cursec[NR_CURSEG_TYPE];
  2018. int curzone[NR_CURSEG_TYPE];
  2019. unsigned int segment_count[2];
  2020. unsigned int block_count[2];
  2021. unsigned int inplace_count;
  2022. unsigned long long base_mem, cache_mem, page_mem;
  2023. };
  2024. static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
  2025. {
  2026. return (struct f2fs_stat_info *)sbi->stat_info;
  2027. }
  2028. #define stat_inc_cp_count(si) ((si)->cp_count++)
  2029. #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
  2030. #define stat_inc_call_count(si) ((si)->call_count++)
  2031. #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
  2032. #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
  2033. #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--)
  2034. #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext))
  2035. #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree))
  2036. #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest))
  2037. #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached))
  2038. #define stat_inc_inline_xattr(inode) \
  2039. do { \
  2040. if (f2fs_has_inline_xattr(inode)) \
  2041. (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \
  2042. } while (0)
  2043. #define stat_dec_inline_xattr(inode) \
  2044. do { \
  2045. if (f2fs_has_inline_xattr(inode)) \
  2046. (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \
  2047. } while (0)
  2048. #define stat_inc_inline_inode(inode) \
  2049. do { \
  2050. if (f2fs_has_inline_data(inode)) \
  2051. (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
  2052. } while (0)
  2053. #define stat_dec_inline_inode(inode) \
  2054. do { \
  2055. if (f2fs_has_inline_data(inode)) \
  2056. (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
  2057. } while (0)
  2058. #define stat_inc_inline_dir(inode) \
  2059. do { \
  2060. if (f2fs_has_inline_dentry(inode)) \
  2061. (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
  2062. } while (0)
  2063. #define stat_dec_inline_dir(inode) \
  2064. do { \
  2065. if (f2fs_has_inline_dentry(inode)) \
  2066. (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
  2067. } while (0)
  2068. #define stat_inc_seg_type(sbi, curseg) \
  2069. ((sbi)->segment_count[(curseg)->alloc_type]++)
  2070. #define stat_inc_block_count(sbi, curseg) \
  2071. ((sbi)->block_count[(curseg)->alloc_type]++)
  2072. #define stat_inc_inplace_blocks(sbi) \
  2073. (atomic_inc(&(sbi)->inplace_count))
  2074. #define stat_inc_atomic_write(inode) \
  2075. (atomic_inc(&F2FS_I_SB(inode)->aw_cnt))
  2076. #define stat_dec_atomic_write(inode) \
  2077. (atomic_dec(&F2FS_I_SB(inode)->aw_cnt))
  2078. #define stat_update_max_atomic_write(inode) \
  2079. do { \
  2080. int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \
  2081. int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \
  2082. if (cur > max) \
  2083. atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \
  2084. } while (0)
  2085. #define stat_inc_seg_count(sbi, type, gc_type) \
  2086. do { \
  2087. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  2088. (si)->tot_segs++; \
  2089. if (type == SUM_TYPE_DATA) { \
  2090. si->data_segs++; \
  2091. si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
  2092. } else { \
  2093. si->node_segs++; \
  2094. si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
  2095. } \
  2096. } while (0)
  2097. #define stat_inc_tot_blk_count(si, blks) \
  2098. (si->tot_blks += (blks))
  2099. #define stat_inc_data_blk_count(sbi, blks, gc_type) \
  2100. do { \
  2101. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  2102. stat_inc_tot_blk_count(si, blks); \
  2103. si->data_blks += (blks); \
  2104. si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \
  2105. } while (0)
  2106. #define stat_inc_node_blk_count(sbi, blks, gc_type) \
  2107. do { \
  2108. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  2109. stat_inc_tot_blk_count(si, blks); \
  2110. si->node_blks += (blks); \
  2111. si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \
  2112. } while (0)
  2113. int f2fs_build_stats(struct f2fs_sb_info *sbi);
  2114. void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
  2115. int __init f2fs_create_root_stats(void);
  2116. void f2fs_destroy_root_stats(void);
  2117. #else
  2118. #define stat_inc_cp_count(si)
  2119. #define stat_inc_bg_cp_count(si)
  2120. #define stat_inc_call_count(si)
  2121. #define stat_inc_bggc_count(si)
  2122. #define stat_inc_dirty_inode(sbi, type)
  2123. #define stat_dec_dirty_inode(sbi, type)
  2124. #define stat_inc_total_hit(sb)
  2125. #define stat_inc_rbtree_node_hit(sb)
  2126. #define stat_inc_largest_node_hit(sbi)
  2127. #define stat_inc_cached_node_hit(sbi)
  2128. #define stat_inc_inline_xattr(inode)
  2129. #define stat_dec_inline_xattr(inode)
  2130. #define stat_inc_inline_inode(inode)
  2131. #define stat_dec_inline_inode(inode)
  2132. #define stat_inc_inline_dir(inode)
  2133. #define stat_dec_inline_dir(inode)
  2134. #define stat_inc_atomic_write(inode)
  2135. #define stat_dec_atomic_write(inode)
  2136. #define stat_update_max_atomic_write(inode)
  2137. #define stat_inc_seg_type(sbi, curseg)
  2138. #define stat_inc_block_count(sbi, curseg)
  2139. #define stat_inc_inplace_blocks(sbi)
  2140. #define stat_inc_seg_count(sbi, type, gc_type)
  2141. #define stat_inc_tot_blk_count(si, blks)
  2142. #define stat_inc_data_blk_count(sbi, blks, gc_type)
  2143. #define stat_inc_node_blk_count(sbi, blks, gc_type)
  2144. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  2145. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  2146. static inline int __init f2fs_create_root_stats(void) { return 0; }
  2147. static inline void f2fs_destroy_root_stats(void) { }
  2148. #endif
  2149. extern const struct file_operations f2fs_dir_operations;
  2150. extern const struct file_operations f2fs_file_operations;
  2151. extern const struct inode_operations f2fs_file_inode_operations;
  2152. extern const struct address_space_operations f2fs_dblock_aops;
  2153. extern const struct address_space_operations f2fs_node_aops;
  2154. extern const struct address_space_operations f2fs_meta_aops;
  2155. extern const struct inode_operations f2fs_dir_inode_operations;
  2156. extern const struct inode_operations f2fs_symlink_inode_operations;
  2157. extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
  2158. extern const struct inode_operations f2fs_special_inode_operations;
  2159. extern struct kmem_cache *inode_entry_slab;
  2160. /*
  2161. * inline.c
  2162. */
  2163. bool f2fs_may_inline_data(struct inode *inode);
  2164. bool f2fs_may_inline_dentry(struct inode *inode);
  2165. void read_inline_data(struct page *page, struct page *ipage);
  2166. bool truncate_inline_inode(struct page *ipage, u64 from);
  2167. int f2fs_read_inline_data(struct inode *inode, struct page *page);
  2168. int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
  2169. int f2fs_convert_inline_inode(struct inode *inode);
  2170. int f2fs_write_inline_data(struct inode *inode, struct page *page);
  2171. bool recover_inline_data(struct inode *inode, struct page *npage);
  2172. struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
  2173. struct fscrypt_name *fname, struct page **res_page);
  2174. int make_empty_inline_dir(struct inode *inode, struct inode *parent,
  2175. struct page *ipage);
  2176. int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
  2177. const struct qstr *orig_name,
  2178. struct inode *inode, nid_t ino, umode_t mode);
  2179. void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
  2180. struct inode *dir, struct inode *inode);
  2181. bool f2fs_empty_inline_dir(struct inode *dir);
  2182. int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
  2183. struct fscrypt_str *fstr);
  2184. int f2fs_inline_data_fiemap(struct inode *inode,
  2185. struct fiemap_extent_info *fieinfo,
  2186. __u64 start, __u64 len);
  2187. /*
  2188. * shrinker.c
  2189. */
  2190. unsigned long f2fs_shrink_count(struct shrinker *shrink,
  2191. struct shrink_control *sc);
  2192. unsigned long f2fs_shrink_scan(struct shrinker *shrink,
  2193. struct shrink_control *sc);
  2194. void f2fs_join_shrinker(struct f2fs_sb_info *sbi);
  2195. void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
  2196. /*
  2197. * extent_cache.c
  2198. */
  2199. unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
  2200. bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext);
  2201. void f2fs_drop_extent_tree(struct inode *inode);
  2202. unsigned int f2fs_destroy_extent_node(struct inode *inode);
  2203. void f2fs_destroy_extent_tree(struct inode *inode);
  2204. bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
  2205. struct extent_info *ei);
  2206. void f2fs_update_extent_cache(struct dnode_of_data *dn);
  2207. void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
  2208. pgoff_t fofs, block_t blkaddr, unsigned int len);
  2209. void init_extent_cache_info(struct f2fs_sb_info *sbi);
  2210. int __init create_extent_cache(void);
  2211. void destroy_extent_cache(void);
  2212. /*
  2213. * crypto support
  2214. */
  2215. static inline bool f2fs_encrypted_inode(struct inode *inode)
  2216. {
  2217. return file_is_encrypt(inode);
  2218. }
  2219. static inline void f2fs_set_encrypted_inode(struct inode *inode)
  2220. {
  2221. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  2222. file_set_encrypt(inode);
  2223. #endif
  2224. }
  2225. static inline bool f2fs_bio_encrypted(struct bio *bio)
  2226. {
  2227. return bio->bi_private != NULL;
  2228. }
  2229. static inline int f2fs_sb_has_crypto(struct super_block *sb)
  2230. {
  2231. return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
  2232. }
  2233. static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
  2234. {
  2235. return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
  2236. }
  2237. #ifdef CONFIG_BLK_DEV_ZONED
  2238. static inline int get_blkz_type(struct f2fs_sb_info *sbi,
  2239. struct block_device *bdev, block_t blkaddr)
  2240. {
  2241. unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
  2242. int i;
  2243. for (i = 0; i < sbi->s_ndevs; i++)
  2244. if (FDEV(i).bdev == bdev)
  2245. return FDEV(i).blkz_type[zno];
  2246. return -EINVAL;
  2247. }
  2248. #endif
  2249. static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
  2250. {
  2251. struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
  2252. return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb);
  2253. }
  2254. static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
  2255. {
  2256. clear_opt(sbi, ADAPTIVE);
  2257. clear_opt(sbi, LFS);
  2258. switch (mt) {
  2259. case F2FS_MOUNT_ADAPTIVE:
  2260. set_opt(sbi, ADAPTIVE);
  2261. break;
  2262. case F2FS_MOUNT_LFS:
  2263. set_opt(sbi, LFS);
  2264. break;
  2265. }
  2266. }
  2267. static inline bool f2fs_may_encrypt(struct inode *inode)
  2268. {
  2269. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  2270. umode_t mode = inode->i_mode;
  2271. return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
  2272. #else
  2273. return 0;
  2274. #endif
  2275. }
  2276. #endif