From patchwork Wed May 23 14:43:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10421471 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 BFDCE6032A for ; Wed, 23 May 2018 14:44:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF473223A4 for ; Wed, 23 May 2018 14:44:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3D6B2843C; Wed, 23 May 2018 14:44:18 +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 E5601223A4 for ; Wed, 23 May 2018 14:44:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 540716B000E; Wed, 23 May 2018 10:44:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4EFA96B0010; Wed, 23 May 2018 10:44:15 -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 3DF7E6B0266; Wed, 23 May 2018 10:44:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id EBADF6B000E for ; Wed, 23 May 2018 10:44:14 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id g1-v6so13282192pfh.19 for ; Wed, 23 May 2018 07:44:14 -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=GrJ0th3IzyZQZNzY+02X5cqmsYx5ArS0tU+BnHGBKmsZW2LdPGfNM+N4vZyWFDsAv/ +qJU9dkReferewgMsvVbLVPaVq/iQ0suRlF9GkVsFbCnGH38DtxvFxva4I6vJTvUQfT8 8V2Mb8jqeV9tAemqwPCDV2aNeckeDN8HrE2/uTbc7pavR0i6kwjKlOlyjidJxmzxy5/9 ORIxUfj+Xe3MwU+EsSbWete9o6tOMegzxAcsjTwgHlemHw2riwqyeTLO0mHJB+lYfRS9 rV9PXOW5S/ctkuiFqrmaOZwZHAKWzYLd4UfyMFzj81dQciEFvFRUmsEobN+yG82TiIpn yNVw== X-Gm-Message-State: ALKqPwchUJ9c3ndo2gYdYxG1fSbUOtHmfU8Vfzfyy1xkFcyJ6u4IqfQt KAOpcBiIelvT3I2PjpSMEsjEmkjtKB2K7NXWiuSLlm5mGPGN0SM20ISvMxQRH6cWeHF+NsWJedN A908eAdTdPQietlTZvEkV9blwMmxiR058FbyIVV3I4DahB3OqT2ay5w8X0YsN8rU= X-Received: by 2002:a65:6493:: with SMTP id e19-v6mr2548504pgv.381.1527086654607; Wed, 23 May 2018 07:44:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoIXH6fdp9yMff3EVI8vc7HSi9cqd4RX/I6bfSw+0bDW2dlJYldzwHh+zeA7/7sl4QaNarV X-Received: by 2002:a65:6493:: with SMTP id e19-v6mr2548462pgv.381.1527086653666; Wed, 23 May 2018 07:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527086653; cv=none; d=google.com; s=arc-20160816; b=e4eR9eaE4gsm2g3v1pf3XyyBGE8tFwzZnrwzAS8nkoQGPEjp/Yv9MuzG4BKdiJdrJz hniCQAFWxJOg3ECNtHbIbTJWSyh0fPMjyIk7gUw1/aYshSDcCnnnK2GhTYDgxN2ozZs1 a/lIBvNNZ4ZbO0gxNuU9kaZgW73+Ow4J7z96iJqVia0kY4iBKlPZBoe2nKpva6luMLIj 1eeoruKnNxNPVokGqs+/dHaqnL4p1Pt17qlrD+JZNNdXv7bMtzsMnZsLK/VvsMHmfrQO X5XDnR9NqDg5bUgrPeDd0PkZ1G+rJFD5WZ55R5fU6ANMmkhbqgO3KSqueoeaUScTUBvj T33w== 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=Y+CScieKyHhG0wCKNREOtiakgiATtTiaHeLdFd38iBbFmDbk5kd+br51HZ6tL/DPIx csUAxBbWHOTqj0O9gHR9jxdBhyY3LPjkBayysgmO7GyAOetOg1KJ5Te7gN7rJSUaHLg2 9eied/ekmiPpyojlN6ZBOllysS/0DRXltw0ynHNyOx3hWYdwpU78QIoCoF8K0ywq+Xh/ rXREHap/lLuGPDOif2HbnTiHG/dT45KfThwaRh9FiJLVn/0qDZ/qeIPcwuFfeWgxuYqA WZL8kXBGLr3P6AwZ+/Zb3E1UZpsgS1mL9xoTqao2+Biwto27Q8qR0zW9NHBU80W15p02 oxQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=rldb7YzM; 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 e93-v6si9142890plk.386.2018.05.23.07.44.13 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 07:44:13 -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=rldb7YzM; 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=hC//8VIaf1U6Kg7d3MsJUnMeGPTQonUBVkhhhkw0w4M=; b=rldb7YzMPjkddUJ3Y9htMX0YM mzpYWV7BBfrtCljhxjwNitAf/lYFmKVuPSjyBiFyRr0XYr8GuI4uKJnrRCu9nHVveV1UBWVI6eRtQ OvgQdirnAr+t9Fs/W93JUjegfZ5xljhS/RLXh6/PhxW0HmCDR9QCV5FIqBiqsz6Hr7ypsnu0ugKXc zicYD+Y9wn/TybFqCRzt+Woo3fGzH7karGMMczp+lk66EskILl0+yLAvjkxnnvOg/fTpYTN7Cx9YE chLGRf7oMihk7tZO1jioC9ft3JJ4F3FNSkyxQmOCgpoS8dYpagLClFKyTnN5Xz49USHMuDq9P8M/Z wBWuUV9yw==; 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 1fLUzq-0000A8-CS; Wed, 23 May 2018 14:44:10 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 03/34] fs: move page_cache_seek_hole_data to iomap.c Date: Wed, 23 May 2018 16:43:26 +0200 Message-Id: <20180523144357.18985-4-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 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 Reviewed-by: Darrick J. Wong --- 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;