f2fs.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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. };
  263. /*
  264. * For superblock
  265. */
  266. /*
  267. * COUNT_TYPE for monitoring
  268. *
  269. * f2fs monitors the number of several block types such as on-writeback,
  270. * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
  271. */
  272. enum count_type {
  273. F2FS_WRITEBACK,
  274. F2FS_DIRTY_DENTS,
  275. F2FS_DIRTY_NODES,
  276. F2FS_DIRTY_META,
  277. NR_COUNT_TYPE,
  278. };
  279. /*
  280. * The below are the page types of bios used in submti_bio().
  281. * The available types are:
  282. * DATA User data pages. It operates as async mode.
  283. * NODE Node pages. It operates as async mode.
  284. * META FS metadata pages such as SIT, NAT, CP.
  285. * NR_PAGE_TYPE The number of page types.
  286. * META_FLUSH Make sure the previous pages are written
  287. * with waiting the bio's completion
  288. * ... Only can be used with META.
  289. */
  290. enum page_type {
  291. DATA,
  292. NODE,
  293. META,
  294. NR_PAGE_TYPE,
  295. META_FLUSH,
  296. };
  297. struct f2fs_sb_info {
  298. struct super_block *sb; /* pointer to VFS super block */
  299. struct proc_dir_entry *s_proc; /* proc entry */
  300. struct buffer_head *raw_super_buf; /* buffer head of raw sb */
  301. struct f2fs_super_block *raw_super; /* raw super block pointer */
  302. int s_dirty; /* dirty flag for checkpoint */
  303. /* for node-related operations */
  304. struct f2fs_nm_info *nm_info; /* node manager */
  305. struct inode *node_inode; /* cache node blocks */
  306. /* for segment-related operations */
  307. struct f2fs_sm_info *sm_info; /* segment manager */
  308. struct bio *bio[NR_PAGE_TYPE]; /* bios to merge */
  309. sector_t last_block_in_bio[NR_PAGE_TYPE]; /* last block number */
  310. struct rw_semaphore bio_sem; /* IO semaphore */
  311. /* for checkpoint */
  312. struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
  313. struct inode *meta_inode; /* cache meta blocks */
  314. struct mutex cp_mutex; /* checkpoint procedure lock */
  315. struct rw_semaphore cp_rwsem; /* blocking FS operations */
  316. struct mutex node_write; /* locking node writes */
  317. struct mutex writepages; /* mutex for writepages() */
  318. bool por_doing; /* recovery is doing or not */
  319. bool on_build_free_nids; /* build_free_nids is doing */
  320. struct task_struct *cp_task; /* checkpoint task */
  321. /* for orphan inode management */
  322. struct list_head orphan_inode_list; /* orphan inode list */
  323. struct mutex orphan_inode_mutex; /* for orphan inode list */
  324. unsigned int n_orphans; /* # of orphan inodes */
  325. /* for directory inode management */
  326. struct list_head dir_inode_list; /* dir inode list */
  327. spinlock_t dir_inode_lock; /* for dir inode list lock */
  328. /* basic file system units */
  329. unsigned int log_sectors_per_block; /* log2 sectors per block */
  330. unsigned int log_blocksize; /* log2 block size */
  331. unsigned int blocksize; /* block size */
  332. unsigned int root_ino_num; /* root inode number*/
  333. unsigned int node_ino_num; /* node inode number*/
  334. unsigned int meta_ino_num; /* meta inode number*/
  335. unsigned int log_blocks_per_seg; /* log2 blocks per segment */
  336. unsigned int blocks_per_seg; /* blocks per segment */
  337. unsigned int segs_per_sec; /* segments per section */
  338. unsigned int secs_per_zone; /* sections per zone */
  339. unsigned int total_sections; /* total section count */
  340. unsigned int total_node_count; /* total node block count */
  341. unsigned int total_valid_node_count; /* valid node block count */
  342. unsigned int total_valid_inode_count; /* valid inode count */
  343. int active_logs; /* # of active logs */
  344. block_t user_block_count; /* # of user blocks */
  345. block_t total_valid_block_count; /* # of valid blocks */
  346. block_t alloc_valid_block_count; /* # of allocated blocks */
  347. block_t last_valid_block_count; /* for recovery */
  348. u32 s_next_generation; /* for NFS support */
  349. atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
  350. struct f2fs_mount_info mount_opt; /* mount options */
  351. /* for cleaning operations */
  352. struct mutex gc_mutex; /* mutex for GC */
  353. struct f2fs_gc_kthread *gc_thread; /* GC thread */
  354. unsigned int cur_victim_sec; /* current victim section num */
  355. /*
  356. * for stat information.
  357. * one is for the LFS mode, and the other is for the SSR mode.
  358. */
  359. #ifdef CONFIG_F2FS_STAT_FS
  360. struct f2fs_stat_info *stat_info; /* FS status information */
  361. unsigned int segment_count[2]; /* # of allocated segments */
  362. unsigned int block_count[2]; /* # of allocated blocks */
  363. int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
  364. int bg_gc; /* background gc calls */
  365. unsigned int n_dirty_dirs; /* # of dir inodes */
  366. #endif
  367. unsigned int last_victim[2]; /* last victim segment # */
  368. spinlock_t stat_lock; /* lock for stat operations */
  369. /* For sysfs suppport */
  370. struct kobject s_kobj;
  371. struct completion s_kobj_unregister;
  372. };
  373. /*
  374. * Inline functions
  375. */
  376. static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
  377. {
  378. return container_of(inode, struct f2fs_inode_info, vfs_inode);
  379. }
  380. static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
  381. {
  382. return sb->s_fs_info;
  383. }
  384. static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
  385. {
  386. return (struct f2fs_super_block *)(sbi->raw_super);
  387. }
  388. static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
  389. {
  390. return (struct f2fs_checkpoint *)(sbi->ckpt);
  391. }
  392. static inline struct f2fs_node *F2FS_NODE(struct page *page)
  393. {
  394. return (struct f2fs_node *)page_address(page);
  395. }
  396. static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
  397. {
  398. return (struct f2fs_nm_info *)(sbi->nm_info);
  399. }
  400. static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
  401. {
  402. return (struct f2fs_sm_info *)(sbi->sm_info);
  403. }
  404. static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
  405. {
  406. return (struct sit_info *)(SM_I(sbi)->sit_info);
  407. }
  408. static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
  409. {
  410. return (struct free_segmap_info *)(SM_I(sbi)->free_info);
  411. }
  412. static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
  413. {
  414. return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
  415. }
  416. static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
  417. {
  418. sbi->s_dirty = 1;
  419. }
  420. static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
  421. {
  422. sbi->s_dirty = 0;
  423. }
  424. static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
  425. {
  426. return le64_to_cpu(cp->checkpoint_ver);
  427. }
  428. static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  429. {
  430. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  431. return ckpt_flags & f;
  432. }
  433. static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  434. {
  435. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  436. ckpt_flags |= f;
  437. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  438. }
  439. static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
  440. {
  441. unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
  442. ckpt_flags &= (~f);
  443. cp->ckpt_flags = cpu_to_le32(ckpt_flags);
  444. }
  445. static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
  446. {
  447. down_read(&sbi->cp_rwsem);
  448. }
  449. static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
  450. {
  451. up_read(&sbi->cp_rwsem);
  452. }
  453. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  454. {
  455. down_write_nest_lock(&sbi->cp_rwsem, &sbi->cp_mutex);
  456. }
  457. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  458. {
  459. up_write(&sbi->cp_rwsem);
  460. }
  461. /*
  462. * Check whether the given nid is within node id range.
  463. */
  464. static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
  465. {
  466. WARN_ON((nid >= NM_I(sbi)->max_nid));
  467. if (nid >= NM_I(sbi)->max_nid)
  468. return -EINVAL;
  469. return 0;
  470. }
  471. #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
  472. /*
  473. * Check whether the inode has blocks or not
  474. */
  475. static inline int F2FS_HAS_BLOCKS(struct inode *inode)
  476. {
  477. if (F2FS_I(inode)->i_xattr_nid)
  478. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1);
  479. else
  480. return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS);
  481. }
  482. static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
  483. struct inode *inode, blkcnt_t count)
  484. {
  485. block_t valid_block_count;
  486. spin_lock(&sbi->stat_lock);
  487. valid_block_count =
  488. sbi->total_valid_block_count + (block_t)count;
  489. if (valid_block_count > sbi->user_block_count) {
  490. spin_unlock(&sbi->stat_lock);
  491. return false;
  492. }
  493. inode->i_blocks += count;
  494. sbi->total_valid_block_count = valid_block_count;
  495. sbi->alloc_valid_block_count += (block_t)count;
  496. spin_unlock(&sbi->stat_lock);
  497. return true;
  498. }
  499. static inline int dec_valid_block_count(struct f2fs_sb_info *sbi,
  500. struct inode *inode,
  501. blkcnt_t count)
  502. {
  503. spin_lock(&sbi->stat_lock);
  504. BUG_ON(sbi->total_valid_block_count < (block_t) count);
  505. BUG_ON(inode->i_blocks < count);
  506. inode->i_blocks -= count;
  507. sbi->total_valid_block_count -= (block_t)count;
  508. spin_unlock(&sbi->stat_lock);
  509. return 0;
  510. }
  511. static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
  512. {
  513. atomic_inc(&sbi->nr_pages[count_type]);
  514. F2FS_SET_SB_DIRT(sbi);
  515. }
  516. static inline void inode_inc_dirty_dents(struct inode *inode)
  517. {
  518. atomic_inc(&F2FS_I(inode)->dirty_dents);
  519. }
  520. static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
  521. {
  522. atomic_dec(&sbi->nr_pages[count_type]);
  523. }
  524. static inline void inode_dec_dirty_dents(struct inode *inode)
  525. {
  526. atomic_dec(&F2FS_I(inode)->dirty_dents);
  527. }
  528. static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
  529. {
  530. return atomic_read(&sbi->nr_pages[count_type]);
  531. }
  532. static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
  533. {
  534. unsigned int pages_per_sec = sbi->segs_per_sec *
  535. (1 << sbi->log_blocks_per_seg);
  536. return ((get_pages(sbi, block_type) + pages_per_sec - 1)
  537. >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
  538. }
  539. static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
  540. {
  541. block_t ret;
  542. spin_lock(&sbi->stat_lock);
  543. ret = sbi->total_valid_block_count;
  544. spin_unlock(&sbi->stat_lock);
  545. return ret;
  546. }
  547. static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
  548. {
  549. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  550. /* return NAT or SIT bitmap */
  551. if (flag == NAT_BITMAP)
  552. return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
  553. else if (flag == SIT_BITMAP)
  554. return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
  555. return 0;
  556. }
  557. static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
  558. {
  559. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  560. int offset = (flag == NAT_BITMAP) ?
  561. le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
  562. return &ckpt->sit_nat_version_bitmap + offset;
  563. }
  564. static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
  565. {
  566. block_t start_addr;
  567. struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
  568. unsigned long long ckpt_version = cur_cp_version(ckpt);
  569. start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
  570. /*
  571. * odd numbered checkpoint should at cp segment 0
  572. * and even segent must be at cp segment 1
  573. */
  574. if (!(ckpt_version & 1))
  575. start_addr += sbi->blocks_per_seg;
  576. return start_addr;
  577. }
  578. static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
  579. {
  580. return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
  581. }
  582. static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
  583. struct inode *inode,
  584. unsigned int count)
  585. {
  586. block_t valid_block_count;
  587. unsigned int valid_node_count;
  588. spin_lock(&sbi->stat_lock);
  589. valid_block_count = sbi->total_valid_block_count + (block_t)count;
  590. sbi->alloc_valid_block_count += (block_t)count;
  591. valid_node_count = sbi->total_valid_node_count + count;
  592. if (valid_block_count > sbi->user_block_count) {
  593. spin_unlock(&sbi->stat_lock);
  594. return false;
  595. }
  596. if (valid_node_count > sbi->total_node_count) {
  597. spin_unlock(&sbi->stat_lock);
  598. return false;
  599. }
  600. if (inode)
  601. inode->i_blocks += count;
  602. sbi->total_valid_node_count = valid_node_count;
  603. sbi->total_valid_block_count = valid_block_count;
  604. spin_unlock(&sbi->stat_lock);
  605. return true;
  606. }
  607. static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
  608. struct inode *inode,
  609. unsigned int count)
  610. {
  611. spin_lock(&sbi->stat_lock);
  612. BUG_ON(sbi->total_valid_block_count < count);
  613. BUG_ON(sbi->total_valid_node_count < count);
  614. BUG_ON(inode->i_blocks < count);
  615. inode->i_blocks -= count;
  616. sbi->total_valid_node_count -= count;
  617. sbi->total_valid_block_count -= (block_t)count;
  618. spin_unlock(&sbi->stat_lock);
  619. }
  620. static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
  621. {
  622. unsigned int ret;
  623. spin_lock(&sbi->stat_lock);
  624. ret = sbi->total_valid_node_count;
  625. spin_unlock(&sbi->stat_lock);
  626. return ret;
  627. }
  628. static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
  629. {
  630. spin_lock(&sbi->stat_lock);
  631. BUG_ON(sbi->total_valid_inode_count == sbi->total_node_count);
  632. sbi->total_valid_inode_count++;
  633. spin_unlock(&sbi->stat_lock);
  634. }
  635. static inline int dec_valid_inode_count(struct f2fs_sb_info *sbi)
  636. {
  637. spin_lock(&sbi->stat_lock);
  638. BUG_ON(!sbi->total_valid_inode_count);
  639. sbi->total_valid_inode_count--;
  640. spin_unlock(&sbi->stat_lock);
  641. return 0;
  642. }
  643. static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
  644. {
  645. unsigned int ret;
  646. spin_lock(&sbi->stat_lock);
  647. ret = sbi->total_valid_inode_count;
  648. spin_unlock(&sbi->stat_lock);
  649. return ret;
  650. }
  651. static inline void f2fs_put_page(struct page *page, int unlock)
  652. {
  653. if (!page || IS_ERR(page))
  654. return;
  655. if (unlock) {
  656. BUG_ON(!PageLocked(page));
  657. unlock_page(page);
  658. }
  659. page_cache_release(page);
  660. }
  661. static inline void f2fs_put_dnode(struct dnode_of_data *dn)
  662. {
  663. if (dn->node_page)
  664. f2fs_put_page(dn->node_page, 1);
  665. if (dn->inode_page && dn->node_page != dn->inode_page)
  666. f2fs_put_page(dn->inode_page, 0);
  667. dn->node_page = NULL;
  668. dn->inode_page = NULL;
  669. }
  670. static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
  671. size_t size, void (*ctor)(void *))
  672. {
  673. return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
  674. }
  675. static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
  676. gfp_t flags)
  677. {
  678. void *entry;
  679. retry:
  680. entry = kmem_cache_alloc(cachep, flags);
  681. if (!entry) {
  682. cond_resched();
  683. goto retry;
  684. }
  685. return entry;
  686. }
  687. #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
  688. static inline bool IS_INODE(struct page *page)
  689. {
  690. struct f2fs_node *p = F2FS_NODE(page);
  691. return RAW_IS_INODE(p);
  692. }
  693. static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
  694. {
  695. return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
  696. }
  697. static inline block_t datablock_addr(struct page *node_page,
  698. unsigned int offset)
  699. {
  700. struct f2fs_node *raw_node;
  701. __le32 *addr_array;
  702. raw_node = F2FS_NODE(node_page);
  703. addr_array = blkaddr_in_node(raw_node);
  704. return le32_to_cpu(addr_array[offset]);
  705. }
  706. static inline int f2fs_test_bit(unsigned int nr, char *addr)
  707. {
  708. int mask;
  709. addr += (nr >> 3);
  710. mask = 1 << (7 - (nr & 0x07));
  711. return mask & *addr;
  712. }
  713. static inline int f2fs_set_bit(unsigned int nr, char *addr)
  714. {
  715. int mask;
  716. int ret;
  717. addr += (nr >> 3);
  718. mask = 1 << (7 - (nr & 0x07));
  719. ret = mask & *addr;
  720. *addr |= mask;
  721. return ret;
  722. }
  723. static inline int f2fs_clear_bit(unsigned int nr, char *addr)
  724. {
  725. int mask;
  726. int ret;
  727. addr += (nr >> 3);
  728. mask = 1 << (7 - (nr & 0x07));
  729. ret = mask & *addr;
  730. *addr &= ~mask;
  731. return ret;
  732. }
  733. /* used for f2fs_inode_info->flags */
  734. enum {
  735. FI_NEW_INODE, /* indicate newly allocated inode */
  736. FI_DIRTY_INODE, /* indicate inode is dirty or not */
  737. FI_INC_LINK, /* need to increment i_nlink */
  738. FI_ACL_MODE, /* indicate acl mode */
  739. FI_NO_ALLOC, /* should not allocate any blocks */
  740. FI_UPDATE_DIR, /* should update inode block for consistency */
  741. FI_DELAY_IPUT, /* used for the recovery */
  742. FI_INLINE_XATTR, /* used for inline xattr */
  743. };
  744. static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
  745. {
  746. set_bit(flag, &fi->flags);
  747. }
  748. static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
  749. {
  750. return test_bit(flag, &fi->flags);
  751. }
  752. static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  753. {
  754. clear_bit(flag, &fi->flags);
  755. }
  756. static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
  757. {
  758. fi->i_acl_mode = mode;
  759. set_inode_flag(fi, FI_ACL_MODE);
  760. }
  761. static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
  762. {
  763. if (is_inode_flag_set(fi, FI_ACL_MODE)) {
  764. clear_inode_flag(fi, FI_ACL_MODE);
  765. return 1;
  766. }
  767. return 0;
  768. }
  769. static inline void get_inline_info(struct f2fs_inode_info *fi,
  770. struct f2fs_inode *ri)
  771. {
  772. if (ri->i_inline & F2FS_INLINE_XATTR)
  773. set_inode_flag(fi, FI_INLINE_XATTR);
  774. }
  775. static inline void set_raw_inline(struct f2fs_inode_info *fi,
  776. struct f2fs_inode *ri)
  777. {
  778. ri->i_inline = 0;
  779. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  780. ri->i_inline |= F2FS_INLINE_XATTR;
  781. }
  782. static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
  783. {
  784. if (is_inode_flag_set(fi, FI_INLINE_XATTR))
  785. return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
  786. return DEF_ADDRS_PER_INODE;
  787. }
  788. static inline void *inline_xattr_addr(struct page *page)
  789. {
  790. struct f2fs_inode *ri;
  791. ri = (struct f2fs_inode *)page_address(page);
  792. return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
  793. F2FS_INLINE_XATTR_ADDRS]);
  794. }
  795. static inline int inline_xattr_size(struct inode *inode)
  796. {
  797. if (is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR))
  798. return F2FS_INLINE_XATTR_ADDRS << 2;
  799. else
  800. return 0;
  801. }
  802. static inline int f2fs_readonly(struct super_block *sb)
  803. {
  804. return sb->s_flags & MS_RDONLY;
  805. }
  806. /*
  807. * file.c
  808. */
  809. int f2fs_sync_file(struct file *, loff_t, loff_t, int);
  810. void truncate_data_blocks(struct dnode_of_data *);
  811. void f2fs_truncate(struct inode *);
  812. int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  813. int f2fs_setattr(struct dentry *, struct iattr *);
  814. int truncate_hole(struct inode *, pgoff_t, pgoff_t);
  815. int truncate_data_blocks_range(struct dnode_of_data *, int);
  816. long f2fs_ioctl(struct file *, unsigned int, unsigned long);
  817. long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
  818. /*
  819. * inode.c
  820. */
  821. void f2fs_set_inode_flags(struct inode *);
  822. struct inode *f2fs_iget(struct super_block *, unsigned long);
  823. void update_inode(struct inode *, struct page *);
  824. int update_inode_page(struct inode *);
  825. int f2fs_write_inode(struct inode *, struct writeback_control *);
  826. void f2fs_evict_inode(struct inode *);
  827. /*
  828. * namei.c
  829. */
  830. struct dentry *f2fs_get_parent(struct dentry *child);
  831. /*
  832. * dir.c
  833. */
  834. struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
  835. struct page **);
  836. struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
  837. ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
  838. void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
  839. struct page *, struct inode *);
  840. int update_dent_inode(struct inode *, const struct qstr *);
  841. int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
  842. void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
  843. int f2fs_make_empty(struct inode *, struct inode *);
  844. bool f2fs_empty_dir(struct inode *);
  845. static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
  846. {
  847. return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
  848. inode);
  849. }
  850. /*
  851. * super.c
  852. */
  853. int f2fs_sync_fs(struct super_block *, int);
  854. extern __printf(3, 4)
  855. void f2fs_msg(struct super_block *, const char *, const char *, ...);
  856. /*
  857. * hash.c
  858. */
  859. f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
  860. /*
  861. * node.c
  862. */
  863. struct dnode_of_data;
  864. struct node_info;
  865. int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
  866. void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
  867. int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
  868. int truncate_inode_blocks(struct inode *, pgoff_t);
  869. int truncate_xattr_node(struct inode *, struct page *);
  870. int remove_inode_page(struct inode *);
  871. struct page *new_inode_page(struct inode *, const struct qstr *);
  872. struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
  873. void ra_node_page(struct f2fs_sb_info *, nid_t);
  874. struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
  875. struct page *get_node_page_ra(struct page *, int);
  876. void sync_inode_page(struct dnode_of_data *);
  877. int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
  878. bool alloc_nid(struct f2fs_sb_info *, nid_t *);
  879. void alloc_nid_done(struct f2fs_sb_info *, nid_t);
  880. void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
  881. void recover_node_page(struct f2fs_sb_info *, struct page *,
  882. struct f2fs_summary *, struct node_info *, block_t);
  883. int recover_inode_page(struct f2fs_sb_info *, struct page *);
  884. int restore_node_summary(struct f2fs_sb_info *, unsigned int,
  885. struct f2fs_summary_block *);
  886. void flush_nat_entries(struct f2fs_sb_info *);
  887. int build_node_manager(struct f2fs_sb_info *);
  888. void destroy_node_manager(struct f2fs_sb_info *);
  889. int __init create_node_manager_caches(void);
  890. void destroy_node_manager_caches(void);
  891. /*
  892. * segment.c
  893. */
  894. void f2fs_balance_fs(struct f2fs_sb_info *);
  895. void invalidate_blocks(struct f2fs_sb_info *, block_t);
  896. void clear_prefree_segments(struct f2fs_sb_info *);
  897. int npages_for_summary_flush(struct f2fs_sb_info *);
  898. void allocate_new_segments(struct f2fs_sb_info *);
  899. struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
  900. struct bio *f2fs_bio_alloc(struct block_device *, int);
  901. void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool);
  902. void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
  903. void write_meta_page(struct f2fs_sb_info *, struct page *);
  904. void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
  905. block_t, block_t *);
  906. void write_data_page(struct inode *, struct page *, struct dnode_of_data*,
  907. block_t, block_t *);
  908. void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t);
  909. void recover_data_page(struct f2fs_sb_info *, struct page *,
  910. struct f2fs_summary *, block_t, block_t);
  911. void rewrite_node_page(struct f2fs_sb_info *, struct page *,
  912. struct f2fs_summary *, block_t, block_t);
  913. void write_data_summaries(struct f2fs_sb_info *, block_t);
  914. void write_node_summaries(struct f2fs_sb_info *, block_t);
  915. int lookup_journal_in_cursum(struct f2fs_summary_block *,
  916. int, unsigned int, int);
  917. void flush_sit_entries(struct f2fs_sb_info *);
  918. int build_segment_manager(struct f2fs_sb_info *);
  919. void destroy_segment_manager(struct f2fs_sb_info *);
  920. /*
  921. * checkpoint.c
  922. */
  923. struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
  924. struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
  925. long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
  926. int acquire_orphan_inode(struct f2fs_sb_info *);
  927. void release_orphan_inode(struct f2fs_sb_info *);
  928. void add_orphan_inode(struct f2fs_sb_info *, nid_t);
  929. void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
  930. int recover_orphan_inodes(struct f2fs_sb_info *);
  931. int get_valid_checkpoint(struct f2fs_sb_info *);
  932. void set_dirty_dir_page(struct inode *, struct page *);
  933. void add_dirty_dir_inode(struct inode *);
  934. void remove_dirty_dir_inode(struct inode *);
  935. struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
  936. void sync_dirty_dir_inodes(struct f2fs_sb_info *);
  937. void write_checkpoint(struct f2fs_sb_info *, bool);
  938. void init_orphan_info(struct f2fs_sb_info *);
  939. int __init create_checkpoint_caches(void);
  940. void destroy_checkpoint_caches(void);
  941. /*
  942. * data.c
  943. */
  944. int reserve_new_block(struct dnode_of_data *);
  945. void update_extent_cache(block_t, struct dnode_of_data *);
  946. struct page *find_data_page(struct inode *, pgoff_t, bool);
  947. struct page *get_lock_data_page(struct inode *, pgoff_t);
  948. struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
  949. int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
  950. int do_write_data_page(struct page *);
  951. /*
  952. * gc.c
  953. */
  954. int start_gc_thread(struct f2fs_sb_info *);
  955. void stop_gc_thread(struct f2fs_sb_info *);
  956. block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
  957. int f2fs_gc(struct f2fs_sb_info *);
  958. void build_gc_manager(struct f2fs_sb_info *);
  959. int __init create_gc_caches(void);
  960. void destroy_gc_caches(void);
  961. /*
  962. * recovery.c
  963. */
  964. int recover_fsync_data(struct f2fs_sb_info *);
  965. bool space_for_roll_forward(struct f2fs_sb_info *);
  966. /*
  967. * debug.c
  968. */
  969. #ifdef CONFIG_F2FS_STAT_FS
  970. struct f2fs_stat_info {
  971. struct list_head stat_list;
  972. struct f2fs_sb_info *sbi;
  973. struct mutex stat_lock;
  974. int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
  975. int main_area_segs, main_area_sections, main_area_zones;
  976. int hit_ext, total_ext;
  977. int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
  978. int nats, sits, fnids;
  979. int total_count, utilization;
  980. int bg_gc;
  981. unsigned int valid_count, valid_node_count, valid_inode_count;
  982. unsigned int bimodal, avg_vblocks;
  983. int util_free, util_valid, util_invalid;
  984. int rsvd_segs, overp_segs;
  985. int dirty_count, node_pages, meta_pages;
  986. int prefree_count, call_count;
  987. int tot_segs, node_segs, data_segs, free_segs, free_secs;
  988. int tot_blks, data_blks, node_blks;
  989. int curseg[NR_CURSEG_TYPE];
  990. int cursec[NR_CURSEG_TYPE];
  991. int curzone[NR_CURSEG_TYPE];
  992. unsigned int segment_count[2];
  993. unsigned int block_count[2];
  994. unsigned base_mem, cache_mem;
  995. };
  996. static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
  997. {
  998. return (struct f2fs_stat_info*)sbi->stat_info;
  999. }
  1000. #define stat_inc_call_count(si) ((si)->call_count++)
  1001. #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
  1002. #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++)
  1003. #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--)
  1004. #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++)
  1005. #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++)
  1006. #define stat_inc_seg_type(sbi, curseg) \
  1007. ((sbi)->segment_count[(curseg)->alloc_type]++)
  1008. #define stat_inc_block_count(sbi, curseg) \
  1009. ((sbi)->block_count[(curseg)->alloc_type]++)
  1010. #define stat_inc_seg_count(sbi, type) \
  1011. do { \
  1012. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1013. (si)->tot_segs++; \
  1014. if (type == SUM_TYPE_DATA) \
  1015. si->data_segs++; \
  1016. else \
  1017. si->node_segs++; \
  1018. } while (0)
  1019. #define stat_inc_tot_blk_count(si, blks) \
  1020. (si->tot_blks += (blks))
  1021. #define stat_inc_data_blk_count(sbi, blks) \
  1022. do { \
  1023. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1024. stat_inc_tot_blk_count(si, blks); \
  1025. si->data_blks += (blks); \
  1026. } while (0)
  1027. #define stat_inc_node_blk_count(sbi, blks) \
  1028. do { \
  1029. struct f2fs_stat_info *si = F2FS_STAT(sbi); \
  1030. stat_inc_tot_blk_count(si, blks); \
  1031. si->node_blks += (blks); \
  1032. } while (0)
  1033. int f2fs_build_stats(struct f2fs_sb_info *);
  1034. void f2fs_destroy_stats(struct f2fs_sb_info *);
  1035. void __init f2fs_create_root_stats(void);
  1036. void f2fs_destroy_root_stats(void);
  1037. #else
  1038. #define stat_inc_call_count(si)
  1039. #define stat_inc_bggc_count(si)
  1040. #define stat_inc_dirty_dir(sbi)
  1041. #define stat_dec_dirty_dir(sbi)
  1042. #define stat_inc_total_hit(sb)
  1043. #define stat_inc_read_hit(sb)
  1044. #define stat_inc_seg_type(sbi, curseg)
  1045. #define stat_inc_block_count(sbi, curseg)
  1046. #define stat_inc_seg_count(si, type)
  1047. #define stat_inc_tot_blk_count(si, blks)
  1048. #define stat_inc_data_blk_count(si, blks)
  1049. #define stat_inc_node_blk_count(sbi, blks)
  1050. static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
  1051. static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
  1052. static inline void __init f2fs_create_root_stats(void) { }
  1053. static inline void f2fs_destroy_root_stats(void) { }
  1054. #endif
  1055. extern const struct file_operations f2fs_dir_operations;
  1056. extern const struct file_operations f2fs_file_operations;
  1057. extern const struct inode_operations f2fs_file_inode_operations;
  1058. extern const struct address_space_operations f2fs_dblock_aops;
  1059. extern const struct address_space_operations f2fs_node_aops;
  1060. extern const struct address_space_operations f2fs_meta_aops;
  1061. extern const struct inode_operations f2fs_dir_inode_operations;
  1062. extern const struct inode_operations f2fs_symlink_inode_operations;
  1063. extern const struct inode_operations f2fs_special_inode_operations;
  1064. #endif