Commit 10560082 authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: convert ext4_getblk() to use the ERR_PTR convention

Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 537d8f93
...@@ -2086,8 +2086,7 @@ extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb, ...@@ -2086,8 +2086,7 @@ extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
extern int ext4_trim_fs(struct super_block *, struct fstrim_range *); extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
/* inode.c */ /* inode.c */
struct buffer_head *ext4_getblk(handle_t *, struct inode *, struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
ext4_lblk_t, int, int *);
struct buffer_head *ext4_bread(handle_t *, struct inode *, struct buffer_head *ext4_bread(handle_t *, struct inode *,
ext4_lblk_t, int, int *); ext4_lblk_t, int, int *);
int ext4_get_block_write(struct inode *inode, sector_t iblock, int ext4_get_block_write(struct inode *inode, sector_t iblock,
......
...@@ -734,11 +734,11 @@ int ext4_get_block(struct inode *inode, sector_t iblock, ...@@ -734,11 +734,11 @@ int ext4_get_block(struct inode *inode, sector_t iblock,
* `handle' can be NULL if create is zero * `handle' can be NULL if create is zero
*/ */
struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
ext4_lblk_t block, int create, int *errp) ext4_lblk_t block, int create)
{ {
struct ext4_map_blocks map; struct ext4_map_blocks map;
struct buffer_head *bh; struct buffer_head *bh;
int fatal = 0, err; int err;
J_ASSERT(handle != NULL || create == 0); J_ASSERT(handle != NULL || create == 0);
...@@ -747,21 +747,14 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, ...@@ -747,21 +747,14 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
err = ext4_map_blocks(handle, inode, &map, err = ext4_map_blocks(handle, inode, &map,
create ? EXT4_GET_BLOCKS_CREATE : 0); create ? EXT4_GET_BLOCKS_CREATE : 0);
/* ensure we send some value back into *errp */ if (err == 0)
*errp = 0; return create ? ERR_PTR(-ENOSPC) : NULL;
if (create && err == 0)
err = -ENOSPC; /* should never happen */
if (err < 0) if (err < 0)
*errp = err; return ERR_PTR(err);
if (err <= 0)
return NULL;
bh = sb_getblk(inode->i_sb, map.m_pblk); bh = sb_getblk(inode->i_sb, map.m_pblk);
if (unlikely(!bh)) { if (unlikely(!bh))
*errp = -ENOMEM; return ERR_PTR(-ENOMEM);
return NULL;
}
if (map.m_flags & EXT4_MAP_NEW) { if (map.m_flags & EXT4_MAP_NEW) {
J_ASSERT(create != 0); J_ASSERT(create != 0);
J_ASSERT(handle != NULL); J_ASSERT(handle != NULL);
...@@ -775,25 +768,26 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, ...@@ -775,25 +768,26 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
*/ */
lock_buffer(bh); lock_buffer(bh);
BUFFER_TRACE(bh, "call get_create_access"); BUFFER_TRACE(bh, "call get_create_access");
fatal = ext4_journal_get_create_access(handle, bh); err = ext4_journal_get_create_access(handle, bh);
if (!fatal && !buffer_uptodate(bh)) { if (unlikely(err)) {
unlock_buffer(bh);
goto errout;
}
if (!buffer_uptodate(bh)) {
memset(bh->b_data, 0, inode->i_sb->s_blocksize); memset(bh->b_data, 0, inode->i_sb->s_blocksize);
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
} }
unlock_buffer(bh); unlock_buffer(bh);
BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
err = ext4_handle_dirty_metadata(handle, inode, bh); err = ext4_handle_dirty_metadata(handle, inode, bh);
if (!fatal) if (unlikely(err))
fatal = err; goto errout;
} else { } else
BUFFER_TRACE(bh, "not a new buffer"); BUFFER_TRACE(bh, "not a new buffer");
}
if (fatal) {
*errp = fatal;
brelse(bh);
bh = NULL;
}
return bh; return bh;
errout:
brelse(bh);
return ERR_PTR(err);
} }
struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
...@@ -801,7 +795,12 @@ struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, ...@@ -801,7 +795,12 @@ struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
{ {
struct buffer_head *bh; struct buffer_head *bh;
bh = ext4_getblk(handle, inode, block, create, err); *err = 0;
bh = ext4_getblk(handle, inode, block, create);
if (IS_ERR(bh)) {
*err = PTR_ERR(bh);
return NULL;
}
if (!bh) if (!bh)
return bh; return bh;
if (buffer_uptodate(bh)) if (buffer_uptodate(bh))
......
...@@ -1226,8 +1226,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir, ...@@ -1226,8 +1226,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
buffer */ buffer */
int num = 0; int num = 0;
ext4_lblk_t nblocks; ext4_lblk_t nblocks;
int i, err = 0; int i, namelen;
int namelen;
*res_dir = NULL; *res_dir = NULL;
sb = dir->i_sb; sb = dir->i_sb;
...@@ -1293,10 +1292,10 @@ static struct buffer_head * ext4_find_entry (struct inode *dir, ...@@ -1293,10 +1292,10 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
break; break;
} }
num++; num++;
bh = ext4_getblk(NULL, dir, b++, 0, &err); bh = ext4_getblk(NULL, dir, b++, 0);
if (unlikely(err)) { if (unlikely(IS_ERR(bh))) {
if (ra_max == 0) if (ra_max == 0)
return ERR_PTR(err); return bh;
break; break;
} }
bh_use[ra_max] = bh; bh_use[ra_max] = bh;
......
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