f2fs.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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. /*
  22. * For mount options
  23. */
  24. #define F2FS_MOUNT_BG_GC 0x00000001
  25. #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
  26. #define F2FS_MOUNT_DISCARD 0x00000004
  27. #define F2FS_MOUNT_NOHEAP 0x00000008
  28. #define F2FS_MOUNT_XATTR_USER 0x00000010
  29. #define F2FS_MOUNT_POSIX_ACL 0x00000020
  30. #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
  31. #define F2FS_MOUNT_INLINE_XATTR 0x00000080
  32. #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
  33. #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
  34. #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
  35. #define ver_after(a, b) (typecheck(unsigned long long, a) && \
  36. typecheck(unsigned long long, b) && \
  37. ((long long)((a) - (b)) > 0))
  38. typedef u32 block_t; /*
  39. * should not change u32, since it is the on-disk block
  40. * address format, __le32.
  41. */
  42. typedef u32 nid_t;
  43. struct f2fs_mount_info {
  44. unsigned int opt;
  45. };
  46. #define CRCPOLY_LE 0xedb88320
  47. static inline __u32 f2fs_crc32(void *buf, size_t len)
  48. {
  49. unsigned char *p = (unsigned char *)buf;
  50. __u32 crc = F2FS_SUPER_MAGIC;
  51. int i;
  52. while (len--) {
  53. crc ^= *p++;
  54. for (i = 0; i < 8; i++)
  55. crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
  56. }
  57. return crc;
  58. }
  59. static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
  60. {
  61. return f2fs_crc32(buf, buf_size) == blk_crc;
  62. }
  63. /*
  64. * For checkpoint manager
  65. */
  66. enum {
  67. NAT_BITMAP,
  68. SIT_BITMAP
  69. };
  70. /* for the list of orphan inodes */
  71. struct orphan_inode_entry {
  72. struct list_head list; /* list head */
  73. nid_t ino; /* inode number */
  74. };
  75. /* for the list of directory inodes */
  76. struct dir_inode_entry {
  77. struct list_head list; /* list head */
  78. struct inode *inode; /* vfs inode pointer */
  79. };
  80. /* for the list of fsync inodes, used only during recovery */
  81. struct fsync_inode_entry {
  82. struct list_head list; /* list head */
  83. struct inode *inode; /* vfs inode pointer */
  84. block_t blkaddr; /* block address locating the last inode */
  85. };
  86. #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
  87. #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
  88. #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
  89. #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
  90. #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
  91. #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
  92. static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
  93. {
  94. int before = nats_in_cursum(rs);
  95. rs->n_nats = cpu_to_le16(before + i);
  96. return before;
  97. }
  98. static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
  99. {
  100. int before = sits_in_cursum(rs);
  101. rs->n_sits = cpu_to_le16(before + i);
  102. return before;
  103. }
  104. /*
  105. * ioctl commands
  106. */
  107. #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
  108. #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
  109. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  110. /*
  111. * ioctl commands in 32 bit emulation
  112. */
  113. #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  114. #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  115. #endif
  116. /*
  117. * For INODE and NODE manager
  118. */
  119. /*
  120. * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
  121. * as its node offset to distinguish from index node blocks.
  122. * But some bits are used to mark the node block.
  123. */
  124. #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
  125. >> OFFSET_BIT_SHIFT)
  126. enum {
  127. ALLOC_NODE, /* allocate a new node page if needed */
  128. LOOKUP_NODE, /* look up a node without readahead */
  129. LOOKUP_NODE_RA, /*
  130. * look up a node with readahead called
  131. * by get_datablock_ro.
  132. */
  133. };
  134. #define F2FS_LINK_MAX 32000 /* maximum link count per file */
  135. /* for in-memory extent cache entry */
  136. struct extent_info {
  137. rwlock_t ext_lock; /* rwlock for consistency */
  138. unsigned int fofs; /* start offset in a file */
  139. u32 blk_addr; /* start block address of the extent */
  140. unsigned int len; /* length of the extent */
  141. };
  142. /*
  143. * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
  144. */
  145. #define FADVISE_COLD_BIT 0x01
  146. #define FADVISE_LOST_PINO_BIT 0x02
  147. struct f2fs_inode_info {
  148. struct inode vfs_inode; /* serve a vfs inode */
  149. unsigned long i_flags; /* keep an inode flags for ioctl */
  150. unsigned char i_advise; /* use to give file attribute hints */
  151. unsigned int i_current_depth; /* use only in directory structure */
  152. unsigned int i_pino; /* parent inode number */
  153. umode_t i_acl_mode; /* keep file acl mode temporarily */
  154. /* Use below internally in f2fs*/
  155. unsigned long flags; /* use to pass per-file flags */
  156. atomic_t dirty_dents; /* # of dirty dentry pages */
  157. f2fs_hash_t chash; /* hash value of given file name */
  158. unsigned int clevel; /* maximum level of given file name */
  159. nid_t i_xattr_nid; /* node id that contains xattrs */
  160. unsigned long long xattr_ver; /* cp version of xattr modification */
  161. struct extent_info ext; /* in-memory extent cache entry */
  162. };
  163. static inline void get_extent_info(struct extent_info *ext,
  164. struct f2fs_extent i_ext)
  165. {
  166. write_lock(&ext->ext_lock);
  167. ext->fofs = le32_to_cpu(i_ext.fofs);
  168. ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
  169. ext->len = le32_to_cpu(i_ext.len);
  170. write_unlock(&ext->ext_lock);
  171. }
  172. static inline void set_raw_extent(struct extent_info *ext,
  173. struct f2fs_extent *i_ext)
  174. {
  175. read_lock(&ext->ext_lock);
  176. i_ext->fofs = cpu_to_le32(ext->fofs);
  177. i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
  178. i_ext->len = cpu_to_le32(ext->len);
  179. read_unlock(&ext->ext_lock);
  180. }
  181. struct f2fs_nm_info {
  182. block_t nat_blkaddr; /* base disk address of NAT */
  183. nid_t max_nid; /* maximum possible node ids */
  184. nid_t next_scan_nid; /* the next nid to be scanned */
  185. /* NAT cache management */
  186. struct radix_tree_root nat_root;/* root of the nat entry cache */
  187. rwlock_t nat_tree_lock; /* protect nat_tree_lock */
  188. unsigned int nat_cnt; /* the # of cached nat entries */
  189. struct list_head nat_entries; /* cached nat entry list (clean) */
  190. struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
  191. /* free node ids management */
  192. struct list_head free_nid_list; /* a list for free nids */
  193. spinlock_t free_nid_list_lock; /* protect free nid list */
  194. unsigned int fcnt; /* the number of free node id */
  195. struct mutex build_lock; /* lock for build free nids */
  196. /* for checkpoint */
  197. char *nat_bitmap; /* NAT bitmap pointer */
  198. int bitmap_size; /* bitmap size */
  199. };
  200. /*
  201. * this structure is used as one of function parameters.
  202. * all the information are dedicated to a given direct node block determined
  203. * by the data offset in a file.
  204. */
  205. struct dnode_of_data {
  206. struct inode *inode; /* vfs inode pointer */
  207. struct page *inode_page; /* its inode page, NULL is possible */
  208. struct page *node_page; /* cached direct node page */
  209. nid_t nid; /* node id of the direct node block */
  210. unsigned int ofs_in_node; /* data offset in the node page */
  211. bool inode_page_locked; /* inode page is locked or not */
  212. block_t data_blkaddr; /* block address of the node block */
  213. };
  214. static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
  215. struct page *ipage, struct page *npage, nid_t nid)
  216. {
  217. memset(dn, 0, sizeof(*dn));
  218. dn->inode = inode;
  219. dn->inode_page = ipage;
  220. dn->node_page = npage;
  221. dn->nid = nid;
  222. }
  223. /*
  224. * For SIT manager
  225. *
  226. * By default, there are 6 active log areas across the whole main area.
  227. * When considering hot and cold data separation to reduce cleaning overhead,
  228. * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
  229. * respectively.
  230. * In the current design, you should not change the numbers intentionally.
  231. * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
  232. * logs individually according to the underlying devices. (default: 6)
  233. * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
  234. * data and 8 for node logs.
  235. */
  236. #define NR_CURSEG_DATA_TYPE (3)
  237. #define NR_CURSEG_NODE_TYPE (3)
  238. #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
  239. enum {
  240. CURSEG_HOT_DATA = 0, /* directory entry blocks */
  241. CURSEG_WARM_DATA, /* data blocks */
  242. CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
  243. CURSEG_HOT_NODE, /* direct node blocks of directory files */
  244. CURSEG_WARM_NODE, /* direct node blocks of normal files */
  245. CURSEG_COLD_NODE, /* indirect node blocks */
  246. NO_CHECK_TYPE
  247. };
  248. struct f2fs_sm_info {
  249. struct sit_info *sit_info; /* whole segment information */
  250. struct free_segmap_info *free_info; /* free segment information */
  251. struct dirty_seglist_info *dirty_info; /* dirty segment information */
  252. struct curseg_info *curseg_array; /* active segment information */
  253. struct list_head wblist_head; /* list of under-writeback pages */
  254. spinlock_t wblist_lock; /* lock for checkpoint */
  255. block_t seg0_blkaddr; /* block address of 0'th segment */
  256. block_t main_blkaddr; /* start block address of main area */
  257. block_t ssa_blkaddr; /* start block address of SSA area */
  258. unsigned int segment_count; /* total # of segments */
  259. unsigned int main_segments; /* # of segments in main area */
  260. unsigned int reserved_segments; /* # of reserved segments */
  261. unsigned int ovp_segments; /* # of overprovision segments */
  262. /* a threshold to reclaim prefree segments */
  263. unsigned int rec_prefree_segments;
  264. };
  265. /*
  266. * For superblock
  267. */
  268. /*
  269. * COUNT_TYPE for monitoring
  270. *
  271. * f2fs monitors the number of several block types such as on-writeback,
  272. * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
  273. */
  274. enum count_type {
  275. F2FS_WRITEBACK,
  276. F2FS_DIRTY_DENTS,
  277. F2FS_DIRTY_NODES,
  278. F2FS_DIRTY_META,
  279. NR_COUNT_TYPE,
  280. };
  281. /*
  282. * The below are the page types of bios used in submti_bio().
  283. * The available types are:
  284. * DATA User data pages. It operates as async mode.
  285. * NODE Node pages. It operates as async mode.
  286. * META FS metadata pages such as SIT, NAT, CP.
  287. * NR_PAGE_TYPE The number of page types.
  288. * META_FLUSH Make sure the previous pages are written
  289. * with waiting the bio's completion
  290. * ... Only can be used with META.
  291. */
  292. enum page_type {
  293. DATA,
  294. NODE,
  295. META,
  296. NR_PAGE_TYPE,
  297. META_FLUSH,
  298. };
  299. struct f2fs_sb_info {
  300. struct super_block *sb; /* pointer to VFS super block */
  301. struct proc_dir_entry *s_proc; /* proc entry */
  302. struct buffer_head *raw_super_buf; /* buffer head of raw sb */
  303. struct f2fs_super_block *raw_super; /* raw super block pointer */
  304. int s_dirty; /* dirty flag for checkpoint */
  305. /* for node-related operations */
  306. struct f2fs_nm_info *nm_info; /* node manager */
  307. struct inode *node_inode; /* cache node blocks */
  308. /* for segment-related operations */
  309. struct f2fs_sm_info *sm_info; /* segment manager */
  310. struct bio *bio[NR_PAGE_TYPE]; /* bios to merge */
  311. sector_t last_block_in_bio[NR_PAGE_TYPE]; /* last block number */
  312. struct rw_semaphore bio_sem; /* IO semaphore */
  313. /* for checkpoint */
  314. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  315. struct inode *meta_inode; /* cache meta blocks */
  316. struct mutex cp_mutex; /* checkpoint procedure lock */
  317. struct rw_semaphore cp_rwsem; /* blocking FS operations */
  318. struct mutex node_write; /* locking node writes */
  319. struct mutex writepages; /* mutex for writepages() */
  320. bool por_doing; /* recovery is doing or not */
  321. bool on_build_free_nids; /* build_free_nids is doing */
  322. struct task_struct *cp_task; /* checkpoint task */
  323. /* for orphan inode management */
  324. struct list_head orphan_inode_list; /* orphan inode list */
  325. struct mutex orphan_inode_mutex; /* for orphan inode list */
  326. unsigned int n_orphans; /* # of orphan inodes */
  327. /* for directory inode management */
  328. struct list_head dir_inode_list; /* dir inode list */
  329. spinlock_t dir_inode_lock; /* for dir inode list lock */
  330. /* basic file system units */
  331. unsigned int log_sectors_per_block; /* log2 sectors per block */
  332. unsigned int log_blocksize; /* log2 block size */
  333. unsigned int blocksize; /* block size */
  334. unsigned int root_ino_num; /* root inode number*/
  335. unsigned int node_ino_num; /* node inode number*/
  336. unsigned int meta_ino_num; /* meta inode number*/
  337. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  338. unsigned int blocks_per_seg; /* blocks per segment */
  339. unsigned int segs_per_sec; /* segments per section */
  340. unsigned int secs_per_zone; /* sections per zone */
  341. unsigned int total_sections; /* total section count */
  342. unsigned int total_node_count; /* total node block count */
  343. unsigned int total_valid_node_count; /* valid node block count */
  344. unsigned int total_valid_inode_count; /* valid inode count */
  345. int active_logs; /* # of active logs */
  346. block_t user_block_count; /* # of user blocks */
  347. block_t total_valid_block_count; /* # of valid blocks */
  348. block_t alloc_valid_block_count; /* # of allocated blocks */
  349. block_t last_valid_block_count; /* for recovery */
  350. u32 s_next_generation; /* for NFS support */
  351. atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
  352. struct f2fs_mount_info mount_opt; /* mount options */
  353. /* for cleaning operations */
  354. struct mutex gc_mutex; /* mutex for GC */
  355. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  356. unsigned int cur_victim_sec; /* current victim section num */
  357. /*
  358. * for stat information.
  359. * one is for the LFS mode, and the other is for the SSR mode.
  360. */
  361. #ifdef CONFIG_F2FS_STAT_FS
  362. struct f2fs_stat_info *stat_info; /* FS status information */
  363. unsigned int segment_count[2]; /* # of allocated segments */
  364. unsigned int block_count[2]; /* # of allocated blocks */
  365. int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
  366. int bg_gc; /* background gc calls */
  367. unsigned int n_dirty_dirs; /* # of dir inodes */
  368. #endif
  369. unsigned int last_victim[2]; /* last victim segment # */
  370. spinlock_t stat_lock; /* lock for stat operations */
  371. /* For sysfs suppport */
  372. struct kobject s_kobj;
  373. struct completion s_kobj_unregister;
  374. };
  375. /*
  376. * Inline functions
  377. */
  378. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  379. {
  380. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  381. }
  382. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  383. {
  384. return sb->s_fs_info;
  385. }
  386. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  387. {
  388. return (struct f2fs_super_block *)(sbi->raw_super);
  389. }
  390. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  391. {
  392. return (struct f2fs_checkpoint *)(sbi->ckpt);
  393. }
  394. static inline struct f2fs_node *F2FS_NODE(struct page *page)
  395. {
  396. return (struct f2fs_node *)page_address(page);
  397. }
  398. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  399. {
  400. return (struct f2fs_nm_info *)(sbi->nm_info);
  401. }
  402. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  403. {
  404. return (struct f2fs_sm_info *)(sbi->sm_info);
  405. }
  406. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  407. {
  408. return (struct sit_info *)(SM_I(sbi)->sit_info);
  409. }
  410. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  411. {
  412. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  413. }
  414. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  415. {
  416. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  417. }
  418. static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
  419. {
  420. sbi->s_dirty = 1;
  421. }
  422. static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
  423. {
  424. sbi->s_dirty = 0;
  425. }
  426. static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
  427. {
  428. return le64_to_cpu(cp->checkpoint_ver);
  429. }
  430. static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  431. {
  432. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  433. return ckpt_flags & f;
  434. }
  435. static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  436. {
  437. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  438. ckpt_flags |= f;
  439. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  440. }
  441. static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  442. {
  443. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  444. ckpt_flags &= (~f);
  445. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  446. }
  447. static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
  448. {
  449. down_read(&sbi->cp_rwsem);
  450. }
  451. static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
  452. {
  453. up_read(&sbi->cp_rwsem);
  454. }
  455. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  456. {
  457. down_write_nest_lock(&sbi->cp_rwsem, &sbi->cp_mutex);
  458. }
  459. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  460. {
  461. up_write(&sbi->cp_rwsem);
  462. }
  463. /*
  464. * Check whether the given nid is within node id range.
  465. */
  466. static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
  467. {
  468. WARN_ON((nid >= NM_I(sbi)->max_nid));
  469. if (nid >= NM_I(sbi)->max_nid)
  470. return -EINVAL;
  471. return 0;
  472. }
  473. #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
  474. /*
  475. * Check whether the inode has blocks or not
  476. */
  477. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  478. {
  479. if (F2FS_I(inode)->i_xattr_nid)
  480. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1);
  481. else
  482. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS);
  483. }
  484. static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
  485. struct inode *inode, blkcnt_t count)
  486. {
  487. block_t valid_block_count;
  488. spin_lock(&sbi->stat_lock);
  489. valid_block_count =
  490. sbi->total_valid_block_count + (block_t)count;
  491. if (valid_block_count > sbi->user_block_count) {
  492. spin_unlock(&sbi->stat_lock);
  493. return false;
  494. }
  495. inode->i_blocks += count;
  496. sbi->total_valid_block_count = valid_block_count;
  497. sbi->alloc_valid_block_count += (block_t)count;
  498. spin_unlock(&sbi->stat_lock);
  499. return true;
  500. }
  501. static inline int dec_valid_block_count(struct f2fs_sb_info *sbi,
  502. struct inode *inode,
  503. blkcnt_t count)
  504. {
  505. spin_lock(&sbi->stat_lock);
  506. BUG_ON(sbi->total_valid_block_count < (block_t) count);
  507. BUG_ON(inode->i_blocks < count);
  508. inode->i_blocks -= count;
  509. sbi->total_valid_block_count -= (block_t)count;
  510. spin_unlock(&sbi->stat_lock);
  511. return 0;
  512. }
  513. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  514. {
  515. atomic_inc(&sbi->nr_pages[count_type]);
  516. F2FS_SET_SB_DIRT(sbi);
  517. }
  518. static inline void inode_inc_dirty_dents(struct inode *inode)
  519. {
  520. atomic_inc(&F2FS_I(inode)->dirty_dents);
  521. }
  522. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  523. {
  524. atomic_dec(&sbi->nr_pages[count_type]);
  525. }
  526. static inline void inode_dec_dirty_dents(struct inode *inode)
  527. {
  528. atomic_dec(&F2FS_I(inode)->dirty_dents);
  529. }
  530. static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
  531. {
  532. return atomic_read(&sbi->nr_pages[count_type]);
  533. }
  534. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  535. {
  536. unsigned int pages_per_sec = sbi->segs_per_sec *
  537. (1 << sbi->log_blocks_per_seg);
  538. return ((get_pages(sbi, block_type) + pages_per_sec - 1)
  539. >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
  540. }
  541. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  542. {
  543. block_t ret;
  544. spin_lock(&sbi->stat_lock);
  545. ret = sbi->total_valid_block_count;
  546. spin_unlock(&sbi->stat_lock);
  547. return ret;
  548. }
  549. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  550. {
  551. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  552. /* return NAT or SIT bitmap */
  553. if (flag == NAT_BITMAP)
  554. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  555. else if (flag == SIT_BITMAP)
  556. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  557. return 0;
  558. }
  559. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  560. {
  561. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  562. int offset = (flag == NAT_BITMAP) ?
  563. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  564. return &ckpt->sit_nat_version_bitmap + offset;
  565. }
  566. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  567. {
  568. block_t start_addr;
  569. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  570. unsigned long long ckpt_version = cur_cp_version(ckpt);
  571. start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  572. /*
  573. * odd numbered checkpoint should at cp segment 0
  574. * and even segent must be at cp segment 1
  575. */
  576. if (!(ckpt_version & 1))
  577. start_addr += sbi->blocks_per_seg;
  578. return start_addr;
  579. }
  580. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  581. {
  582. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  583. }
  584. static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
  585. struct inode *inode,
  586. unsigned int count)
  587. {
  588. block_t valid_block_count;
  589. unsigned int valid_node_count;
  590. spin_lock(&sbi->stat_lock);
  591. valid_block_count = sbi->total_valid_block_count + (block_t)count;
  592. sbi->alloc_valid_block_count += (block_t)count;
  593. valid_node_count = sbi->total_valid_node_count + count;
  594. if (valid_block_count > sbi->user_block_count) {
  595. spin_unlock(&sbi->stat_lock);
  596. return false;
  597. }
  598. if (valid_node_count > sbi->total_node_count) {
  599. spin_unlock(&sbi->stat_lock);
  600. return false;
  601. }
  602. if (inode)
  603. inode->i_blocks += count;
  604. sbi->total_valid_node_count = valid_node_count;
  605. sbi->total_valid_block_count = valid_block_count;
  606. spin_unlock(&sbi->stat_lock);
  607. return true;
  608. }
  609. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  610. struct inode *inode,
  611. unsigned int count)
  612. {
  613. spin_lock(&sbi->stat_lock);
  614. BUG_ON(sbi->total_valid_block_count < count);
  615. BUG_ON(sbi->total_valid_node_count < count);
  616. BUG_ON(inode->i_blocks < count);
  617. inode->i_blocks -= count;
  618. sbi->total_valid_node_count -= count;
  619. sbi->total_valid_block_count -= (block_t)count;
  620. spin_unlock(&sbi->stat_lock);
  621. }
  622. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  623. {
  624. unsigned int ret;
  625. spin_lock(&sbi->stat_lock);
  626. ret = sbi->total_valid_node_count;
  627. spin_unlock(&sbi->stat_lock);
  628. return ret;
  629. }
  630. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  631. {
  632. spin_lock(&sbi->stat_lock);
  633. BUG_ON(sbi->total_valid_inode_count == sbi->total_node_count);
  634. sbi->total_valid_inode_count++;
  635. spin_unlock(&sbi->stat_lock);
  636. }
  637. static inline int dec_valid_inode_count(struct f2fs_sb_info *sbi)
  638. {
  639. spin_lock(&sbi->stat_lock);
  640. BUG_ON(!sbi->total_valid_inode_count);
  641. sbi->total_valid_inode_count--;
  642. spin_unlock(&sbi->stat_lock);
  643. return 0;
  644. }
  645. static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
  646. {
  647. unsigned int ret;
  648. spin_lock(&sbi->stat_lock);
  649. ret = sbi->total_valid_inode_count;
  650. spin_unlock(&sbi->stat_lock);
  651. return ret;
  652. }
  653. static inline void f2fs_put_page(struct page *page, int unlock)
  654. {
  655. if (!page || IS_ERR(page))
  656. return;
  657. if (unlock) {
  658. BUG_ON(!PageLocked(page));
  659. unlock_page(page);
  660. }
  661. page_cache_release(page);
  662. }
  663. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  664. {
  665. if (dn->node_page)
  666. f2fs_put_page(dn->node_page, 1);
  667. if (dn->inode_page && dn->node_page != dn->inode_page)
  668. f2fs_put_page(dn->inode_page, 0);
  669. dn->node_page = NULL;
  670. dn->inode_page = NULL;
  671. }
  672. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  673. size_t size, void (*ctor)(void *))
  674. {
  675. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
  676. }
  677. static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
  678. gfp_t flags)
  679. {
  680. void *entry;
  681. retry:
  682. entry = kmem_cache_alloc(cachep, flags);
  683. if (!entry) {
  684. cond_resched();
  685. goto retry;
  686. }
  687. return entry;
  688. }
  689. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  690. static inline bool IS_INODE(struct page *page)
  691. {
  692. struct f2fs_node *p = F2FS_NODE(page);
  693. return RAW_IS_INODE(p);
  694. }
  695. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  696. {
  697. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  698. }
  699. static inline block_t datablock_addr(struct page *node_page,
  700. unsigned int offset)
  701. {
  702. struct f2fs_node *raw_node;
  703. __le32 *addr_array;
  704. raw_node = F2FS_NODE(node_page);
  705. addr_array = blkaddr_in_node(raw_node);
  706. return le32_to_cpu(addr_array[offset]);
  707. }
  708. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  709. {
  710. int mask;
  711. addr += (nr >> 3);
  712. mask = 1 << (7 - (nr & 0x07));
  713. return mask & *addr;
  714. }
  715. static inline int f2fs_set_bit(unsigned int nr, char *addr)
  716. {
  717. int mask;
  718. int ret;
  719. addr += (nr >> 3);
  720. mask = 1 << (7 - (nr & 0x07));
  721. ret = mask & *addr;
  722. *addr |= mask;
  723. return ret;
  724. }
  725. static inline int f2fs_clear_bit(unsigned int nr, char *addr)
  726. {
  727. int mask;
  728. int ret;
  729. addr += (nr >> 3);
  730. mask = 1 << (7 - (nr & 0x07));
  731. ret = mask & *addr;
  732. *addr &= ~mask;
  733. return ret;
  734. }
  735. /* used for f2fs_inode_info->flags */
  736. enum {
  737. FI_NEW_INODE, /* indicate newly allocated inode */
  738. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  739. FI_INC_LINK, /* need to increment i_nlink */
  740. FI_ACL_MODE, /* indicate acl mode */
  741. FI_NO_ALLOC, /* should not allocate any blocks */
  742. FI_UPDATE_DIR, /* should update inode block for consistency */
  743. FI_DELAY_IPUT, /* used for the recovery */
  744. FI_INLINE_XATTR, /* used for inline xattr */
  745. };
  746. static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
  747. {
  748. set_bit(flag, &fi->flags);
  749. }
  750. static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
  751. {
  752. return test_bit(flag, &fi->flags);
  753. }
  754. static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  755. {
  756. clear_bit(flag, &fi->flags);
  757. }
  758. static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
  759. {
  760. fi->i_acl_mode = mode;
  761. set_inode_flag(fi, FI_ACL_MODE);
  762. }
  763. static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  764. {
  765. if (is_inode_flag_set(fi, FI_ACL_MODE)) {
  766. clear_inode_flag(fi, FI_ACL_MODE);
  767. return 1;
  768. }
  769. return 0;
  770. }
  771. static inline void get_inline_info(struct f2fs_inode_info *fi,
  772. struct f2fs_inode *ri)
  773. {
  774. if (ri->i_inline & F2FS_INLINE_XATTR)
  775. set_inode_flag(fi, FI_INLINE_XATTR);
  776. }
  777. static inline void set_raw_inline(struct f2fs_inode_info *fi,
  778. struct f2fs_inode *ri)
  779. {
  780. ri->i_inline = 0;
  781. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  782. ri->i_inline |= F2FS_INLINE_XATTR;
  783. }
  784. static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
  785. {
  786. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  787. return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
  788. return DEF_ADDRS_PER_INODE;
  789. }
  790. static inline void *inline_xattr_addr(struct page *page)
  791. {
  792. struct f2fs_inode *ri;
  793. ri = (struct f2fs_inode *)page_address(page);
  794. return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
  795. F2FS_INLINE_XATTR_ADDRS]);
  796. }
  797. static inline int inline_xattr_size(struct inode *inode)
  798. {
  799. if (is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR))
  800. return F2FS_INLINE_XATTR_ADDRS << 2;
  801. else
  802. return 0;
  803. }
  804. static inline int f2fs_readonly(struct super_block *sb)
  805. {
  806. return sb->s_flags & MS_RDONLY;
  807. }
  808. /*
  809. * file.c
  810. */
  811. int f2fs_sync_file(struct file *, loff_t, loff_t, int);
  812. void truncate_data_blocks(struct dnode_of_data *);
  813. void f2fs_truncate(struct inode *);
  814. int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  815. int f2fs_setattr(struct dentry *, struct iattr *);
  816. int truncate_hole(struct inode *, pgoff_t, pgoff_t);
  817. int truncate_data_blocks_range(struct dnode_of_data *, int);
  818. long f2fs_ioctl(struct file *, unsigned int, unsigned long);
  819. long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
  820. /*
  821. * inode.c
  822. */
  823. void f2fs_set_inode_flags(struct inode *);
  824. struct inode *f2fs_iget(struct super_block *, unsigned long);
  825. void update_inode(struct inode *, struct page *);
  826. int update_inode_page(struct inode *);
  827. int f2fs_write_inode(struct inode *, struct writeback_control *);
  828. void f2fs_evict_inode(struct inode *);
  829. /*
  830. * namei.c
  831. */
  832. struct dentry *f2fs_get_parent(struct dentry *child);
  833. /*
  834. * dir.c
  835. */
  836. struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
  837. struct page **);
  838. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
  839. ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
  840. void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
  841. struct page *, struct inode *);
  842. int update_dent_inode(struct inode *, const struct qstr *);
  843. int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
  844. void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
  845. int f2fs_make_empty(struct inode *, struct inode *);
  846. bool f2fs_empty_dir(struct inode *);
  847. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  848. {
  849. return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
  850. inode);
  851. }
  852. /*
  853. * super.c
  854. */
  855. int f2fs_sync_fs(struct super_block *, int);
  856. extern __printf(3, 4)
  857. void f2fs_msg(struct super_block *, const char *, const char *, ...);
  858. /*
  859. * hash.c
  860. */
  861. f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
  862. /*
  863. * node.c
  864. */
  865. struct dnode_of_data;
  866. struct node_info;
  867. int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
  868. void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
  869. int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
  870. int truncate_inode_blocks(struct inode *, pgoff_t);
  871. int truncate_xattr_node(struct inode *, struct page *);
  872. int remove_inode_page(struct inode *);
  873. struct page *new_inode_page(struct inode *, const struct qstr *);
  874. struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
  875. void ra_node_page(struct f2fs_sb_info *, nid_t);
  876. struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
  877. struct page *get_node_page_ra(struct page *, int);
  878. void sync_inode_page(struct dnode_of_data *);
  879. int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
  880. bool alloc_nid(struct f2fs_sb_info *, nid_t *);
  881. void alloc_nid_done(struct f2fs_sb_info *, nid_t);
  882. void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
  883. void recover_node_page(struct f2fs_sb_info *, struct page *,
  884. struct f2fs_summary *, struct node_info *, block_t);
  885. int recover_inode_page(struct f2fs_sb_info *, struct page *);
  886. int restore_node_summary(struct f2fs_sb_info *, unsigned int,
  887. struct f2fs_summary_block *);
  888. void flush_nat_entries(struct f2fs_sb_info *);
  889. int build_node_manager(struct f2fs_sb_info *);
  890. void destroy_node_manager(struct f2fs_sb_info *);
  891. int __init create_node_manager_caches(void);
  892. void destroy_node_manager_caches(void);
  893. /*
  894. * segment.c
  895. */
  896. void f2fs_balance_fs(struct f2fs_sb_info *);
  897. void invalidate_blocks(struct f2fs_sb_info *, block_t);
  898. void clear_prefree_segments(struct f2fs_sb_info *);
  899. int npages_for_summary_flush(struct f2fs_sb_info *);
  900. void allocate_new_segments(struct f2fs_sb_info *);
  901. struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
  902. struct bio *f2fs_bio_alloc(struct block_device *, int);
  903. void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool);
  904. void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
  905. void write_meta_page(struct f2fs_sb_info *, struct page *);
  906. void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
  907. block_t, block_t *);
  908. void write_data_page(struct inode *, struct page *, struct dnode_of_data*,
  909. block_t, block_t *);
  910. void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t);
  911. void recover_data_page(struct f2fs_sb_info *, struct page *,
  912. struct f2fs_summary *, block_t, block_t);
  913. void rewrite_node_page(struct f2fs_sb_info *, struct page *,
  914. struct f2fs_summary *, block_t, block_t);
  915. void write_data_summaries(struct f2fs_sb_info *, block_t);
  916. void write_node_summaries(struct f2fs_sb_info *, block_t);
  917. int lookup_journal_in_cursum(struct f2fs_summary_block *,
  918. int, unsigned int, int);
  919. void flush_sit_entries(struct f2fs_sb_info *);
  920. int build_segment_manager(struct f2fs_sb_info *);
  921. void destroy_segment_manager(struct f2fs_sb_info *);
  922. /*
  923. * checkpoint.c
  924. */
  925. struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
  926. struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
  927. long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
  928. int acquire_orphan_inode(struct f2fs_sb_info *);
  929. void release_orphan_inode(struct f2fs_sb_info *);
  930. void add_orphan_inode(struct f2fs_sb_info *, nid_t);
  931. void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
  932. int recover_orphan_inodes(struct f2fs_sb_info *);
  933. int get_valid_checkpoint(struct f2fs_sb_info *);
  934. void set_dirty_dir_page(struct inode *, struct page *);
  935. void add_dirty_dir_inode(struct inode *);
  936. void remove_dirty_dir_inode(struct inode *);
  937. struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
  938. void sync_dirty_dir_inodes(struct f2fs_sb_info *);
  939. void write_checkpoint(struct f2fs_sb_info *, bool);
  940. void init_orphan_info(struct f2fs_sb_info *);
  941. int __init create_checkpoint_caches(void);
  942. void destroy_checkpoint_caches(void);
  943. /*
  944. * data.c
  945. */
  946. int reserve_new_block(struct dnode_of_data *);
  947. void update_extent_cache(block_t, struct dnode_of_data *);
  948. struct page *find_data_page(struct inode *, pgoff_t, bool);
  949. struct page *get_lock_data_page(struct inode *, pgoff_t);
  950. struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
  951. int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
  952. int do_write_data_page(struct page *);
  953. /*
  954. * gc.c
  955. */
  956. int start_gc_thread(struct f2fs_sb_info *);
  957. void stop_gc_thread(struct f2fs_sb_info *);
  958. block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
  959. int f2fs_gc(struct f2fs_sb_info *);
  960. void build_gc_manager(struct f2fs_sb_info *);
  961. int __init create_gc_caches(void);
  962. void destroy_gc_caches(void);
  963. /*
  964. * recovery.c
  965. */
  966. int recover_fsync_data(struct f2fs_sb_info *);
  967. bool space_for_roll_forward(struct f2fs_sb_info *);
  968. /*
  969. * debug.c
  970. */
  971. #ifdef CONFIG_F2FS_STAT_FS
  972. struct f2fs_stat_info {
  973. struct list_head stat_list;
  974. struct f2fs_sb_info *sbi;
  975. struct mutex stat_lock;
  976. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  977. int main_area_segs, main_area_sections, main_area_zones;
  978. int hit_ext, total_ext;
  979. int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
  980. int nats, sits, fnids;
  981. int total_count, utilization;
  982. int bg_gc;
  983. unsigned int valid_count, valid_node_count, valid_inode_count;
  984. unsigned int bimodal, avg_vblocks;
  985. int util_free, util_valid, util_invalid;
  986. int rsvd_segs, overp_segs;
  987. int dirty_count, node_pages, meta_pages;
  988. int prefree_count, call_count;
  989. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  990. int tot_blks, data_blks, node_blks;
  991. int curseg[NR_CURSEG_TYPE];
  992. int cursec[NR_CURSEG_TYPE];
  993. int curzone[NR_CURSEG_TYPE];
  994. unsigned int segment_count[2];
  995. unsigned int block_count[2];
  996. unsigned base_mem, cache_mem;
  997. };
  998. static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
  999. {
  1000. return (struct f2fs_stat_info*)sbi->stat_info;
  1001. }
  1002. #define stat_inc_call_count(si) ((si)->call_count++)
  1003. #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
  1004. #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++)
  1005. #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--)
  1006. #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++)
  1007. #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++)
  1008. #define stat_inc_seg_type(sbi, curseg) \
  1009. ((sbi)->segment_count[(curseg)->alloc_type]++)
  1010. #define stat_inc_block_count(sbi, curseg) \
  1011. ((sbi)->block_count[(curseg)->alloc_type]++)
  1012. #define stat_inc_seg_count(sbi, type) \
  1013. do { \
  1014. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1015. (si)->tot_segs++; \
  1016. if (type == SUM_TYPE_DATA) \
  1017. si->data_segs++; \
  1018. else \
  1019. si->node_segs++; \
  1020. } while (0)
  1021. #define stat_inc_tot_blk_count(si, blks) \
  1022. (si->tot_blks += (blks))
  1023. #define stat_inc_data_blk_count(sbi, blks) \
  1024. do { \
  1025. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1026. stat_inc_tot_blk_count(si, blks); \
  1027. si->data_blks += (blks); \
  1028. } while (0)
  1029. #define stat_inc_node_blk_count(sbi, blks) \
  1030. do { \
  1031. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1032. stat_inc_tot_blk_count(si, blks); \
  1033. si->node_blks += (blks); \
  1034. } while (0)
  1035. int f2fs_build_stats(struct f2fs_sb_info *);
  1036. void f2fs_destroy_stats(struct f2fs_sb_info *);
  1037. void __init f2fs_create_root_stats(void);
  1038. void f2fs_destroy_root_stats(void);
  1039. #else
  1040. #define stat_inc_call_count(si)
  1041. #define stat_inc_bggc_count(si)
  1042. #define stat_inc_dirty_dir(sbi)
  1043. #define stat_dec_dirty_dir(sbi)
  1044. #define stat_inc_total_hit(sb)
  1045. #define stat_inc_read_hit(sb)
  1046. #define stat_inc_seg_type(sbi, curseg)
  1047. #define stat_inc_block_count(sbi, curseg)
  1048. #define stat_inc_seg_count(si, type)
  1049. #define stat_inc_tot_blk_count(si, blks)
  1050. #define stat_inc_data_blk_count(si, blks)
  1051. #define stat_inc_node_blk_count(sbi, blks)
  1052. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  1053. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  1054. static inline void __init f2fs_create_root_stats(void) { }
  1055. static inline void f2fs_destroy_root_stats(void) { }
  1056. #endif
  1057. extern const struct file_operations f2fs_dir_operations;
  1058. extern const struct file_operations f2fs_file_operations;
  1059. extern const struct inode_operations f2fs_file_inode_operations;
  1060. extern const struct address_space_operations f2fs_dblock_aops;
  1061. extern const struct address_space_operations f2fs_node_aops;
  1062. extern const struct address_space_operations f2fs_meta_aops;
  1063. extern const struct inode_operations f2fs_dir_inode_operations;
  1064. extern const struct inode_operations f2fs_symlink_inode_operations;
  1065. extern const struct inode_operations f2fs_special_inode_operations;
  1066. #endif