From patchwork Thu Nov 6 13:35:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Holmberg X-Patchwork-Id: 123635 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 623EB385DC3D for ; Thu, 6 Nov 2025 13:36:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 623EB385DC3D Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=d7TWaYt3 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by sourceware.org (Postfix) with ESMTPS id 1967D385482F for ; Thu, 6 Nov 2025 13:35:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1967D385482F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=wdc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1967D385482F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1762436152; cv=none; b=xeYEEs3rlwbtcUUSLJf8xr1yEKAM4Ncj4gvvcGsVlRwazIeYu6mTJvtPBsWE7xm0mGPR0WCEIuMHqfLy3giG54qdkGMjL6HuHXJ0f5izBZABlK2oLTYNv2EHAM5D7ZN98UiXlkTKZJjrnFmHZK1Sw2ZbfjA8QaNtFMFXZeZlKPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1762436152; c=relaxed/simple; bh=H9PjB1BOQvcWVXcQuw6Cj0DkLIusSBIbCtYE3cjTE4s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OGYQn1S+5/XFU3le3GGCXPWLYYk1pUhd+fvPjC/IeD3fFcsSQwKe841f45srSh+gyqG/c9H4MKkLmsD21NBTc+dTCVTauHfa1lvcwEnKo0g8+vtwzZmcNEzmhO3z2dxLqRF+oL0XJQwdpYg189yfMtqZJqGUtiNpmHhs88ghLNc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1967D385482F DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1762436152; x=1793972152; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=H9PjB1BOQvcWVXcQuw6Cj0DkLIusSBIbCtYE3cjTE4s=; b=d7TWaYt3aTOK64F49rx5pvvUI/BqV+l/SGtXc44mq1emOh/xzPAczWgy DJRmAlqSkD+69cI4/QgmMeIwZHZwe1/3UqTRWNmTfSV6F0BAhFBjUWMjc dPrBNoerdjxJjPlLlzfx8AtipKPeJA8n9GBgOlBRsuTzOapJvoP86YxOy jtQUeqHjTz+efMP/EjcCpFdbHuC461uo/l+5eA/c8lTsJ8H1+ko51v0E9 I1La7JvfjGHHx0OX+1VacCffGw0FW0cbhaUiu0jvNmLVtsXHKiw1n6D2B leXvmzU9gpZ3i49AiRe8vJjiAAAGtsjdbeFCRyRD1BrvW4A0QuoPVs/Ge Q==; X-CSE-ConnectionGUID: qqa2xLBrQFO7emm4gsmTnQ== X-CSE-MsgGUID: IUMg14APTuOpPH851zRZyg== X-IronPort-AV: E=Sophos;i="6.19,284,1754928000"; d="scan'208";a="134260840" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Nov 2025 21:35:51 +0800 IronPort-SDR: 690ca437_jnnQxMwDNkdXSKqixVCQ1SluP/fW06uQkdtE2URtPvIRAke oo7fkkkMJelcI9JUP4Kn0awJxtUCLY6B6IQz+1g== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 06 Nov 2025 05:35:51 -0800 WDCIronportException: Internal Received: from wdap-elfv1o5mea.ad.shared (HELO gcv.wdc.com) ([10.224.178.11]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Nov 2025 05:35:48 -0800 From: Hans Holmberg To: linux-xfs@vger.kernel.org Cc: Carlos Maiolino , Dave Chinner , "Darrick J . Wong" , Christoph Hellwig , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, libc-alpha@sourceware.org, Hans Holmberg Subject: [RFC] xfs: fake fallocate success for always CoW inodes Date: Thu, 6 Nov 2025 14:35:30 +0100 Message-ID: <20251106133530.12927-1-hans.holmberg@wdc.com> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org We don't support preallocations for CoW inodes and we currently fail with -EOPNOTSUPP, but this causes an issue for users of glibc's posix_fallocate[1]. If fallocate fails, posix_fallocate falls back on writing actual data into the range to try to allocate blocks that way. That does not actually gurantee anything for CoW inodes however as we write out of place. So, for this case, users of posix_fallocate will end up writing data unnecessarily AND be left with a broken promise of being able to overwrite the range without ending up with -ENOSPC. So, to avoid the useless data copy that just increases the risk of -ENOSPC, warn the user and fake that the allocation was successful. User space using fallocate[2] for preallocation will now be notified of the missing support for CoW inodes via a logged warning in stead of via the return value. This is not great, but having posix_fallocate write useless data and still not guarantee overwrites is arguably worse. A mount option to choose between these two evils would be good to add, but we would need to agree on the default value first. [1] https://man7.org/linux/man-pages/man3/posix_fallocate.3.html [2] https://man7.org/linux/man-pages/man2/fallocate.2.html Signed-off-by: Hans Holmberg --- fs/xfs/xfs_bmap_util.c | 15 ++++++++++++++- fs/xfs/xfs_file.c | 7 ------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 06ca11731e43..ff7f6aa41fc8 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -659,8 +659,21 @@ xfs_alloc_file_space( xfs_bmbt_irec_t imaps[1], *imapp; int error; - if (xfs_is_always_cow_inode(ip)) + /* + * If always_cow mode we can't use preallocations and thus should not + * create them. + */ + if (xfs_is_always_cow_inode(ip)) { + /* + * In stead of failing the fallocate, pretend it was successful + * to avoid glibc posix_fallocate to fall back on writing actual + * data that won't guarantee that the range can be overwritten + * either. + */ + xfs_warn_once(mp, +"Always CoW inodes do not support preallocations, faking fallocate success."); return 0; + } trace_xfs_alloc_file_space(ip); diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 2702fef2c90c..91e2693873c0 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1312,13 +1312,6 @@ xfs_falloc_allocate_range( loff_t new_size = 0; int error; - /* - * If always_cow mode we can't use preallocations and thus should not - * create them. - */ - if (xfs_is_always_cow_inode(XFS_I(inode))) - return -EOPNOTSUPP; - error = xfs_falloc_newsize(file, mode, offset, len, &new_size); if (error) return error;