@@ -266,13 +266,20 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)
266266 folio_end_read (folio , !(v & BIT (EROFS_ONLINEFOLIO_EIO )));
267267}
268268
269+ struct erofs_iomap_iter_ctx {
270+ struct page * page ;
271+ void * base ;
272+ };
273+
269274static int erofs_iomap_begin (struct inode * inode , loff_t offset , loff_t length ,
270275 unsigned int flags , struct iomap * iomap , struct iomap * srcmap )
271276{
272- int ret ;
277+ struct iomap_iter * iter = container_of (iomap , struct iomap_iter , iomap );
278+ struct erofs_iomap_iter_ctx * ctx = iter -> private ;
273279 struct super_block * sb = inode -> i_sb ;
274280 struct erofs_map_blocks map ;
275281 struct erofs_map_dev mdev ;
282+ int ret ;
276283
277284 map .m_la = offset ;
278285 map .m_llen = length ;
@@ -283,7 +290,6 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
283290 iomap -> offset = map .m_la ;
284291 iomap -> length = map .m_llen ;
285292 iomap -> flags = 0 ;
286- iomap -> private = NULL ;
287293 iomap -> addr = IOMAP_NULL_ADDR ;
288294 if (!(map .m_flags & EROFS_MAP_MAPPED )) {
289295 iomap -> type = IOMAP_HOLE ;
@@ -309,16 +315,20 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
309315 }
310316
311317 if (map .m_flags & EROFS_MAP_META ) {
312- void * ptr ;
313- struct erofs_buf buf = __EROFS_BUF_INITIALIZER ;
314-
315318 iomap -> type = IOMAP_INLINE ;
316- ptr = erofs_read_metabuf (& buf , sb , map .m_pa ,
317- erofs_inode_in_metabox (inode ));
318- if (IS_ERR (ptr ))
319- return PTR_ERR (ptr );
320- iomap -> inline_data = ptr ;
321- iomap -> private = buf .base ;
319+ /* read context should read the inlined data */
320+ if (ctx ) {
321+ struct erofs_buf buf = __EROFS_BUF_INITIALIZER ;
322+ void * ptr ;
323+
324+ ptr = erofs_read_metabuf (& buf , sb , map .m_pa ,
325+ erofs_inode_in_metabox (inode ));
326+ if (IS_ERR (ptr ))
327+ return PTR_ERR (ptr );
328+ iomap -> inline_data = ptr ;
329+ ctx -> page = buf .page ;
330+ ctx -> base = buf .base ;
331+ }
322332 } else {
323333 iomap -> type = IOMAP_MAPPED ;
324334 }
@@ -328,18 +338,18 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
328338static int erofs_iomap_end (struct inode * inode , loff_t pos , loff_t length ,
329339 ssize_t written , unsigned int flags , struct iomap * iomap )
330340{
331- void * ptr = iomap -> private ;
341+ struct iomap_iter * iter = container_of (iomap , struct iomap_iter , iomap );
342+ struct erofs_iomap_iter_ctx * ctx = iter -> private ;
332343
333- if (ptr ) {
344+ if (ctx && ctx -> base ) {
334345 struct erofs_buf buf = {
335- .page = kmap_to_page ( ptr ) ,
336- .base = ptr ,
346+ .page = ctx -> page ,
347+ .base = ctx -> base ,
337348 };
338349
339350 DBG_BUGON (iomap -> type != IOMAP_INLINE );
340351 erofs_put_metabuf (& buf );
341- } else {
342- DBG_BUGON (iomap -> type == IOMAP_INLINE );
352+ ctx -> base = NULL ;
343353 }
344354 return written ;
345355}
@@ -369,18 +379,30 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
369379 */
370380static int erofs_read_folio (struct file * file , struct folio * folio )
371381{
382+ struct iomap_read_folio_ctx read_ctx = {
383+ .ops = & iomap_bio_read_ops ,
384+ .cur_folio = folio ,
385+ };
386+ struct erofs_iomap_iter_ctx iter_ctx = {};
387+
372388 trace_erofs_read_folio (folio , true);
373389
374- iomap_bio_read_folio ( folio , & erofs_iomap_ops );
390+ iomap_read_folio ( & erofs_iomap_ops , & read_ctx , & iter_ctx );
375391 return 0 ;
376392}
377393
378394static void erofs_readahead (struct readahead_control * rac )
379395{
396+ struct iomap_read_folio_ctx read_ctx = {
397+ .ops = & iomap_bio_read_ops ,
398+ .rac = rac ,
399+ };
400+ struct erofs_iomap_iter_ctx iter_ctx = {};
401+
380402 trace_erofs_readahead (rac -> mapping -> host , readahead_index (rac ),
381403 readahead_count (rac ), true);
382404
383- iomap_bio_readahead ( rac , & erofs_iomap_ops );
405+ iomap_readahead ( & erofs_iomap_ops , & read_ctx , & iter_ctx );
384406}
385407
386408static sector_t erofs_bmap (struct address_space * mapping , sector_t block )
@@ -400,9 +422,12 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
400422 if (IS_DAX (inode ))
401423 return dax_iomap_rw (iocb , to , & erofs_iomap_ops );
402424#endif
403- if ((iocb -> ki_flags & IOCB_DIRECT ) && inode -> i_sb -> s_bdev )
425+ if ((iocb -> ki_flags & IOCB_DIRECT ) && inode -> i_sb -> s_bdev ) {
426+ struct erofs_iomap_iter_ctx iter_ctx = {};
427+
404428 return iomap_dio_rw (iocb , to , & erofs_iomap_ops ,
405- NULL , 0 , NULL , 0 );
429+ NULL , 0 , & iter_ctx , 0 );
430+ }
406431 return filemap_read (iocb , to , 0 );
407432}
408433
0 commit comments