linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org
Cc: nl6720 <nl6720@gmail.com>,
	Lasse Collin <lasse.collin@tukaani.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] erofs: add fiemap support with iomap
Date: Fri, 13 Aug 2021 13:29:31 +0800	[thread overview]
Message-ID: <20210813052931.203280-3-hsiangkao@linux.alibaba.com> (raw)
In-Reply-To: <20210813052931.203280-1-hsiangkao@linux.alibaba.com>

This adds fiemap support for both uncompressed files and compressed
files by using iomap infrastructure.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/data.c     | 15 ++++++++++++++-
 fs/erofs/inode.c    |  1 +
 fs/erofs/internal.h |  5 +++++
 fs/erofs/namei.c    |  1 +
 fs/erofs/zmap.c     | 38 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index b2a22aabc9bc..09c46fbdb9b2 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -5,7 +5,6 @@
  */
 #include "internal.h"
 #include <linux/prefetch.h>
-#include <linux/iomap.h>
 #include <linux/dax.h>
 #include <trace/events/erofs.h>
 
@@ -152,6 +151,20 @@ static const struct iomap_ops erofs_iomap_ops = {
 	.iomap_end = erofs_iomap_end,
 };
 
+int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		 u64 start, u64 len)
+{
+	if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) {
+#ifdef CONFIG_EROFS_FS_ZIP
+		return iomap_fiemap(inode, fieinfo, start, len,
+				    &z_erofs_iomap_report_ops);
+#else
+		return -EOPNOTSUPP;
+#endif
+	}
+	return iomap_fiemap(inode, fieinfo, start, len, &erofs_iomap_ops);
+}
+
 /*
  * since we dont have write or truncate flows, so no inode
  * locking needs to be held at the moment.
diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 92728da1d206..d13e0709599c 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -365,6 +365,7 @@ const struct inode_operations erofs_generic_iops = {
 	.getattr = erofs_getattr,
 	.listxattr = erofs_listxattr,
 	.get_acl = erofs_get_acl,
+	.fiemap = erofs_fiemap,
 };
 
 const struct inode_operations erofs_symlink_iops = {
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 2a05b09e1c06..ae33a28c8669 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -15,6 +15,7 @@
 #include <linux/magic.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/iomap.h>
 #include "erofs_fs.h"
 
 /* redefine pr_fmt "erofs: " */
@@ -363,6 +364,8 @@ struct erofs_map_blocks {
 #define EROFS_GET_BLOCKS_FIEMAP	0x0002
 
 /* zmap.c */
+extern const struct iomap_ops z_erofs_iomap_report_ops;
+
 #ifdef CONFIG_EROFS_FS_ZIP
 int z_erofs_fill_inode(struct inode *inode);
 int z_erofs_map_blocks_iter(struct inode *inode,
@@ -381,6 +384,8 @@ static inline int z_erofs_map_blocks_iter(struct inode *inode,
 /* data.c */
 extern const struct file_operations erofs_file_fops;
 struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
+int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		 u64 start, u64 len);
 
 /* inode.c */
 static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c
index a8271ce5e13f..8629e616028c 100644
--- a/fs/erofs/namei.c
+++ b/fs/erofs/namei.c
@@ -245,4 +245,5 @@ const struct inode_operations erofs_dir_iops = {
 	.getattr = erofs_getattr,
 	.listxattr = erofs_listxattr,
 	.get_acl = erofs_get_acl,
+	.fiemap = erofs_fiemap,
 };
diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
index 12256ef12819..6af31ef6f13f 100644
--- a/fs/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -673,3 +673,41 @@ int z_erofs_map_blocks_iter(struct inode *inode,
 	DBG_BUGON(err < 0 && err != -ENOMEM);
 	return err;
 }
+
+static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset,
+				loff_t length, unsigned int flags,
+				struct iomap *iomap, struct iomap *srcmap)
+{
+	int ret;
+	struct erofs_map_blocks map = { .m_la = offset };
+
+	ret = z_erofs_map_blocks_iter(inode, &map, EROFS_GET_BLOCKS_FIEMAP);
+	if (map.mpage)
+		put_page(map.mpage);
+	if (ret < 0)
+		return ret;
+
+	iomap->bdev = inode->i_sb->s_bdev;
+	iomap->offset = map.m_la;
+	iomap->length = map.m_llen;
+	if (map.m_flags & EROFS_MAP_MAPPED) {
+		iomap->type = IOMAP_MAPPED;
+		iomap->addr = map.m_pa;
+	} else {
+		iomap->type = IOMAP_HOLE;
+		iomap->addr = IOMAP_NULL_ADDR;
+		/*
+		 * No strict rule how to describe extents for post EOF, yet
+		 * we need do like below. Otherwise, iomap itself will get
+		 * into an endless loop on post EOF.
+		 */
+		if (iomap->offset >= inode->i_size)
+			iomap->length = length + map.m_la - offset;
+	}
+	iomap->flags = 0;
+	return 0;
+}
+
+const struct iomap_ops z_erofs_iomap_report_ops = {
+	.iomap_begin = z_erofs_iomap_begin_report,
+};
-- 
2.24.4


  parent reply	other threads:[~2021-08-13  5:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13  5:29 [PATCH 0/2] " Gao Xiang
2021-08-13  5:29 ` [PATCH 1/2] erofs: add support for the full decompressed length Gao Xiang
2021-08-14 15:27   ` [PATCH v1.1 " Gao Xiang
2021-08-18 14:11     ` Chao Yu
2021-08-18 15:22     ` [PATCH v1.2] " Gao Xiang
2021-08-16 15:38   ` [PATCH 1/2] " Chao Yu
2021-08-17  0:54     ` [PATCH 1/2] erofs: add support for the full decompressed lengthy Gao Xiang
2021-08-13  5:29 ` Gao Xiang [this message]
2021-08-18 14:11   ` [PATCH 2/2] erofs: add fiemap support with iomap Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210813052931.203280-3-hsiangkao@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=lasse.collin@tukaani.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nl6720@gmail.com \
    --subject='Re: [PATCH 2/2] erofs: add fiemap support with iomap' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).