From patchwork Thu Jul 11 06:21: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: 13730044 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.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 A713C12DD95; Thu, 11 Jul 2024 06:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720678904; cv=none; b=FKwzhEB4fjAlbPWv5R+LRt3yfYRcZpTJFEp8tY+Gk98U3rAZqho7pTk5fTk2/ZoPJxFQenE62hUEY3dmLqPcCBKDctJbzhAwIYwP0/syU2lnYkh+bRZQYZlrTt8WkUJfbjhrNjFFET01JFU34pr1EtdDI6iTD0hAaudUM3jKaiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720678904; c=relaxed/simple; bh=wYnjBVzTcF/OzalHx2oAQbF/PY+TIdryRfsI0bE4fL8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nKfkOGhOK0TSq/wOXV9e7MVZqEsHNObz5h9MtkIOYr4XfXvhp0isK3mKT8TAAH25IV1xwfM6VnFyXfLOlgkoKa60Q2rYOiFtWe8XaklspGptEmUVToX/a5QmoZ06S2yWB+d2t62IKyIRl/KVcXPAWZneLZFDI11Cr2ROJ8FE52E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5957040e32aso370898a12.2; Wed, 10 Jul 2024 23:21:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720678901; x=1721283701; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6jqmu7ZRed+yR97RAgoDGzIXlD6UyBcncdYUkhMXLDQ=; b=i3NfatfxXqSuYYtvb9jfvsr8YUGBbyxBmmcEF48Mofe8QnSq/zCQ1Rkj4JWJ7K0vra Ei37n5rJzwLP0ZgQB0CDwgnSpyCtIv1zPlxcZqMKtk0tjw54tikk+MOlVz/IACuWL7lW uz2LLuJEI09FGMf+pfDv8R+RLZh49449B0NAEFqRbys85C3rQc35KSXz1noVRMcN1jfv V6VAciZgxWk1BlL3Kqml1vQjNHIxBP+EcqjliWc1MKvq185lAo322FjZWP4rXET5GIeo nGxrbG5pIdMgtKoFll3j0acw4y9zT83l0jLVjEbl6nB39AHOsibLozW0Y6absfbCXdSh M1yA== X-Forwarded-Encrypted: i=1; AJvYcCUzSii1TLToGoTb3NHuSbqSQ5NXGi+cGfzXT4ZxYw7FnoU0ZsU2L4LoYL6ik5AblTmBmmbIHtVc5Q31STzDdKvKNh8O+qjIfRdcMIrM X-Gm-Message-State: AOJu0YxQlyqbVn5/1eO6W3sXrBpccTazE65EKmZ30ELdiQ9qmOjXRtzM Ugk4RJlBq+LrVzff2o8Wi7ellvTNtw3d83E+jlBndWuQEexK5wny X-Google-Smtp-Source: AGHT+IFxTA4CMWXVbNisHI+JmfEEAvtFP1tM1wH5lUZpxTZb7pJ1mtNiyc2QktHf6nW8qgE2x6Mn7A== X-Received: by 2002:a05:6402:430b:b0:58c:3252:3ab8 with SMTP id 4fb4d7f45d1cf-594bcba83fcmr8029083a12.37.1720678900708; Wed, 10 Jul 2024 23:21:40 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f73ce200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f73c:e200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a7ff73bsm224815266b.101.2024.07.10.23.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 23:21:40 -0700 (PDT) From: Johannes Thumshirn Date: Thu, 11 Jul 2024 08:21:30 +0200 Subject: [PATCH v2 1/3] btrfs: don't hold dev_replace rwsem over whole of btrfs_map_block Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-b4-rst-updates-v2-1-d7b8113d88b7@kernel.org> References: <20240711-b4-rst-updates-v2-0-d7b8113d88b7@kernel.org> In-Reply-To: <20240711-b4-rst-updates-v2-0-d7b8113d88b7@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Qu Wenru , Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3579; i=jth@kernel.org; h=from:subject:message-id; bh=C/2veQuXInUAYzzKEwd4xcEWSsj265yrCeC73ehFe4I=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaT1V36s6zi7/sO1kp16x1NzPijJ3Vae+Uxw280Gow/Xd uzKZ26u6ChlYRDjYpAVU2Q5Hmq7X8L0CPuUQ6/NYOawMoEMYeDiFICJ8MQyMrRflVzh9Ug+JkXx 6l0T3YvlxziWi26MfrHoqNou1h3H7ggx/A+5cPGWqErSn9+Xm/Sl/y/433BAy4x/3vZJc2Zaz2J ifMcPAA== X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Don't hold the dev_replace rwsem for the entirety of btrfs_map_block(). It is only needed to protect a) calls to find_live_mirror() and b) calling into handle_ops_on_dev_replace(). But there is no need to hold the rwsem for any kind of set_io_stripe() calls. So relax taking the dev_replace rwsem to only protect both cases and check if the device replace status has changed in the meantime, for which we have to re-do the find_live_mirror() calls. This fixes a deadlock on raid-stripe-tree where device replace performs a scrub operation, which in turn calls into btrfs_map_block() to find the physical location of the block. Cc: Filipe Manana Signed-off-by: Johannes Thumshirn Reviewed-by: Josef Bacik Reviewed-by: Qu Wenruo --- fs/btrfs/volumes.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index fcedc43ef291..4209419244a1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6650,14 +6650,9 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, max_len = btrfs_max_io_len(map, map_offset, &io_geom); *length = min_t(u64, map->chunk_len - map_offset, max_len); +again: down_read(&dev_replace->rwsem); dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace); - /* - * Hold the semaphore for read during the whole operation, write is - * requested at commit time but must wait. - */ - if (!dev_replace_is_ongoing) - up_read(&dev_replace->rwsem); switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { case BTRFS_BLOCK_GROUP_RAID0: @@ -6695,6 +6690,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, "stripe index math went horribly wrong, got stripe_index=%u, num_stripes=%u", io_geom.stripe_index, map->num_stripes); ret = -EINVAL; + up_read(&dev_replace->rwsem); goto out; } @@ -6710,6 +6706,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, */ num_alloc_stripes += 2; + up_read(&dev_replace->rwsem); + /* * If this I/O maps to a single device, try to return the device and * physical block information on the stack instead of allocating an @@ -6782,6 +6780,18 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, goto out; } + /* + * Check if something changed the dev_replace state since + * we've checked it for the last time and if redo the whole + * mapping operation. + */ + down_read(&dev_replace->rwsem); + if (dev_replace_is_ongoing != + btrfs_dev_replace_is_ongoing(dev_replace)) { + up_read(&dev_replace->rwsem); + goto again; + } + if (op != BTRFS_MAP_READ) io_geom.max_errors = btrfs_chunk_max_errors(map); @@ -6789,6 +6799,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, op != BTRFS_MAP_READ) { handle_ops_on_dev_replace(bioc, dev_replace, logical, &io_geom); } + up_read(&dev_replace->rwsem); *bioc_ret = bioc; bioc->num_stripes = io_geom.num_stripes; @@ -6796,11 +6807,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, bioc->mirror_num = io_geom.mirror_num; out: - if (dev_replace_is_ongoing) { - lockdep_assert_held(&dev_replace->rwsem); - /* Unlock and let waiting writers proceed */ - up_read(&dev_replace->rwsem); - } btrfs_free_chunk_map(map); return ret; } From patchwork Thu Jul 11 06:21: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: 13730045 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54EBA12DDAF; Thu, 11 Jul 2024 06:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720678905; cv=none; b=dkui+63pDjOa9SYmGB4faOqvx3T2gpJwPlDuj+FSKh0KSaWIyd/EH1wjkPR0fBorZITIZYAm+Hc0rgG2wXB4j3hX6ZKU+az/15lXYM4R0YYEh7xTCdqROYWmCwQGdVNd/7dyRMAJoy1SYeYszIJL3oZNVQtH05A+eDAQHnE08aA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720678905; c=relaxed/simple; bh=E1Rygkno4T5BcJ7XkxRKwwLhNE9/LYnAAlNk2nXPm28=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Dccu0gw5wwxstBm7n9GkGizTfrE7WSy2JatJQgfUZxJ01HEaly6GvrW5SZSrk2/j2PITLywfVM6AHcu2YbjJ0eVbp123O6EOuQ2R1+uMgtFSh0W3lCiIq82ovi9eXrWO1fViNYlZs3/GBxl+otKPr8BPqMcOzPCpzbyIi4/fgo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a6fd513f18bso58802766b.3; Wed, 10 Jul 2024 23:21:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720678902; x=1721283702; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QurXtUEH8BTN9nyQvrsoprlRroyt1ZrLsWM6ZQAHQ/E=; b=e8x7jcqRDuoalh84flGaNqVcfJaEy+bWL9WjZH2IDVM7xlZeeLdJ4loY3WQDtCkN1F A1MZZBqFWEuE1Yza3Y83AXPiCPYfJuC6Z4k1naEe7uX9TDUblBqCjlcJKRnzbFE8JGUn VVlW9uuKva3kCtfoC6ROFSJ7OkJgUHGJ4fYbrZMNz661g5/71uf3XCfyBxmcd8mBVu2R NU2sXdL0HpyjPgyBnzpAxf8kH52AgT+5adWvflTGHfNzOz5LUDzdSI4nv0P1bzjVvdXW B2DxNvruSB1HibqRXNjP1J/6ikapfpAd9f56avdaZxKH/wix4EbdrGrDnD/rc/hXPl1m a21w== X-Forwarded-Encrypted: i=1; AJvYcCXjxI9EQKsgRbflp2aKOKQGuEo1ip+XB90hI4fSX+pFmuAfBdUt34IUghSkSvpOH689bp8NHzppdfnZfjdshdENaJ2YrBpdBYa8swC4 X-Gm-Message-State: AOJu0Yz6ytxdsBdQQZuRj3IjwlpLmGjyU5WfGPYlT5ccVt3/K966S7Ur lcTVmHIux5/U/uf4Na08qNzIh6RtupX0+xhL+L7VahGIB+B9xV/s X-Google-Smtp-Source: AGHT+IE6+eh3Ov+Fr7hFZ1Awnx1zNXof+KAK4NZjeJWzRjrAwqsj5XYOHBQBbWWBjw8TKRZu+G8lTg== X-Received: by 2002:a17:906:f0cc:b0:a6f:e819:da9c with SMTP id a640c23a62f3a-a780b70539bmr480995766b.43.1720678901679; Wed, 10 Jul 2024 23:21:41 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f73ce200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f73c:e200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a7ff73bsm224815266b.101.2024.07.10.23.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 23:21:41 -0700 (PDT) From: Johannes Thumshirn Date: Thu, 11 Jul 2024 08:21:31 +0200 Subject: [PATCH v2 2/3] btrfs: replace stripe extents Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-b4-rst-updates-v2-2-d7b8113d88b7@kernel.org> References: <20240711-b4-rst-updates-v2-0-d7b8113d88b7@kernel.org> In-Reply-To: <20240711-b4-rst-updates-v2-0-d7b8113d88b7@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Qu Wenru , Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2402; i=jth@kernel.org; h=from:subject:message-id; bh=V2ekxPfOBKYmlscJ31n+l+AOq+6mmzYwwxP4yafzWHA=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaT1V36UbPycN61fZN2mM5wCvBv8FZUeq+46tPRw+doiZ TtNrnkxHaUsDGJcDLJiiizHQ233S5geYZ9y6LUZzBxWJpAhDFycAjCRk0aMDHtNj5tPjsmd08kb +cMpnj/8dDB3ddq0fxPMXjD6fWTNfcXIsKJxvrW9XvO9+hvB3w4/yd35Upnv+98D3o6+3XWR3rW l7AA= X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn Update stripe extents in case a write to an already existing address incoming. Reviewed-by: Qu Wenruo Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index e6f7a234b8f6..fd56535b2289 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -73,6 +73,55 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le return ret; } +static int update_raid_extent_item(struct btrfs_trans_handle *trans, + struct btrfs_key *key, + struct btrfs_io_context *bioc) +{ + struct btrfs_path *path; + struct extent_buffer *leaf; + struct btrfs_stripe_extent *stripe_extent; + int num_stripes; + int ret; + int slot; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + ret = btrfs_search_slot(trans, trans->fs_info->stripe_root, key, path, + 0, 1); + if (ret) + return ret == 1 ? ret : -EINVAL; + + leaf = path->nodes[0]; + slot = path->slots[0]; + + btrfs_item_key_to_cpu(leaf, key, slot); + num_stripes = btrfs_num_raid_stripes(btrfs_item_size(leaf, slot)); + stripe_extent = btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent); + + ASSERT(key->offset == bioc->size); + + for (int i = 0; i < num_stripes; i++) { + u64 devid = bioc->stripes[i].dev->devid; + u64 physical = bioc->stripes[i].physical; + u64 length = bioc->stripes[i].length; + struct btrfs_raid_stride *raid_stride = + &stripe_extent->strides[i]; + + if (length == 0) + length = bioc->size; + + btrfs_set_raid_stride_devid(leaf, raid_stride, devid); + btrfs_set_raid_stride_physical(leaf, raid_stride, physical); + } + + btrfs_mark_buffer_dirty(trans, leaf); + btrfs_free_path(path); + + return ret; +} + static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_io_context *bioc) { @@ -112,6 +161,8 @@ static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, ret = btrfs_insert_item(trans, stripe_root, &stripe_key, stripe_extent, item_size); + if (ret == -EEXIST) + ret = update_raid_extent_item(trans, &stripe_key, bioc); if (ret) btrfs_abort_transaction(trans, ret); From patchwork Thu Jul 11 06:21: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: 13730046 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EBB912F386; Thu, 11 Jul 2024 06:21:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720678905; cv=none; b=c/v1q+fmrEoUiMRGG9J6aD0vixXwO++8dxAaTlejlnUJDJ8pyH4d+090/tiXLLR3j9LAXUDGmlUaYAUJEDpR/QFww5k/4a5PHdJTWCOBQ+WCsGTgEi5TOd9uvnf72DEP29I9xfhSMVGX66zhI9O28dxZPeMjL8gHEGRROSkxTA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720678905; c=relaxed/simple; bh=9ZfoQLUEkfJZeB5uHQoavrcYrJdIFjhKrR9D66YuQNk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hz5MsKt97ceP7MSXur+XN43usxJSuG1yfTisdAFz3xEpQpsxamAuthwxScpR9eR3ziIv7cniA7qIEriLq2EeW6XpxK2u+OV0FOdwcX6DhmeKIJRzTP0GHX/T9ACsYM7gwE89J0/5o0wzX3WWZCkwACmPgbjnfhavwmURbTQLEjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a77baa87743so55090466b.3; Wed, 10 Jul 2024 23:21:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720678902; x=1721283702; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T9/IGYREW0Y/xsMMiSEi/qtroO70B9dqqK8GTXc5ZaQ=; b=KcYfH8/xwUc1kSZq7gdt3r4y1D1YkMKIPc/cds946vmD7xPsbBf+jqm2UOQDVF0cwU h57D/enyzOEM4gEjW5ESpzIhg9wcLguOZ+ff1peuvOqTB0PDgraEo/x/XKBevibfe62t 19SPHxYC/2kj+VBYl5hyZB4yqDs6WtuL1t9Gly8+L7m40OCjgdW3qW+UwR93Xe1eXNeV 3VC0RD4Kv2esYpQkUhTqumUWWcrX4P5rwciAgG2Tx0PMmKQetpmS7CxP+qUSh2XE+Nw7 TTL2bV6O3p5txv/D1ZS6EQ2lXL8aI9m34DScwobyLJfU2XMWYORf/njIWaJBdxyKH899 EbsA== X-Forwarded-Encrypted: i=1; AJvYcCVe8bxGh8tb0FaopU5AihGTFvBNEc6U4wNhGKQr75jA65NpakQiTovMd99jHNZR8bG6ZlCPKaMVsm7mdHWDpUsHL9Gf9HpYuxIWn37t X-Gm-Message-State: AOJu0YwJON6ZHUhnmspGXwzNImKWWRSngY5jGVbxvJNG5rS9lhbOSRW8 TdHgQ1zdpo3SV+mBBDaBEH0PXlkKiH0C8nsGR4PX91R6t/+2+onwbXMQiF7a X-Google-Smtp-Source: AGHT+IH42bY/0ZiYAXnh/QNDFpgVMSC5RWKOd6+mds2gtkswNxe/3+ESeyFvZron0W5A5+YupWYqVQ== X-Received: by 2002:a17:907:9711:b0:a77:b0a4:7d88 with SMTP id a640c23a62f3a-a780b689270mr798924566b.10.1720678902623; Wed, 10 Jul 2024 23:21:42 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f73ce200fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f73c:e200:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a7ff73bsm224815266b.101.2024.07.10.23.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 23:21:42 -0700 (PDT) From: Johannes Thumshirn Date: Thu, 11 Jul 2024 08:21:32 +0200 Subject: [PATCH v2 3/3] btrfs: update stripe_extent delete loop assumptions Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-b4-rst-updates-v2-3-d7b8113d88b7@kernel.org> References: <20240711-b4-rst-updates-v2-0-d7b8113d88b7@kernel.org> In-Reply-To: <20240711-b4-rst-updates-v2-0-d7b8113d88b7@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Qu Wenru , Filipe Manana , Johannes Thumshirn X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1121; i=jth@kernel.org; h=from:subject:message-id; bh=/hPivgzVrBaHts4c6z051kDKm5XB367suNlHH/JAm6g=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaT1V35KiC2+1WRSWi0yY535Uqvgwy/KXBxZzgdM/r1hs /VcDt8JHaUsDGJcDLJiiizHQ233S5geYZ9y6LUZzBxWJpAhDFycAjARh7sM/703aAtLZtT6nnjv 3Vjef3V9kNju2euv7Nj4k8lnE/8ZdT5GhjMNjTeTHlt/nbw2ZuasXmOH6lPOVwsn1JtX3lnP6RS +ixkA X-Developer-Key: i=jth@kernel.org; a=openpgp; fpr=EC389CABC2C4F25D8600D0D00393969D2D760850 From: Johannes Thumshirn btrfs_delete_raid_extent() was written under the assumption, that it's call-chain always passes a start, length tuple that matches a single extent. But btrfs_delete_raid_extent() is called by do_free_extent_acounting() which in term is called by __btrfs_free_extent(). But this call-chain passes in a start address and a length that can possibly match multiple on-disk extents. To make this possible, we have to adjust the start and length of each btree node lookup, to not delete beyond the requested range. Signed-off-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/raid-stripe-tree.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index fd56535b2289..6f65be334637 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -66,6 +66,11 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le if (ret) break; + start += key.offset; + length -= key.offset; + if (length == 0) + break; + btrfs_release_path(path); }