@@ -76,6 +76,7 @@ static mempool_t *metapage_mempool;
7676struct meta_anchor {
7777 int mp_count ;
7878 atomic_t io_count ;
79+ blk_status_t status ;
7980 struct metapage * mp [MPS_PER_PAGE ];
8081};
8182
@@ -138,12 +139,16 @@ static inline void inc_io(struct folio *folio)
138139 atomic_inc (& anchor -> io_count );
139140}
140141
141- static inline void dec_io (struct folio * folio , void (* handler ) (struct folio * ))
142+ static inline void dec_io (struct folio * folio , blk_status_t status ,
143+ void (* handler )(struct folio * , blk_status_t ))
142144{
143145 struct meta_anchor * anchor = folio -> private ;
144146
147+ if (anchor -> status == BLK_STS_OK )
148+ anchor -> status = status ;
149+
145150 if (atomic_dec_and_test (& anchor -> io_count ))
146- handler (folio );
151+ handler (folio , anchor -> status );
147152}
148153
149154#else
@@ -168,7 +173,7 @@ static inline void remove_metapage(struct folio *folio, struct metapage *mp)
168173}
169174
170175#define inc_io (folio ) do {} while(0)
171- #define dec_io (folio , handler ) handler(folio)
176+ #define dec_io (folio , status , handler ) handler(folio, status )
172177
173178#endif
174179
@@ -258,23 +263,20 @@ static sector_t metapage_get_blocks(struct inode *inode, sector_t lblock,
258263 return lblock ;
259264}
260265
261- static void last_read_complete (struct folio * folio )
266+ static void last_read_complete (struct folio * folio , blk_status_t status )
262267{
263- if (!folio_test_error (folio ))
264- folio_mark_uptodate (folio );
265- folio_unlock (folio );
268+ if (status )
269+ printk (KERN_ERR "Read error %d at %#llx\n" , status ,
270+ folio_pos (folio ));
271+
272+ folio_end_read (folio , status == 0 );
266273}
267274
268275static void metapage_read_end_io (struct bio * bio )
269276{
270277 struct folio * folio = bio -> bi_private ;
271278
272- if (bio -> bi_status ) {
273- printk (KERN_ERR "metapage_read_end_io: I/O error\n" );
274- folio_set_error (folio );
275- }
276-
277- dec_io (folio , last_read_complete );
279+ dec_io (folio , bio -> bi_status , last_read_complete );
278280 bio_put (bio );
279281}
280282
@@ -300,11 +302,17 @@ static void remove_from_logsync(struct metapage *mp)
300302 LOGSYNC_UNLOCK (log , flags );
301303}
302304
303- static void last_write_complete (struct folio * folio )
305+ static void last_write_complete (struct folio * folio , blk_status_t status )
304306{
305307 struct metapage * mp ;
306308 unsigned int offset ;
307309
310+ if (status ) {
311+ int err = blk_status_to_errno (status );
312+ printk (KERN_ERR "metapage_write_end_io: I/O error\n" );
313+ mapping_set_error (folio -> mapping , err );
314+ }
315+
308316 for (offset = 0 ; offset < PAGE_SIZE ; offset += PSIZE ) {
309317 mp = folio_to_mp (folio , offset );
310318 if (mp && test_bit (META_io , & mp -> flag )) {
@@ -326,12 +334,7 @@ static void metapage_write_end_io(struct bio *bio)
326334
327335 BUG_ON (!folio -> private );
328336
329- if (bio -> bi_status ) {
330- int err = blk_status_to_errno (bio -> bi_status );
331- printk (KERN_ERR "metapage_write_end_io: I/O error\n" );
332- mapping_set_error (folio -> mapping , err );
333- }
334- dec_io (folio , last_write_complete );
337+ dec_io (folio , bio -> bi_status , last_write_complete );
335338 bio_put (bio );
336339}
337340
@@ -454,10 +457,10 @@ static int metapage_write_folio(struct folio *folio,
454457 4 , bio , sizeof (* bio ), 0 );
455458 bio_put (bio );
456459 folio_unlock (folio );
457- dec_io (folio , last_write_complete );
460+ dec_io (folio , BLK_STS_OK , last_write_complete );
458461err_out :
459462 while (bad_blocks -- )
460- dec_io (folio , last_write_complete );
463+ dec_io (folio , BLK_STS_OK , last_write_complete );
461464 return - EIO ;
462465}
463466
0 commit comments