From patchwork Fri Sep 2 20:16:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 914EBC6FA82 for ; Fri, 2 Sep 2022 20:16:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbiIBUQ6 (ORCPT ); Fri, 2 Sep 2022 16:16:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbiIBUQy (ORCPT ); Fri, 2 Sep 2022 16:16:54 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E568DD8B3B for ; Fri, 2 Sep 2022 13:16:41 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id q8so2251394qvr.9 for ; Fri, 02 Sep 2022 13:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=Dzw3EWx7kn6eUX0ykefO6AJK6Hnu5AfB5HKCh1k4CsU=; b=yI4y11bSJy+ywMeKeo5RjBz2OObSFTGcXC3MklHWp+5k5EAa7wT6ys3vBTH+IZpPrU 8yx/VzmU5d3SR8GiTskg+sqj9oUcXml/NsKHrcf9XbFu8hO0edSzArhfG0l+ZJnRXFc0 CrsAOt1u0pObSJN0jOIXfSG4rJzWv/adJvE4Us+GMVg6WKJchfD8y1VF0ybLYae4h6Oc Ir+THxuAXx+DSNDoptbp/KuSOdHTzuLVNN8ymZHv/x0nctGTqQJCGZ6H9WQVwmd2ydA4 QmnGn9ZH41Ju8gEQOUuJxf3YhwCl5hi0/B/Ksx2QiLgFvIKNvMj82fGJO6eUGCJidKIo vflw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Dzw3EWx7kn6eUX0ykefO6AJK6Hnu5AfB5HKCh1k4CsU=; b=K4Laq/Cif5jGt6qrO+XwO72lEZXNVFjzlgVfKpXZjAuvJcanSsE4fWIjUbKAR4OM0m jaLtyGrEEEkPvVSMrU7ecGlGihm1zJkgNH/nNwKrT+kjTtICVJHc8BfY1D9oi58N+fSK LspWq6Hq9I4yNIY4U+2f4PgtGi2UdIQKV3J+fDhf2GliVIK9JiAJ77n9SLQYjYU+NNtj aMSwupGyvomG/VI+gwHjdh/6zqk8UngVc9lCP33LdyR3B5GhRq9XM7zPHg/7hrB3sJ6x +kic/8Wq9+ByRfH6AywT4C45/BJ/SG1uJVUw/2bZi7816DYGRHxFJPCv4/h5/yuoN7lR cnQw== X-Gm-Message-State: ACgBeo3LquHxViZdoXjnkGR01br9467+Wp9hWaFks2z0/6hKEkkXbbgA Q3fh04sOMb1JSbUTFae089+53PYVtXPCzA== X-Google-Smtp-Source: AA6agR6C8oHC9j1qcoexhtgGdpzB6TaqecYU7M3fftWTRrPDkiQdWXjRpDM0kDKmxmgN4AMJCujMXw== X-Received: by 2002:a05:6214:d4e:b0:499:669:de05 with SMTP id 14-20020a0562140d4e00b004990669de05mr21164525qvr.9.1662149800535; Fri, 02 Sep 2022 13:16:40 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id 184-20020a3706c1000000b006b6757a11fcsm1885339qkg.36.2022.09.02.13.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:40 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/31] btrfs: cleanup clean_io_failure Date: Fri, 2 Sep 2022 16:16:06 -0400 Message-Id: <7d5c4a3ca2ceb19fb3c84d5f3e716828cae0fb86.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is exported, so rename it to btrfs_clean_io_failure. Additionally we are passing in the io tree's and such from the inode, so instead of doing all that simply pass in the inode itself and get all the components we need directly inside of btrfs_clean_io_failure. Signed-off-by: Josef Bacik --- fs/btrfs/compression.c | 5 ++--- fs/btrfs/extent-io-tree.h | 6 ++---- fs/btrfs/extent_io.c | 17 +++++++---------- fs/btrfs/inode.c | 7 ++----- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 1c77de3239bc..cac0eeceb815 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -183,9 +183,8 @@ static void end_compressed_bio_read(struct btrfs_bio *bbio) if (!status && (!csum || !btrfs_check_data_csum(inode, bbio, offset, bv.bv_page, bv.bv_offset))) { - clean_io_failure(fs_info, &bi->io_failure_tree, - &bi->io_tree, start, bv.bv_page, - btrfs_ino(bi), bv.bv_offset); + btrfs_clean_io_failure(bi, start, bv.bv_page, + bv.bv_offset); } else { int ret; diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index ec2f8b8e6faa..bb71b4a69022 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -256,9 +256,7 @@ void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, int free_io_failure(struct extent_io_tree *failure_tree, struct extent_io_tree *io_tree, struct io_failure_record *rec); -int clean_io_failure(struct btrfs_fs_info *fs_info, - struct extent_io_tree *failure_tree, - struct extent_io_tree *io_tree, u64 start, - struct page *page, u64 ino, unsigned int pg_offset); +int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, + struct page *page, unsigned int pg_offset); #endif /* BTRFS_EXTENT_IO_TREE_H */ diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 591c191a58bc..acfbf029c18e 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2431,11 +2431,13 @@ static int prev_mirror(const struct io_failure_record *failrec, int cur_mirror) * each time an IO finishes, we do a fast check in the IO failure tree * to see if we need to process or clean up an io_failure_record */ -int clean_io_failure(struct btrfs_fs_info *fs_info, - struct extent_io_tree *failure_tree, - struct extent_io_tree *io_tree, u64 start, - struct page *page, u64 ino, unsigned int pg_offset) +int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, + struct page *page, unsigned int pg_offset) { + struct btrfs_fs_info *fs_info = inode->root->fs_info; + struct extent_io_tree *failure_tree = &inode->io_failure_tree; + struct extent_io_tree *io_tree = &inode->io_tree; + u64 ino = btrfs_ino(inode); u64 private; struct io_failure_record *failrec; struct extent_state *state; @@ -2963,7 +2965,6 @@ static void end_bio_extent_readpage(struct btrfs_bio *bbio) { struct bio *bio = &bbio->bio; struct bio_vec *bvec; - struct extent_io_tree *tree, *failure_tree; struct processed_extent processed = { 0 }; /* * The offset to the beginning of a bio, since one bio can never be @@ -2990,8 +2991,6 @@ static void end_bio_extent_readpage(struct btrfs_bio *bbio) "end_bio_extent_readpage: bi_sector=%llu, err=%d, mirror=%u", bio->bi_iter.bi_sector, bio->bi_status, bbio->mirror_num); - tree = &BTRFS_I(inode)->io_tree; - failure_tree = &BTRFS_I(inode)->io_failure_tree; /* * We always issue full-sector reads, but if some block in a @@ -3032,9 +3031,7 @@ static void end_bio_extent_readpage(struct btrfs_bio *bbio) loff_t i_size = i_size_read(inode); pgoff_t end_index = i_size >> PAGE_SHIFT; - clean_io_failure(BTRFS_I(inode)->root->fs_info, - failure_tree, tree, start, page, - btrfs_ino(BTRFS_I(inode)), 0); + btrfs_clean_io_failure(BTRFS_I(inode), start, page, 0); /* * Zero out the remaining part if this range straddles diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b9d40e25d978..a1b9e2a455d9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7997,8 +7997,6 @@ static blk_status_t btrfs_check_read_dio_bio(struct btrfs_dio_private *dip, { struct inode *inode = dip->inode; struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; - struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree; - struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; const bool csum = !(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM); blk_status_t err = BLK_STS_OK; struct bvec_iter iter; @@ -8011,9 +8009,8 @@ static blk_status_t btrfs_check_read_dio_bio(struct btrfs_dio_private *dip, if (uptodate && (!csum || !btrfs_check_data_csum(inode, bbio, offset, bv.bv_page, bv.bv_offset))) { - clean_io_failure(fs_info, failure_tree, io_tree, start, - bv.bv_page, btrfs_ino(BTRFS_I(inode)), - bv.bv_offset); + btrfs_clean_io_failure(BTRFS_I(inode), start, + bv.bv_page, bv.bv_offset); } else { int ret; From patchwork Fri Sep 2 20:16:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C333C6FA83 for ; Fri, 2 Sep 2022 20:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbiIBUQ7 (ORCPT ); Fri, 2 Sep 2022 16:16:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbiIBUQy (ORCPT ); Fri, 2 Sep 2022 16:16:54 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA55E726D for ; Fri, 2 Sep 2022 13:16:43 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id q8so2251451qvr.9 for ; Fri, 02 Sep 2022 13:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=AZWeJJht4H1nFpESENBH2bZCBoti+8IGiJNZGGKaiwg=; b=itOmWbLASEcag6UjBlKsIpxx7Jt2qiEkXldsyNJFk4UVvTG6ny6nsbZAfS8C2HsQyC aBOmDR8nOjBDdpwT6GwhAFHHtmDUPYk9A/XEPj9Cfx5Suc2qQ030vgawthf0n0VKAUiI kBMChEM++IxOM/8pScA45IPTXDwiMTJMsL35L/ETPZiOQnZXrZrvNtBd7nAYmPd84qM2 tzCnJba+tZnxP58HIhJi4Pm1KDeZKi9uq3aMmidM8h4eiqjF09D6IP1rJNhssQHBRAJ8 y0qU87n/lNgFBF4+kytMhUFxN8TbFRlf7AMKAwxQ31pMTbOi9Uhbx+DSObK6XH65cfzr /9jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=AZWeJJht4H1nFpESENBH2bZCBoti+8IGiJNZGGKaiwg=; b=zSnXyDM7LLkJRuZaCsStHwLb+71LAAk6GTDo3sUz1q0uW8a2UsFeBxiTc+2liUlEI8 GmlpcclPvVr3ygqz31Hl0PHimLGQsALCclhK2M6lbRRFYy3dtgAyqadvdDJCYpZDqybL zbFyMkBISdQ8skSvJIaLIh/uhGK2qQK76HoV82pu2c3koth9/sv/HSAJl2WLXk7r1VwV +LlEYd4Tiod+rtA4w+zA3irnlWRAbgSdFNV7fqAoCn/UQ6UH8AGfWo3GweuIWdsWfxir jTmuoiO+lja9qYXjTHlw3tO2417NxzXW0VWAiK3kzwwZ+zXrPnTjDVyXgAQp90c8m70K P9Ng== X-Gm-Message-State: ACgBeo3ckRosBaRHOAa6o56dsZqzNKb3nLCcM79xztkwwB+/++kuH89Z F6bgC1gyZdTDgMRF1zJQ8VqhKyqcqbD4+A== X-Google-Smtp-Source: AA6agR5oiyNemsh9GDErRvAKvZdzZH+0t23K+9dzlylObmTxlrMuUBIg09BIAAHp0zWMRZHFTmPhbA== X-Received: by 2002:a05:6214:19ee:b0:499:1129:d34b with SMTP id q14-20020a05621419ee00b004991129d34bmr18160051qvc.39.1662149802434; Fri, 02 Sep 2022 13:16:42 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id 73-20020a370b4c000000b006bb619a6a85sm1916991qkl.48.2022.09.02.13.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:42 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/31] btrfs: unexport internal failrec functions Date: Fri, 2 Sep 2022 16:16:07 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org These are internally used functions and are not used outside of extent_io.c. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.h | 6 ------ fs/btrfs/extent_io.c | 13 +++++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index bb71b4a69022..5584968643eb 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -248,14 +248,8 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, struct extent_state **cached_state); /* This should be reworked in the future and put elsewhere. */ -struct io_failure_record *get_state_failrec(struct extent_io_tree *tree, u64 start); -int set_state_failrec(struct extent_io_tree *tree, u64 start, - struct io_failure_record *failrec); void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, u64 end); -int free_io_failure(struct extent_io_tree *failure_tree, - struct extent_io_tree *io_tree, - struct io_failure_record *rec); int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, struct page *page, unsigned int pg_offset); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index acfbf029c18e..be14c15cfafa 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2163,8 +2163,8 @@ u64 count_range_bits(struct extent_io_tree *tree, * set the private field for a given byte offset in the tree. If there isn't * an extent_state there already, this does nothing. */ -int set_state_failrec(struct extent_io_tree *tree, u64 start, - struct io_failure_record *failrec) +static int set_state_failrec(struct extent_io_tree *tree, u64 start, + struct io_failure_record *failrec) { struct rb_node *node; struct extent_state *state; @@ -2191,7 +2191,8 @@ int set_state_failrec(struct extent_io_tree *tree, u64 start, return ret; } -struct io_failure_record *get_state_failrec(struct extent_io_tree *tree, u64 start) +static struct io_failure_record *get_state_failrec(struct extent_io_tree *tree, + u64 start) { struct rb_node *node; struct extent_state *state; @@ -2275,9 +2276,9 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, return bitset; } -int free_io_failure(struct extent_io_tree *failure_tree, - struct extent_io_tree *io_tree, - struct io_failure_record *rec) +static int free_io_failure(struct extent_io_tree *failure_tree, + struct extent_io_tree *io_tree, + struct io_failure_record *rec) { int ret; int err = 0; From patchwork Fri Sep 2 20:16:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0B27C6FA82 for ; Fri, 2 Sep 2022 20:17:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229468AbiIBURD (ORCPT ); Fri, 2 Sep 2022 16:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbiIBUQ4 (ORCPT ); Fri, 2 Sep 2022 16:16:56 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F947EF9C4 for ; Fri, 2 Sep 2022 13:16:45 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id j1so2259764qvv.8 for ; Fri, 02 Sep 2022 13:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=Qj9XNd/lL0rhcPZvexHUZiZr8vyjsyftMtSceQl3r6o=; b=hzKViVxNnnYh1laCeXS8rwi9GklzVl7VU9EU27zcpZYofuW8Fa04XVsAvHzo2Ie/ul x8a+dKAVdETbDTg2F7+1CwrLmZItwsxudBukUfQw/uIQELV9q/eE2ZpyUB2vqtLl/wFz BD/zR6K8lu0wrVd036ZoKkw5TiViSkpLlzRJk5lpYb23JtEFfOYt3KHTrtiGFFjCLWvo vO+c2/Ra19GYRrCKc2olTo0iwgn7Fqg9rEE0OY5I+t77cjw70NTGDXSYtzgnTVnpgUbL rL69F/q1eN7//9EYQ0pDNBE4FExi6+127OK5qDDWe2F4mGfhZyxsmAJSpkGyeEknBsQI /m+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Qj9XNd/lL0rhcPZvexHUZiZr8vyjsyftMtSceQl3r6o=; b=YvKNmmUnpI/iQlhEfe9EkxdmMDEjdgbsyzKLzOxLVKpMJgEJzVdnJ3gqPkzJeJFwZy PB14y5IevcQAxhdc3+HJS1SamGbrsymnWFc4+USnkvTjno91h7CDQjjtsUa6dqkFngAP Vg1F/MDfPbcd7jNjCAjLOn4HjcfkEJ/kEBellXdAtH+9vRCBvxpqKvq0fBVtdrGWuyAK CGf+vHwENg5Cw2yN2puPVErefgKJfb45duINWYpeVXT77Rm066uektvnh1hFnEhudnyz ZQmnvCyext4uXKLu9vfqwGHuaQlAVB925uJSQO/hbmRdLWkzbU9zzHcT9rod3LYz7jVX ZlyQ== X-Gm-Message-State: ACgBeo34n2vXPaVsEn//oFawmUwb557CKAefMeM3U5X3UpKP9LXsHh4b DmrpDaEkEDx3eUzQL/BpCpGtxEkgaF4IPw== X-Google-Smtp-Source: AA6agR5VwSpJ2ETrFYamC1FEqfTLNvjqutGqs0CvBYz8/6GoW4a3Sl5q24Inn+4fZcL6XmYzHRQnug== X-Received: by 2002:a0c:916c:0:b0:499:22d5:be5d with SMTP id q99-20020a0c916c000000b0049922d5be5dmr11768307qvq.55.1662149804136; Fri, 02 Sep 2022 13:16:44 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id x20-20020a05620a0b5400b006b929a56a2bsm2019057qkg.3.2022.09.02.13.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:43 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/31] btrfs: stop using extent_io_tree for io_failure_record's Date: Fri, 2 Sep 2022 16:16:08 -0400 Message-Id: <3470bcd6166aaeda443174064d0e172953513fcd.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We still have this oddity of stashing the io_failure_record in the extent state for the io_failure_tree, which is leftover from when we used to stuff private pointers in extent_io_trees. However this doesn't make a lot of sense for the io failure records, we can simply use a normal rb_tree for this. This will allow us to further simplify the extent_io_tree code by removing the io_failure_rec pointer from the extent state. Convert the io_failure_tree to an rb tree + spinlock in the inode, and then use our rb tree simple helpers to insert and find failed records. This greatly cleans up this code and makes it easier to separate out the extent_io_tree code. Signed-off-by: Josef Bacik --- fs/btrfs/btrfs_inode.h | 3 +- fs/btrfs/extent-io-tree.h | 3 - fs/btrfs/extent_io.c | 164 +++++++++++------------------------ fs/btrfs/extent_io.h | 5 +- fs/btrfs/inode.c | 5 +- fs/btrfs/misc.h | 35 ++++++++ include/trace/events/btrfs.h | 1 - 7 files changed, 96 insertions(+), 120 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index b160b8e124e0..108af52ba870 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -94,7 +94,8 @@ struct btrfs_inode { /* special utility tree used to record which mirrors have already been * tried when checksums fail for a given block */ - struct extent_io_tree io_failure_tree; + struct rb_root io_failure_tree; + spinlock_t io_failure_lock; /* * Keep track of where the inode has extent items mapped in order to diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 5584968643eb..ee2ba4b6e4a1 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -56,7 +56,6 @@ enum { IO_TREE_FS_EXCLUDED_EXTENTS, IO_TREE_BTREE_INODE_IO, IO_TREE_INODE_IO, - IO_TREE_INODE_IO_FAILURE, IO_TREE_RELOC_BLOCKS, IO_TREE_TRANS_DIRTY_PAGES, IO_TREE_ROOT_DIRTY_LOG_PAGES, @@ -89,8 +88,6 @@ struct extent_state { refcount_t refs; u32 state; - struct io_failure_record *failrec; - #ifdef CONFIG_BTRFS_DEBUG struct list_head leak_list; #endif diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index be14c15cfafa..c15a6433d43c 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -326,7 +326,6 @@ static struct extent_state *alloc_extent_state(gfp_t mask) if (!state) return state; state->state = 0; - state->failrec = NULL; RB_CLEAR_NODE(&state->rb_node); btrfs_leak_debug_add(&leak_lock, &state->leak_list, &states); refcount_set(&state->refs, 1); @@ -2159,64 +2158,30 @@ u64 count_range_bits(struct extent_io_tree *tree, return total_bytes; } -/* - * set the private field for a given byte offset in the tree. If there isn't - * an extent_state there already, this does nothing. - */ -static int set_state_failrec(struct extent_io_tree *tree, u64 start, - struct io_failure_record *failrec) +static int insert_failrec(struct btrfs_inode *inode, + struct io_failure_record *failrec) { - struct rb_node *node; - struct extent_state *state; - int ret = 0; + struct rb_node *exist; - spin_lock(&tree->lock); - /* - * this search will find all the extents that end after - * our range starts. - */ - node = tree_search(tree, start); - if (!node) { - ret = -ENOENT; - goto out; - } - state = rb_entry(node, struct extent_state, rb_node); - if (state->start != start) { - ret = -ENOENT; - goto out; - } - state->failrec = failrec; -out: - spin_unlock(&tree->lock); - return ret; + spin_lock(&inode->io_failure_lock); + exist = rb_simple_insert(&inode->io_failure_tree, failrec->bytenr, + &failrec->rb_node); + spin_unlock(&inode->io_failure_lock); + + return (exist == NULL) ? 0 : -EEXIST; } -static struct io_failure_record *get_state_failrec(struct extent_io_tree *tree, - u64 start) +static struct io_failure_record *get_failrec(struct btrfs_inode *inode, + u64 start) { struct rb_node *node; - struct extent_state *state; - struct io_failure_record *failrec; + struct io_failure_record *failrec = ERR_PTR(-ENOENT); - spin_lock(&tree->lock); - /* - * this search will find all the extents that end after - * our range starts. - */ - node = tree_search(tree, start); - if (!node) { - failrec = ERR_PTR(-ENOENT); - goto out; - } - state = rb_entry(node, struct extent_state, rb_node); - if (state->start != start) { - failrec = ERR_PTR(-ENOENT); - goto out; - } - - failrec = state->failrec; -out: - spin_unlock(&tree->lock); + spin_lock(&inode->io_failure_lock); + node = rb_simple_search(&inode->io_failure_tree, start); + if (node) + failrec = rb_entry(node, struct io_failure_record, rb_node); + spin_unlock(&inode->io_failure_lock); return failrec; } @@ -2276,28 +2241,20 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, return bitset; } -static int free_io_failure(struct extent_io_tree *failure_tree, - struct extent_io_tree *io_tree, +static int free_io_failure(struct btrfs_inode *inode, struct io_failure_record *rec) { int ret; - int err = 0; - set_state_failrec(failure_tree, rec->start, NULL); - ret = clear_extent_bits(failure_tree, rec->start, - rec->start + rec->len - 1, - EXTENT_LOCKED | EXTENT_DIRTY); - if (ret) - err = ret; + spin_lock(&inode->io_failure_lock); + rb_erase(&rec->rb_node, &inode->io_failure_tree); + spin_unlock(&inode->io_failure_lock); - ret = clear_extent_bits(io_tree, rec->start, - rec->start + rec->len - 1, + ret = clear_extent_bits(&inode->io_tree, rec->bytenr, + rec->bytenr + rec->len - 1, EXTENT_DAMAGED); - if (ret && !err) - err = ret; - kfree(rec); - return err; + return ret; } /* @@ -2436,22 +2393,13 @@ int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, struct page *page, unsigned int pg_offset) { struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct extent_io_tree *failure_tree = &inode->io_failure_tree; struct extent_io_tree *io_tree = &inode->io_tree; u64 ino = btrfs_ino(inode); - u64 private; struct io_failure_record *failrec; struct extent_state *state; int mirror; - int ret; - - private = 0; - ret = count_range_bits(failure_tree, &private, (u64)-1, 1, - EXTENT_DIRTY, 0); - if (!ret) - return 0; - failrec = get_state_failrec(failure_tree, start); + failrec = get_failrec(inode, start); if (IS_ERR(failrec)) return 0; @@ -2462,12 +2410,12 @@ int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, spin_lock(&io_tree->lock); state = find_first_extent_bit_state(io_tree, - failrec->start, + failrec->bytenr, EXTENT_LOCKED); spin_unlock(&io_tree->lock); - if (!state || state->start > failrec->start || - state->end < failrec->start + failrec->len - 1) + if (!state || state->start > failrec->bytenr || + state->end < failrec->bytenr + failrec->len - 1) goto out; mirror = failrec->this_mirror; @@ -2478,7 +2426,7 @@ int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, } while (mirror != failrec->failed_mirror); out: - free_io_failure(failure_tree, io_tree, failrec); + free_io_failure(inode, failrec); return 0; } @@ -2490,30 +2438,26 @@ int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, */ void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, u64 end) { - struct extent_io_tree *failure_tree = &inode->io_failure_tree; struct io_failure_record *failrec; - struct extent_state *state, *next; + struct rb_node *n, *next; - if (RB_EMPTY_ROOT(&failure_tree->state)) + if (RB_EMPTY_ROOT(&inode->io_failure_tree)) return; - spin_lock(&failure_tree->lock); - state = find_first_extent_bit_state(failure_tree, start, EXTENT_DIRTY); - while (state) { - if (state->start > end) + spin_lock(&inode->io_failure_lock); + n = rb_simple_search_first(&inode->io_failure_tree, start); + while (n) { + failrec = rb_entry(n, struct io_failure_record, rb_node); + if (failrec->bytenr > end) break; - ASSERT(state->end <= end); - - next = next_state(state); - - failrec = state->failrec; - free_extent_state(state); + next = rb_next(n); + rb_erase(&failrec->rb_node, &inode->io_failure_tree); kfree(failrec); - state = next; + n = next; } - spin_unlock(&failure_tree->lock); + spin_unlock(&inode->io_failure_lock); } static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode, @@ -2523,16 +2467,15 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); u64 start = bbio->file_offset + bio_offset; struct io_failure_record *failrec; - struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree; struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; const u32 sectorsize = fs_info->sectorsize; int ret; - failrec = get_state_failrec(failure_tree, start); + failrec = get_failrec(BTRFS_I(inode), start); if (!IS_ERR(failrec)) { btrfs_debug(fs_info, "Get IO Failure Record: (found) logical=%llu, start=%llu, len=%llu", - failrec->logical, failrec->start, failrec->len); + failrec->logical, failrec->bytenr, failrec->len); /* * when data can be on disk more than twice, add to failrec here * (e.g. with a list for failed_mirror) to make @@ -2547,7 +2490,8 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode if (!failrec) return ERR_PTR(-ENOMEM); - failrec->start = start; + RB_CLEAR_NODE(&failrec->rb_node); + failrec->bytenr = start; failrec->len = sectorsize; failrec->failed_mirror = bbio->mirror_num; failrec->this_mirror = bbio->mirror_num; @@ -2572,17 +2516,17 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode } /* Set the bits in the private failure tree */ - ret = set_extent_bits(failure_tree, start, start + sectorsize - 1, - EXTENT_LOCKED | EXTENT_DIRTY); - if (ret >= 0) { - ret = set_state_failrec(failure_tree, start, failrec); - /* Set the bits in the inode's tree */ - ret = set_extent_bits(tree, start, start + sectorsize - 1, - EXTENT_DAMAGED); - } else if (ret < 0) { + ret = insert_failrec(BTRFS_I(inode), failrec); + if (ret) { kfree(failrec); return ERR_PTR(ret); } + ret = set_extent_bits(tree, start, start + sectorsize - 1, + EXTENT_DAMAGED); + if (ret) { + free_io_failure(BTRFS_I(inode), failrec); + return ERR_PTR(ret); + } return failrec; } @@ -2594,8 +2538,6 @@ int btrfs_repair_one_sector(struct inode *inode, struct btrfs_bio *failed_bbio, u64 start = failed_bbio->file_offset + bio_offset; struct io_failure_record *failrec; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); - struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; - struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree; struct bio *failed_bio = &failed_bbio->bio; const int icsum = bio_offset >> fs_info->sectorsize_bits; struct bio *repair_bio; @@ -2624,7 +2566,7 @@ int btrfs_repair_one_sector(struct inode *inode, struct btrfs_bio *failed_bbio, btrfs_debug(fs_info, "failed to repair num_copies %d this_mirror %d failed_mirror %d", failrec->num_copies, failrec->this_mirror, failrec->failed_mirror); - free_io_failure(failure_tree, tree, failrec); + free_io_failure(BTRFS_I(inode), failrec); return -EIO; } diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 69a86ae6fd50..879f8a60cd6f 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -254,8 +254,11 @@ int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num); * bio end_io callback is called to indicate things have failed. */ struct io_failure_record { + struct { + struct rb_node rb_node; + u64 bytenr; + }; /* Use rb_simple_node for search/insert */ struct page *page; - u64 start; u64 len; u64 logical; int this_mirror; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a1b9e2a455d9..7bdf89756be4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8899,6 +8899,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) ei->last_log_commit = 0; spin_lock_init(&ei->lock); + spin_lock_init(&ei->io_failure_lock); ei->outstanding_extents = 0; if (sb->s_magic != BTRFS_TEST_MAGIC) btrfs_init_metadata_block_rsv(fs_info, &ei->block_rsv, @@ -8915,12 +8916,10 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) inode = &ei->vfs_inode; extent_map_tree_init(&ei->extent_tree); extent_io_tree_init(fs_info, &ei->io_tree, IO_TREE_INODE_IO, inode); - extent_io_tree_init(fs_info, &ei->io_failure_tree, - IO_TREE_INODE_IO_FAILURE, inode); extent_io_tree_init(fs_info, &ei->file_extent_tree, IO_TREE_INODE_FILE_EXTENT, inode); + ei->io_failure_tree = RB_ROOT; ei->io_tree.track_uptodate = true; - ei->io_failure_tree.track_uptodate = true; atomic_set(&ei->sync_writers, 0); mutex_init(&ei->log_mutex); btrfs_ordered_inode_tree_init(&ei->ordered_tree); diff --git a/fs/btrfs/misc.h b/fs/btrfs/misc.h index 340f995652f2..4ffd603d19cb 100644 --- a/fs/btrfs/misc.h +++ b/fs/btrfs/misc.h @@ -88,6 +88,41 @@ static inline struct rb_node *rb_simple_search(struct rb_root *root, u64 bytenr) return NULL; } +/** + * Search @root from an entry that starts or comes after @bytenr. + * + * @root: the root to search. + * @bytenr: bytenr to search from. + * + * Return the rb_node that start at or after @bytenr. If there is no entry at + * or after @bytner return NULL. + */ +static inline struct rb_node *rb_simple_search_first(struct rb_root *root, + u64 bytenr) +{ + struct rb_node *node = root->rb_node, *ret = NULL; + struct rb_simple_node *entry, *ret_entry = NULL; + + while (node) { + entry = rb_entry(node, struct rb_simple_node, rb_node); + + if (bytenr < entry->bytenr) { + if (!ret || entry->bytenr < ret_entry->bytenr) { + ret = node; + ret_entry = entry; + } + + node = node->rb_left; + } else if (bytenr > entry->bytenr) { + node = node->rb_right; + } else { + return node; + } + } + + return ret; +} + static inline struct rb_node *rb_simple_insert(struct rb_root *root, u64 bytenr, struct rb_node *node) { diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index 73df80d462dc..4db905311d67 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -84,7 +84,6 @@ struct raid56_bio_trace_info; EM( IO_TREE_FS_EXCLUDED_EXTENTS, "EXCLUDED_EXTENTS") \ EM( IO_TREE_BTREE_INODE_IO, "BTREE_INODE_IO") \ EM( IO_TREE_INODE_IO, "INODE_IO") \ - EM( IO_TREE_INODE_IO_FAILURE, "INODE_IO_FAILURE") \ EM( IO_TREE_RELOC_BLOCKS, "RELOC_BLOCKS") \ EM( IO_TREE_TRANS_DIRTY_PAGES, "TRANS_DIRTY_PAGES") \ EM( IO_TREE_ROOT_DIRTY_LOG_PAGES, "ROOT_DIRTY_LOG_PAGES") \ From patchwork Fri Sep 2 20:16:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0552BECAAD5 for ; Fri, 2 Sep 2022 20:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229863AbiIBURE (ORCPT ); Fri, 2 Sep 2022 16:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiIBUQ4 (ORCPT ); Fri, 2 Sep 2022 16:16:56 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7BF0F2CBD for ; Fri, 2 Sep 2022 13:16:47 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id j17so2333227qtp.12 for ; Fri, 02 Sep 2022 13:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=Zzul0XjQ7K8RbEgqt69BK5NPau1GZEWDBk77SvrCOyE=; b=rpmLgkjuLnWxOxGVUk260emfvUEpMx2pXrGvHO3rlpWOMDqAdDFixMkyyBkU7Qfuo2 XW99vPm3P6CE2dUKqxunat0FHis6/rb9cqOyRQ22Zv9AnrpmysY/huqH8sVAAxjtG/el CHDqdBpM2nsVcQcXK+T7fIQG7W3DIa68mlZak4Rr9HWTWNGHbEvGNyj6U/yrn/pofR7R icCYLA2tc5kQrchm5L0hz2/bW1cdOQXpAA9DB5Pk1y00hZ5/FCkDKP2HjXeCym4Ipe2I YJRqwa+slOvC45erQbFfelDVm9D4TKzrVyYbqujhF4w9XnEWdu/yNhYoi9Ga01xrsmwX 4y0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Zzul0XjQ7K8RbEgqt69BK5NPau1GZEWDBk77SvrCOyE=; b=kNZOcMhFOvWOKy+A6SRW3mZ5mkMoT4PI09lFWcrNXkjpeEd0llYYpZ8PHDF9JPDH6b 7iU9yULXi6z83L6OlYiuGC0pI/enrAu09yVX19bAfkPdrwWC/oJXmdsc9kHneDoTv/OT IucIAnVil8M6ZVR611tVudmZxgVQ8xkUdKrjBQHWnJ27l4xOFyDz1SO6E3KzEjPG2OVs yQ0nNI43a9gaxju5PNCMoBKaAxDaIYKWIV+Gvcj2slJRDalQWK099jtbKG73WMYL0psv f2ZROprCEIZFroPvuxg8/TcIMuX6nZU9tAxcRpuqg/pwqyVOh7pe+rcCJTfL8kgRfrJV B4Sw== X-Gm-Message-State: ACgBeo3lK8cWb84EqszWDi/wCSLqyDClangb/M1t4aZdJS3zMxt3BrDY MhnIbO69KLxpo7Tpn1kk9MfXKPfXFyOWxA== X-Google-Smtp-Source: AA6agR62a5buKfFAlpAUC+RucTLQcgiLAj1HZUjhh+XWEcO2xggi3E5h7gM+2QQzZdRu7umAqd5m5w== X-Received: by 2002:ac8:5c53:0:b0:344:76e1:4843 with SMTP id j19-20020ac85c53000000b0034476e14843mr29356409qtj.281.1662149805829; Fri, 02 Sep 2022 13:16:45 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id r12-20020ac85c8c000000b00344fbd8270bsm1618835qta.42.2022.09.02.13.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:45 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/31] btrfs: use find_first_extent_bit in btrfs_clean_io_failure Date: Fri, 2 Sep 2022 16:16:09 -0400 Message-Id: <243544aa541f1331cc4efade59b1b0b34290a306.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently we're using find_first_extent_bit_state to check if our state contains the given failrec range, however this is more of an internal extent_io_tree helper, and is technically unsafe to use because we're accessing the state outside of the extent_io_tree lock. Instead use the normal helper find_first_extent_bit which returns the range of the extent state we find in find_first_extent_bit_state and use that to do our sanity checking. Signed-off-by: Josef Bacik --- fs/btrfs/extent_io.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c15a6433d43c..598cb66f65df 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2395,9 +2395,10 @@ int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, struct btrfs_fs_info *fs_info = inode->root->fs_info; struct extent_io_tree *io_tree = &inode->io_tree; u64 ino = btrfs_ino(inode); + u64 locked_start, locked_end; struct io_failure_record *failrec; - struct extent_state *state; int mirror; + int ret; failrec = get_failrec(inode, start); if (IS_ERR(failrec)) @@ -2408,14 +2409,10 @@ int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, if (sb_rdonly(fs_info->sb)) goto out; - spin_lock(&io_tree->lock); - state = find_first_extent_bit_state(io_tree, - failrec->bytenr, - EXTENT_LOCKED); - spin_unlock(&io_tree->lock); - - if (!state || state->start > failrec->bytenr || - state->end < failrec->bytenr + failrec->len - 1) + ret = find_first_extent_bit(io_tree, failrec->bytenr, &locked_start, + &locked_end, EXTENT_LOCKED, NULL); + if (ret || locked_start > failrec->bytenr || + locked_end < failrec->bytenr + failrec->len - 1) goto out; mirror = failrec->this_mirror; From patchwork Fri Sep 2 20:16:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A631ECAAD5 for ; Fri, 2 Sep 2022 20:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbiIBURG (ORCPT ); Fri, 2 Sep 2022 16:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbiIBUQ6 (ORCPT ); Fri, 2 Sep 2022 16:16:58 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10BEDF43B0 for ; Fri, 2 Sep 2022 13:16:49 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id g14so2335104qto.11 for ; Fri, 02 Sep 2022 13:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=phfHhYPseWCVNRFeUcRit5SlAyGmW0qmPuPJE5jR5sU=; b=gP3vd0NtPdv3DH+5AejF89FaC13HIRPQU2rLyjaMN0E44cW2/oxY0pnIiWMgz7PMwD 1jM8h19DX1nfd0oW+pf4aVXvGtMbkyJnlespsUyqT06ebvbTSPh6PVGhQJ3i2eE+Cs3f /+hjjuT4F47nXKoCNZ52E8sS4KBpG04XxM9pMfzlBRjAfvAiuE8yLYQig4F332/XsFY3 9heY1bvPIAPbw7HRfZbpWtCApE/C/ByMwJO7PIL31U8KKPBOMdd5sG1viKX1wyuNmNZM kq5vA45PqAqqthvRa97mHidFLwDEh92MluS2m+X0NPKSQnurquhGe76q2OB0caIMiOjC 3SWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=phfHhYPseWCVNRFeUcRit5SlAyGmW0qmPuPJE5jR5sU=; b=YcClrG3Vukpbjf0rw71zyW1+KSCcecfvqwlXLa+7/Kqx6A3yIkkp5O6hFoIALD9V9o 9DrUnC/QWwgIqB0hUFH6Ub4qqOjq+2jwKbzG9Fj/JthJleu8WjvSaZUjZJ1jZkEcvDyy gLjlNFtX953G3Jl1OkU/PLz8ZsPNmoQHDAJ3u3nxddhu6cmSxdFkJ0PAlcUTB2plA6Dp heai5G1yWuRRJ6+bi0W1SWnzgsKOks1pLpmm1k0xOkPajh03Pb5kby8pTp7PJtMXvJSV 6Bem05+PidL/heT6VwTSpN/Szy3ZPDIdJUIn5c8H3wJgTt2gDoeZeP6Hxy06lBCu1SA1 UPMw== X-Gm-Message-State: ACgBeo0qJm/c1knZK9NeQslm7GELpf1vl1tCXOPusGskUjmkCqxdFqVf zq6egPK7WgDNf6oY7lIqs9CScI7PUJxDrQ== X-Google-Smtp-Source: AA6agR4hgHTDAM3da46NFFE7H9ca/pY/N5LcNcBRnvRQHJ80deqQb6VBKEoQCdw/GJFof2YFB8qYHg== X-Received: by 2002:a05:622a:406:b0:343:7ae:4fe9 with SMTP id n6-20020a05622a040600b0034307ae4fe9mr30273853qtx.541.1662149807701; Fri, 02 Sep 2022 13:16:47 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id br36-20020a05620a462400b006b945519488sm2064561qkb.88.2022.09.02.13.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:47 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/31] btrfs: separate out the extent state and extent buffer init code Date: Fri, 2 Sep 2022 16:16:10 -0400 Message-Id: <8647f71f352e274f1ad97c4cdbdce6451d10e47b.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In order to help separate the extent buffer from the extent io tree code we need to break up the init functions. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.h | 4 ++-- fs/btrfs/extent_io.c | 21 ++++++++++++++------- fs/btrfs/extent_io.h | 3 +++ fs/btrfs/super.c | 17 ++++++++++++----- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index ee2ba4b6e4a1..6c2016db304b 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -108,8 +108,8 @@ static inline int lock_extent(struct extent_io_tree *tree, u64 start, u64 end) int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end); -int __init extent_io_init(void); -void __cold extent_io_exit(void); +int __init extent_state_init_cachep(void); +void __cold extent_state_free_cachep(void); u64 count_range_bits(struct extent_io_tree *tree, u64 *start, u64 search_end, diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 598cb66f65df..d95f0779676b 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -230,7 +230,7 @@ static void submit_write_bio(struct extent_page_data *epd, int ret) } } -int __init extent_io_init(void) +int __init extent_state_init_cachep(void) { extent_state_cache = kmem_cache_create("btrfs_extent_state", sizeof(struct extent_state), 0, @@ -238,18 +238,27 @@ int __init extent_io_init(void) if (!extent_state_cache) return -ENOMEM; + return 0; +} + +int __init extent_buffer_init_cachep(void) +{ extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer", sizeof(struct extent_buffer), 0, SLAB_MEM_SPREAD, NULL); - if (!extent_buffer_cache) { - kmem_cache_destroy(extent_state_cache); + if (!extent_buffer_cache) return -ENOMEM; - } return 0; } -void __cold extent_io_exit(void) +void __cold extent_state_free_cachep(void) +{ + btrfs_extent_state_leak_debug_check(); + kmem_cache_destroy(extent_state_cache); +} + +void __cold extent_buffer_free_cachep(void) { /* * Make sure all delayed rcu free are flushed before we @@ -257,8 +266,6 @@ void __cold extent_io_exit(void) */ rcu_barrier(); kmem_cache_destroy(extent_buffer_cache); - btrfs_extent_state_leak_debug_check(); - kmem_cache_destroy(extent_state_cache); } /* diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 879f8a60cd6f..52e4dfea2164 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -64,6 +64,9 @@ struct btrfs_fs_info; struct io_failure_record; struct extent_io_tree; +int __init extent_buffer_init_cachep(void); +void __cold extent_buffer_free_cachep(void); + typedef void (submit_bio_hook_t)(struct inode *inode, struct bio *bio, int mirror_num, enum btrfs_compression_type compress_type); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 767b86e7fe82..1593d4479dde 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2736,13 +2736,17 @@ static int __init init_btrfs_fs(void) if (err) goto free_compress; - err = extent_io_init(); + err = extent_state_init_cachep(); if (err) goto free_cachep; + err = extent_buffer_init_cachep(); + if (err) + goto free_extent_cachep; + err = btrfs_bioset_init(); if (err) - goto free_extent_io; + goto free_eb_cachep; err = extent_map_init(); if (err) @@ -2800,8 +2804,10 @@ static int __init init_btrfs_fs(void) extent_map_exit(); free_bioset: btrfs_bioset_exit(); -free_extent_io: - extent_io_exit(); +free_eb_cachep: + extent_buffer_free_cachep(); +free_extent_cachep: + extent_state_free_cachep(); free_cachep: btrfs_destroy_cachep(); free_compress: @@ -2821,7 +2827,8 @@ static void __exit exit_btrfs_fs(void) ordered_data_exit(); extent_map_exit(); btrfs_bioset_exit(); - extent_io_exit(); + extent_state_free_cachep(); + extent_buffer_free_cachep(); btrfs_interface_exit(); unregister_filesystem(&btrfs_fs_type); btrfs_exit_sysfs(); From patchwork Fri Sep 2 20:16:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A7B7C6FA83 for ; Fri, 2 Sep 2022 20:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229922AbiIBURI (ORCPT ); Fri, 2 Sep 2022 16:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbiIBUQ6 (ORCPT ); Fri, 2 Sep 2022 16:16:58 -0400 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E395F47F0 for ; Fri, 2 Sep 2022 13:16:51 -0700 (PDT) Received: by mail-qt1-x82e.google.com with SMTP id l5so2361515qtv.4 for ; Fri, 02 Sep 2022 13:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=dUXE5TkD0jgwoYKPSa779n8L9NLTD8kdB5l3Ups44Iw=; b=vbHKC6pyIm3wxNVIl269q/OkII95u9g8h5J+Uo5WdyYjnkGQ2va1bzqMFtHQdeDmsg a1xJ5ti+mVcP08lBnBoOt6V7kJir5tG3EQ/7Mx2VQcMHDIKf8jzrlCvs6dB/CF8+PBfm zvpmcEwQX7Z/XaSlGBQXphwX6smInq6Q4eS7YL5F671LHWWV8h4ZpgDJ8Y615rNQLOPc w557AEl8wRRwe06y9rIrX50XpcpgaWEJuzOF9IsU41Qdq6yDDTcF61ZCsHsmIHcW4hSu uyo53FmACqDVkO/JkzW01uzVoftuG4q5zOquyxPZ1QpwgdR+uFIoMrFnDc4xHUP/N8mz Yvfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=dUXE5TkD0jgwoYKPSa779n8L9NLTD8kdB5l3Ups44Iw=; b=K2yfGcO9JARAQOK8uj2uQrFSCz902z4pmcpnGs+dHOiMsn8VgrSJHTK5+vUNjNytBf 8wjLqPPtPbkm0aIrERY5Yd4BngUJfo8Q/LgwPty1xMy7coVV+7sFLZY7rxo/GOesTO40 f5sw3H4APvDelkFj2q/6eUAGghiWhjEwlFH8g9xu4FAMajrOmr/NAU4I/zQVI9Z7BMhw bF+jFO//fXBxMMXaf5jdNwj3cyIQn6RxvePGgyDULW9q9iZd8tnfkCKN+9h/zxOJTduG tLGaO9K5tHAqBiw2viw9qliaQm2HceeF/YnTstRHFC3eljSJune4QTcDp8Gfe0b2iaBb hKXw== X-Gm-Message-State: ACgBeo1TsWReUjU9A6zX0eW+r/G6Ig3yNEW7DqmMVMT6g3TXmuBZ01Vr 0ewvcY0oZ3J7Q3QeYPhmhqfnKwyRNky6Pw== X-Google-Smtp-Source: AA6agR7Bn5aFXe3DRcaowoa3isYmfqqkF2LcgDM0Ni0lAwqYWVGyo1fUR6Mc08W2NvUrkLGM1IlIUg== X-Received: by 2002:a05:622a:148f:b0:344:53fa:18c6 with SMTP id t15-20020a05622a148f00b0034453fa18c6mr30571912qtx.555.1662149809466; Fri, 02 Sep 2022 13:16:49 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id g19-20020ac84813000000b003051ea4e7f6sm1491782qtq.48.2022.09.02.13.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:48 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 06/31] btrfs: separate out the eb and extent state leak helpers Date: Fri, 2 Sep 2022 16:16:11 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently we have the add/del functions generic so that we can use them for both extent buffers and extent states. We want to separate this code however, so separate these helpers into per-object helpers in anticipation of the split. Signed-off-by: Josef Bacik --- fs/btrfs/extent_io.c | 58 +++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index d95f0779676b..27f412a3c668 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -43,25 +43,42 @@ static inline bool extent_state_in_tree(const struct extent_state *state) static LIST_HEAD(states); static DEFINE_SPINLOCK(leak_lock); -static inline void btrfs_leak_debug_add(spinlock_t *lock, - struct list_head *new, - struct list_head *head) +static inline void btrfs_leak_debug_add_eb(struct extent_buffer *eb) +{ + struct btrfs_fs_info *fs_info = eb->fs_info; + unsigned long flags; + + spin_lock_irqsave(&fs_info->eb_leak_lock, flags); + list_add(&eb->leak_list, &fs_info->allocated_ebs); + spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); +} + +static inline void btrfs_leak_debug_add_state(struct extent_state *state) { unsigned long flags; - spin_lock_irqsave(lock, flags); - list_add(new, head); - spin_unlock_irqrestore(lock, flags); + spin_lock_irqsave(&leak_lock, flags); + list_add(&state->leak_list, &states); + spin_unlock_irqrestore(&leak_lock, flags); +} + +static inline void btrfs_leak_debug_del_eb(struct extent_buffer *eb) +{ + struct btrfs_fs_info *fs_info = eb->fs_info; + unsigned long flags; + + spin_lock_irqsave(&fs_info->eb_leak_lock, flags); + list_del(&eb->leak_list); + spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); } -static inline void btrfs_leak_debug_del(spinlock_t *lock, - struct list_head *entry) +static inline void btrfs_leak_debug_del_state(struct extent_state *state) { unsigned long flags; - spin_lock_irqsave(lock, flags); - list_del(entry); - spin_unlock_irqrestore(lock, flags); + spin_lock_irqsave(&leak_lock, flags); + list_del(&state->leak_list); + spin_unlock_irqrestore(&leak_lock, flags); } void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) @@ -125,9 +142,11 @@ static inline void __btrfs_debug_check_extent_io_range(const char *caller, } } #else -#define btrfs_leak_debug_add(lock, new, head) do {} while (0) -#define btrfs_leak_debug_del(lock, entry) do {} while (0) -#define btrfs_extent_state_leak_debug_check() do {} while (0) +#define btrfs_leak_debug_add_eb(eb) do {} while (0) +#define btrfs_leak_debug_add_state(state) do {} while (0) +#define btrfs_leak_debug_del_eb(eb) do {} while (0) +#define btrfs_leak_debug_del_state(state) do {} while (0) +#define btrfs_extent_state_leak_debug_check() do {} while (0) #define btrfs_debug_check_extent_io_range(c, s, e) do {} while (0) #endif @@ -334,7 +353,7 @@ static struct extent_state *alloc_extent_state(gfp_t mask) return state; state->state = 0; RB_CLEAR_NODE(&state->rb_node); - btrfs_leak_debug_add(&leak_lock, &state->leak_list, &states); + btrfs_leak_debug_add_state(state); refcount_set(&state->refs, 1); init_waitqueue_head(&state->wq); trace_alloc_extent_state(state, mask, _RET_IP_); @@ -347,7 +366,7 @@ void free_extent_state(struct extent_state *state) return; if (refcount_dec_and_test(&state->refs)) { WARN_ON(extent_state_in_tree(state)); - btrfs_leak_debug_del(&leak_lock, &state->leak_list); + btrfs_leak_debug_del_state(state); trace_free_extent_state(state, _RET_IP_); kmem_cache_free(extent_state_cache, state); } @@ -5713,7 +5732,7 @@ static void btrfs_release_extent_buffer_pages(struct extent_buffer *eb) static inline void btrfs_release_extent_buffer(struct extent_buffer *eb) { btrfs_release_extent_buffer_pages(eb); - btrfs_leak_debug_del(&eb->fs_info->eb_leak_lock, &eb->leak_list); + btrfs_leak_debug_del_eb(eb); __free_extent_buffer(eb); } @@ -5730,8 +5749,7 @@ __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start, eb->bflags = 0; init_rwsem(&eb->lock); - btrfs_leak_debug_add(&fs_info->eb_leak_lock, &eb->leak_list, - &fs_info->allocated_ebs); + btrfs_leak_debug_add_eb(eb); INIT_LIST_HEAD(&eb->release_list); spin_lock_init(&eb->refs_lock); @@ -6199,7 +6217,7 @@ static int release_extent_buffer(struct extent_buffer *eb) spin_unlock(&eb->refs_lock); } - btrfs_leak_debug_del(&eb->fs_info->eb_leak_lock, &eb->leak_list); + btrfs_leak_debug_del_eb(eb); /* Should be safe to release our pages at this point */ btrfs_release_extent_buffer_pages(eb); #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS From patchwork Fri Sep 2 20:16:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0A7AC6FA82 for ; Fri, 2 Sep 2022 20:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229878AbiIBURJ (ORCPT ); Fri, 2 Sep 2022 16:17:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbiIBUQ6 (ORCPT ); Fri, 2 Sep 2022 16:16:58 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B079FF4931 for ; Fri, 2 Sep 2022 13:16:52 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id g14so2335190qto.11 for ; Fri, 02 Sep 2022 13:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=pwS5JNUJo5O1jJU5UJg3jmCFhjt1cK+PNS4yDs0aoYE=; b=jYDQl9x2UM710HlibjlTpUwqRyReagyEcgp1KRUUb2ZtRlLrOJfKLUqq5Cb50Sbbo2 bgVead260eYix10dO4oHhM9vyVnM32WlQEB2wFugUNoU59muowa2ePh7uDSjXI8389YN pxlHL5dNSd8calXmVta2iStZWnLPYXyWWPUqk4qPi8XjA7empeHBrlTl1ecWu8m8cTfb 2glJzu5dBBt5HvGdqtLyWyj4/3qsDWXTxPka8ogGJlmfI9XfwMJDL49W0R89Ywvq0uKO qxSFVX1cWJVjtvS/r4QY+t9urgxTOBqsMkFBjq7CTOhGrAXwzh6D2bH6DxP8XSNc9p5H fCfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=pwS5JNUJo5O1jJU5UJg3jmCFhjt1cK+PNS4yDs0aoYE=; b=kNBntTWdBTakti9wk4DsLTqj1VwLqgxwYtQoktF3gRf1w7a6FpDW86s2Kn88RU/t1v Yq/j6CZldOlMArldbMzecdG8R/3QGy1w0g4z0UCZx7uZ4eiEHmUloiHYyI/qoIWvVTVS cH+SJUAhvGgvPJkziobYoRbFmr9RMdtBNlf9BaqP5VDtQlUJRbjUWZWgZGOgaVV01AMm LDzc+UWCWTgDnGImCQglNCQH1/Xl1x3YHuZpwNyfBtRMCK4D1X/ZRE2Ldpe6Dx5Kx7oF 6MdDc6KCa1hmlOjxGnYL/Jzh7GY/u9+Xcnx3RxF6BbhiaQcf0o2XJdkDo+EB+45OzozV vCuA== X-Gm-Message-State: ACgBeo3CPwmGrtwdn38uPlGYwelIBkI3AS/4gIr9AI+MMs9ql83V2IcL VGKtRT8BHNjZ5dOzDL9RVcq2/t2dHzJhnQ== X-Google-Smtp-Source: AA6agR5Y3KhRMZzDNTMBxEBuv/hdiXXF04LPDYImV30QgG55KdmFnrXk9Wfyzwq6mLtEm6SerHuwvg== X-Received: by 2002:ac8:5d8f:0:b0:344:a747:abf1 with SMTP id d15-20020ac85d8f000000b00344a747abf1mr30118708qtx.273.1662149811084; Fri, 02 Sep 2022 13:16:51 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id r9-20020a05620a298900b006b919c6749esm2203497qkp.91.2022.09.02.13.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:50 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/31] btrfs: temporarily export alloc_extent_state helpers Date: Fri, 2 Sep 2022 16:16:12 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're going to move this code in stages, but while we're doing that we need to export these helpers so we can more easily move the code into the new file. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.h | 3 +++ fs/btrfs/extent_io.c | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 6c2016db304b..8e7a548b88e9 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -250,4 +250,7 @@ void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, struct page *page, unsigned int pg_offset); +struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc); +struct extent_state *alloc_extent_state(gfp_t mask); + #endif /* BTRFS_EXTENT_IO_TREE_H */ diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 27f412a3c668..47b12837edd6 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -339,7 +339,7 @@ void extent_io_tree_release(struct extent_io_tree *tree) spin_unlock(&tree->lock); } -static struct extent_state *alloc_extent_state(gfp_t mask) +struct extent_state *alloc_extent_state(gfp_t mask) { struct extent_state *state; @@ -710,8 +710,7 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree, return next; } -static struct extent_state * -alloc_extent_state_atomic(struct extent_state *prealloc) +struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc) { if (!prealloc) prealloc = alloc_extent_state(GFP_ATOMIC); From patchwork Fri Sep 2 20:16:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18E7BC6FA82 for ; Fri, 2 Sep 2022 20:17:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229961AbiIBURL (ORCPT ); Fri, 2 Sep 2022 16:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbiIBUQ7 (ORCPT ); Fri, 2 Sep 2022 16:16:59 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C21DD7CD0 for ; Fri, 2 Sep 2022 13:16:54 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id f14so2662761qkm.0 for ; Fri, 02 Sep 2022 13:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=UsmJoToCMvCmoMs6CQlYQ4tOCsfoDyl/L9fYIABJ7oE=; b=uq9BbXe/uZ0mXNjQnL5WAHYUiRvwy/aHqFfImR56Y3iBQOXNskRr5R78H2xMYiM+44 9Bk+ZTJ4ZjFJD6ldm19b8rVSbzZVOk9QsUo/Hhs22LZXVNnB5tBUYnfqhr0tUhM5LDLe tJRh+m0Uko6OfXIJcu3W77qNU1JvhMjigsIn1fF3qHFyltABtNv7KBbQFUtRLnwQ8o4o NkDLwlL6hOh7A6PUsckwdOXc9hwIq77WTxwQt7JXXvL9rzhrIe7Fv0YcNojuh5LeMkUx KZ0PXVwozwFIwiBWu4vZ2Bo44FNF6oatOKj+mv2qj0CKSbpFqRrtITknG6wU/kyo2m5K wEbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=UsmJoToCMvCmoMs6CQlYQ4tOCsfoDyl/L9fYIABJ7oE=; b=Usdm4l+aqgkdVLG0Ixt11a59K3WZUEzHz8JBGMYbL0OgJVAN7P8Jx+NbC7HJk9X44V jGW73AfcwVMr3LVc0+i3Pig+WDjdSIW3Q7Da03oe1WjZs++LUEqJq9BsjuOAn/R+thhx 7qeX7dkJ/XgGnB17CKXTsZq3CnHuwCnwGe35a2aAW4HgznsZBZPADQRFz5VWyNveBV9H a0PsBGIJGczmONG9u2fpPpOl7rVUF9z6Fw5W0Cd0/rOj10bfDTjdBWiwooZULBpxdQTs z415ZhvhunaheVbnG3UIlRUIrZhcUzHDYUgzLGwR04VWPuJQvLCB8S/sJNCYp6RrOMKL LNFw== X-Gm-Message-State: ACgBeo0Kl+9g31TyME0h2ZviVe1OWvFoqdBuoljlNI6SGcTirVHE/U2U 7phyaZS5NxFdV49aOObc6KTiXMERFNNnmQ== X-Google-Smtp-Source: AA6agR4IN3k0Vvu1eAAVkauPLfM8MrigmgS78BUKiAEQTWEEULp54K2pxHm/pP3zTT0+S6gOrt6Ifg== X-Received: by 2002:a05:620a:4409:b0:6bb:beeb:215e with SMTP id v9-20020a05620a440900b006bbbeeb215emr25857374qkp.414.1662149812705; Fri, 02 Sep 2022 13:16:52 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id bl4-20020a05620a1a8400b006b9526cfe6bsm2008497qkb.80.2022.09.02.13.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:52 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/31] btrfs: move extent state init and alloc functions to their own file Date: Fri, 2 Sep 2022 16:16:13 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Start cleaning up extent_io.c by moving the extent state code out of it. This patch starts with the extent state allocation code and the extent_io_tree init code. Signed-off-by: Josef Bacik --- fs/btrfs/Makefile | 2 +- fs/btrfs/extent-io-tree.c | 160 ++++++++++++++++++++++++++++++++++++++ fs/btrfs/extent-io-tree.h | 5 ++ fs/btrfs/extent_io.c | 155 ------------------------------------ 4 files changed, 166 insertions(+), 156 deletions(-) create mode 100644 fs/btrfs/extent-io-tree.c diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 99f9995670ea..fa9ddcc9eb0b 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -31,7 +31,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \ block-rsv.o delalloc-space.o block-group.o discard.o reflink.o \ - subpage.o tree-mod-log.o + subpage.o tree-mod-log.o extent-io-tree.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c new file mode 100644 index 000000000000..2aedac452636 --- /dev/null +++ b/fs/btrfs/extent-io-tree.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include "ctree.h" +#include "extent-io-tree.h" + +static struct kmem_cache *extent_state_cache; + +#ifdef CONFIG_BTRFS_DEBUG +static LIST_HEAD(states); +static DEFINE_SPINLOCK(leak_lock); + +static inline void btrfs_leak_debug_add_state(struct extent_state *state) +{ + unsigned long flags; + + spin_lock_irqsave(&leak_lock, flags); + list_add(&state->leak_list, &states); + spin_unlock_irqrestore(&leak_lock, flags); +} + +static inline void btrfs_leak_debug_del_state(struct extent_state *state) +{ + unsigned long flags; + + spin_lock_irqsave(&leak_lock, flags); + list_del(&state->leak_list); + spin_unlock_irqrestore(&leak_lock, flags); +} + +static inline void btrfs_extent_state_leak_debug_check(void) +{ + struct extent_state *state; + + while (!list_empty(&states)) { + state = list_entry(states.next, struct extent_state, leak_list); + pr_err("BTRFS: state leak: start %llu end %llu state %u in tree %d refs %d\n", + state->start, state->end, state->state, + extent_state_in_tree(state), + refcount_read(&state->refs)); + list_del(&state->leak_list); + kmem_cache_free(extent_state_cache, state); + } +} +#else +#define btrfs_leak_debug_add_state(state) do {} while (0) +#define btrfs_leak_debug_del_state(state) do {} while (0) +#define btrfs_extent_state_leak_debug_check() do {} while (0) +#endif + +/* + * For the file_extent_tree, we want to hold the inode lock when we lookup and + * update the disk_i_size, but lockdep will complain because our io_tree we hold + * the tree lock and get the inode lock when setting delalloc. These two things + * are unrelated, so make a class for the file_extent_tree so we don't get the + * two locking patterns mixed up. + */ +static struct lock_class_key file_extent_tree_class; + +void extent_io_tree_init(struct btrfs_fs_info *fs_info, + struct extent_io_tree *tree, unsigned int owner, + void *private_data) +{ + tree->fs_info = fs_info; + tree->state = RB_ROOT; + tree->dirty_bytes = 0; + spin_lock_init(&tree->lock); + tree->private_data = private_data; + tree->owner = owner; + if (owner == IO_TREE_INODE_FILE_EXTENT) + lockdep_set_class(&tree->lock, &file_extent_tree_class); +} + +void extent_io_tree_release(struct extent_io_tree *tree) +{ + spin_lock(&tree->lock); + /* + * Do a single barrier for the waitqueue_active check here, the state + * of the waitqueue should not change once extent_io_tree_release is + * called. + */ + smp_mb(); + while (!RB_EMPTY_ROOT(&tree->state)) { + struct rb_node *node; + struct extent_state *state; + + node = rb_first(&tree->state); + state = rb_entry(node, struct extent_state, rb_node); + rb_erase(&state->rb_node, &tree->state); + RB_CLEAR_NODE(&state->rb_node); + /* + * btree io trees aren't supposed to have tasks waiting for + * changes in the flags of extent states ever. + */ + ASSERT(!waitqueue_active(&state->wq)); + free_extent_state(state); + + cond_resched_lock(&tree->lock); + } + spin_unlock(&tree->lock); +} + +struct extent_state *alloc_extent_state(gfp_t mask) +{ + struct extent_state *state; + + /* + * The given mask might be not appropriate for the slab allocator, + * drop the unsupported bits + */ + mask &= ~(__GFP_DMA32|__GFP_HIGHMEM); + state = kmem_cache_alloc(extent_state_cache, mask); + if (!state) + return state; + state->state = 0; + RB_CLEAR_NODE(&state->rb_node); + btrfs_leak_debug_add_state(state); + refcount_set(&state->refs, 1); + init_waitqueue_head(&state->wq); + trace_alloc_extent_state(state, mask, _RET_IP_); + return state; +} + +struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc) +{ + if (!prealloc) + prealloc = alloc_extent_state(GFP_ATOMIC); + + return prealloc; +} + +void free_extent_state(struct extent_state *state) +{ + if (!state) + return; + if (refcount_dec_and_test(&state->refs)) { + WARN_ON(extent_state_in_tree(state)); + btrfs_leak_debug_del_state(state); + trace_free_extent_state(state, _RET_IP_); + kmem_cache_free(extent_state_cache, state); + } +} + +void __cold extent_state_free_cachep(void) +{ + btrfs_extent_state_leak_debug_check(); + kmem_cache_destroy(extent_state_cache); +} + +int __init extent_state_init_cachep(void) +{ + extent_state_cache = kmem_cache_create("btrfs_extent_state", + sizeof(struct extent_state), 0, + SLAB_MEM_SPREAD, NULL); + if (!extent_state_cache) + return -ENOMEM; + + return 0; +} diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 8e7a548b88e9..56266e75b4fe 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -253,4 +253,9 @@ int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc); struct extent_state *alloc_extent_state(gfp_t mask); +static inline bool extent_state_in_tree(const struct extent_state *state) +{ + return !RB_EMPTY_NODE(&state->rb_node); +} + #endif /* BTRFS_EXTENT_IO_TREE_H */ diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 47b12837edd6..dade06901937 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -31,18 +31,9 @@ #include "block-group.h" #include "compression.h" -static struct kmem_cache *extent_state_cache; static struct kmem_cache *extent_buffer_cache; -static inline bool extent_state_in_tree(const struct extent_state *state) -{ - return !RB_EMPTY_NODE(&state->rb_node); -} - #ifdef CONFIG_BTRFS_DEBUG -static LIST_HEAD(states); -static DEFINE_SPINLOCK(leak_lock); - static inline void btrfs_leak_debug_add_eb(struct extent_buffer *eb) { struct btrfs_fs_info *fs_info = eb->fs_info; @@ -53,15 +44,6 @@ static inline void btrfs_leak_debug_add_eb(struct extent_buffer *eb) spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); } -static inline void btrfs_leak_debug_add_state(struct extent_state *state) -{ - unsigned long flags; - - spin_lock_irqsave(&leak_lock, flags); - list_add(&state->leak_list, &states); - spin_unlock_irqrestore(&leak_lock, flags); -} - static inline void btrfs_leak_debug_del_eb(struct extent_buffer *eb) { struct btrfs_fs_info *fs_info = eb->fs_info; @@ -72,15 +54,6 @@ static inline void btrfs_leak_debug_del_eb(struct extent_buffer *eb) spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); } -static inline void btrfs_leak_debug_del_state(struct extent_state *state) -{ - unsigned long flags; - - spin_lock_irqsave(&leak_lock, flags); - list_del(&state->leak_list); - spin_unlock_irqrestore(&leak_lock, flags); -} - void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) { struct extent_buffer *eb; @@ -108,21 +81,6 @@ void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); } -static inline void btrfs_extent_state_leak_debug_check(void) -{ - struct extent_state *state; - - while (!list_empty(&states)) { - state = list_entry(states.next, struct extent_state, leak_list); - pr_err("BTRFS: state leak: start %llu end %llu state %u in tree %d refs %d\n", - state->start, state->end, state->state, - extent_state_in_tree(state), - refcount_read(&state->refs)); - list_del(&state->leak_list); - kmem_cache_free(extent_state_cache, state); - } -} - #define btrfs_debug_check_extent_io_range(tree, start, end) \ __btrfs_debug_check_extent_io_range(__func__, (tree), (start), (end)) static inline void __btrfs_debug_check_extent_io_range(const char *caller, @@ -143,10 +101,7 @@ static inline void __btrfs_debug_check_extent_io_range(const char *caller, } #else #define btrfs_leak_debug_add_eb(eb) do {} while (0) -#define btrfs_leak_debug_add_state(state) do {} while (0) #define btrfs_leak_debug_del_eb(eb) do {} while (0) -#define btrfs_leak_debug_del_state(state) do {} while (0) -#define btrfs_extent_state_leak_debug_check() do {} while (0) #define btrfs_debug_check_extent_io_range(c, s, e) do {} while (0) #endif @@ -249,17 +204,6 @@ static void submit_write_bio(struct extent_page_data *epd, int ret) } } -int __init extent_state_init_cachep(void) -{ - extent_state_cache = kmem_cache_create("btrfs_extent_state", - sizeof(struct extent_state), 0, - SLAB_MEM_SPREAD, NULL); - if (!extent_state_cache) - return -ENOMEM; - - return 0; -} - int __init extent_buffer_init_cachep(void) { extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer", @@ -271,12 +215,6 @@ int __init extent_buffer_init_cachep(void) return 0; } -void __cold extent_state_free_cachep(void) -{ - btrfs_extent_state_leak_debug_check(); - kmem_cache_destroy(extent_state_cache); -} - void __cold extent_buffer_free_cachep(void) { /* @@ -287,91 +225,6 @@ void __cold extent_buffer_free_cachep(void) kmem_cache_destroy(extent_buffer_cache); } -/* - * For the file_extent_tree, we want to hold the inode lock when we lookup and - * update the disk_i_size, but lockdep will complain because our io_tree we hold - * the tree lock and get the inode lock when setting delalloc. These two things - * are unrelated, so make a class for the file_extent_tree so we don't get the - * two locking patterns mixed up. - */ -static struct lock_class_key file_extent_tree_class; - -void extent_io_tree_init(struct btrfs_fs_info *fs_info, - struct extent_io_tree *tree, unsigned int owner, - void *private_data) -{ - tree->fs_info = fs_info; - tree->state = RB_ROOT; - tree->dirty_bytes = 0; - spin_lock_init(&tree->lock); - tree->private_data = private_data; - tree->owner = owner; - if (owner == IO_TREE_INODE_FILE_EXTENT) - lockdep_set_class(&tree->lock, &file_extent_tree_class); -} - -void extent_io_tree_release(struct extent_io_tree *tree) -{ - spin_lock(&tree->lock); - /* - * Do a single barrier for the waitqueue_active check here, the state - * of the waitqueue should not change once extent_io_tree_release is - * called. - */ - smp_mb(); - while (!RB_EMPTY_ROOT(&tree->state)) { - struct rb_node *node; - struct extent_state *state; - - node = rb_first(&tree->state); - state = rb_entry(node, struct extent_state, rb_node); - rb_erase(&state->rb_node, &tree->state); - RB_CLEAR_NODE(&state->rb_node); - /* - * btree io trees aren't supposed to have tasks waiting for - * changes in the flags of extent states ever. - */ - ASSERT(!waitqueue_active(&state->wq)); - free_extent_state(state); - - cond_resched_lock(&tree->lock); - } - spin_unlock(&tree->lock); -} - -struct extent_state *alloc_extent_state(gfp_t mask) -{ - struct extent_state *state; - - /* - * The given mask might be not appropriate for the slab allocator, - * drop the unsupported bits - */ - mask &= ~(__GFP_DMA32|__GFP_HIGHMEM); - state = kmem_cache_alloc(extent_state_cache, mask); - if (!state) - return state; - state->state = 0; - RB_CLEAR_NODE(&state->rb_node); - btrfs_leak_debug_add_state(state); - refcount_set(&state->refs, 1); - init_waitqueue_head(&state->wq); - trace_alloc_extent_state(state, mask, _RET_IP_); - return state; -} - -void free_extent_state(struct extent_state *state) -{ - if (!state) - return; - if (refcount_dec_and_test(&state->refs)) { - WARN_ON(extent_state_in_tree(state)); - btrfs_leak_debug_del_state(state); - trace_free_extent_state(state, _RET_IP_); - kmem_cache_free(extent_state_cache, state); - } -} - /** * Search @tree for an entry that contains @offset. Such entry would have * entry->start <= offset && entry->end >= offset. @@ -710,14 +563,6 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree, return next; } -struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc) -{ - if (!prealloc) - prealloc = alloc_extent_state(GFP_ATOMIC); - - return prealloc; -} - static void extent_io_tree_panic(struct extent_io_tree *tree, int err) { btrfs_panic(tree->fs_info, err, From patchwork Fri Sep 2 20:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9813ECAAD5 for ; Fri, 2 Sep 2022 20:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbiIBURK (ORCPT ); Fri, 2 Sep 2022 16:17:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230103AbiIBUQ7 (ORCPT ); Fri, 2 Sep 2022 16:16:59 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7331CCD5E for ; Fri, 2 Sep 2022 13:16:55 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id cv7so2278282qvb.3 for ; Fri, 02 Sep 2022 13:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=7EsfeYjU4s8rij760mXrt8RqUZoUNdhhKeRimdFUM/A=; b=p8pihoyg5v08ITPwbF3KyX1YgmVVVNjwpAKkziUR0FdRPoPc5Rd4u12UL6gHwFT5PP j/kCZJD6u9LogysSZOsKx0PenX9upS0Mi24f2aL9mGzTfhfnMUFmFsjHFz2dtqTldWY5 ahxSok+zI1TPGkOOHUfl2MxKoyMoNyQJC6ccPfxpC3rI042qDKbOK8uhae47tUs7HDpj S33+kMD6+c+HT1xb2qjdB3ha9a0V/DyFuJlhyqBBlWH9G7wkRM9OlVUeRzQhaS35V0Dh YNYsu/hQVeSExBlNkDBx/S06DmL05DlwAVYJvgO6AqSub3aCAs2KknG+I7X6WRRBsELM nB0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=7EsfeYjU4s8rij760mXrt8RqUZoUNdhhKeRimdFUM/A=; b=2TZeOgBDDYTTWy/s3Z7rkCBz3Ka20Y/nO/cnK1gd9F4gnXoa4jOxdt3SDR7AppCz/X iqAksSXzp/t4ifRXmQ/lBgq/CGSWUrX/ymxTRInpkhN0HHhXSTb11uWyDxfACAP4Ie7i dsxS4VA/jpwscqzS0qRipYozb4rosqTks/sr79z+z6TmegGoIAaTozljF/yThwJiwFBM JYpRSxjCiciUMnP/Z+W5oVq058LsP8q/60TsjzGMDoxUe7WPEbf/d5CRxTKmIGkp+5SO 4LwHweFDWBufbqTB6FvydPlttDMCwLFHofs8j+WOQOjDl6Icn9dU21Fr7wLiWAx0+FjO CzkA== X-Gm-Message-State: ACgBeo1Mfw/xBefpPoUQzkcwD20SgGxhODxUS4irle54GomGR152gFJJ rXAOIB5LlhAGo2f825KY7+32UvvKPi6Kfg== X-Google-Smtp-Source: AA6agR5VfGS7swyJYMjaYJiG9oBZdIRR4ULwRx33ty8AgBaG1Ak9vIwPP6eyA21hlyEd0657NONTuQ== X-Received: by 2002:a05:6214:2689:b0:498:f5b1:5c1e with SMTP id gm9-20020a056214268900b00498f5b15c1emr28873065qvb.40.1662149814751; Fri, 02 Sep 2022 13:16:54 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id l5-20020a05620a28c500b006b5f06186aesm2141997qkp.65.2022.09.02.13.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:54 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/31] btrfs: convert BUG_ON(EXTENT_BIT_LOCKED) checks to ASSERT's Date: Fri, 2 Sep 2022 16:16:14 -0400 Message-Id: <4360935b03c1103514ac907f35405e1137fe5486.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org These should be ASSERT()'s, not BUG_ON()'s. Signed-off-by: Josef Bacik --- fs/btrfs/extent_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index dade06901937..028dc72d8b6a 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1293,7 +1293,7 @@ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, * either fail with -EEXIST or changeset will record the whole * range. */ - BUG_ON(bits & EXTENT_LOCKED); + ASSERT(!(bits & EXTENT_LOCKED)); return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS, changeset); @@ -1321,7 +1321,7 @@ int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, * Don't support EXTENT_LOCKED case, same reason as * set_record_extent_bits(). */ - BUG_ON(bits & EXTENT_LOCKED); + ASSERT(!(bits & EXTENT_LOCKED)); return __clear_extent_bit(tree, start, end, bits, 0, 0, NULL, GFP_NOFS, changeset); From patchwork Fri Sep 2 20:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34F68ECAAD5 for ; Fri, 2 Sep 2022 20:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbiIBURM (ORCPT ); Fri, 2 Sep 2022 16:17:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbiIBURA (ORCPT ); Fri, 2 Sep 2022 16:17:00 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2331CE303 for ; Fri, 2 Sep 2022 13:16:57 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id y15so2281496qvn.2 for ; Fri, 02 Sep 2022 13:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=ZzcvWi/eDe71X+0jhazlHVz7b/oAGDfCILaIoMWD+vE=; b=p7j6NPf6zJerjIM4WJhldVcy1TSJ6x88yl+mKubfx8kO5n3WHL37ZfJjpgVL7mGmv1 Jmm7jw29hr0ZExwtTcwbgKpfA5s+wBCckUmE3FmZ4u40Mi33O6U8fYq2kQERt+WJBJfc AUhtrKOgmwEnAN08u2zDIQQvzz9b61Izsb6i0z8DdfQrAwE8WkJ6Lq7yLQ2uGEGuCZ7S tHPB3bOP5hesw3LU3JZ5uIyBgaFP+nPKUH7vuPKIA/C7V1tVC41dFkMPKtI17PE74X/5 XkENdyuPXBXpaUzp7WxaxmNy7VJ9vm5HIIRc57+8oFQvLb92Dn82wVVFoW7nIao9zboR aM/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ZzcvWi/eDe71X+0jhazlHVz7b/oAGDfCILaIoMWD+vE=; b=yS66F7jKRpsTRDsyM5tSwzLrFiHQmH2sEdewpAFRKM1hhEdO0Lo6NV4tAlAuTbR+Gc 1MIwmme7+M0cCJC0Gaj1BdvH3dqTK5RNHlHmukGOHZKIGbrczZ0zFiZPor+aF5L6Aoc3 0MWYntyO1sOKRH7mVqEOq2Hkfv8jNYe4pPiT2Y62YVMTU317kChTgwj5fEnUTgwvmaPM JcP+hHb2GLnnq2RyJS3KCEoEKSvok8JiUWGtDW38IjNqBp+NMbHAnPIbJUW98S7FKbJS smVbktk3RQEgBZAngRXcTkcHN6VSuVMahpk8InE9Ct2mp4tRctGCC1tnuUhyMFHQLN1x 5rnQ== X-Gm-Message-State: ACgBeo2NPOXM7AgacL5BYAU8QAcS0nSHE0JcmsqkpmKCubbVdnpFOgAZ +5qH+Sc79mXGqm/FyB87h6POA8PxR2Ss8w== X-Google-Smtp-Source: AA6agR4wmGVh9XfzRWhW+87xisVzbGCSLGmyW7GgQKBLm6pNwJcC+kjLIcrPiqjpSmAlyRXS9RCtIw== X-Received: by 2002:ad4:5bc7:0:b0:48b:e9ed:47a8 with SMTP id t7-20020ad45bc7000000b0048be9ed47a8mr30616715qvt.108.1662149816453; Fri, 02 Sep 2022 13:16:56 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id bl28-20020a05620a1a9c00b006bc5cdc890bsm1866755qkb.77.2022.09.02.13.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:56 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/31] btrfs: move simple extent bit helpers out of extent_io.c Date: Fri, 2 Sep 2022 16:16:15 -0400 Message-Id: <066177b3509944b0af49e1900358b7e9d6b14139.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org These are just variants and wrappers around the actual work horses of the extent state. Extract these out of extent_io.c. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 45 +++++++++++++++++++++++++++++ fs/btrfs/extent-io-tree.h | 20 +++++++++---- fs/btrfs/extent_io.c | 60 --------------------------------------- 3 files changed, 60 insertions(+), 65 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 2aedac452636..7b8ac9b3bc55 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -142,6 +142,51 @@ void free_extent_state(struct extent_state *state) } } +/* wrappers around set/clear extent bit */ +int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, struct extent_changeset *changeset) +{ + /* + * We don't support EXTENT_LOCKED yet, as current changeset will + * record any bits changed, so for EXTENT_LOCKED case, it will + * either fail with -EEXIST or changeset will record the whole + * range. + */ + ASSERT(!(bits & EXTENT_LOCKED)); + + return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS, + changeset); +} + +int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, struct extent_changeset *changeset) +{ + /* + * Don't support EXTENT_LOCKED case, same reason as + * set_record_extent_bits(). + */ + ASSERT(!(bits & EXTENT_LOCKED)); + + return __clear_extent_bit(tree, start, end, bits, 0, 0, NULL, GFP_NOFS, + changeset); +} + +int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) +{ + int err; + u64 failed_start; + + err = set_extent_bit(tree, start, end, EXTENT_LOCKED, EXTENT_LOCKED, + &failed_start, NULL, GFP_NOFS, NULL); + if (err == -EEXIST) { + if (failed_start > start) + clear_extent_bit(tree, start, failed_start - 1, + EXTENT_LOCKED, 1, 0, NULL); + return 0; + } + return 1; +} + void __cold extent_state_free_cachep(void) { btrfs_extent_state_leak_debug_check(); diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 56266e75b4fe..16a9da4149f3 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -120,14 +120,19 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, int filled, struct extent_state *cached_state); int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, struct extent_changeset *changeset); -int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int wake, int delete, - struct extent_state **cached); int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, int wake, int delete, struct extent_state **cached, gfp_t mask, struct extent_changeset *changeset); +static inline int clear_extent_bit(struct extent_io_tree *tree, u64 start, + u64 end, u32 bits, int wake, int delete, + struct extent_state **cached) +{ + return __clear_extent_bit(tree, start, end, bits, wake, delete, + cached, GFP_NOFS, NULL); +} + static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end) { return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, NULL); @@ -164,8 +169,13 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, unsigned exclusive_bits, u64 *failed_start, struct extent_state **cached_state, gfp_t mask, struct extent_changeset *changeset); -int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits); + +static inline int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, + u64 end, u32 bits) +{ + return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, + GFP_NOWAIT, NULL); +} static inline int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 028dc72d8b6a..b8fdd4aa7583 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1283,50 +1283,6 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, return err; } -/* wrappers around set/clear extent bit */ -int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, struct extent_changeset *changeset) -{ - /* - * We don't support EXTENT_LOCKED yet, as current changeset will - * record any bits changed, so for EXTENT_LOCKED case, it will - * either fail with -EEXIST or changeset will record the whole - * range. - */ - ASSERT(!(bits & EXTENT_LOCKED)); - - return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS, - changeset); -} - -int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits) -{ - return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, - GFP_NOWAIT, NULL); -} - -int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int wake, int delete, - struct extent_state **cached) -{ - return __clear_extent_bit(tree, start, end, bits, wake, delete, - cached, GFP_NOFS, NULL); -} - -int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, struct extent_changeset *changeset) -{ - /* - * Don't support EXTENT_LOCKED case, same reason as - * set_record_extent_bits(). - */ - ASSERT(!(bits & EXTENT_LOCKED)); - - return __clear_extent_bit(tree, start, end, bits, 0, 0, NULL, GFP_NOFS, - changeset); -} - /* * either insert or lock state struct between start and end use mask to tell * us if waiting is desired. @@ -1351,22 +1307,6 @@ int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, return err; } -int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) -{ - int err; - u64 failed_start; - - err = set_extent_bit(tree, start, end, EXTENT_LOCKED, EXTENT_LOCKED, - &failed_start, NULL, GFP_NOFS, NULL); - if (err == -EEXIST) { - if (failed_start > start) - clear_extent_bit(tree, start, failed_start - 1, - EXTENT_LOCKED, 1, 0, NULL); - return 0; - } - return 1; -} - void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) { unsigned long index = start >> PAGE_SHIFT; From patchwork Fri Sep 2 20:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56B32C6FA83 for ; Fri, 2 Sep 2022 20:17:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229764AbiIBURN (ORCPT ); Fri, 2 Sep 2022 16:17:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbiIBURA (ORCPT ); Fri, 2 Sep 2022 16:17:00 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A87D344C for ; Fri, 2 Sep 2022 13:16:58 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id g14so2335388qto.11 for ; Fri, 02 Sep 2022 13:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=HRhiJtjzbat0qp8UfnLyt/cT/Aa6D+S4PuZAeaJNGJM=; b=pLYXIOpVsTjibJLSJXa82BSfgDkS6gyNYsyT9rKU7p6pG/JgMz4gIDOKkEU8XP3DfX 9ignNsuliNJ+5jP+KosuvuhEtA94JHeBTINgIMXI64I4bFut+WyH2XqDRsa9A9m7ujqm Ooxex5E6ByciD3Sj31ffsGylrJbRLVnxgMkgzjaUJEv6Wr9iWHU4apoeX1dLEzWiFAI1 OCdYGf96AKG6/UiGoOuK7EHiiCE1iWMF83pIdtqm8UcCceufOQg+Hq32lr+uUVNvSzL9 hqkKo9ncPywtFVNHCM5Y0AA8+8OrMUVljqY7PH3Zgrq7OgAtsMM0x6PptAQphnFpKD8j P4IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=HRhiJtjzbat0qp8UfnLyt/cT/Aa6D+S4PuZAeaJNGJM=; b=51vGqum7TrxTpGl5cMpaDVnLiaHh+KD96HZa5jIxMJCIphOqFwFjPuCzJuULoZvEHy ABo/2T3WR+B6FVpXZx3bvUAu/pcARCXG2/Oh+tdkuMZ1zchRzW3clgTNEXHk17MTT9B5 HfvqY/F2skGhjepTlIN/MaggfT9naNL7pSISbAKp3WIxASg38s6Knxu3NddkWeV+1EdG rZO+wHs3eSH+WTBvGVWNAKpLscSA1CQGqDGFqM7H5QrdGYuOJ2+kfvC4UoSGIg/gAOrP 1YKSWC2jvw3mssRmxzrmqhFhOqqQRyLqn9GYL/PxJ5OXqfJ+XLP22J2ug2JIh7vVRXn4 KjEg== X-Gm-Message-State: ACgBeo2i2/qua+2EVZuSZq8M4lT0bvfH3e2OhHNoQa8dIBRFq6JGypGa Tl/6ONbO0kS8QgfdSjaoWP9YAB7qHOUezg== X-Google-Smtp-Source: AA6agR6t2lXmMKCz19estObM3/EbMdAOE83tt9XAQaH1DJiBygFjM9ZnlqfwNPAgIgbkdl67WF2gwQ== X-Received: by 2002:a05:622a:1788:b0:344:7c86:f9a1 with SMTP id s8-20020a05622a178800b003447c86f9a1mr29446087qtk.22.1662149818149; Fri, 02 Sep 2022 13:16:58 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id s11-20020a05620a29cb00b006bad20a6cfesm2166248qkp.102.2022.09.02.13.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:57 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 11/31] btrfs: export wait_extent_bit Date: Fri, 2 Sep 2022 16:16:16 -0400 Message-Id: <9a17df6dd26b9231b51843c205346bbad218034c.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is used by the subpage code in addition to lock_extent_bits, so export it so we can move it out of extent_io.c Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.h | 1 + fs/btrfs/extent_io.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 16a9da4149f3..3b63aeca941a 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -253,6 +253,7 @@ int extent_invalidate_folio(struct extent_io_tree *tree, bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, u64 *end, u64 max_bytes, struct extent_state **cached_state); +void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits); /* This should be reworked in the future and put elsewhere. */ void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index b8fdd4aa7583..5bfa14f2b5e3 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -753,8 +753,7 @@ static void wait_on_state(struct extent_io_tree *tree, * The range [start, end] is inclusive. * The tree lock is taken by this function */ -static void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits) +void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { struct extent_state *state; struct rb_node *node; From patchwork Fri Sep 2 20:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7A2BC6FA82 for ; Fri, 2 Sep 2022 20:17:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229943AbiIBURP (ORCPT ); Fri, 2 Sep 2022 16:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiIBURG (ORCPT ); Fri, 2 Sep 2022 16:17:06 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0F8BDC098 for ; Fri, 2 Sep 2022 13:17:02 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id r6so2355054qtx.6 for ; Fri, 02 Sep 2022 13:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=J4Q0+2UlvPptsU6wqSy1AboUJJ+wa8hVYR0l2yQfhbY=; b=nzNnrfOKbhOEnLp2xgzwtUxryDy5tpxtXKegmdHus573kGSi9p7rWFDP18fxQi9N1A gFG+baOE01GGKtNYi9s6NkYqSbj+UMZ4waHp/PfFaAPRQKhDtntH2SEQvv3tgZzdB94l IyLl44ZytBzpgcBf+nH69PwxBQGqcmCrpII84if/cqZEyRiSeI3TUHsUksM9fiTeHL9J LxgAUNiTyxm7hQJH8iHpgcTjlwWw8qYaO4KfMZPbMjomu5RD/JKForM5tdM+wZa/wf3W EfK9DAxp2hoHD3o4NeFy1Kqpb0oI7QVgchBgOPx4vk+MiXPcfjlg7cOJmZ0lVH27NG6q dhLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=J4Q0+2UlvPptsU6wqSy1AboUJJ+wa8hVYR0l2yQfhbY=; b=HHGbYMlKCDh0x4iK7BHVKQCaEtiFKx4jt8iV4pjuBWY0eBL9pRz5s01Lv2bcoIz2F5 t6n7OIXwBQaQXGcmyEJHA0ksie9eDyZp+q5yhJMYRLmUPep/RHRNDnOckapibpHTPF26 EczOmaO6GOvUsgs3Bfv9LddAZnHNYW/irMOklKx3t68+pT1/Pw77VYrM5BCxkGi/ijBT Dz/gkRCWjjC8xW5aqR3DkyUX39pe5vq8jtjIoKfQt60VMV4La/Hqt9g27p/qR7X7M3ch nIyAy15b9XHcpY6HSvkx6Lwh0mG7jZO3b49KjIL6iPlwNpH4+KUJr7wJWCJxCIosJnPy LGPg== X-Gm-Message-State: ACgBeo2tPqXzQw8sBbgGf2+v9F7OZzNmEuMaUDmfNNdjDBRiru55NCWO QsBF5bBKRz7sMy9TWUL5lyqFWt4u2Mftqg== X-Google-Smtp-Source: AA6agR7S8FSysjtuQgzy6zy6kAlFMW4Wm9F/SnBh5S6XDQbDmxjBdlhl5UWWJAhJ/FppWrQbP3FUBA== X-Received: by 2002:ac8:58d4:0:b0:344:5dbe:38a4 with SMTP id u20-20020ac858d4000000b003445dbe38a4mr30575293qta.381.1662149820158; Fri, 02 Sep 2022 13:17:00 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id d16-20020ac86150000000b0033a5048464fsm1709312qtm.11.2022.09.02.13.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:16:59 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 12/31] btrfs: move the core extent_io_tree code into extent-io-tree.c Date: Fri, 2 Sep 2022 16:16:17 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is a big patch unfortunately, all of this code is tightly coupled together. There is no code change at all, it is simply cut and paste from extent_io.c into extent-io-tree.c. Signed-off-by: Josef Bacik Reported-by: kernel test robot --- fs/btrfs/extent-io-tree.c | 1532 ++++++++++++++++++++++++++++++++++ fs/btrfs/extent_io.c | 1658 ++----------------------------------- 2 files changed, 1596 insertions(+), 1594 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 7b8ac9b3bc55..850c4e1c83f5 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -4,6 +4,8 @@ #include #include "ctree.h" #include "extent-io-tree.h" +#include "btrfs_inode.h" +#include "misc.h" static struct kmem_cache *extent_state_cache; @@ -43,12 +45,38 @@ static inline void btrfs_extent_state_leak_debug_check(void) kmem_cache_free(extent_state_cache, state); } } + +#define btrfs_debug_check_extent_io_range(tree, start, end) \ + __btrfs_debug_check_extent_io_range(__func__, (tree), (start), (end)) +static inline void __btrfs_debug_check_extent_io_range(const char *caller, + struct extent_io_tree *tree, u64 start, u64 end) +{ + struct inode *inode = tree->private_data; + u64 isize; + + if (!inode || !is_data_inode(inode)) + return; + + isize = i_size_read(inode); + if (end >= PAGE_SIZE && (end % 2) == 0 && end != isize - 1) { + btrfs_debug_rl(BTRFS_I(inode)->root->fs_info, + "%s: ino %llu isize %llu odd range [%llu,%llu]", + caller, btrfs_ino(BTRFS_I(inode)), isize, start, end); + } +} #else #define btrfs_leak_debug_add_state(state) do {} while (0) #define btrfs_leak_debug_del_state(state) do {} while (0) #define btrfs_extent_state_leak_debug_check() do {} while (0) +#define btrfs_debug_check_extent_io_range(c, s, e) do {} while (0) #endif +struct tree_entry { + u64 start; + u64 end; + struct rb_node rb_node; +}; + /* * For the file_extent_tree, we want to hold the inode lock when we lookup and * update the disk_i_size, but lockdep will complain because our io_tree we hold @@ -142,6 +170,24 @@ void free_extent_state(struct extent_state *state) } } +static int add_extent_changeset(struct extent_state *state, u32 bits, + struct extent_changeset *changeset, + int set) +{ + int ret; + + if (!changeset) + return 0; + if (set && (state->state & bits) == bits) + return 0; + if (!set && (state->state & bits) == 0) + return 0; + changeset->bytes_changed += state->end - state->start + 1; + ret = ulist_add(&changeset->range_changed, state->start, state->end, + GFP_ATOMIC); + return ret; +} + /* wrappers around set/clear extent bit */ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, struct extent_changeset *changeset) @@ -187,6 +233,1492 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) return 1; } +/** + * Search @tree for an entry that contains @offset. Such entry would have + * entry->start <= offset && entry->end >= offset. + * + * @tree: the tree to search + * @offset: offset that should fall within an entry in @tree + * @node_ret: pointer where new node should be anchored (used when inserting an + * entry in the tree) + * @parent_ret: points to entry which would have been the parent of the entry, + * containing @offset + * + * Return a pointer to the entry that contains @offset byte address and don't change + * @node_ret and @parent_ret. + * + * If no such entry exists, return pointer to entry that ends before @offset + * and fill parameters @node_ret and @parent_ret, ie. does not return NULL. + */ +static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree, + u64 offset, + struct rb_node ***node_ret, + struct rb_node **parent_ret) +{ + struct rb_root *root = &tree->state; + struct rb_node **node = &root->rb_node; + struct rb_node *prev = NULL; + struct tree_entry *entry; + + while (*node) { + prev = *node; + entry = rb_entry(prev, struct tree_entry, rb_node); + + if (offset < entry->start) + node = &(*node)->rb_left; + else if (offset > entry->end) + node = &(*node)->rb_right; + else + return *node; + } + + if (node_ret) + *node_ret = node; + if (parent_ret) + *parent_ret = prev; + + /* Search neighbors until we find the first one past the end */ + while (prev && offset > entry->end) { + prev = rb_next(prev); + entry = rb_entry(prev, struct tree_entry, rb_node); + } + + return prev; +} + +/* + * Inexact rb-tree search, return the next entry if @offset is not found + */ +static inline struct rb_node *tree_search(struct extent_io_tree *tree, u64 offset) +{ + return tree_search_for_insert(tree, offset, NULL, NULL); +} + +/** + * Search offset in the tree or fill neighbor rbtree node pointers. + * + * @tree: the tree to search + * @offset: offset that should fall within an entry in @tree + * @next_ret: pointer to the first entry whose range ends after @offset + * @prev_ret: pointer to the first entry whose range begins before @offset + * + * Return a pointer to the entry that contains @offset byte address. If no + * such entry exists, then return NULL and fill @prev_ret and @next_ret. + * Otherwise return the found entry and other pointers are left untouched. + */ +static struct rb_node *tree_search_prev_next(struct extent_io_tree *tree, + u64 offset, + struct rb_node **prev_ret, + struct rb_node **next_ret) +{ + struct rb_root *root = &tree->state; + struct rb_node **node = &root->rb_node; + struct rb_node *prev = NULL; + struct rb_node *orig_prev = NULL; + struct tree_entry *entry; + + ASSERT(prev_ret); + ASSERT(next_ret); + + while (*node) { + prev = *node; + entry = rb_entry(prev, struct tree_entry, rb_node); + + if (offset < entry->start) + node = &(*node)->rb_left; + else if (offset > entry->end) + node = &(*node)->rb_right; + else + return *node; + } + + orig_prev = prev; + while (prev && offset > entry->end) { + prev = rb_next(prev); + entry = rb_entry(prev, struct tree_entry, rb_node); + } + *next_ret = prev; + prev = orig_prev; + + entry = rb_entry(prev, struct tree_entry, rb_node); + while (prev && offset < entry->start) { + prev = rb_prev(prev); + entry = rb_entry(prev, struct tree_entry, rb_node); + } + *prev_ret = prev; + + return NULL; +} + +/* + * utility function to look for merge candidates inside a given range. + * Any extents with matching state are merged together into a single + * extent in the tree. Extents with EXTENT_IO in their state field + * are not merged because the end_io handlers need to be able to do + * operations on them without sleeping (or doing allocations/splits). + * + * This should be called with the tree lock held. + */ +static void merge_state(struct extent_io_tree *tree, + struct extent_state *state) +{ + struct extent_state *other; + struct rb_node *other_node; + + if (state->state & (EXTENT_LOCKED | EXTENT_BOUNDARY)) + return; + + other_node = rb_prev(&state->rb_node); + if (other_node) { + other = rb_entry(other_node, struct extent_state, rb_node); + if (other->end == state->start - 1 && + other->state == state->state) { + if (tree->private_data && + is_data_inode(tree->private_data)) + btrfs_merge_delalloc_extent(tree->private_data, + state, other); + state->start = other->start; + rb_erase(&other->rb_node, &tree->state); + RB_CLEAR_NODE(&other->rb_node); + free_extent_state(other); + } + } + other_node = rb_next(&state->rb_node); + if (other_node) { + other = rb_entry(other_node, struct extent_state, rb_node); + if (other->start == state->end + 1 && + other->state == state->state) { + if (tree->private_data && + is_data_inode(tree->private_data)) + btrfs_merge_delalloc_extent(tree->private_data, + state, other); + state->end = other->end; + rb_erase(&other->rb_node, &tree->state); + RB_CLEAR_NODE(&other->rb_node); + free_extent_state(other); + } + } +} + +static void set_state_bits(struct extent_io_tree *tree, + struct extent_state *state, u32 bits, + struct extent_changeset *changeset); + +/* + * insert an extent_state struct into the tree. 'bits' are set on the + * struct before it is inserted. + * + * This may return -EEXIST if the extent is already there, in which case the + * state struct is freed. + * + * The tree lock is not taken internally. This is a utility function and + * probably isn't what you want to call (see set/clear_extent_bit). + */ +static int insert_state(struct extent_io_tree *tree, + struct extent_state *state, + u32 bits, struct extent_changeset *changeset) +{ + struct rb_node **node; + struct rb_node *parent; + const u64 end = state->end; + + set_state_bits(tree, state, bits, changeset); + + node = &tree->state.rb_node; + while (*node) { + struct tree_entry *entry; + + parent = *node; + entry = rb_entry(parent, struct tree_entry, rb_node); + + if (end < entry->start) { + node = &(*node)->rb_left; + } else if (end > entry->end) { + node = &(*node)->rb_right; + } else { + btrfs_err(tree->fs_info, + "found node %llu %llu on insert of %llu %llu", + entry->start, entry->end, state->start, end); + return -EEXIST; + } + } + + rb_link_node(&state->rb_node, parent, node); + rb_insert_color(&state->rb_node, &tree->state); + + merge_state(tree, state); + return 0; +} + +/* + * Insert state to @tree to the location given by @node and @parent. + */ +static void insert_state_fast(struct extent_io_tree *tree, + struct extent_state *state, struct rb_node **node, + struct rb_node *parent, unsigned bits, + struct extent_changeset *changeset) +{ + set_state_bits(tree, state, bits, changeset); + rb_link_node(&state->rb_node, parent, node); + rb_insert_color(&state->rb_node, &tree->state); + merge_state(tree, state); +} + +/* + * split a given extent state struct in two, inserting the preallocated + * struct 'prealloc' as the newly created second half. 'split' indicates an + * offset inside 'orig' where it should be split. + * + * Before calling, + * the tree has 'orig' at [orig->start, orig->end]. After calling, there + * are two extent state structs in the tree: + * prealloc: [orig->start, split - 1] + * orig: [ split, orig->end ] + * + * The tree locks are not taken by this function. They need to be held + * by the caller. + */ +static int split_state(struct extent_io_tree *tree, struct extent_state *orig, + struct extent_state *prealloc, u64 split) +{ + struct rb_node *parent = NULL; + struct rb_node **node; + + if (tree->private_data && is_data_inode(tree->private_data)) + btrfs_split_delalloc_extent(tree->private_data, orig, split); + + prealloc->start = orig->start; + prealloc->end = split - 1; + prealloc->state = orig->state; + orig->start = split; + + parent = &orig->rb_node; + node = &parent; + while (*node) { + struct tree_entry *entry; + + parent = *node; + entry = rb_entry(parent, struct tree_entry, rb_node); + + if (prealloc->end < entry->start) { + node = &(*node)->rb_left; + } else if (prealloc->end > entry->end) { + node = &(*node)->rb_right; + } else { + free_extent_state(prealloc); + return -EEXIST; + } + } + + rb_link_node(&prealloc->rb_node, parent, node); + rb_insert_color(&prealloc->rb_node, &tree->state); + + return 0; +} + +static struct extent_state *next_state(struct extent_state *state) +{ + struct rb_node *next = rb_next(&state->rb_node); + if (next) + return rb_entry(next, struct extent_state, rb_node); + else + return NULL; +} + +/* + * utility function to clear some bits in an extent state struct. + * it will optionally wake up anyone waiting on this state (wake == 1). + * + * If no bits are set on the state struct after clearing things, the + * struct is freed and removed from the tree + */ +static struct extent_state *clear_state_bit(struct extent_io_tree *tree, + struct extent_state *state, + u32 bits, int wake, + struct extent_changeset *changeset) +{ + struct extent_state *next; + u32 bits_to_clear = bits & ~EXTENT_CTLBITS; + int ret; + + if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { + u64 range = state->end - state->start + 1; + WARN_ON(range > tree->dirty_bytes); + tree->dirty_bytes -= range; + } + + if (tree->private_data && is_data_inode(tree->private_data)) + btrfs_clear_delalloc_extent(tree->private_data, state, bits); + + ret = add_extent_changeset(state, bits_to_clear, changeset, 0); + BUG_ON(ret < 0); + state->state &= ~bits_to_clear; + if (wake) + wake_up(&state->wq); + if (state->state == 0) { + next = next_state(state); + if (extent_state_in_tree(state)) { + rb_erase(&state->rb_node, &tree->state); + RB_CLEAR_NODE(&state->rb_node); + free_extent_state(state); + } else { + WARN_ON(1); + } + } else { + merge_state(tree, state); + next = next_state(state); + } + return next; +} + +static void extent_io_tree_panic(struct extent_io_tree *tree, int err) +{ + btrfs_panic(tree->fs_info, err, + "locking error: extent tree was modified by another thread while locked"); +} + +/* + * clear some bits on a range in the tree. This may require splitting + * or inserting elements in the tree, so the gfp mask is used to + * indicate which allocations or sleeping are allowed. + * + * pass 'wake' == 1 to kick any sleepers, and 'delete' == 1 to remove + * the given range from the tree regardless of state (ie for truncate). + * + * the range [start, end] is inclusive. + * + * This takes the tree lock, and returns 0 on success and < 0 on error. + */ +int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, int wake, int delete, + struct extent_state **cached_state, + gfp_t mask, struct extent_changeset *changeset) +{ + struct extent_state *state; + struct extent_state *cached; + struct extent_state *prealloc = NULL; + struct rb_node *node; + u64 last_end; + int err; + int clear = 0; + + btrfs_debug_check_extent_io_range(tree, start, end); + trace_btrfs_clear_extent_bit(tree, start, end - start + 1, bits); + + if (bits & EXTENT_DELALLOC) + bits |= EXTENT_NORESERVE; + + if (delete) + bits |= ~EXTENT_CTLBITS; + + if (bits & (EXTENT_LOCKED | EXTENT_BOUNDARY)) + clear = 1; +again: + if (!prealloc && gfpflags_allow_blocking(mask)) { + /* + * Don't care for allocation failure here because we might end + * up not needing the pre-allocated extent state at all, which + * is the case if we only have in the tree extent states that + * cover our input range and don't cover too any other range. + * If we end up needing a new extent state we allocate it later. + */ + prealloc = alloc_extent_state(mask); + } + + spin_lock(&tree->lock); + if (cached_state) { + cached = *cached_state; + + if (clear) { + *cached_state = NULL; + cached_state = NULL; + } + + if (cached && extent_state_in_tree(cached) && + cached->start <= start && cached->end > start) { + if (clear) + refcount_dec(&cached->refs); + state = cached; + goto hit_next; + } + if (clear) + free_extent_state(cached); + } + /* + * this search will find the extents that end after + * our range starts + */ + node = tree_search(tree, start); + if (!node) + goto out; + state = rb_entry(node, struct extent_state, rb_node); +hit_next: + if (state->start > end) + goto out; + WARN_ON(state->end < start); + last_end = state->end; + + /* the state doesn't have the wanted bits, go ahead */ + if (!(state->state & bits)) { + state = next_state(state); + goto next; + } + + /* + * | ---- desired range ---- | + * | state | or + * | ------------- state -------------- | + * + * We need to split the extent we found, and may flip + * bits on second half. + * + * If the extent we found extends past our range, we + * just split and search again. It'll get split again + * the next time though. + * + * If the extent we found is inside our range, we clear + * the desired bit on it. + */ + + if (state->start < start) { + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); + err = split_state(tree, state, prealloc, start); + if (err) + extent_io_tree_panic(tree, err); + + prealloc = NULL; + if (err) + goto out; + if (state->end <= end) { + state = clear_state_bit(tree, state, bits, wake, changeset); + goto next; + } + goto search_again; + } + /* + * | ---- desired range ---- | + * | state | + * We need to split the extent, and clear the bit + * on the first half + */ + if (state->start <= end && state->end > end) { + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); + err = split_state(tree, state, prealloc, end + 1); + if (err) + extent_io_tree_panic(tree, err); + + if (wake) + wake_up(&state->wq); + + clear_state_bit(tree, prealloc, bits, wake, changeset); + + prealloc = NULL; + goto out; + } + + state = clear_state_bit(tree, state, bits, wake, changeset); +next: + if (last_end == (u64)-1) + goto out; + start = last_end + 1; + if (start <= end && state && !need_resched()) + goto hit_next; + +search_again: + if (start > end) + goto out; + spin_unlock(&tree->lock); + if (gfpflags_allow_blocking(mask)) + cond_resched(); + goto again; + +out: + spin_unlock(&tree->lock); + if (prealloc) + free_extent_state(prealloc); + + return 0; + +} + +static void wait_on_state(struct extent_io_tree *tree, + struct extent_state *state) + __releases(tree->lock) + __acquires(tree->lock) +{ + DEFINE_WAIT(wait); + prepare_to_wait(&state->wq, &wait, TASK_UNINTERRUPTIBLE); + spin_unlock(&tree->lock); + schedule(); + spin_lock(&tree->lock); + finish_wait(&state->wq, &wait); +} + +/* + * waits for one or more bits to clear on a range in the state tree. + * The range [start, end] is inclusive. + * The tree lock is taken by this function + */ +void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) +{ + struct extent_state *state; + struct rb_node *node; + + btrfs_debug_check_extent_io_range(tree, start, end); + + spin_lock(&tree->lock); +again: + while (1) { + /* + * this search will find all the extents that end after + * our range starts + */ + node = tree_search(tree, start); +process_node: + if (!node) + break; + + state = rb_entry(node, struct extent_state, rb_node); + + if (state->start > end) + goto out; + + if (state->state & bits) { + start = state->start; + refcount_inc(&state->refs); + wait_on_state(tree, state); + free_extent_state(state); + goto again; + } + start = state->end + 1; + + if (start > end) + break; + + if (!cond_resched_lock(&tree->lock)) { + node = rb_next(node); + goto process_node; + } + } +out: + spin_unlock(&tree->lock); +} + +static void set_state_bits(struct extent_io_tree *tree, + struct extent_state *state, + u32 bits, struct extent_changeset *changeset) +{ + u32 bits_to_set = bits & ~EXTENT_CTLBITS; + int ret; + + if (tree->private_data && is_data_inode(tree->private_data)) + btrfs_set_delalloc_extent(tree->private_data, state, bits); + + if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { + u64 range = state->end - state->start + 1; + tree->dirty_bytes += range; + } + ret = add_extent_changeset(state, bits_to_set, changeset, 1); + BUG_ON(ret < 0); + state->state |= bits_to_set; +} + +static void cache_state_if_flags(struct extent_state *state, + struct extent_state **cached_ptr, + unsigned flags) +{ + if (cached_ptr && !(*cached_ptr)) { + if (!flags || (state->state & flags)) { + *cached_ptr = state; + refcount_inc(&state->refs); + } + } +} + +static void cache_state(struct extent_state *state, + struct extent_state **cached_ptr) +{ + return cache_state_if_flags(state, cached_ptr, + EXTENT_LOCKED | EXTENT_BOUNDARY); +} + +/* + * set some bits on a range in the tree. This may require allocations or + * sleeping, so the gfp mask is used to indicate what is allowed. + * + * If any of the exclusive bits are set, this will fail with -EEXIST if some + * part of the range already has the desired bits set. The start of the + * existing range is returned in failed_start in this case. + * + * [start, end] is inclusive This takes the tree lock. + */ +int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, + u32 exclusive_bits, u64 *failed_start, + struct extent_state **cached_state, gfp_t mask, + struct extent_changeset *changeset) +{ + struct extent_state *state; + struct extent_state *prealloc = NULL; + struct rb_node *node; + struct rb_node **p; + struct rb_node *parent; + int err = 0; + u64 last_start; + u64 last_end; + + btrfs_debug_check_extent_io_range(tree, start, end); + trace_btrfs_set_extent_bit(tree, start, end - start + 1, bits); + + if (exclusive_bits) + ASSERT(failed_start); + else + ASSERT(failed_start == NULL); +again: + if (!prealloc && gfpflags_allow_blocking(mask)) { + /* + * Don't care for allocation failure here because we might end + * up not needing the pre-allocated extent state at all, which + * is the case if we only have in the tree extent states that + * cover our input range and don't cover too any other range. + * If we end up needing a new extent state we allocate it later. + */ + prealloc = alloc_extent_state(mask); + } + + spin_lock(&tree->lock); + if (cached_state && *cached_state) { + state = *cached_state; + if (state->start <= start && state->end > start && + extent_state_in_tree(state)) { + node = &state->rb_node; + goto hit_next; + } + } + /* + * this search will find all the extents that end after + * our range starts. + */ + node = tree_search_for_insert(tree, start, &p, &parent); + if (!node) { + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); + prealloc->start = start; + prealloc->end = end; + insert_state_fast(tree, prealloc, p, parent, bits, changeset); + cache_state(prealloc, cached_state); + prealloc = NULL; + goto out; + } + state = rb_entry(node, struct extent_state, rb_node); +hit_next: + last_start = state->start; + last_end = state->end; + + /* + * | ---- desired range ---- | + * | state | + * + * Just lock what we found and keep going + */ + if (state->start == start && state->end <= end) { + if (state->state & exclusive_bits) { + *failed_start = state->start; + err = -EEXIST; + goto out; + } + + set_state_bits(tree, state, bits, changeset); + cache_state(state, cached_state); + merge_state(tree, state); + if (last_end == (u64)-1) + goto out; + start = last_end + 1; + state = next_state(state); + if (start < end && state && state->start == start && + !need_resched()) + goto hit_next; + goto search_again; + } + + /* + * | ---- desired range ---- | + * | state | + * or + * | ------------- state -------------- | + * + * We need to split the extent we found, and may flip bits on + * second half. + * + * If the extent we found extends past our + * range, we just split and search again. It'll get split + * again the next time though. + * + * If the extent we found is inside our range, we set the + * desired bit on it. + */ + if (state->start < start) { + if (state->state & exclusive_bits) { + *failed_start = start; + err = -EEXIST; + goto out; + } + + /* + * If this extent already has all the bits we want set, then + * skip it, not necessary to split it or do anything with it. + */ + if ((state->state & bits) == bits) { + start = state->end + 1; + cache_state(state, cached_state); + goto search_again; + } + + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); + err = split_state(tree, state, prealloc, start); + if (err) + extent_io_tree_panic(tree, err); + + prealloc = NULL; + if (err) + goto out; + if (state->end <= end) { + set_state_bits(tree, state, bits, changeset); + cache_state(state, cached_state); + merge_state(tree, state); + if (last_end == (u64)-1) + goto out; + start = last_end + 1; + state = next_state(state); + if (start < end && state && state->start == start && + !need_resched()) + goto hit_next; + } + goto search_again; + } + /* + * | ---- desired range ---- | + * | state | or | state | + * + * There's a hole, we need to insert something in it and + * ignore the extent we found. + */ + if (state->start > start) { + u64 this_end; + if (end < last_start) + this_end = end; + else + this_end = last_start - 1; + + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); + + /* + * Avoid to free 'prealloc' if it can be merged with + * the later extent. + */ + prealloc->start = start; + prealloc->end = this_end; + err = insert_state(tree, prealloc, bits, changeset); + if (err) + extent_io_tree_panic(tree, err); + + cache_state(prealloc, cached_state); + prealloc = NULL; + start = this_end + 1; + goto search_again; + } + /* + * | ---- desired range ---- | + * | state | + * We need to split the extent, and set the bit + * on the first half + */ + if (state->start <= end && state->end > end) { + if (state->state & exclusive_bits) { + *failed_start = start; + err = -EEXIST; + goto out; + } + + prealloc = alloc_extent_state_atomic(prealloc); + BUG_ON(!prealloc); + err = split_state(tree, state, prealloc, end + 1); + if (err) + extent_io_tree_panic(tree, err); + + set_state_bits(tree, prealloc, bits, changeset); + cache_state(prealloc, cached_state); + merge_state(tree, prealloc); + prealloc = NULL; + goto out; + } + +search_again: + if (start > end) + goto out; + spin_unlock(&tree->lock); + if (gfpflags_allow_blocking(mask)) + cond_resched(); + goto again; + +out: + spin_unlock(&tree->lock); + if (prealloc) + free_extent_state(prealloc); + + return err; + +} + +/** + * convert_extent_bit - convert all bits in a given range from one bit to + * another + * @tree: the io tree to search + * @start: the start offset in bytes + * @end: the end offset in bytes (inclusive) + * @bits: the bits to set in this range + * @clear_bits: the bits to clear in this range + * @cached_state: state that we're going to cache + * + * This will go through and set bits for the given range. If any states exist + * already in this range they are set with the given bit and cleared of the + * clear_bits. This is only meant to be used by things that are mergeable, ie + * converting from say DELALLOC to DIRTY. This is not meant to be used with + * boundary bits like LOCK. + * + * All allocations are done with GFP_NOFS. + */ +int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, u32 clear_bits, + struct extent_state **cached_state) +{ + struct extent_state *state; + struct extent_state *prealloc = NULL; + struct rb_node *node; + struct rb_node **p; + struct rb_node *parent; + int err = 0; + u64 last_start; + u64 last_end; + bool first_iteration = true; + + btrfs_debug_check_extent_io_range(tree, start, end); + trace_btrfs_convert_extent_bit(tree, start, end - start + 1, bits, + clear_bits); + +again: + if (!prealloc) { + /* + * Best effort, don't worry if extent state allocation fails + * here for the first iteration. We might have a cached state + * that matches exactly the target range, in which case no + * extent state allocations are needed. We'll only know this + * after locking the tree. + */ + prealloc = alloc_extent_state(GFP_NOFS); + if (!prealloc && !first_iteration) + return -ENOMEM; + } + + spin_lock(&tree->lock); + if (cached_state && *cached_state) { + state = *cached_state; + if (state->start <= start && state->end > start && + extent_state_in_tree(state)) { + node = &state->rb_node; + goto hit_next; + } + } + + /* + * this search will find all the extents that end after + * our range starts. + */ + node = tree_search_for_insert(tree, start, &p, &parent); + if (!node) { + prealloc = alloc_extent_state_atomic(prealloc); + if (!prealloc) { + err = -ENOMEM; + goto out; + } + prealloc->start = start; + prealloc->end = end; + insert_state_fast(tree, prealloc, p, parent, bits, NULL); + cache_state(prealloc, cached_state); + prealloc = NULL; + goto out; + } + state = rb_entry(node, struct extent_state, rb_node); +hit_next: + last_start = state->start; + last_end = state->end; + + /* + * | ---- desired range ---- | + * | state | + * + * Just lock what we found and keep going + */ + if (state->start == start && state->end <= end) { + set_state_bits(tree, state, bits, NULL); + cache_state(state, cached_state); + state = clear_state_bit(tree, state, clear_bits, 0, NULL); + if (last_end == (u64)-1) + goto out; + start = last_end + 1; + if (start < end && state && state->start == start && + !need_resched()) + goto hit_next; + goto search_again; + } + + /* + * | ---- desired range ---- | + * | state | + * or + * | ------------- state -------------- | + * + * We need to split the extent we found, and may flip bits on + * second half. + * + * If the extent we found extends past our + * range, we just split and search again. It'll get split + * again the next time though. + * + * If the extent we found is inside our range, we set the + * desired bit on it. + */ + if (state->start < start) { + prealloc = alloc_extent_state_atomic(prealloc); + if (!prealloc) { + err = -ENOMEM; + goto out; + } + err = split_state(tree, state, prealloc, start); + if (err) + extent_io_tree_panic(tree, err); + prealloc = NULL; + if (err) + goto out; + if (state->end <= end) { + set_state_bits(tree, state, bits, NULL); + cache_state(state, cached_state); + state = clear_state_bit(tree, state, clear_bits, 0, NULL); + if (last_end == (u64)-1) + goto out; + start = last_end + 1; + if (start < end && state && state->start == start && + !need_resched()) + goto hit_next; + } + goto search_again; + } + /* + * | ---- desired range ---- | + * | state | or | state | + * + * There's a hole, we need to insert something in it and + * ignore the extent we found. + */ + if (state->start > start) { + u64 this_end; + if (end < last_start) + this_end = end; + else + this_end = last_start - 1; + + prealloc = alloc_extent_state_atomic(prealloc); + if (!prealloc) { + err = -ENOMEM; + goto out; + } + + /* + * Avoid to free 'prealloc' if it can be merged with + * the later extent. + */ + prealloc->start = start; + prealloc->end = this_end; + err = insert_state(tree, prealloc, bits, NULL); + if (err) + extent_io_tree_panic(tree, err); + cache_state(prealloc, cached_state); + prealloc = NULL; + start = this_end + 1; + goto search_again; + } + /* + * | ---- desired range ---- | + * | state | + * We need to split the extent, and set the bit + * on the first half + */ + if (state->start <= end && state->end > end) { + prealloc = alloc_extent_state_atomic(prealloc); + if (!prealloc) { + err = -ENOMEM; + goto out; + } + + err = split_state(tree, state, prealloc, end + 1); + if (err) + extent_io_tree_panic(tree, err); + + set_state_bits(tree, prealloc, bits, NULL); + cache_state(prealloc, cached_state); + clear_state_bit(tree, prealloc, clear_bits, 0, NULL); + prealloc = NULL; + goto out; + } + +search_again: + if (start > end) + goto out; + spin_unlock(&tree->lock); + cond_resched(); + first_iteration = false; + goto again; + +out: + spin_unlock(&tree->lock); + if (prealloc) + free_extent_state(prealloc); + + return err; +} + +/* + * either insert or lock state struct between start and end use mask to tell + * us if waiting is desired. + */ +int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, + struct extent_state **cached_state) +{ + int err; + u64 failed_start; + + while (1) { + err = set_extent_bit(tree, start, end, EXTENT_LOCKED, + EXTENT_LOCKED, &failed_start, + cached_state, GFP_NOFS, NULL); + if (err == -EEXIST) { + wait_extent_bit(tree, failed_start, end, EXTENT_LOCKED); + start = failed_start; + } else + break; + WARN_ON(start > end); + } + return err; +} + +/* find the first state struct with 'bits' set after 'start', and + * return it. tree->lock must be held. NULL will returned if + * nothing was found after 'start' + */ +static struct extent_state * +find_first_extent_bit_state(struct extent_io_tree *tree, u64 start, u32 bits) +{ + struct rb_node *node; + struct extent_state *state; + + /* + * this search will find all the extents that end after + * our range starts. + */ + node = tree_search(tree, start); + if (!node) + goto out; + + while (1) { + state = rb_entry(node, struct extent_state, rb_node); + if (state->end >= start && (state->state & bits)) + return state; + + node = rb_next(node); + if (!node) + break; + } +out: + return NULL; +} + +/* + * Find the first offset in the io tree with one or more @bits set. + * + * Note: If there are multiple bits set in @bits, any of them will match. + * + * Return 0 if we find something, and update @start_ret and @end_ret. + * Return 1 if we found nothing. + */ +int find_first_extent_bit(struct extent_io_tree *tree, u64 start, + u64 *start_ret, u64 *end_ret, u32 bits, + struct extent_state **cached_state) +{ + struct extent_state *state; + int ret = 1; + + spin_lock(&tree->lock); + if (cached_state && *cached_state) { + state = *cached_state; + if (state->end == start - 1 && extent_state_in_tree(state)) { + while ((state = next_state(state)) != NULL) { + if (state->state & bits) + goto got_it; + } + free_extent_state(*cached_state); + *cached_state = NULL; + goto out; + } + free_extent_state(*cached_state); + *cached_state = NULL; + } + + state = find_first_extent_bit_state(tree, start, bits); +got_it: + if (state) { + cache_state_if_flags(state, cached_state, 0); + *start_ret = state->start; + *end_ret = state->end; + ret = 0; + } +out: + spin_unlock(&tree->lock); + return ret; +} + +/** + * Find a contiguous area of bits + * + * @tree: io tree to check + * @start: offset to start the search from + * @start_ret: the first offset we found with the bits set + * @end_ret: the final contiguous range of the bits that were set + * @bits: bits to look for + * + * set_extent_bit and clear_extent_bit can temporarily split contiguous ranges + * to set bits appropriately, and then merge them again. During this time it + * will drop the tree->lock, so use this helper if you want to find the actual + * contiguous area for given bits. We will search to the first bit we find, and + * then walk down the tree until we find a non-contiguous area. The area + * returned will be the full contiguous area with the bits set. + */ +int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start, + u64 *start_ret, u64 *end_ret, u32 bits) +{ + struct extent_state *state; + int ret = 1; + + spin_lock(&tree->lock); + state = find_first_extent_bit_state(tree, start, bits); + if (state) { + *start_ret = state->start; + *end_ret = state->end; + while ((state = next_state(state)) != NULL) { + if (state->start > (*end_ret + 1)) + break; + *end_ret = state->end; + } + ret = 0; + } + spin_unlock(&tree->lock); + return ret; +} + +/** + * Find the first range that has @bits not set. This range could start before + * @start. + * + * @tree: the tree to search + * @start: offset at/after which the found extent should start + * @start_ret: records the beginning of the range + * @end_ret: records the end of the range (inclusive) + * @bits: the set of bits which must be unset + * + * Since unallocated range is also considered one which doesn't have the bits + * set it's possible that @end_ret contains -1, this happens in case the range + * spans (last_range_end, end of device]. In this case it's up to the caller to + * trim @end_ret to the appropriate size. + */ +void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, + u64 *start_ret, u64 *end_ret, u32 bits) +{ + struct extent_state *state; + struct rb_node *node, *prev = NULL, *next; + + spin_lock(&tree->lock); + + /* Find first extent with bits cleared */ + while (1) { + node = tree_search_prev_next(tree, start, &prev, &next); + if (!node && !next && !prev) { + /* + * Tree is completely empty, send full range and let + * caller deal with it + */ + *start_ret = 0; + *end_ret = -1; + goto out; + } else if (!node && !next) { + /* + * We are past the last allocated chunk, set start at + * the end of the last extent. + */ + state = rb_entry(prev, struct extent_state, rb_node); + *start_ret = state->end + 1; + *end_ret = -1; + goto out; + } else if (!node) { + node = next; + } + /* + * At this point 'node' either contains 'start' or start is + * before 'node' + */ + state = rb_entry(node, struct extent_state, rb_node); + + if (in_range(start, state->start, state->end - state->start + 1)) { + if (state->state & bits) { + /* + * |--range with bits sets--| + * | + * start + */ + start = state->end + 1; + } else { + /* + * 'start' falls within a range that doesn't + * have the bits set, so take its start as + * the beginning of the desired range + * + * |--range with bits cleared----| + * | + * start + */ + *start_ret = state->start; + break; + } + } else { + /* + * |---prev range---|---hole/unset---|---node range---| + * | + * start + * + * or + * + * |---hole/unset--||--first node--| + * 0 | + * start + */ + if (prev) { + state = rb_entry(prev, struct extent_state, + rb_node); + *start_ret = state->end + 1; + } else { + *start_ret = 0; + } + break; + } + } + + /* + * Find the longest stretch from start until an entry which has the + * bits set + */ + while (1) { + state = rb_entry(node, struct extent_state, rb_node); + if (state->end >= start && !(state->state & bits)) { + *end_ret = state->end; + } else { + *end_ret = state->start - 1; + break; + } + + node = rb_next(node); + if (!node) + break; + } +out: + spin_unlock(&tree->lock); +} + +/* + * find a contiguous range of bytes in the file marked as delalloc, not + * more than 'max_bytes'. start and end are used to return the range, + * + * true is returned if we find something, false if nothing was in the tree + */ +bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, + u64 *end, u64 max_bytes, + struct extent_state **cached_state) +{ + struct rb_node *node; + struct extent_state *state; + u64 cur_start = *start; + bool found = false; + u64 total_bytes = 0; + + spin_lock(&tree->lock); + + /* + * this search will find all the extents that end after + * our range starts. + */ + node = tree_search(tree, cur_start); + if (!node) { + *end = (u64)-1; + goto out; + } + + while (1) { + state = rb_entry(node, struct extent_state, rb_node); + if (found && (state->start != cur_start || + (state->state & EXTENT_BOUNDARY))) { + goto out; + } + if (!(state->state & EXTENT_DELALLOC)) { + if (!found) + *end = state->end; + goto out; + } + if (!found) { + *start = state->start; + *cached_state = state; + refcount_inc(&state->refs); + } + found = true; + *end = state->end; + cur_start = state->end + 1; + node = rb_next(node); + total_bytes += state->end - state->start + 1; + if (total_bytes >= max_bytes) + break; + if (!node) + break; + } +out: + spin_unlock(&tree->lock); + return found; +} + +/* + * count the number of bytes in the tree that have a given bit(s) + * set. This can be fairly slow, except for EXTENT_DIRTY which is + * cached. The total number found is returned. + */ +u64 count_range_bits(struct extent_io_tree *tree, + u64 *start, u64 search_end, u64 max_bytes, + u32 bits, int contig) +{ + struct rb_node *node; + struct extent_state *state; + u64 cur_start = *start; + u64 total_bytes = 0; + u64 last = 0; + int found = 0; + + if (WARN_ON(search_end <= cur_start)) + return 0; + + spin_lock(&tree->lock); + if (cur_start == 0 && bits == EXTENT_DIRTY) { + total_bytes = tree->dirty_bytes; + goto out; + } + /* + * this search will find all the extents that end after + * our range starts. + */ + node = tree_search(tree, cur_start); + if (!node) + goto out; + + while (1) { + state = rb_entry(node, struct extent_state, rb_node); + if (state->start > search_end) + break; + if (contig && found && state->start > last + 1) + break; + if (state->end >= cur_start && (state->state & bits) == bits) { + total_bytes += min(search_end, state->end) + 1 - + max(cur_start, state->start); + if (total_bytes >= max_bytes) + break; + if (!found) { + *start = max(cur_start, state->start); + found = 1; + } + last = state->end; + } else if (contig && found) { + break; + } + node = rb_next(node); + if (!node) + break; + } +out: + spin_unlock(&tree->lock); + return total_bytes; +} + +/* + * searches a range in the state tree for a given mask. + * If 'filled' == 1, this returns 1 only if every extent in the tree + * has the bits set. Otherwise, 1 is returned if any bit in the + * range is found set. + */ +int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, int filled, struct extent_state *cached) +{ + struct extent_state *state = NULL; + struct rb_node *node; + int bitset = 0; + + spin_lock(&tree->lock); + if (cached && extent_state_in_tree(cached) && cached->start <= start && + cached->end > start) + node = &cached->rb_node; + else + node = tree_search(tree, start); + while (node && start <= end) { + state = rb_entry(node, struct extent_state, rb_node); + + if (filled && state->start > start) { + bitset = 0; + break; + } + + if (state->start > end) + break; + + if (state->state & bits) { + bitset = 1; + if (!filled) + break; + } else if (filled) { + bitset = 0; + break; + } + + if (state->end == (u64)-1) + break; + + start = state->end + 1; + if (start > end) + break; + node = rb_next(node); + if (!node) { + if (filled) + bitset = 0; + break; + } + } + spin_unlock(&tree->lock); + return bitset; +} + void __cold extent_state_free_cachep(void) { btrfs_extent_state_leak_debug_check(); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 5bfa14f2b5e3..c38d31b8b18f 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -80,37 +80,11 @@ void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) } spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); } - -#define btrfs_debug_check_extent_io_range(tree, start, end) \ - __btrfs_debug_check_extent_io_range(__func__, (tree), (start), (end)) -static inline void __btrfs_debug_check_extent_io_range(const char *caller, - struct extent_io_tree *tree, u64 start, u64 end) -{ - struct inode *inode = tree->private_data; - u64 isize; - - if (!inode || !is_data_inode(inode)) - return; - - isize = i_size_read(inode); - if (end >= PAGE_SIZE && (end % 2) == 0 && end != isize - 1) { - btrfs_debug_rl(BTRFS_I(inode)->root->fs_info, - "%s: ino %llu isize %llu odd range [%llu,%llu]", - caller, btrfs_ino(BTRFS_I(inode)), isize, start, end); - } -} #else #define btrfs_leak_debug_add_eb(eb) do {} while (0) #define btrfs_leak_debug_del_eb(eb) do {} while (0) -#define btrfs_debug_check_extent_io_range(c, s, e) do {} while (0) #endif -struct tree_entry { - u64 start; - u64 end; - struct rb_node rb_node; -}; - /* * Structure to record info about the bio being assembled, and other info like * how many bytes are there before stripe/ordered extent boundary. @@ -126,1184 +100,85 @@ struct btrfs_bio_ctrl { struct extent_page_data { struct btrfs_bio_ctrl bio_ctrl; /* tells writepage not to lock the state bits for this range - * it still does the unlocking - */ - unsigned int extent_locked:1; - - /* tells the submit_bio code to use REQ_SYNC */ - unsigned int sync_io:1; -}; - -static int add_extent_changeset(struct extent_state *state, u32 bits, - struct extent_changeset *changeset, - int set) -{ - int ret; - - if (!changeset) - return 0; - if (set && (state->state & bits) == bits) - return 0; - if (!set && (state->state & bits) == 0) - return 0; - changeset->bytes_changed += state->end - state->start + 1; - ret = ulist_add(&changeset->range_changed, state->start, state->end, - GFP_ATOMIC); - return ret; -} - -static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) -{ - struct bio *bio; - struct bio_vec *bv; - struct inode *inode; - int mirror_num; - - if (!bio_ctrl->bio) - return; - - bio = bio_ctrl->bio; - bv = bio_first_bvec_all(bio); - inode = bv->bv_page->mapping->host; - mirror_num = bio_ctrl->mirror_num; - - /* Caller should ensure the bio has at least some range added */ - ASSERT(bio->bi_iter.bi_size); - - btrfs_bio(bio)->file_offset = page_offset(bv->bv_page) + bv->bv_offset; - - if (!is_data_inode(inode)) - btrfs_submit_metadata_bio(inode, bio, mirror_num); - else if (btrfs_op(bio) == BTRFS_MAP_WRITE) - btrfs_submit_data_write_bio(inode, bio, mirror_num); - else - btrfs_submit_data_read_bio(inode, bio, mirror_num, - bio_ctrl->compress_type); - - /* The bio is owned by the end_io handler now */ - bio_ctrl->bio = NULL; -} - -/* - * Submit or fail the current bio in an extent_page_data structure. - */ -static void submit_write_bio(struct extent_page_data *epd, int ret) -{ - struct bio *bio = epd->bio_ctrl.bio; - - if (!bio) - return; - - if (ret) { - ASSERT(ret < 0); - btrfs_bio_end_io(btrfs_bio(bio), errno_to_blk_status(ret)); - /* The bio is owned by the end_io handler now */ - epd->bio_ctrl.bio = NULL; - } else { - submit_one_bio(&epd->bio_ctrl); - } -} - -int __init extent_buffer_init_cachep(void) -{ - extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer", - sizeof(struct extent_buffer), 0, - SLAB_MEM_SPREAD, NULL); - if (!extent_buffer_cache) - return -ENOMEM; - - return 0; -} - -void __cold extent_buffer_free_cachep(void) -{ - /* - * Make sure all delayed rcu free are flushed before we - * destroy caches. - */ - rcu_barrier(); - kmem_cache_destroy(extent_buffer_cache); -} - -/** - * Search @tree for an entry that contains @offset. Such entry would have - * entry->start <= offset && entry->end >= offset. - * - * @tree: the tree to search - * @offset: offset that should fall within an entry in @tree - * @node_ret: pointer where new node should be anchored (used when inserting an - * entry in the tree) - * @parent_ret: points to entry which would have been the parent of the entry, - * containing @offset - * - * Return a pointer to the entry that contains @offset byte address and don't change - * @node_ret and @parent_ret. - * - * If no such entry exists, return pointer to entry that ends before @offset - * and fill parameters @node_ret and @parent_ret, ie. does not return NULL. - */ -static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree, - u64 offset, - struct rb_node ***node_ret, - struct rb_node **parent_ret) -{ - struct rb_root *root = &tree->state; - struct rb_node **node = &root->rb_node; - struct rb_node *prev = NULL; - struct tree_entry *entry; - - while (*node) { - prev = *node; - entry = rb_entry(prev, struct tree_entry, rb_node); - - if (offset < entry->start) - node = &(*node)->rb_left; - else if (offset > entry->end) - node = &(*node)->rb_right; - else - return *node; - } - - if (node_ret) - *node_ret = node; - if (parent_ret) - *parent_ret = prev; - - /* Search neighbors until we find the first one past the end */ - while (prev && offset > entry->end) { - prev = rb_next(prev); - entry = rb_entry(prev, struct tree_entry, rb_node); - } - - return prev; -} - -/* - * Inexact rb-tree search, return the next entry if @offset is not found - */ -static inline struct rb_node *tree_search(struct extent_io_tree *tree, u64 offset) -{ - return tree_search_for_insert(tree, offset, NULL, NULL); -} - -/** - * Search offset in the tree or fill neighbor rbtree node pointers. - * - * @tree: the tree to search - * @offset: offset that should fall within an entry in @tree - * @next_ret: pointer to the first entry whose range ends after @offset - * @prev_ret: pointer to the first entry whose range begins before @offset - * - * Return a pointer to the entry that contains @offset byte address. If no - * such entry exists, then return NULL and fill @prev_ret and @next_ret. - * Otherwise return the found entry and other pointers are left untouched. - */ -static struct rb_node *tree_search_prev_next(struct extent_io_tree *tree, - u64 offset, - struct rb_node **prev_ret, - struct rb_node **next_ret) -{ - struct rb_root *root = &tree->state; - struct rb_node **node = &root->rb_node; - struct rb_node *prev = NULL; - struct rb_node *orig_prev = NULL; - struct tree_entry *entry; - - ASSERT(prev_ret); - ASSERT(next_ret); - - while (*node) { - prev = *node; - entry = rb_entry(prev, struct tree_entry, rb_node); - - if (offset < entry->start) - node = &(*node)->rb_left; - else if (offset > entry->end) - node = &(*node)->rb_right; - else - return *node; - } - - orig_prev = prev; - while (prev && offset > entry->end) { - prev = rb_next(prev); - entry = rb_entry(prev, struct tree_entry, rb_node); - } - *next_ret = prev; - prev = orig_prev; - - entry = rb_entry(prev, struct tree_entry, rb_node); - while (prev && offset < entry->start) { - prev = rb_prev(prev); - entry = rb_entry(prev, struct tree_entry, rb_node); - } - *prev_ret = prev; - - return NULL; -} - -/* - * utility function to look for merge candidates inside a given range. - * Any extents with matching state are merged together into a single - * extent in the tree. Extents with EXTENT_IO in their state field - * are not merged because the end_io handlers need to be able to do - * operations on them without sleeping (or doing allocations/splits). - * - * This should be called with the tree lock held. - */ -static void merge_state(struct extent_io_tree *tree, - struct extent_state *state) -{ - struct extent_state *other; - struct rb_node *other_node; - - if (state->state & (EXTENT_LOCKED | EXTENT_BOUNDARY)) - return; - - other_node = rb_prev(&state->rb_node); - if (other_node) { - other = rb_entry(other_node, struct extent_state, rb_node); - if (other->end == state->start - 1 && - other->state == state->state) { - if (tree->private_data && - is_data_inode(tree->private_data)) - btrfs_merge_delalloc_extent(tree->private_data, - state, other); - state->start = other->start; - rb_erase(&other->rb_node, &tree->state); - RB_CLEAR_NODE(&other->rb_node); - free_extent_state(other); - } - } - other_node = rb_next(&state->rb_node); - if (other_node) { - other = rb_entry(other_node, struct extent_state, rb_node); - if (other->start == state->end + 1 && - other->state == state->state) { - if (tree->private_data && - is_data_inode(tree->private_data)) - btrfs_merge_delalloc_extent(tree->private_data, - state, other); - state->end = other->end; - rb_erase(&other->rb_node, &tree->state); - RB_CLEAR_NODE(&other->rb_node); - free_extent_state(other); - } - } -} - -static void set_state_bits(struct extent_io_tree *tree, - struct extent_state *state, u32 bits, - struct extent_changeset *changeset); - -/* - * insert an extent_state struct into the tree. 'bits' are set on the - * struct before it is inserted. - * - * This may return -EEXIST if the extent is already there, in which case the - * state struct is freed. - * - * The tree lock is not taken internally. This is a utility function and - * probably isn't what you want to call (see set/clear_extent_bit). - */ -static int insert_state(struct extent_io_tree *tree, - struct extent_state *state, - u32 bits, struct extent_changeset *changeset) -{ - struct rb_node **node; - struct rb_node *parent; - const u64 end = state->end; - - set_state_bits(tree, state, bits, changeset); - - node = &tree->state.rb_node; - while (*node) { - struct tree_entry *entry; - - parent = *node; - entry = rb_entry(parent, struct tree_entry, rb_node); - - if (end < entry->start) { - node = &(*node)->rb_left; - } else if (end > entry->end) { - node = &(*node)->rb_right; - } else { - btrfs_err(tree->fs_info, - "found node %llu %llu on insert of %llu %llu", - entry->start, entry->end, state->start, end); - return -EEXIST; - } - } - - rb_link_node(&state->rb_node, parent, node); - rb_insert_color(&state->rb_node, &tree->state); - - merge_state(tree, state); - return 0; -} - -/* - * Insert state to @tree to the location given by @node and @parent. - */ -static void insert_state_fast(struct extent_io_tree *tree, - struct extent_state *state, struct rb_node **node, - struct rb_node *parent, unsigned bits, - struct extent_changeset *changeset) -{ - set_state_bits(tree, state, bits, changeset); - rb_link_node(&state->rb_node, parent, node); - rb_insert_color(&state->rb_node, &tree->state); - merge_state(tree, state); -} - -/* - * split a given extent state struct in two, inserting the preallocated - * struct 'prealloc' as the newly created second half. 'split' indicates an - * offset inside 'orig' where it should be split. - * - * Before calling, - * the tree has 'orig' at [orig->start, orig->end]. After calling, there - * are two extent state structs in the tree: - * prealloc: [orig->start, split - 1] - * orig: [ split, orig->end ] - * - * The tree locks are not taken by this function. They need to be held - * by the caller. - */ -static int split_state(struct extent_io_tree *tree, struct extent_state *orig, - struct extent_state *prealloc, u64 split) -{ - struct rb_node *parent = NULL; - struct rb_node **node; - - if (tree->private_data && is_data_inode(tree->private_data)) - btrfs_split_delalloc_extent(tree->private_data, orig, split); - - prealloc->start = orig->start; - prealloc->end = split - 1; - prealloc->state = orig->state; - orig->start = split; - - parent = &orig->rb_node; - node = &parent; - while (*node) { - struct tree_entry *entry; - - parent = *node; - entry = rb_entry(parent, struct tree_entry, rb_node); - - if (prealloc->end < entry->start) { - node = &(*node)->rb_left; - } else if (prealloc->end > entry->end) { - node = &(*node)->rb_right; - } else { - free_extent_state(prealloc); - return -EEXIST; - } - } - - rb_link_node(&prealloc->rb_node, parent, node); - rb_insert_color(&prealloc->rb_node, &tree->state); - - return 0; -} - -static struct extent_state *next_state(struct extent_state *state) -{ - struct rb_node *next = rb_next(&state->rb_node); - if (next) - return rb_entry(next, struct extent_state, rb_node); - else - return NULL; -} - -/* - * utility function to clear some bits in an extent state struct. - * it will optionally wake up anyone waiting on this state (wake == 1). - * - * If no bits are set on the state struct after clearing things, the - * struct is freed and removed from the tree - */ -static struct extent_state *clear_state_bit(struct extent_io_tree *tree, - struct extent_state *state, - u32 bits, int wake, - struct extent_changeset *changeset) -{ - struct extent_state *next; - u32 bits_to_clear = bits & ~EXTENT_CTLBITS; - int ret; - - if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { - u64 range = state->end - state->start + 1; - WARN_ON(range > tree->dirty_bytes); - tree->dirty_bytes -= range; - } - - if (tree->private_data && is_data_inode(tree->private_data)) - btrfs_clear_delalloc_extent(tree->private_data, state, bits); - - ret = add_extent_changeset(state, bits_to_clear, changeset, 0); - BUG_ON(ret < 0); - state->state &= ~bits_to_clear; - if (wake) - wake_up(&state->wq); - if (state->state == 0) { - next = next_state(state); - if (extent_state_in_tree(state)) { - rb_erase(&state->rb_node, &tree->state); - RB_CLEAR_NODE(&state->rb_node); - free_extent_state(state); - } else { - WARN_ON(1); - } - } else { - merge_state(tree, state); - next = next_state(state); - } - return next; -} - -static void extent_io_tree_panic(struct extent_io_tree *tree, int err) -{ - btrfs_panic(tree->fs_info, err, - "locking error: extent tree was modified by another thread while locked"); -} - -/* - * clear some bits on a range in the tree. This may require splitting - * or inserting elements in the tree, so the gfp mask is used to - * indicate which allocations or sleeping are allowed. - * - * pass 'wake' == 1 to kick any sleepers, and 'delete' == 1 to remove - * the given range from the tree regardless of state (ie for truncate). - * - * the range [start, end] is inclusive. - * - * This takes the tree lock, and returns 0 on success and < 0 on error. - */ -int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int wake, int delete, - struct extent_state **cached_state, - gfp_t mask, struct extent_changeset *changeset) -{ - struct extent_state *state; - struct extent_state *cached; - struct extent_state *prealloc = NULL; - struct rb_node *node; - u64 last_end; - int err; - int clear = 0; - - btrfs_debug_check_extent_io_range(tree, start, end); - trace_btrfs_clear_extent_bit(tree, start, end - start + 1, bits); - - if (bits & EXTENT_DELALLOC) - bits |= EXTENT_NORESERVE; - - if (delete) - bits |= ~EXTENT_CTLBITS; - - if (bits & (EXTENT_LOCKED | EXTENT_BOUNDARY)) - clear = 1; -again: - if (!prealloc && gfpflags_allow_blocking(mask)) { - /* - * Don't care for allocation failure here because we might end - * up not needing the pre-allocated extent state at all, which - * is the case if we only have in the tree extent states that - * cover our input range and don't cover too any other range. - * If we end up needing a new extent state we allocate it later. - */ - prealloc = alloc_extent_state(mask); - } - - spin_lock(&tree->lock); - if (cached_state) { - cached = *cached_state; - - if (clear) { - *cached_state = NULL; - cached_state = NULL; - } - - if (cached && extent_state_in_tree(cached) && - cached->start <= start && cached->end > start) { - if (clear) - refcount_dec(&cached->refs); - state = cached; - goto hit_next; - } - if (clear) - free_extent_state(cached); - } - /* - * this search will find the extents that end after - * our range starts - */ - node = tree_search(tree, start); - if (!node) - goto out; - state = rb_entry(node, struct extent_state, rb_node); -hit_next: - if (state->start > end) - goto out; - WARN_ON(state->end < start); - last_end = state->end; - - /* the state doesn't have the wanted bits, go ahead */ - if (!(state->state & bits)) { - state = next_state(state); - goto next; - } - - /* - * | ---- desired range ---- | - * | state | or - * | ------------- state -------------- | - * - * We need to split the extent we found, and may flip - * bits on second half. - * - * If the extent we found extends past our range, we - * just split and search again. It'll get split again - * the next time though. - * - * If the extent we found is inside our range, we clear - * the desired bit on it. - */ - - if (state->start < start) { - prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); - err = split_state(tree, state, prealloc, start); - if (err) - extent_io_tree_panic(tree, err); - - prealloc = NULL; - if (err) - goto out; - if (state->end <= end) { - state = clear_state_bit(tree, state, bits, wake, changeset); - goto next; - } - goto search_again; - } - /* - * | ---- desired range ---- | - * | state | - * We need to split the extent, and clear the bit - * on the first half - */ - if (state->start <= end && state->end > end) { - prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); - err = split_state(tree, state, prealloc, end + 1); - if (err) - extent_io_tree_panic(tree, err); - - if (wake) - wake_up(&state->wq); - - clear_state_bit(tree, prealloc, bits, wake, changeset); - - prealloc = NULL; - goto out; - } - - state = clear_state_bit(tree, state, bits, wake, changeset); -next: - if (last_end == (u64)-1) - goto out; - start = last_end + 1; - if (start <= end && state && !need_resched()) - goto hit_next; - -search_again: - if (start > end) - goto out; - spin_unlock(&tree->lock); - if (gfpflags_allow_blocking(mask)) - cond_resched(); - goto again; - -out: - spin_unlock(&tree->lock); - if (prealloc) - free_extent_state(prealloc); - - return 0; - -} - -static void wait_on_state(struct extent_io_tree *tree, - struct extent_state *state) - __releases(tree->lock) - __acquires(tree->lock) -{ - DEFINE_WAIT(wait); - prepare_to_wait(&state->wq, &wait, TASK_UNINTERRUPTIBLE); - spin_unlock(&tree->lock); - schedule(); - spin_lock(&tree->lock); - finish_wait(&state->wq, &wait); -} - -/* - * waits for one or more bits to clear on a range in the state tree. - * The range [start, end] is inclusive. - * The tree lock is taken by this function - */ -void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) -{ - struct extent_state *state; - struct rb_node *node; - - btrfs_debug_check_extent_io_range(tree, start, end); - - spin_lock(&tree->lock); -again: - while (1) { - /* - * this search will find all the extents that end after - * our range starts - */ - node = tree_search(tree, start); -process_node: - if (!node) - break; - - state = rb_entry(node, struct extent_state, rb_node); - - if (state->start > end) - goto out; - - if (state->state & bits) { - start = state->start; - refcount_inc(&state->refs); - wait_on_state(tree, state); - free_extent_state(state); - goto again; - } - start = state->end + 1; - - if (start > end) - break; - - if (!cond_resched_lock(&tree->lock)) { - node = rb_next(node); - goto process_node; - } - } -out: - spin_unlock(&tree->lock); -} - -static void set_state_bits(struct extent_io_tree *tree, - struct extent_state *state, - u32 bits, struct extent_changeset *changeset) -{ - u32 bits_to_set = bits & ~EXTENT_CTLBITS; - int ret; - - if (tree->private_data && is_data_inode(tree->private_data)) - btrfs_set_delalloc_extent(tree->private_data, state, bits); - - if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { - u64 range = state->end - state->start + 1; - tree->dirty_bytes += range; - } - ret = add_extent_changeset(state, bits_to_set, changeset, 1); - BUG_ON(ret < 0); - state->state |= bits_to_set; -} - -static void cache_state_if_flags(struct extent_state *state, - struct extent_state **cached_ptr, - unsigned flags) -{ - if (cached_ptr && !(*cached_ptr)) { - if (!flags || (state->state & flags)) { - *cached_ptr = state; - refcount_inc(&state->refs); - } - } -} - -static void cache_state(struct extent_state *state, - struct extent_state **cached_ptr) -{ - return cache_state_if_flags(state, cached_ptr, - EXTENT_LOCKED | EXTENT_BOUNDARY); -} - -/* - * set some bits on a range in the tree. This may require allocations or - * sleeping, so the gfp mask is used to indicate what is allowed. - * - * If any of the exclusive bits are set, this will fail with -EEXIST if some - * part of the range already has the desired bits set. The start of the - * existing range is returned in failed_start in this case. - * - * [start, end] is inclusive This takes the tree lock. - */ -int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, - u32 exclusive_bits, u64 *failed_start, - struct extent_state **cached_state, gfp_t mask, - struct extent_changeset *changeset) -{ - struct extent_state *state; - struct extent_state *prealloc = NULL; - struct rb_node *node; - struct rb_node **p; - struct rb_node *parent; - int err = 0; - u64 last_start; - u64 last_end; - - btrfs_debug_check_extent_io_range(tree, start, end); - trace_btrfs_set_extent_bit(tree, start, end - start + 1, bits); - - if (exclusive_bits) - ASSERT(failed_start); - else - ASSERT(failed_start == NULL); -again: - if (!prealloc && gfpflags_allow_blocking(mask)) { - /* - * Don't care for allocation failure here because we might end - * up not needing the pre-allocated extent state at all, which - * is the case if we only have in the tree extent states that - * cover our input range and don't cover too any other range. - * If we end up needing a new extent state we allocate it later. - */ - prealloc = alloc_extent_state(mask); - } - - spin_lock(&tree->lock); - if (cached_state && *cached_state) { - state = *cached_state; - if (state->start <= start && state->end > start && - extent_state_in_tree(state)) { - node = &state->rb_node; - goto hit_next; - } - } - /* - * this search will find all the extents that end after - * our range starts. - */ - node = tree_search_for_insert(tree, start, &p, &parent); - if (!node) { - prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); - prealloc->start = start; - prealloc->end = end; - insert_state_fast(tree, prealloc, p, parent, bits, changeset); - cache_state(prealloc, cached_state); - prealloc = NULL; - goto out; - } - state = rb_entry(node, struct extent_state, rb_node); -hit_next: - last_start = state->start; - last_end = state->end; - - /* - * | ---- desired range ---- | - * | state | - * - * Just lock what we found and keep going - */ - if (state->start == start && state->end <= end) { - if (state->state & exclusive_bits) { - *failed_start = state->start; - err = -EEXIST; - goto out; - } - - set_state_bits(tree, state, bits, changeset); - cache_state(state, cached_state); - merge_state(tree, state); - if (last_end == (u64)-1) - goto out; - start = last_end + 1; - state = next_state(state); - if (start < end && state && state->start == start && - !need_resched()) - goto hit_next; - goto search_again; - } - - /* - * | ---- desired range ---- | - * | state | - * or - * | ------------- state -------------- | - * - * We need to split the extent we found, and may flip bits on - * second half. - * - * If the extent we found extends past our - * range, we just split and search again. It'll get split - * again the next time though. - * - * If the extent we found is inside our range, we set the - * desired bit on it. - */ - if (state->start < start) { - if (state->state & exclusive_bits) { - *failed_start = start; - err = -EEXIST; - goto out; - } - - /* - * If this extent already has all the bits we want set, then - * skip it, not necessary to split it or do anything with it. - */ - if ((state->state & bits) == bits) { - start = state->end + 1; - cache_state(state, cached_state); - goto search_again; - } - - prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); - err = split_state(tree, state, prealloc, start); - if (err) - extent_io_tree_panic(tree, err); - - prealloc = NULL; - if (err) - goto out; - if (state->end <= end) { - set_state_bits(tree, state, bits, changeset); - cache_state(state, cached_state); - merge_state(tree, state); - if (last_end == (u64)-1) - goto out; - start = last_end + 1; - state = next_state(state); - if (start < end && state && state->start == start && - !need_resched()) - goto hit_next; - } - goto search_again; - } - /* - * | ---- desired range ---- | - * | state | or | state | - * - * There's a hole, we need to insert something in it and - * ignore the extent we found. - */ - if (state->start > start) { - u64 this_end; - if (end < last_start) - this_end = end; - else - this_end = last_start - 1; - - prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); - - /* - * Avoid to free 'prealloc' if it can be merged with - * the later extent. - */ - prealloc->start = start; - prealloc->end = this_end; - err = insert_state(tree, prealloc, bits, changeset); - if (err) - extent_io_tree_panic(tree, err); - - cache_state(prealloc, cached_state); - prealloc = NULL; - start = this_end + 1; - goto search_again; - } - /* - * | ---- desired range ---- | - * | state | - * We need to split the extent, and set the bit - * on the first half - */ - if (state->start <= end && state->end > end) { - if (state->state & exclusive_bits) { - *failed_start = start; - err = -EEXIST; - goto out; - } - - prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); - err = split_state(tree, state, prealloc, end + 1); - if (err) - extent_io_tree_panic(tree, err); - - set_state_bits(tree, prealloc, bits, changeset); - cache_state(prealloc, cached_state); - merge_state(tree, prealloc); - prealloc = NULL; - goto out; - } - -search_again: - if (start > end) - goto out; - spin_unlock(&tree->lock); - if (gfpflags_allow_blocking(mask)) - cond_resched(); - goto again; - -out: - spin_unlock(&tree->lock); - if (prealloc) - free_extent_state(prealloc); - - return err; - -} - -/** - * convert_extent_bit - convert all bits in a given range from one bit to - * another - * @tree: the io tree to search - * @start: the start offset in bytes - * @end: the end offset in bytes (inclusive) - * @bits: the bits to set in this range - * @clear_bits: the bits to clear in this range - * @cached_state: state that we're going to cache - * - * This will go through and set bits for the given range. If any states exist - * already in this range they are set with the given bit and cleared of the - * clear_bits. This is only meant to be used by things that are mergeable, ie - * converting from say DELALLOC to DIRTY. This is not meant to be used with - * boundary bits like LOCK. - * - * All allocations are done with GFP_NOFS. - */ -int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, u32 clear_bits, - struct extent_state **cached_state) -{ - struct extent_state *state; - struct extent_state *prealloc = NULL; - struct rb_node *node; - struct rb_node **p; - struct rb_node *parent; - int err = 0; - u64 last_start; - u64 last_end; - bool first_iteration = true; - - btrfs_debug_check_extent_io_range(tree, start, end); - trace_btrfs_convert_extent_bit(tree, start, end - start + 1, bits, - clear_bits); - -again: - if (!prealloc) { - /* - * Best effort, don't worry if extent state allocation fails - * here for the first iteration. We might have a cached state - * that matches exactly the target range, in which case no - * extent state allocations are needed. We'll only know this - * after locking the tree. - */ - prealloc = alloc_extent_state(GFP_NOFS); - if (!prealloc && !first_iteration) - return -ENOMEM; - } - - spin_lock(&tree->lock); - if (cached_state && *cached_state) { - state = *cached_state; - if (state->start <= start && state->end > start && - extent_state_in_tree(state)) { - node = &state->rb_node; - goto hit_next; - } - } - - /* - * this search will find all the extents that end after - * our range starts. - */ - node = tree_search_for_insert(tree, start, &p, &parent); - if (!node) { - prealloc = alloc_extent_state_atomic(prealloc); - if (!prealloc) { - err = -ENOMEM; - goto out; - } - prealloc->start = start; - prealloc->end = end; - insert_state_fast(tree, prealloc, p, parent, bits, NULL); - cache_state(prealloc, cached_state); - prealloc = NULL; - goto out; - } - state = rb_entry(node, struct extent_state, rb_node); -hit_next: - last_start = state->start; - last_end = state->end; - - /* - * | ---- desired range ---- | - * | state | - * - * Just lock what we found and keep going - */ - if (state->start == start && state->end <= end) { - set_state_bits(tree, state, bits, NULL); - cache_state(state, cached_state); - state = clear_state_bit(tree, state, clear_bits, 0, NULL); - if (last_end == (u64)-1) - goto out; - start = last_end + 1; - if (start < end && state && state->start == start && - !need_resched()) - goto hit_next; - goto search_again; - } - - /* - * | ---- desired range ---- | - * | state | - * or - * | ------------- state -------------- | - * - * We need to split the extent we found, and may flip bits on - * second half. - * - * If the extent we found extends past our - * range, we just split and search again. It'll get split - * again the next time though. - * - * If the extent we found is inside our range, we set the - * desired bit on it. - */ - if (state->start < start) { - prealloc = alloc_extent_state_atomic(prealloc); - if (!prealloc) { - err = -ENOMEM; - goto out; - } - err = split_state(tree, state, prealloc, start); - if (err) - extent_io_tree_panic(tree, err); - prealloc = NULL; - if (err) - goto out; - if (state->end <= end) { - set_state_bits(tree, state, bits, NULL); - cache_state(state, cached_state); - state = clear_state_bit(tree, state, clear_bits, 0, NULL); - if (last_end == (u64)-1) - goto out; - start = last_end + 1; - if (start < end && state && state->start == start && - !need_resched()) - goto hit_next; - } - goto search_again; - } - /* - * | ---- desired range ---- | - * | state | or | state | - * - * There's a hole, we need to insert something in it and - * ignore the extent we found. + * it still does the unlocking */ - if (state->start > start) { - u64 this_end; - if (end < last_start) - this_end = end; - else - this_end = last_start - 1; + unsigned int extent_locked:1; - prealloc = alloc_extent_state_atomic(prealloc); - if (!prealloc) { - err = -ENOMEM; - goto out; - } + /* tells the submit_bio code to use REQ_SYNC */ + unsigned int sync_io:1; +}; - /* - * Avoid to free 'prealloc' if it can be merged with - * the later extent. - */ - prealloc->start = start; - prealloc->end = this_end; - err = insert_state(tree, prealloc, bits, NULL); - if (err) - extent_io_tree_panic(tree, err); - cache_state(prealloc, cached_state); - prealloc = NULL; - start = this_end + 1; - goto search_again; - } - /* - * | ---- desired range ---- | - * | state | - * We need to split the extent, and set the bit - * on the first half - */ - if (state->start <= end && state->end > end) { - prealloc = alloc_extent_state_atomic(prealloc); - if (!prealloc) { - err = -ENOMEM; - goto out; - } +static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) +{ + struct bio *bio; + struct bio_vec *bv; + struct inode *inode; + int mirror_num; - err = split_state(tree, state, prealloc, end + 1); - if (err) - extent_io_tree_panic(tree, err); + if (!bio_ctrl->bio) + return; - set_state_bits(tree, prealloc, bits, NULL); - cache_state(prealloc, cached_state); - clear_state_bit(tree, prealloc, clear_bits, 0, NULL); - prealloc = NULL; - goto out; - } + bio = bio_ctrl->bio; + bv = bio_first_bvec_all(bio); + inode = bv->bv_page->mapping->host; + mirror_num = bio_ctrl->mirror_num; -search_again: - if (start > end) - goto out; - spin_unlock(&tree->lock); - cond_resched(); - first_iteration = false; - goto again; + /* Caller should ensure the bio has at least some range added */ + ASSERT(bio->bi_iter.bi_size); -out: - spin_unlock(&tree->lock); - if (prealloc) - free_extent_state(prealloc); + btrfs_bio(bio)->file_offset = page_offset(bv->bv_page) + bv->bv_offset; - return err; + if (!is_data_inode(inode)) + btrfs_submit_metadata_bio(inode, bio, mirror_num); + else if (btrfs_op(bio) == BTRFS_MAP_WRITE) + btrfs_submit_data_write_bio(inode, bio, mirror_num); + else + btrfs_submit_data_read_bio(inode, bio, mirror_num, + bio_ctrl->compress_type); + + /* The bio is owned by the end_io handler now */ + bio_ctrl->bio = NULL; } /* - * either insert or lock state struct between start and end use mask to tell - * us if waiting is desired. + * Submit or fail the current bio in an extent_page_data structure. */ -int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, - struct extent_state **cached_state) +static void submit_write_bio(struct extent_page_data *epd, int ret) { - int err; - u64 failed_start; + struct bio *bio = epd->bio_ctrl.bio; - while (1) { - err = set_extent_bit(tree, start, end, EXTENT_LOCKED, - EXTENT_LOCKED, &failed_start, - cached_state, GFP_NOFS, NULL); - if (err == -EEXIST) { - wait_extent_bit(tree, failed_start, end, EXTENT_LOCKED); - start = failed_start; - } else - break; - WARN_ON(start > end); + if (!bio) + return; + + if (ret) { + ASSERT(ret < 0); + btrfs_bio_end_io(btrfs_bio(bio), errno_to_blk_status(ret)); + /* The bio is owned by the end_io handler now */ + epd->bio_ctrl.bio = NULL; + } else { + submit_one_bio(&epd->bio_ctrl); } - return err; +} + +int __init extent_buffer_init_cachep(void) +{ + extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer", + sizeof(struct extent_buffer), 0, + SLAB_MEM_SPREAD, NULL); + if (!extent_buffer_cache) + return -ENOMEM; + + return 0; +} + +void __cold extent_buffer_free_cachep(void) +{ + /* + * Make sure all delayed rcu free are flushed before we + * destroy caches. + */ + rcu_barrier(); + kmem_cache_destroy(extent_buffer_cache); } void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) @@ -1337,295 +212,6 @@ void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end) } } -/* find the first state struct with 'bits' set after 'start', and - * return it. tree->lock must be held. NULL will returned if - * nothing was found after 'start' - */ -static struct extent_state * -find_first_extent_bit_state(struct extent_io_tree *tree, u64 start, u32 bits) -{ - struct rb_node *node; - struct extent_state *state; - - /* - * this search will find all the extents that end after - * our range starts. - */ - node = tree_search(tree, start); - if (!node) - goto out; - - while (1) { - state = rb_entry(node, struct extent_state, rb_node); - if (state->end >= start && (state->state & bits)) - return state; - - node = rb_next(node); - if (!node) - break; - } -out: - return NULL; -} - -/* - * Find the first offset in the io tree with one or more @bits set. - * - * Note: If there are multiple bits set in @bits, any of them will match. - * - * Return 0 if we find something, and update @start_ret and @end_ret. - * Return 1 if we found nothing. - */ -int find_first_extent_bit(struct extent_io_tree *tree, u64 start, - u64 *start_ret, u64 *end_ret, u32 bits, - struct extent_state **cached_state) -{ - struct extent_state *state; - int ret = 1; - - spin_lock(&tree->lock); - if (cached_state && *cached_state) { - state = *cached_state; - if (state->end == start - 1 && extent_state_in_tree(state)) { - while ((state = next_state(state)) != NULL) { - if (state->state & bits) - goto got_it; - } - free_extent_state(*cached_state); - *cached_state = NULL; - goto out; - } - free_extent_state(*cached_state); - *cached_state = NULL; - } - - state = find_first_extent_bit_state(tree, start, bits); -got_it: - if (state) { - cache_state_if_flags(state, cached_state, 0); - *start_ret = state->start; - *end_ret = state->end; - ret = 0; - } -out: - spin_unlock(&tree->lock); - return ret; -} - -/** - * Find a contiguous area of bits - * - * @tree: io tree to check - * @start: offset to start the search from - * @start_ret: the first offset we found with the bits set - * @end_ret: the final contiguous range of the bits that were set - * @bits: bits to look for - * - * set_extent_bit and clear_extent_bit can temporarily split contiguous ranges - * to set bits appropriately, and then merge them again. During this time it - * will drop the tree->lock, so use this helper if you want to find the actual - * contiguous area for given bits. We will search to the first bit we find, and - * then walk down the tree until we find a non-contiguous area. The area - * returned will be the full contiguous area with the bits set. - */ -int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start, - u64 *start_ret, u64 *end_ret, u32 bits) -{ - struct extent_state *state; - int ret = 1; - - spin_lock(&tree->lock); - state = find_first_extent_bit_state(tree, start, bits); - if (state) { - *start_ret = state->start; - *end_ret = state->end; - while ((state = next_state(state)) != NULL) { - if (state->start > (*end_ret + 1)) - break; - *end_ret = state->end; - } - ret = 0; - } - spin_unlock(&tree->lock); - return ret; -} - -/** - * Find the first range that has @bits not set. This range could start before - * @start. - * - * @tree: the tree to search - * @start: offset at/after which the found extent should start - * @start_ret: records the beginning of the range - * @end_ret: records the end of the range (inclusive) - * @bits: the set of bits which must be unset - * - * Since unallocated range is also considered one which doesn't have the bits - * set it's possible that @end_ret contains -1, this happens in case the range - * spans (last_range_end, end of device]. In this case it's up to the caller to - * trim @end_ret to the appropriate size. - */ -void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, - u64 *start_ret, u64 *end_ret, u32 bits) -{ - struct extent_state *state; - struct rb_node *node, *prev = NULL, *next; - - spin_lock(&tree->lock); - - /* Find first extent with bits cleared */ - while (1) { - node = tree_search_prev_next(tree, start, &prev, &next); - if (!node && !next && !prev) { - /* - * Tree is completely empty, send full range and let - * caller deal with it - */ - *start_ret = 0; - *end_ret = -1; - goto out; - } else if (!node && !next) { - /* - * We are past the last allocated chunk, set start at - * the end of the last extent. - */ - state = rb_entry(prev, struct extent_state, rb_node); - *start_ret = state->end + 1; - *end_ret = -1; - goto out; - } else if (!node) { - node = next; - } - /* - * At this point 'node' either contains 'start' or start is - * before 'node' - */ - state = rb_entry(node, struct extent_state, rb_node); - - if (in_range(start, state->start, state->end - state->start + 1)) { - if (state->state & bits) { - /* - * |--range with bits sets--| - * | - * start - */ - start = state->end + 1; - } else { - /* - * 'start' falls within a range that doesn't - * have the bits set, so take its start as - * the beginning of the desired range - * - * |--range with bits cleared----| - * | - * start - */ - *start_ret = state->start; - break; - } - } else { - /* - * |---prev range---|---hole/unset---|---node range---| - * | - * start - * - * or - * - * |---hole/unset--||--first node--| - * 0 | - * start - */ - if (prev) { - state = rb_entry(prev, struct extent_state, - rb_node); - *start_ret = state->end + 1; - } else { - *start_ret = 0; - } - break; - } - } - - /* - * Find the longest stretch from start until an entry which has the - * bits set - */ - while (1) { - state = rb_entry(node, struct extent_state, rb_node); - if (state->end >= start && !(state->state & bits)) { - *end_ret = state->end; - } else { - *end_ret = state->start - 1; - break; - } - - node = rb_next(node); - if (!node) - break; - } -out: - spin_unlock(&tree->lock); -} - -/* - * find a contiguous range of bytes in the file marked as delalloc, not - * more than 'max_bytes'. start and end are used to return the range, - * - * true is returned if we find something, false if nothing was in the tree - */ -bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, - u64 *end, u64 max_bytes, - struct extent_state **cached_state) -{ - struct rb_node *node; - struct extent_state *state; - u64 cur_start = *start; - bool found = false; - u64 total_bytes = 0; - - spin_lock(&tree->lock); - - /* - * this search will find all the extents that end after - * our range starts. - */ - node = tree_search(tree, cur_start); - if (!node) { - *end = (u64)-1; - goto out; - } - - while (1) { - state = rb_entry(node, struct extent_state, rb_node); - if (found && (state->start != cur_start || - (state->state & EXTENT_BOUNDARY))) { - goto out; - } - if (!(state->state & EXTENT_DELALLOC)) { - if (!found) - *end = state->end; - goto out; - } - if (!found) { - *start = state->start; - *cached_state = state; - refcount_inc(&state->refs); - } - found = true; - *end = state->end; - cur_start = state->end + 1; - node = rb_next(node); - total_bytes += state->end - state->start + 1; - if (total_bytes >= max_bytes) - break; - if (!node) - break; - } -out: - spin_unlock(&tree->lock); - return found; -} - /* * Process one page for __process_pages_contig(). * @@ -1907,66 +493,6 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, start, end, page_ops, NULL); } -/* - * count the number of bytes in the tree that have a given bit(s) - * set. This can be fairly slow, except for EXTENT_DIRTY which is - * cached. The total number found is returned. - */ -u64 count_range_bits(struct extent_io_tree *tree, - u64 *start, u64 search_end, u64 max_bytes, - u32 bits, int contig) -{ - struct rb_node *node; - struct extent_state *state; - u64 cur_start = *start; - u64 total_bytes = 0; - u64 last = 0; - int found = 0; - - if (WARN_ON(search_end <= cur_start)) - return 0; - - spin_lock(&tree->lock); - if (cur_start == 0 && bits == EXTENT_DIRTY) { - total_bytes = tree->dirty_bytes; - goto out; - } - /* - * this search will find all the extents that end after - * our range starts. - */ - node = tree_search(tree, cur_start); - if (!node) - goto out; - - while (1) { - state = rb_entry(node, struct extent_state, rb_node); - if (state->start > search_end) - break; - if (contig && found && state->start > last + 1) - break; - if (state->end >= cur_start && (state->state & bits) == bits) { - total_bytes += min(search_end, state->end) + 1 - - max(cur_start, state->start); - if (total_bytes >= max_bytes) - break; - if (!found) { - *start = max(cur_start, state->start); - found = 1; - } - last = state->end; - } else if (contig && found) { - break; - } - node = rb_next(node); - if (!node) - break; - } -out: - spin_unlock(&tree->lock); - return total_bytes; -} - static int insert_failrec(struct btrfs_inode *inode, struct io_failure_record *failrec) { @@ -1994,62 +520,6 @@ static struct io_failure_record *get_failrec(struct btrfs_inode *inode, return failrec; } -/* - * searches a range in the state tree for a given mask. - * If 'filled' == 1, this returns 1 only if every extent in the tree - * has the bits set. Otherwise, 1 is returned if any bit in the - * range is found set. - */ -int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int filled, struct extent_state *cached) -{ - struct extent_state *state = NULL; - struct rb_node *node; - int bitset = 0; - - spin_lock(&tree->lock); - if (cached && extent_state_in_tree(cached) && cached->start <= start && - cached->end > start) - node = &cached->rb_node; - else - node = tree_search(tree, start); - while (node && start <= end) { - state = rb_entry(node, struct extent_state, rb_node); - - if (filled && state->start > start) { - bitset = 0; - break; - } - - if (state->start > end) - break; - - if (state->state & bits) { - bitset = 1; - if (!filled) - break; - } else if (filled) { - bitset = 0; - break; - } - - if (state->end == (u64)-1) - break; - - start = state->end + 1; - if (start > end) - break; - node = rb_next(node); - if (!node) { - if (filled) - bitset = 0; - break; - } - } - spin_unlock(&tree->lock); - return bitset; -} - static int free_io_failure(struct btrfs_inode *inode, struct io_failure_record *rec) { From patchwork Fri Sep 2 20:16:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 119CAC6FA86 for ; Fri, 2 Sep 2022 20:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbiIBURQ (ORCPT ); Fri, 2 Sep 2022 16:17:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiIBURE (ORCPT ); Fri, 2 Sep 2022 16:17:04 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22273DCFF1 for ; Fri, 2 Sep 2022 13:17:03 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id mn13so2273971qvb.4 for ; Fri, 02 Sep 2022 13:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=6ZQnR23OaOG/Iymrw+qbPSLF/p8xklzJyAl1vI8Hhu0=; b=0POTDz2OzbXsIsYwqFihJeKB7vb689Jk/225a4HimdrGqaLX8LsVN9NfJp2BC0RPdi 5rie2velU6xSN581ZYrhFP9R5GWa4g58CPtrPKrW/74qWu6YAwAyc+UVbB7/EUXbuQqv 5TACZKiF7C+wTw4m4YlDnKxQw8HIOsVuH1c+vc3RM/4ugW7pN+OIVHDU+swhE8vh9lpf HoKr6JLGQ/unGvRdR3vEKuFjsPO76XtR3Y4XY62EuZBACJK/pGsZSOPQbCc3m4NRTi0R rt77jmyYfZHKyVGspFsgZh7ovS7LNciaRhEl0UEqNI/EnkvxUW/pCqYinEyokOFAhESI rBsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=6ZQnR23OaOG/Iymrw+qbPSLF/p8xklzJyAl1vI8Hhu0=; b=R5rqVcp8uzKxAy0atZ2gjxMKZgo1x4n69wK67GVNlcSW5G4yv2feBCzgB98zApePUC 2+XGiN7CReUeYeZZNT7xf/aOo6hRVlRhm9l0xtScI4new5rUZVgyd67fSfKZ933v2aL1 av8rwd/Zqta7Med3SyPEYg5UnPXgHC6ZqEcDDr64BdD8AvayxCX6X0G+/OkmkaRFhuqR PSE4Q75i3aKc4RKZHpMVXquY53NSqVazcalcXnlQYW/CbR2SShUlKcjv7Wep8TDYhvTQ gxN2qkBfQ/9257mE9ctfFizO2QqxdjtYqRS5Rv1YloXgtHa0IRmotVpAHZ9nOFjNbPBi fXZQ== X-Gm-Message-State: ACgBeo2UhWeMwRP7goJOsCP0PYGENlCWh/4VGeEV4is000A0OP2KFozK idmK3oDcZ7hLp6POMg/hfkTUkNTrdHI0XA== X-Google-Smtp-Source: AA6agR58JVgvrjep6N0J8KZ7AgCFjSunfgAQxnzR3rCCknMsZEdnmMQHeYb1TGW4bMC3R+KidVO0vw== X-Received: by 2002:a05:6214:f0e:b0:499:56:c8cb with SMTP id gw14-20020a0562140f0e00b004990056c8cbmr24127298qvb.4.1662149821827; Fri, 02 Sep 2022 13:17:01 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id z4-20020ac84544000000b00343057845f7sm1517916qtn.20.2022.09.02.13.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:01 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 13/31] btrfs: remove struct tree_entry Date: Fri, 2 Sep 2022 16:16:18 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This existed when we overloaded the tree manipulation functions for both the extent_io_tree and the extent buffer tree. However the extent buffers are now stored in a radix tree, so we no longer need this abstraction. Remove struct tree_entry and use extent_state directly instead. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 850c4e1c83f5..4e3cbb4edbe2 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -71,12 +71,6 @@ static inline void __btrfs_debug_check_extent_io_range(const char *caller, #define btrfs_debug_check_extent_io_range(c, s, e) do {} while (0) #endif -struct tree_entry { - u64 start; - u64 end; - struct rb_node rb_node; -}; - /* * For the file_extent_tree, we want to hold the inode lock when we lookup and * update the disk_i_size, but lockdep will complain because our io_tree we hold @@ -258,11 +252,11 @@ static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree struct rb_root *root = &tree->state; struct rb_node **node = &root->rb_node; struct rb_node *prev = NULL; - struct tree_entry *entry; + struct extent_state *entry; while (*node) { prev = *node; - entry = rb_entry(prev, struct tree_entry, rb_node); + entry = rb_entry(prev, struct extent_state, rb_node); if (offset < entry->start) node = &(*node)->rb_left; @@ -280,7 +274,7 @@ static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree /* Search neighbors until we find the first one past the end */ while (prev && offset > entry->end) { prev = rb_next(prev); - entry = rb_entry(prev, struct tree_entry, rb_node); + entry = rb_entry(prev, struct extent_state, rb_node); } return prev; @@ -315,14 +309,14 @@ static struct rb_node *tree_search_prev_next(struct extent_io_tree *tree, struct rb_node **node = &root->rb_node; struct rb_node *prev = NULL; struct rb_node *orig_prev = NULL; - struct tree_entry *entry; + struct extent_state *entry; ASSERT(prev_ret); ASSERT(next_ret); while (*node) { prev = *node; - entry = rb_entry(prev, struct tree_entry, rb_node); + entry = rb_entry(prev, struct extent_state, rb_node); if (offset < entry->start) node = &(*node)->rb_left; @@ -335,15 +329,15 @@ static struct rb_node *tree_search_prev_next(struct extent_io_tree *tree, orig_prev = prev; while (prev && offset > entry->end) { prev = rb_next(prev); - entry = rb_entry(prev, struct tree_entry, rb_node); + entry = rb_entry(prev, struct extent_state, rb_node); } *next_ret = prev; prev = orig_prev; - entry = rb_entry(prev, struct tree_entry, rb_node); + entry = rb_entry(prev, struct extent_state, rb_node); while (prev && offset < entry->start) { prev = rb_prev(prev); - entry = rb_entry(prev, struct tree_entry, rb_node); + entry = rb_entry(prev, struct extent_state, rb_node); } *prev_ret = prev; @@ -426,10 +420,10 @@ static int insert_state(struct extent_io_tree *tree, node = &tree->state.rb_node; while (*node) { - struct tree_entry *entry; + struct extent_state *entry; parent = *node; - entry = rb_entry(parent, struct tree_entry, rb_node); + entry = rb_entry(parent, struct extent_state, rb_node); if (end < entry->start) { node = &(*node)->rb_left; @@ -495,10 +489,10 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig, parent = &orig->rb_node; node = &parent; while (*node) { - struct tree_entry *entry; + struct extent_state *entry; parent = *node; - entry = rb_entry(parent, struct tree_entry, rb_node); + entry = rb_entry(parent, struct extent_state, rb_node); if (prealloc->end < entry->start) { node = &(*node)->rb_left; From patchwork Fri Sep 2 20:16:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0830DC6FA89 for ; Fri, 2 Sep 2022 20:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbiIBURS (ORCPT ); Fri, 2 Sep 2022 16:17:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiIBURH (ORCPT ); Fri, 2 Sep 2022 16:17:07 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5010D275F for ; Fri, 2 Sep 2022 13:17:04 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id w18so2598749qki.8 for ; Fri, 02 Sep 2022 13:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=F+g/fJCJSE8HpoM9LtNLwRyeR57FytCndlKkSsi63LU=; b=1eJyfsYPC4hRJ6fxcpIVaEJ3E1ucafYSHaqvJ17LWhiF4pn2YwndGeqdqHGpUiXXqU 444OK2eYwwRLu4z/ZOZjJ8js2/Itptgfb7MCT+wO+LrpFpbNyabStrj7+3D+qtUoL/5L FGt9I8zJqBxx2Vd24wEZiYQGL8n1oQRkunf5uGAXk5dfkg+ctNYWiBs8gVeNZu+6fI3j iMajrVko05TRKBA7ghRfjvhgcHIlhmv5uQQQQc+sI2ejL3yYXsRMCZ8tMnKQC4q2a/h8 O8I+peMyea+GMDkRmCIZ9ybMBniF4dRmIcXisbWdG7WqFuHtXSjPB1GlmoKcNPFQaEty ypRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=F+g/fJCJSE8HpoM9LtNLwRyeR57FytCndlKkSsi63LU=; b=cFDXzfZrdedCUt2ZQfOuLJhcjR0czkH4IGh0GwcxxGawHTODcHYVsaz+EAz3sHaBM9 GRHxzS1LLNTSgfU4ZBzKUfR6my0qOvOR3Okq8vktf2LcOh1zcUQ4eJ1uJzV7aKhwk+M4 RaRpkFFMBqNOHsR/4jNXOn3B+/hWgQI0fqSgWfJJ9Gvyj0BSRN/ZzeYkeH0mBHZR51kL po33mKlom5VCbuqCW5G2UVNnL/0qw9YgVC3oSH6khhW5eBdsoeBlmgHp2bxv3icflu4Q a/VysafyVO3l1043zsrIDNDhenNrQjyUrGK3hRaAK5msgtwOL40k649+faQua0cNNThR Nn5Q== X-Gm-Message-State: ACgBeo2saYgfxhPLj0tjwDPtEBIx5QLeOuYsWcKFsweO4dP4d4AYznHc XJbktLb/o5wEcEqatHZf0XRoaUgtzWwBIg== X-Google-Smtp-Source: AA6agR6Jan+pe+YQuevbyPRQ9IN1iys0EBwLsW72ssV7qXKlk95t4epfbMmnpEqtj5K1rQ9aL/PFDQ== X-Received: by 2002:a05:620a:170d:b0:6bb:3f82:6a7d with SMTP id az13-20020a05620a170d00b006bb3f826a7dmr24106571qkb.166.1662149823490; Fri, 02 Sep 2022 13:17:03 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id n22-20020ac86756000000b0034355a352d1sm1547459qtp.92.2022.09.02.13.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:03 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 14/31] btrfs: use next_state instead of rb_next where we can Date: Fri, 2 Sep 2022 16:16:19 -0400 Message-Id: <9a273f88a443ecbbc338a0ea87b6294efa6553f2.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can simplify a lot of these functions where we have to cycle through extent_state's by simply using next_state() instead of rb_next(). In many spots this allows us to do things like while (state) { /* whatever */ state = next_state(state); } instead of while (1) { state = rb_entry(n, struct extent_state, rb_node); n = rb_next(n); if (!n) break; } Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 57 +++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 4e3cbb4edbe2..32f86a524bdd 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -770,12 +770,10 @@ void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) * our range starts */ node = tree_search(tree, start); -process_node: if (!node) break; - state = rb_entry(node, struct extent_state, rb_node); - +process_node: if (state->start > end) goto out; @@ -792,7 +790,7 @@ void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) break; if (!cond_resched_lock(&tree->lock)) { - node = rb_next(node); + state = next_state(state); goto process_node; } } @@ -1325,15 +1323,13 @@ find_first_extent_bit_state(struct extent_io_tree *tree, u64 start, u32 bits) node = tree_search(tree, start); if (!node) goto out; + state = rb_entry(node, struct extent_state, rb_node); - while (1) { + while (state) { state = rb_entry(node, struct extent_state, rb_node); if (state->end >= start && (state->state & bits)) return state; - - node = rb_next(node); - if (!node) - break; + state = next_state(state); } out: return NULL; @@ -1521,18 +1517,15 @@ void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, * Find the longest stretch from start until an entry which has the * bits set */ - while (1) { - state = rb_entry(node, struct extent_state, rb_node); + state = rb_entry(node, struct extent_state, rb_node); + while (state) { if (state->end >= start && !(state->state & bits)) { *end_ret = state->end; } else { *end_ret = state->start - 1; break; } - - node = rb_next(node); - if (!node) - break; + state = next_state(state); } out: spin_unlock(&tree->lock); @@ -1566,8 +1559,8 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, goto out; } - while (1) { - state = rb_entry(node, struct extent_state, rb_node); + state = rb_entry(node, struct extent_state, rb_node); + while (state) { if (found && (state->start != cur_start || (state->state & EXTENT_BOUNDARY))) { goto out; @@ -1585,12 +1578,10 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, found = true; *end = state->end; cur_start = state->end + 1; - node = rb_next(node); total_bytes += state->end - state->start + 1; if (total_bytes >= max_bytes) break; - if (!node) - break; + state = next_state(state); } out: spin_unlock(&tree->lock); @@ -1629,8 +1620,8 @@ u64 count_range_bits(struct extent_io_tree *tree, if (!node) goto out; - while (1) { - state = rb_entry(node, struct extent_state, rb_node); + state = rb_entry(node, struct extent_state, rb_node); + while (state) { if (state->start > search_end) break; if (contig && found && state->start > last + 1) @@ -1648,9 +1639,7 @@ u64 count_range_bits(struct extent_io_tree *tree, } else if (contig && found) { break; } - node = rb_next(node); - if (!node) - break; + state = next_state(state); } out: spin_unlock(&tree->lock); @@ -1676,9 +1665,11 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, node = &cached->rb_node; else node = tree_search(tree, start); - while (node && start <= end) { - state = rb_entry(node, struct extent_state, rb_node); + if (!node) + goto out; + state = rb_entry(node, struct extent_state, rb_node); + while (state && start <= end) { if (filled && state->start > start) { bitset = 0; break; @@ -1702,13 +1693,13 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, start = state->end + 1; if (start > end) break; - node = rb_next(node); - if (!node) { - if (filled) - bitset = 0; - break; - } + state = next_state(state); } + + /* We ran out of states and were still inside of our range. */ + if (filled && !state) + bitset = 0; +out: spin_unlock(&tree->lock); return bitset; } From patchwork Fri Sep 2 20:16:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964622 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07AC2C6FA83 for ; Fri, 2 Sep 2022 20:17:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230023AbiIBURR (ORCPT ); Fri, 2 Sep 2022 16:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbiIBURH (ORCPT ); Fri, 2 Sep 2022 16:17:07 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74660E3974 for ; Fri, 2 Sep 2022 13:17:06 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id y17so2273510qvr.5 for ; Fri, 02 Sep 2022 13:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=bpVoGm6kiR8Rt3bEgKfAybcmSUc2idOuTh+rUnr2iCc=; b=QwTkbbS7Q2pGYKJr7VNQpwgMXLnRN9Ag1FdKf8ZGMD1id8FsdjuQLQjLysPg5KmIAK OfkbaA/4Lj3ZHlkPYY/gJt2mttL+9wmjQL9w+UzvyRmD1f7C4m/0mnF4KBlmw7uAPPBO i8OFqdlGNI4nO4AQe7V7/DSu8T1sBC//0vWnEBsi4e7zFfDswqqfuXGseGL74flr0DSD 9lGJFmHNUIgoCGVoB82AHwpIKUn8ku5W8fUectDp15z2cEDc8344ryF1oHCIEU3r03po HboyfDvAml7YH/7ziUnmCgUjFx9TQn9lrYAswyDBYFftCam90J829IJ967wrdF1Bprxo pmFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=bpVoGm6kiR8Rt3bEgKfAybcmSUc2idOuTh+rUnr2iCc=; b=bGQZY7YUED2YeO+vguFMgjwxl+kKVrVWtxq6KMmJ2iOKsP0u7xychfW3Jks785cyIO OaFUnaMZ/sKgIj2P5NpZYzfbcGCbDKJQHK4GjfQVQjsVcZMapvYZpQXAa6rmSSgaDode v6B1YsVSRoPwK2xPiRhvDbDkng2/l58j7viseGzwuGZ4HbASEaEchrEa0FF3HFjN1Vb8 P0wBGf7XTPJvfpIhQxPXzqq5Gwath5hBtEVG+W7rkp/YARV/SNx/UYVGMQEda+CNnMts sVX7sx6AC0m7sc0TNeWzbygqp4b0gC9LqjJctY3ZSBUyF9E/5j3xi4CPnmzBuKG76BNu G4Yw== X-Gm-Message-State: ACgBeo1AJjidGdbX2IPGN9Xw0mhOEyYO9M/xVoQ+7n42vKXnlF8foJZG 91IePWK+3hEeC0Ka/2w6s9pLz0lRYor+qw== X-Google-Smtp-Source: AA6agR7sFl1yAoconlXfuA00eXH5zfPSXVEnNGCa9l2lrIzf9mFxea+h4s0nKhOCO9SYJbE8UL5lDw== X-Received: by 2002:a05:6214:166:b0:498:ef84:f2c9 with SMTP id y6-20020a056214016600b00498ef84f2c9mr30722178qvs.104.1662149825221; Fri, 02 Sep 2022 13:17:05 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y9-20020ac81289000000b003434e47515csm1569048qti.7.2022.09.02.13.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:04 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 15/31] btrfs: make tree_search return struct extent_state Date: Fri, 2 Sep 2022 16:16:20 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a consistent pattern of n = tree_search(); if (!n) goto out; state = rb_entry(n, struct extent_state, rb_node); while (state) { /* do something. */ } which is a bit redundant. If we make tree_search return the state we can simply have state = tree_search(); while (state) { /* do something. */ } which cleans up the code quite a bit. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 51 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 32f86a524bdd..f39eb5e816eb 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -283,9 +283,10 @@ static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree /* * Inexact rb-tree search, return the next entry if @offset is not found */ -static inline struct rb_node *tree_search(struct extent_io_tree *tree, u64 offset) +static inline struct extent_state *tree_search(struct extent_io_tree *tree, u64 offset) { - return tree_search_for_insert(tree, offset, NULL, NULL); + struct rb_node *n = tree_search_for_insert(tree, offset, NULL, NULL); + return (n) ? rb_entry(n, struct extent_state, rb_node) : NULL; } /** @@ -591,7 +592,6 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state *state; struct extent_state *cached; struct extent_state *prealloc = NULL; - struct rb_node *node; u64 last_end; int err; int clear = 0; @@ -642,10 +642,9 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, * this search will find the extents that end after * our range starts */ - node = tree_search(tree, start); - if (!node) + state = tree_search(tree, start); + if (!state) goto out; - state = rb_entry(node, struct extent_state, rb_node); hit_next: if (state->start > end) goto out; @@ -758,7 +757,6 @@ static void wait_on_state(struct extent_io_tree *tree, void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { struct extent_state *state; - struct rb_node *node; btrfs_debug_check_extent_io_range(tree, start, end); @@ -769,11 +767,10 @@ void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) * this search will find all the extents that end after * our range starts */ - node = tree_search(tree, start); - if (!node) - break; - state = rb_entry(node, struct extent_state, rb_node); + state = tree_search(tree, start); process_node: + if (!state) + break; if (state->start > end) goto out; @@ -1313,25 +1310,18 @@ int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, static struct extent_state * find_first_extent_bit_state(struct extent_io_tree *tree, u64 start, u32 bits) { - struct rb_node *node; struct extent_state *state; /* * this search will find all the extents that end after * our range starts. */ - node = tree_search(tree, start); - if (!node) - goto out; - state = rb_entry(node, struct extent_state, rb_node); - + state = tree_search(tree, start); while (state) { - state = rb_entry(node, struct extent_state, rb_node); if (state->end >= start && (state->state & bits)) return state; state = next_state(state); } -out: return NULL; } @@ -1541,7 +1531,6 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, u64 *end, u64 max_bytes, struct extent_state **cached_state) { - struct rb_node *node; struct extent_state *state; u64 cur_start = *start; bool found = false; @@ -1553,13 +1542,12 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, * this search will find all the extents that end after * our range starts. */ - node = tree_search(tree, cur_start); - if (!node) { + state = tree_search(tree, cur_start); + if (!state) { *end = (u64)-1; goto out; } - state = rb_entry(node, struct extent_state, rb_node); while (state) { if (found && (state->start != cur_start || (state->state & EXTENT_BOUNDARY))) { @@ -1597,7 +1585,6 @@ u64 count_range_bits(struct extent_io_tree *tree, u64 *start, u64 search_end, u64 max_bytes, u32 bits, int contig) { - struct rb_node *node; struct extent_state *state; u64 cur_start = *start; u64 total_bytes = 0; @@ -1616,11 +1603,7 @@ u64 count_range_bits(struct extent_io_tree *tree, * this search will find all the extents that end after * our range starts. */ - node = tree_search(tree, cur_start); - if (!node) - goto out; - - state = rb_entry(node, struct extent_state, rb_node); + state = tree_search(tree, cur_start); while (state) { if (state->start > search_end) break; @@ -1656,19 +1639,14 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, int filled, struct extent_state *cached) { struct extent_state *state = NULL; - struct rb_node *node; int bitset = 0; spin_lock(&tree->lock); if (cached && extent_state_in_tree(cached) && cached->start <= start && cached->end > start) - node = &cached->rb_node; + state = cached; else - node = tree_search(tree, start); - if (!node) - goto out; - - state = rb_entry(node, struct extent_state, rb_node); + state = tree_search(tree, start); while (state && start <= end) { if (filled && state->start > start) { bitset = 0; @@ -1699,7 +1677,6 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, /* We ran out of states and were still inside of our range. */ if (filled && !state) bitset = 0; -out: spin_unlock(&tree->lock); return bitset; } From patchwork Fri Sep 2 20:16:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B62B2C6FA86 for ; Fri, 2 Sep 2022 20:17:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230030AbiIBURU (ORCPT ); Fri, 2 Sep 2022 16:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbiIBURJ (ORCPT ); Fri, 2 Sep 2022 16:17:09 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F2DCCC32E for ; Fri, 2 Sep 2022 13:17:08 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id q8so2252200qvr.9 for ; Fri, 02 Sep 2022 13:17:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=m4FfrR3uXRAR+xtQeLgJeMiHsrg7F7P/ODE/4VHRLbs=; b=SJTkVpNPqPlR+KBP8hnkU5d7iYf+5Dm9XuLQasKjqRbl4pbMW/cyGMSfjQddiI4XGC ASkehg3KHX0tu3ZRux1w/LV7LPNEE0ielaOuku3Ja1aIDb1XKDZEDU0XUfOHcHJWGBAx Z3B/3WtNe5QSyhlRZ6hXqZsoY+YE1pO4TjzDfavGTY+nRNa9fGFjkYi7fC1pQ15Au0Ih cMgo7gNXHcc9r5PEZcFIiUWsAp46xxzVoH8xzRXPNYFWKiAUbCLYGHph7xFsX7AsknSz 69b9JnMo4tam7tvIp27/OTJwctVkuPhRJaV/0QErtcf5OpO1ZjqraAMaJg1yCKcbTEsK yy0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=m4FfrR3uXRAR+xtQeLgJeMiHsrg7F7P/ODE/4VHRLbs=; b=L2qCSJsodAChAW3encb2ElrvhcyrdVUEtMBwtduWyoGV0ZsuAtqHOULL1UihK6nfp/ cbDnEU5+3jKmaUcQF/MoqLB3pBpeN8Wvmq0+nsGZN74UIOKlxlhEt/3AXw+noh/Yo3c9 eAdsiPTKKYRkNvaP83msoG6XYIxLik9qauw/LONmcBmqVDi2OF25rI1evtIgSK5/ae+S 767erwm0GUch02K+J/YAyv0BXL3Bq4kobYQDBlEzBSQzS4k/6rlFNgoW00hmovyb2imb N66/mx0VYb4PPg+CEdVzXo9vuhCbUgwdaTvR0XMWJ0Cgb045+6l/C7kjKCRMo3dErmMZ DSvQ== X-Gm-Message-State: ACgBeo0c/eP3jgdVk+rkkyaA19x17BtQNx9tH6UrruyYRW701yS8gBsi X9jMBsnLCBt+5pHiByhztNv6R5pzU3HIFA== X-Google-Smtp-Source: AA6agR7QI08M4v90Zkp0Xn8RnAqdDqZbX2tII4PjQ1fByrXtFRRkiHUmaKp4yv0NKTesT9Oh+IYzTw== X-Received: by 2002:a0c:e082:0:b0:498:f8ed:9a94 with SMTP id l2-20020a0ce082000000b00498f8ed9a94mr27966716qvk.0.1662149826951; Fri, 02 Sep 2022 13:17:06 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id e5-20020ac80105000000b00342b7e4241fsm1576573qtg.77.2022.09.02.13.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:06 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 16/31] btrfs: make tree_search_for_insert return extent_state Date: Fri, 2 Sep 2022 16:16:21 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We use this to search for an extent state, or return the nodes we need to insert a new extent state. This means we have the following pattern node = tree_search_for_insert(); if (!node) { /* alloc and insert. */ goto again; } state = rb_entry(node, struct extent_state, rb_node); we don't use the node for anything else. Making tree_search_for_insert() return the extent_state means we can drop the rb_node and clean this up by eliminating the rb_entry. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 61 ++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index f39eb5e816eb..82a18c233fa0 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -227,6 +227,15 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) return 1; } +static struct extent_state *next_state(struct extent_state *state) +{ + struct rb_node *next = rb_next(&state->rb_node); + if (next) + return rb_entry(next, struct extent_state, rb_node); + else + return NULL; +} + /** * Search @tree for an entry that contains @offset. Such entry would have * entry->start <= offset && entry->end >= offset. @@ -244,15 +253,15 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) * If no such entry exists, return pointer to entry that ends before @offset * and fill parameters @node_ret and @parent_ret, ie. does not return NULL. */ -static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree, - u64 offset, - struct rb_node ***node_ret, - struct rb_node **parent_ret) +static inline struct extent_state *tree_search_for_insert(struct extent_io_tree *tree, + u64 offset, + struct rb_node ***node_ret, + struct rb_node **parent_ret) { struct rb_root *root = &tree->state; struct rb_node **node = &root->rb_node; struct rb_node *prev = NULL; - struct extent_state *entry; + struct extent_state *entry = NULL; while (*node) { prev = *node; @@ -263,7 +272,7 @@ static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree else if (offset > entry->end) node = &(*node)->rb_right; else - return *node; + return entry; } if (node_ret) @@ -272,12 +281,10 @@ static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree *parent_ret = prev; /* Search neighbors until we find the first one past the end */ - while (prev && offset > entry->end) { - prev = rb_next(prev); - entry = rb_entry(prev, struct extent_state, rb_node); - } + while (entry && offset > entry->end) + entry = next_state(entry); - return prev; + return entry; } /* @@ -285,8 +292,7 @@ static inline struct rb_node *tree_search_for_insert(struct extent_io_tree *tree */ static inline struct extent_state *tree_search(struct extent_io_tree *tree, u64 offset) { - struct rb_node *n = tree_search_for_insert(tree, offset, NULL, NULL); - return (n) ? rb_entry(n, struct extent_state, rb_node) : NULL; + return tree_search_for_insert(tree, offset, NULL, NULL); } /** @@ -511,15 +517,6 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig, return 0; } -static struct extent_state *next_state(struct extent_state *state) -{ - struct rb_node *next = rb_next(&state->rb_node); - if (next) - return rb_entry(next, struct extent_state, rb_node); - else - return NULL; -} - /* * utility function to clear some bits in an extent state struct. * it will optionally wake up anyone waiting on this state (wake == 1). @@ -850,7 +847,6 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, { struct extent_state *state; struct extent_state *prealloc = NULL; - struct rb_node *node; struct rb_node **p; struct rb_node *parent; int err = 0; @@ -880,17 +876,15 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, if (cached_state && *cached_state) { state = *cached_state; if (state->start <= start && state->end > start && - extent_state_in_tree(state)) { - node = &state->rb_node; + extent_state_in_tree(state)) goto hit_next; - } } /* * this search will find all the extents that end after * our range starts. */ - node = tree_search_for_insert(tree, start, &p, &parent); - if (!node) { + state = tree_search_for_insert(tree, start, &p, &parent); + if (!state) { prealloc = alloc_extent_state_atomic(prealloc); BUG_ON(!prealloc); prealloc->start = start; @@ -900,7 +894,6 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, prealloc = NULL; goto out; } - state = rb_entry(node, struct extent_state, rb_node); hit_next: last_start = state->start; last_end = state->end; @@ -1086,7 +1079,6 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, { struct extent_state *state; struct extent_state *prealloc = NULL; - struct rb_node *node; struct rb_node **p; struct rb_node *parent; int err = 0; @@ -1116,18 +1108,16 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, if (cached_state && *cached_state) { state = *cached_state; if (state->start <= start && state->end > start && - extent_state_in_tree(state)) { - node = &state->rb_node; + extent_state_in_tree(state)) goto hit_next; - } } /* * this search will find all the extents that end after * our range starts. */ - node = tree_search_for_insert(tree, start, &p, &parent); - if (!node) { + state = tree_search_for_insert(tree, start, &p, &parent); + if (!state) { prealloc = alloc_extent_state_atomic(prealloc); if (!prealloc) { err = -ENOMEM; @@ -1140,7 +1130,6 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, prealloc = NULL; goto out; } - state = rb_entry(node, struct extent_state, rb_node); hit_next: last_start = state->start; last_end = state->end; From patchwork Fri Sep 2 20:16:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9EF3ECAAD5 for ; Fri, 2 Sep 2022 20:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbiIBURT (ORCPT ); Fri, 2 Sep 2022 16:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbiIBURL (ORCPT ); Fri, 2 Sep 2022 16:17:11 -0400 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDCB3CE303 for ; Fri, 2 Sep 2022 13:17:09 -0700 (PDT) Received: by mail-qv1-xf34.google.com with SMTP id x14so2270176qvr.6 for ; Fri, 02 Sep 2022 13:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=+AwI6eBo+LqisNJlM74dVMhtCZp4vIVOIvZM4d3rQuU=; b=dgmB9DF+k6OBwoGBie9BHc8xWFWYpC2kty/GOOfhTObD1ocwqnDvInIHzkFVsnY5tm BBcrDkpQn+vpdss+Yy/x+nA8OvA8ZOenW8YOEakFv1cEPjWqpJiBpMCxpX8Pyw9vwNwm GXmYL7GFfOGhGD9aePt4mzObSFWVKMFCMYZjcP39zx7ZUtIEFTaoXWIDULtfp2/l53Di 0gT8hcT2m1J8G3ppSheJ6vVi95xLDb6ZknlPq0l5GnxqzkMlxHhVYh/W0u7fbC/XfLUx iQpZPmG270Ap+VPTU1mKOg8ZSnC7jcacPYSdTl7WGqTaazWcA0kJQ4Z8gSbP5xihzwPo 6/Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=+AwI6eBo+LqisNJlM74dVMhtCZp4vIVOIvZM4d3rQuU=; b=O5QGkXhySpqRUTSZAiyPtXMcL+8F1Lk7K+vNQZQS0G9nVIUoBjq9sRNvkRJa1/Uxw3 T6Bdq6RNP2sixdJ6yEcIlvrFqsmyqdIbfwFkf+sjPJJ5mbLdJ5UDTBtTYowQ63gkawNv EgtTz9HVRNj6rYNdqL9WMfibQkLElBDfxYuf+havY6UAXRjjKPEqA8OFADqJtKPSidvC ujPRRWY+IdoN4gNK9cGe8K+PIGcuKLCEYG0tyJ31Odt/ItQisNp5yjgLS1lrf98kXjvw a/k6hGcFUUOxjDR8qNST44tpXZEYoJTM3So+QzR1AhBy8Jb5sEbMCgOCedaToC5uow7F 9WVQ== X-Gm-Message-State: ACgBeo3oW27ATGZXSouq4tSRTIabC5jARtEdQsYkhWKQ7LmfKQwg1zZk cDAgjm396DNubsYIzQIBGhH5v3VSlAu3Ag== X-Google-Smtp-Source: AA6agR64Tej5JeiVAGdEnw49ezgMirRimpokh8CbTdlYqYrcDDy7Lpt2oXhgTpP4bkHwjI8E2IjFDQ== X-Received: by 2002:a05:6214:1c8c:b0:473:408f:ddd6 with SMTP id ib12-20020a0562141c8c00b00473408fddd6mr31483245qvb.74.1662149828673; Fri, 02 Sep 2022 13:17:08 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id n22-20020ac86756000000b0034355a352d1sm1547605qtp.92.2022.09.02.13.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:08 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 17/31] btrfs: make tree_search_prev_next return extent_state's Date: Fri, 2 Sep 2022 16:16:22 -0400 Message-Id: <102bb920a9f6dec6e327f1f67d54ff850362b18c.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead of doing the rb_entry again once we return from this function, simply return the actual states themselves, and then clean up the only user of this helper to handle states instead of nodes. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 73 ++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 82a18c233fa0..9bf82c7146a8 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -236,6 +236,15 @@ static struct extent_state *next_state(struct extent_state *state) return NULL; } +static struct extent_state *prev_state(struct extent_state *state) +{ + struct rb_node *next = rb_prev(&state->rb_node); + if (next) + return rb_entry(next, struct extent_state, rb_node); + else + return NULL; +} + /** * Search @tree for an entry that contains @offset. Such entry would have * entry->start <= offset && entry->end >= offset. @@ -307,46 +316,39 @@ static inline struct extent_state *tree_search(struct extent_io_tree *tree, u64 * such entry exists, then return NULL and fill @prev_ret and @next_ret. * Otherwise return the found entry and other pointers are left untouched. */ -static struct rb_node *tree_search_prev_next(struct extent_io_tree *tree, - u64 offset, - struct rb_node **prev_ret, - struct rb_node **next_ret) +static struct extent_state *tree_search_prev_next(struct extent_io_tree *tree, + u64 offset, + struct extent_state **prev_ret, + struct extent_state **next_ret) { struct rb_root *root = &tree->state; struct rb_node **node = &root->rb_node; - struct rb_node *prev = NULL; - struct rb_node *orig_prev = NULL; - struct extent_state *entry; + struct extent_state *orig_prev; + struct extent_state *entry = NULL; ASSERT(prev_ret); ASSERT(next_ret); while (*node) { - prev = *node; - entry = rb_entry(prev, struct extent_state, rb_node); + entry = rb_entry(*node, struct extent_state, rb_node); if (offset < entry->start) node = &(*node)->rb_left; else if (offset > entry->end) node = &(*node)->rb_right; else - return *node; + return entry; } - orig_prev = prev; - while (prev && offset > entry->end) { - prev = rb_next(prev); - entry = rb_entry(prev, struct extent_state, rb_node); - } - *next_ret = prev; - prev = orig_prev; + orig_prev = entry; + while (entry && offset > entry->end) + entry = next_state(entry); + *next_ret = entry; + entry = orig_prev; - entry = rb_entry(prev, struct extent_state, rb_node); - while (prev && offset < entry->start) { - prev = rb_prev(prev); - entry = rb_entry(prev, struct extent_state, rb_node); - } - *prev_ret = prev; + while (entry && offset < entry->start) + entry = prev_state(entry); + *prev_ret = entry; return NULL; } @@ -1415,14 +1417,14 @@ void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 *start_ret, u64 *end_ret, u32 bits) { struct extent_state *state; - struct rb_node *node, *prev = NULL, *next; + struct extent_state *prev = NULL, *next; spin_lock(&tree->lock); /* Find first extent with bits cleared */ while (1) { - node = tree_search_prev_next(tree, start, &prev, &next); - if (!node && !next && !prev) { + state = tree_search_prev_next(tree, start, &prev, &next); + if (!state && !next && !prev) { /* * Tree is completely empty, send full range and let * caller deal with it @@ -1430,24 +1432,21 @@ void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, *start_ret = 0; *end_ret = -1; goto out; - } else if (!node && !next) { + } else if (!state && !next) { /* * We are past the last allocated chunk, set start at * the end of the last extent. */ - state = rb_entry(prev, struct extent_state, rb_node); - *start_ret = state->end + 1; + *start_ret = prev->end + 1; *end_ret = -1; goto out; - } else if (!node) { - node = next; + } else if (!state) { + state = next; } /* * At this point 'node' either contains 'start' or start is * before 'node' */ - state = rb_entry(node, struct extent_state, rb_node); - if (in_range(start, state->start, state->end - state->start + 1)) { if (state->state & bits) { /* @@ -1481,13 +1480,10 @@ void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, * 0 | * start */ - if (prev) { - state = rb_entry(prev, struct extent_state, - rb_node); + if (prev) *start_ret = state->end + 1; - } else { + else *start_ret = 0; - } break; } } @@ -1496,7 +1492,6 @@ void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, * Find the longest stretch from start until an entry which has the * bits set */ - state = rb_entry(node, struct extent_state, rb_node); while (state) { if (state->end >= start && !(state->state & bits)) { *end_ret = state->end; From patchwork Fri Sep 2 20:16:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A12AC6FA83 for ; Fri, 2 Sep 2022 20:17:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbiIBURV (ORCPT ); Fri, 2 Sep 2022 16:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiIBURM (ORCPT ); Fri, 2 Sep 2022 16:17:12 -0400 Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 909B9D1245 for ; Fri, 2 Sep 2022 13:17:11 -0700 (PDT) Received: by mail-qv1-xf2b.google.com with SMTP id l5so2241670qvs.13 for ; Fri, 02 Sep 2022 13:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=B41h4t1fWN6ZCZvrgNTNPCpobaQCPA3fMj1ZGefNfK0=; b=GzFUBkcZdGdY3PuZxOl9xPKYQFm882U80a0xingsxMvvc2/DmiA2Nt3rl66ueqpua4 2fCCFMAavnzdHNKKX8g8n8p+vi5gBO+UZpihZWR9E+YxrEs58jm7KC6r6E2y+Rf4S5Zd 6NJ8hEoMqvEx626MKA0rH0G+l2rPcEmKZyYmqhQT3ToPrSyligk/gLatzL2ujYEx9ZJn xcHh/vjvz3Z/bxQjYZeUHt/HrQZ2Hmx2Tssl8v6rK0HqxS8mtD/oLdhrZYnKfCSdGc2k eyhKurHZpVcBvS5eBcxuzTKT7q/YZCz6UyPafsqzfClm3jNAaVDNJOfTFCklZKG+RSBC GyBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=B41h4t1fWN6ZCZvrgNTNPCpobaQCPA3fMj1ZGefNfK0=; b=Ivf4BFMGFNTejwtkNadmwMW5cWwPwvocM4n4gciqEefNHFsbBXX97McGKjqMuPIMeP GP1pfBwfwhhRh3Qh6C921rAGalQTbXS5135ixbPFtfd8LjCNzdxy2cg8zrxosjw7QEjL ciQCjhBpB32getqEXLvGkArpeZ91BDGrPD3U9r90NuNJrYYZmgO6As9VKkCWKijz0hrH 72gJNXx+DmcebRdgcFGLSyBv0liexzmYl1du9Rq/LacfBFkpbuHsTuOVjsUGrhDVFwLS yep2T+kutroxNnthwkcBQPcU+hXmDnTzZ1jm86EcQNB+RRyNuYVRiA2DnvcFQGaoSjYU V1TA== X-Gm-Message-State: ACgBeo2tP6/FiLS8P+uV8sNKwalxFVrfFCQ3t8UA8jfn+r0V5Kdhl3v/ lCpAQQFwAWYCkgLxRce9NMmFYIl2qwyiSg== X-Google-Smtp-Source: AA6agR56NUx77QbfOKFM9VUJpRwdSJOaZsl/IPW5XCq8aOWza0dXPrCFedpIoHXQBfAehsXX0AtRrQ== X-Received: by 2002:a0c:f242:0:b0:498:f3ff:d9e8 with SMTP id z2-20020a0cf242000000b00498f3ffd9e8mr29169974qvl.18.1662149830363; Fri, 02 Sep 2022 13:17:10 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id s13-20020a05620a0bcd00b006bb82221013sm2321106qki.0.2022.09.02.13.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:09 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 18/31] btrfs: use next_state/prev_state in merge_state Date: Fri, 2 Sep 2022 16:16:23 -0400 Message-Id: <6596fa73ebb4edcb1db79b0c099da17ca7d26275.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We use rb_next/rb_prev and then get the entry for the adjacent items in an extent io tree. We have helpers for this, so convert merge_state to use next_state/prev_state and simplify the code. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 49 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 9bf82c7146a8..bd015f304142 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -366,40 +366,31 @@ static void merge_state(struct extent_io_tree *tree, struct extent_state *state) { struct extent_state *other; - struct rb_node *other_node; if (state->state & (EXTENT_LOCKED | EXTENT_BOUNDARY)) return; - other_node = rb_prev(&state->rb_node); - if (other_node) { - other = rb_entry(other_node, struct extent_state, rb_node); - if (other->end == state->start - 1 && - other->state == state->state) { - if (tree->private_data && - is_data_inode(tree->private_data)) - btrfs_merge_delalloc_extent(tree->private_data, - state, other); - state->start = other->start; - rb_erase(&other->rb_node, &tree->state); - RB_CLEAR_NODE(&other->rb_node); - free_extent_state(other); - } + other = prev_state(state); + if (other && other->end == state->start - 1 && + other->state == state->state) { + if (tree->private_data && is_data_inode(tree->private_data)) + btrfs_merge_delalloc_extent(tree->private_data, + state, other); + state->start = other->start; + rb_erase(&other->rb_node, &tree->state); + RB_CLEAR_NODE(&other->rb_node); + free_extent_state(other); } - other_node = rb_next(&state->rb_node); - if (other_node) { - other = rb_entry(other_node, struct extent_state, rb_node); - if (other->start == state->end + 1 && - other->state == state->state) { - if (tree->private_data && - is_data_inode(tree->private_data)) - btrfs_merge_delalloc_extent(tree->private_data, - state, other); - state->end = other->end; - rb_erase(&other->rb_node, &tree->state); - RB_CLEAR_NODE(&other->rb_node); - free_extent_state(other); - } + other = next_state(state); + if (other && other->start == state->end + 1 && + other->state == state->state) { + if (tree->private_data && is_data_inode(tree->private_data)) + btrfs_merge_delalloc_extent(tree->private_data, state, + other); + state->end = other->end; + rb_erase(&other->rb_node, &tree->state); + RB_CLEAR_NODE(&other->rb_node); + free_extent_state(other); } } From patchwork Fri Sep 2 20:16:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B8F8ECAAD5 for ; Fri, 2 Sep 2022 20:17:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbiIBURW (ORCPT ); Fri, 2 Sep 2022 16:17:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbiIBURO (ORCPT ); Fri, 2 Sep 2022 16:17:14 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 448E0CE303 for ; Fri, 2 Sep 2022 13:17:13 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id j17so2334011qtp.12 for ; Fri, 02 Sep 2022 13:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=NMpI4eQ6mi5IeRB8vcvK1+ytWBB9Hanr4llvJzPUIQs=; b=Dn6HLZQ2TxZaBKRYv0dO+2eICxhzrEfywbqofPozvNlNjdAGpwtTfXqaoc1mS9lWk2 oeKOJ7BCJvMS3UcbiyrsocM9Up0w+xl4dgo5yyA1T0sLJoS3yy7PU1GxonQ//mHcAmyn DbLnDwt10OyWraXAA5ary3q8Jux0TWEmVmTBjDps99+bjso3GxwkLgl7wLVTH14LD1Ih 7lnj9EPXxOY7vIpXbn2lc3IRN4LZy3JBxo74i/zVzrlCpt8Kwmfs8GMzux84evP/ooPN 0yB2MH9V4GOANjj3EmGrCg/9AP5IHvaLn5O2rRWr9GJwEoraC4aB0NWXodHHf9rUn6Fx V1xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=NMpI4eQ6mi5IeRB8vcvK1+ytWBB9Hanr4llvJzPUIQs=; b=6ELMSiKgE5hVzt7eNh9wijL0Bsz6272/01nn8mGrOxgyYw2lPxP/8J9yWWIweFaVjN LvWTUFuDAF6Z5zlS0MbFNpYW7O+6T776WHF+XSTVFenbC+zCbiDKZqSYi7OD+rsNqqMX 5Y0LdlgnuDZ0MF1c8RIX2vFwm3Cyj5Zrq/6eGsZzpBuOCW8fT/gwA4SUnf8AwiiPTlkX pRVZsoyIaSLOwppwDiHK+mqetvYDd4zOuUETubK6OZJZnn9c9qTsBcHKEdDruAIxN+9R bKvMx6y4JmWs278kE1JKRndVjck/6c08Lgqs3B3Ze9bxBpZS9df7M4T7FPOJz5K1Apiw 2ACQ== X-Gm-Message-State: ACgBeo1HpwQbo8iwsd9UfvZUhOOanIQT4tNbSSzZGcekNc9JY7EdXpw9 +eyrAEfQVv6zWgVscr0CGjh/M2X8Lv39zg== X-Google-Smtp-Source: AA6agR4WzYxdVGdfwpRPARSSiwnkunHE6vO7UjcigOzIgP3eOUV4usl1FkXg2jAnetAITiQoQ6pAyg== X-Received: by 2002:a05:622a:650:b0:343:67f3:1b41 with SMTP id a16-20020a05622a065000b0034367f31b41mr29605964qtb.452.1662149832034; Fri, 02 Sep 2022 13:17:12 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id c4-20020ac84e04000000b00344f936bfc0sm1537637qtw.33.2022.09.02.13.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:11 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 19/31] btrfs: remove temporary exports for extent_state movement Date: Fri, 2 Sep 2022 16:16:24 -0400 Message-Id: <381be399ffd33a24732cd1d76788646ea9f4752b.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that the code has been moved we can remove these temporary exports. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 9 +++++++-- fs/btrfs/extent-io-tree.h | 9 --------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index bd015f304142..5f0a00c6aa96 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -9,6 +9,11 @@ static struct kmem_cache *extent_state_cache; +static inline bool extent_state_in_tree(const struct extent_state *state) +{ + return !RB_EMPTY_NODE(&state->rb_node); +} + #ifdef CONFIG_BTRFS_DEBUG static LIST_HEAD(states); static DEFINE_SPINLOCK(leak_lock); @@ -123,7 +128,7 @@ void extent_io_tree_release(struct extent_io_tree *tree) spin_unlock(&tree->lock); } -struct extent_state *alloc_extent_state(gfp_t mask) +static struct extent_state *alloc_extent_state(gfp_t mask) { struct extent_state *state; @@ -144,7 +149,7 @@ struct extent_state *alloc_extent_state(gfp_t mask) return state; } -struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc) +static struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc) { if (!prealloc) prealloc = alloc_extent_state(GFP_ATOMIC); diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 3b63aeca941a..3b17cc33bcec 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -260,13 +260,4 @@ void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, u64 end); int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, struct page *page, unsigned int pg_offset); - -struct extent_state *alloc_extent_state_atomic(struct extent_state *prealloc); -struct extent_state *alloc_extent_state(gfp_t mask); - -static inline bool extent_state_in_tree(const struct extent_state *state) -{ - return !RB_EMPTY_NODE(&state->rb_node); -} - #endif /* BTRFS_EXTENT_IO_TREE_H */ From patchwork Fri Sep 2 20:16:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964628 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2D23C6FA83 for ; Fri, 2 Sep 2022 20:17:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbiIBURX (ORCPT ); Fri, 2 Sep 2022 16:17:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229956AbiIBURQ (ORCPT ); Fri, 2 Sep 2022 16:17:16 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3E1AD3EEB for ; Fri, 2 Sep 2022 13:17:14 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id j1so2260716qvv.8 for ; Fri, 02 Sep 2022 13:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=20Yhsr54XoS92CwX/KkffhTXptoTrMLHY/7ZUT2KoZo=; b=MUZhC6ZS1UN5NUOXLctr+Rr4PL3InaPRxXobMGjqAQU14/V4PJ8c916T3cmL4JQmYA fQ5Uxv/9xdHYpEvw2lJMedIrbziRt+GmACfhEM+fXNehrpgydHoliaJmKyaLBiKllEdi Asu7f96HMkitH2knsQBgHVlRDs9lmO1T/mbWtT3po7jOy28pV2vRqiXGdJK7HNsWetfX mJgzQEEjcx4UNey0o+FTcQExmzS+hREbpyZza3Jr85P9VZ84qEktWfzQgiBhulIN9YvO 6iWumNLmPirSW/u2lgzFTCLrdhU0oAhh+3VfyNdVpSUlZu+pakGBfAgFbehKcJ2Kt/To ef0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=20Yhsr54XoS92CwX/KkffhTXptoTrMLHY/7ZUT2KoZo=; b=KxJ9IkHg8xzobAhU40JBS/J/axDDB+UrM4iizYKVsaweoZvOKr26y40rzGABVuxU/I LH9bV1Dd3BNZ5gKv6AfleRg21eb6186UMOcuAf0g9RYMO9F51M/X+tDhUdNmarjuUrMk FyOSpVUhD7Yvy9EHA4a4qr2ahL6FFapdMZlprOgjKVqas2iXVqmxmVfXV4/fEam5uinv 1+IClym1qeIpCU8ZpF6AP4KVLFGU8ZNHXT/erbR4LWiwmsIfxoQZJpj1tO1uQOfdiO8N 7cbGGq7+Sc7NZrDPmxKfaoKmQV+t9E7DsNQgycQN8ceJXs2sLzTMN6vCZ83jCzd6GGdD W/FA== X-Gm-Message-State: ACgBeo3huhtOV7PZW5j/qN0N9HVmFt1u7aQjVIOJO0GfpawE5+3lP5Bv YDVAJ84sJZQQd4kv7ipsjfI2bl7I8wtVxg== X-Google-Smtp-Source: AA6agR7QV+NqvlkNnKPQdXrnbBaW5uNi6DUVNQb8YQLCL3XZiFJ+jRQXv6vBOucq/S1WItX57Q3EGw== X-Received: by 2002:ad4:5de7:0:b0:496:d0f8:7000 with SMTP id jn7-20020ad45de7000000b00496d0f87000mr30772453qvb.12.1662149833624; Fri, 02 Sep 2022 13:17:13 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id 2-20020ac85742000000b003434f7483a1sm1684712qtx.32.2022.09.02.13.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:13 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 20/31] btrfs: move irrelevant prototypes to their appropriate header Date: Fri, 2 Sep 2022 16:16:25 -0400 Message-Id: <9724af5ba38bba89c9c4abc71301119d60bf8135.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org These prototypes have nothing to do with the extent_io_tree helpers, move them to their appropriate header. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.h | 8 -------- fs/btrfs/extent_io.h | 6 ++++++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 3b17cc33bcec..85acdd13d2c4 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -248,16 +248,8 @@ void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 *start_ret, u64 *end_ret, u32 bits); int find_contiguous_extent_bit(struct extent_io_tree *tree, u64 start, u64 *start_ret, u64 *end_ret, u32 bits); -int extent_invalidate_folio(struct extent_io_tree *tree, - struct folio *folio, size_t offset); bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, u64 *end, u64 max_bytes, struct extent_state **cached_state); void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits); - -/* This should be reworked in the future and put elsewhere. */ -void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, - u64 end); -int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, - struct page *page, unsigned int pg_offset); #endif /* BTRFS_EXTENT_IO_TREE_H */ diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 52e4dfea2164..ba331bced460 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -242,6 +242,8 @@ void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end); void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, struct page *locked_page, u32 bits_to_clear, unsigned long page_ops); +int extent_invalidate_folio(struct extent_io_tree *tree, + struct folio *folio, size_t offset); int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array); @@ -272,6 +274,10 @@ struct io_failure_record { int btrfs_repair_one_sector(struct inode *inode, struct btrfs_bio *failed_bbio, u32 bio_offset, struct page *page, unsigned int pgoff, submit_bio_hook_t *submit_bio_hook); +void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, + u64 end); +int btrfs_clean_io_failure(struct btrfs_inode *inode, u64 start, + struct page *page, unsigned int pg_offset); #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS bool find_lock_delalloc_range(struct inode *inode, From patchwork Fri Sep 2 20:16:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7F7FECAAD5 for ; Fri, 2 Sep 2022 20:17:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbiIBURY (ORCPT ); Fri, 2 Sep 2022 16:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiIBURR (ORCPT ); Fri, 2 Sep 2022 16:17:17 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E24D344C for ; Fri, 2 Sep 2022 13:17:16 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id h21so2366049qta.3 for ; Fri, 02 Sep 2022 13:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=nUH29Kuj+9Kj13POOq6b6+j8Fm5sPuZ/f0gXK+WTPBU=; b=QcJu4mPzW6Fflk0r1x9OgB9XWVigzXxsazfBLU/q1Bmqtig7plyInAgd37BWC/Mu/c 9eGv133VrhoD1RUFkjjz+UWBA7WnzGhXSsnOtbKSlsiulCd4ApCx/o8AM6SzRo+9EIvn cm7NoNBHfG0Irjby+zMdgP0YZ95Gskmd/9GVzXJKTNiGf/T7bpu98tma8cSMBT4qHnYX M5/brBrrRL6Gb9gV3eSfl+AclH2p/lVX7k4dZI+1FwOb8qwX4NDjOejAedxHu2oylTyz iWmd+xBgvy8q3Vo5EWjiIMw9bV/ZHBzugW4JREEUDc4Nu3xzB9LZV9SKAYHTIJwEum0x 5Uqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=nUH29Kuj+9Kj13POOq6b6+j8Fm5sPuZ/f0gXK+WTPBU=; b=z5LFtsDACOIwDTluH6sf7FhYb5dlBXo/5JXgfIQdWY6JD4VQFEQGIzPw3dpoO220QW HVaPbrgl/0jr1eJ+jqltHcO+8K7GAS8Q+JrEexdU4/T9uMKxw9lxdCQ4C/I4OuMgronZ Q5dHHc4rSC36ZxqNDikdD4ZieAtz3bVuK2A/kCs3pS9cWFl7F6bmotteUiqjuyQdQdIk 8C3H8HXgBLIahx5AsZshvGAnA05bFmFSyv68WqR1u95314RwUExPS4SdUg0Z8SzVLlvT aABkxG/aXE6uWL9li4qWrnQBa/EfUuPfk/ZqqJYePPMINDInNV8t+m1pRhSb+2C5aqLW CeAA== X-Gm-Message-State: ACgBeo0ewymVyNf8LhgMQ5U7fAycEqmXT4v2oVElL+PmbkSo5m3Ct9hw tF8JN0n4wcoxejMB6Vgrbr6TN6EmzNHC5g== X-Google-Smtp-Source: AA6agR6O9tVHZpPU+Q7K76DhZmq93ISeAu9ssLdoXY2vv4WYNuBfZTreqQr3IUagT29zxR8wfPETrg== X-Received: by 2002:ac8:7f47:0:b0:344:8d2b:14a9 with SMTP id g7-20020ac87f47000000b003448d2b14a9mr29570359qtk.442.1662149835200; Fri, 02 Sep 2022 13:17:15 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id d16-20020ac86150000000b0033a5048464fsm1709768qtm.11.2022.09.02.13.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:14 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 21/31] btrfs: drop exclusive_bits from set_extent_bit Date: Fri, 2 Sep 2022 16:16:26 -0400 Message-Id: <753911ae28fb8e99d593867fd0874793abbb729b.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is only ever set if we have EXTENT_LOCKED set, so simply push this into the function itself and remove the function argument. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 16 ++++++++-------- fs/btrfs/extent-io-tree.h | 20 ++++++++++---------- fs/btrfs/inode.c | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 5f0a00c6aa96..97df40edf199 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -199,7 +199,7 @@ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, */ ASSERT(!(bits & EXTENT_LOCKED)); - return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS, + return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOFS, changeset); } @@ -221,8 +221,8 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) int err; u64 failed_start; - err = set_extent_bit(tree, start, end, EXTENT_LOCKED, EXTENT_LOCKED, - &failed_start, NULL, GFP_NOFS, NULL); + err = set_extent_bit(tree, start, end, EXTENT_LOCKED, &failed_start, + NULL, GFP_NOFS, NULL); if (err == -EEXIST) { if (failed_start > start) clear_extent_bit(tree, start, failed_start - 1, @@ -839,9 +839,8 @@ static void cache_state(struct extent_state *state, * [start, end] is inclusive This takes the tree lock. */ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, - u32 exclusive_bits, u64 *failed_start, - struct extent_state **cached_state, gfp_t mask, - struct extent_changeset *changeset) + u64 *failed_start, struct extent_state **cached_state, + gfp_t mask, struct extent_changeset *changeset) { struct extent_state *state; struct extent_state *prealloc = NULL; @@ -850,6 +849,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, int err = 0; u64 last_start; u64 last_end; + u32 exclusive_bits = bits & EXTENT_LOCKED; btrfs_debug_check_extent_io_range(tree, start, end); trace_btrfs_set_extent_bit(tree, start, end - start + 1, bits); @@ -1278,8 +1278,8 @@ int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, while (1) { err = set_extent_bit(tree, start, end, EXTENT_LOCKED, - EXTENT_LOCKED, &failed_start, - cached_state, GFP_NOFS, NULL); + &failed_start, cached_state, GFP_NOFS, + NULL); if (err == -EEXIST) { wait_extent_bit(tree, failed_start, end, EXTENT_LOCKED); start = failed_start; diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 85acdd13d2c4..fb6caef20373 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -166,21 +166,21 @@ static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start, int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, struct extent_changeset *changeset); int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, unsigned exclusive_bits, u64 *failed_start, + u32 bits, u64 *failed_start, struct extent_state **cached_state, gfp_t mask, struct extent_changeset *changeset); static inline int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, - GFP_NOWAIT, NULL); + return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOWAIT, + NULL); } static inline int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - return set_extent_bit(tree, start, end, bits, 0, NULL, NULL, GFP_NOFS, + return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOFS, NULL); } @@ -194,8 +194,8 @@ static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, static inline int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask) { - return set_extent_bit(tree, start, end, EXTENT_DIRTY, 0, NULL, NULL, - mask, NULL); + return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL, NULL, mask, + NULL); } static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start, @@ -216,7 +216,7 @@ static inline int set_extent_delalloc(struct extent_io_tree *tree, u64 start, { return set_extent_bit(tree, start, end, EXTENT_DELALLOC | extra_bits, - 0, NULL, cached_state, GFP_NOFS, NULL); + NULL, cached_state, GFP_NOFS, NULL); } static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start, @@ -224,20 +224,20 @@ static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start, { return set_extent_bit(tree, start, end, EXTENT_DELALLOC | EXTENT_DEFRAG, - 0, NULL, cached_state, GFP_NOFS, NULL); + NULL, cached_state, GFP_NOFS, NULL); } static inline int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end) { - return set_extent_bit(tree, start, end, EXTENT_NEW, 0, NULL, NULL, + return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, NULL, GFP_NOFS, NULL); } static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached_state, gfp_t mask) { - return set_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, NULL, + return set_extent_bit(tree, start, end, EXTENT_UPTODATE, NULL, cached_state, mask, NULL); } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7bdf89756be4..85f7407e7975 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2816,7 +2816,7 @@ static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode, ret = set_extent_bit(&inode->io_tree, search_start, search_start + em_len - 1, - EXTENT_DELALLOC_NEW, 0, NULL, cached_state, + EXTENT_DELALLOC_NEW, NULL, cached_state, GFP_NOFS, NULL); next: search_start = extent_map_end(em); @@ -4964,7 +4964,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, if (only_release_metadata) set_extent_bit(&inode->io_tree, block_start, block_end, - EXTENT_NORESERVE, 0, NULL, NULL, GFP_NOFS, NULL); + EXTENT_NORESERVE, NULL, NULL, GFP_NOFS, NULL); out_unlock: if (ret) { From patchwork Fri Sep 2 20:16:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964630 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA16DC6FA82 for ; Fri, 2 Sep 2022 20:17:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbiIBUR0 (ORCPT ); Fri, 2 Sep 2022 16:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbiIBURT (ORCPT ); Fri, 2 Sep 2022 16:17:19 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1012CC889B for ; Fri, 2 Sep 2022 13:17:18 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id cb8so2406219qtb.0 for ; Fri, 02 Sep 2022 13:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=Z0+Hurpun/z0kvloU6g9sjH91umvhSP8/BC8k3Z4wIY=; b=EBHgl5LOegTcFh5y8SBqnMJ1rPmfw9/TU/9yppYMC2lkRcCCtnqlDeY+R08T5JNJiK LGG0JR6Whmx81okHxx2gCs1neFScD05Zn1v43nHxtYUMo4qfDXysZQinBpbniG5NEpR8 uLnJ1iJwjEil7wE6Mzg0XZ5dznMMAYdxzoTi/O2oKdCvwGqYDTlkw5Heex1cPT9TuTdX 1TPbwyS8SMXn3G8H0jTyJ6MnqESj5CH/oYRlDwXR458UV0gOz26oN/gdyu+87jbRaY8i Vu+l17nS2ppGUjnpUxSdA/98VEiLLsGKyrFIKo+om5EJJE1Gu8/ya2P+wUCgBV43hWEx cm0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Z0+Hurpun/z0kvloU6g9sjH91umvhSP8/BC8k3Z4wIY=; b=aWQxRhMA4Dpolf8tgBuRbthfwCq9hJaIC2j3OdYQZEVSei0tZUSJ+gKG0zJWNHu2m2 UR5yGIn4bVwq8AuvnpsEcTd1VDqDsNvwZZX0TKz0XxLrCOsGt0l88EgslL9TsF/mEFxg jcKma5Mval7kr0lU8gOzSK3f3WLOQpXZTX6VNR9wAK2VENKAbl9ZSxufs4BqvBVEOGkd wjt049vJ+fsLP6FK4DwgWBwKOdE1IpVS5eLdzQNTYcfsn+n/J3B3vMrlaKaX69/QCjh0 fGrDllU0k5YlPbLJARWgOXXfVOE9s7Dn1D6/UdVbXboF+k2c3zIDBJum6n0rDM7qSUOB 2MAA== X-Gm-Message-State: ACgBeo3rogACVhE4G773Fi/EUkEtDi+Zz9CxFyQy15/UKNhCNtzaYmJJ XOMvd20vNtksKNUCbRi4dPef7qyE8OqXyQ== X-Google-Smtp-Source: AA6agR7+RxuW8Ewpn5XrdZAKzcQL8iGot6/CkHAn2f11WelVg/oSMo4mQZR8Y1kPDTEgDQ0B08Oz2w== X-Received: by 2002:ac8:5e46:0:b0:344:6be6:82c4 with SMTP id i6-20020ac85e46000000b003446be682c4mr30107409qtx.240.1662149836814; Fri, 02 Sep 2022 13:17:16 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id l5-20020a05620a28c500b006b5f06186aesm2142799qkp.65.2022.09.02.13.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:16 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 22/31] btrfs: remove the wake argument from clear_extent_bits Date: Fri, 2 Sep 2022 16:16:27 -0400 Message-Id: <0f7f6a342f8a1eebe72fe873e57cfac26c3a3fb3.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is only used in the case that we are clearing EXTENT_LOCKED, so infer this value from the bits passed in instead of taking it as an argument. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 7 ++++--- fs/btrfs/extent-io-tree.h | 34 ++++++++++++++-------------------- fs/btrfs/extent_io.c | 4 ++-- fs/btrfs/extent_map.c | 2 +- fs/btrfs/file-item.c | 2 +- fs/btrfs/file.c | 2 +- fs/btrfs/free-space-cache.c | 6 +++--- fs/btrfs/inode.c | 17 ++++++++--------- fs/btrfs/ioctl.c | 2 +- fs/btrfs/reflink.c | 2 +- fs/btrfs/tests/inode-tests.c | 8 ++++---- fs/btrfs/transaction.c | 2 +- 12 files changed, 41 insertions(+), 47 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 97df40edf199..f486e70b444b 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -212,7 +212,7 @@ int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, */ ASSERT(!(bits & EXTENT_LOCKED)); - return __clear_extent_bit(tree, start, end, bits, 0, 0, NULL, GFP_NOFS, + return __clear_extent_bit(tree, start, end, bits, 0, NULL, GFP_NOFS, changeset); } @@ -226,7 +226,7 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) if (err == -EEXIST) { if (failed_start > start) clear_extent_bit(tree, start, failed_start - 1, - EXTENT_LOCKED, 1, 0, NULL); + EXTENT_LOCKED, 0, NULL); return 0; } return 1; @@ -580,7 +580,7 @@ static void extent_io_tree_panic(struct extent_io_tree *tree, int err) * This takes the tree lock, and returns 0 on success and < 0 on error. */ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int wake, int delete, + u32 bits, int delete, struct extent_state **cached_state, gfp_t mask, struct extent_changeset *changeset) { @@ -590,6 +590,7 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u64 last_end; int err; int clear = 0; + int wake = (bits & EXTENT_LOCKED) ? 1 : 0; btrfs_debug_check_extent_io_range(tree, start, end); trace_btrfs_clear_extent_bit(tree, start, end - start + 1, bits); diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index fb6caef20373..bd3c345a7530 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -121,46 +121,40 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, struct extent_changeset *changeset); int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int wake, int delete, - struct extent_state **cached, gfp_t mask, - struct extent_changeset *changeset); + u32 bits, int delete, struct extent_state **cached, + gfp_t mask, struct extent_changeset *changeset); static inline int clear_extent_bit(struct extent_io_tree *tree, u64 start, - u64 end, u32 bits, int wake, int delete, + u64 end, u32 bits, int delete, struct extent_state **cached) { - return __clear_extent_bit(tree, start, end, bits, wake, delete, - cached, GFP_NOFS, NULL); + return __clear_extent_bit(tree, start, end, bits, delete, cached, + GFP_NOFS, NULL); } static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end) { - return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, NULL); + return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, NULL); } static inline int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached) { - return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, cached, - GFP_NOFS, NULL); + return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached, + GFP_NOFS, NULL); } static inline int unlock_extent_cached_atomic(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached) { - return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, cached, - GFP_ATOMIC, NULL); + return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached, + GFP_ATOMIC, NULL); } static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - int wake = 0; - - if (bits & EXTENT_LOCKED) - wake = 1; - - return clear_extent_bit(tree, start, end, bits, wake, 0, NULL); + return clear_extent_bit(tree, start, end, bits, 0, NULL); } int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, @@ -187,8 +181,8 @@ static inline int set_extent_bits(struct extent_io_tree *tree, u64 start, static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached_state) { - return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0, - cached_state, GFP_NOFS, NULL); + return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, + cached_state, GFP_NOFS, NULL); } static inline int set_extent_dirty(struct extent_io_tree *tree, u64 start, @@ -203,7 +197,7 @@ static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start, { return clear_extent_bit(tree, start, end, EXTENT_DIRTY | EXTENT_DELALLOC | - EXTENT_DO_ACCOUNTING, 0, 0, cached); + EXTENT_DO_ACCOUNTING, 0, cached); } int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c38d31b8b18f..66d3fefa8bee 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -487,7 +487,7 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, struct page *locked_page, u32 clear_bits, unsigned long page_ops) { - clear_extent_bit(&inode->io_tree, start, end, clear_bits, 1, 0, NULL); + clear_extent_bit(&inode->io_tree, start, end, clear_bits, 0, NULL); __process_pages_contig(inode->vfs_inode.i_mapping, locked_page, start, end, page_ops, NULL); @@ -3400,7 +3400,7 @@ static int try_release_extent_state(struct extent_io_tree *tree, */ ret = __clear_extent_bit(tree, start, end, ~(EXTENT_LOCKED | EXTENT_NODATASUM | EXTENT_DELALLOC_NEW), - 0, 0, NULL, mask, NULL); + 0, NULL, mask, NULL); /* if clear_extent_bit failed for enomem reasons, * we can't allow the release to continue. diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 6fee14ce2e6b..fae627c28d7c 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -382,7 +382,7 @@ static void extent_map_device_clear_bits(struct extent_map *em, unsigned bits) __clear_extent_bit(&device->alloc_state, stripe->physical, stripe->physical + stripe_size - 1, bits, - 0, 0, NULL, GFP_NOWAIT, NULL); + 0, NULL, GFP_NOWAIT, NULL); } } diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 29999686d234..d44e0d3c84cd 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -118,7 +118,7 @@ int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start, if (btrfs_fs_incompat(inode->root->fs_info, NO_HOLES)) return 0; return clear_extent_bit(&inode->file_extent_tree, start, - start + len - 1, EXTENT_DIRTY, 0, 0, NULL); + start + len - 1, EXTENT_DIRTY, 0, NULL); } static inline u32 max_ordered_sum_bytes(struct btrfs_fs_info *fs_info, diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 0a76ae8b8e96..3a7fc25eb50d 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -473,7 +473,7 @@ int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages, */ clear_extent_bit(&inode->io_tree, start_pos, end_of_last_block, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, - 0, 0, cached); + 0, cached); err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, extra_bits, cached); diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 0c94bbb5dcd7..0bd5b02966c0 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1163,7 +1163,7 @@ update_cache_item(struct btrfs_trans_handle *trans, ret = btrfs_search_slot(trans, root, &key, path, 0, 1); if (ret < 0) { clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, inode->i_size - 1, - EXTENT_DELALLOC, 0, 0, NULL); + EXTENT_DELALLOC, 0, NULL); goto fail; } leaf = path->nodes[0]; @@ -1176,7 +1176,7 @@ update_cache_item(struct btrfs_trans_handle *trans, found_key.offset != offset) { clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, inode->i_size - 1, EXTENT_DELALLOC, 0, - 0, NULL); + NULL); btrfs_release_path(path); goto fail; } @@ -1272,7 +1272,7 @@ static int flush_dirty_cache(struct inode *inode) ret = btrfs_wait_ordered_range(inode, 0, (u64)-1); if (ret) clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, inode->i_size - 1, - EXTENT_DELALLOC, 0, 0, NULL); + EXTENT_DELALLOC, 0, NULL); return ret; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 85f7407e7975..700e6aa4af4f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1748,7 +1748,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, if (count > 0) clear_extent_bit(io_tree, start, end, EXTENT_NORESERVE, - 0, 0, NULL); + 0, NULL); } return cow_file_range(inode, locked_page, start, end, page_started, @@ -3325,7 +3325,7 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) !test_bit(BTRFS_ORDERED_TRUNCATED, &ordered_extent->flags)) clear_extent_bit(&inode->io_tree, start, end, EXTENT_DELALLOC_NEW | EXTENT_ADD_INODE_BYTES, - 0, 0, &cached_state); + 0, &cached_state); btrfs_inode_safe_disk_i_size_write(inode, 0); ret = btrfs_update_inode_fallback(trans, root, inode); @@ -3335,8 +3335,7 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) } ret = 0; out: - clear_extent_bit(&inode->io_tree, start, end, clear_bits, - (clear_bits & EXTENT_LOCKED) ? 1 : 0, 0, + clear_extent_bit(&inode->io_tree, start, end, clear_bits, 0, &cached_state); if (trans) @@ -4937,7 +4936,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, clear_extent_bit(&inode->io_tree, block_start, block_end, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, - 0, 0, &cached_state); + 0, &cached_state); ret = btrfs_set_extent_delalloc(inode, block_start, block_end, 0, &cached_state); @@ -5353,7 +5352,7 @@ static void evict_inode_truncate_pages(struct inode *inode) clear_extent_bit(io_tree, start, end, EXTENT_LOCKED | EXTENT_DELALLOC | - EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 1, 1, + EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 1, &cached_state); cond_resched(); @@ -8442,7 +8441,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, clear_extent_bit(tree, cur, range_end, EXTENT_DELALLOC | EXTENT_LOCKED | EXTENT_DO_ACCOUNTING | - EXTENT_DEFRAG, 1, 0, &cached_state); + EXTENT_DEFRAG, 0, &cached_state); spin_lock_irq(&inode->ordered_tree.lock); set_bit(BTRFS_ORDERED_TRUNCATED, &ordered->flags); @@ -8488,7 +8487,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, if (!inode_evicting) { clear_extent_bit(tree, cur, range_end, EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_UPTODATE | - EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 1, + EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, delete_states, &cached_state); } cur = range_end + 1; @@ -8624,7 +8623,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) */ clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, end, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | - EXTENT_DEFRAG, 0, 0, &cached_state); + EXTENT_DEFRAG, 0, &cached_state); ret2 = btrfs_set_extent_delalloc(BTRFS_I(inode), page_start, end, 0, &cached_state); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index fe0cc816b4eb..274ad3e23190 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1616,7 +1616,7 @@ static int defrag_one_locked_target(struct btrfs_inode *inode, return ret; clear_extent_bit(&inode->io_tree, start, start + len - 1, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | - EXTENT_DEFRAG, 0, 0, cached_state); + EXTENT_DEFRAG, 0, cached_state); set_extent_defrag(&inode->io_tree, start, start + len - 1, cached_state); /* Update the page status */ diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c index 9acf47b11fe6..39556ce1b551 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -92,7 +92,7 @@ static int copy_inline_to_page(struct btrfs_inode *inode, clear_extent_bit(&inode->io_tree, file_offset, range_end, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, - 0, 0, NULL); + 0, NULL); ret = btrfs_set_extent_delalloc(inode, file_offset, range_end, 0, NULL); if (ret) goto out_unlock; diff --git a/fs/btrfs/tests/inode-tests.c b/fs/btrfs/tests/inode-tests.c index cac89c388131..eeba3deb7714 100644 --- a/fs/btrfs/tests/inode-tests.c +++ b/fs/btrfs/tests/inode-tests.c @@ -975,7 +975,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) BTRFS_MAX_EXTENT_SIZE >> 1, (BTRFS_MAX_EXTENT_SIZE >> 1) + sectorsize - 1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, 0, NULL); + EXTENT_UPTODATE, 0, NULL); if (ret) { test_err("clear_extent_bit returned %d", ret); goto out; @@ -1043,7 +1043,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) BTRFS_MAX_EXTENT_SIZE + sectorsize, BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, 0, NULL); + EXTENT_UPTODATE, 0, NULL); if (ret) { test_err("clear_extent_bit returned %d", ret); goto out; @@ -1076,7 +1076,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) /* Empty */ ret = clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, 0, NULL); + EXTENT_UPTODATE, 0, NULL); if (ret) { test_err("clear_extent_bit returned %d", ret); goto out; @@ -1092,7 +1092,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) if (ret) clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, 0, NULL); + EXTENT_UPTODATE, 0, NULL); iput(inode); btrfs_free_dummy_root(root); btrfs_free_dummy_fs_info(fs_info); diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index d9e608935e64..b371f9f5444e 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1116,7 +1116,7 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info, * it's safe to do it (through extent_io_tree_release()). */ err = clear_extent_bit(dirty_pages, start, end, - EXTENT_NEED_WAIT, 0, 0, &cached_state); + EXTENT_NEED_WAIT, 0, &cached_state); if (err == -ENOMEM) err = 0; if (!err) From patchwork Fri Sep 2 20:16:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA878C6FA83 for ; Fri, 2 Sep 2022 20:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230080AbiIBUR2 (ORCPT ); Fri, 2 Sep 2022 16:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbiIBURU (ORCPT ); Fri, 2 Sep 2022 16:17:20 -0400 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA679C889B for ; Fri, 2 Sep 2022 13:17:19 -0700 (PDT) Received: by mail-qt1-x82e.google.com with SMTP id cr9so2326067qtb.13 for ; Fri, 02 Sep 2022 13:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=77a0jGVseOmBdoEHB7/ojV0KwN3p8J4wJ8xeAfmxpu8=; b=FQw+ZQNR3ZZsPbFaJZNVG8EfpuqeLcyZkgeeh2Tki4o9schBfRE9kLig7ZQLnDLDw4 8pMXhdC3cCGbiPptNsOnu338bnVVG1yVp4q2gmaneNJdl8dB9hoG2ZA1HP0lswXeE1tb qaKfy94mx2Kefkp/3QBDtjmqTwU9OCqKsL854xqItp9/TfRLLuxqbvYQnlTqw1LeJsxz wqeKFEQ4oi6FxhNMfuUkWVXQ1kffuPB7eBluAY0A4p5mY2tldcnIuhZkrFJSbjipi0nO bfSpvhSjw7inHXmhf/NMmkpA6KlCwzJxwhJx0UYoE/jq/X2cLceVeaayF08UPjDQzmS5 eVQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=77a0jGVseOmBdoEHB7/ojV0KwN3p8J4wJ8xeAfmxpu8=; b=UdvP843kqv2GZqd4S/rEHPrDL9wg+VTdufw8uKrBruFtzrPyHPIUr3T87FrEneUl9U YmgBpbnjt8dwga502kCdshr4HjvckWBvzAWEyHrbLnopczhnHbS3d29PY5aM6PxQSx8+ EUP5WePoAvNX1UQoTjipo25wAW3nO6xTO0nOBUP7gA42zz026Fbgg0Tuq0dtMQJT/qlw kRAXeULSCACT4suLR7kRey+2tQo9ezFK+DBReNCWuMVN8jekgF0cbkRnxx7AKUpooY0+ 2NxVfaz9ykRksh9kUUNRnieUQRN1oYxFJp8PyqYzLAwN3xPDCfKRRkkzxS553GK1EzWo gkSA== X-Gm-Message-State: ACgBeo1kmgyFL+gj3NPFjwALANROGIBFvyCbMd+TchLYsH0nsQaiSeNO 3F4o+EUu7fLfp7cOnZwfKxomYWWbt/zV6w== X-Google-Smtp-Source: AA6agR4GVxtST/9vgrUUk8D6akwv3laxCjt9KZ19jrLZIJXuQUx8+ImPGu0gNtVkkR+YoY5MGtOPUg== X-Received: by 2002:a05:622a:18e:b0:342:f7a9:a133 with SMTP id s14-20020a05622a018e00b00342f7a9a133mr30261955qtw.402.1662149838529; Fri, 02 Sep 2022 13:17:18 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id o1-20020ac84281000000b0033c36ef019esm1673463qtl.63.2022.09.02.13.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:18 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 23/31] btrfs: remove failed_start argument from set_extent_bit Date: Fri, 2 Sep 2022 16:16:28 -0400 Message-Id: <529dfc42ce5fab69dcc3cc8ed6806b5510d0cf1d.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is only used for internal locking related helpers, everybody else just passes in NULL. I've changed set_extent_bit to __set_extent_bit and made it static, removed failed_start from set_extent_bit and have it call __set_extent_bit with a NULL failed_start, and I've moved some code down below the now static __set_extent_bit. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 110 ++++++++++++++++++++------------------ fs/btrfs/extent-io-tree.h | 22 ++++---- fs/btrfs/inode.c | 4 +- 3 files changed, 70 insertions(+), 66 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index f486e70b444b..9440879862c8 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -187,51 +187,6 @@ static int add_extent_changeset(struct extent_state *state, u32 bits, return ret; } -/* wrappers around set/clear extent bit */ -int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, struct extent_changeset *changeset) -{ - /* - * We don't support EXTENT_LOCKED yet, as current changeset will - * record any bits changed, so for EXTENT_LOCKED case, it will - * either fail with -EEXIST or changeset will record the whole - * range. - */ - ASSERT(!(bits & EXTENT_LOCKED)); - - return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOFS, - changeset); -} - -int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, struct extent_changeset *changeset) -{ - /* - * Don't support EXTENT_LOCKED case, same reason as - * set_record_extent_bits(). - */ - ASSERT(!(bits & EXTENT_LOCKED)); - - return __clear_extent_bit(tree, start, end, bits, 0, NULL, GFP_NOFS, - changeset); -} - -int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) -{ - int err; - u64 failed_start; - - err = set_extent_bit(tree, start, end, EXTENT_LOCKED, &failed_start, - NULL, GFP_NOFS, NULL); - if (err == -EEXIST) { - if (failed_start > start) - clear_extent_bit(tree, start, failed_start - 1, - EXTENT_LOCKED, 0, NULL); - return 0; - } - return 1; -} - static struct extent_state *next_state(struct extent_state *state) { struct rb_node *next = rb_next(&state->rb_node); @@ -839,9 +794,10 @@ static void cache_state(struct extent_state *state, * * [start, end] is inclusive This takes the tree lock. */ -int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, - u64 *failed_start, struct extent_state **cached_state, - gfp_t mask, struct extent_changeset *changeset) +static int __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, u64 *failed_start, + struct extent_state **cached_state, + struct extent_changeset *changeset, gfp_t mask) { struct extent_state *state; struct extent_state *prealloc = NULL; @@ -1054,6 +1010,14 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, } +int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, struct extent_state **cached_state, gfp_t mask, + struct extent_changeset *changeset) +{ + return __set_extent_bit(tree, start, end, bits, NULL, cached_state, + changeset, mask); +} + /** * convert_extent_bit - convert all bits in a given range from one bit to * another @@ -1278,9 +1242,8 @@ int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u64 failed_start; while (1) { - err = set_extent_bit(tree, start, end, EXTENT_LOCKED, - &failed_start, cached_state, GFP_NOFS, - NULL); + err = __set_extent_bit(tree, start, end, EXTENT_LOCKED, + &failed_start, cached_state, NULL, GFP_NOFS); if (err == -EEXIST) { wait_extent_bit(tree, failed_start, end, EXTENT_LOCKED); start = failed_start; @@ -1662,6 +1625,51 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, return bitset; } +/* wrappers around set/clear extent bit */ +int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, struct extent_changeset *changeset) +{ + /* + * We don't support EXTENT_LOCKED yet, as current changeset will + * record any bits changed, so for EXTENT_LOCKED case, it will + * either fail with -EEXIST or changeset will record the whole + * range. + */ + ASSERT(!(bits & EXTENT_LOCKED)); + + return __set_extent_bit(tree, start, end, bits, NULL, NULL, changeset, + GFP_NOFS); +} + +int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, + u32 bits, struct extent_changeset *changeset) +{ + /* + * Don't support EXTENT_LOCKED case, same reason as + * set_record_extent_bits(). + */ + ASSERT(!(bits & EXTENT_LOCKED)); + + return __clear_extent_bit(tree, start, end, bits, 0, NULL, GFP_NOFS, + changeset); +} + +int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) +{ + int err; + u64 failed_start; + + err = __set_extent_bit(tree, start, end, EXTENT_LOCKED, &failed_start, + NULL, NULL, GFP_NOFS); + if (err == -EEXIST) { + if (failed_start > start) + clear_extent_bit(tree, start, failed_start - 1, + EXTENT_LOCKED, 0, NULL); + return 0; + } + return 1; +} + void __cold extent_state_free_cachep(void) { btrfs_extent_state_leak_debug_check(); diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index bd3c345a7530..991bfa3a8391 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -160,22 +160,19 @@ static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start, int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, struct extent_changeset *changeset); int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, u64 *failed_start, - struct extent_state **cached_state, gfp_t mask, + u32 bits, struct extent_state **cached_state, gfp_t mask, struct extent_changeset *changeset); static inline int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOWAIT, - NULL); + return set_extent_bit(tree, start, end, bits, NULL, GFP_NOWAIT, NULL); } static inline int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOFS, - NULL); + return set_extent_bit(tree, start, end, bits, NULL, GFP_NOFS, NULL); } static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, @@ -188,8 +185,7 @@ static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, static inline int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask) { - return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL, NULL, mask, - NULL); + return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL, mask, NULL); } static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start, @@ -210,7 +206,7 @@ static inline int set_extent_delalloc(struct extent_io_tree *tree, u64 start, { return set_extent_bit(tree, start, end, EXTENT_DELALLOC | extra_bits, - NULL, cached_state, GFP_NOFS, NULL); + cached_state, GFP_NOFS, NULL); } static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start, @@ -218,20 +214,20 @@ static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start, { return set_extent_bit(tree, start, end, EXTENT_DELALLOC | EXTENT_DEFRAG, - NULL, cached_state, GFP_NOFS, NULL); + cached_state, GFP_NOFS, NULL); } static inline int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end) { - return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, NULL, - GFP_NOFS, NULL); + return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, GFP_NOFS, + NULL); } static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached_state, gfp_t mask) { - return set_extent_bit(tree, start, end, EXTENT_UPTODATE, NULL, + return set_extent_bit(tree, start, end, EXTENT_UPTODATE, cached_state, mask, NULL); } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 700e6aa4af4f..b82d220e9342 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2816,7 +2816,7 @@ static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode, ret = set_extent_bit(&inode->io_tree, search_start, search_start + em_len - 1, - EXTENT_DELALLOC_NEW, NULL, cached_state, + EXTENT_DELALLOC_NEW, cached_state, GFP_NOFS, NULL); next: search_start = extent_map_end(em); @@ -4963,7 +4963,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, if (only_release_metadata) set_extent_bit(&inode->io_tree, block_start, block_end, - EXTENT_NORESERVE, NULL, NULL, GFP_NOFS, NULL); + EXTENT_NORESERVE, NULL, GFP_NOFS, NULL); out_unlock: if (ret) { From patchwork Fri Sep 2 20:16:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964632 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF8A1ECAAD5 for ; Fri, 2 Sep 2022 20:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbiIBUR3 (ORCPT ); Fri, 2 Sep 2022 16:17:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbiIBURW (ORCPT ); Fri, 2 Sep 2022 16:17:22 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB95C889B for ; Fri, 2 Sep 2022 13:17:21 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id h22so2370036qtu.2 for ; Fri, 02 Sep 2022 13:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=7C/sUqpz+4843Z2ZLxKhlnRqp1+eNYnlR5Hpb3YilQQ=; b=daELAF4KWM6snfoPMC1tIe2PuQbv2tjMwECkrSQjAkW8xEZGv0izIvgbBfLPYTHNSv pM/C+FwXyEEDKSiJku/mix6FQBs7OaGP72eaaRtN9d0nlE32PK2viCEoaBZvBo0f5Sdb Jz5sB4fcBYqSBjhfetGYvkRyhK2ET3KQMOQgpe+iD9V+9QoFRpKKsIkTaqQ4Fz9Vj4v9 ZTmJoAH6z063s5jA3vNO3eW0kgbIc2TkPrV335lONXHed9qUD7AOe3AXDiJUgRTO6dhW AkNwcH2rWXfqun+BkIYn5IZxPTy2NrBnSBlcgWIZEHFUYLiwHpSa7AIRVnxlJ5p+8CIf OrZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=7C/sUqpz+4843Z2ZLxKhlnRqp1+eNYnlR5Hpb3YilQQ=; b=Y8gDxpxB2AUdi5U7v4IwHM+b12cxaIdgv9u+ExcFIDRxtzIzHFn6KMyL5WIwHOUNlH c5JOy+6ediu+2PaUqLdeoZAVsmi3dA2DAgUY6RplWjMuSPhbFAuULFwGfAVJJY2IButr Cco9sysy9JFTDKiouddGM+m9eXhIjjkxywJiv823t6Pwww54a//TXbhkXUCtEhSqaCuf FTH2DnKf5yEMLDGGdU6yAjATBu/EyhaBjaoZ5xl1ZpNjnPfIni4qSGIJyfZxJONqhgNa vJc/we89HhqvDuGFvnI9VCdbvugQppkMF8FeNMPP8ItHzDU7cEd0rjZEvdLOR81HkbTd xDng== X-Gm-Message-State: ACgBeo2aFcwHyz7MSCaHc5TLcyyXVXLhxI3Uu52jjpVcsrTPesZQonUC Z2XLDLW3HIx1YJ4wOA03c9J3BbuPIY4Vhg== X-Google-Smtp-Source: AA6agR6vKAzPPJSUrLaYeK/lH0e+FOT39G/VbKL41e150XgHjNK08jA41qAQF+A/39tsjzVe7+80eQ== X-Received: by 2002:a05:622a:15c3:b0:344:7c48:bfb2 with SMTP id d3-20020a05622a15c300b003447c48bfb2mr29883697qty.370.1662149840200; Fri, 02 Sep 2022 13:17:20 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id b22-20020ac86bd6000000b003447c4f5aa5sm1564947qtt.24.2022.09.02.13.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:19 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 24/31] btrfs: drop extent_changeset from set_extent_bit Date: Fri, 2 Sep 2022 16:16:29 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The only places that set extent_changeset is set_record_extent_bits, everywhere else sets it to NULL. Drop this argument from set_extent_bit. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 5 ++--- fs/btrfs/extent-io-tree.h | 18 ++++++++---------- fs/btrfs/inode.c | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 9440879862c8..7786f603d097 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -1011,11 +1011,10 @@ static int __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, } int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, struct extent_state **cached_state, gfp_t mask, - struct extent_changeset *changeset) + u32 bits, struct extent_state **cached_state, gfp_t mask) { return __set_extent_bit(tree, start, end, bits, NULL, cached_state, - changeset, mask); + NULL, mask); } /** diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 991bfa3a8391..113727a1c8d1 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -160,19 +160,18 @@ static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start, int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, struct extent_changeset *changeset); int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, struct extent_state **cached_state, gfp_t mask, - struct extent_changeset *changeset); + u32 bits, struct extent_state **cached_state, gfp_t mask); static inline int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - return set_extent_bit(tree, start, end, bits, NULL, GFP_NOWAIT, NULL); + return set_extent_bit(tree, start, end, bits, NULL, GFP_NOWAIT); } static inline int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - return set_extent_bit(tree, start, end, bits, NULL, GFP_NOFS, NULL); + return set_extent_bit(tree, start, end, bits, NULL, GFP_NOFS); } static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, @@ -185,7 +184,7 @@ static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, static inline int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask) { - return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL, mask, NULL); + return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL, mask); } static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start, @@ -206,7 +205,7 @@ static inline int set_extent_delalloc(struct extent_io_tree *tree, u64 start, { return set_extent_bit(tree, start, end, EXTENT_DELALLOC | extra_bits, - cached_state, GFP_NOFS, NULL); + cached_state, GFP_NOFS); } static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start, @@ -214,21 +213,20 @@ static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start, { return set_extent_bit(tree, start, end, EXTENT_DELALLOC | EXTENT_DEFRAG, - cached_state, GFP_NOFS, NULL); + cached_state, GFP_NOFS); } static inline int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end) { - return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, GFP_NOFS, - NULL); + return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, GFP_NOFS); } static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached_state, gfp_t mask) { return set_extent_bit(tree, start, end, EXTENT_UPTODATE, - cached_state, mask, NULL); + cached_state, mask); } int find_first_extent_bit(struct extent_io_tree *tree, u64 start, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b82d220e9342..e0c0923e5956 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2817,7 +2817,7 @@ static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode, ret = set_extent_bit(&inode->io_tree, search_start, search_start + em_len - 1, EXTENT_DELALLOC_NEW, cached_state, - GFP_NOFS, NULL); + GFP_NOFS); next: search_start = extent_map_end(em); free_extent_map(em); @@ -4963,7 +4963,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, if (only_release_metadata) set_extent_bit(&inode->io_tree, block_start, block_end, - EXTENT_NORESERVE, NULL, GFP_NOFS, NULL); + EXTENT_NORESERVE, NULL, GFP_NOFS); out_unlock: if (ret) { From patchwork Fri Sep 2 20:16:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1571C6FA83 for ; Fri, 2 Sep 2022 20:17:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbiIBURc (ORCPT ); Fri, 2 Sep 2022 16:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230103AbiIBUR0 (ORCPT ); Fri, 2 Sep 2022 16:17:26 -0400 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32D1D3EEB for ; Fri, 2 Sep 2022 13:17:23 -0700 (PDT) Received: by mail-qv1-xf34.google.com with SMTP id jy14so2251142qvb.12 for ; Fri, 02 Sep 2022 13:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=OCJgGdSef0ZxqnxK2cS/6kCzHmYkeyDYXevxxof/HZk=; b=4Uc8FyGjyanvpTN/jm7K3Ji8DIQeA8t75PUHrIip2TCAKk5WD0Np7XjHOpbrPpDg0S 3GZ8JrMIv/GNV9AhcKOZknwC96ISWD6dcp7nvly34pLKzzdX6sLX6jLBWJtOoPR9Wse8 Dctxn1AzgmNuhSg/saAydOI093SkczukacyplWVvPpdtlby1EmVHWONbKy2sCAzpsNqM 6i6UiEydHSlY14qe52O58f2aTpIjRABkZuBe4bQvENeDgtMo8CRc+KeAce6vsrHRhY0J XTVWYDHZIHZs2/U35i5+koKZtBRF9Hk9FPI9aAsqEhPNmRLvNYyYs0iok7HnPPHFhgHW gpBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=OCJgGdSef0ZxqnxK2cS/6kCzHmYkeyDYXevxxof/HZk=; b=s2AAi8nkmHOJYPOjpaRe89bBPRbDY/lkO9F0hraJhUGl0OtbL634Js6DUKCX2QciuK 5xKBHtXR7qfKGyMvFp8IzoqFUrc5zY6fL4PFA2bCFVhEsN0ms2PbDPVDIO76iyAphpEm wz3iOPzJqKlxhQAwrWxhDAops6eARbpmzF+3M8hO4e6R9n9Hv51id5dHOonqGRs9YiGq VU7S7QmcZrxqhKgWgTRWCoSErvk1dgJeO2XJKzI1Z+iWJizBkSAe/QdQXM/t9fNWCM1h eiqpxSWOM3qQ/LJFcZFeCwN4ssrYDBkxNRqd3Hi5dabaKbc/pvz6src73ih6cs7A4OJ/ Cv0w== X-Gm-Message-State: ACgBeo1kdlINV01DYikaSf1rmML+a1mhLI4I7uL641klF8o9CgSmetbf okxmJ0MngNpn5WVbFCR5tTD3TCYym3n+iw== X-Google-Smtp-Source: AA6agR6c4/6N4OKY4aP5IcaA8/RjA+/qf4AFs8M6s21ekz7XA3PlGZebsTS2Xm1QHuzAnESewDBOnw== X-Received: by 2002:a0c:a907:0:b0:496:cf4f:2426 with SMTP id y7-20020a0ca907000000b00496cf4f2426mr29389975qva.119.1662149842281; Fri, 02 Sep 2022 13:17:22 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id l5-20020ac81485000000b0031f41ea94easm1547082qtj.28.2022.09.02.13.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:21 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 25/31] btrfs: unify the lock/unlock extent variants Date: Fri, 2 Sep 2022 16:16:30 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have two variants of lock/unlock extent, one set that takes a cached state, another that does not. This is slightly annoying, and generally speaking there are only a few places where we don't have a cached state. Simplify this by making lock_extent/unlock_extent the only variant and make it take a cached state, then convert all the callers appropriately. Signed-off-by: Josef Bacik --- fs/btrfs/compression.c | 6 +- fs/btrfs/disk-io.c | 7 +-- fs/btrfs/extent-io-tree.c | 4 +- fs/btrfs/extent-io-tree.h | 22 ++----- fs/btrfs/extent_io.c | 40 ++++++------- fs/btrfs/file.c | 46 +++++++-------- fs/btrfs/free-space-cache.c | 16 +++--- fs/btrfs/inode.c | 98 +++++++++++++++----------------- fs/btrfs/ioctl.c | 22 +++---- fs/btrfs/ordered-data.c | 4 +- fs/btrfs/reflink.c | 8 +-- fs/btrfs/relocation.c | 18 +++--- fs/btrfs/tests/extent-io-tests.c | 6 +- fs/btrfs/tree-log.c | 8 +-- 14 files changed, 142 insertions(+), 163 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index cac0eeceb815..54caa00a2245 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -588,7 +588,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, } page_end = (pg_index << PAGE_SHIFT) + PAGE_SIZE - 1; - lock_extent(tree, cur, page_end); + lock_extent(tree, cur, page_end, NULL); read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, cur, page_end + 1 - cur); read_unlock(&em_tree->lock); @@ -602,7 +602,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, (cur + fs_info->sectorsize > extent_map_end(em)) || (em->block_start >> 9) != cb->orig_bio->bi_iter.bi_sector) { free_extent_map(em); - unlock_extent(tree, cur, page_end); + unlock_extent(tree, cur, page_end, NULL); unlock_page(page); put_page(page); break; @@ -622,7 +622,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, add_size = min(em->start + em->len, page_end + 1) - cur; ret = bio_add_page(cb->orig_bio, page, add_size, offset_in_page(cur)); if (ret != add_size) { - unlock_extent(tree, cur, page_end); + unlock_extent(tree, cur, page_end, NULL); unlock_page(page); put_page(page); break; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index c598f8d57c27..6ec87bed8194 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -131,8 +131,7 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, if (atomic) return -EAGAIN; - lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1, - &cached_state); + lock_extent(io_tree, eb->start, eb->start + eb->len - 1, &cached_state); if (extent_buffer_uptodate(eb) && btrfs_header_generation(eb) == parent_transid) { ret = 0; @@ -145,8 +144,8 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, ret = 1; clear_extent_buffer_uptodate(eb); out: - unlock_extent_cached(io_tree, eb->start, eb->start + eb->len - 1, - &cached_state); + unlock_extent(io_tree, eb->start, eb->start + eb->len - 1, + &cached_state); return ret; } diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 7786f603d097..4fd0cac6564a 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -1234,8 +1234,8 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, * either insert or lock state struct between start and end use mask to tell * us if waiting is desired. */ -int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, - struct extent_state **cached_state) +int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, + struct extent_state **cached_state) { int err; u64 failed_start; diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 113727a1c8d1..aa0314f6802c 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -98,13 +98,8 @@ void extent_io_tree_init(struct btrfs_fs_info *fs_info, void *private_data); void extent_io_tree_release(struct extent_io_tree *tree); -int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, - struct extent_state **cached); - -static inline int lock_extent(struct extent_io_tree *tree, u64 start, u64 end) -{ - return lock_extent_bits(tree, start, end, NULL); -} +int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, + struct extent_state **cached); int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end); @@ -132,20 +127,15 @@ static inline int clear_extent_bit(struct extent_io_tree *tree, u64 start, GFP_NOFS, NULL); } -static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end) -{ - return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, NULL); -} - -static inline int unlock_extent_cached(struct extent_io_tree *tree, u64 start, - u64 end, struct extent_state **cached) +static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, + struct extent_state **cached) { return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached, GFP_NOFS, NULL); } -static inline int unlock_extent_cached_atomic(struct extent_io_tree *tree, - u64 start, u64 end, struct extent_state **cached) +static inline int unlock_extent_atomic(struct extent_io_tree *tree, u64 start, + u64 end, struct extent_state **cached) { return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached, GFP_ATOMIC, NULL); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 66d3fefa8bee..92244f3370b8 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -463,14 +463,14 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, } /* step three, lock the state bits for the whole range */ - lock_extent_bits(tree, delalloc_start, delalloc_end, &cached_state); + lock_extent(tree, delalloc_start, delalloc_end, &cached_state); /* then test to make sure it is all still delalloc */ ret = test_range_bit(tree, delalloc_start, delalloc_end, EXTENT_DELALLOC, 1, cached_state); if (!ret) { - unlock_extent_cached(tree, delalloc_start, delalloc_end, - &cached_state); + unlock_extent(tree, delalloc_start, delalloc_end, + &cached_state); __unlock_for_delalloc(inode, locked_page, delalloc_start, delalloc_end); cond_resched(); @@ -914,8 +914,8 @@ static void end_sector_io(struct page *page, u64 offset, bool uptodate) if (uptodate) set_extent_uptodate(&inode->io_tree, offset, offset + sectorsize - 1, &cached, GFP_ATOMIC); - unlock_extent_cached_atomic(&inode->io_tree, offset, - offset + sectorsize - 1, &cached); + unlock_extent_atomic(&inode->io_tree, offset, offset + sectorsize - 1, + &cached); } static void submit_data_read_repair(struct inode *inode, @@ -1119,8 +1119,7 @@ static void endio_readpage_release_extent(struct processed_extent *processed, * Now we don't have range contiguous to the processed range, release * the processed range now. */ - unlock_extent_cached_atomic(tree, processed->start, processed->end, - &cached); + unlock_extent_atomic(tree, processed->start, processed->end, &cached); update: /* Update processed to current range */ @@ -1762,7 +1761,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, ret = set_page_extent_mapped(page); if (ret < 0) { - unlock_extent(tree, start, end); + unlock_extent(tree, start, end, NULL); btrfs_page_set_error(fs_info, page, start, PAGE_SIZE); unlock_page(page); goto out; @@ -1790,15 +1789,14 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, memzero_page(page, pg_offset, iosize); set_extent_uptodate(tree, cur, cur + iosize - 1, &cached, GFP_NOFS); - unlock_extent_cached(tree, cur, - cur + iosize - 1, &cached); + unlock_extent(tree, cur, cur + iosize - 1, &cached); end_page_read(page, true, cur, iosize); break; } em = __get_extent_map(inode, page, pg_offset, cur, end - cur + 1, em_cached); if (IS_ERR(em)) { - unlock_extent(tree, cur, end); + unlock_extent(tree, cur, end, NULL); end_page_read(page, false, cur, end + 1 - cur); ret = PTR_ERR(em); break; @@ -1873,8 +1871,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, set_extent_uptodate(tree, cur, cur + iosize - 1, &cached, GFP_NOFS); - unlock_extent_cached(tree, cur, - cur + iosize - 1, &cached); + unlock_extent(tree, cur, cur + iosize - 1, &cached); end_page_read(page, true, cur, iosize); cur = cur + iosize; pg_offset += iosize; @@ -1882,7 +1879,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, } /* the get_extent function already copied into the page */ if (block_start == EXTENT_MAP_INLINE) { - unlock_extent(tree, cur, cur + iosize - 1); + unlock_extent(tree, cur, cur + iosize - 1, NULL); end_page_read(page, true, cur, iosize); cur = cur + iosize; pg_offset += iosize; @@ -1898,7 +1895,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, * We have to unlock the remaining range, or the page * will never be unlocked. */ - unlock_extent(tree, cur, end); + unlock_extent(tree, cur, end, NULL); end_page_read(page, false, cur, end + 1 - cur); goto out; } @@ -3365,7 +3362,7 @@ int extent_invalidate_folio(struct extent_io_tree *tree, if (start > end) return 0; - lock_extent_bits(tree, start, end, &cached_state); + lock_extent(tree, start, end, &cached_state); folio_wait_writeback(folio); /* @@ -3373,7 +3370,7 @@ int extent_invalidate_folio(struct extent_io_tree *tree, * so here we only need to unlock the extent range to free any * existing extent state. */ - unlock_extent_cached(tree, start, end, &cached_state); + unlock_extent(tree, start, end, &cached_state); return 0; } @@ -3738,7 +3735,7 @@ int extent_fiemap(struct btrfs_inode *inode, struct fiemap_extent_info *fieinfo, last_for_get_extent = isize; } - lock_extent_bits(&inode->io_tree, start, start + len - 1, + lock_extent(&inode->io_tree, start, start + len - 1, &cached_state); em = get_extent_skip_holes(inode, start, last_for_get_extent); @@ -3851,8 +3848,7 @@ int extent_fiemap(struct btrfs_inode *inode, struct fiemap_extent_info *fieinfo, ret = emit_last_fiemap_cache(fieinfo, &cache); free_extent_map(em); out: - unlock_extent_cached(&inode->io_tree, start, start + len - 1, - &cached_state); + unlock_extent(&inode->io_tree, start, start + len - 1, &cached_state); out_free_ulist: btrfs_free_path(path); @@ -4695,7 +4691,7 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait, if (!try_lock_extent(io_tree, eb->start, eb->start + eb->len - 1)) return -EAGAIN; } else { - ret = lock_extent(io_tree, eb->start, eb->start + eb->len - 1); + ret = lock_extent(io_tree, eb->start, eb->start + eb->len - 1, NULL); if (ret < 0) return ret; } @@ -4705,7 +4701,7 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait, PageUptodate(page) || btrfs_subpage_test_uptodate(fs_info, page, eb->start, eb->len)) { set_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags); - unlock_extent(io_tree, eb->start, eb->start + eb->len - 1); + unlock_extent(io_tree, eb->start, eb->start + eb->len - 1, NULL); return ret; } diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 3a7fc25eb50d..b42ce1e16be8 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1426,15 +1426,14 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages, if (start_pos < inode->vfs_inode.i_size) { struct btrfs_ordered_extent *ordered; - lock_extent_bits(&inode->io_tree, start_pos, last_pos, - cached_state); + lock_extent(&inode->io_tree, start_pos, last_pos, cached_state); ordered = btrfs_lookup_ordered_range(inode, start_pos, last_pos - start_pos + 1); if (ordered && ordered->file_offset + ordered->num_bytes > start_pos && ordered->file_offset <= last_pos) { - unlock_extent_cached(&inode->io_tree, start_pos, - last_pos, cached_state); + unlock_extent(&inode->io_tree, start_pos, last_pos, + cached_state); for (i = 0; i < num_pages; i++) { unlock_page(pages[i]); put_page(pages[i]); @@ -1510,7 +1509,7 @@ int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos, *write_bytes = min_t(size_t, *write_bytes , num_bytes - pos + lockstart); } - unlock_extent(&inode->io_tree, lockstart, lockend); + unlock_extent(&inode->io_tree, lockstart, lockend, NULL); return ret; } @@ -1782,8 +1781,8 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, * possible cached extent state to avoid a memory leak. */ if (extents_locked) - unlock_extent_cached(&BTRFS_I(inode)->io_tree, - lockstart, lockend, &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, + lockend, &cached_state); else free_extent_state(cached_state); @@ -2592,8 +2591,8 @@ static void btrfs_punch_hole_lock_range(struct inode *inode, while (1) { truncate_pagecache_range(inode, lockstart, lockend); - lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend, - cached_state); + lock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend, + cached_state); /* * We can't have ordered extents in the range, nor dirty/writeback * pages, because we have locked the inode's VFS lock in exclusive @@ -2608,8 +2607,8 @@ static void btrfs_punch_hole_lock_range(struct inode *inode, page_lockend)) break; - unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, - lockend, cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend, + cached_state); } btrfs_assert_inode_range_clean(BTRFS_I(inode), lockstart, lockend); @@ -3109,8 +3108,8 @@ static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len) btrfs_end_transaction(trans); btrfs_btree_balance_dirty(fs_info); out: - unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend, - &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend, + &cached_state); out_only_mutex: if (!updated_inode && truncated_block && !ret) { /* @@ -3383,16 +3382,16 @@ static int btrfs_zero_range(struct inode *inode, ret = btrfs_qgroup_reserve_data(BTRFS_I(inode), &data_reserved, alloc_start, bytes_to_reserve); if (ret) { - unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, - lockend, &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, + lockend, &cached_state); goto out; } ret = btrfs_prealloc_file_range(inode, mode, alloc_start, alloc_end - alloc_start, i_blocksize(inode), offset + len, &alloc_hint); - unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, - lockend, &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend, + &cached_state); /* btrfs_prealloc_file_range releases reserved space on error */ if (ret) { space_reserved = false; @@ -3503,8 +3502,8 @@ static long btrfs_fallocate(struct file *file, int mode, } locked_end = alloc_end - 1; - lock_extent_bits(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, - &cached_state); + lock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, + &cached_state); btrfs_assert_inode_range_clean(BTRFS_I(inode), alloc_start, locked_end); @@ -3593,8 +3592,8 @@ static long btrfs_fallocate(struct file *file, int mode, */ ret = btrfs_fallocate_update_isize(inode, actual_end, mode); out_unlock: - unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, - &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, + &cached_state); out: btrfs_inode_unlock(inode, BTRFS_ILOCK_MMAP); extent_changeset_free(data_reserved); @@ -3630,7 +3629,7 @@ static loff_t find_desired_extent(struct btrfs_inode *inode, loff_t offset, lockend--; len = lockend - lockstart + 1; - lock_extent_bits(&inode->io_tree, lockstart, lockend, &cached_state); + lock_extent(&inode->io_tree, lockstart, lockend, &cached_state); while (start < i_size) { em = btrfs_get_extent_fiemap(inode, start, len); @@ -3655,8 +3654,7 @@ static loff_t find_desired_extent(struct btrfs_inode *inode, loff_t offset, cond_resched(); } free_extent_map(em); - unlock_extent_cached(&inode->io_tree, lockstart, lockend, - &cached_state); + unlock_extent(&inode->io_tree, lockstart, lockend, &cached_state); if (ret) { offset = ret; } else { diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 0bd5b02966c0..ecef1ba816c3 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -348,7 +348,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, btrfs_i_size_write(inode, 0); truncate_pagecache(vfs_inode, 0); - lock_extent_bits(&inode->io_tree, 0, (u64)-1, &cached_state); + lock_extent(&inode->io_tree, 0, (u64)-1, &cached_state); btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); /* @@ -360,7 +360,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, inode_sub_bytes(&inode->vfs_inode, control.sub_bytes); btrfs_inode_safe_disk_i_size_write(inode, control.last_size); - unlock_extent_cached(&inode->io_tree, 0, (u64)-1, &cached_state); + unlock_extent(&inode->io_tree, 0, (u64)-1, &cached_state); if (ret) goto fail; @@ -1292,8 +1292,8 @@ cleanup_write_cache_enospc(struct inode *inode, struct extent_state **cached_state) { io_ctl_drop_pages(io_ctl); - unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, - i_size_read(inode) - 1, cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, + cached_state); } static int __btrfs_wait_cache_io(struct btrfs_root *root, @@ -1418,8 +1418,8 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, if (ret) goto out_unlock; - lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, - &cached_state); + lock_extent(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, + &cached_state); io_ctl_set_generation(io_ctl, trans->transid); @@ -1474,8 +1474,8 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, io_ctl_drop_pages(io_ctl); io_ctl_free(io_ctl); - unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, - i_size_read(inode) - 1, &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, + &cached_state); /* * at this point the pages are under IO and we're happy, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e0c0923e5956..39230a6435c7 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -977,7 +977,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, if (!(start >= locked_page_end || end <= locked_page_start)) locked_page = async_chunk->locked_page; } - lock_extent(io_tree, start, end); + lock_extent(io_tree, start, end, NULL); /* We have fall back to uncompressed write */ if (!async_extent->pages) @@ -1524,7 +1524,7 @@ static int cow_file_range_async(struct btrfs_inode *inode, unsigned nofs_flag; const blk_opf_t write_flags = wbc_to_write_flags(wbc); - unlock_extent(&inode->io_tree, start, end); + unlock_extent(&inode->io_tree, start, end, NULL); if (inode->flags & BTRFS_INODE_NOCOMPRESS && !btrfs_test_opt(fs_info, FORCE_COMPRESS)) { @@ -2549,7 +2549,7 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len, ASSERT(pre + post < len); - lock_extent(&inode->io_tree, start, start + len - 1); + lock_extent(&inode->io_tree, start, start + len - 1, NULL); write_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, start, len); if (!em) { @@ -2623,7 +2623,7 @@ static int split_zoned_em(struct btrfs_inode *inode, u64 start, u64 len, out_unlock: write_unlock(&em_tree->lock); - unlock_extent(&inode->io_tree, start, start + len - 1); + unlock_extent(&inode->io_tree, start, start + len - 1, NULL); out: free_extent_map(split_pre); free_extent_map(split_mid); @@ -2929,7 +2929,7 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) if (ret) goto out_page; - lock_extent_bits(&inode->io_tree, page_start, page_end, &cached_state); + lock_extent(&inode->io_tree, page_start, page_end, &cached_state); /* already ordered? We're done */ if (PageOrdered(page)) @@ -2937,8 +2937,8 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) ordered = btrfs_lookup_ordered_range(inode, page_start, PAGE_SIZE); if (ordered) { - unlock_extent_cached(&inode->io_tree, page_start, page_end, - &cached_state); + unlock_extent(&inode->io_tree, page_start, page_end, + &cached_state); unlock_page(page); btrfs_start_ordered_extent(ordered, 1); btrfs_put_ordered_extent(ordered); @@ -2964,8 +2964,7 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) if (free_delalloc_space) btrfs_delalloc_release_space(inode, data_reserved, page_start, PAGE_SIZE, true); - unlock_extent_cached(&inode->io_tree, page_start, page_end, - &cached_state); + unlock_extent(&inode->io_tree, page_start, page_end, &cached_state); out_page: if (ret) { /* @@ -3269,7 +3268,7 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) } clear_bits |= EXTENT_LOCKED; - lock_extent_bits(io_tree, start, end, &cached_state); + lock_extent(io_tree, start, end, &cached_state); if (freespace_inode) trans = btrfs_join_transaction_spacecache(root); @@ -4921,12 +4920,11 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, } wait_on_page_writeback(page); - lock_extent_bits(io_tree, block_start, block_end, &cached_state); + lock_extent(io_tree, block_start, block_end, &cached_state); ordered = btrfs_lookup_ordered_extent(inode, block_start); if (ordered) { - unlock_extent_cached(io_tree, block_start, block_end, - &cached_state); + unlock_extent(io_tree, block_start, block_end, &cached_state); unlock_page(page); put_page(page); btrfs_start_ordered_extent(ordered, 1); @@ -4941,8 +4939,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, ret = btrfs_set_extent_delalloc(inode, block_start, block_end, 0, &cached_state); if (ret) { - unlock_extent_cached(io_tree, block_start, block_end, - &cached_state); + unlock_extent(io_tree, block_start, block_end, &cached_state); goto out_unlock; } @@ -4959,7 +4956,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, btrfs_page_clear_checked(fs_info, page, block_start, block_end + 1 - block_start); btrfs_page_set_dirty(fs_info, page, block_start, block_end + 1 - block_start); - unlock_extent_cached(io_tree, block_start, block_end, &cached_state); + unlock_extent(io_tree, block_start, block_end, &cached_state); if (only_release_metadata) set_extent_bit(&inode->io_tree, block_start, block_end, @@ -5135,7 +5132,7 @@ int btrfs_cont_expand(struct btrfs_inode *inode, loff_t oldsize, loff_t size) break; } free_extent_map(em); - unlock_extent_cached(io_tree, hole_start, block_end - 1, &cached_state); + unlock_extent(io_tree, hole_start, block_end - 1, &cached_state); return err; } @@ -5269,7 +5266,7 @@ static int btrfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentr * While truncating the inode pages during eviction, we get the VFS * calling btrfs_invalidate_folio() against each folio of the inode. This * is slow because the calls to btrfs_invalidate_folio() result in a - * huge amount of calls to lock_extent_bits() and clear_extent_bit(), + * huge amount of calls to lock_extent() and clear_extent_bit(), * which keep merging and splitting extent_state structures over and over, * wasting lots of time. * @@ -5336,7 +5333,7 @@ static void evict_inode_truncate_pages(struct inode *inode) state_flags = state->state; spin_unlock(&io_tree->lock); - lock_extent_bits(io_tree, start, end, &cached_state); + lock_extent(io_tree, start, end, &cached_state); /* * If still has DELALLOC flag, the extent didn't reach disk, @@ -7399,7 +7396,7 @@ static int lock_extent_direct(struct inode *inode, u64 lockstart, u64 lockend, if (!try_lock_extent(io_tree, lockstart, lockend)) return -EAGAIN; } else { - lock_extent_bits(io_tree, lockstart, lockend, cached_state); + lock_extent(io_tree, lockstart, lockend, cached_state); } /* * We're concerned with the entire range that we're going to be @@ -7421,7 +7418,7 @@ static int lock_extent_direct(struct inode *inode, u64 lockstart, u64 lockend, lockstart, lockend))) break; - unlock_extent_cached(io_tree, lockstart, lockend, cached_state); + unlock_extent(io_tree, lockstart, lockend, cached_state); if (ordered) { if (nowait) { @@ -7879,8 +7876,8 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, } if (unlock_extents) - unlock_extent_cached(&BTRFS_I(inode)->io_tree, - lockstart, lockend, &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend, + &cached_state); else free_extent_state(cached_state); @@ -7909,8 +7906,8 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, return 0; unlock_err: - unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend, - &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend, + &cached_state); err: if (dio_data->data_space_reserved) { btrfs_free_reserved_data_space(BTRFS_I(inode), @@ -7933,7 +7930,8 @@ static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length, if (!write && (iomap->type == IOMAP_HOLE)) { /* If reading from a hole, unlock and return */ - unlock_extent(&BTRFS_I(inode)->io_tree, pos, pos + length - 1); + unlock_extent(&BTRFS_I(inode)->io_tree, pos, pos + length - 1, + NULL); return 0; } @@ -7945,7 +7943,7 @@ static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length, pos, length, false); else unlock_extent(&BTRFS_I(inode)->io_tree, pos, - pos + length - 1); + pos + length - 1, NULL); ret = -ENOTBLK; } @@ -7970,7 +7968,7 @@ static void btrfs_dio_private_put(struct btrfs_dio_private *dip) } else { unlock_extent(&BTRFS_I(dip->inode)->io_tree, dip->file_offset, - dip->file_offset + dip->bytes - 1); + dip->file_offset + dip->bytes - 1, NULL); } kfree(dip->csums); @@ -8381,7 +8379,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, } if (!inode_evicting) - lock_extent_bits(tree, page_start, page_end, &cached_state); + lock_extent(tree, page_start, page_end, &cached_state); cur = page_start; while (cur < page_end) { @@ -8579,11 +8577,11 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) } wait_on_page_writeback(page); - lock_extent_bits(io_tree, page_start, page_end, &cached_state); + lock_extent(io_tree, page_start, page_end, &cached_state); ret2 = set_page_extent_mapped(page); if (ret2 < 0) { ret = vmf_error(ret2); - unlock_extent_cached(io_tree, page_start, page_end, &cached_state); + unlock_extent(io_tree, page_start, page_end, &cached_state); goto out_unlock; } @@ -8594,8 +8592,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) ordered = btrfs_lookup_ordered_range(BTRFS_I(inode), page_start, PAGE_SIZE); if (ordered) { - unlock_extent_cached(io_tree, page_start, page_end, - &cached_state); + unlock_extent(io_tree, page_start, page_end, &cached_state); unlock_page(page); up_read(&BTRFS_I(inode)->i_mmap_lock); btrfs_start_ordered_extent(ordered, 1); @@ -8628,8 +8625,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) ret2 = btrfs_set_extent_delalloc(BTRFS_I(inode), page_start, end, 0, &cached_state); if (ret2) { - unlock_extent_cached(io_tree, page_start, page_end, - &cached_state); + unlock_extent(io_tree, page_start, page_end, &cached_state); ret = VM_FAULT_SIGBUS; goto out_unlock; } @@ -8649,7 +8645,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) btrfs_set_inode_last_sub_trans(BTRFS_I(inode)); - unlock_extent_cached(io_tree, page_start, page_end, &cached_state); + unlock_extent(io_tree, page_start, page_end, &cached_state); up_read(&BTRFS_I(inode)->i_mmap_lock); btrfs_delalloc_release_extents(BTRFS_I(inode), PAGE_SIZE); @@ -8750,7 +8746,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) const u64 lock_start = ALIGN_DOWN(new_size, fs_info->sectorsize); control.new_size = new_size; - lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, + lock_extent(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, &cached_state); /* * We want to drop from the next block forward in case this new @@ -8766,8 +8762,8 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) inode_sub_bytes(inode, control.sub_bytes); btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), control.last_size); - unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, - (u64)-1, &cached_state); + unlock_extent(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, + &cached_state); trans->block_rsv = &fs_info->trans_block_rsv; if (ret != -ENOSPC && ret != -EAGAIN) @@ -10346,7 +10342,7 @@ static ssize_t btrfs_encoded_read_inline( } read_extent_buffer(leaf, tmp, ptr, count); btrfs_release_path(path); - unlock_extent_cached(io_tree, start, lockend, cached_state); + unlock_extent(io_tree, start, lockend, cached_state); btrfs_inode_unlock(&inode->vfs_inode, BTRFS_ILOCK_SHARED); *unlocked = true; @@ -10549,7 +10545,7 @@ static ssize_t btrfs_encoded_read_regular(struct kiocb *iocb, if (ret) goto out; - unlock_extent_cached(io_tree, start, lockend, cached_state); + unlock_extent(io_tree, start, lockend, cached_state); btrfs_inode_unlock(&inode->vfs_inode, BTRFS_ILOCK_SHARED); *unlocked = true; @@ -10619,13 +10615,13 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, lockend - start + 1); if (ret) goto out_unlock_inode; - lock_extent_bits(io_tree, start, lockend, &cached_state); + lock_extent(io_tree, start, lockend, &cached_state); ordered = btrfs_lookup_ordered_range(inode, start, lockend - start + 1); if (!ordered) break; btrfs_put_ordered_extent(ordered); - unlock_extent_cached(io_tree, start, lockend, &cached_state); + unlock_extent(io_tree, start, lockend, &cached_state); cond_resched(); } @@ -10699,7 +10695,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, em = NULL; if (disk_bytenr == EXTENT_MAP_HOLE) { - unlock_extent_cached(io_tree, start, lockend, &cached_state); + unlock_extent(io_tree, start, lockend, &cached_state); btrfs_inode_unlock(&inode->vfs_inode, BTRFS_ILOCK_SHARED); unlocked = true; ret = iov_iter_zero(count, iter); @@ -10720,7 +10716,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, free_extent_map(em); out_unlock_extent: if (!unlocked) - unlock_extent_cached(io_tree, start, lockend, &cached_state); + unlock_extent(io_tree, start, lockend, &cached_state); out_unlock_inode: if (!unlocked) btrfs_inode_unlock(&inode->vfs_inode, BTRFS_ILOCK_SHARED); @@ -10858,14 +10854,14 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, end >> PAGE_SHIFT); if (ret) goto out_pages; - lock_extent_bits(io_tree, start, end, &cached_state); + lock_extent(io_tree, start, end, &cached_state); ordered = btrfs_lookup_ordered_range(inode, start, num_bytes); if (!ordered && !filemap_range_has_page(inode->vfs_inode.i_mapping, start, end)) break; if (ordered) btrfs_put_ordered_extent(ordered); - unlock_extent_cached(io_tree, start, end, &cached_state); + unlock_extent(io_tree, start, end, &cached_state); cond_resched(); } @@ -10927,7 +10923,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, if (start + encoded->len > inode->vfs_inode.i_size) i_size_write(&inode->vfs_inode, start + encoded->len); - unlock_extent_cached(io_tree, start, end, &cached_state); + unlock_extent(io_tree, start, end, &cached_state); btrfs_delalloc_release_extents(inode, num_bytes); @@ -10958,7 +10954,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, if (!extent_reserved) btrfs_free_reserved_data_space_noquota(fs_info, disk_num_bytes); out_unlock: - unlock_extent_cached(io_tree, start, end, &cached_state); + unlock_extent(io_tree, start, end, &cached_state); out_pages: for (i = 0; i < nr_pages; i++) { if (pages[i]) @@ -11199,7 +11195,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, isize = ALIGN_DOWN(inode->i_size, fs_info->sectorsize); - lock_extent_bits(io_tree, 0, isize - 1, &cached_state); + lock_extent(io_tree, 0, isize - 1, &cached_state); start = 0; while (start < isize) { u64 logical_block_start, physical_block_start; @@ -11336,7 +11332,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, if (!IS_ERR_OR_NULL(em)) free_extent_map(em); - unlock_extent_cached(io_tree, 0, isize - 1, &cached_state); + unlock_extent(io_tree, 0, isize - 1, &cached_state); if (ret) btrfs_swap_deactivate(file); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 274ad3e23190..d59e1f1b762e 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1218,10 +1218,10 @@ static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start, /* get the big lock and read metadata off disk */ if (!locked) - lock_extent_bits(io_tree, start, end, &cached); + lock_extent(io_tree, start, end, &cached); em = defrag_get_extent(BTRFS_I(inode), start, newer_than); if (!locked) - unlock_extent_cached(io_tree, start, end, &cached); + unlock_extent(io_tree, start, end, &cached); if (IS_ERR(em)) return NULL; @@ -1333,10 +1333,10 @@ static struct page *defrag_prepare_one_page(struct btrfs_inode *inode, while (1) { struct btrfs_ordered_extent *ordered; - lock_extent_bits(&inode->io_tree, page_start, page_end, &cached_state); + lock_extent(&inode->io_tree, page_start, page_end, &cached_state); ordered = btrfs_lookup_ordered_range(inode, page_start, PAGE_SIZE); - unlock_extent_cached(&inode->io_tree, page_start, page_end, - &cached_state); + unlock_extent(&inode->io_tree, page_start, page_end, + &cached_state); if (!ordered) break; @@ -1666,9 +1666,9 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len, wait_on_page_writeback(pages[i]); /* Lock the pages range */ - lock_extent_bits(&inode->io_tree, start_index << PAGE_SHIFT, - (last_index << PAGE_SHIFT) + PAGE_SIZE - 1, - &cached_state); + lock_extent(&inode->io_tree, start_index << PAGE_SHIFT, + (last_index << PAGE_SHIFT) + PAGE_SIZE - 1, + &cached_state); /* * Now we have a consistent view about the extent map, re-check * which range really needs to be defragged. @@ -1694,9 +1694,9 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len, kfree(entry); } unlock_extent: - unlock_extent_cached(&inode->io_tree, start_index << PAGE_SHIFT, - (last_index << PAGE_SHIFT) + PAGE_SIZE - 1, - &cached_state); + unlock_extent(&inode->io_tree, start_index << PAGE_SHIFT, + (last_index << PAGE_SHIFT) + PAGE_SIZE - 1, + &cached_state); free_pages: for (i = 0; i < nr_pages; i++) { if (pages[i]) { diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index eb24a6d20ff8..40a364c11178 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -1043,7 +1043,7 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start, cachedp = cached_state; while (1) { - lock_extent_bits(&inode->io_tree, start, end, cachedp); + lock_extent(&inode->io_tree, start, end, cachedp); ordered = btrfs_lookup_ordered_range(inode, start, end - start + 1); if (!ordered) { @@ -1056,7 +1056,7 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start, refcount_dec(&cache->refs); break; } - unlock_extent_cached(&inode->io_tree, start, end, cachedp); + unlock_extent(&inode->io_tree, start, end, cachedp); btrfs_start_ordered_extent(ordered, 1); btrfs_put_ordered_extent(ordered); } diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c index 39556ce1b551..7a0db71d683b 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -615,8 +615,8 @@ static int btrfs_clone(struct inode *src, struct inode *inode, static void btrfs_double_extent_unlock(struct inode *inode1, u64 loff1, struct inode *inode2, u64 loff2, u64 len) { - unlock_extent(&BTRFS_I(inode1)->io_tree, loff1, loff1 + len - 1); - unlock_extent(&BTRFS_I(inode2)->io_tree, loff2, loff2 + len - 1); + unlock_extent(&BTRFS_I(inode1)->io_tree, loff1, loff1 + len - 1, NULL); + unlock_extent(&BTRFS_I(inode2)->io_tree, loff2, loff2 + len - 1, NULL); } static void btrfs_double_extent_lock(struct inode *inode1, u64 loff1, @@ -634,8 +634,8 @@ static void btrfs_double_extent_lock(struct inode *inode1, u64 loff1, swap(range1_end, range2_end); } - lock_extent(&BTRFS_I(inode1)->io_tree, loff1, range1_end); - lock_extent(&BTRFS_I(inode2)->io_tree, loff2, range2_end); + lock_extent(&BTRFS_I(inode1)->io_tree, loff1, range1_end, NULL); + lock_extent(&BTRFS_I(inode2)->io_tree, loff2, range2_end, NULL); btrfs_assert_inode_range_clean(BTRFS_I(inode1), loff1, range1_end); btrfs_assert_inode_range_clean(BTRFS_I(inode2), loff2, range2_end); diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 45c02aba2492..d87020ae5810 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1127,7 +1127,7 @@ int replace_file_extents(struct btrfs_trans_handle *trans, btrfs_drop_extent_cache(BTRFS_I(inode), key.offset, end, 1); unlock_extent(&BTRFS_I(inode)->io_tree, - key.offset, end); + key.offset, end, NULL); } } @@ -1566,9 +1566,9 @@ static int invalidate_extent_cache(struct btrfs_root *root, } /* the lock_extent waits for read_folio to complete */ - lock_extent(&BTRFS_I(inode)->io_tree, start, end); + lock_extent(&BTRFS_I(inode)->io_tree, start, end, NULL); btrfs_drop_extent_cache(BTRFS_I(inode), start, end, 1); - unlock_extent(&BTRFS_I(inode)->io_tree, start, end); + unlock_extent(&BTRFS_I(inode)->io_tree, start, end, NULL); } return 0; } @@ -2869,13 +2869,13 @@ static noinline_for_stack int prealloc_file_extent_cluster( else end = cluster->end - offset; - lock_extent(&inode->io_tree, start, end); + lock_extent(&inode->io_tree, start, end, NULL); num_bytes = end + 1 - start; ret = btrfs_prealloc_file_range(&inode->vfs_inode, 0, start, num_bytes, num_bytes, end + 1, &alloc_hint); cur_offset = end + 1; - unlock_extent(&inode->io_tree, start, end); + unlock_extent(&inode->io_tree, start, end, NULL); if (ret) break; } @@ -2904,7 +2904,7 @@ static noinline_for_stack int setup_relocation_extent_mapping(struct inode *inod em->block_start = block_start; set_bit(EXTENT_FLAG_PINNED, &em->flags); - lock_extent(&BTRFS_I(inode)->io_tree, start, end); + lock_extent(&BTRFS_I(inode)->io_tree, start, end, NULL); while (1) { write_lock(&em_tree->lock); ret = add_extent_mapping(em_tree, em, 0); @@ -2915,7 +2915,7 @@ static noinline_for_stack int setup_relocation_extent_mapping(struct inode *inod } btrfs_drop_extent_cache(BTRFS_I(inode), start, end, 0); } - unlock_extent(&BTRFS_I(inode)->io_tree, start, end); + unlock_extent(&BTRFS_I(inode)->io_tree, start, end, NULL); return ret; } @@ -3006,7 +3006,7 @@ static int relocate_one_page(struct inode *inode, struct file_ra_state *ra, goto release_page; /* Mark the range delalloc and dirty for later writeback */ - lock_extent(&BTRFS_I(inode)->io_tree, clamped_start, clamped_end); + lock_extent(&BTRFS_I(inode)->io_tree, clamped_start, clamped_end, NULL); ret = btrfs_set_extent_delalloc(BTRFS_I(inode), clamped_start, clamped_end, 0, NULL); if (ret) { @@ -3039,7 +3039,7 @@ static int relocate_one_page(struct inode *inode, struct file_ra_state *ra, boundary_start, boundary_end, EXTENT_BOUNDARY); } - unlock_extent(&BTRFS_I(inode)->io_tree, clamped_start, clamped_end); + unlock_extent(&BTRFS_I(inode)->io_tree, clamped_start, clamped_end, NULL); btrfs_delalloc_release_extents(BTRFS_I(inode), clamped_len); cur += clamped_len; diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c index a232b15b8021..4c824b7f07dd 100644 --- a/fs/btrfs/tests/extent-io-tests.c +++ b/fs/btrfs/tests/extent-io-tests.c @@ -172,7 +172,7 @@ static int test_find_delalloc(u32 sectorsize) sectorsize - 1, start, end); goto out_bits; } - unlock_extent(tmp, start, end); + unlock_extent(tmp, start, end, NULL); unlock_page(locked_page); put_page(locked_page); @@ -208,7 +208,7 @@ static int test_find_delalloc(u32 sectorsize) test_err("there were unlocked pages in the range"); goto out_bits; } - unlock_extent(tmp, start, end); + unlock_extent(tmp, start, end, NULL); /* locked_page was unlocked above */ put_page(locked_page); @@ -263,7 +263,7 @@ static int test_find_delalloc(u32 sectorsize) test_err("pages in range were not all locked"); goto out_bits; } - unlock_extent(tmp, start, end); + unlock_extent(tmp, start, end, NULL); /* * Now to test where we run into a page that is no longer dirty in the diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 020e01ea44bc..b5018e42cf06 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4271,8 +4271,8 @@ static int log_csums(struct btrfs_trans_handle *trans, * file which happens to refer to the same extent as well. Such races * can leave checksum items in the log with overlapping ranges. */ - ret = lock_extent_bits(&log_root->log_csum_range, sums->bytenr, - lock_end, &cached_state); + ret = lock_extent(&log_root->log_csum_range, sums->bytenr, lock_end, + &cached_state); if (ret) return ret; /* @@ -4288,8 +4288,8 @@ static int log_csums(struct btrfs_trans_handle *trans, if (!ret) ret = btrfs_csum_file_blocks(trans, log_root, sums); - unlock_extent_cached(&log_root->log_csum_range, sums->bytenr, lock_end, - &cached_state); + unlock_extent(&log_root->log_csum_range, sums->bytenr, lock_end, + &cached_state); return ret; } From patchwork Fri Sep 2 20:16:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D965C6FA82 for ; Fri, 2 Sep 2022 20:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbiIBURa (ORCPT ); Fri, 2 Sep 2022 16:17:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230095AbiIBURZ (ORCPT ); Fri, 2 Sep 2022 16:17:25 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A78E7D275F for ; Fri, 2 Sep 2022 13:17:24 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id j17so2334402qtp.12 for ; Fri, 02 Sep 2022 13:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=wZ6OuK2NAfOCeUPYTZ/OlS83L37BSn6t4Gct7rDvXrs=; b=W+84fnggCxY8RQEeAvhBpXlAQcoDM1VnZUAxHfS8emxY6DifxdsvsPOJYelhEuJLtN FhkUjfZ5wnLWfGmPlFQJNzXy53D9r7VyZLQfwyrqKfbGp2VvVf0ae6csgsbVy+XekCgH VBcrGRmUXA7KJx89o+HP32k7rTSeFfprGADOG1ZFT4/sRya+SiVCDpPUbLZ9Yd42B6+i eoOmj/UjUO7T+M7Nc5lEdIISU4G19BioEh42zfDvMiMgYSKCvEq7y1zqGRFflvLHT31B dbBNaYgj0xz1SREXQrf9f4M67/d9WY+Nv+f3HSX1BSNpQjZrAcPOv20kAvVIexpLabAD vb7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=wZ6OuK2NAfOCeUPYTZ/OlS83L37BSn6t4Gct7rDvXrs=; b=J58em2ckq0e6nnV57bwjGZ3+GjO2rjH9lVVAgLwTQO1uB4du05jM9azDZ3Y+MzEp2h eBPkNOZhBpRZwqEzIrL0GwATTLGBP2vnYv1yHuNNAFu/DfL5/YTK6/qg1ERlWw64Kd7M l6DlhEL8ZSg6qWbEUwvl8RDiwSOts35zWbLWVrR/xRLJJuDk3vR99OfPgK9ypyCkdQ8G a+GzTTcWTziOhH+LcrK+Fu9yVj7mq/rSbd3ObSQBeMSnc8QrK49E2htn/JSfGZyKywmu qDOwIqilNWn3XSw3NAXBJaKV+BYM00/LhCXgDL8v7Di6RkKpJ3Wl8BtGFCrl7jjZ4hhR ZUGQ== X-Gm-Message-State: ACgBeo2yWQqmOi4lFKd6Tm3w8BSDOGnYQDgbj+pPqW0Whbs4PIlqi1fU EKbs8tkxM8RRF7VZbfaX3cIKf5BVWn/L9w== X-Google-Smtp-Source: AA6agR79pNTirA+30f7F6Mx58AbE9d0l1NHXX56vZsDqTRd3nrnKMz+x0eNcIcyYoWO3akTKnad9yw== X-Received: by 2002:a05:622a:14d1:b0:344:b14a:b22a with SMTP id u17-20020a05622a14d100b00344b14ab22amr28989471qtx.203.1662149843975; Fri, 02 Sep 2022 13:17:23 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id i11-20020a05620a248b00b006bb29d932e1sm2193407qkn.105.2022.09.02.13.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:23 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 26/31] btrfs: get rid of track_uptodate Date: Fri, 2 Sep 2022 16:16:31 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is no longer used anymore, remove it from the extent_io_tree. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 1 - fs/btrfs/extent-io-tree.h | 1 - fs/btrfs/inode.c | 1 - 3 files changed, 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 6ec87bed8194..af073af8131e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2232,7 +2232,6 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info) RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node); extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree, IO_TREE_BTREE_INODE_IO, inode); - BTRFS_I(inode)->io_tree.track_uptodate = false; extent_map_tree_init(&BTRFS_I(inode)->extent_tree); BTRFS_I(inode)->root = btrfs_grab_root(fs_info->tree_root); diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index aa0314f6802c..37543fb713bd 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -70,7 +70,6 @@ struct extent_io_tree { struct btrfs_fs_info *fs_info; void *private_data; u64 dirty_bytes; - bool track_uptodate; /* Who owns this io tree, should be one of IO_TREE_* */ u8 owner; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 39230a6435c7..b21387ea5e97 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8914,7 +8914,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) extent_io_tree_init(fs_info, &ei->file_extent_tree, IO_TREE_INODE_FILE_EXTENT, inode); ei->io_failure_tree = RB_ROOT; - ei->io_tree.track_uptodate = true; atomic_set(&ei->sync_writers, 0); mutex_init(&ei->log_mutex); btrfs_ordered_inode_tree_init(&ei->ordered_tree); From patchwork Fri Sep 2 20:16:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 912CDECAAD5 for ; Fri, 2 Sep 2022 20:17:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbiIBURd (ORCPT ); Fri, 2 Sep 2022 16:17:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230138AbiIBUR1 (ORCPT ); Fri, 2 Sep 2022 16:17:27 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F156CD8B3B for ; Fri, 2 Sep 2022 13:17:26 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id g14so2336345qto.11 for ; Fri, 02 Sep 2022 13:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=JTRNybFsiSQz3Xr2wvZbMDEPaSj35+GSU75Uv10Ntmw=; b=wUA2jDe22lNShmZlZg3kfPfb9i0dIkr7wHcTyKaAUUT5cMlbyYbQ1gUDApetZxBG90 5lO+Yp6zhBMju5JmQ6wX0DYTqkX0nC8fBRd9jDajpkRdyct3NWv807/vL53+Z3LYBH3p 4bX9SGlKTw77v/FfYmujjInUljRDPfe84iqWTxVAvCpZv0fFj1GBOPfWbvcVZofIzfDJ FRXvSiSf2D38vSe+uXdjFagp+eMHLAOGvWM91dUV3hz42wZIf6JxJVEt5ZivJBx7r9cc DyAoAu4F0Z0Lxmc8++Zf3MfIDjA+uqouXW72VDNt5dEelsXvaRwE89GzCNfqHbmjkEbT ZvDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=JTRNybFsiSQz3Xr2wvZbMDEPaSj35+GSU75Uv10Ntmw=; b=ugBopT0reCm1QzVO9xJb8azGDLKHs2JtiJrUmWLreloYjO98ntQJG8TtKdB8Tx1qDt 8HrDkGGjqENF7xg7bDH/B5W/2nLvRnWdQ/GXAKLnhxgEwzYCFsoXrYBDmDqyVBMcQWIA 3HjP6eyScvlSSPIRzdqa1vYFbOqgNzgaH2OOZXw6n4zh9eCayEccBrlK72vxVr4B+ULz BucxwGW6HbNFfOjbCXQ8KCvpiXg+l1YYpQhhYr5ZHIaXeRKhnxtAEjjNo31JsRUt033H ZcFPYUPNlMv9IwfeEVSevDOwYj3x+IoO0u5ZlO/EfkzLY/IVxsrnH5mgWwvd+C7XktVN EiOQ== X-Gm-Message-State: ACgBeo3tAp7ePBELy2CZmY7kRk1RtlbYGkiGRv56j1GiK3ZzBEVO9eMv 3WxxSSqYS9ZIdi9M+n1mvxcQinv093aDzQ== X-Google-Smtp-Source: AA6agR5wPXRt6FC4SAPw2M3fT/fLRqnwTB/wgEQdU0ScLbgjulWD7L9ufwqTzcMk6sWMw+bTB/C1Ng== X-Received: by 2002:ac8:5f8f:0:b0:342:fb0c:77d0 with SMTP id j15-20020ac85f8f000000b00342fb0c77d0mr29560350qta.93.1662149845624; Fri, 02 Sep 2022 13:17:25 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id i11-20020a05620a150b00b006af08c26774sm1980300qkk.47.2022.09.02.13.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:25 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 27/31] btrfs: get rid of ->dirty_bytes Date: Fri, 2 Sep 2022 16:16:32 -0400 Message-Id: <9e5e464b37fbc7973534375ff18b0fae9bf0365e.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This was used as an optimization for count_range_bits(EXTENT_DIRTY), but we no longer do that, thus nothing actually uses the ->dirty_bytes counter in the extent_io_tree. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 17 +---------------- fs/btrfs/extent-io-tree.h | 1 - 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 4fd0cac6564a..b4e70d4f243b 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -91,7 +91,6 @@ void extent_io_tree_init(struct btrfs_fs_info *fs_info, { tree->fs_info = fs_info; tree->state = RB_ROOT; - tree->dirty_bytes = 0; spin_lock_init(&tree->lock); tree->private_data = private_data; tree->owner = owner; @@ -486,12 +485,6 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree, u32 bits_to_clear = bits & ~EXTENT_CTLBITS; int ret; - if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { - u64 range = state->end - state->start + 1; - WARN_ON(range > tree->dirty_bytes); - tree->dirty_bytes -= range; - } - if (tree->private_data && is_data_inode(tree->private_data)) btrfs_clear_delalloc_extent(tree->private_data, state, bits); @@ -756,10 +749,6 @@ static void set_state_bits(struct extent_io_tree *tree, if (tree->private_data && is_data_inode(tree->private_data)) btrfs_set_delalloc_extent(tree->private_data, state, bits); - if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { - u64 range = state->end - state->start + 1; - tree->dirty_bytes += range; - } ret = add_extent_changeset(state, bits_to_set, changeset, 1); BUG_ON(ret < 0); state->state |= bits_to_set; @@ -1538,10 +1527,7 @@ u64 count_range_bits(struct extent_io_tree *tree, return 0; spin_lock(&tree->lock); - if (cur_start == 0 && bits == EXTENT_DIRTY) { - total_bytes = tree->dirty_bytes; - goto out; - } + /* * this search will find all the extents that end after * our range starts. @@ -1567,7 +1553,6 @@ u64 count_range_bits(struct extent_io_tree *tree, } state = next_state(state); } -out: spin_unlock(&tree->lock); return total_bytes; } diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 37543fb713bd..94574062eabe 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -69,7 +69,6 @@ struct extent_io_tree { struct rb_root state; struct btrfs_fs_info *fs_info; void *private_data; - u64 dirty_bytes; /* Who owns this io tree, should be one of IO_TREE_* */ u8 owner; From patchwork Fri Sep 2 20:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964636 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB768C6FA86 for ; Fri, 2 Sep 2022 20:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbiIBURf (ORCPT ); Fri, 2 Sep 2022 16:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbiIBUR3 (ORCPT ); Fri, 2 Sep 2022 16:17:29 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81DE4D7CD0 for ; Fri, 2 Sep 2022 13:17:28 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id h27so2596903qkk.9 for ; Fri, 02 Sep 2022 13:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=pJaO90J+KIVu2AkMg0BstJPyn9eCjvbtqQaAMqhFCZE=; b=D131+0kVpTQNSKLhk7pIlhCfai/FiKB3NemwVfSyiYrAN/oIdHmE6BCw9mqImC12Cf dMZsL8iYnKKXejUMOw5Cgnf3ZG5fC4gRCj7G63SzBdNO3IShpoDLX9dWZPA/Dimxy7Sv mcabVneZeSlE5CpAynFhBgutBTCv8Xns7VmUHzAJgfeR1LMJAa//YUbWmsisRLt1v5lU sNjS14Xa7sc2n6n3Pc4czIfq3ZhbNO+gxQpXwW7zy6WORZV8IIuiBqRiiktWc12540CO lyBWzBl+nn0x+Pbl5ssi/9y8wl3a5nDjbeNZX5KQLZZvsCVI7VGyDgf+kv7pYKrcln18 21Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=pJaO90J+KIVu2AkMg0BstJPyn9eCjvbtqQaAMqhFCZE=; b=0cYDUHwJG9FKRi+1x3sEqh+i8ase4K62aMeQrtp6/Uclp9Q1g6J0AcFDq2FuKqo3ct vG2FTZFlJGbcoEwaYkwg23vYvYBYQGqDb/IHjNl8VMbHigyxXKAnSdXpXVyCP84fTjxf VLII9lUrJTy2j6snEE5hmH1QQ0R25k0udjQI5anxNIoVWRYcACm5AT4nPxqHaeUUw/Zi 5kPAFLDGyE2KGx/PL7/ldcapqh15dpW6A5UlzTCOO4SqHCqvUOKg+6Mtm0tuWhUC0gxQ gDKDpPcaIoqPE7ePscNDSTj19U0S6DZrQUC9idHq+5nSTTonRoN62C3gtA9NNFZLzAcC LPsw== X-Gm-Message-State: ACgBeo1ezcuZfZnWJac3pLE3UChlLsuuW9NbUx+y6Zp/0aYOoQY0Lonm x3cM8cMBGOQmi4s6KsbVPbMtlx61yhsWfA== X-Google-Smtp-Source: AA6agR5x9iC6eAQR1IHiJZjL714xI5yS12PMRAgfUcNOhls8ikUj/yD6pmVUiVtQivfmx+5rc1UbsA== X-Received: by 2002:a05:620a:4587:b0:6bb:a6c6:14c5 with SMTP id bp7-20020a05620a458700b006bba6c614c5mr24004238qkb.362.1662149847292; Fri, 02 Sep 2022 13:17:27 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id x9-20020a05620a448900b006b5e296452csm2253378qkp.54.2022.09.02.13.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:26 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 28/31] btrfs: don't clear CTL bits when trying to release extent state Date: Fri, 2 Sep 2022 16:16:33 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When trying to release the extent states due to memory pressure we'll set all the bits except LOCKED, NODATASUM, and DELALLOC_NEW. This includes some of the CTL bits, which isn't really a problem but isn't correct either. Exclude the CTL bits from this clearing. Signed-off-by: Josef Bacik --- fs/btrfs/extent_io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 92244f3370b8..849ecccca53e 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3389,15 +3389,17 @@ static int try_release_extent_state(struct extent_io_tree *tree, if (test_range_bit(tree, start, end, EXTENT_LOCKED, 0, NULL)) { ret = 0; } else { + u32 clear_bits = ~(EXTENT_LOCKED | EXTENT_NODATASUM | + EXTENT_DELALLOC_NEW | EXTENT_CTLBITS); + /* * At this point we can safely clear everything except the * locked bit, the nodatasum bit and the delalloc new bit. * The delalloc new bit will be cleared by ordered extent * completion. */ - ret = __clear_extent_bit(tree, start, end, - ~(EXTENT_LOCKED | EXTENT_NODATASUM | EXTENT_DELALLOC_NEW), - 0, NULL, mask, NULL); + ret = __clear_extent_bit(tree, start, end, clear_bits, 0, NULL, + mask, NULL); /* if clear_extent_bit failed for enomem reasons, * we can't allow the release to continue. From patchwork Fri Sep 2 20:16:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A294ECAAD5 for ; Fri, 2 Sep 2022 20:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230164AbiIBURg (ORCPT ); Fri, 2 Sep 2022 16:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230095AbiIBURb (ORCPT ); Fri, 2 Sep 2022 16:17:31 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BABF1D344C for ; Fri, 2 Sep 2022 13:17:29 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id g14so2336477qto.11 for ; Fri, 02 Sep 2022 13:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=gbd5khjYraWJArMQaXxmQuFAzAD4XuznmxOKkkkzZtw=; b=WEB0F2b4Y2+OvVK+Rn1nWS87RqoZrtGcTTdKBjfRu7Un5ELMe8iQ1U+fo2LjbNux4Y crJyVdXP6MWz39qE2gaO7mpaUNcU48S4O674FkFd9fgeRqaWBoTA6yLSWCL+DU6Yi+wq v2bSRC72PrfO9lj0Hb19ojcnVHUYUSOLGyTQwFKdlQ6tCDgVso5XYnSLEJZUXVQgkl4d UFVU/jLXjPvchfBMO1gKsAVtZla1SJUtXw6RfJws0LeHraSccQ8LrMwVrgMlfIec1ecW H/QhoD/8haYj0+WXt1S23jYxcGfgwQBpIlUckBVif5SvFgrCV6nP6MOsilS9bk7blAQM QJUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=gbd5khjYraWJArMQaXxmQuFAzAD4XuznmxOKkkkzZtw=; b=GPscgLMsl+/foE8nFTisa0FbaHygBsvJWxbjlQ6tkXJz6ykpRvP1bdx/YRn6rUVl49 xyN32DgRZ/WPThsh6g/jBDyq0P1DUv4SkFNTxb5y63NlSAIq7O6D0GJedkmqVpi77O9h KKl74FkFLW9tpxftj59nIHFl87UgANwDgx2KvJRyBhv2HyQ940L0zLslv4TPyPX2aq/5 JxaeZ04b8Yj+u+r49wxm5MWjt7PvjloT7UWxqquOZNvPgjZ+mMq5jnGVbF97PLyd65Gk Dmg3lSAReLDZUL9nhgpBnjTQP2hILylA1nemcG19p5xkUxRO+nYdGLU3wOjEYnVgPeuA m9Vw== X-Gm-Message-State: ACgBeo0kokwR1i2H9tdFUb84zzRRxG8N32HQt+RTMN5skeNy6PoZboib WiVGjQUWPWkYXnoPKby9iHaWEVc6AuM3OA== X-Google-Smtp-Source: AA6agR5Yp7OZ2dlbBMRBhHiBtBWgvE/d3LOyQytT7H0hCcQZ8qxThWdt1cZ5lr6WKUhm6n99Qib+PQ== X-Received: by 2002:a05:622a:287:b0:343:6e93:ac49 with SMTP id z7-20020a05622a028700b003436e93ac49mr31039111qtw.75.1662149848935; Fri, 02 Sep 2022 13:17:28 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id q190-20020ae9dcc7000000b006a5d2eb58b2sm2030180qkf.33.2022.09.02.13.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:28 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 29/31] btrfs: replace delete argument with EXTENT_CLEAR_ALL_BITS Date: Fri, 2 Sep 2022 16:16:34 -0400 Message-Id: <9b4b4878f30d5c77ae6665d3bb7e4c7352d5ea0d.1662149276.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead of taking up a whole argument to indicate we're clearing everything in a range, simply add another EXTENT bit to control this, and then update all the callers to drop this argument from the clear_extent_bit variants. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 17 ++++++++------- fs/btrfs/extent-io-tree.h | 28 +++++++++++++++--------- fs/btrfs/extent_io.c | 4 ++-- fs/btrfs/extent_map.c | 2 +- fs/btrfs/file-item.c | 2 +- fs/btrfs/file.c | 2 +- fs/btrfs/free-space-cache.c | 6 +++--- fs/btrfs/inode.c | 41 +++++++++++++++++------------------- fs/btrfs/ioctl.c | 2 +- fs/btrfs/reflink.c | 2 +- fs/btrfs/tests/inode-tests.c | 8 +++---- fs/btrfs/transaction.c | 2 +- 12 files changed, 61 insertions(+), 55 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index b4e70d4f243b..f37de54056e8 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -528,8 +528,7 @@ static void extent_io_tree_panic(struct extent_io_tree *tree, int err) * This takes the tree lock, and returns 0 on success and < 0 on error. */ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int delete, - struct extent_state **cached_state, + u32 bits, struct extent_state **cached_state, gfp_t mask, struct extent_changeset *changeset) { struct extent_state *state; @@ -538,17 +537,19 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, u64 last_end; int err; int clear = 0; - int wake = (bits & EXTENT_LOCKED) ? 1 : 0; + int wake; + int delete = bits & EXTENT_CLEAR_ALL_BITS; btrfs_debug_check_extent_io_range(tree, start, end); trace_btrfs_clear_extent_bit(tree, start, end - start + 1, bits); - if (bits & EXTENT_DELALLOC) - bits |= EXTENT_NORESERVE; - if (delete) bits |= ~EXTENT_CTLBITS; + if (bits & EXTENT_DELALLOC) + bits |= EXTENT_NORESERVE; + + wake = (bits & EXTENT_LOCKED) ? 1 : 0; if (bits & (EXTENT_LOCKED | EXTENT_BOUNDARY)) clear = 1; again: @@ -1634,7 +1635,7 @@ int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, */ ASSERT(!(bits & EXTENT_LOCKED)); - return __clear_extent_bit(tree, start, end, bits, 0, NULL, GFP_NOFS, + return __clear_extent_bit(tree, start, end, bits, NULL, GFP_NOFS, changeset); } @@ -1648,7 +1649,7 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) if (err == -EEXIST) { if (failed_start > start) clear_extent_bit(tree, start, failed_start - 1, - EXTENT_LOCKED, 0, NULL); + EXTENT_LOCKED, NULL); return 0; } return 1; diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 94574062eabe..a8671116b59f 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -35,10 +35,18 @@ struct io_failure_record; * delalloc bytes decremented, in an atomic way to prevent races with stat(2). */ #define EXTENT_ADD_INODE_BYTES (1U << 15) + +/* + * Set during truncate when we're clearing an entire range and we just want the + * extent states to go away. + */ +#define EXTENT_CLEAR_ALL_BITS (1U << 16) + #define EXTENT_DO_ACCOUNTING (EXTENT_CLEAR_META_RESV | \ EXTENT_CLEAR_DATA_RESV) #define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | \ - EXTENT_ADD_INODE_BYTES) + EXTENT_ADD_INODE_BYTES | \ + EXTENT_CLEAR_ALL_BITS) /* * Redefined bits above which are used only in the device allocation tree, @@ -114,35 +122,35 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits, struct extent_changeset *changeset); int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, - u32 bits, int delete, struct extent_state **cached, - gfp_t mask, struct extent_changeset *changeset); + u32 bits, struct extent_state **cached, gfp_t mask, + struct extent_changeset *changeset); static inline int clear_extent_bit(struct extent_io_tree *tree, u64 start, - u64 end, u32 bits, int delete, + u64 end, u32 bits, struct extent_state **cached) { - return __clear_extent_bit(tree, start, end, bits, delete, cached, + return __clear_extent_bit(tree, start, end, bits, cached, GFP_NOFS, NULL); } static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached) { - return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached, + return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, cached, GFP_NOFS, NULL); } static inline int unlock_extent_atomic(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached) { - return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 0, cached, + return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, cached, GFP_ATOMIC, NULL); } static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 bits) { - return clear_extent_bit(tree, start, end, bits, 0, NULL); + return clear_extent_bit(tree, start, end, bits, NULL); } int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, @@ -165,7 +173,7 @@ static inline int set_extent_bits(struct extent_io_tree *tree, u64 start, static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state **cached_state) { - return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, + return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE, cached_state, GFP_NOFS, NULL); } @@ -180,7 +188,7 @@ static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start, { return clear_extent_bit(tree, start, end, EXTENT_DIRTY | EXTENT_DELALLOC | - EXTENT_DO_ACCOUNTING, 0, cached); + EXTENT_DO_ACCOUNTING, cached); } int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 849ecccca53e..ae0951841515 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -487,7 +487,7 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, struct page *locked_page, u32 clear_bits, unsigned long page_ops) { - clear_extent_bit(&inode->io_tree, start, end, clear_bits, 0, NULL); + clear_extent_bit(&inode->io_tree, start, end, clear_bits, NULL); __process_pages_contig(inode->vfs_inode.i_mapping, locked_page, start, end, page_ops, NULL); @@ -3398,7 +3398,7 @@ static int try_release_extent_state(struct extent_io_tree *tree, * The delalloc new bit will be cleared by ordered extent * completion. */ - ret = __clear_extent_bit(tree, start, end, clear_bits, 0, NULL, + ret = __clear_extent_bit(tree, start, end, clear_bits, NULL, mask, NULL); /* if clear_extent_bit failed for enomem reasons, diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index fae627c28d7c..d5640e695e6b 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -382,7 +382,7 @@ static void extent_map_device_clear_bits(struct extent_map *em, unsigned bits) __clear_extent_bit(&device->alloc_state, stripe->physical, stripe->physical + stripe_size - 1, bits, - 0, NULL, GFP_NOWAIT, NULL); + NULL, GFP_NOWAIT, NULL); } } diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index d44e0d3c84cd..45949261c699 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -118,7 +118,7 @@ int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start, if (btrfs_fs_incompat(inode->root->fs_info, NO_HOLES)) return 0; return clear_extent_bit(&inode->file_extent_tree, start, - start + len - 1, EXTENT_DIRTY, 0, NULL); + start + len - 1, EXTENT_DIRTY, NULL); } static inline u32 max_ordered_sum_bytes(struct btrfs_fs_info *fs_info, diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index b42ce1e16be8..cd5eb63a4223 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -473,7 +473,7 @@ int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages, */ clear_extent_bit(&inode->io_tree, start_pos, end_of_last_block, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, - 0, cached); + cached); err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, extra_bits, cached); diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index ecef1ba816c3..7859eeca484c 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1163,7 +1163,7 @@ update_cache_item(struct btrfs_trans_handle *trans, ret = btrfs_search_slot(trans, root, &key, path, 0, 1); if (ret < 0) { clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, inode->i_size - 1, - EXTENT_DELALLOC, 0, NULL); + EXTENT_DELALLOC, NULL); goto fail; } leaf = path->nodes[0]; @@ -1175,7 +1175,7 @@ update_cache_item(struct btrfs_trans_handle *trans, if (found_key.objectid != BTRFS_FREE_SPACE_OBJECTID || found_key.offset != offset) { clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, - inode->i_size - 1, EXTENT_DELALLOC, 0, + inode->i_size - 1, EXTENT_DELALLOC, NULL); btrfs_release_path(path); goto fail; @@ -1272,7 +1272,7 @@ static int flush_dirty_cache(struct inode *inode) ret = btrfs_wait_ordered_range(inode, 0, (u64)-1); if (ret) clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, inode->i_size - 1, - EXTENT_DELALLOC, 0, NULL); + EXTENT_DELALLOC, NULL); return ret; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b21387ea5e97..a394c3efabcd 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1748,7 +1748,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, if (count > 0) clear_extent_bit(io_tree, start, end, EXTENT_NORESERVE, - 0, NULL); + NULL); } return cow_file_range(inode, locked_page, start, end, page_started, @@ -3324,7 +3324,7 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) !test_bit(BTRFS_ORDERED_TRUNCATED, &ordered_extent->flags)) clear_extent_bit(&inode->io_tree, start, end, EXTENT_DELALLOC_NEW | EXTENT_ADD_INODE_BYTES, - 0, &cached_state); + &cached_state); btrfs_inode_safe_disk_i_size_write(inode, 0); ret = btrfs_update_inode_fallback(trans, root, inode); @@ -3334,7 +3334,7 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) } ret = 0; out: - clear_extent_bit(&inode->io_tree, start, end, clear_bits, 0, + clear_extent_bit(&inode->io_tree, start, end, clear_bits, &cached_state); if (trans) @@ -4934,7 +4934,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, clear_extent_bit(&inode->io_tree, block_start, block_end, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, - 0, &cached_state); + &cached_state); ret = btrfs_set_extent_delalloc(inode, block_start, block_end, 0, &cached_state); @@ -5348,8 +5348,7 @@ static void evict_inode_truncate_pages(struct inode *inode) end - start + 1); clear_extent_bit(io_tree, start, end, - EXTENT_LOCKED | EXTENT_DELALLOC | - EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 1, + EXTENT_CLEAR_ALL_BITS | EXTENT_DO_ACCOUNTING, &cached_state); cond_resched(); @@ -8384,9 +8383,9 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, cur = page_start; while (cur < page_end) { struct btrfs_ordered_extent *ordered; - bool delete_states; u64 range_end; u32 range_len; + u32 extra_flags = 0; ordered = btrfs_lookup_first_ordered_range(inode, cur, page_end + 1 - cur); @@ -8396,7 +8395,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, * No ordered extent covering this range, we are safe * to delete all extent states in the range. */ - delete_states = true; + extra_flags = EXTENT_CLEAR_ALL_BITS; goto next; } if (ordered->file_offset > cur) { @@ -8407,7 +8406,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, * the ordered extent in the next iteration. */ range_end = ordered->file_offset - 1; - delete_states = true; + extra_flags = EXTENT_CLEAR_ALL_BITS; goto next; } @@ -8422,7 +8421,6 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, * We can't delete the extent states as * btrfs_finish_ordered_io() may still use some of them. */ - delete_states = false; goto next; } btrfs_page_clear_ordered(fs_info, &folio->page, cur, range_len); @@ -8439,7 +8437,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, clear_extent_bit(tree, cur, range_end, EXTENT_DELALLOC | EXTENT_LOCKED | EXTENT_DO_ACCOUNTING | - EXTENT_DEFRAG, 0, &cached_state); + EXTENT_DEFRAG, &cached_state); spin_lock_irq(&inode->ordered_tree.lock); set_bit(BTRFS_ORDERED_TRUNCATED, &ordered->flags); @@ -8447,6 +8445,12 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, cur - ordered->file_offset); spin_unlock_irq(&inode->ordered_tree.lock); + /* + * If the ordered extent has finished, we're safe to delete all + * the extent states of the range, otherwise + * btrfs_finish_ordered_io() will get executed by endio for + * other pages, so we can't delete extent states. + */ if (btrfs_dec_test_ordered_pending(inode, &ordered, cur, range_end + 1 - cur)) { btrfs_finish_ordered_io(ordered); @@ -8454,14 +8458,7 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, * The ordered extent has finished, now we're again * safe to delete all extent states of the range. */ - delete_states = true; - } else { - /* - * btrfs_finish_ordered_io() will get executed by endio - * of other pages, thus we can't delete extent states - * anymore - */ - delete_states = false; + extra_flags = EXTENT_CLEAR_ALL_BITS; } next: if (ordered) @@ -8485,8 +8482,8 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, if (!inode_evicting) { clear_extent_bit(tree, cur, range_end, EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_UPTODATE | - EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, - delete_states, &cached_state); + EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG | + extra_flags, &cached_state); } cur = range_end + 1; } @@ -8620,7 +8617,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) */ clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, end, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | - EXTENT_DEFRAG, 0, &cached_state); + EXTENT_DEFRAG, &cached_state); ret2 = btrfs_set_extent_delalloc(BTRFS_I(inode), page_start, end, 0, &cached_state); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index d59e1f1b762e..d5dd8bed1488 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1616,7 +1616,7 @@ static int defrag_one_locked_target(struct btrfs_inode *inode, return ret; clear_extent_bit(&inode->io_tree, start, start + len - 1, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | - EXTENT_DEFRAG, 0, cached_state); + EXTENT_DEFRAG, cached_state); set_extent_defrag(&inode->io_tree, start, start + len - 1, cached_state); /* Update the page status */ diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c index 7a0db71d683b..f50586ff85c8 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -92,7 +92,7 @@ static int copy_inline_to_page(struct btrfs_inode *inode, clear_extent_bit(&inode->io_tree, file_offset, range_end, EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, - 0, NULL); + NULL); ret = btrfs_set_extent_delalloc(inode, file_offset, range_end, 0, NULL); if (ret) goto out_unlock; diff --git a/fs/btrfs/tests/inode-tests.c b/fs/btrfs/tests/inode-tests.c index eeba3deb7714..b1c88dd187cb 100644 --- a/fs/btrfs/tests/inode-tests.c +++ b/fs/btrfs/tests/inode-tests.c @@ -975,7 +975,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) BTRFS_MAX_EXTENT_SIZE >> 1, (BTRFS_MAX_EXTENT_SIZE >> 1) + sectorsize - 1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, NULL); + EXTENT_UPTODATE, NULL); if (ret) { test_err("clear_extent_bit returned %d", ret); goto out; @@ -1043,7 +1043,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) BTRFS_MAX_EXTENT_SIZE + sectorsize, BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, NULL); + EXTENT_UPTODATE, NULL); if (ret) { test_err("clear_extent_bit returned %d", ret); goto out; @@ -1076,7 +1076,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) /* Empty */ ret = clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, NULL); + EXTENT_UPTODATE, NULL); if (ret) { test_err("clear_extent_bit returned %d", ret); goto out; @@ -1092,7 +1092,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) if (ret) clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1, EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_UPTODATE, 0, NULL); + EXTENT_UPTODATE, NULL); iput(inode); btrfs_free_dummy_root(root); btrfs_free_dummy_fs_info(fs_info); diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index b371f9f5444e..681404a5cd36 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1116,7 +1116,7 @@ static int __btrfs_wait_marked_extents(struct btrfs_fs_info *fs_info, * it's safe to do it (through extent_io_tree_release()). */ err = clear_extent_bit(dirty_pages, start, end, - EXTENT_NEED_WAIT, 0, &cached_state); + EXTENT_NEED_WAIT, &cached_state); if (err == -ENOMEM) err = 0; if (!err) From patchwork Fri Sep 2 20:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03433C6FA82 for ; Fri, 2 Sep 2022 20:17:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230166AbiIBURi (ORCPT ); Fri, 2 Sep 2022 16:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbiIBURc (ORCPT ); Fri, 2 Sep 2022 16:17:32 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C76A9D86D4 for ; Fri, 2 Sep 2022 13:17:31 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id a15so2615865qko.4 for ; Fri, 02 Sep 2022 13:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=Rlh8wzxy9xEB0pARSrW1TZQUkqNBeT0gPM+yrEwJAvE=; b=0YRjCo96j0Tqx2jS8s6jfSmzbHVY3RXnNJTOaV6pyIKs+mrgvViwv4R+Wm1YoP/f0G aX5deHc9kxJbv85KpJidZbAoqOCPTBproC8K6KVBX5GFV45Ny+NTextxlCNTr5+AFgl5 thTPUZYFw323WM07ZyreeSFzuIvi3JEvV4e4mHjUDQdAnkRfDRGaV1nSn4H/KdpDPjHf 7mW4nrDJ6bImnc8z/bQoBGYura/40ncioEDqHsuo7Df7BcmXWzn0W6Ja2Lm7PAzRNnqs JLGNsprYTMq2a7UtP/lDEJjfhbFkpetd7k2ln+GPIRyfRRHulQ5cgknOnmuRNRTafAcZ khkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Rlh8wzxy9xEB0pARSrW1TZQUkqNBeT0gPM+yrEwJAvE=; b=NmAyuvBk6M2zyFY56lu43mFe5XvwYSchOioNRYB1hnsoigWpbnsZWjSVJvx8TCNurx 8/pLnkiJuf+Q40l0wXPvv39jJ/zF4OpaH2/O4vPDDVKGePuqWU4tQKs8ERv+5yAnXD40 Vk/pySDNoVioILuPNrnIX35njMQYdjGt+16+ctGKjRg3kY2SggYL46K/75VtcibSE89s lqjQ8vFnv8Zm2JWI3VqZxU3L5rXVLISZEwg4Cs3WfqVFsOdj+BvL4GseO8oZrMA1p+4Y bRiHzMXKQHBHRg2eN0mEesoxyml4S4UIzYFm+d27+cfW23qXHyqAYRpipRVN+9cAMHZ1 t5qw== X-Gm-Message-State: ACgBeo3s9myzy6k6oElfQusRPrJQQwjv6gggo8DxAU691tTqepcHrCOV vyQbyCSPadTr+UiVIT7q45yI+V/X9rHbRw== X-Google-Smtp-Source: AA6agR4jo2uuhlK1heaR8wEQA62zDChJBz6xSvKHjMMV/yL8lyM36jbtr4wKwRQcI5B+07LX8BA8jw== X-Received: by 2002:a05:620a:1786:b0:6bb:387c:4e2a with SMTP id ay6-20020a05620a178600b006bb387c4e2amr24906435qkb.194.1662149850599; Fri, 02 Sep 2022 13:17:30 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id q65-20020ae9dc44000000b006bb5cdd4031sm1921975qkf.40.2022.09.02.13.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:30 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 30/31] btrfs: don't init io tree with private data for non inodes Date: Fri, 2 Sep 2022 16:16:35 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We only use this for normal inodes, so don't set it if we're not a normal inode. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 2 +- fs/btrfs/inode.c | 2 +- fs/btrfs/transaction.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index af073af8131e..0e4de8ed8d81 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2231,7 +2231,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info) RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node); extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree, - IO_TREE_BTREE_INODE_IO, inode); + IO_TREE_BTREE_INODE_IO, NULL); extent_map_tree_init(&BTRFS_I(inode)->extent_tree); BTRFS_I(inode)->root = btrfs_grab_root(fs_info->tree_root); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a394c3efabcd..f5bf276b32a4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8909,7 +8909,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) extent_map_tree_init(&ei->extent_tree); extent_io_tree_init(fs_info, &ei->io_tree, IO_TREE_INODE_IO, inode); extent_io_tree_init(fs_info, &ei->file_extent_tree, - IO_TREE_INODE_FILE_EXTENT, inode); + IO_TREE_INODE_FILE_EXTENT, NULL); ei->io_failure_tree = RB_ROOT; atomic_set(&ei->sync_writers, 0); mutex_init(&ei->log_mutex); diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 681404a5cd36..faa9602733c7 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -365,7 +365,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, spin_lock_init(&cur_trans->releasing_ebs_lock); list_add_tail(&cur_trans->list, &fs_info->trans_list); extent_io_tree_init(fs_info, &cur_trans->dirty_pages, - IO_TREE_TRANS_DIRTY_PAGES, fs_info->btree_inode); + IO_TREE_TRANS_DIRTY_PAGES, NULL); extent_io_tree_init(fs_info, &cur_trans->pinned_extents, IO_TREE_FS_PINNED_EXTENTS, NULL); fs_info->generation++; From patchwork Fri Sep 2 20:16:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12964639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4270BECAAD5 for ; Fri, 2 Sep 2022 20:17:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230169AbiIBURj (ORCPT ); Fri, 2 Sep 2022 16:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbiIBURd (ORCPT ); Fri, 2 Sep 2022 16:17:33 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E43E1D8E14 for ; Fri, 2 Sep 2022 13:17:32 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id g14so2336610qto.11 for ; Fri, 02 Sep 2022 13:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=gz6bRoIfAhL2QVg/hVUDAaMs8W87PD05jLnQ0mOTd5w=; b=iU5b03KYanIHrHx5S8+V2uVMsSS8LekORuzkGr3xLXF3iAYic+qeVPYbJSXun+x9F/ u5njOhHAAD4ynskZPH9Gwh+EWxB1c98PN8izlWUTs8Coo6FwdDcqhdcO+DE17BcvklMo GzPjQek5/imcOPHvcIAI0Byn+uxRHIicckq/tjeFFuMO+XW4DkpuWFJHEoaq90sl6Gin 3RHzYcM8s5dIg/C50gCy3cFJUYr3VxTGVNcz2MBqiZaXO5+SFe48TRBVT8EDF7x3+PVT VxlHZRn53G1H26XSMkJbyGv9k2bK4Ij134f3akd96Xcw4uDaj5mVLyaNBw6RI3GNqyCw U21g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=gz6bRoIfAhL2QVg/hVUDAaMs8W87PD05jLnQ0mOTd5w=; b=GN+GakdOZxW3jpnuY0NCfsIzUfnTIext/YT7LDil2xI1hM5bXs5LOpNrqDclbcl9RK cCPwVSjMKxvhyJyvWnkmXaXd900nhu9ocMrixQ+1wVeBFwpZPC4pt4Qu/NZlUoVEofmf kkBOTYDL9NwobtKIYfpEx9vZkbSqqc8MaLQIrTk4Ct/IItpkd3ozASXJhz5IGph//hev aQnYJanMrq0ot6uw/HjIE60be8QAkhjXqNbxP65DGQbc2oVBMH3aMs3sABWNDTHllx7A 9kx53kVfBJRYw9aJ9HuVMmXtDqV5CuqG2e06v6ci/+6qBfhWpMfu5UdaElPPMkGKflAy ZQXw== X-Gm-Message-State: ACgBeo0ljzVyz6wmLaK451H0za5uAGJY1XkqwIbyenUKyLKuZFBPedCu H9plo3fmQfxQMGpIJF9ZsMqFKzX/vJlqvw== X-Google-Smtp-Source: AA6agR5a6W0ppe824FdefcDITm06OXGGXjpLT0Zn6xvmmvIO3gPaWx/Y7nqOWjpE1YuhBaL59CBcpQ== X-Received: by 2002:a05:622a:5cb:b0:344:551a:c804 with SMTP id d11-20020a05622a05cb00b00344551ac804mr29588887qtb.645.1662149852284; Fri, 02 Sep 2022 13:17:32 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id w17-20020a05620a0e9100b006a6d7c3a82esm1966690qkm.15.2022.09.02.13.17.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 13:17:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 31/31] btrfs: remove is_data_inode() checks in extent-io-tree.c Date: Fri, 2 Sep 2022 16:16:36 -0400 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're only init'ing extent_io_tree's with a private data if we're a normal inode, so we don't need this extra check. Signed-off-by: Josef Bacik --- fs/btrfs/extent-io-tree.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index f37de54056e8..c67370469548 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -59,7 +59,7 @@ static inline void __btrfs_debug_check_extent_io_range(const char *caller, struct inode *inode = tree->private_data; u64 isize; - if (!inode || !is_data_inode(inode)) + if (!inode) return; isize = i_size_read(inode); @@ -332,7 +332,7 @@ static void merge_state(struct extent_io_tree *tree, other = prev_state(state); if (other && other->end == state->start - 1 && other->state == state->state) { - if (tree->private_data && is_data_inode(tree->private_data)) + if (tree->private_data) btrfs_merge_delalloc_extent(tree->private_data, state, other); state->start = other->start; @@ -343,7 +343,7 @@ static void merge_state(struct extent_io_tree *tree, other = next_state(state); if (other && other->start == state->end + 1 && other->state == state->state) { - if (tree->private_data && is_data_inode(tree->private_data)) + if (tree->private_data) btrfs_merge_delalloc_extent(tree->private_data, state, other); state->end = other->end; @@ -437,7 +437,7 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig, struct rb_node *parent = NULL; struct rb_node **node; - if (tree->private_data && is_data_inode(tree->private_data)) + if (tree->private_data) btrfs_split_delalloc_extent(tree->private_data, orig, split); prealloc->start = orig->start; @@ -485,7 +485,7 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree, u32 bits_to_clear = bits & ~EXTENT_CTLBITS; int ret; - if (tree->private_data && is_data_inode(tree->private_data)) + if (tree->private_data) btrfs_clear_delalloc_extent(tree->private_data, state, bits); ret = add_extent_changeset(state, bits_to_clear, changeset, 0); @@ -747,7 +747,7 @@ static void set_state_bits(struct extent_io_tree *tree, u32 bits_to_set = bits & ~EXTENT_CTLBITS; int ret; - if (tree->private_data && is_data_inode(tree->private_data)) + if (tree->private_data) btrfs_set_delalloc_extent(tree->private_data, state, bits); ret = add_extent_changeset(state, bits_to_set, changeset, 1);