Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3548671pxb; Mon, 24 Jan 2022 11:59:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRLRgZQkmJwnglPsweCMx7pZsF/W43iXr+ul6RStC6TshuhafuUMOZF4Elh6gIppkZchzX X-Received: by 2002:a63:b401:: with SMTP id s1mr12949380pgf.313.1643054350258; Mon, 24 Jan 2022 11:59:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054350; cv=none; d=google.com; s=arc-20160816; b=Sxa0Ea8vHgPqKfzdS8HOg3wm8ZOOAYrdPwGej60bHzf1j498Vgy+ZSnmL46uN62BRS Cu1vZS35HumYoBDzkNTk4RDgO2e5C4A5TW3oBDIUWRaNlCeGX8tesY4nb980ssbFBCUm 1X2EUtTqS2FeMOKherf6xMlDMxoJiVJvVEmTyOKpQ1dNskgiuFERbIJ6dZLLlsMBarCx wqaSRghgeHPdjd3hSNIq98iHOTZBkPUbaubEo2WbGhvIQk495bnWwuMDh48RWQUYlMIV LgLUP1DVUFE4OO+4p6PNifCFyFK319zyGz19zyBUt95g32QnQWDkZ4zFdB7lSWOcIEos M0aA== 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=LVo97itYVBV+QKw0NoQ2s/qHeK/FGiQ+wn+Yp1ywm64=; b=gsfPSe3KGRE075kj/TRsa/xJXGoZKEphpgRYZvyJ5pYi5GRgKB9h/jQQDroDmWI09G 9TTZewoM+PDqjQEqlMo+V6WDie7Ej0s1E1DNE1g43kwWI2RQyK80HhnXxsjLkeoq+1rz BQlNenjTzDt0yuD6ZtxHSouovXXhdSwqvNtzEknTzjPtcheuz5sagvG72y2fIR4HVta+ SXMPFUMROc9SrX4Iuw6ZbVK3A8F4OfDbpddTVx6lCTvNW6OUlwTKrmK7C6J4SzWQwwCB m+pDkkWEXKv2vveYb7lEM1DO+JECpYPVofgcyW2UitZHJ8+rKWyl+xt+l9zYjLys7LF7 /4sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PTZmIJ5B; 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 v27si15697611pga.21.2022.01.24.11.58.55; Mon, 24 Jan 2022 11:59:10 -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=PTZmIJ5B; 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 S1343774AbiAXS4p (ORCPT + 99 others); Mon, 24 Jan 2022 13:56:45 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:51876 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343997AbiAXSxC (ORCPT ); Mon, 24 Jan 2022 13:53:02 -0500 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 ams.source.kernel.org (Postfix) with ESMTPS id 387FAB8121C; Mon, 24 Jan 2022 18:53:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43B8EC36AE9; Mon, 24 Jan 2022 18:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050380; bh=sTTgpgmbUcfDJ3e7vQshhsXsvJ02IkzeYILauBlTR2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PTZmIJ5Bm0gP/comaZwtf0CJ/rjU5liQSdl8lSJAEcI0usiv4IdGMQAxfDFLwK4DL MZy2y5Qn2WIWSI4URkSK3b0VTFgSpB/z8Px2BRRD5wNjDgeaS2Vf96HstL/Cb2ZKTZ 80K3I9b6s2mfFvD/1oETTe9TPrEnO+OVeYfdD8+Y= 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.4 100/114] ext4: dont use the orphan list when migrating an inode Date: Mon, 24 Jan 2022 19:43:15 +0100 Message-Id: <20220124183930.198387689@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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 @@ -459,12 +459,12 @@ int ext4_ext_migrate(struct inode *inode return retval; /* - * 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); @@ -485,10 +485,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; @@ -500,7 +496,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); /* @@ -525,12 +520,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; }