1 ext4: convert ext4_bread() to use the ERR_PTR convention
3 From: Theodore Ts'o <tytso@mit.edu>
5 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 fs/ext4/dir.c | 8 +++-----
9 fs/ext4/inode.c | 14 ++++----------
10 fs/ext4/namei.c | 34 ++++++++++++++++++----------------
11 fs/ext4/super.c | 18 ++++++++----------
12 5 files changed, 34 insertions(+), 43 deletions(-)
14 diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
15 index 0bb3f9e..c24143e 100644
18 @@ -151,13 +151,11 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
21 file->f_ra.prev_pos = (loff_t)index << PAGE_CACHE_SHIFT;
22 - bh = ext4_bread(NULL, inode, map.m_lblk, 0, &err);
23 + bh = ext4_bread(NULL, inode, map.m_lblk, 0);
29 - * We ignore I/O errors on directories so users have a chance
30 - * of recovering data when there's a bad sector
34 EXT4_ERROR_FILE(file, 0,
35 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
36 index 8009077..ca53bce 100644
39 @@ -2087,8 +2087,7 @@ extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
42 struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
43 -struct buffer_head *ext4_bread(handle_t *, struct inode *,
44 - ext4_lblk_t, int, int *);
45 +struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int);
46 int ext4_get_block_write(struct inode *inode, sector_t iblock,
47 struct buffer_head *bh_result, int create);
48 int ext4_get_block(struct inode *inode, sector_t iblock,
49 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
50 index 0dfc1cd..8aa241a 100644
53 @@ -791,27 +791,21 @@ errout:
56 struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
57 - ext4_lblk_t block, int create, int *err)
58 + ext4_lblk_t block, int create)
60 struct buffer_head *bh;
63 bh = ext4_getblk(handle, inode, block, create);
71 - if (buffer_uptodate(bh))
72 + if (!bh || buffer_uptodate(bh))
74 ll_rw_block(READ | REQ_META | REQ_PRIO, 1, &bh);
76 if (buffer_uptodate(bh))
81 + return ERR_PTR(-EIO);
84 int ext4_walk_page_buffers(handle_t *handle,
85 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
86 index 26f114b..af13c90 100644
89 @@ -53,7 +53,7 @@ static struct buffer_head *ext4_append(handle_t *handle,
92 struct buffer_head *bh;
96 if (unlikely(EXT4_SB(inode->i_sb)->s_max_dir_size_kb &&
97 ((inode->i_size >> 10) >=
98 @@ -62,9 +62,9 @@ static struct buffer_head *ext4_append(handle_t *handle,
100 *block = inode->i_size >> inode->i_sb->s_blocksize_bits;
102 - bh = ext4_bread(handle, inode, *block, 1, &err);
104 - return ERR_PTR(err);
105 + bh = ext4_bread(handle, inode, *block, 1);
108 inode->i_size += inode->i_sb->s_blocksize;
109 EXT4_I(inode)->i_disksize = inode->i_size;
110 BUFFER_TRACE(bh, "get_write_access");
111 @@ -94,20 +94,20 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
113 struct buffer_head *bh;
114 struct ext4_dir_entry *dirent;
115 - int err = 0, is_dx_block = 0;
116 + int is_dx_block = 0;
118 - bh = ext4_bread(NULL, inode, block, 0, &err);
121 - ext4_error_inode(inode, __func__, line, block,
122 - "Directory hole found");
123 - return ERR_PTR(-EIO);
125 + bh = ext4_bread(NULL, inode, block, 0);
127 __ext4_warning(inode->i_sb, __func__, line,
128 - "error reading directory block "
129 - "(ino %lu, block %lu)", inode->i_ino,
130 + "error %ld reading directory block "
131 + "(ino %lu, block %lu)", PTR_ERR(bh), inode->i_ino,
132 (unsigned long) block);
133 - return ERR_PTR(err);
138 + ext4_error_inode(inode, __func__, line, block, "Directory hole found");
139 + return ERR_PTR(-EIO);
141 dirent = (struct ext4_dir_entry *) bh->b_data;
142 /* Determine whether or not we have an index block */
143 @@ -640,7 +640,9 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
144 u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash;
146 printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range);
147 - if (!(bh = ext4_bread (NULL,dir, block, 0,&err))) continue;
148 + bh = ext4_bread(NULL,dir, block, 0);
149 + if (!bh || IS_ERR(bh))
152 dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1):
153 dx_show_leaf(hinfo, (struct ext4_dir_entry_2 *) bh->b_data, blocksize, 0);
154 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
155 index 0b28b36..896e452 100644
156 --- a/fs/ext4/super.c
157 +++ b/fs/ext4/super.c
158 @@ -5305,7 +5305,6 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
160 struct inode *inode = sb_dqopt(sb)->files[type];
161 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
163 int offset = off & (sb->s_blocksize - 1);
166 @@ -5320,9 +5319,9 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
168 tocopy = sb->s_blocksize - offset < toread ?
169 sb->s_blocksize - offset : toread;
170 - bh = ext4_bread(NULL, inode, blk, 0, &err);
173 + bh = ext4_bread(NULL, inode, blk, 0);
175 + return PTR_ERR(bh);
176 if (!bh) /* A hole? */
177 memset(data, 0, tocopy);
179 @@ -5343,8 +5342,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
181 struct inode *inode = sb_dqopt(sb)->files[type];
182 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
184 - int offset = off & (sb->s_blocksize - 1);
185 + int err, offset = off & (sb->s_blocksize - 1);
186 struct buffer_head *bh;
187 handle_t *handle = journal_current_handle();
189 @@ -5365,14 +5363,16 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
193 - bh = ext4_bread(handle, inode, blk, 1, &err);
194 + bh = ext4_bread(handle, inode, blk, 1);
196 + return PTR_ERR(bh);
199 BUFFER_TRACE(bh, "get write access");
200 err = ext4_journal_get_write_access(handle, bh);
207 memcpy(bh->b_data+offset, data, len);
208 @@ -5381,8 +5381,6 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
209 err = ext4_handle_dirty_metadata(handle, NULL, bh);
214 if (inode->i_size < off + len) {
215 i_size_write(inode, off + len);
216 EXT4_I(inode)->i_disksize = inode->i_size;