f2fs.h 55 KB

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