From patchwork Thu Dec 12 07:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904778 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC06620B21F for ; Thu, 12 Dec 2024 07:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990159; cv=none; b=ZUpODmZlGFlSMEceRPT5RKEf9guhWCN+pliCRojH1RUNjLLiSn6bf1WRkJZ5ON6VmWvmvrTkHxOZWR83jRmb++fZjH4o4hl/fZb/dAdHiLR8TYvas28XdXAC1mMwpo5zxHsoGC6WqjN1k3CMSfftMOHvXtgHOqd6A8dpeVKQIZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990159; c=relaxed/simple; bh=Y0HwGaYxizeZk8pd8C2hoMrkuworcNKQt7v60O8OuCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=azifo/hYb0j0/9R+GrMxmYQUNH19YWBUNuHo2JXH1iCzHaCg4PXQRfKFln942lA/GMxowFbyqvtj2EooQFnDYIXeCCAHFnDE0TBM4ErqXMpciBw6ZuIQb09NUsyIumyFCpQIkIVVjeAfWs+aszdrBRYP3fFZHrMtuEz0wnR2Wsc= 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.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5d27243ba8bso500602a12.2 for ; Wed, 11 Dec 2024 23:55:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990156; x=1734594956; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pEfrWvEsqPw0eIeXgAQG+diIzmvxZsaH8mP9t5XgUCY=; b=vM/WaWu2ChVuXX/kY7G1EsRjMs3Pr15oq9k2jUuC0QBlOKsKPfS7VCVhE4cB+EIMBP s2CktHlgOu/rkf3IErqAVOu2jJVsy5IUBdE5f6acxbsOTvWJ8jr3h6ByKhWq7ER+nYWd AcnV4sdSi6LquEBtWwODdZuqHyzO99sna0AEygghy409o44ImsQY82kXrd3uKskSIZx0 hsYgqRAmxIBb7qCyW5kbXfjAc0VUZ6WQJNUtDSq9maokJjhq/RZotnr45/p0fec+JxKF zAAK2j2EydY0/cwltXicS+XuawzEPwZv3EaJqiJD3l27JGccRTgw1uaNtDDvmuSOt+w0 Xl0w== X-Gm-Message-State: AOJu0YzDMu9St4q0em6GQ3s9YnVLkSRs97CGWmsBBI2n5yFW6Kkf+ElA ztMbllXYxn3qoqqrw7SGD5/54nEdNNm5BFpgQ6WxqgiCywojpq6zkoH0rowo X-Gm-Gg: ASbGncsMptQzJOa68832Tw2aSI8vih3nG9C/c5OVIfZuy7u/Vy6V9+Qh7M/tthxfR21 rlJL1il6NW94+1YYaNce6Rlv+oJIJphPTPxpOmPKy3UD+s9OK80SYrToEtXL9WfmQbPc/wpRDSn endsz7tvnjlt828w17ykGCTMSO+hLvPWl8JTnjiQ79344JyCIsiu7BCrEDyUkoNOM5zae8pJr2k 8TAjgPK+UMlNav+n2ZLk8l0A99gTbMTCCbV/S6QQP1sY6uRTjpD/TLp1hqcBtblnrQGBcg53sqV k5eeW6YHrJjIdmfcG5xnD/qDjjUSUt6NdY/rX/g= X-Google-Smtp-Source: AGHT+IGXJxltW3v3xVSx2U2QPKanuqpnzCw4z/K14Fed5mmUGYN02Ft/Ch03zCluHGhykWXCbvfFHw== X-Received: by 2002:a17:907:7617:b0:aa6:8211:ff85 with SMTP id a640c23a62f3a-aa6b1225c4fmr456706066b.35.1733990155902; Wed, 11 Dec 2024 23:55:55 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:55:55 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 01/14] btrfs: don't try to delete RAID stripe-extents if we don't need to Date: Thu, 12 Dec 2024 08:55:20 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn Don't try to delete RAID stripe-extents if we don't need to. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 13 ++++++++++++- fs/btrfs/tests/raid-stripe-tree-tests.c | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 9ffc79f250fb..2c4ee5a9449a 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -59,9 +59,20 @@ 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); + 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 30f17eb7b6a8..f060c04c7f76 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 Thu Dec 12 07:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904779 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFE962010F2 for ; Thu, 12 Dec 2024 07:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990160; cv=none; b=dVoXU8gS8890UrhhFZ3DGc4W9Hgy+ZeSaiLtkbxo8FLvrK1KzWV6BXxfP1L74xHX4s7av/EI4Vc820gKYpbs2Pb6fBjsBWG5cxRn17OOsqKGW73+iELuzZsUwTOOF19gKQR8ShFgGiuEhx3kqVmRxmbiMHyh6l+R4pI4QPvQb3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990160; c=relaxed/simple; bh=OCaXa0NzEIm6ZCKngS0pAtWSnax0jtvF50XJF0y+/2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nSaH4zV/V9F2g0dPmxGKkE6nvuK3av/Pd929yavjXj+IV5Ggi7ZAZgD2zeMjQXk/HS43CqhoKt+BY+45t/ZPCmeRjiX1bbYZ2BzdbVGw3bH9SKdFVBgu3cz/DyUnW8O+MgbN1bjNAl8boyKpU5gznbEhhVu8qj89djRbiI1QZ0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aa689a37dd4so49100466b.3 for ; Wed, 11 Dec 2024 23:55:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990157; x=1734594957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A27WXwlr+NKMxDnhWBcMq6poAJO8ZvIuq9iuqLy5Wv4=; b=JpXze8eyMDkXQmJNWObADoIENqZ29SwnUYrpIXVRerzzSyaXNAio4zE1FJ7koihUZz Ef6SNbIfPpDpC3WpRcXjz0WU/2Gg/7pOU6qDT8pyXlspq+8rws8HDqZSz0rq+3YfnK8f E1pUzI18H6Dn+WOy+wy6JTvhlMtQlzC9YlJeJoiZVtH+HDZfmOoxOjo1WgKhoHOJ3z20 dqDIFfiCepOZNIcDzi2n5PTFNebFOsSDUdDPbDcEroaHfBf5YsJ4fCxdbs/nNxwluLuW tKXb9XTkG8VDYse7DF5u/r0M9y4IhQ9SmZaH7R8OuPRzt1uIt6R9ljh38IKjGtXABfBp ohrA== X-Gm-Message-State: AOJu0YxTvshlrhZilTwxLX1HwrEIhYAzG/44meF8PxNFwCwZVZnlWcI5 0dyzxBP/8W8vwXP3OvLBFVnm5V13uqGxOStrqjV3YDUEajvkos61F8t83oAb X-Gm-Gg: ASbGncuhb2HxFk003wZtZlBt7y2V7/biMFg+0oKVQdAbw54VJGJDmz/O9Pe6J1KDs/Q njEka1twnyp8+Cga2odznStlwG9PtTpSCcNtL9zauI09LgGnTTR9880kzGQoyQ6UPtxbXLk922L YHtNxHwH5VxPgi+/FxdSqspUoStbxu+/rTwwoGQUIGIfe9rY2T4oetS6HvP254Wdpv39UrBnfUd 4j5qrmLc44GNCCaOEJLuJlsjxoao9nD/IGp/oa0G04SxlRyw5mqoWQG8EzzU11+KUWAasKUvxeA 2hlvnP8WURxjj9yHo7F7Ckkhgt2DzCdDCkfC8CE= X-Google-Smtp-Source: AGHT+IHzKsHW8gN2myRt/SqPPrjJFWtSF6NXzUO9+kpJbKwPYEkTAbDq1iAc+QpVr2Y2X6OvQ/UbHA== X-Received: by 2002:a17:906:319a:b0:a9e:b150:a99d with SMTP id a640c23a62f3a-aa6b10f521fmr517639266b.5.1733990156865; Wed, 11 Dec 2024 23:55:56 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:55:56 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 02/14] btrfs: assert RAID stripe-extent length is always greater than 0 Date: Thu, 12 Dec 2024 08:55:21 +0100 Message-ID: <83cba5c8af717d24462ff9d9490dd0849d604f64.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 2c4ee5a9449a..d341fc2a8a4f 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -28,6 +28,7 @@ static void btrfs_partially_delete_raid_extent(struct btrfs_trans_handle *trans, .offset = newlen, }; + ASSERT(newlen > 0); ASSERT(oldkey->type == BTRFS_RAID_STRIPE_KEY); leaf = path->nodes[0]; From patchwork Thu Dec 12 07:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904780 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBBAC20B7FF for ; Thu, 12 Dec 2024 07:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990161; cv=none; b=XOhUsVnfH5UGCpNtcXVr9AjzSTUZ3VIDNVKSgfmOyfQZeYRR08+j3Svc+b5pE5HrLhcMNefCVWa2dpQKusgsj6ithQXf6mAushCB9MifyuzQin+JMEG7cP6IK8+M7AvWDZTmyapYeYGHd8+8gh44dyuzffBubdgxrjH6hcnGAa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990161; c=relaxed/simple; bh=QWLL0tgkDIWEyir+WW9TAMvbKy1a1CF2hSQstE0tTmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jlzZ/f3usIzlYGM/itzwniACF7NHe+9Mei13RUIPfMIfpHq+02XPnmjqnr7RIzcvmBV/LWjoZOu9RDTH6J0DUoPyqQLJ2LpU+LaRVMYqJgZjAnzSTlxS3Hg89rNuv2NNt7tzs4Lc8iEBgd0Py+mKNv2Qs/d1yBhgFdCM2PIH19U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-aa68b513abcso50339466b.0 for ; Wed, 11 Dec 2024 23:55:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990158; x=1734594958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s7s4BeQ713kByi2QeKLX91gwAxcwTp8lak+2I8QfqVA=; b=Dnz7PrIapXfGQeF61Vm6yJHNGnpE0Xc85fb6Mpm5mDCdessZLApCypNrddeAzEZhjg e/dELwat+HXrcZ+k6f7jrEr77amH7bhwI7twC4jhsudVPT5CNTdQYgbDPwldAvfVdGDg 2jBpLr5Q9hItgW6xrInoFmHRKUgJgeXhR4EJVB0NzG8fYkWdajz3vd6MNC4S+nbGNwvw 9IzAkeCxi/jwCr9eYtEfbEy88bY1ASJ0nHk7eJArVoeSNp/wu3k6pfcfW5e5mV4/id8I tVVkN43ZXaen0/VGc/BKTfmLCN4jgJNUyeO3gUCNokPqc9X7YEA7OW4zV9W2A3zIv+j0 Ogxg== X-Gm-Message-State: AOJu0Yw1QjCITjGHt8e/92giWRt5FaBgmA4kkRUoZPo7f9bVp3129BDV pvJjBj8vtYnpCoO64eXFzUqRv4RC+yx7FuTbSpSjfREW8bExZ6nVykBhPI1O X-Gm-Gg: ASbGncvOiT6Gj+IGYlR+0BLoWQA+dvpLjHl3LYiMlaYLNjcRoXvGjjSoq1upj8EB8iG tE0LfEZiHYXPBl/aA/XHAZmKHhjUDMUruXVjVx+43+YlU+oqE2emxorz+Leo2TcLR6lPWAcAt2t DvXFsVS81+FsHA/qr5JHut5ynpY2GroLi5zChKtZ91+hmFP2j5HKcXsdZFNa5PWXZRCVBcEM3/+ 8sE+DY8Nv+Z1Wjr+6zsJGYIud503BoEXxyVK/Y1t+LONb0pgyjTCJN6h5JMEz00SpRnwTLfQ7PD iU2HrULJkC0jxsxF4bJnVF8K1Kt2u2UuM7UnVpU= X-Google-Smtp-Source: AGHT+IG8bVlyXCmSszUWIqWNqz8lPveWNwulqzFUTY80i4ea6reIH28Au0pJvtRj+pcEeZBkqFErCw== X-Received: by 2002:a17:906:7307:b0:aa6:32f9:d1a7 with SMTP id a640c23a62f3a-aa6c1cf1b1fmr399136466b.38.1733990157806; Wed, 11 Dec 2024 23:55:57 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:55:57 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 03/14] btrfs: fix search when deleting a RAID stripe-extent Date: Thu, 12 Dec 2024 08:55:22 +0100 Message-ID: <29bc20b873dca2bf2e44af4b13ffb85c28d7b3de.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn When searching for a RAID stripe-extent for deletion, use an offset of -1 to always get the "left" slot in the btree and correctly handle the slot selection. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index d341fc2a8a4f..d6f7d7d60e76 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -81,14 +81,18 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le while (1) { key.objectid = start; key.type = BTRFS_RAID_STRIPE_KEY; - key.offset = 0; + key.offset = (u64)-1; ret = btrfs_search_slot(trans, stripe_root, &key, path, -1, 1); 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 Thu Dec 12 07:55:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904781 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.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 997D720B81C for ; Thu, 12 Dec 2024 07:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990162; cv=none; b=js7MPmQB2HIY552oxgRFcX1gcsEEx0e5FfLNfDkgNfyaWt2Z3fxgWf4CGcCWfXxHTzC7ko6rqZ8tiC61hpgFezZCXlJK+qn5hftcWUZVqRx7j7uhdTs6actSoYLQ/mSwTeypEuPIgAFQR1npoEBT4DsnYYl0v58PbHCs4ceFpxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990162; c=relaxed/simple; bh=T80pbk3+9U6Eq7QYEC1OcK4IsfabXu2sE6gFAiEIB8Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d/t8W5wRUJEyDXtggFlynbncU99QLwC74lmcGWiE1RyeFwjYkRws6LaA8tRYlYonEru/quKcqnS1GJVwMgod7O7O9tiQTBQIe3/aHOv2cgA7/VbAHHovWpgg7cwQvGORIxuUvi4+GD+uPzqjWMjU81nff+9CZoiLvIT4+CjiAz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.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-ej1-f44.google.com with SMTP id a640c23a62f3a-aa5f1909d6fso44747966b.3 for ; Wed, 11 Dec 2024 23:56:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990159; x=1734594959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=696dQ0ZhIy+mpCg8XFG1c2cuF3ANJg5C50ThsK/CYrk=; b=l/RopM+WGbsJawLl/swA9Jazx/I8zEwpesj0rq4zB1R9xorCO+XIM3XMRCCVyfyT02 7XQSFjgbgOgSCYAeyGtV+xEoE5WD0Q6EoIlQEel+kfTg+az+HZiAw/EiNB5fjJWasHfB 4xhHtuINr1qXbfCtijQcu0dqRW1ZxSfkzNGDwG27/kqjR1QZA8TVy44pcIOsnHcS69jn hrNSqQG4ziAaoKq1IZbTzuU7szaNFqv0A+opKwvKlFdgjw9FrglwlDDLb9k5C5QSIC14 nUuCscQKWbC41sB8wJuSvDHVAdyXZUe6dA8x4Yc0dtRcFXgjw0g9J70neGq4rxkulJMG 3KRQ== X-Gm-Message-State: AOJu0YyYjXIKum486JdVpuWIigyJfsxmEeMPQUjK0ctV8l8EOKM4oodK 8mWAdu3cBzF8VVRBFM3KRHFo1PswvGmq6FYleu61JLwTA2gcQugJPBm1fP9m X-Gm-Gg: ASbGncsg/cT51X5uxUkPSoYi1oHbXwGeMvvT1fmSE8BXoy5P8gfGmL3qOVa8AcT1FBw uFxASnPoFNahPtFBJyBUS0r0pODgE4D+meEOVmwgYP9aN1m+IjD+BEgwj8IAVuqcIW7Drrufvy8 NiizIYId8gd5HE0+zih/FXek09zmztiErkLdmHVSgarME8O6f4DQ4ame3AGJ6D06TwzyU7573AY wcHeyiVpW8wu9JmHCnhkCcCUn1dEOuZ8KffbPMEILgQ0cu+wCsFvLHK1O0zybHvGFWY9nPMBZlM rDh5Qv4SH14xi8yROGwMYvkoCuuJkJkA815SCus= X-Google-Smtp-Source: AGHT+IHxk7GXihis0SQ6VM4ZL/j+Z36QseofYW+ktrc/2oL6h/AvuDsJUhn8xe3LALgD7/ei1MOUeg== X-Received: by 2002:a17:906:3111:b0:aa6:9b02:7fd0 with SMTP id a640c23a62f3a-aa6b0f4fa0fmr525362266b.0.1733990158726; Wed, 11 Dec 2024 23:55:58 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:55:58 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 04/14] btrfs: fix front delete range calculation for RAID stripe extents Date: Thu, 12 Dec 2024 08:55:23 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- fs/btrfs/raid-stripe-tree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index d6f7d7d60e76..092e24e1de32 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -138,10 +138,13 @@ 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); + length = 0; break; } From patchwork Thu Dec 12 07:55:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904782 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.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 79F0D20C005 for ; Thu, 12 Dec 2024 07:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990163; cv=none; b=UDgrUfLYK1VcpkkRtu5cyBBIvAk48SNLkdnpkJAPXP2U5XlsE3uM+IC7yBBaoHrZlCXj7byzWcX8S3yUHoHJXHlE+Zs/cZdQCqYY1Oi5PysQctb3gzwhCiWBJ9Jkaq/xevaOt8fyijE6p9TVR9saKdhpFfeTHzd8Ll6NaKqTpKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990163; c=relaxed/simple; bh=CbHgCjSTjEV1L+IQnWjT7hcGVbYX4lbV1ysAMVDYJS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TEa2onMFQcXZtTdxy0WcgBr+gZWknIDrUgFR2OzmXjTyd6Vu7Xk3vnNdV3+CJD5vJ9/aFHO9RimNnE5SHijGbm5HPNxVz+ObLQlNfRWa3Dvjbbm6p1UO8MXlmimO4uto6jkFsTIo3+Hc7+/g8zFedZgkrEEDMcir4lFueYNx2u8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.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-ej1-f49.google.com with SMTP id a640c23a62f3a-aa662795ca3so287544066b.1 for ; Wed, 11 Dec 2024 23:56:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990160; x=1734594960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1fKnwTDnFI/1sBQ+A4p7FY1EVfEWjujAuvSIFfiJIIA=; b=HKjUrs09W1xiL1pRfUdVmWwgLDfFBpYRfLY489+C+c/FOy4IB4kG6g3b3J5Zee9YBA UQxnxVUy4orp7/NN3oyMc+OCVd0Le7/aRiPDgXIXVyEpEHLAvgdaGpFmtXpICEQKq8YZ bihFdte7nKwUbuSFJQri54YvjyhczViEtxnu/OX+pmClb4POvzBn8kWjhfxns/KSNa5R swF733NWMHgfylec8Yj4pZowejOUK54M47YpIoNGGKjnR372spP7zksZCPi5BaKN/tIt 2KjHzGoKg87Du7lvOZNVm2sdel1G2Scc5AUXbZduJjb53vIhWRkJ288jHqhEpuldManR wiyg== X-Gm-Message-State: AOJu0YyXzWMD2lM4lF9cDK8/5sD5qwvB0wMB0PsOGh5GXUXsyCXblcLw SI/t+0t47/YUsnuDB0LeJZ3kb2IxSBELlS7xgblaiz2kIWvCHR4uYk9pucqP X-Gm-Gg: ASbGncsrr/TBTyWJiEgjetC4ayCOmW5deThAyhCjf++YaEZSCBbZ847XvoHCa9CxFE8 vNKIZxgk082elwaGoSta8Lf4m1j1G1QX6+CLNovujkheHrTOo6xRQRGLH3pf13+qUaYUbaLhjJN dP+ud0Thl2u3VncOWabl2xcA9o46KBTKW54LcpPL+/DMsyVMgl+J8EQaz9FYGTYpIN5t+TkeYJF kLlbZU9Eyv1dly4cu92LIV6b9skmHTPbSQri+hY9O96heK7/wkwggcSFA545VqcimzKW08XK1sV HOdhE8NVo7XjPZ8hqwwyAAjyYjVNAZHnnzVdSeM= X-Google-Smtp-Source: AGHT+IHOu/UF4F8CMTM6ehHDChk6+XqSoiVUQz+3Ukn20QUGsDsAS5XtYdTbBiMpnoOFcU9/YGAshA== X-Received: by 2002:a17:906:9c18:b0:aa6:54df:6abf with SMTP id a640c23a62f3a-aa6c4139005mr198838666b.18.1733990159698; Wed, 11 Dec 2024 23:55:59 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:55:59 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 05/14] btrfs: fix tail delete of RAID stripe-extents Date: Thu, 12 Dec 2024 08:55:24 +0100 Message-ID: <93790ce532e9e18fba57268a6230ec312ca38360.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 092e24e1de32..6246ab4c1a21 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -121,11 +121,18 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le * length to the new size and then re-insert the item. */ if (found_start < start) { - u64 diff = start - found_start; + u64 diff_start = start - found_start; btrfs_partially_delete_raid_extent(trans, path, &key, - diff, 0); - break; + diff_start, 0); + + start += (key.offset - diff_start); + length -= (key.offset - diff_start); + if (length == 0) + break; + + btrfs_release_path(path); + continue; } /* From patchwork Thu Dec 12 07:55:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904783 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A445420C01B for ; Thu, 12 Dec 2024 07:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990164; cv=none; b=IozFOvEXHq6PgRloVDSYbCTkQqrmnQQ06tXfTMABvlwsdCjC26QfeYcQt4q4FbrgMdWs+7KSnttHEJiZmeNbBmfVKVtokqer85Mz3R7TSHAye3sYB5WQZzDEKKm1EXtxfXMlJ9e59Pnvmtzu/rke7Y1IRTzdgPWpDX78RWtYKsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990164; c=relaxed/simple; bh=t24b2IIGQIho4XE2mnR390bfmaWPWPUYgA93KXVxWb0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fuw3ZDJHSNxb13DVZhA6/cfOG4Tw4RDeqhlMkkJz+EuqsPXpjxCnfdeIsZ0imILZOUcQebOTt0eUtYq8yDKqmCIrhl5e1keReaa1rgLvlMX5pxt3yNLyyVebzTF2QKd8L78cKro9zZeaw2In/RBZmFHkF1HUYtYhD3/5sAzwNk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aa696d3901bso50072466b.1 for ; Wed, 11 Dec 2024 23:56:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990161; x=1734594961; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A+hs0AA+wFdftCsQ9QhutGkhavg9W9yBT5CHlPrSZkI=; b=Ki3KPMir1nuPakyrsEcczZICI9EBl30TrTCb9sE3XgjveESKj8hN5f5gJ6tC5rs9YQ gqJkjWWnJwIR7djhvVqBGKfXj4F6mHOQo33YUxL30BgsNVTcrnww90AXBXYypGNGHAfC yhX366I9BrvNgiUohkOSjjs1tRcAhllCSWeik03KvcxZzJyd6TovmEN/9RN5ngnAdhVS dNN5zLgHZrfAMfhP5bcoGUaKKUoPIexvGoYnfIuZqLkKWqjwkZxn9MdHctu0p3tYo7Ag P31zArBa6JzdbGPV1VVApD/bQWC0rnP7M9yrouOI0YOByRvlJXD32nqaZURU5MYQ/T5X csDQ== X-Gm-Message-State: AOJu0YxN7a2gyUY3l5ctrSRbQ3DLuWTWfgwrjFQ3ellt0jmgBMFh+Ixo mbXUMCWxCM6MPxTcJ5A/japZcx97KalphfwqAXmoP5B8ncLGkRcIAAmCayIX X-Gm-Gg: ASbGncvzHvudCgi8hFYLvrB1if4E6l8tbP3gtcnCMbDLyrofma2kgVXe7/2rfwfx4ka epRq4fVC7vtYLgicazhkPKwj6q0ZmgICqIRT4cZRoZlvzkT+rIAyYoeb+sSfADNZp1zOd6qyIvx UfbPX+jZz93pyKNBV/5JCSeDygIU5meSn0MelG4wCW9miSLDxvBfAqcNWDusmbtqrX14nSrPmIu JlShcWihj3dtBc/9fWW8RRIdFU1S1vpRQMSvjOfXAi6JURNphOexTDLUF1IJJX5Zt1g99Uzq+aJ spBWfi8exaK18ps5J9aQWCKjx9xa69jthZYTXHY= X-Google-Smtp-Source: AGHT+IEYijW8gz5gX9vbZcXfwAKhaYrMaLhmqpkUEJy9zdZHPPxnuoZqi0sufcUKhVusAWW36rqtDA== X-Received: by 2002:a17:907:7808:b0:aa6:7c8e:8085 with SMTP id a640c23a62f3a-aa6c1b09cf5mr270266166b.15.1733990160702; Wed, 11 Dec 2024 23:56:00 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:00 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 06/14] btrfs: fix deletion of a range spanning parts two RAID stripe extents Date: Thu, 12 Dec 2024 08:55:25 +0100 Message-ID: <73a3c0f290dc84b8b802c8705503370d8cb62bc8.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 6246ab4c1a21..ccf455b30314 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -101,6 +101,33 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le found_end = found_start + key.offset; ret = 0; + /* + * The stripe extent starts before the range we want to delete, + * but the range spans more than one stripe extent: + * + * |--- RAID Stripe Extent ---||--- RAID Stripe Extent ---| + * |--- keep ---|--- drop ---| + * + * This means we have to get the previous item, truncate its + * length and then restart the search. + */ + if (found_start > start) { + if (slot == 0) + break; + + 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; @@ -155,6 +182,9 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le break; } + /* + * Finally we can delete the whole item, no more special cases. + */ ret = btrfs_del_item(trans, stripe_root, path); if (ret) break; From patchwork Thu Dec 12 07:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904784 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C01120B7E4 for ; Thu, 12 Dec 2024 07:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990165; cv=none; b=OOJDFdvca2oW0PKcUwJPd0VaAjwQDzQ0eojMm1uoqL4I/u2QCMQVxlRUYiMQ5rgFacC1WXsBqS7VxPJoEbOKOqH5XuutZsz5QiZBN+qqXi8uicHYgBGX5BNNnLQ/1TkorrLMkZqgTszCVsTUz3LNWTl1YwJaXdi7B1yKBCzTlFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990165; c=relaxed/simple; bh=FPGDS49td3ziVWZjlkQ2zVAgMkp4kA/i2ehvigPCw08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cgNl2wEuu8iZplbaZtiStMy3mGbI+VXjTLUCAAzok4xTEnqmv0fwIIReJk0oMsoeEeWwGIREpB10R7IWawWleRAhlSLtvvO56XKg93nEoViBZpOOg3vgvstotIwwM0s0wYC7tnBGuqY5rRVmgz+BEQgWZgp0Xi9HXUmaEleddoQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-aa1e6ecd353so40476766b.1 for ; Wed, 11 Dec 2024 23:56:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990162; x=1734594962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XErpM1vqE1dV6Fu8tSD8IkYMheM4WDtZLeIjdrqirXs=; b=a3RFSSxHZkZZlxdvM2LPhZTER1aGz80JctX2k7Pno7PW3VnnbafYgjHaf7g6i02vo7 GNZKxLTECWULbdcUqUaF0S/vP2izCPh+h9PKWxcqzzejc88VNZXzK6x+n9/q+B69DVsC RSPSZ7sejLQqXXBl0h/G9ZN8yqI2JGJykXP3PPsLiHkb/ndf2SJAHQoi7t/2tmwFgjp2 mD6/crJ6Mm255K1HmfNveekPHFBO7No+6Nf5D2YfVvy58K1EzDrxnThl28hFf1I05Htk ueRjR4H8oztR/VqlqhqH2t/61QtlY6VewODtdE+FUj7Ct1/cvdVKr+NojNF4wIhfWiQ0 eKKw== X-Gm-Message-State: AOJu0YwRY1dOe4t2FiiZ+2fy57NP/0uFGkvKTrQYHxIbfL41HolKOlp+ obNnv9IF37HLu35v5w28m96yqzNUxPorKFoudoo42yeb2hdBlqO6eJ3YI/Kx X-Gm-Gg: ASbGnctAGu9SeOXdoP062rF3ZoPVycydvK2fwqcu0xORbxyKKm+473au7E2v67l/kWo E6QDO31maS2ahdRqZkkNPPNiexLDTYezcTVNf7dgH6BWPIJ+kOk+nYk8leqgbF8EMpayMYqfIeK z8vH0WfLquMSFqSqqT2DEajBaHEnnhu7SpBFT2v7C6EZBqsZ2tHqe/kc84eGrwvO93irEPXwneY Qbu25oOqcZ3PGYT9wDVsoICZtUua83U+9n5SsKnniQd6uJ9D5CjG2JZA1BvyFMTesSbxezPKx/r sFPqYa5okwzzD/AYXDOQB3YPsAHWJlWiVMc96BA= X-Google-Smtp-Source: AGHT+IGl5IBEM2MToTCmg6zSlS/rZ0QXQR9HNDAZOT/se0ve/gEQzXkWlwZSNILB3PZNx38FfqXtwQ== X-Received: by 2002:a05:6402:5299:b0:5d0:fb56:3f with SMTP id 4fb4d7f45d1cf-5d4edccdea2mr263049a12.12.1733990161827; Wed, 11 Dec 2024 23:56:01 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:01 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 07/14] btrfs: implement hole punching for RAID stripe extents Date: Thu, 12 Dec 2024 08:55:26 +0100 Message-ID: <038e3971d12f2f8aef69a96c999916f37165f12b.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn If the stripe extent we want to delete starts before the range we want to delete and ends after the range we want to delete we're punching a hole in the stripe extent: |--- RAID Stripe Extent ---| | keep |--- drop ---| keep | This means we need to a) truncate the existing item and b) create a second item for the remaining range. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.c | 1 + fs/btrfs/raid-stripe-tree.c | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 693dc27ffb89..5682692b5ba5 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -3903,6 +3903,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 ccf455b30314..6ec72732c4ad 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -138,6 +138,60 @@ 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); + } + btrfs_mark_buffer_dirty(trans, leaf); + + /* "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); + length = 0; + break; + } + /* * The stripe extent starts before the range we want to delete: * From patchwork Thu Dec 12 07:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904785 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFABD20C475 for ; Thu, 12 Dec 2024 07:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990166; cv=none; b=qZW02X2JHv2cowlyDs+2pnfaIAlfMQX0DKC68XF1/Ej0UdgGaFU3XJx9xJITzhB7y3ACcc8ovMYRIKQ5SB2Qafa9qNWQUUnOCmCbDC/uo4Up0uQK9GNwuOAZ77MO/dxF3y9liqgGsrE3ayEoxBQE6mWH6qmdqhydnDhHYnVEFkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990166; c=relaxed/simple; bh=4QqCu13Uy5cHu+8lHHKkGF5lSxstAF4etbLQpPYmRw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vGeAzy1/B6k0DWN6I6fyM8EiKaOXOy5f6Up6aFfGEy5icLplDZuy5GKpjV3y9AQdR6EQDt0cfGWBQgqsniZlH1/zt/6/j4ogJ5fj787N3mWaWiOUzdwoHGp+5TaIUKdl9otgHTbStt6/4DiV6VfQKMqYjptQ4zYPcgH9vxiqYX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-aa662795ca3so287551066b.1 for ; Wed, 11 Dec 2024 23:56:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990163; x=1734594963; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z2oADBldU/duH3ovVq73sYfZwo8nJgfMtsDB3Avxygk=; b=FUb2/jCb1bXXc35f8yl7XY5ppFOA9mSnqsk1YPst4D74OvlThlLiklYTOzJPCipfU3 nV4vAdM/ILEmgEQ+G296/CDm7b2WUoVdCXIanWPAnZBmCCimTv13pQp3wPdGDfG8jvgS OrE18qjmyIa9qlAkYNQZvW7F/KJpIEtLpjBixUPuUMm/2rnOlRvCNXBIdP0S1JmFli4b vwYuVgpVIsA/grj1my7CnyHumPGk71fhBPhx12eig0OlGdQ+sFiVYjz8/kCneFMvcG0G 8D0sHfhK5nQdBiqarOtvP+6QHt9uOr6GObW1KyxaDGrkFFAvZpmg2Ry9/5GCLNxUiG2W 7jhg== X-Gm-Message-State: AOJu0YwWDLDhZbV3OBR2vdWtlR2u8qq55l6BVfE6eBUFNPG5xdvbOC/A Q/DK0bIW5lWG4Ehj2yGlnXJIZiMTTSdwE4UNXMFu+vzk2NiurISOZUYVGoSf X-Gm-Gg: ASbGncv8AfVE0JUh2ClUWBS8O0B4FM2cyRBZvkyJV1rn39+Yj4h2WdG7K+CNrs1a6Jf MgsTLz/G60b7N8T/TjZmuM0bvCi6u4xSRQ52oOeCwVO2omW3s2AlGM0hNfgUvyCfxE/RdYCeUN1 bqkCrztAdr1x4Hq+E6J20qyN0jCJ37qfWuCD5jmPG+cfHRVzHXPNZ/8ADBlgO4vcB2YyGDXFegA KddqF+1OJUmuq28E1HXJxCVD4FPqOQ1KJxhvfTvXYYROxVZImCJlLKD/8bliIpaEI7a3aYPP8hm RuWNE1hlCji48jFZdvvOPFteu/xgjGAPZahk9gs= X-Google-Smtp-Source: AGHT+IEDKPVkHPZ4ik8fz1UGuF1sq9O09O1nKpnLIuKHB0rqrsC1bjB50ETzWRnF2EpxZ4k19ETF2A== X-Received: by 2002:a17:906:9555:b0:aa6:50ee:d44c with SMTP id a640c23a62f3a-aa6c4131cdcmr180151266b.15.1733990162821; Wed, 11 Dec 2024 23:56:02 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:02 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 08/14] btrfs: don't use btrfs_set_item_key_safe on RAID stripe-extents Date: Thu, 12 Dec 2024 08:55:27 +0100 Message-ID: <1b225c76de3d41571e080a03d971a961de26d9bb.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 critical (device nvme1n1): slot 201 key (5679448064 230 32768) new key (5680439296 230 1028096) ------------[ cut here ]------------ kernel BUG at fs/btrfs/ctree.c:2672! 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 6ec72732c4ad..f713d8417681 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 Thu Dec 12 07:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904786 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AAF220C485 for ; Thu, 12 Dec 2024 07:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990166; cv=none; b=mxyMykHrrUsNxLIP9RizJQs9AZFrJ6Xess9a9Kj3GvcWV3xcNiLruYfMG+wuc7Zmv5LYJJSan/g2uZtoYpD0EtadPrnoYwMFJWb/WM6Isz0NXZwz61oJRBOx82sIBUl86OfjzE3syWyuANKj9/kqQP9mtHhUVqeSqTVJ2KERA6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990166; c=relaxed/simple; bh=DPCdWz0uEldY2rRUaGlSEV+v2xvBHaWjnQLAEL6VZGY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tg/+IE96+7m2h8s2ocGouvkVzQv64NooFx/hZZ3LLeuQWGVok9VNV1j3WeRxV/trw5nR8j4dZvRFY3pDp+vPO87Ui6PbIXO+stIwxyQn19ud2w8Qnr0+JpZ4C7f/E4x/HcyJfLTIM0NiZhREw2AiXDtj1lVSA+ANYJWZxBaG9/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-aa670ffe302so48525066b.2 for ; Wed, 11 Dec 2024 23:56:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990164; x=1734594964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eF15fnQ7O/HlXtS6eEPT/P4udZm/bAW5ml/GacSwR1E=; b=GQ9nOB3lnmJ0w/kmJGrfFIMHJ+hk1fAKRpXMfguyNksXbiJkUnSONkyICb0andXB6R 3LZKsbiMOMjFRvX277kjg01AzWwbYwM5Xm3kESrX/nWhhr852mr604fFk8jptg31ONUr KVZiyt6CJTtIStu27+ryhvKNhNs+VlV8bAMLOo98oPagIP7bS9z+XC+vYvVwVLeazz2s sgg/A8du5Dr778k6fi68/u2FhPBjNBW3RDISNEEs/DIcFd4+ACJSMgxzaw1mdCVDGmm3 MHdgtqXdIYbEtWimk/UqFBKDjRjU+lTORfSFwySjmt0BlJ0Z2ZDLVSjZgOIJVE9aMCA3 xmUg== X-Gm-Message-State: AOJu0YyeyJEu0RV4Q78/oyCzQQi4xM8VKJpKR3HisoXfotF34vhrVCgA bCFldWPXvRhSrqZq2lfxzQ4GyH3pvxIlQn186Df784kIbPh8txl20Z8LRjFi X-Gm-Gg: ASbGncvu8+sweDXz08h5tUhEF8nXcehQ6g4Xmy8AfhNU0YbZilZNhDtC6DUmxZ0diyK 0M33zYolQpz+V8rAKkQqQBwEYnRbAm+KqQqNcbbgkYKhNHIwQ47KeSdB0oVaSFjdSyQBC3tAJ8K qnuAOfUu+P5W2JzYNo8SHDywTciJojWqErZH1AOLsiINTf7XSln8m+TpOj57jwVPWEigxRcbgIO UjRwYQtEkDbgzsWIe1Hmuiww0pf9sgYFpe97NclcP7npdZ2OefgEoSurMFfbfvPIhnk4/AXerp2 mnskohTjCU+enq8nXtFC7YjO7W88WO6xRcybSOk= X-Google-Smtp-Source: AGHT+IH9rEYLvDEW8YJN/9BIJLLVlLn8rUtCaGB8rmE8YKGPZci8wk3IXru4A2su0JoL5UrBnm4syA== X-Received: by 2002:a17:906:318a:b0:aa6:7165:504c with SMTP id a640c23a62f3a-aa6c1cf0b1cmr262992566b.37.1733990163750; Wed, 11 Dec 2024 23:56:03 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:03 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 09/14] btrfs: selftests: check for correct return value of failed lookup Date: Thu, 12 Dec 2024 08:55:28 +0100 Message-ID: <001ec4d2336af581f1014c6a3ec96c24ba6e5dba.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 f060c04c7f76..19f6147a38a5 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -125,7 +125,7 @@ static int test_front_delete(struct btrfs_trans_handle *trans) } ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe); - if (!ret) { + if (ret != -ENODATA) { ret = -EINVAL; test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", logical, logical + SZ_32K); From patchwork Thu Dec 12 07:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904787 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 746D220CCE0 for ; Thu, 12 Dec 2024 07:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990169; cv=none; b=YIoyE736Czrzhn3eXIhzZNSdPRLJJ9b63bzT6CcY/fK5hgBDoyYKQkwVJaGnhJFqvIhlKLF3s3MczOkkmQWrq5skVR5S5JRjTGefmVNdjs1H8+XLlQAbyihtkT6x0y6In63/B5zT3Arz2v5ojn4LyBtKuzfIG/IDg5c3tEMRjjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990169; c=relaxed/simple; bh=dTPU98wO8+hhf6fsmIai0iqs6Yv7Lf4wrssXlwuQXTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f61V91Grb+OwCRskkGvuDhKWfnRLCn2plhKsb6Mert7dlKwfJrcIXS3JF6r36s0m5rckhzVP4Ipp0nhpK16HWZA8hsnZbJOR3khugtKODyp8ME/sSUMpaPiWnOMEp7DusDiPkcIX/fuxPkXLyLGaWXhiGbBzcuJpTplLjHYawsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.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-ej1-f41.google.com with SMTP id a640c23a62f3a-a9a68480164so39279566b.3 for ; Wed, 11 Dec 2024 23:56:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990165; x=1734594965; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4A2xgaq7wh417qcM0Z8T4Mev1gyoxlAEwwcir/r31RU=; b=P+eJkYrVCbV9h74QBD896Dz8z/7pIU5vX3TyPz/TeLnQvXHzaM3hmL1RDuPZ4WpEGE y4j5vEtwa5kBYfZUVZv7w00UeDtGO2ZvsXhGIIiRN+Zw/fYBnKoyHnX9eyqmgWXuVq4L AVwFLhfHdJ8RL1OGzb8T0H5L4hLgaqfbqkIW5OqbVE97r1KcwWGKmDzq8jVDeLSt2Vvy 2hdhmlUnHAr3hM4zgmkOLFPkvJtaVAsj/yydhc78QtgoPWDf/fi16dvQhHVnMp0+TMQR p71fNJOw35W1/xtN6gzakSRAP33TJps+SVZjSGDRP6xibiW0h7c5+AIYA1Ra3MoGvIm0 sXkA== X-Gm-Message-State: AOJu0Yw5vBh9AtG4++VQrUMkAwBRjgvoKib9zaWfokiePhCLZsYk8/jO tJqCFfKtX2Vyni0+2ZRRUKV0/HO/Zwb6CSn7jCaohiwhehXOgIFbW8qrfzGc X-Gm-Gg: ASbGncsUkEMSD+sS6dAaq2rKpLQ3h01Bbsjf6xFbEpLMgbGUUzkqqHipaS6DnjmHVEt hSLgbnJwjZ5QNQ+rZNwQtmwq0tLqNswXWwD/qaXM5FIoEGdKFCVSwP9cLlJZ9fvEXGyuQVghkbb LqGwcI9JVyenWVX7s968mpU1CmtWRzip7abKCkN+cLpUnNWNtiZOm5L3rA4VsH90aYWEu1ZpXOF e2pEA7nRz8G4fiMqK5T4aySyda7n/TCfBUvI9RSGTAA3vRdr6bixfNYZ8lXo/WALj66r07vw7oJ tvnti0elUuXEFjfkFd4pGH+DPktrwKI9a0/sq1I= X-Google-Smtp-Source: AGHT+IFqn2+PLv5RBXvnozsgg5REvM4zWKlxibZe1JohrVUHh/0uPhMRCEXSY5OYrgTmw2ppGc7XhA== X-Received: by 2002:a17:906:3118:b0:aa5:27d4:980a with SMTP id a640c23a62f3a-aa6c1d2ba9dmr258265766b.49.1733990164690; Wed, 11 Dec 2024 23:56:04 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:04 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 10/14] btrfs: selftests: don't split RAID extents in half Date: Thu, 12 Dec 2024 08:55:29 +0100 Message-ID: <9cabbac863682a0da549d04d37e785a11a9b51c0.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 19f6147a38a5..12f3dbb23a64 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -14,6 +14,8 @@ #define RST_TEST_NUM_DEVICES (2) #define RST_TEST_RAID1_TYPE (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1) +#define SZ_48K (SZ_32K + SZ_16K) + typedef int (*test_func_t)(struct btrfs_trans_handle *trans); static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_devices, @@ -94,32 +96,32 @@ static int test_front_delete(struct btrfs_trans_handle *trans) goto out; } - ret = btrfs_delete_raid_extent(trans, logical, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical, SZ_16K); if (ret) { test_err("deleting RAID extent [%llu, %llu] failed", logical, - logical + SZ_32K); + logical + SZ_16K); goto out; } - len = SZ_32K; - ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_32K, &len, + len -= SZ_16K; + ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_16K, &len, map_type, 0, &io_stripe); if (ret) { test_err("lookup of RAID extent [%llu, %llu] failed", - logical + SZ_32K, logical + SZ_32K + len); + logical + SZ_16K, logical + SZ_64K); goto out; } - if (io_stripe.physical != logical + SZ_32K) { + if (io_stripe.physical != logical + SZ_16K) { test_err("invalid physical address, expected %llu, got %llu", - logical + SZ_32K, io_stripe.physical); + logical + SZ_16K, io_stripe.physical); ret = -EINVAL; goto out; } - if (len != SZ_32K) { + if (len != SZ_48K) { test_err("invalid stripe length, expected %llu, got %llu", - (u64)SZ_32K, len); + (u64)SZ_48K, len); ret = -EINVAL; goto out; } @@ -128,11 +130,11 @@ static int test_front_delete(struct btrfs_trans_handle *trans) if (ret != -ENODATA) { ret = -EINVAL; test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail", - logical, logical + SZ_32K); + logical, logical + SZ_16K); goto out; } - ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical + SZ_16K, SZ_48K); out: btrfs_put_bioc(bioc); return ret; @@ -209,14 +211,14 @@ static int test_tail_delete(struct btrfs_trans_handle *trans) goto out; } - ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K); + ret = btrfs_delete_raid_extent(trans, logical + SZ_48K, SZ_16K); if (ret) { test_err("deleting RAID extent [%llu, %llu] failed", - logical + SZ_32K, logical + SZ_64K); + logical + SZ_48K, logical + SZ_64K); goto out; } - len = SZ_32K; + len = SZ_48K; ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe); if (ret) { test_err("lookup of RAID extent [%llu, %llu] failed", logical, @@ -231,9 +233,19 @@ static int test_tail_delete(struct btrfs_trans_handle *trans) goto out; } - if (len != SZ_32K) { + if (len != SZ_48K) { test_err("invalid stripe length, expected %llu, got %llu", - (u64)SZ_32K, len); + (u64)SZ_48K, len); + ret = -EINVAL; + goto out; + } + + len = SZ_16K; + ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_48K, &len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID extent [%llu, %llu] succeeded should fail", + logical + SZ_48K, logical + SZ_64K); ret = -EINVAL; goto out; } From patchwork Thu Dec 12 07:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904788 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79DD420B7FC for ; Thu, 12 Dec 2024 07:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990170; cv=none; b=Nk43nRTIs5Zj8xxIJRRNYKgUGCXUyrsMhIhH/nemOLYu6XC9ql74mwkZwQJpr23U+g2x4XNOUlx6OjPqbQUinqdKi3gkDud1ZZCNCns0r5aa3GC73eVTDaAuDQZTGsLZA0AUYwDOotj5j5FEibVXsKQ/FucB1/45Wki3cuaVWXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990170; c=relaxed/simple; bh=lsalZYTX7Yfe+Z2ikNJkiwDQeUMbpgUuww8qUyEQH1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qEFMQXVgT+4inzeyNiSe55IeLXs7zmiH4Z4bTQE4eXrSgQjGcegWblkxUKhrpePfVPKljhe4FYpONbGX3ALOmV6kFjGARQnaV/aSujF7USK8iuHfzobkI4AdqfSsM+wbB8a7CJPVuy+/MMvdTAJmZqv4IEOdQtvfgTI8RDQ1870= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-aa6aad76beeso43439966b.2 for ; Wed, 11 Dec 2024 23:56:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990167; x=1734594967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BGBSaj/NTtT7gerNC19D9yN2B2q1gfc9/emRAxeQxqI=; b=lXJQTpjXOkEjVo94Hreg2qhTIpxCb45KchzZlW8OA0s7shcj0vBMUm0+tfg06AKSHU fei8EApDTc15Jp53xcrPPJNGQs61OYo7AH7F530ni3xdE038vEVxCEVb2tQBGMfEiP7U Mn3QD6J78za8XLg3sN8vWF+se86mETl9soXwpHp3lVUkYGKiucGJvjM+xGzgogSDCZgh Q1McpBRgz/RGEXPDluNefTEPaveO8g8nd3pKSXDISmjcehL15eK9goV85mAAU7grC0OT VwyuMu+KV4PTtUSC3nGSQKky+hhgouqB+lmbz/9ZXrzGOhHD3RrAI5Pz4c693PM/iR6Q 9R9A== X-Gm-Message-State: AOJu0YyLWrwSSIEE/hC/GSeDGV92vTB2ip8/u3mQ91wOazQLaBwzv0Iq OP6YtJVTzYk6A+w9snZVpXjHwV3qIFKa9BwJoMHF6R4TyAXBAz7H/931bN3P X-Gm-Gg: ASbGncs7y4/+X8nEUkWS6wS2KWVcN25xtLjumK4WkadUQZwXjvyF3MbYB2ogkP0c/Nv iNLITUOe9ZgBaszBQtx785KDGCu9k1JenckFSPgmYSzoPnOK0G34+4pKpc8cccv8qY3UL+2Q8ai AKwnKCsF2EpG1McvITsjjr4xMGJWbdQpImJui6qQIumre9KOhNW4ohR1TxzQPaH3tyW3Jzy7CVS SkRfJvo0JR3YCIorWBakIhkx9M7opylknAKs2bFGGTXmhB5kUY2rtMBZA9BK3ar+JfxuzHkw27f 4JWeUjLtHRWa9ZjVoqZQCK3zE6bpst9MZzZD+Hg= X-Google-Smtp-Source: AGHT+IETe7PekR4qdpeocSdh/fn6qpJyEaOIH36n93N/VcYaDjb3+TEKz4fSUijHpFmjHHLzw7dquw== X-Received: by 2002:a17:907:c912:b0:aa6:7cf3:c6ef with SMTP id a640c23a62f3a-aa6b1192f5dmr471598066b.15.1733990166739; Wed, 11 Dec 2024 23:56:06 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:05 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 11/14] btrfs: selftests: test RAID stripe-tree deletion spanning two items Date: Thu, 12 Dec 2024 08:55:30 +0100 Message-ID: <3f5da94fb0a98e09556468efdfff1cd7f71495c5.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 12f3dbb23a64..a815fc5c4dd3 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,149 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de return NULL; } +/* + * Test a 1M RST write that spans two adjecent RST items on disk and then + * delete a portion starting in the first item and spanning into the second + * item. This is similar to test_front_delete(), but spanning multiple items. + */ +static int test_front_delete_prev_item(struct btrfs_trans_handle *trans) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_io_context *bioc; + struct btrfs_io_stripe io_stripe = { 0 }; + u64 map_type = RST_TEST_RAID1_TYPE; + u64 logical1 = SZ_1M; + u64 logical2 = SZ_2M; + u64 len = SZ_1M; + int ret; + + bioc = alloc_btrfs_io_context(fs_info, logical1, RST_TEST_NUM_DEVICES); + if (!bioc) { + test_std_err(TEST_ALLOC_IO_CONTEXT); + ret = -ENOMEM; + goto out; + } + + io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0); + bioc->map_type = map_type; + bioc->size = len; + + /* insert RAID extent 1. */ + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical1 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + bioc->logical = logical2; + /* Insert RAID extent 2, directly adjacent to it. */ + for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) { + struct btrfs_io_stripe *stripe = &bioc->stripes[i]; + + stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i); + if (!stripe->dev) { + test_err("cannot find device with devid %d", i); + ret = -EINVAL; + goto out; + } + + stripe->physical = logical2 + i * SZ_1G; + } + + ret = btrfs_insert_one_raid_extent(trans, bioc); + if (ret) { + test_err("inserting RAID extent failed: %d", ret); + goto out; + } + + ret = btrfs_delete_raid_extent(trans, logical1 + SZ_512K, SZ_1M); + if (ret) { + test_err("deleting RAID extent [%llu, %llu] failed", + logical1 + SZ_512K, (u64)SZ_1M); + goto out; + } + + /* Verify item 1 is truncated to 512K. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical1, &len, map_type, 0, + &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", logical1, + logical1 + len); + goto out; + } + + if (io_stripe.physical != logical1) { + test_err("invalid physical address, expected %llu got %llu", + logical1, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_512K) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_512K, len); + ret = -EINVAL; + goto out; + } + + /* Verify item 2's start is moved by 512K. */ + ret = btrfs_get_raid_extent_offset(fs_info, logical2 + SZ_512K, &len, + map_type, 0, &io_stripe); + if (ret) { + test_err("lookup of RAID extent [%llu, %llu] failed", + logical2 + SZ_512K, logical2 + len); + goto out; + } + + if (io_stripe.physical != logical2 + SZ_512K) { + test_err("invalid physical address, expected %llu got %llu", + logical2 + SZ_512K, io_stripe.physical); + ret = -EINVAL; + goto out; + } + + if (len != SZ_512K) { + test_err("invalid stripe length, expected %llu got %llu", + (u64)SZ_512K, len); + ret = -EINVAL; + goto out; + } + + /* Verify there's a hole at [1M+512K, 2M+512K] */ + len = SZ_1M; + ret = btrfs_get_raid_extent_offset(fs_info, logical1 + SZ_512K, &len, + map_type, 0, &io_stripe); + if (ret != -ENODATA) { + test_err("lookup of RAID [%llu, %llu] succeeded, should fail", + logical1 + SZ_512K, logical1 + SZ_512K + len); + goto out; + } + + /* Clean up after us. */ + ret = btrfs_delete_raid_extent(trans, logical1, SZ_512K); + if (ret) + goto out; + + ret = btrfs_delete_raid_extent(trans, logical2 + SZ_512K, SZ_512K); + +out: + btrfs_put_bioc(bioc); + return ret; +} + /* * Test a 64K RST write on a 2 disk RAID1 at a logical address of 1M and then * delete the 1st 32K, making the new start address 1M+32K. @@ -468,6 +611,7 @@ static const test_func_t tests[] = { test_create_update_delete, test_tail_delete, test_front_delete, + test_front_delete_prev_item, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Thu Dec 12 07:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904789 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 3D8D920B7FE for ; Thu, 12 Dec 2024 07:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990170; cv=none; b=d9fIh1ly02naepY7OYiR+XX0W7mhUtNgXKAzjNN5zTnazfENNeWB5wVrlNsBK6mu2MV5mr2rGxX9MEL4aNORdPp2hK56zw1bCV0CEg85gAjO51D1jm82T4ZgGUQTrF6/zr0m6CCvWg+mGxhDmysmvk8Oo5T7LHhupfblYtOPOak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990170; c=relaxed/simple; bh=BWH0+6z1Iwy9XUQzsDvEhGduSzrwaIIFPeTo5EHBmpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JZMJ9Byet+Ox4cAbqVjQtNbGZAOYAwLRDdb3PYMoIemFWnu9x3IIWR1vpN5QaIJS0P00Hzogp2vF3DwtCfSiy63PPGkcEFKTqKLz/euKasDBLFGwrHLeo9hNU9IN52gnzcDxJuXOUXjyiX1n4ESufJ13Ger6JPrgSQyAc8neHi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.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-ej1-f41.google.com with SMTP id a640c23a62f3a-aa6c0d1833eso45410666b.1 for ; Wed, 11 Dec 2024 23:56:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990168; x=1734594968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r48XIgLiD0tfU33Kd3M1iAsJHXPjIUYXmKA/bdPJW9c=; b=HB2yr3cxtDY0GRPCH5qMy8ptjpKn0zipAcJ/QFr+KFlow4PXY6v2pwATRRIjsnX7k9 CmDaIwalqYWDFSJ4Y/PxRu6fe9bwTRZClRvV93IEHOBLHpalRrQPGnbA1d1TbvH6qLy3 JHudcr1QOzQU0z1EUsuxyS/+M04dgGyKFshvSioZN8tfafnCQTwzWDKOIJHXT3EILqot acrmcDfM2DbMVVJH917eOoyivCTvkPpdHMNfi7ZmieVaHGr4C3pi1y8skZi74Q3EuVLA DECxpFoDtbBi2lvm0CCfsxd/zAEudUcxfSnYH/BvA2D3bVEu7YTkNn/Uf/lj2HlLEU8v QLDQ== X-Gm-Message-State: AOJu0YyOz4YDMJJ0XL8qxvXm9kxeXx+Mq0S6qNw/GqRgDQ+EGwgmGIpY RTPpUIBHQUhWs+nMWBkLWHEYPIdUeBclPgXXJaucsqqdC8n8VGSloDCnPgrF X-Gm-Gg: ASbGncuJBPTJlRlWyot7RyZAgvTo89ytaXFz1Y4ucWa4C/mpGCq3Bekat2KRyEvjVze 9dJNxR+xOkbr5NCC7D399k4oQ/mpJG5eQbwmGRG5iz2eqIjfQMAISlCYIG8CO/yIwDH4YLlY7rV mfzWZVnGRik+pnmiuOJQbVzNrV/d/PAAo8qcGhBUZy/MsK/wAG3XfwM258+WYkr+O4k35RXAG32 UH0c95zmqrHwSJlyrSB3YIuRv3Cq6RKsSAX1Fl+jmMceD6nfZcD3lQQBoDYx3HAAs/Z+XZG30yh LpQdajuFrhx9RYjReammGu6lEGXBF93uQMK3FGA= X-Google-Smtp-Source: AGHT+IEI6X/+7SB1IBvUzY110eAhhJscsIpbiUTMtQgFXhJmRTdV9471TVWnBexFXBejD1LuX+/+Ng== X-Received: by 2002:a17:906:4ca:b0:aa6:993a:259f with SMTP id a640c23a62f3a-aa6b1396ea0mr621290466b.40.1733990167643; Wed, 11 Dec 2024 23:56:07 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:07 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 12/14] btrfs: selftests: add selftest for punching holes into the RAID stripe extents Date: Thu, 12 Dec 2024 08:55:31 +0100 Message-ID: <48a5cfb4c94de62c961f36d0a6ff9c9c24902116.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn Add a selftest for punching a hole into a RAID stripe extent. The test create an 1M extent and punches a 64k bytes long hole at offset of 32k from the start of the extent. Afterwards it verifies the start and length of both resulting new extents "left" and "right" as well as the absence of the hole. Signed-off-by: Johannes Thumshirn --- fs/btrfs/tests/raid-stripe-tree-tests.c | 133 ++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c index a815fc5c4dd3..37b87ccb5858 100644 --- a/fs/btrfs/tests/raid-stripe-tree-tests.c +++ b/fs/btrfs/tests/raid-stripe-tree-tests.c @@ -31,6 +31,138 @@ 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; + } + + /* 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 +744,7 @@ static const test_func_t tests[] = { test_tail_delete, test_front_delete, test_front_delete_prev_item, + test_punch_hole, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Thu Dec 12 07:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904790 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5580A20DD58 for ; Thu, 12 Dec 2024 07:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990173; cv=none; b=Bi/OwoxP6xoFsRaSBDLnO3WMW+NKYr9Miqx+u7opXe19oBWHFtFpS7DMuOiiX/n/Jf2sY7KdQVePJZ9D6LdSY0hVjqHOw4L/tmVvtrlmLc2c3IMpT5vC4bqdW/AT0NyS5q3c0Nsxs/tH92q3nxmgc0nN0ufkJgYq2fr/Pa/ZdcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990173; c=relaxed/simple; bh=jXZrJPWGovd5Z8NgLmgV1Rcpxy4kXQAEZtI5WlnnKFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pR1kwVqlriMP/fexZS7eVs02NPKrSMOgc22HyEdQCxTNKYQCPx/QuWO8oiJMoA8A8DKe5se0rCC0z87VEwvF2v3ufI/8jj4bDCJsZHzxA9X0IWnULT6sSf0iqD2jpgRUXEa4Gq91zzZp9U/50/6i0mH9afWcYYr2CkLeM9Dmg1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aa67333f7d2so40457666b.0 for ; Wed, 11 Dec 2024 23:56:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990170; x=1734594970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MBwWq+36VjgbADt9rxWO7KTgR6EWm+cYtUJRpKHMaoc=; b=ewnAKNogtLZtr5pgkZGIsITslg4GHSXImLFwTXnkrw/INmu4QQ7S0s5Mb4hEgTwfP8 BMt7l/7r6up8RVQnOEOyE/lLjXfM7bZvP+8zTUSeG8Htu3naMya+uRpPnjnq41VV7eR8 GxgXKGjMWjTabo4HvMFB5jdW3xXANsY8Q++CXq4SGgs6r2+Usog9po92YhKc4+Jo5U0o lypF/ZLmveqvPxIG0QZRuv2GE3gwe9pntpuL26LiOooj44vT7zdpgtFTALCgwmyPWol/ DyfgYBW6bjb9fAgl/zy2zpIsi68vThiXg7hW2juFwABgE0JuiiMfug9q5BzrxIZR1h3J FVhw== X-Gm-Message-State: AOJu0YyKugxt4pp3gZB/+2B+sH71gIo1HHxSosQVbIQyNvVaoE3adUN7 yDaUf+KfDW87JEh4UUdjUzsDwPZznkgyFY0/hzOot6nNqlfEUdrp+uj80Yew X-Gm-Gg: ASbGncvmwvYFcljIFUZ6/7prIWzUvnnwH6Yen4Po9b809EbtTynJyvIHuMb96ScpJk3 FZT0AYkd8RG4JUqByJHnNCwmbqbXh6Kwt5pZ+U67nI0CpUpMKA5dRaxcbb8YjAPxTjd/dvjf2fK wyREmqgijfx7+tm3Ue9t+M0+esOYlgceaLe2PK06YPsp/l900FyuZbIrQZC0svWvpt0epP4d0n5 m2zz+uxQoWoe0kh/LeFs+9nOFEadxikcWYD+okynHW+L0CpfABwKC3GMFdDQeC8DAvvjJVB0zcT Nstlzyd9IxjFFj1mLdLyQB9E+mqQX14IfffF19Q= X-Google-Smtp-Source: AGHT+IFaCUQekPwWjaD4LLOkYRKAuRfH7/M2Hs7pRj+R4vQQLLrGCJhrxe8TJoHQZ+02b0dLD78/aw== X-Received: by 2002:a17:906:2929:b0:aa5:31f5:922a with SMTP id a640c23a62f3a-aa6b119dc22mr537091666b.19.1733990169628; Wed, 11 Dec 2024 23:56:09 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:09 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 13/14] btrfs: selftests: add test for punching a hole into 3 RAID stripe-extents Date: Thu, 12 Dec 2024 08:55:32 +0100 Message-ID: <9ca5d0de8c4ebd1e6267f1fbae9238753d14cf50.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn Signed-off-by: Johannes Thumshirn --- 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 37b87ccb5858..8d74e95a8a75 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) { @@ -745,6 +927,7 @@ static const test_func_t tests[] = { test_front_delete, test_front_delete_prev_item, test_punch_hole, + test_punch_hole_3extents, }; static int run_test(test_func_t test, u32 sectorsize, u32 nodesize) From patchwork Thu Dec 12 07:55:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13904791 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEC4920C007 for ; Thu, 12 Dec 2024 07:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990175; cv=none; b=TzZmo6h+1tAa7PJ2PBWZoLi1m7g1w0dGcXp72idWQ5CpGCGBiJc2EvladpgmlCFgAiSfz1Cm58PdZHAnG9Bd9PPGZxYh4U2Z09IjeMkGFm2kIR86ZmKJT6haWGyxvA+geoQQ65BBjDCiG1KCi2pFpFbzVoigDZy+B+LPohvENII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733990175; c=relaxed/simple; bh=st38RmZEpm0aq87kK+7A5xOXIND1kKFBw9NGlzNmH/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pksDbfbrG+KY2z5rZDy3O0Mu+KP0an6v7tf+vBqJo4hgLmRG30vgRc9tJyVUaAZ5bsf8FAcoxXQGLksckR8IVd2cpfhsM7a5wgQheRo/nR6DQNtNf9+G0IHacq39ayoVV2Q+t0xc4mFlRlGF8NtS4hDbNMx0GTsdCKu8vLh5O50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9f1c590ecdso48511766b.1 for ; Wed, 11 Dec 2024 23:56:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733990172; x=1734594972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gikd2Wwi7AUJNjoWPoX2fc6Q5hZzYRYSNZdpT755xGc=; b=vA1CsHbeYcZWpehrImty0BTncIMpt8kbwmtKloAkeBbEcw3f0gaeUOsYSMjZrZ5uYJ zh2QDWftDqQN/MMemSftXCBqM25Hla5Po42YIUsztH1Y4Y4JClrbGcmkVtwqFxWmJymY 0o02AeItnbKTEiXROz89GVekvt6VE4kWTdupGlWU77OeBKzpufR47tp1vxjPEXfEMJ1J QjQKg1vV+mz9VvJ1uPEQ4GpBAJM95x7dpKSfKI/Om5gIKpbVZiETu3d3I76L2yMSVjyH 7k5aelrPpDiHRGDZizVmaJ4SSYbujY8hNfG1jT0nI9OJ7rWWUFugyzmn4nv+A6I74qU2 k9xQ== X-Gm-Message-State: AOJu0YxZH3QPTsqowo0oxRVuMaEuErE7ffCNnjg7tHLv0zZ8d36XmVdf zTTi92d6udeX3kJAzt6JVL00plMFEZqlv2siuonBlP/+kzEU1CMCuN4tZouK X-Gm-Gg: ASbGncvNFfSAc+xoHHX7hSkMfQOtgaZZB+tsjFXAsIut+QucggaJQ1H6dQfCjSRtOda 0jwY4/koJWYjL+3mQKwGxxhnH7Ry5TmrB387wOBmRRpdWMUfeAD6/yo2H4z8Wtp9Yt/palLwT5E vdwbXZStjdcX9mh+0musFvkHcLFCvDnGwKI6jH0CJ3HmgYXHuwv7a8IErnCyjsSHcVDyiu9Y6fN 7pGaQjBBBukeV9lE8tPpf8wXe2sMgi/fJUBjCIpi6tYj3A5bimkOff12BqrNbiBKljoLQDbfmPV g4IBHS7ulYgvEi8HJDUUjeQ65uYEt3DAIilXgxg= X-Google-Smtp-Source: AGHT+IGqAYWWC4/SVfmFC6X0ZSwCTApH/E9twwx18IR56oTBO+4ziXv7mLLDaE4opAM6Cyk6/f0otw== X-Received: by 2002:a17:906:32c2:b0:aa6:7588:cbeb with SMTP id a640c23a62f3a-aa6b10f5e52mr511570966b.11.1733990170614; Wed, 11 Dec 2024 23:56:10 -0800 (PST) Received: from nuc.fritz.box (p200300f6f7081700fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f708:1700:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6a3a80d6csm350730766b.8.2024.12.11.23.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:56:10 -0800 (PST) From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Josef Bacik , Damien Le Moal , David Sterba , Naohiro Aota , Qu Wenruo , Filipe Manana , Johannes Thumshirn Subject: [PATCH 14/14] btrfs: selftests: add a selftest for deleting two out of three extents Date: Thu, 12 Dec 2024 08:55:33 +0100 Message-ID: <8b38b12a3a1f3ead232143bbab1829ecff3b570f.1733989299.git.jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn Add a selftest creating three extents and then deleting two out of the three extents. Signed-off-by: Johannes Thumshirn --- 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 8d74e95a8a75..29c45f75941f 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 is 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) { @@ -928,6 +1071,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)