diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-07-25 18:47:16 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-07-29 10:40:25 -0400 |
commit | 953e6cc6bcb615dfa373320ffa62b574c6be608a (patch) | |
tree | 0518b26673d6ec969713035f97b1ed72cd9bf90a /fs/f2fs | |
parent | 0f7b2abd188089a44f60e2bf8521d1363ada9e12 (diff) |
f2fs: punch the core function for inode management
This patch punches out the core functions to manage the inode numbers.
Reviewed-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/checkpoint.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 0b4710c1d370..1c6eb6bcfd99 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c | |||
@@ -282,6 +282,47 @@ const struct address_space_operations f2fs_meta_aops = { | |||
282 | .set_page_dirty = f2fs_set_meta_page_dirty, | 282 | .set_page_dirty = f2fs_set_meta_page_dirty, |
283 | }; | 283 | }; |
284 | 284 | ||
285 | static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino) | ||
286 | { | ||
287 | struct list_head *head; | ||
288 | struct orphan_inode_entry *new, *e; | ||
289 | |||
290 | new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC); | ||
291 | new->ino = ino; | ||
292 | |||
293 | spin_lock(&sbi->orphan_inode_lock); | ||
294 | list_for_each_entry(e, &sbi->orphan_inode_list, list) { | ||
295 | if (e->ino == ino) { | ||
296 | spin_unlock(&sbi->orphan_inode_lock); | ||
297 | kmem_cache_free(orphan_entry_slab, new); | ||
298 | return; | ||
299 | } | ||
300 | if (e->ino > ino) | ||
301 | break; | ||
302 | } | ||
303 | |||
304 | /* add new entry into list which is sorted by inode number */ | ||
305 | list_add_tail(&new->list, &e->list); | ||
306 | spin_unlock(&sbi->orphan_inode_lock); | ||
307 | } | ||
308 | |||
309 | static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino) | ||
310 | { | ||
311 | struct orphan_inode_entry *e; | ||
312 | |||
313 | spin_lock(&sbi->orphan_inode_lock); | ||
314 | list_for_each_entry(e, &sbi->orphan_inode_list, list) { | ||
315 | if (e->ino == ino) { | ||
316 | list_del(&e->list); | ||
317 | sbi->n_orphans--; | ||
318 | spin_unlock(&sbi->orphan_inode_lock); | ||
319 | kmem_cache_free(orphan_entry_slab, e); | ||
320 | return; | ||
321 | } | ||
322 | } | ||
323 | spin_unlock(&sbi->orphan_inode_lock); | ||
324 | } | ||
325 | |||
285 | int acquire_orphan_inode(struct f2fs_sb_info *sbi) | 326 | int acquire_orphan_inode(struct f2fs_sb_info *sbi) |
286 | { | 327 | { |
287 | int err = 0; | 328 | int err = 0; |
@@ -306,48 +347,14 @@ void release_orphan_inode(struct f2fs_sb_info *sbi) | |||
306 | 347 | ||
307 | void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) | 348 | void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) |
308 | { | 349 | { |
309 | struct list_head *head; | ||
310 | struct orphan_inode_entry *new, *orphan; | ||
311 | |||
312 | new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC); | ||
313 | new->ino = ino; | ||
314 | |||
315 | spin_lock(&sbi->orphan_inode_lock); | ||
316 | head = &sbi->orphan_inode_list; | ||
317 | list_for_each_entry(orphan, head, list) { | ||
318 | if (orphan->ino == ino) { | ||
319 | spin_unlock(&sbi->orphan_inode_lock); | ||
320 | kmem_cache_free(orphan_entry_slab, new); | ||
321 | return; | ||
322 | } | ||
323 | |||
324 | if (orphan->ino > ino) | ||
325 | break; | ||
326 | } | ||
327 | |||
328 | /* add new orphan entry into list which is sorted by inode number */ | 350 | /* add new orphan entry into list which is sorted by inode number */ |
329 | list_add_tail(&new->list, &orphan->list); | 351 | __add_ino_entry(sbi, ino); |
330 | spin_unlock(&sbi->orphan_inode_lock); | ||
331 | } | 352 | } |
332 | 353 | ||
333 | void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) | 354 | void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) |
334 | { | 355 | { |
335 | struct list_head *head; | 356 | /* remove orphan entry from orphan list */ |
336 | struct orphan_inode_entry *orphan; | 357 | __remove_ino_entry(sbi, ino); |
337 | |||
338 | spin_lock(&sbi->orphan_inode_lock); | ||
339 | head = &sbi->orphan_inode_list; | ||
340 | list_for_each_entry(orphan, head, list) { | ||
341 | if (orphan->ino == ino) { | ||
342 | list_del(&orphan->list); | ||
343 | f2fs_bug_on(sbi->n_orphans == 0); | ||
344 | sbi->n_orphans--; | ||
345 | spin_unlock(&sbi->orphan_inode_lock); | ||
346 | kmem_cache_free(orphan_entry_slab, orphan); | ||
347 | return; | ||
348 | } | ||
349 | } | ||
350 | spin_unlock(&sbi->orphan_inode_lock); | ||
351 | } | 358 | } |
352 | 359 | ||
353 | static void recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) | 360 | static void recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) |