From patchwork Fri May 18 16:47:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10411203 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 C62C36031B for ; Fri, 18 May 2018 16:48:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0DD128894 for ; Fri, 18 May 2018 16:48:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A549F288A0; Fri, 18 May 2018 16:48:47 +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 B07B828619 for ; Fri, 18 May 2018 16:48:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9B916B05FD; Fri, 18 May 2018 12:48:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CFBF36B05FE; Fri, 18 May 2018 12:48: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 B9D3F6B05FF; Fri, 18 May 2018 12:48:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id 769846B05FD for ; Fri, 18 May 2018 12:48:44 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id q15-v6so5029872pff.17 for ; Fri, 18 May 2018 09:48: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=hC//8VIaf1U6Kg7d3MsJUnMeGPTQonUBVkhhhkw0w4M=; b=GTKO+ZT3MX93KUI9116aQSWe9+tf5RcTZwdvmbYtZkCv41Y2zK/Gf6aIOLr9ApsCK7 CL8D3Uz4zaiY3e3CXW0mE4DrfZMDoC6jW54kp1I4y/Gz+1YnMnszzNaIeRL51c1kdq25 TlCNFJs0qd05zz4On7r6jc0XgI6+FH6/CAmaEpeSGPWVqPGdMuosTEgC94HxbysNkc0i fe36c5lYfm9Cj3S2kCnPbZcAGikUrDAd0FQS3VxanYZ9f4unA3Fgo2iouWExfAOwihaX UapAn7Mk6MwEviDOh0RavN10AgknxDDOuA0kTL+EHbWXvGRxfLjydOwhVu+EEnfEgyNY yZLw== X-Gm-Message-State: ALKqPwe7kvHUHdhbLkfZ38PXss1jqSQfR/WMMHjI0wPoxT6U6/R/ZaWx OEfCPsKk5iCaJSQ7Wg1WSDqiMt1U6RwOCRT4gSLkDGukhjJYC0+5olJnSFVIPnayjw7VeQ/tkoB lUh2mNkEfs0bBOoKhBUOwdJa+XGRluW6QkUZvwgCxeKtr2FwAs5NC+3cFHg8AW0w= X-Received: by 2002:a62:f909:: with SMTP id o9-v6mr10165798pfh.256.1526662124111; Fri, 18 May 2018 09:48:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZosIb48GPGrJGNlsb7D9X6MDbXilCZZ2mm1/guQJ7AF6iAVv5KyQ/PjkEJ4CsnYMtHR0aHw X-Received: by 2002:a62:f909:: with SMTP id o9-v6mr10165752pfh.256.1526662123138; Fri, 18 May 2018 09:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526662123; cv=none; d=google.com; s=arc-20160816; b=rolaxYLJjv+bt2dx6IDWF3MZiTd91J993jx0Asl1lvxmlFDdDTm1TnsS4Z4KSLUMsh 9PFG7cvbbYIjO53mjVQNrMse05Bzv0IwrxeB5e1FSL7QxQ3rws65mEQpWlGm1T+BgVqG l16uZXB587etJUN4jBOxrebCJawIZNgtMc+XnHyBX3htogtZuVY+hqnF1B4DMqn4cIBN RUVyAMO19o0GXNo5IE1pQNyWT+URMJj3i0yo741anc7xItnOqMGRhF5KRwZ5a0DLeVHD 9bcIyuu3QTfeVyqGdrHycM5RYG1ey5EmG3wM46N9ZJyls9CpKXOJ8QlcbZV119Yt6w/E 7DBw== 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=hC//8VIaf1U6Kg7d3MsJUnMeGPTQonUBVkhhhkw0w4M=; b=ZOIKSGrWtc5C5WEF9CDPED9LBospG5jPBMMe1n0OOYYHQ+Ue3hzZdg0Yb9hRpIqEs+ NlDlW3tx7Fybm7NWeR9rZxwXNBpOfLgh5ppPAy/hMxVswmex9hx9HQixxaJWiQ+x9VmW MuZ98NtAQFYA//ETsFgd4jDsMZaz6qBbxddOoQqCOi9B1aOVKnymn5iCHLMtsRhGTvDA Abh+IzkGgtXIyJPhTcfXe1ebfBBSflCxul/gDAn+r+lTNSBGwyWG5YCYbqXoMsQGE1sX bWrsu0UuMsr6VChwcOY5FGmMZF5bgdTMUzypsA6ABP7o+tc0ZnhNmAV9Yn9w0a/sof+N fzYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=u7aiJ/7j; spf=pass (google.com: best guess record for domain of batv+77ddf8e9b1b344f28472+5381+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+77ddf8e9b1b344f28472+5381+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 3-v6si8013779plh.34.2018.05.18.09.48.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 09:48:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+77ddf8e9b1b344f28472+5381+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=u7aiJ/7j; spf=pass (google.com: best guess record for domain of batv+77ddf8e9b1b344f28472+5381+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+77ddf8e9b1b344f28472+5381+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=hC//8VIaf1U6Kg7d3MsJUnMeGPTQonUBVkhhhkw0w4M=; b=u7aiJ/7jDfTULbM+nvR3yiYoz KU+gXMugMmuMZRD3vMKkC0nPsIjdIheYi03cRMefV8aH6wI9HI9vNUljtYWKeT0dUE5nT3R6VmEof DsP2vBa6zfHo+ZN4Et7PRvLLDdh2hztJGxYSjFgxmRiR+D5hSEH9mXKZ30DbGOJpDLvixHPAmf/E8 nRc+bWfTV6RguuP9EIgQnaWyO6Bwc7G229QK34vnEGkQjTaAyUI8Zi5lqnnUAWDCA1poZHZHAJ35H /fWzHZeoV5s9Xy87SUvbHy1BQX3po09DF1KOaIBwR3can/GjTVSf656t6C95diIxrluHSduur1p1e KRUtylEnw==; 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 1fJiYc-0006SB-6f; Fri, 18 May 2018 16:48: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 03/34] fs: move page_cache_seek_hole_data to iomap.c Date: Fri, 18 May 2018 18:47:59 +0200 Message-Id: <20180518164830.1552-4-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 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 bd964b2ad99a..aba2a948b235 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -3430,120 +3430,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 f2456d0d8ddd..4a01d2f4e8e9 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -588,6 +589,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;