Commit 860d21e2 authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: return ENOMEM if sb_getblk() fails

The only reason for sb_getblk() failing is if it can't allocate the
buffer_head.  So ENOMEM is more appropriate than EIO.  In addition,
make sure that the file system is marked as being inconsistent if
sb_getblk() fails.
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
Cc: stable@vger.kernel.org
parent 9931faca
...@@ -725,6 +725,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, ...@@ -725,6 +725,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
struct ext4_extent_header *eh; struct ext4_extent_header *eh;
struct buffer_head *bh; struct buffer_head *bh;
short int depth, i, ppos = 0, alloc = 0; short int depth, i, ppos = 0, alloc = 0;
int ret;
eh = ext_inode_hdr(inode); eh = ext_inode_hdr(inode);
depth = ext_depth(inode); depth = ext_depth(inode);
...@@ -752,12 +753,15 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, ...@@ -752,12 +753,15 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
path[ppos].p_ext = NULL; path[ppos].p_ext = NULL;
bh = sb_getblk(inode->i_sb, path[ppos].p_block); bh = sb_getblk(inode->i_sb, path[ppos].p_block);
if (unlikely(!bh)) if (unlikely(!bh)) {
ret = -ENOMEM;
goto err; goto err;
}
if (!bh_uptodate_or_lock(bh)) { if (!bh_uptodate_or_lock(bh)) {
trace_ext4_ext_load_extent(inode, block, trace_ext4_ext_load_extent(inode, block,
path[ppos].p_block); path[ppos].p_block);
if (bh_submit_read(bh) < 0) { ret = bh_submit_read(bh);
if (ret < 0) {
put_bh(bh); put_bh(bh);
goto err; goto err;
} }
...@@ -768,13 +772,15 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, ...@@ -768,13 +772,15 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
put_bh(bh); put_bh(bh);
EXT4_ERROR_INODE(inode, EXT4_ERROR_INODE(inode,
"ppos %d > depth %d", ppos, depth); "ppos %d > depth %d", ppos, depth);
ret = -EIO;
goto err; goto err;
} }
path[ppos].p_bh = bh; path[ppos].p_bh = bh;
path[ppos].p_hdr = eh; path[ppos].p_hdr = eh;
i--; i--;
if (ext4_ext_check_block(inode, eh, i, bh)) ret = ext4_ext_check_block(inode, eh, i, bh);
if (ret < 0)
goto err; goto err;
} }
...@@ -796,7 +802,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, ...@@ -796,7 +802,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
ext4_ext_drop_refs(path); ext4_ext_drop_refs(path);
if (alloc) if (alloc)
kfree(path); kfree(path);
return ERR_PTR(-EIO); return ERR_PTR(ret);
} }
/* /*
...@@ -951,7 +957,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, ...@@ -951,7 +957,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
} }
bh = sb_getblk(inode->i_sb, newblock); bh = sb_getblk(inode->i_sb, newblock);
if (!bh) { if (!bh) {
err = -EIO; err = -ENOMEM;
goto cleanup; goto cleanup;
} }
lock_buffer(bh); lock_buffer(bh);
...@@ -1024,7 +1030,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, ...@@ -1024,7 +1030,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
newblock = ablocks[--a]; newblock = ablocks[--a];
bh = sb_getblk(inode->i_sb, newblock); bh = sb_getblk(inode->i_sb, newblock);
if (!bh) { if (!bh) {
err = -EIO; err = -ENOMEM;
goto cleanup; goto cleanup;
} }
lock_buffer(bh); lock_buffer(bh);
...@@ -1136,11 +1142,8 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode, ...@@ -1136,11 +1142,8 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
return err; return err;
bh = sb_getblk(inode->i_sb, newblock); bh = sb_getblk(inode->i_sb, newblock);
if (!bh) { if (!bh)
err = -EIO; return -ENOMEM;
ext4_std_error(inode->i_sb, err);
return err;
}
lock_buffer(bh); lock_buffer(bh);
err = ext4_journal_get_create_access(handle, bh); err = ext4_journal_get_create_access(handle, bh);
......
...@@ -146,6 +146,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, ...@@ -146,6 +146,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
Indirect *p = chain; Indirect *p = chain;
struct buffer_head *bh; struct buffer_head *bh;
int ret = -EIO;
*err = 0; *err = 0;
/* i_data is not going away, no lock needed */ /* i_data is not going away, no lock needed */
...@@ -154,8 +155,10 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, ...@@ -154,8 +155,10 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
goto no_block; goto no_block;
while (--depth) { while (--depth) {
bh = sb_getblk(sb, le32_to_cpu(p->key)); bh = sb_getblk(sb, le32_to_cpu(p->key));
if (unlikely(!bh)) if (unlikely(!bh)) {
ret = -ENOMEM;
goto failure; goto failure;
}
if (!bh_uptodate_or_lock(bh)) { if (!bh_uptodate_or_lock(bh)) {
if (bh_submit_read(bh) < 0) { if (bh_submit_read(bh) < 0) {
...@@ -177,7 +180,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, ...@@ -177,7 +180,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
return NULL; return NULL;
failure: failure:
*err = -EIO; *err = ret;
no_block: no_block:
return p; return p;
} }
...@@ -471,7 +474,7 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode, ...@@ -471,7 +474,7 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
*/ */
bh = sb_getblk(inode->i_sb, new_blocks[n-1]); bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
if (unlikely(!bh)) { if (unlikely(!bh)) {
err = -EIO; err = -ENOMEM;
goto failed; goto failed;
} }
......
...@@ -1188,7 +1188,7 @@ static int ext4_convert_inline_data_nolock(handle_t *handle, ...@@ -1188,7 +1188,7 @@ static int ext4_convert_inline_data_nolock(handle_t *handle,
data_bh = sb_getblk(inode->i_sb, map.m_pblk); data_bh = sb_getblk(inode->i_sb, map.m_pblk);
if (!data_bh) { if (!data_bh) {
error = -EIO; error = -ENOMEM;
goto out_restore; goto out_restore;
} }
......
...@@ -714,7 +714,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, ...@@ -714,7 +714,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
bh = sb_getblk(inode->i_sb, map.m_pblk); bh = sb_getblk(inode->i_sb, map.m_pblk);
if (!bh) { if (!bh) {
*errp = -EIO; *errp = -ENOMEM;
return NULL; return NULL;
} }
if (map.m_flags & EXT4_MAP_NEW) { if (map.m_flags & EXT4_MAP_NEW) {
...@@ -3660,11 +3660,8 @@ static int __ext4_get_inode_loc(struct inode *inode, ...@@ -3660,11 +3660,8 @@ static int __ext4_get_inode_loc(struct inode *inode,
iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb); iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb);
bh = sb_getblk(sb, block); bh = sb_getblk(sb, block);
if (!bh) { if (!bh)
EXT4_ERROR_INODE_BLOCK(inode, block, return -ENOMEM;
"unable to read itable block");
return -EIO;
}
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
lock_buffer(bh); lock_buffer(bh);
......
...@@ -80,6 +80,8 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh, ...@@ -80,6 +80,8 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
* is not blocked in the elevator. */ * is not blocked in the elevator. */
if (!*bh) if (!*bh)
*bh = sb_getblk(sb, mmp_block); *bh = sb_getblk(sb, mmp_block);
if (!*bh)
return -ENOMEM;
if (*bh) { if (*bh) {
get_bh(*bh); get_bh(*bh);
lock_buffer(*bh); lock_buffer(*bh);
......
...@@ -334,7 +334,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, ...@@ -334,7 +334,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
bh = sb_getblk(sb, blk); bh = sb_getblk(sb, blk);
if (!bh) if (!bh)
return ERR_PTR(-EIO); return ERR_PTR(-ENOMEM);
if ((err = ext4_journal_get_write_access(handle, bh))) { if ((err = ext4_journal_get_write_access(handle, bh))) {
brelse(bh); brelse(bh);
bh = ERR_PTR(err); bh = ERR_PTR(err);
...@@ -411,7 +411,7 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle, ...@@ -411,7 +411,7 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle,
bh = sb_getblk(sb, flex_gd->groups[group].block_bitmap); bh = sb_getblk(sb, flex_gd->groups[group].block_bitmap);
if (!bh) if (!bh)
return -EIO; return -ENOMEM;
err = ext4_journal_get_write_access(handle, bh); err = ext4_journal_get_write_access(handle, bh);
if (err) if (err)
...@@ -501,7 +501,7 @@ static int setup_new_flex_group_blocks(struct super_block *sb, ...@@ -501,7 +501,7 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
gdb = sb_getblk(sb, block); gdb = sb_getblk(sb, block);
if (!gdb) { if (!gdb) {
err = -EIO; err = -ENOMEM;
goto out; goto out;
} }
...@@ -1065,7 +1065,7 @@ static void update_backups(struct super_block *sb, int blk_off, char *data, ...@@ -1065,7 +1065,7 @@ static void update_backups(struct super_block *sb, int blk_off, char *data,
bh = sb_getblk(sb, backup_block); bh = sb_getblk(sb, backup_block);
if (!bh) { if (!bh) {
err = -EIO; err = -ENOMEM;
break; break;
} }
ext4_debug("update metadata backup %llu(+%llu)\n", ext4_debug("update metadata backup %llu(+%llu)\n",
......
...@@ -887,16 +887,17 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -887,16 +887,17 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
new_bh = sb_getblk(sb, block); new_bh = sb_getblk(sb, block);
if (!new_bh) { if (!new_bh) {
error = -ENOMEM;
getblk_failed: getblk_failed:
ext4_free_blocks(handle, inode, NULL, block, 1, ext4_free_blocks(handle, inode, NULL, block, 1,
EXT4_FREE_BLOCKS_METADATA); EXT4_FREE_BLOCKS_METADATA);
error = -EIO;
goto cleanup; goto cleanup;
} }
lock_buffer(new_bh); lock_buffer(new_bh);
error = ext4_journal_get_create_access(handle, new_bh); error = ext4_journal_get_create_access(handle, new_bh);
if (error) { if (error) {
unlock_buffer(new_bh); unlock_buffer(new_bh);
error = -EIO;
goto getblk_failed; goto getblk_failed;
} }
memcpy(new_bh->b_data, s->base, new_bh->b_size); memcpy(new_bh->b_data, s->base, new_bh->b_size);
......
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