Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp650022iog; Thu, 30 Jun 2022 07:40:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tTD4U/2LZVAdvpGPv2nBjS7rnsV0d15wMwdSOqjWKbDiFrPW+7HQHVzNhJuEyjQx8lEwE/ X-Received: by 2002:a17:902:c101:b0:16a:11e9:a485 with SMTP id 1-20020a170902c10100b0016a11e9a485mr16028248pli.29.1656600044324; Thu, 30 Jun 2022 07:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656600044; cv=none; d=google.com; s=arc-20160816; b=taMalMGaA/tgKqfaTq3/WTrdLW/E22P0zwP6mazBQVBuKVW8inRhEjHiUS1zfM7hgF jjnto/F53rT4YS14pcO2IRxxdQZ7KZzgWDPiG8ciUtk0nCP/sN5bWmeJ1fAXm7Y6sn3T gZHQ7cmg7OfIXkZVg2p5FNQPgb9WZbotabvGm0ly32qvYllAFx2SO4KSI5+jmEv+R8Xv klSYvLmDMM6rjlYQEpy7vi4xr27FpKp14PSdijkzy8HX0U/I1dx6si+atraVcytKje3/ /mD7l4ovcctQpI7x+7h+V4pQkZhKqltrXerIHWkgEopArwj/uI+EZw3zE15Z43urzbuI kT4A== 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=Ssz1RO0HOf0RwrHF4dV4sZT3Z4i/ag6w2cr+ETl5Cr4=; b=qmwmfoOyYnHvZt2leTHlbcthHMV36FN9rS+YuRJP7YBP4nfB0vlJfP2/YrGH+ABY/T h+UQxIQ5atLabrFNlxRkDiFXyMLZCAQ+pB5rSYGI/iKENVBPwJ20q/yPGKgcZaGHZ/72 er78YpnnwTjSTk6EpZ8xa6YjpCaWTD56+AHRkwr3BR7m1mKIbu2nwl1XR9Ny3/299Hh4 LI2s2Bs+tt01sa38LQmiFaLZA5ZdaxykNIYVTxTgbXPZmwrPa4fIvEBDNy4skb//iLog k5jkPcPQwzsXrnUvt/lNg5ErbD8liwc/SYnbbBzx5uEXilGU6YGjAD8iw4yHv4/4krTM pH2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I48QhDJ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oa18-20020a17090b1bd200b001ecb608ea41si3339022pjb.167.2022.06.30.07.40.32; Thu, 30 Jun 2022 07:40:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I48QhDJ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236687AbiF3OIn (ORCPT + 99 others); Thu, 30 Jun 2022 10:08:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235377AbiF3OHC (ORCPT ); Thu, 30 Jun 2022 10:07:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B4DE4D163; Thu, 30 Jun 2022 06:54:24 -0700 (PDT) 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 48813B82AF4; Thu, 30 Jun 2022 13:54:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93668C34115; Thu, 30 Jun 2022 13:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656597257; bh=y7RjIpPTJdsuZnRv738o0NqQH+oYqZEghea+VF06qW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I48QhDJ1kVd1ydGdQ6FmOnu4RIPBaprmOpbIRNFsEjuXlcth/LAZFAdJcpC/ubT4D caZ9qL9y9Audzq5GOMUriv8jzIEDAhP99AfhPly10vQuKYrgjhV5lQwfl1IND2HOxv 5bT93Wa+wsTbPOI6rdduWyj/fRuitK2bbRQvM6/w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , "Darrick J. Wong" , Amir Goldstein Subject: [PATCH 5.10 07/12] xfs: punch out data fork delalloc blocks on COW writeback failure Date: Thu, 30 Jun 2022 15:47:12 +0200 Message-Id: <20220630133230.906794591@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220630133230.676254336@linuxfoundation.org> References: <20220630133230.676254336@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brian Foster commit 5ca5916b6bc93577c360c06cb7cdf71adb9b5faf upstream. If writeback I/O to a COW extent fails, the COW fork blocks are punched out and the data fork blocks left alone. It is possible for COW fork blocks to overlap non-shared data fork blocks (due to cowextsz hint prealloc), however, and writeback unconditionally maps to the COW fork whenever blocks exist at the corresponding offset of the page undergoing writeback. This means it's quite possible for a COW fork extent to overlap delalloc data fork blocks, writeback to convert and map to the COW fork blocks, writeback to fail, and finally for ioend completion to cancel the COW fork blocks and leave stale data fork delalloc blocks around in the inode. The blocks are effectively stale because writeback failure also discards dirty page state. If this occurs, it is likely to trigger assert failures, free space accounting corruption and failures in unrelated file operations. For example, a subsequent reflink attempt of the affected file to a new target file will trip over the stale delalloc in the source file and fail. Several of these issues are occasionally reproduced by generic/648, but are reproducible on demand with the right sequence of operations and timely I/O error injection. To fix this problem, update the ioend failure path to also punch out underlying data fork delalloc blocks on I/O error. This is analogous to the writeback submission failure path in xfs_discard_page() where we might fail to map data fork delalloc blocks and consistent with the successful COW writeback completion path, which is responsible for unmapping from the data fork and remapping in COW fork blocks. Fixes: 787eb485509f ("xfs: fix and streamline error handling in xfs_end_io") Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Amir Goldstein Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_aops.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -145,6 +145,7 @@ xfs_end_ioend( struct iomap_ioend *ioend) { struct xfs_inode *ip = XFS_I(ioend->io_inode); + struct xfs_mount *mp = ip->i_mount; xfs_off_t offset = ioend->io_offset; size_t size = ioend->io_size; unsigned int nofs_flag; @@ -160,18 +161,26 @@ xfs_end_ioend( /* * Just clean up the in-memory strutures if the fs has been shut down. */ - if (XFS_FORCED_SHUTDOWN(ip->i_mount)) { + if (XFS_FORCED_SHUTDOWN(mp)) { error = -EIO; goto done; } /* - * Clean up any COW blocks on an I/O error. + * Clean up all COW blocks and underlying data fork delalloc blocks on + * I/O error. The delalloc punch is required because this ioend was + * mapped to blocks in the COW fork and the associated pages are no + * longer dirty. If we don't remove delalloc blocks here, they become + * stale and can corrupt free space accounting on unmount. */ error = blk_status_to_errno(ioend->io_bio->bi_status); if (unlikely(error)) { - if (ioend->io_flags & IOMAP_F_SHARED) + if (ioend->io_flags & IOMAP_F_SHARED) { xfs_reflink_cancel_cow_range(ip, offset, size, true); + xfs_bmap_punch_delalloc_range(ip, + XFS_B_TO_FSBT(mp, offset), + XFS_B_TO_FSB(mp, size)); + } goto done; }