f2fs.h 69 KB

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