From patchwork Sat Aug 17 09:47:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767099 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 43E461422D2; Sat, 17 Aug 2024 09:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888120; cv=fail; b=C7zAQKSoE8+SuPAOkX4RXTdvDddqFPL74nc4d9TVbQtnQJqappZjZGWesclP4kAao4p5S9m5J0XsD4b+AoNsF/NWzKbTgsrqk4YLyJnKYpmC/xB3MYzT0Uz/IoL/EGg1+5U7OTAvd/h05y0XmwIwyOTSzXc8jWYcNIaWhzIkkV0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888120; c=relaxed/simple; bh=yZU2c6ZG/1+aBwlyF3buJrRHxCW6Pis0wdP9JmmYCSo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=S1Y8XHFEC9cIi3XRo7o7td3E0Aw8p4BlSPojZazZinwmWejKCzqQFC31ZAlbJSZUzsM+WqnNstAc+69yq2OCzCkv6/o1EPfWfjIpSwFDAwXVz4Y9g0/hGl/U/EJqQkP9WAvGF8b5OTAsGofCppbJY+QaksM/vvO8UCg4POlIHI0= 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=P1Mz4WdN; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=jP+DqKpF; arc=fail smtp.client-ip=205.220.177.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="P1Mz4WdN"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="jP+DqKpF" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H9lR6g025828; Sat, 17 Aug 2024 09:48:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=mg3KwTuBisyad2RTZuLAwDfvThje4Gg1zyutjcECz5g=; b= P1Mz4WdNWbAhOqFBaHRMPX6U7U2MD4Xb1Hg5yaEHp3KNDl1Su5MRIPP+Q2wwq+6N Ie4ohRV+p9ZDDHbJiWdy0Uw/QI1cgiThT7wjqZRgodeLG15rgmgAziYMnuTp6HuW 07V1KcOZnNZn7Elxmn2RUKs5YSbUpZBFWV/F+m0P3z/qnu7LVxPjk9KnA8dD1kEd ZYGqoD4fEGtZFt9OwzeqgwxqH0UuP6prGMhbY5+zUquVTO4NziXhvyyDR4u61B+1 p5nkB5yXira17kE7tmcTJSx2hYUkuHVBIS/7OvqgDXAumcUz1S54rO1gAHRlh7vF waSv8yQVu9tpyBBSJhfzzg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m6g87dr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:20 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H87Ykc037368; Sat, 17 Aug 2024 09:48:20 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 412ja5f26w-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CETiqKKMNkWKAO2BeGMkWbAiHqMbWA6NVRUVuZD4pliNNC7wWOfSn/susZlKsDFpK1MKLG9KxpJfSZtgIr+BpEM3Xko3jd/dcmch4IKu9whheTuDdEX5UnJJRsjcX0afU90uPyWYa+jPlLNv6pnyCxovqfotCLgqWsfRs2Hvr/z0wcgU9D2DGfdi6Fi3lr6lviFxJKRFJ9SOFVVePpFGETjYIg6NL3sc1NWSV36cq2zgtSCp0nnlZh1KMpcPNeYHfsLRXqh3TZhNVfD+Q2h1xCLnIkAfi9hWSPqnB5popIVzFtPGaiwaOvxwdOPSb85prCd6k1wmHztgMhdDbGwNnw== 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=mg3KwTuBisyad2RTZuLAwDfvThje4Gg1zyutjcECz5g=; b=XK9K1JarNjEtzfkc76wahSipCkTvK+63u7oNgo/jrvJ56jBEdjy7BjAVJgYTsrD+Q/ityYfIu1jC/oCRGMtbw50oaKfG9rxpiDQt7XZJ5SxXZ+llKajCKTLA9qd0NCl4XU7C6eJsD9T3klGgIid14u/qk65qezr3x5ZD88M6d3JU6izsiPdHcJmlhPFRyk7Yn6xdUChwkrgfeC78yTj2R/vz2sdLw/tr423lFlFobsba/w5ES1iwxxxiKX20nRkuND9GBrks8l5OfVpBO22HUnD79mlnfW24vyFiGqotVUGgHc0KiHXOXxUL+5zWe8mTtzGJuAx7Q1JXQzP1vu1OHA== 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=mg3KwTuBisyad2RTZuLAwDfvThje4Gg1zyutjcECz5g=; b=jP+DqKpFqIYIVyuKqxf6THoTlvgLiBwl1QbV9LL8OeOrtp3TqtfyOG5z/KTMewbbA6ttPTsvMo2GlTKneML363AWhbzsLR+5bK8I1owAWeVgRAX9iWU56Sop5Sdv4dN30gD8VZKP7Gtt4kOTwjnOJf7uz6p7eykqPvnFo6Qc3Co= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:17 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:17 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de 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, kbusch@kernel.org, John Garry Subject: [PATCH v5 1/7] block/fs: Pass an iocb to generic_atomic_write_valid() Date: Sat, 17 Aug 2024 09:47:54 +0000 Message-Id: <20240817094800.776408-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0060.namprd03.prod.outlook.com (2603:10b6:208:32d::35) 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_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: eb6044c2-6fdf-4640-30cc-08dcbea1b8a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: GE7hjsw1+e9YzuKdGPSlUH1jgrOFGbu6znM8v2ft11ofuYGGP9UDDs700eKsfqDgpqnns+gFvgoAPROLWTSx9raokR4IfKEXIfgjGon1h+bz8KfWYcXoPL+MZKOQfNQOxhFNVPR59+YR9M/J953s04qCSfoP7ZV4Vx05XpdVJm4vEEMnaqe6l9Rw0xAPdBdx/P6f6aP7cb1Z23Cpm2ZxjZKjF0RPeGjI60nBFe0uF49gmob33zxy/AgrTQp914eH9EYxZEtiCxF9IHqavVyR9CxsL+dd7CK5b3+4NQMmiPsj1ba31zP/+H8teqAPBf3nWb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;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aXwlUCGJQxZH6mTgBg3z8ocF+DmzoPhs1+WAthcgC/en/aKmTxC8X0mX3y5o1M7VWxZNfLQMXemG0ZwR+zSJGBXJ+lfeewiBNWXCrotoQg0fCVt5ZAQH4di60Ha5h2u9YGt2go5tP8S/XEICdkXT+LsNq6jajP3Iv4qFM2XznzZ39gNA3owJVA2/49S8GOEzdbhJrzCOYSEF0K+FRaQpzMSev6OW6a0aY8+FUvYRsCd9zUXrhHMmoV6gHXuSi3FMB2a4r9KCFVrebIvuOvmX5UckijvL0Fy4A/Y/e4X0htcy7qfrWKymzszxBkUYZhNW3KSoN0MFJvHbXLBr1T4ocvy38kzZrUX4lugHFdm48y/MXgyr5JK/WbhM7P+dOdYrwOTENFgxXfr7xe4VBZrRuu3gIz8ep0rHa8FHh6oc739QAUSjQJGBEXY/48meOp0+T9AyIHxBVW4fRAcf0BJXu2Dq9nYdBS4+jFKUesA/BiLSEKG7x/BksH5jsX80DAXKoBJieOtB32mGbP3XeOJ9KHQ5jkz6REGwUZUiqlHCweI5resISm8uIDCWoacLKMYrGe63xh28+usma2KHtahDxOXWyK3d1IWOEIpBlIrUGJw8Q7gWPd1RfkCIMolWRYrcCaJXFQzuE9T6/wcU4u5bV88Me9TTgzHyrQLuOPn6YWWHCYPr+Bm8TTbxFNITJY+9Zyaw7VBGRQTFMizDGCVIE63pswMya+8ndh8tpdxfltEAvszhD99bpsLsytwcljGiCYkEPjrmrnVmYGytLfQrAcUgFHcJuAYOrKerhlIEtWaH3cnuVQ7gB7GTL147kDhZBRPl8SylEB/NmBMh9pQXqLwM7lj2aXA0ObXZhHaOL38rJ8pxaPCqeJwJIOJTb4tdDvMN/i8mCmmDwU0fTz9RRdrsj3zk5un5ZROSxVhvxKnZm0VZ7ujI9rSUVSlLYwLnBecVBDN9wUVkOJ/5Gc5VomoyWGQ6wiXZqVwxjdKMN8O90rF94uQQ66U7AtK8qLAk9ewqm2Wvz1T12PQsyYOIatROK2GhWrS/+42vhNMzkC4zg6atydWNu3lSD8LgBV9i9eJf4w2Dby38T+g1URJzfL1l+SXdzOiIZApeIb9KEySKUFu1Bwslnw9lXbz6/Oa9HjOyzYQ9yNBXDGXar26WTH5PRE2+cPwXjdXNdS7pvyABczlaFiVn0y177Q47rUsuFjask+JDzILbu8Y6msNVtvaPEq2vOw9Kt+DfoihKkK3uh9hzVPb5gJa6xyouSymJbYbJE49hH8XAue4EoLInCGRc/XaH1bP8QA6whY3hpRzoIY5tpGXsAN6F4neh6sEmvWeGMWwKMscarlJT2NB3l4Gm9vhRyHIm0huYG0UBTJzFMiengAnCI5CgCQ1TA74WJmApmVX6nC9G3Ts9PhMA78d8w2PH038icxiAaHqjdCXifXQdycVUClVKXWL57kN4rYK4i1zqfxEWY1X+AuGZRBDpFSaElzQj2yGBvVgNR2LfzWegVbnj06DjS5q00I/Wl7F+n7xVirPVae/E9VCofYWke4E97MHbt70Uw4ZBsnT770WQUN4E0XsbMeN+jxBfX/mpsiZO+XWvno+HINndRQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: XwDAsu1QouN1Hbj1bTEPdXSwzg2ZISyrPd0OL1ADP1gxGVTiyjjMiCDv34rfUdJpWQdwik7kgAy0K8s2lLF8zIaQxbRpgUAiww05sNVzJ0VnhFe+cia3Z4lcUuisM/K16yzSN74lix6WjDPTP7PaOpdzdTayABCzGCn4OLSGvQJAoLA7D3QP6evmYrNGl2U/XNoKMu7tTHmpbcq/L/QdKldG9HaylleY4qWhKYELh5iIkomBbwVNzFwNtoyLW02ruOJz8hC/k9mWBtr3zq2Inz854Gh2VQNVyrLliswDxSV5vBpsGnZO2a3A0HmufH7zzNse6ZCny1NpPSecRQV0ygLFOAHmx20Fuymlxyk2la6MIZfz7HgKrJUYPQXXFJ6SkVS+OPYVdabASUHVZU3ECPcTg121Xospnlr338B6BOPsvBDuLPTN37fg3N9Evx0AnZ0i2ZCaOZ/Xl3hLLijs/SdJ/MSXjqW5hrefzOnkHr5mJMneU9Xl2NkJVfF2loX6Q0pbex0qiYccqbxOxQ5RHc3d44ln2Yeg6aWNSvJtJZKzVExWt95MjRS39vsgMKfsmV3tXlmF23BPPkF0CMuJJfWbi/3MQqfOBv/qXJ0B0nI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb6044c2-6fdf-4640-30cc-08dcbea1b8a3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:17.7784 (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: CRzeb9zzySxO7vw0sFJ53D6Xa7qC3/U9T3h/HJ2kniv0MUX3HNVMyuOPUFa1YVcTI3ESfJ2H+AIxWbxHqtpueQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: W8BgnJckfdoRSMBYskF3QcKPfAS8Svc9 X-Proofpoint-GUID: W8BgnJckfdoRSMBYskF3QcKPfAS8Svc9 Darrick and Hannes thought it better that generic_atomic_write_valid() should be passed a struct iocb, and not just the member of that struct which is referenced; see [0] and [1]. I think that makes a more generic and clean API, so make that change. [0] https://lore.kernel.org/linux-block/680ce641-729b-4150-b875-531a98657682@suse.de/ [1] https://lore.kernel.org/linux-xfs/20240620212401.GA3058325@frogsfrogsfrogs/ Suggested-by: Darrick J. Wong Suggested-by: Hannes Reinecke Signed-off-by: John Garry Reviewed-by: Darrick J. Wong --- block/fops.c | 8 ++++---- fs/read_write.c | 4 ++-- include/linux/fs.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block/fops.c b/block/fops.c index 9825c1713a49..1c0f9d313845 100644 --- a/block/fops.c +++ b/block/fops.c @@ -34,13 +34,13 @@ static blk_opf_t dio_bio_write_op(struct kiocb *iocb) return opf; } -static bool blkdev_dio_invalid(struct block_device *bdev, loff_t pos, +static bool blkdev_dio_invalid(struct block_device *bdev, struct kiocb *iocb, struct iov_iter *iter, bool is_atomic) { - if (is_atomic && !generic_atomic_write_valid(iter, pos)) + if (is_atomic && !generic_atomic_write_valid(iocb, iter)) return true; - return pos & (bdev_logical_block_size(bdev) - 1) || + return iocb->ki_pos & (bdev_logical_block_size(bdev) - 1) || !bdev_iter_is_aligned(bdev, iter); } @@ -373,7 +373,7 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) if (!iov_iter_count(iter)) return 0; - if (blkdev_dio_invalid(bdev, iocb->ki_pos, iter, is_atomic)) + if (blkdev_dio_invalid(bdev, iocb, iter, is_atomic)) return -EINVAL; nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1); diff --git a/fs/read_write.c b/fs/read_write.c index 90e283b31ca1..d8af6f2f1c9a 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1737,7 +1737,7 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out) return 0; } -bool generic_atomic_write_valid(struct iov_iter *iter, loff_t pos) +bool generic_atomic_write_valid(struct kiocb *iocb, struct iov_iter *iter) { size_t len = iov_iter_count(iter); @@ -1747,7 +1747,7 @@ bool generic_atomic_write_valid(struct iov_iter *iter, loff_t pos) if (!is_power_of_2(len)) return false; - if (!IS_ALIGNED(pos, len)) + if (!IS_ALIGNED(iocb->ki_pos, len)) return false; return true; diff --git a/include/linux/fs.h b/include/linux/fs.h index fd34b5755c0b..55d8b6beac7a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3657,6 +3657,6 @@ static inline bool vfs_empty_path(int dfd, const char __user *path) return !c; } -bool generic_atomic_write_valid(struct iov_iter *iter, loff_t pos); +bool generic_atomic_write_valid(struct kiocb *iocb, struct iov_iter *iter); #endif /* _LINUX_FS_H */ From patchwork Sat Aug 17 09:47:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767098 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 43E88143723; Sat, 17 Aug 2024 09:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888119; cv=fail; b=qJwFGWlF2oJt4OnnJYmPEstoLppgFxIe6iJlQyWt7ZRVERTt8ML3OOduyQyeYPfmzN2AOQGFNlo+oeP6sq+8761SMmOk34o40DzEqN+u5FbyJckr/QqQ456ZK+XoSqkzCTzMNXhAxH3VEEwu59FrGUpGYRDoSY6CIzo8ckB/f7Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888119; c=relaxed/simple; bh=GYx7CpZu+ABnTqW6ZZtiDZhVHmU+L1Ki3PkGG5AMl9o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Riqji5Xp7o6PR80u3LgGWevUNLEFcGoPX7GWnb6z5bfwX+0SyaNiq0QL2DsRYqbL65UT0xVImTTLi1Go1Fzt15Ru2lzazTaaj4QttrGxnYLOVZN6qdjmnY4W7i/0h9Sbea1MpYnDm4jKq7/9dkpA5114/k/RJBO9nA9gTQG5++U= 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=FtsSpQAM; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=eQLwpUSY; arc=fail smtp.client-ip=205.220.177.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="FtsSpQAM"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="eQLwpUSY" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H899rT016343; Sat, 17 Aug 2024 09:48:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=4FdaJnhZHFCRUjbwSGkwVcBVhcAaRCPdrwgw6Q3ROfc=; b= FtsSpQAMlr2lrFcBPLGGhKhC6abTd5pPfniUlwtXgLSIegCtEH/ychJJynyRfjwH SxnOsA9tIfWwX01uakc4tfPTtAgi599bki84fkqhuRCTTUU79jSbvB5QWpHyA/9a DlpJE0I6nsfpdf9nCcfm3DBnfxI6QFFOfcAHX0rtl74wT2omOOkkY1jsTM4I9TIO 6/CZBgJi0WAJo2533Xecd3TQ3rzFsqLhqMqtS8Zp9Bd7kzcLnEkac2rdJ5cHHGqN hXZa3p7xqaF46TcGQDBuKN/3v9U0ljAzWm5Koyy8pn7t3Bg1dzJPKjDzPJpeSpfV Yf8vOpVkrzOV+6AtkFA6Kw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m3dg7mq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:22 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H769sZ002603; Sat, 17 Aug 2024 09:48:21 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 412ja5y3xd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DqcW5V6dS2Yco0u+QXIRiqvHV7A8ZuB+BIk+zcetQb/pHdvon1Ks2RWz3+REPgqD5Zd7v4ARnLoS9Nx+P4Bv5nWMjLDzcRBQIqDLe3t4wc03uXjZK1jDZrM9KeEWOFP+KxiqAWaeAfOqetRs/dwCFBTkXihp44U10yT/MHMUVBovF3h7XAplW0hTcVnZzlrMXe7UzS/NmiYwy2tVtzOYYUY6dt8bhTb0NlR1b5OU5Y1XXAgOj0O4WLuVWxis8CosukH4oSh/a7zIsRxnvOgBjUse5y5fj68ymbXr4oikvlZjB7KzVSDGm1NWYrKksOvMqj4+3I0lfZckq1+b9WpPPg== 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=4FdaJnhZHFCRUjbwSGkwVcBVhcAaRCPdrwgw6Q3ROfc=; b=JrV8vHQDHNYd/AtYVwHwGhMUID3i4il6ftnrbJ37uXvcKGVSu5IlQewTOnn+bvjOQBxtqeJspgCHlXgG4awOj9exJ7v/bvelrcfWohzXfxlh7VEvPbs/dm/tggKhWqUlTPSJksUR0s9AW9O3wKUAMJLLeBaLjnzH60H4ndN0Vy9/6Z5TmVzmdp5yuPGc/Vk2ptE3DSM0j11Ls+j3mNZeFot2VKJmu8dg5G65LnMfruRYZuTDa/yHjDglTXKr20r6GXe7va5BITgBhPXegV+1yXYDiWfvZ8DjuWkKkVdRUzlQbd9JTzUdAzGKIGBx9rskBhWH6zXR39VxK87Rl0VP4w== 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=4FdaJnhZHFCRUjbwSGkwVcBVhcAaRCPdrwgw6Q3ROfc=; b=eQLwpUSYkV24SNCFFUBFpw4Zwt8R4bBfH4HNUrFnRmGKuT3taOXRrCLzB7C8/XlfyrIot2q9gOiI/73Xp13hmxMKAJUXN5f3XxyFB8CFDZQSchhlHaCMQ+ZR/1trQ67aFyasOM1PEhkSqm7nVxdHW3K4QBhL/sGsoOQMs4C2h20= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:19 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:19 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de 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, kbusch@kernel.org, John Garry Subject: [PATCH v5 2/7] fs: Export generic_atomic_write_valid() Date: Sat, 17 Aug 2024 09:47:55 +0000 Message-Id: <20240817094800.776408-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR01CA0036.prod.exchangelabs.com (2603:10b6:208:10c::49) 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_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: 33b70d32-346f-433e-361b-08dcbea1b99e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 41JPtk0amngSqcctOtEk4GqXXekId1b0Q6OsZwcADTccH7/m8JjF2J2UkJmz6Y0307wjrlnOwBUoHFV6F/S4RfA0XM6YaEebsWwfBJ/ufi/tTP/BZhg1LfK0ow3qej/vOQ5fEm1VjmKfp6lfNyx6ZZm6hTpe1ie3IjMxTlgH6EUp4JMcSNzh7UrIn0pHSDrBrMa6rpl/uuZJhn/XQP9JfA0pkpMMXjATzKK46bYt4uEwxngRvK+trRQlFgzbm1gVJTvVyFa0HRX0RUUc177TWx6GeASu8we14/ftKIYVY58s3rs4QIJGJZ0g6MMEiAHfeB4g6/43hi92XLls8zBb9kHHNmxPa6EFd0CipL13dWdsFIR2LIdxu8iEGtU1JcuXzKLMIy9VAuQSq7cR3x1MJwPmQ1e9iakjtYTCbJntH3Kqx6+U8pnUuVZBCLG6yzd66UQan+a/LTaPgLCbC0ipaImbyZV/XlxBWODCVwnmBZMEKAi86Whs+i5tlS8/LCvKIgtN7YfPowp7CI9zZd00JOysOQTBOf/1FnVOfxQmgDTKFwr7dFjpgnIXHV+DK0igTBBQYCRYdheCnCwG8xLSKJJw1cEYQa+RAoktq4lfxzUM6npooS/Iee6ydc1e8JSJ/1WwCZxtQE1OZtFDdaG++BrN3a2mpcH73l1ijeLhvDSoJVg0Rd+LISrjsHrHkn6Is7VdhZRPBE1G5qzNb0CXB9inc7UCSmbVXnv5clbthomSnTJwZ/VvBay2pJ2Vz8s5gfrapF6AlbAPa1X/FyBIgXy48jyyPeNGR+DtIaze6dSpbS5vudDg2rtGdHY0de+IIhHVl5/PJPm0bYGRF2ZoL4ORKzENJLdZyNSfztNA64E2lz4F8TjKiaQ63nszhRE8duta68O74PrHNVhFYZWybnXFFiuZGe4i3g/7YUdO4ofXuGNfqJum3o3D/RTrVX0ZnFFAXUfYlKXszjGW/7PUHsab7Juj4RsKFdbI5r4oIF1JK1o8MkqhKquyafHlOiKKJME3qPJmqhLcNeE17R58munPUPX53scUPOXDWeDOT4AcG8ygllKerFxFbZ8R476xkZUXeXWt6nBcxOKGl1G5eFe93VIOW0D2JjUPXk+nRiIVw46wQZ7EV1S/k3Jp9MmRmBehUacGP9AJ1CYKjd5CfLBqiPP3cUP5bLo3RCW5etIbBSMgqtN6GBvNpNmv2erVeOqWJbV7g2p4e2/rv2iNNeBkue7nlUrRZ3w5k+G94spUs5J1z6TVj7s7z0+RHpDBI6gSg8RNDGMteH1u5tXN+1XnBr3hTKPYP+UpcgqSMWuFcM2xYinAVQnfMdXla2/9uR+QWasKDZ4yxja9ZFo1ng== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kcaXeOZL1RW1fK+LfJ11ZxsG2+q0d7nknbP3vglVL3bx1ABBWF0/di9AGCsVu8zqWM4kq0Td404xoQK2fx2sm2KBe9Vh/jaccbIVRBYjzOmGIMbXOtTF01rUjNrRgvbNVwGK1EqNivOuBTVU0IXxXz4dzifJ7pqRbkkB1M8H2c7MQZfBR8UXCoa9IRfUjojL+BDBMcP90YQKkL6p7ueyf3UL5ejQTq6er9JlkFOXbluSYKJpj9AIXAqdWCkMcqnNRiFoBXs8HvqgVrV9/jRaM2Czk/0goZhd7tMzRJLo7VI6BAW3Sa9ceo4lOWdcCSh+wNB3Mczw9r7mY4RVVjEo/luriHzWs4TUQwRshdEy1ZpNAE0rYkjhQuU+cYQlYD7bXC8moQUk9CwQM9alHsFPNmfE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vuSI7nwdfmDkw0UXmT+PN2rpe6JeJoRb33l/HJ0Dndh3t4fz4gLZHY26am5cMo39Rbo91WdEagvr5eo5vW5ls1/3/IPmto7v9PJ9hWjRPU42HfQKDFSO5RPK/7jyryFAtAEw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 6f6XdWmFP60C3D3nX8x14/NQnmvgzHVmonfZwofIb9gYJHZEFRwVA/EewoauHtpi2Hzzwy+LQXjZ1yyj2UabPzwW8bulwzaDue/IDuyHbO8lu8MjKCBe9CAz9STMtaJqQUtJIeTPdXmjCQP0dOlE0V7ABfY0giawYaq2kcor/ZnBX0jZWp2lLFtuTlI0LbloNJn+tTK5BnN12Ecl7YNvThiqmvqga7ytaprFm69mtTpQ+zUl/+KYqsvCqeC4x2aLM4FTo9CqvmhUIV1S43KUQkb6pi0nS+Y79IuUdhCVcc7pzx5LiHae9qAlRqwWkmrlijZ4y7RulvhYIVzsEHx6/FzhGMsy+jbOPSts8O9JkZH7tBU44m4Z+PYKYaNcFctAXt2jVo0IPjKFsGop3oIulxIZIlgGJiGOVIhwDgyRpIcDNsOqTEyyS5+Ny2eTYFBgog1s8K4DvsQmP1oUNmWJZo46orTWvJrqAIHJhttv198tz16tgmxrVxAGo4pxurbYsgZ1BAT/ILTL+gWIWsUuWKMIilBijiJzCEv1ordB1qnJLhswO5rRbt8vbApKGRbG6k9YIT2dTzY2J85ICZqrCL/c2fLfqojoKgHc3FWvokk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33b70d32-346f-433e-361b-08dcbea1b99e X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:19.3891 (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: 2QLuAE3daQc1xw3z4ak/Uu6pfCNwGcJt0BFSMs+Tk4o9V3lq7mB5U1ynRvLgPErU1ffN8SCJrUI+C8gojIKbqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: SfNKAJQ73vCXxAczbD4yBopie0_-aaKF X-Proofpoint-GUID: SfNKAJQ73vCXxAczbD4yBopie0_-aaKF The XFS code will need this. Signed-off-by: John Garry Reviewed-by: Darrick J. Wong --- fs/read_write.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/read_write.c b/fs/read_write.c index d8af6f2f1c9a..babc3673c22c 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1752,3 +1752,4 @@ bool generic_atomic_write_valid(struct kiocb *iocb, struct iov_iter *iter) return true; } +EXPORT_SYMBOL_GPL(generic_atomic_write_valid); From patchwork Sat Aug 17 09:47:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767104 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 ACEF51487F4; Sat, 17 Aug 2024 09:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888178; cv=fail; b=HbCthjFCKSr2qMU+1y+yhKdHPt4rAp0d4OHGLM0aAQpLw4GbTuwSPiBAMllxlSrHYwkNBaFxFM3I5+U4kRalWk9LkzbC4oejCKiRJqFZAHAwT+PbeBSztMiQiWq896FA8v+iXhqNb9XHpNIGFZg73/jwh+SG+TxNtfj2aN9DwZA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888178; c=relaxed/simple; bh=Qv8Y6m90GLOx7Fego1WSBH4oDraxPRqQlVnTLDA5pH4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=f1juDE6qqRtkdGEa5eQoHZk3GMdQKQozqSCyGe4ZVSbP7fx0C3ECJRklmCi8mb2e6NS0DuDVZiN9LWpl0JU6cq1C4QHTc7eZp5HiASaSYmkL8vUkhNhUlUH5OV0faUAVOD8+4+qCBnTdd+Ic4GF51oV+9bkrcXYVEWZo+AOOrdU= 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=LloWzh63; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=W1YZTk9z; arc=fail smtp.client-ip=205.220.177.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="LloWzh63"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="W1YZTk9z" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H4979s029885; Sat, 17 Aug 2024 09:48:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=QXfLt9wVw+nYMvfs5iT6Ek2lV8aybxP3E79isDYvIU8=; b= LloWzh63h2lkfyRiI8TTDKIbo7nq7Y/MCp+t/spicmX3HA1SSpdnkWWPkpK0jaMR Pqq5TKBqrJ8oh0ImI6x98idisgOeDaAIst20aKOn0aMiO8E71RAhZxBHPLj6y8Q2 XozxbTJmdy9/L+c/l0tIZK0UjQ40dHmeCFCYPMJALdzscXwy/rBm4AK3CXu2uZoI sCn648pilmw8V/YgUkBtS/B+/NTyOmsuZwYUMYqQBDGjZaF0mZ6Mkf8U7Uh70onR D/NqBTIipchuKhnLSsrzzYzhVQ8lAumcKmOahVAYuMyaixfgkQ+mRRN9NvrMEnPk rAdyAb3eZgX/rX4wWKaw1g== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m3hg7e6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:24 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H82r2b037215; Sat, 17 Aug 2024 09:48:23 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2172.outbound.protection.outlook.com [104.47.57.172]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 412jaby1y7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WA/NN7TFeSsTy1knXTL/+lH9GRoVe6wYXTJkHwAlG6kgadrPLTmPAAaaWZL0xzbm6vVeAUZAFytB9kTvVVKS7xV4JJ0GSpnCgTNVanOxqC2tjBA52RY0MmrwFmnVIlgbbbU21NZZcYSBJlnJetKVd6q1LrDjRhJDoQfaFh4qT8vgIDd33wpzkj0qXkjI5VRi6GFpkZY/p8fRxlyGI+ztAbP7MmOSwj2tKfWH52v1vgsxa9i9f+saoCk/EPzuk7lnOxc4qdaA/Z00qMZi3KCTgbMtfMUGYBGtk7F+suAbCsfdtmYjiaJ7szNZ2bIqu24NMa2oORP6FS6eaqoqMHPqnA== 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=QXfLt9wVw+nYMvfs5iT6Ek2lV8aybxP3E79isDYvIU8=; b=fnwihhMzyfrw7PoHiLNfOnD4GjcvydM4ltGlManqzoFBGOpiEXj07WszT0qGRzzBy1+uCRdt3D3fgDplPEjfk5tTAah5tsvcktQ7W2WOkjRh6DSblff6wWEBFsmIVU15/sysVkNWo14gJbpNmyDI/dEVTmM5M/PIP+DQhi5bmQaXeGgKvptuJ9rnAE9hzwgpyH11qO2uHKlh3VYlgiQlS/jgiQnHsrc/gxUy6peS4ZR4iTq+kNty+onJ4V/Inbe9yaQaRnLC7zaoTtLTDK2HnFB7kLf84v2jyeTgZtz/jgZAKhOIRVenlj6rOUS7WZ7vY2bE9BiSSgFdO6ZMsNEr0A== 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=QXfLt9wVw+nYMvfs5iT6Ek2lV8aybxP3E79isDYvIU8=; b=W1YZTk9zhDW68nUeakU0PUAevXc5XkVngc2ZPCr3BhBokHVrbVZRyXGKapUAEFMsI/O12MtTIHOnmkCpRoWeuBDDmiMy1ONRLgyThCaUUMxWS6B/CfhibfGy04CHj/sguytxhhMyWCTkjMXE3E3X3/xzwDA2zIEuD7bSIEh9J0I= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:21 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:21 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de 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, kbusch@kernel.org, John Garry Subject: [PATCH v5 3/7] fs: iomap: Atomic write support Date: Sat, 17 Aug 2024 09:47:56 +0000 Message-Id: <20240817094800.776408-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: BN8PR04CA0065.namprd04.prod.outlook.com (2603:10b6:408:d4::39) 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_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: a255fb06-f977-487c-3534-08dcbea1ba94 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 35fHRKqQ2Wuz/OIja2JwplIgT6AabfH0X1ovIlrkdDhqgaf01HSug+ovclmEWNMHVXg43Lk5mJU49lqJowNw9Z5lhniFj6OSd+uAoO4zGXqAzdIqlg4JS4qSgR9keuDYrzzflzZZhp8jGg/pEGzZvcd5VM7vOHa1FGeAKc8NZldKUKTeo5w+4LQRTsWITMmFYvqLSE/mMpP/n8TgSu0wySWQbpsL7xp+iD/nIZAKLvPOaHCw+SZNZnB9MfWO5df97Q/4lb1njzD5FyJrK4nacgrh6IXKWSPNKWy/B8v1ANYodVsBBp/+peARs3JVle5hrN25aqG9GnpVy4cwXOEfkZm7iYRVdszKzBgqqlrlMcAkxS+0UEulh4KnzlDjoj8ee7laWUsqQ75ip3Prb3IhBTB4gWCGXciNbO8aGxypVIO2NonS5Luy9sbFuqU6112WZ/+DYGWYtIoHwNC4Ut795yDRX1P4SVszwHhASGvc9T+38Y2cdgbaw5sfFjLYuY7ave8Qb0cMQQqJ0yjj+QSVLN8u+h91sOhZB3Z1tiG9yhdu+tV1kRlKfDX5fY8d/NsEGbntV+FbESlHbSclHh6p2A4RmXbYmjlS/GldRCe7Ah9POgITDsOjzSATvoQiqlaf5KW5e38QGW0nyi1F56CMnmFXkBkaV/fxhctMP1f+ghoovdGBTWCfDM1QLrrEHtf73aVXe1xngUPltX/TT+yUQLg2m9FSBbFd3vaPbclCZAZsZyPj9Qzo7NMIm21jWo5UIbmckBcgChGRlH0GauZxMtIx3Z0ATxW7aJF0iV0mAHUqx+VBVEWJn4XgFtYHSZCc/vbvQIuoimgKHKeUpG3Sm8gRBVJERwToteIdhBXLNHktI9SIceZwyAPwtG+oqwdpNQbFZ+dyuw8ANS9hrJLu3WtwKOino0BOw9PeUX4j/Doq8ouIOf25fuD8eRqXG4CSk4V4v6cEf4RJV9k4DKyWQw2Eai15YHNOMPblVz1bE6oFN7zcod+km7TkqChy4nHIU1hvTcUgynHMt/u48ef2tFIsxV6P4QcYTfWfXzGinODXcNPvoRFZ4iIdRRYiW/MCwQsf8QAHnw7wIrEccKPs6BsK4V5OsqIK01DBmH1rC7Fzj3Csr+vjeahMnofkad3YiWKFeD5ETJkv4S7wpm6eK4wB/jnWgnfXdxoyITGKXdJU6gYsBSTBZ3WhRzhZTE/22KUvRDIv2Na0xbpPwhcBEUIvKzwypLdgQlK8nO8zT2TGN2/QXrhyLAFiEgZwdVLGi3jBU1rEYu6uFb7PWYs54xp2yKPIKfmo+Ee7O+6r6w+5Qow+U/WdziCS18lmjOMcDVP0FFWSfgLELV2aHaDKqA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pjwYXCQTg2TLkONh70NX2EfirsyYlAo+DSJ8Q1YwE8oxRkhNA9E7EnnsvTq5dBsPCxSJjFRoYCzhZkEgYUS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Y5Oxf4OEidgpL3xmANqDLIiD4OUoP5JpmUDI6rziUEfkhgdAKAMIj4xpJ2XNK0sPlW07dsYVLWUwFE4N7f+8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a255fb06-f977-487c-3534-08dcbea1ba94 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:20.9922 (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: 9vNqMxmK5azkdHIsCuC6zhKL45cKoU5o4BK/kdO7aEMPC/wULsRTQd6BCCwkgUsYlFE8gmOxy0zwMb3L1e74PQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: gimawJWq14inVYFrZw9_TZg7bfYjktml X-Proofpoint-GUID: gimawJWq14inVYFrZw9_TZg7bfYjktml Support direct I/O atomic writes by producing a single bio with REQ_ATOMIC flag set. We rely on the FS to guarantee extent alignment, such that an atomic write should never straddle two or more extents. The FS should also check for validity of an atomic write length/alignment. For each iter, data is appended to the single bio. That bio is allocated on the first iter. If that total bio data does not match the expected total, then error and do not submit the bio as we cannot tolerate a partial write. Signed-off-by: John Garry --- fs/iomap/direct-io.c | 122 +++++++++++++++++++++++++++++++++++------- fs/iomap/trace.h | 3 +- include/linux/iomap.h | 1 + 3 files changed, 106 insertions(+), 20 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f3b43d223a46..72f28d53ab03 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -37,6 +37,7 @@ struct iomap_dio { int error; size_t done_before; bool wait_for_completion; + struct bio *atomic_bio; union { /* used during submission and for synchronous completion: */ @@ -61,6 +62,24 @@ static struct bio *iomap_dio_alloc_bio(const struct iomap_iter *iter, return bio_alloc(iter->iomap.bdev, nr_vecs, opf, GFP_KERNEL); } +static struct bio *iomap_dio_alloc_bio_data(const struct iomap_iter *iter, + struct iomap_dio *dio, unsigned short nr_vecs, blk_opf_t opf, + loff_t pos) +{ + struct bio *bio = iomap_dio_alloc_bio(iter, dio, nr_vecs, opf); + struct inode *inode = iter->inode; + + fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, + GFP_KERNEL); + bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos); + bio->bi_write_hint = inode->i_write_hint; + bio->bi_ioprio = dio->iocb->ki_ioprio; + bio->bi_private = dio; + bio->bi_end_io = iomap_dio_bio_end_io; + + return bio; +} + static void iomap_dio_submit_bio(const struct iomap_iter *iter, struct iomap_dio *dio, struct bio *bio, loff_t pos) { @@ -256,7 +275,7 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, * clearing the WRITE_THROUGH flag in the dio request. */ static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio, - const struct iomap *iomap, bool use_fua) + const struct iomap *iomap, bool use_fua, bool atomic) { blk_opf_t opflags = REQ_SYNC | REQ_IDLE; @@ -268,6 +287,8 @@ static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio, opflags |= REQ_FUA; else dio->flags &= ~IOMAP_DIO_WRITE_THROUGH; + if (atomic) + opflags |= REQ_ATOMIC; return opflags; } @@ -275,21 +296,23 @@ static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio, static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, struct iomap_dio *dio) { + bool atomic = dio->iocb->ki_flags & IOCB_ATOMIC; const struct iomap *iomap = &iter->iomap; struct inode *inode = iter->inode; unsigned int fs_block_size = i_blocksize(inode), pad; + struct iov_iter *i = dio->submit.iter; loff_t length = iomap_length(iter); loff_t pos = iter->pos; blk_opf_t bio_opf; struct bio *bio; bool need_zeroout = false; bool use_fua = false; - int nr_pages, ret = 0; + int nr_pages, orig_nr_pages, ret = 0; size_t copied = 0; size_t orig_count; if ((pos | length) & (bdev_logical_block_size(iomap->bdev) - 1) || - !bdev_iter_is_aligned(iomap->bdev, dio->submit.iter)) + !bdev_iter_is_aligned(iomap->bdev, i)) return -EINVAL; if (iomap->type == IOMAP_UNWRITTEN) { @@ -322,15 +345,35 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, dio->flags &= ~IOMAP_DIO_CALLER_COMP; } + if (dio->atomic_bio) { + /* + * These should not fail, but check just in case. + * Caller takes care of freeing the bio. + */ + if (iter->iomap.bdev != dio->atomic_bio->bi_bdev) { + ret = -EINVAL; + goto out; + } + + if (dio->atomic_bio->bi_iter.bi_sector + + (dio->atomic_bio->bi_iter.bi_size >> SECTOR_SHIFT) != + iomap_sector(iomap, pos)) { + ret = -EINVAL; + goto out; + } + } else if (atomic) { + orig_nr_pages = bio_iov_vecs_to_alloc(i, BIO_MAX_VECS); + } + /* * Save the original count and trim the iter to just the extent we * are operating on right now. The iter will be re-expanded once * we are done. */ - orig_count = iov_iter_count(dio->submit.iter); - iov_iter_truncate(dio->submit.iter, length); + orig_count = iov_iter_count(i); + iov_iter_truncate(i, length); - if (!iov_iter_count(dio->submit.iter)) + if (!iov_iter_count(i)) goto out; /* @@ -365,27 +408,46 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, * can set up the page vector appropriately for a ZONE_APPEND * operation. */ - bio_opf = iomap_dio_bio_opflags(dio, iomap, use_fua); + bio_opf = iomap_dio_bio_opflags(dio, iomap, use_fua, atomic); + + if (atomic) { + size_t orig_atomic_size; + + if (!dio->atomic_bio) { + dio->atomic_bio = iomap_dio_alloc_bio_data(iter, + dio, orig_nr_pages, bio_opf, pos); + } + orig_atomic_size = dio->atomic_bio->bi_iter.bi_size; + + /* + * In case of error, caller takes care of freeing the bio. The + * smallest size of atomic write is i_node size, so no need for + * tail zeroing out. + */ + ret = bio_iov_iter_get_pages(dio->atomic_bio, i); + if (!ret) { + copied = dio->atomic_bio->bi_iter.bi_size - + orig_atomic_size; + } - nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_VECS); + dio->size += copied; + goto out; + } + + nr_pages = bio_iov_vecs_to_alloc(i, BIO_MAX_VECS); do { size_t n; if (dio->error) { - iov_iter_revert(dio->submit.iter, copied); + iov_iter_revert(i, copied); copied = ret = 0; goto out; } - bio = iomap_dio_alloc_bio(iter, dio, nr_pages, bio_opf); + bio = iomap_dio_alloc_bio_data(iter, dio, nr_pages, bio_opf, pos); fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); - bio->bi_iter.bi_sector = iomap_sector(iomap, pos); - bio->bi_write_hint = inode->i_write_hint; - bio->bi_ioprio = dio->iocb->ki_ioprio; - bio->bi_private = dio; - bio->bi_end_io = iomap_dio_bio_end_io; - ret = bio_iov_iter_get_pages(bio, dio->submit.iter); + ret = bio_iov_iter_get_pages(bio, i); if (unlikely(ret)) { /* * We have to stop part way through an IO. We must fall @@ -408,8 +470,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, dio->size += n; copied += n; - nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter, - BIO_MAX_VECS); + nr_pages = bio_iov_vecs_to_alloc(i, BIO_MAX_VECS); /* * We can only poll for single bio I/Os. */ @@ -435,7 +496,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, } out: /* Undo iter limitation to current extent */ - iov_iter_reexpand(dio->submit.iter, orig_count - copied); + iov_iter_reexpand(i, orig_count - copied); if (copied) return copied; return ret; @@ -555,6 +616,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, struct blk_plug plug; struct iomap_dio *dio; loff_t ret = 0; + size_t orig_count = iov_iter_count(iter); trace_iomap_dio_rw_begin(iocb, iter, dio_flags, done_before); @@ -580,6 +642,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (iocb->ki_flags & IOCB_NOWAIT) iomi.flags |= IOMAP_NOWAIT; + if (iocb->ki_flags & IOCB_ATOMIC) { + if (bio_iov_vecs_to_alloc(iter, INT_MAX) > BIO_MAX_VECS) + return ERR_PTR(-EINVAL); + iomi.flags |= IOMAP_ATOMIC; + } + dio->atomic_bio = NULL; + if (iov_iter_rw(iter) == READ) { /* reads can always complete inline */ dio->flags |= IOMAP_DIO_INLINE_COMP; @@ -665,6 +734,21 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, iocb->ki_flags &= ~IOCB_HIPRI; } + if (iocb->ki_flags & IOCB_ATOMIC) { + if (ret >= 0) { + if (dio->size == orig_count) { + iomap_dio_submit_bio(&iomi, dio, + dio->atomic_bio, iocb->ki_pos); + } else { + if (dio->atomic_bio) + bio_put(dio->atomic_bio); + ret = -EINVAL; + } + } else if (dio->atomic_bio) { + bio_put(dio->atomic_bio); + } + } + blk_finish_plug(&plug); /* diff --git a/fs/iomap/trace.h b/fs/iomap/trace.h index 0a991c4ce87d..4118a42cdab0 100644 --- a/fs/iomap/trace.h +++ b/fs/iomap/trace.h @@ -98,7 +98,8 @@ DEFINE_RANGE_EVENT(iomap_dio_rw_queued); { IOMAP_REPORT, "REPORT" }, \ { IOMAP_FAULT, "FAULT" }, \ { IOMAP_DIRECT, "DIRECT" }, \ - { IOMAP_NOWAIT, "NOWAIT" } + { IOMAP_NOWAIT, "NOWAIT" }, \ + { IOMAP_ATOMIC, "ATOMIC" } #define IOMAP_F_FLAGS_STRINGS \ { IOMAP_F_NEW, "NEW" }, \ diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 6fc1c858013d..8fd949442262 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -178,6 +178,7 @@ struct iomap_folio_ops { #else #define IOMAP_DAX 0 #endif /* CONFIG_FS_DAX */ +#define IOMAP_ATOMIC (1 << 9) struct iomap_ops { /* From patchwork Sat Aug 17 09:47:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767103 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 2A2B214EC47; Sat, 17 Aug 2024 09:48:43 +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=1723888125; cv=fail; b=PiWZvg4dJhxsJz4OLUOeBAJdLUMCozvApHZWTpBcuEosVpff1t/icOvacg/vCQkhmhjilhhWeBug9Yn2tyjAJKG571WOw0c1DG8gdP/RIhLWq5cRi209ET60PXZcjLZ2VlV66WBL+88LOI3OAxu0HZo3kg0IxrLUpKvpXAplDr4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888125; c=relaxed/simple; bh=EO79lrMO6s5HLmNaV2s5qz2u4D8NayFVfLzHVHNUOI4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=gtoHTWeqj0k+KLjxBz/JCvWACjGhN72t8Yby047MB6YD+c2+ElqYrJ15qKWLy3+OK9xJWSiSe1CtfKRbbmc6tBTfoUTtt0ZvN1UIAHQlZPTbSPUafY7eEMaScP84T2KeMqRWmMYu8yJgxA4CbFMbZEd5VZ5D/yJFUIPyTnI1Los= 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=ZlXjGVP8; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=vPvxyPi5; 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="ZlXjGVP8"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="vPvxyPi5" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H3cwYq016060; Sat, 17 Aug 2024 09:48:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=HcFhOOyCAg0pxM2P8Hxtqb2nQYZd2mVqG51j/7hxr5I=; b= ZlXjGVP8+rWvON2hTwgouskTd20DSQL76OEg/QkxkWJpPSIW6uB/sxbNe8RyM70B XRA4gVvOI1udw8S412hQrt/T5xA1XHIe5EyB9fsIURLGgerwYHIHmVgCqATZscWc NpEXqFhGDFlvxkpsAzOj1P5l9gx6PO7+aXgCNZJFySjXHzEGOHE+G9hLfmypl2Xe NQE/QOvQpDj1AiBYEm1xHaOIFlF9pOYjwYXUn6uj3tFhw++iWeFxG390Xrurg27Y yUAvKjczf+GlnJnikqO072U7Z5AZKRHRO9pJIO0u+YkJoE+6BMq04vEhtCdOl2No Km0pISCyiXbEgxX7LRWm1g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m4ur7jv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:25 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H5jh12037350; Sat, 17 Aug 2024 09:48:25 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 412ja5f27s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q7zQwEaJrZjaToPjm7TJzxWvNsULXEKHV3Xux+R8FtRJkdgPjWUpesVKReDB0LS9iAdgCrkLq3uQvvYMximHiyvfTJKQUgFMIJ8ZsdJ/082wDfcwJKUIuJ1ShI3syF5RNcgolYqfbztzKGw6K79D6X60pHv6qk+UMTcJUmTTGn0iKLhm5to5VcYAciUdAxoYt2Q6ZX3EjgjqzJCZ1lmEyrsClMsGRA/MsCslxJSpwnyTc3S2Kx3Dyt75RJRmYx8921UWOKvdJxN14z0K/slZMqQ6E7mXtiiP5ZOVWDZ5oNywo1e6ugn0mkw+WVxmfOPccvt/IyfnadzGCMmEJd9bYA== 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=HcFhOOyCAg0pxM2P8Hxtqb2nQYZd2mVqG51j/7hxr5I=; b=df7kwV+0iEk81wfe9C3KEjvXrqxCKB0pNBDd2WOBPDUFQD9ukmM9CIxnjcTtDnAdB0q9wRZvM3ISt0NVqkl5EQKDAp6cTYBa6LInmILq+5tluwf6FqwrXXdXdzFbMirGaXR85m+8hfH0Mg6JD8J5g+C+5bWjvOOwql30nxgdm5Va3z8hDMQE5uVS/6tgNVvWMfBhQKgusRysF8piLpCfkJ+9zLmMw5iYdYJKs7RBnPemFrIYjhRpk9r1Mw0R1FSs5yUOjmRMRrOaeGTDkJCXb1W4P6tg3S3t+FaYRJQzgtiV7SEUt2jGxhELyBFBhP93P9kECERZF0DBEriHyEyAZg== 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=HcFhOOyCAg0pxM2P8Hxtqb2nQYZd2mVqG51j/7hxr5I=; b=vPvxyPi5Lagb4qVRI3AhoItkZOEsRbHJBJM/QgE83UCFYMlh6Iu3OifWEkC9ddwgQwyv0HubCSWCeVehJX3h2oN0CX7VH9RUxj7i2n9ruAwjUAWEA+M8iN/guT41QEib+l0QRtw68L4JvoRDSMvgvHW1/Wa1rCmeWbQyUKQQLfU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:22 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:22 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de 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, kbusch@kernel.org, John Garry Subject: [PATCH v5 4/7] xfs: Support FS_XFLAG_ATOMICWRITES for forcealign Date: Sat, 17 Aug 2024 09:47:57 +0000 Message-Id: <20240817094800.776408-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: BN8PR04CA0062.namprd04.prod.outlook.com (2603:10b6:408:d4::36) 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_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: 304c6ecf-e23d-4820-50ee-08dcbea1bb8f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: HKNt5JoB1n6xU+azzoBUcUBTbgsARGIR7a5N9ldppJh9BhnCMG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rUr0pfpQ6KvReVjHHx0hJ7PgJtC2fmS3n//hsp9RruITuqqqc2xgEix0L93OV5yvuSTuUlW2hcw3OMashVKsf5xwAGC78jLjohtLJ3sGpkUrgr5j074eOzk35MJi0pt1B/NPoUX0W42AFmyx4BHFCHitUbrQP+My+3WTm3wJ1QU/fn/9F0G+DIkw9CkTY8f3CaL+YOU9J3hkxn1my37Qi8ueiWqkZvaj54M5RNK/Xw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7jkp+CHn31/ZJZ1U0xigYXhczC9275pz0rg47VeOmHCvaQmMfrufEd5TRDCTlmQRr/9PF/hlJE3Ycr18y7mU/vB9ulEuUhUfTC8O/mTRQ6Tb0Jy0pi+W++MO10iBt1GoX2PXzCPh38rxvzS/xo2JJXt+rFqOQExbrHAQVlEAS0WvCmAozZ959t7ZoeTxmMBZ908yRNZQK+FlZtGTGJL6zFAPvNVJimYyvhVlNv2b2LghocDy26sVXpCJPOVrB1EoadKuAfG7X4OmevnsC+V+Hq1FtF4Fpxs/ciRc0G4FHYL/Sny8SyL07kn0Ayw0wxQ0J0qOzsogNjlCK6alDs/ywf21Glkd/PiaFQHDYIxXj44r8nDGWDIKWw/NWXJvrSOU0F8Zv30mWRjFBBg/t+igF6B1jbEzfCTXBG+199NLDoNIXyLkKyKOlpX+vMxg9PMEXoFfApqTprzEFTzGUNBJDbfTf9UM8AWPyrGaXXOwQ1tOjB5lBUdJQh++MAvzEorhUkhf62q9/1nRbFJ4t80d2AOcXGZXMfENPNZE1wHthPo+8sxeR69rEyYcKwFY25aqdxQS/HsKp9XpiYD5fA/j5wAV7ixTH9Eb9DNnNgSfVxTX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WgTFuU7lgaG5YyX/9z1CIXX6mDYD4BTnEHX234jKXD0Mp3KcuAXcrfNWJlABroElZljWbt4JadpEgcufbKf3kUUaRi1xvI6CxUr1Ey9aiH3jgxzRpy2wPjPOmx4T/sAQ75CMJY7JQzWtgG60GmwDBDgfkaY6E+GOogqj2SmBC9r1whjnZNf9aYE7DPPVueXo9QcVVtmPphB2JPPcTNupDRqkJiEtlUJ/IMHt8kQHkqvECleGqvho88ZoiF8pg+wpggIdk9qEG3WI0VtuHuYYvvDEG2PguicBkYi3afXjlk75nc4Lu39LewW1umtBfsR5PBO5tLK4RKtxY0V56xl0IrL4WTQEgklyWCs+SLrMexiLDvjM8BwDHHa14T/qk75nejr7/CO8F2TYZk2xmuP1IyRjZeAnrpkpuwN8JOosPKpEi4qNa78vUkRgSZrBC3x2eQoCHnSYFZ7KzcinR+qUe/Lr9eqkbK54RnBwLqyC9ilCMF63Oev0zYczFb9iaEpfeK+sY8SZNWdojOJmri45BEhactlNQwDKHarSPhn1C7WJnN2dJdrQ9KLRhnqBgg+WxAnTwHAaujWzaVST0orqPz44VQ6lobipImaXo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 304c6ecf-e23d-4820-50ee-08dcbea1bb8f X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:22.6659 (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: FL3Nh6mu+S2BREhP9tVTmdeFo5gyF3QtXbBBiYlhMNOhoBrAX/xfYiOOPfYTxKalFWXux5KsXa2UBeatAbsEtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: PvCAhgsaY20Ko9uByycfcqUlbaFonJKI X-Proofpoint-GUID: PvCAhgsaY20Ko9uByycfcqUlbaFonJKI Add initial support for new flag FS_XFLAG_ATOMICWRITES for forcealign enabled. This flag is a file attribute that mirrors an ondisk inode flag. Actual support for untorn file writes (for now) depends on both the iflag and the underlying storage devices, which we can only really check at statx and pwritev2() time. This is the same story as FS_XFLAG_DAX, which signals to the fs that we should try to enable the fsdax IO path on the file (instead of the regular page cache), but applications have to query STAT_ATTR_DAX to find out if they really got that IO path. Current kernel support for atomic writes is based on HW support (for atomic writes). As such, it is required to ensure extent alignment with atomic_write_unit_max so that an atomic write can result in a single HW-compliant IO operation. rtvol also guarantees extent alignment, but we are basing support initially on forcealign, which is not supported for rtvol yet. Signed-off-by: John Garry --- fs/xfs/libxfs/xfs_format.h | 11 +++++-- fs/xfs/libxfs/xfs_inode_buf.c | 52 ++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.c | 4 +++ fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_buf.c | 15 +++++++++- fs/xfs/xfs_buf.h | 4 ++- fs/xfs/xfs_buf_mem.c | 2 +- fs/xfs/xfs_inode.h | 5 ++++ fs/xfs/xfs_ioctl.c | 52 ++++++++++++++++++++++++++++++++++ fs/xfs/xfs_mount.h | 2 ++ fs/xfs/xfs_super.c | 12 ++++++++ include/uapi/linux/fs.h | 1 + 12 files changed, 157 insertions(+), 5 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 04c6cbc943c2..a9f3389438a6 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -353,12 +353,16 @@ xfs_sb_has_compat_feature( #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2) /* reflinked files */ #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3) /* inobt block counts */ #define XFS_SB_FEAT_RO_COMPAT_FORCEALIGN (1 << 30) /* aligned file data extents */ +#define XFS_SB_FEAT_RO_COMPAT_ATOMICWRITES (1 << 31) /* atomicwrites enabled */ + #define XFS_SB_FEAT_RO_COMPAT_ALL \ (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ XFS_SB_FEAT_RO_COMPAT_REFLINK| \ XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \ - XFS_SB_FEAT_RO_COMPAT_FORCEALIGN) + XFS_SB_FEAT_RO_COMPAT_FORCEALIGN | \ + XFS_SB_FEAT_RO_COMPAT_ATOMICWRITES) + #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL static inline bool xfs_sb_has_ro_compat_feature( @@ -1097,6 +1101,7 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) #define XFS_DIFLAG2_NREXT64_BIT 4 /* large extent counters */ /* data extent mappings for regular files must be aligned to extent size hint */ #define XFS_DIFLAG2_FORCEALIGN_BIT 5 +#define XFS_DIFLAG2_ATOMICWRITES_BIT 6 #define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT) #define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT) @@ -1104,10 +1109,12 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) #define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT) #define XFS_DIFLAG2_NREXT64 (1 << XFS_DIFLAG2_NREXT64_BIT) #define XFS_DIFLAG2_FORCEALIGN (1 << XFS_DIFLAG2_FORCEALIGN_BIT) +#define XFS_DIFLAG2_ATOMICWRITES (1 << XFS_DIFLAG2_ATOMICWRITES_BIT) #define XFS_DIFLAG2_ANY \ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \ - XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_FORCEALIGN) + XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_FORCEALIGN | \ + XFS_DIFLAG2_ATOMICWRITES) static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip) { diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 1c59891fa9e2..59933c7df56d 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -178,7 +178,10 @@ xfs_inode_from_disk( struct xfs_inode *ip, struct xfs_dinode *from) { + struct xfs_buftarg *target = xfs_inode_buftarg(ip); struct inode *inode = VFS_I(ip); + struct xfs_mount *mp = ip->i_mount; + struct xfs_sb *sbp = &mp->m_sb; int error; xfs_failaddr_t fa; @@ -261,6 +264,13 @@ xfs_inode_from_disk( } if (xfs_is_reflink_inode(ip)) xfs_ifork_init_cow(ip); + + if (xfs_inode_has_atomicwrites(ip)) { + if (sbp->sb_blocksize < target->bt_bdev_awu_min || + sbp->sb_blocksize * ip->i_extsize > target->bt_bdev_awu_max) + ip->i_diflags2 &= ~XFS_DIFLAG2_ATOMICWRITES; + } + return 0; out_destroy_data_fork: @@ -483,6 +493,40 @@ xfs_dinode_verify_nrext64( return NULL; } +static xfs_failaddr_t +xfs_inode_validate_atomicwrites( + struct xfs_mount *mp, + uint32_t extsize, + uint64_t flags2) +{ + /* superblock rocompat feature flag */ + if (!xfs_has_atomicwrites(mp)) + return __this_address; + + /* + * forcealign is required, so rely on sanity checks in + * xfs_inode_validate_forcealign() + */ + if (!(flags2 & XFS_DIFLAG2_FORCEALIGN)) + return __this_address; + + if (!is_power_of_2(extsize)) + return __this_address; + + /* Required to guarantee data block alignment */ + if (mp->m_sb.sb_agblocks % extsize) + return __this_address; + + /* Requires stripe unit+width be a multiple of extsize */ + if (mp->m_dalign && (mp->m_dalign % extsize)) + return __this_address; + + if (mp->m_swidth && (mp->m_swidth % extsize)) + return __this_address; + + return NULL; +} + xfs_failaddr_t xfs_dinode_verify( struct xfs_mount *mp, @@ -666,6 +710,14 @@ xfs_dinode_verify( return fa; } + if (flags2 & XFS_DIFLAG2_ATOMICWRITES) { + fa = xfs_inode_validate_atomicwrites(mp, + be32_to_cpu(dip->di_extsize), + flags2); + if (fa) + return fa; + } + return NULL; } diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index b264939d8855..dbd5b16e1844 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -82,6 +82,8 @@ xfs_flags2diflags2( di_flags2 |= XFS_DIFLAG2_COWEXTSIZE; if (xflags & FS_XFLAG_FORCEALIGN) di_flags2 |= XFS_DIFLAG2_FORCEALIGN; + if (xflags & FS_XFLAG_ATOMICWRITES) + di_flags2 |= XFS_DIFLAG2_ATOMICWRITES; return di_flags2; } @@ -130,6 +132,8 @@ xfs_ip2xflags( flags |= FS_XFLAG_COWEXTSIZE; if (ip->i_diflags2 & XFS_DIFLAG2_FORCEALIGN) flags |= FS_XFLAG_FORCEALIGN; + if (ip->i_diflags2 & XFS_DIFLAG2_ATOMICWRITES) + flags |= FS_XFLAG_ATOMICWRITES; } if (xfs_inode_has_attr_fork(ip)) diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index e56911553edd..5de8725bf93a 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -166,6 +166,8 @@ xfs_sb_version_to_features( features |= XFS_FEAT_INOBTCNT; if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_FORCEALIGN) features |= XFS_FEAT_FORCEALIGN; + if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_ATOMICWRITES) + features |= XFS_FEAT_ATOMICWRITES; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE) features |= XFS_FEAT_FTYPE; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index aa4dbda7b536..44bee3e2b2bb 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -2060,6 +2060,8 @@ int xfs_init_buftarg( struct xfs_buftarg *btp, size_t logical_sectorsize, + unsigned int awu_min, + unsigned int awu_max, const char *descr) { /* Set up device logical sector size mask */ @@ -2086,6 +2088,9 @@ xfs_init_buftarg( btp->bt_shrinker->scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker->private_data = btp; shrinker_register(btp->bt_shrinker); + + btp->bt_bdev_awu_min = awu_min; + btp->bt_bdev_awu_max = awu_max; return 0; out_destroy_io_count: @@ -2102,6 +2107,7 @@ xfs_alloc_buftarg( { struct xfs_buftarg *btp; const struct dax_holder_operations *ops = NULL; + unsigned int awu_min = 0, awu_max = 0; #if defined(CONFIG_FS_DAX) && defined(CONFIG_MEMORY_FAILURE) ops = &xfs_dax_holder_operations; @@ -2115,6 +2121,13 @@ xfs_alloc_buftarg( btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off, mp, ops); + if (bdev_can_atomic_write(btp->bt_bdev)) { + struct request_queue *q = bdev_get_queue(btp->bt_bdev); + + awu_min = queue_atomic_write_unit_min_bytes(q); + awu_max = queue_atomic_write_unit_max_bytes(q); + } + /* * When allocating the buftargs we have not yet read the super block and * thus don't know the file system sector size yet. @@ -2122,7 +2135,7 @@ xfs_alloc_buftarg( if (xfs_setsize_buftarg(btp, bdev_logical_block_size(btp->bt_bdev))) goto error_free; if (xfs_init_buftarg(btp, bdev_logical_block_size(btp->bt_bdev), - mp->m_super->s_id)) + awu_min, awu_max, mp->m_super->s_id)) goto error_free; return btp; diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index b1580644501f..3bcd8137d739 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -124,6 +124,8 @@ struct xfs_buftarg { struct percpu_counter bt_io_count; struct ratelimit_state bt_ioerror_rl; + unsigned int bt_bdev_awu_min, bt_bdev_awu_max; + /* built-in cache, if we're not using the perag one */ struct xfs_buf_cache bt_cache[]; }; @@ -393,7 +395,7 @@ bool xfs_verify_magic16(struct xfs_buf *bp, __be16 dmagic); /* for xfs_buf_mem.c only: */ int xfs_init_buftarg(struct xfs_buftarg *btp, size_t logical_sectorsize, - const char *descr); + unsigned int awu_min, unsigned int awu_max, const char *descr); void xfs_destroy_buftarg(struct xfs_buftarg *btp); #endif /* __XFS_BUF_H__ */ diff --git a/fs/xfs/xfs_buf_mem.c b/fs/xfs/xfs_buf_mem.c index 9bb2d24de709..af48a8da2f0f 100644 --- a/fs/xfs/xfs_buf_mem.c +++ b/fs/xfs/xfs_buf_mem.c @@ -93,7 +93,7 @@ xmbuf_alloc( btp->bt_meta_sectorsize = XMBUF_BLOCKSIZE; btp->bt_meta_sectormask = XMBUF_BLOCKSIZE - 1; - error = xfs_init_buftarg(btp, XMBUF_BLOCKSIZE, descr); + error = xfs_init_buftarg(btp, XMBUF_BLOCKSIZE, 0, 0, descr); if (error) goto out_bcache; diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 336124105c47..cfcb67da12cb 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -321,6 +321,11 @@ static inline bool xfs_inode_has_forcealign(struct xfs_inode *ip) return ip->i_diflags2 & XFS_DIFLAG2_FORCEALIGN; } +static inline bool xfs_inode_has_atomicwrites(struct xfs_inode *ip) +{ + return ip->i_diflags2 & XFS_DIFLAG2_ATOMICWRITES; +} + /* * Decide if this file is a realtime file whose data allocation unit is larger * than a single filesystem block. diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index a68ec68e5b92..7af2837779e8 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -502,6 +502,49 @@ xfs_ioctl_setattr_forcealign( return 0; } + +/* + * Forcealign requires a power-of-2 extent size hint. + */ +static int +xfs_ioctl_setattr_atomicwrites( + struct xfs_inode *ip, + struct fileattr *fa) +{ + struct xfs_buftarg *target = xfs_inode_buftarg(ip); + struct xfs_mount *mp = ip->i_mount; + uint32_t extsize = XFS_B_TO_FSB(mp, fa->fsx_extsize); + struct xfs_sb *sbp = &mp->m_sb; + + if (!xfs_has_atomicwrites(mp)) + return -EINVAL; + + if (!(fa->fsx_xflags & FS_XFLAG_FORCEALIGN)) + return -EINVAL; + + if (!is_power_of_2(extsize)) + return -EINVAL; + + /* Required to guarantee data block alignment */ + if (mp->m_sb.sb_agblocks % extsize) + return -EINVAL; + + /* Requires stripe unit+width be a multiple of extsize */ + if (mp->m_dalign && (mp->m_dalign % extsize)) + return -EINVAL; + + if (mp->m_swidth && (mp->m_swidth % extsize)) + return -EINVAL; + + if (target->bt_bdev_awu_min > sbp->sb_blocksize) + return -EINVAL; + + if (target->bt_bdev_awu_max < fa->fsx_extsize) + return -EINVAL; + + return 0; +} + static int xfs_ioctl_setattr_xflags( struct xfs_trans *tp, @@ -511,9 +554,12 @@ xfs_ioctl_setattr_xflags( struct xfs_mount *mp = ip->i_mount; bool rtflag = (fa->fsx_xflags & FS_XFLAG_REALTIME); bool forcealign = fa->fsx_xflags & FS_XFLAG_FORCEALIGN; + bool atomic_writes; uint64_t i_flags2; int error; + atomic_writes = fa->fsx_xflags & FS_XFLAG_ATOMICWRITES; + /* Can't change RT or forcealign flags if any extents are allocated. */ if (rtflag != XFS_IS_REALTIME_INODE(ip) || forcealign != xfs_inode_has_forcealign(ip)) { @@ -554,6 +600,12 @@ xfs_ioctl_setattr_xflags( return error; } + if (atomic_writes) { + error = xfs_ioctl_setattr_atomicwrites(ip, fa); + if (error) + return error; + } + ip->i_diflags = xfs_flags2diflags(ip, fa->fsx_xflags); ip->i_diflags2 = i_flags2; diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 30228fea908d..0c5a3ae3cdaf 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -300,6 +300,7 @@ typedef struct xfs_mount { #define XFS_FEAT_NREXT64 (1ULL << 26) /* large extent counters */ #define XFS_FEAT_EXCHANGE_RANGE (1ULL << 27) /* exchange range */ #define XFS_FEAT_FORCEALIGN (1ULL << 28) /* aligned file data extents */ +#define XFS_FEAT_ATOMICWRITES (1ULL << 29) /* atomic writes support */ /* Mount features */ #define XFS_FEAT_NOATTR2 (1ULL << 48) /* disable attr2 creation */ @@ -387,6 +388,7 @@ __XFS_HAS_V4_FEAT(v3inodes, V3INODES) __XFS_HAS_V4_FEAT(crc, CRC) __XFS_HAS_V4_FEAT(pquotino, PQUOTINO) __XFS_HAS_FEAT(forcealign, FORCEALIGN) +__XFS_HAS_FEAT(atomicwrites, ATOMICWRITES) /* * Mount features diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index b52a01b50387..5352b90b2bb6 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1721,6 +1721,18 @@ xfs_fs_fill_super( mp->m_features &= ~XFS_FEAT_DISCARD; } + if (xfs_has_atomicwrites(mp)) { + if (!xfs_has_forcealign(mp)) { + xfs_alert(mp, + "forcealign required for atomicwrites!"); + error = -EINVAL; + goto out_filestream_unmount; + } + + xfs_warn(mp, +"EXPERIMENTAL atomicwrites feature in use. Use at your own risk!"); + } + if (xfs_has_reflink(mp)) { if (mp->m_sb.sb_rblocks) { xfs_alert(mp, diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index f55d650f904a..c416f549e94d 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -160,6 +160,7 @@ struct fsxattr { #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */ /* data extent mappings for regular files must be aligned to extent size hint */ #define FS_XFLAG_FORCEALIGN 0x00020000 +#define FS_XFLAG_ATOMICWRITES 0x00040000 /* atomic writes enabled */ #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ /* the read-only stuff doesn't really belong here, but any other place is From patchwork Sat Aug 17 09:47:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767101 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 2D47414EC4B; Sat, 17 Aug 2024 09:48:42 +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=1723888125; cv=fail; b=r4EDHuFbaZH6qCd0lazvRP3ST3Vs/jVb9Lodm+B5aQ6yiJT4b++D8xFTOiPmOuLuXS9bYECFZ2iGe9y9BZB4a2NMFs7jPeH1OsHX9+i/Dltmm7JzZw3GNekr3oLFhB6yA55D7B0LwAHxohRxYZNPCFcMAlrJmAMZyMlmj5+q8Ew= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888125; c=relaxed/simple; bh=eHi+Sr+xKoY6ew/Iq7+B+dzKCz/w1yaKXTEgpjcVStA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=OGCXCusgEHPxD4OuQI/lKCvfkBIsKKu3hC3rJDjnYKgXsjuhuP0y0/UPdDCDSHuPMTd4qpT+h9PYnq1RcQVn1KLpbZDqcsSkUNTU5jIVbe/9Q/erYu1ZC6bw0bxnfzajZXTetnO53S8MTfEC+P0PfsK9AwT+4f0GN3HgdK47iLo= 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=V9ei0Dg3; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=B0tQo8IM; 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="V9ei0Dg3"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="B0tQo8IM" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H4jcEI010282; Sat, 17 Aug 2024 09:48:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=LFa4FRTWKLYa9qsjerysXyWyYZxrVlTZrd7Quw8jk7k=; b= V9ei0Dg3IZAL0QRHYhHw72NHaNFPQiYZ8LgnSVDOXl9ntr88pDfPlvoEhLcYlMf9 CdWIT+df6AZkWZIz4tXquZXn5WsYYtnEKjLjtAg+OOQoW1Ab+fcWjJbGevbw8XMI lbPsnqt5qStXCwk4j1eIV2yPMRIbKvtFKZ0ThW2T34GHg/oRwYXO2CJQuqm63hLW Nu2jnjq6rhKXaULFDYShaA/LqkZpnUDScLTh/BeS/NAT90qfma6xEOXwJGWmNw5+ 9rtPWISZt5gpuBUqjMfb4YStd5oEV3vfgRM3wV1XB6PIiI8JMdiRxW1T5NMZBLUH dIt/CokKDI+7YjZSgIVtuQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412mdsr7ax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:28 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H811UJ031437; Sat, 17 Aug 2024 09:48:27 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2175.outbound.protection.outlook.com [104.47.57.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 412ja5y121-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i+UXyKH9qMNBP/GrpxXrL7+69G/+8L5aEdN4Q+A/JqGaLtHuMSW2mHpxS6rdfhRyvQhhmyrkuMEps2rpFMOcLIH0GIk5fMpRz10A3aK1xj6m5FTrDcc82zwnWdz8IGX6Z06ZrMuihUWLfy2T0EHO7dSXbc6zkFOA9rC6xYc+66ajP/BiCZnR/78BPHhaNyHL0/LjxH8A4FBacBeweLANEi5H5MduWRH464CMrbTr7j4+7n45uYy1dA7CwRmEDi4K0qObfl0PhsZtzcjHkkPE9QovFgHUgkZJ6GG2QEpSgBsOQKs2RIf/Z/5v6b4QEUbnLwh9nnwm+jBKVrq/KCMJTA== 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=LFa4FRTWKLYa9qsjerysXyWyYZxrVlTZrd7Quw8jk7k=; b=uNkrBQZFSt3ExA21hQPlOy+lHgmWZKElc62OvsG4P//7Uc3cXVDcC6HQYYYfPd3bnog5ZWwaWwbavmGRYdZZ0PPSqtR2L6H5T/2eON2WQPS6RIF3lrsnAmYtSQQfARyfCdR2/I9/rlQYtIKcHBGUNcltSzPAofTJvqNa+cy14mMi80umlrW+8qWRMoQtccs5ayvpF74oMgsUluQjcqvjdZWNXiCWHDf3L88bubC8WgzXAHhrMlB/4Dn89MoiYRU+6Axk0hHIiR00uwjyIpc6GE21WFGo3bt7qqIC5uSj+3WpfFkMgQ/zObY4KcSjtB6vK/dUD8ilo8vkxnL4DMngOQ== 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=LFa4FRTWKLYa9qsjerysXyWyYZxrVlTZrd7Quw8jk7k=; b=B0tQo8IMANVYcO4QPYcGd3XcYrh2ix9opuDEnlPLyukFNuE1NwzH6yNAFzUT60Sl415xrLIIqEgcfzvoMHo+vSXZ00COqcRB6FbV5LyiMfmy8wbMbgbpsPFKxEg5eq/zFIHFZQ61k+GkBX7Ibkxb6xZwHKzGcuMzG2XKK/Ce5WE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:24 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:24 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de 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, kbusch@kernel.org, John Garry Subject: [PATCH v5 5/7] xfs: Support atomic write for statx Date: Sat, 17 Aug 2024 09:47:58 +0000 Message-Id: <20240817094800.776408-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: LV3P220CA0010.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:234::30) 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_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: 827a42f3-a7b7-4d14-6455-08dcbea1bc70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: JCFuHyjOZDhGrQ6PfiAjdM7v11/CZKcurNttdUul7JQI0yIcJUQIBok0sbSKj12AyfUkz3+OdKUFj4W4lFjEYMInY5j3cy1NdZ+Fjsw+xkW4oDwKVfrv1fBUIOOaDGA0LG0xNLUr0G904ubgoCarjy/OpDi6evroT/H2U1T3Q5cGNdLI7y238W6vur+kWX3PX7Yze5v+7wyn7AfzOjJrVL1Bthv24pZ4I7DSb04RiWzOW8qYbsQ8CPJa4XtSeUfxVgCo3pDk8lXhCQSPair8tt0Q6UhsGNCW/QTMLE27SdH+9B+zNKGFCybM98JxoXuGlO9jGHvbdIc3zaFL3ygKxQJdgwXqsvBE/Rzvtg7CgzylTNLodkz7LkM3Tk40qefku7skyDWf1bYIZ3HMWDW/QlS53BGYB3AeatCUd0/YjicnvZUruRi6w0gqpD+0cxqE1/xz1hfWB5qgxK+/rNc2QS17tEOVLuTjvZynMVmfdqjzfqstf50GTJaUEEfuUfN625Aj0QCKAgkePH9SmOv52NSz8MTeb2ttx8HHxSaTdmDTskEXXkVjGYH7pbmVUqGWmQeQuI84sUuuZM7QMy8YO0dqCB9RqsvdxLnNQTANj5cpUQ9zM/pwiSV8fbJy9QjOFBSTI2kNGX08DuRD/yEs5Lid+gFSkkj01VKn27egB0YCEl1o8h5TA7/8g/QestP8Flb7bi9jWFhj4HKfUQ2fd//ZN74yLdKDsDzCITpiua0uBea268BowNEugr793yf78ZDTyMNvsG4JbwUEa9x693JmnduRcm+9kRP3BtGL2pAq9rovMlGNsUHJDI0fpIpC+FT6fMii04tB1iI43VwC2HJVSsP4xL8ArBDDDfefsYLiaytnJLFJET/JjGgTv13AyXJMz3Xl0jM+zqpu+JYeNGTLc3KUV2vYyyFnmwARgqr8LgfeBaaFOxPEB8L6QusvCDuZepzwHHfmibxuFEtcJm70vvgQyaw9ooJqqQhkg7hrbO9nx/5qGtATzRA9kGvOspRRkq0clF9udZ2tgxSegJooMI/dAjuqRXhyUv2veK28tlEcCYs1WD8ZV/sAtzhj3fNZr+hfJqIlZAq2hkBPTQw4OxPAu+Oyh/d4DVr4zVs9c08KaaL1Ygp9B6aNeSlC6yLB+9W+Jkw3IvYhGGua/sXc0OCvYrbhGwEi8rxD/J1xu7C2VCN/kim7HFuMKdudZS8U6vL5rFxRgDJ1vLTedbauTv4p4vS5mWC2U3zOjdayIitLxCdc0IW2MaWdrWEV3HjWaJZLvexDPadzZutkAhe6iweJhYaazifZ8pcXRBJgKWGeB0V/RDbHl65y3QDGqlGJaTq6/JDoNsMEDPd+SA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TZtzNb1yW+ccGSHVON6rxKGC99CZL2Rt6ohzkhWRi4mUPj7mVoIxlQWlyme7FkWuqTrCplLxHtm4agSaB78RUZlil5qu+t1dsR454u6i3bxJzHnoxEPf/4Kvw34lhXFQXa3bneytiIsqAT0jRBb0jBRneJzZjrXN+yF8AMKBMsxagi91Igy4OYeVs3cUS5J1aLe3oBTg2GwiiNHwXANfmeiWs3A0yBWjMPOyX8Hve/pxyxtTyfnbGgK6AbFZbUtJLS/WcIp9eSOXfnJCKBjKC0EIjDdonl7pIEl2U+R7Gn2x3Onkj2etW4HT/bK6KxfUKaxMyqNq2dCBRU0dVoDX2itR2oS8dv70WRNMUd6m/YtuIuGpoFM3/iCoIDxJxhllan/7U/wgyK9KurIRfvzOhn7eTOUesdiGEnynIWw5/XKtpigZWycwa5IAWaJJ7l/3A2EleQ6565AE4CHsQwaxR+0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OoxClHJVi5ShpEteTnmq6wCj0lf/AcKxJlfpHTX2h2zVaFhi399OFP/I+xFOYNV2ApNvNHg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: JwH3/IBiASEX9lySH9Dk9X1+93Qez87dqkyIZyjWUM3B9HYJevh1guPtMZJCiVb0882pAZ3mRtZ5vU17AA8m3REkDGfIv4HD0Zpiu2QlNt9NDKQbYQQHlsb8G/605TdnIS6vGGN9jHpVYwE2tnhRlVP/NeEgsX68yZ8Pjl9Y1NXapJeoRsfWjoeEb4H6H7Uj53m6+HJqARDkLS3zj1g9WOeZx2JhuTjg9STs0knWZk0qS/fYXl9FbUluXi2P92C3LRtuRQBemKJIHS6KdIZqt9XpzD/8+qHxP+r2FKSQmUFYOxfPfREWGILA3nffTWik0XkPSe1j9y2LHATJ25EmYYnqyQWuxeBny1UUpauE5KaRwgVLCYbnKJwSjmW9HZtVMvNvrFWy3hcRz4aYQiOQTIK2GWoKbN6csXpOzoXG0oULEsH054sKlKTxnKx4rl1cYfUc05FFsIWBG5Lnzpx7p6gWBNrb/FY5+E7IoVFYDIZO8PXdZlcg0WIuiXYtR1NFvk9vgH5RKTgQMDTE/07/+76zyWngPV6OaqwxI+9UbDfFnf+azGvV5aVMlcSWNbElGOHVSFbPJGzwJazTiynMUnUzwJseuxiMOJn6bc4Djbg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 827a42f3-a7b7-4d14-6455-08dcbea1bc70 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:24.1433 (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: ++e/SfUDIPxKVDnz6hjDSA4MWwqXJzdiCgAbjVjh18yrAreJmYxwR+NYPxxY3oiwywsyRNhDlifIV2vUS5WixQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: 64SJE5CeYWdLldsjMedtXExwlKzLmXIB X-Proofpoint-GUID: 64SJE5CeYWdLldsjMedtXExwlKzLmXIB Support providing info on atomic write unit min and max for an inode. For simplicity, currently we limit the min at the FS block size, but a lower limit could be supported in future. This is required by iomap DIO. The atomic write unit min and max is limited by the guaranteed extent alignment for the inode. Signed-off-by: John Garry --- fs/xfs/xfs_iops.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 6e017aa6f61d..c20becd3a7c9 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -570,6 +570,27 @@ xfs_stat_blksize( return PAGE_SIZE; } +static void +xfs_get_atomic_write_attr( + struct xfs_inode *ip, + unsigned int *unit_min, + unsigned int *unit_max) +{ + struct xfs_buftarg *target = xfs_inode_buftarg(ip); + struct xfs_mount *mp = ip->i_mount; + struct xfs_sb *sbp = &mp->m_sb; + unsigned int extsz_bytes = XFS_FSB_TO_B(mp, ip->i_extsize); + + if (!xfs_inode_has_atomicwrites(ip)) { + *unit_min = 0; + *unit_max = 0; + return; + } + + *unit_min = sbp->sb_blocksize; + *unit_max = min(target->bt_bdev_awu_max, extsz_bytes); +} + STATIC int xfs_vn_getattr( struct mnt_idmap *idmap, @@ -643,6 +664,13 @@ xfs_vn_getattr( stat->dio_mem_align = bdev_dma_alignment(bdev) + 1; stat->dio_offset_align = bdev_logical_block_size(bdev); } + if (request_mask & STATX_WRITE_ATOMIC) { + unsigned int unit_min, unit_max; + + xfs_get_atomic_write_attr(ip, &unit_min, &unit_max); + generic_fill_statx_atomic_writes(stat, + unit_min, unit_max); + } fallthrough; default: stat->blksize = xfs_stat_blksize(ip); From patchwork Sat Aug 17 09:47:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767102 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 2F10914EC4E; Sat, 17 Aug 2024 09:48:42 +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=1723888125; cv=fail; b=fKlaWqusd13OdPiEOeVgiN0IQ8nJuw1ZyQE/3h/RG3WwBw13YuYJaBUq+Fwv3hgcVQ6WY8BUhJQqu87DHpg8h9lXqsbriYktEX7UdzSPC10O2EMmXHMzM3Vu2QmE5kfg00EvfgGlSk1C3EdEu+rxwLhCgJz2wLrrAdCyPk8RsWE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888125; c=relaxed/simple; bh=D4aXnk8UeMaPh0XQlyOSWm/OMrNuFw7/bGsduXlbJAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=u6PwQCpOLtZIVaGGG64b7aEEIlB9ndj5nDl4mYkOUc0J+Ca4TUqYNJXsXgFUsxl9K+3wsg3/IrXFysFc+oBehlJHwSNvbpHuhXpN8sBqs9nqwZbSWED76r11GtqUYmykbBH41mi+O9RGz0DvOKGhVj+Xjk3Jdjm77EeoU8/7RCY= 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=TM8yJKMM; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=iKxfI+5M; 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="TM8yJKMM"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="iKxfI+5M" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H8G7I3018252; Sat, 17 Aug 2024 09:48:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=XBgSR9D8hHZU1SortIL7gHTZlCU2PByJAQHBZrYkVrc=; b= TM8yJKMMgLEOsff8MzXODQRzxwZ3fkOwAltf8PvvgN1BlottbQLIx0muBAb8PlOJ G1PRHvZ3I9dzImQx0NHoHo6jdX6lC8Xa5SAMuQYJBGnPLQe0juoNnYsvS/m5mL86 EX3vVZSXAlm6MuLFSqJXveAgXbfXwg76Aw/GAzs5Ga0G4knHVQYjzBp8aeKcOgXz uKTGEroB8AIvaRKhLp71TrGBV7/5TtCC9C/iUVaWXojzHQ1gIl5hl1nRlfIWr9vm GpTr/FxUjMkeXjmAjJeCXxDFGLlJhLgMStUor4GtTVM3yuX5cy7O2IDIEpVjVmPA ILP3/8XEbAREeNiqTmqvCA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m4587mu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:28 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H811UK031437; Sat, 17 Aug 2024 09:48:28 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2175.outbound.protection.outlook.com [104.47.57.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 412ja5y121-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Va8xUixT3hipfP2wiVvG5l4fEhZZMbWBABKrQpjDLko2O9sdmM2myICLj4IqvV4S/+BRGTo/9Gi2qD897LFJbHpt99RmeUaaVESNWPQJAUNtIQ79UbFdjMbGTCV4742LGZ7L+5RhNcY1/Uu8u+mcVMnFkbcCxYhgSGPHD6yNWaNEMfiHf4W4dcfrL0WAueaSrLqzpOOYsODXFUa68+FfndYJd10fs8tpGJ1Re1TbQsKpsls6NVnopHo4W4hvGAaCU5TU/Lu8LBZwPy0a9qNyd1aeJD3lXuatFN5wcBsy92FTUakRB2h6FskQaFapEnVDjzSRz9GT2Loe8SWfQUVwbA== 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=XBgSR9D8hHZU1SortIL7gHTZlCU2PByJAQHBZrYkVrc=; b=WKJsv6+Usl5c2Cg0yavbWSn/dpmQM+7bGPD/v2GSRLC3RC4rjCaxjS4ndvcURjZWDNcpu1bmvMyhfM4EF7hpgdt5Va5APYzPq7KIPpMzC89VtGW1t8B2s+vE+/NiyiTzvCudUXr8AG8N+EuUB/TN7uKbvDhkvEuouPuZUoGmHQ7nnwFkagtQv9tnB2EjvDRbjjaXnUkQrs5zBzN52/99sYobpR+EbCyg5vz8JErh5y9mgtS03aj78yl9qBhy1MQ6bufdvS8ZJPP09tZugmFWIe2WN+7WLo48HMEeM5g9lsfr0NXZQgq64SYc7pyzX2pVtBp+hSz2VllmZ7WCMZO/8A== 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=XBgSR9D8hHZU1SortIL7gHTZlCU2PByJAQHBZrYkVrc=; b=iKxfI+5MD737PayY477xKQJ1pL4UgA2m/5p0poJGNCu+tVlFp6tt1Itl8ELCG6iuMih2OQQ4VO2TnPGVhB2rqj+P6UuTWs8yNVH7fdLPHZOqfcT9p4krd8YFPiJcYEQIccRc9rqz1kw6VpIKbP+ERp0axwcDiWZtLEb9b/ExEGI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:25 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:25 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de 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, kbusch@kernel.org, John Garry Subject: [PATCH v5 6/7] xfs: Validate atomic writes Date: Sat, 17 Aug 2024 09:47:59 +0000 Message-Id: <20240817094800.776408-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR02CA0023.namprd02.prod.outlook.com (2603:10b6:208:fc::36) 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_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: fe48bc44-c381-43e3-2c93-08dcbea1bd2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 01ZlNN/hcKDhReRJZLH4c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svetWPcIHZHKFWlIh9XaRisJHB4QiTCroDb6HFJk+UlXVX2FZMQWpZseo7syjldJjsOxnhzzgT2hggdxUW0y31WUfZJoPPXQ2Yy9kjx2sF90hMbeo9gLnPuhi9lq8kX+GdswS9ELbpFuI78c3u1ToAsfURJb8m/z2gnHKYiZdFNh8cfeCk7TvnktOX92wfONQNGVkRE+6ieyY5OyulgsbD1FMyDhvptxDmUtdbplxfL3/bnbucV7V6GXsmxQM6NQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fvuy0Dv/arA7NOFTR3iXcANs9D94oQsSl5EN9btDfhYYgLlMM0FvwkcJSniJksZArTWPrM74KZwFL4Ku1yP+jVJRgrWCatgWWGU6u1fxxvkwNLAkbLj8LJKFhd6PkjMiW9MgfNJwjcw2+khYULFBpZOtPDtnZUG8kIk3i9iDv1iPaUTyzl8p+O2JMYTsgMv6Egs/OXq/mA2YDvHj1wfe489QeOkEIYyDMTlxh56VtC6BxFaj2pSce0NLCBXJCZud7A7f4XYTjpq3tjeHSZLT3MJQRLhx+voNfh5T4tP27P+hETqXLIWdAJ0hnCMfHVdVvxYgzXGJREaswuKayfRzslJvKdxxMFtG6q+zK4uY7Zxn5eBUsnkoxG8cOaVo72QMUScqNMEc6oEp6QfuTH0yn6OwqzAMjD9UgdGTST0Ep4pCcrgjeRH7fhlfrT/RxtSSucqfcnSjX65E8MVVplsAaIhxC3vcYU/dF03xF7TupBkUtVzeGR2UZQrP2zsubRul20q4/4rRw2e+PMAuec+0J5lXGXK7/FPe6QJ8xFp6T1Z9e+N6s/97cHLhVC0vkRzKvdi49pLlUGKVQzo7TpCbGp7y+aUR2n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-ExternalHop-MessageData-0: uAthMtHjvOu7hiqKU08bcDK9FPDb+mn8Tyo0GxjXnuahoxmK2cG1hfW55WiUcjtP1HOxFk8IsrSk2Vcgog2ARbIxm6an/kLqZs6pJ/EERNaB6zt3k2O8bu/0Sgxjpfj9A375fsD041/oXyn8RIEMMV5ZZiDw11umfNwVzvsEa/cVoHyNrEqF2z1hzCSQBUqKqKe+EgxtaT5yBTENz56i1PSt2V9eSmPtlbHrTJMOGdWlruUMePsG8ecj9DTS0zyaKhKdctHBuxHG4g3lHw8+BjQ0S4XSQLc2B9948QmH7XRpOZw/qS2TeyiSNVMBH7lwUb5Y5QhsG7SmTZXM5Kv49rZFZTVjZegilk0kwuIfoJ1pEFWZlEj7QyQMBzHhSbS8lSF52SC8F0z8qQ5ehiET1goTB8Z5u+kKPDcmO+1uJ7lznXyTZqA5tTBOtJun9JM/9gvXtmm4wd4lxMV335Mo+tkgNqgNXf7NC/jqnV4yw/97R0rG8AENj1H+kH96tJRuqk3TFitDvB6VUy8kmOj0g671L+wI2KzY1YL0X20VgeJr6jrFGDJiMhZTQtQdPPLdpNhFRVrYNkLD/ZyIkRXzJE1mXjMEfxfYZz3edXR0Iy0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe48bc44-c381-43e3-2c93-08dcbea1bd2c X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:25.4324 (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: kbpKJ6GzoIOt/JmMCXJXnNS/fJOogQwfl5ghXtppY5GNpM5E9IhTfECC644xvpOm06bsWNto0ai6QiHvyW2i/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: EP27VvkOVrsQN0No2GLXOroEKIZuq4Uq X-Proofpoint-GUID: EP27VvkOVrsQN0No2GLXOroEKIZuq4Uq Validate that an atomic write adheres to length/offset rules. Since we require extent alignment for atomic writes, this effectively also enforces that the BIO which iomap produces is aligned. For an IOCB with IOCB_ATOMIC set to get as far as xfs_file_dio_write(), FMODE_CAN_ATOMIC_WRITE will need to be set for the file; for this, FORCEALIGN and also ATOMICWRITES flags would also need to be set for the inode. Signed-off-by: John Garry --- fs/xfs/xfs_file.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 4cdc54dc9686..9b6530a4eb4a 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -684,9 +684,20 @@ xfs_file_dio_write( struct kiocb *iocb, struct iov_iter *from) { - struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); + struct inode *inode = file_inode(iocb->ki_filp); + struct xfs_inode *ip = XFS_I(inode); struct xfs_buftarg *target = xfs_inode_buftarg(ip); size_t count = iov_iter_count(from); + struct xfs_mount *mp = ip->i_mount; + + if (iocb->ki_flags & IOCB_ATOMIC) { + if (count < i_blocksize(inode)) + return -EINVAL; + if (count > XFS_FSB_TO_B(mp, ip->i_extsize)) + return -EINVAL; + if (!generic_atomic_write_valid(iocb, from)) + return -EINVAL; + } /* direct I/O must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask) From patchwork Sat Aug 17 09:48:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767105 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.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 991C314659D; Sat, 17 Aug 2024 09:50:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888243; cv=fail; b=X2MEzHu2CjaN+XL6Ib876WceXPc/JvZ4JxjOPPxpo32Z52QlLTp1ZLMejzNAVilKVEy+s3vDi5fDff6aWrCyKQm3yOxYS/Z6pc4vr+EvGB0MP8A70RRLTlNh2wZ0hdS1JRQd7JJkXtdKx11btXJfuOyEOfE9Eizq8qPNjIZDJik= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888243; c=relaxed/simple; bh=/PmvLwg2gc5mEPSuPtBUXqggXavSC5VczM11cmaj3ek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=YN3Z/nSJ7Lyu8E4iWlcu+gc4+aNdQOIDqWbXp2q5Pl7ua/TnP4tJMIdjpl9JDzfjmf6jqzBgZt0/p+Ubt1Mmlp8FW9VekMeZtPMxcIhFtuMs2K/8x23SSqaPx02r8hsUI2X/cHQv2VWzYJ3Kj18gHEZTVRgp6+xsDz418VBRcqU= 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=nEqMfpP3; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=m/B9mY3E; arc=fail smtp.client-ip=205.220.177.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="nEqMfpP3"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="m/B9mY3E" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H8VcB8020383; Sat, 17 Aug 2024 09:48:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=my3x/GJey/9khfYN7B75qEa1wmhc9epLDfdvaLxnatw=; b= nEqMfpP3foAMwpqu1J2RnMIYA3ueO0zCZLM6uNHc2LIKKTqKs6jDBjbcoe18Cxkf H5OqB9qP+NkX3vy4CK5fRM1hmaA5hQzB9cyFeTwFg052dBYranGsVu6UQPUrAGh6 sG+J1UEjUUoFmsuMu2uThWvhudSeyN2BBpgJOnvaTXHf2YmVCqmpEU0dUqZG5P1I 07z5wEYGf003wZGd1rOaOYOQpIAGFpnf2trJ19I8t1xRpD66I5IKBtHGsa9g/G+u csWkESOOdxnIQqn1IsqmoXiMGPaZigHNZeXM0ZZ1sfZ69DLuzPZA2fSR59s4Kjz6 i3CyALREDf1WsZZOBbs54Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m3hg7e7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:29 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H811UM031437; Sat, 17 Aug 2024 09:48:28 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2175.outbound.protection.outlook.com [104.47.57.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 412ja5y121-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IHtw3BLXImS789MYqzB7OR02DhqljHq5tuU3Vr39h6OKMucgmoL1mMq6+Cqca86hhdxqy+tXE8nm2c4WJkN4XZKJF81AJJQ1NbZxsgNh5JIdWPb2P3bbvDGmcUUmCvOVSOHnhoHBxWwvlOAhaAeIySFoOiFqEb5ny2YJrOsfdhWdA9iwa+7WZJ4672nkg38Tx9g9PwWltDjWSVlz4gVGlGqFWJtKJbAOaLjDCasFRhMroDA9ub36i1vguRu1gxBveaaur/5+fzxoUIpWd/3qN2PDZ1j/HLmaTDciMGOeia2nYyYTVex3kSTUlLredI1SspjruY3cL5hZBZXP999kFg== 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=my3x/GJey/9khfYN7B75qEa1wmhc9epLDfdvaLxnatw=; b=ZnmoYUaWDZnU10GOVsrzo9eoITlTK+Djvl1Kn70DAdnR0G2Axb5JuTfYwtkRuy3fMLJu3xulLnjH/BzkjGETDel19n6DouNS9WlAYNG6Bi2oCt5yV17qMXLs5RgwLhzwuoGo663yMHxkQNpwXNQK3ONbfGBg6Aq5pl0k+UORHvjkkUuEJWCMnAfNShhxBGzUUTEg/nolgvBNyU1zYIlw8bxw3gwkJN11QbKuFq52V/IR9jngUAk4++jqSHwhtktN+bY2wFAp0+vCYX1qSc8z9OeQnsuAqO9CUfMM6yrVhmpEbyMT1oI1EBB2sQJrCjqpFsRwr5cuOyZs6tpTpX7sbg== 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=my3x/GJey/9khfYN7B75qEa1wmhc9epLDfdvaLxnatw=; b=m/B9mY3Ei7nZj+/zeSyF7JO2tsu9Ou1CHx3q+IHmAmOJxnzUaeee4Ln5sKEK3m92736JWNQH5/tO44rujBysSoVXWyvfcKLvMBd8RMCJmmwMfrv4rNAwLfTj8eNxEePPkwTGzGBGv8SeNywfKbXCCT+C+ubOFRClwYIsaKXjasY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:27 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:27 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de 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, kbusch@kernel.org, John Garry Subject: [PATCH v5 7/7] xfs: Support setting FMODE_CAN_ATOMIC_WRITE Date: Sat, 17 Aug 2024 09:48:00 +0000 Message-Id: <20240817094800.776408-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR02CA0029.namprd02.prod.outlook.com (2603:10b6:208:fc::42) 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_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: b5a46481-f53d-4c08-913d-08dcbea1be1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 8s/RvbBrNDBlYTx0X+XznPBuaKtRwk+4EneG7rmcgkBbf8XWOg8pIM27/fHjijLM1AnEmP5NIi8e/1TO97jOZHS+50vsMdA0pbVcxngf/rhzGsLahkJa+Jrga0RKk8uEpvRrflG2dgAG0hG5QwZdaj05BDu8cZoBW8Cwy/yStFRDKSYrZBF5SmyLb4hh9e2OKj7xB3PJcMpfoBU+kQj/mS7VjJguzeFRO11hfAhITXVpich17MZRLvByv+w9dOWHg3Two6MEy7fjxfN3rR3s9FQtEVqrkF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Pg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y4+7kNX0+BH9GwLmjvrOm4FK/b+6vClrS7ViPEpxeUduNbbz+hwAVfi/69wOdCSkToINptZhEZq5ZYhn9LSahkDlp4UD0B9lL8ildG7Tqy32VQL9/PiknXMjh0teaHOOdGleHOIguuvA6/Sq+dPnh6T1W768341CrR4z9xJJ8EkdMVkEa34xSBEQ/UQyfBUDXClvauW689/LmEZxryiFxfZq1YonMUboxaR5oZmSau0TeEFI/znsf8nMe3RhCDkDX0I9cWgWgYnPeVJtitjMR3L2st4TlASCAyT/80TzR8XValzPUQhyAIn4/OgZrN6twHEXoimkA+oIAIDRV+x1qoDF9VCvKR6SqBxG3rMdgq0auVTFKPe9J5NNPFfn1hW5qYOpDoT8BtqiVWXSh3OI/JRSrU8SKbO7sbBidouhpCf17Vhp64SO9XbL0/YTUa75w2gxfarNexgJsPShjFjNpz1aoYDmrZyPD2diMu1F+fuitc3YbHA6btt2IeyLBMloPVBSfABtGqitIu4BJ1LF/MQ0XahAiAv4siN19ZM63UmCVRJ7yrUD8EMIsWXaLaLR4WRoLipw8+8niz4MrkIAsPVHgZiZ7C0/96Rer5crbjEwp8I5DfTP6Rh+JLrdALVA3uQao1h6EoHbbCQniwlumQXQc5yABwRSdfGuJCFm3WYIqEpz6bKy/FaRP7wNP9U1jhK0V4JcoSykXaNVV7O8flfkhyRLGA92lUlGWFlexLToVSvrMkSZ/I5Llkwu4FLvE/1FR8OEu+K1PYgOcKmVx9IBjT/Efm5Yl35MfjlBh2mlWgcYBV+p3Lp9rtZ7j8oBCPPR9dj+uSBaGxFl0ozrxQM98AcUwx1X2Xts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PBC4S4B2fNQCxSFx8GUsuKhzoRQ7NP9go+qTkkbMlQXLipM8mw3BLCeDzaJfytiEnu4jrOxDk7qPWMcAPbCJhZNw13c9cbb1FDHqRp9Ro6EjG2DABRqjMAZcYKmDpE5SLx0JzbHOWgpUzWqoXjpqhZ9aBIrhKyzHKK1iyXliGw6PqhA3O6GHOOXZ4aMLj9TIHOTDKazB8GZ9rUc85dSt/YygFB6VHMePtiRVJzzjofRcoh3XOpOFnhKwpVQwm4alYpNDd4H4fFmHb/d7Lc8YQZIUjGRD0u39IR4mvhAWdMR8iuayIvlcnIxIKSYWcWPBCj7677lc67MGA28wPPEu5HT8R9nfQwkSmQ+i9vgLb2ZBwOXAekqH67fJavFLsZ0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5a46481-f53d-4c08-913d-08dcbea1be1d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:27.0230 (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: FUVpcjWu0PCnAXKeL/2Qf2qMFA6C7tS0SvqFhR3HHTpr0kbPb0GRjEcJHnRobDghu7bukYyvGXoG71uw1rFk/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: E2AKdCACKgMYEiU_nzgf8lqTgA7IpjbG X-Proofpoint-GUID: E2AKdCACKgMYEiU_nzgf8lqTgA7IpjbG For when an inode is enabled for atomic writes, set FMODE_CAN_ATOMIC_WRITE flag. Only direct IO is currently supported, so check for that also. We rely on the block layer to reject atomic writes which exceed the bdev request_queue limits, so don't bother checking any such thing here. Signed-off-by: John Garry --- 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 9b6530a4eb4a..3489d478809e 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1149,6 +1149,18 @@ xfs_file_remap_range( return remapped > 0 ? remapped : ret; } +static bool xfs_file_open_can_atomicwrite( + struct inode *inode, + struct file *file) +{ + struct xfs_inode *ip = XFS_I(inode); + + if (!(file->f_flags & O_DIRECT)) + return false; + + return xfs_inode_has_atomicwrites(ip); +} + STATIC int xfs_file_open( struct inode *inode, @@ -1157,6 +1169,8 @@ xfs_file_open( if (xfs_is_shutdown(XFS_M(inode->i_sb))) return -EIO; file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT; + if (xfs_file_open_can_atomicwrite(inode, file)) + file->f_mode |= FMODE_CAN_ATOMIC_WRITE; return generic_file_open(inode, file); }