aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2014-08-29 20:51:32 -0400
committerTheodore Ts'o <tytso@mit.edu>2014-08-29 20:51:32 -0400
commit1056008226769fe982236c26038a095aeb47714b (patch)
tree28a89f23fb0bcb514083c0e8dbb21ed4c6259d66 /fs/ext4
parent537d8f93805ace30ce097736d3aac041931274b1 (diff)
ext4: convert ext4_getblk() to use the ERR_PTR convention
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/ext4.h3
-rw-r--r--fs/ext4/inode.c51
-rw-r--r--fs/ext4/namei.c9
3 files changed, 30 insertions, 33 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index b0c225cdb52c..8009077079e4 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2086,8 +2086,7 @@ extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
2086extern int ext4_trim_fs(struct super_block *, struct fstrim_range *); 2086extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
2087 2087
2088/* inode.c */ 2088/* inode.c */
2089struct buffer_head *ext4_getblk(handle_t *, struct inode *, 2089struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
2090 ext4_lblk_t, int, int *);
2091struct buffer_head *ext4_bread(handle_t *, struct inode *, 2090struct buffer_head *ext4_bread(handle_t *, struct inode *,
2092 ext4_lblk_t, int, int *); 2091 ext4_lblk_t, int, int *);
2093int ext4_get_block_write(struct inode *inode, sector_t iblock, 2092int ext4_get_block_write(struct inode *inode, sector_t iblock,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 3aa26e9117c4..0dfc1cd1eb52 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -734,11 +734,11 @@ int ext4_get_block(struct inode *inode, sector_t iblock,
734 * `handle' can be NULL if create is zero 734 * `handle' can be NULL if create is zero
735 */ 735 */
736struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, 736struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
737 ext4_lblk_t block, int create, int *errp) 737 ext4_lblk_t block, int create)
738{ 738{
739 struct ext4_map_blocks map; 739 struct ext4_map_blocks map;
740 struct buffer_head *bh; 740 struct buffer_head *bh;
741 int fatal = 0, err; 741 int err;
742 742
743 J_ASSERT(handle != NULL || create == 0); 743 J_ASSERT(handle != NULL || create == 0);
744 744
@@ -747,21 +747,14 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
747 err = ext4_map_blocks(handle, inode, &map, 747 err = ext4_map_blocks(handle, inode, &map,
748 create ? EXT4_GET_BLOCKS_CREATE : 0); 748 create ? EXT4_GET_BLOCKS_CREATE : 0);
749 749
750 /* ensure we send some value back into *errp */ 750 if (err == 0)
751 *errp = 0; 751 return create ? ERR_PTR(-ENOSPC) : NULL;
752
753 if (create && err == 0)
754 err = -ENOSPC; /* should never happen */
755 if (err < 0) 752 if (err < 0)
756 *errp = err; 753 return ERR_PTR(err);
757 if (err <= 0)
758 return NULL;
759 754
760 bh = sb_getblk(inode->i_sb, map.m_pblk); 755 bh = sb_getblk(inode->i_sb, map.m_pblk);
761 if (unlikely(!bh)) { 756 if (unlikely(!bh))
762 *errp = -ENOMEM; 757 return ERR_PTR(-ENOMEM);
763 return NULL;
764 }
765 if (map.m_flags & EXT4_MAP_NEW) { 758 if (map.m_flags & EXT4_MAP_NEW) {
766 J_ASSERT(create != 0); 759 J_ASSERT(create != 0);
767 J_ASSERT(handle != NULL); 760 J_ASSERT(handle != NULL);
@@ -775,25 +768,26 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
775 */ 768 */
776 lock_buffer(bh); 769 lock_buffer(bh);
777 BUFFER_TRACE(bh, "call get_create_access"); 770 BUFFER_TRACE(bh, "call get_create_access");
778 fatal = ext4_journal_get_create_access(handle, bh); 771 err = ext4_journal_get_create_access(handle, bh);
779 if (!fatal && !buffer_uptodate(bh)) { 772 if (unlikely(err)) {
773 unlock_buffer(bh);
774 goto errout;
775 }
776 if (!buffer_uptodate(bh)) {
780 memset(bh->b_data, 0, inode->i_sb->s_blocksize); 777 memset(bh->b_data, 0, inode->i_sb->s_blocksize);
781 set_buffer_uptodate(bh); 778 set_buffer_uptodate(bh);
782 } 779 }
783 unlock_buffer(bh); 780 unlock_buffer(bh);
784 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); 781 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
785 err = ext4_handle_dirty_metadata(handle, inode, bh); 782 err = ext4_handle_dirty_metadata(handle, inode, bh);
786 if (!fatal) 783 if (unlikely(err))
787 fatal = err; 784 goto errout;
788 } else { 785 } else
789 BUFFER_TRACE(bh, "not a new buffer"); 786 BUFFER_TRACE(bh, "not a new buffer");
790 }
791 if (fatal) {
792 *errp = fatal;
793 brelse(bh);
794 bh = NULL;
795 }
796 return bh; 787 return bh;
788errout:
789 brelse(bh);
790 return ERR_PTR(err);
797} 791}
798 792
799struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, 793struct 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{ 795{
802 struct buffer_head *bh; 796 struct buffer_head *bh;
803 797
804 bh = ext4_getblk(handle, inode, block, create, err); 798 *err = 0;
799 bh = ext4_getblk(handle, inode, block, create);
800 if (IS_ERR(bh)) {
801 *err = PTR_ERR(bh);
802 return NULL;
803 }
805 if (!bh) 804 if (!bh)
806 return bh; 805 return bh;
807 if (buffer_uptodate(bh)) 806 if (buffer_uptodate(bh))
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 1421ec1cd7e4..26f114b1e4d6 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1226,8 +1226,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
1226 buffer */ 1226 buffer */
1227 int num = 0; 1227 int num = 0;
1228 ext4_lblk_t nblocks; 1228 ext4_lblk_t nblocks;
1229 int i, err = 0; 1229 int i, namelen;
1230 int namelen;
1231 1230
1232 *res_dir = NULL; 1231 *res_dir = NULL;
1233 sb = dir->i_sb; 1232 sb = dir->i_sb;
@@ -1293,10 +1292,10 @@ restart:
1293 break; 1292 break;
1294 } 1293 }
1295 num++; 1294 num++;
1296 bh = ext4_getblk(NULL, dir, b++, 0, &err); 1295 bh = ext4_getblk(NULL, dir, b++, 0);
1297 if (unlikely(err)) { 1296 if (unlikely(IS_ERR(bh))) {
1298 if (ra_max == 0) 1297 if (ra_max == 0)
1299 return ERR_PTR(err); 1298 return bh;
1300 break; 1299 break;
1301 } 1300 }
1302 bh_use[ra_max] = bh; 1301 bh_use[ra_max] = bh;