From patchwork Fri Apr 19 18:16:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636714 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA8C130A5B for ; Fri, 19 Apr 2024 18:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550638; cv=none; b=iWKiKPOLyLXIvX+dcUPBkfCiAh4YDd4pQXfvOKK7cthPO2auXeyYp1bcX+Sfc2S6YlfNxYWcjKUgQtZ6MoNdIf/fF1EQqBk4xjR2pRBopQzXVTSwoP4ihrTSUDi+E6oD9z7spdUnrLzKiHCu/b4IGWcev4TnMV2J4dsydq8wPXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550638; c=relaxed/simple; bh=yLAKJjeyuCKLtU1yKko3PqdPmkAaQI52Jj9ivazbWYE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DvxqyKZ5cPo5zP0kdIQ9aVgDF84uuxF6BJRiozUn6qVnkHYx6/knOZhkMSMi+FScUyrj5859mFlvGAahoYXJkU93zaIO5f7kPrIkV15hWT0HqhTYYkoAczXXpSx+JUHh93FrOn/jRVXQx7mv0S2R+xMvSKyK7JqpIf4luXxQrLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=HxiJIJGF; arc=none smtp.client-ip=209.85.167.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="HxiJIJGF" Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3c70e46f3caso1240855b6e.2 for ; Fri, 19 Apr 2024 11:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550636; x=1714155436; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Z31+zLHW3b8QEl1jHvlW3MeAcA7zHCJ8yETwFDHgxiY=; b=HxiJIJGFgGxY9y9HaDAdlmg9EClYjwXaCj4pAj3rPNdJCiywMAyDQTuBn5y0+bx0gr O2OYixvPXh84BNpNz00dvpAmiiEP4D/fvF7+XHE5mzk9kCSRr3oU+w86aoZjXmhrsfJg uR8tim6qojwCW6zSHRw/FP9y2IzkBgXlslXnQayHdwSuh10SjSRowIFmR2AecK+3RJ7g qSVxjTcvbI73IdgaJNWGlHE4UFzbj6q+Bd89VCURoyUl+r85Gk01Bi1ioV/DywTKxzEB xHy9yx/KynvFeGcfx8J+1rWXO9taVu7hbs3I/+5eaJJfbxtCou4guWqRuagWtjaAjsim WOlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550636; x=1714155436; 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:message-id:reply-to; bh=Z31+zLHW3b8QEl1jHvlW3MeAcA7zHCJ8yETwFDHgxiY=; b=CXZr0fCEDFjjIzz5LaYrZqVSdsrybc4IwBY9oZrQ5V2LqKhXckV9pXeWXpXZbslB+g RGYYXlXU4Ne5rhWpH+GeOwsOCwRrCDUxbvddK3sNm2fu9dBeKdlZDYEE02Oqif+eW7ki ylS2aCZ9ysOSbw/OBkLGcMQhBQFBr5jPgdeS0JpPF6u0VJNnwF5boPdifYKxrLzQeOKl yyjSlSOlxQeCmJvlCkHV0at/suYUoXaFTwI4yDxWJizGuQTHkja12uyDVLhziImgxR75 gN3qAGKI5m3Ao+2/p4Ro8Shx5n4Aw/bw17bSsIluBevDsJ8l6zed6WOy63zlc/YNkRJx sPOA== X-Gm-Message-State: AOJu0Yz5Kxa4ysJY9uq8pGCICI9vLeLFX9AMScypwKiqdv9WdZ9GEabJ m4LkuSiJB3M/p4JbuDOynks9PG5disOl2xlJWYsAKAoZ35yxc/OkrSoJOwo21Zgl27sbfBgds0t w X-Google-Smtp-Source: AGHT+IF686qwrA9x5uIXEv3ZmrPshnwXQTTouQSu0QOAEJeBMD1/xP34fR4vFjes15XHqlglJJ8tXg== X-Received: by 2002:a05:6808:2c4:b0:3c7:2914:9784 with SMTP id a4-20020a05680802c400b003c729149784mr2757693oid.16.1713550636158; Fri, 19 Apr 2024 11:17:16 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id pe16-20020a05620a851000b007883184574esm1814432qkn.98.2024.04.19.11.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:15 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/15] btrfs: don't do find_extent_buffer in do_walk_down Date: Fri, 19 Apr 2024 14:16:56 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We do find_extent_buffer(), and then if we don't find the eb in cache we call btrfs_find_create_tree_block(), which calls find_extent_buffer() first and then allocates the extent buffer. The reason we're doing this is because if we don't find the extent buffer in cache we set reada = 1. However this doesn't matter, because lower down we only trigger reada if !btrfs_buffer_uptodate(eb), which is what the case would be if we didn't find the extent buffer in cache and had to allocate it. Clean this up to simply call btrfs_find_create_tree_block(), and then use the fact that we're having to read the extent buffer off of disk to go ahead and kick off readahead. Signed-off-by: Josef Bacik Reviewed-by: Qu Wenruo --- fs/btrfs/extent-tree.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 023920d0d971..64bb8c69e57a 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5434,7 +5434,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, struct btrfs_key key; struct extent_buffer *next; int level = wc->level; - int reada = 0; int ret = 0; bool need_account = false; @@ -5460,14 +5459,11 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, btrfs_node_key_to_cpu(path->nodes[level], &check.first_key, path->slots[level]); - next = find_extent_buffer(fs_info, bytenr); - if (!next) { - next = btrfs_find_create_tree_block(fs_info, bytenr, - btrfs_root_id(root), level - 1); - if (IS_ERR(next)) - return PTR_ERR(next); - reada = 1; - } + next = btrfs_find_create_tree_block(fs_info, bytenr, + btrfs_root_id(root), level - 1); + if (IS_ERR(next)) + return PTR_ERR(next); + btrfs_tree_lock(next); ret = btrfs_lookup_extent_info(trans, fs_info, bytenr, level - 1, 1, @@ -5518,7 +5514,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, } if (!next) { - if (reada && level == 1) + if (level == 1) reada_walk_down(trans, root, wc, path); next = read_tree_block(fs_info, bytenr, &check); if (IS_ERR(next)) { From patchwork Fri Apr 19 18:16:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636715 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DF6813BAFF for ; Fri, 19 Apr 2024 18:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550640; cv=none; b=UghLJe7L7qtXtO/ev5sDeuHW6EnQmOkVopDZDNPMNIDVg713onXQx0GY3M0kZ/HTTXFmRqn10h2d+a5h4Ou6aWMqFf2u99jyOka8YZWVyOWPHfZy/9VUtz3M8OnJexY62CotCSpLpxTdT23FmjVyol3V8Ln9E2w1fQK1IQEedlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550640; c=relaxed/simple; bh=q7/5CkeojkN4ZfhKHGwqBHU0G5fisrm/mgoKjJ+nB5I=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HdgpQGvcZOFg32lnhlfNkGhv8ga8GIVAuFvpyoHRU3zbWYmLnsiPN2/VwoVAfYs+nn5Hl2tNBgyPsq48GBGoOOOVB7ddHEuGWrQyfpa4PgSw/dclobUXUO4SlGtiP67KzMOWa3ysU9z/AIy/hKBdH8v2kZNQfirCkcIi8hU3n5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=JgGSZnPn; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="JgGSZnPn" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-434c695ec3dso13206821cf.0 for ; Fri, 19 Apr 2024 11:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550637; x=1714155437; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=J4UX7HscCsJKX1WEuQVA5yF+d3O92wIy5EAeUIpWIcY=; b=JgGSZnPnDF1PNhmFE0WZQbMhKYPgLPcu2DqjtHtLROV0XG9Y4yGgoStyfD3i+8UHXs vopplyf4CqjJE4xGMJ4w0RcSmSSiB/vMvpLRRm4Myu37UI2HJpSV9IVC0AtpSihX5JyF d3XLOA91zshBYv5S5vzH881Poe/zx7aPN1FI3BsM9rftQd4ghTFCCGef5L616smkHbq+ 0o6Vva8+q15tTm3mqgAXZTMteYdcnY9N9a2XkZpavtW7wMTes7Wb4A2zBa7/JaMlO3xB pmnBLUE8+yfuOVA30MbIS8Ylib80Rx+ESvuQAUszUXuoZ6OaYMbRtiApN7K3CFHakD+i wgqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550637; x=1714155437; 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:message-id:reply-to; bh=J4UX7HscCsJKX1WEuQVA5yF+d3O92wIy5EAeUIpWIcY=; b=cZXlobyfgPRpe9X58LU4cpn79EBp8IpUpwwIb27D8JVCDKYonoDe2ouuyHkGCyb25l i6Z0/3KBaHvZ6SdKSikXlDhskiXlF8GsIAy8Lz2+UwROA6H2gGMkPvxANxGBNnRup32V P/R5cfIJGPRF/iuZ4+ejj9rHf/6Hve7SKc0m8BloM09wAO/adSwdTPH/kgJr5ocPSe27 8VHx9FT3CChELMF58ElwGdScLCEQsQ40O2Pu072t/MyDa8Hfn/4b2QQWOrtS+OZ7KM5s 0kMMexZA66msJKMApB7PNBbA+aDs8a6rfha9H2L4hUJwN0XDof++IaqEIEf2IG/7nldw Vrfw== X-Gm-Message-State: AOJu0YxPhQ86qeXXFqH+R5cdedzSrzmrSvPfYf7lWLqc+hYE1/dAkjEv zGLDFOQDVSnvtuPcYnFMnfpm2lbgSmzq5f0UKDNSo5vFmrA81VzmicC8si8isX2a8/k5hs+HdMN r X-Google-Smtp-Source: AGHT+IEae//+zBwDRFX4vKX4urxs7Ga5kYoC/VB7cpB3Ti/991yW+f/pyfSOE2TthUDGnVALt3w3nQ== X-Received: by 2002:a05:622a:10f:b0:438:e018:18e4 with SMTP id u15-20020a05622a010f00b00438e01818e4mr2176342qtw.27.1713550637382; Fri, 19 Apr 2024 11:17:17 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id y15-20020ac8708f000000b0043476c7f668sm1796650qto.5.2024.04.19.11.17.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:17 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/15] btrfs: push ->owner_root check into btrfs_read_extent_buffer Date: Fri, 19 Apr 2024 14:16:57 -0400 Message-ID: <3487ee70ac2e8fd2c82027c892e91f12a4a47324.1713550368.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently we're only doing this in read_tree_block(), however btrfs_check_eb_owner() properly deals with ->owner_root being set to 0, and in fact we're duplicating this check in read_block_for_search(). Push this check up into btrfs_read_extent_buffer() and fixup read_block_for_search() to just return the result from btrfs_read_extent_buffer() and drop the duplicate check. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 7 +------ fs/btrfs/disk-io.c | 6 ++---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 1a49b9232990..48aa14046343 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1551,12 +1551,7 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p, if (ret) { free_extent_buffer(tmp); btrfs_release_path(p); - return -EIO; - } - if (btrfs_check_eb_owner(tmp, btrfs_root_id(root))) { - free_extent_buffer(tmp); - btrfs_release_path(p); - return -EUCLEAN; + return ret; } if (unlock_up) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index c2dc88f909b0..64523dc1060d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -251,6 +251,8 @@ int btrfs_read_extent_buffer(struct extent_buffer *eb, if (failed && !ret && failed_mirror) btrfs_repair_eb_io_failure(eb, failed_mirror); + if (!ret) + ret = btrfs_check_eb_owner(eb, check->owner_root); return ret; } @@ -635,10 +637,6 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, free_extent_buffer_stale(buf); return ERR_PTR(ret); } - if (btrfs_check_eb_owner(buf, check->owner_root)) { - free_extent_buffer_stale(buf); - return ERR_PTR(-EUCLEAN); - } return buf; } From patchwork Fri Apr 19 18:16:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636716 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B24BC13C3F9 for ; Fri, 19 Apr 2024 18:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550641; cv=none; b=VgF/cALWiXuwdl34WNaXO/qqE4iMSNGfr/JwpB2qSipTA/5fqhUiini4OpQty7fCv+s1J4GSgK0/Jq/1+h3SO/6hKY6eBstHAe9liNg4IZQo752paV0aMkEsM9seXgOiIFSy3WME6fVfF5Mm1svQBGP0Cm5xev7Pd4r2b/0a4X4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550641; c=relaxed/simple; bh=2lbu7MlZ20OCPUMDY7PD15w3ICPg8Sl1AeFxPWiwIC8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mb4wz+m6LGolbtNiGwQHCB31eZBUm28yt+KJVtfACAYe4ZwjnVlZjNFpRCNL2ys3g4GOyX+Q/w4a/CwPdlTbc+MGIj/1F4NX0tWGZv4GgsfJCucxQdwMf+L7RGgnA4q0xFcu1/R2612NEPs/qWg18auGcmQWV2og1YlBeV9WBTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=LkXiNJbf; arc=none smtp.client-ip=209.85.161.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="LkXiNJbf" Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5ad211d3370so341058eaf.1 for ; Fri, 19 Apr 2024 11:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550638; x=1714155438; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=gByU/8pUjCoMe84UQHkVi5p3TEOKUhAcnFsVY0GJioY=; b=LkXiNJbfHSB4+O7cCFYdpZ4ZxXMkl+YLGP5vJ0z8UQds+X5Ysg5ap6/dBuenKJenhI w+JQ3HVllOdkp45EZcxbTx1QGu7/eR+YRKGqcW5+vjtd+9c+DPZFk8vqY1ZWiyjMmm16 qd+GVmKTtpbp0PsoX0gL94nnVe9JVrAjtDrGnpAf6oYuPUbcR2tgJ+rgcMTERjlp2nzw 7Q85+5xO6ToFOX5+0iZbopGKBnne3x76dBHcI9g8rK4IOI3/UNKkZRT3dQnGQ+84XwAY 0Xzbxp2q3gGmQqpnOEYB7VYQOmt6WnbOwD2Gcb6eRTbDMc6v0C5ALvmGzbQskULArcN0 bMmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550638; x=1714155438; 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:message-id:reply-to; bh=gByU/8pUjCoMe84UQHkVi5p3TEOKUhAcnFsVY0GJioY=; b=cjf2nHvJdmoPqENIS0IlM/jf4smjg484RdKOx/iBiI1ZwqMhs+Ttfu/NfRceBaxlO3 ht/0KjzkXIsFGeVZB++uFK5yizS+6GPRa9oouM9Kl3FaUYXqpDJnVDL48stGy9VbmuX0 cKoPaEYIriwbNeAj1jwzqCH9MeBC/cPJ89Lpdap9aHlih9iiwN7+3MCEbyJPDMYuRJKA yAtJlFZwLDh1O5PhaNJMoUaf/h93n3jQUbVdjc7kE2m2n471N8XNRUwVTo7DtLf37InW yQuObeXtxQXPeO9wiMzDmebTxCYAIofRhostxqncBGEOnU/LZEhNhyuBmEEwrO+n6j1K 0mYg== X-Gm-Message-State: AOJu0Yzj7fAKi5tc0TYbe/8Y5mRxPmlx9uM0PeQxyruvDxJD7/QUMfzT /OPCmVk0ie7mt3vUVjIsmILUUmCO2qPnZ3BdM9lNR7f+vxljNViohPaOOV7e6P61p3Uxxe1ii2H O X-Google-Smtp-Source: AGHT+IHCgkWUouO8+KWBPulD7k0Py+6n5Vlu8RAXV4cR/O/5srif5vvfTgXmBexouXac1f6ratCuVg== X-Received: by 2002:a05:6358:4b09:b0:186:d3c9:fc0b with SMTP id kr9-20020a0563584b0900b00186d3c9fc0bmr3481486rwc.30.1713550638550; Fri, 19 Apr 2024 11:17:18 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id l12-20020a0ce08c000000b0069b5acd4645sm1749116qvk.82.2024.04.19.11.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:18 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/15] btrfs: use btrfs_read_extent_buffer in do_walk_down Date: Fri, 19 Apr 2024 14:16:58 -0400 Message-ID: <469a21efbd9050203d1e150004ecafa3c312aa05.1713550368.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently if our extent buffer isn't uptodate we will drop the lock, free it, and then call read_tree_block() for the bytenr. This is inefficient, we already have the extent buffer, we can simply call btrfs_read_extent_buffer(). Collapse these two cases down into one if statement, if we are not uptodate we can drop the lock, trigger readahead, and do the read using btrfs_read_extent_buffer(), and carry on. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 64bb8c69e57a..b8ef918ee440 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5508,22 +5508,15 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, if (!btrfs_buffer_uptodate(next, generation, 0)) { btrfs_tree_unlock(next); - free_extent_buffer(next); - next = NULL; - *lookup_info = 1; - } - - if (!next) { if (level == 1) reada_walk_down(trans, root, wc, path); - next = read_tree_block(fs_info, bytenr, &check); - if (IS_ERR(next)) { - return PTR_ERR(next); - } else if (!extent_buffer_uptodate(next)) { + ret = btrfs_read_extent_buffer(next, &check); + if (ret) { free_extent_buffer(next); - return -EIO; + return ret; } btrfs_tree_lock(next); + *lookup_info = 1; } level--; From patchwork Fri Apr 19 18:16:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636717 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3B5513C69B for ; Fri, 19 Apr 2024 18:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550642; cv=none; b=lUMoDFniw57Z8mwhxltnQExWlfSqdjdNZtdBffuxqW8keScmQhxtJoqmN+udlbnlvNGjn0LpWgieQAtSO2d9prTLPFrcUM+H2WLKVbHhR6cFbxzIjy8KsEBVwpyp4yMC9ltGi0mmBkcRpK7zKpcCjpwaH7Fq8QAr9Y+VQUMB0oQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550642; c=relaxed/simple; bh=nc2okafF/XhO8W9guLBOEqcBaz2Fd+XQKkbH9SKhqu8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dettRKVF1hnr5HBTzCurLDui5WO93+FyQ0IAR5U2/1HdCh7vm9o/0UqDhD+i1U+uj6QiPXBLZwW6eoHf4mCGF6j5CnVEJ12hQloetyw8uqhzNiEIQdH0DDbTjzh5fmgXw7c4PExRtAbb+fCRw5AutZOnZfAjaG9pfYZkTQuBV5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=qrCF/X4O; arc=none smtp.client-ip=209.85.161.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="qrCF/X4O" Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5aa2551d33dso1360275eaf.0 for ; Fri, 19 Apr 2024 11:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550639; x=1714155439; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=us8RMZv1QlZ/NsV2TLxfCp7jngBrjzcwfxtMS/16V0M=; b=qrCF/X4OXNRHwhcVBi3IxE8U4FXPVEwMXlfOtplrri854T6K4rAyw7fZDyMmV+Dln9 FOuj8G/KZTZ4MCZ+7+ilMq1YZwNFuk+lYtLeMniYjsWFvepZ933aYOuy3/XvbLi+uQ8c H0hn3bCDUoyuLSmn8vDRfBfckXAN7l0T8sk7Su/mhYz11fwqQFSXD5e6RaiHzzRbeIl4 m4IzoSObNCpk2/m5sWICUnLixwDcUxmj1bFpNL54YoPFus4vj4MmnPcLSHXeP9JMZKhl j5wg1vAA6/aKD61UQBuELtssCbLIijz0GtQ4hiTo11GtvVgIUpAZq5LzeoocXuor/kJh K2ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550639; x=1714155439; 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:message-id:reply-to; bh=us8RMZv1QlZ/NsV2TLxfCp7jngBrjzcwfxtMS/16V0M=; b=DNRwCCMiCBmAoj0x6OqkYMbcm8cRtfQUV5jmxAIJirGHeus/gT/cfzpch8uIwh7vtx RLXEpCWHxVFrRJOSRCl/LAkuDT8lQu7PC5ageUL7aWs0SuCDbzOyBcib7KHB23KCGqBz qbw4OKH1X8gH4i59cC7dpBakjftdi6oej6G4kJN1mYAopmrgew+0u67r3e7pP2ZFf55W bbjJ457R2wcIlX19iH8tQp2m9fJ+hHejVKDaxmB0kkp/dz7flKfJ0rsFLpwCvaPBaGvz SoPMq7VCskZFlCBejYf6rp1tKDcXBSv1/n05vWApaH4mHsAAyU3g0Qg7+FkGntdoESDY RCPw== X-Gm-Message-State: AOJu0YxZVd8GFRskQtjfKAkPoByfU7ekBVgF9jFHv6YxAwORfBK0YL4V 4Exqr8iJKs6yJM1f4/niJvzztF3xuLVjy3CSN6r4FBxSkKlY92KB528TCpSxnvHZyvDoTtX3qGY u X-Google-Smtp-Source: AGHT+IHlQEQbsh9qHjcCbt5z+Ik/n+eGb1OKG50XjyWNVc3pix5nrbtplqeYgenJGlzGlgn/6vJh8g== X-Received: by 2002:a05:6359:4e85:b0:183:a47e:6284 with SMTP id os5-20020a0563594e8500b00183a47e6284mr3185111rwb.5.1713550639661; Fri, 19 Apr 2024 11:17:19 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id t10-20020a0cc44a000000b006915ae114efsm1762378qvi.52.2024.04.19.11.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:19 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/15] btrfs: push lookup_info into walk_control Date: Fri, 19 Apr 2024 14:16:59 -0400 Message-ID: <52e6da7480af222872e563032e8089ba07306d09.1713550368.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of using a flag we're passing around everywhere, add a field to walk_control that we're already passing around everywhere and use that instead. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index b8ef918ee440..0ebbad032c73 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5221,6 +5221,7 @@ struct walk_control { int reada_slot; int reada_count; int restarted; + int lookup_info; }; #define DROP_REFERENCE 1 @@ -5317,7 +5318,7 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, static noinline int walk_down_proc(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, - struct walk_control *wc, int lookup_info) + struct walk_control *wc) { struct btrfs_fs_info *fs_info = root->fs_info; int level = wc->level; @@ -5332,7 +5333,7 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, * when reference count of tree block is 1, it won't increase * again. once full backref flag is set, we never clear it. */ - if (lookup_info && + if (wc->lookup_info && ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) || (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag)))) { BUG_ON(!path->locks[level]); @@ -5424,7 +5425,7 @@ static int check_ref_exists(struct btrfs_trans_handle *trans, static noinline int do_walk_down(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, - struct walk_control *wc, int *lookup_info) + struct walk_control *wc) { struct btrfs_fs_info *fs_info = root->fs_info; u64 bytenr; @@ -5446,7 +5447,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, */ if (wc->stage == UPDATE_BACKREF && generation <= root->root_key.offset) { - *lookup_info = 1; + wc->lookup_info = 1; return 1; } @@ -5478,7 +5479,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ret = -EIO; goto out_unlock; } - *lookup_info = 0; + wc->lookup_info = 0; if (wc->stage == DROP_REFERENCE) { if (wc->refs[level - 1] > 1) { @@ -5516,7 +5517,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, return ret; } btrfs_tree_lock(next); - *lookup_info = 1; + wc->lookup_info = 1; } level--; @@ -5605,7 +5606,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, goto out_unlock; } no_delete: - *lookup_info = 1; + wc->lookup_info = 1; ret = 1; out_unlock: @@ -5739,11 +5740,11 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, struct walk_control *wc) { int level = wc->level; - int lookup_info = 1; int ret = 0; + wc->lookup_info = 1; while (level >= 0) { - ret = walk_down_proc(trans, root, path, wc, lookup_info); + ret = walk_down_proc(trans, root, path, wc); if (ret) break; @@ -5754,7 +5755,7 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, btrfs_header_nritems(path->nodes[level])) break; - ret = do_walk_down(trans, root, path, wc, &lookup_info); + ret = do_walk_down(trans, root, path, wc); if (ret > 0) { path->slots[level]++; continue; From patchwork Fri Apr 19 18:17:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636718 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 167A413C905 for ; Fri, 19 Apr 2024 18:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550643; cv=none; b=UTHVqqVybrdA4QZh5WsuC5urUdw3mxvBdwDXBl+183NTSwCHuvRBuPNcbjp9JNRIfgp/cxVWvaLIHKW50x11DX4UQvHzdizH+65mNZeG5HJuCbCK9IGoJlkvi0f+eZgEvBqYyxQvPll3s/4n5A7Jkqx3X6YiY3fgba1bIHnUh20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550643; c=relaxed/simple; bh=KzHmp05/Wo2kKg3UCSlB89t49owyeLF/elQAy9QqQF8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OlpocsIxIKK3voXIOU9whvRv0BQUlx8VyY5+nlZUIGioiCu0slUKs5CPC3rsUYdYuw089ZiFcd9h9GA1Jt/CJ+av/rs3DNZbaVF/yFnb3+AAYCNqXLxwiBDdnzao6fsQropg35ZIRaM2cq+UcsmF/2sBn2Go05YdSDXMwqHil1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=GNa13sli; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="GNa13sli" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78edc3ad5fdso195263385a.0 for ; Fri, 19 Apr 2024 11:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550641; x=1714155441; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=uOM0zyVqt5YQcXWXCQH2v1El0afwyY8kNvtYtv+qgHM=; b=GNa13slidQkVh0BmCguEiNJJdbRXHmukib7HAWLXgEUVQxJXIGLjTjjahSiectvmCO roNytNZbrVY7OPtZVs3qnml9ingM894oV7PW57OiD0FGGV4KcAMtJovFGx1176S0ilYM ApJKjqrsF7IhsDIYe9MdCqiMKqDv/5AitHEe2aEaK4sSgNb6n8b84HX/pOQUFQ84cJLh yeQFhSewq5rGB6zAGpp0Ew67KtTB2jFHfoEWEd2UjNgdurS+HnzpvSk6kr/Z6ATTD3VK u7/CsrkRKGjt1l7rqOGxGk9FY8iu4Ddn9MN3ofpVu4mENc9G7ch17jfbEHGC81ru/YSl qm4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550641; x=1714155441; 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:message-id:reply-to; bh=uOM0zyVqt5YQcXWXCQH2v1El0afwyY8kNvtYtv+qgHM=; b=r4FMHNZZ5riJJhKZrJ4xr9p+euGMQEbhfl4An3P9WNj/Uh4woIZi0JymcW1l+Vuw+1 aTqd7Kiz3C2hdLn5GYCIC4oYzmUpymumrbVXQpRDlDetmrqdfXDNY6jqhTcES35ZXMqg t+JtQuW/6KHr0swctmwCFTc28LTmXsTchyXR8db5M5469rkewtcvhqQwFlLn2QBj7tWZ akPEBd/loT0MDg+rePYAXA0QDGRTp1MyqTSGODDiHDZSGYVQExt8RWcAOEh0oPGJaDvJ nzZbLc0XpYmi60XQG1l2wI1IMZNTQtF8mgAfQgSPHHDnh5cSg1EvrhZaxFGoqi4nYPwV O/Cg== X-Gm-Message-State: AOJu0YwmkJLt2IImRhsa5ym53l3mvwt6/APSzkQwcY/jOJQXdwdukqJ5 K5uELlMN3ZWHRaxJIf+V8E2cbP4VQp5gvvqjY7RiY4gO2lWXrKHbQys+7hMnxcdTc3BfQP/FyMQ i X-Google-Smtp-Source: AGHT+IGE/WVXf1+ryXvQc1pxUSymbIo2sO+SsN9cGsC3g2ZnGGwJaCrfrqr0BcmvuKNEX0PyRUmdJA== X-Received: by 2002:a05:620a:2407:b0:78e:bd2d:4ab8 with SMTP id d7-20020a05620a240700b0078ebd2d4ab8mr10713088qkn.30.1713550640851; Fri, 19 Apr 2024 11:17:20 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id u24-20020a05620a023800b0078f12e42f0csm1417646qkm.20.2024.04.19.11.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:20 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/15] btrfs: move the eb uptodate code into it's own helper Date: Fri, 19 Apr 2024 14:17:00 -0400 Message-ID: <569ec6a3d78ce12808f515ddc0924bea62733221.1713550368.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 do_walk_down() already has a bunch of things going on, and there's a bit of code related to reading in the next eb if we decide we need it. Move this code off into it's own helper to clean up do_walk_down() a little bit. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 68 +++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0ebbad032c73..9132cfb7fee1 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5409,6 +5409,51 @@ static int check_ref_exists(struct btrfs_trans_handle *trans, return 1; } +/* + * We may not have an uptodate block, so if we are going to walk down into this + * block we need to drop the lock, read it off of the disk, re-lock it and + * return to continue dropping the snapshot. + */ +static int check_next_block_uptodate(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_path *path, + struct walk_control *wc, + struct extent_buffer *next) +{ + struct btrfs_tree_parent_check check = { 0 }; + u64 generation; + int level = wc->level; + int ret; + + btrfs_assert_tree_write_locked(next); + + generation = btrfs_node_ptr_generation(path->nodes[level], + path->slots[level]); + + if (btrfs_buffer_uptodate(next, generation, 0)) + return 0; + + check.level = level - 1; + check.transid = generation; + check.owner_root = btrfs_root_id(root); + check.has_first_key = true; + btrfs_node_key_to_cpu(path->nodes[level], &check.first_key, + path->slots[level]); + + btrfs_tree_unlock(next); + if (level == 1) + reada_walk_down(trans, root, wc, path); + ret = btrfs_read_extent_buffer(next, &check); + if (ret) { + free_extent_buffer(next); + return ret; + } + btrfs_tree_lock(next); + wc->lookup_info = 1; + return 0; +} + + /* * helper to process tree block pointer. * @@ -5431,7 +5476,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, u64 bytenr; u64 generation; u64 owner_root = 0; - struct btrfs_tree_parent_check check = { 0 }; struct btrfs_key key; struct extent_buffer *next; int level = wc->level; @@ -5453,13 +5497,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); - check.level = level - 1; - check.transid = generation; - check.owner_root = btrfs_root_id(root); - check.has_first_key = true; - btrfs_node_key_to_cpu(path->nodes[level], &check.first_key, - path->slots[level]); - next = btrfs_find_create_tree_block(fs_info, bytenr, btrfs_root_id(root), level - 1); if (IS_ERR(next)) @@ -5507,18 +5544,9 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, goto skip; } - if (!btrfs_buffer_uptodate(next, generation, 0)) { - btrfs_tree_unlock(next); - if (level == 1) - reada_walk_down(trans, root, wc, path); - ret = btrfs_read_extent_buffer(next, &check); - if (ret) { - free_extent_buffer(next); - return ret; - } - btrfs_tree_lock(next); - wc->lookup_info = 1; - } + ret = check_next_block_uptodate(trans, root, path, wc, next); + if (ret) + return ret; level--; ASSERT(level == btrfs_header_level(next)); From patchwork Fri Apr 19 18:17:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636719 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B11713B598 for ; Fri, 19 Apr 2024 18:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550644; cv=none; b=jGtSRbM5GVFhCtiJU7/SDxxNF9pBmP7Lla4uDw1OrQ1HLk1UYDFQdzlAtn7ybbq5UD01t0vco7WkVT3I9uHsgJFBbTk5oyeGgvuurgDbVzrcEJRpiZgYPvKureDF85/aa4UC8Zqs96tZBF7PGAVRSjebscwmZX5pgco0QiM6Ob8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550644; c=relaxed/simple; bh=C0tBehzN7791iUKERYw6L04mt0yxXgEDaKuy4um33xs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PxwxUoR1DkyKyfi6P3IF98W55cyOGMCi1Q6ZITRf8/jOCv/AXpMBPCkcd65b207Tv1x5vrkocFrLjnPa/maguqA8alCRGXEXqoJkxgdmBx/N+eBwF16rioOkV/YmITzzLGIbbKc6CNfpuovbsmbaxkZFsudW37lKhenNWTcndDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=o4bdUp39; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="o4bdUp39" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-78f0e3b6feeso93173685a.1 for ; Fri, 19 Apr 2024 11:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550642; x=1714155442; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=DL89FSMitRllfpEs9f5TxZiYHV2JxqhGK5Us3v7HTs0=; b=o4bdUp39lWJBRgw82ZVjvYBmtF9skUPx77kiw2mc04rKl0vQSpOKrbtBBCmpJRzifL EvTswxovzdGfIsJOHIazKOy2bHr/3ELCZVi7z9360uGrfJXo+wwg+6dM4xgB/w9c6xOx oK6NOC14gWa01EE68Mq+XTCnWfpZlXasxsPqcrWUIslojvdCacb4hGC13GokWqFJqYKi Qd4JpO+fXWgP42uYQGTgPswJeazIw6f/ZPh/DGraMLWg3H92X5XoTy3G9kM1anVyZE8L OtMQN5pVh38Cvz/WqCb7BpdxRkwlgere8PXbHazx5lDednhhLPCzOrf1KXVu+e5CFbxW yWpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550642; x=1714155442; 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:message-id:reply-to; bh=DL89FSMitRllfpEs9f5TxZiYHV2JxqhGK5Us3v7HTs0=; b=TGLE1EJzzaCuA5X7xNx8RjOGiNG0jHxkSffZij0RdtXH99HsnA22MyQseWV1/ikc6c htkFBQ3wjIi1u8TkYl0NRNhm05wfU44D+oSls7Vv4Jz5n8BxhpCnVYtuPl+RJGWOpod2 Opo7QgLVtHSvV1r9+Hz0A8F7fwsE1dxvoX+mCl8MFCavWz/erOiR2buSeI0ohoFudMAP FYIyhflJlmNMVZraR0lek8yaitN3vQpkqjf1h6s79mY8iJ5g8g4bQNE+fMtSeI1p9Mdk s+RVM/fz6RoKX38XW7yjixIl7XSq63mtCb+EsIIq2jlj9BQxwgq5uS398MscO9TPFctG SfpQ== X-Gm-Message-State: AOJu0YwP7O0pObf15jKlyl9uxKwuWKV3EHTCtNxzCXtJ4eQRLV2Q7nfZ gcqidB5bjqw0ugsu07WzfF/IIn8D8cjLT+N0ZL77Pj8eubM6QagSkf3kJZGQKs7r57PUVVmZOjc 9 X-Google-Smtp-Source: AGHT+IGitGjCIBZptLt4XUwMII+lQZ70eDoIqhZqNH12f1/BfpFb1aHzELdRdTO859WD68vg6SJedA== X-Received: by 2002:a05:620a:126b:b0:78f:33e:8507 with SMTP id b11-20020a05620a126b00b0078f033e8507mr3500634qkl.36.1713550641964; Fri, 19 Apr 2024 11:17:21 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id t4-20020a05620a004400b0078d5af15c4csm1818376qkt.38.2024.04.19.11.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:21 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 06/15] btrfs: remove need_account in do_walk_down Date: Fri, 19 Apr 2024 14:17:01 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We only set this if wc->refs[level - 1] > 1, and we check this way up above where we need it because the first thing we do before dropping our refs is reset wc->refs[level - 1] to 0. Re-order re-setting of wc->refs to after our drop logic, and then remove the need_account variable and simply check wc->refs[level - 1] directly instead of using a variable. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9132cfb7fee1..afe0694c675b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5480,7 +5480,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, struct extent_buffer *next; int level = wc->level; int ret = 0; - bool need_account = false; generation = btrfs_node_ptr_generation(path->nodes[level], path->slots[level]); @@ -5520,7 +5519,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, if (wc->stage == DROP_REFERENCE) { if (wc->refs[level - 1] > 1) { - need_account = true; if (level == 1 && (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) goto skip; @@ -5563,8 +5561,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, wc->reada_slot = 0; return 0; skip: - wc->refs[level - 1] = 0; - wc->flags[level - 1] = 0; if (wc->stage == DROP_REFERENCE) { struct btrfs_ref ref = { .action = BTRFS_DROP_DELAYED_REF, @@ -5609,7 +5605,8 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, * already accounted them at merge time (replace_path), * thus we could skip expensive subtree trace here. */ - if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID && need_account) { + if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID && + wc->refs[level - 1] > 1) { ret = btrfs_qgroup_trace_subtree(trans, next, generation, level - 1); if (ret) { @@ -5634,6 +5631,8 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, goto out_unlock; } no_delete: + wc->refs[level - 1] = 0; + wc->flags[level - 1] = 0; wc->lookup_info = 1; ret = 1; From patchwork Fri Apr 19 18:17:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636720 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EE0B13BAFC for ; Fri, 19 Apr 2024 18:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550645; cv=none; b=gOtS7PDEJI4L9f/KVycMPnYP+1yhLSrcgyBbt5qxO/S1lFG/SFXSLKgiMKACkEG/+rfdWMDXHjtBUVTo/gc6DfOSYZslk7XiOrT7/bpszpgVr8QHTc0VA50QypZkZglWuOj0kV7ODa2WvEZkQsC3lGi2rMRiFu9kUHl7RucxRsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550645; c=relaxed/simple; bh=om3tnd99vdxF8SGn42D4/BQpacDCWEnsxy0DZIXXwNc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PMoKFSDjil56wABvlabA20JShLbvczRqDnDCnpNrGNxs0xpjeOLrS21PRHueNfnhCtLKrYBeAFrogd5Jokmby8Q1bYWTHVVhuPDHyN2SAs7YNRn++CXxqKNNnLcwpgmLOn188QYtdFZCyYbqff9Sjy7A0yvU94m8dDK3KdscrTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Qm4vhDrr; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Qm4vhDrr" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-78f056f928eso145950285a.0 for ; Fri, 19 Apr 2024 11:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550643; x=1714155443; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=YESm67M8BmJKsD3F1nymsp03dFHrE/Pl/wfnxNOqlTA=; b=Qm4vhDrrePwZSHkvtqd/WdyI/0cx8cstbmH8qI8ANGnrnr5qKcPu47WEUvprRcvDA8 VBQu3NIu0/di0h9Pu+BR0gE4ucB9Qlxm+h1VDRsUACUwKdiWQQXoybVOIW4XVFiOQCLG D5/gH23X6OdwhW9IAUNGhQ9nnrisPibfJhhh3+c149Y9EBavDa9LyrtrHvDokgX/Gtxg kL9qboWKQ1vdzt+E0+8FjHCqsBUSYo5L2ma6xAaGWS61bFQa3bWKSiN8Q8zwKxuYzfPQ Ps9U6vKYvKbdFGAOvn+4zvb5DRD7bTzZ+o5JkSLBhb0TvFh4/lghCiMlkrM13LLqGsoL J/gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550643; x=1714155443; 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:message-id:reply-to; bh=YESm67M8BmJKsD3F1nymsp03dFHrE/Pl/wfnxNOqlTA=; b=rgRKK+Rm5SZLWtFdvfDwh0VAX4/ocFXcZp1z4e8ulNFUnAZoRsTOLV334vbi3vfwgl TemwCCARxFz3VCSvQ/y+0AfO8i2QvDaXsm3sz7QYtJgX2RBsbLH+77e4TyDlvwrPDl2+ o6QHjCcdOK3EYrTj8K/VQrs27YINpX4WfU9q00Qxi+pkBLWM9jAoATQaIILpvHVbvAOk DYOS0bsTxhl8RXBmI4fhJImolLHdvokmqVKYws1RxoeStGyx9X3P2hXgKqS/zkGJcWMr h1eduSLtOydEUOtQC/xSWNoA0ffZlJxJdlp5ZrX9EZTrRaedDwSV+8HjAC7OLcX1M9M/ tHbg== X-Gm-Message-State: AOJu0YxFlBGT+P/GeaVI0D7KzehGclGwrGIRd5mb+i74T4Jd2wcJHeAo Gbw5mWtWinnqbWtDyuZdfDOimXl1Ue4ZKSE6lLHDIldtkfBURU2WKlM0wKuhGrrO/Pui2N2lWz1 k X-Google-Smtp-Source: AGHT+IFOZISiYk1mlHIbCJKCDbaSIHkbCo79HuXXOJBE8dBXFG0vftlHCn0rcdwqLj/mGDYg2mD9JQ== X-Received: by 2002:a05:620a:ecf:b0:78d:5b09:2a3 with SMTP id x15-20020a05620a0ecf00b0078d5b0902a3mr2936289qkm.46.1713550643046; Fri, 19 Apr 2024 11:17:23 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id de19-20020a05620a371300b0078ec3f23519sm1809510qkb.8.2024.04.19.11.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:22 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/15] btrfs: unify logic to decide if we need to walk down into a node Date: Fri, 19 Apr 2024 14:17:02 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We currently duplicate the logic for walking into a node during snapshot delete. In one case it is during the actual delete, and in the other we use it for deciding if we should reada the block or not. Extract this code into it's own helper and comment fully what we're doing, and then update the two users to use the new helper. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 135 +++++++++++++++++++++++++++-------------- 1 file changed, 91 insertions(+), 44 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index afe0694c675b..0f3c1ce27d17 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5227,6 +5227,81 @@ struct walk_control { #define DROP_REFERENCE 1 #define UPDATE_BACKREF 2 +/* + * Decide if we need to walk down into this node to adjust the references. + * + * @root - the root we are currently deleting. + * @wc - the walk control for this deletion. + * @eb - the parent eb that we're currently visiting. + * @refs - the number of refs for wc->level - 1. + * @flags - the flags for wc->level - 1. + * @slot - the slot in the eb that we're currently checking. + * + * This is meant to be called when we're evaluating if a node we point to at + * wc->level should be read and walked into, or if we can simply delete our + * reference to it. We return true if we should walk into the node, false if we + * can skip it. + * + * We have assertions in here to make sure this is called correctly. We assume + * that sanity checking on the blocks read to this point has been done, so any + * corrupted file systems must have been caught before calling this function. + */ +static bool visit_node_for_delete(struct btrfs_root *root, + struct walk_control *wc, + struct extent_buffer *eb, + u64 refs, u64 flags, int slot) +{ + struct btrfs_key key; + u64 generation; + int level = wc->level; + + ASSERT(level > 0); + ASSERT(wc->refs[level - 1] > 0); + + /* + * The update backref stage we only want to skip if we already have + * FULL_BACKREF set, otherwise we need to read. + */ + if (wc->stage == UPDATE_BACKREF) { + if (level == 1 && flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) + return false; + return true; + } + + /* + * We're the last ref on this block, we must walk into it and process + * any refs it's pointing at. + */ + if (wc->refs[level - 1] == 1) + return true; + + /* + * If we're already FULL_BACKREF then we know we can just drop our + * current reference. + */ + if (level == 1 && flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) + return false; + + /* + * This block is older than our creation generation, we can drop our + * reference to it. + */ + generation = btrfs_node_ptr_generation(eb, slot); + if (!wc->update_ref || generation <= root->root_key.offset) + return false; + + /* + * This block was processed from a previous snapshot deletion run, we + * can skip it. + */ + btrfs_node_key_to_cpu(eb, &key, slot); + if (btrfs_comp_cpu_keys(&key, &wc->update_progress) < 0) + return false; + + /* All other cases we need to wander into the node. */ + return true; +} + static noinline void reada_walk_down(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct walk_control *wc, @@ -5238,7 +5313,6 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, u64 refs; u64 flags; u32 nritems; - struct btrfs_key key; struct extent_buffer *eb; int ret; int slot; @@ -5280,26 +5354,9 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, continue; BUG_ON(refs == 0); - if (wc->stage == DROP_REFERENCE) { - if (refs == 1) - goto reada; - - if (wc->level == 1 && - (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) - continue; - if (!wc->update_ref || - generation <= root->root_key.offset) - continue; - btrfs_node_key_to_cpu(eb, &key, slot); - ret = btrfs_comp_cpu_keys(&key, - &wc->update_progress); - if (ret < 0) - continue; - } else { - if (wc->level == 1 && - (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) - continue; - } + /* If we don't need to visit this node don't reada. */ + if (!visit_node_for_delete(root, wc, eb, refs, flags, slot)) + continue; reada: btrfs_readahead_node_child(eb, slot); nread++; @@ -5476,7 +5533,6 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, u64 bytenr; u64 generation; u64 owner_root = 0; - struct btrfs_key key; struct extent_buffer *next; int level = wc->level; int ret = 0; @@ -5517,29 +5573,20 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, } wc->lookup_info = 0; - if (wc->stage == DROP_REFERENCE) { - if (wc->refs[level - 1] > 1) { - if (level == 1 && - (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) - goto skip; + /* If we don't have to walk into this node skip it. */ + if (!visit_node_for_delete(root, wc, path->nodes[level], + wc->refs[level - 1], wc->flags[level - 1], + path->slots[level])) + goto skip; - if (!wc->update_ref || - generation <= root->root_key.offset) - goto skip; - - btrfs_node_key_to_cpu(path->nodes[level], &key, - path->slots[level]); - ret = btrfs_comp_cpu_keys(&key, &wc->update_progress); - if (ret < 0) - goto skip; - - wc->stage = UPDATE_BACKREF; - wc->shared_level = level - 1; - } - } else { - if (level == 1 && - (wc->flags[0] & BTRFS_BLOCK_FLAG_FULL_BACKREF)) - goto skip; + /* + * We have to walk down into this node, and if we're currently at the + * DROP_REFERNCE stage and this block is shared then we need to switch + * to the UPDATE_BACKREF stage in order to convert to FULL_BACKREF. + */ + if (wc->stage == DROP_REFERENCE && wc->refs[level - 1] > 1) { + wc->stage = UPDATE_BACKREF; + wc->shared_level = level - 1; } ret = check_next_block_uptodate(trans, root, path, wc, next); From patchwork Fri Apr 19 18:17:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636721 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3525213C9B7 for ; Fri, 19 Apr 2024 18:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550646; cv=none; b=iRTrpbg9mgbMq0qka1PSGyIGl8kGZTmtnasz4DvTGqeTcgZAPJMpeeU/p379ReezIXF2OR0iT9AMxZzJG86RFuDIH3eC++TY/lAwvQkuWuzue2bX+GxGz9Nv9u/xlU/olTctnNouk2uOUOrkMRyCSPvmZ0UNqzn8n6jeWTOt51s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550646; c=relaxed/simple; bh=9V1jrNqGT4ZaVoFUuXe/yvpYV2aIif5YUidm2WO9u4s=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XGfEeALKkSQLlUzDvWC/apZwTa2HZlJiR/ymPOh+fGmB7fsC3gkM5pR4jFAPIWG7mMgTpAmaeqyY1K22hGTAbVKRJRYLqYwoGN0hDA1m4ugyD+djf8xu2dkV1onWiRYbfpLDVrE/+b1Y8y5G9WjeZ92ALTA9VPFB7vZx8p5KTdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=OCtfy1ft; arc=none smtp.client-ip=209.85.161.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="OCtfy1ft" Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5aa2551d33dso1360362eaf.0 for ; Fri, 19 Apr 2024 11:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550644; x=1714155444; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GCf7JUkjr9rRK3v84J+022TilJaTvc2e9eYvXNXyTas=; b=OCtfy1ftBA4ORmvTsrfAIZcqR1tHl27R+K95QJoN05CGYtljrQqE8nH8nNeelkcBPO YTLagEKcZkaNyqjI3aCsixRkmDgo6OEzGi0jGczVHG3xVjHcDP0WEtoKLw6pOS6fRBFq rnxsCRuE4pxjYbo6o2XENzILP2WC7rmiX6xjOzPXcPC5QqYFIiNq/3PNew6uVRQH4tMz KZxV2/N/eFj35jlJkB5PklB+2gW4Wdi2hQQ6EZtONZRKoCqAMuP2EpOeVBS5S/+cuJkH KNAaslAWYjKJrM8YnxQBzuf20aaznHesSOEqeLAWyqwgnVJgHecPx/EIxaF5GYzFHSuJ bZ+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550644; x=1714155444; 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:message-id:reply-to; bh=GCf7JUkjr9rRK3v84J+022TilJaTvc2e9eYvXNXyTas=; b=ur3IAOK1fetEO+H9ilnzCbKE24ideHpjf5PlJWZvjvCaYWZphkgt1CzCdYh2PokAqb tSXOfCLBQGWYT6DfWC9T1FTfpVEQUxtBZ9XlSEJUiDe7eKdtYX5epTGAVpma4+24KWrk B9aYzKXfdn7vToxPRMc7ixDf3/U84ICyFwzEhyPJUtzZc4KcUT5u0WbeceKf0V3kEfzO 2gXsiwuxX8/n0hVr7q7oLAK913c3KHoYP1C4iSeuQCkypyDURLnXJG+p743ddlCox35E aALAcgtia6OYcmcWmkLRZ4YSXXNoC1SmiboZKDxVOajSrSoNbbCb9lgaW7zdCzj/SCvP 2O0g== X-Gm-Message-State: AOJu0Yxc6M95qPIxN8wq00IQ0Qm7VKjpFGU+9pQKwgCi4ZDdmY/A8Lw8 0ukzbFgCIZGYixkDqI4M+5CUFjyqFJ3qwPK1+yospk8kyXfL+hf4Atu+8yHiVx8g+tn8eLKk0tw b X-Google-Smtp-Source: AGHT+IGaIuFiw9LUy/3oubU07vr5MZmFlmuQbZHmjkncNkU9JlWcuT81c/E5pLuGV2G5JfzJqGmW1A== X-Received: by 2002:a05:6358:5bd0:b0:17f:2811:921c with SMTP id i16-20020a0563585bd000b0017f2811921cmr3719626rwf.27.1713550644174; Fri, 19 Apr 2024 11:17:24 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id o7-20020a0c8c47000000b0069b4cc9780fsm1782512qvb.2.2024.04.19.11.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:23 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/15] btrfs: extract the reference dropping code into it's own helper Date: Fri, 19 Apr 2024 14:17:03 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is a big chunk of code in do_walk_down that will conditionally remove the reference for the child block we're currently evaluating. Extract it out into it's own helper and call that from do_walk_down instead. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 162 +++++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 70 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0f3c1ce27d17..17dabedda997 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5510,6 +5510,95 @@ static int check_next_block_uptodate(struct btrfs_trans_handle *trans, return 0; } +/* + * If we determine that we don't have to visit wc->level - 1 then we need to + * determine if we can drop our reference. + * + * If we are UPDATE_BACKREF then we will not, we need to update our backrefs. + * + * If we are DROP_REFERENCE this will figure out if we need to drop our current + * reference, skipping it if we dropped it from a previous incompleted drop, or + * dropping it if we still have a reference to it. + */ +static int maybe_drop_reference(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_path *path, + struct walk_control *wc, + struct extent_buffer *next, + u64 owner_root) +{ + struct btrfs_ref ref = { + .action = BTRFS_DROP_DELAYED_REF, + .bytenr = next->start, + .num_bytes = root->fs_info->nodesize, + .owning_root = owner_root, + .ref_root = btrfs_root_id(root), + }; + int level = wc->level; + int ret; + + /* We are UPDATE_BACKREF, we're not dropping anything. */ + if (wc->stage == UPDATE_BACKREF) + return 0; + + if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { + ref.parent = path->nodes[level]->start; + } else { + ASSERT(btrfs_root_id(root) == + btrfs_header_owner(path->nodes[level])); + if (btrfs_root_id(root) != + btrfs_header_owner(path->nodes[level])) { + btrfs_err(root->fs_info, + "mismatched block owner"); + return -EIO; + } + } + + /* + * If we had a drop_progress we need to verify the refs are set as + * expected. If we find our ref then we know that from here on out + * everything should be correct, and we can clear the + * ->restarted flag. + */ + if (wc->restarted) { + ret = check_ref_exists(trans, root, next->start, ref.parent, + level - 1); + if (ret <= 0) + return ret; + ret = 0; + wc->restarted = 0; + } + + /* + * Reloc tree doesn't contribute to qgroup numbers, and we have already + * accounted them at merge time (replace_path), thus we could skip + * expensive subtree trace here. + */ + if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID && + wc->refs[level - 1] > 1) { + u64 generation = btrfs_node_ptr_generation(path->nodes[level], + path->slots[level]); + + ret = btrfs_qgroup_trace_subtree(trans, next, generation, level - 1); + if (ret) { + btrfs_err_rl(root->fs_info, + "Error %d accounting shared subtree. Quota is out of sync, rescan required.", + ret); + } + } + + /* + * We need to update the next key in our walk control so we can + * update the drop_progress key accordingly. We don't care if + * find_next_key doesn't find a key because that means we're at + * the end and are going to clean up now. + */ + wc->drop_level = level; + find_next_key(path, level, &wc->drop_progress); + + btrfs_init_tree_ref(&ref, level - 1, 0, false); + return btrfs_free_extent(trans, &ref); +} /* * helper to process tree block pointer. @@ -5608,76 +5697,9 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, wc->reada_slot = 0; return 0; skip: - if (wc->stage == DROP_REFERENCE) { - struct btrfs_ref ref = { - .action = BTRFS_DROP_DELAYED_REF, - .bytenr = bytenr, - .num_bytes = fs_info->nodesize, - .owning_root = owner_root, - .ref_root = btrfs_root_id(root), - }; - if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { - ref.parent = path->nodes[level]->start; - } else { - ASSERT(btrfs_root_id(root) == - btrfs_header_owner(path->nodes[level])); - if (btrfs_root_id(root) != - btrfs_header_owner(path->nodes[level])) { - btrfs_err(root->fs_info, - "mismatched block owner"); - ret = -EIO; - goto out_unlock; - } - } - - /* - * If we had a drop_progress we need to verify the refs are set - * as expected. If we find our ref then we know that from here - * on out everything should be correct, and we can clear the - * ->restarted flag. - */ - if (wc->restarted) { - ret = check_ref_exists(trans, root, bytenr, ref.parent, - level - 1); - if (ret < 0) - goto out_unlock; - if (ret == 0) - goto no_delete; - ret = 0; - wc->restarted = 0; - } - - /* - * Reloc tree doesn't contribute to qgroup numbers, and we have - * already accounted them at merge time (replace_path), - * thus we could skip expensive subtree trace here. - */ - if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID && - wc->refs[level - 1] > 1) { - ret = btrfs_qgroup_trace_subtree(trans, next, - generation, level - 1); - if (ret) { - btrfs_err_rl(fs_info, - "Error %d accounting shared subtree. Quota is out of sync, rescan required.", - ret); - } - } - - /* - * We need to update the next key in our walk control so we can - * update the drop_progress key accordingly. We don't care if - * find_next_key doesn't find a key because that means we're at - * the end and are going to clean up now. - */ - wc->drop_level = level; - find_next_key(path, level, &wc->drop_progress); - - btrfs_init_tree_ref(&ref, level - 1, 0, false); - ret = btrfs_free_extent(trans, &ref); - if (ret) - goto out_unlock; - } -no_delete: + ret = maybe_drop_reference(trans, root, path, wc, next, owner_root); + if (ret) + goto out_unlock; wc->refs[level - 1] = 0; wc->flags[level - 1] = 0; wc->lookup_info = 1; From patchwork Fri Apr 19 18:17:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636722 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB94713C3E8 for ; Fri, 19 Apr 2024 18:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550647; cv=none; b=ZmjI9JLlpxtl6S0mS/Sy1gFoTzfbT0u4iI2DYoZ2k6o8LwQLVg9p2nRQNaETvVm+Je0EjYd77JFTJvVxrRppEc8JMZW7MUC8S67gIKD3iRGrHge2XSq21i1dZoSW4rF/jELZdMCKKD8T+OJmMqh5trLpND8TQlQOtME77m60iCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550647; c=relaxed/simple; bh=dyM6Q7FuZh2qz7JtsaFVML21R+zbmgVnIudXatb4pM8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kZj5XmEA6vjFxofAZQtiR2FAtu8oJn7UhL0Dvmrrj67clmRTJFRhdefEiZwvxwC3iSbiRKR0q8dYYA0bdomnlmAZKNspSuFq1pznY9nTRwALEnDaLGQwmIo+tRClEIwgI0RY2nNDeS6kcq6ZnaeJLocov8g/0SDiy/MFfeA8/vI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=U1sY1Xx1; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="U1sY1Xx1" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-78f0628da1eso144958085a.3 for ; Fri, 19 Apr 2024 11:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550645; x=1714155445; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QewteRjjwSIaiFQHtMZ+y+ny01dS+MURSIocHi0q58M=; b=U1sY1Xx1MRhYriHnRJwD5Ar5jqWJGHZr5WkGEnkvn6RUrfOHAL7iS+VTG/Q0XC/p/d xRrzkOL99ab14tvT1Ti1JbCx4HG9w6JqYT81ze/8UUdl5mnBu3lkPeNw922f3Np5FoMK XmPCfZ1ThVuA13/xmNliLMFK0bvFrPBV44QIxgjInKDxk8fHeR4feYsR4vp/VVU7Dl4c Er2f7V9uLBSxSx0bzmnSH0rlIWepGV0ehf8KVbr+WoCulh6jZWHi8Df5/Vl8ilG7C+M3 0+8eAQBffgoQSpKQ3f/mkpY8dkVENgtalmMwce2tyhnDF9k94Ul6B8go3h7DiLBJLWAC 4pdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550645; x=1714155445; 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:message-id:reply-to; bh=QewteRjjwSIaiFQHtMZ+y+ny01dS+MURSIocHi0q58M=; b=p8x8BE0fPgFou9KjlIym9KCd52A+dYKKolDko3PK6zc5ULYMCGJxQK67WZfImjoqMo JYkBLVY7hCn81ppotaBy5+T2PoW6CK2Z+SQPzzRNG59RNgIGNwT4xDtKaLT51XDYlVJB oOnvCyONWtsPiJXPd7Ymkd1NmIqy3aUIIpMPs9LycTcFhbpH2D7OfzCRrvr7hWlLf5V0 0zDRgy0ul5/z3fFgUKkzbF4H0z0/9lgbsscrMadN1bVjm11geqtV8P9eZdmJQMpwA2DF kMHVdF/mqRKowj0cFbQBJlYGBeodJo3KsoL+n4p6uA0TJUnh6y2uvnwKn322jYdLGdGb ykBA== X-Gm-Message-State: AOJu0YyR6FBy13wagPmpS52cXrK9feLtS5CTd/ld1wsE2VbWTv278QuX O/imU7KlmP+JevJTuVqn4+Zl5FxS1NLD2GsRLAIj05ehYLYAGdg1c8tuwXTxBeCMZ4WI1VYqZZF b X-Google-Smtp-Source: AGHT+IE1re+avLkgguPRpPYJAk9xai8qkh2Msq7WCGlFJIlDWEkmme5GhihICFBQrk3E+K3kgZTBug== X-Received: by 2002:a0c:f548:0:b0:6a0:5ba9:140b with SMTP id p8-20020a0cf548000000b006a05ba9140bmr3045314qvm.9.1713550645549; Fri, 19 Apr 2024 11:17:25 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id h20-20020a0cedb4000000b0069b1ed91846sm1416846qvr.143.2024.04.19.11.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:25 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/15] btrfs: don't BUG_ON ENOMEM in walk_down_proc Date: Fri, 19 Apr 2024 14:17:04 -0400 Message-ID: <1d39470100d7101a6fbac12de8fcf8de519ef7cb.1713550368.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We handle errors here properly, ENOMEM isn't fatal, return the error. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 17dabedda997..61bea83bce19 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5399,7 +5399,6 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, &wc->refs[level], &wc->flags[level], NULL); - BUG_ON(ret == -ENOMEM); if (ret) return ret; BUG_ON(wc->refs[level] == 0); From patchwork Fri Apr 19 18:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636723 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC76813C9B7 for ; Fri, 19 Apr 2024 18:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550649; cv=none; b=AdWBebi+bFWSyBOHV/d5VKNS/AZshEwpNOMkL3lxNR5tINRHML22o8Gx9dBsW8INzjOxKyLTbTvtnd1JlnDolIKkvN8p4qlia0xrL996FAY3vnTMvk7lAewNygRdcWwcgyi1wsU5WxwXz9pGOXIIQAzGuAuFHh1Sr2cGMtQ6e/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550649; c=relaxed/simple; bh=dWUwkeSD2ngjlmK64WCexJYjjB9mGk98X+KUg+2m8To=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fEibqt62pjgkDixM203NSM5TYYKPzIwLviFjuPEpJFF9i9Usf0kM48haqXKH5PKpZvGPkVgLQVitGD7+ghLDO/BE0S28dUDLJ6gi19mc91qmnycgvryhdPJZxXciQKQ1STU5ZpV0+Zj6+WafhYvwBxCJiGSBGPhtqf40k7/9GOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=FkvnaW1m; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="FkvnaW1m" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-69943ef42b2so14783896d6.3 for ; Fri, 19 Apr 2024 11:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550647; x=1714155447; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ds4i5mh0AtvV6PFQ7dse4dofkPX0LJnTwJVG6mYTFq8=; b=FkvnaW1mOFNOuDUX1QmHvK7gmlO6Ot+z0jfjybSzbZDmYMNZm/0A46z2nlLSlA7nLr wqbb1LQHbZGGrFXTP2NKtiIZm0o/IT9XM7XLQOeN02e0H+C8V+hTLcoIvkDZMX4zsJCE EngGAP0ekNW5tMA2pDGR4zaJaGUQcw8or68VgFlo7kmzKNuZOxkKfdlCtsR6PvIpXPg7 5Bl/fAB0bpPR6JnX7TMCQmBtWfDoeMlQ/H/otH+QaFjz4ZKyQ0em02a/fRE2DryaVK+S Cm5lH1qR2mMEK8nPT/HkIlnuRhXEw7SsKUYhP9vZMHtjVM6Nl1+htgOgpea9Wk0V/285 eePg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550647; x=1714155447; 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:message-id:reply-to; bh=ds4i5mh0AtvV6PFQ7dse4dofkPX0LJnTwJVG6mYTFq8=; b=f77jdrAkcunsAzbsEWgsJQ63jJOzIHpQ21ek01ETMIsAf0U04x1U+MhhVNR3yVY/SN TWg11y6/XEqDbatMpMXv1PZESHtkhhTSIFX+4fM/XWqXDDlygcq/j0ezs0qfBiO6wSP3 kDAD0CV7Pf4EBG4zySIWywQTr1W51KIw6jhxsnVNQUecTYIVatksVsrkw2NJkwLEX1Vv jgJ3W3xkyRyx+l/gXpNICMqbiXxqs4sclD0tg2xC0v9AdWjPTnVWaaWUZPmCXdgSQBkK 71I/iN9HO89P0T7hLIqBcOo7/S/xYH8I/KZNmdPRsnUje0ZplN6dP2dyK6Sw8dvfq/6v 5J3w== X-Gm-Message-State: AOJu0YynKF9cqrpPRaZSYz/0J7CZfUVm/Cvw6Fz4NLImZIJOdO4DWitL OdSiCukgs6yVJLKmfz8fqA/10v1dOkY03q8F2v+Z46tlvyQ1voD19XtA13eU9nFSi5Z/3PMMDwY O X-Google-Smtp-Source: AGHT+IGQNA9qkE7TtcDC8tUR1jBtNNIlxUfQMdeWJTU4fbZKSABfsuRvA0zdW+oIKCm4BBLR4qajXA== X-Received: by 2002:ad4:510e:0:b0:6a0:59e6:a3ff with SMTP id g14-20020ad4510e000000b006a059e6a3ffmr3166985qvp.12.1713550646671; Fri, 19 Apr 2024 11:17:26 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id u10-20020a0cdd0a000000b0069b60baec46sm1708302qvk.146.2024.04.19.11.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:26 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/15] btrfs: handle errors from ref mods during UPDATE_BACKREF Date: Fri, 19 Apr 2024 14:17:05 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have blanket BUG_ON(ret) after every one of these reference mod attempts, which is just incorrect. If we encounter any errors during walk_down_tree() we will abort, so abort on any one of these failures. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 61bea83bce19..889e27911f0c 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5419,11 +5419,20 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, if (!(wc->flags[level] & flag)) { BUG_ON(!path->locks[level]); ret = btrfs_inc_ref(trans, root, eb, 1); - BUG_ON(ret); /* -ENOMEM */ + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } ret = btrfs_dec_ref(trans, root, eb, 0); - BUG_ON(ret); /* -ENOMEM */ + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } ret = btrfs_set_disk_extent_flags(trans, eb, flag); - BUG_ON(ret); /* -ENOMEM */ + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } wc->flags[level] |= flag; } From patchwork Fri Apr 19 18:17:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636724 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 100CB13C3E8 for ; Fri, 19 Apr 2024 18:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550650; cv=none; b=pSpHTAq/bGEr0Bk3+1pI2xTzDLiLWh7QwZJNrDEhRDNKBbTkVj3PClk7GnYPSb/U5zF9aNz+rytJXMyvElGLAajU4rurS6c9G8cpR+v3MwYrZA9KVzc/zhYlqtTe/WDh2duSeB9eOENQVo1L6XqJrBdQYeGsVNgP/BhqVRBQovM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550650; c=relaxed/simple; bh=kfeMEiRytq3vpjK7OzHldK/rtKP/mp24qM3MnRiQk2o=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EPjRkjWifDN+790+Mq9RMaC/WPgzAS+FLoHdwU1Gqx5L9GYSugX0NWbu0M4CWWFrOAROPljyLLLHs6Qxxaggs4ew97nVHl15YDveqvQvtNI6VTTqMmB8KdMqR406J4L+SvFjmxaHz5l9HZgibFvIHEgItTNC4W814+cSGju2s7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=xIPam/Bh; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="xIPam/Bh" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6eb7b6f92d4so1362987a34.0 for ; Fri, 19 Apr 2024 11:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550648; x=1714155448; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xZtEfhFX3Urpiq626sdyXwfakzghak+oAYfCpY+UyvA=; b=xIPam/BhNQiEw65nbwm1isaeUsalspaThZpEc8wBt6M1LEuB9ft9A4iv0dZLu0Zf14 RU4i+u0En9ewf6EZvx+ykyexFP1zXSks5uX4N5Xa7owkUuROBemn2OOu9zF21ccT3Ef3 TRYC2vGFikZdGvmP2VVSLZ2N6J1drTe/vQ3u9JmA90XIgCwTN1EsN08qh7ipB5Mx2z5Q GA8HV6x2QNp3YGGbLFHajc3JpwXeqTL5C+t+f6pD6rHdKGXKJRxYUMWDxSV1oiJYwhDv kSA5xs/oHtTBMB8nHw/rZx1+fEOn4LRM984A846O6L+23ZBAvf0r+fkoUzhZpR5XpgON EPLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550648; x=1714155448; 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:message-id:reply-to; bh=xZtEfhFX3Urpiq626sdyXwfakzghak+oAYfCpY+UyvA=; b=HwqHE3waC9Za9j2IXdeO0YekGtjfI1pXJRkhpvPZQU3nhJ0JM6J3jGfZt2s1hilA5v B2Sf4RbmHMTy/MEIuBIH5HmAYodIrY5MIg1aUkcrOYx2T/NkspQUSDwNoWoSG4lskT4c IhP7d1S1QAStADtlgDAAyQ/Q8hSOxCK8B9q9rGNJ9hu/VrvPCGnt3WrxLmDpY16JZgcG tfxcSdJ6lfiiH+f5avRbzEQXX1dYTDtnC0eYdSu514OY36Q1E1VBrCERgPw2Qq0/G0qD zJHCOTR7yKNhJ9m5IMGxMJw8HunTAssPQQHQZ3pdSYkboUKmA0HP6wCLJJCrsTNEWuIi RCcg== X-Gm-Message-State: AOJu0Yxz28w7hknD2b6QmbtOmwyEsO0Plc7gdZ1p0hwYrxi33zwVN5pz R6JxqXtnPwtTzHvbLm67Khrg0Cg58SRRdMNfU8kV69+FwTrU3FIhm1qoMMmcwxW7ZLBd4YXAQ6L E X-Google-Smtp-Source: AGHT+IEN2UkUj4uanHryI7xMz1WbP1qmtrlbiIOS5ypqbF+LY3btMvO3Agv1YksSK1DnxKWUuJ882w== X-Received: by 2002:a05:6830:d2:b0:6eb:ca3e:e2a1 with SMTP id x18-20020a05683000d200b006ebca3ee2a1mr3094678oto.6.1713550648122; Fri, 19 Apr 2024 11:17:28 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id bi39-20020a05620a31a700b0078d66ed5e41sm1787371qkb.131.2024.04.19.11.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:27 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 11/15] btrfs: replace BUG_ON with ASSERT in walk_down_proc Date: Fri, 19 Apr 2024 14:17:06 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have a couple of areas where we check to make sure the tree block is locked before looking up or messing with references. This is old code so it has this as BUG_ON(). Convert this to ASSERT() for developers. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 889e27911f0c..43fe12b073c3 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5393,7 +5393,7 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, if (wc->lookup_info && ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) || (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag)))) { - BUG_ON(!path->locks[level]); + ASSERT(path->locks[level]); ret = btrfs_lookup_extent_info(trans, fs_info, eb->start, level, 1, &wc->refs[level], @@ -5417,7 +5417,7 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, /* wc->stage == UPDATE_BACKREF */ if (!(wc->flags[level] & flag)) { - BUG_ON(!path->locks[level]); + ASSERT(path->locks[level]); ret = btrfs_inc_ref(trans, root, eb, 1); if (ret) { btrfs_abort_transaction(trans, ret); From patchwork Fri Apr 19 18:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636725 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6860213C9B7 for ; Fri, 19 Apr 2024 18:17:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550651; cv=none; b=cC6o8B79Vej3QzJmjUJWMNyVSd/m2sBGQPJf3qMZqPTYKyyYsoeMqwofx43i7YIii1voWgAiluCCRDwda7lmI3UEZUYhMsvaIVueBW5PcXhtmX8sUvhNpxC07j3Owjs9+MH+JIv2eiSqpL4Y+OdpKJnSfzioyP4j0Pn+vhdW+no= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550651; c=relaxed/simple; bh=w9YYDmwT2t1cyTuhVadO3n+9GvwlS68P2kzxVirEPqA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jnn75xD2LzrZFDkjDNEioHCCWmL/NQKdsZYr7otybLO319JUWhAJvpmuvVWdoVwbNcwr2fQGq8BOW8ciVNYh/+Ob6kA15Enm2NybwXMCaRaWCT6aSGTGCOSm1XtKFmkJCgdP+dQzlGxGFtx/JePckTyjwsmAAW7apz6ZtF71jlE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=ne0+DCzJ; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="ne0+DCzJ" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-437a660c94fso12500161cf.1 for ; Fri, 19 Apr 2024 11:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550649; x=1714155449; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kml1FXGdCYQacK4u/UcOEpFthQUNLf77Zonk3NRyEhQ=; b=ne0+DCzJs9MjF6Z2AtGP3yX2mGZOaCPolQ6pk3qJuHH+R6ql4VvCeg75snCnd2JUnE 6npNKobmm09peP+vsAtkD+v7e8QddCTVcevRHKM1r0HrhTcawnq3dodjgZI058xJbEPZ MdM1QSU/W6zC3zADRLoAJX5ZEQCTXvGJo5J+7NxkQbFxQTBhJQNRViwY3q2Z3T4+saoo p8KOaCh0GFNB5C5BextfnNG8QQLayUHX1shEfP7eQSX7FsVz9A41zQtLQDYdY+rEPcnO NlgybsaiVmAweV7Jc/n6Mv37esrQDCY/EJ7+DjAcAKvRhvkutp+cxwfFQ9OMFC36raJF THFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550649; x=1714155449; 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:message-id:reply-to; bh=kml1FXGdCYQacK4u/UcOEpFthQUNLf77Zonk3NRyEhQ=; b=GKhQ3vvna+LrZ7psKsg6Gd+RDvmIxCiorG4H0QWqdtkA5KVV0Niyvoep+Zb1pHuiVk t9hczFk89GzGtj+zhD95PNPRmSHC6pAhnaCgstBjxmW0xRlDszYm/YusRCna1nhNs5YB DjiEq9jDsyk/Y6SVtAWA1EeBGfqPMSteDHZk/1wHO/H6dyy1X6Dp49b6K5/uXctxqbLY sd98RqCh4ztUIdq88aaGhFrsNXz/HDye1ayxO+jYIRHGBDR8nAaykdfcFPkn3jeCxUO3 VM/s6jMJsYBHia+dAHXjxY3WbsB/5xa0dIeswMYD9D34g8fZg8Aq4FK71vrRm5E/GNg3 XJCA== X-Gm-Message-State: AOJu0YxuLk8POtpvRVi1ihegJu4dknDQj31ebTYUrtR8gl+aJDAqRQ9z jsjI44pBu4YqfclpcItoCt8YRX8BPBLd7kz1857emrT44eAVb8YQ8JAHKHbz7OEZVKPCUGgeOEj U X-Google-Smtp-Source: AGHT+IE83m+9sxqzAWF8rkbdtGG8CpbafXpr7WxP1hsNfS5TDhev/1ePYav4OijhwEDybNMy/wm5DA== X-Received: by 2002:a05:622a:118a:b0:437:acca:c682 with SMTP id m10-20020a05622a118a00b00437accac682mr3214938qtk.30.1713550649276; Fri, 19 Apr 2024 11:17:29 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id o10-20020ac8554a000000b00434a352e239sm1798708qtr.43.2024.04.19.11.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:28 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 12/15] btrfs: clean up our handling of refs == 0 in snapshot delete Date: Fri, 19 Apr 2024 14:17:07 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In reada we BUG_ON(refs == 0), which could be unkind since we aren't holding a lock on the extent leaf and thus could get a transient incorrect answer. In walk_down_proc we also BUG_ON(refs == 0), which could happen if we have extent tree corruption. Change that to return -EUCLEAN. In do_walk_down() we catch this case and handle it correctly, however we return -EIO, which -EUCLEAN is a more appropriate error code. Finally in walk_up_proc we have the same BUG_ON(refs == 0), so convert that to proper error handling. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 43fe12b073c3..5eb39f405fd5 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5352,7 +5352,15 @@ static noinline void reada_walk_down(struct btrfs_trans_handle *trans, /* We don't care about errors in readahead. */ if (ret < 0) continue; - BUG_ON(refs == 0); + + /* + * This could be racey, it's conceivable that we raced and end + * up with a bogus refs count, if that's the case just skip, if + * we are actually corrupt we will notice when we look up + * everything again with our locks. + */ + if (refs == 0) + continue; /* If we don't need to visit this node don't reada. */ if (!visit_node_for_delete(root, wc, eb, refs, flags, slot)) @@ -5401,7 +5409,10 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, NULL); if (ret) return ret; - BUG_ON(wc->refs[level] == 0); + if (unlikely(wc->refs[level] == 0)) { + btrfs_err(fs_info, "Missing references."); + return -EUCLEAN; + } } if (wc->stage == DROP_REFERENCE) { @@ -5665,7 +5676,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, if (unlikely(wc->refs[level - 1] == 0)) { btrfs_err(fs_info, "Missing references."); - ret = -EIO; + ret = -EUCLEAN; goto out_unlock; } wc->lookup_info = 0; @@ -5776,7 +5787,10 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, path->locks[level] = 0; return ret; } - BUG_ON(wc->refs[level] == 0); + if (unlikely(wc->refs[level] == 0)) { + btrfs_err(fs_info, "Missing refs."); + return -EUCLEAN; + } if (wc->refs[level] == 1) { btrfs_tree_unlock_rw(eb, path->locks[level]); path->locks[level] = 0; From patchwork Fri Apr 19 18:17:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636726 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 561A413CFB9 for ; Fri, 19 Apr 2024 18:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550653; cv=none; b=S29gxYfrRwwx/TpQpYyzm/DkhOYSG/bFQbqjarMLobcB1E2Boqon6GwiEOqoVNe8tdqa+62V7JjBSoQDFdFrcqu2vMrRJExbkk6PB64uqYuG/T9F6ExxCg7aD+/Po6kDKKCtx2AJGedL4QJvDn8+qaBm8XxLjqMNMlODiKh523w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550653; c=relaxed/simple; bh=zNwsJO4RReHMEO+kXEi5z6GIb8b3QDhI0tBj5Qsgqf8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kB7KhhJYixFejyP0hsUclzjLK02y9MO56STv6b3y24tM6L1Gf3fRTHpY+SAcpFPd+oVJsJNs9447rq37dQixsjJToFW9Y4eMG3oHMyFMfOzU08/l06dsAuFl+2bcV8GQWwOyjaB0dhqMwasnb6otRLGrkrloOJC4yZbVHmQO5Rw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Cq103nMC; arc=none smtp.client-ip=209.85.167.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Cq103nMC" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3c60adf3474so1453112b6e.1 for ; Fri, 19 Apr 2024 11:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550650; x=1714155450; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=L7Qup1YQZSsagIf8Cv6SwXyCxu5zOUCz8W3WQpzckZM=; b=Cq103nMC00wXlIinIvchGnlXqKZQsR8kYBGtizQ9MIn7TuBpJl+JMokjuFXiM+vg9M NZfL8ChZ77s99zutVsGvvfy8qBddAK+nt07annIWqr2nydcry8A/5JKJYQzpAe/mgXpB 7kNBliP15KEvqBGZ8lVzxxNm4JbVAIKd5a+ptPHQSH+0MW5MAqpWg+9wqcyeMHtG44hL k7/tLzbnlqmaD+uwIr1mtGigvYZBn3lJoHkeq6Bt/r/7BtLnz3DEPt+IdTOoL9zRevgT fEORR8bqkvAdC7s9+ibI9QXWzv6TDHTI3uAxSf7zCICpwC26doal1JJHfjlj+SszmCND uFeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550650; x=1714155450; 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:message-id:reply-to; bh=L7Qup1YQZSsagIf8Cv6SwXyCxu5zOUCz8W3WQpzckZM=; b=HLsM5vlnBEsgKw/W9NXpNUGLruTPQcXinfyZsY9SAKNcxjObEsj4Iw1hBUs2LUGe9M ApmKrkbcGrjWlgvZGY6tfm4AAEdNZrmMeLl2nkPK37bqycn+66taH7qFsq71bA3yVfHo DLEAwj0DYIKyAzze8kRvU/KqQnYU7sKGBswrGhbbN9m00+ApmJn49UIZxWOouAljoMWJ 5wIBbGW8ceUklw3KCZUoT4xZMJif1UsiyzMEWvc0fgaOeXoKGjtcqJD3a3JvplWcpIdc SSJoBXhgfFmgtBIqgXOw9FDeD7i+34BeiS0coC5EFUYrxOXjnfmrnKIc5AxFMB8wLxNC ywPA== X-Gm-Message-State: AOJu0YyDBSsC5+xiE7OzW6uByY7W8gFJA0Dg0ah/7vB1DBzUzVFlz+eG KZZ8nptqawYTT2m+l3XGhodZcbDKd+tSIGtOGGiJAzHMaDumi2jxV7JTDTb2LpzwXI6W9Fmb+OL c X-Google-Smtp-Source: AGHT+IEr36kwHiwY8qRYI1lZg13belw7AD7HTkV2NgR99yap4Uc5j7JFapTfmCvJUTkN45sFf8+yyA== X-Received: by 2002:a05:6808:3c4:b0:3c6:f7ce:babd with SMTP id o4-20020a05680803c400b003c6f7cebabdmr3419471oie.44.1713550650386; Fri, 19 Apr 2024 11:17:30 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id k8-20020ac86048000000b00434efa0feaasm1786984qtm.1.2024.04.19.11.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:30 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 13/15] btrfs: convert correctness BUG_ON()'s to ASSERT()'s in walk_up_proc Date: Fri, 19 Apr 2024 14:17:08 -0400 Message-ID: <118364bfc6ec45c519fe92949820eff8896d0837.1713550368.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In walk_up_proc we have several sanity checks that should only trip if the programmer made a mistake. Convert these to ASSERT()'s instead of BUG_ON()'s. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 5eb39f405fd5..d3d2f61b7363 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5755,7 +5755,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, u64 parent = 0; if (wc->stage == UPDATE_BACKREF) { - BUG_ON(wc->shared_level < level); + ASSERT(wc->shared_level >= level); if (level < wc->shared_level) goto out; @@ -5773,7 +5773,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, * count is one. */ if (!path->locks[level]) { - BUG_ON(level == 0); + ASSERT(level > 0); btrfs_tree_lock(eb); path->locks[level] = BTRFS_WRITE_LOCK; @@ -5800,7 +5800,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, } /* wc->stage == DROP_REFERENCE */ - BUG_ON(wc->refs[level] > 1 && !path->locks[level]); + ASSERT(path->locks[level] || wc->refs[level] == 1); if (wc->refs[level] == 1) { if (level == 0) { From patchwork Fri Apr 19 18:17:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636727 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 880D513CFBE for ; Fri, 19 Apr 2024 18:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550653; cv=none; b=gAwuGxD3x3EIAlkWrniKktyaynlnyTGomk/Yquml/LNGqreIgLfmsPRnPiGWVVqU6j9deYsnkJo9wkGMDjM6AAda7Bfm/VvTJ90BfLpdMpGGGYLpK+Zjo2fDJHU6vzMAVNJv0OocH+iwMFR8PxOCjJIRpNcKkCM3Mh6Gygo0DaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550653; c=relaxed/simple; bh=5ThSzafXlJ0SeYuBY8QIChqvYKSd7NAUQu2VAkoTE4U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dl67+xU2N6HfghDhO4lLl9K/hLAZDD7tcqThug6GStsp1npk56QZGvf8a9lsMqlBIofEzP2Y9cgBngXKeclZqVCqEKvmKCFsA/b8YwiVWtiW3twcG1cjHSYzIXeYIg3MkSwU10PhGYRtQigjIwTPH0b02+5FnZV19+X+6ECTt4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=dc7RDby1; arc=none smtp.client-ip=209.85.167.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="dc7RDby1" Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3bbbc6e51d0so1379695b6e.3 for ; Fri, 19 Apr 2024 11:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550651; x=1714155451; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=znahDsmr3ypRHAWUU20B5AwgcnzUuYeAuBAUcPbrJXE=; b=dc7RDby1bBekqCXe0VNLQEP13Zg8t6ApP5fG5VFP3vRT9fCHzRZOhFHmwDNTWgnkOP ggLtTQtqVt7TppjY89EreDKInxl8+dx1/tfEf2+187oEi6c5nD+oLuLGj6zlbDyKd/fr tfpzbSh7Wc9CdEB3znrpH2PhvM3qHlFTzH6hJdiFVTxbtseN3At9IPUsQ/hu9eVt4cc1 /URf2V2t+RXCZrY7DQYd2Tzijo2Z146uRyD6ke3bwK1y+0kXua+MObTw+8pt9isJpOxd EUwG2VErPK0lxy3NPSNscWluvDsCcjn5mgqWe3wI1jeWXdJ3VtFWAlQEUa12GHzxFVMK sndg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550651; x=1714155451; 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:message-id:reply-to; bh=znahDsmr3ypRHAWUU20B5AwgcnzUuYeAuBAUcPbrJXE=; b=jB9iFFdCTBlDD1llGEmcHN7d74gmG5IL9LLAku/TVSmIxhgjmyF/eUPfN7sqWYBSai Lqx76v01TkwOZ40S1QDNi70ZObNpxO2DZpvM9taZVRvZR8TVfYcO3fUVBsy+vr7O3+vv zY78QhjIQE/dwijbiHNcPZukVnvHypcL5qNRU2/9AMdMz2ZvsCPHeYr3QAW+rJ81wdbH xkdDnSsKggJtnRXb5eZ2PYY41Hge601RaF0pwPRF3Oq6q72HfXtclgyUISOehOjxi3bV S7R7gN5juYatnwUu1VUhLI9sVFxxOz0jjDaXc0zwALEHatpCQFImKEDPtubj3vBUy1sW opuA== X-Gm-Message-State: AOJu0Ywhn6JcyGbbBuxgC+KWnMzb4ZNz2eHoOIoCkCMmm60sfcL4uQot twVv4bSyewfJzSKa3XSwivclXNZx0nPHwud+yQIi2Q8FWJkMUGekxpnAnqp2Rv3FjuOx3Ay25nd X X-Google-Smtp-Source: AGHT+IG489r65Yb0Kh1BvXd9wRp0ttSbdY/vw02oMrWI5IRz35Dn0z96WWLN3lA/vweGuf2H3eZ2Dg== X-Received: by 2002:aca:1e0c:0:b0:3c7:4b08:e6ae with SMTP id m12-20020aca1e0c000000b003c74b08e6aemr2062712oic.40.1713550651559; Fri, 19 Apr 2024 11:17:31 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id b6-20020ac812c6000000b0043769a2d3d3sm1781691qtj.78.2024.04.19.11.17.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 14/15] btrfs: handle errors from btrfs_dec_ref properly Date: Fri, 19 Apr 2024 14:17:09 -0400 Message-ID: <85733fb309238393fbfb60dd4c2d88ca3becbc37.1713550368.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In walk_up_proc() we BUG_ON(ret) from btrfs_dec_ref(). This is incorrect, we have proper error handling here, return the error. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d3d2f61b7363..0f59339aac5d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5808,7 +5808,10 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, ret = btrfs_dec_ref(trans, root, eb, 1); else ret = btrfs_dec_ref(trans, root, eb, 0); - BUG_ON(ret); /* -ENOMEM */ + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } if (is_fstree(btrfs_root_id(root))) { ret = btrfs_qgroup_trace_leaf_items(trans, eb); if (ret) { From patchwork Fri Apr 19 18:17:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13636728 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1916A13D246 for ; Fri, 19 Apr 2024 18:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550655; cv=none; b=ALvAo4fxRTtQn+Idi4E5/rChA9VN3f66YkjzKIh2XYhY/5aNDROwfa6paJj3ETcGbi1FYIqKFZ10lzmaAnzyLbN3/c9+cwqs/nZtuaBVrD/QgyegPjL1lF3nQkCvtOiVzfPVx2Qi+I3ICnfTR1bYlNU0F4f+aSSoXCGTsD5DB8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550655; c=relaxed/simple; bh=ReeWvP5uMAIh35C4wvBNEaAZX4+zA90ZGFbTWPRZ434=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gkeXpnffNsHE+kN5hOqoNvKjVDsGSls2YgPubxYGn5bCNdCn9zlCVJ6j5JckYTmd9gGzAq5MlSwsS3TMfQuMA1MEmdNKcDm7/n/UwV2YMfFwmYW3ks0pERydtNJGs6gMo0jaOJahY349FYDKZREAE6OvdyDeR+3fEGmX+Ze08zA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=STuaWApr; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="STuaWApr" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-78efd1a0022so162612685a.3 for ; Fri, 19 Apr 2024 11:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713550653; x=1714155453; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=tI5PnXeuUMCrMlzsmarziyIL4iNGvtZYhcWqRvcIj0U=; b=STuaWAprsy3nWUkSyTwaMRdl/zhHboidESawskkeJmaNM6cOzP7dXIISVZxUmEHaRa YKaBZZFPB+HBN2PBlMjqMMNZGUEZedXZgbVaKZX6cle5esdA5Z5l3U+Yc2THJw9KOhHd +m4XrVKcOOcQRnuUR3OlviVKn59qf9jXZ9YO0jlej/TQF70YOy/nzhxvp/mkxBuitcME YGvX3MAl8EJ7xY4jxp0qubv1wA1Me5w8uzvf08Waf9PnCuIubALtYUpm+/IyZJIPnatx q/ZmBM5MME5Nu6Hngv9xA2Tq+k+FwgmVYf0vfPUzEUX90a/SK+ULUdPoLbpgxdgfRO9K TeWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550653; x=1714155453; 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:message-id:reply-to; bh=tI5PnXeuUMCrMlzsmarziyIL4iNGvtZYhcWqRvcIj0U=; b=grRXVw3fJkOhX59796y+lcmXvddObjvPPYDpUuCTAfIDnwUkzYLzFjxfEQ38IUWZjg c2YSy1ig49XwumfCKAP78XPx8bSXf4D95TUOGJvBxWQDgWyWwqnmEklhpgQXs6/jSqrv J4yj7PvIs8DsW9R0a/+7/5cICVjCGeR75xUnMGJ825qWXo2+aNLGMfLn2wfbbYxZtmb6 g7qRpDFEDUvVE7RKY+xDHWp1rjcdrW2ptGIoNVakEQsqe+NBNgPz4Z41GvvltLrJ18U/ ZO+ZufgKkQrBM4r5stHrI2uZ+/bODqXot3bihIVwhbnohKq4L1e8+7RzbbsQW+69CXJy NHpw== X-Gm-Message-State: AOJu0YyN3vJcKh3MqO6HsFwbrqMc2xvXo3rGj3kX4QQStc7xzG0rqZ60 lea9RJ77H2XF0BjwVhtAopYamiv9S2ki3erdFR6tsBWXIERdsC4KrZP55TBsEBByosYeFRbh8mt 5 X-Google-Smtp-Source: AGHT+IHgNDuCBLQ6YbN3/mPsdvsr3JVE71hjwC+aoUoE8SgHBeIRGsAfadd6du4WlsHynaxshxGFwQ== X-Received: by 2002:a05:620a:1998:b0:78b:e7ed:2a08 with SMTP id bm24-20020a05620a199800b0078be7ed2a08mr4110926qkb.41.1713550652743; Fri, 19 Apr 2024 11:17:32 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id u10-20020a05620a084a00b0078a04882ac2sm1797625qku.53.2024.04.19.11.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:17:32 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 15/15] btrfs: add documentation around snapshot delete Date: Fri, 19 Apr 2024 14:17:10 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Snapshot delete has some complicated looking code that is weirdly subtle at times. I've cleaned it up the best I can without re-writing it, but there are still a lot of details that are non-obvious. Add a bunch of comments to the main parts of the code to help future developers better understand the mechanics of snapshot deletion. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0f59339aac5d..83be60f60422 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5224,7 +5224,20 @@ struct walk_control { int lookup_info; }; +/* + * This is our normal stage. We are traversing blocks the current snapshot owns + * and we are dropping any of our references to any children we are able to, and + * then freeing the block once we've processed all of the children. + */ #define DROP_REFERENCE 1 + +/* + * We enter this stage when we have to walk into a child block (meaning we can't + * simply drop our reference to it from our current parent node) and there are + * more than one reference on it. If we are the owner of any of the children + * blocks from the current parent node then we have to do the FULL_BACKREF dance + * on them in order to drop our normal ref and add the shared ref. + */ #define UPDATE_BACKREF 2 /* @@ -5855,6 +5868,27 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, return -EUCLEAN; } +/* + * walk_down_tree consists of two steps. + * + * walk_down_proc(). Look up the reference count and reference of our current + * wc->level. At this point path->nodes[wc->level] should be populated and + * uptodate, and in most cases should already be locked. If we are in + * DROP_REFERENCE and our refcount is > 1 then we've entered a shared node and + * we can walk back up the tree. If we are UPDATE_BACKREF we have to set + * FULL_BACKREF on this node if it's not already set, and then do the + * FULL_BACKREF conversion dance, which is to drop the root reference and add + * the shared reference to all of this nodes children. + * + * do_walk_down(). This is where we actually start iterating on the children of + * our current path->nodes[wc->level]. For DROP_REFERENCE that means dropping + * our reference to the children that return false from visit_node_for_delete(), + * which has various conditions where we know we can just drop our reference + * without visiting the node. For UPDATE_BACKREF we will skip any children that + * visit_node_for_delete() returns false for, only walking down when necessary. + * The bulk of the work for UPDATE_BACKREF occurs in the walk_up_tree() part of + * snapshot deletion. + */ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, @@ -5887,6 +5921,24 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans, return (ret == 1) ? 0 : ret; } +/* + * walk_up_tree is responsible for making sure we visit every slot on our + * current node, and if we're at the end of that node then we call + * walk_up_proc() on our current node which will do one of a few things based on + * our stage. + * + * UPDATE_BACKREF. If we wc->level is currently less than our wc->shared_level + * then we need to walk back up the tree, and then going back down into the + * other slots via walk_down_tree to update any other children from our original + * wc->shared_level. Once we're at or above our wc->shared_level we can switch + * back to DROP_REFERENCE, lookup the current nodes refs and flags, and carry + * on. + * + * DROP_REFERENCE. If our refs == 1 then we're going to free this tree block. + * If we're level 0 then we need to btrfs_dec_ref() on all of the data extents + * in our current leaf. After that we call btrfs_free_tree_block() on the + * current node and walk up to the next node to walk down the next slot. + */ static noinline int walk_up_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path,