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.
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>
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.
44 #define LOGFS_DEBUG (0)
47 #define log_cond(cond, fmt, arg...) do { \
49 printk(KERN_DEBUG fmt, ##arg); \
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 /* FIXME: This should really be somewhere in the 64bit area. */
81 #define LOGFS_LINK_MAX (1<<30)
83 /* Read-only filesystem */
84 #define LOGFS_SB_FLAG_RO 0x0001
85 #define LOGFS_SB_FLAG_DIRTY 0x0002
86 #define LOGFS_SB_FLAG_OBJ_ALIAS 0x0004
87 #define LOGFS_SB_FLAG_SHUTDOWN 0x0008
89 /* Write Control Flags */
90 #define WF_LOCK 0x01 /* take write lock */
91 #define WF_WRITE 0x02 /* write block */
92 #define WF_DELETE 0x04 /* delete old block */
94 typedef u8 __bitwise level_t
;
95 typedef u8 __bitwise gc_level_t
;
97 #define LEVEL(level) ((__force level_t)(level))
98 #define GC_LEVEL(gc_level) ((__force gc_level_t)(gc_level))
100 #define SUBLEVEL(level) ( (void)((level) == LEVEL(1)), \
101 (__force level_t)((__force u8)(level) - 1) )
104 * struct logfs_area - area management information
106 * @a_sb: the superblock this area belongs to
107 * @a_is_open: 1 if the area is currently open, else 0
108 * @a_segno: segment number of area
109 * @a_written_bytes: number of bytes already written back
110 * @a_used_bytes: number of used bytes
111 * @a_ops: area operations (either journal or ostore)
112 * @a_erase_count: erase count
115 struct logfs_area
{ /* a segment open for writing */
116 struct super_block
*a_sb
;
121 const struct logfs_area_ops
*a_ops
;
127 * struct logfs_area_ops - area operations
129 * @get_free_segment: fill area->ofs with the offset of a free segment
130 * @get_erase_count: fill area->erase_count (needs area->ofs)
131 * @erase_segment: erase and setup segment
133 struct logfs_area_ops
{
134 void (*get_free_segment
)(struct logfs_area
*area
);
135 void (*get_erase_count
)(struct logfs_area
*area
);
136 int (*erase_segment
)(struct logfs_area
*area
);
139 struct logfs_super
; /* forward */
141 * struct logfs_device_ops - device access operations
143 * @readpage: read one page (mm page)
144 * @writeseg: write one segment. may be a partial segment
145 * @erase: erase one segment
146 * @read: read from the device
147 * @erase: erase part of the device
148 * @can_write_buf: decide whether wbuf can be written to ofs
150 struct logfs_device_ops
{
151 struct page
*(*find_first_sb
)(struct super_block
*sb
, u64
*ofs
);
152 struct page
*(*find_last_sb
)(struct super_block
*sb
, u64
*ofs
);
153 int (*write_sb
)(struct super_block
*sb
, struct page
*page
);
154 int (*readpage
)(void *_sb
, struct page
*page
);
155 void (*writeseg
)(struct super_block
*sb
, u64 ofs
, size_t len
);
156 int (*erase
)(struct super_block
*sb
, loff_t ofs
, size_t len
,
158 int (*can_write_buf
)(struct super_block
*sb
, u64 ofs
);
159 void (*sync
)(struct super_block
*sb
);
160 void (*put_device
)(struct logfs_super
*s
);
164 * struct candidate_list - list of similar candidates
166 struct candidate_list
{
167 struct rb_root rb_tree
;
174 * struct gc_candidate - "candidate" segment to be garbage collected next
176 * @list: list (either free of low)
177 * @segno: segment number
178 * @valid: number of valid bytes
179 * @erase_count: erase count of segment
180 * @dist: distance from tree root
182 * Candidates can be on two lists. The free list contains electees rather
183 * than candidates - segments that no longer contain any valid data. The
184 * low list contains candidates to be picked for GC. It should be kept
185 * short. It is not required to always pick a perfect candidate. In the
186 * worst case GC will have to move more data than absolutely necessary.
188 struct gc_candidate
{
189 struct rb_node rb_node
;
190 struct candidate_list
*list
;
198 * struct logfs_journal_entry - temporary structure used during journal scan
201 * @version: normalized version
205 struct logfs_journal_entry
{
213 enum transaction_state
{
226 * struct logfs_transaction - essential fields to support atomic dirops
229 * @dir: inode of directory containing dentry
230 * @pos: pos of dentry in directory
232 struct logfs_transaction
{
233 enum transaction_state state
;
240 * struct logfs_shadow - old block in the shadow of a not-yet-committed new one
241 * @old_ofs: offset of old block on medium
242 * @new_ofs: offset of new block on medium
245 * @old_len: size of old block, including header
246 * @new_len: size of new block, including header
247 * @level: block level
249 struct logfs_shadow
{
261 * @new: shadows where old_ofs==0, indexed by new_ofs
262 * @old: shadows where old_ofs!=0, indexed by old_ofs
263 * @segment_map: bitfield of segments containing shadows
264 * @no_shadowed_segment: number of segments containing shadows
267 struct btree_head64
new;
268 struct btree_head64 old
;
269 struct btree_head32 segment_map
;
270 int no_shadowed_segments
;
273 struct object_alias_item
{
274 struct list_head list
;
280 * struct logfs_block - contains any block state
281 * @type: indirect block or inode
282 * @full: number of fully populated children
283 * @partial: number of partially populated children
285 * Most blocks are directly represented by page cache pages. But when a block
286 * becomes dirty, is part of a transaction, contains aliases or is otherwise
287 * special, a struct logfs_block is allocated to track the additional state.
288 * Inodes are very similar to indirect blocks, so they can also get one of
289 * these structures added when appropriate.
291 #define BLOCK_INDIRECT 1 /* Indirect block */
292 #define BLOCK_INODE 2 /* Inode */
293 struct logfs_block_ops
;
295 struct list_head alias_list
;
296 struct list_head item_list
;
297 struct super_block
*sb
;
303 struct logfs_transaction
*ta
;
304 unsigned long alias_map
[LOGFS_BLOCK_FACTOR
/ BITS_PER_LONG
];
305 struct logfs_block_ops
*ops
;
311 typedef int write_alias_t(struct super_block
*sb
, u64 ino
, u64 bix
,
312 level_t level
, int child_no
, __be64 val
);
313 struct logfs_block_ops
{
314 void (*write_block
)(struct logfs_block
*block
);
315 void (*free_block
)(struct super_block
*sb
, struct logfs_block
*block
);
316 int (*write_alias
)(struct super_block
*sb
,
317 struct logfs_block
*block
,
318 write_alias_t
*write_one_alias
);
321 #define MAX_JOURNAL_ENTRIES 256
324 struct mtd_info
*s_mtd
; /* underlying device */
325 struct block_device
*s_bdev
; /* underlying device */
326 const struct logfs_device_ops
*s_devops
;/* device access */
327 struct inode
*s_master_inode
; /* inode file */
328 struct inode
*s_segfile_inode
; /* segment file */
329 struct inode
*s_mapping_inode
; /* device mapping */
330 atomic_t s_pending_writes
; /* outstanting bios */
332 mempool_t
*s_btree_pool
; /* for btree nodes */
333 mempool_t
*s_alias_pool
; /* aliases in segment.c */
334 u64 s_feature_incompat
;
335 u64 s_feature_ro_compat
;
336 u64 s_feature_compat
;
339 struct page
*s_erase_page
; /* for dev_bdev.c */
341 struct btree_head32 s_segment_alias
; /* remapped segments */
342 int s_no_object_aliases
;
343 struct list_head s_object_alias
; /* remapped objects */
344 struct btree_head128 s_object_alias_tree
; /* remapped objects */
345 struct mutex s_object_alias_mutex
;
347 struct mutex s_dirop_mutex
; /* for creat/unlink/rename */
348 u64 s_victim_ino
; /* used for atomic dir-ops */
349 u64 s_rename_dir
; /* source directory ino */
350 u64 s_rename_pos
; /* position of source dd */
352 long s_segsize
; /* size of a segment */
353 int s_segshift
; /* log2 of segment size */
354 long s_segmask
; /* 1 << s_segshift - 1 */
355 long s_no_segs
; /* segments on device */
356 long s_no_journal_segs
; /* segments used for journal */
357 long s_no_blocks
; /* blocks per segment */
358 long s_writesize
; /* minimum write size */
359 int s_writeshift
; /* log2 of write size */
360 u64 s_size
; /* filesystem size */
361 struct logfs_area
*s_area
[LOGFS_NO_AREAS
]; /* open segment array */
362 u64 s_gec
; /* global erase count */
363 u64 s_wl_gec_ostore
; /* time of last wl event */
364 u64 s_wl_gec_journal
; /* time of last wl event */
365 u64 s_sweeper
; /* current sweeper pos */
366 u8 s_ifile_levels
; /* max level of ifile */
367 u8 s_iblock_levels
; /* max level of regular files */
368 u8 s_data_levels
; /* # of segments to leaf block*/
369 u8 s_total_levels
; /* sum of above three */
370 struct btree_head32 s_cand_tree
; /* all candidates */
371 struct candidate_list s_free_list
; /* 100% free segments */
372 struct candidate_list s_reserve_list
; /* Bad segment reserve */
373 struct candidate_list s_low_list
[LOGFS_NO_AREAS
];/* good candidates */
374 struct candidate_list s_ec_list
; /* wear level candidates */
375 struct btree_head32 s_reserved_segments
;/* sb, journal, bad, etc. */
377 u64 s_last_ino
; /* highest ino used */
378 long s_inos_till_wrap
;
379 u32 s_generation
; /* i_generation for new files */
380 struct list_head s_freeing_list
; /* inodes being freed */
381 /* journal.c fields */
382 struct mutex s_journal_mutex
;
383 void *s_je
; /* journal entry to compress */
384 void *s_compressed_je
; /* block to write to journal */
385 u32 s_journal_seg
[LOGFS_JOURNAL_SEGS
]; /* journal segments */
386 u32 s_journal_ec
[LOGFS_JOURNAL_SEGS
]; /* journal erasecounts */
388 struct logfs_area
*s_journal_area
; /* open journal segment */
389 __be64 s_je_array
[MAX_JOURNAL_ENTRIES
];
392 int s_sum_index
; /* for the 12 summaries */
393 struct shadow_tree s_shadow_tree
;
394 int s_je_fill
; /* index of current je */
395 /* readwrite.c fields */
396 struct mutex s_write_mutex
;
398 mempool_t
*s_block_pool
; /* struct logfs_block pool */
399 mempool_t
*s_shadow_pool
; /* struct logfs_shadow pool */
400 struct list_head s_writeback_list
; /* writeback pages */
403 * - s_used_bytes specifies space used to store valid data objects.
404 * - s_dirty_used_bytes is space used to store non-committed data
405 * objects. Those objects have already been written themselves,
406 * but they don't become valid until all indirect blocks up to the
407 * journal have been written as well.
408 * - s_dirty_free_bytes is space used to store the old copy of a
409 * replaced object, as long as the replacement is non-committed.
410 * In other words, it is the amount of space freed when all dirty
411 * blocks are written back.
412 * - s_free_bytes is the amount of free space available for any
414 * - s_root_reserve is the amount of free space available only to
415 * the root user. Non-privileged users can no longer write once
416 * this watermark has been reached.
417 * - s_speed_reserve is space which remains unused to speed up
418 * garbage collection performance.
419 * - s_dirty_pages is the space reserved for currently dirty pages.
420 * It is a pessimistic estimate, so some/most will get freed on
423 * s_used_bytes + s_free_bytes + s_speed_reserve = total usable size
427 u64 s_dirty_free_bytes
;
428 u64 s_dirty_used_bytes
;
432 /* Bad block handling:
433 * - s_bad_seg_reserve is a number of segments usually kept
434 * free. When encountering bad blocks, the affected segment's data
435 * is _temporarily_ moved to a reserved segment.
436 * - s_bad_segments is the number of known bad segments.
438 u32 s_bad_seg_reserve
;
443 * struct logfs_inode - in-memory inode
445 * @vfs_inode: struct inode
446 * @li_data: data pointers
447 * @li_used_bytes: number of used bytes
448 * @li_freeing_list: used to track inodes currently being freed
449 * @li_flags: inode flags
450 * @li_refcount: number of internal (GC-induced) references
453 struct inode vfs_inode
;
454 u64 li_data
[LOGFS_EMBEDDED_FIELDS
];
456 struct list_head li_freeing_list
;
457 struct logfs_block
*li_block
;
463 #define journal_for_each(__i) for (__i = 0; __i < LOGFS_JOURNAL_SEGS; __i++)
464 #define for_each_area(__i) for (__i = 0; __i < LOGFS_NO_AREAS; __i++)
465 #define for_each_area_down(__i) for (__i = LOGFS_NO_AREAS - 1; __i >= 0; __i--)
468 int logfs_compress(void *in
, void *out
, size_t inlen
, size_t outlen
);
469 int logfs_uncompress(void *in
, void *out
, size_t inlen
, size_t outlen
);
470 int __init
logfs_compr_init(void);
471 void logfs_compr_exit(void);
475 int logfs_get_sb_bdev(struct logfs_super
*s
,
476 struct file_system_type
*type
,
477 const char *devname
);
479 static inline int logfs_get_sb_bdev(struct logfs_super
*s
,
480 struct file_system_type
*type
,
489 int logfs_get_sb_mtd(struct logfs_super
*s
, int mtdnr
);
491 static inline int logfs_get_sb_mtd(struct logfs_super
*s
, int mtdnr
)
498 extern const struct inode_operations logfs_symlink_iops
;
499 extern const struct inode_operations logfs_dir_iops
;
500 extern const struct file_operations logfs_dir_fops
;
501 int logfs_replay_journal(struct super_block
*sb
);
504 extern const struct inode_operations logfs_reg_iops
;
505 extern const struct file_operations logfs_reg_fops
;
506 extern const struct address_space_operations logfs_reg_aops
;
507 int logfs_readpage(struct file
*file
, struct page
*page
);
508 long logfs_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
509 int logfs_fsync(struct file
*file
, int datasync
);
512 u32
get_best_cand(struct super_block
*sb
, struct candidate_list
*list
, u32
*ec
);
513 void logfs_gc_pass(struct super_block
*sb
);
514 int logfs_check_areas(struct super_block
*sb
);
515 int logfs_init_gc(struct super_block
*sb
);
516 void logfs_cleanup_gc(struct super_block
*sb
);
519 extern const struct super_operations logfs_super_operations
;
520 struct inode
*logfs_iget(struct super_block
*sb
, ino_t ino
);
521 struct inode
*logfs_safe_iget(struct super_block
*sb
, ino_t ino
, int *cookie
);
522 void logfs_safe_iput(struct inode
*inode
, int cookie
);
523 struct inode
*logfs_new_inode(struct inode
*dir
, int mode
);
524 struct inode
*logfs_new_meta_inode(struct super_block
*sb
, u64 ino
);
525 struct inode
*logfs_read_meta_inode(struct super_block
*sb
, u64 ino
);
526 int logfs_init_inode_cache(void);
527 void logfs_destroy_inode_cache(void);
528 void logfs_set_blocks(struct inode
*inode
, u64 no
);
529 /* these logically belong into inode.c but actually reside in readwrite.c */
530 int logfs_read_inode(struct inode
*inode
);
531 int __logfs_write_inode(struct inode
*inode
, long flags
);
532 void logfs_evict_inode(struct inode
*inode
);
535 void logfs_write_anchor(struct super_block
*sb
);
536 int logfs_init_journal(struct super_block
*sb
);
537 void logfs_cleanup_journal(struct super_block
*sb
);
538 int write_alias_journal(struct super_block
*sb
, u64 ino
, u64 bix
,
539 level_t level
, int child_no
, __be64 val
);
540 void do_logfs_journal_wl_pass(struct super_block
*sb
);
543 pgoff_t
logfs_pack_index(u64 bix
, level_t level
);
544 void logfs_unpack_index(pgoff_t index
, u64
*bix
, level_t
*level
);
545 int logfs_inode_write(struct inode
*inode
, const void *buf
, size_t count
,
546 loff_t bix
, long flags
, struct shadow_tree
*shadow_tree
);
547 int logfs_readpage_nolock(struct page
*page
);
548 int logfs_write_buf(struct inode
*inode
, struct page
*page
, long flags
);
549 int logfs_delete(struct inode
*inode
, pgoff_t index
,
550 struct shadow_tree
*shadow_tree
);
551 int logfs_rewrite_block(struct inode
*inode
, u64 bix
, u64 ofs
,
552 gc_level_t gc_level
, long flags
);
553 int logfs_is_valid_block(struct super_block
*sb
, u64 ofs
, u64 ino
, u64 bix
,
554 gc_level_t gc_level
);
555 int logfs_truncate(struct inode
*inode
, u64 size
);
556 u64
logfs_seek_hole(struct inode
*inode
, u64 bix
);
557 u64
logfs_seek_data(struct inode
*inode
, u64 bix
);
558 int logfs_open_segfile(struct super_block
*sb
);
559 int logfs_init_rw(struct super_block
*sb
);
560 void logfs_cleanup_rw(struct super_block
*sb
);
561 void logfs_add_transaction(struct inode
*inode
, struct logfs_transaction
*ta
);
562 void logfs_del_transaction(struct inode
*inode
, struct logfs_transaction
*ta
);
563 void logfs_write_block(struct logfs_block
*block
, long flags
);
564 int logfs_write_obj_aliases_pagecache(struct super_block
*sb
);
565 void logfs_get_segment_entry(struct super_block
*sb
, u32 segno
,
566 struct logfs_segment_entry
*se
);
567 void logfs_set_segment_used(struct super_block
*sb
, u64 ofs
, int increment
);
568 void logfs_set_segment_erased(struct super_block
*sb
, u32 segno
, u32 ec
,
569 gc_level_t gc_level
);
570 void logfs_set_segment_reserved(struct super_block
*sb
, u32 segno
);
571 void logfs_set_segment_unreserved(struct super_block
*sb
, u32 segno
, u32 ec
);
572 struct logfs_block
*__alloc_block(struct super_block
*sb
,
573 u64 ino
, u64 bix
, level_t level
);
574 void __free_block(struct super_block
*sb
, struct logfs_block
*block
);
575 void btree_write_block(struct logfs_block
*block
);
576 void initialize_block_counters(struct page
*page
, struct logfs_block
*block
,
577 __be64
*array
, int page_is_empty
);
578 int logfs_exist_block(struct inode
*inode
, u64 bix
);
579 int get_page_reserve(struct inode
*inode
, struct page
*page
);
580 extern struct logfs_block_ops indirect_block_ops
;
583 int logfs_erase_segment(struct super_block
*sb
, u32 ofs
, int ensure_erase
);
584 int wbuf_read(struct super_block
*sb
, u64 ofs
, size_t len
, void *buf
);
585 int logfs_segment_read(struct inode
*inode
, struct page
*page
, u64 ofs
, u64 bix
,
587 int logfs_segment_write(struct inode
*inode
, struct page
*page
,
588 struct logfs_shadow
*shadow
);
589 int logfs_segment_delete(struct inode
*inode
, struct logfs_shadow
*shadow
);
590 int logfs_load_object_aliases(struct super_block
*sb
,
591 struct logfs_obj_alias
*oa
, int count
);
592 void move_page_to_btree(struct page
*page
);
593 int logfs_init_mapping(struct super_block
*sb
);
594 void logfs_sync_area(struct logfs_area
*area
);
595 void logfs_sync_segments(struct super_block
*sb
);
596 void freeseg(struct super_block
*sb
, u32 segno
);
599 int logfs_init_areas(struct super_block
*sb
);
600 void logfs_cleanup_areas(struct super_block
*sb
);
601 int logfs_open_area(struct logfs_area
*area
, size_t bytes
);
602 int __logfs_buf_write(struct logfs_area
*area
, u64 ofs
, void *buf
, size_t len
,
605 static inline int logfs_buf_write(struct logfs_area
*area
, u64 ofs
,
606 void *buf
, size_t len
)
608 return __logfs_buf_write(area
, ofs
, buf
, len
, 0);
611 static inline int logfs_buf_recover(struct logfs_area
*area
, u64 ofs
,
612 void *buf
, size_t len
)
614 return __logfs_buf_write(area
, ofs
, buf
, len
, 1);
618 struct page
*emergency_read_begin(struct address_space
*mapping
, pgoff_t index
);
619 void emergency_read_end(struct page
*page
);
620 void logfs_crash_dump(struct super_block
*sb
);
621 void *memchr_inv(const void *s
, int c
, size_t n
);
622 int logfs_statfs(struct dentry
*dentry
, struct kstatfs
*stats
);
623 int logfs_check_ds(struct logfs_disk_super
*ds
);
624 int logfs_write_sb(struct super_block
*sb
);
626 static inline struct logfs_super
*logfs_super(struct super_block
*sb
)
628 return sb
->s_fs_info
;
631 static inline struct logfs_inode
*logfs_inode(struct inode
*inode
)
633 return container_of(inode
, struct logfs_inode
, vfs_inode
);
636 static inline void logfs_set_ro(struct super_block
*sb
)
638 logfs_super(sb
)->s_flags
|= LOGFS_SB_FLAG_RO
;
641 #define LOGFS_BUG(sb) do { \
642 struct super_block *__sb = sb; \
643 logfs_crash_dump(__sb); \
644 logfs_super(__sb)->s_flags |= LOGFS_SB_FLAG_RO; \
648 #define LOGFS_BUG_ON(condition, sb) \
649 do { if (unlikely(condition)) LOGFS_BUG((sb)); } while (0)
651 static inline __be32
logfs_crc32(void *data
, size_t len
, size_t skip
)
653 return cpu_to_be32(crc32(~0, data
+skip
, len
-skip
));
656 static inline u8
logfs_type(struct inode
*inode
)
658 return (inode
->i_mode
>> 12) & 15;
661 static inline pgoff_t
logfs_index(struct super_block
*sb
, u64 pos
)
663 return pos
>> sb
->s_blocksize_bits
;
666 static inline u64
dev_ofs(struct super_block
*sb
, u32 segno
, u32 ofs
)
668 return ((u64
)segno
<< logfs_super(sb
)->s_segshift
) + ofs
;
671 static inline u32
seg_no(struct super_block
*sb
, u64 ofs
)
673 return ofs
>> logfs_super(sb
)->s_segshift
;
676 static inline u32
seg_ofs(struct super_block
*sb
, u64 ofs
)
678 return ofs
& logfs_super(sb
)->s_segmask
;
681 static inline u64
seg_align(struct super_block
*sb
, u64 ofs
)
683 return ofs
& ~logfs_super(sb
)->s_segmask
;
686 static inline struct logfs_block
*logfs_block(struct page
*page
)
688 return (void *)page
->private;
691 static inline level_t
shrink_level(gc_level_t __level
)
693 u8 level
= (__force u8
)__level
;
695 if (level
>= LOGFS_MAX_LEVELS
)
696 level
-= LOGFS_MAX_LEVELS
;
697 return (__force level_t
)level
;
700 static inline gc_level_t
expand_level(u64 ino
, level_t __level
)
702 u8 level
= (__force u8
)__level
;
704 if (ino
== LOGFS_INO_MASTER
) {
705 /* ifile has separate areas */
706 level
+= LOGFS_MAX_LEVELS
;
708 return (__force gc_level_t
)level
;
711 static inline int logfs_block_shift(struct super_block
*sb
, level_t level
)
713 level
= shrink_level((__force gc_level_t
)level
);
714 return (__force
int)level
* (sb
->s_blocksize_bits
- 3);
717 static inline u64
logfs_block_mask(struct super_block
*sb
, level_t level
)
719 return ~0ull << logfs_block_shift(sb
, level
);
722 static inline struct logfs_area
*get_area(struct super_block
*sb
,
725 return logfs_super(sb
)->s_area
[(__force u8
)gc_level
];
728 static inline void logfs_mempool_destroy(mempool_t
*pool
)
731 mempool_destroy(pool
);