From patchwork Tue Jan 7 12:47:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928847 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A1B81E3DC4; Tue, 7 Jan 2025 12:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254073; cv=none; b=hC8euNPSBbIvwbT4AjTJx3cac5CSfoYZu/L5GsC1bKiys+ONLnBiCsQYxUcXW1HGjPmj2wRRjFC3WSVfs2uKuTWk36Ay4uhiVD08q+jFzuftPChLouMLjxk/Mkm/38FRF38lp7IM2Y8BspXmMEIwaPslEj6rkAZO+cwBLTXabeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254073; c=relaxed/simple; bh=4dccEVdYglD0Dmgm54SCN7FdILwAHo5bmKqFGoZac7Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MCGYqbT8ZHPjjj/ir4gJXDV16cq9fzpcP3dXX9ZlnMYXODopFyn64iOjUbAH1xgwPbw8CICIJofDUpuQeVag58aHwRwoc7HOptkT61wmvbMsgqGkVMbZl5k+ywEBDcFHMDqQ+W2kYeVXAUpEp5pRfqAy2pDWNps/Ly3jTCYiF4g= 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.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43625c4a50dso106851065e9.0; Tue, 07 Jan 2025 04:47:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254069; x=1736858869; 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=rQ2XH5NLBv71T4OjQH8i8r7Ei7+B6QrcJlpQOt48wPM=; b=TPk+34lYvsg0+Kr9Jlab7iJDw5PzUkhwDFXH2u43cmB55yp1t0rzpXRS//o1W4tI+0 FKear1c3u7Kdqqe9lOPMVUtbW8uLpY9mzhoEk3ohCmALuZO8olT1NsjQWWNmxyJ/MHaH 5bIvfEWs+GaviizzOdnq+qadKtdcaFcn78roEwQwqC+Q0225bVLdFE6ZHZ/dF4lDwXg6 sWEBQnmIwWzz7Imqdn4UPr7rmeOdchCbUUP+be0Nmof8sysPk4klOYU3bKgJhOytKoFa cg7RBkELpZhizc81K96i/5LiBG6B86b2+5HB4o9ZvtgL9oJF2thfPah1f4OdgLWt0Afb UR0w== X-Forwarded-Encrypted: i=1; AJvYcCXwn+TiQZBR6tQBgyZIsj+7B14HQTKMzU+6WC/T4j0gOmp95RZHQH9NKe3QKPkg7vTg7w5Qyv1r94A2Tk0=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj+dfTrg9/9c1c64ehxDtg6jXZ6ZKd6WVMVVy8jyAATjOeiaP/ lD0KqcyREN5qsBhdLH31aeACcaIfmV2iTOX0lp1Eq3jWFO+UWMP2tN9Mrg== X-Gm-Gg: ASbGnctO6x9FaMabyUGsNQYyx9jLeYW/ElLePuh7mLHW2zH1/iQQBhor8IdpyshdEDP 6DN/Hmp1qKFs9U4sL9CD8dIkJL1mMb2Ge5uXfQv6hw0phsTNMcTGNdqnUB0rJhcK1/hly0kpnH1 Z8N/JkwVEgqcps9RattPLqYWMQOQhneNOqR7YJd0o0+ELYyfi0C2SUBuTmEpJKNIsMDHNrvLbbu blzgHL0A1Itk4PQ/i6ju2Ndj0rYUjiqkTkLdw6wKzX8liyH3l9Zeo2Cu+LjpwhbowRlFN46YmLd v9rVrihlibhfEFZwL7RnEaOZYlA6uDK6vYm7 X-Google-Smtp-Source: AGHT+IEeMOyJTTb64xoIxLCYpfFmjJBMah+Qx9nAn/2OtmnH3SKDpkUSM0jzc2zWnkuceKmOW4AqNA== X-Received: by 2002:a05:600c:1d21:b0:434:a4a6:51f8 with SMTP id 5b1f17b1804b1-4366790e3fdmr582775485e9.0.1736254068450; Tue, 07 Jan 2025 04:47:48 -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-4366127c508sm596884845e9.33.2025.01.07.04.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:48 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:31 +0100 Subject: [PATCH v2 01/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: <20250107-rst-delete-fixes-v2-1-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1964; i=jth@kernel.org; h=from:subject:message-id; bh=W7+obICRHX3n/iMqbxUrpU4kmmyR3NNrLIE17rHDiq4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhV0Biut5T5p6/0mueGER+y0s6cluGenVQpf7fVKf v3vZG1uRykLgxgXg6yYIsvxUNv9EqZH2Kccem0GM4eVCWQIAxenAExkCQfDH57f4TftZSeuzL9w SO3QOVefOXpTrXb3FOk26G1b8qnrVDYjw8KjHDOVOxL3nu0INdk0M87rZTgLo7SewZuFgs+UfSa 95QcA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't try to delete RAID stripe-extents if we don't need to. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/raid-stripe-tree.c | 15 ++++++++++++++- fs/btrfs/tests/raid-stripe-tree-tests.c | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 45b823a0913aea5fdaab91a80e79d253a66bb700..757e9c681f6c49f2d0295c1b3b2de56aad3c94a6 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -59,9 +59,22 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le int slot; int ret; - if (!stripe_root) + if (!btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE) || !stripe_root) return 0; + if (!btrfs_is_testing(fs_info)) { + struct btrfs_chunk_map *map; + bool use_rst; + + map = btrfs_find_chunk_map(fs_info, start, length); + if (!map) + return -EINVAL; + use_rst = btrfs_need_stripe_tree_update(fs_info, map->type); + btrfs_free_chunk_map(map); + if (!use_rst) + return 0; + } + path = btrfs_alloc_path(); if (!path) return -ENOMEM; diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 30f17eb7b6a8a1dfa9f66ed5508da42a70db1fa3..f060c04c7f76357e6d2c6ba78a8ba981e35645bd 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -478,8 +478,9 @@ static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) ret = PTR_ERR(root); goto out; } - btrfs_set_super_compat_ro_flags(root->fs_info->super_copy, + btrfs_set_super_incompat_flags(root->fs_info->super_copy, BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE); + btrfs_set_fs_incompat(root->fs_info, RAID_STRIPE_TREE); root->root_key.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID; root->root_key.type = BTRFS_ROOT_ITEM_KEY; root->root_key.offset = 0; From patchwork Tue Jan 7 12:47:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928849 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 68E4B3B1A2; Tue, 7 Jan 2025 12:47:51 +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=1736254074; cv=none; b=LCC0ebm2+3dlEB60RwDhRdrwm2/QmoVGxFoq/wms1ZbNV0DS1X+ogqgj0apjkHK0weavoJLD5yE8f4AhPDz3Zoe4uUfZ+APbmItMZhHt7DjuRzJxHanLdmjaaUttqb6e7eGEdSVhPh83HNjpXzYNhiyw5IVD/xcLNEOgRfXDoZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254074; c=relaxed/simple; bh=cmg/e4DtS1x9ynWJmvbGGFXWsmwYnW8bG9f4O9YhOfc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jLfNNNbgbQy8/CjCAcTPO2v2hwBVaNmFiTZf2ujXWQWHl6wVWiyUlJ8Os7gRaghnhTh56WPV8GxDS8W4G5LEj2N70GIZJCFsYMukvZ8uzeZWXsFZ7e1ARrrjZq6zm0ldoPWwjbxUV3kt2R2OLop4GNdHgg3cHkYyMv9A+zLHkhk= 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-436202dd730so110830955e9.2; Tue, 07 Jan 2025 04:47:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254070; x=1736858870; 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=N+5ggwxdRaVoBFgMRpwyGAE5qeoDuhmi7L4h/AtgZWw=; b=B2RoXdynMSL+irdf6WDqXlSleGSXXGNPkwFI05uIMtFMTGHQaUia7xBE4Zk7FAI+ag 2QhDfD7OnJObUiHlrAzpOmJ9Rbs4duUhC5Oz5HOQzMCVfWSop1L6F92cTBCpzt1Mz7Ui m0jcchNftqHLKs7oXepnX2kFWLe7IRDQFvyaBgcYmU0LJtDoe1n2b/+7WG927CNd7e/f n3vnSHPyvO9D/pHGTveeQD2Jwpx23uSKo3FRgW0fWM1IMnBM/j6CljgNFpRphtvaGWdb K+JF5yKk+eFf5k7bAhpfwLA7pI+hhyL3GMFcj2iPJgLk12euHbs0zrkPJAsb1UMD1X0m PPCg== X-Forwarded-Encrypted: i=1; AJvYcCW/W1WlNISMBRiE4X9G+qZ1uabJjTTwvlksnj7Bm6k4EFBw8RxaALn4Kr5cLJwNRqH+Al7rcsaayvyGvPs=@vger.kernel.org X-Gm-Message-State: AOJu0YzTnMcFb82rm+/wpPISnfYiQHuXt520zoOIGyU5kiuyLZXvOlNR vXWLm31CRv+ifcc+KlrhqKgyPoDmJZC8tlZhfXhYGN+L11MmQVetTr2gzQ== X-Gm-Gg: ASbGnct5x9FOt8HcJsB5WwVRDUBVEzb5KmlWwn2New4gxAakWfrDIXVV9WsgNlra/X3 c0/Wct5J1LwApxzN4wG796KQ1m2L/GHqE520zu2Tgjm1cT46omo9CfRuGOUYF84kEG7k96AwaJU bNPeanbCat8zNbLLKXIxSgOnxNsoRXiJwc1ZXyqXqJGbWapAXoEKtZ6N+Uhb3A2t3OJUWimSOeZ 2Cx0jQUjWo0TfRUhHohyk7ynSNc4wayEeZDoO91eAf5OYx7fxYKGlOUzhHv4Kyz6IODhIsx2jRL PFflVcwy+IhjIO6gJ8HofPEnQvouU5zXHjsK X-Google-Smtp-Source: AGHT+IEOXRbkPy0EW2A49aKoYlrWYgfDug3484Nq3lYm/Z08+eF8PnHOxLw9IWkFkAguT5G1sKJohw== X-Received: by 2002:a05:600c:3c90:b0:434:f3a1:b210 with SMTP id 5b1f17b1804b1-43668b79018mr455123325e9.32.1736254069460; Tue, 07 Jan 2025 04:47:49 -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-4366127c508sm596884845e9.33.2025.01.07.04.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:49 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:32 +0100 Subject: [PATCH v2 02/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: <20250107-rst-delete-fixes-v2-2-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , 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=FKo3jsLA2NKrgavCYnmk4JrYWKFLwngM3O7N654ylk4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhVMszHYp3W/xO+o6wlr+fywu4ndW9U+NHAszJ5gY rOsfuekjlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZhI5mqG/9mXvq4OjsuT3Do/ +0tFsHfd7Oy5DlMz/0yd/NFtsdOOS9cZGXZbt6uESVv9O52/npMjLSw9LM3xErPvdsXV7YXnQk0 XsgAA 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 757e9c681f6c49f2d0295c1b3b2de56aad3c94a6..5c6224ed3eda53a11a41bffdf6c789fbd6d3a503 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 Tue Jan 7 12:47:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928848 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 3A64D1F03D0; Tue, 7 Jan 2025 12:47:52 +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=1736254074; cv=none; b=A2906hJWvsIDzYcWpGiGSK7FOcaeCUKSmSfgu8C6bMj5jkMsDFZKzq8eZ4rd5yczlCIsFK8G3k7HVsPR6fxoDu9+EEK4zYP/4hjjSNr3K0fQMpXeUGrsL5Pbwr2GtxaWkg3o7skCuZUPI1JpYW0fp0gYy6s/vcI8deQZqMMllvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254074; c=relaxed/simple; bh=GIKHDQhqZDJAYaFHZGrkBjKhlMrRaLC7syejF347pTk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b+MPGNPrXtYaGGhDlDCzcQt822wB+7h90bdCQfEQtgyLA7qJM9KC/WgZgTZ4ul3PpWPxWng1+abLzwES7GM4Hh8nKiLZ6DcdIQ47cxXhD0kevk7EES40cxUT8yAuABKD561OT0g0RDEV4q7sc8jP0tW7O1Do64kXTC/Ku5I2Auk= 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-4361f796586so159470205e9.3; Tue, 07 Jan 2025 04:47:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254070; x=1736858870; 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=FZ+41chn53AePcraYYwzRS0bJwF7+ChOsC22yjS6oeQ=; b=T+Gba6HsHvwGY26kGDqYxeXH0zS9Y/scxxnkdfmGyhRyvjiRndXR8QPTgihBj8FcpA KbvsJBL3WC0nSbpAozpO7Njyxd2ziyhAyMSDXke3Z69Yw2FNz1ysCrxfE5/i0xpoN0QH T7pY6RtUGPHrP0H7eK3Hvj5tBkBUBdcMl0lCmT/Fbn3HQGLz4HqezXyKKAH1aBsrrFRp dYqxMo5WeypZ7dkyjqmVvGqfOBW/v2zITIsSYxj71FE5E+vleOHlaeACVQfDrkHS5bsD kj224wvQlcSjSMpJLUW3r/Z0Ky8TaN6niUrWnwTbdPt1l4oBEh4IBCA93862Fszxhh67 T4ew== X-Forwarded-Encrypted: i=1; AJvYcCVsYb6ksGbrpHFLkV6EdqL0V2hfLjNF13+TBIAz6Mv0Jv+lTzIBaJrpdxNjOgxj1/MinoiBVokm0TDJjWk=@vger.kernel.org X-Gm-Message-State: AOJu0YyNcoYmcS+Y7Rw159nzBe60zlh8yqwaJ/2y1ZnwK+KUGHGyj7Ug q0uMZsp/c1kxKJT7Lln/vxE4a0u91nlz8dMV5v9z+CCEkKhQg5OIK3/JGg== X-Gm-Gg: ASbGncv8lZ1pJN8sv+eHS2PSvpDmS+X61RQoYg0gjQfOWj8NtJRjv0G5zER7BD21nv/ YxR7qICxYbWwNhy+yCdTJ2ly0FXdtRZVNW5PotTAvyR/88QROWT0oF2WHw1zuc2I9RK/q/mvXIC J7NG+YgC4k2tdfibjPFQEwdBJsp9BrjohN3jmxIyAJic/0gYjJFtoBYao0LKUNVdOoPgGz/8JDX NWbwET9a5bnZnEpiI8HfIpnCxTj4kru8d50Xboc8zfpvXWG0jc344bVCiafy+YuCQWvd/898CQb qCik//1M0s7gi8qXou2tOqoVYt3JwdQ98HlA X-Google-Smtp-Source: AGHT+IF6Pacu9vst++guSQ2z1yKyR2kDw8NVNA/GR542pTf8v9Xkg+gh1FI95hccbvz0fzGKBe/jgg== X-Received: by 2002:a05:600c:1388:b0:434:f131:1e71 with SMTP id 5b1f17b1804b1-4366854c07emr504368665e9.8.1736254070268; Tue, 07 Jan 2025 04:47:50 -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-4366127c508sm596884845e9.33.2025.01.07.04.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:49 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:33 +0100 Subject: [PATCH v2 03/14] btrfs: fix search when deleting a RAID stripe-extent Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250107-rst-delete-fixes-v2-3-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=904; i=jth@kernel.org; h=from:subject:message-id; bh=glA+R11vO1yQhVEHOgoPFPTfxl/IB6/5DfePvcXkVqM=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhVar/m+VEr/EqOAqezjL43nz8dbzC/jjC3eMfVRs qPh4rSJHaUsDGJcDLJiiizHQ233S5geYZ9y6LUZzBxWJpAhDFycAjAR4yZGhsk9Ou7nTlz44H5i w6rV946yMp4Q+MUWxS7rUv07/nGEWjkjw4v4pTtyms1YZ5/vzvR/N2uTnaKOw2wDP7/O5y3zfDs nMQEA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Only pick the previous slot, when btrfs_search_slot() returned '1'. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 5c6224ed3eda53a11a41bffdf6c789fbd6d3a503..0c4d218a99d4aaea5da6c39624e20e77758a89d3 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -89,8 +89,12 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le if (ret < 0) break; - if (path->slots[0] == btrfs_header_nritems(path->nodes[0])) - path->slots[0]--; + if (ret == 1) { + ret = 0; + if (path->slots[0] == + btrfs_header_nritems(path->nodes[0])) + path->slots[0]--; + } leaf = path->nodes[0]; slot = path->slots[0]; From patchwork Tue Jan 7 12:47:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928852 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 29B581F03FB; Tue, 7 Jan 2025 12:47:52 +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=1736254076; cv=none; b=CsXSucb1a/joZIt5CwjrOVC8LVAVqI0fvol0t2SXObp6EnGUIMJqP0fwE3FA2HzxTycNsJnCUPTN0xF/TQTfYfgSKRvFzbPS+JbLSahYSiWQ4uLGgF1sWMW47woWQKuzCOXd8n8KVc6Od8lkvhD6cW0yw8D9PRougDs46rkbVtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254076; c=relaxed/simple; bh=vvq1v6mp8BvbKnZZYDSASKecH1BwwpK/VfSurMQRQaQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EylVUtWhIEqUDvNI85OghLAnEvDo1twVQxatoMi2er3ktq54gwxAXUGiWFHTY5AVBGfztPWwnMwzc6Udz06nZXaFZdQmyaYD1wLIYQFNzKuKw3aWl0DIjpUmm6HsNGU1v2e4PR3Wqs6GJ7tcgO+32/UcuXr5dvPhwK6w6U1lHpo= 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-4361f65ca01so153874465e9.1; Tue, 07 Jan 2025 04:47:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254071; x=1736858871; 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=iJ+34kt1gEseDje5K63RAt8/DsV4tsL9QDJbvq9xVwE=; b=EOs6r4dem22x/WCugGZx5jjaIjSm+/Q4O4EfIGWw+7VRZFsNfl8wR9XKc3kb1+L171 TUoYpcqJickbmoNRkn6M5LYvSKmpiKccv4jmtxCQZGMOS7EQJUt2ds99JV9cFk1QPdTR 0n/PdVaM4j3wmxwc+BLA1VfBf87LgP7ILhItlmPiVJZ632R0zIFAeJOpgz20VopIo/UF d2eTA5ARfRcJ8gSFF74Xuxk1T45KHSpjVjvTlVZBLC+2r/yNCIKuCaSeZL2GVyDMF2T6 af1eLTxjUX7WheLh0r0Wle1AITvrJ3R9Y0Hvt2GBXV0v5ZryxXXFK7F74vYkAUYuwJxi XIyA== X-Forwarded-Encrypted: i=1; AJvYcCX/NNzmtSEDPCIGxaSC+WZmXU7F1pfnUQljcZJmk+ubBgdF42fl4ETekvREMYAvIfOQKcdoxigJswId220=@vger.kernel.org X-Gm-Message-State: AOJu0YyDEjI889LsVwh8Icr3u1+PDjVvhcMjJPZOs+bFcwHzbDLtb8SF kMBsIBD39Sl0s8Nes3C7pwBlnE1z3mgb7Az2J466pDzagVdrsVp1kd7MSg== X-Gm-Gg: ASbGncsoLloft+kV+WSCBfKGlIAEwkyCWr1qYAU88FJ70NU1ZLPyqJHsLqX++owrjOx h149UihvLrDRek4GqmdMflUZr3WXx53ljONgZi60CbhjotcrxYqaWZ7LJOV284PdxINMqDY0JMv +dAqLaJbhDTeMITaDCCq79gdvRwwVBJXoJdcjZzaopmXrMI41AAWaJubnEjgRgKAwaZZOfc+Kzx TAn567cYmflhvlQzmkt5VRd77RULhb26LE2P6d7o/GPVVEijgavpmahydpAZLiobEi28HCRJ++z /pSbrDQGniu3gDQ9xDgn1oeO0S0TdohLe0Yh X-Google-Smtp-Source: AGHT+IFipoVT5TS0n2tfz0gbCHD3ebuwGudJhTyHd4cQMOaj5fplF1z5j9viIYSSZYlRcUXfhUGzOg== X-Received: by 2002:a05:600c:35d2:b0:435:d22:9c9e with SMTP id 5b1f17b1804b1-43668646335mr528896695e9.19.1736254071122; Tue, 07 Jan 2025 04:47:51 -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-4366127c508sm596884845e9.33.2025.01.07.04.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:50 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:34 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-4-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , 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=VYTA66hDlZ5B7qrLFBNCdOMUx1quVhlOJvFShrWXqdM=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhXeSf967FpZk6HZK6ap/xSNnNTWVSwVPrRn3ks7I 45GHiGejlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZjIdV1GhsdfL3c1/JVcsONi gfuHxQUbtj8+sm5JiraU+Zvt09dtnqrL8N95kYpxEtvMje5sx8x2f+6On7S3h3350o/eyptZwvp yM9gA 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 0c4d218a99d4aaea5da6c39624e20e77758a89d3..7fc6ef214f87d480df27023816dd800610d7dcf0 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -140,10 +140,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 Tue Jan 7 12:47:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928850 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F22901F0E31; Tue, 7 Jan 2025 12:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254076; cv=none; b=Rag6AbRFnHMAb+52l76iqijAN7x/bhfcvjGdgVOA6kWiBw4J6RrNulpIuElas9XKsQq2DDi4qyqr+OopbBuWCjnLjXL0vhRJF7UWJ5WhBzPZ6nQ4BjtlM0AqMxo4r6TWB8zGB0DhddnmJRF8HZy1GDlt27i+vCi1BDjUZqYINhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254076; c=relaxed/simple; bh=RTbvXSoM1H8POFrhE/4oLSdcSX1/P8nRSKULuhMcw74=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tP20S+imtn1l0eFYEnV0zFo8V8H7pJp7iqVV5sSnNte+nk5ndKPCm2r8r4l32vcPeiwgocecyfjJ3kTLffqLSEdKNYm7iWeGXR892d77pGyWQOrwYB9s6sKGuEMboktK5sm1cHMkEgRHWjc1/go+6SS6wBB6kGJW5hx2QVj+4Es= 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.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4361c705434so111938555e9.3; Tue, 07 Jan 2025 04:47:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254072; x=1736858872; 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=xSYpPypGdh/4KheFCajssO/QgOBFMd+r8ioOCQO7O7c=; b=rFq4d5vQidPYQVh24GvhaTn0fGNxmXt9jhAvSHWY53DKP8oL4tGNzu3uVX35zLzE3K kGFueA7Qo4CnDg6tk1laSjd+cEMyhMSz2/G85jbBinlKOLHhThpRqDJGsH2lnCWyWFaC ZTKrzt0yd18sANoiQ68XnzekhnKovvslmjoF8U10chE1CQoZOZV7QS01qxkcQlh7cXvQ SLEx1wzLaZiOGhy/KGfzi082tvN+iPlEgRmoxafWhqfQ/LTkbQ9ufoHrTDUTBmNFPfy3 hzqDDgfPNOZh3Bp/mUj/JBvixGaxKDJ7LrHPXIcM+1Fld45vYgz94xVSv8sIHwV/g2P4 pt/Q== X-Forwarded-Encrypted: i=1; AJvYcCVo45LhZSVvuWgpqKCxNDOU8ECbaRehKjMzwc5jiX6J/cHJmE3uEfbXxVykMERa5/k5JOJz3nYx2lJxUq8=@vger.kernel.org X-Gm-Message-State: AOJu0YwR/nyF07/NpvoMd8dexJtSkMeY1ndJq1ZOuWQcjeAvzi+RzZA+ nbxbmsRkMCt+8RK5gFQcFMtcDn2lp3l9VdG32H+MZANCaCPYpLXwrqA/5g== X-Gm-Gg: ASbGncvEUZ4my5awKfRBNqdF4EyZXdNqD+nozgWV8w6QNChA16KXhc8Jp5Y+tBFEtKK wkAMWV54Dy9zbFMh2r+5iNCdnmEA9UUUOUl3BStVvk/CXhXbjkwXZUUvz6yVl48kR80/IA0wNMl OBYm5ZzjeSXEhf8JcJlwN0H9gNmvJr+8gO2iFu07FI4MJNmaewfb06IbyH5saSOuqMWW5r8Q2Gi C8cuidu95T0vZ4g6T4mvG/Vbx2bfikOmJskHEGzmaRKUJuBNkLFLJuE80C8c964+MRr03Rz9olr fIdMrNsk+qoPd7P+e3UY6uzwtZ56R/UtmIAg X-Google-Smtp-Source: AGHT+IHwahq+KsImSfG7F4SZ05t7hQYbpjuOuZfAOUwg94H8959glRPG4BvkMr8VJbQuKsB2IMfqiw== X-Received: by 2002:a05:600c:3554:b0:434:9934:575 with SMTP id 5b1f17b1804b1-436686461d6mr541436855e9.16.1736254072127; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:51 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:35 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-5-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1140; i=jth@kernel.org; h=from:subject:message-id; bh=ldy157oU5ZbR1CUQv8mzWFLdMoj2ibd+pxqwLCsNhKs=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhUqeLrMkP236O/lrvnup2Oul2en3TCuYj2WfKxBR IPRea51RykLgxgXg6yYIsvxUNv9EqZH2Kccem0GM4eVCWQIAxenAEzELoyRYabqZuZiju3mSZa/ VINMpazSPyXO+ZCzSMB9amqY/HSNlwx/eBLYpze/ZKlmf3Lz4C6GNcfYHn7Q59Q7a17OtHLntK/ 53AA= 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 7fc6ef214f87d480df27023816dd800610d7dcf0..79f8f692aaa8f6df2c9482fbd7777c2812528f65 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -123,11 +123,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 Tue Jan 7 12:47:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928851 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 C6E3F1F0E52; Tue, 7 Jan 2025 12:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254076; cv=none; b=EBPOZhlHJe7e9zyS1hwsxRypzLkY7mJpDShEqZYQxfaIp8pqKFpYmVSjEJ1ayONAoA/qN8X+fEcU4ULmk+So2wSYeuuJwkC8fYM2uGLvAapyKiew4qIOJgQw65SJ98ykWYB54R+DruNePlVIpYR63hIf75gIByrHWrY/QDdTep0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254076; c=relaxed/simple; bh=Ri/61TC1qvjbcGtqWjE7tlIVpIWdWIHK0k0XQdxDVGo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eLDjNxEJ3vSWIRmhjHJluaqPwWrA/zf2HIs5DXRrll2eWErWtHMRv6GCXJte3XC4li8h4k7aemD1M+53R+lFyKdcIzYkkgsXxhyNGr8cGzjSbCB3n++7fgAvlbCtcEmDZa74HwAHTnG++aTTx5nYIY8Q5iYmNFtGxm9R+Kl0s4k= 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.44 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-f44.google.com with SMTP id 5b1f17b1804b1-436a39e4891so55288875e9.1; Tue, 07 Jan 2025 04:47:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254073; x=1736858873; 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=8HMhazJ4aHrtYYO6dr59OnqHZ0soK8Yigb9JVzCFUHo=; b=hjeIFb0i9Hs15tfZ7uIjkZQpCBtV6jJK1ffrGnlYdhvE/dcMRFPpL9kCkBcmcqwmGf JeMj2EH4wswnTVp+9dyOAN+I/r6k9N6qSGPBBz9eAPT7hLptWE24GJ6T1mUvbufzWD0l iznF2yUYTUydp4Nu89/wJjMOts+Do03rhkaD7PpOx62Wqy2OBt8ROHPMUJ1h56dRCi0c izjuIYYcEEtgldF7RVmwgKDiEPESj6MZ6yQ5QozgJwBE1LD+ST6TyrChpBd05U26OYa2 0ziQ50DZlKdMaQYGBv6F1sC2p1qZWR+pamqeZqm2W5eJ8rfV+x7eEONdESq4/A8JoRJj RCIA== X-Forwarded-Encrypted: i=1; AJvYcCVxcSdsHcZpONB4uy5Q1rmpMLcBj1Y6hqZEYGOaw/2kdgtFNIgSKZoXQS1UxcDgnaBGt2RVejgGSsXkEPk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4A6g7MKw+ua9ldATGn5o0wmYOze6/hENv/iLTNO0RLljE5O2h WPSkUDvayXJAk03qJDcNZxMz/HxlIfrbgmKITF/5xyaJwiz8JyJWq5yerw== X-Gm-Gg: ASbGnctYzmcYvmr+SJSpVzcnFlwhBrX6CzmGtcgWad8pe87urBurTOvJl5xrrRF2U2S FIRSsOpG4JSk4si+OFMHFE4KJqgSgt/JdA8GvFWXKm6Jhw9f7FBfWV1gm2wq0tJrMtyE7e2EnwP mD5hzvoSIdKSC8kHIqZGAqg85WII4/zWZ5yPt2jccJGXa4RizD0IClOlJuFymR5NTNrXITaHA1E 5AyHdh39wxNYrAeatAw9ZA+xSqqWFkHr7zRta9l4ocj5woRq0od5Pfzwm1Rd2LGKRyq8p0CpGx6 1MFDve+5OgNOnZL7t1wojQxnQyxaHdVhU1lj X-Google-Smtp-Source: AGHT+IGzWdzW9NRWzbdtYm7udxlFpnR2z7yKEn7GmU2WIQ6591jqL7Hc2I3gK4R++2PFtEZfs3IX0Q== X-Received: by 2002:a05:600c:154c:b0:434:9f81:76d5 with SMTP id 5b1f17b1804b1-43668b49a47mr492588715e9.22.1736254073031; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:52 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:36 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-6-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2148; i=jth@kernel.org; h=from:subject:message-id; bh=pJGqsi9OfeqSzNQ9MPTfpV7JL3HzH6XVBbbaT6qHJ/4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhWe+73KVKhbpaT50G/Xsx0btuqc2Wt3zWTCZaepx S/abnRydJSyMIhxMciKKbIcD7XdL2F6hH3KoddmMHNYmUCGMHBxCsBExE8z/Pf8tlIuatMOFb9t OuvWbJtVfTRn++GOUyFyl+L9Sg5+LVdkZFhxTXvViez1q9/ortySFqURt9baTswzeJrzQ77PLPy T1ZkA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn When a user requests the deletion of a range that spans multiple stripe extents and btrfs_search_slot() returns us the second RAID stripe extent, we need to pick the previous item and truncate it, if there's still a range to delete left, move on to the next item. The following diagram illustrates the operation: |--- RAID Stripe Extent ---||--- RAID Stripe Extent ---| |--- keep ---|--- drop ---| While at it, comment the trivial case of a whole item delete as well. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 79f8f692aaa8f6df2c9482fbd7777c2812528f65..893d963951315abfc734e1ca232b3087b7889431 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -103,6 +103,31 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le found_end = found_start + key.offset; ret = 0; + /* + * The stripe extent starts before the range we want to delete, + * but the range spans more than one stripe extent: + * + * |--- RAID Stripe Extent ---||--- RAID Stripe Extent ---| + * |--- keep ---|--- drop ---| + * + * This means we have to get the previous item, truncate its + * length and then restart the search. + */ + if (found_start > start) { + + ret = btrfs_previous_item(stripe_root, path, start, + BTRFS_RAID_STRIPE_KEY); + if (ret < 0) + break; + ret = 0; + + leaf = path->nodes[0]; + slot = path->slots[0]; + btrfs_item_key_to_cpu(leaf, &key, slot); + found_start = key.objectid; + found_end = found_start + key.offset; + } + if (key.type != BTRFS_RAID_STRIPE_KEY) break; @@ -156,6 +181,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 Tue Jan 7 12:47:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928854 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 C0BAC1F1303; Tue, 7 Jan 2025 12:47:55 +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=1736254080; cv=none; b=eZah443A2MfBMS2yoyUppzOScfksCC9iHyyDSLaxHmOce+37nxWB0gFuy1g6JKyELuXx9OvhWhTA6grjK18FKZH3HHL7sfo/QVfSc0aaTmqL6800iRANa0359xdSNe+P+C3Zx0cOtNfirwOgvsu5lG0uPTbtWKF65/17ANOkE9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254080; c=relaxed/simple; bh=58Gd8KQlYpvqTrF5zIUph//YzaJlr3jYRa8+CqkE9RQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GImwIvLqdiWKWlxduN6OdUkxrw/dGEE8DU1AOa8mry8Qhp0J/dMl8Q+EsQYXDHJVrfx3iOTIEnElHWa//mPXTnETwkgIM8CI1TEY8MMyLpnvxOIjAWa8FCT7z8FgoQSchWtVcDrKWfDOWOPJxX18hOBapsrjxSg171XEWDozoOo= 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-436345cc17bso112069945e9.0; Tue, 07 Jan 2025 04:47:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254074; x=1736858874; 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=92WJlMl4zxcREifQvN1xZFLk6LPYCZQK0qlMkK8xgPA=; b=j027mBJCnDZVEnv3cqxywVAxnnRvW4aeq8vgXFtQ631JXXLxAbAAOIisx7rl2xzc1O /+mJ+MLJhDAwnVtbuvAxMzbvqYy58+0lYbnz03CcO1kHQ8TS4Hx6Y/IlZYEbDw07sNe+ R/KQoLz5gsQMzUgmzCdJyRFpv8eMVFbRIVzyYpw87ucxOXpEEft9qTk1MKUc+XMZVIV/ 0P5STJL6anfGRBu/HX4oRnBdHDl7d79FiSAGeqe3ocF4o6b1Pngqot/P6FwxLAMlybNP bkmuayhJe4+GV3Dg6OE7Fce389vC+Cz0hcuZ+A3X6SXknvoO39bk51S0JIeG676Br+MR vZBQ== X-Forwarded-Encrypted: i=1; AJvYcCXgYakQI0RlbA8X6rnIvIn4CPtLlcd70IxRlRXpGdxNtFQWW/8xqWPmOpNeiTC8FBo7PuF5f4oydPIDm04=@vger.kernel.org X-Gm-Message-State: AOJu0YzkibBDhko6GK3vry+qUQMDsEmSl0UekLAksJI+BQMvBzGeL3RJ m+Lo4YT7pJmiMqxd18ne++WObsEmXViwD5qd+r/+ZX9tEVhw4x+p7PwsxQ== X-Gm-Gg: ASbGncsK9Xfx46usoOWxfH77yuWST4Ix83a9pQVCrFzK3kDfXYylT9GtZ+Mssgphe87 Byz2WcFoWuCS2g5U++XnAO3RcP3I8PBIazIixvezxBonVrXDB3yOxFrUvI/vl7hRNXNAcm+phMs N/52gn5lPvt+ayJbPlwO0f/xIIA1T5+Uucwslosb+ihcWFmFgpnO5lXk+v3APA8HbRAwmyajKre SGZYHdCalv+c8LDLneXhYaRg2WJay0sywdNduODGpMXB80KXarPbFuqRs47IAnQ55PrJUtKS7MI v4xtmDLoBUbqcpOn5+Z85xZaLaX3VrctQcTA X-Google-Smtp-Source: AGHT+IFnOgjCf0tKCouKaof1UjLBpqMB3eg6bVsVfeaw04pfslFiwJ87ZOKmKaRP3D1cYLNOq08KJw== X-Received: by 2002:a05:600c:1d1d:b0:431:5044:e388 with SMTP id 5b1f17b1804b1-43668b5e172mr497511865e9.22.1736254073912; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:53 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:37 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-7-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , 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=AxkJp5qY5UjE1UdyCqOfRthbS1A/pn7c+ONIah7ZhWc=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhVynbbra9l+NUd81etvbF92363ft2vr5YcsCgWpe 8Wk31lyd5SyMIhxMciKKbIcD7XdL2F6hH3KoddmMHNYmUCGMHBxCsBEJjUyMpzVeb/adOrpEHVW aZe1r35VT9l7SJfLKu5xnj/3Pvbw0A+MDM+z2lLjghaqbXwxrzau8NTM7YfPX30+Y+0q598f3SV c+BkA 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 Reviewed-by: Filipe Manana --- 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 893d963951315abfc734e1ca232b3087b7889431..d15df49c61a86a4188b822b05453428e444920b5 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -138,6 +138,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 Tue Jan 7 12:47:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928853 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 CD3CA1F03F0; Tue, 7 Jan 2025 12:47:56 +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=1736254080; cv=none; b=h0il6G/fSrgYmx5VCAeVH7tzIAKYwNZ4taB0sEnGI+51e0rWtLK219lmf18lsKmNdjXh/J+DGxG2Gl622NL/5VmpKI3ZoAJBWPIqyde587zS+UAMPuvbWVKPQi2bLvA+dflNzyjOEbqGebWIm9v9tXeJ5RVeeUvk/HehDteK4Qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254080; c=relaxed/simple; bh=I85BPA74WANccPzPo7y6mE+E1q3qybDn2+rKMeMi5Vo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=esG2gXA8Knjw5qklpZ0uYOx6LF6xsh4ytUjTTBjhAVILcuDSDp6PGvZazTW2FlBBynQOFYB4S6cpnN8bWQ/QmT4UeTssiuTZ6h4D+x6lhukredA12jfdZNQB6V/JXUBdBO8XM1vonrKRc+Eo1++PLgrzT16kLfD6yVei9HzbWe4= 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-43625c4a50dso106851975e9.0; Tue, 07 Jan 2025 04:47:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254075; x=1736858875; 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=bCFXJ4bPN7GjxGZnZEmd9wZjo3kp25RgFP16fnw213M=; b=PxBXnADAfNiIKcBKa3cV+i8A+Q5j/wx1KpfEiZe1SMAs7I7i43bpwF5gCN3lvNg8/Q Uf95x5wJGHduDvHC4+cK8OqK/a/ilg7QQ1yeTjKk3FMHtssXmWHDBpODCgjNQD4dsSkz rthdiWiYsRHRTg/zVLyvqtRY9crStQFl7+ESc9GAf7gng6jK6hdvsmfVvIoKHQwYRFYi KpExO7mT88+uoJGMTPLvsQFkcykQFSyG6EFYu/V+KU1x7Iv9wT1waInWxiMTWI7eVJ2q hMg9MWNf77WvAadqbi6VLNQejV5gevAztZbv1jxbMMyiAV7R9f8avL/O1TIHmyNFJwu5 zqlw== X-Forwarded-Encrypted: i=1; AJvYcCWIHzokOkq9n4lSB3kpa8cjM9nnKWi4mokIM3JB/qeu0etEwyJuiGtaguu3xAWYgU41bJxxc7Ioe8ZI9V0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz39N7RpKOiEKvM8cXDkIt/PhtxkHZEbyXsE7dtZc7R8GudUE5d 2miyJm4MxwIem81te6Y6m/Xky0/WD6bJ+61qJHZKaPE6lLjLYARpWMGLBQ== X-Gm-Gg: ASbGncuE1E4TfnfYyKWFCqy+DI3qPzo977gcPPZMYWxYHkv+PFYUdmE/wRBjri5GAP5 YA4vsLBF4lkr8AW+CzJSLMRBNLiBaqAevYoj+l2+HKphChJRAlL3mN0KVeuL4gRbv5K4grpG7NI rHio9kKS6IEQHf2ARZiqUoiqBBP1phaEezqIvZ8MT3KZrWU92pskBCvF6pKCT6kAYXw105snTFv SVdK069xCdTrHUV1eCZa08FBRe/7Yv4sfopf0DsmNkUcUL27ZNrgx55TE6/HGGffo8eQeug6AYA LFFTHIbwgnvaMjFWZ8hX1oWJUW/wH5XhU90/ X-Google-Smtp-Source: AGHT+IFd6SW1E56yTMBIeAlZWFSGkFjqW3J8uGqWiUE08QZuh2t3tEtCRGvJ1wot5hm4B07VQPplYQ== X-Received: by 2002:a05:600c:1d21:b0:434:a4a6:51f8 with SMTP id 5b1f17b1804b1-4366790e3fdmr582778405e9.0.1736254074861; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:54 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:38 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-8-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5650; i=jth@kernel.org; h=from:subject:message-id; bh=OYXWebrPVzfgGPih4xV3ZZ2/GhP86lPYcyXfDLrTdCo=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhVumZi0reXR2ksX6xcwfWCdEPJzxY3/KpkcMjfTW 5+oz3y0qqOUhUGMi0FWTJHleKjtfgnTI+xTDr02g5nDygQyhIGLUwAm4rCT4TebdY9AQWlkTmNH mrPULcGIQ9/O/Q1dLv15os/D85acfJYM/yy1Xhkfirj5/O+U7lqhKT2hc4S+u7C+m/1g35WvN6U WzGECAA== X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't use btrfs_set_item_key_safe() to modify the keys in the RAID stripe-tree as this can lead to corruption of the tree, which is caught by the checks in btrfs_set_item_key_safe(): BTRFS info (device nvme1n1): leaf 49168384 gen 15 total ptrs 194 free space 8329 owner 12 BTRFS info (device nvme1n1): refs 2 lock_owner 1030 current 1030 [ snip ] item 105 key (354549760 230 20480) itemoff 14587 itemsize 16 stride 0 devid 5 physical 67502080 item 106 key (354631680 230 4096) itemoff 14571 itemsize 16 stride 0 devid 1 physical 88559616 item 107 key (354631680 230 32768) itemoff 14555 itemsize 16 stride 0 devid 1 physical 88555520 item 108 key (354717696 230 28672) itemoff 14539 itemsize 16 stride 0 devid 2 physical 67604480 [ snip ] BTRFS critical (device nvme1n1): slot 106 key (354631680 230 32768) new key (354635776 230 4096) ------------[ cut here ]------------ kernel BUG at fs/btrfs/ctree.c:2602! Oops: invalid opcode: 0000 [#1] PREEMPT SMP PTI CPU: 1 UID: 0 PID: 1055 Comm: fsstress Not tainted 6.13.0-rc1+ #1464 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 RIP: 0010:btrfs_set_item_key_safe+0xf7/0x270 Code: RSP: 0018:ffffc90001337ab0 EFLAGS: 00010287 RAX: 0000000000000000 RBX: ffff8881115fd000 RCX: 0000000000000000 RDX: 0000000000000001 RSI: 0000000000000001 RDI: 00000000ffffffff RBP: ffff888110ed6f50 R08: 00000000ffffefff R09: ffffffff8244c500 R10: 00000000ffffefff R11: 00000000ffffffff R12: ffff888100586000 R13: 00000000000000c9 R14: ffffc90001337b1f R15: ffff888110f23b58 FS: 00007f7d75c72740(0000) GS:ffff88813bd00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fa811652c60 CR3: 0000000111398001 CR4: 0000000000370eb0 Call Trace: ? __die_body.cold+0x14/0x1a ? die+0x2e/0x50 ? do_trap+0xca/0x110 ? do_error_trap+0x65/0x80 ? btrfs_set_item_key_safe+0xf7/0x270 ? exc_invalid_op+0x50/0x70 ? btrfs_set_item_key_safe+0xf7/0x270 ? asm_exc_invalid_op+0x1a/0x20 ? btrfs_set_item_key_safe+0xf7/0x270 btrfs_partially_delete_raid_extent+0xc4/0xe0 btrfs_delete_raid_extent+0x227/0x240 __btrfs_free_extent.isra.0+0x57f/0x9c0 ? exc_coproc_segment_overrun+0x40/0x40 __btrfs_run_delayed_refs+0x2fa/0xe80 btrfs_run_delayed_refs+0x81/0xe0 btrfs_commit_transaction+0x2dd/0xbe0 ? preempt_count_add+0x52/0xb0 btrfs_sync_file+0x375/0x4c0 do_fsync+0x39/0x70 __x64_sys_fsync+0x13/0x20 do_syscall_64+0x54/0x110 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f7d7550ef90 Code: RSP: 002b:00007ffd70237248 EFLAGS: 00000202 ORIG_RAX: 000000000000004a RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007f7d7550ef90 RDX: 000000000000013a RSI: 000000000040eb28 RDI: 0000000000000004 RBP: 000000000000001b R08: 0000000000000078 R09: 00007ffd7023725c R10: 00007f7d75400390 R11: 0000000000000202 R12: 028f5c28f5c28f5c R13: 8f5c28f5c28f5c29 R14: 000000000040b520 R15: 00007f7d75c726c8 Instead copy the item, adjust the key and per-device physical addresses and re-insert it into the tree. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index d15df49c61a86a4188b822b05453428e444920b5..a4225ad043216e5d7035a71eab6bcc49b242836f 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, *new; 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); + + new = kzalloc(item_size, GFP_NOFS); + if (!new) + 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(&new->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, new, item_size); + +out: + kfree(new); + return ret; } int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length) From patchwork Tue Jan 7 12:47:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928856 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 C95741F2363; Tue, 7 Jan 2025 12:47:57 +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=1736254083; cv=none; b=jRDhyUL5cws7urLjNULrHEbSqON2jZs/8Jcd8bty9YqeNpOX5iGlBxmhjreLJe+Oo04SqC40FhNanlz2+it8wtyqUTwSJOUgWu8JmEo8cjQfLKinU4aFoufzeMEcybNQqbTGa+2mPaDnPo0zg5Adsr8Ba6LFMwlmJpIQR4M/ZbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254083; c=relaxed/simple; bh=kxPheXsGcgr7C7bmW2sFDIN+8yZhU6P18+xwCuVRn3o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TkOCzfSGFLIJi4WXP7RtFI0HMX/Gax4QCPJNnSy76hBRFYhTjYKKOq1zM/4Cx/gkUwQVKn/Xh8wxRbDF4BOvdV8y8vUlXvoYDUJchHtxl/GaT/m8GO1VokrAH2jM+Avbhp/nAjy6tJG72BVX7cacyyxVMWWGaWEkMiASY+69a7U= 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-43618283d48so111997155e9.1; Tue, 07 Jan 2025 04:47:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254076; x=1736858876; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s4qxRvmfu7+JXk512bdqWeZXj/ZLfnbrQ2mO7uJqnjk=; b=wg9VI//s2IGO8qtOAaQFjNgKGx5fC7407lYh9jg1KcAOEFC82WFPiZN7rgb3rp8euq 6xAQsdjSkLx8yqbe62/iASrFgz6sQeMGDK9mLclLbwIbhm/Pxci1s82Vrvo2nvMN7b5M 2FPKF95Usr2NW0PSFT7a9GC2mD3lLnqYkL+0Rd34a9r05dAz1BuSkqFoH2JqNsAWTHbI rx1LmdvSlvZnH66N3N2tbBNEPLChspTdt1jukme5x8HCZh5I1KhKgPGpjMLhwkDusHb8 fKIPVn5UVpGYJdvHYW3Kd1mOO9bPbzhWt5aJAyq71JqKQMRFJp6ph6SP6HMWN+PMSUaB WYWg== X-Forwarded-Encrypted: i=1; AJvYcCXnNyNPTt3o2gLmn5RJl0TncDKaBQ8pQcEkhzK0Zp5kQMAWmukPG1NEgP0Uen0r+ZvZpvaG1bnpacX6Or4=@vger.kernel.org X-Gm-Message-State: AOJu0YxSvKJxtuiJp36XTgAXgVpkT8qdXMjNEetcZ51m7CzppdtKk0kq aQAB9/f10Q116+JYb1Kb5HvCnbuuPFrvaoNq8Ir/Xec4MMWJQNmS9CuUWw== X-Gm-Gg: ASbGncu11UINsJ++3AGe5QgoOy+kXAuAzHuVcBJvS0dLY3qGqdXDE5mxrmm8fTRvHWH v28b2pczWBbOO4whlQunXEMdCeKRE7bC2grJGxf0ngMkwHNGJHQhWPrWbNjzlgLqAH1y4miquT5 fk0FetmWnmaEikF+EPTubKxHk2b9tXrBAMA+nNMGE9ZAQmwFLNonUe3Dqlfflz0DoeEC17v4SEO 0uZOgvQWgyv/MUBGIQ24cjjWocybpJCe/BfLJJNbIDHoK0AzcisLYWK05s1XAGkRj71Q7LF7rWR Y7J6anfWGATZidb6c7LuYitfPVn6nuFqZQpi X-Google-Smtp-Source: AGHT+IE9aeh4Lr468eG0o0wsJYJS9hFeRSanSJtFDz5kmozzNdydoBEncfl1ImRPq0B9/+Re76OD2g== X-Received: by 2002:a05:600c:a0a:b0:434:f0df:9f6 with SMTP id 5b1f17b1804b1-4366854737fmr553050555e9.3.1736254075828; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:55 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:39 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-9-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1169; i=jth@kernel.org; h=from:subject:message-id; bh=Hai+FH+wlQA9jUF34rKWHq12Hes2Et4vpJtRh4PDbc4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhUmSlY9bWWNrfiS6bG9QT/zw8XE4m51zkq3/t2Lg uvmf+7uKGVhEONikBVTZDkeartfwvQI+5RDr81g5rAygQxh4OIUgIlMbWBkmMqgv++vu9PS3zHP pdy17bn3yOypOBaTUlF6pEday6j0KSPDqYbytcVn09h3bBXYF3kk/l/k19NPv4myG3zYeSnJxP4 vIwA= X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Commit 5e72aabc1fff ("btrfs: return ENODATA in case RST lookup fails") changed btrfs_get_raid_extent_offset()'s return value to ENODATA in case the RAID stripe-tree lookup failed. Adjust the test cases which check for absence of a given range to check for ENODATA as return value in this case. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index f060c04c7f76357e6d2c6ba78a8ba981e35645bd..19f6147a38a54f6fe581264a971542840bc61180 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -125,7 +125,7 @@ static int test_front_delete(struct btrfs_trans_handle *trans) } ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe); - if (!ret) { + if (ret != -ENODATA) { ret = -EINVAL; test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", logical, logical + SZ_32K); From patchwork Tue Jan 7 12:47:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928855 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 BDAB9208AD; Tue, 7 Jan 2025 12:47:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254082; cv=none; b=NdtqU1OL3TCkTSTdd0dPC4Xlv5PnBSzn4npYgTo+UV/Wk36SZ8l5gXrTsj8jEyBR6jaYl8jOERh1fnNaDtDLvkBddXy4/u5otBBDdxlzDzMzk9u2oFL29uy46KqdwXcBmaxsfZPd5L2i6AuKwV8AE4EHpc4UIcRiIBAwE8x/Jz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254082; c=relaxed/simple; bh=Y61cv6XONm5aSh6hqCsDgZWpAA78IkIVPAV2P/Gdd4Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TsWz9uEJz6NcdsZjq9euBKMh+8/ej/mrXULL8cWWeBAwnHzGEP2mce49sm5PPH0wVhDiFJr80w9tqnM71mUjjA3D18hPQ04pRKLbdW2IXmsLzDYlSpA8cqO9aybvYGumNnFUlWGRhw/N95TeqB/ogyDgLTWGj67NXd04z2Tc3XU= 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.44 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-f44.google.com with SMTP id 5b1f17b1804b1-43675b1155bso147921465e9.2; Tue, 07 Jan 2025 04:47:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254077; x=1736858877; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wo94xRQW7tw3npwzxFYun+vVy3ZCNUGiTzgM9DSsIwc=; b=NfBL5G/X8BSOkjxlvniBxCpZbbyKrABJnHo1jukNXOroqni6UR6rkp9zOcARo5K67o z40YLrHJUkvHmsnq3z0mBXDdaHI2FWVIczGkVHd22FZ9am3otoIBFbqPfERdaUvpSvCW Dg6nKrWx1SN3orsPektX+uJwcnue7fYNg2uE3bRjs7btv2rgkZ/0QiBthu0eaBzTItyB 3SoYkKAl5XmhkgP3P2N4JcfRVnKLFAuA1yoqBZ0Wk2FpVw7F4XzolTxOKaKQ3Hl3b9tn IWWQyZtwScwxaHe1y2bBLaB36GjaW2+BrfXRzmZJWMW2QkoHfYLOfvMPEEHsAM+ahfLX JmmA== X-Forwarded-Encrypted: i=1; AJvYcCXcHmv4gcc/SirT4XcQJ0bm1tYAzXQ8DwC/kCkcTXXfzPyth4bj2rYPHiPgKVBkGaE0JsvPob3n492pLos=@vger.kernel.org X-Gm-Message-State: AOJu0YzzH6Ws2hj7qO28lxxn9gX4sQVvWsoNm6/o8w78UxkWfb5BkVGj 65tts7rhsrRr1VeXaGa5cVsBvjcUjb2lk6lEIzkx5I1stSFq9q1cwRQC+g== X-Gm-Gg: ASbGncuJ88LaQa/z0qKa141I4tPd9Y1D5tEumesHDlj6AcFo0wPFs+7FrnmOOydSuzC cgsTt+jp3BPX0IzUE2jof2TDbhTIoTkJxh5nsYxzpPT57L96K3YKzCGG4uyXSynSjIadHYvaqP2 JJzq1aSPBEu+IG7E7Ts9WBCbIaRuoDq1kbYXBY27q7zCrrVcvjZgYOdrnAO+k6HyR+qJyuLgJCL YrmAA0i1wgr5SNA24ID5Xn7z73UwqZUhqSttzql746jdIJhq/zw601FWaPnqXFaOl/kQM80oLh0 DFUjKOAdTZ3Xeby4msmP0e9O5iTECr8MenNO X-Google-Smtp-Source: AGHT+IGOHd3+acGuNHFj14ExIK0HkqFGilzbQQllLLY8rN2DudjFZT8qfy/r3mRsaoIMeoJk9gx4yg== X-Received: by 2002:a05:600c:4f0d:b0:432:cbe5:4f09 with SMTP id 5b1f17b1804b1-43671247b46mr508799485e9.4.1736254076761; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:56 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:40 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-10-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4127; i=jth@kernel.org; h=from:subject:message-id; bh=BKJ9UtZqMumOGnIO3fSUYTuxPI6H2ODSwOVX3gFSNx4=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhW+36/206WwbdMMuc/CoR+dSu8xnPWLWjzXpiut6 keLd/TGjlIWBjEuBlkxRZbjobb7JUyPsE859NoMZg4rE8gQBi5OAZjIpr0M/9PdAy9WRsuLOzGa 7JEqe3KppU9w4eaTpxZtmJJTLt4w7xrD/9yuWYmnum3q9f4Xt9858+xmvvj0G4sDX1Z1cYqwHvg TzA0A X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn The selftests for partially deleting the start or tail of RAID stripe-extents split these extents in half. This can hide errors in the calculation, so don't split the RAID stripe-extents in half but delete the first or last 16K of the 64K extents. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 44 +++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 19f6147a38a54f6fe581264a971542840bc61180..12f3dbb23a6423c4d224c5b087b35862b8d643db 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -14,6 +14,8 @@ #define RST_TEST_NUM_DEVICES (2) #define RST_TEST_RAID1_TYPE (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1) +#define SZ_48K (SZ_32K + SZ_16K) + typedef int (*test_func_t)(struct btrfs_trans_handle *trans); static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_devices, @@ -94,32 +96,32 @@ static int test_front_delete(struct btrfs_trans_handle *trans) goto out; } - ret = btrfs_delete_raid_extent(trans, logical, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical, SZ_16K); if (ret) { test_err("deleting RAID extent [%llu, %llu] failed", logical, - logical + SZ_32K); + logical + SZ_16K); goto out; } - len = SZ_32K; - ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_32K, &len, + len -= SZ_16K; + ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_16K, &len, map_type, 0, &io_stripe); if (ret) { test_err("lookup of RAID extent [%llu, %llu] failed", - logical + SZ_32K, logical + SZ_32K + len); + logical + SZ_16K, logical + SZ_64K); goto out; } - if (io_stripe.physical != logical + SZ_32K) { + if (io_stripe.physical != logical + SZ_16K) { test_err("invalid physical address, expected %llu, got %llu", - logical + SZ_32K, io_stripe.physical); + logical + SZ_16K, io_stripe.physical); ret = -EINVAL; goto out; } - if (len != SZ_32K) { + if (len != SZ_48K) { test_err("invalid stripe length, expected %llu, got %llu", - (u64)SZ_32K, len); + (u64)SZ_48K, len); ret = -EINVAL; goto out; } @@ -128,11 +130,11 @@ static int test_front_delete(struct btrfs_trans_handle *trans) if (ret != -ENODATA) { ret = -EINVAL; test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", - logical, logical + SZ_32K); + logical, logical + SZ_16K); goto out; } - ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical + SZ_16K, SZ_48K); out: btrfs_put_bioc(bioc); return ret; @@ -209,14 +211,14 @@ static int test_tail_delete(struct btrfs_trans_handle *trans) goto out; } - ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical + SZ_48K, SZ_16K); if (ret) { test_err("deleting RAID extent [%llu, %llu] failed", - logical + SZ_32K, logical + SZ_64K); + logical + SZ_48K, logical + SZ_64K); goto out; } - len = SZ_32K; + len = SZ_48K; ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe); if (ret) { test_err("lookup of RAID extent [%llu, %llu] failed", logical, @@ -231,9 +233,19 @@ static int test_tail_delete(struct btrfs_trans_handle *trans) goto out; } - if (len != SZ_32K) { + if (len != SZ_48K) { test_err("invalid stripe length, expected %llu, got %llu", - (u64)SZ_32K, len); + (u64)SZ_48K, len); + ret = -EINVAL; + goto out; + } + + len = SZ_16K; + ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_48K, &len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] succeeded should fail", + logical + SZ_48K, logical + SZ_64K); ret = -EINVAL; goto out; } From patchwork Tue Jan 7 12:47:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13928857 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 B224D1F2C2D; Tue, 7 Jan 2025 12:47:59 +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=1736254083; cv=none; b=nIm1ZOdE4XJaJsqbElWQP0Gj2/IWpTCv5aNE5C1IBGIE4Y5lhA+FnwGR4aEHp0Q4vuDcoSBjseGw8JkFPC+qZyZo445Y1OzeYBM236PK+X9oZ3Oc75NY/u3EtPwxD8X33+GFKQTXC2swUXSEQijdO94UiICVgz+3Fe3X+icXfnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254083; c=relaxed/simple; bh=dJgfFFrHMNX/wt/rlx1ta5IfOA20OE0pHFuC1mtWUk4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EPxVmSDBRShxEEnc3FjjnKpAqhPVWt+9s5U7+jxkIdH7jZSOPyfcZ08HCUN5VagfCTvF7P8d7rjoNWf4ttwec/QKSkVgpzTlRsVcjXb+cgEsBKmzN03Cg19UQC5BaOsN/lMBbrdkMKBO4Ds3EJphA7qfGofabfUJZT7t6RuMpQU= 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-43622267b2eso161824005e9.0; Tue, 07 Jan 2025 04:47:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254078; x=1736858878; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=71XSAwVnZXJGsAihpgV4sKSQDjM/13//Z7lrZY4oczs=; b=GSzypaHujIMjSkGDS55zDFPZGJ4e4J/Uf6PvgV8iSAs1t/lOWFxisYCj0CI2xTGsNG i2wocKn+HcErqksaKEoWV8A/J2Qs0D7b3xF96R5Nfq+mYVr17muA+3bMTIc8nJhQHHl+ NeKZXRPfcWcDkopL7/qByooZPfLW962XF9lFm8RMSY2Q8RaZkuxznwD1GCJnjvaxkKdt cLPDgk4LUKux2CbROC9UVDWQZFKJAZOdi0E3TOOzFr0UoSP13m4J2ybI4NhaGWTLoXDd f/rRUt2s2nDxK4+X83cybb8xgz9L6a/b2v8QM/5ap0jKC5brEwMEI9RCC1qkTdEd2N2E WoOA== X-Forwarded-Encrypted: i=1; AJvYcCWswjc3M2/vreZjAhOoWO0SlzpO5mtEglUwq9ADlbfNBg4VNOLBLoeQowoCBwOkSowbuG4DXbHZztb3NlA=@vger.kernel.org X-Gm-Message-State: AOJu0YxGQXzVBviI1sP9vdBhL8xKum2YjaN0AJfqy1yWPSSpGCLcEPQN OaVG0TFgLfLcgREUdDXUkBAaxg8BP4V4OQNP1qvy31+Wcv81N7to6+oYXg== X-Gm-Gg: ASbGnctnAAQorUn+mjlyZk+zHKzmpHslDSuezwLLmZRca27ygi4TaYeDvIxeCv676R2 bu3oyLjnkUDmNeOMcHLhdxVcwMLuCuxTne86yj+Lwt+MBwY6pCfTFsljbgbLzTW7v1rTLtha1T+ K//5iQwmSXcSi3RsCPEYOOvep+vJedZAeYSS3RWpt1OHiD3zrJhQBoM3DCaoBmymtUttg/1/wBC wq2ujPYF4PAI4sw1NpNjuJ5NmlrdO1MgLzkTlTOm+QB1p2/9lNCwCC2xrZWG8nofUFfR91B4VSz E4foSD2ph3olV0PGuFatRaYN4TfvkNVQ8hUp X-Google-Smtp-Source: AGHT+IFE1zt8adFn6ZNeImxchz/dBqGfM7brPaQ8kB+RQ76maEoS3xKrlZke2nAlEVd4ASdgKl1x4Q== X-Received: by 2002:a05:600c:458f:b0:431:5632:448b with SMTP id 5b1f17b1804b1-43668b5e0c3mr464998095e9.25.1736254077792; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:57 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:41 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-11-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5465; i=jth@kernel.org; h=from:subject:message-id; bh=7tLwXx2q11gSgeKl57UDh77jQX1COSI4LUB0wCH0mGQ=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhUxfMt+W9nNobY8ScFxibahjZJM0qpE3hdRAlssn 4SGakR1lLIwiHExyIopshwPtd0vYXqEfcqh12Ywc1iZwIZwcQrARJa9ZGQ4kXOFbetf73f/Gpwr 8ywnRmxI+Vn7+t+cM+/Ydiv/n6HDw/BPabVb4NR1G+7PudNkXxvJeb3vVOJjp8qEpT8i7386cX0 CEwA= X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Add a selftest for RAID stripe-tree deletion with a delete range spanning two items, so that we're punching a hole into two adjacent RAID stripe extents truncating the first and "moving" the second to the right. The following diagram illustrates the operation: |--- RAID Stripe Extent ---||--- RAID Stripe Extent ---| |----- keep -----|--- drop ---|----- keep ----| Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 144 ++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index 12f3dbb23a6423c4d224c5b087b35862b8d643db..a815fc5c4dd32e9b10844ad6df34f418c2e88ce7 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,149 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de return NULL; } +/* + * Test a 1M RST write that spans two adjecent RST items on disk and then + * delete a portion starting in the first item and spanning into the second + * item. This is similar to test_front_delete(), but spanning multiple items. + */ +static int test_front_delete_prev_item(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 logical2 = SZ_2M; + u64 len = SZ_1M; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + bioc->map_type = map_type; + bioc->size = len; + + /* insert RAID extent 1. */ + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical2; + /* Insert RAID extent 2, directly adjacent to it. */ + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical2 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical1 + SZ_512K, SZ_1M); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1 + SZ_512K, (u64)SZ_1M); + goto out; + } + + /* Verify item 1 is truncated to 512K. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len, map_type, 0, + &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", logical1, + logical1 + len); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_512K) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_512K, len); + ret = -EINVAL; + goto out; + } + + /* Verify item 2's start is moved by 512K. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical2 + SZ_512K, &len, + map_type, 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical2 + SZ_512K, logical2 + len); + goto out; + } + + if (io_stripe.physical != logical2 + SZ_512K) { + test_err("invalid physical address, expected %llu got %llu", + logical2 + SZ_512K, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_512K) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_512K, len); + ret = -EINVAL; + goto out; + } + + /* Verify there's a hole at [1M+512K, 2M+512K] */ + len = SZ_1M; + ret = btrfs_get_raid_extent_offset(fs_info, logical1 + SZ_512K, &len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID [%llu, %llu] succeeded, should fail", + logical1 + SZ_512K, logical1 + SZ_512K + len); + goto out; + } + + /* Clean up after us. */ + ret = btrfs_delete_raid_extent(trans, logical1, SZ_512K); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(trans, logical2 + SZ_512K, SZ_512K); + +out: + btrfs_put_bioc(bioc); + return ret; +} + /* * Test a 64K RST write on a 2 disk RAID1 at a logical address of 1M and then * delete the 1st 32K, making the new start address 1M+32K. @@ -468,6 +611,7 @@ static const test_func_t tests[] = { test_create_update_delete, test_tail_delete, test_front_delete, + test_front_delete_prev_item, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Tue Jan 7 12:47: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: 13928858 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 E11781EB9F9; Tue, 7 Jan 2025 12:48:00 +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=1736254084; cv=none; b=bMOe1Dr+eFC1YHelrg01MW5zadB+T5sArd1pg2dMloOD4Zd3jPsl8JMTyut8gx/YEll5++m0/9hjm3t+s/YzfLQN3EtqEdT99z8yGOYXrjzsyIa7STMmgGjGmxSlY04SYgQFdri7nxJxHPeono51T0taFflaWv0MFC9gFr0Kb3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254084; c=relaxed/simple; bh=7fuPeZ6eTkkUO02ONgT8YE81H5pgw5MM/PhBKMB8iwM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k7Bn3cfD2ITueR8VGk7+R83UUMzsUH5CT42WH12VCOYVT0zmF1Cp/oVlqCwjDPB2axz71wbg/ICGh1KPItBSEeglJk9xSDrmzIuM0cs/pIf3BICT+OQVK3e9u7CwP6f2fQS544WSY9olC1iUHcygYoYbX545FrbuxABKuHMlNKI= 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-4361f65ca01so153875625e9.1; Tue, 07 Jan 2025 04:48:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254079; x=1736858879; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g3PSh0B2ZMCmXCLngvICZw3M5+xhN20esGOtQ6jcvP4=; b=bm/wckDyHDbE/SkD456plGCNCOWOJwuoHCXlgYFpmLmkbTFr9L58eR8Y7r6eTNzmwR 5QG3OgOQGd3Zd5cYjWBDuzk4MFQZ+sZkoZuV1BiBjrX93ZcH0QI9h2iycaxqMlkiCJVx kF0tRJ7VaHsTNG25/0gHuTHIb5rN521gSCbNczMpoPLKd+Ha0t5w+UjW7zy7qYoKuFJ7 IaNWpfGRawRNAlogG3nv04GC9xqJjoUgT6IQEix/+QGndMh1hlTsrOi6SlUzFYERN87+ F+lRi7gKDWqytesVroKNuvPuvOmq24/kblX9NY95GtdP7weH9TBDAECsBS6f7mGm95Rr l4LA== X-Forwarded-Encrypted: i=1; AJvYcCW+NDCYXU8XWzJpjhNLy8Poneq8qMwEMCJ7Q0TWrZ94X4qUZTBz5+UlWYIL1j56Xk8gHBf2671pW/fJN9w=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8XCARLlFmiNP5TPu/x22PBguEZNqlV1rNwNLPhmUclihFGJyc FFm6hVIa8qGvf8A3CFCU3Q8EixyCqf0nOOhSvPfqD20+hTvqsOGgrLLJ3A== X-Gm-Gg: ASbGncs0VUhptQESJgiINPTTIGE5c7mL/OPNlkrhU8ZsrBapv/GxtNlqMU3sNrNUyEV ys068Oi7CmA1xTBhZljCXEUDpjFiVJOKQJoCPQiFdyiQhbHG0PpZlnX2Xz7NWL1N0B2Ix0fsX80 dhMl8kYoPCOy9/myvpVnfBL7OqaN+3rcGk203glCMFd0gDHZEyjRXkxpfXuoNT5tyLHBHJGgkHV e9Q0N6Oxiu0wh3MrtCynLPiYlENa8Oh9pqXQN1a0Lk4/XD2/bhFrmtXJ293yjtZ0+mHt5Tt6iiK u4RqeiwsEbYN7z1XUe0WUJUdxiztVgDIgNpY X-Google-Smtp-Source: AGHT+IEibbKn9hcgmS1QMfr2XH3bhFZ5hAEFO6m0eanFwsoqIxybOxoK7gS5p5sQlsqzB6jIa5AkPw== X-Received: by 2002:a05:600c:a0a:b0:434:fe62:28c1 with SMTP id 5b1f17b1804b1-43668645ffdmr568238375e9.18.1736254078686; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:58 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:42 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-12-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5069; i=jth@kernel.org; h=from:subject:message-id; bh=EVHDj16oSZY+6HbUp0NyPkXxXTNMaQAqUAlZnYdPi9g=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhXNOhCxV9u92OvQIm2Dgi07dGZvMD6X++GznqX68 mczpfmOd5SyMIhxMciKKbIcD7XdL2F6hH3KoddmMHNYmUCGMHBxCsBEcnYw/PdWOS3ExS0TLfUh V/u22Pc5klsk7tZHuxxOfLlz03uOlEhGhibWRde/zwrfF9TulMaqedtTtElukt+xryo2Qqeztkr zsAAA 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 a815fc5c4dd32e9b10844ad6df34f418c2e88ce7..c7e44e944f5ecc37ffb937237cb81fefbafbaf9a 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,145 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de return NULL; } +/* Test punching a hole into a single RAID stripe-extent. */ +static int test_punch_hole(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 hole_start = logical1 + SZ_32K; + u64 hole_len = SZ_64K; + u64 logical2 = hole_start + hole_len; + u64 len = SZ_1M; + u64 len1 = SZ_32K; + u64 len2 = len - len1 - hole_len; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + bioc->map_type = map_type; + bioc->size = len; + + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len, map_type, 0, + &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", logical1, + logical1 + len); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_1M) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_1M, len); + ret = -EINVAL; + goto out; + } + + ret = btrfs_delete_raid_extent(trans, hole_start, hole_len); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + hole_start, hole_start + hole_len); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len1, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu, got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len1 != SZ_32K) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_32K, len1); + ret = -EINVAL; + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical2, &len2, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", logical2, + logical2 + len2); + goto out; + } + + if (io_stripe.physical != logical2) { + test_err("invalid physical address, expected %llu, got %llu", + logical2, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len2 != len - len1 - hole_len) { + test_err("invalid length, expected %llu, got %llu", + len - len1 - hole_len, len2); + ret = -EINVAL; + goto out; + } + + /* Check for the absence of the hole. */ + ret = btrfs_get_raid_extent_offset(fs_info, hole_start, &hole_len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + ret = -EINVAL; + test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", + hole_start, hole_start + SZ_64K); + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical1, len1); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(trans, logical2, len2); +out: + btrfs_put_bioc(bioc); + return ret; +} + /* * Test a 1M RST write that spans two adjecent RST items on disk and then * delete a portion starting in the first item and spanning into the second @@ -612,6 +751,7 @@ static const test_func_t tests[] = { test_tail_delete, test_front_delete, test_front_delete_prev_item, + test_punch_hole, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Tue Jan 7 12:47: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: 13928859 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.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 A22AE1F2C58; Tue, 7 Jan 2025 12:48:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254085; cv=none; b=SeiCYPcPDX8bnBhBiWoYFRCoLpXkoChJb+Wpy0MTNIMonAYs3p3zn/hhGrQ2QM4J1JitGj5TYpHYY6dreY34gCSdwDmFdKZrirJdZLNMlpHlNli2KN9El5p3Vaqq4N+/kpnDI/N0urKVAUKNavJ1e8KCdcPOFzdMQQF9ZDZVEvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254085; c=relaxed/simple; bh=1AB4jwcI+lHYlYRcQqkQHVIt8MBO3ki9zuAxI9V49EE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S4CX/iP43VuApK50ZV+lXHKBXy0quKLaFO3o5CqxW1ng54IGnELdseTim8gS0TRsAe+XL63SzQimZWD3jpI6mgXwu5Yn+AyFi2uJ7E0ohsjn65pFemRncEEhvxJpO1xOttddk5qoIi9yMML4QiVpo1GPh985Yi43HFxSE7XF7jE= 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.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-wr1-f47.google.com with SMTP id ffacd0b85a97d-386329da1d9so7208948f8f.1; Tue, 07 Jan 2025 04:48:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254080; x=1736858880; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C5zvsivh78DDNjeh2ZcSnXDI0hKH6mj4dodObFPkjBY=; b=aXZdNtK+BZ5MScjflImVcIgXr0wG7u3elg6bd4+ozcHBfSPaRd2f7BdgtclGbRbgyZ 4rd9QbHuO23Gyn99fsE9TfuxR4sZtJqSd9OfkZFQ/I4wi7Nkfa2PKKzU6El63fdP+JoI f4iUw8JfgygEeaZgp4Od7uNVKETI5cjgQ6VOPXe+MJHcW3u0+62r9eaCCxsTB4s5yTS+ BvKpvjGYauSeylUq0eo3x6kA9gjQkhoAI7NYgo6YYb0UAkNoJ6klCsN8/DHGl9N1sEVH ZtXhRlOvwq4AzLKF3SJB2m7reeZp8PheQg9XucHWHlWHPw+r6p8mE6vSo2bJgITGoPtQ VOlQ== X-Forwarded-Encrypted: i=1; AJvYcCVrv6gsyu09kXASjPRXXzNjpOLZuX9j8VFg17QGlhcZuC3x+SpMh9zEyLUWiwFKt2FHJjWdMs6gLD7wocs=@vger.kernel.org X-Gm-Message-State: AOJu0YxdeS35inPUzwELcmAx3t2Ra8pWoO9Id2VI+st78uFhQVOZ6hCg TIaZVdoLl51eFwrQgJwKoIjn3YEs1UqvynPYuW5B592zOkITwrIP8ns9BA== X-Gm-Gg: ASbGnctaElXbt/OmJOdXzIsJb+lKHkU3SiOm0mN5612ga6Jmh7hr0WAg9DEzs/nVViX xpjeIapoDrRX1G//Qnt8nivtBSNQVWGZcuAk4Vj866/oEKSMjQ8DicPgiAvDR8umv4siwYreRmT DnuqVp8W7WhmOjpIvH8qGU5yNBQ52ukrgRhopagSwFQr53TViAtN484c97kBi1pZFyQU/PAXp1A tgiHGgybanRLiFWCcbjotfGsxhl/vNsnG6U+9ygEJ9s3K2MFR9XFcAZmd1Mg8SsPBufuZi7zGtz 8yZiYkUuxkHP2sNEfXbldNqrjQcs+XfTvVMw X-Google-Smtp-Source: AGHT+IGnxS0+auQ6sGjRktG+CrQnSJpucjwpxDOsKOlNT0eAt7DrP4JZnKcly9Zk0jhrY2VD60V37w== X-Received: by 2002:a5d:648a:0:b0:386:36e7:f44f with SMTP id ffacd0b85a97d-38a221fb038mr42569704f8f.18.1736254079728; Tue, 07 Jan 2025 04:47: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-4366127c508sm596884845e9.33.2025.01.07.04.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:47:59 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:43 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-13-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6236; i=jth@kernel.org; h=from:subject:message-id; bh=ZR4+z/8IzbGtRFmu+ycYbFa6RrLQUuwbhqkmEim1rB0=; b=kA0DAAoW0p7yIq+KHe4ByyZiAGd9InLIsOyT09fQfCJvS6/Fm6nct6I3Zlmgr0fVZmgbumEif 4h1BAAWCgAdFiEEx1U9vxg1xAeUwus20p7yIq+KHe4FAmd9InIACgkQ0p7yIq+KHe7DzgEA0Bss OFqEeAKwQCVFxVjfOH5FRnSUQCTiOaaVz/CQe80BAL+ULXogwG1g+sQ8tZbO4p9SPWT6ywP2KMb YmYl6/icF X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Test creating a range of three RAID stripe-extents and then punch a hole in the middle, deleting all of the middle extents and partially deleting the "book ends". Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 183 ++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index c7e44e944f5ecc37ffb937237cb81fefbafbaf9a..e12b6abbfd2be66170d33ab13b1e0971444c0f9a 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,188 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de return NULL; } +/* + * Test creating a range of three extents and then punch a hole in the middle, + * deleting all of the middle extents and partially deleting the "book ends" + */ +static int test_punch_hole_3extents(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 len1 = SZ_1M; + u64 logical2 = logical1 + len1; + u64 len2 = SZ_1M; + u64 logical3 = logical2 + len2; + u64 len3 = SZ_1M; + u64 hole_start = logical1 + SZ_256K; + u64 hole_len = SZ_2M; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + + /* Prepare for the test, 1st create 3 x 1M extents. */ + bioc->map_type = map_type; + bioc->size = len1; + + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical2; + bioc->size = len2; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical2 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical3; + bioc->size = len3; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical3 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + /* + * Delete a range starting at logical1 + 256K and 2M in length. Extent + * 1 is truncated to 256k length, extent 2 is completely dropped and + * extent 3 is moved 256K to the right. + */ + ret = btrfs_delete_raid_extent(trans, hole_start, hole_len); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + hole_start, hole_start + hole_len); + goto out; + } + + /* Get the first extent and check its size. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len1, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu, got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len1 != SZ_256K) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_256K, len1); + ret = -EINVAL; + goto out; + } + + /* Get the second extent and check it's absent. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical2, &len2, map_type, + 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] succeeded should fail", + logical2, logical2 + len2); + ret = -EINVAL; + goto out; + } + + /* Get the third extent and check its size. */ + logical3 += SZ_256K; + ret = btrfs_get_raid_extent_offset(fs_info, logical3, &len3, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical3, logical3 + len3); + goto out; + } + + if (io_stripe.physical != logical3) { + test_err("invalid physical address, expected %llu, got %llu", + logical3 + SZ_256K, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len3 != SZ_1M - SZ_256K) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_1M - SZ_256K, len3); + ret = -EINVAL; + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical1, len1); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical3, len3); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1, logical1 + len1); + goto out; + } + +out: + btrfs_put_bioc(bioc); + return ret; +} + /* Test punching a hole into a single RAID stripe-extent. */ static int test_punch_hole(struct btrfs_trans_handle *trans) { @@ -752,6 +934,7 @@ static const test_func_t tests[] = { test_front_delete, test_front_delete_prev_item, test_punch_hole, + test_punch_hole_3extents, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Tue Jan 7 12:47: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: 13928860 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D4663B1A2; Tue, 7 Jan 2025 12:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254086; cv=none; b=sZK/ZsZ9IUHhGBPh3/ijz8tve0lBEtikfgSyLJC0ypdH8Wb16NErmStH46FQkrx5CUPbvXepidD6LOCWyGI6PWjTWu9BbjidfjEp7kHdJUCXSXJ27frRjeQ7JqeTUMRCc/PBeGu1TqZFWrXB9Nyt0Lz6AWu0ssBv/wA9Ux6h5Bs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736254086; c=relaxed/simple; bh=O6xA0U6e8EcrdV9gBkOcBpJ1iaQ0NLLesxhyKpoD70U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DWS5o0VnYxmyL7GTpblcW3zNe1/MNZlW68ZPOo5rdlcjNtosLZ7m6E1n09oD9zM9O76gsjtVQfXDLONjZsB3CyaFZeHVAhOxS7Z5T6KqLBtN7G1Cfc2iTqaffQE8S8KFB+ukM8cLx3zhe+4GDVdelgDEDNegOzhUoFWBmPQBsbM= 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.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43626213fffso95831995e9.1; Tue, 07 Jan 2025 04:48:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254081; x=1736858881; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9VjMqnnPdmmXdxnSjbPvoY1ry5RF8O2XMIoYq3Ycrjc=; b=mIXpY/89rKlVtV2fLHeSe/Zcp8itPIfbLkDJZwZaYmDCqtHmgPiBf+6yTKBZOZw3Ls xU0XYEeb3NPPI7fjWmmt03NLixgQjTM/og3n3FnpnuqyEuHsjp3r5vIx8yyVSEe/R0mw HdZ8j+WBN2HAFw+ei3nJT3gKWzlD+vaztvzkE3u07rdBk+HD2gCgC/XyugD+9ixbQzZr cYKFSS9zyodWxbgrTjCGTBT0kBy/kVQ8HP6AmGGyDKcnklBQbTBqGQiOQxH8qHUzwMzR 7Eigv03OJSqIOtkxNtGNQHzWNuxqh1fZ//p0SfrP4PVB0feuRWWAG4K1LLtEdRzZFusE gPaA== X-Forwarded-Encrypted: i=1; AJvYcCXkHqyke6SQjpJbs1qmWAByLMU9KVQRu3YQfwjWHU+O/Gje8Wcd6qKrjWUbCtz9POz2ZDDVnyK9Ar5/kdE=@vger.kernel.org X-Gm-Message-State: AOJu0YyZHZ5eEqAVQi7nD4Zir8nncGTkxNt3A9oCE5Q4IiE2RQD9VpY8 y5di/S/Irc499bW3FXAJV+jCbyIY7uwDVi9FqT/kYrhTAgU8eQPYkR0/1Q== X-Gm-Gg: ASbGnctR15aAehsBePRaYNe3RUmNpLFGoKT0C/UAekNWgyHLg/J75ACUiQ1ew2eIlJu ujt5CtjuoNYL0MzvQT/udaEpZSINvfNwtSJxKK8zO17Gh3Vg3WAyYCkjoobLT877hpaze/klXjv rtenYhaNhvdt4sBzWh2NroZQNHJ+lBrgBveV71AG22gJ1oXWySzZruygaWE8gD2Yw2MB8pLxVbj WF1GitIiQ4lhsnE71XUbt+oO75yh8lf0GHSvgNTRMQDkUEBkcnaNKJE8lHQ7xY61ZBzb46A2Kof +2+dmLWhTtLZR8TmE9ud9/ssuDfEJ8zM0MM4 X-Google-Smtp-Source: AGHT+IFFzkQfEutSaulWgleGeMdH07LAqYJkY4OqPNG733r16FrxfeBQW7cw+kks76sIu0BKQhFUPA== X-Received: by 2002:a7b:c8da:0:b0:436:51ff:25de with SMTP id 5b1f17b1804b1-436dc1c7f41mr25500305e9.7.1736254080618; Tue, 07 Jan 2025 04:48:00 -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-4366127c508sm596884845e9.33.2025.01.07.04.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:48:00 -0800 (PST) From: Johannes Thumshirn Date: Tue, 07 Jan 2025 13:47:44 +0100 Subject: [PATCH v2 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: <20250107-rst-delete-fixes-v2-14-0c7b14c0aac2@kernel.org> References: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> In-Reply-To: <20250107-rst-delete-fixes-v2-0-0c7b14c0aac2@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4970; i=jth@kernel.org; h=from:subject:message-id; bh=tFlMhQskj89bb4c6eNa63cULusVqX4eFepmYM+2AqgU=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaTXKhVNli8Wdvuy/KLw89o/O3ccvt1yNpexNkjFfEn8q atMR24Zd5SyMIhxMciKKbIcD7XdL2F6hH3KoddmMHNYmUCGMHBxCsBELFwY/sftzb+tOf3MgZPl j+arvgk9lvXUff6GMv2ErYvkZJ8LaB9hZOjyS98j/mBx5tyirBOcmbr+9hsL0mXSc1kErkz4suW XDx8A X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Add a selftest creating three extents and then deleting two out of the three extents. Signed-off-by: Johannes Thumshirn Reviewed-by: Filipe Manana --- fs/btrfs/tests/raid-stripe-tree-tests.c | 144 ++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index e12b6abbfd2be66170d33ab13b1e0971444c0f9a..6c7e561e55641472a63bb15c8c2213273111ad08 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -213,6 +213,149 @@ static int test_punch_hole_3extents(struct btrfs_trans_handle *trans) return ret; } +static int test_delete_two_extents(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 len1 = SZ_1M; + u64 logical2 = logical1 + len1; + u64 len2 = SZ_1M; + u64 logical3 = logical2 + len2; + u64 len3 = SZ_1M; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + + /* Prepare for the test, 1st create 3 x 1M extents. */ + bioc->map_type = map_type; + bioc->size = len1; + + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical2; + bioc->size = len2; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical2 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical3; + bioc->size = len3; + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical3 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + /* + * Delete a range starting at logical1 and 2M in length. Extents 1 + * and 2 are dropped and extent 3 is kept as is. + */ + ret = btrfs_delete_raid_extent(trans, logical1, len1 + len2); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1, logical1 + len1 + len2); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len1, map_type, + 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] suceeded, should fail\n", + logical1, len1); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical2, &len2, map_type, + 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] suceeded, should fail\n", + logical2, len2); + goto out; + } + + ret = btrfs_get_raid_extent_offset(fs_info, logical3, &len3, map_type, + 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed\n", + logical3, len3); + goto out; + } + + if (io_stripe.physical != logical3) { + test_err("invalid physical address, expected %llu, got %llu", + logical3, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len3 != SZ_1M) { + test_err("invalid stripe length, expected %llu, got %llu", + (u64)SZ_1M, len3); + ret = -EINVAL; + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical3, len3); +out: + btrfs_put_bioc(bioc); + return ret; +} + /* Test punching a hole into a single RAID stripe-extent. */ static int test_punch_hole(struct btrfs_trans_handle *trans) { @@ -935,6 +1078,7 @@ static const test_func_t tests[] = { test_front_delete_prev_item, test_punch_hole, test_punch_hole_3extents, + test_delete_two_extents, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize)