From patchwork Mon Jan 13 19:31:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937942 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 07CFD1BFE10; Mon, 13 Jan 2025 19:31:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796715; cv=none; b=okK7N7nQRGbXtymiGHjiL251KBXgzneb9JmBcWW4a/TJDlvv0XKM9YPlRJvvfJrDROM6vWIRbwoK3ll8Ngo8lm7fEnMpWn8WHYwj9VFM6ZPCqfcG5EdDhV99TPFjcMazenHHDuNfJvxHymDBYM2qAInz9QvF3jRPzwqDuuD8zwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796715; c=relaxed/simple; bh=12M08uOzmewaRubKx3ilmywyb5xCZHGXotZUfNS0yws=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uRRaJtYuIfqIU7k05JHBM8+8EG3YZQLs2yNbnAiFpJrDuRhStMEDhZYn2njsWRtw5EqqUZIG3mzSn+qDXltIuo9433PRmbFChX7pl94etX0tuB6E9qi5TzwxwHVEMwcFFG1XtmggybnQ0IiRnQMv1mrxfo+cLZcV1afC8aeL6WI= 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.128.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-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4361c705434so33815305e9.3; Mon, 13 Jan 2025 11:31:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796712; x=1737401512; 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=LaVmQNFO5ColZz3dSwoLzStXNgbCzBBF6SfmCjsGQeg=; b=bH2nZjQKw6caeANZTzHw0vCejO7fiFdgUXZEh2zkj430UKfRBHi2amkV16kWuthGH6 ASxyLoEepsuITVsqkheDrvWEm01WkObQrkeF9AkDtamIWG+0DrTk4o0MP7NYiOjOhMA0 v7iQbS3HoBL7JwC42OPIf1XZlIEvpf+w/JY/vX5FCtKk+/Xm+cWdoz2/oj/+0VVwTGpo rbJbNM4KUsLDgSkvy8UsTU3Ihia+BsCRHTZeI94vYmzUIiHL5CCZKKG84z1K6HDxNLr4 H+8m29o+ehhQKhUkfVbkWml+kGR6E5fjPB+0BnEyZ/Nl2zqEAU9PX/O1+u8GPZWiXoE+ /94A== X-Forwarded-Encrypted: i=1; AJvYcCUtPvC6E/BTxnUt2/QCMdQOym4wKITQz+7HdFIkeGJ+dbsuynnkZSHj67FwUxKjyTndyIVNqM9eHdI8GK/Y@vger.kernel.org, AJvYcCX4TjtYXsmLtOuR0su/ucnwIeXd7WKTVv0c30Z55jIjpUpP8DtG7yqhfRVXntxREfsTo9TRad2TNvu5Cw==@vger.kernel.org X-Gm-Message-State: AOJu0Yyw1gyqEDgSdkOfcRfitO6RCQnxrPTjZF7JqqODZpuCMutM0DwJ fJ4om/p9DHMY3HocfT+/HBPTZLMASOm7U+ms5+8lvqE0Xpejk5e+ X-Gm-Gg: ASbGncv6tvZq9OYX6cD/F7CJMtplhf697Cz//brrPjzsv6k1h8xua0FFdFn9703Q2eY 4nl6amV7ODMggXc5JuA+m5kZJ1IH744FR0+gsl5N/hGZ31IFX15Tn5LdOycg1PbzXQEAwwiFo8f tr+qqGhEaialMboFTawoYUnAESno/7LlkiPAUrcTiZ6PJnmrgTWWOG72T0O1LZu0LIVph0F4/kY 3KDXUYhl2ujdOS68dbz1MGD76bCVvuUeN9gFR//uJoQVcye/fxqSCVtdWm+la2BSO1NeOXSbFat hr3AYbH31UDi8QXMw0/g01oHAwY0ctRwLql/ X-Google-Smtp-Source: AGHT+IGcoo7XhMBGBK6O/oiRXZ83xTzhYTBdS2GhVc0EtNVYJLiSPhI5gzIic5Hgo2RPcZbNmYaj/Q== X-Received: by 2002:a05:600c:3543:b0:434:f767:68ea with SMTP id 5b1f17b1804b1-436e2677c7dmr223148565e9.5.1736796712283; Mon, 13 Jan 2025 11:31:52 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:51 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:42 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-1-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=1203; i=jth@kernel.org; h=from:subject:message-id; bh=KtjrQjuXR52mbd1aGQPzcGKndXVW0hIn1fHnx4Cksm8=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3Zqk0nJr1Lmn6RCGWQla+3sNyARXSsvymawLrfurcD g/e/4Ono5SFQYyLQVZMkeV4qO1+CdMj7FMOvTaDmcPKBDKEgYtTACbipMfwP9Zz65vdna73WOdF tNt7B71lf/GbJf3Z1jyPs0Easr5RjowMm7Xtd7y5/ER9Wo2xKVu4BZfINCcJHtUFL/NynL/Lp1h yAQA= 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 30f17eb7b6a8a1dfa9f66ed5508da42a70db1fa3..5801142ba7c3a43ea075a1f7aafe704c8e1e075b 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -478,8 +478,8 @@ 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_FEATURE_INCOMPAT_RAID_STRIPE_TREE); + 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; root->root_key.offset = 0; From patchwork Mon Jan 13 19:31:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937943 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 17B321B4148; Mon, 13 Jan 2025 19:31:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796716; cv=none; b=Xmi7gyy1eAeP2j3vrG7wG96oKPBCTMtw8oZ2oQ/f+mWY8ockcxGc39tCM+JQnBEQm62xrf9Kdrm5Uf97MGCtwxjeZv1bnNwJ202K3htUXO+Gi7IDfn8QREn4A4FYXAChLCwfmpT37p9K0owGSXv1fIanw4ohuTBWnI/nqN+qhLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796716; c=relaxed/simple; bh=yvho1QOJ5DawE1Hyg/ygQpn9UCmjwG2FQVhHi/Baiq0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lo/on7BqicxVUAmsjabytMjaQWjm4gIWtJ3wy2b3z2mkp2Khjl8XI+mhyoGBRyeSD3buejFROg/9tY/UgROlIdTKc2imSrG3R/4LGCMvt7W1SAOiGPXf0wZ7jFR2Y7utXuxDkKZI+K14LQHZNVF+KTt4TKdgHVK21kfZyNNfVdE= 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.128.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-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4363ae65100so49381445e9.0; Mon, 13 Jan 2025 11:31:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796713; x=1737401513; 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=SE8XSMUUJ4gCjDUgwP7SFNvKrBjkJdUPGdOmAllFh3g=; b=NwO9mlvyCqIapaiFdHWdoltD5ukwvVKGOF0ONsU/gD4uDKF7XvSgl38EhvxLL0gJHp Nxi6XHanGaQLRADLtvFYf0H/1wSb0+nOrp39WMaHv7oaqiddwHFBrwOdPiwBhDNybflZ DALKJRLkNR2046U/nmEOn2upsKUggX17nwDiE2XKYgVwCHXMKpHVFvFhvysOmMBvqoRc 1TSWDfH/Rm8yvDfmjdnFzo8yPe2QwtqKvZCfDNfyRezl8vYfMUg6zPyb88WXdxmcP3jy S5AQVbpL6KfIl//+je0idY4Y0rvaBqeypIEKmQ652g6GmJTLMAuUE9MdPt21zb7Q42KG 7U4g== X-Forwarded-Encrypted: i=1; AJvYcCV5AUU5GKGYTAAEnkx0UsaWhZ4NRffo8dM74jVEakPaC5uIWBaswA3MVVc2DqJrPvHbOaCLXtuR7j9xfXvw@vger.kernel.org, AJvYcCVQacGrJ6F0X3TPRsTMraDVIi6YoDm5iwaf+SkTGgJFoiiX8y4Uaki4GvtszjciEQHEo9oSpNRSzttI/g==@vger.kernel.org X-Gm-Message-State: AOJu0YxVX4Cu2xgbbs4KqmnSxtG8B4wyGaKS/hz9VovCmY1eicT9CTaZ 9LAnJiCfgPdpX7rLYYyy4cY7yqEfRU2GAh52CImz0G6xAhEVxUnj X-Gm-Gg: ASbGncuwe98rTh2CmF6NXwFDkGEAH9f7wlinlNzxU5WNngd3jmAwpT/xAUh50afwxkM shDHuVr1EMkm86UOcwdAMRt/M4WoDkpqWY2AiuNQeCUTbt8GOybZIjuoYzl0dDyvi3roPmSsUfo RThrDK6PHeaOtCrHC1sRlxePeCJkZnLGccF9oYJk9hhRdBsLRO7aMf1ecv2Yuh2VG99xKHTy/BV riTvkaFOFV0++tdbEIE9SDhma75h5JaAH4dvH9pjAfsO4mqj5pkeh+dL07CuViDY3RP+t1PqST0 XpAucg5O0yQ4Aefh0wrWIAvUxpOsvYZ3jSiP X-Google-Smtp-Source: AGHT+IGMLXP2TA1xWjQcRFg1t8Yk6OvFm3o5+ASMG1ohAaESsP663pokJPvk7znfCJOv8PBO3l6PzA== X-Received: by 2002:a05:600c:4f4e:b0:436:1ac2:1acf with SMTP id 5b1f17b1804b1-436e26e28cemr192394095e9.20.1736796713189; Mon, 13 Jan 2025 11:31:53 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:52 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:43 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-2-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=1462; i=jth@kernel.org; h=from:subject:message-id; bh=2C9jlaNt6GWgnHoLWl0KVRWkpPixzD1jfNTUzmhT44k=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqlwXV3REGF15vO7v6sd0vapvuxT10v2/1Nacdb7A JtKn29wRykLgxgXg6yYIsvxUNv9EqZH2Kccem0GM4eVCWQIAxenAExk62GGP3znbDZmbkwxMXoW zhSvUlMt5tKn1Zm94VV7VLDx1GTz5Qz/q5nMNh5y/WE++7Nqp23NofeG7Xu8zmu99WROu5k665c YIwA= 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 ++++++++++++++- 1 file changed, 14 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; From patchwork Mon Jan 13 19:31:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937944 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16A751CC89D; Mon, 13 Jan 2025 19:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796717; cv=none; b=B0PPVdWfRlnUG587SzIx7OecCLx272knAAgeOxrE43MQxbw3PK7UUevgFOP8uHvncXfvwtXXvEQYuD+uv5HRMfk+biou3ZYbD9vqYW7Meh1WCyoJZmxP3CoCHgLhl+uC1fHU6aqqUljGI/4E1H04M/U8kBs7lyiHmseCB49iocE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796717; c=relaxed/simple; bh=dr6eMa7aZX3mdAc3Sis8Kf7XJi6Q+T6fLGYjF8gg0FA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d42w1Bb/F7qpg598abmrz6xuo8qmvvasfK1Uq68aje8WptNmxdZYSrCPZZDY8q6UAhRr5yjacIiNPxQf/AiYQudY0g89OJKY0q016Mi9Pj1H44OQYZJ2N1NRLfU3n5pUFByUHfoUVPb9/HJIYJIdCoXpBix2pd5UfQl/TgrO6+g= 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.128.49 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-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4361f65ca01so44942055e9.1; Mon, 13 Jan 2025 11:31:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796714; x=1737401514; 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=Grj471EPIyKD5qOfIhEgeYUOm0DkUXtdcl2o5NuT9IEaC8V24fZkh647tlPvIk49O1 JuBtF53yHD5SR2rBmqQz8uFrHoVYe/5Bx2VtmvcYC5JsttgW+5Ir/UDSAcgdzbaiAAa6 J8RK1oyuBrXqUkUoYrCxjmiXHbkXr0FuMGhc+/vKaU5dES727QTdp9gLXWddZd59GxgK XVUmS7xwMFxoaf3C1gBy24Xp1Itr6NU7uOHOMrPk1shQsNc83MQ8BmyBLfJLydnpRg1i InYBqonjs72QLxm6gBR3rRZOSpQ86TnhF/GywJC933iwzPmhiiVydxRfqRNP/FuEd0u3 d0NQ== X-Forwarded-Encrypted: i=1; AJvYcCXLI5Iqi7aH/bGD9i6IgpExx6l0962YkeN8WeEn54IqICgxC8er0IsEerm4Hv2+v201Tw1C1dE4uVqkOw==@vger.kernel.org, AJvYcCXgzyEkRq8GO7lJR/7FSUv9CE4ZnaJ9XvB2Nm4e+pfedxb+4GF9Fg1iwK9osfyd+XYOxfu/YDJAtG5guCTl@vger.kernel.org X-Gm-Message-State: AOJu0Yzg93cy83d/BQV7IcsVCMBWM91r6jRJVYKC+0jID8sv961oagpd /Kt4NwWEsDdrJUNqmvYZykNZOA8+Mg34MLe3O9hNj3kyOSf0W4bd X-Gm-Gg: ASbGncu3/IKPjfU5PnOdbLKZGYmM0ddLUoeoz3v9CXmvcjtmEpt1x329NCJPY2mnylD qiezHS9x+0JnjJhsjbZSMi387yBXnIReqMEAcZJSV7tfq6AxlNe41zMRbDVFTYft37HQq+odOum nV6s4ZQRqixtNxi5ltJxsdK08wGStFM5OG1oNV78XTUq4Vz6mpT/kVBojNgK1BQOPvoAig0OOtt FNCAjZd+sZCz/TsnwM6xmWFzrHZHl+khW9Z5nUm5PmVdEvKfEWu3dOVFTupZWwzmlyiRj7BW6ds c+2eX4AgCe2Dq+9k7xubARtfvs9JnjU5aFTd X-Google-Smtp-Source: AGHT+IHBVJjLIrusI1TdzQuHNKTpjig59w/jnLNSt9aCKSHuQVlXfX70Erkju2vMfbhgxRCSZz9iYQ== X-Received: by 2002:a05:600c:524f:b0:435:d22:9c9e with SMTP id 5b1f17b1804b1-436e26d0cf9mr178309115e9.19.1736796714087; Mon, 13 Jan 2025 11:31:54 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:53 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:44 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-3-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqlwlXvWxDWEnN6bsDzt8sp9x5JVWE01teVTN+lGn 7wz69vqjlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZiIyEeGvxJRT4NKMh7cPxNU mqP95KX+12bZTs/4R2dFLDT6Qt1q2xgZ3r3SvajBEdR8cuIh4w0qS+1Crq0InLBbyLZJZUa+Vak wHwA= 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 Mon Jan 13 19:31:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937945 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 D09D01CD214; Mon, 13 Jan 2025 19:31:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796718; cv=none; b=YCJO5SoLskqK+HoPA8Z3fCiDb1IrRVBJYn0lB5vJAYRBpU+1GpKcyPNb8b+Dr9D6iaLtAr0mBEbqSC0Gf8tuDyLEXe8e8YJ0T7DdCjLo/SKNvMEKnBSVIU1h34eIhyel55IcKP9CetglNj3zFvBcwrGfh9jFJ7TYWqB+HnwlxPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796718; c=relaxed/simple; bh=7RU977jD6JRAc8nXAQ13ycRxUPQ4S0XJnjV+jaAEk0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RiLEWDL/KQzkLr9cGQp8CiINsC4bAegMHtwMZ21aJEf/14AgaVaajCtn5gfS7iLOxYPOIVNc8CnhSJKcApxJ+QvP2rB5m9FKwvWSsHlN0ynQNX1MqoRdlE7e1zRBYtHQP82FYdZwC+exQSKZJnFAPC8Cr9tn7rU02cvDwtfE/yU= 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.128.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-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4364a37a1d7so49383335e9.3; Mon, 13 Jan 2025 11:31:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796715; x=1737401515; 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=TlB56/cg+otbaigp8YX7WfB9y9xapsWHk4ltIWIDb6A0hHE1MaONppqxMEe/q3Hvr+ FWUrxK2nmK3uojNZAkXm3UJNdUplpzhpmgaDDS5zqFHKxTIrkdcnEYKLc1fateZeiGK2 ygcksckY54YC0ljnn188MYsYWBQEcVMu+q2eJ2mQFbQyyZoXNy4oXkUvKILGlbGYs8mF yWoosNSQUmnY0H4gpOATzzjt8kPUe8yD6hiWyGT7ij74CR6Zs6kKVEuZXEHZ0ZCQJGtM LaSjEut5GAd6hT5MCsd8O54CTa/43NRrn9ayheqc/SfB9EbBgCtasWuveqgRPW9FrLkZ OHxA== X-Forwarded-Encrypted: i=1; AJvYcCVPeSh7b/Hmaur07+cYjoVFuYLi6sWDDWZvvZx83d5KoIvAtVlLm0M690gfEowCay9D2b9p/sCbjvrbaw==@vger.kernel.org, AJvYcCXszIL2QRr1hf+/SecpBBxnUacwms8+1lc5BDSaWC45oddpubgOW4WW3QMapjIwiOiZ2pvnnNbtY7OLS8g0@vger.kernel.org X-Gm-Message-State: AOJu0Yw99JtXY49SsXhIj3zyfsJiU98WgoFakBYaMzXW3CDr89wlJOUY OIuhrhv18hl3A+uTcpM8cIcBojs1zF/ZRhW/oACHlB1lLk5Nugqzw8h4MA== X-Gm-Gg: ASbGncupwxw7BdXMKfddCAsJtaLBYz88dkHBf3y3Dtqy3CZTVOZ5B1CuOoexW8WPCgr Nj5wn84nfW0aPVO5/nt6CqjOejfcQOJzHq1dWtqqFKYbzeXSTyENTGoWy0OyLGiwck9kgAomlxH o0fMBw/UKpn8Slp6x6NbnYLCt9IvWHM/Lz6q/RF9luV2pjYFesj6UX3V4piQASyiRTX8ba+Uvd8 P7d4h3SQ+xbAVgsekIJXfZmP+rxxbNr8U+nEz+dXD9S6v7JeXs9zQqzN+BCMrFuMyUu6Whpkbyc Le3UE+MhI6cTEjipGqHz4+h2fxgRUSi856pF X-Google-Smtp-Source: AGHT+IEV6tZO9q1vLUrrCXo7HzrGsfGGmOd37KnbXPk5eWkBQpMOIoN2ppnPKkUgW0HrCSAn2Z9GRw== X-Received: by 2002:a05:600c:3149:b0:434:f297:8e78 with SMTP id 5b1f17b1804b1-436e267fbe1mr206805665e9.7.1736796714951; Mon, 13 Jan 2025 11:31:54 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:54 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:45 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-4-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=kA0DAAoW0p7yIq+KHe4ByyZiAGeFaiShqW9+25+MBdI5BWqrlaTaokB2WcrOZwOA/VsXf5/Em Yh1BAAWCgAdFiEEx1U9vxg1xAeUwus20p7yIq+KHe4FAmeFaiQACgkQ0p7yIq+KHe5XUwEA0VNu wPUDDKjOFsAyjmQA4KR/Ynn1jZsMJy2+zfwBxjgA/3QbkFsGT11fYi+8okCAntuZWvGP3YElIw3 Xje7xf7EA 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 Mon Jan 13 19:31:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937946 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.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 8BAB11CEEA0; Mon, 13 Jan 2025 19:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796719; cv=none; b=Y19FHbTyUGiYV5/s/Z2Gz/1FHOP9wo95AQ7bkDJTPIBaBuRCeRY+4OzHiG1YDm/8qP+x4foaPDOwLP6KiTrG0o34LzcsQYqrepM6l/uP6AE5XjkVJIdpio1Kv6VQm4k+ZS1LM5icZPj++6PguHGQz3qtmBzEoTtNbAqVvL5N75U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796719; c=relaxed/simple; bh=TPpzFBz1Tfok3H7Juh1nfS2qBg6gCG/rB+9bQp42q6k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H1cJdjSAO1gBrt3dFuC7POXF6/CS2KvkqeOx2QfQiv1tD2DAWNHcHteZGGSMYXXWC9lRcE4HLwd1sxrF970M2rGjIsFJ3MX6jndUNs9BZr903Hwn5ZJhHOhkV/XZCWWd34k6kuFuAOcyMPd9l2YHDbYaPHLBScKS4pbdBPoH5Nk= 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.128.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-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43623f0c574so33909085e9.2; Mon, 13 Jan 2025 11:31:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796716; x=1737401516; 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=ZsEaYpvmJzDNu7RVGunxsApSRPAsfCF5gQicBq3MxLzPrPfJRqg+ey4/A6BJsi8PK4 OkPrdGvqu+5bpwTlBIjAo6hZbNHtGL1fSSjjEHRhHcBkTux8Ut21jemLFfSUTbfXlsmv GQnpcp+qFzt0ac4iAEqEZPtUlgvAeMGX8dYE5S2S4b3o44CWsPKYNjBpmbYdRL+pucMk 5GAcUoR/qG+YtPI6y7eG4NN59epZuhQej3UF0FUxkqMq+Mdnq63q3O0jRLNk9JbNNbrd 9xlCL5ZTgwsbkXZn0faOj85RTM21J5t8soBAnttCoOq0ji70RmJ1NMMSL0BBRB5CsmTs vDaA== X-Forwarded-Encrypted: i=1; AJvYcCUtpq1HyxKR3ujAZZh7QZHO5o2AOSmsjg2b+jlxmc1IT6Srdl6me5b//x1nJSHG2J7yJ+GNhhEZ6weO9lyn@vger.kernel.org, AJvYcCVKO2IERjHInl6bCvSwCCl2w3uGEmxuiXJfkdjTvaOPq1n0kA/WoNc+QgUx8CtI6JqpCUMYvNttsksn9A==@vger.kernel.org X-Gm-Message-State: AOJu0YxBr40FsQP9icBAwPhByRHmebv8Dh7WQl02s8BUh+3fMHhgFY9b wNSW5ZqrnIt011TxvqWhQiPUHnqSMa9to/9XDIEy153BKyDxD19r X-Gm-Gg: ASbGnct6CEl0EgtZhKdrkBz4FsP8AdwgDvODbotRh/no3kVCWoSSZiFssal5NUTdCU2 N7QLllrUSmKNfTRboS4v7FN/tW1YDaQO3yIzkMs9pAsvNknAb5UYwdmGQ4sforWGEVgkS3ry6ix 5Om9I/no3WxB1/ckrsreJySkdAgLNVKFvvhqkWV9bnKTwvpzpyS4HpeNZAZzsd7+3FdjWHdBwYr 0CvtYL5rXwS7G8ihOp4tZwAS5CacqH3KfN03ztutOKFtVqui5wvVVup+4jIAU+B5PN8JLL+1jUg 07Y6j/9eJeK/1XjJUiZoZCTVouNNlCpsy5Wr X-Google-Smtp-Source: AGHT+IEuYsViG5PnE5LnRc/Ka1JVYXGAuxhgF4sCSQRRovHgJHJvwJpz0tbH8YPPqP4dDQB2K2fOVQ== X-Received: by 2002:a05:6000:1fa1:b0:385:ed20:3be2 with SMTP id ffacd0b85a97d-38a87355790mr22313544f8f.48.1736796715760; Mon, 13 Jan 2025 11:31:55 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:55 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:46 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-5-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqnmlGqveVa3e83vOQvV1tT5b7hwZ3VI9opby9Plv taaXPJM7ChlYRDjYpAVU2Q5Hmq7X8L0CPuUQ6/NYOawMoEMYeDiFICJvJdj+Ctt6BTqPNPjcWer qbrTiwfbLBZu0jpa5KHi+fCFw5brHMsY/ofpR1lO5tq6uav/1Pf5ke3SnMYqTBmqf17db9fc9Ss shhkA 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 Mon Jan 13 19:31:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937947 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.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 4274E1D434F; Mon, 13 Jan 2025 19:31:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796721; cv=none; b=pKTV0cnnmZFaPK/7+nNWd05be8RJ8OxeXILs7RPzsEtMcACK2KlO3WYor4pLFms0BrPWWMVE8iVTNe1xzct5WHPTlzSblQmjmAV6ZyDUslFOaUcOWHS405DyoOv+QsBiPJbPoAS31xhuKmIv2cDPSl+w+BQwHu+8KgO6C8kYQJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796721; c=relaxed/simple; bh=v/AzGRElAhfmCc0Wwzrav5BH9j1J8DzovXh2zzemAak=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pf+9HOB1kZvzljaULgpcPxzp6GTbfJIV4imt7QH9y/SaFTl6c0f1T4lMU5i8JufKISiYAi4dbfKwMIh4ZjWBaWC3C71SuvnhxgcqItinsMcopzSYrq3qpRL9xq4XpHg+qeDcs3bvQgpB++JmzVFG3BRgiME7Cv3/yHbpGB8iZyE= 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.128.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-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4361dc6322fso33111225e9.3; Mon, 13 Jan 2025 11:31:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796717; x=1737401517; 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=OwOVTJLL2QDiljjWMMdlNJK4mSoOFW+TYjus+eD9Qm0=; b=dlcHc65wn5s5Pfl6tCawbEozwg+N+qOCtPkxIjbod2WxNWnTba6MHTX1t9rB3pgV1T jnaFcuQB2IbL5GbLTB5pjxiovReDAT2zQAsZLdFxR0Q3m3qm+b35/6faORJyIPe4Rv8J ZWvuvaFS24olINwxIVHJrSn+WAuqEErQergPTKrth1GP3f2nRcNF+BMIMGFe0r8c+3uF 2Kiq0t/MSw6NMI1YGOP6wcTo2DrGGJX8ofAcIu55VrLeZj15D+OygwAvOUV1UaTTChRg a8JyQGOtaehUOwF84YZkT0AR1afBl9YvVmA+SjHgqOz+VmCSQRf7cYnrNxN2ZJmEISXK jz3Q== X-Forwarded-Encrypted: i=1; AJvYcCWsKO7mBBMIFEC9OOyepq6S9TPMU7x8+TXeXTAbOHcAo6uQY+VkeBC3vMzGTSdHnB5JDqolux6EseC1+w==@vger.kernel.org, AJvYcCXcMFWolNuVGHF4yRXT5IQBTKx/YCvh/0JWcjlf2i7UKdLsiKOHOR8AjomN6XfPprJFzAY4nqM5mYM6Ww+0@vger.kernel.org X-Gm-Message-State: AOJu0Yw24RQfzCRtK6/Jpr1yBfCrJoR67LJlFNXLZjntgVJf7gt3F2Tv UZHXHNjBCNkNyiE53F58yE4qrqgnTVDaDCk15HNo3DMG8GURUDht X-Gm-Gg: ASbGnct+4Dstk4sJalBrXps8e2Xov1aNTbibtqG1i/dHpyorwsprQQZbnqFJ2jFn2qA nbwELHP/hcMwgDLdWjf/KIAo3bTvvjZ/n8Mo3nZ3XpkniZuDrvxOqfvx2dz+rYc5wn3T4cTQnvP oMgfDRb/KnkAkWZqi8eFS8JRDDf5e3YDD/uj1lxdMf40EAjunqsIe2NjIiRRqlpmeBealFJTSSk +ykQ5vuI8s20VgoLDt+TRbqit4xt57v9iZVd7/+W03W4DIBywojqqt6FrTLh2EMeBvwVvS+xH7o pvUDa6H3GGxS/TzoqFEaT0CnHk2kFJBQmDv+ X-Google-Smtp-Source: AGHT+IEiqYxnpB9mXryVdK8Y1LbfuRKfFJIMpDEs/1Klnm6jxhrc8OXOfnAYYuNmJtW7q57Q+4ohVw== X-Received: by 2002:a5d:5f52:0:b0:385:fcfb:8d4f with SMTP id ffacd0b85a97d-38a872deb1amr22369913f8f.21.1736796716564; Mon, 13 Jan 2025 11:31:56 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:56 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:47 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-6-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=2290; i=jth@kernel.org; h=from:subject:message-id; bh=lKSxT/kooJ8KWaK7tVlSQBKGrctXAYhbadOlH5Nl02U=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqkW72Oqd300oeXLv6z24s4px75qXFcoDdP8uqtre o+uUmVaRykLgxgXg6yYIsvxUNv9EqZH2Kccem0GM4eVCWQIAxenAEyE5xzD/8qmGNmlQQ7nT1R9 7b0uF3VAQ/fC87dhU2UfnUrs2G78WJzhn1Xjp+SUE0u3xpU17ywxjX88iztyLpvFKT6Ofzf1Lur VMgAA 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 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index ef76202c3a38460c5a36d7309ac0a616f73b0cc0..439b0e63d00d0ffa3ceb2314a39f2653e8a6e9ec 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -99,6 +99,37 @@ 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) { + if (slot == 0) { + ret = btrfs_previous_item(stripe_root, path, start, + BTRFS_RAID_STRIPE_KEY); + if (ret) { + if (ret > 0) + ret = -ENOENT; + break; + } + } else { + path->slots[0]--; + } + + leaf = path->nodes[0]; + slot = path->slots[0]; + btrfs_item_key_to_cpu(leaf, &key, slot); + found_start = key.objectid; + found_end = found_start + key.offset; + ASSERT(found_start <= start); + } + if (key.type != BTRFS_RAID_STRIPE_KEY) break; @@ -152,6 +183,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 Mon Jan 13 19:31:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937948 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 443A01D45EA; Mon, 13 Jan 2025 19:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796721; cv=none; b=rnVuo7uBFoevU8cmuzEvlGOvRQTRyZmfA5K0XWXWkw4qOQoGpuyOoNnxBGoy6x7eCLR67NF05+RUxIKq7oNZtgObh7tR7eadyBOEd3apuydQxLJw1DKz2Cyqb8L57pl6qb8/+ab5s11fEq6rCjnIxewGZXy/W5iieIVFuZ3VG8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796721; c=relaxed/simple; bh=TmACSHqrN7sfl9FsVJCIJwxp+Q9vTJXTL1DaLOgUhYU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s6JvKUcuwKJvhtNFJV6vADNvMOzf30jP0amaOmhetf5iTWcA161bijK1qFVBOmT31mgSc+BQP33WUE1MnaaRTh1W8x+UqTlKagMdKtlxB2wyzE03jX05STMTcqMjWmMtSZUVyUzRfaUjOw2SvsOOtTFIxsQ2ZocgDtMhVKzwGXk= 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.128.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-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4361815b96cso33190375e9.1; Mon, 13 Jan 2025 11:31:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796717; x=1737401517; 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=ucyJoNw6QFKkSZ2jNzF6PvZw0GMEtb/7zoh8ROnU+zs=; b=Ue+tUTqxFodNqcMN7Ct6EvhRpc+TEYhhU6bZtzBdU5VnTsRfG+uJSN1JSRDhJNvneC R0Qvhu/R/KS++n+3KlzUCj4AjqFwHYDnzwfuSVvYWdPWQv4wabzAKwJawbj1oxfdYnVp gwDNX3vHB3NCStlIC2hMIya1PNa2XtcbPZ1u616Gznnw1YjFcFEhfhVbseYYwcCnDiUJ ZkohEN7/+Gx0P/Wr8Fcz0qehXmBG5kV7TaU0QGl0jEsN4LKaImV3PwMbAwBZSM7i5m0M 8NQ91qOGv53CYbZk38LmStgF9c6sRgI3LVnfKwX1FeVSAWmjQeIpJ7knO1TMc/upLFY/ R4Qg== X-Forwarded-Encrypted: i=1; AJvYcCULWE1xZseMo0PnV3nK3ydKSQEZTIE6Kwu6rLyXcDLA3ZlCvk9azDjHA8BYJD5FlpDWTT12Ljsv9eDAjw==@vger.kernel.org, AJvYcCWCAaEtU6yfilg4RvJaK23q8KG71JEtSmp8ck2djl840Y5oo26vWTvLsxlFHrKQN4ZuO2FKFEbYCnuWzMlx@vger.kernel.org X-Gm-Message-State: AOJu0YyoEjrITSxBnkQiVlfa0aRltRqyrCVCOSTQ3OO5ccOnUHiftw4p M/9qJRsONl+pB9bkhDGRG7pc0m4RNGu87Rk0v2UvvWFBxnuzm5w7 X-Gm-Gg: ASbGncvVj3UpTQDUnOddKA1eFkHU+rY13JZEmv8zzfuIdvBxd25m9FWsz7tJJ0/4DLv zydYFQiXe62V1QRYeRMtY4mXqib3GoOXopI67pvFBLvGtnN2PpXjlHBxAWbZLWkPpmohNx31uCW LwV2UaNdr8+S6w4cPLM3AscYe3igdHmSrVlS1OZlZZq3OT7BRl8FWQud7KaPCT2Wx66o5SdVGRW 0sokA3KoJi6V5EGcfX20PD11z+K+3SE4c1gRmcsFnUlX4fN43pWEa1r7usICOF1dwOD4ZC7grNq WpxrpTqjybRB29D2PlqG487x8gvjjsiuRM/n X-Google-Smtp-Source: AGHT+IE1cclo1ieKVxHR4FQJlzNAC30rUdEle4T6yY8hd9qXxQvjPDagSYDw0ECYjYVHhWYWxVi6CQ== X-Received: by 2002:a05:600c:4f06:b0:436:6160:5b81 with SMTP id 5b1f17b1804b1-436e26b98d1mr223553545e9.14.1736796717418; Mon, 13 Jan 2025 11:31:57 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:57 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:48 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-7-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=L8Hoo5vCoU/RSEY6WScLora10s8xNCnlLJcM0w/MT2o=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqkK7snMc9vPKNww6aiI2dLSt6/ulLq8l627rFTrv y3zitDejlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZiIRC0jw7Evzx6nsbh0WnxY 8cOB7Z3aHM24BxMsTQKfniq5tXZb026G/6W6DSYO5k1LendwyqrN513F3OO2Tf9RZtKFHB9RafX 1rAA= 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 439b0e63d00d0ffa3ceb2314a39f2653e8a6e9ec..a5dc97210b16701a23549204bdadea0c554b6bb9 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -140,6 +140,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 Mon Jan 13 19:31:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937950 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3725C1D5CFD; Mon, 13 Jan 2025 19:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796723; cv=none; b=e/yzauoA+aYU/fdLQHuvRu9zAcTdq+3msqtNQ9g9/ToQ4ODMUMtfv6swpfCR2EmOpqt6pxZRVusjaQ6Bq3qm0MApVMzd/dlrsHncucFYCB/vCIRxGVPCXVRWIcBumgIQQXCZDyb1UwwUeHUdW/L0eyzQVgE8HknAlHw/RH5UxSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796723; c=relaxed/simple; bh=O82KFeFW8NSShxFoXcxPlu5/R6MAVIb/w3nv/RCbFuc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V028w9Tl7l5U8LLijz1geAWGSqOkoZjepaYpfJM633q1FU/pvF5OwlFO6YAG90K1u/e380lDOIeC2kcw13oZlyDnpVsSx+Q40U87Ksj0IlpUwPc5QkAGQH8xyPL4bkyyEcvOxL7VStgpFzzCTzMwAi0ezGNYS68nTAaH+UsXdw4= 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.128.49 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-wm1-f49.google.com with SMTP id 5b1f17b1804b1-43624b2d453so49118665e9.2; Mon, 13 Jan 2025 11:31:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796718; x=1737401518; 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=VV5IpmvSzypxFoaN7RsKRkmHAYNYQyXRvoPh6kZbF2Y=; b=VVVxwdb/MYJPgTSSCashG4sSbyXv8jdNoCnVp2AxepHH2TgQxHwRV9wu3Xe+oc3cJ/ PXTDPkkovmjUozu+k6Nj0BAS1ywyAb7H8VzXs6VpB485btaIgAgdxTFsH26eSfvR5FE0 j8xVuSAQr5SdwcJmhvlSpBmb10I6Yun6EBDcdaQ+jyoMzBVSNsMhNccE4lRVFM3fbyxp JM42PHTS3AbshhZO8Jxg6bWaK07Dsu7Cj8Z1CmLrNP8XL0Cx1B9yeGxC7oVT7vnaoyXE 4KnepsK9qHfoAVzhsJaJ/Wr/OLwKeLZy+i4UCaorOH00FnevxP3c40ZZ5ECbDE+RRYay 8//w== X-Forwarded-Encrypted: i=1; AJvYcCUIPPzVwxvqO85l+frul2vGOIbE/yGBDLOH8VejldrL7xD8NcK3xdZYrbZIIkTTMdFUUNmlnIr36+hsOxYG@vger.kernel.org, AJvYcCXY4Mpzsl05F43lr0y6ov1q7FUcfD7PD3Z7H7gQiAD2cI6UfmlZEnY9D79RP1olvPk0IBNmhWLeVgybwQ==@vger.kernel.org X-Gm-Message-State: AOJu0YycEhOjll1EfVwrC5cDkM9l6Meyv0zBXy9wYg/UTs/7CnvUyjeC Id2zMZli6Vs+JV+vkghflLwJbi9Lb4zWP4tEY2TWxJaa8m+9VqRM X-Gm-Gg: ASbGnctP+q21cEFpzrlth/7lCjUTVosZnHR/6p/bCHm1UO/zpu9clKJC4NllYUpANpg EEynlVtIZL0B4M3RRHrbDTEBtSfqTwAqazYlucH9cxfmsFDJsSvs55VDhe4nAGBCFL1Lj6tG8oD 1aU4IMSPcEkfWISB3vd9W8M6Hi9pLUpC4zKs6SeWBpHE4Y/HyS83mrO52GJTCk9vdmBKcrivcJI FhDoqU8eUg5fOPoraaF/JvSEpN81AhWSJUIq0ZZbnpAp7eedeNEohWcZJGvK5rQ394Lbh/QN1JR Dr8Jap6rF/G2ZepdiVZcufX0opkbTpf9+g1/ X-Google-Smtp-Source: AGHT+IEYLm32Ve0ngCgebfXxVIdp0LGD+a7JoKzmquP0MvVMtPKP8816+q2P4sz3E5UwvybYuX1DbQ== X-Received: by 2002:a05:600c:1f81:b0:434:f739:7cd9 with SMTP id 5b1f17b1804b1-436e26995b8mr207760305e9.9.1736796718254; Mon, 13 Jan 2025 11:31:58 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:57 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:49 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-8-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=5791; i=jth@kernel.org; h=from:subject:message-id; bh=Wk/SePVaY9KJFyHv7vnAuJtNbOOn8eIkKNcDPrSyOJM=; b=kA0DAAoW0p7yIq+KHe4ByyZiAGeFaiWjQvQVenMH+pIWgYGkPD3SSIaeGehR7dpsgiu5anjbe oh1BAAWCgAdFiEEx1U9vxg1xAeUwus20p7yIq+KHe4FAmeFaiUACgkQ0p7yIq+KHe5KNwD9HiP1 /tret06ZkZLXQ0YjZFNBcqeACYZCJlq097B771gBAIZMGZVwda6w2oBSX6E1p5aF8M9WB15nC7v vsLt51kEH 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 While the root cause of the tree order corruption isn't clear, using btrfs_duplicate_item() to copy the item and then adjusting both the key and the per-device physical addresses is a safe way to counter this problem. 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 a5dc97210b16701a23549204bdadea0c554b6bb9..9ea07a98eda3d52449c96c6921afe4cc94c38e6a 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 Mon Jan 13 19:31:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937949 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 01A941D5CDE; Mon, 13 Jan 2025 19:32:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796722; cv=none; b=EL2SpG46GJmNCuC/cb7CKexE+l/AvRQxCwnonh0f1+zYqlH56ZS85LgPyHb+o48V4mEv3Ate3zkeYD7Knx6SMx8j++nscmKDv6ZGAf/Uso5fZ2w7VB/3dKHvzdiqteBQ1MyVUn55ohKLXT6viEt8wos1gzgkwq5vrQMiBGEdie8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796722; c=relaxed/simple; bh=Mb2mbbxV3p+EXpECpOEJS4xSGbFakF+RpCzW4AqCEpE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=syu1t4wXKhBn+XpR8gBxtSejBMu3m1r9r3JmiiBfcdIlaBjrQVNihrrcqwfPH9AxgXnqZdEmaFKl2Poe0XonpShomlH5UiI0B5WljiaFaXY+xQ3Xurlx3siogLa8nT5Cl6xMWO0URf6ieEsMO88HrbngU62OFrJ4+jJOL56kGyY= 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.128.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-wm1-f46.google.com with SMTP id 5b1f17b1804b1-436a03197b2so33125045e9.2; Mon, 13 Jan 2025 11:32:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796719; x=1737401519; 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=lu01/icAOaMKJQ1N8bi/iPhOqWnpeONyNRPo9uS0xA4=; b=FQSt74INQhbDmCSb7Tg4crII1wRXduy47v4vxQeqld/pA011u8L874ZEqNzb/a01U2 I5FNcfJK8GETzkrjzKUFdku10UmeOzwzxuiXJ+hce5KvkzItCPJIo0YnQmZW+VTv0EjD Ztz4UpbH/nb5SIYT/0xdy01M31yO5a3GHvEd47dB8klQrSCwZWCt+W8l6dyrcr2XXr1d P1U+zqdZQaIM1chRFKS1Mj0/BfonOa41298UOEaXsJ6dHWCR7p+6M6KCKqt12m1NM0N4 EgDXdSOO32TCZoLiZxjnRA9JOcLRQ7rjwvN2owLCS7FpgwKbGoiPZ1/qXRWX6TQfbLmT Rk4w== X-Forwarded-Encrypted: i=1; AJvYcCVNLprwYRs59PiTAAHrZBVsE0HQF0GsrlfT5GDLzBu/w6Qm2SsCToiR8JSq5wHwbrA0HekY2B/JR5+dpw==@vger.kernel.org, AJvYcCWy7CUKi1KP7Xgrb7Q0rnM1OnBFs5q4et6VZtaPu4iWgc6AtzOA4MzfFXlB77VU0xMnfU91znB75E3nxWZV@vger.kernel.org X-Gm-Message-State: AOJu0YyYzXMgbvbYP5kEoE90Gl1b7XtfB0nPacU12bXq3uoAX3Qi0n+a ciB99+b60TFSLcZBUCv4eJU5fFalKkORoB06Y9QjCMSWlBXPEYe9 X-Gm-Gg: ASbGnctDsF8Le5rke/TFYM8SwuXkjIRnczVhU+A30SYFNwXBlDEDEepVJFQjU256C42 WNGmmGDfE4buS2hl322luVKpZ71ryo5ymfapT3C011UWBwlfPBNbU4qxoS9TiAdAUhdzAAigx/4 ONjgMwpErjwKEY06T6iPGkQ3BAUkOWrZzPBJ9qvW98WVznfUvCpXzx6XBWNFSsyoxsJ/JTXlcLN sbcM0n7kjydf28F6kkKamFLfa1zGJ8NTsNUsWYDYhyPp3lyQ7VevmrXqJsb22TogyriCjpecKut 4GDG2sEYlgC9ydlNqDJdkemlNovPTkluwmts X-Google-Smtp-Source: AGHT+IGin6n2+s5a68qbfJu1G9jQI5x/io+CmyqjHLcafBciIJVm0mlEuMgJ+5HzQrTH+UkG2M14OQ== X-Received: by 2002:a5d:5f44:0:b0:38a:864e:29b1 with SMTP id ffacd0b85a97d-38a8730ddf8mr20939700f8f.41.1736796719181; Mon, 13 Jan 2025 11:31:59 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:58 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:50 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-9-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=3NmorNyjCFrz6Eu8D9jlOv96RRP7GYjFuh5kmtTr2Bo=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqnaMl4541XN5ri/LGemUeaD7b9So1nCj3H8mNRdf WWSyqGijlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZhIjSEjw4kl+cu6l/qYvQq6 ln1B/y/rqXDZU0yv31Z9/d25ZoP3S2VGhkdhhda2iz/qfrk9ReCAaXX4edcO9/l3jBk22weKdJT PYwcA 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 5801142ba7c3a43ea075a1f7aafe704c8e1e075b..446c46d89152a5a903476c5ab1abef81978c2aef 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 Mon Jan 13 19:31:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937951 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 BD2191EE7A4; Mon, 13 Jan 2025 19:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796724; cv=none; b=Wqv5oGsFIfWjZaWpRuIlqYUfb8Fq6UqljkpvKLQ9waZSK7qlBlkk7dR/GfscYDEIuAvbiksg6uxr9xIofQuDmZ8bFjbGrgyjscz6/DmY72YQ6AEPOoB/f1TeUcF+8CoUvv3/tP+govMPl0dJW7KocfoTyOOnhmR+OUTtcZtcoR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796724; c=relaxed/simple; bh=w5qZztUH2e3eNwWq/SsGElt7/PtIalBrKOR0qlroJLA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LIa6Zp0iwkD+Ackdcae6bBiQFuYhOQqzPS8gmeNnFXpK6rvdr/bx6ZBRD5riJOb6Y3FnsGDeMFmx6GiAIw2IHit9OvKvtdSyWP185gj7LoqfakeCYvAJACqvc9Bm5DA9JzQxOnctItXu1TAp6R7sEZMrZB172jeUN+cjubcIrPs= 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.128.41 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-wm1-f41.google.com with SMTP id 5b1f17b1804b1-436a39e4891so32829595e9.1; Mon, 13 Jan 2025 11:32:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796721; x=1737401521; 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=9lYbTFMBuCIPE1uBL3n/gmzZstoHZgCeNJ9JWSt4JBs=; b=NMjq6LZhDrJweuxNDHWkvbYt8zwUUEGgCrPI66NFFrUKTwb9OGs39OA2rDeUIAYN/9 RnxM46Mxh7LSLP32Qx3rnnR2Y2xX43/zBkrj8NLGexUBce8hYfk5i620iI/0KDAk9UOM stSA8Uj2rN1UjgpJdPAvHl66jP7ZicE3NNUcG+rxK2JlyrgQjr84S0Asm8ef541H2qsl WsKR2R0QBaQeQEBxU9FsARz5V8XBM2bM55sLUtoIGbgYKzEBexUxkiz5mknRdRQPBzLs G08tDZhsr3AQllgHXlaQLPbI9DPZT+UsbHWg4muI7tp4FhaKteuCOAJ7CRkbKyia7FA8 3CQw== X-Forwarded-Encrypted: i=1; AJvYcCWB8wvlywyEVPr66buqIfq02xINp6URos8s1tXabu4Nkm4CC299x3GzMVv1sCnIMydZ28yyoM+lxKY6jQ==@vger.kernel.org, AJvYcCWmJUvcIVor9AdhPDRbfI8pbbNCUAAwwgqikLCKh4g8R6lEs03HNp/2Mzma4tzVbdXX1ZbXDxEezGjF7uPU@vger.kernel.org X-Gm-Message-State: AOJu0YwiXLGZ/C8i7OZuA0adZqj7bq8PM+TJy9Xgk+mwbPddw6+y3Odc sQ8PowHE7wl/FsRXHOuXGz1dqvafHLHd4BgdHX3mYvAfZ8bAuObL X-Gm-Gg: ASbGncsAvvW+cSHjgNLYMXq4cpjhu7sea2lstLjorewlK+nUoGXMPjW9Yp7TgeWU/Nc 3z7YP+grVX8NKeLaG+b2ctsKmXdXd2VvcQ73PDkMH8BzvxaNXKZ3426Yvh1KnYhEnLFU/x6AScw Xvm6sqdF/6EwiTHbbad3Poapy32NeOiWZIqLQTLg0Dge84ZGRUPG8Utr2qxstp0+VQR3Tuv+2HP wki/0Wuu8GW62+wuw1KSLMNIvj0+H9X0jlwxT+CZqF2EGq9tXEkHmsAOE+7N5YZZ4aIXo5wzNjR fVcbkYGZxsdFqOcWMPDfc8tl+PmPeWcKGDuQ X-Google-Smtp-Source: AGHT+IG2AhxzcI58jheR7j9ozUGeOyLTteS3yCY5XvpAarUkzY4hkRigBWVEla6TSujBRAc7za1pRQ== X-Received: by 2002:a7b:cc14:0:b0:436:e751:e417 with SMTP id 5b1f17b1804b1-436e751e4ddmr191773795e9.7.1736796721036; Mon, 13 Jan 2025 11:32:01 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:31:59 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:51 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-10-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=9tBCl1tRdaRHBU9/u8961DwANMUjbMM2sk8km51WH+M=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqmmSZ7a432AoXp1zNY1j2x5jwY5sDtzdq2TKDlwb CbzDua4jlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZjI1AKG/1EflE3nHVXi43x5 rP1IxVP31je51imfb+k8lVZPmyYufIeR4eyzDOkE7/d/P/9JaVUxkP+atN1903bP16V5HSuOvJ6 XyQwA 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 446c46d89152a5a903476c5ab1abef81978c2aef..da73369a79b41d90cd05bc1c8c373d1ef5f253cc 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 Mon Jan 13 19:31:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937952 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.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 B8D961F9423; Mon, 13 Jan 2025 19:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796725; cv=none; b=YzqqpOVhn/goOF51UfI/RFHzcq1lkrDw3dSyDlQ+ydz98vHICGFAa7UYP/97ooypzU3TJvCpcnMLXf0CI3yDNs7uGUZ2YLpUjoAPZk090CMG8hSMNSNRg4qrRuxTvN6mOt/G87Fk1abSNoIwY2o3p++FofJJboHylTv3E5z9Ww8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796725; c=relaxed/simple; bh=gDP/I78MDlAkYzglHE8sONICC/MAn9JP0XxUPCQ8Yyg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BfNAr6/d0fHwe0EpMUplue61PrfXYeJdTWrQ9P2+6h2ObhO94HttmXLX4aG8Vn330qQKDGcZIBgz08dSZyZwgxhe94zkVgAt2QJ++tJ4kComZAPW2cQb9gTG90c3lt+2vPuhTVzRkDuCAeNFDgFXPHX9xTeuHy7LDCrms9mk1sE= 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.128.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-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4361fe642ddso49410925e9.2; Mon, 13 Jan 2025 11:32:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796722; x=1737401522; 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=Sf1MZZCNyGnD5eJ+FhAWK0BfEji/54ltHeaNcuHF5kY=; b=IwwcEEblDAutlHquQAS7u3auG1eY0gY9fZATRd2QR0rwSzHWvlJbLYBRQBpnu9UA7n 5O/b+aBnA/edIhumxnQrU9cpR3zixHxndlFozMyvMcdWVFx8OiW0/WPesC/GpBejUT1j 9GWmHkHZnSEDNGM54EOipu5iBb6enOQPkdDrA+m+J307Z0FPMpZh6nCNfjDwcS26b30x 2/j29jNrfbKk/ghhUKAwWBlWHiHkkRvXYJYZBZ2m/vkZOZRlMiz52mYIBhw2lT0NoRlc cniol5gcwCKvVCdhSKOclaoQR1ih5MMSd7qLHp/BgqnIICz4YmN7iQLpkfgsVfoOopne UcWQ== X-Forwarded-Encrypted: i=1; AJvYcCW11FnePCKL94iZIH4W8kOzTts9yF/1MPRl8U3dIfyluys9f4hRLhGgrkrk8FWVta6jj2tY7Xk9qWSSiQ==@vger.kernel.org, AJvYcCW5Hk+iAAbLTUk2LYg884IneLBgS27vTRIyW1ysDkv/iuQrH8Cj48vVAyLXu2DJ7EEoxoCGsORM4OoW0kJb@vger.kernel.org X-Gm-Message-State: AOJu0YyfkrJmoE7fjz6eA9OYYaSxOgoM39vxh1JeCUoO3eAekEsag7sl 5rl6h2/ev98H7eaMH2YKYg+u9hxMxGZi6JOyW2YNjEOPH6DfJOVJ X-Gm-Gg: ASbGncsYVncsF7pirtCbuh2aKF95lnJReKW5bFDqHAhcr7oktfDdCfWzHX9xaIVZCaz cTDlyMke8du9YLmFOq3npEyzYWg/mdVmq8YQ25SA29sIeC65AmqNakUaN60Y8Whnwy7E0vQ9Iyd vJT9sl2LDUaW6Wqw62PZpyRuhDbHKePxGk2DDFum9vExj6xNGtETmGF1EHSMA3NQ4vxEgLgEsJr Shtl+tPuwSLMkobFOWx7WbrUlsr/JcEcxzhVnMmnKLRq0u7doeCpIRrqtgxwA144NEkxr12H5+x W0hI6m1+AKa5LfvKNZ8vK03Uo2gMQ6Lf5ZEQ X-Google-Smtp-Source: AGHT+IE/miXKCD1BKJ2B/xBdPFfZ4alKznPnzbQZ03Z/A8IGeSwhFyZYyEW9vkUwgNIT9nkeqGCEzQ== X-Received: by 2002:a05:600c:1c84:b0:434:e9ee:c2d with SMTP id 5b1f17b1804b1-436e26e2725mr176538155e9.26.1736796721873; Mon, 13 Jan 2025 11:32:01 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:32:01 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:52 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-11-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=Pmlf4j9IejX6u5oXvfLGlm5RsFbWv1KD23mgVZl/JvI=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqneEJ8kydOluPQo31aOCD3BKI0X5nuNO96tD8733 O00Uy2mo5SFQYyLQVZMkeV4qO1+CdMj7FMOvTaDmcPKBDKEgYtTACaS9Ybhn8lDczPxSWvf7GWM OKzh9Z3bdcm26VM/6D5lmjqrkc+6/Qsjw22Xv2t97GUqfxzRbZhxyTGfSeae7Cr+7HVMV2X51p/ qYAEA 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 da73369a79b41d90cd05bc1c8c373d1ef5f253cc..2138d7561f40efed5449ebd9ae66aa6adec4858e 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 Mon Jan 13 19:31:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937953 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.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 97E521F9A90; Mon, 13 Jan 2025 19:32:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796726; cv=none; b=sJLXV9Te2AvX/btLVkl8w0IkC6WYtJUbm6Y0K0Ta0GREGpYT3TGqKCW9X40XP0bjRkXcYBYSDNGxudthRcAYclIAyoE4SyMDvEHUyV6xzrw86ZPxuURIHVD4QczaqAJCxmiWXbZsSp8GzlxjxGqXYC/fo1qYtTrWdvE5QeSkoMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796726; c=relaxed/simple; bh=LzyPjO3Kv5CbdoOJNMEDoznEK5M2gPvof+JnHQnPz1I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dbMZFt+fPUZ5VyJAr6vMPHIGVfDhRQsZDvFupM2kPxwTJTKvwuWvab3GTSiTC0NFKox8PKf+T808iCmwK79aP4KjWOxzg1LAXJ00wR9Lxzc9kHR7evFTuMV7evbrrelnOLKCcBOl785q5tDXh9DR4xBwKyTAaIpqVJSX0sZiEO0= 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.221.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-wr1-f48.google.com with SMTP id ffacd0b85a97d-3863703258fso3578508f8f.1; Mon, 13 Jan 2025 11:32:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796723; x=1737401523; 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=6Ur/+A0ELFVMxAVca9a6mKArrXJSe18Wd0kDdlASpQk=; b=eAswST5iLbziqDNntolZxADNcoc3I95UYwbu6AIqO6+z6UtJKBJJIHXye8ydUSswmn lKZ9vofdpmNNS4dMaoEOqga+xIucfoiSYQyejlvzOLhHY2ByHQmrXnWjUCNpnmAhL58F d+deZbA2MiLQZ21fYgSpiorp76PBxbwov13GL//+Wxh8dizRkkb+mVFL/fydTcvXRI6c T8eZHq8uCD1+JpxSuxTJeXo+Yy1Ijp5938ONSb1yDPa/cEiQ80WJwJoeyFGchW9Cm0/J hAKwyDIlmVjFKEHFE3nDy5XgQ3dZIyaVM5FIGqFa5AvLV+u9pZqzbbFFD0t91gAqFHlq PGrA== X-Forwarded-Encrypted: i=1; AJvYcCVrJBc/5IGh3PdF2Wq8uasKOjB5uA06ZCMXvzkOUY9LYs7oztwu8W9xpDywmsq3B39Avpmn32y+fCkZyASp@vger.kernel.org, AJvYcCWkvq8eLMVN5FcncV2pu/pMB9XJd2M0Tiwz6Wcpv8Gyuf/snmssh3e3uaje2Vf1qimZdzsaE5X8O9tkzQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yz3qxtILL3ftMIsxOd62JjOnCvW4806zOa1iNNtL1zJP9Tz15Bo l7l2L+NS75lcA+bHAAMljgspliS1YGS6J/7Uk6xGtMIyGUiqBbsq X-Gm-Gg: ASbGncvfxYKDdNwURjFttUW5ZPSJ10i2I/L+T5n3LeiHxCDcw7qdixoDSJkov7js8X5 6URLvNgsV8po7FWY1uwulQ3WUVUMYMNSOFm13l1V2MdE8rGIJBZRP4VkQ6T4XpJmkzQHcvLv+CM cKg8Ak15RIQgzE9N6Z1qewzHT37q1PComYu4d/kdZtKsWHaNAvxd7sRtwo7NNEvTwQfKZDUUZla fIydZjd2rWBS3ZsZ2i8qY+MqQt7mqkraEy4qNsk5Dw0yTZb1MAIgRACkwvhGRrkvV7R+vTqXZf9 bBBKMcKco6pkKIqUiMjOL4cmZ+/1SPJco9YP X-Google-Smtp-Source: AGHT+IGK0c+lKzHAxjaz9yWEW6WsFg8gXZlAMsxPc1fJXKbRSxi28L/3yPOO+at+Os5PMwXUYNFK5g== X-Received: by 2002:a05:6000:1547:b0:386:34af:9bae with SMTP id ffacd0b85a97d-38a8b0b7fd0mr14515951f8f.4.1736796722808; Mon, 13 Jan 2025 11:32:02 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:32:02 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:53 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-12-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=5117; i=jth@kernel.org; h=from:subject:message-id; bh=SaNEzj9HvSfFtWgV9sIm5xhTefDohh7cX/HrQLrGrXU=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3Zqn+FQ1atNQq6PZex2XGF46uf8zf/8CjcKWWjANfz 3+ju91FHaUsDGJcDLJiiizHQ233S5geYZ9y6LUZzBxWJpAhDFycAjCR4zsYGfZMEgnfFPPaRFYn 0cfizvZZeRpLZ9101pHSTvj1RvnwsU8M/90uKHVXLl1v7MM474X2ds23Hux5R6cyyDR5Cz5dVsp ozw0A 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 Reviewed-by: Filipe Manana --- 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 2138d7561f40efed5449ebd9ae66aa6adec4858e..f71e2ed97b2a8069d4af45c073fcbdd427905325 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 Mon Jan 13 19:31:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937954 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 D38201F9EC8; Mon, 13 Jan 2025 19:32:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796728; cv=none; b=HgLclFEkKB8sonrlTkwEpVuVSwCBYzYJg6xOYQ9B5JXUKUK+90/WjqaPmWQR/ble/JvxSRG2hmO/pI+e3SUjHjFgnaI0oS6X582Zo7gDMXxw1O4nyQ0BLoGVqSzUFgGlR348UvutLTvTOJVAN3tDSlQZ/a1kBUEWZ+7N5CTJcug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796728; c=relaxed/simple; bh=eoHpGvYEYnLQ45fC+G9SKF8MwRnIGG9F7C99Q+XahH4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C90XaEZsX0eWZ19W9R6MSIZgOdnle+4whNZMfU7az4Q6Mb3dx+4icucukzv0G+53AIsm1w2V5GMxlKqq57dgfMkoqQLsUr8vLrT1zmuSoWKBImvitkZ/Wl0bRaoSUncDSoiFuodl2X7IP3XXpMCIXw7UKyrUpyLp2m/5l1FIQzw= 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.128.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-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43621d27adeso32764015e9.2; Mon, 13 Jan 2025 11:32:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796724; x=1737401524; 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=lPj0r4XCxEfWZHW3cEMl0QHLGDNa7kG2aj8kvuFQOmQ=; b=ms0ueFjlL4t0dcS/D69lL4clwRWJUBV3MIVwyx0QvVPsvCvqL4/I2FQ+wIbyyE+428 y7g1D4Iuq0QLvd7czgFAWUHpMePRbUaRfUmhXYlmBZJD2NbKjACGkUq2jRKl7TmIGYD+ lvdzJqcA7IgkE9asZUM935hPlKUyCPAVFxPiDZZkqgzCxbAYM1C+ZhvWiHDNvQm0R5f4 LFuFzW84wYEWPzPp14+h+RqP6eaywh7vIVAbjjCugM4OmRgcWw9aaNDcbLVSLYosL/PL yx8Z+K2JA0T1uUBI+P3L6EJZx2n6aNZp77tq2M1dqQBNZwaEi/bzRlmoibSkl3oMiARn V/kQ== X-Forwarded-Encrypted: i=1; AJvYcCWK+0yvDbd8zYE0IcM+03+dCgFXniiBB1u6tVhABGW1cKcY6h9QvF3J13lvdE6Rqi6IYOWqkbnD7XRcA8Cf@vger.kernel.org, AJvYcCX1RMnCB5m9ay98xw+TPakfxOzNP5mgl6/3i6Y0odp5BGbb6H7ilxSpAPeh/Osw1R+4n27bHb+XQbLTwA==@vger.kernel.org X-Gm-Message-State: AOJu0YyGUhV6rroyrpXF4hnfOGQWZLxZ2ij5kfi+WVU5l1RAJQyO5o43 NlErpSyhuKHjwpXK7fEREI98LA7EYi89+hNGb9vGGARgADQkOPDW X-Gm-Gg: ASbGncuqPDlsrbtX2kB77nNTNhYgfNVljypHaMDdo97g/xJ9hji/c00J99j0HZgDxgD x2ZYlE/A7s6nr0VpHDlydBNjQEGoE1PZFS/lg2GLxj32lqRCnu9pp44u3xabr9t4PlGliwC5wkv fTcqK6WYU+AZdEejltI1MksUYopsrZa6Z7KueB9F63SGxxSv+MptjYmfIRZ+iTJYQ42Hav3wwDk K7Sfd6HMCSM0YAPrPB1yMbNOa9pujTm5ajbSEbNPtzkh8CK+6Y6O7NkLBb3sf5bJ/NYx/VO59pY HK61Js6UAImLvbMR3qLoejsTSxPVJXnDdFFp X-Google-Smtp-Source: AGHT+IGEqSutg4TufNeYWiIsEgjHPDPz/EU9pmStOtiScexaxbzS+GsnMqopvVfhuFOeDs1vWUsc2w== X-Received: by 2002:a05:600c:1c98:b0:434:a04f:2557 with SMTP id 5b1f17b1804b1-436e266e802mr196701695e9.4.1736796723750; Mon, 13 Jan 2025 11:32:03 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:32:03 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:54 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-13-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=8fxmSbOef6Jwx1uuEAO2yWzEF8rJOV2UM2ZHGlsK6h4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3Zqm9rlvvv/ebdth6l1P13/e2KPntc824VHHt4tJIv Rrrnr9HO0pZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAiG18w/I+SEPn8XVj7gZaL rLLIRP6LZZ7lx+4+f/foFueiWS+W8Wsw/Hf+XGfiOTVJKy9ial25Y4pQeAnL06Kn+7cIiPHrzd2 3lwEA 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 f71e2ed97b2a8069d4af45c073fcbdd427905325..6365cf1e08a5d0d2e6b11a219d292db02275eb70 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 Mon Jan 13 19:31:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13937955 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.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 84C831F9F5F; Mon, 13 Jan 2025 19:32:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796728; cv=none; b=KUDXEmXU4KAZl4i0gGm6qliuCw/dPUdfJ+S80In8nhAk1ybZvAG6B3tYLF4bMsQFOuPChnlAp6frKZaxx9nGNAoRxZDaH5p18fDb5KR2mv7Y3GRXcKg3Ej8tPUNUaYZfHH/V4x7PRtp6v8IEmHwvpJIj5iXDt2MQd7XOU4gwCUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736796728; c=relaxed/simple; bh=a2D31HL+b0vBvzMICTsCYmbMeh0kRcWFFuv01Ss+Nsw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iNy5grh+2yvoto4krgMolmeFzct9GpS271LsCHqXKV6GRoqVOKuHu4hCrc3RHLES6j2TyAumMAlTvuxNM2TRqNsCqhAWwX+FWQ7w51PetOOdW6Ewfb0JnmDujoUJsp4kKaWyw7yEwKCQ3tICqohA43Sl4VNGW7toJeGfR1+plKw= 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.128.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-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43618283d48so33903585e9.1; Mon, 13 Jan 2025 11:32:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736796725; x=1737401525; 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=5K3V9QWHXuJ6xxtV+RQPaKdykPic91LAByNAfLRmofA=; b=m10UW+A6qAM95lWaJBGn7QXL8T0H0bYNxFVNJ6z6DVRg4iSt+Oqviu9aowRjPctD00 ViU26qtbM7S0u94AYFMn3X9QB5s3+TA6tAUwtaeK31ddwZ5HDjojkGRuvFNSN0HSEXeg fgbfPToo3dGgmoZh5WcvFbhmgFr+8FC3tMXM+xG3tYFK9HafUIEpzHHexFSxnZ0tcbEb lKP2Rn0krmwgZaYQGIISJj5xO0sawNHgk1sizGnjoAto/KLRvkc2pUYSOEIvSFRYXuMJ K6LNLxPiLEMfd/+GrFLOrgzm0rOr5Sz12UFl9t9qXr6l5ay1GTmno4N9pVZBxnw1nIip EfSQ== X-Forwarded-Encrypted: i=1; AJvYcCWGGS6+D+/PeTbkA3pUQTAgkBUb1pplqsuE0rTIwZAblhcA3H3JA5BJmJFOPI4V+uexDaIsnB9kYSuA/A==@vger.kernel.org, AJvYcCWJMIfb6P5DHwH5bz+9rZ2/Rd/9gSdYp+GsXBdJa6C2H5y89XyNLizQhRAYDZL+Qm44+24QVpUHzRoIaJpM@vger.kernel.org X-Gm-Message-State: AOJu0YyG/sN5RjRlDl8Ddl0gcjEoJuNSjFcSgHLmBvG2pKgeEzD0tRK6 SMEv3+ZBoe5W45g03P+jJ9H4r1fLxuwfsr1O+mSNN/z0mdukR9LB X-Gm-Gg: ASbGncubvnMA64LvF80CZ8nIVX2E6I9Q7OL57e7v/Xk/FWsdO0w3ht6XJetKAd2lkxH Hf2iWGTfLe26Sv1Aygl5izkkHaqV/zRVhdC6tA8WlcRR1nIUXog1xPVPwntkENYATIT3i+M3FOu QpoFgoHrO/jhRmRRMBqfuWXAmP3FL253+ndX0NCN5RQhgW8kdUzJvFDksxxGQhmllbauhIqamQQ MhrQ8hxKFiP+k7UORCArMabDX3qWpHZSEM/K5rslIbCgXtTFVSrOgR9is8lJ0sd1UItH0sRLb/M o9c2gt79rcsIYmRdNfq+lL6Jv9YWp06+M/ME X-Google-Smtp-Source: AGHT+IECICG4/4svbFau6OhfM7ZxsVqENRXoVHnUqWgFHHujcfqFYh30eFm+SDAgYy2WONz8UOHUXw== X-Received: by 2002:a05:600c:4511:b0:434:fe3c:c67c with SMTP id 5b1f17b1804b1-436e26e51eemr177438345e9.26.1736796724621; Mon, 13 Jan 2025 11:32:04 -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 5b1f17b1804b1-436e2da6271sm186221475e9.9.2025.01.13.11.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 11:32:04 -0800 (PST) From: Johannes Thumshirn Date: Mon, 13 Jan 2025 20:31:55 +0100 Subject: [PATCH v4 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: <20250113-rst-delete-fixes-v4-14-c00c61d2b126@kernel.org> References: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@kernel.org> In-Reply-To: <20250113-rst-delete-fixes-v4-0-c00c61d2b126@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=xQRMlJYgYbM7Yr+yNmYmjqxYz5n1mdnAiVjmPu/CZRg=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaS3ZqnZGGz/sG697OK8Wx9m8TI2Xzuhd0NNPNhzW/jrU 7VTOLxdO0pZGMS4GGTFFFmOh9rulzA9wj7l0GszmDmsTCBDGLg4BWAivxwZfrModXs7GmT4Hu+W PfnrlxuXkccen8PNNyQXntFerPL5ZyQjw9wZ/+v/C/MnPzhiH3Ln84I5eW5LKipFhO2OT3qscqU 9iB0A 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 6365cf1e08a5d0d2e6b11a219d292db02275eb70..6f4eeeb8d4563dd75d436e0fa38fec78ccdc79d0 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)