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