f2fs.h 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449
  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/cred.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/bio.h>
  24. #include <linux/blkdev.h>
  25. #include <linux/quotaops.h>
  26. #include <crypto/hash.h>
  27. #define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTION)
  28. #include <linux/fscrypt.h>
  29. #ifdef CONFIG_F2FS_CHECK_FS
  30. #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
  31. #else
  32. #define f2fs_bug_on(sbi, condition) \
  33. do { \
  34. if (unlikely(condition)) { \
  35. WARN_ON(1); \
  36. set_sbi_flag(sbi, SBI_NEED_FSCK); \
  37. } \
  38. } while (0)
  39. #endif
  40. enum {
  41. FAULT_KMALLOC,
  42. FAULT_KVMALLOC,
  43. FAULT_PAGE_ALLOC,
  44. FAULT_PAGE_GET,
  45. FAULT_ALLOC_BIO,
  46. FAULT_ALLOC_NID,
  47. FAULT_ORPHAN,
  48. FAULT_BLOCK,
  49. FAULT_DIR_DEPTH,
  50. FAULT_EVICT_INODE,
  51. FAULT_TRUNCATE,
  52. FAULT_IO,
  53. FAULT_CHECKPOINT,
  54. FAULT_DISCARD,
  55. FAULT_MAX,
  56. };
  57. #ifdef CONFIG_F2FS_FAULT_INJECTION
  58. #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1)
  59. struct f2fs_fault_info {
  60. atomic_t inject_ops;
  61. unsigned int inject_rate;
  62. unsigned int inject_type;
  63. };
  64. extern char *f2fs_fault_name[FAULT_MAX];
  65. #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
  66. #endif
  67. /*
  68. * For mount options
  69. */
  70. #define F2FS_MOUNT_BG_GC 0x00000001
  71. #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
  72. #define F2FS_MOUNT_DISCARD 0x00000004
  73. #define F2FS_MOUNT_NOHEAP 0x00000008
  74. #define F2FS_MOUNT_XATTR_USER 0x00000010
  75. #define F2FS_MOUNT_POSIX_ACL 0x00000020
  76. #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
  77. #define F2FS_MOUNT_INLINE_XATTR 0x00000080
  78. #define F2FS_MOUNT_INLINE_DATA 0x00000100
  79. #define F2FS_MOUNT_INLINE_DENTRY 0x00000200
  80. #define F2FS_MOUNT_FLUSH_MERGE 0x00000400
  81. #define F2FS_MOUNT_NOBARRIER 0x00000800
  82. #define F2FS_MOUNT_FASTBOOT 0x00001000
  83. #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
  84. #define F2FS_MOUNT_FORCE_FG_GC 0x00004000
  85. #define F2FS_MOUNT_DATA_FLUSH 0x00008000
  86. #define F2FS_MOUNT_FAULT_INJECTION 0x00010000
  87. #define F2FS_MOUNT_ADAPTIVE 0x00020000
  88. #define F2FS_MOUNT_LFS 0x00040000
  89. #define F2FS_MOUNT_USRQUOTA 0x00080000
  90. #define F2FS_MOUNT_GRPQUOTA 0x00100000
  91. #define F2FS_MOUNT_PRJQUOTA 0x00200000
  92. #define F2FS_MOUNT_QUOTA 0x00400000
  93. #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000
  94. #define F2FS_MOUNT_RESERVE_ROOT 0x01000000
  95. #define F2FS_OPTION(sbi) ((sbi)->mount_opt)
  96. #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
  97. #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option)
  98. #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option)
  99. #define ver_after(a, b) (typecheck(unsigned long long, a) && \
  100. typecheck(unsigned long long, b) && \
  101. ((long long)((a) - (b)) > 0))
  102. typedef u32 block_t; /*
  103. * should not change u32, since it is the on-disk block
  104. * address format, __le32.
  105. */
  106. typedef u32 nid_t;
  107. struct f2fs_mount_info {
  108. unsigned int opt;
  109. int write_io_size_bits; /* Write IO size bits */
  110. block_t root_reserved_blocks; /* root reserved blocks */
  111. kuid_t s_resuid; /* reserved blocks for uid */
  112. kgid_t s_resgid; /* reserved blocks for gid */
  113. int active_logs; /* # of active logs */
  114. int inline_xattr_size; /* inline xattr size */
  115. #ifdef CONFIG_F2FS_FAULT_INJECTION
  116. struct f2fs_fault_info fault_info; /* For fault injection */
  117. #endif
  118. #ifdef CONFIG_QUOTA
  119. /* Names of quota files with journalled quota */
  120. char *s_qf_names[MAXQUOTAS];
  121. int s_jquota_fmt; /* Format of quota to use */
  122. #endif
  123. /* For which write hints are passed down to block layer */
  124. int whint_mode;
  125. int alloc_mode; /* segment allocation policy */
  126. int fsync_mode; /* fsync policy */
  127. bool test_dummy_encryption; /* test dummy encryption */
  128. };
  129. #define F2FS_FEATURE_ENCRYPT 0x0001
  130. #define F2FS_FEATURE_BLKZONED 0x0002
  131. #define F2FS_FEATURE_ATOMIC_WRITE 0x0004
  132. #define F2FS_FEATURE_EXTRA_ATTR 0x0008
  133. #define F2FS_FEATURE_PRJQUOTA 0x0010
  134. #define F2FS_FEATURE_INODE_CHKSUM 0x0020
  135. #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040
  136. #define F2FS_FEATURE_QUOTA_INO 0x0080
  137. #define F2FS_FEATURE_INODE_CRTIME 0x0100
  138. #define F2FS_FEATURE_LOST_FOUND 0x0200
  139. #define F2FS_FEATURE_VERITY 0x0400 /* reserved */
  140. #define F2FS_HAS_FEATURE(sb, mask) \
  141. ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
  142. #define F2FS_SET_FEATURE(sb, mask) \
  143. (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask))
  144. #define F2FS_CLEAR_FEATURE(sb, mask) \
  145. (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask))
  146. /*
  147. * Default values for user and/or group using reserved blocks
  148. */
  149. #define F2FS_DEF_RESUID 0
  150. #define F2FS_DEF_RESGID 0
  151. /*
  152. * For checkpoint manager
  153. */
  154. enum {
  155. NAT_BITMAP,
  156. SIT_BITMAP
  157. };
  158. #define CP_UMOUNT 0x00000001
  159. #define CP_FASTBOOT 0x00000002
  160. #define CP_SYNC 0x00000004
  161. #define CP_RECOVERY 0x00000008
  162. #define CP_DISCARD 0x00000010
  163. #define CP_TRIMMED 0x00000020
  164. #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi)
  165. #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */
  166. #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */
  167. #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */
  168. #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */
  169. #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */
  170. #define DEF_CP_INTERVAL 60 /* 60 secs */
  171. #define DEF_IDLE_INTERVAL 5 /* 5 secs */
  172. struct cp_control {
  173. int reason;
  174. __u64 trim_start;
  175. __u64 trim_end;
  176. __u64 trim_minlen;
  177. };
  178. /*
  179. * indicate meta/data type
  180. */
  181. enum {
  182. META_CP,
  183. META_NAT,
  184. META_SIT,
  185. META_SSA,
  186. META_POR,
  187. DATA_GENERIC,
  188. META_GENERIC,
  189. };
  190. /* for the list of ino */
  191. enum {
  192. ORPHAN_INO, /* for orphan ino list */
  193. APPEND_INO, /* for append ino list */
  194. UPDATE_INO, /* for update ino list */
  195. TRANS_DIR_INO, /* for trasactions dir ino list */
  196. FLUSH_INO, /* for multiple device flushing */
  197. MAX_INO_ENTRY, /* max. list */
  198. };
  199. struct ino_entry {
  200. struct list_head list; /* list head */
  201. nid_t ino; /* inode number */
  202. unsigned int dirty_device; /* dirty device bitmap */
  203. };
  204. /* for the list of inodes to be GCed */
  205. struct inode_entry {
  206. struct list_head list; /* list head */
  207. struct inode *inode; /* vfs inode pointer */
  208. };
  209. struct fsync_node_entry {
  210. struct list_head list; /* list head */
  211. struct page *page; /* warm node page pointer */
  212. unsigned int seq_id; /* sequence id */
  213. };
  214. /* for the bitmap indicate blocks to be discarded */
  215. struct discard_entry {
  216. struct list_head list; /* list head */
  217. block_t start_blkaddr; /* start blockaddr of current segment */
  218. unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */
  219. };
  220. /* default discard granularity of inner discard thread, unit: block count */
  221. #define DEFAULT_DISCARD_GRANULARITY 16
  222. /* max discard pend list number */
  223. #define MAX_PLIST_NUM 512
  224. #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \
  225. (MAX_PLIST_NUM - 1) : (blk_num - 1))
  226. enum {
  227. D_PREP, /* initial */
  228. D_PARTIAL, /* partially submitted */
  229. D_SUBMIT, /* all submitted */
  230. D_DONE, /* finished */
  231. };
  232. struct discard_info {
  233. block_t lstart; /* logical start address */
  234. block_t len; /* length */
  235. block_t start; /* actual start address in dev */
  236. };
  237. struct discard_cmd {
  238. struct rb_node rb_node; /* rb node located in rb-tree */
  239. union {
  240. struct {
  241. block_t lstart; /* logical start address */
  242. block_t len; /* length */
  243. block_t start; /* actual start address in dev */
  244. };
  245. struct discard_info di; /* discard info */
  246. };
  247. struct list_head list; /* command list */
  248. struct completion wait; /* compleation */
  249. struct block_device *bdev; /* bdev */
  250. unsigned short ref; /* reference count */
  251. unsigned char state; /* state */
  252. unsigned char issuing; /* issuing discard */
  253. int error; /* bio error */
  254. spinlock_t lock; /* for state/bio_ref updating */
  255. unsigned short bio_ref; /* bio reference count */
  256. };
  257. enum {
  258. DPOLICY_BG,
  259. DPOLICY_FORCE,
  260. DPOLICY_FSTRIM,
  261. DPOLICY_UMOUNT,
  262. MAX_DPOLICY,
  263. };
  264. struct discard_policy {
  265. int type; /* type of discard */
  266. unsigned int min_interval; /* used for candidates exist */
  267. unsigned int mid_interval; /* used for device busy */
  268. unsigned int max_interval; /* used for candidates not exist */
  269. unsigned int max_requests; /* # of discards issued per round */
  270. unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */
  271. bool io_aware; /* issue discard in idle time */
  272. bool sync; /* submit discard with REQ_SYNC flag */
  273. bool ordered; /* issue discard by lba order */
  274. unsigned int granularity; /* discard granularity */
  275. };
  276. struct discard_cmd_control {
  277. struct task_struct *f2fs_issue_discard; /* discard thread */
  278. struct list_head entry_list; /* 4KB discard entry list */
  279. struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */
  280. struct list_head wait_list; /* store on-flushing entries */
  281. struct list_head fstrim_list; /* in-flight discard from fstrim */
  282. wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */
  283. unsigned int discard_wake; /* to wake up discard thread */
  284. struct mutex cmd_lock;
  285. unsigned int nr_discards; /* # of discards in the list */
  286. unsigned int max_discards; /* max. discards to be issued */
  287. unsigned int discard_granularity; /* discard granularity */
  288. unsigned int undiscard_blks; /* # of undiscard blocks */
  289. unsigned int next_pos; /* next discard position */
  290. atomic_t issued_discard; /* # of issued discard */
  291. atomic_t issing_discard; /* # of issing discard */
  292. atomic_t discard_cmd_cnt; /* # of cached cmd count */
  293. struct rb_root root; /* root of discard rb-tree */
  294. bool rbtree_check; /* config for consistence check */
  295. };
  296. /* for the list of fsync inodes, used only during recovery */
  297. struct fsync_inode_entry {
  298. struct list_head list; /* list head */
  299. struct inode *inode; /* vfs inode pointer */
  300. block_t blkaddr; /* block address locating the last fsync */
  301. block_t last_dentry; /* block address locating the last dentry */
  302. };
  303. #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats))
  304. #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits))
  305. #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne)
  306. #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid)
  307. #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se)
  308. #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno)
  309. #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
  310. #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
  311. static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
  312. {
  313. int before = nats_in_cursum(journal);
  314. journal->n_nats = cpu_to_le16(before + i);
  315. return before;
  316. }
  317. static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
  318. {
  319. int before = sits_in_cursum(journal);
  320. journal->n_sits = cpu_to_le16(before + i);
  321. return before;
  322. }
  323. static inline bool __has_cursum_space(struct f2fs_journal *journal,
  324. int size, int type)
  325. {
  326. if (type == NAT_JOURNAL)
  327. return size <= MAX_NAT_JENTRIES(journal);
  328. return size <= MAX_SIT_JENTRIES(journal);
  329. }
  330. /*
  331. * ioctl commands
  332. */
  333. #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
  334. #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
  335. #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
  336. #define F2FS_IOCTL_MAGIC 0xf5
  337. #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
  338. #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
  339. #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
  340. #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
  341. #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
  342. #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32)
  343. #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7)
  344. #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \
  345. struct f2fs_defragment)
  346. #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \
  347. struct f2fs_move_range)
  348. #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \
  349. struct f2fs_flush_device)
  350. #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \
  351. struct f2fs_gc_range)
  352. #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32)
  353. #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32)
  354. #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32)
  355. #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15)
  356. #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
  357. #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
  358. #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT
  359. /*
  360. * should be same as XFS_IOC_GOINGDOWN.
  361. * Flags for going down operation used by FS_IOC_GOINGDOWN
  362. */
  363. #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
  364. #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
  365. #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
  366. #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
  367. #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */
  368. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  369. /*
  370. * ioctl commands in 32 bit emulation
  371. */
  372. #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  373. #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  374. #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION
  375. #endif
  376. #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR
  377. #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR
  378. struct f2fs_gc_range {
  379. u32 sync;
  380. u64 start;
  381. u64 len;
  382. };
  383. struct f2fs_defragment {
  384. u64 start;
  385. u64 len;
  386. };
  387. struct f2fs_move_range {
  388. u32 dst_fd; /* destination fd */
  389. u64 pos_in; /* start position in src_fd */
  390. u64 pos_out; /* start position in dst_fd */
  391. u64 len; /* size to move */
  392. };
  393. struct f2fs_flush_device {
  394. u32 dev_num; /* device number to flush */
  395. u32 segments; /* # of segments to flush */
  396. };
  397. /* for inline stuff */
  398. #define DEF_INLINE_RESERVED_SIZE 1
  399. #define DEF_MIN_INLINE_SIZE 1
  400. static inline int get_extra_isize(struct inode *inode);
  401. static inline int get_inline_xattr_addrs(struct inode *inode);
  402. #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \
  403. (CUR_ADDRS_PER_INODE(inode) - \
  404. get_inline_xattr_addrs(inode) - \
  405. DEF_INLINE_RESERVED_SIZE))
  406. /* for inline dir */
  407. #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \
  408. ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
  409. BITS_PER_BYTE + 1))
  410. #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \
  411. BITS_PER_BYTE - 1) / BITS_PER_BYTE)
  412. #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \
  413. ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
  414. NR_INLINE_DENTRY(inode) + \
  415. INLINE_DENTRY_BITMAP_SIZE(inode)))
  416. /*
  417. * For INODE and NODE manager
  418. */
  419. /* for directory operations */
  420. struct f2fs_dentry_ptr {
  421. struct inode *inode;
  422. void *bitmap;
  423. struct f2fs_dir_entry *dentry;
  424. __u8 (*filename)[F2FS_SLOT_LEN];
  425. int max;
  426. int nr_bitmap;
  427. };
  428. static inline void make_dentry_ptr_block(struct inode *inode,
  429. struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t)
  430. {
  431. d->inode = inode;
  432. d->max = NR_DENTRY_IN_BLOCK;
  433. d->nr_bitmap = SIZE_OF_DENTRY_BITMAP;
  434. d->bitmap = t->dentry_bitmap;
  435. d->dentry = t->dentry;
  436. d->filename = t->filename;
  437. }
  438. static inline void make_dentry_ptr_inline(struct inode *inode,
  439. struct f2fs_dentry_ptr *d, void *t)
  440. {
  441. int entry_cnt = NR_INLINE_DENTRY(inode);
  442. int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode);
  443. int reserved_size = INLINE_RESERVED_SIZE(inode);
  444. d->inode = inode;
  445. d->max = entry_cnt;
  446. d->nr_bitmap = bitmap_size;
  447. d->bitmap = t;
  448. d->dentry = t + bitmap_size + reserved_size;
  449. d->filename = t + bitmap_size + reserved_size +
  450. SIZE_OF_DIR_ENTRY * entry_cnt;
  451. }
  452. /*
  453. * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
  454. * as its node offset to distinguish from index node blocks.
  455. * But some bits are used to mark the node block.
  456. */
  457. #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
  458. >> OFFSET_BIT_SHIFT)
  459. enum {
  460. ALLOC_NODE, /* allocate a new node page if needed */
  461. LOOKUP_NODE, /* look up a node without readahead */
  462. LOOKUP_NODE_RA, /*
  463. * look up a node with readahead called
  464. * by get_data_block.
  465. */
  466. };
  467. #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */
  468. #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */
  469. #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
  470. /* for in-memory extent cache entry */
  471. #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
  472. /* number of extent info in extent cache we try to shrink */
  473. #define EXTENT_CACHE_SHRINK_NUMBER 128
  474. struct rb_entry {
  475. struct rb_node rb_node; /* rb node located in rb-tree */
  476. unsigned int ofs; /* start offset of the entry */
  477. unsigned int len; /* length of the entry */
  478. };
  479. struct extent_info {
  480. unsigned int fofs; /* start offset in a file */
  481. unsigned int len; /* length of the extent */
  482. u32 blk; /* start block address of the extent */
  483. };
  484. struct extent_node {
  485. struct rb_node rb_node;
  486. union {
  487. struct {
  488. unsigned int fofs;
  489. unsigned int len;
  490. u32 blk;
  491. };
  492. struct extent_info ei; /* extent info */
  493. };
  494. struct list_head list; /* node in global extent list of sbi */
  495. struct extent_tree *et; /* extent tree pointer */
  496. };
  497. struct extent_tree {
  498. nid_t ino; /* inode number */
  499. struct rb_root root; /* root of extent info rb-tree */
  500. struct extent_node *cached_en; /* recently accessed extent node */
  501. struct extent_info largest; /* largested extent info */
  502. struct list_head list; /* to be used by sbi->zombie_list */
  503. rwlock_t lock; /* protect extent info rb-tree */
  504. atomic_t node_cnt; /* # of extent node in rb-tree*/
  505. };
  506. /*
  507. * This structure is taken from ext4_map_blocks.
  508. *
  509. * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
  510. */
  511. #define F2FS_MAP_NEW (1 << BH_New)
  512. #define F2FS_MAP_MAPPED (1 << BH_Mapped)
  513. #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten)
  514. #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
  515. F2FS_MAP_UNWRITTEN)
  516. struct f2fs_map_blocks {
  517. block_t m_pblk;
  518. block_t m_lblk;
  519. unsigned int m_len;
  520. unsigned int m_flags;
  521. pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */
  522. pgoff_t *m_next_extent; /* point to next possible extent */
  523. int m_seg_type;
  524. };
  525. /* for flag in get_data_block */
  526. enum {
  527. F2FS_GET_BLOCK_DEFAULT,
  528. F2FS_GET_BLOCK_FIEMAP,
  529. F2FS_GET_BLOCK_BMAP,
  530. F2FS_GET_BLOCK_PRE_DIO,
  531. F2FS_GET_BLOCK_PRE_AIO,
  532. F2FS_GET_BLOCK_PRECACHE,
  533. };
  534. /*
  535. * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
  536. */
  537. #define FADVISE_COLD_BIT 0x01
  538. #define FADVISE_LOST_PINO_BIT 0x02
  539. #define FADVISE_ENCRYPT_BIT 0x04
  540. #define FADVISE_ENC_NAME_BIT 0x08
  541. #define FADVISE_KEEP_SIZE_BIT 0x10
  542. #define FADVISE_HOT_BIT 0x20
  543. #define FADVISE_VERITY_BIT 0x40 /* reserved */
  544. #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT)
  545. #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
  546. #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
  547. #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT)
  548. #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT)
  549. #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT)
  550. #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT)
  551. #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT)
  552. #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT)
  553. #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
  554. #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT)
  555. #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
  556. #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT)
  557. #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
  558. #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT)
  559. #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT)
  560. #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT)
  561. #define DEF_DIR_LEVEL 0
  562. enum {
  563. GC_FAILURE_PIN,
  564. GC_FAILURE_ATOMIC,
  565. MAX_GC_FAILURE
  566. };
  567. struct f2fs_inode_info {
  568. struct inode vfs_inode; /* serve a vfs inode */
  569. unsigned long i_flags; /* keep an inode flags for ioctl */
  570. unsigned char i_advise; /* use to give file attribute hints */
  571. unsigned char i_dir_level; /* use for dentry level for large dir */
  572. unsigned int i_current_depth; /* only for directory depth */
  573. /* for gc failure statistic */
  574. unsigned int i_gc_failures[MAX_GC_FAILURE];
  575. unsigned int i_pino; /* parent inode number */
  576. umode_t i_acl_mode; /* keep file acl mode temporarily */
  577. /* Use below internally in f2fs*/
  578. unsigned long flags; /* use to pass per-file flags */
  579. struct rw_semaphore i_sem; /* protect fi info */
  580. atomic_t dirty_pages; /* # of dirty pages */
  581. f2fs_hash_t chash; /* hash value of given file name */
  582. unsigned int clevel; /* maximum level of given file name */
  583. struct task_struct *task; /* lookup and create consistency */
  584. struct task_struct *cp_task; /* separate cp/wb IO stats*/
  585. nid_t i_xattr_nid; /* node id that contains xattrs */
  586. loff_t last_disk_size; /* lastly written file size */
  587. #ifdef CONFIG_QUOTA
  588. struct dquot *i_dquot[MAXQUOTAS];
  589. /* quota space reservation, managed internally by quota code */
  590. qsize_t i_reserved_quota;
  591. #endif
  592. struct list_head dirty_list; /* dirty list for dirs and files */
  593. struct list_head gdirty_list; /* linked in global dirty list */
  594. struct list_head inmem_ilist; /* list for inmem inodes */
  595. struct list_head inmem_pages; /* inmemory pages managed by f2fs */
  596. struct task_struct *inmem_task; /* store inmemory task */
  597. struct mutex inmem_lock; /* lock for inmemory pages */
  598. struct extent_tree *extent_tree; /* cached extent_tree entry */
  599. /* avoid racing between foreground op and gc */
  600. struct rw_semaphore i_gc_rwsem[2];
  601. struct rw_semaphore i_mmap_sem;
  602. struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */
  603. int i_extra_isize; /* size of extra space located in i_addr */
  604. kprojid_t i_projid; /* id for project quota */
  605. int i_inline_xattr_size; /* inline xattr size */
  606. struct timespec64 i_crtime; /* inode creation time */
  607. struct timespec64 i_disk_time[4];/* inode disk times */
  608. };
  609. static inline void get_extent_info(struct extent_info *ext,
  610. struct f2fs_extent *i_ext)
  611. {
  612. ext->fofs = le32_to_cpu(i_ext->fofs);
  613. ext->blk = le32_to_cpu(i_ext->blk);
  614. ext->len = le32_to_cpu(i_ext->len);
  615. }
  616. static inline void set_raw_extent(struct extent_info *ext,
  617. struct f2fs_extent *i_ext)
  618. {
  619. i_ext->fofs = cpu_to_le32(ext->fofs);
  620. i_ext->blk = cpu_to_le32(ext->blk);
  621. i_ext->len = cpu_to_le32(ext->len);
  622. }
  623. static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
  624. u32 blk, unsigned int len)
  625. {
  626. ei->fofs = fofs;
  627. ei->blk = blk;
  628. ei->len = len;
  629. }
  630. static inline bool __is_discard_mergeable(struct discard_info *back,
  631. struct discard_info *front, unsigned int max_len)
  632. {
  633. return (back->lstart + back->len == front->lstart) &&
  634. (back->len + front->len <= max_len);
  635. }
  636. static inline bool __is_discard_back_mergeable(struct discard_info *cur,
  637. struct discard_info *back, unsigned int max_len)
  638. {
  639. return __is_discard_mergeable(back, cur, max_len);
  640. }
  641. static inline bool __is_discard_front_mergeable(struct discard_info *cur,
  642. struct discard_info *front, unsigned int max_len)
  643. {
  644. return __is_discard_mergeable(cur, front, max_len);
  645. }
  646. static inline bool __is_extent_mergeable(struct extent_info *back,
  647. struct extent_info *front)
  648. {
  649. return (back->fofs + back->len == front->fofs &&
  650. back->blk + back->len == front->blk);
  651. }
  652. static inline bool __is_back_mergeable(struct extent_info *cur,
  653. struct extent_info *back)
  654. {
  655. return __is_extent_mergeable(back, cur);
  656. }
  657. static inline bool __is_front_mergeable(struct extent_info *cur,
  658. struct extent_info *front)
  659. {
  660. return __is_extent_mergeable(cur, front);
  661. }
  662. extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync);
  663. static inline void __try_update_largest_extent(struct inode *inode,
  664. struct extent_tree *et, struct extent_node *en)
  665. {
  666. if (en->ei.len > et->largest.len) {
  667. et->largest = en->ei;
  668. f2fs_mark_inode_dirty_sync(inode, true);
  669. }
  670. }
  671. /*
  672. * For free nid management
  673. */
  674. enum nid_state {
  675. FREE_NID, /* newly added to free nid list */
  676. PREALLOC_NID, /* it is preallocated */
  677. MAX_NID_STATE,
  678. };
  679. struct f2fs_nm_info {
  680. block_t nat_blkaddr; /* base disk address of NAT */
  681. nid_t max_nid; /* maximum possible node ids */
  682. nid_t available_nids; /* # of available node ids */
  683. nid_t next_scan_nid; /* the next nid to be scanned */
  684. unsigned int ram_thresh; /* control the memory footprint */
  685. unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */
  686. unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */
  687. /* NAT cache management */
  688. struct radix_tree_root nat_root;/* root of the nat entry cache */
  689. struct radix_tree_root nat_set_root;/* root of the nat set cache */
  690. struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
  691. struct list_head nat_entries; /* cached nat entry list (clean) */
  692. spinlock_t nat_list_lock; /* protect clean nat entry list */
  693. unsigned int nat_cnt; /* the # of cached nat entries */
  694. unsigned int dirty_nat_cnt; /* total num of nat entries in set */
  695. unsigned int nat_blocks; /* # of nat blocks */
  696. /* free node ids management */
  697. struct radix_tree_root free_nid_root;/* root of the free_nid cache */
  698. struct list_head free_nid_list; /* list for free nids excluding preallocated nids */
  699. unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */
  700. spinlock_t nid_list_lock; /* protect nid lists ops */
  701. struct mutex build_lock; /* lock for build free nids */
  702. unsigned char **free_nid_bitmap;
  703. unsigned char *nat_block_bitmap;
  704. unsigned short *free_nid_count; /* free nid count of NAT block */
  705. /* for checkpoint */
  706. char *nat_bitmap; /* NAT bitmap pointer */
  707. unsigned int nat_bits_blocks; /* # of nat bits blocks */
  708. unsigned char *nat_bits; /* NAT bits blocks */
  709. unsigned char *full_nat_bits; /* full NAT pages */
  710. unsigned char *empty_nat_bits; /* empty NAT pages */
  711. #ifdef CONFIG_F2FS_CHECK_FS
  712. char *nat_bitmap_mir; /* NAT bitmap mirror */
  713. #endif
  714. int bitmap_size; /* bitmap size */
  715. };
  716. /*
  717. * this structure is used as one of function parameters.
  718. * all the information are dedicated to a given direct node block determined
  719. * by the data offset in a file.
  720. */
  721. struct dnode_of_data {
  722. struct inode *inode; /* vfs inode pointer */
  723. struct page *inode_page; /* its inode page, NULL is possible */
  724. struct page *node_page; /* cached direct node page */
  725. nid_t nid; /* node id of the direct node block */
  726. unsigned int ofs_in_node; /* data offset in the node page */
  727. bool inode_page_locked; /* inode page is locked or not */
  728. bool node_changed; /* is node block changed */
  729. char cur_level; /* level of hole node page */
  730. char max_level; /* level of current page located */
  731. block_t data_blkaddr; /* block address of the node block */
  732. };
  733. static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  734. struct page *ipage, struct page *npage, nid_t nid)
  735. {
  736. memset(dn, 0, sizeof(*dn));
  737. dn->inode = inode;
  738. dn->inode_page = ipage;
  739. dn->node_page = npage;
  740. dn->nid = nid;
  741. }
  742. /*
  743. * For SIT manager
  744. *
  745. * By default, there are 6 active log areas across the whole main area.
  746. * When considering hot and cold data separation to reduce cleaning overhead,
  747. * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
  748. * respectively.
  749. * In the current design, you should not change the numbers intentionally.
  750. * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
  751. * logs individually according to the underlying devices. (default: 6)
  752. * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
  753. * data and 8 for node logs.
  754. */
  755. #define NR_CURSEG_DATA_TYPE (3)
  756. #define NR_CURSEG_NODE_TYPE (3)
  757. #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  758. enum {
  759. CURSEG_HOT_DATA = 0, /* directory entry blocks */
  760. CURSEG_WARM_DATA, /* data blocks */
  761. CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
  762. CURSEG_HOT_NODE, /* direct node blocks of directory files */
  763. CURSEG_WARM_NODE, /* direct node blocks of normal files */
  764. CURSEG_COLD_NODE, /* indirect node blocks */
  765. NO_CHECK_TYPE,
  766. };
  767. struct flush_cmd {
  768. struct completion wait;
  769. struct llist_node llnode;
  770. nid_t ino;
  771. int ret;
  772. };
  773. struct flush_cmd_control {
  774. struct task_struct *f2fs_issue_flush; /* flush thread */
  775. wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
  776. atomic_t issued_flush; /* # of issued flushes */
  777. atomic_t issing_flush; /* # of issing flushes */
  778. struct llist_head issue_list; /* list for command issue */
  779. struct llist_node *dispatch_list; /* list for command dispatch */
  780. };
  781. struct f2fs_sm_info {
  782. struct sit_info *sit_info; /* whole segment information */
  783. struct free_segmap_info *free_info; /* free segment information */
  784. struct dirty_seglist_info *dirty_info; /* dirty segment information */
  785. struct curseg_info *curseg_array; /* active segment information */
  786. struct rw_semaphore curseg_lock; /* for preventing curseg change */
  787. block_t seg0_blkaddr; /* block address of 0'th segment */
  788. block_t main_blkaddr; /* start block address of main area */
  789. block_t ssa_blkaddr; /* start block address of SSA area */
  790. unsigned int segment_count; /* total # of segments */
  791. unsigned int main_segments; /* # of segments in main area */
  792. unsigned int reserved_segments; /* # of reserved segments */
  793. unsigned int ovp_segments; /* # of overprovision segments */
  794. /* a threshold to reclaim prefree segments */
  795. unsigned int rec_prefree_segments;
  796. /* for batched trimming */
  797. unsigned int trim_sections; /* # of sections to trim */
  798. struct list_head sit_entry_set; /* sit entry set list */
  799. unsigned int ipu_policy; /* in-place-update policy */
  800. unsigned int min_ipu_util; /* in-place-update threshold */
  801. unsigned int min_fsync_blocks; /* threshold for fsync */
  802. unsigned int min_seq_blocks; /* threshold for sequential blocks */
  803. unsigned int min_hot_blocks; /* threshold for hot block allocation */
  804. unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */
  805. /* for flush command control */
  806. struct flush_cmd_control *fcc_info;
  807. /* for discard command control */
  808. struct discard_cmd_control *dcc_info;
  809. };
  810. /*
  811. * For superblock
  812. */
  813. /*
  814. * COUNT_TYPE for monitoring
  815. *
  816. * f2fs monitors the number of several block types such as on-writeback,
  817. * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
  818. */
  819. #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
  820. enum count_type {
  821. F2FS_DIRTY_DENTS,
  822. F2FS_DIRTY_DATA,
  823. F2FS_DIRTY_QDATA,
  824. F2FS_DIRTY_NODES,
  825. F2FS_DIRTY_META,
  826. F2FS_INMEM_PAGES,
  827. F2FS_DIRTY_IMETA,
  828. F2FS_WB_CP_DATA,
  829. F2FS_WB_DATA,
  830. NR_COUNT_TYPE,
  831. };
  832. /*
  833. * The below are the page types of bios used in submit_bio().
  834. * The available types are:
  835. * DATA User data pages. It operates as async mode.
  836. * NODE Node pages. It operates as async mode.
  837. * META FS metadata pages such as SIT, NAT, CP.
  838. * NR_PAGE_TYPE The number of page types.
  839. * META_FLUSH Make sure the previous pages are written
  840. * with waiting the bio's completion
  841. * ... Only can be used with META.
  842. */
  843. #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
  844. enum page_type {
  845. DATA,
  846. NODE,
  847. META,
  848. NR_PAGE_TYPE,
  849. META_FLUSH,
  850. INMEM, /* the below types are used by tracepoints only. */
  851. INMEM_DROP,
  852. INMEM_INVALIDATE,
  853. INMEM_REVOKE,
  854. IPU,
  855. OPU,
  856. };
  857. enum temp_type {
  858. HOT = 0, /* must be zero for meta bio */
  859. WARM,
  860. COLD,
  861. NR_TEMP_TYPE,
  862. };
  863. enum need_lock_type {
  864. LOCK_REQ = 0,
  865. LOCK_DONE,
  866. LOCK_RETRY,
  867. };
  868. enum cp_reason_type {
  869. CP_NO_NEEDED,
  870. CP_NON_REGULAR,
  871. CP_HARDLINK,
  872. CP_SB_NEED_CP,
  873. CP_WRONG_PINO,
  874. CP_NO_SPC_ROLL,
  875. CP_NODE_NEED_CP,
  876. CP_FASTBOOT_MODE,
  877. CP_SPEC_LOG_NUM,
  878. CP_RECOVER_DIR,
  879. };
  880. enum iostat_type {
  881. APP_DIRECT_IO, /* app direct IOs */
  882. APP_BUFFERED_IO, /* app buffered IOs */
  883. APP_WRITE_IO, /* app write IOs */
  884. APP_MAPPED_IO, /* app mapped IOs */
  885. FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */
  886. FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */
  887. FS_META_IO, /* meta IOs from kworker/reclaimer */
  888. FS_GC_DATA_IO, /* data IOs from forground gc */
  889. FS_GC_NODE_IO, /* node IOs from forground gc */
  890. FS_CP_DATA_IO, /* data IOs from checkpoint */
  891. FS_CP_NODE_IO, /* node IOs from checkpoint */
  892. FS_CP_META_IO, /* meta IOs from checkpoint */
  893. FS_DISCARD, /* discard */
  894. NR_IO_TYPE,
  895. };
  896. struct f2fs_io_info {
  897. struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
  898. nid_t ino; /* inode number */
  899. enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
  900. enum temp_type temp; /* contains HOT/WARM/COLD */
  901. int op; /* contains REQ_OP_ */
  902. int op_flags; /* req_flag_bits */
  903. block_t new_blkaddr; /* new block address to be written */
  904. block_t old_blkaddr; /* old block address before Cow */
  905. struct page *page; /* page to be written */
  906. struct page *encrypted_page; /* encrypted page */
  907. struct list_head list; /* serialize IOs */
  908. bool submitted; /* indicate IO submission */
  909. int need_lock; /* indicate we need to lock cp_rwsem */
  910. bool in_list; /* indicate fio is in io_list */
  911. bool is_meta; /* indicate borrow meta inode mapping or not */
  912. bool retry; /* need to reallocate block address */
  913. enum iostat_type io_type; /* io type */
  914. struct writeback_control *io_wbc; /* writeback control */
  915. unsigned char version; /* version of the node */
  916. };
  917. #define is_read_io(rw) ((rw) == READ)
  918. struct f2fs_bio_info {
  919. struct f2fs_sb_info *sbi; /* f2fs superblock */
  920. struct bio *bio; /* bios to merge */
  921. sector_t last_block_in_bio; /* last block number */
  922. struct f2fs_io_info fio; /* store buffered io info. */
  923. struct rw_semaphore io_rwsem; /* blocking op for bio */
  924. spinlock_t io_lock; /* serialize DATA/NODE IOs */
  925. struct list_head io_list; /* track fios */
  926. };
  927. #define FDEV(i) (sbi->devs[i])
  928. #define RDEV(i) (raw_super->devs[i])
  929. struct f2fs_dev_info {
  930. struct block_device *bdev;
  931. char path[MAX_PATH_LEN];
  932. unsigned int total_segments;
  933. block_t start_blk;
  934. block_t end_blk;
  935. #ifdef CONFIG_BLK_DEV_ZONED
  936. unsigned int nr_blkz; /* Total number of zones */
  937. u8 *blkz_type; /* Array of zones type */
  938. #endif
  939. };
  940. enum inode_type {
  941. DIR_INODE, /* for dirty dir inode */
  942. FILE_INODE, /* for dirty regular/symlink inode */
  943. DIRTY_META, /* for all dirtied inode metadata */
  944. ATOMIC_FILE, /* for all atomic files */
  945. NR_INODE_TYPE,
  946. };
  947. /* for inner inode cache management */
  948. struct inode_management {
  949. struct radix_tree_root ino_root; /* ino entry array */
  950. spinlock_t ino_lock; /* for ino entry lock */
  951. struct list_head ino_list; /* inode list head */
  952. unsigned long ino_num; /* number of entries */
  953. };
  954. /* For s_flag in struct f2fs_sb_info */
  955. enum {
  956. SBI_IS_DIRTY, /* dirty flag for checkpoint */
  957. SBI_IS_CLOSE, /* specify unmounting */
  958. SBI_NEED_FSCK, /* need fsck.f2fs to fix */
  959. SBI_POR_DOING, /* recovery is doing or not */
  960. SBI_NEED_SB_WRITE, /* need to recover superblock */
  961. SBI_NEED_CP, /* need to checkpoint */
  962. SBI_IS_SHUTDOWN, /* shutdown by ioctl */
  963. };
  964. enum {
  965. CP_TIME,
  966. REQ_TIME,
  967. MAX_TIME,
  968. };
  969. enum {
  970. GC_NORMAL,
  971. GC_IDLE_CB,
  972. GC_IDLE_GREEDY,
  973. GC_URGENT,
  974. };
  975. enum {
  976. WHINT_MODE_OFF, /* not pass down write hints */
  977. WHINT_MODE_USER, /* try to pass down hints given by users */
  978. WHINT_MODE_FS, /* pass down hints with F2FS policy */
  979. };
  980. enum {
  981. ALLOC_MODE_DEFAULT, /* stay default */
  982. ALLOC_MODE_REUSE, /* reuse segments as much as possible */
  983. };
  984. enum fsync_mode {
  985. FSYNC_MODE_POSIX, /* fsync follows posix semantics */
  986. FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */
  987. FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */
  988. };
  989. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  990. #define DUMMY_ENCRYPTION_ENABLED(sbi) \
  991. (unlikely(F2FS_OPTION(sbi).test_dummy_encryption))
  992. #else
  993. #define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
  994. #endif
  995. struct f2fs_sb_info {
  996. struct super_block *sb; /* pointer to VFS super block */
  997. struct proc_dir_entry *s_proc; /* proc entry */
  998. struct f2fs_super_block *raw_super; /* raw super block pointer */
  999. struct rw_semaphore sb_lock; /* lock for raw super block */
  1000. int valid_super_block; /* valid super block no */
  1001. unsigned long s_flag; /* flags for sbi */
  1002. struct mutex writepages; /* mutex for writepages() */
  1003. #ifdef CONFIG_BLK_DEV_ZONED
  1004. unsigned int blocks_per_blkz; /* F2FS blocks per zone */
  1005. unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */
  1006. #endif
  1007. /* for node-related operations */
  1008. struct f2fs_nm_info *nm_info; /* node manager */
  1009. struct inode *node_inode; /* cache node blocks */
  1010. /* for segment-related operations */
  1011. struct f2fs_sm_info *sm_info; /* segment manager */
  1012. /* for bio operations */
  1013. struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */
  1014. struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE];
  1015. /* bio ordering for NODE/DATA */
  1016. /* keep migration IO order for LFS mode */
  1017. struct rw_semaphore io_order_lock;
  1018. mempool_t *write_io_dummy; /* Dummy pages */
  1019. /* for checkpoint */
  1020. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  1021. int cur_cp_pack; /* remain current cp pack */
  1022. spinlock_t cp_lock; /* for flag in ckpt */
  1023. struct inode *meta_inode; /* cache meta blocks */
  1024. struct mutex cp_mutex; /* checkpoint procedure lock */
  1025. struct rw_semaphore cp_rwsem; /* blocking FS operations */
  1026. struct rw_semaphore node_write; /* locking node writes */
  1027. struct rw_semaphore node_change; /* locking node change */
  1028. wait_queue_head_t cp_wait;
  1029. unsigned long last_time[MAX_TIME]; /* to store time in jiffies */
  1030. long interval_time[MAX_TIME]; /* to store thresholds */
  1031. struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
  1032. spinlock_t fsync_node_lock; /* for node entry lock */
  1033. struct list_head fsync_node_list; /* node list head */
  1034. unsigned int fsync_seg_id; /* sequence id */
  1035. unsigned int fsync_node_num; /* number of node entries */
  1036. /* for orphan inode, use 0'th array */
  1037. unsigned int max_orphans; /* max orphan inodes */
  1038. /* for inode management */
  1039. struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */
  1040. spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */
  1041. /* for extent tree cache */
  1042. struct radix_tree_root extent_tree_root;/* cache extent cache entries */
  1043. struct mutex extent_tree_lock; /* locking extent radix tree */
  1044. struct list_head extent_list; /* lru list for shrinker */
  1045. spinlock_t extent_lock; /* locking extent lru list */
  1046. atomic_t total_ext_tree; /* extent tree count */
  1047. struct list_head zombie_list; /* extent zombie tree list */
  1048. atomic_t total_zombie_tree; /* extent zombie tree count */
  1049. atomic_t total_ext_node; /* extent info count */
  1050. /* basic filesystem units */
  1051. unsigned int log_sectors_per_block; /* log2 sectors per block */
  1052. unsigned int log_blocksize; /* log2 block size */
  1053. unsigned int blocksize; /* block size */
  1054. unsigned int root_ino_num; /* root inode number*/
  1055. unsigned int node_ino_num; /* node inode number*/
  1056. unsigned int meta_ino_num; /* meta inode number*/
  1057. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  1058. unsigned int blocks_per_seg; /* blocks per segment */
  1059. unsigned int segs_per_sec; /* segments per section */
  1060. unsigned int secs_per_zone; /* sections per zone */
  1061. unsigned int total_sections; /* total section count */
  1062. unsigned int total_node_count; /* total node block count */
  1063. unsigned int total_valid_node_count; /* valid node block count */
  1064. loff_t max_file_blocks; /* max block index of file */
  1065. int dir_level; /* directory level */
  1066. unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */
  1067. int readdir_ra; /* readahead inode in readdir */
  1068. block_t user_block_count; /* # of user blocks */
  1069. block_t total_valid_block_count; /* # of valid blocks */
  1070. block_t discard_blks; /* discard command candidats */
  1071. block_t last_valid_block_count; /* for recovery */
  1072. block_t reserved_blocks; /* configurable reserved blocks */
  1073. block_t current_reserved_blocks; /* current reserved blocks */
  1074. unsigned int nquota_files; /* # of quota sysfile */
  1075. u32 s_next_generation; /* for NFS support */
  1076. /* # of pages, see count_type */
  1077. atomic_t nr_pages[NR_COUNT_TYPE];
  1078. /* # of allocated blocks */
  1079. struct percpu_counter alloc_valid_block_count;
  1080. /* writeback control */
  1081. atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */
  1082. /* valid inode count */
  1083. struct percpu_counter total_valid_inode_count;
  1084. struct f2fs_mount_info mount_opt; /* mount options */
  1085. /* for cleaning operations */
  1086. struct mutex gc_mutex; /* mutex for GC */
  1087. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  1088. unsigned int cur_victim_sec; /* current victim section num */
  1089. unsigned int gc_mode; /* current GC state */
  1090. /* for skip statistic */
  1091. unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */
  1092. unsigned long long skipped_gc_rwsem; /* FG_GC only */
  1093. /* threshold for gc trials on pinned files */
  1094. u64 gc_pin_file_threshold;
  1095. /* maximum # of trials to find a victim segment for SSR and GC */
  1096. unsigned int max_victim_search;
  1097. /*
  1098. * for stat information.
  1099. * one is for the LFS mode, and the other is for the SSR mode.
  1100. */
  1101. #ifdef CONFIG_F2FS_STAT_FS
  1102. struct f2fs_stat_info *stat_info; /* FS status information */
  1103. unsigned int segment_count[2]; /* # of allocated segments */
  1104. unsigned int block_count[2]; /* # of allocated blocks */
  1105. atomic_t inplace_count; /* # of inplace update */
  1106. atomic64_t total_hit_ext; /* # of lookup extent cache */
  1107. atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */
  1108. atomic64_t read_hit_largest; /* # of hit largest extent node */
  1109. atomic64_t read_hit_cached; /* # of hit cached extent node */
  1110. atomic_t inline_xattr; /* # of inline_xattr inodes */
  1111. atomic_t inline_inode; /* # of inline_data inodes */
  1112. atomic_t inline_dir; /* # of inline_dentry inodes */
  1113. atomic_t aw_cnt; /* # of atomic writes */
  1114. atomic_t vw_cnt; /* # of volatile writes */
  1115. atomic_t max_aw_cnt; /* max # of atomic writes */
  1116. atomic_t max_vw_cnt; /* max # of volatile writes */
  1117. int bg_gc; /* background gc calls */
  1118. unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */
  1119. #endif
  1120. spinlock_t stat_lock; /* lock for stat operations */
  1121. /* For app/fs IO statistics */
  1122. spinlock_t iostat_lock;
  1123. unsigned long long write_iostat[NR_IO_TYPE];
  1124. bool iostat_enable;
  1125. /* For sysfs suppport */
  1126. struct kobject s_kobj;
  1127. struct completion s_kobj_unregister;
  1128. /* For shrinker support */
  1129. struct list_head s_list;
  1130. int s_ndevs; /* number of devices */
  1131. struct f2fs_dev_info *devs; /* for device list */
  1132. unsigned int dirty_device; /* for checkpoint data flush */
  1133. spinlock_t dev_lock; /* protect dirty_device */
  1134. struct mutex umount_mutex;
  1135. unsigned int shrinker_run_no;
  1136. /* For write statistics */
  1137. u64 sectors_written_start;
  1138. u64 kbytes_written;
  1139. /* Reference to checksum algorithm driver via cryptoapi */
  1140. struct crypto_shash *s_chksum_driver;
  1141. /* Precomputed FS UUID checksum for seeding other checksums */
  1142. __u32 s_chksum_seed;
  1143. };
  1144. #ifdef CONFIG_F2FS_FAULT_INJECTION
  1145. #define f2fs_show_injection_info(type) \
  1146. printk("%sF2FS-fs : inject %s in %s of %pF\n", \
  1147. KERN_INFO, f2fs_fault_name[type], \
  1148. __func__, __builtin_return_address(0))
  1149. static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
  1150. {
  1151. struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
  1152. if (!ffi->inject_rate)
  1153. return false;
  1154. if (!IS_FAULT_SET(ffi, type))
  1155. return false;
  1156. atomic_inc(&ffi->inject_ops);
  1157. if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
  1158. atomic_set(&ffi->inject_ops, 0);
  1159. return true;
  1160. }
  1161. return false;
  1162. }
  1163. #else
  1164. #define f2fs_show_injection_info(type) do { } while (0)
  1165. static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
  1166. {
  1167. return false;
  1168. }
  1169. #endif
  1170. /* For write statistics. Suppose sector size is 512 bytes,
  1171. * and the return value is in kbytes. s is of struct f2fs_sb_info.
  1172. */
  1173. #define BD_PART_WRITTEN(s) \
  1174. (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \
  1175. (s)->sectors_written_start) >> 1)
  1176. static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
  1177. {
  1178. sbi->last_time[type] = jiffies;
  1179. }
  1180. static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
  1181. {
  1182. unsigned long interval = sbi->interval_time[type] * HZ;
  1183. return time_after(jiffies, sbi->last_time[type] + interval);
  1184. }
  1185. static inline bool is_idle(struct f2fs_sb_info *sbi)
  1186. {
  1187. struct block_device *bdev = sbi->sb->s_bdev;
  1188. struct request_queue *q = bdev_get_queue(bdev);
  1189. struct request_list *rl = &q->root_rl;
  1190. if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
  1191. return false;
  1192. return f2fs_time_over(sbi, REQ_TIME);
  1193. }
  1194. /*
  1195. * Inline functions
  1196. */
  1197. static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc,
  1198. const void *address, unsigned int length)
  1199. {
  1200. struct {
  1201. struct shash_desc shash;
  1202. char ctx[4];
  1203. } desc;
  1204. int err;
  1205. BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx));
  1206. desc.shash.tfm = sbi->s_chksum_driver;
  1207. desc.shash.flags = 0;
  1208. *(u32 *)desc.ctx = crc;
  1209. err = crypto_shash_update(&desc.shash, address, length);
  1210. BUG_ON(err);
  1211. return *(u32 *)desc.ctx;
  1212. }
  1213. static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
  1214. unsigned int length)
  1215. {
  1216. return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length);
  1217. }
  1218. static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
  1219. void *buf, size_t buf_size)
  1220. {
  1221. return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
  1222. }
  1223. static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
  1224. const void *address, unsigned int length)
  1225. {
  1226. return __f2fs_crc32(sbi, crc, address, length);
  1227. }
  1228. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  1229. {
  1230. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  1231. }
  1232. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  1233. {
  1234. return sb->s_fs_info;
  1235. }
  1236. static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
  1237. {
  1238. return F2FS_SB(inode->i_sb);
  1239. }
  1240. static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
  1241. {
  1242. return F2FS_I_SB(mapping->host);
  1243. }
  1244. static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
  1245. {
  1246. return F2FS_M_SB(page->mapping);
  1247. }
  1248. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  1249. {
  1250. return (struct f2fs_super_block *)(sbi->raw_super);
  1251. }
  1252. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  1253. {
  1254. return (struct f2fs_checkpoint *)(sbi->ckpt);
  1255. }
  1256. static inline struct f2fs_node *F2FS_NODE(struct page *page)
  1257. {
  1258. return (struct f2fs_node *)page_address(page);
  1259. }
  1260. static inline struct f2fs_inode *F2FS_INODE(struct page *page)
  1261. {
  1262. return &((struct f2fs_node *)page_address(page))->i;
  1263. }
  1264. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  1265. {
  1266. return (struct f2fs_nm_info *)(sbi->nm_info);
  1267. }
  1268. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  1269. {
  1270. return (struct f2fs_sm_info *)(sbi->sm_info);
  1271. }
  1272. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  1273. {
  1274. return (struct sit_info *)(SM_I(sbi)->sit_info);
  1275. }
  1276. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  1277. {
  1278. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  1279. }
  1280. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  1281. {
  1282. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  1283. }
  1284. static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
  1285. {
  1286. return sbi->meta_inode->i_mapping;
  1287. }
  1288. static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
  1289. {
  1290. return sbi->node_inode->i_mapping;
  1291. }
  1292. static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  1293. {
  1294. return test_bit(type, &sbi->s_flag);
  1295. }
  1296. static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  1297. {
  1298. set_bit(type, &sbi->s_flag);
  1299. }
  1300. static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  1301. {
  1302. clear_bit(type, &sbi->s_flag);
  1303. }
  1304. static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
  1305. {
  1306. return le64_to_cpu(cp->checkpoint_ver);
  1307. }
  1308. static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type)
  1309. {
  1310. if (type < F2FS_MAX_QUOTAS)
  1311. return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]);
  1312. return 0;
  1313. }
  1314. static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
  1315. {
  1316. size_t crc_offset = le32_to_cpu(cp->checksum_offset);
  1317. return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
  1318. }
  1319. static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  1320. {
  1321. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  1322. return ckpt_flags & f;
  1323. }
  1324. static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
  1325. {
  1326. return __is_set_ckpt_flags(F2FS_CKPT(sbi), f);
  1327. }
  1328. static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  1329. {
  1330. unsigned int ckpt_flags;
  1331. ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  1332. ckpt_flags |= f;
  1333. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  1334. }
  1335. static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
  1336. {
  1337. unsigned long flags;
  1338. spin_lock_irqsave(&sbi->cp_lock, flags);
  1339. __set_ckpt_flags(F2FS_CKPT(sbi), f);
  1340. spin_unlock_irqrestore(&sbi->cp_lock, flags);
  1341. }
  1342. static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  1343. {
  1344. unsigned int ckpt_flags;
  1345. ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  1346. ckpt_flags &= (~f);
  1347. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  1348. }
  1349. static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
  1350. {
  1351. unsigned long flags;
  1352. spin_lock_irqsave(&sbi->cp_lock, flags);
  1353. __clear_ckpt_flags(F2FS_CKPT(sbi), f);
  1354. spin_unlock_irqrestore(&sbi->cp_lock, flags);
  1355. }
  1356. static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
  1357. {
  1358. unsigned long flags;
  1359. set_sbi_flag(sbi, SBI_NEED_FSCK);
  1360. if (lock)
  1361. spin_lock_irqsave(&sbi->cp_lock, flags);
  1362. __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
  1363. kfree(NM_I(sbi)->nat_bits);
  1364. NM_I(sbi)->nat_bits = NULL;
  1365. if (lock)
  1366. spin_unlock_irqrestore(&sbi->cp_lock, flags);
  1367. }
  1368. static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
  1369. struct cp_control *cpc)
  1370. {
  1371. bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
  1372. return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
  1373. }
  1374. static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
  1375. {
  1376. down_read(&sbi->cp_rwsem);
  1377. }
  1378. static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
  1379. {
  1380. return down_read_trylock(&sbi->cp_rwsem);
  1381. }
  1382. static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
  1383. {
  1384. up_read(&sbi->cp_rwsem);
  1385. }
  1386. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  1387. {
  1388. down_write(&sbi->cp_rwsem);
  1389. }
  1390. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  1391. {
  1392. up_write(&sbi->cp_rwsem);
  1393. }
  1394. static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
  1395. {
  1396. int reason = CP_SYNC;
  1397. if (test_opt(sbi, FASTBOOT))
  1398. reason = CP_FASTBOOT;
  1399. if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
  1400. reason = CP_UMOUNT;
  1401. return reason;
  1402. }
  1403. static inline bool __remain_node_summaries(int reason)
  1404. {
  1405. return (reason & (CP_UMOUNT | CP_FASTBOOT));
  1406. }
  1407. static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
  1408. {
  1409. return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) ||
  1410. is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG));
  1411. }
  1412. /*
  1413. * Check whether the inode has blocks or not
  1414. */
  1415. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  1416. {
  1417. block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
  1418. return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block;
  1419. }
  1420. static inline bool f2fs_has_xattr_block(unsigned int ofs)
  1421. {
  1422. return ofs == XATTR_NODE_OFFSET;
  1423. }
  1424. static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi,
  1425. struct inode *inode, bool cap)
  1426. {
  1427. if (!inode)
  1428. return true;
  1429. if (!test_opt(sbi, RESERVE_ROOT))
  1430. return false;
  1431. if (IS_NOQUOTA(inode))
  1432. return true;
  1433. if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid()))
  1434. return true;
  1435. if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) &&
  1436. in_group_p(F2FS_OPTION(sbi).s_resgid))
  1437. return true;
  1438. if (cap && capable(CAP_SYS_RESOURCE))
  1439. return true;
  1440. return false;
  1441. }
  1442. static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
  1443. static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
  1444. struct inode *inode, blkcnt_t *count)
  1445. {
  1446. blkcnt_t diff = 0, release = 0;
  1447. block_t avail_user_block_count;
  1448. int ret;
  1449. ret = dquot_reserve_block(inode, *count);
  1450. if (ret)
  1451. return ret;
  1452. if (time_to_inject(sbi, FAULT_BLOCK)) {
  1453. f2fs_show_injection_info(FAULT_BLOCK);
  1454. release = *count;
  1455. goto enospc;
  1456. }
  1457. /*
  1458. * let's increase this in prior to actual block count change in order
  1459. * for f2fs_sync_file to avoid data races when deciding checkpoint.
  1460. */
  1461. percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
  1462. spin_lock(&sbi->stat_lock);
  1463. sbi->total_valid_block_count += (block_t)(*count);
  1464. avail_user_block_count = sbi->user_block_count -
  1465. sbi->current_reserved_blocks;
  1466. if (!__allow_reserved_blocks(sbi, inode, true))
  1467. avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
  1468. if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
  1469. diff = sbi->total_valid_block_count - avail_user_block_count;
  1470. if (diff > *count)
  1471. diff = *count;
  1472. *count -= diff;
  1473. release = diff;
  1474. sbi->total_valid_block_count -= diff;
  1475. if (!*count) {
  1476. spin_unlock(&sbi->stat_lock);
  1477. goto enospc;
  1478. }
  1479. }
  1480. spin_unlock(&sbi->stat_lock);
  1481. if (unlikely(release)) {
  1482. percpu_counter_sub(&sbi->alloc_valid_block_count, release);
  1483. dquot_release_reservation_block(inode, release);
  1484. }
  1485. f2fs_i_blocks_write(inode, *count, true, true);
  1486. return 0;
  1487. enospc:
  1488. percpu_counter_sub(&sbi->alloc_valid_block_count, release);
  1489. dquot_release_reservation_block(inode, release);
  1490. return -ENOSPC;
  1491. }
  1492. static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
  1493. struct inode *inode,
  1494. block_t count)
  1495. {
  1496. blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
  1497. spin_lock(&sbi->stat_lock);
  1498. f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
  1499. f2fs_bug_on(sbi, inode->i_blocks < sectors);
  1500. sbi->total_valid_block_count -= (block_t)count;
  1501. if (sbi->reserved_blocks &&
  1502. sbi->current_reserved_blocks < sbi->reserved_blocks)
  1503. sbi->current_reserved_blocks = min(sbi->reserved_blocks,
  1504. sbi->current_reserved_blocks + count);
  1505. spin_unlock(&sbi->stat_lock);
  1506. f2fs_i_blocks_write(inode, count, false, true);
  1507. }
  1508. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  1509. {
  1510. atomic_inc(&sbi->nr_pages[count_type]);
  1511. if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES ||
  1512. count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA)
  1513. return;
  1514. set_sbi_flag(sbi, SBI_IS_DIRTY);
  1515. }
  1516. static inline void inode_inc_dirty_pages(struct inode *inode)
  1517. {
  1518. atomic_inc(&F2FS_I(inode)->dirty_pages);
  1519. inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
  1520. F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
  1521. if (IS_NOQUOTA(inode))
  1522. inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
  1523. }
  1524. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  1525. {
  1526. atomic_dec(&sbi->nr_pages[count_type]);
  1527. }
  1528. static inline void inode_dec_dirty_pages(struct inode *inode)
  1529. {
  1530. if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
  1531. !S_ISLNK(inode->i_mode))
  1532. return;
  1533. atomic_dec(&F2FS_I(inode)->dirty_pages);
  1534. dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
  1535. F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
  1536. if (IS_NOQUOTA(inode))
  1537. dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
  1538. }
  1539. static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
  1540. {
  1541. return atomic_read(&sbi->nr_pages[count_type]);
  1542. }
  1543. static inline int get_dirty_pages(struct inode *inode)
  1544. {
  1545. return atomic_read(&F2FS_I(inode)->dirty_pages);
  1546. }
  1547. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  1548. {
  1549. unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
  1550. unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >>
  1551. sbi->log_blocks_per_seg;
  1552. return segs / sbi->segs_per_sec;
  1553. }
  1554. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  1555. {
  1556. return sbi->total_valid_block_count;
  1557. }
  1558. static inline block_t discard_blocks(struct f2fs_sb_info *sbi)
  1559. {
  1560. return sbi->discard_blks;
  1561. }
  1562. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  1563. {
  1564. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  1565. /* return NAT or SIT bitmap */
  1566. if (flag == NAT_BITMAP)
  1567. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  1568. else if (flag == SIT_BITMAP)
  1569. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  1570. return 0;
  1571. }
  1572. static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
  1573. {
  1574. return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
  1575. }
  1576. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  1577. {
  1578. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  1579. int offset;
  1580. if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) {
  1581. offset = (flag == SIT_BITMAP) ?
  1582. le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0;
  1583. return &ckpt->sit_nat_version_bitmap + offset;
  1584. }
  1585. if (__cp_payload(sbi) > 0) {
  1586. if (flag == NAT_BITMAP)
  1587. return &ckpt->sit_nat_version_bitmap;
  1588. else
  1589. return (unsigned char *)ckpt + F2FS_BLKSIZE;
  1590. } else {
  1591. offset = (flag == NAT_BITMAP) ?
  1592. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  1593. return &ckpt->sit_nat_version_bitmap + offset;
  1594. }
  1595. }
  1596. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  1597. {
  1598. block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  1599. if (sbi->cur_cp_pack == 2)
  1600. start_addr += sbi->blocks_per_seg;
  1601. return start_addr;
  1602. }
  1603. static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
  1604. {
  1605. block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  1606. if (sbi->cur_cp_pack == 1)
  1607. start_addr += sbi->blocks_per_seg;
  1608. return start_addr;
  1609. }
  1610. static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
  1611. {
  1612. sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
  1613. }
  1614. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  1615. {
  1616. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  1617. }
  1618. static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
  1619. struct inode *inode, bool is_inode)
  1620. {
  1621. block_t valid_block_count;
  1622. unsigned int valid_node_count;
  1623. bool quota = inode && !is_inode;
  1624. if (quota) {
  1625. int ret = dquot_reserve_block(inode, 1);
  1626. if (ret)
  1627. return ret;
  1628. }
  1629. if (time_to_inject(sbi, FAULT_BLOCK)) {
  1630. f2fs_show_injection_info(FAULT_BLOCK);
  1631. goto enospc;
  1632. }
  1633. spin_lock(&sbi->stat_lock);
  1634. valid_block_count = sbi->total_valid_block_count +
  1635. sbi->current_reserved_blocks + 1;
  1636. if (!__allow_reserved_blocks(sbi, inode, false))
  1637. valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
  1638. if (unlikely(valid_block_count > sbi->user_block_count)) {
  1639. spin_unlock(&sbi->stat_lock);
  1640. goto enospc;
  1641. }
  1642. valid_node_count = sbi->total_valid_node_count + 1;
  1643. if (unlikely(valid_node_count > sbi->total_node_count)) {
  1644. spin_unlock(&sbi->stat_lock);
  1645. goto enospc;
  1646. }
  1647. sbi->total_valid_node_count++;
  1648. sbi->total_valid_block_count++;
  1649. spin_unlock(&sbi->stat_lock);
  1650. if (inode) {
  1651. if (is_inode)
  1652. f2fs_mark_inode_dirty_sync(inode, true);
  1653. else
  1654. f2fs_i_blocks_write(inode, 1, true, true);
  1655. }
  1656. percpu_counter_inc(&sbi->alloc_valid_block_count);
  1657. return 0;
  1658. enospc:
  1659. if (quota)
  1660. dquot_release_reservation_block(inode, 1);
  1661. return -ENOSPC;
  1662. }
  1663. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  1664. struct inode *inode, bool is_inode)
  1665. {
  1666. spin_lock(&sbi->stat_lock);
  1667. f2fs_bug_on(sbi, !sbi->total_valid_block_count);
  1668. f2fs_bug_on(sbi, !sbi->total_valid_node_count);
  1669. f2fs_bug_on(sbi, !is_inode && !inode->i_blocks);
  1670. sbi->total_valid_node_count--;
  1671. sbi->total_valid_block_count--;
  1672. if (sbi->reserved_blocks &&
  1673. sbi->current_reserved_blocks < sbi->reserved_blocks)
  1674. sbi->current_reserved_blocks++;
  1675. spin_unlock(&sbi->stat_lock);
  1676. if (!is_inode)
  1677. f2fs_i_blocks_write(inode, 1, false, true);
  1678. }
  1679. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  1680. {
  1681. return sbi->total_valid_node_count;
  1682. }
  1683. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  1684. {
  1685. percpu_counter_inc(&sbi->total_valid_inode_count);
  1686. }
  1687. static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
  1688. {
  1689. percpu_counter_dec(&sbi->total_valid_inode_count);
  1690. }
  1691. static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
  1692. {
  1693. return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
  1694. }
  1695. static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
  1696. pgoff_t index, bool for_write)
  1697. {
  1698. struct page *page;
  1699. if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) {
  1700. if (!for_write)
  1701. page = find_get_page_flags(mapping, index,
  1702. FGP_LOCK | FGP_ACCESSED);
  1703. else
  1704. page = find_lock_page(mapping, index);
  1705. if (page)
  1706. return page;
  1707. if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
  1708. f2fs_show_injection_info(FAULT_PAGE_ALLOC);
  1709. return NULL;
  1710. }
  1711. }
  1712. if (!for_write)
  1713. return grab_cache_page(mapping, index);
  1714. return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
  1715. }
  1716. static inline struct page *f2fs_pagecache_get_page(
  1717. struct address_space *mapping, pgoff_t index,
  1718. int fgp_flags, gfp_t gfp_mask)
  1719. {
  1720. if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) {
  1721. f2fs_show_injection_info(FAULT_PAGE_GET);
  1722. return NULL;
  1723. }
  1724. return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
  1725. }
  1726. static inline void f2fs_copy_page(struct page *src, struct page *dst)
  1727. {
  1728. char *src_kaddr = kmap(src);
  1729. char *dst_kaddr = kmap(dst);
  1730. memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
  1731. kunmap(dst);
  1732. kunmap(src);
  1733. }
  1734. static inline void f2fs_put_page(struct page *page, int unlock)
  1735. {
  1736. if (!page)
  1737. return;
  1738. if (unlock) {
  1739. f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
  1740. unlock_page(page);
  1741. }
  1742. put_page(page);
  1743. }
  1744. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  1745. {
  1746. if (dn->node_page)
  1747. f2fs_put_page(dn->node_page, 1);
  1748. if (dn->inode_page && dn->node_page != dn->inode_page)
  1749. f2fs_put_page(dn->inode_page, 0);
  1750. dn->node_page = NULL;
  1751. dn->inode_page = NULL;
  1752. }
  1753. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  1754. size_t size)
  1755. {
  1756. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
  1757. }
  1758. static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
  1759. gfp_t flags)
  1760. {
  1761. void *entry;
  1762. entry = kmem_cache_alloc(cachep, flags);
  1763. if (!entry)
  1764. entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
  1765. return entry;
  1766. }
  1767. static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi,
  1768. int npages, bool no_fail)
  1769. {
  1770. struct bio *bio;
  1771. if (no_fail) {
  1772. /* No failure on bio allocation */
  1773. bio = bio_alloc(GFP_NOIO, npages);
  1774. if (!bio)
  1775. bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
  1776. return bio;
  1777. }
  1778. if (time_to_inject(sbi, FAULT_ALLOC_BIO)) {
  1779. f2fs_show_injection_info(FAULT_ALLOC_BIO);
  1780. return NULL;
  1781. }
  1782. return bio_alloc(GFP_KERNEL, npages);
  1783. }
  1784. static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
  1785. unsigned long index, void *item)
  1786. {
  1787. while (radix_tree_insert(root, index, item))
  1788. cond_resched();
  1789. }
  1790. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  1791. static inline bool IS_INODE(struct page *page)
  1792. {
  1793. struct f2fs_node *p = F2FS_NODE(page);
  1794. return RAW_IS_INODE(p);
  1795. }
  1796. static inline int offset_in_addr(struct f2fs_inode *i)
  1797. {
  1798. return (i->i_inline & F2FS_EXTRA_ATTR) ?
  1799. (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0;
  1800. }
  1801. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  1802. {
  1803. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  1804. }
  1805. static inline int f2fs_has_extra_attr(struct inode *inode);
  1806. static inline block_t datablock_addr(struct inode *inode,
  1807. struct page *node_page, unsigned int offset)
  1808. {
  1809. struct f2fs_node *raw_node;
  1810. __le32 *addr_array;
  1811. int base = 0;
  1812. bool is_inode = IS_INODE(node_page);
  1813. raw_node = F2FS_NODE(node_page);
  1814. /* from GC path only */
  1815. if (is_inode) {
  1816. if (!inode)
  1817. base = offset_in_addr(&raw_node->i);
  1818. else if (f2fs_has_extra_attr(inode))
  1819. base = get_extra_isize(inode);
  1820. }
  1821. addr_array = blkaddr_in_node(raw_node);
  1822. return le32_to_cpu(addr_array[base + offset]);
  1823. }
  1824. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  1825. {
  1826. int mask;
  1827. addr += (nr >> 3);
  1828. mask = 1 << (7 - (nr & 0x07));
  1829. return mask & *addr;
  1830. }
  1831. static inline void f2fs_set_bit(unsigned int nr, char *addr)
  1832. {
  1833. int mask;
  1834. addr += (nr >> 3);
  1835. mask = 1 << (7 - (nr & 0x07));
  1836. *addr |= mask;
  1837. }
  1838. static inline void f2fs_clear_bit(unsigned int nr, char *addr)
  1839. {
  1840. int mask;
  1841. addr += (nr >> 3);
  1842. mask = 1 << (7 - (nr & 0x07));
  1843. *addr &= ~mask;
  1844. }
  1845. static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
  1846. {
  1847. int mask;
  1848. int ret;
  1849. addr += (nr >> 3);
  1850. mask = 1 << (7 - (nr & 0x07));
  1851. ret = mask & *addr;
  1852. *addr |= mask;
  1853. return ret;
  1854. }
  1855. static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
  1856. {
  1857. int mask;
  1858. int ret;
  1859. addr += (nr >> 3);
  1860. mask = 1 << (7 - (nr & 0x07));
  1861. ret = mask & *addr;
  1862. *addr &= ~mask;
  1863. return ret;
  1864. }
  1865. static inline void f2fs_change_bit(unsigned int nr, char *addr)
  1866. {
  1867. int mask;
  1868. addr += (nr >> 3);
  1869. mask = 1 << (7 - (nr & 0x07));
  1870. *addr ^= mask;
  1871. }
  1872. /*
  1873. * Inode flags
  1874. */
  1875. #define F2FS_SECRM_FL 0x00000001 /* Secure deletion */
  1876. #define F2FS_UNRM_FL 0x00000002 /* Undelete */
  1877. #define F2FS_COMPR_FL 0x00000004 /* Compress file */
  1878. #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */
  1879. #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
  1880. #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */
  1881. #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */
  1882. #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */
  1883. /* Reserved for compression usage... */
  1884. #define F2FS_DIRTY_FL 0x00000100
  1885. #define F2FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  1886. #define F2FS_NOCOMPR_FL 0x00000400 /* Don't compress */
  1887. #define F2FS_ENCRYPT_FL 0x00000800 /* encrypted file */
  1888. /* End compression flags --- maybe not all used */
  1889. #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */
  1890. #define F2FS_IMAGIC_FL 0x00002000 /* AFS directory */
  1891. #define F2FS_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
  1892. #define F2FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  1893. #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
  1894. #define F2FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  1895. #define F2FS_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
  1896. #define F2FS_EXTENTS_FL 0x00080000 /* Inode uses extents */
  1897. #define F2FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */
  1898. #define F2FS_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
  1899. #define F2FS_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
  1900. #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
  1901. #define F2FS_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
  1902. #define F2FS_FL_USER_VISIBLE 0x304BDFFF /* User visible flags */
  1903. #define F2FS_FL_USER_MODIFIABLE 0x204BC0FF /* User modifiable flags */
  1904. /* Flags we can manipulate with through F2FS_IOC_FSSETXATTR */
  1905. #define F2FS_FL_XFLAG_VISIBLE (F2FS_SYNC_FL | \
  1906. F2FS_IMMUTABLE_FL | \
  1907. F2FS_APPEND_FL | \
  1908. F2FS_NODUMP_FL | \
  1909. F2FS_NOATIME_FL | \
  1910. F2FS_PROJINHERIT_FL)
  1911. /* Flags that should be inherited by new inodes from their parent. */
  1912. #define F2FS_FL_INHERITED (F2FS_SECRM_FL | F2FS_UNRM_FL | F2FS_COMPR_FL |\
  1913. F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL |\
  1914. F2FS_NOCOMPR_FL | F2FS_JOURNAL_DATA_FL |\
  1915. F2FS_NOTAIL_FL | F2FS_DIRSYNC_FL |\
  1916. F2FS_PROJINHERIT_FL)
  1917. /* Flags that are appropriate for regular files (all but dir-specific ones). */
  1918. #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_TOPDIR_FL))
  1919. /* Flags that are appropriate for non-directories/regular files. */
  1920. #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL)
  1921. static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags)
  1922. {
  1923. if (S_ISDIR(mode))
  1924. return flags;
  1925. else if (S_ISREG(mode))
  1926. return flags & F2FS_REG_FLMASK;
  1927. else
  1928. return flags & F2FS_OTHER_FLMASK;
  1929. }
  1930. /* used for f2fs_inode_info->flags */
  1931. enum {
  1932. FI_NEW_INODE, /* indicate newly allocated inode */
  1933. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  1934. FI_AUTO_RECOVER, /* indicate inode is recoverable */
  1935. FI_DIRTY_DIR, /* indicate directory has dirty pages */
  1936. FI_INC_LINK, /* need to increment i_nlink */
  1937. FI_ACL_MODE, /* indicate acl mode */
  1938. FI_NO_ALLOC, /* should not allocate any blocks */
  1939. FI_FREE_NID, /* free allocated nide */
  1940. FI_NO_EXTENT, /* not to use the extent cache */
  1941. FI_INLINE_XATTR, /* used for inline xattr */
  1942. FI_INLINE_DATA, /* used for inline data*/
  1943. FI_INLINE_DENTRY, /* used for inline dentry */
  1944. FI_APPEND_WRITE, /* inode has appended data */
  1945. FI_UPDATE_WRITE, /* inode has in-place-update data */
  1946. FI_NEED_IPU, /* used for ipu per file */
  1947. FI_ATOMIC_FILE, /* indicate atomic file */
  1948. FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */
  1949. FI_VOLATILE_FILE, /* indicate volatile file */
  1950. FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
  1951. FI_DROP_CACHE, /* drop dirty page cache */
  1952. FI_DATA_EXIST, /* indicate data exists */
  1953. FI_INLINE_DOTS, /* indicate inline dot dentries */
  1954. FI_DO_DEFRAG, /* indicate defragment is running */
  1955. FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */
  1956. FI_NO_PREALLOC, /* indicate skipped preallocated blocks */
  1957. FI_HOT_DATA, /* indicate file is hot */
  1958. FI_EXTRA_ATTR, /* indicate file has extra attribute */
  1959. FI_PROJ_INHERIT, /* indicate file inherits projectid */
  1960. FI_PIN_FILE, /* indicate file should not be gced */
  1961. FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */
  1962. };
  1963. static inline void __mark_inode_dirty_flag(struct inode *inode,
  1964. int flag, bool set)
  1965. {
  1966. switch (flag) {
  1967. case FI_INLINE_XATTR:
  1968. case FI_INLINE_DATA:
  1969. case FI_INLINE_DENTRY:
  1970. case FI_NEW_INODE:
  1971. if (set)
  1972. return;
  1973. case FI_DATA_EXIST:
  1974. case FI_INLINE_DOTS:
  1975. case FI_PIN_FILE:
  1976. f2fs_mark_inode_dirty_sync(inode, true);
  1977. }
  1978. }
  1979. static inline void set_inode_flag(struct inode *inode, int flag)
  1980. {
  1981. if (!test_bit(flag, &F2FS_I(inode)->flags))
  1982. set_bit(flag, &F2FS_I(inode)->flags);
  1983. __mark_inode_dirty_flag(inode, flag, true);
  1984. }
  1985. static inline int is_inode_flag_set(struct inode *inode, int flag)
  1986. {
  1987. return test_bit(flag, &F2FS_I(inode)->flags);
  1988. }
  1989. static inline void clear_inode_flag(struct inode *inode, int flag)
  1990. {
  1991. if (test_bit(flag, &F2FS_I(inode)->flags))
  1992. clear_bit(flag, &F2FS_I(inode)->flags);
  1993. __mark_inode_dirty_flag(inode, flag, false);
  1994. }
  1995. static inline void set_acl_inode(struct inode *inode, umode_t mode)
  1996. {
  1997. F2FS_I(inode)->i_acl_mode = mode;
  1998. set_inode_flag(inode, FI_ACL_MODE);
  1999. f2fs_mark_inode_dirty_sync(inode, false);
  2000. }
  2001. static inline void f2fs_i_links_write(struct inode *inode, bool inc)
  2002. {
  2003. if (inc)
  2004. inc_nlink(inode);
  2005. else
  2006. drop_nlink(inode);
  2007. f2fs_mark_inode_dirty_sync(inode, true);
  2008. }
  2009. static inline void f2fs_i_blocks_write(struct inode *inode,
  2010. block_t diff, bool add, bool claim)
  2011. {
  2012. bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
  2013. bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
  2014. /* add = 1, claim = 1 should be dquot_reserve_block in pair */
  2015. if (add) {
  2016. if (claim)
  2017. dquot_claim_block(inode, diff);
  2018. else
  2019. dquot_alloc_block_nofail(inode, diff);
  2020. } else {
  2021. dquot_free_block(inode, diff);
  2022. }
  2023. f2fs_mark_inode_dirty_sync(inode, true);
  2024. if (clean || recover)
  2025. set_inode_flag(inode, FI_AUTO_RECOVER);
  2026. }
  2027. static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
  2028. {
  2029. bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
  2030. bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
  2031. if (i_size_read(inode) == i_size)
  2032. return;
  2033. i_size_write(inode, i_size);
  2034. f2fs_mark_inode_dirty_sync(inode, true);
  2035. if (clean || recover)
  2036. set_inode_flag(inode, FI_AUTO_RECOVER);
  2037. }
  2038. static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
  2039. {
  2040. F2FS_I(inode)->i_current_depth = depth;
  2041. f2fs_mark_inode_dirty_sync(inode, true);
  2042. }
  2043. static inline void f2fs_i_gc_failures_write(struct inode *inode,
  2044. unsigned int count)
  2045. {
  2046. F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count;
  2047. f2fs_mark_inode_dirty_sync(inode, true);
  2048. }
  2049. static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid)
  2050. {
  2051. F2FS_I(inode)->i_xattr_nid = xnid;
  2052. f2fs_mark_inode_dirty_sync(inode, true);
  2053. }
  2054. static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino)
  2055. {
  2056. F2FS_I(inode)->i_pino = pino;
  2057. f2fs_mark_inode_dirty_sync(inode, true);
  2058. }
  2059. static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
  2060. {
  2061. struct f2fs_inode_info *fi = F2FS_I(inode);
  2062. if (ri->i_inline & F2FS_INLINE_XATTR)
  2063. set_bit(FI_INLINE_XATTR, &fi->flags);
  2064. if (ri->i_inline & F2FS_INLINE_DATA)
  2065. set_bit(FI_INLINE_DATA, &fi->flags);
  2066. if (ri->i_inline & F2FS_INLINE_DENTRY)
  2067. set_bit(FI_INLINE_DENTRY, &fi->flags);
  2068. if (ri->i_inline & F2FS_DATA_EXIST)
  2069. set_bit(FI_DATA_EXIST, &fi->flags);
  2070. if (ri->i_inline & F2FS_INLINE_DOTS)
  2071. set_bit(FI_INLINE_DOTS, &fi->flags);
  2072. if (ri->i_inline & F2FS_EXTRA_ATTR)
  2073. set_bit(FI_EXTRA_ATTR, &fi->flags);
  2074. if (ri->i_inline & F2FS_PIN_FILE)
  2075. set_bit(FI_PIN_FILE, &fi->flags);
  2076. }
  2077. static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
  2078. {
  2079. ri->i_inline = 0;
  2080. if (is_inode_flag_set(inode, FI_INLINE_XATTR))
  2081. ri->i_inline |= F2FS_INLINE_XATTR;
  2082. if (is_inode_flag_set(inode, FI_INLINE_DATA))
  2083. ri->i_inline |= F2FS_INLINE_DATA;
  2084. if (is_inode_flag_set(inode, FI_INLINE_DENTRY))
  2085. ri->i_inline |= F2FS_INLINE_DENTRY;
  2086. if (is_inode_flag_set(inode, FI_DATA_EXIST))
  2087. ri->i_inline |= F2FS_DATA_EXIST;
  2088. if (is_inode_flag_set(inode, FI_INLINE_DOTS))
  2089. ri->i_inline |= F2FS_INLINE_DOTS;
  2090. if (is_inode_flag_set(inode, FI_EXTRA_ATTR))
  2091. ri->i_inline |= F2FS_EXTRA_ATTR;
  2092. if (is_inode_flag_set(inode, FI_PIN_FILE))
  2093. ri->i_inline |= F2FS_PIN_FILE;
  2094. }
  2095. static inline int f2fs_has_extra_attr(struct inode *inode)
  2096. {
  2097. return is_inode_flag_set(inode, FI_EXTRA_ATTR);
  2098. }
  2099. static inline int f2fs_has_inline_xattr(struct inode *inode)
  2100. {
  2101. return is_inode_flag_set(inode, FI_INLINE_XATTR);
  2102. }
  2103. static inline unsigned int addrs_per_inode(struct inode *inode)
  2104. {
  2105. return CUR_ADDRS_PER_INODE(inode) - get_inline_xattr_addrs(inode);
  2106. }
  2107. static inline void *inline_xattr_addr(struct inode *inode, struct page *page)
  2108. {
  2109. struct f2fs_inode *ri = F2FS_INODE(page);
  2110. return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
  2111. get_inline_xattr_addrs(inode)]);
  2112. }
  2113. static inline int inline_xattr_size(struct inode *inode)
  2114. {
  2115. return get_inline_xattr_addrs(inode) * sizeof(__le32);
  2116. }
  2117. static inline int f2fs_has_inline_data(struct inode *inode)
  2118. {
  2119. return is_inode_flag_set(inode, FI_INLINE_DATA);
  2120. }
  2121. static inline int f2fs_exist_data(struct inode *inode)
  2122. {
  2123. return is_inode_flag_set(inode, FI_DATA_EXIST);
  2124. }
  2125. static inline int f2fs_has_inline_dots(struct inode *inode)
  2126. {
  2127. return is_inode_flag_set(inode, FI_INLINE_DOTS);
  2128. }
  2129. static inline bool f2fs_is_pinned_file(struct inode *inode)
  2130. {
  2131. return is_inode_flag_set(inode, FI_PIN_FILE);
  2132. }
  2133. static inline bool f2fs_is_atomic_file(struct inode *inode)
  2134. {
  2135. return is_inode_flag_set(inode, FI_ATOMIC_FILE);
  2136. }
  2137. static inline bool f2fs_is_commit_atomic_write(struct inode *inode)
  2138. {
  2139. return is_inode_flag_set(inode, FI_ATOMIC_COMMIT);
  2140. }
  2141. static inline bool f2fs_is_volatile_file(struct inode *inode)
  2142. {
  2143. return is_inode_flag_set(inode, FI_VOLATILE_FILE);
  2144. }
  2145. static inline bool f2fs_is_first_block_written(struct inode *inode)
  2146. {
  2147. return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN);
  2148. }
  2149. static inline bool f2fs_is_drop_cache(struct inode *inode)
  2150. {
  2151. return is_inode_flag_set(inode, FI_DROP_CACHE);
  2152. }
  2153. static inline void *inline_data_addr(struct inode *inode, struct page *page)
  2154. {
  2155. struct f2fs_inode *ri = F2FS_INODE(page);
  2156. int extra_size = get_extra_isize(inode);
  2157. return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]);
  2158. }
  2159. static inline int f2fs_has_inline_dentry(struct inode *inode)
  2160. {
  2161. return is_inode_flag_set(inode, FI_INLINE_DENTRY);
  2162. }
  2163. static inline int is_file(struct inode *inode, int type)
  2164. {
  2165. return F2FS_I(inode)->i_advise & type;
  2166. }
  2167. static inline void set_file(struct inode *inode, int type)
  2168. {
  2169. F2FS_I(inode)->i_advise |= type;
  2170. f2fs_mark_inode_dirty_sync(inode, true);
  2171. }
  2172. static inline void clear_file(struct inode *inode, int type)
  2173. {
  2174. F2FS_I(inode)->i_advise &= ~type;
  2175. f2fs_mark_inode_dirty_sync(inode, true);
  2176. }
  2177. static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
  2178. {
  2179. bool ret;
  2180. if (dsync) {
  2181. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  2182. spin_lock(&sbi->inode_lock[DIRTY_META]);
  2183. ret = list_empty(&F2FS_I(inode)->gdirty_list);
  2184. spin_unlock(&sbi->inode_lock[DIRTY_META]);
  2185. return ret;
  2186. }
  2187. if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
  2188. file_keep_isize(inode) ||
  2189. i_size_read(inode) & ~PAGE_MASK)
  2190. return false;
  2191. if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime))
  2192. return false;
  2193. if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime))
  2194. return false;
  2195. if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime))
  2196. return false;
  2197. if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3,
  2198. &F2FS_I(inode)->i_crtime))
  2199. return false;
  2200. down_read(&F2FS_I(inode)->i_sem);
  2201. ret = F2FS_I(inode)->last_disk_size == i_size_read(inode);
  2202. up_read(&F2FS_I(inode)->i_sem);
  2203. return ret;
  2204. }
  2205. static inline bool f2fs_readonly(struct super_block *sb)
  2206. {
  2207. return sb_rdonly(sb);
  2208. }
  2209. static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
  2210. {
  2211. return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
  2212. }
  2213. static inline bool is_dot_dotdot(const struct qstr *str)
  2214. {
  2215. if (str->len == 1 && str->name[0] == '.')
  2216. return true;
  2217. if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
  2218. return true;
  2219. return false;
  2220. }
  2221. static inline bool f2fs_may_extent_tree(struct inode *inode)
  2222. {
  2223. if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
  2224. is_inode_flag_set(inode, FI_NO_EXTENT))
  2225. return false;
  2226. return S_ISREG(inode->i_mode);
  2227. }
  2228. static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
  2229. size_t size, gfp_t flags)
  2230. {
  2231. if (time_to_inject(sbi, FAULT_KMALLOC)) {
  2232. f2fs_show_injection_info(FAULT_KMALLOC);
  2233. return NULL;
  2234. }
  2235. return kmalloc(size, flags);
  2236. }
  2237. static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
  2238. size_t size, gfp_t flags)
  2239. {
  2240. return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO);
  2241. }
  2242. static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi,
  2243. size_t size, gfp_t flags)
  2244. {
  2245. if (time_to_inject(sbi, FAULT_KVMALLOC)) {
  2246. f2fs_show_injection_info(FAULT_KVMALLOC);
  2247. return NULL;
  2248. }
  2249. return kvmalloc(size, flags);
  2250. }
  2251. static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
  2252. size_t size, gfp_t flags)
  2253. {
  2254. return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
  2255. }
  2256. static inline int get_extra_isize(struct inode *inode)
  2257. {
  2258. return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
  2259. }
  2260. static inline int get_inline_xattr_addrs(struct inode *inode)
  2261. {
  2262. return F2FS_I(inode)->i_inline_xattr_size;
  2263. }
  2264. #define f2fs_get_inode_mode(i) \
  2265. ((is_inode_flag_set(i, FI_ACL_MODE)) ? \
  2266. (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
  2267. #define F2FS_TOTAL_EXTRA_ATTR_SIZE \
  2268. (offsetof(struct f2fs_inode, i_extra_end) - \
  2269. offsetof(struct f2fs_inode, i_extra_isize)) \
  2270. #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr))
  2271. #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \
  2272. ((offsetof(typeof(*f2fs_inode), field) + \
  2273. sizeof((f2fs_inode)->field)) \
  2274. <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \
  2275. static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
  2276. {
  2277. int i;
  2278. spin_lock(&sbi->iostat_lock);
  2279. for (i = 0; i < NR_IO_TYPE; i++)
  2280. sbi->write_iostat[i] = 0;
  2281. spin_unlock(&sbi->iostat_lock);
  2282. }
  2283. static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
  2284. enum iostat_type type, unsigned long long io_bytes)
  2285. {
  2286. if (!sbi->iostat_enable)
  2287. return;
  2288. spin_lock(&sbi->iostat_lock);
  2289. sbi->write_iostat[type] += io_bytes;
  2290. if (type == APP_WRITE_IO || type == APP_DIRECT_IO)
  2291. sbi->write_iostat[APP_BUFFERED_IO] =
  2292. sbi->write_iostat[APP_WRITE_IO] -
  2293. sbi->write_iostat[APP_DIRECT_IO];
  2294. spin_unlock(&sbi->iostat_lock);
  2295. }
  2296. #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \
  2297. (!is_read_io(fio->op) || fio->is_meta))
  2298. bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
  2299. block_t blkaddr, int type);
  2300. void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
  2301. static inline void verify_blkaddr(struct f2fs_sb_info *sbi,
  2302. block_t blkaddr, int type)
  2303. {
  2304. if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) {
  2305. f2fs_msg(sbi->sb, KERN_ERR,
  2306. "invalid blkaddr: %u, type: %d, run fsck to fix.",
  2307. blkaddr, type);
  2308. f2fs_bug_on(sbi, 1);
  2309. }
  2310. }
  2311. static inline bool __is_valid_data_blkaddr(block_t blkaddr)
  2312. {
  2313. if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR)
  2314. return false;
  2315. return true;
  2316. }
  2317. static inline bool is_valid_data_blkaddr(struct f2fs_sb_info *sbi,
  2318. block_t blkaddr)
  2319. {
  2320. if (!__is_valid_data_blkaddr(blkaddr))
  2321. return false;
  2322. verify_blkaddr(sbi, blkaddr, DATA_GENERIC);
  2323. return true;
  2324. }
  2325. /*
  2326. * file.c
  2327. */
  2328. int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
  2329. void f2fs_truncate_data_blocks(struct dnode_of_data *dn);
  2330. int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock);
  2331. int f2fs_truncate(struct inode *inode);
  2332. int f2fs_getattr(const struct path *path, struct kstat *stat,
  2333. u32 request_mask, unsigned int flags);
  2334. int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
  2335. int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
  2336. void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count);
  2337. int f2fs_precache_extents(struct inode *inode);
  2338. long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  2339. long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  2340. int f2fs_pin_file_control(struct inode *inode, bool inc);
  2341. /*
  2342. * inode.c
  2343. */
  2344. void f2fs_set_inode_flags(struct inode *inode);
  2345. bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page);
  2346. void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page);
  2347. struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
  2348. struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
  2349. int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
  2350. void f2fs_update_inode(struct inode *inode, struct page *node_page);
  2351. void f2fs_update_inode_page(struct inode *inode);
  2352. int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
  2353. void f2fs_evict_inode(struct inode *inode);
  2354. void f2fs_handle_failed_inode(struct inode *inode);
  2355. /*
  2356. * namei.c
  2357. */
  2358. int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
  2359. bool hot, bool set);
  2360. struct dentry *f2fs_get_parent(struct dentry *child);
  2361. /*
  2362. * dir.c
  2363. */
  2364. unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de);
  2365. struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname,
  2366. f2fs_hash_t namehash, int *max_slots,
  2367. struct f2fs_dentry_ptr *d);
  2368. int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
  2369. unsigned int start_pos, struct fscrypt_str *fstr);
  2370. void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
  2371. struct f2fs_dentry_ptr *d);
  2372. struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
  2373. const struct qstr *new_name,
  2374. const struct qstr *orig_name, struct page *dpage);
  2375. void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode,
  2376. unsigned int current_depth);
  2377. int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots);
  2378. void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
  2379. struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
  2380. struct fscrypt_name *fname, struct page **res_page);
  2381. struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
  2382. const struct qstr *child, struct page **res_page);
  2383. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p);
  2384. ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
  2385. struct page **page);
  2386. void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
  2387. struct page *page, struct inode *inode);
  2388. void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
  2389. const struct qstr *name, f2fs_hash_t name_hash,
  2390. unsigned int bit_pos);
  2391. int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
  2392. const struct qstr *orig_name,
  2393. struct inode *inode, nid_t ino, umode_t mode);
  2394. int f2fs_add_dentry(struct inode *dir, struct fscrypt_name *fname,
  2395. struct inode *inode, nid_t ino, umode_t mode);
  2396. int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
  2397. struct inode *inode, nid_t ino, umode_t mode);
  2398. void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
  2399. struct inode *dir, struct inode *inode);
  2400. int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
  2401. bool f2fs_empty_dir(struct inode *dir);
  2402. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  2403. {
  2404. return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name,
  2405. inode, inode->i_ino, inode->i_mode);
  2406. }
  2407. /*
  2408. * super.c
  2409. */
  2410. int f2fs_inode_dirtied(struct inode *inode, bool sync);
  2411. void f2fs_inode_synced(struct inode *inode);
  2412. int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly);
  2413. void f2fs_quota_off_umount(struct super_block *sb);
  2414. int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
  2415. int f2fs_sync_fs(struct super_block *sb, int sync);
  2416. extern __printf(3, 4)
  2417. void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
  2418. int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi);
  2419. /*
  2420. * hash.c
  2421. */
  2422. f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
  2423. struct fscrypt_name *fname);
  2424. /*
  2425. * node.c
  2426. */
  2427. struct dnode_of_data;
  2428. struct node_info;
  2429. int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid);
  2430. bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type);
  2431. bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page);
  2432. void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi);
  2433. void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page);
  2434. void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi);
  2435. int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
  2436. bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
  2437. bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino);
  2438. int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
  2439. struct node_info *ni);
  2440. pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
  2441. int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
  2442. int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from);
  2443. int f2fs_truncate_xattr_node(struct inode *inode);
  2444. int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi,
  2445. unsigned int seq_id);
  2446. int f2fs_remove_inode_page(struct inode *inode);
  2447. struct page *f2fs_new_inode_page(struct inode *inode);
  2448. struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs);
  2449. void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
  2450. struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
  2451. struct page *f2fs_get_node_page_ra(struct page *parent, int start);
  2452. void f2fs_move_node_page(struct page *node_page, int gc_type);
  2453. int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
  2454. struct writeback_control *wbc, bool atomic,
  2455. unsigned int *seq_id);
  2456. int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
  2457. struct writeback_control *wbc,
  2458. bool do_balance, enum iostat_type io_type);
  2459. int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
  2460. bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
  2461. void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
  2462. void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
  2463. int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
  2464. void f2fs_recover_inline_xattr(struct inode *inode, struct page *page);
  2465. int f2fs_recover_xattr_data(struct inode *inode, struct page *page);
  2466. int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
  2467. int f2fs_restore_node_summary(struct f2fs_sb_info *sbi,
  2468. unsigned int segno, struct f2fs_summary_block *sum);
  2469. void f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  2470. int f2fs_build_node_manager(struct f2fs_sb_info *sbi);
  2471. void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi);
  2472. int __init f2fs_create_node_manager_caches(void);
  2473. void f2fs_destroy_node_manager_caches(void);
  2474. /*
  2475. * segment.c
  2476. */
  2477. bool f2fs_need_SSR(struct f2fs_sb_info *sbi);
  2478. void f2fs_register_inmem_page(struct inode *inode, struct page *page);
  2479. void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure);
  2480. void f2fs_drop_inmem_pages(struct inode *inode);
  2481. void f2fs_drop_inmem_page(struct inode *inode, struct page *page);
  2482. int f2fs_commit_inmem_pages(struct inode *inode);
  2483. void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need);
  2484. void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi);
  2485. int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino);
  2486. int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi);
  2487. int f2fs_flush_device_cache(struct f2fs_sb_info *sbi);
  2488. void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free);
  2489. void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
  2490. bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
  2491. void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi);
  2492. void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi);
  2493. bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi);
  2494. void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
  2495. struct cp_control *cpc);
  2496. void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
  2497. int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
  2498. void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
  2499. int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
  2500. bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
  2501. struct cp_control *cpc);
  2502. struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno);
  2503. void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src,
  2504. block_t blk_addr);
  2505. void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
  2506. enum iostat_type io_type);
  2507. void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio);
  2508. void f2fs_outplace_write_data(struct dnode_of_data *dn,
  2509. struct f2fs_io_info *fio);
  2510. int f2fs_inplace_write_data(struct f2fs_io_info *fio);
  2511. void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
  2512. block_t old_blkaddr, block_t new_blkaddr,
  2513. bool recover_curseg, bool recover_newaddr);
  2514. void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
  2515. block_t old_addr, block_t new_addr,
  2516. unsigned char version, bool recover_curseg,
  2517. bool recover_newaddr);
  2518. void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
  2519. block_t old_blkaddr, block_t *new_blkaddr,
  2520. struct f2fs_summary *sum, int type,
  2521. struct f2fs_io_info *fio, bool add_list);
  2522. void f2fs_wait_on_page_writeback(struct page *page,
  2523. enum page_type type, bool ordered);
  2524. void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr);
  2525. void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
  2526. void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
  2527. int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
  2528. unsigned int val, int alloc);
  2529. void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  2530. int f2fs_build_segment_manager(struct f2fs_sb_info *sbi);
  2531. void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi);
  2532. int __init f2fs_create_segment_manager_caches(void);
  2533. void f2fs_destroy_segment_manager_caches(void);
  2534. int f2fs_rw_hint_to_seg_type(enum rw_hint hint);
  2535. enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
  2536. enum page_type type, enum temp_type temp);
  2537. /*
  2538. * checkpoint.c
  2539. */
  2540. void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
  2541. struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
  2542. struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
  2543. struct page *f2fs_get_meta_page_nofail(struct f2fs_sb_info *sbi, pgoff_t index);
  2544. struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
  2545. bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
  2546. block_t blkaddr, int type);
  2547. int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
  2548. int type, bool sync);
  2549. void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index);
  2550. long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
  2551. long nr_to_write, enum iostat_type io_type);
  2552. void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
  2553. void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
  2554. void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all);
  2555. bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode);
  2556. void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
  2557. unsigned int devidx, int type);
  2558. bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
  2559. unsigned int devidx, int type);
  2560. int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi);
  2561. int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi);
  2562. void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi);
  2563. void f2fs_add_orphan_inode(struct inode *inode);
  2564. void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
  2565. int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi);
  2566. int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi);
  2567. void f2fs_update_dirty_page(struct inode *inode, struct page *page);
  2568. void f2fs_remove_dirty_inode(struct inode *inode);
  2569. int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type);
  2570. void f2fs_wait_on_all_pages_writeback(struct f2fs_sb_info *sbi);
  2571. int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
  2572. void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi);
  2573. int __init f2fs_create_checkpoint_caches(void);
  2574. void f2fs_destroy_checkpoint_caches(void);
  2575. /*
  2576. * data.c
  2577. */
  2578. int f2fs_init_post_read_processing(void);
  2579. void f2fs_destroy_post_read_processing(void);
  2580. void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
  2581. void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
  2582. struct inode *inode, nid_t ino, pgoff_t idx,
  2583. enum page_type type);
  2584. void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
  2585. int f2fs_submit_page_bio(struct f2fs_io_info *fio);
  2586. void f2fs_submit_page_write(struct f2fs_io_info *fio);
  2587. struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
  2588. block_t blk_addr, struct bio *bio);
  2589. int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
  2590. void f2fs_set_data_blkaddr(struct dnode_of_data *dn);
  2591. void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr);
  2592. int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count);
  2593. int f2fs_reserve_new_block(struct dnode_of_data *dn);
  2594. int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index);
  2595. int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from);
  2596. int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index);
  2597. struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
  2598. int op_flags, bool for_write);
  2599. struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index);
  2600. struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index,
  2601. bool for_write);
  2602. struct page *f2fs_get_new_data_page(struct inode *inode,
  2603. struct page *ipage, pgoff_t index, bool new_i_size);
  2604. int f2fs_do_write_data_page(struct f2fs_io_info *fio);
  2605. int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
  2606. int create, int flag);
  2607. int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  2608. u64 start, u64 len);
  2609. bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio);
  2610. bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio);
  2611. void f2fs_invalidate_page(struct page *page, unsigned int offset,
  2612. unsigned int length);
  2613. int f2fs_release_page(struct page *page, gfp_t wait);
  2614. #ifdef CONFIG_MIGRATION
  2615. int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
  2616. struct page *page, enum migrate_mode mode);
  2617. #endif
  2618. bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len);
  2619. void f2fs_clear_page_cache_dirty_tag(struct page *page);
  2620. /*
  2621. * gc.c
  2622. */
  2623. int f2fs_start_gc_thread(struct f2fs_sb_info *sbi);
  2624. void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi);
  2625. block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
  2626. int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background,
  2627. unsigned int segno);
  2628. void f2fs_build_gc_manager(struct f2fs_sb_info *sbi);
  2629. /*
  2630. * recovery.c
  2631. */
  2632. int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only);
  2633. bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi);
  2634. /*
  2635. * debug.c
  2636. */
  2637. #ifdef CONFIG_F2FS_STAT_FS
  2638. struct f2fs_stat_info {
  2639. struct list_head stat_list;
  2640. struct f2fs_sb_info *sbi;
  2641. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  2642. int main_area_segs, main_area_sections, main_area_zones;
  2643. unsigned long long hit_largest, hit_cached, hit_rbtree;
  2644. unsigned long long hit_total, total_ext;
  2645. int ext_tree, zombie_tree, ext_node;
  2646. int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta;
  2647. int ndirty_data, ndirty_qdata;
  2648. int inmem_pages;
  2649. unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all;
  2650. int nats, dirty_nats, sits, dirty_sits;
  2651. int free_nids, avail_nids, alloc_nids;
  2652. int total_count, utilization;
  2653. int bg_gc, nr_wb_cp_data, nr_wb_data;
  2654. int nr_flushing, nr_flushed, flush_list_empty;
  2655. int nr_discarding, nr_discarded;
  2656. int nr_discard_cmd;
  2657. unsigned int undiscard_blks;
  2658. int inline_xattr, inline_inode, inline_dir, append, update, orphans;
  2659. int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt;
  2660. unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
  2661. unsigned int bimodal, avg_vblocks;
  2662. int util_free, util_valid, util_invalid;
  2663. int rsvd_segs, overp_segs;
  2664. int dirty_count, node_pages, meta_pages;
  2665. int prefree_count, call_count, cp_count, bg_cp_count;
  2666. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  2667. int bg_node_segs, bg_data_segs;
  2668. int tot_blks, data_blks, node_blks;
  2669. int bg_data_blks, bg_node_blks;
  2670. unsigned long long skipped_atomic_files[2];
  2671. int curseg[NR_CURSEG_TYPE];
  2672. int cursec[NR_CURSEG_TYPE];
  2673. int curzone[NR_CURSEG_TYPE];
  2674. unsigned int segment_count[2];
  2675. unsigned int block_count[2];
  2676. unsigned int inplace_count;
  2677. unsigned long long base_mem, cache_mem, page_mem;
  2678. };
  2679. static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
  2680. {
  2681. return (struct f2fs_stat_info *)sbi->stat_info;
  2682. }
  2683. #define stat_inc_cp_count(si) ((si)->cp_count++)
  2684. #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
  2685. #define stat_inc_call_count(si) ((si)->call_count++)
  2686. #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
  2687. #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
  2688. #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--)
  2689. #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext))
  2690. #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree))
  2691. #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest))
  2692. #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached))
  2693. #define stat_inc_inline_xattr(inode) \
  2694. do { \
  2695. if (f2fs_has_inline_xattr(inode)) \
  2696. (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \
  2697. } while (0)
  2698. #define stat_dec_inline_xattr(inode) \
  2699. do { \
  2700. if (f2fs_has_inline_xattr(inode)) \
  2701. (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \
  2702. } while (0)
  2703. #define stat_inc_inline_inode(inode) \
  2704. do { \
  2705. if (f2fs_has_inline_data(inode)) \
  2706. (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
  2707. } while (0)
  2708. #define stat_dec_inline_inode(inode) \
  2709. do { \
  2710. if (f2fs_has_inline_data(inode)) \
  2711. (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
  2712. } while (0)
  2713. #define stat_inc_inline_dir(inode) \
  2714. do { \
  2715. if (f2fs_has_inline_dentry(inode)) \
  2716. (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
  2717. } while (0)
  2718. #define stat_dec_inline_dir(inode) \
  2719. do { \
  2720. if (f2fs_has_inline_dentry(inode)) \
  2721. (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
  2722. } while (0)
  2723. #define stat_inc_seg_type(sbi, curseg) \
  2724. ((sbi)->segment_count[(curseg)->alloc_type]++)
  2725. #define stat_inc_block_count(sbi, curseg) \
  2726. ((sbi)->block_count[(curseg)->alloc_type]++)
  2727. #define stat_inc_inplace_blocks(sbi) \
  2728. (atomic_inc(&(sbi)->inplace_count))
  2729. #define stat_inc_atomic_write(inode) \
  2730. (atomic_inc(&F2FS_I_SB(inode)->aw_cnt))
  2731. #define stat_dec_atomic_write(inode) \
  2732. (atomic_dec(&F2FS_I_SB(inode)->aw_cnt))
  2733. #define stat_update_max_atomic_write(inode) \
  2734. do { \
  2735. int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \
  2736. int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \
  2737. if (cur > max) \
  2738. atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \
  2739. } while (0)
  2740. #define stat_inc_volatile_write(inode) \
  2741. (atomic_inc(&F2FS_I_SB(inode)->vw_cnt))
  2742. #define stat_dec_volatile_write(inode) \
  2743. (atomic_dec(&F2FS_I_SB(inode)->vw_cnt))
  2744. #define stat_update_max_volatile_write(inode) \
  2745. do { \
  2746. int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \
  2747. int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \
  2748. if (cur > max) \
  2749. atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \
  2750. } while (0)
  2751. #define stat_inc_seg_count(sbi, type, gc_type) \
  2752. do { \
  2753. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  2754. si->tot_segs++; \
  2755. if ((type) == SUM_TYPE_DATA) { \
  2756. si->data_segs++; \
  2757. si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
  2758. } else { \
  2759. si->node_segs++; \
  2760. si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
  2761. } \
  2762. } while (0)
  2763. #define stat_inc_tot_blk_count(si, blks) \
  2764. ((si)->tot_blks += (blks))
  2765. #define stat_inc_data_blk_count(sbi, blks, gc_type) \
  2766. do { \
  2767. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  2768. stat_inc_tot_blk_count(si, blks); \
  2769. si->data_blks += (blks); \
  2770. si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \
  2771. } while (0)
  2772. #define stat_inc_node_blk_count(sbi, blks, gc_type) \
  2773. do { \
  2774. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  2775. stat_inc_tot_blk_count(si, blks); \
  2776. si->node_blks += (blks); \
  2777. si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \
  2778. } while (0)
  2779. int f2fs_build_stats(struct f2fs_sb_info *sbi);
  2780. void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
  2781. int __init f2fs_create_root_stats(void);
  2782. void f2fs_destroy_root_stats(void);
  2783. #else
  2784. #define stat_inc_cp_count(si) do { } while (0)
  2785. #define stat_inc_bg_cp_count(si) do { } while (0)
  2786. #define stat_inc_call_count(si) do { } while (0)
  2787. #define stat_inc_bggc_count(si) do { } while (0)
  2788. #define stat_inc_dirty_inode(sbi, type) do { } while (0)
  2789. #define stat_dec_dirty_inode(sbi, type) do { } while (0)
  2790. #define stat_inc_total_hit(sb) do { } while (0)
  2791. #define stat_inc_rbtree_node_hit(sb) do { } while (0)
  2792. #define stat_inc_largest_node_hit(sbi) do { } while (0)
  2793. #define stat_inc_cached_node_hit(sbi) do { } while (0)
  2794. #define stat_inc_inline_xattr(inode) do { } while (0)
  2795. #define stat_dec_inline_xattr(inode) do { } while (0)
  2796. #define stat_inc_inline_inode(inode) do { } while (0)
  2797. #define stat_dec_inline_inode(inode) do { } while (0)
  2798. #define stat_inc_inline_dir(inode) do { } while (0)
  2799. #define stat_dec_inline_dir(inode) do { } while (0)
  2800. #define stat_inc_atomic_write(inode) do { } while (0)
  2801. #define stat_dec_atomic_write(inode) do { } while (0)
  2802. #define stat_update_max_atomic_write(inode) do { } while (0)
  2803. #define stat_inc_volatile_write(inode) do { } while (0)
  2804. #define stat_dec_volatile_write(inode) do { } while (0)
  2805. #define stat_update_max_volatile_write(inode) do { } while (0)
  2806. #define stat_inc_seg_type(sbi, curseg) do { } while (0)
  2807. #define stat_inc_block_count(sbi, curseg) do { } while (0)
  2808. #define stat_inc_inplace_blocks(sbi) do { } while (0)
  2809. #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0)
  2810. #define stat_inc_tot_blk_count(si, blks) do { } while (0)
  2811. #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0)
  2812. #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0)
  2813. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  2814. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  2815. static inline int __init f2fs_create_root_stats(void) { return 0; }
  2816. static inline void f2fs_destroy_root_stats(void) { }
  2817. #endif
  2818. extern const struct file_operations f2fs_dir_operations;
  2819. extern const struct file_operations f2fs_file_operations;
  2820. extern const struct inode_operations f2fs_file_inode_operations;
  2821. extern const struct address_space_operations f2fs_dblock_aops;
  2822. extern const struct address_space_operations f2fs_node_aops;
  2823. extern const struct address_space_operations f2fs_meta_aops;
  2824. extern const struct inode_operations f2fs_dir_inode_operations;
  2825. extern const struct inode_operations f2fs_symlink_inode_operations;
  2826. extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
  2827. extern const struct inode_operations f2fs_special_inode_operations;
  2828. extern struct kmem_cache *f2fs_inode_entry_slab;
  2829. /*
  2830. * inline.c
  2831. */
  2832. bool f2fs_may_inline_data(struct inode *inode);
  2833. bool f2fs_may_inline_dentry(struct inode *inode);
  2834. void f2fs_do_read_inline_data(struct page *page, struct page *ipage);
  2835. void f2fs_truncate_inline_inode(struct inode *inode,
  2836. struct page *ipage, u64 from);
  2837. int f2fs_read_inline_data(struct inode *inode, struct page *page);
  2838. int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
  2839. int f2fs_convert_inline_inode(struct inode *inode);
  2840. int f2fs_write_inline_data(struct inode *inode, struct page *page);
  2841. bool f2fs_recover_inline_data(struct inode *inode, struct page *npage);
  2842. struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
  2843. struct fscrypt_name *fname, struct page **res_page);
  2844. int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
  2845. struct page *ipage);
  2846. int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
  2847. const struct qstr *orig_name,
  2848. struct inode *inode, nid_t ino, umode_t mode);
  2849. void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
  2850. struct page *page, struct inode *dir,
  2851. struct inode *inode);
  2852. bool f2fs_empty_inline_dir(struct inode *dir);
  2853. int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
  2854. struct fscrypt_str *fstr);
  2855. int f2fs_inline_data_fiemap(struct inode *inode,
  2856. struct fiemap_extent_info *fieinfo,
  2857. __u64 start, __u64 len);
  2858. /*
  2859. * shrinker.c
  2860. */
  2861. unsigned long f2fs_shrink_count(struct shrinker *shrink,
  2862. struct shrink_control *sc);
  2863. unsigned long f2fs_shrink_scan(struct shrinker *shrink,
  2864. struct shrink_control *sc);
  2865. void f2fs_join_shrinker(struct f2fs_sb_info *sbi);
  2866. void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
  2867. /*
  2868. * extent_cache.c
  2869. */
  2870. struct rb_entry *f2fs_lookup_rb_tree(struct rb_root *root,
  2871. struct rb_entry *cached_re, unsigned int ofs);
  2872. struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi,
  2873. struct rb_root *root, struct rb_node **parent,
  2874. unsigned int ofs);
  2875. struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root *root,
  2876. struct rb_entry *cached_re, unsigned int ofs,
  2877. struct rb_entry **prev_entry, struct rb_entry **next_entry,
  2878. struct rb_node ***insert_p, struct rb_node **insert_parent,
  2879. bool force);
  2880. bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
  2881. struct rb_root *root);
  2882. unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
  2883. bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext);
  2884. void f2fs_drop_extent_tree(struct inode *inode);
  2885. unsigned int f2fs_destroy_extent_node(struct inode *inode);
  2886. void f2fs_destroy_extent_tree(struct inode *inode);
  2887. bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
  2888. struct extent_info *ei);
  2889. void f2fs_update_extent_cache(struct dnode_of_data *dn);
  2890. void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
  2891. pgoff_t fofs, block_t blkaddr, unsigned int len);
  2892. void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi);
  2893. int __init f2fs_create_extent_cache(void);
  2894. void f2fs_destroy_extent_cache(void);
  2895. /*
  2896. * sysfs.c
  2897. */
  2898. int __init f2fs_init_sysfs(void);
  2899. void f2fs_exit_sysfs(void);
  2900. int f2fs_register_sysfs(struct f2fs_sb_info *sbi);
  2901. void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi);
  2902. /*
  2903. * crypto support
  2904. */
  2905. static inline bool f2fs_encrypted_inode(struct inode *inode)
  2906. {
  2907. return file_is_encrypt(inode);
  2908. }
  2909. static inline bool f2fs_encrypted_file(struct inode *inode)
  2910. {
  2911. return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode);
  2912. }
  2913. static inline void f2fs_set_encrypted_inode(struct inode *inode)
  2914. {
  2915. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  2916. file_set_encrypt(inode);
  2917. inode->i_flags |= S_ENCRYPTED;
  2918. #endif
  2919. }
  2920. /*
  2921. * Returns true if the reads of the inode's data need to undergo some
  2922. * postprocessing step, like decryption or authenticity verification.
  2923. */
  2924. static inline bool f2fs_post_read_required(struct inode *inode)
  2925. {
  2926. return f2fs_encrypted_file(inode);
  2927. }
  2928. #define F2FS_FEATURE_FUNCS(name, flagname) \
  2929. static inline int f2fs_sb_has_##name(struct super_block *sb) \
  2930. { \
  2931. return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_##flagname); \
  2932. }
  2933. F2FS_FEATURE_FUNCS(encrypt, ENCRYPT);
  2934. F2FS_FEATURE_FUNCS(blkzoned, BLKZONED);
  2935. F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR);
  2936. F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA);
  2937. F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM);
  2938. F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
  2939. F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO);
  2940. F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME);
  2941. F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND);
  2942. #ifdef CONFIG_BLK_DEV_ZONED
  2943. static inline int get_blkz_type(struct f2fs_sb_info *sbi,
  2944. struct block_device *bdev, block_t blkaddr)
  2945. {
  2946. unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
  2947. int i;
  2948. for (i = 0; i < sbi->s_ndevs; i++)
  2949. if (FDEV(i).bdev == bdev)
  2950. return FDEV(i).blkz_type[zno];
  2951. return -EINVAL;
  2952. }
  2953. #endif
  2954. static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
  2955. {
  2956. struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
  2957. return blk_queue_discard(q) || f2fs_sb_has_blkzoned(sbi->sb);
  2958. }
  2959. static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
  2960. {
  2961. clear_opt(sbi, ADAPTIVE);
  2962. clear_opt(sbi, LFS);
  2963. switch (mt) {
  2964. case F2FS_MOUNT_ADAPTIVE:
  2965. set_opt(sbi, ADAPTIVE);
  2966. break;
  2967. case F2FS_MOUNT_LFS:
  2968. set_opt(sbi, LFS);
  2969. break;
  2970. }
  2971. }
  2972. static inline bool f2fs_may_encrypt(struct inode *inode)
  2973. {
  2974. #ifdef CONFIG_F2FS_FS_ENCRYPTION
  2975. umode_t mode = inode->i_mode;
  2976. return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
  2977. #else
  2978. return false;
  2979. #endif
  2980. }
  2981. static inline bool f2fs_force_buffered_io(struct inode *inode, int rw)
  2982. {
  2983. return (f2fs_post_read_required(inode) ||
  2984. (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
  2985. F2FS_I_SB(inode)->s_ndevs);
  2986. }
  2987. #ifdef CONFIG_F2FS_FAULT_INJECTION
  2988. extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
  2989. unsigned int type);
  2990. #else
  2991. #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0)
  2992. #endif
  2993. #endif