From patchwork Tue May 7 18:12: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: 13657532 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.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 BD88C16ABC7 for ; Tue, 7 May 2024 18:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105548; cv=none; b=RNzWYACCJALazM7u2L8lPn76GuvwT6GIuAtNDUgQ4AT+NAmnCroVFe0cz2CagBz6ejuYLLiHuYv4iMQHd4THbVXJgECbrElRw9ankQHa/UUorA61GEIcG19Klb8XVnBGEH7x1X9Cjbk3kkgKRWhKG+msv7fs0rcSQ0QHi6juYzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105548; c=relaxed/simple; bh=F3d6Qihv++wQKFxkvWTlrSEB4w4EXSa83G5JD6f4ARE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XnA7d0d8HR5ezWmHwBBJMwBth+RvWnQUUp5hAAq7hfWfu6QJzpX7AOv3I+9/gR9MRSJqr05D2nz3ziGNViBv6Dqfq2wQUeFPKH8KkXvwlvJsMFKb5X2LT06PU5PuElcYOYw8VRpb+hFyLJ4DdmaQcjeVZajgIrsAm+Rf4rEroas= 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=rXYGCa7Q; arc=none smtp.client-ip=209.85.128.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="rXYGCa7Q" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-61e0c2b5cd2so81207b3.1 for ; Tue, 07 May 2024 11:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105545; x=1715710345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T6YgBjv6xHbxEq4dJcwOVpR1231RQWvmYFp/ZNwUhRM=; b=rXYGCa7QCtyOFlKo7L01D0OzqwHRFjIKd/4rmBlNu1ntAFHspkG/10KTJtFRRJ6YlS Y99qdq05KuPKMoipeQwcTWoVmuS0UV8jgw3FFm5jOXTplIAtLMgDWeMF/LI41IsB3o5e OGx85gtvZwvekMkgqq6RHIe04fD/6bKYqXtHdzBtClMxEFhE9AfQ9PXknDNSzwd5l6Tn nn6+ov0VKKuonnGQChyd+omsi5y6Z7OfxekJgvd0ztrsNDDnlamJmudxEw4hhYr7bl/f IMKvS6r7dyvqRZOo+VOeQTpF6N5oh0GBev22aC98oQayg9FvdSLo+wBDDnYwk7+IaeGS cZCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105545; x=1715710345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T6YgBjv6xHbxEq4dJcwOVpR1231RQWvmYFp/ZNwUhRM=; b=HLGh6U+UGoouMqlQoj8zvzLAQQ6ku8EngAEvtSw4uypQEFft0px/p8h8P0FXao64wd dMO4IsIicEDTJ3dT2sdaIPURAv1/azmvjabDcZs3CsWdi6MJzACe3TpQEcyl+Oi9qpvx bt4ZoMWiJUitypAMFyYC8aK6+P2xBwZdwh0YYvQebSg9Ku6aJLayhHun9d09YRxogc0D 9kDVvv2B4SWpRvD0TV3PyhnE4hAp+V9JkEc4m5cBy3b3QcEWsa9SUxcCZj3Y1GMTbv5u GmlfwU1Jwbj5Z5KzFVwuZkaEvarZLJ/OMEDzQMmvOzAdiUJYsGlxIYll1mMCXpJXUv+Z 2V6A== X-Gm-Message-State: AOJu0Ywmi/Dt+Tbu/JwuVaUv9HBsXd6N4uK5ykUslquJTrmR23VGPofE 1iMGE7vUjbcnUYHFVu74JMcpZILvGSybIBSvqfboCSlCBKxkNSfFRCoibx2NUzHOG6ZacGFHldz Z X-Google-Smtp-Source: AGHT+IGImF0dLaBkFkZiDM2pS3lfgfLOwpBFWoNR/Os8JkQcBpExt616mOFQTKoH+HOBkdArSeMy1Q== X-Received: by 2002:a81:91d4:0:b0:61e:eec:ec5d with SMTP id 00721157ae682-62085a6fe8cmr5791727b3.5.1715105544114; Tue, 07 May 2024 11:12:24 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id g21-20020a0ddd15000000b0061be5fe1e80sm2846482ywe.80.2024.05.07.11.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:23 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v3 01/15] btrfs: don't do find_extent_buffer in do_walk_down Date: Tue, 7 May 2024 14:12:02 -0400 Message-ID: <679aea878e1a1bba534462f1f6d8d61808f0de76.1715105406.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 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. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- 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 47d48233b592..d020ee1a6473 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5433,7 +5433,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; @@ -5459,14 +5458,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, @@ -5517,7 +5513,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 Tue May 7 18:12: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: 13657531 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 91E1F15ECC6 for ; Tue, 7 May 2024 18:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105548; cv=none; b=Xfuet215FtEAWloA/RpPAr/0zisqP+iDbhNeGTW9O83KMOqHwzqmIOYkarcwWKxojoKQaEKC96/IiGaEso3IEpUN5+1QrZ6nltMwG7XhJqjCm0SJ1zHloMlmQy5vq2zwbMnqWcylJWFF+xpGFbUJIAtnj4AIuXycv+o0B6NP6QA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105548; c=relaxed/simple; bh=mwDddtv5TcOx0Vxe1iXgiTMaUbZIsoNTsKB/M3zPyAY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GrtYXQ80cickyrju2o0dqtM/wL/Rw/2sjmVmN++rEXChNQ4v+r60N4uh6tZr4hmKkJW6GWSGAnhSnC+jXVaB5A65vOyn5xUq1YUhO+Gqae/tiaq0tMFAP0DvASxBeJQaF9gKbHZRvRdF9eq5dyes1Yk5cnwDw4lth6GJ5ylPeYU= 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=v1XuW6nv; arc=none smtp.client-ip=209.85.219.181 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="v1XuW6nv" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-de5ea7edb90so3561032276.1 for ; Tue, 07 May 2024 11:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105545; x=1715710345; 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=P4byrbGED+hkLveYLsNrZSI1dripGf/IQBH7DwgK+vI=; b=v1XuW6nvlOeBXpVV4sZG2/T4cG8WFOxX2J2gN8E5ApLOybzgrdh61r2OP/w9I5NDQA +K8R0iuQYHa8lFz/0QbSjCS1Y2ZC0JVADN4YwLsZ4Lo03OJpWMrBGOtjnDgSTD0e6zj9 ISQfYTCi8Alk6PsEvSPrgOPvzGsJ7BEgzlH3WEvaa9IABu5CiV3VY0DFZwGgc7ywsVzF oqirXBKoX3qNXsizmaOP3qloxeNSmH9HD7KMgPbdND9iwjhmOsExLM5pjREDY5xheh3t y051kbU4RoEugeyrwYMF4kP+3t35/B2bL8sw9wnmQpO5gLhfAbbHdmZ14DpWEd1joscq pemA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105545; x=1715710345; 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=P4byrbGED+hkLveYLsNrZSI1dripGf/IQBH7DwgK+vI=; b=gDpW9WmXW2toJFcUEwhd9dpr1egwbEkYxCX4OJKL+Edz6XUUm1e2ZX5m+w6i1tltjM 1VizHorFJB/QLMvsiUJ0GfeFtj9B6BFtzup4j7Hyx/sAXyKPue/TOnhP9zT7Zn4RvjJM ljsnYYMHpRx8SImMSu0cl0oWG0aCzqMU4K2y2o3d8C1I4m7iNM7AW3Q2Y2fMRvKI9bJ0 1PCdtHUe+cTXvYLoQPRZG12brjNOazcqMYmiTyzsbygmqBI8lfhIP7tBh9/k4oZB5duu d+XA0QyHDK1oHWzU14EGU+EKrbfCb4UVFwDCUZe/zBvxaD+NP7q0OYybSBXxWTDuCU78 zFOw== X-Gm-Message-State: AOJu0YwjSgmrgNivcIc8qqgnCQmmCHXk2xp2sNPVEF/g3tz/EIG/mYwO WP1KZGqhdEa/ovjE6uVUyuaeRYINeeU+4/Yf5+mh9nZZV8YyJd44bRTuuGMzKSY8TqRWTbFo+/v O X-Google-Smtp-Source: AGHT+IGjLuHLQQLhJmH1hPbZUaLw4VQ+Zi2aI6DLugd1lECbmv/9DDvzX6mAlaVn7+KTONyzk8ITWA== X-Received: by 2002:a5b:251:0:b0:de5:4d41:80c3 with SMTP id 3f1490d57ef6-debb9e4d5d5mr473331276.55.1715105545407; Tue, 07 May 2024 11:12:25 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 5-20020a250905000000b00de896cb3a47sm1097156ybj.61.2024.05.07.11.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:25 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 02/15] btrfs: remove all extra btrfs_check_eb_owner() calls Date: Tue, 7 May 2024 14:12:03 -0400 Message-ID: <343d19395e2cfe7b15cde8e618f80cae17e9b0e7.1715105406.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 have a handful of btrfs_check_eb_owner() calls in various places and helpers that read extent buffers. However we call this in the endio handler for every metadata block, so these extra checks are unnecessary, simply remove them from everywhere except the endio handler. Signed-off-by: Josef Bacik Reviewed-by: Qu Wenruo --- fs/btrfs/ctree.c | 7 +------ fs/btrfs/disk-io.c | 4 ---- 2 files changed, 1 insertion(+), 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 a91a8056758a..92ada19ccd10 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -635,10 +635,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 Tue May 7 18:12: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: 13657533 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (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 9A74216D313 for ; Tue, 7 May 2024 18:12:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105549; cv=none; b=gJN0L5RkdgpCS0jgpW7dHr97v13rRaZiQDWRNXgdIPbqxeS8sJ1AQlYhJ7F2Nbp32OFiYDeP1lb2hsrigXanE1L3//jAM/PzSXwCl3ewUwWyNhJyuiwmSUkftFaryTyNIIeS1P/4WSGZ3h58pyyq7CzunFAmwswz2eTWst6td9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105549; c=relaxed/simple; bh=HRe/cY89W88DPjqUozx9WNddjUI5Jt2zRhFofBo1x24=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=piPBNpmjAuzmHs3MbXBhjaxV8Z89l5x8c0JU0dhKuA6a2Ew9YOejghkGGv/9/frfkTLbgMNmd55uLajdAszKN+jZUrTPzohE1K6sA65lotJXYUGeCzwx2INPDsJ9LOLPsoOwfpSHa7habbxuEG6DSor2zQRgdMvI6+TlKj0Ze90= 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=Tu/zWMRV; arc=none smtp.client-ip=209.85.219.173 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="Tu/zWMRV" Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-debaa161ae3so1016074276.1 for ; Tue, 07 May 2024 11:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105546; x=1715710346; 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=ccXBod5dCco1QGMkPtLIUd6x9rTE1uxOFGGOETtDk7k=; b=Tu/zWMRVEZC1kwHxv/95VW7mrwzQOEThUEM8Ta3+yI05fZnNSK4G1xyPQxlTf02YtG vPEMoJ+MZ/klSD+NDn3H5d657SCDsQrAtVtSd742f8lD9DB/G0LSfQYM4lHwbwnYiNZx j7Mx+6KZsf1yqma2Cczf2OYSNEZAgnjU7JhHLvM205BkvAHcLvQwu2gbeI3vbbywV4nq d296P15AhYlI5zTsrlmNtnWqolFtd+t2vUUNxDFR4jIzLiG7BZN/n7Eb4lzpKA9bDdk3 dBUZlO77yGdB5GiHvluKlJ7w8t5SlBY5q7es5twR6eTTvNHT0H4JobQjvtUkvy41Zg3w GUdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105546; x=1715710346; 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=ccXBod5dCco1QGMkPtLIUd6x9rTE1uxOFGGOETtDk7k=; b=nZh1z/7AxPpU6PGxsV6QcQJ20aJnTkLxrhNQPqkNDPMekfGlxUVnqzyxWcpwoNFqLG oyd2bNo0APOdPEpOySslYForwXeZZb2VuHf42TkyGcc2+BUaxpzoxqtp4syGirRTiFDH 5w1mD3TboTd5eHf1ENlFrCym8REul0rbVRqU3Rv1TJRx3yoGftgZqR+3L7UMztEhRPmX GiG604stNfal55K8a5T8WWl68fahKF3LD9sqxBN+wOUOkLeUIiHRyi5oX0NOT3etAZDp rGdz4ce/zAHQaK/vJKaD+68dVGlVVlfnXgL2goxg5sQFFIJB0Gck8XiYLxskDoKn68nB ajxQ== X-Gm-Message-State: AOJu0YwAdFr5oABFCoiiww4aocSqrO1MXn5jz95GMD/kmTFilmrAeOVq dag000YFvaJTvG4nDRtBLNfKKOLyEeqYHOIZo8VyVZ4j8XyIYGXjgFFyuNPqPA6DrODZUPwx6Q+ a X-Google-Smtp-Source: AGHT+IEfC13Q7ZK2VF2sQ3Hf10G5XrXL8q7u7tYJo5MG7p3MOeOguhxKPsgP18ZlJPEj8JCwp8Ynfw== X-Received: by 2002:a25:780a:0:b0:de4:8061:48c5 with SMTP id 3f1490d57ef6-debb9cfc30amr504262276.15.1715105546459; Tue, 07 May 2024 11:12:26 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id h3-20020a255f43000000b00de5ac6580f3sm2688676ybm.49.2024.05.07.11.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:26 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 03/15] btrfs: use btrfs_read_extent_buffer in do_walk_down Date: Tue, 7 May 2024 14:12:04 -0400 Message-ID: <12da2f4b382a07d9254c7e2c53391be4d32325c1.1715105406.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 d020ee1a6473..fa59a0b5bc2d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5507,22 +5507,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 Tue May 7 18:12: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: 13657534 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 8F9D016D330 for ; Tue, 7 May 2024 18:12:28 +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=1715105550; cv=none; b=jQT4uF4xp5ZoEK0IhvzWcpptJWvoocQTOngn2YDKlEaCACYTgdh+LG2xtLRHMPEZoQfafx7H1Y21Ji5/8o3XR12PPElkaygncZ5o2uLrpmGonXpxoP41of/ZvxzC8wV9d1P+T5l9ENIqfTmbdMDVcaZIuBOobjvX4Lcd+ZbNZns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105550; c=relaxed/simple; bh=fYq78qYTSQ/+Y+QM3pFr52t3obwjC6nncoDUrZbsqLc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GKEgKk6fBNXH5cco/MmLRDQ0c5FrgVynLJurlMPG8ODzYRW9CuRoh0MOD8HzHWjEGzf+sHxqA74hpQiq3AEuAJ9UPHojwwS5lS6zgH+bXepDbFWsv12P206wJvNmyeOCmlFsKc6r+y8QxSEfGQ3LkrkB/V/eWEShXbntGUllukc= 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=SzTrNn4r; 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="SzTrNn4r" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3c97066a668so794304b6e.0 for ; Tue, 07 May 2024 11:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105547; x=1715710347; 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=JUMgMR07HOPlAJJcrUpT3nPIaH1wKehtqfxgaAiuFec=; b=SzTrNn4rLbGOci3YjSLPPCUAbUSTrkUGpjIVRHkKSJ2x6e7xTEuiFdxARIl89gB/vN +N2TChXdKZnO5fNK0YNzbJcRynmQuwI3UnZYquqHDAE00TygjmhPgN8D1SCfkJRt2tqa sVA/pgyKGlNoVw4e0UqETKeGqNiqSdu9I2z+oG31xqYKVwOIGFOVzJYISBHkfy1RabUa 49IL8YfkzApznlx9hVRjo7I24G58NBNopqO3KYBLC/ZxYZfp6BQIUf0kihzfGOzljceJ e9VJe+8pIycnB6RP1f+/AsbwMzC3MO3ZmZYmuSMBYwyo8BLVNKI51gU+Wu24e4NusNzx CT5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105547; x=1715710347; 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=JUMgMR07HOPlAJJcrUpT3nPIaH1wKehtqfxgaAiuFec=; b=DFd9dW9gpTHCTCxbmiIKuQXaexbSpYVcL96iwUWsNbk/JFOiX/G3dYFhp3fzAtOGxw TMK0tipSpi/dquNuRxsG6Yg2FqcBJwHejhvHtdxAkjaFBB+iyfn1NXLhgAyBHa8OAhdF q4fjAqKj2YNN24F2solEJZ+96vHPXOqNQ3ocUmfL9X8WyqD+94pXMSrbBfSQIyZdeD/p znmUa5meeWmZBampRuKU5FAkMulJKh4Q0XutaCxZsb2U7DV1N5g5pbC/BKavhDvGygiD ZOkV6j9y5jkHwUowA6/83WHvkCmUui3J/wFJQ6UkIdlXj9HllfJpbgFhUpccdyquuboC Ziow== X-Gm-Message-State: AOJu0Yw4tQ3UnA7suAhEqEJoe0/fGWStvGB5695DaIg0TYqsly2X45Mp +2nwTT8P8Oh3FGORBcYNLmOsHoC9u4SqcEvvi0Yy/BaNShcwcEh5pS7IiPBvHUNX1hG1cCzuPgr i X-Google-Smtp-Source: AGHT+IFwADdKRi8h/TQuy1QOP2ccM/nyeofqOSL+x+j5RZ0GdgfLHkQWuy/jJk6uD9PA6Dj/Q/lqhw== X-Received: by 2002:aca:1308:0:b0:3c8:62c4:f44c with SMTP id 5614622812f47-3c9853066e8mr341207b6e.36.1715105547538; Tue, 07 May 2024 11:12:27 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id w13-20020a25918d000000b00de6134b2c3esm2693468ybl.24.2024.05.07.11.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:27 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 04/15] btrfs: push lookup_info into walk_control Date: Tue, 7 May 2024 14:12: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 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 fa59a0b5bc2d..1d59764f58b4 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5220,6 +5220,7 @@ struct walk_control { int reada_slot; int reada_count; int restarted; + int lookup_info; }; #define DROP_REFERENCE 1 @@ -5316,7 +5317,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; @@ -5331,7 +5332,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]); @@ -5423,7 +5424,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; @@ -5445,7 +5446,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; } @@ -5477,7 +5478,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) { @@ -5515,7 +5516,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--; @@ -5604,7 +5605,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: @@ -5738,11 +5739,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; @@ -5753,7 +5754,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 Tue May 7 18:12: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: 13657536 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (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 E262216D330 for ; Tue, 7 May 2024 18:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105553; cv=none; b=JRVJ4/q0FiMVMql6QE3gxrkmAciExBZunPNZIs3Ft80WpDQ23Vgw5UUo3Yy17gXjQniNgN0pEUhT/OOWlbXwjY3lroMhSWhBOauSJPzZohX0uzgakd02Hfylsq7agACFEHXxmj7r1t6oKoGNLK2VNNuxy3pIgCBsvJQGUn+jP9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105553; c=relaxed/simple; bh=i8RXtZ0smrzDy+1N96mqeYoGyp+Hs01PVjLVlvxxkGk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JzHCBqqZjTGngpawNYeNHRaHGxG/LxXI08RpZCTwSbaGwNv/Vo72qWhKGj/vu+toL+XMqyIJ9UZsR0GT72o4SwXJZRm4Lrqn9ePOZauw3gR8s5G7hbSRwLw3h+ovp2Rot4CaBuXMkEo5ZWy0UAoCil27l7mgWzrgXTEe4nf/S60= 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=BunGXst0; arc=none smtp.client-ip=209.85.128.182 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="BunGXst0" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-61ab6faf179so36386107b3.1 for ; Tue, 07 May 2024 11:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105550; x=1715710350; 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=7wGp5IYvkDHig0jwh1l9YZvi35B8FpyMMfq8GLRr3wE=; b=BunGXst0OQ9NYuCiXm103wrF7kVqMTnukb8BGxObblxZQA0Q4eQA6z8shjNT2fsT9I /wX9cXH8qlv4ptlSLNUpeGIpxt4BvWOk64lmnEta5n+H5AZuD7RjIogvjnxluxmX0vFM +vPbGB4xK+9N8uUa2QoB2IRCwb6h5EwpN1QuRAxITWZQfXJu+Fu8fio8Tp310GHvvZDw 7lNX/rdFpbHJCQHmREaJnIcUbykNRBxtBLedPL7Ev0M4tpykrj8UhCd11P1TvaPSOQBC ZQrzCQ/Ai1wG2CpPUQuvzfA0duZW4AsR79YqeQHL2WRCRU1wnqIP1bllq7nIS2qbSMWr /fHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105550; x=1715710350; 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=7wGp5IYvkDHig0jwh1l9YZvi35B8FpyMMfq8GLRr3wE=; b=C3anLIO/uBUAJ0GJicFCPs9+rbzZv3mZfFTjYMRMVyjyaCBDGpgsJVnzgH1M3ovu9k mh4AYN3fsgHfUQlvDXWSe24XXwcHVFox9aMsqwpyNRpBdlD2CIn7y4UrVfZJFAS3Pg8H mLgMbV/L27ZeVZKOhdm/Vy/F2hXyzWjBhYf02eDn0jC5+p4O8zh6SlWiCq7zWCFgX+dM jVeE1tjtT1+C6CD1jgYIwkvc4Ip/TPegKk3enAHmGUhy05dc4xaM6eM0KebdZknLuRI9 u4MyCRKFZLFZUGAlnnY1ZHo61Zkt0XqQ2v3KRU/jnRX6zyrQABjfVN0Lo6TgDsBCKMyL CTaw== X-Gm-Message-State: AOJu0YyHvkn2r0z6j1Y18rxeQI/Us3Ovaakpc4jc2tQv1tNRN4AfwaiD LAzHZQ17ytpEOv6y/0alAyMUoy34vsN9nkKa42cNF2xQoUV4DOl7ekaWTXDxygzTcG8OsJS/6qF W X-Google-Smtp-Source: AGHT+IF0OZ6sNYn+1gKHUZPc9+6AvnAbEIt8t8umZRVXQfIonNHvobBWqp2P46YPIwTFDMIyzAtpCg== X-Received: by 2002:a81:be10:0:b0:61a:ca09:dae3 with SMTP id 00721157ae682-62085da6e92mr5964707b3.26.1715105549610; Tue, 07 May 2024 11:12:29 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id g23-20020a81ae57000000b0061bed5b2c38sm2856984ywk.0.2024.05.07.11.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:29 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 05/15] btrfs: move the eb uptodate code into it's own helper Date: Tue, 7 May 2024 14:12: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 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 1d59764f58b4..8f5cf889e24d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5408,6 +5408,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. * @@ -5430,7 +5475,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; @@ -5452,13 +5496,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)) @@ -5506,18 +5543,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 Tue May 7 18:12: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: 13657535 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.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 139B516D320 for ; Tue, 7 May 2024 18:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105553; cv=none; b=jRqw0G2R91cVADclbMBaAyscv0Wn/gE0SebEiMR5Zzu0Uhrgcee7CebO4OgCUUOKPX8NuuCcscx/mwp+2juYv7ALGHxAOkSVgEBprDnJ73V+ox7CxZlHK/3M41TUPOT/MqvDoDhEH8SqtzpFsPCm7Wc7CizNGgutl5JQzYXa3kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105553; c=relaxed/simple; bh=Xkik9oyzjLOjQjX8zLJDqz5ahPdSsEF6qd/+9+fLnlc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GyAjdI1Yj/hyo7vx+UK4fjknsTG7UsPtQcHH1lwjztFjiESrQnFISf7zSqNQryHD/F6NteAnb7EpoqVQvwbMqemkFkfR2bx47CJy3uSbdzPZjH69/6tRNjb8gnoNrt9wxladWs43sIcrDFpTql9FfxDcXUNc/pojBkghfOGqnFI= 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=xbabJnv6; arc=none smtp.client-ip=209.85.219.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="xbabJnv6" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-deb654482bcso3527542276.1 for ; Tue, 07 May 2024 11:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105551; x=1715710351; 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=4Anif3BubDGLs9ZXWD9H+TR+TBYRn+hGnqSRX6TXZ7U=; b=xbabJnv66WIYNWP6eYqNH8Y88flRfzpIg0g3mXLy8q+bnu6R43paebxHNVbr5WxaJF 1myULBdstcH+Vt5f0vZHR/ZipQu+lZ54Izw/D0NA4aiMIfSWrLTOXNIuG3ZLAlpLA2t8 4vx5Mn1f/EPnitlaLfnRCt3yHhak4TiSaG4U4t6LAnxtP9l0WA//d+TcyhMxBBrewY6P Q59p/QDNN3pQc2Cxe6hwjoLMU941bV5AM/wTaCmwlFEvNaoA4aqj0xCJMfeT0XMV0KnH aaRmFty5g84wSBvLgwuskiqPPTUMhC9ifp7hlJ3HrSBJKy2f0QVrzYH3YG06rdaT5bEU CjpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105551; x=1715710351; 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=4Anif3BubDGLs9ZXWD9H+TR+TBYRn+hGnqSRX6TXZ7U=; b=tG4wk7ryiTAnffsZDDrv4QuD8iJSJ4lot+ErRKhLZ8Z9qqhLHl4B404I/1Mrvgw2Rz 1NeAW9lqJVnalxxyl6EWPFohPiYUuilMYBhvmY70wgpAoCRFC+GB98iw3ZCuQ61vQSfu UxJoonleusg3I8S8i6EEKoN0/xgJ+FR+r+i3kcb58pcleJju5JAMwjWWc0pZotEvko0U AjS84mhi03LsBf9x5tMawgllkpOI39h+SKCnL+vU1hZ2kAg/3+lh4kznCVAIITnYfmLQ FGIClPFZq08XQYViEmX1HFgErdL9JfaecpQg3RWLdn8CcnbcxQ/2jgJdOnXhkvbKpDZo blsg== X-Gm-Message-State: AOJu0Yxkozw/5DmuTn3DxceuZluNs7D/eGZEn1IBDpskDDCqeInRH2Ff TcFJnfGNRoSEcdnTn/xWuDwNjX2W3BfzRGEueEB6geQmLlTE3h/rl8NO0fxCkk+q2dok3wHQg1d o X-Google-Smtp-Source: AGHT+IF/GqdSUwVfXWPMazS00+eT8IzQlHU2U6Vjf5O4Qp6BAeTLuenOfDZSuIDeSJJm8dkFbe3Jbg== X-Received: by 2002:a25:be91:0:b0:deb:3c11:8eb9 with SMTP id 3f1490d57ef6-debb9cfa78emr468221276.8.1715105550816; Tue, 07 May 2024 11:12:30 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id u16-20020a5b04d0000000b00de598c93b96sm2615654ybp.48.2024.05.07.11.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:30 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 06/15] btrfs: remove need_account in do_walk_down Date: Tue, 7 May 2024 14:12:07 -0400 Message-ID: <99f75d941bf2e92e29d532eb6535f66aa74fa8e6.1715105406.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 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 8f5cf889e24d..ae11a2bd417e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5479,7 +5479,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]); @@ -5519,7 +5518,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; @@ -5562,8 +5560,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, @@ -5608,7 +5604,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) { @@ -5633,6 +5630,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 Tue May 7 18:12: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: 13657537 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.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 1E65B16D4E6 for ; Tue, 7 May 2024 18:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105554; cv=none; b=UTsWaE7daYBTUCpCnSieiM3UdtIbvP5041vdo0CODLCeE4icTV3Ryud3wUP/PELdUq4RrN41DLA4G39U4sknw5gYeGTf3EmQna95UA920uQJhjvDAhAOzwAi+nOJ/fXmAgHasFsF2toOxgK9R3KN5tx/V2+l5vwQQswL5JiC4EM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105554; c=relaxed/simple; bh=LQ8r/jHHzE6+gmHFXFiUfQEBkGuWHJ1pVhZ7DHF6m0k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CEn7PHYb+YKhOxfDqfGMIOg5ADL8j+S8JpjyoOcCHcS5i9vsr48UxmfeG4nfw5WCV0z8GzLjezHZrB4dLvur8HIF3wU7wasnePOjxFnc/c+Qx+kYeCe8TDTJEXlLlnPZOLCq9YxBSvdwqTKkyt1U4qL1A5H5G3JcPGZb2nWHS1A= 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=dcmz7Mj3; arc=none smtp.client-ip=209.85.128.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="dcmz7Mj3" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-61df496df01so26841847b3.3 for ; Tue, 07 May 2024 11:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105552; x=1715710352; 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=Bs0EQg6KDmseCGr1wk4s34jwgnqkOtSw5juHC8avOSY=; b=dcmz7Mj3wBAtSxMTmarqwOkvvNld3TM74KGuSkI85MRNHLfqUpP95Hs8eNyvKYAElg zsMSfPxTqA0ISk/QqVb6NRra30nh3Dp+MBIN+aBSQmyrswGvGur+Sn5iBhjUWGpWmfzm fQefcpNZSZeWS//ilDd6SLsMpcF9Ita7Lf+SnYj4aPKpeUieND7qNh9IX+L3hAayppdQ LF+jVS7LcEvlfCtN+g+V1+eEs1jMux6IZeW5P3zrG1AXc/RG5xJH5Shb/gXHwQtbHTql OrSHj9n/uq9GgQHhLRAkFrDdZyat6zVT8I2ZxqS/xMo9ZVzWLKL94X21oQ6pb3rCcOEB 8UPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105552; x=1715710352; 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=Bs0EQg6KDmseCGr1wk4s34jwgnqkOtSw5juHC8avOSY=; b=c0DwY+UXvCwRZLC0lCNDV+hza9+aDNGrxhpRtoDSN8QiKHxB51ksjGLChfvg5XfEBd MPZvvBJcGG+wWompJZS20MRwzhp/eZmx9yHRo7UKS8WqHVnVIbRUOo7y6MRNPuqP9X2v edCOghaO+S8+Sh1EJKD6/6J2YvDsoEfX/xENWboJvOvh0jJfxNM4/4i+V3nT7b7aZQ/j FfadBHAKET8Q9aTrfOTD59X7deDckh3XAaUxOgHFC3YSCJi62yDIQf3iklFr4Qo16G4+ aU78lu4sb0ou08difA9q0geeJA4RLIecXzHk+vAmXgpsqOtZrP57xJN2PBtFtG/WdOEh 6CMw== X-Gm-Message-State: AOJu0YzZidncuWQsnTlUBZsn6YOoeha+/E2jmedOEo3xaNZI+uCFBN/P EIdPe/txuMBzL4f+Q3a7It612s4/pGShOND2i1W0+yqUCeHSYHEIES2FxyJV7Aj5QSe6ddhbOH0 U X-Google-Smtp-Source: AGHT+IGa/fUawzR90FoUsZai9MoPZUkHGhi6kPVRetVzZ1aahRq/yvTihA8wOuQA8Am4YDObkHeUnQ== X-Received: by 2002:a0d:ce05:0:b0:61a:d372:8767 with SMTP id 00721157ae682-62085edeeb4mr4829117b3.51.1715105551869; Tue, 07 May 2024 11:12:31 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id y83-20020a81a156000000b0061be65cc0dbsm2839965ywg.120.2024.05.07.11.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 07/15] btrfs: unify logic to decide if we need to walk down into a node Date: Tue, 7 May 2024 14:12:08 -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 ae11a2bd417e..4c6647760aa5 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5226,6 +5226,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, @@ -5237,7 +5312,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; @@ -5279,26 +5353,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++; @@ -5475,7 +5532,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; @@ -5516,29 +5572,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 Tue May 7 18:12: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: 13657538 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 1888216D9A3 for ; Tue, 7 May 2024 18:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105555; cv=none; b=Hvmj5TxEJjxFz4AhvE+u1GkX4W0IfvOPOdBjp1s6BWZneq6dvi9WnKmqhgDvfEh6TnrY3XoRu6v1Bx8HQ/y88JiLNz5Qq1uZkHNnvSUwBT6CwrtTWfSAG1CRD/tTvPvTJ0dOMun7iCLRMhQ4xz93xCPRqeqQRja7QvaN3hB9RVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105555; c=relaxed/simple; bh=ozJn28uetYl5jqiL3j5NZpx3Fnew0O9VQZ9vES2z1mY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MCW1izf7+UrlC1j5sJm4uOhHS63Y1bUtu0WcsWzpwdpsrEd//y+VsDy2BPE8FTDSg5m17h+vs0XdLnjUhpIUDf1kLqUIASVkd4j6m6rs5vjhkFhn+LeCffVa3SjRME8x8yjHcLta2ck58u2Lhp2n4i4iUYPVzxKwrpXxZ9RKNkg= 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=wPSVknv2; arc=none smtp.client-ip=209.85.219.176 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="wPSVknv2" Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-ddda842c399so3595713276.3 for ; Tue, 07 May 2024 11:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105553; x=1715710353; 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=0Zwz3T/FubqPGoNBdrjMLwZUNRumqym3HUPrJS3Jpvc=; b=wPSVknv2fY5K8Uc3onI7bHlkjRez4lFZpAoJi0vTI/s6IgfMG/eoQyoc/+9XsKxSYl IZ2rx2mku0aX55cPLgHWuaxrmKEQ40BoLimIrLh9SSVGk83bhQlnlev3yt6NHNRMOR/5 /fvfaouwPRTTVyli8aZASZH9tsVfbAzIXoXp2mhqbMt7pF5bbooslzuxs8ZpRD6FVbzG 0y4mpvyAdxBDQbUpPv/H7YCaODFzyP6swJozyZnfMhBezNsL2KuF3iM6CAPbWyQvlAQv uuvhm8w/8R8Kr7kN7XBFhsLAxme6gXaIGFsX6zUzW5a2KqIcw2K/vhKJRongsFIvjx95 wwOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105553; x=1715710353; 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=0Zwz3T/FubqPGoNBdrjMLwZUNRumqym3HUPrJS3Jpvc=; b=WMvUrrf3ad0Z9ll1S+TmSFVF55HHqqygmYtm4VusWVkD6wuDBCTGD7qp85dJ+/GYxY KSSaM0zQMkIEqS9Nl3TZGR52OjSBrcs5Aawy7ieF+QJ3wfHh3ptr7WpjRL+FHJOjp9gS bdhXfSqnrsXGAzFkxOOssP6anrLIQ5ng+NQZVfMyaufPEPco79A9NyQXIkyjYr2CoBtJ nWsVlH7RN9g+6QJVxKRfJkH7lmcRQlbflM19iG/TS82sYCErFAqxKFBQBX9yb4dTe6q0 nO52kqE61+kRMk+97+VG6kd/vKxRYS7JgdBxj5W1fJ4dQbauhdQ1Xs6+purNmuaJ3TkW 7EKA== X-Gm-Message-State: AOJu0YzBeu2f6Jsbf6b91NDL1LwqDwBDHnJpUrVu4qWz8x10GTWGmTpl QfhFX2HQQpkm8Jc4asexEFhR5Iiks3G9FFlS19VF1e1uhy+YQA9ZiWVnCIFF4Me+TBpxZjGOdMr 6 X-Google-Smtp-Source: AGHT+IHXFHFi7r35/Dvn9zLGPado0I83Mdpqrizd4TrgYEBG6jGugDoVNA2gwAQX/rCh/EDCzMqkdg== X-Received: by 2002:a25:c5ce:0:b0:de6:86f:c6a4 with SMTP id 3f1490d57ef6-debb9dbaca2mr605840276.44.1715105552960; Tue, 07 May 2024 11:12:32 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id z2-20020a256642000000b00de8347331dcsm2690420ybm.55.2024.05.07.11.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:32 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 08/15] btrfs: extract the reference dropping code into it's own helper Date: Tue, 7 May 2024 14:12:09 -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 4c6647760aa5..bf59e2f00ff8 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5509,6 +5509,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. @@ -5607,76 +5696,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 Tue May 7 18:12: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: 13657539 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (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 9904E16D9B9 for ; Tue, 7 May 2024 18:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105556; cv=none; b=E5ZFRgZPm1tgtJiEmNE7GGZBONGqnbcQFsA0GkdNorYm0+h321oviG7tJtPimpigBI1MFrT7vHlVnW8VhwuiozxutanOokGxYLseRyq8uhEkKlbo5vATwSHkVfmsySvfFr/dUry2Mxz0W/V6KIr9IqvxcxHc+7tbz1DiRMrs/ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105556; c=relaxed/simple; bh=eNn8v4yxlSxXI5la1doDYCLdN5AUq9c9Go4aPSjyOB4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U1vrw9J2LOjlR38r/OEblxFLQpmrV4zxMUFpaonR/NRAGdvG4wwtZQoBF/qvF2yNvCi0+7RtMzKrliw17kPB14MR+I2GaOi16YZUSxkcCKfGPCbbZMMRhRlu6q10hpFA4kBIJyPdTvKpCfCOwqYBCjhWVvLOYlpaFmbapxgV1gM= 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=wchxbVuB; arc=none smtp.client-ip=209.85.128.173 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="wchxbVuB" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-61816fc256dso35570257b3.0 for ; Tue, 07 May 2024 11:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105554; x=1715710354; 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=Kd9anvl2wwYVLNkKNpL22YqkpY4M67UnyZ3hqVkAdBI=; b=wchxbVuBx1HUR4yFkuv9AbCbsl86cEtofvEJ30g1xZ23AXNHpD9wa1y3MMej07SsVZ kUgE59GHU6YYg0OiJghmzehVX2t1rEJ23LKtCY9dX4X1dFIuI/BZ75HhtFx3g3Pdx2zP Q+k23QZ4ouahKSV3vPSbkrYa7PuuUoMDz/F4QsM+9tFKpAsuAItMhmH0H0kfbAoqMI0B 2G+B8e7BPSBYfYvfcFyQL/cxYwpgXy0zGTKwhQgrI/LZlMIHBSpI0qkuVungnZ7AGa2e qhD1cMUE2LCHWQuefWqw3NPiWmjS4BHLYQUIfnngQnEMp6uDFePd/KZsoVa6m1PshI4p tj3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105554; x=1715710354; 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=Kd9anvl2wwYVLNkKNpL22YqkpY4M67UnyZ3hqVkAdBI=; b=T5Py2uDukRupNaMHXmbHKkHPq3guipYhBaAqWRU9gnEmsUUwvNpYZzhJtkVrltYS9Q RTRc4JzwkH7AkluBC2sDwAn9clYgGgLF6AropATNygtysnXabi1/yoGI+OSen6s1Y5/4 8Mg+tfWjMrE5d4ngx9moD878K2Uly55llTeKLwlCxtc/G0jcF3e7lK66A2RLB+ruBaxR ojV4S3DUYGjrlNxAqn/RAB2GK13227wERyI4i82QSmdTXPg0K+7j9WuSMFPdpTJGpkCU fJJhbc63MxXpFJgHxdD95Cffdb/vEYTmlNdu5H34WDjpOC/3LoFV/VSsWOV7YZXX8leP jZEw== X-Gm-Message-State: AOJu0YxDFWRlClucZWQ6GiNbpViBQ9jNyH3M819mf4SHZR+Rc9E8D7ia PLpIObzytCLa15g52eWcpmkvpPXegj4VEUBGRZAuWKXBmtlB9wukSVmYcxSl/loBiHae2E/Y0o3 o X-Google-Smtp-Source: AGHT+IGPO07J2cYuP+DVIy/9DzfjBPsmmDYrtouW66iNmITWsRF3/7eEnZOE429xw7Ob5G7RWSsCTg== X-Received: by 2002:a0d:f642:0:b0:617:d384:6135 with SMTP id 00721157ae682-62085c48a9fmr5964117b3.49.1715105554558; Tue, 07 May 2024 11:12:34 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id h124-20020a816c82000000b0061448978753sm2831111ywc.41.2024.05.07.11.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:34 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 09/15] btrfs: don't BUG_ON ENOMEM in walk_down_proc Date: Tue, 7 May 2024 14:12:10 -0400 Message-ID: <20201dbb319e76335cae0969ecd4981a9fb8d696.1715105406.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 bf59e2f00ff8..df3b6acc63cf 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5398,7 +5398,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 Tue May 7 18:12:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13657540 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (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 365A416D9C8 for ; Tue, 7 May 2024 18:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105558; cv=none; b=BWIllUVj5QMQS0ClCwpzGSgyxkccJMnMHVHDoigMEukpKfdPIHTxR7NiOLgyEYLTSXgBmsCDA/f4JQ6XR36rMiFbHZbUTPLZ2lvbdTVD+rDoPYOVx/RncSiSSP352wPnHBTZtrZ1XbTs0VvhCLSoqd29UGNJolSsxF4cPm3a+4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105558; c=relaxed/simple; bh=zoV9661pC/mzj2acwhd6/oXf5IOiZQXnPfw67Hhy384=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OwNnSlRnOXGs2JupXC/GXJLwvurFD3FcLdzVNPzLmKBfHFVDhTLD7UvrHA3zK3nio47c44urropXoeFZZkpHAmukPDW+xCKY50FHDgNpwhwNFkCzMm5+nDeIXuBQW7MIipXfflFtK49nfy8tvQ0mTpWwf9k+6Vjqso6GvcRVGto= 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=ZJSJm9ZK; arc=none smtp.client-ip=209.85.128.174 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="ZJSJm9ZK" Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-61816fc256dso35570637b3.0 for ; Tue, 07 May 2024 11:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105556; x=1715710356; 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=rJjfXXCDeBwxlqZFPLDX4+ku/LlOc7au7TobqVnD3kM=; b=ZJSJm9ZKoHslMP8AGoeOaOa+9LM6QlXxoX8Zm2ic7+9Zm9p5N8vwc3qAv4O8erhcV7 JTz1P3tkLa9Y032vqYBcTB6i0hPWxTtIOGUC4pIZnhxVfYEmsaW6af8sYS/SbGBDMOk7 AaQkjN80QDwXdQH0Dn78DPbFdKrLE+mzvB8SDw1eA7i9kXTqq8BW+tAEUGpwt8dSuDlq 8fQcaSZ0vtnnfRI2cEOXmRbuFVehgxZUqxdAGX4ZbXndENCsn9zQKXGZjIIjFD4P5VKb Enf1OXMdQi/4KFKBvqQxJPorJXGekkDwbFhJjwUF4AeMD3daY3za9OwjiE3QxlP4FSNQ pt8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105556; x=1715710356; 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=rJjfXXCDeBwxlqZFPLDX4+ku/LlOc7au7TobqVnD3kM=; b=EZwYh+Goclt+ZnCzqpyrYNzGBZ4j4tYCly65acT4MFfj5RLA9Nr/b5qWQR2pG2OiO4 02oHotIQRsMhmGI5Ts0p9iGfBxChHhQCQn9L6gZIjqomOtoMephM8KLFyseG31Oo9EY5 Dsjt+OG5bi24lxsLBnXjSZnWdk9lI5Sfe4dRnWMZmEstA5b505O5tDEciNCBZYwB3gj/ d6TN+QGu9Rk04I/5/W29MxFTu3P7jjscDkG/NhLkKGTFO0TuPi0LRnpUCHzR7PyO7zbg tMlMu7j0lHuhW+JrVH9FRlPzacv8GYPDz4rvPgVfxAnktJCSrBLgwA8tRkcHnsd1BmR4 P5pw== X-Gm-Message-State: AOJu0YzQn2TrNVqJJgSYMaJx5DSxskVr1jgBJW/JMaFEuRVHbxi0whjx CJO2IE0oYppoMhuAEU+6VzUUwKZ2/TgjyKv2pMSZqbbBjSQApWI3vkM6bQqmI1073T1XjioXxOq I X-Google-Smtp-Source: AGHT+IEjm462uk+8kFrpmSoX1lwWTEdIp9nFDwB1P3DccU5z8S9KZ3O+7d5qxcMXE93ZyITsMSKkJg== X-Received: by 2002:a81:9182:0:b0:618:90cc:bc43 with SMTP id 00721157ae682-62085a7a6f8mr6430567b3.22.1715105556077; Tue, 07 May 2024 11:12:36 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id t2-20020a81e442000000b0061b07de76b3sm2820250ywl.38.2024.05.07.11.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:35 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 10/15] btrfs: handle errors from ref mods during UPDATE_BACKREF Date: Tue, 7 May 2024 14:12:11 -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 df3b6acc63cf..0dc333331219 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5418,11 +5418,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 Tue May 7 18:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13657541 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.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 4E47116D9B9 for ; Tue, 7 May 2024 18:12:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105559; cv=none; b=OHvSV9tocwP1SqvzY41DSDbkTRyqO5G/E5K365r9qfMFmM1HwAyI1clOPAxGgUO7wXC2B7uD4xat62qMUsxoW6NsFNfDmwaSOyv4/FJ6ocRY1hhIYrsk/5XNcyIM2aqSEHxPfanbXKyRTJGGuyo98N0FDx/TgNnX5nbBFQA54NM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105559; c=relaxed/simple; bh=N6k4QAy6YmgIzuBv3UbjkAqckRemx80XpARWAF3yddU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lP4tFwfQVrp8jaIeKxHO3jEWvqCji+Jd+5GLVyXh8cjKHDquYAMrkoAy3fHIdsJwUojsr5LxEezcQaYMfaCYN3JWKHVQPdhONIcH27kNYkrMJ9lhmRln329eXEqBUzdpZvCglQOehSf9/1GloOcca872lM0KuBMiAVYjAvDsxzQ= 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=Y/xKC0Z/; arc=none smtp.client-ip=209.85.219.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="Y/xKC0Z/" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-debaa161ae3so1016252276.1 for ; Tue, 07 May 2024 11:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105557; x=1715710357; 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=4o4E/zlvhEvAwve3wuYe7HKWbPGiYm3aR3FSwzZ5Rb0=; b=Y/xKC0Z/vEoy5VBMifBScgKoEf8y0HxmONUXjv3WLqjeDCznEfsy6l8jQQb5eSudZB X/HuRtZhZjAtL/3e6fIb3IhSyCxh3ZpFt7XrrYNNI8bzDuWxLJtTuOROmXb0FdlM0UmU pV3bQBbwkxpvy/P7QVeLXNs6EEqNL6BUKBT8FX3GiveO/3LHPEk8atFJQ4lrJJJVz1/C 5TjePgzeGrAryazm2jb7QTXjq8wVtoqaaSPEM4ojlwyShGXHe9JJ2sI2aNK0PV69d9rj hGMUrYaaLueLvd70sVpNQufKmv878YA3AOlao1eNXlJz7rDi9BZYZJ1Smfxn/3t5T9bY BdDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105557; x=1715710357; 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=4o4E/zlvhEvAwve3wuYe7HKWbPGiYm3aR3FSwzZ5Rb0=; b=cWq55doI7jLbXci9VE22scncHH4jRPbC8vgUXufKrFyxzM9uVhiAv80ZaZPclhAoN7 PQVceJ6wCu18Rln3srzcbgFQ593nnDy7Eg8Bxuv3iNtgLBy0L5p/pmPIMkEvP8z3MfId TevlAaoyQ9tKkxzF8Kjhn1aF9LuBHm+dqxHxUw+22JPFvSc8yWJujjC7kPzB2QqJ8l+S oyKE6fxF6S0RWlpQKvi8LJqdV0NosypLVG3OJe1sofAbwcrXYAbpfbKEuQLOLTXdEeeg PcM+7HPdWmJJQ0Vq6boTs4vfXT5tSj4QAchohEChApBHAEHTfMpL8vQqXScx1vDOp1PI ngTQ== X-Gm-Message-State: AOJu0YyojgrVarMKma+pd1UbpbyJ/w3f/tstg84iBTeH9JqfS80fZ62X c7tG7mm4tYHTiFzlO/eLvcuaV1qmJvPQJCx1+ID1Ch/XT7u8XWt6ZXFwT+lZiHrn21VMH+5aO6D / X-Google-Smtp-Source: AGHT+IFtmPgojqi/jQegEQixsQWUsdrxjCFu8qW32btsyofMk8eQd8Xq+9JE1yR1h1FkWbLSf55gKQ== X-Received: by 2002:a25:cec7:0:b0:de6:17aa:e711 with SMTP id 3f1490d57ef6-debb9cde0d6mr615605276.7.1715105557186; Tue, 07 May 2024 11:12:37 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id z17-20020a5b0a51000000b00deb742c5d87sm1464885ybq.25.2024.05.07.11.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:36 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 11/15] btrfs: replace BUG_ON with ASSERT in walk_down_proc Date: Tue, 7 May 2024 14:12:12 -0400 Message-ID: <42b7f7ebeff52747dbc1a757751319c818e41efb.1715105406.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 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 0dc333331219..c75a5b3ddb8f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5392,7 +5392,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], @@ -5416,7 +5416,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 Tue May 7 18:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13657542 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.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 7E9B616DEAF for ; Tue, 7 May 2024 18:12:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105561; cv=none; b=NKuOkJr7YNSkE5TJSxz9CKkuBQQT+UvU/MHiKdcfWdzvolHafPMVn19s3eZ/vQT9zmP8RoI9b69EN0ijpmjcIIq2xnQWB4f/1QfvBr4cAjuuIJ8k2ei/tbjbGSgf2f2npRmv/9BGmPOsyWYbr9LrH5FDES1KmYefuj0zFoaQQD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105561; c=relaxed/simple; bh=KhqqIUGDegCY9XYuce287PAhNDNWiSK7iwHSwJIpRVY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZdAr5ExlNTY1P0OraUPbshc8M1T9JFQslHAlbo6FGs73OPLU24wFwBJ1AbyMz8/eCm8zZYCLNoObPEDZmtHUt9efEqoGv22zojkhAbjL23j8l86HX7T+T5cf0RYa3zwkpfey1eXCukG9A+WLmryPl97rBK83v5IDczo7nHDytC8= 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=2yCKoqoX; arc=none smtp.client-ip=209.85.128.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="2yCKoqoX" Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-61e0c1ec7e2so259207b3.0 for ; Tue, 07 May 2024 11:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105559; x=1715710359; 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=GPnY+pD+b1QnliSmODM5TAvUO8IPiGhZ6cPOEHOmHFM=; b=2yCKoqoXP7hxGEPeZqk3zDrXEE14WqclCICSqzkrKD55JQmR53PnxA/DLnhsTEhN84 4cUOnFL74uGMiB5iDyuoOzkurvHjI4T8k4Cr6BfQWIN8AoT0AgbjjO/H3MGov3pntcas 0KWqWtTn08uvk0HbCPZZkmI+86voxFViczTscGW1+T1BYfS0J7/qziy3yGbhN6OeQstG FmC8EaObmUTEdDqc0MJ3raRr6IG/9LqpA5X3JNrdIHRiGH8DoFqOIehApwxKfA1T01K4 1MzXyzAK3uTMMkmv2pKea/wta2Oe1fWWG6Xwl0/wkpnozVivOJQb53uxSZ0+/PwNvD3J kOEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105559; x=1715710359; 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=GPnY+pD+b1QnliSmODM5TAvUO8IPiGhZ6cPOEHOmHFM=; b=PbZ51Hurtrd2d4In8qCHyx0Pn/5FIGw4eE3/82U0MAsRWc0zcjhlH0KN7asquF7NW2 B65zyeGMWd7l3bowDuraYzNXU8DdhGp+xumWmlYmUqIbkPIuyZvQ2EZOw/bCuLT2O8cj w/XEnIhjM3Ok/wD1K2ZzI3q6ccJNgbwROEEVYzHLfP6v7D2GaU3R/1S3ZrTcTDQO0Krx SvmhzhE8CGkbuUL5t/yx4b18Rqk5BxPSMAWWGNsJSeuFXI9l5V8J/JrQb1QqFwQtUISL Dd6Wrp7pEnmgy9B0RN10KslSvgjMdrVlFvjlIKJYmEnfwFb4CUAcetJktSRuNvdQbhlx /j/Q== X-Gm-Message-State: AOJu0Yx/UOEYOoHn6YoodOteFle4dJmB+kuyTOUj4dk1huXtlKMbX5PY UlUObs9YsnZfPGK/6PgZH5C/4mlAXTup/rK6qheEgmUVcP3t7vQsp8DxVbwnvCMAszAEimX+jn6 w X-Google-Smtp-Source: AGHT+IHknQoqed7NBPIiwEEQr2XuT3gRbRrFP/dNcY3SSxYu2ZA4wgWjF8gL9fKs8NpL1lO1CQM7HQ== X-Received: by 2002:a81:91d4:0:b0:61e:eec:ec5d with SMTP id 00721157ae682-62085a6fe8cmr5798287b3.5.1715105559305; Tue, 07 May 2024 11:12:39 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id be18-20020a05690c009200b0061521b0bb33sm2760395ywb.63.2024.05.07.11.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:38 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 12/15] btrfs: clean up our handling of refs == 0 in snapshot delete Date: Tue, 7 May 2024 14:12:13 -0400 Message-ID: <874b3cb1c1591a96572a32d27b80b205cee4b795.1715105406.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 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. Also adjust the error message so we can actually do something with the information. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index c75a5b3ddb8f..2e3a2aba8001 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5351,7 +5351,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)) @@ -5400,7 +5408,12 @@ 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, + "bytenr %llu has 0 references, expect > 0", + eb->start); + return -EUCLEAN; + } } if (wc->stage == DROP_REFERENCE) { @@ -5663,8 +5676,9 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, goto out_unlock; if (unlikely(wc->refs[level - 1] == 0)) { - btrfs_err(fs_info, "Missing references."); - ret = -EIO; + btrfs_err(fs_info, "bytenr %llu has 0 references, expect > 0", + bytenr); + ret = -EUCLEAN; goto out_unlock; } wc->lookup_info = 0; @@ -5775,7 +5789,13 @@ 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_tree_unlock_rw(eb, path->locks[level]); + btrfs_err(fs_info, + "bytenr %llu has 0 references, expect > 0", + eb->start); + return -EUCLEAN; + } if (wc->refs[level] == 1) { btrfs_tree_unlock_rw(eb, path->locks[level]); path->locks[level] = 0; From patchwork Tue May 7 18:12:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13657543 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.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 B82CC16DEB3 for ; Tue, 7 May 2024 18:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105563; cv=none; b=hkn9+/g1ESYfXKkaoqgHhztxyl73lNxanyijJoarXwAxKgQN8GTvoKs0JPcLUyAjiddUR1jwXGzPJUOAlOWFuNdvgXGLDXXDn8yT7XYbiljl/qP1M587GIvejqyicZIdW0k0SDe4Q/bCHtpJkYo1jStzoiUEzFqHBg6PObzObDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105563; c=relaxed/simple; bh=1Tn3+SagoUfzZXAAexFvohSblTFaT4QtJz9w8IcCINI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g+hMRQjg+dIhBkr6If+RZNBrJxRWUay2A9Pe3HlJrIZJ9OKGu6tpvyrIcwbR79CXWltAtOt0tzqtu9s3BpKEBKsPl5Ek0S9VkOhVGI//3VESQ3w4kY3t651S4jUqTsZlXTD/6BsT2DJXjktWf/f1RXL3k/DTZvhTnyeQ5+F33jI= 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=Ltz1syrg; arc=none smtp.client-ip=209.85.219.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="Ltz1syrg" Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-de5ea7edb90so3561246276.1 for ; Tue, 07 May 2024 11:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105560; x=1715710360; 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=9Mnhk/eNwsblskxgTsDO1tvm4+/gLwjWmEhn0tCBkF8=; b=Ltz1syrgrPVZe5FBGwGx8cL4vt+Z4SDbJ7IsdYCBOBUVD8tcqjcYdf8fVxKThVD5// K/1BryQHJ24dCFsbuCLTA/F3Xhf5aqNZnXIvTpMAoAkBfu49lETxR+VFaLg5rROsSp70 YUwQnyKuq5W1Nfe3/siZwJMZjUXhysLsAtvuiUPs3oj0bq0tMODUtk1hR/F38ue6sG0Y TlEP7FspT7jP+On79QkFqqTodo++6Pk6PwLywfhncqldsRRv6YuFcm3mvWEtZj9RJfXd WcRsj1vMbJYEuX6Ey4TDWWtfIPZ3lOCb+z8dcayyadyedfcU5t0ph8S1XJtCW5bGuDn9 V8pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105560; x=1715710360; 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=9Mnhk/eNwsblskxgTsDO1tvm4+/gLwjWmEhn0tCBkF8=; b=baRgRoxru+mWc3BCqrfg1jJl+YSPC3bhYZBfmllQQj/qWIgvwv052cParY1XXuzurd jAAHLpqcLa08lROHIPIJ+8hsGTuLt1WP9UPn496NPpsGatPHpyUoqGxLqvRYQiAS0+wI G4mik5Bf4tOFGFD0UZphbY2Nfah7ujqJkeMr5dh+MphaZmlkDaYW81z1WFhlCQiYBN+i a6RbknjNOvPSwHx2B+FM7ZAmrAaNKLhhTp+349Yct1NabPh60hrueFe9GP6XGNPNa0ri If3PuB3xzXXHxYc7g9Fa34j6vwbow0gt9XD3mjHBWLgQ6PqoRSfzS6iaWO1sZbst4qBp KK8A== X-Gm-Message-State: AOJu0YxWfcikuzFxAJ6dCT+M0kI05P54V6TTxBEYBHaso86am/usvNdf gnXYnly5imCn2JuUJ+rUxiW50UAbhycQtbho4jtZx/J3RsCX8hd6E+XswG7cp+8uAPXFlazjXiC n X-Google-Smtp-Source: AGHT+IH5kwGLXZfYr3hF13gbawd+hU+fTEcZUhLdK43HIXyug/E24ScMaACjZTCCRSFTEXlDIPcDhg== X-Received: by 2002:a25:68cb:0:b0:de6:3d8:3deb with SMTP id 3f1490d57ef6-debb9d8ceb2mr491587276.21.1715105560519; Tue, 07 May 2024 11:12:40 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id w8-20020a05690204e800b00de60bbad61csm2607720ybs.63.2024.05.07.11.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:40 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 13/15] btrfs: convert correctness BUG_ON()'s to ASSERT()'s in walk_up_proc Date: Tue, 7 May 2024 14:12:14 -0400 Message-ID: <6f51da324645bbd9e202fbec73614ed2e2c5954b.1715105406.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 2e3a2aba8001..c6f8c31087a1 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5757,7 +5757,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; @@ -5775,7 +5775,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; @@ -5805,7 +5805,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 Tue May 7 18:12:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13657544 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.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 ADAD716DEC3 for ; Tue, 7 May 2024 18:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105564; cv=none; b=Tg0A7vKYfXfV0AvsMllqNpJhKkTIHOiSSAl+74KyEtoP/zE9yZEbdDnMxLKk7dfbrMQExoH02lviJbWfix0SiAsHm0gmNuUwQiZUtvKR/Xwb4fSfM0BqPUIIPtuvo2K25KPB8TOgMF9ixD7EQVobAEnupzxv96jwAESgl4SU+Kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105564; c=relaxed/simple; bh=iZis5zLxnFWmVJZALoC+7zO5IX2YaZ7dSLc97xxGo5U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dmfCiNKVEGI5qUxFlw0fcyTI1kUwx6O+3m9l7NVhu/ykNXUvdDo5zC0Rrndy5l9NLUoRWgLD7IazvbXX/8Otn/l5jEspPpIp6MiRre4VNblHEEo6jTkKr4TlyC8B7Y4V1aKRvFTf+5Q8HEmcYo4VkhJSkuul9qRqyn98mDY3xD8= 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=r97fVelp; arc=none smtp.client-ip=209.85.128.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="r97fVelp" Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-61b68644ab4so32057657b3.0 for ; Tue, 07 May 2024 11:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105561; x=1715710361; 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=XciRHnXwG7+rxxPrjA/zpLK8DRFmxqEElJp0i9BkG5k=; b=r97fVelpyxF1/TkrBLPWNR7u486AFVUce45yEK/5UjuzCbDdn6tFbAI5EBXCMwOns3 TmMQhdpULRjET0CH4TL1rtDjqLYWBQwXAHvSSORLe0BPVVYE6bFfWkSXgAkFmB0ILU/M DN/uCy0DarRkwauQDlDzgPo96RKs1eFF5yKjAQsFnzcdmai+Z7S/5J2aCjwz3DX3Nhz/ vFwW1fJChnuPw7exW29oHXLgjSeGLqUQOJPQsPd5DqAqUt8KZoIH1S7LLAbvThKbVX8R HAir4m5tnZMYbtYq/c14Y9rBUF8xf7XuKciD/2geVmiYoUVvj+eYCecD67NgrAQUwFpu Z3Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105561; x=1715710361; 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=XciRHnXwG7+rxxPrjA/zpLK8DRFmxqEElJp0i9BkG5k=; b=ZPDf654S1+GaxpQw4OTpcd1nthmE4wKU8kn/jfJ2P6BkAMGnDCSI466zB9N4tvbKzX 6/huOJgvZ6O/j0yAhbTgWpKHNmxdlpeUxkl38B71r+9egR3wWj1wBkOKraRoMNSh822r wxzzq8QjIS8Qk89RRpRJjC8HWrZUuHVyl3qlf2jdCqNIlOJGxzY4QN4D3ayqYyAguTNg 9FgRmIQ0gwI3SkH/GnhGJjQ0JyAxFUGttxOg6FDc3uG8SscKZ/537rKZMsdanK0OrjdR qU0UiwVRRgfdk0mQVasZYiPZ/adSgZLdYBV+eM/GJ8qVBUafTt8h5IHxUNaJ+ympQqWy yOug== X-Gm-Message-State: AOJu0YyQDumMsq3uCCNpb3oCB+pzKV7mQTou/dFVo+kNHwJquFwmC4JA o7fbX1FX/dToJu/gbXw/9ZadNaAytmXWuNWS+FaBN+a56XbPWzj2Z6nYBEDLJdFBxumf+anDCJd q X-Google-Smtp-Source: AGHT+IHvjLosrAYrjZhjsbw5T0+PoNIPHqriSLdHmrPZ23zWq//ULPZk46VB85NodVA44NFlswBfEw== X-Received: by 2002:a0d:df47:0:b0:61a:d6ce:487a with SMTP id 00721157ae682-62085c5de4dmr6046337b3.19.1715105561564; Tue, 07 May 2024 11:12:41 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id g5-20020a0dc405000000b0061435846686sm2871810ywd.95.2024.05.07.11.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:41 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 14/15] btrfs: handle errors from btrfs_dec_ref properly Date: Tue, 7 May 2024 14:12:15 -0400 Message-ID: <35e8920a5589c41f7fd7f951e5b88627dcc8801a.1715105406.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 c6f8c31087a1..743f78322fed 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5813,7 +5813,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 Tue May 7 18:12:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13657545 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 0890716DED8 for ; Tue, 7 May 2024 18:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105565; cv=none; b=GQZz52Q6OhradGwKnviQ3TuJEYj9mmlJy5nX+e8MCcfhg1R5AQKXsmzl99RvJbviE21uhhVR6AYJsqyQQmLo6vt3eZO/pq1zIycyiIttzb6wgUq7pXsZHurM6pLfqH/UPq1d2lqIiGAOP6tG9IEZqcuBbU6vtNYrRjF1yFn+WDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105565; c=relaxed/simple; bh=7EuX/D5uY4USCm1vWn5ThNThW2glY8Ma4FjrXf5m/ew=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rp265W8odFCTSxVeWskupqk50ZKBeXoiIeN01kjjcHZDqm6kajM/zcfHmr+/O+PoF8wcsHAbmG1RDsXzdqK06w7lmwUynF9kBA1catwmLs9o7Mpg2uJGPNsoTgNMyNyXrnBLKNSM+1q6l+DPic7n+88l18j4khQWO1HXEFpZyG4= 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=JGKSy0Ag; arc=none smtp.client-ip=209.85.128.181 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="JGKSy0Ag" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-61bed5ce32fso38350817b3.2 for ; Tue, 07 May 2024 11:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1715105563; x=1715710363; 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=oqY3Rx2KAwCn3LtafZ3TUHafD732X+6yJCbuJ0dSJZA=; b=JGKSy0AgpjOqOt6892w4S8CbX7H4PX6WoYApkCVhe0gyOCndiBITLLMvKgvAbg5MvZ Ym3NNS+Tp/xKmBSreae3mlTO4oieF4Fkid76PQifo4KLfAuSzmnhPS1P955YVGvgO7HA BwW2xFNHFOJy5M8ESDhxGwEZM20RMgpK78aUWYSMVPtoihHefT8172xGG3BTOiliKmPm nzHitV67Wnogh0Y+2p8iQJ2rLZ757fHcMSeR+70Cq11M9Nar0MMpXLOBg9Bd0/abP6W1 53D4TDG8uqwHhy+gx5scH+sztfqngyk7oOjGfOklFaCuDlKHm3Hq5NAw+5t9OGR4QXho xx6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105563; x=1715710363; 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=oqY3Rx2KAwCn3LtafZ3TUHafD732X+6yJCbuJ0dSJZA=; b=JSOvds166lo1rC5FF/qhAFZIyNDChOF/aaOZPxz3FLN+akN/Jxb1wa42o+qq0mzSa6 NQB7YM3P4htwEUjbGV1l0XWQKqn680ixHR5XuDQoMHuAmjI7FA+4JUz/tWgp9XwFlvMx SzMRc8Q3oYdhU8HnjolVuGf1mEsZqr8vf3zJYas0StwjO590aCQcZmqLz0uIb0Npx/nR sJQyS83rEgV5RoQKIJksZFtpyElGryEzUBmPZjIpuWegW8+9sgJ1NNMqX9BxgiQT59bz eJZQsaFvJ7r2uZM/zvRPxaTQAvQq1G4CCto/5n59POEaT8UTtqtnBDihz1CIwalixLk/ Md/g== X-Gm-Message-State: AOJu0Yx9duFRg5fYh57FXWOZ/R8Y0J+sdJ2rUx1hnkML/7AFDBCS9dZV sUjdLiGG790NcD7khESsUUThsviC60MvZpI9g2wKsbsJfDfqsE6kT2chFwbFDifNh6GPqy4claW 2 X-Google-Smtp-Source: AGHT+IGb3zGPDKKkwjf4IAW9nehckE0kMMaD8+TcsEeJ5r45ne8vtskt1SP1RngyFFtW2onAYgNDUQ== X-Received: by 2002:a05:690c:4a0e:b0:61d:fd3e:abe5 with SMTP id 00721157ae682-62085c3ec60mr6219387b3.52.1715105562754; Tue, 07 May 2024 11:12:42 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id l80-20020a0de253000000b0061beabc76afsm2834199ywe.9.2024.05.07.11.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:12:42 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 15/15] btrfs: add documentation around snapshot delete Date: Tue, 7 May 2024 14:12:16 -0400 Message-ID: <346b44dda597538cafc442672b13607a8711cbc3.1715105406.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 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 743f78322fed..6a9d216c660a 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5223,7 +5223,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 /* @@ -5860,6 +5873,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, @@ -5892,6 +5926,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,