f2fs.h 65 KB

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