From patchwork Wed May 23 14:43:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10421645 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 338056032A for ; Wed, 23 May 2018 14:46:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2286628733 for ; Wed, 23 May 2018 14:46:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1783928868; Wed, 23 May 2018 14:46:04 +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=unavailable 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 964E028733 for ; Wed, 23 May 2018 14:46:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D4AA6B027F; Wed, 23 May 2018 10:45:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 00B006B0280; Wed, 23 May 2018 10:45:17 -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 DCABF6B0281; Wed, 23 May 2018 10:45:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 948B46B027F for ; Wed, 23 May 2018 10:45:17 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id t2-v6so558826pgo.0 for ; Wed, 23 May 2018 07:45:17 -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=KMrvDwk8LZ37swu6bibo04GBuXkt0RKEFb1Igq2ys8k=; b=UX7wJGbSkuRRFEmhQBBqyi9oL2/dkDijRbGNb3SYXWr3nppUT04NZWCyhpSax9T5r6 oZhPjwJrWw68tw98SZJdy7Axo6ChwfQmPhiyeaedNGjLVYOXYpJmvuOrN3OsWg7F4Bdv BhT5uUG42t1r5YH/odih13aeREv6aUKyAk6+femj+TA80KupDDlECroDofDS/MhDe0Wj anTEo992ysWWRmKDszYL4T9d5wvLyG9YxnOqWn6lvteEtVZttzwaqonKlpVCG83P9ebt a3m/+MPLU990LxjHDytgrudNBexohXoxwieS7bM36EZa/CCUj+oP+8bcob3Zqjb+cbPG 4HFQ== X-Gm-Message-State: ALKqPweWUNnB7M0ALsbWkpiciBWnUt0yEbxIQTOZ/OxJf3s+Z5S/eR+J +U50UDFuNAU96LHWZ6EeZfqPRgNZAoWBS2L1/ssFlkjcSEWeHQIKHFMzHqo15BRVHUDzlME/NJZ 67Vr5pngKugxj29acZdxiw03Wdw4tSdbLiJIqDDJpzaRjA6nkZekXEbMAZLHBUT8= X-Received: by 2002:a62:3085:: with SMTP id w127-v6mr3214678pfw.224.1527086717225; Wed, 23 May 2018 07:45:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKFG/ky9PNZhlcIEd8cZNvyCmYj8VupaRD2a+oeJPzh/0EYr9y2QjCwx/Qbf7I5yRvHBbV X-Received: by 2002:a62:3085:: with SMTP id w127-v6mr3214617pfw.224.1527086716103; Wed, 23 May 2018 07:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527086716; cv=none; d=google.com; s=arc-20160816; b=Jsk4JfcyKrb8TdnbVVEVTnkzVYpW2Dh9KK5Ls+K45af6N5b7IpIoMDxoJTnMQa+dBC niblpQhVDmEe5lbbGGFmRhWlwVfrSQsnpmYCT6l51kvadBqfPq4kdhgsya/2qC1yDVBI kF0LG146PaGp/MIJ5nLfopXqk9GNNH9uLQJyQxibhcJxO6w+n5E9dTkpaHO3ngnITGEv jDNYuIjaaWS86iScghqo2PC4Od/bWrOM8XXUIMsQQB1QTwfCWkWCUasBErTILIgXJ+7o J6ido6+7xAG7sYXn0tFfO56e//xhkWQ0OUKy2wSN9mRc0CbofRF5iaQz/B4VVaosOqan uNSg== 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=KMrvDwk8LZ37swu6bibo04GBuXkt0RKEFb1Igq2ys8k=; b=PnXZYW+Aag3KX4gRrvCcbJN6aozPr9NvKeBHhaC++wczZYBynRRg99BghnB0c6zu0R oN45joaT3UYe9PITVkJnkoY3oCOlXU4sHMIexBo9/LxO0POgCL+VzOMhO1ELuPLkggu5 irdNRqp88M6dOvc/AOLRUpCT+ZDYlMvXn5HreOHxJ3lB1So177osOqHmunZj6Wlo5L7S quPa97eCtmWZbTqtZL0Gl6xh2LuO9KbKLw7C78AOHCXkNifziPNkBOTB/7wMTq4lpisE Pw88qpuKe5TvPvcF+ID70ioTj4Nird5zrSR1XLJruWEMpU/pnPEx/wvUNwk1aOPUPXfF XS9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=DaNMoGSt; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+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 2-v6si19258755pfk.287.2018.05.23.07.45.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 07:45:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+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=DaNMoGSt; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+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=KMrvDwk8LZ37swu6bibo04GBuXkt0RKEFb1Igq2ys8k=; b=DaNMoGSt/IIMuhwFPONIl89UZ nKsInaTBCoCGbGWaLFNEoot4VnY/FHN6nor67sp5qO3bGSV5A9JQskgu3WyiVG/QeZc445RoFM6LE M2xiCWUe7CpzdoY1w9DPZ9LS5jmk+9w1KTb/3m3qpk/QyocQRcbCd4U3VdXjGRGnr/CHsjFm9h3po 4Zcx9dVmFzw3/VmPdBT99Rv2fm+E0dbIa/GDybMp9KWQo4bQGLrzZR4cYs0hklXjKVEKHN9bNJla8 7QESlHTOwjAZnaTwQHCazPt9CD00fKFzxZFVT+mbW7FQjem+IZFbAQAM2qdr/rg0NEh7+OGYtiOeA QvJ/vMWPQ==; Received: from 089144199016.atnat0008.highway.a1.net ([89.144.199.16] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLV0s-00011n-Sa; Wed, 23 May 2018 14:45:15 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 24/34] xfs: remove xfs_reflink_find_cow_mapping Date: Wed, 23 May 2018 16:43:47 +0200 Message-Id: <20180523144357.18985-25-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523144357.18985-1-hch@lst.de> References: <20180523144357.18985-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 a50f69c2c602..a4b4a7037deb 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 713e857d9ffa..8e5eb8e70c89 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 9d4c4ca24fe6..ed8f774944ba 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -3227,7 +3227,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);