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__
9 #include <linux/types.h> /* for __u?? */
12 /* Mask when is applied to given block number shows is that block number is a
14 #define REISER4_FAKE_BLOCKNR_BIT_MASK 0x8000000000000000ULL
15 /* Mask which isolates a type of object this fake block number was assigned
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 */
27 BLOCK_NOT_COUNTED
= 0, /* reiser4 has no info about this block yet */
28 BLOCK_GRABBED
= 1, /* free space grabbed for further allocation
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
34 BLOCK_ALLOCATED
= 4 /* block is mapped to disk, real on-disk block
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 */
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
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 */
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 */
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
,
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
*);
155 extern void reiser4_check_block(const reiser4_block_nr
*, int);
159 # define reiser4_check_block(beg, val) noop
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__ */
171 c-indentation-style: "K&R"