Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp593621lqt; Mon, 18 Mar 2024 18:37:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIUNz9ffxrbnP0Qn6bM88U/yP3CeHUHpfeM56WwA2TKzG45DflEugVy83VI9oLzO+bdPbQswqA7iZeyZ7ZdkDk6oUG8YJ5FLKkqFWiyA== X-Google-Smtp-Source: AGHT+IEHX5Z1RQFLGiP85vVdvuD1o8Cm+A6/XSGVgaXuVJrDmgfpDmdt86th6ks9786sAZlFq3/H X-Received: by 2002:a05:6402:5308:b0:568:93f:36c0 with SMTP id eo8-20020a056402530800b00568093f36c0mr710638edb.39.1710812260004; Mon, 18 Mar 2024 18:37:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710812259; cv=pass; d=google.com; s=arc-20160816; b=jgvBDaeC/eexvEOP+4sMXpJKfbH8+YHT8Xaf8W0EH9CdyWk89NdpSqq1rpobfgtuEl +kLalcsSizFVsSqqLD/5n15tUsUoyflwsf2cCEoOegRdZ49W03OyxWHyBJvKD5gt2kpd IFbdctLiXg29lZe3TmYm8LkuwttlMfIV9dHFiXhHc7Hvh0wZBtyJr3qzkQuznUG3z/7L rCfK1fdsKSIsjNJ2+Rj4ixyqCZ7ayp/K6WMxH218bHVH32sraBxcwN05R/eQKvYQ68QY Lk4wMoxS0lKcGVpgp4anTZ2R2qVQv+qUWdFuFU/X69wVNj0jPeAc3uw+widOG95WnTlV olGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=f0fyGdLMdqAt62Mj3i8YvssVjW8nym8BokCsl0P0et0=; fh=5dB93T9RUScPXiJBPgMY9ddAKXpKWIKqxrLOkZR5g5k=; b=SxYfSpTLP8ZpSrZi4yJsnxdps3jn6FMWiRyvk9Vau/e2owqHLJfOVp6C8GJGERTREW I3zwr6t3A+aW3yB2mvt/CdIQVs9efOEhkSdV6bpfoKrkKVXPuHBrr68UF9qMBr0TAtd7 8tO7KdjDQe3Bwap3r8aXrT7exf7EZxcgL1cYDT9DguTagB0QiJjuPTGcr1rMdsHxXp2C 7mcLi28+SA0kpeOA8rIeJ8VXNmrRAvmt2egZ04r6WCq0QENRVje7TkaKZ58XtS9P8ny3 DLbNFoRsRyYa9KZWV/Z/ECch0Jndb5OkFlFxyWZEepI2kXGuqcTxe33lxlarXQwvv/de aPsw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-106891-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106891-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 2-20020a508742000000b00568d7b60bf4si1763373edv.601.2024.03.18.18.37.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 18:37:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106891-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-106891-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106891-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8FCBF1F21292 for ; Tue, 19 Mar 2024 01:37:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC1A965BDD; Tue, 19 Mar 2024 01:36:21 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD57B62818; Tue, 19 Mar 2024 01:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710812181; cv=none; b=RaOtC8MN07SSsiOvE1EUSpIaSG3pzcO6MtPVipRXtTBFBs2PQHiZsYXpzu7YxtWjHohDbgcDOr6hobBMyd3cHQNhObfaopV5lhM/qrsGtqyJIQM9WvAvK8dfTgqMYXLmtq9WsUC+lt9pIWLj474QjckS1DF/q963mPuKCc7XH+A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710812181; c=relaxed/simple; bh=PdlNcyW+Li7wLZBFFBCsK66gTN9+ABo4TkwldkPTvEk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IK1RWMoA19jI3oNsFjmGXjm+bUZoQlfc2ksSpmZ36YEtHNV0YGQXu72cBZ56n+uHramD+E2YQN8137DnyRuNATKBhqPHz3tQ09POLuML+5zsO1V4r/R4PPMVeu5RPqaC69/x56XzJz3edgY3RbYKxYZNlbiTP2zp9zDISqmF2Os= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TzDPd63SFz4f3kK8; Tue, 19 Mar 2024 09:18:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A92461A016E; Tue, 19 Mar 2024 09:18:33 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g7O5_hlUIGNHQ--.34497S7; Tue, 19 Mar 2024 09:18:33 +0800 (CST) From: Zhang Yi To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, tytso@mit.edu, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH v3 3/9] xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset Date: Tue, 19 Mar 2024 09:10:56 +0800 Message-Id: <20240319011102.2929635-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240319011102.2929635-1-yi.zhang@huaweicloud.com> References: <20240319011102.2929635-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAn9g7O5_hlUIGNHQ--.34497S7 X-Coremail-Antispam: 1UD129KBjvJXoWxCr13tw1DAw48AF1fZrW3Awb_yoWrCw4UpF Z3Ca43GF4qqw1rZFsayF10qw1Skw1xCFW8KF43Wwn7Z3yYvr1fWFn2kF18u34Ut3yfZ3W2 qr45Aa47Wws8Za7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8Jw CI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUojjgUUUU U X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Since xfs_bmapi_convert_delalloc() only attempts to allocate the entire delalloc extent and require multiple invocations to allocate the target offset. So xfs_convert_blocks() add a loop to do this job and we call it in the write back path, but xfs_convert_blocks() isn't a common helper. Let's do it in xfs_bmapi_convert_delalloc() and drop xfs_convert_blocks(), preparing for the post EOF delalloc blocks converting in the buffered write begin path. Signed-off-by: Zhang Yi Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 34 +++++++++++++++++++++++-- fs/xfs/xfs_aops.c | 54 +++++++++++----------------------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 07dc35de8ce5..042e8d3ab0ba 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4516,8 +4516,8 @@ xfs_bmapi_write( * invocations to allocate the target offset if a large enough physical extent * is not available. */ -int -xfs_bmapi_convert_delalloc( +static int +__xfs_bmapi_convert_delalloc( struct xfs_inode *ip, int whichfork, xfs_off_t offset, @@ -4648,6 +4648,36 @@ xfs_bmapi_convert_delalloc( return error; } +/* + * Pass in a dellalloc extent and convert it to real extents, return the real + * extent that maps offset_fsb in iomap. + */ +int +xfs_bmapi_convert_delalloc( + struct xfs_inode *ip, + int whichfork, + loff_t offset, + struct iomap *iomap, + unsigned int *seq) +{ + int error; + + /* + * Attempt to allocate whatever delalloc extent currently backs offset + * and put the result into iomap. Allocate in a loop because it may + * take several attempts to allocate real blocks for a contiguous + * delalloc extent if free space is sufficiently fragmented. + */ + do { + error = __xfs_bmapi_convert_delalloc(ip, whichfork, offset, + iomap, seq); + if (error) + return error; + } while (iomap->offset + iomap->length <= offset); + + return 0; +} + int xfs_bmapi_remap( struct xfs_trans *tp, diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 813f85156b0c..6479e0dac69d 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -233,45 +233,6 @@ xfs_imap_valid( return true; } -/* - * Pass in a dellalloc extent and convert it to real extents, return the real - * extent that maps offset_fsb in wpc->iomap. - * - * The current page is held locked so nothing could have removed the block - * backing offset_fsb, although it could have moved from the COW to the data - * fork by another thread. - */ -static int -xfs_convert_blocks( - struct iomap_writepage_ctx *wpc, - struct xfs_inode *ip, - int whichfork, - loff_t offset) -{ - int error; - unsigned *seq; - - if (whichfork == XFS_COW_FORK) - seq = &XFS_WPC(wpc)->cow_seq; - else - seq = &XFS_WPC(wpc)->data_seq; - - /* - * Attempt to allocate whatever delalloc extent currently backs offset - * and put the result into wpc->iomap. Allocate in a loop because it - * may take several attempts to allocate real blocks for a contiguous - * delalloc extent if free space is sufficiently fragmented. - */ - do { - error = xfs_bmapi_convert_delalloc(ip, whichfork, offset, - &wpc->iomap, seq); - if (error) - return error; - } while (wpc->iomap.offset + wpc->iomap.length <= offset); - - return 0; -} - static int xfs_map_blocks( struct iomap_writepage_ctx *wpc, @@ -289,6 +250,7 @@ xfs_map_blocks( struct xfs_iext_cursor icur; int retries = 0; int error = 0; + unsigned int *seq; if (xfs_is_shutdown(mp)) return -EIO; @@ -386,7 +348,19 @@ xfs_map_blocks( trace_xfs_map_blocks_found(ip, offset, count, whichfork, &imap); return 0; allocate_blocks: - error = xfs_convert_blocks(wpc, ip, whichfork, offset); + /* + * Convert a dellalloc extent to a real one. The current page is held + * locked so nothing could have removed the block backing offset_fsb, + * although it could have moved from the COW to the data fork by another + * thread. + */ + if (whichfork == XFS_COW_FORK) + seq = &XFS_WPC(wpc)->cow_seq; + else + seq = &XFS_WPC(wpc)->data_seq; + + error = xfs_bmapi_convert_delalloc(ip, whichfork, offset, + &wpc->iomap, seq); if (error) { /* * If we failed to find the extent in the COW fork we might have -- 2.39.2