From patchwork Mon Jul 1 10:25:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13717760 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 44A7984D29; Mon, 1 Jul 2024 10:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829527; cv=none; b=oH3Ua4fWKOkqWhe7btVLhTGfT1c9ssJk9NHuk+RGuTpubfu/n6UXQ+CVnizhUs0lMta9XInu8i1iO3W1bRjHD9CHfmiPY4OhsjZj6oHY5N4wLkP90OOSyoCdLYidQdT+kMXPt/rlnL158jfMBqsMQKgEoTQz+cUoJyQpfV6RNeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829527; c=relaxed/simple; bh=pdLAdw8AbZIIIqEbHF3B9lATObRLtWTBZcl4cyl+jVA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gAPhz+In7KTzt2l4yndYrVWgD3KzTP5xDmIF3vJ4/G59XCofZvKVUppU943xEJQAwk17ijeglMaLQ2EtmRdKaQ9t3UsjxYRjN1Ob6H+M2dSg03C4ejQCCLOhLc4SAF+CePJxkqi1I+/vYTBytn6XZO39FC0O08TXle3MjnO2b78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5854ac817afso56902a12.2; Mon, 01 Jul 2024 03:25:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719829525; x=1720434325; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c3M8GIwcTP2w6CaI85iIBf+6uE7YDXide+uxJUTmFVs=; b=iE9PatDok/LADHyBTePVd9d381OEA4TuRnORTGOGzp77C4dIJVkqmxt5gMOHNExxS/ /0NkH28nZndM5rFjiwrXo3o3fhAnvzSnJKl3uRslXLqu00WcbL9c2EFhfFXxesUezo1N UEtCA34louvsD05SMXhTJigS/qdb6i3qdy2PsjgpJx9vkxqOsV3HKy/o75gNcGP7FW6z wrt+5aNh3zAQ4a3IUebFkJZ/AjUv1ibo1z3pJGiCj10HiLAUUuHIjx0zCGml0pXAxR56 V7LcDWngPFRZ2r4pZQV/XzmOR2uTKAJyODykn/OJ3US+ZC6wIuWzKVr/prYlSmfiMLFa gfmg== X-Forwarded-Encrypted: i=1; AJvYcCW+klTP+DOjfUYeF6w8Kb+8GkX1eaipvrvvm60iu9paJlobSgq5P8UuRrfR4JQDWdof/nfCGhCvV2f62eJ8wW+cbFVstSaUxHCNgLjL X-Gm-Message-State: AOJu0Ywpli+3LefUZcC3gPT+cXxXa5Dlq5JPDZY/zWbkX1OcbG+ww8xv npSH4Nmpj1PIK7l2H80nAz31zSaVjoABrPWzasyEAE2Iu+FQJLGT2X+J/g== X-Google-Smtp-Source: AGHT+IHDIUs+Btlle/80N7RuFpfFk6isvbItryFLFBl4+0cfjgExi1OR4p3DFxie0ApVD7kfiHrcRA== X-Received: by 2002:a05:6402:42cb:b0:57d:22ef:d055 with SMTP id 4fb4d7f45d1cf-5879f983b59mr4077835a12.24.1719829524509; Mon, 01 Jul 2024 03:25:24 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58612c83583sm4238901a12.5.2024.07.01.03.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 03:25:24 -0700 (PDT) From: Johannes Thumshirn Date: Mon, 01 Jul 2024 12:25:15 +0200 Subject: [PATCH v3 1/5] btrfs: replace stripe extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240701-b4-rst-updates-v3-1-e0437e1e04a6@kernel.org> References: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> In-Reply-To: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2025; i=jth@kernel.org; h=from:subject:message-id; bh=3H78qr1E4CM/iN5I9YPMUD81FD/yCQ/9SOrHfoxgDzI=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaQ1tQhN//wx14u59Ons9umbm6bqdmxnir+0qedF56qzp TE2bF1vO0pZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAi168x/BVL82mYGSa6NLg/ 8lto/aP5xlsfHv33wC96wb/mP788wxwZ/nAzJMVv4HtsduxH/wnu8hlb3y2UXVLD/1Lu4CWRuxt rs/gA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn If we can't insert a stripe extent in the RAID stripe tree, because the key that points to the specific position in the stripe tree is already existing, we have to remove the item and then replace it by a new item. This can happen for example on device replace operations. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index e6f7a234b8f6..3020820dd6e2 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -73,6 +73,37 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le return ret; } +static int replace_raid_extent_item(struct btrfs_trans_handle *trans, + struct btrfs_key *key, + struct btrfs_stripe_extent *stripe_extent, + const size_t item_size) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_path *path; + int ret; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + ret = btrfs_search_slot(trans, stripe_root, key, path, -1, 1); + if (ret) + goto err; + + ret = btrfs_del_item(trans, stripe_root, path); + if (ret) + goto err; + + btrfs_free_path(path); + + return btrfs_insert_item(trans, stripe_root, key, stripe_extent, + item_size); + err: + btrfs_free_path(path); + return ret; +} + static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_io_context *bioc) { @@ -112,6 +143,9 @@ static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, ret = btrfs_insert_item(trans, stripe_root, &stripe_key, stripe_extent, item_size); + if (ret == -EEXIST) + ret = replace_raid_extent_item(trans, &stripe_key, + stripe_extent, item_size); if (ret) btrfs_abort_transaction(trans, ret); From patchwork Mon Jul 1 10:25:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13717761 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DD6A12C486; Mon, 1 Jul 2024 10:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829528; cv=none; b=TLDIDvVI0+cR9A0GCy79qZArRFf2xNKgIggLVeyZQWgvWjLjmoqJGxJV4Mg/UsOhouM0mTbK+84vepszZYjWZPafApcPBro0DRpx2HCEMeircEYbcftnrcoQ8gtQppZyV951b1+ThQAQwat5ZmZimWOpKplKSG/9isOJIt0b3qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829528; c=relaxed/simple; bh=Ihnv77fdO6VNQuv7P1wE+zU2Zro1Fedjo4vDunZrwuw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R+gneLs22doAV87CVS9EdoeE/G2hfP33U1MvSYs+AB7SUgI9XKmVxK6NO415mC2rW2m56N+3pm6IcE+kdJm+ZKr1uOvBTb4KEXvu0Y4ijW/qRlvrv0w0UM/QSI5bNqIs9Fa5CtoeLEOnGRo0DbWaObAAPY+4QWHX7WTCQESBXsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5858e973ef5so37401a12.0; Mon, 01 Jul 2024 03:25:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719829525; x=1720434325; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b0JT/Xo83f4nbcp2XDGTrGdTQ8pcv3iU30WHc4X2nJU=; b=P+EnMmJGLjFg0Yr3xUmBZWj0iHJ/mx4melKbGImtSsS1OLiIqI4cR6wxZJhYargKtt sfWHoSR4iXYxr4dpRGqdUDre0vgzXGSDHMbBvuAAphGOcNW0IqBxgr2i7q77tEUZfIDc CN4G03LqfLQvyV/D5HItj3IB7JcNWp4r3FhI6Gze1isj70WG5jiMjgHKF7UBlPixn7QG /DoPMPmBVZPIqMuly6zU058je5RxyOgMHLbaY3WQgxmk0nrDx7qAW2p7M+jP1pBV3n3C aOZJ5McNSIjry5OyYjGL1HfAZfRHQVCRS2IV0qyTkyM1zAWLNier7sSGQwyoqOxjOAvG gRzQ== X-Forwarded-Encrypted: i=1; AJvYcCV+5K5oS+vVRjO4sNYJqCZtGPSrMQFYX6jqSa8YoYnNpwZGw/bBSS0gqVbSTN7oxwQMQOY8ygdc98s3OGP9QE2HA8ZPDXAjVzqlJ+fh X-Gm-Message-State: AOJu0YwWjvCHft+SqnTG79nuUsPttNCVbyMRIZOh0rfvQ0j4zskhR12i HXbXwM/rHGdAkSprik1w2OU/a6Bu/h4RcTIzJmTO95WUAKDQjpI+qfmjbA== X-Google-Smtp-Source: AGHT+IHW+PvoEk4sz1fCjEyY1kf5G9YsfZe/k7tgQ9NdeGMBRVfVPMR8NsuZdAlRZDqx0jHQOeu47Q== X-Received: by 2002:a05:6402:51c7:b0:585:4048:12a6 with SMTP id 4fb4d7f45d1cf-5879f5a61d2mr4313157a12.19.1719829525407; Mon, 01 Jul 2024 03:25:25 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58612c83583sm4238901a12.5.2024.07.01.03.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 03:25:25 -0700 (PDT) From: Johannes Thumshirn Date: Mon, 01 Jul 2024 12:25:16 +0200 Subject: [PATCH v3 2/5] btrfs: split RAID stripes on deletion Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240701-b4-rst-updates-v3-2-e0437e1e04a6@kernel.org> References: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> In-Reply-To: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=4283; i=jth@kernel.org; h=from:subject:message-id; bh=c4gL3l0PJr5NwuEdLrKy7RI6oaeMUeYRLq3GongUBWg=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaQ1tQgpd9e9abube/F3aN3G+uT9b5vfa9qt3GT0IMy1W kG5+vipjlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZjIdCaGf4oZihMNQu7Ybl8r +43N4Z/sjhnNjqXn/ixYeMf/VK+zQD3Df5f/66oEd5l3y688dat3X3J58fmNm8v+BAeE+Mcsu/g ngxMA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn The current RAID stripe code assumes, that we will always remove a whole stripe entry. But if we're only removing a part of a RAID stripe we're hitting the ASSERT()ion checking for this condition. Instead of assuming the complete deletion of a RAID stripe, split the stripe if we need to. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.c | 1 + fs/btrfs/raid-stripe-tree.c | 100 +++++++++++++++++++++++++++++++++----------- 2 files changed, 77 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index e33f9f5a228d..16f9cf6360a4 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -3863,6 +3863,7 @@ static noinline int setup_leaf_for_split(struct btrfs_trans_handle *trans, btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); BUG_ON(key.type != BTRFS_EXTENT_DATA_KEY && + key.type != BTRFS_RAID_STRIPE_KEY && key.type != BTRFS_EXTENT_CSUM_KEY); if (btrfs_leaf_free_space(leaf) >= ins_len) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 3020820dd6e2..64e36b46cbab 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -33,42 +33,94 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le if (!path) return -ENOMEM; - while (1) { - key.objectid = start; - key.type = BTRFS_RAID_STRIPE_KEY; - key.offset = length; +again: + key.objectid = start; + key.type = BTRFS_RAID_STRIPE_KEY; + key.offset = length; - ret = btrfs_search_slot(trans, stripe_root, &key, path, -1, 1); - if (ret < 0) - break; - if (ret > 0) { - ret = 0; - if (path->slots[0] == 0) - break; - path->slots[0]--; - } + ret = btrfs_search_slot(trans, stripe_root, &key, path, -1, 1); + if (ret < 0) + goto out; + if (ret > 0) { + ret = 0; + if (path->slots[0] == 0) + goto out; + path->slots[0]--; + } + + leaf = path->nodes[0]; + slot = path->slots[0]; + btrfs_item_key_to_cpu(leaf, &key, slot); + found_start = key.objectid; + found_end = found_start + key.offset; + + /* That stripe ends before we start, we're done. */ + if (found_end <= start) + goto out; + + trace_btrfs_raid_extent_delete(fs_info, start, end, + found_start, found_end); + + if (found_start < start) { + u64 diff = start - found_start; + struct btrfs_key new_key; + int num_stripes; + struct btrfs_stripe_extent *stripe_extent; + + new_key.objectid = start; + new_key.type = BTRFS_RAID_STRIPE_KEY; + new_key.offset = length - diff; + + ret = btrfs_duplicate_item(trans, stripe_root, path, + &new_key); + if (ret) + goto out; leaf = path->nodes[0]; slot = path->slots[0]; - btrfs_item_key_to_cpu(leaf, &key, slot); - found_start = key.objectid; - found_end = found_start + key.offset; - /* That stripe ends before we start, we're done. */ - if (found_end <= start) - break; + num_stripes = + btrfs_num_raid_stripes(btrfs_item_size(leaf, slot)); + stripe_extent = + btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent); + + for (int i = 0; i < num_stripes; i++) { + struct btrfs_raid_stride *raid_stride = + &stripe_extent->strides[i]; + u64 physical = + btrfs_raid_stride_physical(leaf, raid_stride); + + btrfs_set_raid_stride_physical(leaf, raid_stride, + physical + diff); + } + + btrfs_mark_buffer_dirty(trans, leaf); + btrfs_release_path(path); + goto again; + } + + if (found_end > end) { + u64 diff = found_end - end; + struct btrfs_key new_key; - trace_btrfs_raid_extent_delete(fs_info, start, end, - found_start, found_end); + new_key.objectid = found_start; + new_key.type = BTRFS_RAID_STRIPE_KEY; + new_key.offset = length - diff; - ASSERT(found_start >= start && found_end <= end); - ret = btrfs_del_item(trans, stripe_root, path); + ret = btrfs_duplicate_item(trans, stripe_root, path, + &new_key); if (ret) - break; + goto out; + btrfs_mark_buffer_dirty(trans, leaf); btrfs_release_path(path); + goto again; + } + ret = btrfs_del_item(trans, stripe_root, path); + + out: btrfs_free_path(path); return ret; } From patchwork Mon Jul 1 10:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13717762 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 3438813DBA7; Mon, 1 Jul 2024 10:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829530; cv=none; b=cHXQ7rugRbtqIaARjnQs1CWjXqyH2cdgiVfHIfcuE2EjXpO0tXQ9WoAX4Xy/d1csToXcS/Ek5F+nIjFMuYLKIbVHxtEbTgz/vrNokDYHWiRK+/qwg4x5jTB16VwVejl3p7QSX3eVuVy/sV6DFyJAEaHaIF3OdIX6LJ8g1wP3WiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829530; c=relaxed/simple; bh=JIR1NayWgSJJj+2ghrWH3OVRkFQ8gWSkNmn3JViO92s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LVS28mWP8be/khkISDZ/nQbogs75e30ZokE30kD2UdTSHH8SYfoBX1r0JLr2GhuRMbESWL8/cfaPD7HK2mdt7izFhwWSAIT0tdqZ/46VGoFI9EO6IRq2mTUbkHa0W5o6c5sExPxyLAv4Ig6F2gYG3S8aVbbqa8obrB1yKR7RxY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-57d4ee2aaabso59812a12.2; Mon, 01 Jul 2024 03:25:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719829526; x=1720434326; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6QKa51KTKFE0sFxlYAvAVK2+JGhIDNObrLxW8iW8Dpg=; b=qyKS7EHRPzkJDtzNDzPq1x8n4qBRAM6ML45bBeNEbSiX5w6RQbOm1DgDwpfFWdTyP4 uMtfI6Zra7G4D1OdCHDmdWdsXU6TYrvy0WTQcn4TWMMwJWFSjD2XnmvkoinFWTX4e3M3 MpnJERk/5uk/iliUNnpsJ45bOSUeaSo2G9vpJkbwS12JVP0i7jHHVF7+4tF9QXIXKVCS ArcWzjHyfSppD3sB1QAwuEY7Bbd5DnXAp5K17Ji4yskYJbTRGe98nFKDv7Oxv5oi5Nua 3Ocnr1wGQYHrOwYhyTS4g6h+rRhgYaz7JwXqJDL84M0DfNr349+WHzotO34gmszfqGIJ 2+Uw== X-Forwarded-Encrypted: i=1; AJvYcCWcz6/ljVxpQxZM3MRguFu4LvttBcV4UhLvbl5OsXSkHP9b7wW3oXfXkPCSlD9QBRpGUzcoB5Nv1X239FNRVFdA49FWVsWdnhgB6ZzA X-Gm-Message-State: AOJu0YwbKBAq3BNLabAHAPjOAcdlL7/eUQFtozCSsL/0eo7+kv8O+GrJ 7VbVRYLaOzDRlRRmoeMX20PUdvbAslZADii/WHjZ/dpVyz71OwK7aNVFmA== X-Google-Smtp-Source: AGHT+IH+PmR6jq4Yn1HHJIhaVB2Vyb0BCB7pjUfU3WcipsClyG8O+BBR0q5bSA3lyXcoDl2sU/gFvA== X-Received: by 2002:a05:6402:90e:b0:57c:5996:cfc7 with SMTP id 4fb4d7f45d1cf-587a0bfeb9bmr4173993a12.30.1719829526463; Mon, 01 Jul 2024 03:25:26 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58612c83583sm4238901a12.5.2024.07.01.03.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 03:25:26 -0700 (PDT) From: Johannes Thumshirn Date: Mon, 01 Jul 2024 12:25:17 +0200 Subject: [PATCH v3 3/5] btrfs: stripe-tree: add selftests Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240701-b4-rst-updates-v3-3-e0437e1e04a6@kernel.org> References: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> In-Reply-To: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=10060; i=jth@kernel.org; h=from:subject:message-id; bh=YJsEb3+yxVnUPpAG/7oFafIr8R+i0LpbalhA99JkFks=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaQ1tQhxbSiyqsueuypK6/j/Cc18Vh4nu7iUfmoKpnK3T gngDv7ZUcrCIMbFICumyHI81Ha/hOkR9imHXpvBzGFlAhnCwMUpABM5UMvI8Hvt5MsMe4K5zc7s 2O1ScirIeGF84FTDUx59rZ6q/LeLHBn+cJypd58xqdrJ4118S7Gk394paQGWRhNvNk7Rd3sqcZq TBwA= X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Add self-tests for the RAID stripe tree code. Signed-off-by: Johannes Thumshirn --- fs/btrfs/Makefile | 3 +- fs/btrfs/raid-stripe-tree.c | 3 +- fs/btrfs/raid-stripe-tree.h | 5 + fs/btrfs/tests/btrfs-tests.c | 3 + fs/btrfs/tests/btrfs-tests.h | 1 + fs/btrfs/tests/raid-stripe-tree-tests.c | 258 ++++++++++++++++++++++++++++++++ 6 files changed, 271 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 87617f2968bc..3cfc440c636c 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -43,4 +43,5 @@ btrfs-$(CONFIG_FS_VERITY) += verity.o btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \ tests/extent-buffer-tests.o tests/btrfs-tests.o \ tests/extent-io-tests.o tests/inode-tests.o tests/qgroup-tests.o \ - tests/free-space-tree-tests.o tests/extent-map-tests.o + tests/free-space-tree-tests.o tests/extent-map-tests.o \ + tests/raid-stripe-tree-tests.o diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 64e36b46cbab..c5c2f19387ff 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -156,7 +156,8 @@ static int replace_raid_extent_item(struct btrfs_trans_handle *trans, return ret; } -static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, +EXPORT_FOR_TESTS +int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_io_context *bioc) { struct btrfs_fs_info *fs_info = trans->fs_info; diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 1ac1c21aac2f..541836421778 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -28,6 +28,11 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_ordered_extent *ordered_extent); +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, + struct btrfs_io_context *bioc); +#endif + static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info, u64 map_type) { diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index ce50847e1e01..18e1ab4a0914 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c @@ -291,6 +291,9 @@ int btrfs_run_sanity_tests(void) ret = btrfs_test_free_space_tree(sectorsize, nodesize); if (ret) goto out; + ret = btrfs_test_raid_stripe_tree(sectorsize, nodesize); + if (ret) + goto out; } } ret = btrfs_test_extent_map(); diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h index dc2f2ab15fa5..61bcadaf2036 100644 --- a/fs/btrfs/tests/btrfs-tests.h +++ b/fs/btrfs/tests/btrfs-tests.h @@ -37,6 +37,7 @@ int btrfs_test_extent_io(u32 sectorsize, u32 nodesize); int btrfs_test_inodes(u32 sectorsize, u32 nodesize); int btrfs_test_qgroups(u32 sectorsize, u32 nodesize); int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize); +int btrfs_test_raid_stripe_tree(u32 sectorsize, u32 nodesize); int btrfs_test_extent_map(void); struct inode *btrfs_new_test_inode(void); struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize); diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c new file mode 100644 index 000000000000..9a5848c4a1c4 --- /dev/null +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2024 Western Digital Corporation. All rights reserved. + */ +#include +#include +#include +#include +#include +#include +#include +#include "btrfs-tests.h" +#include "../disk-io.h" +#include "../transaction.h" +#include "../volumes.h" +#include "../raid-stripe-tree.h" +#include "../block-group.h" + +static struct btrfs_io_context *alloc_dummy_bioc(struct btrfs_fs_info *fs_info, + u64 logical, u16 total_stripes) +{ + struct btrfs_io_context *bioc; + + bioc = kzalloc(sizeof(struct btrfs_io_context) + + sizeof(struct btrfs_io_stripe) * total_stripes, + GFP_KERNEL); + + if (!bioc) + return NULL; + + refcount_set(&bioc->refs, 1); + + bioc->fs_info = fs_info; + bioc->replace_stripe_src = -1; + bioc->full_stripe_logical = (u64)-1; + bioc->logical = logical; + + return bioc; +} + +typedef int (*test_func_t)(struct btrfs_fs_info *); + +static int test_stripe_tree_delete_tail(struct btrfs_fs_info *fs_info) +{ + struct btrfs_trans_handle trans; + struct btrfs_io_context *bioc; + const u64 map_type = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1; + const int total_stripes = btrfs_bg_type_to_factor(map_type); + u64 logical = SZ_8K; + u64 length = SZ_64K; + int i; + int ret; + + btrfs_init_dummy_trans(&trans, fs_info); + + bioc = alloc_dummy_bioc(fs_info, logical, total_stripes); + if (!bioc) + return -ENOMEM; + + bioc->size = length; + bioc->map_type = map_type; + for (i = 0; i < total_stripes; ++i) { + struct btrfs_device *dev; + + dev = kzalloc(sizeof(struct btrfs_device), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto out; + } + dev->devid = i; + bioc->stripes[i].dev = dev; + bioc->stripes[i].length = length; + bioc->stripes[i].physical = i * SZ_8K; + } + + ret = btrfs_insert_one_raid_extent(&trans, bioc); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(&trans, logical, SZ_16K); + +out: + for (i = 0; i < total_stripes; i++) + kfree(bioc->stripes[i].dev); + + kfree(bioc); + return ret; +} + +static int test_stripe_tree_delete_front(struct btrfs_fs_info *fs_info) +{ + struct btrfs_trans_handle trans; + struct btrfs_io_context *bioc; + const u64 map_type = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1; + const int total_stripes = btrfs_bg_type_to_factor(map_type); + u64 logical = SZ_8K; + u64 length = SZ_64K; + int i; + int ret; + + btrfs_init_dummy_trans(&trans, fs_info); + + bioc = alloc_dummy_bioc(fs_info, logical, total_stripes); + if (!bioc) + return -ENOMEM; + + bioc->size = length; + bioc->map_type = map_type; + for (i = 0; i < total_stripes; i++) { + struct btrfs_device *dev; + + dev = kzalloc(sizeof(struct btrfs_device), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto out; + } + dev->devid = i; + bioc->stripes[i].dev = dev; + bioc->stripes[i].length = length; + bioc->stripes[i].physical = i * SZ_8K; + } + + ret = btrfs_insert_one_raid_extent(&trans, bioc); + if (ret) + goto out; + ret = btrfs_delete_raid_extent(&trans, logical, SZ_8K); +out: + for (i = 0; i < total_stripes; i++) + kfree(bioc->stripes[i].dev); + + kfree(bioc); + return ret; + +} + +static int test_stripe_tree_delete_whole(struct btrfs_fs_info *fs_info) +{ + struct btrfs_trans_handle trans; + struct btrfs_io_context *bioc; + const u64 map_type = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1; + const int total_stripes = btrfs_bg_type_to_factor(map_type); + u64 logical = SZ_8K; + u64 length = SZ_64K; + int i; + int ret; + + btrfs_init_dummy_trans(&trans, fs_info); + + bioc = alloc_dummy_bioc(fs_info, logical, total_stripes); + if (!bioc) + return -ENOMEM; + + bioc->size = length; + bioc->map_type = map_type; + for (i = 0; i < total_stripes; ++i) { + struct btrfs_device *dev; + + dev = kzalloc(sizeof(struct btrfs_device), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto out; + } + dev->devid = i; + bioc->stripes[i].dev = dev; + bioc->stripes[i].length = length; + bioc->stripes[i].physical = i * SZ_8K; + } + + ret = btrfs_insert_one_raid_extent(&trans, bioc); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(&trans, logical, length); + +out: + for (i = 0; i < total_stripes; i++) + kfree(bioc->stripes[i].dev); + + kfree(bioc); + return ret; +} + +static int test_stripe_tree_delete(struct btrfs_fs_info *fs_info) +{ + test_func_t delete_tests[] = { + test_stripe_tree_delete_whole, + test_stripe_tree_delete_front, + test_stripe_tree_delete_tail, + }; + int ret; + + for (int i = 0; i < ARRAY_SIZE(delete_tests); i++) { + test_func_t test = delete_tests[i]; + + ret = test(fs_info); + if (ret) + goto out; + } + +out: + return ret; +} + +int btrfs_test_raid_stripe_tree(u32 sectorsize, u32 nodesize) +{ + test_func_t tests[] = { + test_stripe_tree_delete, + }; + struct btrfs_fs_info *fs_info; + struct btrfs_root *root = NULL; + int ret = 0; + + test_msg("running raid-stripe-tree tests"); + + fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize); + if (!fs_info) { + test_std_err(TEST_ALLOC_FS_INFO); + ret = -ENOMEM; + goto out; + } + + root = btrfs_alloc_dummy_root(fs_info); + if (IS_ERR(root)) { + test_std_err(TEST_ALLOC_ROOT); + ret = PTR_ERR(root); + goto out; + } + + btrfs_set_super_incompat_flags(fs_info->super_copy, + BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE); + root->root_key.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID; + root->root_key.type = BTRFS_ROOT_ITEM_KEY; + root->root_key.offset = 0; + btrfs_global_root_insert(root); + fs_info->stripe_root = root; + + root->node = alloc_test_extent_buffer(fs_info, nodesize); + if (IS_ERR(root->node)) { + test_std_err(TEST_ALLOC_EXTENT_BUFFER); + ret = PTR_ERR(root->node); + goto out; + } + btrfs_set_header_level(root->node, 0); + btrfs_set_header_nritems(root->node, 0); + root->alloc_bytenr += 2 * nodesize; + + for (int i = 0; i < ARRAY_SIZE(tests); i++) { + test_func_t test = tests[i]; + + ret = test(fs_info); + if (ret) + goto out; + } +out: + btrfs_free_dummy_root(root); + btrfs_free_dummy_fs_info(fs_info); + return ret; +} From patchwork Mon Jul 1 10:25:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13717763 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 156CE14373A; Mon, 1 Jul 2024 10:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829530; cv=none; b=Ab/iebT9EhurT+wXiCK5xv0CGb4X+P60hlsd2loy8hHbg7Iy6q2Sl0FCWKZ/PQdq0gVTZXV70YxTddBVyKN+a+Aj4wmAnQHe8txCLR3ZJSWdkh+7ZeLPOnwnUtR5XWqTJ+Cu1gvRu03SGdOCdo72b/LbGVR6r1FY48VhKRocInU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829530; c=relaxed/simple; bh=s8ZarDR4XS9a3c2Cd4LDAESM/KS7/anxARtZNbWCb1o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XMmBajZWo0yg72qyb5M7dzGlwmaenXMWn596nbM8gw9Uz8w4a2/eTKE5+WEx/XMTNNjDi7zpunxlMZCzMNjz+7aJ3QSltJqCYqDq8BhKLrHvSfiss1aeqPQGNWtje13hpkzB1UKAblKwkRv3VN8zwMHWwhS66hJ3jgCcwCHCswk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-57ccd1111b0so24559a12.3; Mon, 01 Jul 2024 03:25:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719829527; x=1720434327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1KPpjUc13iqbgrbu6+Pky7AZs5MQgVb7sL8cFHoyy6o=; b=G5Q5A3X5rFD5dvmJGwh47UIeTyzd33ONjL1W/ZXrCi7IAgC+0znC2CywLIyrBzDlq4 o9q/xvPXSiP1loAt8OaCRPXgn8f/zv2i/LxnaEF1tCpM2M32tseX9HG7+cRIkmWvx/JY /P9ulAgGnpw5/y/wY1OiVGoXMSZnldvlYpWbaIWX2TxqnAuZvkKxatX94OlHNSogHhhH ZCSBPcHRuFiZhwoWvS3PHBFpwNA0G9tMpPEE79vlZOooIEncojCf+O2QA9q02+gS2FJf XyQw/TBI+n2zK+vnfkCP0WjE/h6M7z3o74c4WlY+J5GcX5u8c66jNx+eLdQ5sp6o6guy HLcg== X-Forwarded-Encrypted: i=1; AJvYcCUsZ5lsefJVJ/kYehNnnUCzPUMDfa1sccZiKGgUJCdoeiyN5l031Gv3GZrpqyCxL3IlsvJqlPtYUhk5VilbQ93B5eaNty3cpZEL32S+ X-Gm-Message-State: AOJu0YxmE5kgjrbRf+xgCmh/MIzAzQwxHVpWZ5hVraEcUwPyEatm/FZR Ak/N4BQOJ1XR1vbukB+9iqZbOexAVsG6MLR1BeKyjr1iUaR/gPyCblzyLg== X-Google-Smtp-Source: AGHT+IFJvzp0aeBO2IONr77eBrmZr/lVps3WXS29PCmyT1B4ZXN0BB2auNZ7kD+596yxMMjllD5jIg== X-Received: by 2002:a05:6402:5107:b0:57c:6ade:d8f5 with SMTP id 4fb4d7f45d1cf-5879f69aff4mr5114637a12.21.1719829527380; Mon, 01 Jul 2024 03:25:27 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58612c83583sm4238901a12.5.2024.07.01.03.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 03:25:27 -0700 (PDT) From: Johannes Thumshirn Date: Mon, 01 Jul 2024 12:25:18 +0200 Subject: [PATCH v3 4/5] btrfs: don't hold dev_replace rwsem over whole of btrfs_map_block Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240701-b4-rst-updates-v3-4-e0437e1e04a6@kernel.org> References: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> In-Reply-To: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3452; i=jth@kernel.org; h=from:subject:message-id; bh=7HqQqz7PhsBmLZ1BQWPpYtyUVF2OZsMrQjoXL2UBmZ4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaQ1tQiFzzx4U3VDQHPev68vcpc0lpmY/WrTUXj9ZnKRm ZoYx1PGjlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZiIpzQjQ9s/z8s6CSEtfuef qs3cINn2ev17OSXLw7PlrKsXntrfE8zw34Mp7t56c1+roNVBkga3dke+PWfR8uuj6rKLR+4vuyy RyQwA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't hold the dev_replace rwsem for the entirety of btrfs_map_block(). It is only needed to protect a) calls to find_live_mirror() and b) calling into handle_ops_on_dev_replace(). But there is no need to hold the rwsem for any kind of set_io_stripe() calls. So relax taking the dev_replace rwsem to only protect both cases and check if the device replace status has changed in the meantime, for which we have to re-do the find_live_mirror() calls. This fixes a deadlock on raid-stripe-tree where device replace performs a scrub operation, which in turn calls into btrfs_map_block() to find the physical location of the block. Signed-off-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index fcedc43ef291..4209419244a1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6650,14 +6650,9 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, max_len = btrfs_max_io_len(map, map_offset, &io_geom); *length = min_t(u64, map->chunk_len - map_offset, max_len); +again: down_read(&dev_replace->rwsem); dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace); - /* - * Hold the semaphore for read during the whole operation, write is - * requested at commit time but must wait. - */ - if (!dev_replace_is_ongoing) - up_read(&dev_replace->rwsem); switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { case BTRFS_BLOCK_GROUP_RAID0: @@ -6695,6 +6690,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, "stripe index math went horribly wrong, got stripe_index=%u, num_stripes=%u", io_geom.stripe_index, map->num_stripes); ret = -EINVAL; + up_read(&dev_replace->rwsem); goto out; } @@ -6710,6 +6706,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, */ num_alloc_stripes += 2; + up_read(&dev_replace->rwsem); + /* * If this I/O maps to a single device, try to return the device and * physical block information on the stack instead of allocating an @@ -6782,6 +6780,18 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, goto out; } + /* + * Check if something changed the dev_replace state since + * we've checked it for the last time and if redo the whole + * mapping operation. + */ + down_read(&dev_replace->rwsem); + if (dev_replace_is_ongoing != + btrfs_dev_replace_is_ongoing(dev_replace)) { + up_read(&dev_replace->rwsem); + goto again; + } + if (op != BTRFS_MAP_READ) io_geom.max_errors = btrfs_chunk_max_errors(map); @@ -6789,6 +6799,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, op != BTRFS_MAP_READ) { handle_ops_on_dev_replace(bioc, dev_replace, logical, &io_geom); } + up_read(&dev_replace->rwsem); *bioc_ret = bioc; bioc->num_stripes = io_geom.num_stripes; @@ -6796,11 +6807,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, bioc->mirror_num = io_geom.mirror_num; out: - if (dev_replace_is_ongoing) { - lockdep_assert_held(&dev_replace->rwsem); - /* Unlock and let waiting writers proceed */ - up_read(&dev_replace->rwsem); - } btrfs_free_chunk_map(map); return ret; } From patchwork Mon Jul 1 10:25:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13717764 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.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 617DF1494BC; Mon, 1 Jul 2024 10:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829531; cv=none; b=JAP4W4dgJP2blbHqEKGG6vFpWP/cZAavHjiMhsbHu3fURuP0/DPTNZ4QsbxB+yXiRVMwO//CQAwVkXAQWNrMezAofQQFQSgbHsb7pQ37CHDQbO/pjBpinzXrYWS21u+jAmYnMwyhFIArXdsdNB0QjhsdXJQrHE+MqYhvkpjykPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719829531; c=relaxed/simple; bh=Yj5SCX5l4/okuBvj4Ucm+ZQavcLkaJ6bqHI3fb6JgnI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LSKgkCslwdOSOHZLB9FzOZF92wUy7Yq7lbTws1LL7oICb1u21gp1K5dT8UOwStgUe1Z7ebllvVAHoRaLxFzRZ8m1/OlHYirvbQgWSAAqBrvmnF+ze4/zbcUFaqQkhNNp/J5FfzyFh2tX427N1y7KCS1H5iw6VZkJpxvgojSb/QU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2ebec2f11b7so31300041fa.2; Mon, 01 Jul 2024 03:25:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719829528; x=1720434328; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jP/apTv+9FNllVUJY4WmB60/Cc824SZb39Pn8gR8ark=; b=s8E/W/HPaIlyn04BNfG+meel8jnMtX3NfAtxZShZajH875fpd7moGfWY3LtMukyYjF C4oLVzaL+v7WZg32iP2t2PNRlHLjsJth7bma9ZFhxNlNwhWjZCuc+BV078E6cF2GChLG UXRzNyeCc3RX1mZNVN7ByzbyGY9YPIZi4mOQs/kHfF1MgQpLa1IrCwkCVEkkLOfQs8JZ QocuqUpYDcmb3jHusEgMj5g0GK9rtdlxXSAlKe4NaI7h0KGzPXY8WO69498/XlmS7Pmr mHzn1G9TO5vMLQulBHiWUdNqWv20jHoRjUQnnRLaDcSB1LJrNHBOPYlBpSCgaq0T35Sj lczQ== X-Forwarded-Encrypted: i=1; AJvYcCXB6FqyJ3oUA2317cbiMreUI0lXtisD2zDPtl+RQCnISQpd80c5+RAB8S+UxnPMYnISyjSR7UlvfXnRuN+Pa7uS3FD11zx72sAVYD0t X-Gm-Message-State: AOJu0YxGhe6CiP1gMXpfgPrsftXsgly2RaL6/ZA4Rhi+8tftJW+E+ngh XKy4YSdb/P0qXdyPd/SVAugLUluXrRaVu89E6Wj//FjC1c7xUCKp+OxUAQ== X-Google-Smtp-Source: AGHT+IEyvWjCLAYmJvHMJmrQgTbJvkpF1hnJwvFy7ZM58s2cuL8wciiAHiQp93/AHjugN5Fz0HZjCw== X-Received: by 2002:a2e:b52f:0:b0:2ec:4eca:7487 with SMTP id 38308e7fff4ca-2ee5e359087mr29813301fa.20.1719829528290; Mon, 01 Jul 2024 03:25:28 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f72f3200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72f:3200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58612c83583sm4238901a12.5.2024.07.01.03.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 03:25:27 -0700 (PDT) From: Johannes Thumshirn Date: Mon, 01 Jul 2024 12:25:19 +0200 Subject: [PATCH v3 5/5] btrfs: rst: don't print tree dump in case lookup fails Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240701-b4-rst-updates-v3-5-e0437e1e04a6@kernel.org> References: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> In-Reply-To: <20240701-b4-rst-updates-v3-0-e0437e1e04a6@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1099; i=jth@kernel.org; h=from:subject:message-id; bh=hPH+yDcHHSCCTGaxgQsuEn+PqYUALMNCW5mky+nNld8=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaQ1tQiVuqxV3XFsTc1q7rYL5Zxz/8mFa/gl/FnL8Jpnz Yo8vWWNHaUsDGJcDLJiiizHQ233S5geYZ9y6LUZzBxWJpAhDFycAjCRxa6MDA/dNmo37wy7eq25 R4FP9N6T6zpP1PQydPR9jvZPvKWwhYuR4cLj4+/DOztFOLZ5fJ/bd8xyz6Ha8i+7Iz0sn89qiHl ozAgA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't print tree dump in case a raid-stripe-tree lookup fails. Dumping the stripe tree in case of a lookup failure was originally intended to be a debug feature, but it turned out to be a problem, in case of i.e. readahead. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index c5c2f19387ff..20be7d0c52e6 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -332,10 +332,8 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, out: if (ret > 0) ret = -ENOENT; - if (ret && ret != -EIO && !stripe->is_scrub) { - if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) - btrfs_print_tree(leaf, 1); - btrfs_err(fs_info, + if (ret && ret != -EIO) { + btrfs_debug(fs_info, "cannot find raid-stripe for logical [%llu, %llu] devid %llu, profile %s", logical, logical + *length, stripe->dev->devid, btrfs_bg_type_to_raid_name(map_type));