2727#include "alloc.h"
2828#include "dat.h"
2929
30- static inline __le64 * nilfs_direct_dptrs (const struct nilfs_direct * direct )
30+ static inline __le64 * nilfs_direct_dptrs (const struct nilfs_bmap * direct )
3131{
3232 return (__le64 * )
33- ((struct nilfs_direct_node * )direct -> d_bmap . b_u .u_data + 1 );
33+ ((struct nilfs_direct_node * )direct -> b_u .u_data + 1 );
3434}
3535
3636static inline __u64
37- nilfs_direct_get_ptr (const struct nilfs_direct * direct , __u64 key )
37+ nilfs_direct_get_ptr (const struct nilfs_bmap * direct , __u64 key )
3838{
3939 return le64_to_cpu (* (nilfs_direct_dptrs (direct ) + key ));
4040}
4141
42- static inline void nilfs_direct_set_ptr (struct nilfs_direct * direct ,
42+ static inline void nilfs_direct_set_ptr (struct nilfs_bmap * direct ,
4343 __u64 key , __u64 ptr )
4444{
4545 * (nilfs_direct_dptrs (direct ) + key ) = cpu_to_le64 (ptr );
4646}
4747
48- static int nilfs_direct_lookup (const struct nilfs_bmap * bmap ,
48+ static int nilfs_direct_lookup (const struct nilfs_bmap * direct ,
4949 __u64 key , int level , __u64 * ptrp )
5050{
51- struct nilfs_direct * direct ;
5251 __u64 ptr ;
5352
54- direct = (struct nilfs_direct * )bmap ; /* XXX: use macro for level 1 */
5553 if (key > NILFS_DIRECT_KEY_MAX || level != 1 )
5654 return - ENOENT ;
5755 ptr = nilfs_direct_get_ptr (direct , key );
@@ -63,11 +61,10 @@ static int nilfs_direct_lookup(const struct nilfs_bmap *bmap,
6361 return 0 ;
6462}
6563
66- static int nilfs_direct_lookup_contig (const struct nilfs_bmap * bmap ,
64+ static int nilfs_direct_lookup_contig (const struct nilfs_bmap * direct ,
6765 __u64 key , __u64 * ptrp ,
6866 unsigned maxblocks )
6967{
70- struct nilfs_direct * direct = (struct nilfs_direct * )bmap ;
7168 struct inode * dat = NULL ;
7269 __u64 ptr , ptr2 ;
7370 sector_t blocknr ;
@@ -79,8 +76,8 @@ static int nilfs_direct_lookup_contig(const struct nilfs_bmap *bmap,
7976 if (ptr == NILFS_BMAP_INVALID_PTR )
8077 return - ENOENT ;
8178
82- if (NILFS_BMAP_USE_VBN (bmap )) {
83- dat = nilfs_bmap_get_dat (bmap );
79+ if (NILFS_BMAP_USE_VBN (direct )) {
80+ dat = nilfs_bmap_get_dat (direct );
8481 ret = nilfs_dat_translate (dat , ptr , & blocknr );
8582 if (ret < 0 )
8683 return ret ;
@@ -106,41 +103,40 @@ static int nilfs_direct_lookup_contig(const struct nilfs_bmap *bmap,
106103}
107104
108105static __u64
109- nilfs_direct_find_target_v (const struct nilfs_direct * direct , __u64 key )
106+ nilfs_direct_find_target_v (const struct nilfs_bmap * direct , __u64 key )
110107{
111108 __u64 ptr ;
112109
113- ptr = nilfs_bmap_find_target_seq (& direct -> d_bmap , key );
110+ ptr = nilfs_bmap_find_target_seq (direct , key );
114111 if (ptr != NILFS_BMAP_INVALID_PTR )
115112 /* sequential access */
116113 return ptr ;
117114 else
118115 /* block group */
119- return nilfs_bmap_find_target_in_group (& direct -> d_bmap );
116+ return nilfs_bmap_find_target_in_group (direct );
120117}
121118
122- static void nilfs_direct_set_target_v (struct nilfs_direct * direct ,
119+ static void nilfs_direct_set_target_v (struct nilfs_bmap * direct ,
123120 __u64 key , __u64 ptr )
124121{
125- direct -> d_bmap . b_last_allocated_key = key ;
126- direct -> d_bmap . b_last_allocated_ptr = ptr ;
122+ direct -> b_last_allocated_key = key ;
123+ direct -> b_last_allocated_ptr = ptr ;
127124}
128125
129126static int nilfs_direct_insert (struct nilfs_bmap * bmap , __u64 key , __u64 ptr )
130127{
131- struct nilfs_direct * direct = (struct nilfs_direct * )bmap ;
132128 union nilfs_bmap_ptr_req req ;
133129 struct inode * dat = NULL ;
134130 struct buffer_head * bh ;
135131 int ret ;
136132
137133 if (key > NILFS_DIRECT_KEY_MAX )
138134 return - ENOENT ;
139- if (nilfs_direct_get_ptr (direct , key ) != NILFS_BMAP_INVALID_PTR )
135+ if (nilfs_direct_get_ptr (bmap , key ) != NILFS_BMAP_INVALID_PTR )
140136 return - EEXIST ;
141137
142138 if (NILFS_BMAP_USE_VBN (bmap )) {
143- req .bpr_ptr = nilfs_direct_find_target_v (direct , key );
139+ req .bpr_ptr = nilfs_direct_find_target_v (bmap , key );
144140 dat = nilfs_bmap_get_dat (bmap );
145141 }
146142 ret = nilfs_bmap_prepare_alloc_ptr (bmap , & req , dat );
@@ -150,13 +146,13 @@ static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
150146 set_buffer_nilfs_volatile (bh );
151147
152148 nilfs_bmap_commit_alloc_ptr (bmap , & req , dat );
153- nilfs_direct_set_ptr (direct , key , req .bpr_ptr );
149+ nilfs_direct_set_ptr (bmap , key , req .bpr_ptr );
154150
155151 if (!nilfs_bmap_dirty (bmap ))
156152 nilfs_bmap_set_dirty (bmap );
157153
158154 if (NILFS_BMAP_USE_VBN (bmap ))
159- nilfs_direct_set_target_v (direct , key , req .bpr_ptr );
155+ nilfs_direct_set_target_v (bmap , key , req .bpr_ptr );
160156
161157 nilfs_bmap_add_blocks (bmap , 1 );
162158 }
@@ -165,33 +161,30 @@ static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
165161
166162static int nilfs_direct_delete (struct nilfs_bmap * bmap , __u64 key )
167163{
168- struct nilfs_direct * direct = (struct nilfs_direct * )bmap ;
169164 union nilfs_bmap_ptr_req req ;
170165 struct inode * dat ;
171166 int ret ;
172167
173168 if (key > NILFS_DIRECT_KEY_MAX ||
174- nilfs_direct_get_ptr (direct , key ) == NILFS_BMAP_INVALID_PTR )
169+ nilfs_direct_get_ptr (bmap , key ) == NILFS_BMAP_INVALID_PTR )
175170 return - ENOENT ;
176171
177172 dat = NILFS_BMAP_USE_VBN (bmap ) ? nilfs_bmap_get_dat (bmap ) : NULL ;
178- req .bpr_ptr = nilfs_direct_get_ptr (direct , key );
173+ req .bpr_ptr = nilfs_direct_get_ptr (bmap , key );
179174
180175 ret = nilfs_bmap_prepare_end_ptr (bmap , & req , dat );
181176 if (!ret ) {
182177 nilfs_bmap_commit_end_ptr (bmap , & req , dat );
183- nilfs_direct_set_ptr (direct , key , NILFS_BMAP_INVALID_PTR );
178+ nilfs_direct_set_ptr (bmap , key , NILFS_BMAP_INVALID_PTR );
184179 nilfs_bmap_sub_blocks (bmap , 1 );
185180 }
186181 return ret ;
187182}
188183
189- static int nilfs_direct_last_key (const struct nilfs_bmap * bmap , __u64 * keyp )
184+ static int nilfs_direct_last_key (const struct nilfs_bmap * direct , __u64 * keyp )
190185{
191- struct nilfs_direct * direct ;
192186 __u64 key , lastkey ;
193187
194- direct = (struct nilfs_direct * )bmap ;
195188 lastkey = NILFS_DIRECT_KEY_MAX + 1 ;
196189 for (key = NILFS_DIRECT_KEY_MIN ; key <= NILFS_DIRECT_KEY_MAX ; key ++ )
197190 if (nilfs_direct_get_ptr (direct , key ) !=
@@ -211,15 +204,13 @@ static int nilfs_direct_check_insert(const struct nilfs_bmap *bmap, __u64 key)
211204 return key > NILFS_DIRECT_KEY_MAX ;
212205}
213206
214- static int nilfs_direct_gather_data (struct nilfs_bmap * bmap ,
207+ static int nilfs_direct_gather_data (struct nilfs_bmap * direct ,
215208 __u64 * keys , __u64 * ptrs , int nitems )
216209{
217- struct nilfs_direct * direct ;
218210 __u64 key ;
219211 __u64 ptr ;
220212 int n ;
221213
222- direct = (struct nilfs_direct * )bmap ;
223214 if (nitems > NILFS_DIRECT_NBLOCKS )
224215 nitems = NILFS_DIRECT_NBLOCKS ;
225216 n = 0 ;
@@ -237,7 +228,6 @@ static int nilfs_direct_gather_data(struct nilfs_bmap *bmap,
237228int nilfs_direct_delete_and_convert (struct nilfs_bmap * bmap ,
238229 __u64 key , __u64 * keys , __u64 * ptrs , int n )
239230{
240- struct nilfs_direct * direct ;
241231 __le64 * dptrs ;
242232 int ret , i , j ;
243233
@@ -253,8 +243,7 @@ int nilfs_direct_delete_and_convert(struct nilfs_bmap *bmap,
253243 bmap -> b_ops -> bop_clear (bmap );
254244
255245 /* convert */
256- direct = (struct nilfs_direct * )bmap ;
257- dptrs = nilfs_direct_dptrs (direct );
246+ dptrs = nilfs_direct_dptrs (bmap );
258247 for (i = 0 , j = 0 ; i < NILFS_DIRECT_NBLOCKS ; i ++ ) {
259248 if ((j < n ) && (i == keys [j ])) {
260249 dptrs [i ] = (i != key ) ?
@@ -272,7 +261,6 @@ int nilfs_direct_delete_and_convert(struct nilfs_bmap *bmap,
272261static int nilfs_direct_propagate (struct nilfs_bmap * bmap ,
273262 struct buffer_head * bh )
274263{
275- struct nilfs_direct * direct = (struct nilfs_direct * )bmap ;
276264 struct nilfs_palloc_req oldreq , newreq ;
277265 struct inode * dat ;
278266 __u64 key ;
@@ -284,7 +272,7 @@ static int nilfs_direct_propagate(struct nilfs_bmap *bmap,
284272
285273 dat = nilfs_bmap_get_dat (bmap );
286274 key = nilfs_bmap_data_get_key (bmap , bh );
287- ptr = nilfs_direct_get_ptr (direct , key );
275+ ptr = nilfs_direct_get_ptr (bmap , key );
288276 if (!buffer_nilfs_volatile (bh )) {
289277 oldreq .pr_entry_nr = ptr ;
290278 newreq .pr_entry_nr = ptr ;
@@ -294,20 +282,20 @@ static int nilfs_direct_propagate(struct nilfs_bmap *bmap,
294282 nilfs_dat_commit_update (dat , & oldreq , & newreq ,
295283 bmap -> b_ptr_type == NILFS_BMAP_PTR_VS );
296284 set_buffer_nilfs_volatile (bh );
297- nilfs_direct_set_ptr (direct , key , newreq .pr_entry_nr );
285+ nilfs_direct_set_ptr (bmap , key , newreq .pr_entry_nr );
298286 } else
299287 ret = nilfs_dat_mark_dirty (dat , ptr );
300288
301289 return ret ;
302290}
303291
304- static int nilfs_direct_assign_v (struct nilfs_direct * direct ,
292+ static int nilfs_direct_assign_v (struct nilfs_bmap * direct ,
305293 __u64 key , __u64 ptr ,
306294 struct buffer_head * * bh ,
307295 sector_t blocknr ,
308296 union nilfs_binfo * binfo )
309297{
310- struct inode * dat = nilfs_bmap_get_dat (& direct -> d_bmap );
298+ struct inode * dat = nilfs_bmap_get_dat (direct );
311299 union nilfs_bmap_ptr_req req ;
312300 int ret ;
313301
@@ -321,7 +309,7 @@ static int nilfs_direct_assign_v(struct nilfs_direct *direct,
321309 return ret ;
322310}
323311
324- static int nilfs_direct_assign_p (struct nilfs_direct * direct ,
312+ static int nilfs_direct_assign_p (struct nilfs_bmap * direct ,
325313 __u64 key , __u64 ptr ,
326314 struct buffer_head * * bh ,
327315 sector_t blocknr ,
@@ -340,27 +328,25 @@ static int nilfs_direct_assign(struct nilfs_bmap *bmap,
340328 sector_t blocknr ,
341329 union nilfs_binfo * binfo )
342330{
343- struct nilfs_direct * direct ;
344331 __u64 key ;
345332 __u64 ptr ;
346333
347- direct = (struct nilfs_direct * )bmap ;
348334 key = nilfs_bmap_data_get_key (bmap , * bh );
349335 if (unlikely (key > NILFS_DIRECT_KEY_MAX )) {
350336 printk (KERN_CRIT "%s: invalid key: %llu\n" , __func__ ,
351337 (unsigned long long )key );
352338 return - EINVAL ;
353339 }
354- ptr = nilfs_direct_get_ptr (direct , key );
340+ ptr = nilfs_direct_get_ptr (bmap , key );
355341 if (unlikely (ptr == NILFS_BMAP_INVALID_PTR )) {
356342 printk (KERN_CRIT "%s: invalid pointer: %llu\n" , __func__ ,
357343 (unsigned long long )ptr );
358344 return - EINVAL ;
359345 }
360346
361347 return NILFS_BMAP_USE_VBN (bmap ) ?
362- nilfs_direct_assign_v (direct , key , ptr , bh , blocknr , binfo ) :
363- nilfs_direct_assign_p (direct , key , ptr , bh , blocknr , binfo );
348+ nilfs_direct_assign_v (bmap , key , ptr , bh , blocknr , binfo ) :
349+ nilfs_direct_assign_p (bmap , key , ptr , bh , blocknr , binfo );
364350}
365351
366352static const struct nilfs_bmap_operations nilfs_direct_ops = {
0 commit comments