From patchwork Thu Jan 9 15:15:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932891 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 C1F8721CA17; Thu, 9 Jan 2025 15:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435723; cv=none; b=fw61xq93LPKnkNlzLooHF4hh5lYRBjXHcM+xbjCIE/xAxLHC8kBoLbX0tpLJVgVc5gOogNE+SnxrQ7yZhGiXl/sEUx+OyWkdHi2l176eGW9uTt/noYGqfr4HCnve4AxI/3OOVa84gW6I2GKAII0exjhmKoeoID3zYMC1iUhYmQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435723; c=relaxed/simple; bh=7m1P2WMNKMiLMgmu1jXxFcDWxTXkJUpg1PzMqMBDVEs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p6Q2dnNs73fXYYhNtuAkw46raNUURyYtpv+bbzca5T/I2USE6GTs1mTruoIK640XtjFd2bk7i3/wJjKXQwvHRjVipnJQHXkE/p6f4RP5DpLLrktx4MsnJbAX7hSTR7WyNmw5zW1F4ej+2sVLLpbVTYs9qKyVvWyi9neqH8hwQm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-aaf900cc7fbso211569466b.3; Thu, 09 Jan 2025 07:15:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435720; x=1737040520; 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=nZsPMEezMKhEZXtJ3m4i/eKlU2y6sEdgUqz8mk4+cE8=; b=O5xf/p7X64jnWUWsdorRQD2Vkbthj7M2qkaYTk28EHO7HBXYspuJIBMW1byldhbNuR 8X3mna4h5hACpm9ahCtlqvq7IiBVgNuH7B8/kj7jDx8ZfirlsL91uXXo9cx+eCAeJWnI TPyc+XpLPBYvxK6lDtYwo5c+UKMsbgqlJmVCDkv+uM2xHWopz5hm/VYtEw/RVqewzCHe 9GKf8S8U3hQ4tr6uttfSwklx3EV9sfcK6KyHg2DYoqfyYzG0egWSB7S4mlV8RiyA0fDx Ta0WApUc1xbFoCrAIeYqfNf7UIA8XU+IwFxl5BUDNRAh9FU7IpHjqhNr1LB+xeFKa/EL rgTw== X-Forwarded-Encrypted: i=1; AJvYcCURWWMxiz5eIaJXDfnynDiCOU7AMVUy149dfCRdurF2OgdIvMrJWZfGzFX9BshtisrA/+HcNitC39eifcbI@vger.kernel.org, AJvYcCX0uV24ELkwtzrpQf6zMWa1sR4B1tVb55d/LzMj7YQMsWSwq/tMYosYzYH7jxXmAqn+driuRKJBHifsYg==@vger.kernel.org X-Gm-Message-State: AOJu0YxUpupAWXFA5J84q127i4vGHyWSejsvctoDBwZwP07QKAV6HQOV lneAFMneOB1G44HBAij2/fINmrkLi092NhtqP5+1RIg01AiEdJt3 X-Gm-Gg: ASbGncuFDXgiawT6r+v9rHZFRAvc8Njq0hbxNZ1MSAc6xtjJmF/QG+r+jfK/IExfSbk s+W78Y3Ydq2Bd0IAgTpc5Zq8a8eS7nj3+7W/cVCDQjhUX1mlGuV+uRRU7h/398M6xfsyyfWtZvB +7pVRc/BPBK6bF5So2ApA0gip6jYpMbPeIFFv1wmuoXxFXc8iZxBuo5L4y1y2JbR8UpucA0GsQm +oCcvUCgPhrRXLmVYxF32gmJ+mOSNG+N+zDoijwkiBXEAEX+hcbW2Njl5rDPFl+3vBZmYK1Dp9W +eD6iv/ckyfzqoY2WaIAVXNcPrht9P9UOdi1 X-Google-Smtp-Source: AGHT+IFLIS04qqyGqzlRZ5P0W194aznwzcHcQbxiQS3JxGmT2PGbdCWZ6vCUfMt+OWVG2KHiq8wlVQ== X-Received: by 2002:a17:906:c14c:b0:aa5:2575:e75d with SMTP id a640c23a62f3a-ab2ab6bfe61mr656555466b.2.1736435719534; Thu, 09 Jan 2025 07:15:19 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:19 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:02 +0100 Subject: [PATCH v3 01/14] btrfs: selftests: correct RAID stripe-tree feature flag setting Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-1-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1114; i=jth@kernel.org; h=from:subject:message-id; bh=602kjni+87ScGLTTRcJreyPkEJNwSWrWWrRwoSU1jmQ=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2B+7379917fqToaP9y88gS2BTJ7n5ReNeVOpoTmk 5PGdzMXdZSyMIhxMciKKbIcD7XdL2F6hH3KoddmMHNYmUCGMHBxCsBEAlYzMtw8u2UK25VpJb/+ qaRocJz84nM72v3HRd/HPXc0+qe384sw/Hdqk1XYtuDwL3ZRHpuuB5tU2Kzba6ev0vmoVvFsEkf HSnYA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn RAID stripe-tree is an incompatible feature not a read-only compatible, so set the incompat flag not a compat_ro one in the selftest code. Subsequent changes in btrfs_delete_raid_extent() will start checking for this flag. Signed-off-by: Johannes Thumshirn --- fs/btrfs/tests/raid-stripe-tree-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 30f17eb7b6a8a1dfa9f66ed5508da42a70db1fa3..2e8083f1d0d184a23317facbb566ef949639a8a7 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -478,7 +478,7 @@ static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) ret = PTR_ERR(root); goto out; } - btrfs_set_super_compat_ro_flags(root->fs_info->super_copy, + btrfs_set_super_incompat_flags(root->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; From patchwork Thu Jan 9 15:15:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932893 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CA4521CFF0; Thu, 9 Jan 2025 15:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435724; cv=none; b=m/67/5fH47skypbwytnwL/2MPJ0yKKPCWqjTZTG8/BcRIybyGZ87X714s5YBQeuK1eEsj3ytd1xmFN8imz9nXOtH81p4nzeD0BKpu0fuC77aYgXmlU5YSkpaQNgFt+ZfU5dHcFbD//1gpbi5Fqjt5WZHagaEAkPlYU923XpLsxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435724; c=relaxed/simple; bh=nDHaNn1VA42Nqy+KzH1vDglgIIwzwAdXjfSI9GIrdPI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eA/Qm2ztzSMDT0tTPzHJehAuqQSmSsg95FT4ElBARw6twU3N3stE2qMxUUJvtrGlKkY26753FqfzP9WvYepcU+ajN9Ix3rgjTg2hcetUqzXz490/ggLVZ7dh0tU3iTkjHGY7eivoNRTwXmSVTaAVRExcUB1D5qdDOAfAmsIQD0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-aa6b4cc7270so166666866b.0; Thu, 09 Jan 2025 07:15:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435721; x=1737040521; 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=5nPgOpo09U+aMg6lojzJKZD2YVp6zwKoPsftL/1sNH0=; b=Nb88PqKfdbPl8xJgSC9fbh1+fnR1869BiNLS3OzPXsmqUun2dBEFhmFe759goAAtqc /+XYOo9O19U6eE1MM689U70++C/v3Fe/9/tHq7+r/4NsQOaC36gtSxMfFQHWZMv1hmcX kMEQgUtBPdUTyAmVTcxpxvuVlfDtuNcC4pDyIGBl7jvvhk3IgdrCXmjh0uw+qoo5dKfl oeCQ26lTUOnEcvwRYoI5CoDrH5Vpnw+CoObSGxOd+PfUaUsda5kCh6TbUrVqlE2+mxjV 6diSYWIf4tQwx6k11MLzQ9Tb+Y1aAC+QuSCO2t/uRVqonzNvZJnNWXiE3TbQ0U5UqdzC zTlA== X-Forwarded-Encrypted: i=1; AJvYcCUY+EycPv6nw9xrqGcN3BCCXhcRbM8CUx5M300dnWdhWqlo1syo1Ep83Il3CcJ0/28T7j3UKqEoXoAGgQ==@vger.kernel.org, AJvYcCUorxAa2BpFLMjCOvHD2bAta9uqSsGrgGS5usnND1yKi0Iid9TcBZ3sIeQn9CeZcyFxG0N+XKtlloNpYhxp@vger.kernel.org X-Gm-Message-State: AOJu0YzvlvHMN7lHVuR+E6tD7zWhE5+mX/Ux+Njs9plDPrzC0+0G0NgS L1t2G+0obx70HVTrEx+Vo3IdV4HKn483ckafqzgLxvTiK/vRMFsJ X-Gm-Gg: ASbGnctlefyvABI+TFwg9HHs6K6OmHqVUxWw+St8yoGkHOkjGbCdzpC731js8hxrf88 w9INcaDLgI6+Gz4vONeYPb/QYzmJ5mKzdZFS5WBXixr18UuN/LQ4LtVy4eyBLvmLIJ50Z4Cc1gt qZyk6rhZBwIVtqMGrkCXnjYfkGeQ7MyGXsigVFm6fOf448AlxSsALOnvhSAudSisyHNPypAno8/ xiIKrQkGOLVjXQYK3Axqdzctqowtl/tTZmZtrPiv15cFqKk4/vZnzX4tKjgeO0swDG53RTYJLhH igM8kWGKVYahKCrrDSlSZTikWbWoW/C9EwML X-Google-Smtp-Source: AGHT+IFN+NzMdezi7ezy7wiCDC3wI1o3mHTp3HqBNtSwXbXJSkSNbQz57iRGtIky8L8+I4gXnhaevA== X-Received: by 2002:a05:6402:321a:b0:5d3:cff5:635e with SMTP id 4fb4d7f45d1cf-5d972e63d86mr15500622a12.26.1736435720482; Thu, 09 Jan 2025 07:15:20 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:20 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:03 +0100 Subject: [PATCH v3 02/14] btrfs: don't try to delete RAID stripe-extents if we don't need to Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-2-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2212; i=jth@kernel.org; h=from:subject:message-id; bh=DwPyDVlnF+iWOQrGDC+7oSUBI24Ggo3Gzbhb6/bjcq8=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2DxPtS4+WGfWM7D595ssfceb5wtLSm+N2HVAqmFD h2/6yX+d5SyMIhxMciKKbIcD7XdL2F6hH3KoddmMHNYmUCGMHBxCsBEnEwY/heaef9m4zt211qx YrWemss6w4y77R9W6J3XzmCcoGYk2MnIMNXpla311n6TVGX+khtuHHcuCy9LPmA7p1qgeu7qM1H afAA= X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Even if the RAID stripe-tree is not enabled in the filesystem, do_free_extent_accounting() still calls into btrfs_delete_raid_extent(). Check if the extent in question is on a block-group that has a profile which is used by RAID stripe-tree before attempting to delete a stripe extent. Return early if it doesn't, otherwise we're doing a unnecessary search. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/raid-stripe-tree.c | 15 ++++++++++++++- fs/btrfs/tests/raid-stripe-tree-tests.c | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 0bf3c032d9dc43eefe158e430813add9292c577e..be923144cc85a0ecb370dbb1ebeea44269a1f4ad 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -59,9 +59,22 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le int slot; int ret; - if (!stripe_root) + if (!btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE) || !stripe_root) return 0; + if (!btrfs_is_testing(fs_info)) { + struct btrfs_chunk_map *map; + bool use_rst; + + map = btrfs_find_chunk_map(fs_info, start, length); + if (!map) + return -EINVAL; + use_rst = btrfs_need_stripe_tree_update(fs_info, map->type); + btrfs_free_chunk_map(map); + if (!use_rst) + return 0; + } + path = btrfs_alloc_path(); if (!path) return -ENOMEM; diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 2e8083f1d0d184a23317facbb566ef949639a8a7..f060c04c7f76357e6d2c6ba78a8ba981e35645bd 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -480,6 +480,7 @@ static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) } btrfs_set_super_incompat_flags(root->fs_info->super_copy, BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE); + btrfs_set_fs_incompat(root->fs_info, 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; From patchwork Thu Jan 9 15:15:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932894 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 4D08A21D58F; Thu, 9 Jan 2025 15:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435725; cv=none; b=tf9Z24wNHxelwW/6T31EAKChphxUQtOF3shxqbSGN1Uq0iaNfn5mlhPaUvT4TOPhVhjc3ckvy0285CZtfj4Y/Tgg5rSu/ge9jX3T/pM00BuSmgDUvbTQEYgqfYwQ0yUhidvb6jRp290RiGHGp4j49Xi+wMjU2m+EZK+pjzrEUlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435725; c=relaxed/simple; bh=dr6eMa7aZX3mdAc3Sis8Kf7XJi6Q+T6fLGYjF8gg0FA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J8/hYHCs09PyVPC0fqEhjayOjNdvXmg/UUYiprfol3pb3KHnf/YmzDSZOFkgE1PkI0V8Frnh9cCfzN+WHDmnZ9aOqFI4azzkDj7Akf5TEZUrp6PX9sEIwSRS8b9aTYMBSoz5R4JgCrcZjtXCPPAkvxiXThBCVgveIdoxiu3jAYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-aa689a37dd4so196559966b.3; Thu, 09 Jan 2025 07:15:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435721; x=1737040521; 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=TiVBZyMEPUj9kKl+Kgc4755bAqGr6clEU+UsodEl16E=; b=dDRAog8FR1PVS6CvJkdEiwBHY/0442CIcMdILW184+SnWK02PSfKKLyUQy7SY7O7FM wyV5+b8IJWF9B4Z/UVMHmZldVeghJpcQK48N7EPnvKkR72ibgSRuF8V5VtRD8NwdEVmr zcYMHQ61f3ibRwqn/Wb+eAKfSGF8odxIP0rHRsEChPS4KImcKe7DK6m6Lhu3wk87n5zT BqE/0XabQTXrI6DB53kMDrsbSE/LDtSovTNrTSJfw4xe6wP49QSUPEfCKH3rA3/Xya3L gjCaNnPtsDaMPI7tMZkAZuA8rQt9KKDTrH0Q0Q6V+FtVP/2H7padXwOkdI04rE+NnYR3 yrYA== X-Forwarded-Encrypted: i=1; AJvYcCWcqykb7l1crBFxKUfdWRLkHOrZOi3yCgD74B6L53Z5vJDNfKA6JexfLUr94Xxhwa0fCClMoXEG/vrxl4Lm@vger.kernel.org, AJvYcCXwpDKbZ70Qit5krqjBnf1N4T7WiUdlrUuCP01MdV2rFhU32qsXKhqafaR4e3xNsFKRHv9THJLLlfdonA==@vger.kernel.org X-Gm-Message-State: AOJu0YyE8SA2JLROl5Hi1BxEZYbHnwuxUwjW0rDUdWpkyLSa7CrsNXe5 rK3EAoHfsAKKRqDpn7q8zhz/A77eCX7VFFneYRGinOzGIbR4zD9Z8zpORg== X-Gm-Gg: ASbGncu5N4/XOedtuD8eX77R4IWUewXd4I3zR6xZt8kv5xHmgIUJdKWITishkonmjdA UB5/o6VpKT7p6hvpOFGiB3CHx+7DQxUJRhsJIatfcD0wmHCs8Lhm8W+u27O9UpKvfr0cmJRZ++m bHhp+MBD4SwBAYAmf8rKZUnCzZNAsf/OOIjHlpVeqeyBq5cDRkHWLCYg1wdq2HkRtO3kiqRr+nx RD9p+8y1t6xvDAjYQUqyCWcsjRGF2DV7UxQGWwjVxLe5mYhGTwI5iKd9u4xMiscfNsDRCR5pFoV pMFKnZS6tJPidLkBCTNhEyCOPK6hmEfnni+n X-Google-Smtp-Source: AGHT+IHjxecBjRighX8BRJMdLZbfV+1eK30ovPOKwEscHs1H4qbEiz19Apl39uMC7fxJ1nmIksO7Xw== X-Received: by 2002:a17:907:809:b0:aaf:117c:e929 with SMTP id a640c23a62f3a-ab2abcb1440mr641283066b.57.1736435721412; Thu, 09 Jan 2025 07:15:21 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:21 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:04 +0100 Subject: [PATCH v3 03/14] btrfs: assert RAID stripe-extent length is always greater than 0 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-3-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=797; i=jth@kernel.org; h=from:subject:message-id; bh=5L8Yr+hmUCjhksYmwhWau8cY2+f/Vjr1c4fw/eMouPM=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2BZ09hwX+FNFsu2/vtm061+Scr3rH17qDawJFBD/ rWguMTjjlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZjIX2mGf9aM5o4X9DZmsP09 NlXW9pq3+Q7fBRtlhPsXzBA5I8pznIOR4ecs66+z2xN/5l/OmZbqKmtzL0Z/n8h59pgHcxPKz1k HMQIA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn When modifying a RAID stripe-extent, ASSERT() that the length of the new RAID stripe-extent is always greater than 0. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/raid-stripe-tree.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index be923144cc85a0ecb370dbb1ebeea44269a1f4ad..0c351eda3551efec67c35d76d06e648da5f33c71 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -28,6 +28,7 @@ static void btrfs_partially_delete_raid_extent(struct btrfs_trans_handle *trans, .offset = newlen, }; + ASSERT(newlen > 0); ASSERT(oldkey->type == BTRFS_RAID_STRIPE_KEY); leaf = path->nodes[0]; From patchwork Thu Jan 9 15:15:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932895 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 247C321D5BE; Thu, 9 Jan 2025 15:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435726; cv=none; b=DnIrxGBQlyUikB3YKx6mkQ4nQk8tkieNt4SLBne5Gqmk59IqaUADj3TQlUK1Y62YsrcOegFlXaMfLwBJ/hh0sYIv9YScqeEcyK38X0/HTDvTXrJigsQjC3+IKUrcfoOY7rNVk2dNaiLex+q+QkSaqdgHWsN8F07qL/WAGX7+gcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435726; c=relaxed/simple; bh=7RU977jD6JRAc8nXAQ13ycRxUPQ4S0XJnjV+jaAEk0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U4wMA3tmWTPlYhVWL9opr6N4ZrAFaNe52k+LSu1h4ItL6Ogozi6lJVJDzJuEDEuLj+UWH6KlLX28gy3BuqEbVolfa6bw+VnAlVWw4AlRJGp8S8M1HuhTsKZIcopryzPZFTqc/9Eff+SCc999Dx/PqlO9aQE8UWJMEegW6bb2mNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-aaf60d85238so207514366b.0; Thu, 09 Jan 2025 07:15:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435722; x=1737040522; 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=0f7HYuc/zbqPX3K8D9UCOiwzkZM0PQUy17Tw7kvX52w=; b=s9j3gTchYHS5Mqv3Tv5HRpNZ1gxCImkPTymfGGFx67VW3MMKei6ZqexuAR6ayL1iWJ qJfyjMCXj16FVsZ4tbEOBNLgndVUEQSNbOHQo0BU7609M9W2YopQojufQUl9x+4pZpsT nlM0DjlKmEoagFiA6HWLmD/jkXTSLUj1iAl8j2Q9CaRthp4Yplf7vjCtoR/3y4H9NrXq 7Qcy4wQt0zK19Yknr4E0pC7Ek+FN3AXB54tWnYptaqUd4EjOp0EXB2WO1d2y2w4HAeCO vXVfSygwnv/vHWIWPV6MXJINqiTZBosPZdUSqnK8RUsCpXQZrE6RtU1dqHmt/xiC7raS Mi0A== X-Forwarded-Encrypted: i=1; AJvYcCUqZpHXecOzEu/jYF8uVCONQa+wP1GWyWyI4XN19EaTwMpcwwKGmLqm0n/kIi+KJ83A/uA30Ay4exV98OX4@vger.kernel.org, AJvYcCWLstVwELSZ72fE5RdEWQSBVkSdWWD+hRER3QZBMxxJ4dJ9HE6PSOIwQeYizOFbvms+BXRJV3/mPJJUGg==@vger.kernel.org X-Gm-Message-State: AOJu0YyFdN+chO6gaOUhudRJfH7fPkQjQP3LiAmZ/wgv30VjV279VrMq bCatNm/K89BLccjBvgIhMz3g6c5xPivYRBlRycQJkObdyDbNRIIx X-Gm-Gg: ASbGnctEhD5FwRB3/a6Ti1Rx1DY4EX5xNaHTkttuACNWIUGppbdj8uNvVAsylDfOwuG WcJRck3Bh6H1Uqdey95uyqm5PsBZtILbGsALhmZm/I6xuNt8epYxaKYBA0m0XzendY3amX9qCDd CiHuzdU9zEFqK9BW8kyJrs5MifC45MzQaq5FMFEqaMiR7gWu9I/TGTbqZWi0gnDLS5MLc7GxTJn 0cnvZYZ/2g6m07YA9kHCIxT4bVx68wvqI5G1G1xS/s/XUw0m21MKWSKYNmMfC+C57SZl+2B1ibI 7JGVBFf5LR1jW4SuDOX0CEZGeMI7HZOcuifI X-Google-Smtp-Source: AGHT+IEQDuH5vEI2s87tcEK5jCYm/XUFOxyLSJn5epjUE+x/2rNdA5AxjGzQGSgPPt0wmvtRSff3Pg== X-Received: by 2002:a17:907:9410:b0:aae:8495:e064 with SMTP id a640c23a62f3a-ab2abc78b52mr581770266b.40.1736435722341; Thu, 09 Jan 2025 07:15:22 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:21 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:05 +0100 Subject: [PATCH v3 04/14] btrfs: fix front delete range calculation for RAID stripe extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-4-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1158; i=jth@kernel.org; h=from:subject:message-id; bh=5+Uh5g3sT+QliGHP6NK8OMLhj3AmhkLM0KvlvFFuU6s=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2BpCnuVOXF6X+e62OX2i1srTrc+7cgSMnznxDv5a vOO2TLfO0pZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAiH/kZ/qck9LvuP3fqk47q j+kZYarbEw4/j1nywmVTpf9Vn8szpmxn+Geu5PBydrRWxNuyn5y/YwQWFrP6WPnXf7iU9FV3i/H Ke4wA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn When deleting the front of a RAID stripe-extent the delete code miscalculates the size on how much to pad the remaining extent part in the front. Fix the calculation so we're always having the sizes we expect. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/raid-stripe-tree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 0c351eda3551efec67c35d76d06e648da5f33c71..9e559ad48810b704c997ff5e51222aced0b91637 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -136,10 +136,12 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le * length to the new size and then re-insert the item. */ if (found_end > end) { - u64 diff = found_end - end; + u64 diff_end = found_end - end; btrfs_partially_delete_raid_extent(trans, path, &key, - diff, diff); + key.offset - length, + length); + ASSERT(key.offset - diff_end == length); break; } From patchwork Thu Jan 9 15:15:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932896 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 F1A872206A2; Thu, 9 Jan 2025 15:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435726; cv=none; b=jGZBl1adhRxIaX+S1gZQmQCrKJYgcOUFjIwILJVludPoid3zr3cgsOX62hzMzz5eQBgzVQWGnwu1rny1vwVCluND8oZnqdNoYpzD3MqVdYv3KGe/AJ8OF22n140dv7qefD1hwzaf+SnUuKS70r11mmPoasSFizioUM1rYp+52Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435726; c=relaxed/simple; bh=TPpzFBz1Tfok3H7Juh1nfS2qBg6gCG/rB+9bQp42q6k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KLt3R8KwAuyuRFZL6GvpXbmGyU7AOk4VOMU78Ok5aCN8JVB87zkiUXcEeTsV4ZdNeDR7+EM+H7Yw0591Nv/DERHt1Ar2seU5komVXMayiBHAfA+c3j76JCvR3JXvhahBS8EatJ39sb4ucJBLIleQMl1QSkzG76t/JtaqfM9q3Tc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-aaec111762bso213316066b.2; Thu, 09 Jan 2025 07:15:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435723; x=1737040523; 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=2zCcosPCtrb/W/+0fS/Fgj8H05OM3LWN+IlkXQWO1tc=; b=PFntVmtwcW3um8U3SHStGp7eBOyKCHm5LJhOtyfAc9OvFYcLhE5sSvAEBw+k4jVIAr 0yYe7fpwAiSsiALRTLkPKNAn0gYGz533I0Ex0KPpuKJsK4kzXvQUYw8t3S7784WSm5nE 5XQSLOk1uDQyvBN5d76fdVs/3DmcfYGw6x9u3pm6xN6X8kC4gMu4qQ7IdYvZC7ic3hED lJeNkvG3N+7kroTx+bEztW2vFMrFNTdWutnVxkaPPvCtpRDhHF+Ugw2srx+1Dt+kJjJT 9vg8c4ei/o0Y5P4xsuKkDmP5SXe3QLCtRoXXWRU0hWc4nly5B8G9ceSd/tayV5WaMPhA 5j1A== X-Forwarded-Encrypted: i=1; AJvYcCW6CLoG69MUu9X/9hG54WbC2vZ4dfb+Z9D47rDdioYG0ofqjUD1TBQ9TthgL+vWqYknkJ7KzwFWTCNTfN4q@vger.kernel.org, AJvYcCXwGwIAsAdIl/+z8/C49npr0cFIEz2HPQDOepjpWETmj/9yw1kwvrCts5h6QVZqNubVL3TasPusAtvEQg==@vger.kernel.org X-Gm-Message-State: AOJu0YwZR/hQRpT2Xr8+b9HWW/4FTDUDc5cLqqqE1SYO6hMaDVzCSCmt jfSybWPUJR9gOa31vC1yK4QndAT9Gpe8LF+Hy2lR3YMQydsCXHVv X-Gm-Gg: ASbGncuZn/srYdYcO+OIVfW4dvefmlIO9Lqull8z3K4t70dg3eabfvma4O7sRVwXnvX GndRy1wrkzl5ygzNbrmBiDnI2CiUx9/Fqo/Rd92B9G8e0eHLDiv7zCTmfmaBDyXtN1bMJhWDmbn fnnGonqVg+toeZHehyKU/oOC5wJbhZqSMOCDh1V0I9hUEpweBI4Zj12AXwtCTCdf65zTkYlOhmm SytxmAAtn9KrprX20zn/dE2zjsYwDeRLyJb+zl5Hlrarw5jx/f1K9YBiWZgMo/cQLEdGNnomkqv JP3HY1c5+sRP8T17HVHyeh24FxG4RaKALLuO X-Google-Smtp-Source: AGHT+IFMZS8N6ajle8qw/ZE0uq7t8wx3XX+lJtOj6WkITaDfrFdr1C9nEgNfIu67IuCGjIN815loeA== X-Received: by 2002:a17:906:4fd0:b0:aa6:a7ef:7f1f with SMTP id a640c23a62f3a-ab2ab6a760emr606877466b.11.1736435723334; Thu, 09 Jan 2025 07:15:23 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:22 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:06 +0100 Subject: [PATCH v3 05/14] btrfs: fix tail delete of RAID stripe-extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-5-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1188; i=jth@kernel.org; h=from:subject:message-id; bh=yBjlqqgQ2kb+Va+7H2jeNcFMvs3zrjoSGy7Zp6K5xgU=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2Dp0d8rs+2SDM93A12xxKwtGtdkfS5z/3nK4JCeE ljQddm4o5SFQYyLQVZMkeV4qO1+CdMj7FMOvTaDmcPKBDKEgYtTACay+wIjw7HZ8mW/+VZpbVOY Om3Oxb5rOTv4BH3ivm+6kyQ1958mpwrDP4vft6JLv0R/2F5/vDGUV/Kmz2RXx7lK07SC/1xTlXx nxgAA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Fix tail delete of RAID stripe-extents, if there is a range to be deleted as well after the tail delete of the extent. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/raid-stripe-tree.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 9e559ad48810b704c997ff5e51222aced0b91637..ef76202c3a38460c5a36d7309ac0a616f73b0cc0 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -119,11 +119,18 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le * length to the new size and then re-insert the item. */ if (found_start < start) { - u64 diff = start - found_start; + u64 diff_start = start - found_start; btrfs_partially_delete_raid_extent(trans, path, &key, - diff, 0); - break; + diff_start, 0); + + start += (key.offset - diff_start); + length -= (key.offset - diff_start); + if (length == 0) + break; + + btrfs_release_path(path); + continue; } /* From patchwork Thu Jan 9 15:15:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932897 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EC66221D87; Thu, 9 Jan 2025 15:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435727; cv=none; b=AZVwHx71lSAtmeoFuexjfZPFjYqiXfPuGuyznP7htL5g4pvqYmQ9LzucLeRmtUXfG/p0sXJ8+c+MlploB+tFdHJ6HKOd4ubnM7HVGWe4RI/DI6+cm7WlWW4nyLPKCKa4UADdGqrkJOrTlAEreljRwTXdsvqZ1Zjlo8oZHVBgVjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435727; c=relaxed/simple; bh=5+GO5u/tRwV2HB0C8zTuqEoqQvdwsnHEErFsy2/1Kgo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=toHZ+6Gbymy2bJzB8daKzrpnb+6YfYUGCMrFP5JoORDuoby76meiHDPYmJmyjxSywOoKB49G99Gp0/xuC2s2TizFZaVb+YfL0gkeCjLMq0GWXhE/YbIBE4gFZLillAOSqD9BibwmgFzrCfgr0w/XqlQAHABnPUtzPGiOgPHcmPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-aaee2c5ee6eso179506166b.1; Thu, 09 Jan 2025 07:15:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435724; x=1737040524; 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=k3d8/nVjfNcp0Km7LERY2QbSQIyI1MyK/I+gtmInxFs=; b=IVTZANbuOURrwUOuwMjLcciN1S38RK+2/0AeM5zcUIloWdfBXE/MMei95v05yISRle dP1zVPl8zF/aC8kuDzcaz4M/7/fagE0JEUygWwhhIGsPFxT+4VNsB0nU+B/3uTuVfQDG 4c5oB82Tu/taBf9eG/DJmcHyLBD34RFb6IzeTTFWZX1KPKI+93q9DjKq06Yc0H+L7gl5 9AQX4Klv5OOWMBpdFNCp0rvxqumz7tLjpEmvj+UrLVpDKqoiTPHcDdeeZKLpdSkzZQv8 cLEBF6e1+45RS89M+lI3twh3Gr+EPXVVDg23NvTJcqY0/HSP7KRxY3JU3E7GHUWSizwY 4YSg== X-Forwarded-Encrypted: i=1; AJvYcCU80WHWYpVLUc6VpASUkTa4kEYAuPWdY332Zs4AYvYdt/KFDAs8NXy5R5HjtxKDUD21IWymbcCtFlH2Wg==@vger.kernel.org, AJvYcCWac2NCDn3haqLfzpAgZlx8+9p+hwRpx1yONVHvmv9jn6C658w76qkUWAMNQ9OkfKYnQYUcfFK7ihAZXBL1@vger.kernel.org X-Gm-Message-State: AOJu0YwYU4Pm8dvnL+pSOiXnUVGMuACxh0N3yS4o/IpFdEP13/9Wjh7i 2S+pkjPkYoLEfvfUsHc5lzy0xlgPzK1kQKxvGX5ceHAH05uMrRd9ZINusw== X-Gm-Gg: ASbGncudrkeKjubHYB529mjO+l0bENgZljaNA+Rj4Y1uDSBp5owEsoVud9JvZ+0YdIj 2ZD+NBs6EewURp1kqnW9O0ZGvXC1L9of21mqGOEZiGKwt2GK0cvO2HOlDWBdzdTtx/IRgvxl4QT gijwVfkTGHYb8mORgJjMKNBibCw71QqZHvdmj6JW8U4sf0oXFVG7ePQrrC0+yCD4KfZITWYcVOk a8ioqHKmtY58HUo8O5VYxNXVJii11od6w5AviE40LSKVbfG3JK4YVMkNu95BvDXfqfnSeV1EZ0z MAUcFJ3cdnRkiPYg8HsTitm2pRXhJ5yJ1RsG X-Google-Smtp-Source: AGHT+IF8O34911EEdzAt8qt/e9HM8Sk/YAFRhXRHiBJBlPuEkOAgaheD/qkb7Tr30p40exllObRCXg== X-Received: by 2002:a17:907:787:b0:aae:849f:3255 with SMTP id a640c23a62f3a-ab2ab709e27mr609965166b.34.1736435724278; Thu, 09 Jan 2025 07:15:24 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:23 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:07 +0100 Subject: [PATCH v3 06/14] btrfs: fix deletion of a range spanning parts two RAID stripe extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-6-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2146; i=jth@kernel.org; h=from:subject:message-id; bh=ewxDBIkZMuYfdG9lr4vnlMtFx3CMq9782G1Np1tOcSQ=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2Cxf7gh79T1bQtiIxvi7jT8CUg97nRvhnKpg7DVm tMRdb95O0pZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAiHdMYGbZlmCuWHN5gw778 2VY+jk93rgg+4HQ63Gw1aeW9qFt1Ya8Z/vD0WhVcUKtil/K+mtH5rKHlyfP559/GZgpvPTN/M7d yJSMA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn When a user requests the deletion of a range that spans multiple stripe extents and btrfs_search_slot() returns us the second RAID stripe extent, we need to pick the previous item and truncate it, if there's still a range to delete left, move on to the next item. The following diagram illustrates the operation: |--- RAID Stripe Extent ---||--- RAID Stripe Extent ---| |--- keep ---|--- drop ---| While at it, comment the trivial case of a whole item delete as well. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index ef76202c3a38460c5a36d7309ac0a616f73b0cc0..7ddc139ae1cf2d4844b1955ed3ecfe1b91f40049 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -99,6 +99,31 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le found_end = found_start + key.offset; ret = 0; + /* + * The stripe extent starts before the range we want to delete, + * but the range spans more than one stripe extent: + * + * |--- RAID Stripe Extent ---||--- RAID Stripe Extent ---| + * |--- keep ---|--- drop ---| + * + * This means we have to get the previous item, truncate its + * length and then restart the search. + */ + if (found_start > start) { + + ret = btrfs_previous_item(stripe_root, path, start, + BTRFS_RAID_STRIPE_KEY); + if (ret < 0) + break; + ret = 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; + } + if (key.type != BTRFS_RAID_STRIPE_KEY) break; @@ -152,6 +177,9 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le break; } + /* + * Finally we can delete the whole item, no more special cases. + */ ret = btrfs_del_item(trans, stripe_root, path); if (ret) break; From patchwork Thu Jan 9 15:15:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932898 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 1DBB3222563; Thu, 9 Jan 2025 15:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435728; cv=none; b=lIurE3wQPvaRLi9+mj6be1a0XtYc5pOH5d6DnQ4nfJ/klHqEBW+k7jftF2zL5Qk9LpcxJyH1WelVqi3BRplX1Fcn2cdAUArklN6tiqFvlwcVAuebu0jRQ8W1xX3YufCx6W+4T6ldcX3a9qMD/Vy1GxZY3vK4m0BgipMI+Vu9La4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435728; c=relaxed/simple; bh=41y7RZ7gEYvLkAxEzpK1EqpSSlg8rGbhKlFDY0WUQvk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BHpBvaDZrTTBs9BRHvV1czvPf2RPXGpXCE8j5ZaHoBEQCmdC+qS9aZxUTe2zaZkdiW2DIRgqqEmI2Vn/U2i9xQhG8KYG2vsehEcPb0pKeXv7ZHUTpIMLPYW85lheqTR0N6UX0bIsdUGvV9rbgLi+Mo0wOajna3l0AW9U4kqKCBU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aaeecbb7309so211219766b.0; Thu, 09 Jan 2025 07:15:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435725; x=1737040525; 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=dbj3XbmfCs1NqrWpUNZLnYWPO6zpl4oL3yPP5bqydJ0=; b=cOFiK43raP8EK/1h7VezrbpLD6ul9WFWfsZhbT+P8ETcqZkIO6FTyYOdPviVwNsvXO zWM9sq7o0jLJ4sXxQJx3xaH0/xA+tgyXhxlAcVJ3wA15i5x1qEETDcjMQOJfRJD4/ToU KDJWqEqM+iTsxKITUTflJ1gVzMsTSXwQPoXIMD4XutpROm5DZ04EUwouXdJh6Bo6pcL8 jMqlH+1gV+/PEUBuBtMh4goyyMybjV9ecClDJ67PANQAOEQvI8RLJ2c2VAVEM114u5QR 6+xjQAI/zo/nEX0EMA53Jv23fyKSK38ZZaKk1Sk0icfho1jrxkjlMPnzUzfdEjZxsVRS 7H/w== X-Forwarded-Encrypted: i=1; AJvYcCVUB83bIvf9qIWbp7Mg/rk/YvYSFQO6dCXgW1Y2PNyT4wMR/8gSOt87k7bnRrE5fjf4um2JsNx6/sgshQ==@vger.kernel.org, AJvYcCVqGJxBqmaIdTR/Yd/2X/E028TJajyY/hv0krQzLKbKTjQNh/6/L5+3jmvvG+u1Ck2W6Wruag14N/KS0R3L@vger.kernel.org X-Gm-Message-State: AOJu0YxWOWC2BGv+Aw4ExbG20vFSrSNwLFjbFNvBdv0Qxrs9clrDm1hA NLkkXGayfXcHN08NcIPPmTZW7m3aC6maNkToY442gZ9V6lm9jcH7 X-Gm-Gg: ASbGncuGK3Zq8RQM6CbiLI45hjf0MnbNUenDPO3hnkimHGXBFxeXj+bB3OZ8KX4I7/a iAWhY9dNSBp29mQYlapIaaduqbsr86UZmL04H+lSBplQq+mpD5VWTsDfqmu14bGRMiSlLnTh7TE /VOE/ov6Ybq548LgEzSCs/K1b5pb8Yj5p95Ha+hTvw1Jm9NWGvJnjOL7CZlSP/dZOqunpyCu8rJ NCNL/JX8v/AD1SivW0f5AUsVC2Htn8AJKRD1eFBL8JeAP/w58yhgsICFgMBqAiKzNwQur6MY+jS fT9yMG9htBRGhdwF4eHhJTCOPp6LVzJ8OsYU X-Google-Smtp-Source: AGHT+IG3vrh6023ytXDJw93ekDuO2rlP63qmfezgFi8yNraYUiHG3+Ckk1u+HcA9aEONKN/bV4GzTA== X-Received: by 2002:a17:907:3da8:b0:aae:ce4c:ca40 with SMTP id a640c23a62f3a-ab2ab740698mr563703966b.32.1736435725206; Thu, 09 Jan 2025 07:15:25 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:24 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:08 +0100 Subject: [PATCH v3 07/14] btrfs: implement hole punching for RAID stripe extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-7-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3166; i=jth@kernel.org; h=from:subject:message-id; bh=R9uOQGw9UkR9TkHDlN99eELkUGXAOXliXrIBwVbzV9o=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2CZsTRS5kns56KQ1l0d8yV2z3yt/GuLY9C9u4d8j qzfd3/prY5SFgYxLgZZMUWW46G2+yVMj7BPOfTaDGYOKxPIEAYuTgGYSHkaI8OJDXUXNu78Fvx5 Z4ShhcDR5IVrio1aPjEyH5766LDd48RpDP+zTjE3rva9EbGvw9PtlvThfTWJiiefuySe1dMNYpF 85sELAA== X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn If the stripe extent we want to delete starts before the range we want to delete and ends after the range we want to delete we're punching a hole in the stripe extent: |--- RAID Stripe Extent ---| | keep |--- drop ---| keep | This means we need to a) truncate the existing item and b) create a second item for the remaining range. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.c | 1 + fs/btrfs/raid-stripe-tree.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index c93f52a30a16028470594de1d1256dbec5c7899c..92071ca0655f0f1920eb841e77d3444a0e0d8834 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -3833,6 +3833,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 7ddc139ae1cf2d4844b1955ed3ecfe1b91f40049..e0bb95304dd51eb8e4bcf11281e65092e4551645 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -134,6 +134,55 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le trace_btrfs_raid_extent_delete(fs_info, start, end, found_start, found_end); + /* + * The stripe extent starts before the range we want to delete + * and ends after the range we want to delete, i.e. we're + * punching a hole in the stripe extent: + * + * |--- RAID Stripe Extent ---| + * | keep |--- drop ---| keep | + * + * This means we need to a) truncate the existing item and b) + * create a second item for the remaining range. + */ + if (found_start < start && found_end > end) { + size_t item_size; + u64 diff_start = start - found_start; + u64 diff_end = found_end - end; + struct btrfs_stripe_extent *extent; + struct btrfs_key newkey = { + .objectid = end, + .type = BTRFS_RAID_STRIPE_KEY, + .offset = diff_end, + }; + + /* "right" item */ + ret = btrfs_duplicate_item(trans, stripe_root, path, + &newkey); + if (ret) + break; + + item_size = btrfs_item_size(leaf, path->slots[0]); + extent = btrfs_item_ptr(leaf, path->slots[0], + struct btrfs_stripe_extent); + + for (int i = 0; i < btrfs_num_raid_stripes(item_size); i++) { + struct btrfs_raid_stride *stride = &extent->strides[i]; + u64 phys; + + phys = btrfs_raid_stride_physical(leaf, stride); + phys += diff_start + length; + btrfs_set_raid_stride_physical(leaf, stride, phys); + } + + /* "left" item */ + path->slots[0]--; + btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); + btrfs_partially_delete_raid_extent(trans, path, &key, + diff_start, 0); + break; + } + /* * The stripe extent starts before the range we want to delete: * From patchwork Thu Jan 9 15:15:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932902 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AEF621D5BE; Thu, 9 Jan 2025 15:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435733; cv=none; b=au2YunWryrArJ9rbroLD6pTrnYHPaMdlg++IZRcYV78IJgJUaEhWqfWc1p8V1aDqilN660Ma4JCpvCCC+WdFT4Jwc6KkWJDca0wuGeqvpZQpIAWmuRJPwa6y6vuPoR7FyF50SqyZwLvgXkQUPv7XpBvdmi4Ma6ZVjawUUzaztU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435733; c=relaxed/simple; bh=iOUBr9vnm9rlrsY3YOAvgr1queRyQczGA5qSRr33m9s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OnuM0W4pIex9DSbZaKimxRbk9QueNtolVdcZZ0vY1ewAc4LTjFFyc0ZMdjfACXu7LCSCZK2cqYLBCxsFUZQ9ey2gNbEpb5k68zNhCEuYUckhp98tIjHsZPwvmFsEoeF3YORrpAINaXpi8+ZLjMBHEbMCdhwob9mKO+AHKEIa55I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-aa692211331so199017366b.1; Thu, 09 Jan 2025 07:15:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435726; x=1737040526; 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=pljSv7QY3Pirg6lfdP8PEgMpw5IukrzApLqHT3bx72M=; b=hs5+S4KhuSlrutytP+N9RX1kENSyPgtd1MrYWtO9rGSHyjaSQetV9759RFdu+r8Zc8 2PXVpTuV9XNcnc1FmI+fGe7K6m/X47elsORJbAbpt2WD8JoguWgMzIvsvWAVKLL+BIkm vs7gZ7g/RlD1lRrgj51GBE/7C69az0XSblTcM4GUWI8p9+Ht2+/QfSBu3DHSdyYQNKO+ uxyS6+mq/jhhGpABg1/CgSeceUYtY2T1fsy1H/z9n+N7CFsYYS+Ag5jI+FaEUPuF7xnp 282prb+fKBzx0cGrpgWL9UDd9i20Q1rmFe4sN73G4FuOniKztvzTo5bkXTgl9pq1/H9m hHXQ== X-Forwarded-Encrypted: i=1; AJvYcCWoGX6rX92mmlisWdljDDFZfSMmKxPEM4Qc+GPiOl2mFKjAcONi+J72T4H8iUX+Fx/ta0qIbzjLpAQZoQ==@vger.kernel.org, AJvYcCXB8a7V6HgplKszlebvGKPzMSbTgCgFjzNMd8kT7hUtoIidHwC6AgUXM1nXzzKO0mSJs9fvBmaTXuNFptwq@vger.kernel.org X-Gm-Message-State: AOJu0YxobkSQJEbZhKgq9zVVwjmwU3Wm5wLSw2/hwquY+oOaY5SaZUSa VNbo+lKo99nBGpTt2kIxYI7nggByDGgMYQTNadWHjdJDP7wuB1hP X-Gm-Gg: ASbGncuG+mfZpElYGmpRidyrvEq4hA9sNMp+5fdEi0P6EBFcKvOvNsfEi0wpjRn+LKz AX0nlIObJoaugtsA8rFEezQeRWG+J4jX+WWU4jFw4yKdqAnOjxq+tdngfDnC1ukjVRU+khJBGyF 6S4pjtr1E0LYxo8U1UYu95F+6lZS4u9imiZMsLH5yf+/6IfWmbHbDp0m6BpJ0Ol2M1ygYSbQ5qw +dub754BZovtqEqjGS1UN2Wizyu74JoDIljyeGIa9V2InUfiQy72Y0jolkGbaDs3qqSBWqHtzmA 9trzGrxOqbB71CVlEcmqmpYoeadfb7SSg5C/ X-Google-Smtp-Source: AGHT+IEnsw+hDxcoSXj6T3wnTBcrwuatmJ/U3ynXMmNHmu4TpSUeH6lBUfT/aBdIYJfOfgo0cPY6RQ== X-Received: by 2002:a17:907:12cd:b0:aa6:7c36:3428 with SMTP id a640c23a62f3a-ab2c3acf112mr270311666b.0.1736435726135; Thu, 09 Jan 2025 07:15:26 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:25 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:09 +0100 Subject: [PATCH v3 08/14] btrfs: don't use btrfs_set_item_key_safe on RAID stripe-extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-8-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5674; i=jth@kernel.org; h=from:subject:message-id; bh=z3Xi2x6xfSi2w+ggmz2oPWTKmTsszHxlh33hmMOG3kM=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2DJOhlzopxtYS6Tzb1S7ornHZxhQUJ/Fi5guHS58 N2e96VSHaUsDGJcDLJiiizHQ233S5geYZ9y6LUZzBxWJpAhDFycAjARjwsM/6MSfHo8O2RTZkme eZvq8un1o++OXsaWAsZazxYX2ZbGBjH8d/3I+8LfbM1Ltw1WL8pfHZ7x/LRHYsfuu7/uv+beb/a xlAkA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't use btrfs_set_item_key_safe() to modify the keys in the RAID stripe-tree as this can lead to corruption of the tree, which is caught by the checks in btrfs_set_item_key_safe(): BTRFS info (device nvme1n1): leaf 49168384 gen 15 total ptrs 194 free space 8329 owner 12 BTRFS info (device nvme1n1): refs 2 lock_owner 1030 current 1030 [ snip ] item 105 key (354549760 230 20480) itemoff 14587 itemsize 16 stride 0 devid 5 physical 67502080 item 106 key (354631680 230 4096) itemoff 14571 itemsize 16 stride 0 devid 1 physical 88559616 item 107 key (354631680 230 32768) itemoff 14555 itemsize 16 stride 0 devid 1 physical 88555520 item 108 key (354717696 230 28672) itemoff 14539 itemsize 16 stride 0 devid 2 physical 67604480 [ snip ] BTRFS critical (device nvme1n1): slot 106 key (354631680 230 32768) new key (354635776 230 4096) ------------[ cut here ]------------ kernel BUG at fs/btrfs/ctree.c:2602! Oops: invalid opcode: 0000 [#1] PREEMPT SMP PTI CPU: 1 UID: 0 PID: 1055 Comm: fsstress Not tainted 6.13.0-rc1+ #1464 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 RIP: 0010:btrfs_set_item_key_safe+0xf7/0x270 Code: RSP: 0018:ffffc90001337ab0 EFLAGS: 00010287 RAX: 0000000000000000 RBX: ffff8881115fd000 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: 00000000ffffffff RBP: ffff888110ed6f50 R08: 00000000ffffefff R09: ffffffff8244c500 R10: 00000000ffffefff R11: 00000000ffffffff R12: ffff888100586000 R13: 00000000000000c9 R14: ffffc90001337b1f R15: ffff888110f23b58 FS: 00007f7d75c72740(0000) GS:ffff88813bd00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fa811652c60 CR3: 0000000111398001 CR4: 0000000000370eb0 Call Trace: ? __die_body.cold+0x14/0x1a ? die+0x2e/0x50 ? do_trap+0xca/0x110 ? do_error_trap+0x65/0x80 ? btrfs_set_item_key_safe+0xf7/0x270 ? exc_invalid_op+0x50/0x70 ? btrfs_set_item_key_safe+0xf7/0x270 ? asm_exc_invalid_op+0x1a/0x20 ? btrfs_set_item_key_safe+0xf7/0x270 btrfs_partially_delete_raid_extent+0xc4/0xe0 btrfs_delete_raid_extent+0x227/0x240 __btrfs_free_extent.isra.0+0x57f/0x9c0 ? exc_coproc_segment_overrun+0x40/0x40 __btrfs_run_delayed_refs+0x2fa/0xe80 btrfs_run_delayed_refs+0x81/0xe0 btrfs_commit_transaction+0x2dd/0xbe0 ? preempt_count_add+0x52/0xb0 btrfs_sync_file+0x375/0x4c0 do_fsync+0x39/0x70 __x64_sys_fsync+0x13/0x20 do_syscall_64+0x54/0x110 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f7d7550ef90 Code: RSP: 002b:00007ffd70237248 EFLAGS: 00000202 ORIG_RAX: 000000000000004a RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007f7d7550ef90 RDX: 000000000000013a RSI: 000000000040eb28 RDI: 0000000000000004 RBP: 000000000000001b R08: 0000000000000078 R09: 00007ffd7023725c R10: 00007f7d75400390 R11: 0000000000000202 R12: 028f5c28f5c28f5c R13: 8f5c28f5c28f5c29 R14: 000000000040b520 R15: 00007f7d75c726c8 Instead copy the item, adjust the key and per-device physical addresses and re-insert it into the tree. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index e0bb95304dd51eb8e4bcf11281e65092e4551645..f07d898694c2f27a4ca59e4932556de7edf77a10 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -13,12 +13,13 @@ #include "volumes.h" #include "print-tree.h" -static void btrfs_partially_delete_raid_extent(struct btrfs_trans_handle *trans, +static int btrfs_partially_delete_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_path *path, const struct btrfs_key *oldkey, u64 newlen, u64 frontpad) { - struct btrfs_stripe_extent *extent; + struct btrfs_root *stripe_root = trans->fs_info->stripe_root; + struct btrfs_stripe_extent *extent, *newitem; struct extent_buffer *leaf; int slot; size_t item_size; @@ -27,6 +28,7 @@ static void btrfs_partially_delete_raid_extent(struct btrfs_trans_handle *trans, .type = BTRFS_RAID_STRIPE_KEY, .offset = newlen, }; + int ret; ASSERT(newlen > 0); ASSERT(oldkey->type == BTRFS_RAID_STRIPE_KEY); @@ -34,17 +36,31 @@ static void btrfs_partially_delete_raid_extent(struct btrfs_trans_handle *trans, leaf = path->nodes[0]; slot = path->slots[0]; item_size = btrfs_item_size(leaf, slot); + + newitem = kzalloc(item_size, GFP_NOFS); + if (!newitem) + return -ENOMEM; + extent = btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent); for (int i = 0; i < btrfs_num_raid_stripes(item_size); i++) { struct btrfs_raid_stride *stride = &extent->strides[i]; u64 phys; - phys = btrfs_raid_stride_physical(leaf, stride); - btrfs_set_raid_stride_physical(leaf, stride, phys + frontpad); + phys = btrfs_raid_stride_physical(leaf, stride) + frontpad; + btrfs_set_stack_raid_stride_physical(&newitem->strides[i], phys); } - btrfs_set_item_key_safe(trans, path, &newkey); + ret = btrfs_del_item(trans, stripe_root, path); + if (ret) + goto out; + + btrfs_release_path(path); + ret = btrfs_insert_item(trans, stripe_root, &newkey, newitem, item_size); + +out: + kfree(newitem); + return ret; } int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length) From patchwork Thu Jan 9 15:15:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932899 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 EECA022259F; Thu, 9 Jan 2025 15:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435730; cv=none; b=pxKVlUski+uo+xeN+Ii2oPB94LWUs8vLdjUnC4YYEDrhbRZ3ek9DCcfZY7lvuo0NOYJsMOYY02elbkBk8PBhJGfQE0UqXPlQ9KIiAbD02EYRsv69B+dZFG7Sc98Sq4EPTBg71OoCmLr424Ca1wAHchnc4qCy09J4y3tOwjm827s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435730; c=relaxed/simple; bh=kxPheXsGcgr7C7bmW2sFDIN+8yZhU6P18+xwCuVRn3o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j6SLaTfvSZiOFbR95tnuH6sN6vwAQcFBoRFGDgARBooLrJejeQarPqjJlEDdden8FCg2wXA02wJb83H35yFvZbFpJWD/TCXYG+kkmMETSkCpm8n+bbaEWPBvmSn6NoAas3DqMrFBIGQccDNHXjne7sJMT9lbfifw6OVAc2UUPa0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-aaf900cc7fbso211592866b.3; Thu, 09 Jan 2025 07:15:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435727; x=1737040527; 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=s4qxRvmfu7+JXk512bdqWeZXj/ZLfnbrQ2mO7uJqnjk=; b=Qr7uDvfgSwFI+HcqhZRBzzrNzx0VbK4Xc0mr+Gk+w78qiERWxJj39QfYdPH9O/62N9 4wHN+QTCeQAIoFu5738Un3ai8SNUIcRhbSrO1l8KtfNTjr5N6GbsF2zrYXMQoqqFXZ1W 3LJKOaIcaS1zWvRnLWe+cPw9kWi8OK+n9WB7xlSNaoy13nA8Gp0hRNUTqm5Ix2IFJfzf +jIl90EHl510D5GU8Dle7FzZIvSVVY/+GO9HoTuPNICPZyatK7rPfBCMZ82uawJFfnpl 306CzT1FxIx1Nx+UT90STAmKBPiGW9q5KZYCsWguuC4yfU94bFMca3W7MPOGzjDGfZH7 V+bw== X-Forwarded-Encrypted: i=1; AJvYcCX5kmg9HZgT+5YKpcbbj5RgaI56Anm29IhoOP2FaBj0o8IGkg8cRdkw6ldCxzi//dyvzx10ux1zuy/pfw==@vger.kernel.org, AJvYcCXGIfhPcV5tZl4vWvTkyo2n77Xp/oV6fzCapLILWoVqE7lcQvTo9gRA8/hQ0pCIiUJTwzRQ2QDuHu0MuDql@vger.kernel.org X-Gm-Message-State: AOJu0Yx+TIBCamcXe1Cunv+UAFU2a/64xf3x9X8s2M5KJ84nYDoyE7LR LqrJxqx0wQGZJ3u3gmjJMaZNNU0gjFbOI7zKDeTNuvvwhnuB9Rr8 X-Gm-Gg: ASbGnctr7fyqq8GB9Teib4ikq3rQ8pqvq5K5fmPY/eHz/LWyDgKKer8BjSsv3W+nzkS t6UchuCWsnCy93+UuP+c+anj/1m43CglGsB3DYAXJDrEq7xV93k84vXUd3Q5/eo37pEHxeqW07/ GSAlRsJixxjn6Aw4f4JgJQg/7MVQcsRtRRBVob8NR8ZK2V9lQTzNN9xCd1U/kxzoeLxddK2AWy7 necF+thT07sapdHGSDF9MPk/PGZnb8CildVlQdo9h/nNHt4WxxVRxIO+wzSbR3NoWWJs3Fr+tGn S4VSNqpp+hV/Ld+mLqtwHbxO8QWsEEtyleZM X-Google-Smtp-Source: AGHT+IHDDZceAa1sKL8dn6/9yMfzEjIDZXcupVZ2tXxTfyaRTVq5pZ7nCEdRdnyajz9BCzCdqPSSFQ== X-Received: by 2002:a17:907:6090:b0:aab:d4f0:c598 with SMTP id a640c23a62f3a-ab2ab7415b9mr632374966b.27.1736435727071; Thu, 09 Jan 2025 07:15:27 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:26 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:10 +0100 Subject: [PATCH v3 09/14] btrfs: selftests: check for correct return value of failed lookup Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-9-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1169; i=jth@kernel.org; h=from:subject:message-id; bh=Hai+FH+wlQA9jUF34rKWHq12Hes2Et4vpJtRh4PDbc4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2A5tI5/wvrLHYyPik+ZPb2ubcgS0zynvP70p4+bJ VcuzWSU7yhlYRDjYpAVU2Q5Hmq7X8L0CPuUQ6/NYOawMoEMYeDiFICJrE9lZGgIEfq1WYTJWC0r V70izD78wVWzs6/fi360F33JZh2eqMnwT9mhU0rxe2z98zIN1z/PmxzLJeqilKW7m2zms/4SbL7 JBQA= X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Commit 5e72aabc1fff ("btrfs: return ENODATA in case RST lookup fails") changed btrfs_get_raid_extent_offset()'s return value to ENODATA in case the RAID stripe-tree lookup failed. Adjust the test cases which check for absence of a given range to check for ENODATA as return value in this case. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index f060c04c7f76357e6d2c6ba78a8ba981e35645bd..19f6147a38a54f6fe581264a971542840bc61180 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -125,7 +125,7 @@ static int test_front_delete(struct btrfs_trans_handle *trans) } ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe); - if (!ret) { + if (ret != -ENODATA) { ret = -EINVAL; test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", logical, logical + SZ_32K); From patchwork Thu Jan 9 15:15:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932901 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 486BF2236E9; Thu, 9 Jan 2025 15:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435733; cv=none; b=RZbhYJlv0CZ7Wrv60To1IR8Ef+v2mA3oBT+JrLV4nPeyT8NScyQcLAygUvN7Izk54YZ8YW+F3iXfqgTg3zonyuDeHq+SUz3zodcaH2bm6JrQaetOtvzr9wqL9b6AyAdE8tbkRH90EvsF3EOdFI+exNzdl2tSNSK8zH4fjOdVtYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435733; c=relaxed/simple; bh=Y61cv6XONm5aSh6hqCsDgZWpAA78IkIVPAV2P/Gdd4Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DdFs7bOCzk2roErCrqGmbF0+eFhz0sBkbbX6CtBFNUEHbHKSaWKxY62uWK2HJTITccgEvLVSPbJGeUMK8cGdL5ph/vOsi9leRL1L53sJPLlGhmMbwHz7gLy/9ftUBFPcTNgDLPfGlQXyY8FLOFoDKb01mbpTRF9hP+iwb/MIbRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-aae81f4fdc4so223173166b.0; Thu, 09 Jan 2025 07:15:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435730; x=1737040530; 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=Wo94xRQW7tw3npwzxFYun+vVy3ZCNUGiTzgM9DSsIwc=; b=FJ13hmUNvfK5a4okH9p1MiBogwnOOkf6Yp4euXa/+DsW9YUosA8rUj8XXjAehPK5ie 6KWNZHvEDWBWOkJlJG8Yl2ycnBBhPBgyXhQF0otvoNlHoE3+J+VDNG07GYv039TPRYsp HmTYxCp+M/oaE3XWM/QJ5Hjp7RjrI1jD6iSjwNw8pTLg3fWmzEOwqIxV1jzEqyvsMuPr QUerpgt4WEoXTs6AhFWTnneOvSZnnmttW+Tt7gmFu31SPLD85+CPAXDR16lL9m9ZPZgg GpCPWpHPfgA7RL2P9LB3Id7ikdfdBqVwHmloR8cO9juU1QLsWeBKuDD0vJvWrYKk80VZ K4Vw== X-Forwarded-Encrypted: i=1; AJvYcCVhrCZzBwWpSWXuILfdQqmUjw5OJVALK4KZGHZNPZZy2+dWRSKGqSYYX9TNa5PhUsg+SmsCuXTo3uvYC6ZM@vger.kernel.org, AJvYcCXqxXDMzBwLi0nR4M/gFAH60yI9gJkVd3J4kZhRXxTvW1eGUsX3q/f7WsMmNOADX4NaahIjp0Vsa1CCCg==@vger.kernel.org X-Gm-Message-State: AOJu0YyRtZj47UqsjvHrsnbbm/6aGPFaoMb1dKtpivaX0xwuw5RDtptA OwRYicBW2ZKk8BX8FSpExgnbrnkzLXlLwpjZVxlu0LoRX1CMhx5z+IKFTg== X-Gm-Gg: ASbGncsXKctS7CbAe4uDd3Rbf2KCRqpCTBHsGpXM+7gBzOab2Y8oqIUCvow406vG9EF yM1moSYp4T2lklf2e2p4P9Kq0Aqmtu9jLWbejVzXTYmq/B7MoaxnU9REGTHdw7n5nzrvwPhH4MN qZ3xRTjk64xFgxldnAngIbDNYpgjJ+2chBSG0mNfeRnTVIOcbX3HxUd80sfpXflwkD7pfehndww wdT0Xkvz+fYn8SDjat5PhUXa5/F1Pz4rlfatdOXOWpuGTlzSpuJLNuUdAX0meyENyZ28ooMiRSx gmE90GbEcsKMZ8hxhgpFy+MB3JRBb48BUPMJ X-Google-Smtp-Source: AGHT+IEcVa8XSVCe0QzRkAVY9XKYyYLE2XeFL1KBk6OoVV6Uw+zDcCV8N3Pas9Ppodlw0mk/5De94g== X-Received: by 2002:a17:907:2da4:b0:aaf:1183:e9be with SMTP id a640c23a62f3a-ab2ab6a8b31mr575455166b.2.1736435727973; Thu, 09 Jan 2025 07:15:27 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:27 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:11 +0100 Subject: [PATCH v3 10/14] btrfs: selftests: don't split RAID extents in half Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-10-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4127; i=jth@kernel.org; h=from:subject:message-id; bh=BKJ9UtZqMumOGnIO3fSUYTuxPI6H2ODSwOVX3gFSNx4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2A9aCnwtb/0Rc3Ktz6NMnePng+InN7mtSDlrvapW ber9uaYdpSyMIhxMciKKbIcD7XdL2F6hH3KoddmMHNYmUCGMHBxCsBEpDcwMsztyfVeaXPh4t+0 HXPyzk6qadt3uzVUS6CIs7ThBcPt3n+MDDv3vD2qcOQZ3+e3d7uDzwQqq6TuTfijJyBXFe2+5Zb +OQYA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn The selftests for partially deleting the start or tail of RAID stripe-extents split these extents in half. This can hide errors in the calculation, so don't split the RAID stripe-extents in half but delete the first or last 16K of the 64K extents. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 44 +++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 19f6147a38a54f6fe581264a971542840bc61180..12f3dbb23a6423c4d224c5b087b35862b8d643db 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -14,6 +14,8 @@ #define RST_TEST_NUM_DEVICES (2) #define RST_TEST_RAID1_TYPE (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1) +#define SZ_48K (SZ_32K + SZ_16K) + typedef int (*test_func_t)(struct btrfs_trans_handle *trans); static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_devices, @@ -94,32 +96,32 @@ static int test_front_delete(struct btrfs_trans_handle *trans) goto out; } - ret = btrfs_delete_raid_extent(trans, logical, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical, SZ_16K); if (ret) { test_err("deleting RAID extent [%llu, %llu] failed", logical, - logical + SZ_32K); + logical + SZ_16K); goto out; } - len = SZ_32K; - ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_32K, &len, + len -= SZ_16K; + ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_16K, &len, map_type, 0, &io_stripe); if (ret) { test_err("lookup of RAID extent [%llu, %llu] failed", - logical + SZ_32K, logical + SZ_32K + len); + logical + SZ_16K, logical + SZ_64K); goto out; } - if (io_stripe.physical != logical + SZ_32K) { + if (io_stripe.physical != logical + SZ_16K) { test_err("invalid physical address, expected %llu, got %llu", - logical + SZ_32K, io_stripe.physical); + logical + SZ_16K, io_stripe.physical); ret = -EINVAL; goto out; } - if (len != SZ_32K) { + if (len != SZ_48K) { test_err("invalid stripe length, expected %llu, got %llu", - (u64)SZ_32K, len); + (u64)SZ_48K, len); ret = -EINVAL; goto out; } @@ -128,11 +130,11 @@ static int test_front_delete(struct btrfs_trans_handle *trans) if (ret != -ENODATA) { ret = -EINVAL; test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", - logical, logical + SZ_32K); + logical, logical + SZ_16K); goto out; } - ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical + SZ_16K, SZ_48K); out: btrfs_put_bioc(bioc); return ret; @@ -209,14 +211,14 @@ static int test_tail_delete(struct btrfs_trans_handle *trans) goto out; } - ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical + SZ_48K, SZ_16K); if (ret) { test_err("deleting RAID extent [%llu, %llu] failed", - logical + SZ_32K, logical + SZ_64K); + logical + SZ_48K, logical + SZ_64K); goto out; } - len = SZ_32K; + len = SZ_48K; ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe); if (ret) { test_err("lookup of RAID extent [%llu, %llu] failed", logical, @@ -231,9 +233,19 @@ static int test_tail_delete(struct btrfs_trans_handle *trans) goto out; } - if (len != SZ_32K) { + if (len != SZ_48K) { test_err("invalid stripe length, expected %llu, got %llu", - (u64)SZ_32K, len); + (u64)SZ_48K, len); + ret = -EINVAL; + goto out; + } + + len = SZ_16K; + ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_48K, &len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] succeeded should fail", + logical + SZ_48K, logical + SZ_64K); ret = -EINVAL; goto out; } From patchwork Thu Jan 9 15:15:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932900 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 D2D8D223335; Thu, 9 Jan 2025 15:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435732; cv=none; b=pH1UE7mfg1pjf6uPf5mE8tf1lyxlpTq26+9WgMrMotMtPhS+UdoF9Nxwu9MCKuUn/RDmJ//mosrDXua4wWYDRHXLJHeCj7USD/Jw+2fkaXgf6QVZL7UlLBA2EBLDUAt9sznLkclWgsSqHlPGMoT4ROUHkeMWlZs76RkuCh3U9GE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435732; c=relaxed/simple; bh=dJgfFFrHMNX/wt/rlx1ta5IfOA20OE0pHFuC1mtWUk4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JW2S01rIYblvkDX3vcH8sQc6Ny8T3botZAkarufAENzbXlfih9iOZPP8qtVVhRlU2JiTnNMsBzudn3mhwNY/kpnkH2YBKoOSkQSTN0qswcDTAqi/4EO/lV/ZtYFO6uLXdFUtw4FRJhR186c42zsCngIGfnlpnxYor8ZWMuwMrwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-aa68b513abcso197669566b.0; Thu, 09 Jan 2025 07:15:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435729; x=1737040529; 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=71XSAwVnZXJGsAihpgV4sKSQDjM/13//Z7lrZY4oczs=; b=QnrTaSASkMJ1nEyu09Umq7xmVz1Wptz8IDHF/xELL6uBIMcdp7TZpyGytkExqxp+8O vYCOLloyut3+Lrh3PMiATID8Kfpzq2OoooXsA2oF6Ee3+JZxddoplMdfpHcSxhB3yQjA e8wtEmop53OeavCp6t7noh6EZ1qn2PeLvY3Dm6WwcSsiAR+COsAGV+OmAkHyzdCnLCbD jv8c1AXHzrTSSQydO3mNRn5JRcySrcTmPAvs4HnN++t+Cc3/ZVu2FpfZPncteTlV3/C9 UJ1mtrO9E4WO5MvRSTOESG0X83BpdF+tg1yc2z96F6dVLbnC4p2JEflbqhHWSB3yjnWp Cl1g== X-Forwarded-Encrypted: i=1; AJvYcCVJUROlJHqGzZAHM80rfImEcUVD9wYl3+x9GpLdtfM3Tuv731jAQutQedyRNhRV8fkUzZTV6XVkiVXIvLd5@vger.kernel.org, AJvYcCVuyrNEzpDwSh22/IMEAu0TXgNHUo1lRQK10kdf+kI3cRuEfPyyJehVoLFhUOI/5Guhm0MyWH8o7nUgtg==@vger.kernel.org X-Gm-Message-State: AOJu0Yz2gLb5C9FT+HEWIDSilr2S7RElC3vDGTe8Q4uLaMOLJC6f8PLm Mtcg5nEuhsH9ZeYw7benE5XxduIZHjrhMNf9FgxcHX2qhmuOTUZOmPtFMw== X-Gm-Gg: ASbGncvC9VY5Ucfp6/PPzvSGi/3qegMet4QXFi18ofcRK6atFHI1NaJJvmNhtj7S/9X TGVF6hehqzuTGavGggKLRAakvzWH4EsBGYQpn0n87nx+si6n2LUjz7noKrQVCAH+ZR4KoU1SAeX 0FToQOeNZmkmMqMJJc+vvGRPR6q58JbiGdyYn0aKywfbUkvWfcb81Kn4fcKRsY+jiC6UY5Wpqd/ JSfH/TCLYnm8z0R/0Q15P975ZHtApEPNOhR0ZJa7XWJ9ar1MCDaN/CrcbnBq8SWgIsCY8WDoo/s mNns56iH+RBA90ecmyGnL3wkHbdT4qCAAIcU X-Google-Smtp-Source: AGHT+IHwm7qlglao5OWNBR/6kYmwL8Y89xfmccUFdMBWRHsrLOIAIh8VrZLV9z8mYg7SWOG5TgQAKw== X-Received: by 2002:a17:907:d8f:b0:aab:736c:558 with SMTP id a640c23a62f3a-ab2abdbfe2bmr574170166b.55.1736435728901; Thu, 09 Jan 2025 07:15:28 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:28 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:12 +0100 Subject: [PATCH v3 11/14] btrfs: selftests: test RAID stripe-tree deletion spanning two items Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-11-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5465; i=jth@kernel.org; h=from:subject:message-id; bh=7tLwXx2q11gSgeKl57UDh77jQX1COSI4LUB0wCH0mGQ=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2BdE80idEhP4NruCcdkpRWrnOaueLt8sag480Me7 k1vs5h4OkpZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAiCzcz/E9IunTzR6iM52YL 2agnrELbP62QlP/7bPMWHt3SrVPaYqYz/OFrSV475UveNHZPE22fHnUljXPHKov2Nu99HcCiEMz 3hRsA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Add a selftest for RAID stripe-tree deletion with a delete range spanning two items, so that we're punching a hole into two adjacent RAID stripe extents truncating the first and "moving" the second to the right. The following diagram illustrates the operation: |--- RAID Stripe Extent ---||--- RAID Stripe Extent ---| |----- keep -----|--- drop ---|----- keep ----| Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 144 ++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 12f3dbb23a6423c4d224c5b087b35862b8d643db..a815fc5c4dd32e9b10844ad6df34f418c2e88ce7 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,149 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de return NULL; } +/* + * Test a 1M RST write that spans two adjecent RST items on disk and then + * delete a portion starting in the first item and spanning into the second + * item. This is similar to test_front_delete(), but spanning multiple items. + */ +static int test_front_delete_prev_item(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 logical2 = SZ_2M; + u64 len = SZ_1M; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + bioc->map_type = map_type; + bioc->size = len; + + /* insert RAID extent 1. */ + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical2; + /* Insert RAID extent 2, directly adjacent to it. */ + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical2 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical1 + SZ_512K, SZ_1M); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1 + SZ_512K, (u64)SZ_1M); + goto out; + } + + /* Verify item 1 is truncated to 512K. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len, map_type, 0, + &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", logical1, + logical1 + len); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_512K) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_512K, len); + ret = -EINVAL; + goto out; + } + + /* Verify item 2's start is moved by 512K. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical2 + SZ_512K, &len, + map_type, 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical2 + SZ_512K, logical2 + len); + goto out; + } + + if (io_stripe.physical != logical2 + SZ_512K) { + test_err("invalid physical address, expected %llu got %llu", + logical2 + SZ_512K, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_512K) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_512K, len); + ret = -EINVAL; + goto out; + } + + /* Verify there's a hole at [1M+512K, 2M+512K] */ + len = SZ_1M; + ret = btrfs_get_raid_extent_offset(fs_info, logical1 + SZ_512K, &len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID [%llu, %llu] succeeded, should fail", + logical1 + SZ_512K, logical1 + SZ_512K + len); + goto out; + } + + /* Clean up after us. */ + ret = btrfs_delete_raid_extent(trans, logical1, SZ_512K); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(trans, logical2 + SZ_512K, SZ_512K); + +out: + btrfs_put_bioc(bioc); + return ret; +} + /* * Test a 64K RST write on a 2 disk RAID1 at a logical address of 1M and then * delete the 1st 32K, making the new start address 1M+32K. @@ -468,6 +611,7 @@ static const test_func_t tests[] = { test_create_update_delete, test_tail_delete, test_front_delete, + test_front_delete_prev_item, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Thu Jan 9 15:15:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932903 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 A089C2236EC; Thu, 9 Jan 2025 15:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435733; cv=none; b=D87BUv+plsdiw3kDIvzf2vGaati5K882t3g3li0Ckl1yeAqaLsTPu6oIOJCbV9xOJ9DUpIl5X9uGKgFnHk4m2mu1nqqLuBQ4q7PhrXNt7rjV8eYRUOfywRey3a5XTinmaaI0YXf/U2PMYR5DCEr96kJwUvRG4j3n8rnd8r/cWoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435733; c=relaxed/simple; bh=7fuPeZ6eTkkUO02ONgT8YE81H5pgw5MM/PhBKMB8iwM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kVOCh6gGbEIj0s+UrjWYh+sWDBMYuUEHOWy7Nri0CNBuEPuq2sWT28aQ3YTb+hnxU8NYw1tFoLHJGtMrJfxtjWDHSxxANscOrUzarAKW3qtdEOQ6/VOqO65D+qjOG3SkWfuyNJjryUJHu+EPzft8M+w8ayek0THSlOiMGdpYmZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-ab2c9b8aecaso113540066b.0; Thu, 09 Jan 2025 07:15:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435730; x=1737040530; 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=g3PSh0B2ZMCmXCLngvICZw3M5+xhN20esGOtQ6jcvP4=; b=tqS96EOUtaz7T5B2kVm7S5m2iWjOi+Ck6A7IOJ211f78JqsqnOB2maGyOCGz/oxdY8 8tiT/hxJpXmpLsCYh6+PrqtP2dzNBZRTQWUeZBCuVH+7GDyPhycAnFYulVgweXdqmNXH L6o+TBWoQGC0pmwvuqAlyjjpT/UEi7j/RZrsQFoRcGfM3myyWjxHZtxRdSal6rrlZ7kI /RTEz7Ab3ChVe8K2Z/8hh2gfCe2CCq0H+GtGTlOR8l/o6e0tncYC/9fXTWPn1T3Y6Egd 2Sb8BHcwr7S+0QamPVeKp1awSkSuf1ug+xUI0VMDBMtXqxIiXTmenhJE330aF33la9Z6 MF1g== X-Forwarded-Encrypted: i=1; AJvYcCUM1HnU1NQXm8GmFNeflJVP1O5GCHuK0UH9wnxdE+8FQIFGx73d4VVT1jiGjrmJK39ECC6SkAz6Ii13RA==@vger.kernel.org, AJvYcCXClD+VDVR24JG67ALzNrU+JgrJXaDbD9z4Wn8eKIFtxaQPcFOdavqXtYVitOn4YaWXcJbTQcmLZzLANON1@vger.kernel.org X-Gm-Message-State: AOJu0YylS2bRsjwmWu3kAejGmMcaDkuhNVJqi806Brk5idPt5oYFVVtS LI2guHjYbe7C5OzaRqDScb2CakIMlVu59vRKbSk6ph1pGBn6G3uG X-Gm-Gg: ASbGnct9Lx2EhFadFb0GN8+Tjviz1RMZD3QHa9tJKp8K4akvMdyicm85mzaEJmnlgZh sh71/NxOLYUHUP/5cdx9piCVDzBCPhpm3RswFmWT0krrm/SxSlOu22ifJcs63Ay0o4fqC4/DPVJ NBtIQYsapNSXAnAoJ0SRweazh+9AizRm2e/jWWj5uvD95samRqXOUKEgAjd1CsDcYADho1wMRbq tem/043TI/UO4dR6rmWJ7BL6ZRpdnnPjVrThSJ1snkMXkXJQIc301t3ryhgK5wDLpOk4fBFi3yp OZgTQWtVAmJsJLBx41iYV6zUF4ez9EkaHG6m X-Google-Smtp-Source: AGHT+IHc4Ne0XQo49HEGrQUZxV1ZxV8G9yZalXIJPutExISHA/aoFHipW8OtY9E6nmjyjq4zmnix+A== X-Received: by 2002:a17:906:fe48:b0:aab:9842:71f9 with SMTP id a640c23a62f3a-ab2ab559c13mr663710166b.22.1736435729850; Thu, 09 Jan 2025 07:15:29 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:29 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:13 +0100 Subject: [PATCH v3 12/14] btrfs: selftests: add selftest for punching holes into the RAID stripe extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-12-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5069; i=jth@kernel.org; h=from:subject:message-id; bh=EVHDj16oSZY+6HbUp0NyPkXxXTNMaQAqUAlZnYdPi9g=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2BNOzhZqPu3qQWv5aeN+ZsSZu158HSff6Bv58N/S 5j4jOLcO0pZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAiEbGMDJ8UnhslKHz4Y/H2 ltzyQzWl4s+MpF4xH/h9qbl6o7C5iSrDf6cDVh+uCMesDv523vLjlc0zi6sXLGCtbFNdrdW/bcr EKj4A X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Add a selftest for punching a hole into a RAID stripe extent. The test create an 1M extent and punches a 64k bytes long hole at offset of 32k from the start of the extent. Afterwards it verifies the start and length of both resulting new extents "left" and "right" as well as the absence of the hole. Signed-off-by: Johannes Thumshirn --- fs/btrfs/tests/raid-stripe-tree-tests.c | 140 ++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index a815fc5c4dd32e9b10844ad6df34f418c2e88ce7..c7e44e944f5ecc37ffb937237cb81fefbafbaf9a 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,145 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de return NULL; } +/* Test punching a hole into a single RAID stripe-extent. */ +static int test_punch_hole(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 hole_start = logical1 + SZ_32K; + u64 hole_len = SZ_64K; + u64 logical2 = hole_start + hole_len; + u64 len = SZ_1M; + u64 len1 = SZ_32K; + u64 len2 = len - len1 - hole_len; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + bioc->map_type = map_type; + bioc->size = len; + + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len, map_type, 0, + &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", logical1, + logical1 + len); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_1M) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_1M, len); + ret = -EINVAL; + goto out; + } + + ret = btrfs_delete_raid_extent(trans, hole_start, hole_len); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + hole_start, hole_start + hole_len); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len1, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu, got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len1 != SZ_32K) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_32K, len1); + ret = -EINVAL; + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical2, &len2, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", logical2, + logical2 + len2); + goto out; + } + + if (io_stripe.physical != logical2) { + test_err("invalid physical address, expected %llu, got %llu", + logical2, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len2 != len - len1 - hole_len) { + test_err("invalid length, expected %llu, got %llu", + len - len1 - hole_len, len2); + ret = -EINVAL; + goto out; + } + + /* Check for the absence of the hole. */ + ret = btrfs_get_raid_extent_offset(fs_info, hole_start, &hole_len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + ret = -EINVAL; + test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", + hole_start, hole_start + SZ_64K); + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical1, len1); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(trans, logical2, len2); +out: + btrfs_put_bioc(bioc); + return ret; +} + /* * Test a 1M RST write that spans two adjecent RST items on disk and then * delete a portion starting in the first item and spanning into the second @@ -612,6 +751,7 @@ static const test_func_t tests[] = { test_tail_delete, test_front_delete, test_front_delete_prev_item, + test_punch_hole, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Thu Jan 9 15:15:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932904 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6DF221D5AB; Thu, 9 Jan 2025 15:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435734; cv=none; b=nAFANDgtXNYlg76B2QIf93laMTBg3fQRBXMIZvOcoA10yxmVTa7BN59MSPzo+pKq488ZNCQ2mpmLxl5ID92rXf4TWNkwUida2Q8I/Z37SeO/VT9ha9gxqRzIWxUn06AASqTBvIHbLLJcEYzL6Ktm/Kx0TztZ0p5hreLX0fxRZcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435734; c=relaxed/simple; bh=1AB4jwcI+lHYlYRcQqkQHVIt8MBO3ki9zuAxI9V49EE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PnM2vHdBvjfB3IL3BU2tLIwcQFgSPoo6jX8fmAtpPlqEGhENAqXbAwR9vPslGcZmQzabq686g0L/4oxlFSoPNsR73Zvd5TJ0EcZ/Imr26ahBRSJ4/54TaNEfRH+6afPcCG+04H63w6K+wb0KixJWxGOumNJ1cEQPw6/q1fJNNr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-aaec111762bso213335466b.2; Thu, 09 Jan 2025 07:15:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435731; x=1737040531; 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=C5zvsivh78DDNjeh2ZcSnXDI0hKH6mj4dodObFPkjBY=; b=wAxfWLcp+Ud5Csp0+3kIJd575b0MTAcx9BjbXnBEHd0D3MegvAHn8u6oD38fHKmqJS o/Qi6tzWUZdxzcapTL+qYOj50HaD+1SSeQp6WTa5rq8zy7aTRwzY/Kg9NlnJPLxIpQWd hOzF0SxpnDmseBa7QrWQ7aJbReXuUvX7A6LyGC2U+PYjipLhZ6dtUbhaM+bKhoHqr/Zk Ww8XxeuU6ri5BeACrkudbo/TKGo+/NjBEmCrK9DTKOLb8atir4qPl26FH1Mv1+yrW3PP bNqJWJP2EG0BC6ytwJA0J/atyrW1WllWAOzUFG/T9qFJN0KD/arZ3rF1EYVFVKer0arI t07Q== X-Forwarded-Encrypted: i=1; AJvYcCVQmdGnyQEUs/PBvS0N3cIsbEjzwOaNfKTflBXYIRKG/WuQ2D5L17SrVKtP5Q8nx3RQyfOlhwWCq6bmyg==@vger.kernel.org, AJvYcCXeZey5jyB3XDuvna3n+E2z3ucL4ZikVLUb9wl+zTgh5dKGuDj0bjgM6Y27miCKTF4xgpSaytbg1fewNGxu@vger.kernel.org X-Gm-Message-State: AOJu0Yw9GOc27j4zLz+GANNQjIsXctOt/d+jzrbxZak4o/7aXFOsM4Ja ma+T2bsc64mFUPblpbpCEWBIPy1c80gA4dztemGqdjRCKrsZRJWP X-Gm-Gg: ASbGnctWvtL8av4mrBk2QwEkucRcJWCO+c8SGlaCg+Q7jFVBgAxbba9nXUaOxdTCdLa FFnlOfOgdJxvN6NxpUxNyMkkJwEstYt4+nxIl8wTYI/H0X/ct5aGywhCggSFz4E+eo1DOk64UVk 9THdj8egLvLXAJ9D1FITHEvTd5wnIZKs9Aqfg8th/Ilokpwu2yymdS4tZzpjZBagT1RRYqMzRoq ya1NoZMWCwWgzs4Wbg+Oz9p/q4J6zMeYeV8i7ruCtkTE0fISNxeXjlP0QWV5Yo8vpbY7zjmThO3 5HpNQw+Hg5+hAY0LWfGV3o/yJWYda6FcxMDR X-Google-Smtp-Source: AGHT+IFMbcs+sRTrpEanYnX7cR1jbJDgbeZEoQAqS4vx8wNuafTXyiy4YhszQdUZH1pYN4qVzNcvRw== X-Received: by 2002:a17:906:c143:b0:aae:8490:9363 with SMTP id a640c23a62f3a-ab2ab7408a4mr681805466b.34.1736435730744; Thu, 09 Jan 2025 07:15:30 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:30 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:14 +0100 Subject: [PATCH v3 13/14] btrfs: selftests: add test for punching a hole into 3 RAID stripe-extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-13-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6236; i=jth@kernel.org; h=from:subject:message-id; bh=ZR4+z/8IzbGtRFmu+ycYbFa6RrLQUuwbhqkmEim1rB0=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2D97vpwX7P6tg/m2s3Td9e8+Ry6fP6Fq9ZV4XkvZ eq2XZ/2pqOUhUGMi0FWTJHleKjtfgnTI+xTDr02g5nDygQyhIGLUwAmMs2JkWGfhZOT4P9mxt/X XMK4Pa/aR388d/e2Xbr7hUkVe4s9nS0YGdbsVOFSM2i8rjBhRntiSm7/tIcfF+vdO68we0sCm9C KOi4A X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Test creating a range of three RAID stripe-extents and then punch a hole in the middle, deleting all of the middle extents and partially deleting the "book ends". Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 183 ++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index c7e44e944f5ecc37ffb937237cb81fefbafbaf9a..e12b6abbfd2be66170d33ab13b1e0971444c0f9a 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,188 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de return NULL; } +/* + * Test creating a range of three extents and then punch a hole in the middle, + * deleting all of the middle extents and partially deleting the "book ends" + */ +static int test_punch_hole_3extents(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 len1 = SZ_1M; + u64 logical2 = logical1 + len1; + u64 len2 = SZ_1M; + u64 logical3 = logical2 + len2; + u64 len3 = SZ_1M; + u64 hole_start = logical1 + SZ_256K; + u64 hole_len = SZ_2M; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + + /* Prepare for the test, 1st create 3 x 1M extents. */ + bioc->map_type = map_type; + bioc->size = len1; + + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical2; + bioc->size = len2; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical2 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical3; + bioc->size = len3; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical3 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + /* + * Delete a range starting at logical1 + 256K and 2M in length. Extent + * 1 is truncated to 256k length, extent 2 is completely dropped and + * extent 3 is moved 256K to the right. + */ + ret = btrfs_delete_raid_extent(trans, hole_start, hole_len); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + hole_start, hole_start + hole_len); + goto out; + } + + /* Get the first extent and check its size. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len1, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu, got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len1 != SZ_256K) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_256K, len1); + ret = -EINVAL; + goto out; + } + + /* Get the second extent and check it's absent. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical2, &len2, map_type, + 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] succeeded should fail", + logical2, logical2 + len2); + ret = -EINVAL; + goto out; + } + + /* Get the third extent and check its size. */ + logical3 += SZ_256K; + ret = btrfs_get_raid_extent_offset(fs_info, logical3, &len3, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical3, logical3 + len3); + goto out; + } + + if (io_stripe.physical != logical3) { + test_err("invalid physical address, expected %llu, got %llu", + logical3 + SZ_256K, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len3 != SZ_1M - SZ_256K) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_1M - SZ_256K, len3); + ret = -EINVAL; + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical1, len1); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical3, len3); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + +out: + btrfs_put_bioc(bioc); + return ret; +} + /* Test punching a hole into a single RAID stripe-extent. */ static int test_punch_hole(struct btrfs_trans_handle *trans) { @@ -752,6 +934,7 @@ static const test_func_t tests[] = { test_front_delete, test_front_delete_prev_item, test_punch_hole, + test_punch_hole_3extents, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Thu Jan 9 15:15:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13932905 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.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 7B1AD22371A; Thu, 9 Jan 2025 15:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435735; cv=none; b=Cu9rh1rR8ohz0hDIJvHwf6lZC+hSimsAYpiNflTtEIncZZYDplKtGMaarBmP9EUoETIcmhcNBOaL/A8nI+rJCLqVE5VlTup3yitv0aJQLYdL79vyQYMjSJrm0pSqJlTZsW/rB0QHnkIRbcWsjJSA3LcT3n4efaZKltNUOZObp8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736435735; c=relaxed/simple; bh=O6xA0U6e8EcrdV9gBkOcBpJ1iaQ0NLLesxhyKpoD70U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CFGPfd1ANDh6/8cYg9jiFHI2ZagYSfqLBFWosu57M+G22GO6StDgiIhdhVs67iSjSTyuL7YxSvB6MmDPyjIsLmNt7wazmLZPI4nZ9DrDncudWIrjDMvs/3s8+cCEcoz4nmR/mpGUmV1VVM7mM1KhCurR0/O1KgjNLs5Q4Q103Kk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-aa67ac42819so158995766b.0; Thu, 09 Jan 2025 07:15:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736435732; x=1737040532; 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=9VjMqnnPdmmXdxnSjbPvoY1ry5RF8O2XMIoYq3Ycrjc=; b=DoFyQ8iZI2xOwNBiVN4hYgMAdDjNNUY+XvP2A2ZhUT0wgdwU7pkSCC6ZQS/1/yTdwk LbrACUszzJoAIls49c5O5hRKZLEWozw6KNcTkAL3y1S+7CWqztaXp7m0HlB0GsgUi+Xk 7GkEvSP98qZjMv+0nPssuiKOTZJ4IQkuJFGhv/B80fgWTTnE2qkdw+t/sb3VsAWTU7Si pHUYVW3p3vrlzWiBFBTrHrI1xtZar6BLPeX0RDiW3gzzBvpaFF4rgM80BdYxytXN2fnh Hx/bFv7oEZMNZjBXsTAxrTl5cdxI4v4VW5fV2gfuXU9hDEoTw9UeRt6Pz7zUWGo7i6Fq jdbQ== X-Forwarded-Encrypted: i=1; AJvYcCVceqqINUQFanohHhFD2xEVbRfo/+T0DiLxsx3oGmmPBnB/MTn86oHbJsxRIV8whqp/lAp6qnjbb22TwA==@vger.kernel.org, AJvYcCWynkCRMkGwoZ6/W53DZ+mMba0FrlqxgglwVnEGwL9a1Z//qG3s/CzmkDrH0bV8W4m+Evb8Uo7+8G6VOyeG@vger.kernel.org X-Gm-Message-State: AOJu0YylsrvQw5+lqyWg7642PybJljd6X/3IAunWWPG0HlrGJzDF3L/w KcXsPOX1XS2+qDfpOLmU/S9qvFppRR2ikJhpsz6qry0+CTVWTqQJ X-Gm-Gg: ASbGncu/ypIMPwhn74fpVL6qhXkKEIuwJ8zUwb+8c3/Ty5IWN2Rau4Rm72WBQiUKMXt SvjSGCgEOpSc4L8mbhSJ5s68ZVVikmeDbbxjmsNYHZammd1XvcvHYwxcp1ZKrHbGMfKc9ancIsr TJhmOeo6TSZ9VLAaXOr4KzvmF8TY7rg43OSLg3TxzOnOVAd/3IjNM3Qawy3x9e+s0NneHJs4Jy0 B2HpEBmS26NxXtvpv9xRuJeRRqUmEM5LoX35ByGygwTM6Z0A4/3th2sFG1kh7oR7igsh1czz5wG 7zsFJNNLuiVohA+BGJ5Wwhw539g9y1KPXXHa X-Google-Smtp-Source: AGHT+IFVAs88sxMHf56IEEcXaCJLI3KFDemZBw9jJ3144m7fm/re9ArLlf/FClHAMC82Iqdr5unhXA== X-Received: by 2002:a17:907:7f08:b0:aab:9430:40e9 with SMTP id a640c23a62f3a-ab2ab70a84emr576387366b.32.1736435731654; Thu, 09 Jan 2025 07:15:31 -0800 (PST) Received: from [127.0.0.1] (p200300f6f7218600fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f721:8600:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95615a6sm81539366b.94.2025.01.09.07.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 07:15:31 -0800 (PST) From: Johannes Thumshirn Date: Thu, 09 Jan 2025 16:15:15 +0100 Subject: [PATCH v3 14/14] btrfs: selftests: add a selftest for deleting two out of three extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-rst-delete-fixes-v3-14-b5c73a4b2a80@kernel.org> References: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> In-Reply-To: <20250109-rst-delete-fixes-v3-0-b5c73a4b2a80@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4970; i=jth@kernel.org; h=from:subject:message-id; bh=tFlMhQskj89bb4c6eNa63cULusVqX4eFepmYM+2AqgU=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXv2A1mXtjxZ/XJcmbbmwp4ojbaXnv+YmpnyVTwup2d Ul7Tq6Z1lHKwiDGxSArpshyPNR2v4TpEfYph16bwcxhZQIZwsDFKQATET3JyPDfOfnVeS2b6Jsc 2fGBfX93zUnKX2t+9t8C5oAG+QmJOgcZ/tl8Viw7L/U+4KvDORnZHXn7e6S195jNf16+pueVPZ+ oAzsA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Add a selftest creating three extents and then deleting two out of the three extents. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 144 ++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index e12b6abbfd2be66170d33ab13b1e0971444c0f9a..6c7e561e55641472a63bb15c8c2213273111ad08 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -213,6 +213,149 @@ static int test_punch_hole_3extents(struct btrfs_trans_handle *trans) return ret; } +static int test_delete_two_extents(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 len1 = SZ_1M; + u64 logical2 = logical1 + len1; + u64 len2 = SZ_1M; + u64 logical3 = logical2 + len2; + u64 len3 = SZ_1M; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + + /* Prepare for the test, 1st create 3 x 1M extents. */ + bioc->map_type = map_type; + bioc->size = len1; + + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical2; + bioc->size = len2; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical2 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical3; + bioc->size = len3; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical3 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + /* + * Delete a range starting at logical1 and 2M in length. Extents 1 + * and 2 are dropped and extent 3 is kept as is. + */ + ret = btrfs_delete_raid_extent(trans, logical1, len1 + len2); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1, logical1 + len1 + len2); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len1, map_type, + 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] suceeded, should fail\n", + logical1, len1); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical2, &len2, map_type, + 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] suceeded, should fail\n", + logical2, len2); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical3, &len3, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed\n", + logical3, len3); + goto out; + } + + if (io_stripe.physical != logical3) { + test_err("invalid physical address, expected %llu, got %llu", + logical3, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len3 != SZ_1M) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_1M, len3); + ret = -EINVAL; + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical3, len3); +out: + btrfs_put_bioc(bioc); + return ret; +} + /* Test punching a hole into a single RAID stripe-extent. */ static int test_punch_hole(struct btrfs_trans_handle *trans) { @@ -935,6 +1078,7 @@ static const test_func_t tests[] = { test_front_delete_prev_item, test_punch_hole, test_punch_hole_3extents, + test_delete_two_extents, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize)