From patchwork Wed Oct 16 10:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13838089 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 E2A61207213; Wed, 16 Oct 2024 10:04:14 +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=1729073056; cv=fail; b=gOPMR0svGJWTat3bCWnRT83NPIyMy8g20ETk5FcaBz0+birACeYLmpRlm+dCupI5FSLp7SI7RyLekbo6VCqb2NV5c+10bKzzWU086cIwJsTXPucNbC03faUIRfzVJlEN9P1JhhZCe9BCeWc7aHLAq6BuJMC0NzOJRi64Xvyg45M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729073056; c=relaxed/simple; bh=GOiCNcapzhN1Hi79FTL2lTsFiOc15kCIgEEDUH+f1WU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=T+9D+EViVqxU/mlZvUafBS0bw4ipu3NM1zbiLjTGf6RsBQHT9ckVVNiD5ZK/p7HWnrBBYxI9nD+bSH7IJ1lPaEqggbPKmQNxLBrpcwyraa37/kb5CuzBgrleVSQVVzvnHnZiiFk1A5d+XiLP+w+qVTro6WgJUNBEtoUcuKA7F68= 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=RVnpvViY; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=rC64dnSz; 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="RVnpvViY"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="rC64dnSz" 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 49G9tfEb010088; Wed, 16 Oct 2024 10:03:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=IbaI8wdmvgvI+qEvkhliJjNYO1Y1ZNPP3yej5CL/TWk=; b= RVnpvViYpXyY3hg/MT//R4BxKlNSm6J0KdJ96STUG55x47WpB2XHMK7UtFbFvl6I xa3TmqFyGHBgEpu5XFHoKgi/m0Lp3Uh633rDr9FTL5XXfss482FPNnvRUrO/eGDQ RstnaaiN+DwqlrGr6K8Mv67m4HPEOGxnVQnlG+1IdNq4ey5/kM6NEWkVrM7rOhUG xeXl1Llr2FX3tQqcpVzreMhnEcWTnpHcfEecH9A2VG2a284ZvEi+ff7roje82V/g 8JLpJ59JmRIJOMOB5GPnrsHCb3o2pQfVwM82WY4LuQF16c19WOhXIw02+3v3GzZ3 iTN5bXYPJrxSVraRCWweFw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427hntbdg6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:03:59 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49G8r0Zu026718; Wed, 16 Oct 2024 10:03:57 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2168.outbound.protection.outlook.com [104.47.73.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 427fjf6eet-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2024 10:03:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=INj7BWO9t+ksOsnlsjWWXvzGry5xASX47cU5uziXTMktbRu0hcyQ7w5IMaC07U+F/cxtgNhXw32gxkHiNlCYwBBMm6xlVW03wLlUVij91NEWC41poEzzKvTPzkFWKRvrBnQE5qPIUnKATMjTAjRxokRFk8TINGZthtV+sBgvWrsgBWra/so5uUxrfalaero1sGm1T5tdEu+a+Zk30GeXMRBZNIH8t5no2CY6i9V2JOIeLmG4VxyJmSPJPMAjhbvo6PLqIZAoGzf9o0i8VEdfYm6P/K0b0olhIO7zNZ26q2g+x/hk7B0Kma5wKZrRKt0QUVjlsC656yyvovwJ9jfFYQ== 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=IbaI8wdmvgvI+qEvkhliJjNYO1Y1ZNPP3yej5CL/TWk=; b=aURvqxVcJSoL0FK1E6qJRoGjaunbpG1aNWgc+Sj7uRSvVBWYsimKDKeIuGmIlhLccRgo5eHjtCNe5KN7aG/DSaMxntXE6zWf57wadWsIAgX3yN38XeYBTkjxjZFMr84+A0tIvINJWA/fptxRVbUoNdx5wmexIUs7e7YRYr08E4pgmJORizV154xzKnMtaikboW5ej+LFbITIC8fA5Corqfaeay0pwrNBmmBfMT4CEitTjyxIQ79If4v57PVbWGHZBienh1I+9YupnCZBj8RSB138aQDN5P1wJHM+t1McV5kWMbDdWQgUQ9Eri8ZMVPtMtS+mQs6/I3NZJSzVOTiZ4Q== 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=IbaI8wdmvgvI+qEvkhliJjNYO1Y1ZNPP3yej5CL/TWk=; b=rC64dnSzl6yDg7A8pBYgta0UT0GP7z2+vpV7ooiePYO3JD+GtoEM9Kn08bYq+5tS8LLW0q8NK/t+ghgMW88egfwupB8BbqCrPEI8QH/0OdFiXqbDvAAvqHVQ2KTnHnOtEmIlz9TBbW9WgA15GHwxwIYoGZPJ7y2Sbcb8/xeQ8k4= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by CY8PR10MB6634.namprd10.prod.outlook.com (2603:10b6:930:56::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Wed, 16 Oct 2024 10:03:55 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%5]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 10:03:54 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, dchinner@redhat.com, hch@lst.de, cem@kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, hare@suse.de, martin.petersen@oracle.com, catherine.hoang@oracle.com, mcgrof@kernel.org, ritesh.list@gmail.com, ojaswin@linux.ibm.com, John Garry Subject: [PATCH v9 5/8] fs: iomap: Atomic write support Date: Wed, 16 Oct 2024 10:03:22 +0000 Message-Id: <20241016100325.3534494-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20241016100325.3534494-1-john.g.garry@oracle.com> References: <20241016100325.3534494-1-john.g.garry@oracle.com> X-ClientProxiedBy: BYAPR05CA0071.namprd05.prod.outlook.com (2603:10b6:a03:74::48) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|CY8PR10MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: de0c49cf-d649-481d-ea00-08dcedc9d801 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: 69GAg1y6Ic8mhrEVsDzXGdV3jE26K23c/q1UKjyd2R6ttB2iK+B6uTQ6z9vgm6eYnVkfua8MSRvnDkWkZY4cAPP6Ur9sawEca+1yS58Teu60MDITVxOKdv+63LRyvL8Vw0AV+rale1/kxtpBgMNZu5HNIju02Q9smqG81PRvVZAcryXBEm6VCZQW6/zbDDp4dwuOF8N0hoMS+WNEjpIhiBQPuxwWey0WdqBui9hDYC8T4T1J5zCiYAFXyE7h6yY0NSR+xmUeWbJ4Z4Yb3Lgm7HEAXfl3qBecQVx/OQPeN2sFenAAPYHULyzZtBX0gPkzrCwX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PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5tunbVVUWfO/CNTsisNmd49OQ+TSaUm4COLFZg/mWRDt6IJwD5Xu3lEpMb+B4xEt0n0Xb+XojFmADY/oT1JAcyqDOUUFPq7MV16cPSQX1Fm3RSViOeN8HHbwBFRuSOraIAvfHgBuFitTwyZ4vsh/fnFq5ga7eussZI003HNJpPMda03lYqy/WnKzmfE2ZEx0gDZmLP3M2bKdL4gUF5mHEsORy1G4L70N0Ws4qoAuXAd1ty0ld8IK1lG1n5gFNdQJHGqLltaXnKzExZE4YMAwrjJ8+0Wl9lnZM21s/RkTiLytTF8Xo+WTbVKq531KpTp1rQWAbaVF5iGbLUX3DprlA4Yn/Pvl5fYRhYx1tXE8tHY4/lpoZX7KkqTNE6jtJe9Dg2xSR3E5BBqm+1uBhiNmx+cu7IwFA511LiMfSt302Kh+TlmJxfdg0GcdvuIYHG+8628X7KGYbJ5KFeGFJQfgPbHsINxOFZcYrvQANchPeCtp7Zgx2B4W56Qq5/G48LTtJ5GXxzowi9DTYryJb5eXPEv9Gpn4ZCJM0yRmKpW0XyF/mvyIKOLudRNcMMokYMwtxTMza2FAV97j6gh+a0/rlsScxW8AMHKv8apckfiVLoFXcpSfZoCGeGXAlsXur4IHJ2dTzFRYexlsRWKSlNp2K/AqRR7MtxXn/ja2DdqVfgionjYq36vfgRkZeMN+VIfEfExMstXqksuBBus42y+zDQTzdHZwVHOjaG2u6Tz/WMMpa/HVwDxJk8O/y0R6opO2y0duB71H16bfwPyHAwm7dG3dQqfthrtIAibD1SQLUxiMMAzhCocdyAr9tOIDBB2To1deQnbwp+luMlWgTJ0AZ3n3Y7LXnFeHqfIklYCU071KBOaqVeGeirNmDw6XmYHNHWz+odBPXjdstJDs0efJMjPSCnj/Vb2E6ddT2ZVKIBTx0RQJV9IKZFh8MG79N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AR/4mvCEjNt2IUAxcAL0X6E0O28xGdWGX0DP8KDIrL7gy0K8vaR9Ie0dRVEsNFcSjByksRkEGp+aVZyjJ24uFnZUNjntJgXVv/3G0p0IugoOa8c2hgb4Y37cm87xCFLwSgY+9EomlrW/rXc4RJ3kESdY2MOGJ54JIrRmpZU+ms+Bk7HTsC7nOGxtxQ/seFf4eC71/XyDWyr2gm20gYjqIuDVjekUFB3Seamw0redZddViVD2brxz3gQBXyGVp6kA1PkWpLTYdSN9mOJXW4jJ5GgESSJ8yhtsk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: de0c49cf-d649-481d-ea00-08dcedc9d801 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 10:03:54.9138 (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: 78rYFDsEmAaj+oBvZTJYEaCthpWUNhVLaVVPqPexm/d0KK416IAC1n6p0g3wqqgnRKxzgXLdB2WNO4Cgx7QCWA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6634 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-16_07,2024-10-15_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 spamscore=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410160062 X-Proofpoint-ORIG-GUID: Ojg1hsCm37P9PLCW5h4M15p2XToQx6bg X-Proofpoint-GUID: Ojg1hsCm37P9PLCW5h4M15p2XToQx6bg Support direct I/O atomic writes by producing a single bio with REQ_ATOMIC flag set. Initially FSes (XFS) should only support writing a single FS block atomically. As with any atomic write, we should produce a single bio which covers the complete write length. Reviewed-by: Christoph Hellwig Signed-off-by: John Garry Reviewed-by: Darrick J. Wong --- .../filesystems/iomap/operations.rst | 11 ++++++ fs/iomap/direct-io.c | 38 +++++++++++++++++-- fs/iomap/trace.h | 3 +- include/linux/iomap.h | 1 + 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Documentation/filesystems/iomap/operations.rst b/Documentation/filesystems/iomap/operations.rst index b93115ab8748..5f382076db67 100644 --- a/Documentation/filesystems/iomap/operations.rst +++ b/Documentation/filesystems/iomap/operations.rst @@ -513,6 +513,17 @@ IOMAP_WRITE`` with any combination of the following enhancements: if the mapping is unwritten and the filesystem cannot handle zeroing the unaligned regions without exposing stale contents. + * ``IOMAP_ATOMIC``: This write is being issued with torn-write + protection. Only a single bio can be created for the write, and the + write must not be split into multiple I/O requests, i.e. flag + REQ_ATOMIC must be set. + The file range to write must be aligned to satisfy the requirements + of both the filesystem and the underlying block device's atomic + commit capabilities. + If filesystem metadata updates are required (e.g. unwritten extent + conversion or copy on write), all updates for the entire file range + must be committed atomically as well. + Callers commonly hold ``i_rwsem`` in shared or exclusive mode before calling this function. diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f637aa0706a3..ed4764e3b8f0 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -271,7 +271,7 @@ static int 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; @@ -283,6 +283,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; } @@ -293,7 +295,8 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, const struct iomap *iomap = &iter->iomap; struct inode *inode = iter->inode; unsigned int fs_block_size = i_blocksize(inode), pad; - loff_t length = iomap_length(iter); + const loff_t length = iomap_length(iter); + bool atomic = iter->flags & IOMAP_ATOMIC; loff_t pos = iter->pos; blk_opf_t bio_opf; struct bio *bio; @@ -303,6 +306,9 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, size_t copied = 0; size_t orig_count; + if (atomic && length != fs_block_size) + return -EINVAL; + if ((pos | length) & (bdev_logical_block_size(iomap->bdev) - 1) || !bdev_iter_is_aligned(iomap->bdev, dio->submit.iter)) return -EINVAL; @@ -382,7 +388,7 @@ 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); nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_VECS); do { @@ -415,6 +421,17 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, } n = bio->bi_iter.bi_size; + if (WARN_ON_ONCE(atomic && n != length)) { + /* + * This bio should have covered the complete length, + * which it doesn't, so error. We may need to zero out + * the tail (complete FS block), similar to when + * bio_iov_iter_get_pages() returns an error, above. + */ + ret = -EINVAL; + bio_put(bio); + goto zero_tail; + } if (dio->flags & IOMAP_DIO_WRITE) { task_io_account_write(n); } else { @@ -598,6 +615,9 @@ __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) + iomi.flags |= IOMAP_ATOMIC; + if (iov_iter_rw(iter) == READ) { /* reads can always complete inline */ dio->flags |= IOMAP_DIO_INLINE_COMP; @@ -659,7 +679,17 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (ret != -EAGAIN) { trace_iomap_dio_invalidate_fail(inode, iomi.pos, iomi.len); - ret = -ENOTBLK; + if (iocb->ki_flags & IOCB_ATOMIC) { + /* + * folio invalidation failed, maybe + * this is transient, unlock and see if + * the caller tries again. + */ + ret = -EAGAIN; + } else { + /* fall back to buffered write */ + ret = -ENOTBLK; + } } goto out_free_dio; } 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 d0420e962ffd..84282db3e4c1 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 { /*