From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com ([209.132.183.28]:57418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbeLEJSJ (ORCPT ); Wed, 5 Dec 2018 04:18:09 -0500 From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, adilger@dilger.ca, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 08/10 V2] fiemap: Use a callback to fill fiemap extents Date: Wed, 5 Dec 2018 10:17:26 +0100 Message-Id: <20181205091728.29903-9-cmaiolino@redhat.com> In-Reply-To: <20181205091728.29903-1-cmaiolino@redhat.com> References: <20181205091728.29903-1-cmaiolino@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: As a goal to enable fiemap infrastructure to be used by fibmap too, we need a way to use different helpers to fill extent data, depending on its usage. One helper to fill extent data stored in user address space (used in fiemap), and another fo fill extent data stored in kernel address space (will be used in fibmap). This patch sets up the usage of a callback to be used to fill in the extents. It transforms the current fiemap_fill_next_extent, into a simple helper to call the callback, avoiding unneeded changes on any filesystem, and reutilizes the original function as the callback used by FIEMAP. V2: - Now based on the rework on fiemap_extent_info (previous was based on fiemap_ctx) Signed-off-by: Carlos Maiolino --- fs/ioctl.c | 39 +++++++++++++++++++++++---------------- include/linux/fs.h | 7 +++++++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index a8eae8916e01..6086978fe01e 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -75,25 +75,10 @@ static int ioctl_fibmap(struct file *filp, int __user *p) return error; } -/** - * fiemap_fill_next_extent - Fiemap helper function - * @fieinfo: Fiemap context passed into ->fiemap - * @logical: Extent logical start offset, in bytes - * @phys: Extent physical start offset, in bytes - * @len: Extent length, in bytes - * @flags: FIEMAP_EXTENT flags that describe this extent - * - * Called from file system ->fiemap callback. Will populate extent - * info as passed in via arguments and copy to user memory. On - * success, extent count on fieinfo is incremented. - * - * Returns 0 on success, -errno on error, 1 if this was the last - * extent that will fit in user array. - */ #define SET_UNKNOWN_FLAGS (FIEMAP_EXTENT_DELALLOC) #define SET_NO_UNMOUNTED_IO_FLAGS (FIEMAP_EXTENT_DATA_ENCRYPTED) #define SET_NOT_ALIGNED_FLAGS (FIEMAP_EXTENT_DATA_TAIL|FIEMAP_EXTENT_DATA_INLINE) -int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, +int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, u64 phys, u64 len, u32 flags) { struct fiemap_extent extent; @@ -130,6 +115,27 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, return 1; return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; } + +/** + * fiemap_fill_next_extent - Fiemap helper function + * @fieinfo: Fiemap context passed into ->fiemap + * @logical: Extent logical start offset, in bytes + * @phys: Extent physical start offset, in bytes + * @len: Extent length, in bytes + * @flags: FIEMAP_EXTENT flags that describe this extent + * + * Called from file system ->fiemap callback. Will populate extent + * info as passed in via arguments and copy to user memory. On + * success, extent count on fieinfo is incremented. + * + * Returns 0 on success, -errno on error, 1 if this was the last + * extent that will fit in user array. + */ +int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, + u64 phys, u64 len, u32 flags) +{ + return fieinfo->fi_cb(fieinfo, logical, phys, len, flags); +} EXPORT_SYMBOL(fiemap_fill_next_extent); /** @@ -210,6 +216,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg) fieinfo.fi_extents_start = ufiemap->fm_extents; fieinfo.fi_start = fiemap.fm_start; fieinfo.fi_len = len; + fieinfo.fi_cb = fiemap_fill_user_extent; if (fiemap.fm_extent_count != 0 && !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start, diff --git a/include/linux/fs.h b/include/linux/fs.h index 16a58dfe09cc..7a434979201c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -64,6 +64,7 @@ struct fscrypt_operations; struct fs_context; struct fs_parameter_description; struct fsinfo_kparams; +struct fiemap_extent_info; enum fsinfo_attribute; extern void __init inode_init(void); @@ -1695,6 +1696,10 @@ extern bool may_open_dev(const struct path *path); /* * VFS FS_IOC_FIEMAP helper definitions. */ + +typedef int (*fiemap_fill_cb)(struct fiemap_extent_info *fieinfo, u64 logical, + u64 phys, u64 len, u32 flags); + struct fiemap_extent_info { unsigned int fi_flags; /* Flags as passed from user */ u64 fi_start; @@ -1703,7 +1708,9 @@ struct fiemap_extent_info { unsigned int fi_extents_max; /* Size of fiemap_extent array */ void *fi_extents_start; /* Start of fiemap_extent array */ + fiemap_fill_cb fi_cb; }; + int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, u64 phys, u64 len, u32 flags); int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); -- 2.17.2