From patchwork Wed Sep 5 13:57:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10588931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF1F15A4 for ; Wed, 5 Sep 2018 13:58:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB73D2A21A for ; Wed, 5 Sep 2018 13:58:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE7E82A21C; Wed, 5 Sep 2018 13:58:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68D292A21A for ; Wed, 5 Sep 2018 13:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727682AbeIES23 (ORCPT ); Wed, 5 Sep 2018 14:28:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57274 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727669AbeIES23 (ORCPT ); Wed, 5 Sep 2018 14:28:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBE3FDFDD; Wed, 5 Sep 2018 13:58:08 +0000 (UTC) Received: from odin.usersys.redhat.com (ovpn-204-31.brq.redhat.com [10.40.204.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB3581003218; Wed, 5 Sep 2018 13:58:07 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: hch@lst.de, sandeen@redhat.com, david@fromorbit.com Subject: [PATCH 1/2] fs: Replace direct ->bmap calls by bmap() Date: Wed, 5 Sep 2018 15:57:47 +0200 Message-Id: <20180905135748.30098-2-cmaiolino@redhat.com> In-Reply-To: <20180905135748.30098-1-cmaiolino@redhat.com> References: <20180905135748.30098-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 05 Sep 2018 13:58:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 05 Sep 2018 13:58:08 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cmaiolino@redhat.com' RCPT:'' Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Prepare the field to use ->fiemap for FIBMAP ioctl Signed-off-by: Carlos Maiolino --- fs/cachefiles/rdwr.c | 5 ++--- fs/ecryptfs/mmap.c | 5 ++--- fs/ioctl.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index 40f7595aad10..186e203d64a7 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -435,7 +435,7 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op, block0 = page->index; block0 <<= shift; - block = inode->i_mapping->a_ops->bmap(inode->i_mapping, block0); + block = bmap(inode, block0); _debug("%llx -> %llx", (unsigned long long) block0, (unsigned long long) block); @@ -737,8 +737,7 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op, block0 = page->index; block0 <<= shift; - block = inode->i_mapping->a_ops->bmap(inode->i_mapping, - block0); + block = bmap(inode, block0); _debug("%llx -> %llx", (unsigned long long) block0, (unsigned long long) block); diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index cdf358b209d9..16626fce5754 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -544,9 +544,8 @@ static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block) inode = (struct inode *)mapping->host; lower_inode = ecryptfs_inode_to_lower(inode); - if (lower_inode->i_mapping->a_ops->bmap) - rc = lower_inode->i_mapping->a_ops->bmap(lower_inode->i_mapping, - block); + + rc = bmap(lower_inode, block); return rc; } diff --git a/fs/ioctl.c b/fs/ioctl.c index 3212c29235ce..413585d58415 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -53,19 +53,21 @@ EXPORT_SYMBOL(vfs_ioctl); static int ioctl_fibmap(struct file *filp, int __user *p) { - struct address_space *mapping = filp->f_mapping; + struct inode *inode = filp->f_inode; int res, block; - /* do we support this mess? */ - if (!mapping->a_ops->bmap) - return -EINVAL; if (!capable(CAP_SYS_RAWIO)) return -EPERM; res = get_user(block, p); if (res) return res; - res = mapping->a_ops->bmap(mapping, block); - return put_user(res, p); + + res = bmap(inode, block); + + if (res) + return put_user(res, p); + else + return -EINVAL; } /** From patchwork Wed Sep 5 13:57:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10588937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CC8D5A4 for ; Wed, 5 Sep 2018 13:58:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 696692A218 for ; Wed, 5 Sep 2018 13:58:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D79E2A21B; Wed, 5 Sep 2018 13:58:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F31252A21D for ; Wed, 5 Sep 2018 13:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727687AbeIES2d (ORCPT ); Wed, 5 Sep 2018 14:28:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58264 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727308AbeIES2d (ORCPT ); Wed, 5 Sep 2018 14:28:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4154C40216E3; Wed, 5 Sep 2018 13:58:12 +0000 (UTC) Received: from odin.usersys.redhat.com (ovpn-204-31.brq.redhat.com [10.40.204.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CE2D112D180; Wed, 5 Sep 2018 13:58:10 +0000 (UTC) From: Carlos Maiolino 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 Message-Id: <20180905135748.30098-3-cmaiolino@redhat.com> In-Reply-To: <20180905135748.30098-1-cmaiolino@redhat.com> References: <20180905135748.30098-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 05 Sep 2018 13:58:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 05 Sep 2018 13:58:12 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cmaiolino@redhat.com' RCPT:'' Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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)