Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3580438pxb; Mon, 24 Jan 2022 12:43:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwO8Kx8B6CSQqEFNUcmPUWv8lo1o//ffkjd3pteFGDnrwhRW3tGR/oIU2VefMGmH9TA5URV X-Received: by 2002:a17:90b:1883:: with SMTP id mn3mr14545pjb.153.1643057011572; Mon, 24 Jan 2022 12:43:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057011; cv=none; d=google.com; s=arc-20160816; b=iu/SUwhktXlVVDTUS6c9QNCANdn2Kz3m+RRqHwhc4ZsnNUhxhUkHdLNg9QS3NciqMo BqYA0xLrAfX6JjDmc4MUPS/ozHzYUs0uK2EkBFWfu9qCivOKB31ZMAMvJpiFTCdnzk7Q 2KGHvslI2qPJ2Y/Kk5ZYNsw/yslbWrKTrTpXVe/QPUMsIQOzVvRf0Vd8KoYhjQfbS2ch OJjaMP9cU/anG2Vl01DXd50G6+oa5TPT41Zsk3RQsi8HZSudBv3lPRZbaeSucxpUeKof AcBjXYTdTdz/dz7NP+GEuaYt6wlhn15Agz7qawBdxQeYlBm5u13ZcxiqFrQektvaIFVN Eirg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3fl1X8hizpao+n64cdDMSmXE5Shl43kyDiTn/KzmzS8=; b=ZpevGgyzlKWIz9rDWTkgpuNp5nb9ZNiB0GbVIx63/RpF+KiNpivtCu0Dymn3C0N2f7 AsTMVBVYQOx05JzHJrYTAkm7/eyzRP5arnMHsJnw8jr4BesvswE4/OxJg6NI304jpMmz jJ79L8weesJ5zPlSe4gRwNYI3KKyATnohEHHbHzhzxY/AEYm+g5j4bPfTIt0YN9Rt3FF 3r+MHnF3sjpvRfiJ6bEmTRY6e5r0/Sk3mrWOCnfvT3379Q1s0aKz67wMzZtALPDhSX/i UbFZfOifKOADJhFpx6K2yq/CEWhGOonuVRRUGs1Xq6+PDR1ANPo60bnVveRhdlbo/RRK 1uZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=13JPWYd2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x15si6521618pfd.329.2022.01.24.12.43.10; Mon, 24 Jan 2022 12:43:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=13JPWYd2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352813AbiAXT5h (ORCPT + 99 others); Mon, 24 Jan 2022 14:57:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356113AbiAXTpR (ORCPT ); Mon, 24 Jan 2022 14:45:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90AD7C02415F; Mon, 24 Jan 2022 11:22:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2FD86614AA; Mon, 24 Jan 2022 19:22:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BF7EC36B0C; Mon, 24 Jan 2022 19:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052157; bh=Rx8dchfiegJrJJRwYhJBopyQhGvxJQNkEZe4Sd9hbbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=13JPWYd2FLiGj+nz4W6ZLu8KEGdAtmDk5VXl3903os+ioVt64T9ZlpzB9+pAYBu2g OUXuRPZZifYmmRljrCxYyA2xST7Qaq2qTqA0GA4a5vb1TRzj+j8dD3deZnevMfkjdt Je0/kVE0NRfm0rIOuRVbJnZOrWqoSPLHpXNymHTo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Lukas Czerner , stable@kernel.org Subject: [PATCH 4.19 206/239] ext4: dont use the orphan list when migrating an inode Date: Mon, 24 Jan 2022 19:44:04 +0100 Message-Id: <20220124183949.658666774@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Theodore Ts'o commit 6eeaf88fd586f05aaf1d48cb3a139d2a5c6eb055 upstream. We probably want to remove the indirect block to extents migration feature after a deprecation window, but until then, let's fix a potential data loss problem caused by the fact that we put the tmp_inode on the orphan list. In the unlikely case where we crash and do a journal recovery, the data blocks belonging to the inode being migrated are also represented in the tmp_inode on the orphan list --- and so its data blocks will get marked unallocated, and available for reuse. Instead, stop putting the tmp_inode on the oprhan list. So in the case where we crash while migrating the inode, we'll leak an inode, which is not a disaster. It will be easily fixed the next time we run fsck, and it's better than potentially having blocks getting claimed by two different files, and losing data as a result. Signed-off-by: Theodore Ts'o Reviewed-by: Lukas Czerner Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/migrate.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c @@ -455,12 +455,12 @@ int ext4_ext_migrate(struct inode *inode percpu_down_write(&sbi->s_writepages_rwsem); /* - * Worst case we can touch the allocation bitmaps, a bgd - * block, and a block to link in the orphan list. We do need - * need to worry about credits for modifying the quota inode. + * Worst case we can touch the allocation bitmaps and a block + * group descriptor block. We do need need to worry about + * credits for modifying the quota inode. */ handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, - 4 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb)); + 3 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb)); if (IS_ERR(handle)) { retval = PTR_ERR(handle); @@ -481,10 +481,6 @@ int ext4_ext_migrate(struct inode *inode * Use the correct seed for checksum (i.e. the seed from 'inode'). This * is so that the metadata blocks will have the correct checksum after * the migration. - * - * Note however that, if a crash occurs during the migration process, - * the recovery process is broken because the tmp_inode checksums will - * be wrong and the orphans cleanup will fail. */ ei = EXT4_I(inode); EXT4_I(tmp_inode)->i_csum_seed = ei->i_csum_seed; @@ -496,7 +492,6 @@ int ext4_ext_migrate(struct inode *inode clear_nlink(tmp_inode); ext4_ext_tree_init(handle, tmp_inode); - ext4_orphan_add(handle, tmp_inode); ext4_journal_stop(handle); /* @@ -521,12 +516,6 @@ int ext4_ext_migrate(struct inode *inode handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, 1); if (IS_ERR(handle)) { - /* - * It is impossible to update on-disk structures without - * a handle, so just rollback in-core changes and live other - * work to orphan_list_cleanup() - */ - ext4_orphan_del(NULL, tmp_inode); retval = PTR_ERR(handle); goto out_tmp_inode; }