From patchwork Fri May 18 16:48:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10411629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2957E601F9 for ; Fri, 18 May 2018 17:01:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 193D6289F6 for ; Fri, 18 May 2018 17:01:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DCAD28A0D; Fri, 18 May 2018 17:01:48 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 AC413289F6 for ; Fri, 18 May 2018 17:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752375AbeERRBo (ORCPT ); Fri, 18 May 2018 13:01:44 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:49940 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752204AbeERQtP (ORCPT ); Fri, 18 May 2018 12:49:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6+RgIQxjxnUBcColKSeMd24PgiZ+EX6nOTCIPCUlY04=; b=oNL4/iJjeuX2s1LOGNXYJ6h9u oBIQdi3HKUE6WC4pCPF797TeTa+Lual7Gvs4rxZWq9cUkbxTLXWqTMLgNJukkCjIijlFLV2K6nieU oNZMc3BKAfIM+n0IaAlEyDRBoR5ZN3G8kohhgj3LwXugfUp9FQNnS6gulmWxTkzV69r16n5F3AYP1 vkSZWBSkLlIZ9gc8c+xcBStXzoEQh89J6etUZMu/muem+Huw28bJpmdrrcTX6IWc9uVMMJD235uVc gCx2/JHfYFlxNLneCbz+yZeBZ2d5tlv5laqH+e7AVFQnJ9LoONY3rCFTmizM6aL9f99lUFGvFhfaz +LjeOx0xw==; Received: from 80-109-164-210.cable.dynamic.surfer.at ([80.109.164.210] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fJiZ8-0006Yv-5v; Fri, 18 May 2018 16:49:14 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 14/34] iomap: add an iomap-based bmap implementation Date: Fri, 18 May 2018 18:48:10 +0200 Message-Id: <20180518164830.1552-15-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518164830.1552-1-hch@lst.de> References: <20180518164830.1552-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds a simple iomap-based implementation of the legacy ->bmap interface. Note that we can't easily add checks for rt or reflink files, so these will have to remain in the callers. This interface just needs to die.. Signed-off-by: Christoph Hellwig --- fs/iomap.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/iomap.h | 3 +++ 2 files changed, 37 insertions(+) diff --git a/fs/iomap.c b/fs/iomap.c index 44259eadb69d..7c1b071d115c 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1419,3 +1419,37 @@ int iomap_swapfile_activate(struct swap_info_struct *sis, } EXPORT_SYMBOL_GPL(iomap_swapfile_activate); #endif /* CONFIG_SWAP */ + +static loff_t +iomap_bmap_actor(struct inode *inode, loff_t pos, loff_t length, + void *data, struct iomap *iomap) +{ + sector_t *bno = data, addr; + + if (iomap->type == IOMAP_MAPPED) { + addr = (pos - iomap->offset + iomap->addr) >> inode->i_blkbits; + if (addr > INT_MAX) + WARN(1, "would truncate bmap result\n"); + else + *bno = addr; + } + return 0; +} + +/* legacy ->bmap interface. 0 is the error return (!) */ +sector_t +iomap_bmap(struct address_space *mapping, sector_t bno, + const struct iomap_ops *ops) +{ + struct inode *inode = mapping->host; + loff_t pos = bno >> inode->i_blkbits; + unsigned blocksize = i_blocksize(inode); + + if (filemap_write_and_wait(mapping)) + return 0; + + bno = 0; + iomap_apply(inode, pos, blocksize, 0, ops, &bno, iomap_bmap_actor); + return bno; +} +EXPORT_SYMBOL_GPL(iomap_bmap); diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 819e0cd2a950..a044a824da85 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -4,6 +4,7 @@ #include +struct address_space; struct fiemap_extent_info; struct inode; struct iov_iter; @@ -100,6 +101,8 @@ loff_t iomap_seek_hole(struct inode *inode, loff_t offset, const struct iomap_ops *ops); loff_t iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops); +sector_t iomap_bmap(struct address_space *mapping, sector_t bno, + const struct iomap_ops *ops); /* * Flags for direct I/O ->end_io: