diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2010-07-10 05:07:04 -0400 |
---|---|---|
committer | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2010-07-22 21:02:13 -0400 |
commit | 10ff885ba6f56bf7480ce3b5daf38c07600ecea3 (patch) | |
tree | d1a301a1f870bcc2085c840eb875097e2fe0cb7b /fs | |
parent | 583ada4761e18bb105ce5181b0b13cf55ead6201 (diff) |
nilfs2: get rid of nilfs_direct uses
This replaces all uses of nilfs_direct struct in implementation of
direct mapping with nilfs_bmap struct.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/nilfs2/direct.c | 78 |
1 files changed, 32 insertions, 46 deletions
diff --git a/fs/nilfs2/direct.c b/fs/nilfs2/direct.c index fd006eefc254..cfc7218914d6 100644 --- a/fs/nilfs2/direct.c +++ b/fs/nilfs2/direct.c | |||
@@ -27,31 +27,29 @@ | |||
27 | #include "alloc.h" | 27 | #include "alloc.h" |
28 | #include "dat.h" | 28 | #include "dat.h" |
29 | 29 | ||
30 | static inline __le64 *nilfs_direct_dptrs(const struct nilfs_direct *direct) | 30 | static inline __le64 *nilfs_direct_dptrs(const struct nilfs_bmap *direct) |
31 | { | 31 | { |
32 | return (__le64 *) | 32 | 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); |
34 | } | 34 | } |
35 | 35 | ||
36 | static inline __u64 | 36 | static 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) |
38 | { | 38 | { |
39 | return le64_to_cpu(*(nilfs_direct_dptrs(direct) + key)); | 39 | return le64_to_cpu(*(nilfs_direct_dptrs(direct) + key)); |
40 | } | 40 | } |
41 | 41 | ||
42 | static inline void nilfs_direct_set_ptr(struct nilfs_direct *direct, | 42 | static inline void nilfs_direct_set_ptr(struct nilfs_bmap *direct, |
43 | __u64 key, __u64 ptr) | 43 | __u64 key, __u64 ptr) |
44 | { | 44 | { |
45 | *(nilfs_direct_dptrs(direct) + key) = cpu_to_le64(ptr); | 45 | *(nilfs_direct_dptrs(direct) + key) = cpu_to_le64(ptr); |
46 | } | 46 | } |
47 | 47 | ||
48 | static int nilfs_direct_lookup(const struct nilfs_bmap *bmap, | 48 | static int nilfs_direct_lookup(const struct nilfs_bmap *direct, |
49 | __u64 key, int level, __u64 *ptrp) | 49 | __u64 key, int level, __u64 *ptrp) |
50 | { | 50 | { |
51 | struct nilfs_direct *direct; | ||
52 | __u64 ptr; | 51 | __u64 ptr; |
53 | 52 | ||
54 | direct = (struct nilfs_direct *)bmap; /* XXX: use macro for level 1 */ | ||
55 | if (key > NILFS_DIRECT_KEY_MAX || level != 1) | 53 | if (key > NILFS_DIRECT_KEY_MAX || level != 1) |
56 | return -ENOENT; | 54 | return -ENOENT; |
57 | ptr = nilfs_direct_get_ptr(direct, key); | 55 | ptr = nilfs_direct_get_ptr(direct, key); |
@@ -63,11 +61,10 @@ static int nilfs_direct_lookup(const struct nilfs_bmap *bmap, | |||
63 | return 0; | 61 | return 0; |
64 | } | 62 | } |
65 | 63 | ||
66 | static int nilfs_direct_lookup_contig(const struct nilfs_bmap *bmap, | 64 | static int nilfs_direct_lookup_contig(const struct nilfs_bmap *direct, |
67 | __u64 key, __u64 *ptrp, | 65 | __u64 key, __u64 *ptrp, |
68 | unsigned maxblocks) | 66 | unsigned maxblocks) |
69 | { | 67 | { |
70 | struct nilfs_direct *direct = (struct nilfs_direct *)bmap; | ||
71 | struct inode *dat = NULL; | 68 | struct inode *dat = NULL; |
72 | __u64 ptr, ptr2; | 69 | __u64 ptr, ptr2; |
73 | sector_t blocknr; | 70 | sector_t blocknr; |
@@ -79,8 +76,8 @@ static int nilfs_direct_lookup_contig(const struct nilfs_bmap *bmap, | |||
79 | if (ptr == NILFS_BMAP_INVALID_PTR) | 76 | if (ptr == NILFS_BMAP_INVALID_PTR) |
80 | return -ENOENT; | 77 | return -ENOENT; |
81 | 78 | ||
82 | if (NILFS_BMAP_USE_VBN(bmap)) { | 79 | if (NILFS_BMAP_USE_VBN(direct)) { |
83 | dat = nilfs_bmap_get_dat(bmap); | 80 | dat = nilfs_bmap_get_dat(direct); |
84 | ret = nilfs_dat_translate(dat, ptr, &blocknr); | 81 | ret = nilfs_dat_translate(dat, ptr, &blocknr); |
85 | if (ret < 0) | 82 | if (ret < 0) |
86 | return ret; | 83 | return ret; |
@@ -106,29 +103,28 @@ static int nilfs_direct_lookup_contig(const struct nilfs_bmap *bmap, | |||
106 | } | 103 | } |
107 | 104 | ||
108 | static __u64 | 105 | static __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) |
110 | { | 107 | { |
111 | __u64 ptr; | 108 | __u64 ptr; |
112 | 109 | ||
113 | ptr = nilfs_bmap_find_target_seq(&direct->d_bmap, key); | 110 | ptr = nilfs_bmap_find_target_seq(direct, key); |
114 | if (ptr != NILFS_BMAP_INVALID_PTR) | 111 | if (ptr != NILFS_BMAP_INVALID_PTR) |
115 | /* sequential access */ | 112 | /* sequential access */ |
116 | return ptr; | 113 | return ptr; |
117 | else | 114 | else |
118 | /* block group */ | 115 | /* block group */ |
119 | return nilfs_bmap_find_target_in_group(&direct->d_bmap); | 116 | return nilfs_bmap_find_target_in_group(direct); |
120 | } | 117 | } |
121 | 118 | ||
122 | static void nilfs_direct_set_target_v(struct nilfs_direct *direct, | 119 | static void nilfs_direct_set_target_v(struct nilfs_bmap *direct, |
123 | __u64 key, __u64 ptr) | 120 | __u64 key, __u64 ptr) |
124 | { | 121 | { |
125 | direct->d_bmap.b_last_allocated_key = key; | 122 | direct->b_last_allocated_key = key; |
126 | direct->d_bmap.b_last_allocated_ptr = ptr; | 123 | direct->b_last_allocated_ptr = ptr; |
127 | } | 124 | } |
128 | 125 | ||
129 | static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) | 126 | static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) |
130 | { | 127 | { |
131 | struct nilfs_direct *direct = (struct nilfs_direct *)bmap; | ||
132 | union nilfs_bmap_ptr_req req; | 128 | union nilfs_bmap_ptr_req req; |
133 | struct inode *dat = NULL; | 129 | struct inode *dat = NULL; |
134 | struct buffer_head *bh; | 130 | struct buffer_head *bh; |
@@ -136,11 +132,11 @@ static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) | |||
136 | 132 | ||
137 | if (key > NILFS_DIRECT_KEY_MAX) | 133 | if (key > NILFS_DIRECT_KEY_MAX) |
138 | return -ENOENT; | 134 | 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) |
140 | return -EEXIST; | 136 | return -EEXIST; |
141 | 137 | ||
142 | if (NILFS_BMAP_USE_VBN(bmap)) { | 138 | 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); |
144 | dat = nilfs_bmap_get_dat(bmap); | 140 | dat = nilfs_bmap_get_dat(bmap); |
145 | } | 141 | } |
146 | ret = nilfs_bmap_prepare_alloc_ptr(bmap, &req, dat); | 142 | 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) | |||
150 | set_buffer_nilfs_volatile(bh); | 146 | set_buffer_nilfs_volatile(bh); |
151 | 147 | ||
152 | nilfs_bmap_commit_alloc_ptr(bmap, &req, dat); | 148 | 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); |
154 | 150 | ||
155 | if (!nilfs_bmap_dirty(bmap)) | 151 | if (!nilfs_bmap_dirty(bmap)) |
156 | nilfs_bmap_set_dirty(bmap); | 152 | nilfs_bmap_set_dirty(bmap); |
157 | 153 | ||
158 | if (NILFS_BMAP_USE_VBN(bmap)) | 154 | 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); |
160 | 156 | ||
161 | nilfs_bmap_add_blocks(bmap, 1); | 157 | nilfs_bmap_add_blocks(bmap, 1); |
162 | } | 158 | } |
@@ -165,33 +161,30 @@ static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr) | |||
165 | 161 | ||
166 | static int nilfs_direct_delete(struct nilfs_bmap *bmap, __u64 key) | 162 | static int nilfs_direct_delete(struct nilfs_bmap *bmap, __u64 key) |
167 | { | 163 | { |
168 | struct nilfs_direct *direct = (struct nilfs_direct *)bmap; | ||
169 | union nilfs_bmap_ptr_req req; | 164 | union nilfs_bmap_ptr_req req; |
170 | struct inode *dat; | 165 | struct inode *dat; |
171 | int ret; | 166 | int ret; |
172 | 167 | ||
173 | if (key > NILFS_DIRECT_KEY_MAX || | 168 | 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) |
175 | return -ENOENT; | 170 | return -ENOENT; |
176 | 171 | ||
177 | dat = NILFS_BMAP_USE_VBN(bmap) ? nilfs_bmap_get_dat(bmap) : NULL; | 172 | 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); |
179 | 174 | ||
180 | ret = nilfs_bmap_prepare_end_ptr(bmap, &req, dat); | 175 | ret = nilfs_bmap_prepare_end_ptr(bmap, &req, dat); |
181 | if (!ret) { | 176 | if (!ret) { |
182 | nilfs_bmap_commit_end_ptr(bmap, &req, dat); | 177 | 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); |
184 | nilfs_bmap_sub_blocks(bmap, 1); | 179 | nilfs_bmap_sub_blocks(bmap, 1); |
185 | } | 180 | } |
186 | return ret; | 181 | return ret; |
187 | } | 182 | } |
188 | 183 | ||
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) |
190 | { | 185 | { |
191 | struct nilfs_direct *direct; | ||
192 | __u64 key, lastkey; | 186 | __u64 key, lastkey; |
193 | 187 | ||
194 | direct = (struct nilfs_direct *)bmap; | ||
195 | lastkey = NILFS_DIRECT_KEY_MAX + 1; | 188 | lastkey = NILFS_DIRECT_KEY_MAX + 1; |
196 | for (key = NILFS_DIRECT_KEY_MIN; key <= NILFS_DIRECT_KEY_MAX; key++) | 189 | for (key = NILFS_DIRECT_KEY_MIN; key <= NILFS_DIRECT_KEY_MAX; key++) |
197 | if (nilfs_direct_get_ptr(direct, key) != | 190 | if (nilfs_direct_get_ptr(direct, key) != |
@@ -211,15 +204,13 @@ static int nilfs_direct_check_insert(const struct nilfs_bmap *bmap, __u64 key) | |||
211 | return key > NILFS_DIRECT_KEY_MAX; | 204 | return key > NILFS_DIRECT_KEY_MAX; |
212 | } | 205 | } |
213 | 206 | ||
214 | static int nilfs_direct_gather_data(struct nilfs_bmap *bmap, | 207 | static int nilfs_direct_gather_data(struct nilfs_bmap *direct, |
215 | __u64 *keys, __u64 *ptrs, int nitems) | 208 | __u64 *keys, __u64 *ptrs, int nitems) |
216 | { | 209 | { |
217 | struct nilfs_direct *direct; | ||
218 | __u64 key; | 210 | __u64 key; |
219 | __u64 ptr; | 211 | __u64 ptr; |
220 | int n; | 212 | int n; |
221 | 213 | ||
222 | direct = (struct nilfs_direct *)bmap; | ||
223 | if (nitems > NILFS_DIRECT_NBLOCKS) | 214 | if (nitems > NILFS_DIRECT_NBLOCKS) |
224 | nitems = NILFS_DIRECT_NBLOCKS; | 215 | nitems = NILFS_DIRECT_NBLOCKS; |
225 | n = 0; | 216 | n = 0; |
@@ -237,7 +228,6 @@ static int nilfs_direct_gather_data(struct nilfs_bmap *bmap, | |||
237 | int nilfs_direct_delete_and_convert(struct nilfs_bmap *bmap, | 228 | int nilfs_direct_delete_and_convert(struct nilfs_bmap *bmap, |
238 | __u64 key, __u64 *keys, __u64 *ptrs, int n) | 229 | __u64 key, __u64 *keys, __u64 *ptrs, int n) |
239 | { | 230 | { |
240 | struct nilfs_direct *direct; | ||
241 | __le64 *dptrs; | 231 | __le64 *dptrs; |
242 | int ret, i, j; | 232 | int ret, i, j; |
243 | 233 | ||
@@ -253,8 +243,7 @@ int nilfs_direct_delete_and_convert(struct nilfs_bmap *bmap, | |||
253 | bmap->b_ops->bop_clear(bmap); | 243 | bmap->b_ops->bop_clear(bmap); |
254 | 244 | ||
255 | /* convert */ | 245 | /* convert */ |
256 | direct = (struct nilfs_direct *)bmap; | 246 | dptrs = nilfs_direct_dptrs(bmap); |
257 | dptrs = nilfs_direct_dptrs(direct); | ||
258 | for (i = 0, j = 0; i < NILFS_DIRECT_NBLOCKS; i++) { | 247 | for (i = 0, j = 0; i < NILFS_DIRECT_NBLOCKS; i++) { |
259 | if ((j < n) && (i == keys[j])) { | 248 | if ((j < n) && (i == keys[j])) { |
260 | dptrs[i] = (i != key) ? | 249 | dptrs[i] = (i != key) ? |
@@ -272,7 +261,6 @@ int nilfs_direct_delete_and_convert(struct nilfs_bmap *bmap, | |||
272 | static int nilfs_direct_propagate(struct nilfs_bmap *bmap, | 261 | static int nilfs_direct_propagate(struct nilfs_bmap *bmap, |
273 | struct buffer_head *bh) | 262 | struct buffer_head *bh) |
274 | { | 263 | { |
275 | struct nilfs_direct *direct = (struct nilfs_direct *)bmap; | ||
276 | struct nilfs_palloc_req oldreq, newreq; | 264 | struct nilfs_palloc_req oldreq, newreq; |
277 | struct inode *dat; | 265 | struct inode *dat; |
278 | __u64 key; | 266 | __u64 key; |
@@ -284,7 +272,7 @@ static int nilfs_direct_propagate(struct nilfs_bmap *bmap, | |||
284 | 272 | ||
285 | dat = nilfs_bmap_get_dat(bmap); | 273 | dat = nilfs_bmap_get_dat(bmap); |
286 | key = nilfs_bmap_data_get_key(bmap, bh); | 274 | key = nilfs_bmap_data_get_key(bmap, bh); |
287 | ptr = nilfs_direct_get_ptr(direct, key); | 275 | ptr = nilfs_direct_get_ptr(bmap, key); |
288 | if (!buffer_nilfs_volatile(bh)) { | 276 | if (!buffer_nilfs_volatile(bh)) { |
289 | oldreq.pr_entry_nr = ptr; | 277 | oldreq.pr_entry_nr = ptr; |
290 | newreq.pr_entry_nr = ptr; | 278 | newreq.pr_entry_nr = ptr; |
@@ -294,20 +282,20 @@ static int nilfs_direct_propagate(struct nilfs_bmap *bmap, | |||
294 | nilfs_dat_commit_update(dat, &oldreq, &newreq, | 282 | nilfs_dat_commit_update(dat, &oldreq, &newreq, |
295 | bmap->b_ptr_type == NILFS_BMAP_PTR_VS); | 283 | bmap->b_ptr_type == NILFS_BMAP_PTR_VS); |
296 | set_buffer_nilfs_volatile(bh); | 284 | 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); |
298 | } else | 286 | } else |
299 | ret = nilfs_dat_mark_dirty(dat, ptr); | 287 | ret = nilfs_dat_mark_dirty(dat, ptr); |
300 | 288 | ||
301 | return ret; | 289 | return ret; |
302 | } | 290 | } |
303 | 291 | ||
304 | static int nilfs_direct_assign_v(struct nilfs_direct *direct, | 292 | static int nilfs_direct_assign_v(struct nilfs_bmap *direct, |
305 | __u64 key, __u64 ptr, | 293 | __u64 key, __u64 ptr, |
306 | struct buffer_head **bh, | 294 | struct buffer_head **bh, |
307 | sector_t blocknr, | 295 | sector_t blocknr, |
308 | union nilfs_binfo *binfo) | 296 | union nilfs_binfo *binfo) |
309 | { | 297 | { |
310 | struct inode *dat = nilfs_bmap_get_dat(&direct->d_bmap); | 298 | struct inode *dat = nilfs_bmap_get_dat(direct); |
311 | union nilfs_bmap_ptr_req req; | 299 | union nilfs_bmap_ptr_req req; |
312 | int ret; | 300 | int ret; |
313 | 301 | ||
@@ -321,7 +309,7 @@ static int nilfs_direct_assign_v(struct nilfs_direct *direct, | |||
321 | return ret; | 309 | return ret; |
322 | } | 310 | } |
323 | 311 | ||
324 | static int nilfs_direct_assign_p(struct nilfs_direct *direct, | 312 | static int nilfs_direct_assign_p(struct nilfs_bmap *direct, |
325 | __u64 key, __u64 ptr, | 313 | __u64 key, __u64 ptr, |
326 | struct buffer_head **bh, | 314 | struct buffer_head **bh, |
327 | sector_t blocknr, | 315 | sector_t blocknr, |
@@ -340,18 +328,16 @@ static int nilfs_direct_assign(struct nilfs_bmap *bmap, | |||
340 | sector_t blocknr, | 328 | sector_t blocknr, |
341 | union nilfs_binfo *binfo) | 329 | union nilfs_binfo *binfo) |
342 | { | 330 | { |
343 | struct nilfs_direct *direct; | ||
344 | __u64 key; | 331 | __u64 key; |
345 | __u64 ptr; | 332 | __u64 ptr; |
346 | 333 | ||
347 | direct = (struct nilfs_direct *)bmap; | ||
348 | key = nilfs_bmap_data_get_key(bmap, *bh); | 334 | key = nilfs_bmap_data_get_key(bmap, *bh); |
349 | if (unlikely(key > NILFS_DIRECT_KEY_MAX)) { | 335 | if (unlikely(key > NILFS_DIRECT_KEY_MAX)) { |
350 | printk(KERN_CRIT "%s: invalid key: %llu\n", __func__, | 336 | printk(KERN_CRIT "%s: invalid key: %llu\n", __func__, |
351 | (unsigned long long)key); | 337 | (unsigned long long)key); |
352 | return -EINVAL; | 338 | return -EINVAL; |
353 | } | 339 | } |
354 | ptr = nilfs_direct_get_ptr(direct, key); | 340 | ptr = nilfs_direct_get_ptr(bmap, key); |
355 | if (unlikely(ptr == NILFS_BMAP_INVALID_PTR)) { | 341 | if (unlikely(ptr == NILFS_BMAP_INVALID_PTR)) { |
356 | printk(KERN_CRIT "%s: invalid pointer: %llu\n", __func__, | 342 | printk(KERN_CRIT "%s: invalid pointer: %llu\n", __func__, |
357 | (unsigned long long)ptr); | 343 | (unsigned long long)ptr); |
@@ -359,8 +345,8 @@ static int nilfs_direct_assign(struct nilfs_bmap *bmap, | |||
359 | } | 345 | } |
360 | 346 | ||
361 | return NILFS_BMAP_USE_VBN(bmap) ? | 347 | return NILFS_BMAP_USE_VBN(bmap) ? |
362 | nilfs_direct_assign_v(direct, key, ptr, bh, blocknr, binfo) : | 348 | nilfs_direct_assign_v(bmap, key, ptr, bh, blocknr, binfo) : |
363 | nilfs_direct_assign_p(direct, key, ptr, bh, blocknr, binfo); | 349 | nilfs_direct_assign_p(bmap, key, ptr, bh, blocknr, binfo); |
364 | } | 350 | } |
365 | 351 | ||
366 | static const struct nilfs_bmap_operations nilfs_direct_ops = { | 352 | static const struct nilfs_bmap_operations nilfs_direct_ops = { |