mm-only debug patch...
[mmotm.git] / fs / reiser4 / block_alloc.h
blob689efc1814bf742627d43790a7fc1d498267ad9d
1 /* Copyright 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
3 #if !defined(__FS_REISER4_BLOCK_ALLOC_H__)
4 #define __FS_REISER4_BLOCK_ALLOC_H__
6 #include "dformat.h"
7 #include "forward.h"
9 #include <linux/types.h> /* for __u?? */
10 #include <linux/fs.h>
12 /* Mask when is applied to given block number shows is that block number is a
13 fake one */
14 #define REISER4_FAKE_BLOCKNR_BIT_MASK 0x8000000000000000ULL
15 /* Mask which isolates a type of object this fake block number was assigned
16 to */
17 #define REISER4_BLOCKNR_STATUS_BIT_MASK 0xC000000000000000ULL
19 /*result after applying the REISER4_BLOCKNR_STATUS_BIT_MASK should be compared
20 against these two values to understand is the object unallocated or bitmap
21 shadow object (WORKING BITMAP block, look at the plugin/space/bitmap.c) */
22 #define REISER4_UNALLOCATED_STATUS_VALUE 0xC000000000000000ULL
23 #define REISER4_BITMAP_BLOCKS_STATUS_VALUE 0x8000000000000000ULL
25 /* specification how block allocation was counted in sb block counters */
26 typedef enum {
27 BLOCK_NOT_COUNTED = 0, /* reiser4 has no info about this block yet */
28 BLOCK_GRABBED = 1, /* free space grabbed for further allocation
29 of this block */
30 BLOCK_FLUSH_RESERVED = 2, /* block is reserved for flush needs. */
31 BLOCK_UNALLOCATED = 3, /* block is used for existing in-memory object
32 ( unallocated formatted or unformatted
33 node) */
34 BLOCK_ALLOCATED = 4 /* block is mapped to disk, real on-disk block
35 number assigned */
36 } block_stage_t;
38 /* a hint for block allocator */
39 struct reiser4_blocknr_hint {
40 /* FIXME: I think we want to add a longterm lock on the bitmap block
41 here. This is to prevent jnode_flush() calls from interleaving
42 allocations on the same bitmap, once a hint is established. */
44 /* search start hint */
45 reiser4_block_nr blk;
46 /* if not zero, it is a region size we search for free blocks in */
47 reiser4_block_nr max_dist;
48 /* level for allocation, may be useful have branch-level and higher
49 write-optimized. */
50 tree_level level;
51 /* block allocator assumes that blocks, which will be mapped to disk,
52 are in this specified block_stage */
53 block_stage_t block_stage;
54 /* If direction = 1 allocate blocks in backward direction from the end
55 * of disk to the beginning of disk. */
56 unsigned int backward:1;
60 /* These flags control block allocation/deallocation behavior */
61 enum reiser4_ba_flags {
62 /* do allocatations from reserved (5%) area */
63 BA_RESERVED = (1 << 0),
65 /* block allocator can do commit trying to recover free space */
66 BA_CAN_COMMIT = (1 << 1),
68 /* if operation will be applied to formatted block */
69 BA_FORMATTED = (1 << 2),
71 /* defer actual block freeing until transaction commit */
72 BA_DEFER = (1 << 3),
74 /* allocate blocks for permanent fs objects (formatted or unformatted),
75 not wandered of log blocks */
76 BA_PERMANENT = (1 << 4),
78 /* grab space even it was disabled */
79 BA_FORCE = (1 << 5),
81 /* use default start value for free blocks search. */
82 BA_USE_DEFAULT_SEARCH_START = (1 << 6)
85 typedef enum reiser4_ba_flags reiser4_ba_flags_t;
87 extern void reiser4_blocknr_hint_init(reiser4_blocknr_hint * hint);
88 extern void reiser4_blocknr_hint_done(reiser4_blocknr_hint * hint);
89 extern void update_blocknr_hint_default(const struct super_block *,
90 const reiser4_block_nr *);
91 extern void get_blocknr_hint_default(reiser4_block_nr *);
93 extern reiser4_block_nr reiser4_fs_reserved_space(struct super_block *super);
95 int assign_fake_blocknr_formatted(reiser4_block_nr *);
96 reiser4_block_nr fake_blocknr_unformatted(int);
98 /* free -> grabbed -> fake_allocated -> used */
100 int reiser4_grab_space(__u64 count, reiser4_ba_flags_t flags);
101 void all_grabbed2free(void);
102 void grabbed2free(reiser4_context * , reiser4_super_info_data * , __u64 count);
103 void fake_allocated2free(__u64 count, reiser4_ba_flags_t flags);
104 void grabbed2flush_reserved_nolock(txn_atom * atom, __u64 count);
105 void grabbed2flush_reserved(__u64 count);
106 int reiser4_alloc_blocks(reiser4_blocknr_hint * hint,
107 reiser4_block_nr * start,
108 reiser4_block_nr * len, reiser4_ba_flags_t flags);
109 int reiser4_dealloc_blocks(const reiser4_block_nr *,
110 const reiser4_block_nr *,
111 block_stage_t, reiser4_ba_flags_t flags);
113 static inline int reiser4_alloc_block(reiser4_blocknr_hint * hint,
114 reiser4_block_nr * start,
115 reiser4_ba_flags_t flags)
117 reiser4_block_nr one = 1;
118 return reiser4_alloc_blocks(hint, start, &one, flags);
121 static inline int reiser4_dealloc_block(const reiser4_block_nr * block,
122 block_stage_t stage,
123 reiser4_ba_flags_t flags)
125 const reiser4_block_nr one = 1;
126 return reiser4_dealloc_blocks(block, &one, stage, flags);
129 #define reiser4_grab_space_force(count, flags) \
130 reiser4_grab_space(count, flags | BA_FORCE)
132 extern void grabbed2free_mark(__u64 mark);
133 extern int reiser4_grab_reserved(struct super_block *,
134 __u64, reiser4_ba_flags_t);
135 extern void reiser4_release_reserved(struct super_block *super);
137 /* grabbed -> fake_allocated */
139 /* fake_allocated -> used */
141 /* used -> fake_allocated -> grabbed -> free */
143 extern void flush_reserved2grabbed(txn_atom * atom, __u64 count);
145 extern int reiser4_blocknr_is_fake(const reiser4_block_nr * da);
147 extern void grabbed2cluster_reserved(int count);
148 extern void cluster_reserved2grabbed(int count);
149 extern void cluster_reserved2free(int count);
151 extern int reiser4_check_block_counters(const struct super_block *);
153 #if REISER4_DEBUG
155 extern void reiser4_check_block(const reiser4_block_nr *, int);
157 #else
159 # define reiser4_check_block(beg, val) noop
161 #endif
163 extern int reiser4_pre_commit_hook(void);
164 extern void reiser4_post_commit_hook(void);
165 extern void reiser4_post_write_back_hook(void);
167 #endif /* __FS_REISER4_BLOCK_ALLOC_H__ */
169 /* Make Linus happy.
170 Local variables:
171 c-indentation-style: "K&R"
172 mode-name: "LC"
173 c-basic-offset: 8
174 tab-width: 8
175 fill-column: 120
176 End: