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=1796385057; b=ZEe8bQI1Gn0SEmDJkJkCQ8bhL2FCmYruhR4ZkHAQeAM/VDe0Fkvwa69rJgWFdZ2X2UyW FCDL40Gd0/2hoB7CkCK+/8afEWy9f/IB8vs9vQEILAsqGhwrfaocgpw26g4dBJYy/0wWk FNlKLzaFC6wsM0R7wSFomqqg/JALCg7oD6mJVWhPEyFKqR+0u/O+KLbwImnEiTdhEa1Do JtIzY6qQuDCFZpQknhsaSAgc5maV8r8ABXoqDZIkMzg74sR79ELhvE5OmHFq65LxY8XSp GwX65iGMVu1ehDOWvjP6AMEr7A6vNRBk8Fjz9jzjPXPltB650+B7uQszf/H47Y4LE6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385057; 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=gXQndvkxcqdop//lKIS8FMZVkF3JiDcIV97aJ70+ZHs=; b=bcEbvwGHq1GvW9sg/Kdz+M/1KTNLUlRSA4uIaIJyIdwDxppS9Ihe21274MlKGOVhtvQd iCCpAM/xmIAzfbopxzuYwNfTYUk92FTfkTe06YkdUMLDm6E4559ZNNm0lrU95tNjejHQl Mvd9Ypfyjk09eEPELhLMRo5qrnrGM75k6VEwJsWwrwajslODwV+L4JEct8FYENjDU2H8x Qreeam4cxPyd1REmeyRU3LLnyOMWj7Vypqcsna3Zfa5PGNAmCCTF9xdCoLL8UgrZzudW1 Dpb/fG+sPIbwmb0oMcFPpZEN82bbG/8uuGumSz7P6LWo90ZmXqLrjCf0FmggBQPRSRg== 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=ATQY1mgD; 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 CD419606A322; Fri, 4 Dec 2026 11:50:57 +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=ATQY1mgD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44DBC1F000C2; Fri, 4 Dec 2026 11:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385057; bh=gXQndvkxcqdop//lKIS8FMZVkF3JiDcIV97aJ70+ZHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ATQY1mgD1cpjX/iZnq9qpsi0+NTycJgjJeWzeLwf3onXNFabxpzTSA/3zzV1nHaPy R6if+VtE4aUe4x75ywtT8SgM/UQs4yVmtBJf6c9UzayL/TrfaMiCSxBt1BC09c3fqw 4VKi0RHLl370PMjMsIMwlPdyE6tBKcz7Q8Dw1wCQ= 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.6 0400/1167] btrfs: roll back sprout setup after device add failure Date: Fri, 4 Dec 2026 18:57:07 +0900 Message-ID: <20261204100712.445172752@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 btrfs_update_per_profile_avail(fs_info) call and its context line, since that helper doesn't exist in this tree. ] 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 626f6aa5ef2f3..1c2df0e24350d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2696,6 +2696,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. */ @@ -3003,6 +3038,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