From patchwork Wed Oct 16 10:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13838091 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 CB2CE2076D2; Wed, 16 Oct 2024 10:04:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729073059; cv=fail; b=fQiu+56I9x9CW1mIcJWInlpfBucDgERKzmUla5+Rw3trtAXCmIOQAzeWbFU98I8u5XIAXwQndzGX7bfxGQllXK4AswsrfsAfOxOwpmk0aBntdIlhvJIcpjheqjiDqkMfR7BUOIe6BVyR+Cwgorz+UNYqZBeD0eOxVFxm+QlycIU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729073059; c=relaxed/simple; bh=MXdRBkt9h4k25bBTYZJkua5Ybydsg5IdV4X7V2w97IM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=bQAHNyvmVn6nW/PrAqe137iDhJCwKL+WDkhOu+01Mzobfk4VwXy4jvYOulaNiCizr9r+QnA4Jh+tRe0FCBgWO/4ZzYPSVVDKJcqEAShFscABmM6c3TKQkyHHUjU1D/eVSnnx04UH8qHHmZwqDHZEx03B+g9bkh4wyaLiuGIusQY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=inMiyFRi; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=R3T7EMBw; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="inMiyFRi"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="R3T7EMBw" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49G9tesu008711; Wed, 16 Oct 2024 10:04:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=tf4u8+QC/LEyz3zn6cGEP9PhoikUK4o8XoflYwEC1ys=; b= inMiyFRiD5NrLIZLkgJ8cXu6QwxHfxTWoheqqwWu2+8KMyvhf4ssvA3wR/DBr7T6 7yXybDU+iKCtJXuRMb65asEpzeHA86tAaLORi345Lvmjky3T/CRntz3JgtnEbtUO gEDPwTDWc0CxOuMnhRH2VBExsk9lkrVxfcLziPy0ORF029+3Yxjc2zi1Alqpohhy ysz70IRWzg3eIrkdYI+gpIC6/UItoSYesL/doTWpCRQK7btx99uLQn7+VU+puJMB 72xrhBMtDnfd+yc4mfiTFQBAjuoO4r6mxd4QMRRWwcLXkCjVpaPK3/zZN+/CH1LE JRSRPXZpkbrPBEzNPiUv4Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427h09jv3x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:04:02 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49G9xbO3026283; Wed, 16 Oct 2024 10:04:01 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2172.outbound.protection.outlook.com [104.47.73.172]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj8mhss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:04:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yhP1CK7aur2TD7L2Zfk1vS4W8TYws/R44htLIvpdb1XE8DElhKH5n8MnFr8YTPngKS9/By3NoyzTACEfgOm4WZHllnmiB+e2s34FaKhCNOpZY3z3CA3yoV3KwP9V9b07aDUNiQY4oT+LWqtTuvI6yo2sYciqipDM5g8IbkgkBLIastKMT2smZkg2Umr5D2nzHt9tjXcrBQFWBxbY7GVPyYxGw2xUhs8Z2F5jXZ0WkSkgTGbtJhCrLeQZiklOUxkQabICu+rt2sSET8Ixcenu3bdp6RVnEW+qnsI3w+a8P7/DZkVCSfcgoYu00SBTpSOWKw6i9Rlm5BuzUSb+kKuGQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tf4u8+QC/LEyz3zn6cGEP9PhoikUK4o8XoflYwEC1ys=; b=O88UPvq9fkBPRJ8hzyIndNebIwiDoyF6as8k9dMCjlPmqFI95kCqlXE+ON5FvioOyitL5Hjr8gO87vXEG8yXf/w6V2gygGVS9eLo1i0zqa6WBey6FzyD4KpTlLpiINCNsgT4lR92QKnx1ZhDwYr7mgItPSTh4ZJkUmBBPVtydvcC2iAXwK6qyoRGvjxo6PHn1g3N97BJ+jl7b/lmSql1HdlGKr9qxd5UsX7QljPQS0nlWb5/PQS8QaCtVvzxBTcDX+CeNYxUeo06j93GrGsb9cYGnTUlZyQfQ4+eQHjdqUoT1tCwgVyzMi4F4pb7drNP4ZkM2HGt+DcYntukSzdAJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tf4u8+QC/LEyz3zn6cGEP9PhoikUK4o8XoflYwEC1ys=; b=R3T7EMBwxnWgEmRqTu7I3RJcENS5+aK+EqPPfTMHyvlPc5MH5iHEnEYtdUNU6+Qh1CvjUfkR1VXXGRk+H7ODYXzn1WJSnsRBSZLp65j5LBOJ7yf/eaKliZDFYyo5HWFFuRcJSaHy9yyut7kXXuBn6/+gXcGZdJ1bG4b+Yl5L+HA= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CY8PR10MB6634.namprd10.prod.outlook.com (2603:10b6:930:56::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Wed, 16 Oct 2024 10:03:59 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%5]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 10:03:58 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, dchinner@redhat.com, hch@lst.de, cem@kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, hare@suse.de, martin.petersen@oracle.com, catherine.hoang@oracle.com, mcgrof@kernel.org, ritesh.list@gmail.com, ojaswin@linux.ibm.com, John Garry Subject: [PATCH v9 7/8] xfs: Validate atomic writes Date: Wed, 16 Oct 2024 10:03:24 +0000 Message-Id: <20241016100325.3534494-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20241016100325.3534494-1-john.g.garry@oracle.com> References: <20241016100325.3534494-1-john.g.garry@oracle.com> X-ClientProxiedBy: BYAPR05CA0070.namprd05.prod.outlook.com (2603:10b6:a03:74::47) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CY8PR10MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: dd159a0f-1093-4cd3-3fb2-08dcedc9da63 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: LPXFMhGlJ5Ic37uU0finfHiPTQnErR+frXtP4gJ5x6VlHdGz9tGoQfGxT0gwuma8SwgLS5KVzzV8Ygxj4C2cjLIGJn5OnCKlhRCzCUDa3PcuXywC+LXb8PFNtRiew6L4pgiJiJ2p+otMdmyzSgfzlsMgeYIkh+s8PviW/TrYiwqskDCKIx5nKd5BCXD3M3021VzR1np0pZ72mn+YM/d2ssLWBYOFfSCGY8NcXhT83lLRLJcBlRXSrtC7PMOdjs1IpJjcKDdkglg7+NVAXGz65T5aFewdLapC1VwgEFP627/tXnDIDMdA25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KOmKk1JUGam/81nMr4ZTeNuQ6SHFDG/EvVuYmeTypFEC1VynEdgrRYIPZPSsJVMDjPhSVkJV3wSBIWE68RG+x/ZN34UNapnmqYnfEXwO59ho16V+bzVgXRJHz3fd3dFVDtQG1ccUbt7o+v20gY9Ixaf81kWAFN03KadsdwZ9y/u3+zWJbcsOSPw/ZF9sD/U2oTwBK2r+ENAual0fyWRLLXBqxGzhpWElfX7bB5dDY48cXkttm1X1qjdfwDnLJztpkIh06MYDIdqz1KcQu5EO/fDDuVJjgHCOoqpSKSXegg8Utn1x0DB5UR+WvIPsUPa2bEJPsBmUQIDGNNhqx5gzMCru+LTcYoqKpv9R98ddwMU3216sO3Z0iDhHdwoi0oKc39cAufvcDfwaPoOwdrOsyWVySioKPbZk5atU0qB2BxRaM8UZYTusIKNwP6FkWYf6tuouXutBLEENkrER3XYJv/nA2av+OjujqVlGRyT2ManbBnOyIY1QbpEtYHIwMpbHaK2e9Svoe8/zk3sseHooyAPFNMb4erJ8hWk2jIqUCUy9WgJc9no/T0PBRHu0AE4el355+q86XPTHD4dZJDsF4suMWQX/q3AYJJ8jSgmcFFyRYuDPIF9ED5luglLF66t/1SnMFsGnwzTkjcac5Gg30p4pEK/8Fi2odarIc6u4zJWBoj0OZpjTw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 8NnoK0STg2PyOhW4vNHAch86OWXS+GofjycGzqUv8pLtmDayCCvaD0OFiLkaYoLiRMV+5oB1G9gylSAAq61rq+sEnc7efJlpIopIYr5DSGjKm5paiphH92MrgzU8hDWoKmiYa4Jcl69EKPfrew4pdlylQYqlt6D0/KMS5SMwAE+1XqKbZXd7aNUY6rZwZ7dnOqyMRqlAw32H8S7gxZf/5DwmMO6OaSj9BgkZ610rNZSuMQuchpxpX2Mya66NobHYLKi4Grs3qeBi0uRG22MOg5kCLX9KTDXKW4i4Ud0dqGlISOeEFHud/aYBuNo5gc/xAd5pk7re6ByzvSX8k9L72AlQRV+pfw6dZ3GpDbNFoiA028n2dwCGw+bt0/4Qa5Fp/M32gm/bH6a03RaMrSCHuCNr0fX6XwXFJCxSIHLkSpIZJLxY6BAHX4CUKOnige0zkmT1FdK4Pz+acxITWw5Eozv/KmsgTKokSYDjSwo/Aumv/tVTnuE0TJZs8qfac5WNCvl7Ny/WuaGRUwL6EhHJbKvVDtn7v1q0oV9BfoBu0ap5N8wMITIbHN17+OSnH8kAVO4QDtD4ZWb0MMwviT5QBom2NSDOU+yzbLu6J+sjYM0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd159a0f-1093-4cd3-3fb2-08dcedc9da63 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 10:03:58.9252 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SLj1OMdSOSR1BW0wNwGYukjEE3L2XFowrVnk7m6dTGlWeDs/heW9B+M/p29WkcTL3SymToAQI8/B0bo9TWTvRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6634 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-16_07,2024-10-15_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410160062 X-Proofpoint-GUID: kbDaolBxtCHRUq1tPgZQghRu2xZwbVFx X-Proofpoint-ORIG-GUID: kbDaolBxtCHRUq1tPgZQghRu2xZwbVFx Validate that an atomic write adheres to length/offset rules. Currently we can only write a single FS block. For an IOCB with IOCB_ATOMIC set to get as far as xfs_file_write_iter(), FMODE_CAN_ATOMIC_WRITE will need to be set for the file; for this, ATOMICWRITES flags would also need to be set for the inode. Signed-off-by: John Garry Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index b19916b11fd5..1ccbc1eb75c9 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -852,6 +852,20 @@ xfs_file_write_iter( if (IS_DAX(inode)) return xfs_file_dax_write(iocb, from); + if (iocb->ki_flags & IOCB_ATOMIC) { + /* + * Currently only atomic writing of a single FS block is + * supported. It would be possible to atomic write smaller than + * a FS block, but there is no requirement to support this. + * Note that iomap also does not support this yet. + */ + if (ocount != ip->i_mount->m_sb.sb_blocksize) + return -EINVAL; + ret = generic_atomic_write_valid(iocb, from); + if (ret) + return ret; + } + if (iocb->ki_flags & IOCB_DIRECT) { /* * Allow a directio write to fall back to a buffered