test_and_set_bit_le(1, dent_blk->dentry_bitmap);
set_summary(&sum, ino, 0, ni.version);
- reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_DATA);
+ ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_DATA);
+ ASSERT(!ret);
ret = dev_write_block(dent_blk, blkaddr);
ASSERT(ret >= 0);
memcpy(data_blk, symname, symlen);
set_summary(&sum, ino, 0, ni.version);
- reserve_new_block(sbi, &blkaddr, &sum, CURSEG_WARM_DATA);
+ ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_WARM_DATA);
+ ASSERT(!ret);
ret = dev_write_block(data_blk, blkaddr);
ASSERT(ret >= 0);
/* write child */
set_summary(&sum, de->ino, 0, ni.version);
- reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_NODE);
+ ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_NODE);
+ ASSERT(!ret);
/* update nat info */
update_nat_blkaddr(sbi, de->ino, de->ino, blkaddr);
int f2fs_sload(struct f2fs_sb_info *);
/* segment.c */
-void reserve_new_block(struct f2fs_sb_info *, block_t *,
+int reserve_new_block(struct f2fs_sb_info *, block_t *,
struct f2fs_summary *, int);
int new_data_block(struct f2fs_sb_info *, void *,
struct dnode_of_data *, int);
struct node_info ni;
block_t blkaddr = NULL_ADDR;
int type;
+ int ret;
f2fs_inode = dn->inode_blk;
get_node_info(sbi, dn->nid, &ni);
set_summary(&sum, dn->nid, 0, ni.version);
- reserve_new_block(sbi, &blkaddr, &sum, type);
+ ret = reserve_new_block(sbi, &blkaddr, &sum, type);
+ if (ret) {
+ free(node_blk);
+ return 0;
+ }
/* update nat info */
update_nat_blkaddr(sbi, le32_to_cpu(f2fs_inode->footer.ino),
ASSERT(dev_write_block(inode, blkaddr) >= 0);
}
-void reserve_new_block(struct f2fs_sb_info *sbi, block_t *to,
+int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to,
struct f2fs_summary *sum, int type)
{
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
u64 blkaddr, offset;
u64 old_blkaddr = *to;
+ if (old_blkaddr == NULL_ADDR) {
+ if (c.func == FSCK) {
+ if (fsck->chk.valid_blk_cnt >= sbi->user_block_count) {
+ ERR_MSG("Not enough space");
+ return -ENOSPC;
+ }
+ } else {
+ if (sbi->total_valid_block_count >=
+ sbi->user_block_count) {
+ ERR_MSG("Not enough space");
+ return -ENOSPC;
+ }
+ }
+ }
+
blkaddr = SM_I(sbi)->main_blkaddr;
if (find_next_free_block(sbi, &blkaddr, 0, type)) {
- ERR_MSG("Not enough space to allocate blocks");
+ ERR_MSG("Can't find free block");
ASSERT(0);
}
/* read/write SSA */
*to = (block_t)blkaddr;
update_sum_entry(sbi, *to, sum);
+
+ return 0;
}
int new_data_block(struct f2fs_sb_info *sbi, void *block,
struct node_info ni;
unsigned int blkaddr = datablock_addr(dn->node_blk, dn->ofs_in_node);
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
+ int ret;
if (!is_set_ckpt_flags(cp, CP_UMOUNT_FLAG)) {
c.alloc_failed = 1;
get_node_info(sbi, dn->nid, &ni);
set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
- reserve_new_block(sbi, &dn->data_blkaddr, &sum, type);
+ ret = reserve_new_block(sbi, &dn->data_blkaddr, &sum, type);
+ if (ret) {
+ c.alloc_failed = 1;
+ return ret;
+ }
if (blkaddr == NULL_ADDR)
inc_inode_blocks(dn);