From patchwork Wed May 9 07:48:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10388419 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 0074960170 for ; Wed, 9 May 2018 07:49:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E715728E08 for ; Wed, 9 May 2018 07:49:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBECD28E65; Wed, 9 May 2018 07:49: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=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E64128E08 for ; Wed, 9 May 2018 07:49:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9ED26B035F; Wed, 9 May 2018 03:49:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A26FA6B0361; Wed, 9 May 2018 03:49:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 875B86B0362; Wed, 9 May 2018 03:49:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 41FA46B035F for ; Wed, 9 May 2018 03:49:44 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id 91-v6so3310274plf.6 for ; Wed, 09 May 2018 00:49:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=bA02disUZxHG1YUkESbhX5TEYC+FFvtyifooP5RB/Vk=; b=chjeFd7NVmtZU4cHzeWk7crWVgMCOGK9MN/ZC8EL8CpYjuWr0HIRuLSSDwtChRmYek uts0Yvq19DcroHvqbYYkcpXJ3wRSBQLDtIK4WdryRGRETUwRbG/ChHDmXCNLAW8QGmCW tVzgpsLm8kSAQD4DPSchEAD9Fp6jW5cHiVGwNlLccYZ7wFlVOdzrtaS9TrNp6P1llOAQ IUmDkOsWnvXDRLhzoY8rvR2N6wz8/dwHT1NjbxNS5oBNvOHCesGb874QWxqQMqbMHmSk vZz8irn+J1vMpxtM2Tu5nJOKfNCD1gBXDZnKUhIF3bfle1icYY9foBlWrzNYPt+m1XCV n7Jw== X-Gm-Message-State: ALQs6tAjjfL7B/5xnKFnLb5wuAnqKmudQVZLOlCGn298dO+LAThdfT6A sowJpnVHWSZPex3LVUT6GgX101P3O0F9KUI8csXy+EDT9YfHtzRayC9lMfKdspMeFdcvrA5RDRs 00+bD9QFkZZsmTt58WRmA30RZ5Ad6TfLwiKvqs2oRO5JainHOXItGiaTEw8ZpLaQ= X-Received: by 2002:a63:5fd2:: with SMTP id t201-v6mr35828838pgb.315.1525852183933; Wed, 09 May 2018 00:49:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp0soDdEx86+UW6+FWa19C1WtMBTnyOs9vknugA43Sbscge9fdCZyJer4ogzbEMbQF81P+x X-Received: by 2002:a63:5fd2:: with SMTP id t201-v6mr35828810pgb.315.1525852183093; Wed, 09 May 2018 00:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525852183; cv=none; d=google.com; s=arc-20160816; b=yUvLrvj1x4kgquHXywdRHB75jN2SUh7vOmzc7kd1d7KPNsZnkJil+z2V7fpY4lJDlw Zfn+g//8YlbzY7hRj6Y51va3DpgUrESH8n6EDCIXsS/3fsoFa4HCzoROdfdj3FTlJjd7 znyWL5X1+AUrxZo1pTK/zV+L11xKVkbuJk+bCrjJWDP6kFi8/bB4rG2jVJ2S2AGURtHT lJoOzdUi9dy9dcGODqK0IW1kg1gc3j3Cj2OhFeAdyEVmFkqJA0F8UUpGxNrGQ+xvkK6J GJ9ltWzDrr+KVk2E8v5BVgXYbj5hXW7JBHYwiR/CBjiA+RYbqvWzabqlCcfxluZnsei5 f2dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=bA02disUZxHG1YUkESbhX5TEYC+FFvtyifooP5RB/Vk=; b=O376FSAN9oRnMN1Kin88pb1s3Hy2QYTlswyAaH91caFTBR9cJCCR9F9woLnzJyXf9p pMXDP2L6pomwKM8OzQ0RW+yjznH6pEU3Eiv8L4wZWISI7uzt5yJEc8QUyutY/eR+GAUl LK3ueXkurxVZ+wVPItyqBD8ryPR0tP47zS8sZnIs53CS/XLQg4uW6YoFTbd6dUUbqhYg QwV0uQRVg9WQ+uLXzQGD6XAct6B5rIfvC/R1HV4oNeRzt555ztkbnvRZtO5yo1ieNHhe JEClHyy1n21P/qN1hKFjWIjME//OtGpfEMeltej5hdmLFnn4xx892oy+BEQH4VITHeoK zDyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=jvRKcm4m; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id u89si27125210pfa.234.2018.05.09.00.49.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 00:49:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=jvRKcm4m; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org 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=bA02disUZxHG1YUkESbhX5TEYC+FFvtyifooP5RB/Vk=; b=jvRKcm4mzeK5WH9uWj+eciRTw xJ+OzaukGxAfq642RpkBedMxDg/NxMsIvffZoEC3ctXLs7BwtfKpfz88PCdJDnhbU9O1TMtHGK9ia ga8lWUMOiZEV0KoouR8CekehFawVJSnqqcYTI78XUJWqbLv8nsZ5bOZfJPNIyuFp4dxRTuLsiynOe jfC79AiBrUoJOhJMm8Z4sq7RFZJIXDB7Qs2nfyVcGwL9wl64wO6oFkJeToGGmfLTGx7cI8inLkwCL 1MDyKH3966ZzGxeC7DFN+E2k0cOMtccvgBP2eI6mO1/fbPA5vWBEkXbhWA2AjTgqbf9BXAPu693xe 9pFNuQytQ==; Received: from 213-225-15-246.nat.highway.a1.net ([213.225.15.246] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGJr4-0001hO-2b; Wed, 09 May 2018 07:49:42 +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 19/33] xfs: remove xfs_reflink_find_cow_mapping Date: Wed, 9 May 2018 09:48:16 +0200 Message-Id: <20180509074830.16196-20-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509074830.16196-1-hch@lst.de> References: <20180509074830.16196-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We only have one caller left, and open coding the simple extent list lookup in it allows us to make the code both more understandable and reuse calculations and variables already present. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_aops.c | 17 ++++++++++++----- fs/xfs/xfs_reflink.c | 30 ------------------------------ fs/xfs/xfs_reflink.h | 2 -- fs/xfs/xfs_trace.h | 1 - 4 files changed, 12 insertions(+), 38 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 6ad43829c89a..41616629dd13 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -385,6 +385,7 @@ xfs_map_blocks( ssize_t count = i_blocksize(inode); xfs_fileoff_t offset_fsb, end_fsb; int whichfork = XFS_DATA_FORK; + struct xfs_iext_cursor icur; int error = 0; int nimaps = 1; @@ -396,8 +397,18 @@ xfs_map_blocks( (ip->i_df.if_flags & XFS_IFEXTENTS)); ASSERT(offset <= mp->m_super->s_maxbytes); + if (offset > mp->m_super->s_maxbytes - count) + count = mp->m_super->s_maxbytes - offset; + end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); + offset_fsb = XFS_B_TO_FSBT(mp, offset); + + /* + * Check if this is offset is covered by a COW extents, and if yes use + * it directly instead of looking up anything in the data fork. + */ if (xfs_is_reflink_inode(ip) && - xfs_reflink_find_cow_mapping(ip, offset, imap)) { + xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, imap) && + imap->br_startoff <= offset_fsb) { xfs_iunlock(ip, XFS_ILOCK_SHARED); /* * Truncate can race with writeback since writeback doesn't @@ -417,10 +428,6 @@ xfs_map_blocks( goto done; } - if (offset > mp->m_super->s_maxbytes - count) - count = mp->m_super->s_maxbytes - offset; - end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); - offset_fsb = XFS_B_TO_FSBT(mp, offset); error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, imap, &nimaps, XFS_BMAPI_ENTIRE); if (!nimaps) { diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index cdbd342a5249..3776b7bbd8c6 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -484,36 +484,6 @@ xfs_reflink_allocate_cow( return error; } -/* - * Find the CoW reservation for a given byte offset of a file. - */ -bool -xfs_reflink_find_cow_mapping( - struct xfs_inode *ip, - xfs_off_t offset, - struct xfs_bmbt_irec *imap) -{ - struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK); - xfs_fileoff_t offset_fsb; - struct xfs_bmbt_irec got; - struct xfs_iext_cursor icur; - - ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)); - - if (!xfs_is_reflink_inode(ip)) - return false; - offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); - if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got)) - return false; - if (got.br_startoff > offset_fsb) - return false; - - trace_xfs_reflink_find_cow_mapping(ip, offset, 1, XFS_IO_OVERWRITE, - &got); - *imap = got; - return true; -} - /* * Trim an extent to end at the next CoW reservation past offset_fsb. */ diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index 701487bab468..15a456492667 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -32,8 +32,6 @@ extern int xfs_reflink_allocate_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap, bool *shared, uint *lockmode); extern int xfs_reflink_convert_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); -extern bool xfs_reflink_find_cow_mapping(struct xfs_inode *ip, xfs_off_t offset, - struct xfs_bmbt_irec *imap); extern void xfs_reflink_trim_irec_to_next_cow(struct xfs_inode *ip, xfs_fileoff_t offset_fsb, struct xfs_bmbt_irec *imap); diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 8955254b900e..aa284f840d33 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -3220,7 +3220,6 @@ DEFINE_INODE_IREC_EVENT(xfs_reflink_convert_cow); DEFINE_RW_EVENT(xfs_reflink_reserve_cow); DEFINE_SIMPLE_IO_EVENT(xfs_reflink_bounce_dio_write); -DEFINE_IOMAP_EVENT(xfs_reflink_find_cow_mapping); DEFINE_INODE_IREC_EVENT(xfs_reflink_trim_irec); DEFINE_SIMPLE_IO_EVENT(xfs_reflink_cancel_cow_range);