aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <chao2.yu@samsung.com>2014-03-28 23:33:17 -0400
committerJaegeuk Kim <jaegeuk.kim@samsung.com>2014-04-01 20:56:27 -0400
commit2d7b822ad9daf0ea903accacaa89340ddd3f201f (patch)
treebd39738c9bdb003fdea4e897836595b2c8b1593b
parentcf0ee0f09bc09f54b9852dda1088b9cdcd4f8683 (diff)
f2fs: use list_for_each_entry{_safe} for simplyfying code
This patch use list_for_each_entry{_safe} instead of list_for_each{_safe} for simplfying code. Signed-off-by: Chao Yu <chao2.yu@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
-rw-r--r--fs/f2fs/checkpoint.c37
-rw-r--r--fs/f2fs/node.c16
-rw-r--r--fs/f2fs/recovery.c6
-rw-r--r--fs/f2fs/segment.c6
4 files changed, 24 insertions, 41 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index d877f46c75ed..4aa521aa9bc3 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -308,16 +308,15 @@ void release_orphan_inode(struct f2fs_sb_info *sbi)
308 308
309void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) 309void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
310{ 310{
311 struct list_head *head, *this; 311 struct list_head *head;
312 struct orphan_inode_entry *new = NULL, *orphan = NULL; 312 struct orphan_inode_entry *new, *orphan;
313 313
314 new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC); 314 new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC);
315 new->ino = ino; 315 new->ino = ino;
316 316
317 spin_lock(&sbi->orphan_inode_lock); 317 spin_lock(&sbi->orphan_inode_lock);
318 head = &sbi->orphan_inode_list; 318 head = &sbi->orphan_inode_list;
319 list_for_each(this, head) { 319 list_for_each_entry(orphan, head, list) {
320 orphan = list_entry(this, struct orphan_inode_entry, list);
321 if (orphan->ino == ino) { 320 if (orphan->ino == ino) {
322 spin_unlock(&sbi->orphan_inode_lock); 321 spin_unlock(&sbi->orphan_inode_lock);
323 kmem_cache_free(orphan_entry_slab, new); 322 kmem_cache_free(orphan_entry_slab, new);
@@ -326,14 +325,10 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
326 325
327 if (orphan->ino > ino) 326 if (orphan->ino > ino)
328 break; 327 break;
329 orphan = NULL;
330 } 328 }
331 329
332 /* add new_oentry into list which is sorted by inode number */ 330 /* add new orphan entry into list which is sorted by inode number */
333 if (orphan) 331 list_add_tail(&new->list, &orphan->list);
334 list_add(&new->list, this->prev);
335 else
336 list_add_tail(&new->list, head);
337 spin_unlock(&sbi->orphan_inode_lock); 332 spin_unlock(&sbi->orphan_inode_lock);
338} 333}
339 334
@@ -561,14 +556,12 @@ static int __add_dirty_inode(struct inode *inode, struct dir_inode_entry *new)
561{ 556{
562 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 557 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
563 struct list_head *head = &sbi->dir_inode_list; 558 struct list_head *head = &sbi->dir_inode_list;
564 struct list_head *this; 559 struct dir_inode_entry *entry;
565 560
566 list_for_each(this, head) { 561 list_for_each_entry(entry, head, list)
567 struct dir_inode_entry *entry;
568 entry = list_entry(this, struct dir_inode_entry, list);
569 if (unlikely(entry->inode == inode)) 562 if (unlikely(entry->inode == inode))
570 return -EEXIST; 563 return -EEXIST;
571 } 564
572 list_add_tail(&new->list, head); 565 list_add_tail(&new->list, head);
573 stat_inc_dirty_dir(sbi); 566 stat_inc_dirty_dir(sbi);
574 return 0; 567 return 0;
@@ -618,7 +611,8 @@ void add_dirty_dir_inode(struct inode *inode)
618void remove_dirty_dir_inode(struct inode *inode) 611void remove_dirty_dir_inode(struct inode *inode)
619{ 612{
620 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 613 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
621 struct list_head *this, *head; 614 struct list_head *head;
615 struct dir_inode_entry *entry;
622 616
623 if (!S_ISDIR(inode->i_mode)) 617 if (!S_ISDIR(inode->i_mode))
624 return; 618 return;
@@ -630,9 +624,7 @@ void remove_dirty_dir_inode(struct inode *inode)
630 } 624 }
631 625
632 head = &sbi->dir_inode_list; 626 head = &sbi->dir_inode_list;
633 list_for_each(this, head) { 627 list_for_each_entry(entry, head, list) {
634 struct dir_inode_entry *entry;
635 entry = list_entry(this, struct dir_inode_entry, list);
636 if (entry->inode == inode) { 628 if (entry->inode == inode) {
637 list_del(&entry->list); 629 list_del(&entry->list);
638 stat_dec_dirty_dir(sbi); 630 stat_dec_dirty_dir(sbi);
@@ -654,15 +646,14 @@ done:
654struct inode *check_dirty_dir_inode(struct f2fs_sb_info *sbi, nid_t ino) 646struct inode *check_dirty_dir_inode(struct f2fs_sb_info *sbi, nid_t ino)
655{ 647{
656 648
657 struct list_head *this, *head; 649 struct list_head *head;
658 struct inode *inode = NULL; 650 struct inode *inode = NULL;
651 struct dir_inode_entry *entry;
659 652
660 spin_lock(&sbi->dir_inode_lock); 653 spin_lock(&sbi->dir_inode_lock);
661 654
662 head = &sbi->dir_inode_list; 655 head = &sbi->dir_inode_list;
663 list_for_each(this, head) { 656 list_for_each_entry(entry, head, list) {
664 struct dir_inode_entry *entry;
665 entry = list_entry(this, struct dir_inode_entry, list);
666 if (entry->inode->i_ino == ino) { 657 if (entry->inode->i_ino == ino) {
667 inode = entry->inode; 658 inode = entry->inode;
668 break; 659 break;
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 4b27e36e40fc..a161e955c4c8 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1451,7 +1451,6 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
1451{ 1451{
1452 struct f2fs_nm_info *nm_i = NM_I(sbi); 1452 struct f2fs_nm_info *nm_i = NM_I(sbi);
1453 struct free_nid *i = NULL; 1453 struct free_nid *i = NULL;
1454 struct list_head *this;
1455retry: 1454retry:
1456 if (unlikely(sbi->total_valid_node_count + 1 >= nm_i->max_nid)) 1455 if (unlikely(sbi->total_valid_node_count + 1 >= nm_i->max_nid))
1457 return false; 1456 return false;
@@ -1461,11 +1460,9 @@ retry:
1461 /* We should not use stale free nids created by build_free_nids */ 1460 /* We should not use stale free nids created by build_free_nids */
1462 if (nm_i->fcnt && !on_build_free_nids(nm_i)) { 1461 if (nm_i->fcnt && !on_build_free_nids(nm_i)) {
1463 f2fs_bug_on(list_empty(&nm_i->free_nid_list)); 1462 f2fs_bug_on(list_empty(&nm_i->free_nid_list));
1464 list_for_each(this, &nm_i->free_nid_list) { 1463 list_for_each_entry(i, &nm_i->free_nid_list, list)
1465 i = list_entry(this, struct free_nid, list);
1466 if (i->state == NID_NEW) 1464 if (i->state == NID_NEW)
1467 break; 1465 break;
1468 }
1469 1466
1470 f2fs_bug_on(i->state != NID_NEW); 1467 f2fs_bug_on(i->state != NID_NEW);
1471 *nid = i->nid; 1468 *nid = i->nid;
@@ -1780,7 +1777,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
1780 struct f2fs_nm_info *nm_i = NM_I(sbi); 1777 struct f2fs_nm_info *nm_i = NM_I(sbi);
1781 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); 1778 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
1782 struct f2fs_summary_block *sum = curseg->sum_blk; 1779 struct f2fs_summary_block *sum = curseg->sum_blk;
1783 struct list_head *cur, *n; 1780 struct nat_entry *ne, *cur;
1784 struct page *page = NULL; 1781 struct page *page = NULL;
1785 struct f2fs_nat_block *nat_blk = NULL; 1782 struct f2fs_nat_block *nat_blk = NULL;
1786 nid_t start_nid = 0, end_nid = 0; 1783 nid_t start_nid = 0, end_nid = 0;
@@ -1792,18 +1789,17 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
1792 mutex_lock(&curseg->curseg_mutex); 1789 mutex_lock(&curseg->curseg_mutex);
1793 1790
1794 /* 1) flush dirty nat caches */ 1791 /* 1) flush dirty nat caches */
1795 list_for_each_safe(cur, n, &nm_i->dirty_nat_entries) { 1792 list_for_each_entry_safe(ne, cur, &nm_i->dirty_nat_entries, list) {
1796 struct nat_entry *ne;
1797 nid_t nid; 1793 nid_t nid;
1798 struct f2fs_nat_entry raw_ne; 1794 struct f2fs_nat_entry raw_ne;
1799 int offset = -1; 1795 int offset = -1;
1800 block_t new_blkaddr; 1796 block_t new_blkaddr;
1801 1797
1802 ne = list_entry(cur, struct nat_entry, list);
1803 nid = nat_get_nid(ne);
1804
1805 if (nat_get_blkaddr(ne) == NEW_ADDR) 1798 if (nat_get_blkaddr(ne) == NEW_ADDR)
1806 continue; 1799 continue;
1800
1801 nid = nat_get_nid(ne);
1802
1807 if (flushed) 1803 if (flushed)
1808 goto to_nat_page; 1804 goto to_nat_page;
1809 1805
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index bbef4ed157a7..b1ae89f0f44e 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -27,14 +27,12 @@ bool space_for_roll_forward(struct f2fs_sb_info *sbi)
27static struct fsync_inode_entry *get_fsync_inode(struct list_head *head, 27static struct fsync_inode_entry *get_fsync_inode(struct list_head *head,
28 nid_t ino) 28 nid_t ino)
29{ 29{
30 struct list_head *this;
31 struct fsync_inode_entry *entry; 30 struct fsync_inode_entry *entry;
32 31
33 list_for_each(this, head) { 32 list_for_each_entry(entry, head, list)
34 entry = list_entry(this, struct fsync_inode_entry, list);
35 if (entry->inode->i_ino == ino) 33 if (entry->inode->i_ino == ino)
36 return entry; 34 return entry;
37 } 35
38 return NULL; 36 return NULL;
39} 37}
40 38
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 570ab9a084c5..cb49e6390ffa 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -340,8 +340,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)
340void clear_prefree_segments(struct f2fs_sb_info *sbi) 340void clear_prefree_segments(struct f2fs_sb_info *sbi)
341{ 341{
342 struct list_head *head = &(SM_I(sbi)->discard_list); 342 struct list_head *head = &(SM_I(sbi)->discard_list);
343 struct list_head *this, *next; 343 struct discard_entry *entry, *this;
344 struct discard_entry *entry;
345 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); 344 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
346 unsigned long *prefree_map = dirty_i->dirty_segmap[PRE]; 345 unsigned long *prefree_map = dirty_i->dirty_segmap[PRE];
347 unsigned int total_segs = TOTAL_SEGS(sbi); 346 unsigned int total_segs = TOTAL_SEGS(sbi);
@@ -370,8 +369,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi)
370 mutex_unlock(&dirty_i->seglist_lock); 369 mutex_unlock(&dirty_i->seglist_lock);
371 370
372 /* send small discards */ 371 /* send small discards */
373 list_for_each_safe(this, next, head) { 372 list_for_each_entry_safe(entry, this, head, list) {
374 entry = list_entry(this, struct discard_entry, list);
375 f2fs_issue_discard(sbi, entry->blkaddr, entry->len); 373 f2fs_issue_discard(sbi, entry->blkaddr, entry->len);
376 list_del(&entry->list); 374 list_del(&entry->list);
377 SM_I(sbi)->nr_discards -= entry->len; 375 SM_I(sbi)->nr_discards -= entry->len;