From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387833; b=vk4/LGOLAbD1TJgIN9EzbT14oVj+PXZsVJq3O/xO3OvxrHQJ+kxYt/d4peQ4j54kPMOH wqeVTqJSN/9uWVY3NaKTDXY84BlS3S/e5wOtb0kvfTVeMZJrU8fuDL8vDtFue1yJ3UKJq Nfg7DoPFQvFpx+kpIlZqhDh4gtEc7ZQI73rKxD56YV8ZZ2R5kiP0PMbjnmG9hu1IjeZAW 7qWS9L3XZ+4lGtG54iVksZaWunae82UTONCcrK0vI332HNm/t4GUfTdTzEoHbwpIzbqMV y+2Ebyw0Tgr1m8LYijZDH74zsbYCXV2I8+OYhO1a9zLZEYejOKLcJlvhC/Kb/neFYpA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387833; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=5iNGLjbw3TxyyG/SjIOoMMgjOZLmuos10DVbMH6SAKg=; b=EOZEDpIt6Y6f91XwG2tEmA5WHqY73CmJOPYKU1GG0jeRWakTZNqCFQcIyQOAU+RDOeQf DPJQGK1Cr4dbaLRLw381wjBYrQbv7EsAKHyKnBZCEarh2m/EWPpoZ4G5ZFdYF85Y8h0i9 obsXbBQYCNIWl0YU5qgHNKhm0/u/ZQ+llrYXYvL0SZiHUC/303eXoCCH6qzlWiWRkj6OS 7RMnUNgt2F8K+O83E+Zm1Eb06fbxJ7c1EjnVq6e/t18bW+1dVZfb3VYTLqrk8erOY3jlk QGPdBtMrKWerzLZAtu4I10IfmgGJFoOaOEvPkhT3/33gU6eaw9NF9LOSVXJ31yX346A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=GkC1rBK9; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40BFD606A32C; Fri, 4 Dec 2026 12:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=GkC1rBK9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 582EB1F000CE; Fri, 4 Dec 2026 12:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387833; bh=5iNGLjbw3TxyyG/SjIOoMMgjOZLmuos10DVbMH6SAKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GkC1rBK9h7hXgU1OnjEG1EHGTLOtJmCGHiehtugTBxZQh0487T0I2U+bOM/uy8SMT 07xO9Ymiz9biaSOU+eNS0ZJ4nP+AapaIrds1QbdekV7VzIPNxtlXQJQlksU9vaFfZq H+peUfDgpPUV9q+rR0uWJskXPLAUg+WYWry46aeo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qu Wenruo , Guanghui Yang <3497809730@qq.com>, David Sterba , Sasha Levin Subject: [PATCH 6.1 0377/1059] btrfs: roll back sprout setup after device add failure Date: Fri, 4 Dec 2026 18:58:28 +0900 Message-ID: <20261204100654.055377085@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guanghui Yang <3497809730@qq.com> [ Upstream commit f5166f53b60b4d1ee9957c0baccd3b09735001d4 ] btrfs_init_new_device() calls btrfs_setup_sprout() before creating the first writable chunks for a seed filesystem. That moves the seed devices out of fs_info->fs_devices, clears the seeding state and installs a new fsid for the sprout filesystem. If a later step fails, the error path removes the new device but leaves fs_info->fs_devices in the partially initialized sprout state. The mounted filesystem can then be left with no open devices after the failed device add. Add the inverse of btrfs_setup_sprout() and use it from the error path so the mounted seed filesystem is restored before the temporary seed_devices copy is released. Fixes: 2b82032c34ec ("Btrfs: Seed device support") Assisted-by: Codex:gpt-5 Reviewed-by: Qu Wenruo Signed-off-by: Guanghui Yang <3497809730@qq.com> [ Fix a conflict with per-profile available space, revert sprout before updating per-profile available space estimation. ] Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba [ sashal: Dropped the context line calling btrfs_update_per_profile_avail(), which doesn't exist here, so btrfs_rollback_sprout() now sits directly before the chunk_mutex unlock. ] Signed-off-by: Sasha Levin --- fs/btrfs/volumes.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 04283d3497e5a..4223defd9ca74 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2717,6 +2717,41 @@ static void btrfs_setup_sprout(struct btrfs_fs_info *fs_info, btrfs_set_super_flags(disk_super, super_flags); } +static void btrfs_rollback_sprout(struct btrfs_fs_info *fs_info, + struct btrfs_fs_devices *seed_devices) +{ + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + struct btrfs_super_block *disk_super = fs_info->super_copy; + struct btrfs_device *device; + u64 super_flags; + + lockdep_assert_held(&uuid_mutex); + lockdep_assert_held(&fs_devices->device_list_mutex); + + list_del_init(&seed_devices->seed_list); + list_splice_init_rcu(&seed_devices->devices, &fs_devices->devices, synchronize_rcu); + list_for_each_entry(device, &fs_devices->devices, dev_list) { + device->fs_devices = fs_devices; + } + + fs_devices->seeding = true; + fs_devices->num_devices = seed_devices->num_devices; + fs_devices->open_devices = seed_devices->open_devices; + fs_devices->missing_devices = seed_devices->missing_devices; + fs_devices->rotating = seed_devices->rotating; + fs_devices->latest_dev = seed_devices->latest_dev; + + memcpy(fs_devices->fsid, seed_devices->fsid, BTRFS_FSID_SIZE); + memcpy(fs_devices->metadata_uuid, seed_devices->metadata_uuid, BTRFS_FSID_SIZE); + memcpy(disk_super->fsid, seed_devices->fsid, BTRFS_FSID_SIZE); + + super_flags = (btrfs_super_flags(disk_super) | BTRFS_SUPER_FLAG_SEEDING); + btrfs_set_super_flags(disk_super, super_flags); + + seed_devices->opened = 0; + free_fs_devices(seed_devices); +} + /* * Store the expected generation for seed devices in device items. */ @@ -3032,6 +3067,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path orig_super_total_bytes); btrfs_set_super_num_devices(fs_info->super_copy, orig_super_num_devices); + if (seeding_dev) + btrfs_rollback_sprout(fs_info, seed_devices); mutex_unlock(&fs_info->chunk_mutex); mutex_unlock(&fs_info->fs_devices->device_list_mutex); error_trans: -- 2.53.0