logfs.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * fs/logfs/logfs.h
  3. *
  4. * As should be obvious for Linux kernel code, license is GPLv2
  5. *
  6. * Copyright (c) 2005-2008 Joern Engel <joern@logfs.org>
  7. *
  8. * Private header for logfs.
  9. */
  10. #ifndef FS_LOGFS_LOGFS_H
  11. #define FS_LOGFS_LOGFS_H
  12. #undef __CHECK_ENDIAN__
  13. #define __CHECK_ENDIAN__
  14. #include <linux/btree.h>
  15. #include <linux/crc32.h>
  16. #include <linux/fs.h>
  17. #include <linux/kernel.h>
  18. #include <linux/mempool.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/mtd/mtd.h>
  21. #include "logfs_abi.h"
  22. #define LOGFS_DEBUG_SUPER (0x0001)
  23. #define LOGFS_DEBUG_SEGMENT (0x0002)
  24. #define LOGFS_DEBUG_JOURNAL (0x0004)
  25. #define LOGFS_DEBUG_DIR (0x0008)
  26. #define LOGFS_DEBUG_FILE (0x0010)
  27. #define LOGFS_DEBUG_INODE (0x0020)
  28. #define LOGFS_DEBUG_READWRITE (0x0040)
  29. #define LOGFS_DEBUG_GC (0x0080)
  30. #define LOGFS_DEBUG_GC_NOISY (0x0100)
  31. #define LOGFS_DEBUG_ALIASES (0x0200)
  32. #define LOGFS_DEBUG_BLOCKMOVE (0x0400)
  33. #define LOGFS_DEBUG_ALL (0xffffffff)
  34. #define LOGFS_DEBUG (0x01)
  35. /*
  36. * To enable specific log messages, simply define LOGFS_DEBUG to match any
  37. * or all of the above.
  38. */
  39. #ifndef LOGFS_DEBUG
  40. #define LOGFS_DEBUG (0)
  41. #endif
  42. #define log_cond(cond, fmt, arg...) do { \
  43. if (cond) \
  44. printk(KERN_DEBUG fmt, ##arg); \
  45. } while (0)
  46. #define log_super(fmt, arg...) \
  47. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_SUPER, fmt, ##arg)
  48. #define log_segment(fmt, arg...) \
  49. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_SEGMENT, fmt, ##arg)
  50. #define log_journal(fmt, arg...) \
  51. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_JOURNAL, fmt, ##arg)
  52. #define log_dir(fmt, arg...) \
  53. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_DIR, fmt, ##arg)
  54. #define log_file(fmt, arg...) \
  55. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_FILE, fmt, ##arg)
  56. #define log_inode(fmt, arg...) \
  57. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_INODE, fmt, ##arg)
  58. #define log_readwrite(fmt, arg...) \
  59. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_READWRITE, fmt, ##arg)
  60. #define log_gc(fmt, arg...) \
  61. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_GC, fmt, ##arg)
  62. #define log_gc_noisy(fmt, arg...) \
  63. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_GC_NOISY, fmt, ##arg)
  64. #define log_aliases(fmt, arg...) \
  65. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_ALIASES, fmt, ##arg)
  66. #define log_blockmove(fmt, arg...) \
  67. log_cond(LOGFS_DEBUG & LOGFS_DEBUG_BLOCKMOVE, fmt, ##arg)
  68. #define PG_pre_locked PG_owner_priv_1
  69. #define PagePreLocked(page) test_bit(PG_pre_locked, &(page)->flags)
  70. #define SetPagePreLocked(page) set_bit(PG_pre_locked, &(page)->flags)
  71. #define ClearPagePreLocked(page) clear_bit(PG_pre_locked, &(page)->flags)
  72. /* FIXME: This should really be somewhere in the 64bit area. */
  73. #define LOGFS_LINK_MAX (1<<30)
  74. /* Read-only filesystem */
  75. #define LOGFS_SB_FLAG_RO 0x0001
  76. #define LOGFS_SB_FLAG_DIRTY 0x0002
  77. #define LOGFS_SB_FLAG_OBJ_ALIAS 0x0004
  78. #define LOGFS_SB_FLAG_SHUTDOWN 0x0008
  79. /* Write Control Flags */
  80. #define WF_LOCK 0x01 /* take write lock */
  81. #define WF_WRITE 0x02 /* write block */
  82. #define WF_DELETE 0x04 /* delete old block */
  83. typedef u8 __bitwise level_t;
  84. typedef u8 __bitwise gc_level_t;
  85. #define LEVEL(level) ((__force level_t)(level))
  86. #define GC_LEVEL(gc_level) ((__force gc_level_t)(gc_level))
  87. #define SUBLEVEL(level) ( (void)((level) == LEVEL(1)), \
  88. (__force level_t)((__force u8)(level) - 1) )
  89. /**
  90. * struct logfs_area - area management information
  91. *
  92. * @a_sb: the superblock this area belongs to
  93. * @a_is_open: 1 if the area is currently open, else 0
  94. * @a_segno: segment number of area
  95. * @a_written_bytes: number of bytes already written back
  96. * @a_used_bytes: number of used bytes
  97. * @a_ops: area operations (either journal or ostore)
  98. * @a_erase_count: erase count
  99. * @a_level: GC level
  100. */
  101. struct logfs_area { /* a segment open for writing */
  102. struct super_block *a_sb;
  103. int a_is_open;
  104. u32 a_segno;
  105. u32 a_written_bytes;
  106. u32 a_used_bytes;
  107. const struct logfs_area_ops *a_ops;
  108. u32 a_erase_count;
  109. gc_level_t a_level;
  110. };
  111. /**
  112. * struct logfs_area_ops - area operations
  113. *
  114. * @get_free_segment: fill area->ofs with the offset of a free segment
  115. * @get_erase_count: fill area->erase_count (needs area->ofs)
  116. * @erase_segment: erase and setup segment
  117. */
  118. struct logfs_area_ops {
  119. void (*get_free_segment)(struct logfs_area *area);
  120. void (*get_erase_count)(struct logfs_area *area);
  121. int (*erase_segment)(struct logfs_area *area);
  122. };
  123. struct logfs_super; /* forward */
  124. /**
  125. * struct logfs_device_ops - device access operations
  126. *
  127. * @readpage: read one page (mm page)
  128. * @writeseg: write one segment. may be a partial segment
  129. * @erase: erase one segment
  130. * @read: read from the device
  131. * @erase: erase part of the device
  132. * @can_write_buf: decide whether wbuf can be written to ofs
  133. */
  134. struct logfs_device_ops {
  135. struct page *(*find_first_sb)(struct super_block *sb, u64 *ofs);
  136. struct page *(*find_last_sb)(struct super_block *sb, u64 *ofs);
  137. int (*write_sb)(struct super_block *sb, struct page *page);
  138. int (*readpage)(void *_sb, struct page *page);
  139. void (*writeseg)(struct super_block *sb, u64 ofs, size_t len);
  140. int (*erase)(struct super_block *sb, loff_t ofs, size_t len,
  141. int ensure_write);
  142. int (*can_write_buf)(struct super_block *sb, u64 ofs);
  143. void (*sync)(struct super_block *sb);
  144. void (*put_device)(struct logfs_super *s);
  145. };
  146. /**
  147. * struct candidate_list - list of similar candidates
  148. */
  149. struct candidate_list {
  150. struct rb_root rb_tree;
  151. int count;
  152. int maxcount;
  153. int sort_by_ec;
  154. };
  155. /**
  156. * struct gc_candidate - "candidate" segment to be garbage collected next
  157. *
  158. * @list: list (either free of low)
  159. * @segno: segment number
  160. * @valid: number of valid bytes
  161. * @erase_count: erase count of segment
  162. * @dist: distance from tree root
  163. *
  164. * Candidates can be on two lists. The free list contains electees rather
  165. * than candidates - segments that no longer contain any valid data. The
  166. * low list contains candidates to be picked for GC. It should be kept
  167. * short. It is not required to always pick a perfect candidate. In the
  168. * worst case GC will have to move more data than absolutely necessary.
  169. */
  170. struct gc_candidate {
  171. struct rb_node rb_node;
  172. struct candidate_list *list;
  173. u32 segno;
  174. u32 valid;
  175. u32 erase_count;
  176. u8 dist;
  177. };
  178. /**
  179. * struct logfs_journal_entry - temporary structure used during journal scan
  180. *
  181. * @used:
  182. * @version: normalized version
  183. * @len: length
  184. * @offset: offset
  185. */
  186. struct logfs_journal_entry {
  187. int used;
  188. s16 version;
  189. u16 len;
  190. u16 datalen;
  191. u64 offset;
  192. };
  193. enum transaction_state {
  194. CREATE_1 = 1,
  195. CREATE_2,
  196. UNLINK_1,
  197. UNLINK_2,
  198. CROSS_RENAME_1,
  199. CROSS_RENAME_2,
  200. TARGET_RENAME_1,
  201. TARGET_RENAME_2,
  202. TARGET_RENAME_3
  203. };
  204. /**
  205. * struct logfs_transaction - essential fields to support atomic dirops
  206. *
  207. * @ino: target inode
  208. * @dir: inode of directory containing dentry
  209. * @pos: pos of dentry in directory
  210. */
  211. struct logfs_transaction {
  212. enum transaction_state state;
  213. u64 ino;
  214. u64 dir;
  215. u64 pos;
  216. };
  217. /**
  218. * struct logfs_shadow - old block in the shadow of a not-yet-committed new one
  219. * @old_ofs: offset of old block on medium
  220. * @new_ofs: offset of new block on medium
  221. * @ino: inode number
  222. * @bix: block index
  223. * @old_len: size of old block, including header
  224. * @new_len: size of new block, including header
  225. * @level: block level
  226. */
  227. struct logfs_shadow {
  228. u64 old_ofs;
  229. u64 new_ofs;
  230. u64 ino;
  231. u64 bix;
  232. int old_len;
  233. int new_len;
  234. gc_level_t gc_level;
  235. };
  236. /**
  237. * struct shadow_tree
  238. * @new: shadows where old_ofs==0, indexed by new_ofs
  239. * @old: shadows where old_ofs!=0, indexed by old_ofs
  240. * @segment_map: bitfield of segments containing shadows
  241. * @no_shadowed_segment: number of segments containing shadows
  242. */
  243. struct shadow_tree {
  244. struct btree_head64 new;
  245. struct btree_head64 old;
  246. struct btree_head32 segment_map;
  247. int no_shadowed_segments;
  248. };
  249. struct object_alias_item {
  250. struct list_head list;
  251. __be64 val;
  252. int child_no;
  253. };
  254. /**
  255. * struct logfs_block - contains any block state
  256. * @type: indirect block or inode
  257. * @full: number of fully populated children
  258. * @partial: number of partially populated children
  259. *
  260. * Most blocks are directly represented by page cache pages. But when a block
  261. * becomes dirty, is part of a transaction, contains aliases or is otherwise
  262. * special, a struct logfs_block is allocated to track the additional state.
  263. * Inodes are very similar to indirect blocks, so they can also get one of
  264. * these structures added when appropriate.
  265. */
  266. #define BLOCK_INDIRECT 1 /* Indirect block */
  267. #define BLOCK_INODE 2 /* Inode */
  268. struct logfs_block_ops;
  269. struct logfs_block {
  270. struct list_head alias_list;
  271. struct list_head item_list;
  272. struct super_block *sb;
  273. u64 ino;
  274. u64 bix;
  275. level_t level;
  276. struct page *page;
  277. struct inode *inode;
  278. struct logfs_transaction *ta;
  279. unsigned long alias_map[LOGFS_BLOCK_FACTOR / BITS_PER_LONG];
  280. const struct logfs_block_ops *ops;
  281. int full;
  282. int partial;
  283. int reserved_bytes;
  284. };
  285. typedef int write_alias_t(struct super_block *sb, u64 ino, u64 bix,
  286. level_t level, int child_no, __be64 val);
  287. struct logfs_block_ops {
  288. void (*write_block)(struct logfs_block *block);
  289. void (*free_block)(struct super_block *sb, struct logfs_block*block);
  290. int (*write_alias)(struct super_block *sb,
  291. struct logfs_block *block,
  292. write_alias_t *write_one_alias);
  293. };
  294. #define MAX_JOURNAL_ENTRIES 256
  295. struct logfs_super {
  296. struct mtd_info *s_mtd; /* underlying device */
  297. struct block_device *s_bdev; /* underlying device */
  298. const struct logfs_device_ops *s_devops;/* device access */
  299. struct inode *s_master_inode; /* inode file */
  300. struct inode *s_segfile_inode; /* segment file */
  301. struct inode *s_mapping_inode; /* device mapping */
  302. atomic_t s_pending_writes; /* outstanting bios */
  303. long s_flags;
  304. mempool_t *s_btree_pool; /* for btree nodes */
  305. mempool_t *s_alias_pool; /* aliases in segment.c */
  306. u64 s_feature_incompat;
  307. u64 s_feature_ro_compat;
  308. u64 s_feature_compat;
  309. u64 s_feature_flags;
  310. u64 s_sb_ofs[2];
  311. struct page *s_erase_page; /* for dev_bdev.c */
  312. /* alias.c fields */
  313. struct btree_head32 s_segment_alias; /* remapped segments */
  314. int s_no_object_aliases;
  315. struct list_head s_object_alias; /* remapped objects */
  316. struct btree_head128 s_object_alias_tree; /* remapped objects */
  317. struct mutex s_object_alias_mutex;
  318. /* dir.c fields */
  319. struct mutex s_dirop_mutex; /* for creat/unlink/rename */
  320. u64 s_victim_ino; /* used for atomic dir-ops */
  321. u64 s_rename_dir; /* source directory ino */
  322. u64 s_rename_pos; /* position of source dd */
  323. /* gc.c fields */
  324. long s_segsize; /* size of a segment */
  325. int s_segshift; /* log2 of segment size */
  326. long s_segmask; /* 1 << s_segshift - 1 */
  327. long s_no_segs; /* segments on device */
  328. long s_no_journal_segs; /* segments used for journal */
  329. long s_no_blocks; /* blocks per segment */
  330. long s_writesize; /* minimum write size */
  331. int s_writeshift; /* log2 of write size */
  332. u64 s_size; /* filesystem size */
  333. struct logfs_area *s_area[LOGFS_NO_AREAS]; /* open segment array */
  334. u64 s_gec; /* global erase count */
  335. u64 s_wl_gec_ostore; /* time of last wl event */
  336. u64 s_wl_gec_journal; /* time of last wl event */
  337. u64 s_sweeper; /* current sweeper pos */
  338. u8 s_ifile_levels; /* max level of ifile */
  339. u8 s_iblock_levels; /* max level of regular files */
  340. u8 s_data_levels; /* # of segments to leaf block*/
  341. u8 s_total_levels; /* sum of above three */
  342. struct btree_head32 s_cand_tree; /* all candidates */
  343. struct candidate_list s_free_list; /* 100% free segments */
  344. struct candidate_list s_reserve_list; /* Bad segment reserve */
  345. struct candidate_list s_low_list[LOGFS_NO_AREAS];/* good candidates */
  346. struct candidate_list s_ec_list; /* wear level candidates */
  347. struct btree_head32 s_reserved_segments;/* sb, journal, bad, etc. */
  348. /* inode.c fields */
  349. u64 s_last_ino; /* highest ino used */
  350. long s_inos_till_wrap;
  351. u32 s_generation; /* i_generation for new files */
  352. struct list_head s_freeing_list; /* inodes being freed */
  353. /* journal.c fields */
  354. struct mutex s_journal_mutex;
  355. void *s_je; /* journal entry to compress */
  356. void *s_compressed_je; /* block to write to journal */
  357. u32 s_journal_seg[LOGFS_JOURNAL_SEGS]; /* journal segments */
  358. u32 s_journal_ec[LOGFS_JOURNAL_SEGS]; /* journal erasecounts */
  359. u64 s_last_version;
  360. struct logfs_area *s_journal_area; /* open journal segment */
  361. __be64 s_je_array[MAX_JOURNAL_ENTRIES];
  362. int s_no_je;
  363. int s_sum_index; /* for the 12 summaries */
  364. struct shadow_tree s_shadow_tree;
  365. int s_je_fill; /* index of current je */
  366. /* readwrite.c fields */
  367. struct mutex s_write_mutex;
  368. int s_lock_count;
  369. mempool_t *s_block_pool; /* struct logfs_block pool */
  370. mempool_t *s_shadow_pool; /* struct logfs_shadow pool */
  371. struct list_head s_writeback_list; /* writeback pages */
  372. /*
  373. * Space accounting:
  374. * - s_used_bytes specifies space used to store valid data objects.
  375. * - s_dirty_used_bytes is space used to store non-committed data
  376. * objects. Those objects have already been written themselves,
  377. * but they don't become valid until all indirect blocks up to the
  378. * journal have been written as well.
  379. * - s_dirty_free_bytes is space used to store the old copy of a
  380. * replaced object, as long as the replacement is non-committed.
  381. * In other words, it is the amount of space freed when all dirty
  382. * blocks are written back.
  383. * - s_free_bytes is the amount of free space available for any
  384. * purpose.
  385. * - s_root_reserve is the amount of free space available only to
  386. * the root user. Non-privileged users can no longer write once
  387. * this watermark has been reached.
  388. * - s_speed_reserve is space which remains unused to speed up
  389. * garbage collection performance.
  390. * - s_dirty_pages is the space reserved for currently dirty pages.
  391. * It is a pessimistic estimate, so some/most will get freed on
  392. * page writeback.
  393. *
  394. * s_used_bytes + s_free_bytes + s_speed_reserve = total usable size
  395. */
  396. u64 s_free_bytes;
  397. u64 s_used_bytes;
  398. u64 s_dirty_free_bytes;
  399. u64 s_dirty_used_bytes;
  400. u64 s_root_reserve;
  401. u64 s_speed_reserve;
  402. u64 s_dirty_pages;
  403. /* Bad block handling:
  404. * - s_bad_seg_reserve is a number of segments usually kept
  405. * free. When encountering bad blocks, the affected segment's data
  406. * is _temporarily_ moved to a reserved segment.
  407. * - s_bad_segments is the number of known bad segments.
  408. */
  409. u32 s_bad_seg_reserve;
  410. u32 s_bad_segments;
  411. };
  412. /**
  413. * struct logfs_inode - in-memory inode
  414. *
  415. * @vfs_inode: struct inode
  416. * @li_data: data pointers
  417. * @li_used_bytes: number of used bytes
  418. * @li_freeing_list: used to track inodes currently being freed
  419. * @li_flags: inode flags
  420. * @li_refcount: number of internal (GC-induced) references
  421. */
  422. struct logfs_inode {
  423. struct inode vfs_inode;
  424. u64 li_data[LOGFS_EMBEDDED_FIELDS];
  425. u64 li_used_bytes;
  426. struct list_head li_freeing_list;
  427. struct logfs_block *li_block;
  428. u32 li_flags;
  429. u8 li_height;
  430. int li_refcount;
  431. };
  432. #define journal_for_each(__i) for (__i = 0; __i < LOGFS_JOURNAL_SEGS; __i++)
  433. #define for_each_area(__i) for (__i = 0; __i < LOGFS_NO_AREAS; __i++)
  434. #define for_each_area_down(__i) for (__i = LOGFS_NO_AREAS - 1; __i >= 0; __i--)
  435. /* compr.c */
  436. int logfs_compress(void *in, void *out, size_t inlen, size_t outlen);
  437. int logfs_uncompress(void *in, void *out, size_t inlen, size_t outlen);
  438. int __init logfs_compr_init(void);
  439. void logfs_compr_exit(void);
  440. /* dev_bdev.c */
  441. #ifdef CONFIG_BLOCK
  442. int logfs_get_sb_bdev(struct logfs_super *s,
  443. struct file_system_type *type,
  444. const char *devname);
  445. #else
  446. static inline int logfs_get_sb_bdev(struct logfs_super *s,
  447. struct file_system_type *type,
  448. const char *devname)
  449. {
  450. return -ENODEV;
  451. }
  452. #endif
  453. /* dev_mtd.c */
  454. #if IS_ENABLED(CONFIG_MTD)
  455. int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr);
  456. #else
  457. static inline int logfs_get_sb_mtd(struct logfs_super *s, int mtdnr)
  458. {
  459. return -ENODEV;
  460. }
  461. #endif
  462. /* dir.c */
  463. extern const struct inode_operations logfs_dir_iops;
  464. extern const struct file_operations logfs_dir_fops;
  465. int logfs_replay_journal(struct super_block *sb);
  466. /* file.c */
  467. extern const struct inode_operations logfs_reg_iops;
  468. extern const struct file_operations logfs_reg_fops;
  469. extern const struct address_space_operations logfs_reg_aops;
  470. int logfs_readpage(struct file *file, struct page *page);
  471. long logfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  472. int logfs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
  473. /* gc.c */
  474. u32 get_best_cand(struct super_block *sb, struct candidate_list *list, u32 *ec);
  475. void logfs_gc_pass(struct super_block *sb);
  476. int logfs_check_areas(struct super_block *sb);
  477. int logfs_init_gc(struct super_block *sb);
  478. void logfs_cleanup_gc(struct super_block *sb);
  479. /* inode.c */
  480. extern const struct super_operations logfs_super_operations;
  481. struct inode *logfs_iget(struct super_block *sb, ino_t ino);
  482. struct inode *logfs_safe_iget(struct super_block *sb, ino_t ino, int *cookie);
  483. void logfs_safe_iput(struct inode *inode, int cookie);
  484. struct inode *logfs_new_inode(struct inode *dir, umode_t mode);
  485. struct inode *logfs_new_meta_inode(struct super_block *sb, u64 ino);
  486. struct inode *logfs_read_meta_inode(struct super_block *sb, u64 ino);
  487. int logfs_init_inode_cache(void);
  488. void logfs_destroy_inode_cache(void);
  489. void logfs_set_blocks(struct inode *inode, u64 no);
  490. /* these logically belong into inode.c but actually reside in readwrite.c */
  491. int logfs_read_inode(struct inode *inode);
  492. int __logfs_write_inode(struct inode *inode, struct page *, long flags);
  493. void logfs_evict_inode(struct inode *inode);
  494. /* journal.c */
  495. void logfs_write_anchor(struct super_block *sb);
  496. int logfs_init_journal(struct super_block *sb);
  497. void logfs_cleanup_journal(struct super_block *sb);
  498. int write_alias_journal(struct super_block *sb, u64 ino, u64 bix,
  499. level_t level, int child_no, __be64 val);
  500. void do_logfs_journal_wl_pass(struct super_block *sb);
  501. /* readwrite.c */
  502. pgoff_t logfs_pack_index(u64 bix, level_t level);
  503. void logfs_unpack_index(pgoff_t index, u64 *bix, level_t *level);
  504. int logfs_inode_write(struct inode *inode, const void *buf, size_t count,
  505. loff_t bix, long flags, struct shadow_tree *shadow_tree);
  506. int logfs_readpage_nolock(struct page *page);
  507. int logfs_write_buf(struct inode *inode, struct page *page, long flags);
  508. int logfs_delete(struct inode *inode, pgoff_t index,
  509. struct shadow_tree *shadow_tree);
  510. int logfs_rewrite_block(struct inode *inode, u64 bix, u64 ofs,
  511. gc_level_t gc_level, long flags);
  512. int logfs_is_valid_block(struct super_block *sb, u64 ofs, u64 ino, u64 bix,
  513. gc_level_t gc_level);
  514. int logfs_truncate(struct inode *inode, u64 size);
  515. u64 logfs_seek_hole(struct inode *inode, u64 bix);
  516. u64 logfs_seek_data(struct inode *inode, u64 bix);
  517. int logfs_open_segfile(struct super_block *sb);
  518. int logfs_init_rw(struct super_block *sb);
  519. void logfs_cleanup_rw(struct super_block *sb);
  520. void logfs_add_transaction(struct inode *inode, struct logfs_transaction *ta);
  521. void logfs_del_transaction(struct inode *inode, struct logfs_transaction *ta);
  522. void logfs_write_block(struct logfs_block *block, long flags);
  523. int logfs_write_obj_aliases_pagecache(struct super_block *sb);
  524. void logfs_get_segment_entry(struct super_block *sb, u32 segno,
  525. struct logfs_segment_entry *se);
  526. void logfs_set_segment_used(struct super_block *sb, u64 ofs, int increment);
  527. void logfs_set_segment_erased(struct super_block *sb, u32 segno, u32 ec,
  528. gc_level_t gc_level);
  529. void logfs_set_segment_reserved(struct super_block *sb, u32 segno);
  530. void logfs_set_segment_unreserved(struct super_block *sb, u32 segno, u32 ec);
  531. struct logfs_block *__alloc_block(struct super_block *sb,
  532. u64 ino, u64 bix, level_t level);
  533. void __free_block(struct super_block *sb, struct logfs_block *block);
  534. void btree_write_block(struct logfs_block *block);
  535. void initialize_block_counters(struct page *page, struct logfs_block *block,
  536. __be64 *array, int page_is_empty);
  537. int logfs_exist_block(struct inode *inode, u64 bix);
  538. int get_page_reserve(struct inode *inode, struct page *page);
  539. void logfs_get_wblocks(struct super_block *sb, struct page *page, int lock);
  540. void logfs_put_wblocks(struct super_block *sb, struct page *page, int lock);
  541. extern const struct logfs_block_ops indirect_block_ops;
  542. /* segment.c */
  543. int logfs_erase_segment(struct super_block *sb, u32 ofs, int ensure_erase);
  544. int wbuf_read(struct super_block *sb, u64 ofs, size_t len, void *buf);
  545. int logfs_segment_read(struct inode *inode, struct page *page, u64 ofs, u64 bix,
  546. level_t level);
  547. int logfs_segment_write(struct inode *inode, struct page *page,
  548. struct logfs_shadow *shadow);
  549. int logfs_segment_delete(struct inode *inode, struct logfs_shadow *shadow);
  550. int logfs_load_object_aliases(struct super_block *sb,
  551. struct logfs_obj_alias *oa, int count);
  552. void move_page_to_btree(struct page *page);
  553. int logfs_init_mapping(struct super_block *sb);
  554. void logfs_sync_area(struct logfs_area *area);
  555. void logfs_sync_segments(struct super_block *sb);
  556. void freeseg(struct super_block *sb, u32 segno);
  557. void free_areas(struct super_block *sb);
  558. /* area handling */
  559. int logfs_init_areas(struct super_block *sb);
  560. void logfs_cleanup_areas(struct super_block *sb);
  561. int logfs_open_area(struct logfs_area *area, size_t bytes);
  562. int __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
  563. int use_filler);
  564. static inline int logfs_buf_write(struct logfs_area *area, u64 ofs,
  565. void *buf, size_t len)
  566. {
  567. return __logfs_buf_write(area, ofs, buf, len, 0);
  568. }
  569. static inline int logfs_buf_recover(struct logfs_area *area, u64 ofs,
  570. void *buf, size_t len)
  571. {
  572. return __logfs_buf_write(area, ofs, buf, len, 1);
  573. }
  574. /* super.c */
  575. struct page *emergency_read_begin(struct address_space *mapping, pgoff_t index);
  576. void emergency_read_end(struct page *page);
  577. void logfs_crash_dump(struct super_block *sb);
  578. int logfs_statfs(struct dentry *dentry, struct kstatfs *stats);
  579. int logfs_check_ds(struct logfs_disk_super *ds);
  580. int logfs_write_sb(struct super_block *sb);
  581. static inline struct logfs_super *logfs_super(struct super_block *sb)
  582. {
  583. return sb->s_fs_info;
  584. }
  585. static inline struct logfs_inode *logfs_inode(struct inode *inode)
  586. {
  587. return container_of(inode, struct logfs_inode, vfs_inode);
  588. }
  589. static inline void logfs_set_ro(struct super_block *sb)
  590. {
  591. logfs_super(sb)->s_flags |= LOGFS_SB_FLAG_RO;
  592. }
  593. #define LOGFS_BUG(sb) do { \
  594. struct super_block *__sb = sb; \
  595. logfs_crash_dump(__sb); \
  596. logfs_super(__sb)->s_flags |= LOGFS_SB_FLAG_RO; \
  597. BUG(); \
  598. } while (0)
  599. #define LOGFS_BUG_ON(condition, sb) \
  600. do { if (unlikely(condition)) LOGFS_BUG((sb)); } while (0)
  601. static inline __be32 logfs_crc32(void *data, size_t len, size_t skip)
  602. {
  603. return cpu_to_be32(crc32(~0, data+skip, len-skip));
  604. }
  605. static inline u8 logfs_type(struct inode *inode)
  606. {
  607. return (inode->i_mode >> 12) & 15;
  608. }
  609. static inline pgoff_t logfs_index(struct super_block *sb, u64 pos)
  610. {
  611. return pos >> sb->s_blocksize_bits;
  612. }
  613. static inline u64 dev_ofs(struct super_block *sb, u32 segno, u32 ofs)
  614. {
  615. return ((u64)segno << logfs_super(sb)->s_segshift) + ofs;
  616. }
  617. static inline u32 seg_no(struct super_block *sb, u64 ofs)
  618. {
  619. return ofs >> logfs_super(sb)->s_segshift;
  620. }
  621. static inline u32 seg_ofs(struct super_block *sb, u64 ofs)
  622. {
  623. return ofs & logfs_super(sb)->s_segmask;
  624. }
  625. static inline u64 seg_align(struct super_block *sb, u64 ofs)
  626. {
  627. return ofs & ~logfs_super(sb)->s_segmask;
  628. }
  629. static inline struct logfs_block *logfs_block(struct page *page)
  630. {
  631. return (void *)page->private;
  632. }
  633. static inline level_t shrink_level(gc_level_t __level)
  634. {
  635. u8 level = (__force u8)__level;
  636. if (level >= LOGFS_MAX_LEVELS)
  637. level -= LOGFS_MAX_LEVELS;
  638. return (__force level_t)level;
  639. }
  640. static inline gc_level_t expand_level(u64 ino, level_t __level)
  641. {
  642. u8 level = (__force u8)__level;
  643. if (ino == LOGFS_INO_MASTER) {
  644. /* ifile has separate areas */
  645. level += LOGFS_MAX_LEVELS;
  646. }
  647. return (__force gc_level_t)level;
  648. }
  649. static inline int logfs_block_shift(struct super_block *sb, level_t level)
  650. {
  651. level = shrink_level((__force gc_level_t)level);
  652. return (__force int)level * (sb->s_blocksize_bits - 3);
  653. }
  654. static inline u64 logfs_block_mask(struct super_block *sb, level_t level)
  655. {
  656. return ~0ull << logfs_block_shift(sb, level);
  657. }
  658. static inline struct logfs_area *get_area(struct super_block *sb,
  659. gc_level_t gc_level)
  660. {
  661. return logfs_super(sb)->s_area[(__force u8)gc_level];
  662. }
  663. static inline void logfs_mempool_destroy(mempool_t *pool)
  664. {
  665. if (pool)
  666. mempool_destroy(pool);
  667. }
  668. #endif