From patchwork Fri Jul 12 07:48:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13731361 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B1BC13B2BB; Fri, 12 Jul 2024 07:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720770527; cv=none; b=q10Z/EgiR0qECdllmIZUS5Tv5rnoUREzc2mAR81ZC87yQk2lBGHtZhiMDrr9gatB1khvc/j8CTaQVsxH0NT8DrK9mMipCKTped8j+6Us00UhmK1hOGSqy2B6N+hcBfGEHsnKtzI3izxDh03JJYGuShq5hcoxj2rE3NnpusrtZEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720770527; 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=VeSpcGQ8kXOiVCY4USYh2eg3xUVVX04y3Va7YlvDgx5JJ1VFqQ2Qee6sFK8FXkUjNjDJi2djxzMuZcm68IFQ2buSt0dViBxhkh9kZ1BH0f7MxLwkYn4/jmfgamaYEslyR9bq3pBE+0Eenbh77i5Ocfc7xgaLok82n6zx1EUiHEY= 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.128.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-wm1-f54.google.com with SMTP id 5b1f17b1804b1-426717a2d12so10314155e9.0; Fri, 12 Jul 2024 00:48:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720770524; x=1721375324; 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=laFzCHZcMp0g0Vs7lK8Fv/ey/GVKGd0PIXSfdd2DLge9HqGb8FbTHzlXgmUEXiN6mj 3VsNSVQA7ERJvKqou3KCTBagTKhy4S6Xellea9VxxlpRlVUUkAP0o/HL8ELxXJFng+nS BQfqISmHj5s0V4chTF8YRj5EcjSNP52oscLhHUPJhqH1+5hDHOhL/+TcWufI0i+Y0j3/ pcfTOOjNC3jqh2PILrWUBxevGlm5O3hY9mu8BUwT6Lpqzv3CoCuRR/4x/7IVpUEsAjY4 uJPIrlegAVYRvlSLw5QS6elRgKrtCnISSeJ9sjd7lrhOCC147TXAZ79zKn9r84m0v5o9 p9yQ== X-Forwarded-Encrypted: i=1; AJvYcCWUviKDQ+cnree0YOiXpGoEpv+c9fWSY//xWGpNwl3UwCxKmyr/n8opp2+HXFRrI93i20fn3HeS4UXYJULpqjgnK0FB9h5v9QNVy5iC X-Gm-Message-State: AOJu0Yx0OcCyIk3+BBFOAM/aDk7QqPuaJjoWKX35sLVVLWYrbCVB8f8z Vtp4PPt17uodijMgpVmxK/AOeMml9gKR8MbUAdpmB5DESNz/YVBq X-Google-Smtp-Source: AGHT+IEeomES8zZlRcnj8cmM5sp6zSmql8wK8MRRHYOYM1ODnDSWDv57/cJmR/d/q5TwptAlJ9EGvQ== X-Received: by 2002:a05:600c:33a5:b0:426:6fb1:6b64 with SMTP id 5b1f17b1804b1-4279da024e6mr15977515e9.7.1720770524172; Fri, 12 Jul 2024 00:48:44 -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 5b1f17b1804b1-4279f2d74d5sm13532115e9.46.2024.07.12.00.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 00:48:43 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 12 Jul 2024 09:48:36 +0200 Subject: [PATCH v3 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: <20240712-b4-rst-updates-v3-1-5cf27dac98a7@kernel.org> References: <20240712-b4-rst-updates-v3-0-5cf27dac98a7@kernel.org> In-Reply-To: <20240712-b4-rst-updates-v3-0-5cf27dac98a7@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=owGbwMvMwCV2ad4npfVdsu8YT6slMaRNuH/L6b/BmnlfRE8nV6mpy/+VCnyw4sRL5uK694xPd t5xnr+kt6OUhUGMi0FWTJHleKjtfgnTI+xTDr02g5nDygQyhIGLUwAmUvefkeHif7d/HtqrH5z/ Uc89eUPdR/UvrFsvZRRoHmF2a1iz/n4+wz/LdxxNB7fMyS8NntwR5vrw0ZWU7HnTZnvFbVE7b1H n/pcVAA== 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 Fri Jul 12 07:48:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13731362 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD7AF13DBA0; Fri, 12 Jul 2024 07:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720770528; cv=none; b=O6h16KczAQAyGLSLlbBpWE47DNnrkVL4CnMVyeRj2GABlPaMZJ3T4mNAuEfZXkBioCUIWxd6SoXXiLGUqPi1jbO79n4zPoYmwdb+va/v9m8ftC7PRoT8qjdEmMCQPqdu1Bn1KweXR8HuPAacZmzx6LfnNK0KhZ6TkDijGPiu+mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720770528; c=relaxed/simple; bh=XUwugfCE9Tm+k6GDreopNnOooRbhzsUUDl5CILgTSt4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=on0WoY8qIWJfGGCZUklAxTjJz99JGzqBEBOB+C4Th3hrnXkQ+26xliyB2Rv/I6eps1FmdnO/z4ets7i7GsAUE9uro0cPmUE8lG7XeF/LB7m44ODal5vgzw5T2NQfYd39pgYSfOfBKFyO/P7NlVngTzVzDydHeCbDUNiEAVn18HE= 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.128.47 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-wm1-f47.google.com with SMTP id 5b1f17b1804b1-426717a2d12so10314255e9.0; Fri, 12 Jul 2024 00:48:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720770525; x=1721375325; 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=q2FIO7np3Ivb7Xklcye4ZI+8TK1UL4eZRCnQV0PzGzs=; b=XeK0iemmxyJNXjtLiGhtPP6V92qNJjBGW59sUm/WRjSafaGLS+qMtINEf1CyQMchi7 LTIZ2AAKkTCb9Hc7ToZ9fV4VlFStzZBl+QR5JGB/KK/fQWJ/EwHNCspGLNegv7i2zQLE lQzhGTI7B5Aqx+gx9Lj+jcIqY5dh3cJj2lrAPWELMI+wzytxCTW5fA5x0dydEG0YbZnW pWMxECJxLl7GaSWO6B7zVRlblkwk3yAIplupEapN4aJUxFt6Ehu8svo7KM3P91+8BBZr 4mPo88F9Qnzava0kvrbtQXDgZ6xyJqDaJnnVtllRZqSVviD/tEwwW5+jgK3f9KQ03X4i H5Hg== X-Forwarded-Encrypted: i=1; AJvYcCXVgWZ/4s5PAEIoP9U/NgMzZct5kqg7TlW4uJEdAAG9pK6o0Tmai2UjvVL/oyfZvBiDaHXhSpEv1JAMl6f/gXZBLGuSHQc4hQG0e5QM X-Gm-Message-State: AOJu0Yzlclf0+b9ZABgVTPLyFig1/FFMMhr32PvRLeAyvY1LWTC8MR5s ydi8ulcvzv2LEg1/TPI+lS5robsrG5a6rsT2+QxkkkzqxCqTAlzG X-Google-Smtp-Source: AGHT+IG5b7wTHma6DdXeRHS2MUe1fLAA/3B/ylXxcuC4fkr3T8IthFxiwfaNy3jklpKuHubc+91S2A== X-Received: by 2002:a05:600c:6b0b:b0:426:698b:791f with SMTP id 5b1f17b1804b1-4279d9f3513mr13070895e9.3.1720770525117; Fri, 12 Jul 2024 00:48:45 -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 5b1f17b1804b1-4279f2d74d5sm13532115e9.46.2024.07.12.00.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 00:48:44 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 12 Jul 2024 09:48:37 +0200 Subject: [PATCH v3 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: <20240712-b4-rst-updates-v3-2-5cf27dac98a7@kernel.org> References: <20240712-b4-rst-updates-v3-0-5cf27dac98a7@kernel.org> In-Reply-To: <20240712-b4-rst-updates-v3-0-5cf27dac98a7@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=1793; i=jth@kernel.org; h=from:subject:message-id; bh=dOFoLPAc5U8sFuri/LBq+DIup0Nt+zq+aMLO188sAjY=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaRNuH9ryfz1fJKFQbePZ5p+enemjjXh+Yl0Jdb32zYda qgJrpoj11HKwiDGxSArpshyPNR2v4TpEfYph16bwcxhZQIZwsDFKQAT0RRjZPiW5Rqy4tmzCk1D fVPmx+rbGrddClq8944WH8s84SbnQ2qMDHdsZt9dU2Jhq1xfYr2572nvNYmlV51m6V61+fq5vHj 9dT4A 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. Signed-off-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/raid-stripe-tree.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index e6f7a234b8f6..53ca2c1a32ac 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -73,6 +73,36 @@ 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_stripe_extent *stripe_extent, + const size_t item_size) +{ + struct btrfs_path *path; + struct extent_buffer *leaf; + 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]; + + write_extent_buffer(leaf, stripe_extent, + btrfs_item_ptr_offset(leaf, slot), item_size); + 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 +142,9 @@ 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, stripe_extent, + item_size); if (ret) btrfs_abort_transaction(trans, ret); From patchwork Fri Jul 12 07:48:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13731363 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F7DB1422B1; Fri, 12 Jul 2024 07:48:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720770529; cv=none; b=s9U/PmDQg2unCrO1EOq1V3y2Uc2sTAkfwIAdtSh4RymWZBRyiU97z425dl4QxY/m5oDtm0xCRD6FXINqolrD95jhXVhMRahH/RWMQjf3aiXFAgIfvBzDRidRjynfTapd9kX8+zvD15wjv1av06xWHSArMiQqlPZckp0n4n3TEGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720770529; c=relaxed/simple; bh=Pv3ReBbFDrRzKBp0pYyoWKmnUJmOhSx6MpxIF4C+hpQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mp80OsA5MTuH55TTUTZtzwBCfiKbfiQ9fz02T9cigXsku5ygSs8IMgAPE88LxAyXyo453rsCOKWsQfDRKsVXzeZFBO0uN/p3yasTw4njxmB0VMp4T9NcK8xbB+vdP5lLr56FdRTO1bbgPJnzi+Ff5LTDLDJY0Sv1tIx+xIx/Mpw= 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.128.50 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-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4266f535e82so11111475e9.1; Fri, 12 Jul 2024 00:48:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720770526; x=1721375326; 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=FU/sAo9QXGocL/MbdLgzEi6X9hN6Ia2DdL8qs9+GIJg=; b=qyUMuRqMXR7RDwEHEdwPUkFMQKvNniINnzTLQ7gdiPGOmcby8BogFvzjQA+A4Xp/T9 RtdkutX9VrwDnrycdTsNGi3ezMYcMQxmTicb93B56byoM2kHMPlM19KKS7oXFv8dWW8p d6niVr+2xDcJ9S8yN4H5m9KWe5pv61E8pXHDIVv1m+Sc56//fPVx+/gMeJRIPGPPBoZA R0heq3z+mh0aqzyDq1ul8YrRzpOpx72lmsqqV3Vlkb/OTSnwlYiyxZEPcSXuEWeTFLui Ltk8/1l6u0XxakY9G2o8VNeC7/CML+uTWhUm+Cg7dmigBnRdZOMhCD2/p2tUG7l2Luyg jbCw== X-Forwarded-Encrypted: i=1; AJvYcCXL2sprZa95+zHC+GCCReR+DE8p8scURwInXTQ0ytBOe0ZxDtzueF45h3AEtvA9yiygZbTHEtTi0hCB3fkSz8oeL+CjW71K8RRPYgk9 X-Gm-Message-State: AOJu0Yw6ntm8ipbFu+t/xtjkD1ybt8m9W3oJziJjJN6jzCvgkmvUdop3 BlFn12rkpA1W0BRIzbJinLjil7ibjtpSfEiIKVuygg5gbJdocdhR X-Google-Smtp-Source: AGHT+IEg/QqLkAdxijfiOX8BsO14Gs84p/1C+xuD6t83ahgeXqp7lD6CFmr7NDaqwTvE/2MQbzfvTA== X-Received: by 2002:a05:600c:4c15:b0:425:7796:8e2c with SMTP id 5b1f17b1804b1-426707d8b58mr76198545e9.12.1720770526078; Fri, 12 Jul 2024 00:48:46 -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 5b1f17b1804b1-4279f2d74d5sm13532115e9.46.2024.07.12.00.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 00:48:45 -0700 (PDT) From: Johannes Thumshirn Date: Fri, 12 Jul 2024 09:48:38 +0200 Subject: [PATCH v3 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: <20240712-b4-rst-updates-v3-3-5cf27dac98a7@kernel.org> References: <20240712-b4-rst-updates-v3-0-5cf27dac98a7@kernel.org> In-Reply-To: <20240712-b4-rst-updates-v3-0-5cf27dac98a7@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=1160; i=jth@kernel.org; h=from:subject:message-id; bh=84BxxsaozfQOVybRl0+FKGjleLtGfNGJKDIsOaj3c0M=; b=owGbwMvMwCV2ad4npfVdsu8YT6slMaRNuH/rk2KGq53r6f/b9+xpcj/iFvRg4W2t++xNJib9n wv1F4ee6yhlYRDjYpAVU2Q5Hmq7X8L0CPuUQ6/NYOawMoEMYeDiFICJKHozMuzQXr3y9OxA9i9F fn+7nKJLwhIXm1465v3u2/Hp85V5epYw/K9x8ukJOWTa17RrwhUh3q++iobq2Zx7XiizVNhPsLt wigEA 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 53ca2c1a32ac..684d4744f02d 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); }