add patch move-error-report-out-of-atomic-context
[ext4-patch-queue.git] / convert-ext4_bread-to-use-the-ERR_PTR-convention
blobf8e9d2fbe1fa3dba57b88967441faa0d5fdfb885
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>
6 ---
7  fs/ext4/dir.c   |  8 +++-----
8  fs/ext4/ext4.h  |  3 +--
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
16 --- a/fs/ext4/dir.c
17 +++ b/fs/ext4/dir.c
18 @@ -151,13 +151,11 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
19                                         &file->f_ra, file,
20                                         index, 1);
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);
24 +                       if (IS_ERR(bh))
25 +                               return PTR_ERR(bh);
26                 }
28 -               /*
29 -                * We ignore I/O errors on directories so users have a chance
30 -                * of recovering data when there's a bad sector
31 -                */
32                 if (!bh) {
33                         if (!dir_has_error) {
34                                 EXT4_ERROR_FILE(file, 0,
35 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
36 index 8009077..ca53bce 100644
37 --- a/fs/ext4/ext4.h
38 +++ b/fs/ext4/ext4.h
39 @@ -2087,8 +2087,7 @@ extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
41  /* inode.c */
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
51 --- a/fs/ext4/inode.c
52 +++ b/fs/ext4/inode.c
53 @@ -791,27 +791,21 @@ errout:
54  }
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)
59  {
60         struct buffer_head *bh;
62 -       *err = 0;
63         bh = ext4_getblk(handle, inode, block, create);
64 -       if (IS_ERR(bh)) {
65 -               *err = PTR_ERR(bh);
66 -               return NULL;
67 -       }
68 -       if (!bh)
69 +       if (IS_ERR(bh))
70                 return bh;
71 -       if (buffer_uptodate(bh))
72 +       if (!bh || buffer_uptodate(bh))
73                 return bh;
74         ll_rw_block(READ | REQ_META | REQ_PRIO, 1, &bh);
75         wait_on_buffer(bh);
76         if (buffer_uptodate(bh))
77                 return bh;
78         put_bh(bh);
79 -       *err = -EIO;
80 -       return NULL;
81 +       return ERR_PTR(-EIO);
82  }
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
87 --- a/fs/ext4/namei.c
88 +++ b/fs/ext4/namei.c
89 @@ -53,7 +53,7 @@ static struct buffer_head *ext4_append(handle_t *handle,
90                                         ext4_lblk_t *block)
91  {
92         struct buffer_head *bh;
93 -       int err = 0;
94 +       int err;
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);
103 -       if (!bh)
104 -               return ERR_PTR(err);
105 +       bh = ext4_bread(handle, inode, *block, 1);
106 +       if (IS_ERR(bh))
107 +               return bh;
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);
119 -       if (!bh) {
120 -               if (err == 0) {
121 -                       ext4_error_inode(inode, __func__, line, block,
122 -                                              "Directory hole found");
123 -                       return ERR_PTR(-EIO);
124 -               }
125 +       bh = ext4_bread(NULL, inode, block, 0);
126 +       if (IS_ERR(bh)) {
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);
135 +               return bh;
136 +       }
137 +       if (!bh) {
138 +               ext4_error_inode(inode, __func__, line, block, "Directory hole found");
139 +               return ERR_PTR(-EIO);
140         }
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;
145                 struct stats stats;
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))
150 +                       continue;
151                 stats = levels?
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);
162 -       int err = 0;
163         int offset = off & (sb->s_blocksize - 1);
164         int tocopy;
165         size_t toread;
166 @@ -5320,9 +5319,9 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
167         while (toread > 0) {
168                 tocopy = sb->s_blocksize - offset < toread ?
169                                 sb->s_blocksize - offset : toread;
170 -               bh = ext4_bread(NULL, inode, blk, 0, &err);
171 -               if (err)
172 -                       return err;
173 +               bh = ext4_bread(NULL, inode, blk, 0);
174 +               if (IS_ERR(bh))
175 +                       return PTR_ERR(bh);
176                 if (!bh)        /* A hole? */
177                         memset(data, 0, tocopy);
178                 else
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);
183 -       int err = 0;
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,
190                 return -EIO;
191         }
193 -       bh = ext4_bread(handle, inode, blk, 1, &err);
194 +       bh = ext4_bread(handle, inode, blk, 1);
195 +       if (IS_ERR(bh))
196 +               return PTR_ERR(bh);
197         if (!bh)
198                 goto out;
199         BUFFER_TRACE(bh, "get write access");
200         err = ext4_journal_get_write_access(handle, bh);
201         if (err) {
202                 brelse(bh);
203 -               goto out;
204 +               return err;
205         }
206         lock_buffer(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);
210         brelse(bh);
211  out:
212 -       if (err)
213 -               return err;
214         if (inode->i_size < off + len) {
215                 i_size_write(inode, off + len);
216                 EXT4_I(inode)->i_disksize = inode->i_size;
217 -- 
218 2.1.0