* [PATCH 2/2] Ext3: add necessary check in case IO error happens @ 2013-01-11 11:58 shilong wang 2013-01-11 16:26 ` Jan Kara 0 siblings, 1 reply; 5+ messages in thread From: shilong wang @ 2013-01-11 11:58 UTC (permalink / raw) To: viro; +Cc: linux-fsdevel From: Wang Shilong <wangsl-fnst@cn.fujitsu.com> As we know IO ERROR may happen when the function 'sb_getblk' is called. Add necessary check for it. The patch also fix a coding style problem. Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> --- fs/ext3/inode.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index ff574b4..59b6178 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c @@ -676,6 +676,10 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode, * parent to disk. */ bh = sb_getblk(inode->i_sb, new_blocks[n-1]); + if (!bh) { + err = -EIO; + goto failed; + } branch[n].bh = bh; lock_buffer(bh); BUFFER_TRACE(bh, "call get_create_access"); @@ -717,7 +721,7 @@ failed: BUFFER_TRACE(branch[i].bh, "call journal_forget"); ext3_journal_forget(handle, branch[i].bh); } - for (i = 0; i <indirect_blks; i++) + for (i = 0; i < indirect_blks; i++) ext3_free_blocks(handle, inode, new_blocks[i], 1); ext3_free_blocks(handle, inode, new_blocks[i], num); -- 1.7.7.6 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Ext3: add necessary check in case IO error happens 2013-01-11 11:58 [PATCH 2/2] Ext3: add necessary check in case IO error happens shilong wang @ 2013-01-11 16:26 ` Jan Kara 2013-01-12 2:20 ` shilong wang 2013-01-12 20:30 ` Theodore Ts'o 0 siblings, 2 replies; 5+ messages in thread From: Jan Kara @ 2013-01-11 16:26 UTC (permalink / raw) To: shilong wang; +Cc: viro, linux-fsdevel On Fri 11-01-13 03:58:28, shilong wang wrote: > From: Wang Shilong <wangsl-fnst@cn.fujitsu.com> > > As we know IO ERROR may happen when the function 'sb_getblk' is > called. Add necessary check for it. > > The patch also fix a coding style problem. Thanks for the patch. I think returning ENOMEM instead of EIO would be better. Otherwise the patch looks OK. Honza > > Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> > --- > fs/ext3/inode.c | 6 +++++- > 1 files changed, 5 insertions(+), 1 deletions(-) > > diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c > index ff574b4..59b6178 100644 > --- a/fs/ext3/inode.c > +++ b/fs/ext3/inode.c > @@ -676,6 +676,10 @@ static int ext3_alloc_branch(handle_t *handle, > struct inode *inode, > * parent to disk. > */ > bh = sb_getblk(inode->i_sb, new_blocks[n-1]); > + if (!bh) { > + err = -EIO; > + goto failed; > + } > branch[n].bh = bh; > lock_buffer(bh); > BUFFER_TRACE(bh, "call get_create_access"); > @@ -717,7 +721,7 @@ failed: > BUFFER_TRACE(branch[i].bh, "call journal_forget"); > ext3_journal_forget(handle, branch[i].bh); > } > - for (i = 0; i <indirect_blks; i++) > + for (i = 0; i < indirect_blks; i++) > ext3_free_blocks(handle, inode, new_blocks[i], 1); > > ext3_free_blocks(handle, inode, new_blocks[i], num); > -- > 1.7.7.6 > -- > To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Jan Kara <jack@suse.cz> SUSE Labs, CR ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Ext3: add necessary check in case IO error happens 2013-01-11 16:26 ` Jan Kara @ 2013-01-12 2:20 ` shilong wang 2013-01-12 20:30 ` Theodore Ts'o 1 sibling, 0 replies; 5+ messages in thread From: shilong wang @ 2013-01-12 2:20 UTC (permalink / raw) To: Jan Kara; +Cc: linux-fsdevel Thanks very much for your reply. I will resend the patch later, Besides, i find there are many places where EIO is used when 'sb_getblk' fails. Shall i replace all of them with ENOMEM? 2013/1/11 Jan Kara <jack@suse.cz>: > On Fri 11-01-13 03:58:28, shilong wang wrote: >> From: Wang Shilong <wangsl-fnst@cn.fujitsu.com> >> >> As we know IO ERROR may happen when the function 'sb_getblk' is >> called. Add necessary check for it. >> >> The patch also fix a coding style problem. > Thanks for the patch. I think returning ENOMEM instead of EIO would be > better. Otherwise the patch looks OK. > > Honza >> >> Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> >> --- >> fs/ext3/inode.c | 6 +++++- >> 1 files changed, 5 insertions(+), 1 deletions(-) >> >> diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c >> index ff574b4..59b6178 100644 >> --- a/fs/ext3/inode.c >> +++ b/fs/ext3/inode.c >> @@ -676,6 +676,10 @@ static int ext3_alloc_branch(handle_t *handle, >> struct inode *inode, >> * parent to disk. >> */ >> bh = sb_getblk(inode->i_sb, new_blocks[n-1]); >> + if (!bh) { >> + err = -EIO; >> + goto failed; >> + } >> branch[n].bh = bh; >> lock_buffer(bh); >> BUFFER_TRACE(bh, "call get_create_access"); >> @@ -717,7 +721,7 @@ failed: >> BUFFER_TRACE(branch[i].bh, "call journal_forget"); >> ext3_journal_forget(handle, branch[i].bh); >> } >> - for (i = 0; i <indirect_blks; i++) >> + for (i = 0; i < indirect_blks; i++) >> ext3_free_blocks(handle, inode, new_blocks[i], 1); >> >> ext3_free_blocks(handle, inode, new_blocks[i], num); >> -- >> 1.7.7.6 >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html > -- > Jan Kara <jack@suse.cz> > SUSE Labs, CR ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Ext3: add necessary check in case IO error happens 2013-01-11 16:26 ` Jan Kara 2013-01-12 2:20 ` shilong wang @ 2013-01-12 20:30 ` Theodore Ts'o 2013-01-12 21:12 ` [PATCH] ext4: return ENOMEM if sb_getblk() fails Theodore Ts'o 1 sibling, 1 reply; 5+ messages in thread From: Theodore Ts'o @ 2013-01-12 20:30 UTC (permalink / raw) To: Jan Kara; +Cc: shilong wang, viro, linux-fsdevel On Fri, Jan 11, 2013 at 05:26:33PM +0100, Jan Kara wrote: > Thanks for the patch. I think returning ENOMEM instead of EIO would be > better. Otherwise the patch looks OK. This may be because fs/ext4/inode.c was returning EIO in similar circumstances. I agree ENOMEM is a better error code. I'll fix up ext4.... - Ted ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] ext4: return ENOMEM if sb_getblk() fails 2013-01-12 20:30 ` Theodore Ts'o @ 2013-01-12 21:12 ` Theodore Ts'o 0 siblings, 0 replies; 5+ messages in thread From: Theodore Ts'o @ 2013-01-12 21:12 UTC (permalink / raw) To: Ext4 Developers List; +Cc: Theodore Ts'o, stable 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: "Theodore Ts'o" <tytso@mit.edu> Cc: stable@vger.kernel.org --- fs/ext4/extents.c | 21 ++++++++++++--------- fs/ext4/indirect.c | 9 ++++++--- fs/ext4/inline.c | 2 +- fs/ext4/inode.c | 9 +++------ fs/ext4/mmp.c | 2 ++ fs/ext4/resize.c | 8 ++++---- fs/ext4/xattr.c | 3 ++- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 5ae1674..6913a8d 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -725,6 +725,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, struct ext4_extent_header *eh; struct buffer_head *bh; short int depth, i, ppos = 0, alloc = 0; + int ret; eh = ext_inode_hdr(inode); depth = ext_depth(inode); @@ -752,12 +753,15 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, path[ppos].p_ext = NULL; bh = sb_getblk(inode->i_sb, path[ppos].p_block); - if (unlikely(!bh)) + if (unlikely(!bh)) { + ret = -ENOMEM; goto err; + } if (!bh_uptodate_or_lock(bh)) { trace_ext4_ext_load_extent(inode, block, path[ppos].p_block); - if (bh_submit_read(bh) < 0) { + ret = bh_submit_read(bh); + if (ret < 0) { put_bh(bh); goto err; } @@ -768,13 +772,15 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, put_bh(bh); EXT4_ERROR_INODE(inode, "ppos %d > depth %d", ppos, depth); + ret = -EIO; goto err; } path[ppos].p_bh = bh; path[ppos].p_hdr = eh; i--; - if (ext4_ext_check_block(inode, eh, i, bh)) + ret = ext4_ext_check_block(inode, eh, i, bh); + if (ret < 0) goto err; } @@ -796,7 +802,7 @@ err: ext4_ext_drop_refs(path); if (alloc) kfree(path); - return ERR_PTR(-EIO); + return ERR_PTR(ret); } /* @@ -1136,11 +1142,8 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode, return err; bh = sb_getblk(inode->i_sb, newblock); - if (!bh) { - err = -EIO; - ext4_std_error(inode->i_sb, err); - return err; - } + if (!bh) + return -ENOMEM; lock_buffer(bh); err = ext4_journal_get_create_access(handle, bh); diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 20862f9..8d83d1e 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -146,6 +146,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, struct super_block *sb = inode->i_sb; Indirect *p = chain; struct buffer_head *bh; + int ret = -EIO; *err = 0; /* i_data is not going away, no lock needed */ @@ -154,8 +155,10 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, goto no_block; while (--depth) { bh = sb_getblk(sb, le32_to_cpu(p->key)); - if (unlikely(!bh)) + if (unlikely(!bh)) { + ret = -ENOMEM; goto failure; + } if (!bh_uptodate_or_lock(bh)) { if (bh_submit_read(bh) < 0) { @@ -177,7 +180,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, return NULL; failure: - *err = -EIO; + *err = ret; no_block: return p; } @@ -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]); if (unlikely(!bh)) { - err = -EIO; + err = -ENOMEM; goto failed; } diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 387c47c..93a3408 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -1188,7 +1188,7 @@ static int ext4_convert_inline_data_nolock(handle_t *handle, data_bh = sb_getblk(inode->i_sb, map.m_pblk); if (!data_bh) { - error = -EIO; + error = -ENOMEM; goto out_restore; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index cbfe13b..9ccc140 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -714,7 +714,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, bh = sb_getblk(inode->i_sb, map.m_pblk); if (!bh) { - *errp = -EIO; + *errp = -ENOMEM; return NULL; } if (map.m_flags & EXT4_MAP_NEW) { @@ -3660,11 +3660,8 @@ static int __ext4_get_inode_loc(struct inode *inode, iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb); bh = sb_getblk(sb, block); - if (!bh) { - EXT4_ERROR_INODE_BLOCK(inode, block, - "unable to read itable block"); - return -EIO; - } + if (!bh) + return -ENOMEM; if (!buffer_uptodate(bh)) { lock_buffer(bh); diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index fe7c63f..44734f1 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -80,6 +80,8 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh, * is not blocked in the elevator. */ if (!*bh) *bh = sb_getblk(sb, mmp_block); + if (!*bh) + return -ENOMEM; if (*bh) { get_bh(*bh); lock_buffer(*bh); diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index d99387b..02824dc 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -334,7 +334,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, bh = sb_getblk(sb, blk); if (!bh) - return ERR_PTR(-EIO); + return ERR_PTR(-ENOMEM); if ((err = ext4_journal_get_write_access(handle, bh))) { brelse(bh); bh = ERR_PTR(err); @@ -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); if (!bh) - return -EIO; + return -ENOMEM; err = ext4_journal_get_write_access(handle, bh); if (err) @@ -501,7 +501,7 @@ static int setup_new_flex_group_blocks(struct super_block *sb, gdb = sb_getblk(sb, block); if (!gdb) { - err = -EIO; + err = -ENOMEM; goto out; } @@ -1065,7 +1065,7 @@ static void update_backups(struct super_block *sb, int blk_off, char *data, bh = sb_getblk(sb, backup_block); if (!bh) { - err = -EIO; + err = -ENOMEM; break; } ext4_debug("update metadata backup %llu(+%llu)\n", diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 3a91ebc..07d684a 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -887,16 +887,17 @@ inserted: new_bh = sb_getblk(sb, block); if (!new_bh) { + error = -ENOMEM; getblk_failed: ext4_free_blocks(handle, inode, NULL, block, 1, EXT4_FREE_BLOCKS_METADATA); - error = -EIO; goto cleanup; } lock_buffer(new_bh); error = ext4_journal_get_create_access(handle, new_bh); if (error) { unlock_buffer(new_bh); + error = -EIO; goto getblk_failed; } memcpy(new_bh->b_data, s->base, new_bh->b_size); -- 1.7.12.rc0.22.gcdd159b ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-01-12 21:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-01-11 11:58 [PATCH 2/2] Ext3: add necessary check in case IO error happens shilong wang 2013-01-11 16:26 ` Jan Kara 2013-01-12 2:20 ` shilong wang 2013-01-12 20:30 ` Theodore Ts'o 2013-01-12 21:12 ` [PATCH] ext4: return ENOMEM if sb_getblk() fails Theodore Ts'o
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.