diff options
-rw-r--r-- | fs/f2fs/data.c | 29 | ||||
-rw-r--r-- | fs/f2fs/dir.c | 7 | ||||
-rw-r--r-- | fs/f2fs/inline.c | 6 |
3 files changed, 26 insertions, 16 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index fc7a28c5ad23..63d190264a36 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -258,13 +258,16 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index) bool need_put = dn->inode_page ? false : true; int err; + /* if inode_page exists, index should be zero */ + f2fs_bug_on(!need_put && index); + err = get_dnode_of_data(dn, index, ALLOC_NODE); if (err) return err; + if (dn->data_blkaddr == NULL_ADDR) err = reserve_new_block(dn); - - if (need_put) + if (err || need_put) f2fs_put_dnode(dn); return err; } @@ -510,10 +513,10 @@ repeat: * * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and * f2fs_unlock_op(). - * Note that, npage is set only by make_empty_dir. + * Note that, ipage is set only by make_empty_dir. */ struct page *get_new_data_page(struct inode *inode, - struct page *npage, pgoff_t index, bool new_i_size) + struct page *ipage, pgoff_t index, bool new_i_size) { struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct address_space *mapping = inode->i_mapping; @@ -521,14 +524,16 @@ struct page *get_new_data_page(struct inode *inode, struct dnode_of_data dn; int err; - set_new_dnode(&dn, inode, npage, npage, 0); + set_new_dnode(&dn, inode, ipage, NULL, 0); err = f2fs_reserve_block(&dn, index); if (err) return ERR_PTR(err); repeat: page = grab_cache_page(mapping, index); - if (!page) - return ERR_PTR(-ENOMEM); + if (!page) { + err = -ENOMEM; + goto put_err; + } if (PageUptodate(page)) return page; @@ -540,11 +545,13 @@ repeat: err = f2fs_submit_page_bio(sbi, page, dn.data_blkaddr, READ_SYNC); if (err) - return ERR_PTR(err); + goto put_err; + lock_page(page); if (unlikely(!PageUptodate(page))) { f2fs_put_page(page, 1); - return ERR_PTR(-EIO); + err = -EIO; + goto put_err; } if (unlikely(page->mapping != mapping)) { f2fs_put_page(page, 1); @@ -560,6 +567,10 @@ repeat: mark_inode_dirty_sync(inode); } return page; + +put_err: + f2fs_put_dnode(&dn); + return ERR_PTR(err); } static int __allocate_data_block(struct dnode_of_data *dn) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 6da77e5c753b..f815ca0c5819 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -342,11 +342,11 @@ static struct page *init_inode_metadata(struct inode *inode, err = f2fs_init_acl(inode, dir, page); if (err) - goto error; + goto put_error; err = f2fs_init_security(inode, dir, name, page); if (err) - goto error; + goto put_error; wait_on_page_writeback(page); } else { @@ -370,8 +370,9 @@ static struct page *init_inode_metadata(struct inode *inode, } return page; -error: +put_error: f2fs_put_page(page, 1); +error: remove_inode_page(inode); return ERR_PTR(err); } diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 2a756e57aed9..688305afbc74 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -81,10 +81,9 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page) * i_addr[0] is not used for inline data, * so reserving new block will not destroy inline data */ - set_new_dnode(&dn, inode, ipage, ipage, 0); + set_new_dnode(&dn, inode, ipage, NULL, 0); err = f2fs_reserve_block(&dn, 0); if (err) { - f2fs_put_page(ipage, 1); f2fs_unlock_op(sbi); return err; } @@ -111,9 +110,8 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page) stat_dec_inline_inode(inode); sync_inode_page(&dn); - f2fs_put_page(ipage, 1); + f2fs_put_dnode(&dn); f2fs_unlock_op(sbi); - return err; } |