Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp655753iog; Thu, 30 Jun 2022 07:47:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vhD12QSUz9DhBi9hGedqrij7hS2uJg0PQ0f9Sp7hE7lecP/0SmbKyFuY+7CiQQl5Wwn3hb X-Received: by 2002:a17:906:ae0f:b0:726:32b3:17f4 with SMTP id le15-20020a170906ae0f00b0072632b317f4mr9563453ejb.116.1656600474123; Thu, 30 Jun 2022 07:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656600474; cv=none; d=google.com; s=arc-20160816; b=z4h3OKx8LlREuOjepPNMGVLXU0U9gAjTC7ySG2tbYNcPojIjbmJDvn+qj4By2uz8dC 0iLW+3vh1cS52D5PYgDR8F0B2BamhClobqO3dKHFEQTrHZMn4WVo+/daWYk3gQhl3NYM HzbgyZVfqSzFqzGDYvVqUYUZZpz/Z+4ooBdGT5hfVL6G+gSTvyuNVd6LL5ZaTz9Qrh18 tZyWl0EWvs4zTsOEwN3snx0/HZaSRey3fJm2Ywc6J13h7da28rgxL2ZegVEhokxFFRJp AeRcSd1yhWDRU8LQYt3mpr3rZ0N2xTy/ilsNR3CwYrSY4LC2nVm9j4cyq3lqsUuslQPX RKZw== 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=hs5PZbcE0pwdfm64MNlvF4cKOOQ5tLFeMI6Uba2uWRA=; b=KhiVlpipN+BwllkdU3UNx0QxlRVlTfwuEsAyTjeY3ciq9JN480ANhlWXf2GyYGYR1X fwnzWfsyU8RWzbXoTnovDVqDM83tVRZRMTxYXG4XGEawMnn0UkhVU0JBqVvnYkBBP9o9 9FmWxlKRVrP9skz+4TQubh11nufrxWtoXrFAu29RF6p6OlO3FUuMljVPi0QJRQtrnzVB fs3rI5wkejmnpGH2ZFYK0uTr9fE2iHBwRqK6ymtHjBmEhTTEIr3yvQN3iUSwxZiELSto 0SN2vkhUAtLXfuZtkK+8SkDign2shZn+zuUUeiLDnAFS21o9pg9f3yFS4c4UNQUPGDOo 5GEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RFj49F1E; 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 m14-20020aa7c2ce000000b00435d8e8923dsi18709708edp.469.2022.06.30.07.47.29; Thu, 30 Jun 2022 07:47:54 -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=RFj49F1E; 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 S236735AbiF3OJc (ORCPT + 99 others); Thu, 30 Jun 2022 10:09:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236960AbiF3OIA (ORCPT ); Thu, 30 Jun 2022 10:08:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D461076E9F; Thu, 30 Jun 2022 06:54:55 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5557862124; Thu, 30 Jun 2022 13:54:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB9BC34115; Thu, 30 Jun 2022 13:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656597292; bh=JQvFxHlyvg7oC1HqZzzyFGMHYaktl60NzjfZoKfqJ/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RFj49F1EfDDffgsT/ymXpreYbWaeTjy4sgnCYC2DFRkRb9UwCuUIx4wcU12RVMhfa 0JzAtGzLQ/6V/6Gb3b8WtFFVCxdXvfjC57ZJ4G9NRe4VneJ6eXY7rUdu6+p0EDZYzD FLU06q74344pnNLws+CeKxaIaAmR0RT30AokPFDA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Brian Foster , "Darrick J. Wong" , Leah Rumancik Subject: [PATCH 5.15 06/28] xfs: punch out data fork delalloc blocks on COW writeback failure Date: Thu, 30 Jun 2022 15:47:02 +0200 Message-Id: <20220630133233.113538634@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220630133232.926711493@linuxfoundation.org> References: <20220630133232.926711493@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 [ Upstream commit 5ca5916b6bc93577c360c06cb7cdf71adb9b5faf ] 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: Leah Rumancik 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 @@ -82,6 +82,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; @@ -97,18 +98,26 @@ xfs_end_ioend( /* * Just clean up the in-memory structures if the fs has been shut down. */ - if (xfs_is_shutdown(ip->i_mount)) { + if (xfs_is_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; }