f2fs.h 51 KB

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