From patchwork Wed May 9 07:48:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10388311 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 464F8602C2 for ; Wed, 9 May 2018 07:48:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3901228E05 for ; Wed, 9 May 2018 07:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DADB28E56; Wed, 9 May 2018 07:48:52 +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 7DEB828E05 for ; Wed, 9 May 2018 07:48:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1C526B033D; Wed, 9 May 2018 03:48:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DD9E36B033F; Wed, 9 May 2018 03:48:49 -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 C6E2B6B033E; Wed, 9 May 2018 03:48:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id 8109B6B033A for ; Wed, 9 May 2018 03:48:49 -0400 (EDT) Received: by mail-pg0-f72.google.com with SMTP id k189-v6so457312pgc.10 for ; Wed, 09 May 2018 00:48:49 -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=rWiSKFlBEuMLYoWOCIFbW+A7kb1lwO3/U1dxk6MJ/5g=; b=W3PWN8ww1ivsmFua871SKWSEwe0SE9hiQWOcHdvCh6sIewVjK4MfUgz4VMj0ndvtVi CF/2BFIRYkjH+0M6HbGMtBNj6uZS6O5xVwxOEQOvkfOvOVp5sxtPlOqrpAIXFZWZtky3 5I6gGCYbPDkpc9hwVjpHHpCMQwPR5R87zd5TolKClhOCPp+5cNqUmCSpaJfFFdW3JTN+ sjZa9+ZH18IvambUGViXXRhaNrXoCu5CqzmRvMDqYcApYvL3QvU77kxFSgN2s0xlXvCO Z0uoAMEH0NFFyT1OXlP2TAGvt9Gv0erxKlouN1K9uuam1siPlaNgqwDuZivpMZ/+yC+4 AhbA== X-Gm-Message-State: ALQs6tBfcSI8WP1D7UXZXvnOxyVTbVV1XHcEaWotq2RD5kXPOAAdHKaE u+mSaq1dDP2qNJyaXnSvFsEIRLXjT4hLMA455x83MyKQfN9n/tA+uNiL4k6bSKD59t4uwb03B6J n00Ic1hMYgfErN5fkIwBlWa6ABp14VHsKxtwsGjJL7NGyQrxtrZ+Hoq3DWRVrPsA= X-Received: by 2002:a17:902:7283:: with SMTP id d3-v6mr21657610pll.192.1525852129208; Wed, 09 May 2018 00:48:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqHRZsBZwMr1q7VUheF68ck06WmubjsqGXAmXnro94a/XhDLrJxkeY0Yf/pqfFxl3rB+6K8 X-Received: by 2002:a17:902:7283:: with SMTP id d3-v6mr21657575pll.192.1525852128270; Wed, 09 May 2018 00:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525852128; cv=none; d=google.com; s=arc-20160816; b=FNlq9cE6KouTsdnF5GEE1GJj+SIctGmmN8PBWPiwDM/TAXPB1Pc0Z9i0PYobegfsGB x5XN+20zxDr5kOWyqXBw4hiHQxB71xcpx9k8nipFtAtswHArP5y+3NZDrkIAYT2cWsiG AzbPm7ARcGoEiCGNaNcTFaPJ8F4VhtU1T4MNh9ddq5IDsnAfpjUkNItOA8qzdFVd1P+I 8X41nO+ybTB8K1dfU6sC4GZZwEFzJqTI/CsyX8eeqPh0M919oIFq6X/wInxFC/RV+/hb qmJACSvK4P/8OYaixBAAWAGzyYwWNFYvC92eZ4yvOr/xu4DEg3+w9A0RTepI3A6Nh4Y3 fi1Q== 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=rWiSKFlBEuMLYoWOCIFbW+A7kb1lwO3/U1dxk6MJ/5g=; b=f8aR3KYSV+PDeOa//pTnweQlkuu2o/K7H4vsxAyFBZhQ1Q3jV7aE5CC0Hps2JGqIxu RiOaSXAnc31ynHIwYPgMHFTxzZOFKbXr3AVg/a2hBjUue2mcmizbiO5hCDfVvYcVJnI6 5/8/G5jgWW+yOEOXUgGensPvCv2g2j+efc/h2EXjedcbW8zSignd4vpX1M5lcrmV/NFn p0d2/3ggVY6C8NATh8h+rN20xos73IE9gD/yezKGvCfR6inPQvQ/4Z6GEURgiVYKq6zQ DgYq1l5cKNPBVOsMdd86rqIR742qjE3/puhg6nfDClZBZW6pKC1F6UEA9ArdcIv5lRP7 akHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=nWv0Np52; 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 a35-v6si22066913pli.85.2018.05.09.00.48.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 00:48:48 -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=nWv0Np52; 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=rWiSKFlBEuMLYoWOCIFbW+A7kb1lwO3/U1dxk6MJ/5g=; b=nWv0Np52eQwgfv5rVhZ8KJYja SxSMKqB0eUGkfKxERHtjq2A9y15pkBu33iGfTo2ttvVs+0aUpRZ1FXHfZfovrmir9zu/n9wreyndl 5UlufPCg+QxmsFpaMxzCzFUQJd69NCmUR88FOSzjz+M/TUjZoVtIlwEDJ5Cm/qyk2fWc7C+GflblP mj0oZiA4ygSMpaLP3FtaMJaZAkYECA61x1/F+Rm8M9YQcVt8wF0YFzFdGbduyxIxtss6m5eMyzZ91 pc2rfpYSfHPtxKWi4u3xpyaXJ+0D2EFhtFewqgeYJdXiVgXpqdlwAZHSdUeIwTZ2ads+mfBdsq9ZB OYh/PiIfw==; 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 1fGJqB-00013d-3T; Wed, 09 May 2018 07:48:47 +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 03/33] fs: move page_cache_seek_hole_data to iomap.c Date: Wed, 9 May 2018 09:48:00 +0200 Message-Id: <20180509074830.16196-4-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 This function is only used by the iomap code, depends on being called from it, and will soon stop poking into buffer head internals. Signed-off-by: Christoph Hellwig --- fs/buffer.c | 114 ----------------------------------- fs/iomap.c | 116 ++++++++++++++++++++++++++++++++++++ include/linux/buffer_head.h | 2 - 3 files changed, 116 insertions(+), 116 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 923391702f51..71ea9a29e9d5 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -3431,120 +3431,6 @@ int bh_submit_read(struct buffer_head *bh) } EXPORT_SYMBOL(bh_submit_read); -/* - * Seek for SEEK_DATA / SEEK_HOLE within @page, starting at @lastoff. - * - * Returns the offset within the file on success, and -ENOENT otherwise. - */ -static loff_t -page_seek_hole_data(struct page *page, loff_t lastoff, int whence) -{ - loff_t offset = page_offset(page); - struct buffer_head *bh, *head; - bool seek_data = whence == SEEK_DATA; - - if (lastoff < offset) - lastoff = offset; - - bh = head = page_buffers(page); - do { - offset += bh->b_size; - if (lastoff >= offset) - continue; - - /* - * Unwritten extents that have data in the page cache covering - * them can be identified by the BH_Unwritten state flag. - * Pages with multiple buffers might have a mix of holes, data - * and unwritten extents - any buffer with valid data in it - * should have BH_Uptodate flag set on it. - */ - - if ((buffer_unwritten(bh) || buffer_uptodate(bh)) == seek_data) - return lastoff; - - lastoff = offset; - } while ((bh = bh->b_this_page) != head); - return -ENOENT; -} - -/* - * Seek for SEEK_DATA / SEEK_HOLE in the page cache. - * - * Within unwritten extents, the page cache determines which parts are holes - * and which are data: unwritten and uptodate buffer heads count as data; - * everything else counts as a hole. - * - * Returns the resulting offset on successs, and -ENOENT otherwise. - */ -loff_t -page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length, - int whence) -{ - pgoff_t index = offset >> PAGE_SHIFT; - pgoff_t end = DIV_ROUND_UP(offset + length, PAGE_SIZE); - loff_t lastoff = offset; - struct pagevec pvec; - - if (length <= 0) - return -ENOENT; - - pagevec_init(&pvec); - - do { - unsigned nr_pages, i; - - nr_pages = pagevec_lookup_range(&pvec, inode->i_mapping, &index, - end - 1); - if (nr_pages == 0) - break; - - for (i = 0; i < nr_pages; i++) { - struct page *page = pvec.pages[i]; - - /* - * At this point, the page may be truncated or - * invalidated (changing page->mapping to NULL), or - * even swizzled back from swapper_space to tmpfs file - * mapping. However, page->index will not change - * because we have a reference on the page. - * - * If current page offset is beyond where we've ended, - * we've found a hole. - */ - if (whence == SEEK_HOLE && - lastoff < page_offset(page)) - goto check_range; - - lock_page(page); - if (likely(page->mapping == inode->i_mapping) && - page_has_buffers(page)) { - lastoff = page_seek_hole_data(page, lastoff, whence); - if (lastoff >= 0) { - unlock_page(page); - goto check_range; - } - } - unlock_page(page); - lastoff = page_offset(page) + PAGE_SIZE; - } - pagevec_release(&pvec); - } while (index < end); - - /* When no page at lastoff and we are not done, we found a hole. */ - if (whence != SEEK_HOLE) - goto not_found; - -check_range: - if (lastoff < offset + length) - goto out; -not_found: - lastoff = -ENOENT; -out: - pagevec_release(&pvec); - return lastoff; -} - void __init buffer_init(void) { unsigned long nrpages; diff --git a/fs/iomap.c b/fs/iomap.c index afd163586aa0..13f518c7d3be 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -587,6 +588,121 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, } EXPORT_SYMBOL_GPL(iomap_fiemap); +/* + * Seek for SEEK_DATA / SEEK_HOLE within @page, starting at @lastoff. + * + * Returns the offset within the file on success, and -ENOENT otherwise. + */ +static loff_t +page_seek_hole_data(struct page *page, loff_t lastoff, int whence) +{ + loff_t offset = page_offset(page); + struct buffer_head *bh, *head; + bool seek_data = whence == SEEK_DATA; + + if (lastoff < offset) + lastoff = offset; + + bh = head = page_buffers(page); + do { + offset += bh->b_size; + if (lastoff >= offset) + continue; + + /* + * Unwritten extents that have data in the page cache covering + * them can be identified by the BH_Unwritten state flag. + * Pages with multiple buffers might have a mix of holes, data + * and unwritten extents - any buffer with valid data in it + * should have BH_Uptodate flag set on it. + */ + + if ((buffer_unwritten(bh) || buffer_uptodate(bh)) == seek_data) + return lastoff; + + lastoff = offset; + } while ((bh = bh->b_this_page) != head); + return -ENOENT; +} + +/* + * Seek for SEEK_DATA / SEEK_HOLE in the page cache. + * + * Within unwritten extents, the page cache determines which parts are holes + * and which are data: unwritten and uptodate buffer heads count as data; + * everything else counts as a hole. + * + * Returns the resulting offset on successs, and -ENOENT otherwise. + */ +static loff_t +page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length, + int whence) +{ + pgoff_t index = offset >> PAGE_SHIFT; + pgoff_t end = DIV_ROUND_UP(offset + length, PAGE_SIZE); + loff_t lastoff = offset; + struct pagevec pvec; + + if (length <= 0) + return -ENOENT; + + pagevec_init(&pvec); + + do { + unsigned nr_pages, i; + + nr_pages = pagevec_lookup_range(&pvec, inode->i_mapping, &index, + end - 1); + if (nr_pages == 0) + break; + + for (i = 0; i < nr_pages; i++) { + struct page *page = pvec.pages[i]; + + /* + * At this point, the page may be truncated or + * invalidated (changing page->mapping to NULL), or + * even swizzled back from swapper_space to tmpfs file + * mapping. However, page->index will not change + * because we have a reference on the page. + * + * If current page offset is beyond where we've ended, + * we've found a hole. + */ + if (whence == SEEK_HOLE && + lastoff < page_offset(page)) + goto check_range; + + lock_page(page); + if (likely(page->mapping == inode->i_mapping) && + page_has_buffers(page)) { + lastoff = page_seek_hole_data(page, lastoff, whence); + if (lastoff >= 0) { + unlock_page(page); + goto check_range; + } + } + unlock_page(page); + lastoff = page_offset(page) + PAGE_SIZE; + } + pagevec_release(&pvec); + } while (index < end); + + /* When no page at lastoff and we are not done, we found a hole. */ + if (whence != SEEK_HOLE) + goto not_found; + +check_range: + if (lastoff < offset + length) + goto out; +not_found: + lastoff = -ENOENT; +out: + pagevec_release(&pvec); + return lastoff; +} + + static loff_t iomap_seek_hole_actor(struct inode *inode, loff_t offset, loff_t length, void *data, struct iomap *iomap) diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 894e5d125de6..96225a77c112 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -205,8 +205,6 @@ void write_boundary_block(struct block_device *bdev, sector_t bblock, unsigned blocksize); int bh_uptodate_or_lock(struct buffer_head *bh); int bh_submit_read(struct buffer_head *bh); -loff_t page_cache_seek_hole_data(struct inode *inode, loff_t offset, - loff_t length, int whence); extern int buffer_heads_over_limit;