From: Carlos Maiolino <cmaiolino@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: hch@lst.de, sandeen@redhat.com, david@fromorbit.com
Subject: [PATCH 2/2] Use fiemap internal infra-structure to handle FIBMAP
Date: Wed, 5 Sep 2018 15:57:48 +0200 [thread overview]
Message-ID: <20180905135748.30098-3-cmaiolino@redhat.com> (raw)
In-Reply-To: <20180905135748.30098-1-cmaiolino@redhat.com>
This patch modifies ioctl_fibmap to use FIEMAP interface internally. The
FIBMAP API is not changed, but now ->bmap can go.
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
fs/inode.c | 38 +++++++++++++++++++++++++++++++++++++-
fs/ioctl.c | 11 +++++++++--
include/uapi/linux/fiemap.h | 1 +
3 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index 41812a3e829e..07befc5f253b 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1588,9 +1588,45 @@ EXPORT_SYMBOL(iput);
*/
sector_t bmap(struct inode *inode, sector_t block)
{
+
+ struct fiemap_extent_info fieinfo = { 0, };
+ struct fiemap_extent fextent;
+ u64 start = block << inode->i_blkbits;
+ int error;
sector_t res = 0;
- if (inode->i_mapping->a_ops->bmap)
+
+ if (inode->i_op->fiemap) {
+ fextent.fe_logical = 0;
+ fextent.fe_physical = 0;
+ fieinfo.fi_flags = FIEMAP_KERNEL_FIBMAP;
+ fieinfo.fi_extents_max = 1;
+ fieinfo.fi_extents_start = (__force struct fiemap_extent __user *) &fextent;
+
+ error = inode->i_op->fiemap(inode, &fieinfo, start, 1);
+
+ /* FIBMAP expect a zero return for error */
+ if (error)
+ goto out;
+
+ /*
+ * Fiemap implementation of some filesystems will return the
+ * extent map beginning at the requested offset
+ * (fextent.fi_logical == start), while other FSes will return
+ * the beginning of the extent at fextent.fe_logical, even if
+ * the requested offset is somehwere in the middle of the
+ * extent. We must be sure to return the correct block block
+ * here in both cases.
+ */
+ if (fextent.fe_logical != start)
+ res = (fextent.fe_physical + start) >> inode->i_blkbits;
+ else
+ res = fextent.fe_physical >> inode->i_blkbits;
+
+ } else if (inode->i_mapping->a_ops->bmap) {
res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block);
+ }
+
+out:
return res;
}
EXPORT_SYMBOL(bmap);
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 413585d58415..58de1dd507b1 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -117,8 +117,14 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
extent.fe_flags = flags;
dest += fieinfo->fi_extents_mapped;
- if (copy_to_user(dest, &extent, sizeof(extent)))
- return -EFAULT;
+
+ if (fieinfo->fi_flags & FIEMAP_KERNEL_FIBMAP) {
+ memcpy((__force struct fiemap_extent *)dest, &extent,
+ sizeof(extent));
+ } else {
+ if (copy_to_user(dest, &extent, sizeof(extent)))
+ return -EFAULT;
+ }
fieinfo->fi_extents_mapped++;
if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max)
@@ -146,6 +152,7 @@ int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags)
u32 incompat_flags;
incompat_flags = fieinfo->fi_flags & ~(FIEMAP_FLAGS_COMPAT & fs_flags);
+ incompat_flags &= ~(FIEMAP_KERNEL_FIBMAP);
if (incompat_flags) {
fieinfo->fi_flags = incompat_flags;
return -EBADR;
diff --git a/include/uapi/linux/fiemap.h b/include/uapi/linux/fiemap.h
index 8c0bc24d5d95..7064a3fa5421 100644
--- a/include/uapi/linux/fiemap.h
+++ b/include/uapi/linux/fiemap.h
@@ -42,6 +42,7 @@ struct fiemap {
#define FIEMAP_FLAG_SYNC 0x00000001 /* sync file data before map */
#define FIEMAP_FLAG_XATTR 0x00000002 /* map extended attribute tree */
#define FIEMAP_FLAG_CACHE 0x00000004 /* request caching of the extents */
+#define FIEMAP_KERNEL_FIBMAP 0x00000008 /* Use FIEMAP for FIBMAP */
#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
--
2.14.4
next prev parent reply other threads:[~2018-09-05 18:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-05 13:57 [PATCH RFC 0/2] ->bmap interface retirement Carlos Maiolino
2018-09-05 13:57 ` [PATCH 1/2] fs: Replace direct ->bmap calls by bmap() Carlos Maiolino
2018-09-05 14:23 ` Eric Sandeen
2018-09-05 18:55 ` Christoph Hellwig
2018-09-06 8:04 ` Carlos Maiolino
2018-09-06 8:03 ` Carlos Maiolino
2018-09-05 13:57 ` Carlos Maiolino [this message]
2018-09-05 14:31 ` [PATCH 2/2] Use fiemap internal infra-structure to handle FIBMAP Matthew Wilcox
2018-09-05 18:56 ` Christoph Hellwig
2018-09-06 8:31 ` Carlos Maiolino
2018-09-10 7:50 ` Christoph Hellwig
2018-09-10 10:31 ` Carlos Maiolino
2018-09-26 13:34 ` Carlos Maiolino
2018-09-06 8:18 ` Carlos Maiolino
2018-09-05 14:40 ` Eric Sandeen
2018-09-06 8:12 ` Carlos Maiolino
2018-09-06 15:53 ` Eric Sandeen
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=20180905135748.30098-3-cmaiolino@redhat.com \
--to=cmaiolino@redhat.com \
--cc=david@fromorbit.com \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sandeen@redhat.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).