Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp673956rdb; Tue, 19 Sep 2023 07:08:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+TuwCx9uAAorVCvp6JuZU/BVwVntB5y5tH9TjbKt6mC7qJAj3HEEUx0XUkfhK46Ha4tJK X-Received: by 2002:a17:902:c403:b0:1c3:f745:1cd5 with SMTP id k3-20020a170902c40300b001c3f7451cd5mr16061482plk.34.1695132491055; Tue, 19 Sep 2023 07:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695132491; cv=none; d=google.com; s=arc-20160816; b=KLDiI2mnvePhtfJYpfYTwbAxcs+w2XKf4W7xSaNnX/QeBHjdY98eaTlpETi71MwPBt eKJ5AQPs3ugxK/b5drzAKwNUbPFfL7AGVT6h5bjbIgYwpXTZpAilWCwEk3EWQDlLCvx1 Dq8UF5SzlHE38GJ+gcOOvW2Ci7sAaT5jHd1h3XhGFq0WucQCV/hT+PXU+E7xteJVnLWC IleAArm8SGZHqmJdTPYj27s/i75QxPu1EUu5KI7oNGCCyh6smT4Vh4UKmYNlI/0g5bqp co0IBd7MvRmL4knrWXTLww9gLtXzrB6afkFNzCU9CUkWYS0L6wCgrjE6TpxzR0JTIJMj QC1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nArwds4hDHBhHYufta7EFXQvOR30NKKhjUtIyvFznt4=; fh=Ex900LeWemyNv8v7eVaT25lhS5hAbxvedq4sD5vnIX8=; b=kJXFhcFRdUcsDH/oVD05VVsp5K9Q42rtQ4APwNzK2JBtQz6dGdKVuhnfYu67nr0MyD 4lhcNmUuFE9TkkgCZErjMsUK8tNRk1hOzuH6xmAsJ8MigOgguyhQDFADdMQjP0LHCsEh mEs9wneuJDn4uaHmD59vhZLnmRePgeGk1UTvFFnMA25HUzw5yRaDd2O6jQh1wMCoxc+i e9xMhQIQMc9GwRqZUT8JGHc0gGqU87W+N2zgnPvxRf0SXmTFdIbHECFXw7rl8ThbIXl1 4QTzJYP/9OBhaLjfvkZHHBMfodCIGOXsFSa4Ulsif1qNkfANj3qi+mopqDDnn3oP3OO+ RAog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=RTTNLwri; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l8-20020a170903244800b001bf5c12ea06si10284676pls.404.2023.09.19.07.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 07:08:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=RTTNLwri; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 394D880D8FFA; Mon, 18 Sep 2023 21:52:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231596AbjISEwl (ORCPT + 99 others); Tue, 19 Sep 2023 00:52:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbjISEvx (ORCPT ); Tue, 19 Sep 2023 00:51:53 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A743F122; Mon, 18 Sep 2023 21:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=nArwds4hDHBhHYufta7EFXQvOR30NKKhjUtIyvFznt4=; b=RTTNLwriDilS/kAKdKH3GwxU+Z 7jktCZAGBgGUmuWIt+5Pse+UewyOWiwO3uXEu8zXRi4MU3iF27q0hSUVvxkGsxkrXyyodbljvAcTp 0LMy4wLm7Of+4x8zyZiuxQCq/rSIpgFdS8Wi2Vjs0saHDOwl9OPAP5MHyEcN0pkK3zuOeVDeN+J6f 9LIzJ1L7U+P7GbH6ABVZJvsvhPtasrFVv307p1uIJDRigSb7QqthAk0YeppXMZvCx6gCNKIr5soCQ TPdbgB84XvpOr5H3RR/9eBDj9R540Bb/LAdli8aC/6jB6QiZLjbt7Mg6a/GJxGfSxBpI87NOJLLrD VfuCNkWA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qiSi2-00FFkN-Ba; Tue, 19 Sep 2023 04:51:38 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, gfs2@lists.linux.dev, linux-nilfs@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, ntfs3@lists.linux.dev, ocfs2-devel@lists.linux.dev, reiserfs-devel@vger.kernel.org, linux-ext4@vger.kernel.org, Pankaj Raghav Subject: [PATCH 04/26] buffer: Add get_nth_bh() Date: Tue, 19 Sep 2023 05:51:13 +0100 Message-Id: <20230919045135.3635437-5-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230919045135.3635437-1-willy@infradead.org> References: <20230919045135.3635437-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 21:52:42 -0700 (PDT) Extract this useful helper from nilfs_page_get_nth_block() Signed-off-by: Matthew Wilcox (Oracle) --- fs/nilfs2/page.h | 7 +------ include/linux/buffer_head.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/fs/nilfs2/page.h b/fs/nilfs2/page.h index 21ddcdd4d63e..344d71942d36 100644 --- a/fs/nilfs2/page.h +++ b/fs/nilfs2/page.h @@ -55,12 +55,7 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode, static inline struct buffer_head * nilfs_page_get_nth_block(struct page *page, unsigned int count) { - struct buffer_head *bh = page_buffers(page); - - while (count-- > 0) - bh = bh->b_this_page; - get_bh(bh); - return bh; + return get_nth_bh(page_buffers(page), count); } #endif /* _NILFS_PAGE_H */ diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 1001244a8941..9fc615ee17fd 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -457,6 +457,28 @@ __bread(struct block_device *bdev, sector_t block, unsigned size) return __bread_gfp(bdev, block, size, __GFP_MOVABLE); } +/** + * get_nth_bh - Get a reference on the n'th buffer after this one. + * @bh: The buffer to start counting from. + * @count: How many buffers to skip. + * + * This is primarily useful for finding the nth buffer in a folio; in + * that case you pass the head buffer and the byte offset in the folio + * divided by the block size. It can be used for other purposes, but + * it will wrap at the end of the folio rather than returning NULL or + * proceeding to the next folio for you. + * + * Return: The requested buffer with an elevated refcount. + */ +static inline struct buffer_head *get_nth_bh(struct buffer_head *bh, + unsigned int count) +{ + while (count--) + bh = bh->b_this_page; + get_bh(bh); + return bh; +} + bool block_dirty_folio(struct address_space *mapping, struct folio *folio); #ifdef CONFIG_BUFFER_HEAD -- 2.40.1