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;
}
*
* 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;
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;
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);
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)
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 {
}
return page;
-error:
+put_error:
f2fs_put_page(page, 1);
+error:
remove_inode_page(inode);
return ERR_PTR(err);
}
* 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;
}
stat_dec_inline_inode(inode);
sync_inode_page(&dn);
- f2fs_put_page(ipage, 1);
+ f2fs_put_dnode(&dn);
f2fs_unlock_op(sbi);
-
return err;
}