Commit 2d7b822a authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

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: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
parent cf0ee0f0
...@@ -308,16 +308,15 @@ void release_orphan_inode(struct f2fs_sb_info *sbi) ...@@ -308,16 +308,15 @@ void release_orphan_inode(struct f2fs_sb_info *sbi)
void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
{ {
struct list_head *head, *this; struct list_head *head;
struct orphan_inode_entry *new = NULL, *orphan = NULL; struct orphan_inode_entry *new, *orphan;
new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC); new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC);
new->ino = ino; new->ino = ino;
spin_lock(&sbi->orphan_inode_lock); spin_lock(&sbi->orphan_inode_lock);
head = &sbi->orphan_inode_list; head = &sbi->orphan_inode_list;
list_for_each(this, head) { list_for_each_entry(orphan, head, list) {
orphan = list_entry(this, struct orphan_inode_entry, list);
if (orphan->ino == ino) { if (orphan->ino == ino) {
spin_unlock(&sbi->orphan_inode_lock); spin_unlock(&sbi->orphan_inode_lock);
kmem_cache_free(orphan_entry_slab, new); kmem_cache_free(orphan_entry_slab, new);
...@@ -326,14 +325,10 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) ...@@ -326,14 +325,10 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
if (orphan->ino > ino) if (orphan->ino > ino)
break; break;
orphan = NULL;
} }
/* add new_oentry into list which is sorted by inode number */ /* add new orphan entry into list which is sorted by inode number */
if (orphan) list_add_tail(&new->list, &orphan->list);
list_add(&new->list, this->prev);
else
list_add_tail(&new->list, head);
spin_unlock(&sbi->orphan_inode_lock); spin_unlock(&sbi->orphan_inode_lock);
} }
...@@ -561,14 +556,12 @@ static int __add_dirty_inode(struct inode *inode, struct dir_inode_entry *new) ...@@ -561,14 +556,12 @@ static int __add_dirty_inode(struct inode *inode, struct dir_inode_entry *new)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct list_head *head = &sbi->dir_inode_list; struct list_head *head = &sbi->dir_inode_list;
struct list_head *this; struct dir_inode_entry *entry;
list_for_each(this, head) { list_for_each_entry(entry, head, list)
struct dir_inode_entry *entry;
entry = list_entry(this, struct dir_inode_entry, list);
if (unlikely(entry->inode == inode)) if (unlikely(entry->inode == inode))
return -EEXIST; return -EEXIST;
}
list_add_tail(&new->list, head); list_add_tail(&new->list, head);
stat_inc_dirty_dir(sbi); stat_inc_dirty_dir(sbi);
return 0; return 0;
...@@ -618,7 +611,8 @@ void add_dirty_dir_inode(struct inode *inode) ...@@ -618,7 +611,8 @@ void add_dirty_dir_inode(struct inode *inode)
void remove_dirty_dir_inode(struct inode *inode) void remove_dirty_dir_inode(struct inode *inode)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct list_head *this, *head; struct list_head *head;
struct dir_inode_entry *entry;
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
return; return;
...@@ -630,9 +624,7 @@ void remove_dirty_dir_inode(struct inode *inode) ...@@ -630,9 +624,7 @@ void remove_dirty_dir_inode(struct inode *inode)
} }
head = &sbi->dir_inode_list; head = &sbi->dir_inode_list;
list_for_each(this, head) { list_for_each_entry(entry, head, list) {
struct dir_inode_entry *entry;
entry = list_entry(this, struct dir_inode_entry, list);
if (entry->inode == inode) { if (entry->inode == inode) {
list_del(&entry->list); list_del(&entry->list);
stat_dec_dirty_dir(sbi); stat_dec_dirty_dir(sbi);
...@@ -654,15 +646,14 @@ void remove_dirty_dir_inode(struct inode *inode) ...@@ -654,15 +646,14 @@ void remove_dirty_dir_inode(struct inode *inode)
struct inode *check_dirty_dir_inode(struct f2fs_sb_info *sbi, nid_t ino) struct inode *check_dirty_dir_inode(struct f2fs_sb_info *sbi, nid_t ino)
{ {
struct list_head *this, *head; struct list_head *head;
struct inode *inode = NULL; struct inode *inode = NULL;
struct dir_inode_entry *entry;
spin_lock(&sbi->dir_inode_lock); spin_lock(&sbi->dir_inode_lock);
head = &sbi->dir_inode_list; head = &sbi->dir_inode_list;
list_for_each(this, head) { list_for_each_entry(entry, head, list) {
struct dir_inode_entry *entry;
entry = list_entry(this, struct dir_inode_entry, list);
if (entry->inode->i_ino == ino) { if (entry->inode->i_ino == ino) {
inode = entry->inode; inode = entry->inode;
break; break;
......
...@@ -1451,7 +1451,6 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid) ...@@ -1451,7 +1451,6 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
{ {
struct f2fs_nm_info *nm_i = NM_I(sbi); struct f2fs_nm_info *nm_i = NM_I(sbi);
struct free_nid *i = NULL; struct free_nid *i = NULL;
struct list_head *this;
retry: retry:
if (unlikely(sbi->total_valid_node_count + 1 >= nm_i->max_nid)) if (unlikely(sbi->total_valid_node_count + 1 >= nm_i->max_nid))
return false; return false;
...@@ -1461,11 +1460,9 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid) ...@@ -1461,11 +1460,9 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
/* We should not use stale free nids created by build_free_nids */ /* We should not use stale free nids created by build_free_nids */
if (nm_i->fcnt && !on_build_free_nids(nm_i)) { if (nm_i->fcnt && !on_build_free_nids(nm_i)) {
f2fs_bug_on(list_empty(&nm_i->free_nid_list)); f2fs_bug_on(list_empty(&nm_i->free_nid_list));
list_for_each(this, &nm_i->free_nid_list) { list_for_each_entry(i, &nm_i->free_nid_list, list)
i = list_entry(this, struct free_nid, list);
if (i->state == NID_NEW) if (i->state == NID_NEW)
break; break;
}
f2fs_bug_on(i->state != NID_NEW); f2fs_bug_on(i->state != NID_NEW);
*nid = i->nid; *nid = i->nid;
...@@ -1780,7 +1777,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi) ...@@ -1780,7 +1777,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
struct f2fs_nm_info *nm_i = NM_I(sbi); struct f2fs_nm_info *nm_i = NM_I(sbi);
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
struct f2fs_summary_block *sum = curseg->sum_blk; struct f2fs_summary_block *sum = curseg->sum_blk;
struct list_head *cur, *n; struct nat_entry *ne, *cur;
struct page *page = NULL; struct page *page = NULL;
struct f2fs_nat_block *nat_blk = NULL; struct f2fs_nat_block *nat_blk = NULL;
nid_t start_nid = 0, end_nid = 0; nid_t start_nid = 0, end_nid = 0;
...@@ -1792,18 +1789,17 @@ void flush_nat_entries(struct f2fs_sb_info *sbi) ...@@ -1792,18 +1789,17 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
mutex_lock(&curseg->curseg_mutex); mutex_lock(&curseg->curseg_mutex);
/* 1) flush dirty nat caches */ /* 1) flush dirty nat caches */
list_for_each_safe(cur, n, &nm_i->dirty_nat_entries) { list_for_each_entry_safe(ne, cur, &nm_i->dirty_nat_entries, list) {
struct nat_entry *ne;
nid_t nid; nid_t nid;
struct f2fs_nat_entry raw_ne; struct f2fs_nat_entry raw_ne;
int offset = -1; int offset = -1;
block_t new_blkaddr; block_t new_blkaddr;
ne = list_entry(cur, struct nat_entry, list);
nid = nat_get_nid(ne);
if (nat_get_blkaddr(ne) == NEW_ADDR) if (nat_get_blkaddr(ne) == NEW_ADDR)
continue; continue;
nid = nat_get_nid(ne);
if (flushed) if (flushed)
goto to_nat_page; goto to_nat_page;
......
...@@ -27,14 +27,12 @@ bool space_for_roll_forward(struct f2fs_sb_info *sbi) ...@@ -27,14 +27,12 @@ bool space_for_roll_forward(struct f2fs_sb_info *sbi)
static struct fsync_inode_entry *get_fsync_inode(struct list_head *head, static struct fsync_inode_entry *get_fsync_inode(struct list_head *head,
nid_t ino) nid_t ino)
{ {
struct list_head *this;
struct fsync_inode_entry *entry; struct fsync_inode_entry *entry;
list_for_each(this, head) { list_for_each_entry(entry, head, list)
entry = list_entry(this, struct fsync_inode_entry, list);
if (entry->inode->i_ino == ino) if (entry->inode->i_ino == ino)
return entry; return entry;
}
return NULL; return NULL;
} }
......
...@@ -340,8 +340,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi) ...@@ -340,8 +340,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)
void clear_prefree_segments(struct f2fs_sb_info *sbi) void clear_prefree_segments(struct f2fs_sb_info *sbi)
{ {
struct list_head *head = &(SM_I(sbi)->discard_list); struct list_head *head = &(SM_I(sbi)->discard_list);
struct list_head *this, *next; struct discard_entry *entry, *this;
struct discard_entry *entry;
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
unsigned long *prefree_map = dirty_i->dirty_segmap[PRE]; unsigned long *prefree_map = dirty_i->dirty_segmap[PRE];
unsigned int total_segs = TOTAL_SEGS(sbi); unsigned int total_segs = TOTAL_SEGS(sbi);
...@@ -370,8 +369,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi) ...@@ -370,8 +369,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi)
mutex_unlock(&dirty_i->seglist_lock); mutex_unlock(&dirty_i->seglist_lock);
/* send small discards */ /* send small discards */
list_for_each_safe(this, next, head) { list_for_each_entry_safe(entry, this, head, list) {
entry = list_entry(this, struct discard_entry, list);
f2fs_issue_discard(sbi, entry->blkaddr, entry->len); f2fs_issue_discard(sbi, entry->blkaddr, entry->len);
list_del(&entry->list); list_del(&entry->list);
SM_I(sbi)->nr_discards -= entry->len; SM_I(sbi)->nr_discards -= entry->len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment