f2fs.h 37 KB

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