From patchwork Tue Oct 30 13:18:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 10660917 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 DAD931734 for ; Tue, 30 Oct 2018 13:19:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4B0C2A3CD for ; Tue, 30 Oct 2018 13:19:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C93892A3EB; Tue, 30 Oct 2018 13:19:30 +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 698D42A3CD for ; Tue, 30 Oct 2018 13:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727965AbeJ3WMx (ORCPT ); Tue, 30 Oct 2018 18:12:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43598 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727876AbeJ3WMx (ORCPT ); Tue, 30 Oct 2018 18:12:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51A3D30821F4; Tue, 30 Oct 2018 13:19:28 +0000 (UTC) Received: from odin.usersys.redhat.com (unknown [10.40.205.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2A0E5DD6B; Tue, 30 Oct 2018 13:19:26 +0000 (UTC) From: Carlos Maiolino To: linux-fsdevel@vger.kernel.org Cc: sandeen@redhat.com, hch@lst.de, david@fromorbit.com, darrick.wong@oracle.com Subject: [PATCH 18/20] Use FIEMAP for FIBMAP calls Date: Tue, 30 Oct 2018 14:18:21 +0100 Message-Id: <20181030131823.29040-19-cmaiolino@redhat.com> In-Reply-To: <20181030131823.29040-1-cmaiolino@redhat.com> References: <20181030131823.29040-1-cmaiolino@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 30 Oct 2018 13:19:28 +0000 (UTC) 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 Enables the usage of FIEMAP ioctl infrastructure to handle FIBMAP calls, from this point, ->bmap() methods can start to be removed. Signed-off-by: Carlos Maiolino --- This patch can be improved, since fiemap_fill_kernel_extent and fiemap_fill_usr_extent shares a lot of common code, which still is WIP. fs/inode.c | 35 ++++++++++++++++++++++++++++++----- fs/ioctl.c | 31 +++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index d09a6f4f0335..389c2165959c 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1591,11 +1591,36 @@ EXPORT_SYMBOL(iput); */ int bmap(struct inode *inode, sector_t *block) { - if (!inode->i_mapping->a_ops->bmap) - return -EINVAL; - - *block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block); - return 0; + struct fiemap_ctx f_ctx; + struct fiemap_extent fextent; + u64 start = *block << inode->i_blkbits; + int error = -EINVAL; + + if (inode->i_op->fiemap) { + fextent.fe_logical = 0; + fextent.fe_physical = 0; + f_ctx.fc_extents_max = 1; + f_ctx.fc_extents_mapped = 0; + f_ctx.fc_data = &fextent; + f_ctx.fc_start = start; + f_ctx.fc_len = 1; + f_ctx.fc_flags = 0; + f_ctx.fc_cb = fiemap_fill_kernel_extent; + + error = inode->i_op->fiemap(inode, &f_ctx); + + if (error) + goto out; + + *block = (fextent.fe_physical + + (start - fextent.fe_logical)) >> inode->i_blkbits; + + } else if (inode->i_mapping->a_ops->bmap) { + *block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block); + error = 0; + } +out: + return error; } EXPORT_SYMBOL(bmap); diff --git a/fs/ioctl.c b/fs/ioctl.c index 71d11201a06b..dce710699b82 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -113,6 +113,37 @@ int fiemap_fill_usr_extent(struct fiemap_ctx *f_ctx, u64 logical, return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; } +int fiemap_fill_kernel_extent(struct fiemap_ctx *f_ctx, u64 logical, + u64 phys, u64 len, u32 flags) +{ + struct fiemap_extent *extent = f_ctx->fc_data; + + if (f_ctx->fc_extents_max == 0) { + f_ctx->fc_extents_mapped++; + return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; + } + + if (f_ctx->fc_extents_mapped >= f_ctx->fc_extents_max) + return 1; + + if (flags & SET_UNKNOWN_FLAGS) + flags |= FIEMAP_EXTENT_UNKNOWN; + if (flags & SET_NO_UNMOUNTED_IO_FLAGS) + flags |= FIEMAP_EXTENT_ENCODED; + if (flags & SET_NOT_ALIGNED_FLAGS) + flags |= FIEMAP_EXTENT_NOT_ALIGNED; + + extent->fe_logical = logical; + extent->fe_physical = phys; + extent->fe_length = len; + extent->fe_flags = flags; + + f_ctx->fc_extents_mapped++; + + if (f_ctx->fc_extents_mapped == f_ctx->fc_extents_max) + return 1; + return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; +} /** * fiemap_fill_next_extent - Fiemap helper function * @fieinfo: Fiemap context passed into ->fiemap diff --git a/include/linux/fs.h b/include/linux/fs.h index 4c6dee908a38..7f623a434cb0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1704,6 +1704,8 @@ struct fiemap_ctx { u64 fc_len; }; +int fiemap_fill_kernel_extent(struct fiemap_ctx *f_ctx, u64 logical, + u64 phys, u64 len, u32 flags); int fiemap_fill_next_extent(struct fiemap_ctx *f_ctx, u64 logical, u64 phys, u64 len, u32 flags); int fiemap_check_flags(struct fiemap_ctx *f_ctx, u32 fs_flags);