Skip to content

Commit eadcd6b

Browse files
committed
erofs: add fiemap support with iomap
This adds fiemap support for both uncompressed files and compressed files by using iomap infrastructure. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent d95ae5e commit eadcd6b

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

fs/erofs/data.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "internal.h"
77
#include <linux/prefetch.h>
8-
#include <linux/iomap.h>
98
#include <linux/dax.h>
109
#include <trace/events/erofs.h>
1110

@@ -152,6 +151,20 @@ static const struct iomap_ops erofs_iomap_ops = {
152151
.iomap_end = erofs_iomap_end,
153152
};
154153

154+
int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
155+
u64 start, u64 len)
156+
{
157+
if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) {
158+
#ifdef CONFIG_EROFS_FS_ZIP
159+
return iomap_fiemap(inode, fieinfo, start, len,
160+
&z_erofs_iomap_report_ops);
161+
#else
162+
return -EOPNOTSUPP;
163+
#endif
164+
}
165+
return iomap_fiemap(inode, fieinfo, start, len, &erofs_iomap_ops);
166+
}
167+
155168
/*
156169
* since we dont have write or truncate flows, so no inode
157170
* locking needs to be held at the moment.

fs/erofs/inode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ const struct inode_operations erofs_generic_iops = {
365365
.getattr = erofs_getattr,
366366
.listxattr = erofs_listxattr,
367367
.get_acl = erofs_get_acl,
368+
.fiemap = erofs_fiemap,
368369
};
369370

370371
const struct inode_operations erofs_symlink_iops = {

fs/erofs/internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/magic.h>
1616
#include <linux/slab.h>
1717
#include <linux/vmalloc.h>
18+
#include <linux/iomap.h>
1819
#include "erofs_fs.h"
1920

2021
/* redefine pr_fmt "erofs: " */
@@ -363,6 +364,8 @@ struct erofs_map_blocks {
363364
#define EROFS_GET_BLOCKS_FIEMAP 0x0002
364365

365366
/* zmap.c */
367+
extern const struct iomap_ops z_erofs_iomap_report_ops;
368+
366369
#ifdef CONFIG_EROFS_FS_ZIP
367370
int z_erofs_fill_inode(struct inode *inode);
368371
int z_erofs_map_blocks_iter(struct inode *inode,
@@ -381,6 +384,8 @@ static inline int z_erofs_map_blocks_iter(struct inode *inode,
381384
/* data.c */
382385
extern const struct file_operations erofs_file_fops;
383386
struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
387+
int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
388+
u64 start, u64 len);
384389

385390
/* inode.c */
386391
static inline unsigned long erofs_inode_hash(erofs_nid_t nid)

fs/erofs/namei.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,5 @@ const struct inode_operations erofs_dir_iops = {
245245
.getattr = erofs_getattr,
246246
.listxattr = erofs_listxattr,
247247
.get_acl = erofs_get_acl,
248+
.fiemap = erofs_fiemap,
248249
};

fs/erofs/zmap.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,41 @@ int z_erofs_map_blocks_iter(struct inode *inode,
675675
DBG_BUGON(err < 0 && err != -ENOMEM);
676676
return err;
677677
}
678+
679+
static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset,
680+
loff_t length, unsigned int flags,
681+
struct iomap *iomap, struct iomap *srcmap)
682+
{
683+
int ret;
684+
struct erofs_map_blocks map = { .m_la = offset };
685+
686+
ret = z_erofs_map_blocks_iter(inode, &map, EROFS_GET_BLOCKS_FIEMAP);
687+
if (map.mpage)
688+
put_page(map.mpage);
689+
if (ret < 0)
690+
return ret;
691+
692+
iomap->bdev = inode->i_sb->s_bdev;
693+
iomap->offset = map.m_la;
694+
iomap->length = map.m_llen;
695+
if (map.m_flags & EROFS_MAP_MAPPED) {
696+
iomap->type = IOMAP_MAPPED;
697+
iomap->addr = map.m_pa;
698+
} else {
699+
iomap->type = IOMAP_HOLE;
700+
iomap->addr = IOMAP_NULL_ADDR;
701+
/*
702+
* No strict rule how to describe extents for post EOF, yet
703+
* we need do like below. Otherwise, iomap itself will get
704+
* into an endless loop on post EOF.
705+
*/
706+
if (iomap->offset >= inode->i_size)
707+
iomap->length = length + map.m_la - offset;
708+
}
709+
iomap->flags = 0;
710+
return 0;
711+
}
712+
713+
const struct iomap_ops z_erofs_iomap_report_ops = {
714+
.iomap_begin = z_erofs_iomap_begin_report,
715+
};

0 commit comments

Comments
 (0)