]>
Commit | Line | Data |
---|---|---|
5eb563f5 RK |
1 | /* |
2 | * mdt.c - meta data file for NILFS | |
3 | * | |
4 | * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | * | |
20 | * Written by Ryusuke Konishi <ryusuke@osrg.net> | |
21 | */ | |
22 | ||
23 | #include <linux/buffer_head.h> | |
24 | #include <linux/mpage.h> | |
25 | #include <linux/mm.h> | |
26 | #include <linux/writeback.h> | |
27 | #include <linux/backing-dev.h> | |
28 | #include <linux/swap.h> | |
29 | #include "nilfs.h" | |
30 | #include "segment.h" | |
31 | #include "page.h" | |
32 | #include "mdt.h" | |
33 | ||
34 | ||
35 | #define NILFS_MDT_MAX_RA_BLOCKS (16 - 1) | |
36 | ||
37 | #define INIT_UNUSED_INODE_FIELDS | |
38 | ||
39 | static int | |
40 | nilfs_mdt_insert_new_block(struct inode *inode, unsigned long block, | |
41 | struct buffer_head *bh, | |
42 | void (*init_block)(struct inode *, | |
43 | struct buffer_head *, void *)) | |
44 | { | |
45 | struct nilfs_inode_info *ii = NILFS_I(inode); | |
46 | void *kaddr; | |
47 | int ret; | |
48 | ||
49 | /* Caller exclude read accesses using page lock */ | |
50 | ||
51 | /* set_buffer_new(bh); */ | |
52 | bh->b_blocknr = 0; | |
53 | ||
54 | ret = nilfs_bmap_insert(ii->i_bmap, block, (unsigned long)bh); | |
55 | if (unlikely(ret)) | |
56 | return ret; | |
57 | ||
58 | set_buffer_mapped(bh); | |
59 | ||
60 | kaddr = kmap_atomic(bh->b_page, KM_USER0); | |
61 | memset(kaddr + bh_offset(bh), 0, 1 << inode->i_blkbits); | |
62 | if (init_block) | |
63 | init_block(inode, bh, kaddr); | |
64 | flush_dcache_page(bh->b_page); | |
65 | kunmap_atomic(kaddr, KM_USER0); | |
66 | ||
67 | set_buffer_uptodate(bh); | |
68 | nilfs_mark_buffer_dirty(bh); | |
69 | nilfs_mdt_mark_dirty(inode); | |
70 | return 0; | |
71 | } | |
72 | ||
73 | static int nilfs_mdt_create_block(struct inode *inode, unsigned long block, | |
74 | struct buffer_head **out_bh, | |
75 | void (*init_block)(struct inode *, | |
76 | struct buffer_head *, | |
77 | void *)) | |
78 | { | |
79 | struct the_nilfs *nilfs = NILFS_MDT(inode)->mi_nilfs; | |
5eb563f5 RK |
80 | struct super_block *sb = inode->i_sb; |
81 | struct nilfs_transaction_info ti; | |
82 | struct buffer_head *bh; | |
83 | int err; | |
84 | ||
85 | if (!sb) { | |
201913ed RK |
86 | /* |
87 | * Make sure this function is not called from any | |
88 | * read-only context. | |
89 | */ | |
90 | if (!nilfs->ns_writer) { | |
91 | WARN_ON(1); | |
5eb563f5 RK |
92 | err = -EROFS; |
93 | goto out; | |
94 | } | |
201913ed | 95 | sb = nilfs->ns_writer->s_super; |
5eb563f5 RK |
96 | } |
97 | ||
98 | nilfs_transaction_begin(sb, &ti, 0); | |
99 | ||
100 | err = -ENOMEM; | |
101 | bh = nilfs_grab_buffer(inode, inode->i_mapping, block, 0); | |
102 | if (unlikely(!bh)) | |
103 | goto failed_unlock; | |
104 | ||
105 | err = -EEXIST; | |
14351104 | 106 | if (buffer_uptodate(bh)) |
5eb563f5 | 107 | goto failed_bh; |
14351104 | 108 | |
5eb563f5 RK |
109 | wait_on_buffer(bh); |
110 | if (buffer_uptodate(bh)) | |
111 | goto failed_bh; | |
5eb563f5 RK |
112 | |
113 | bh->b_bdev = nilfs->ns_bdev; | |
114 | err = nilfs_mdt_insert_new_block(inode, block, bh, init_block); | |
115 | if (likely(!err)) { | |
116 | get_bh(bh); | |
117 | *out_bh = bh; | |
118 | } | |
119 | ||
120 | failed_bh: | |
121 | unlock_page(bh->b_page); | |
122 | page_cache_release(bh->b_page); | |
123 | brelse(bh); | |
124 | ||
125 | failed_unlock: | |
47420c79 RK |
126 | if (likely(!err)) |
127 | err = nilfs_transaction_commit(sb); | |
128 | else | |
129 | nilfs_transaction_abort(sb); | |
5eb563f5 RK |
130 | out: |
131 | return err; | |
132 | } | |
133 | ||
134 | static int | |
135 | nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, | |
136 | int mode, struct buffer_head **out_bh) | |
137 | { | |
138 | struct buffer_head *bh; | |
0f3fe33b | 139 | __u64 blknum = 0; |
5eb563f5 RK |
140 | int ret = -ENOMEM; |
141 | ||
142 | bh = nilfs_grab_buffer(inode, inode->i_mapping, blkoff, 0); | |
143 | if (unlikely(!bh)) | |
144 | goto failed; | |
145 | ||
146 | ret = -EEXIST; /* internal code */ | |
147 | if (buffer_uptodate(bh)) | |
148 | goto out; | |
149 | ||
150 | if (mode == READA) { | |
151 | if (!trylock_buffer(bh)) { | |
152 | ret = -EBUSY; | |
153 | goto failed_bh; | |
154 | } | |
1f5abe7e | 155 | } else /* mode == READ */ |
5eb563f5 | 156 | lock_buffer(bh); |
5eb563f5 RK |
157 | |
158 | if (buffer_uptodate(bh)) { | |
159 | unlock_buffer(bh); | |
160 | goto out; | |
161 | } | |
14351104 RK |
162 | |
163 | ret = nilfs_bmap_lookup(NILFS_I(inode)->i_bmap, blkoff, &blknum); | |
164 | if (unlikely(ret)) { | |
165 | unlock_buffer(bh); | |
166 | goto failed_bh; | |
5eb563f5 | 167 | } |
14351104 | 168 | bh->b_bdev = NILFS_MDT(inode)->mi_nilfs->ns_bdev; |
0f3fe33b | 169 | bh->b_blocknr = (sector_t)blknum; |
14351104 | 170 | set_buffer_mapped(bh); |
5eb563f5 RK |
171 | |
172 | bh->b_end_io = end_buffer_read_sync; | |
173 | get_bh(bh); | |
174 | submit_bh(mode, bh); | |
175 | ret = 0; | |
176 | out: | |
177 | get_bh(bh); | |
178 | *out_bh = bh; | |
179 | ||
180 | failed_bh: | |
181 | unlock_page(bh->b_page); | |
182 | page_cache_release(bh->b_page); | |
183 | brelse(bh); | |
184 | failed: | |
185 | return ret; | |
186 | } | |
187 | ||
188 | static int nilfs_mdt_read_block(struct inode *inode, unsigned long block, | |
189 | struct buffer_head **out_bh) | |
190 | { | |
191 | struct buffer_head *first_bh, *bh; | |
192 | unsigned long blkoff; | |
193 | int i, nr_ra_blocks = NILFS_MDT_MAX_RA_BLOCKS; | |
194 | int err; | |
195 | ||
196 | err = nilfs_mdt_submit_block(inode, block, READ, &first_bh); | |
197 | if (err == -EEXIST) /* internal code */ | |
198 | goto out; | |
199 | ||
200 | if (unlikely(err)) | |
201 | goto failed; | |
202 | ||
203 | blkoff = block + 1; | |
204 | for (i = 0; i < nr_ra_blocks; i++, blkoff++) { | |
205 | err = nilfs_mdt_submit_block(inode, blkoff, READA, &bh); | |
206 | if (likely(!err || err == -EEXIST)) | |
207 | brelse(bh); | |
208 | else if (err != -EBUSY) | |
209 | break; /* abort readahead if bmap lookup failed */ | |
210 | ||
211 | if (!buffer_locked(first_bh)) | |
212 | goto out_no_wait; | |
213 | } | |
214 | ||
215 | wait_on_buffer(first_bh); | |
216 | ||
217 | out_no_wait: | |
218 | err = -EIO; | |
219 | if (!buffer_uptodate(first_bh)) | |
220 | goto failed_bh; | |
221 | out: | |
222 | *out_bh = first_bh; | |
223 | return 0; | |
224 | ||
225 | failed_bh: | |
226 | brelse(first_bh); | |
227 | failed: | |
228 | return err; | |
229 | } | |
230 | ||
231 | /** | |
232 | * nilfs_mdt_get_block - read or create a buffer on meta data file. | |
233 | * @inode: inode of the meta data file | |
234 | * @blkoff: block offset | |
235 | * @create: create flag | |
236 | * @init_block: initializer used for newly allocated block | |
237 | * @out_bh: output of a pointer to the buffer_head | |
238 | * | |
239 | * nilfs_mdt_get_block() looks up the specified buffer and tries to create | |
240 | * a new buffer if @create is not zero. On success, the returned buffer is | |
241 | * assured to be either existing or formatted using a buffer lock on success. | |
242 | * @out_bh is substituted only when zero is returned. | |
243 | * | |
244 | * Return Value: On success, it returns 0. On error, the following negative | |
245 | * error code is returned. | |
246 | * | |
247 | * %-ENOMEM - Insufficient memory available. | |
248 | * | |
249 | * %-EIO - I/O error | |
250 | * | |
251 | * %-ENOENT - the specified block does not exist (hole block) | |
252 | * | |
253 | * %-EINVAL - bmap is broken. (the caller should call nilfs_error()) | |
254 | * | |
255 | * %-EROFS - Read only filesystem (for create mode) | |
256 | */ | |
257 | int nilfs_mdt_get_block(struct inode *inode, unsigned long blkoff, int create, | |
258 | void (*init_block)(struct inode *, | |
259 | struct buffer_head *, void *), | |
260 | struct buffer_head **out_bh) | |
261 | { | |
262 | int ret; | |
263 | ||
264 | /* Should be rewritten with merging nilfs_mdt_read_block() */ | |
265 | retry: | |
266 | ret = nilfs_mdt_read_block(inode, blkoff, out_bh); | |
267 | if (!create || ret != -ENOENT) | |
268 | return ret; | |
269 | ||
270 | ret = nilfs_mdt_create_block(inode, blkoff, out_bh, init_block); | |
271 | if (unlikely(ret == -EEXIST)) { | |
272 | /* create = 0; */ /* limit read-create loop retries */ | |
273 | goto retry; | |
274 | } | |
275 | return ret; | |
276 | } | |
277 | ||
278 | /** | |
279 | * nilfs_mdt_delete_block - make a hole on the meta data file. | |
280 | * @inode: inode of the meta data file | |
281 | * @block: block offset | |
282 | * | |
283 | * Return Value: On success, zero is returned. | |
284 | * On error, one of the following negative error code is returned. | |
285 | * | |
286 | * %-ENOMEM - Insufficient memory available. | |
287 | * | |
288 | * %-EIO - I/O error | |
289 | * | |
290 | * %-EINVAL - bmap is broken. (the caller should call nilfs_error()) | |
291 | */ | |
292 | int nilfs_mdt_delete_block(struct inode *inode, unsigned long block) | |
293 | { | |
294 | struct nilfs_inode_info *ii = NILFS_I(inode); | |
295 | int err; | |
296 | ||
297 | err = nilfs_bmap_delete(ii->i_bmap, block); | |
84338237 | 298 | if (!err || err == -ENOENT) { |
5eb563f5 RK |
299 | nilfs_mdt_mark_dirty(inode); |
300 | nilfs_mdt_forget_block(inode, block); | |
301 | } | |
302 | return err; | |
303 | } | |
304 | ||
305 | /** | |
306 | * nilfs_mdt_forget_block - discard dirty state and try to remove the page | |
307 | * @inode: inode of the meta data file | |
308 | * @block: block offset | |
309 | * | |
310 | * nilfs_mdt_forget_block() clears a dirty flag of the specified buffer, and | |
311 | * tries to release the page including the buffer from a page cache. | |
312 | * | |
313 | * Return Value: On success, 0 is returned. On error, one of the following | |
314 | * negative error code is returned. | |
315 | * | |
316 | * %-EBUSY - page has an active buffer. | |
317 | * | |
318 | * %-ENOENT - page cache has no page addressed by the offset. | |
319 | */ | |
320 | int nilfs_mdt_forget_block(struct inode *inode, unsigned long block) | |
321 | { | |
322 | pgoff_t index = (pgoff_t)block >> | |
323 | (PAGE_CACHE_SHIFT - inode->i_blkbits); | |
324 | struct page *page; | |
325 | unsigned long first_block; | |
326 | int ret = 0; | |
327 | int still_dirty; | |
328 | ||
329 | page = find_lock_page(inode->i_mapping, index); | |
330 | if (!page) | |
331 | return -ENOENT; | |
332 | ||
333 | wait_on_page_writeback(page); | |
334 | ||
335 | first_block = (unsigned long)index << | |
336 | (PAGE_CACHE_SHIFT - inode->i_blkbits); | |
337 | if (page_has_buffers(page)) { | |
338 | struct buffer_head *bh; | |
339 | ||
340 | bh = nilfs_page_get_nth_block(page, block - first_block); | |
341 | nilfs_forget_buffer(bh); | |
342 | } | |
343 | still_dirty = PageDirty(page); | |
344 | unlock_page(page); | |
345 | page_cache_release(page); | |
346 | ||
347 | if (still_dirty || | |
348 | invalidate_inode_pages2_range(inode->i_mapping, index, index) != 0) | |
349 | ret = -EBUSY; | |
350 | return ret; | |
351 | } | |
352 | ||
353 | /** | |
354 | * nilfs_mdt_mark_block_dirty - mark a block on the meta data file dirty. | |
355 | * @inode: inode of the meta data file | |
356 | * @block: block offset | |
357 | * | |
358 | * Return Value: On success, it returns 0. On error, the following negative | |
359 | * error code is returned. | |
360 | * | |
361 | * %-ENOMEM - Insufficient memory available. | |
362 | * | |
363 | * %-EIO - I/O error | |
364 | * | |
365 | * %-ENOENT - the specified block does not exist (hole block) | |
366 | * | |
367 | * %-EINVAL - bmap is broken. (the caller should call nilfs_error()) | |
368 | */ | |
369 | int nilfs_mdt_mark_block_dirty(struct inode *inode, unsigned long block) | |
370 | { | |
371 | struct buffer_head *bh; | |
372 | int err; | |
373 | ||
374 | err = nilfs_mdt_read_block(inode, block, &bh); | |
375 | if (unlikely(err)) | |
376 | return err; | |
377 | nilfs_mark_buffer_dirty(bh); | |
378 | nilfs_mdt_mark_dirty(inode); | |
379 | brelse(bh); | |
380 | return 0; | |
381 | } | |
382 | ||
383 | int nilfs_mdt_fetch_dirty(struct inode *inode) | |
384 | { | |
385 | struct nilfs_inode_info *ii = NILFS_I(inode); | |
386 | ||
387 | if (nilfs_bmap_test_and_clear_dirty(ii->i_bmap)) { | |
388 | set_bit(NILFS_I_DIRTY, &ii->i_state); | |
389 | return 1; | |
390 | } | |
391 | return test_bit(NILFS_I_DIRTY, &ii->i_state); | |
392 | } | |
393 | ||
394 | static int | |
395 | nilfs_mdt_write_page(struct page *page, struct writeback_control *wbc) | |
396 | { | |
397 | struct inode *inode = container_of(page->mapping, | |
398 | struct inode, i_data); | |
399 | struct super_block *sb = inode->i_sb; | |
027d6404 | 400 | struct the_nilfs *nilfs = NILFS_MDT(inode)->mi_nilfs; |
5eb563f5 RK |
401 | struct nilfs_sb_info *writer = NULL; |
402 | int err = 0; | |
403 | ||
404 | redirty_page_for_writepage(wbc, page); | |
405 | unlock_page(page); | |
406 | ||
407 | if (page->mapping->assoc_mapping) | |
408 | return 0; /* Do not request flush for shadow page cache */ | |
409 | if (!sb) { | |
027d6404 RK |
410 | down_read(&nilfs->ns_writer_sem); |
411 | writer = nilfs->ns_writer; | |
01a261e0 | 412 | if (!writer) { |
027d6404 | 413 | up_read(&nilfs->ns_writer_sem); |
5eb563f5 | 414 | return -EROFS; |
01a261e0 | 415 | } |
5eb563f5 RK |
416 | sb = writer->s_super; |
417 | } | |
418 | ||
419 | if (wbc->sync_mode == WB_SYNC_ALL) | |
420 | err = nilfs_construct_segment(sb); | |
421 | else if (wbc->for_reclaim) | |
422 | nilfs_flush_segment(sb, inode->i_ino); | |
423 | ||
424 | if (writer) | |
027d6404 | 425 | up_read(&nilfs->ns_writer_sem); |
5eb563f5 RK |
426 | return err; |
427 | } | |
428 | ||
429 | ||
7f09410b | 430 | static const struct address_space_operations def_mdt_aops = { |
5eb563f5 | 431 | .writepage = nilfs_mdt_write_page, |
fa032744 | 432 | .sync_page = block_sync_page, |
5eb563f5 RK |
433 | }; |
434 | ||
6e1d5dcc | 435 | static const struct inode_operations def_mdt_iops; |
828c0950 | 436 | static const struct file_operations def_mdt_fops; |
5eb563f5 RK |
437 | |
438 | /* | |
439 | * NILFS2 uses pseudo inodes for meta data files such as DAT, cpfile, sufile, | |
440 | * ifile, or gcinodes. This allows the B-tree code and segment constructor | |
441 | * to treat them like regular files, and this helps to simplify the | |
442 | * implementation. | |
443 | * On the other hand, some of the pseudo inodes have an irregular point: | |
444 | * They don't have valid inode->i_sb pointer because their lifetimes are | |
445 | * longer than those of the super block structs; they may continue for | |
446 | * several consecutive mounts/umounts. This would need discussions. | |
447 | */ | |
5731e191 RK |
448 | /** |
449 | * nilfs_mdt_new_common - allocate a pseudo inode for metadata file | |
450 | * @nilfs: nilfs object | |
451 | * @sb: super block instance the metadata file belongs to | |
452 | * @ino: inode number | |
453 | * @gfp_mask: gfp mask for data pages | |
454 | * @objsz: size of the private object attached to inode->i_private | |
455 | */ | |
5eb563f5 RK |
456 | struct inode * |
457 | nilfs_mdt_new_common(struct the_nilfs *nilfs, struct super_block *sb, | |
5731e191 | 458 | ino_t ino, gfp_t gfp_mask, size_t objsz) |
5eb563f5 | 459 | { |
a53b4751 | 460 | struct inode *inode = nilfs_alloc_inode_common(nilfs); |
5eb563f5 RK |
461 | |
462 | if (!inode) | |
463 | return NULL; | |
464 | else { | |
465 | struct address_space * const mapping = &inode->i_data; | |
5731e191 | 466 | struct nilfs_mdt_info *mi; |
5eb563f5 | 467 | |
5731e191 | 468 | mi = kzalloc(max(sizeof(*mi), objsz), GFP_NOFS); |
5eb563f5 RK |
469 | if (!mi) { |
470 | nilfs_destroy_inode(inode); | |
471 | return NULL; | |
472 | } | |
473 | mi->mi_nilfs = nilfs; | |
474 | init_rwsem(&mi->mi_sem); | |
475 | ||
476 | inode->i_sb = sb; /* sb may be NULL for some meta data files */ | |
477 | inode->i_blkbits = nilfs->ns_blocksize_bits; | |
478 | inode->i_flags = 0; | |
479 | atomic_set(&inode->i_count, 1); | |
480 | inode->i_nlink = 1; | |
481 | inode->i_ino = ino; | |
482 | inode->i_mode = S_IFREG; | |
483 | inode->i_private = mi; | |
484 | ||
485 | #ifdef INIT_UNUSED_INODE_FIELDS | |
486 | atomic_set(&inode->i_writecount, 0); | |
487 | inode->i_size = 0; | |
488 | inode->i_blocks = 0; | |
489 | inode->i_bytes = 0; | |
490 | inode->i_generation = 0; | |
491 | #ifdef CONFIG_QUOTA | |
492 | memset(&inode->i_dquot, 0, sizeof(inode->i_dquot)); | |
493 | #endif | |
494 | inode->i_pipe = NULL; | |
495 | inode->i_bdev = NULL; | |
496 | inode->i_cdev = NULL; | |
497 | inode->i_rdev = 0; | |
498 | #ifdef CONFIG_SECURITY | |
499 | inode->i_security = NULL; | |
500 | #endif | |
501 | inode->dirtied_when = 0; | |
502 | ||
503 | INIT_LIST_HEAD(&inode->i_list); | |
504 | INIT_LIST_HEAD(&inode->i_sb_list); | |
505 | inode->i_state = 0; | |
506 | #endif | |
507 | ||
508 | spin_lock_init(&inode->i_lock); | |
509 | mutex_init(&inode->i_mutex); | |
510 | init_rwsem(&inode->i_alloc_sem); | |
511 | ||
512 | mapping->host = NULL; /* instead of inode */ | |
513 | mapping->flags = 0; | |
514 | mapping_set_gfp_mask(mapping, gfp_mask); | |
515 | mapping->assoc_mapping = NULL; | |
516 | mapping->backing_dev_info = nilfs->ns_bdi; | |
517 | ||
518 | inode->i_mapping = mapping; | |
519 | } | |
520 | ||
521 | return inode; | |
522 | } | |
523 | ||
524 | struct inode *nilfs_mdt_new(struct the_nilfs *nilfs, struct super_block *sb, | |
5731e191 | 525 | ino_t ino, size_t objsz) |
5eb563f5 | 526 | { |
5731e191 | 527 | struct inode *inode; |
5eb563f5 | 528 | |
5731e191 | 529 | inode = nilfs_mdt_new_common(nilfs, sb, ino, NILFS_MDT_GFP, objsz); |
5eb563f5 RK |
530 | if (!inode) |
531 | return NULL; | |
532 | ||
533 | inode->i_op = &def_mdt_iops; | |
534 | inode->i_fop = &def_mdt_fops; | |
535 | inode->i_mapping->a_ops = &def_mdt_aops; | |
536 | return inode; | |
537 | } | |
538 | ||
539 | void nilfs_mdt_set_entry_size(struct inode *inode, unsigned entry_size, | |
540 | unsigned header_size) | |
541 | { | |
542 | struct nilfs_mdt_info *mi = NILFS_MDT(inode); | |
543 | ||
544 | mi->mi_entry_size = entry_size; | |
545 | mi->mi_entries_per_block = (1 << inode->i_blkbits) / entry_size; | |
546 | mi->mi_first_entry_offset = DIV_ROUND_UP(header_size, entry_size); | |
547 | } | |
548 | ||
549 | void nilfs_mdt_set_shadow(struct inode *orig, struct inode *shadow) | |
550 | { | |
551 | shadow->i_mapping->assoc_mapping = orig->i_mapping; | |
552 | NILFS_I(shadow)->i_btnode_cache.assoc_mapping = | |
553 | &NILFS_I(orig)->i_btnode_cache; | |
554 | } | |
555 | ||
fd66c0d5 | 556 | static void nilfs_mdt_clear(struct inode *inode) |
5eb563f5 RK |
557 | { |
558 | struct nilfs_inode_info *ii = NILFS_I(inode); | |
559 | ||
560 | invalidate_mapping_pages(inode->i_mapping, 0, -1); | |
561 | truncate_inode_pages(inode->i_mapping, 0); | |
562 | ||
fd66c0d5 RK |
563 | if (test_bit(NILFS_I_BMAP, &ii->i_state)) |
564 | nilfs_bmap_clear(ii->i_bmap); | |
5eb563f5 RK |
565 | nilfs_btnode_cache_clear(&ii->i_btnode_cache); |
566 | } | |
567 | ||
568 | void nilfs_mdt_destroy(struct inode *inode) | |
569 | { | |
570 | struct nilfs_mdt_info *mdi = NILFS_MDT(inode); | |
571 | ||
fd66c0d5 RK |
572 | nilfs_mdt_clear(inode); |
573 | ||
5eb563f5 RK |
574 | kfree(mdi->mi_bgl); /* kfree(NULL) is safe */ |
575 | kfree(mdi); | |
576 | nilfs_destroy_inode(inode); | |
577 | } |