Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp320720rdb; Thu, 30 Nov 2023 05:54:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/PWHqaTNVNAc7sONDUqbI5asDN+AtCO12RJ6zzTmY0j/FPRBecn5tw2PebGVLS3t9eBtg X-Received: by 2002:a05:6a00:1c91:b0:6cd:e063:3646 with SMTP id y17-20020a056a001c9100b006cde0633646mr4009700pfw.28.1701352472842; Thu, 30 Nov 2023 05:54:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701352472; cv=none; d=google.com; s=arc-20160816; b=wzLWKBj9yePxkq4/VRjI0dKWipa1+AbJTPCgRsn+H3fK/SzCawJ3JI8yUL0vdmAM7z TEyGVR38tBRMparX/btkrvIOQNkmpIe41tQte/aiq9Edt3canASEehosjnueO49AOLem 9/ANwVaTWgOy+qrN4sIlCpNU7FltnbYVoAxNDo2y3Tryg5TYzlQwpbD+fmvt3uzqVPRB Snh5FHutFiNEEa8IoWTiuik7LK1xbspmGiVDY0KwTHKJT1DO2Vn/bu+53ERVuH5PIS7m VMr+IljgtH+vMjKs5Ee8CIw2OdN1gqJ6VkVY7pWYQE3cDW6tTMBkqCS9nR86Jezq3+Y6 RTfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=I4EWMLFOy1eJZwXfsCVABkVMsuSEuv+Jei1udxbxQWg=; fh=o0c9oRQqGcw+lX35liWyz4mGWjDo/97N/+E1+y9wprk=; b=Ol046V/2osk1pznvPHeUCxjbO4Ry64n3yY7Bys0vr92vVwRo25OKMOiQxh7sXCaR2N /Bqazrezp7YkIJEOmwqfV6M1LV8q8DClvlgk/yFKji3VBobXgeU/npJ8L+DT536VTpKq 8ZNXiebz3+4p9U8ghIAEMidBnvhj9lp57QfavzJRwLecd0DGG3C0ezMcGHIM+wuVzSr3 cMuWGTjaMQFnkKJUBFbrq+rELBh7zqEyLL2AkpR2vyPr/PgC/8ytQC31tYlL8br0zk00 2Tt8eDEd6DhOoyxwrFHf3ZZ9WO5Mb8WxH9MxBFj1QVMGqvVhbwwCKX5wUYDLtZcV5jHt df3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NeJBBMoZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id fc16-20020a056a002e1000b006cbf2bc6eaesi1303246pfb.188.2023.11.30.05.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:54:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NeJBBMoZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 703B1826EE82; Thu, 30 Nov 2023 05:54:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345939AbjK3NyM (ORCPT + 99 others); Thu, 30 Nov 2023 08:54:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345935AbjK3Nxx (ORCPT ); Thu, 30 Nov 2023 08:53:53 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B8BD1715; Thu, 30 Nov 2023 05:53:49 -0800 (PST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AUDnXKC001388; Thu, 30 Nov 2023 13:53:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=I4EWMLFOy1eJZwXfsCVABkVMsuSEuv+Jei1udxbxQWg=; b=NeJBBMoZ2jTcxxtiQqRVxMOnkn9+H9cYcY0rFEwQXLb9TgqLzXZn9yw7hjaj+06nHgh4 Yl4ZIhMeWDhjkrcgpXgf8Bp37Guk7+zx3Rgy6oA9siMVNGMsaqkuNzKTGB8ZYzRBBkka 3hUQ63MV8G0HgOvEFhEegkmvGN11EqJ26LRSLPt3XL/6nxd1CAqcCDA010qaX0u7fLsL /mwwRMJkmoSNhwFnMWhWzMvs/kx9KNleQN3n9BWOwuTwWTdRAmJvaPESFN+R+HT26ZeR W4i5XnFrIEcoGmtr292CzejtyJ47BdxVgUbkaWkG+/oB3mY/ac4MADQpCxVhTPBWxEo+ Zw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3upu2vh3mv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 13:53:44 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AUDowTT006599; Thu, 30 Nov 2023 13:53:43 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3upu2vh3mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 13:53:43 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3AUDnC7r029505; Thu, 30 Nov 2023 13:53:42 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ukwfke1sq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 13:53:42 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3AUDrepf30212398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Nov 2023 13:53:40 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 867932004D; Thu, 30 Nov 2023 13:53:40 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 02BCF20040; Thu, 30 Nov 2023 13:53:38 +0000 (GMT) Received: from li-bb2b2a4c-3307-11b2-a85c-8fa5c3a69313.ibm.com.com (unknown [9.43.76.38]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 30 Nov 2023 13:53:37 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Ritesh Harjani , linux-kernel@vger.kernel.org, "Darrick J . Wong" , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, John Garry , dchinner@redhat.com Subject: [RFC 5/7] block: export blkdev_atomic_write_valid() and refactor api Date: Thu, 30 Nov 2023 19:23:14 +0530 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ZugCvRCajbO69dPqhlk8SBBZ4fODI8KN X-Proofpoint-ORIG-GUID: c1vCyZy5Tdbw7RUuXr_sq8Rtv4ONgRya X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-30_12,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 mlxlogscore=839 adultscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311300102 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 30 Nov 2023 05:54:30 -0800 (PST) Export the blkdev_atomic_write_valid() function so that other filesystems can call it as a part of validating the atomic write operation. Further, refactor the api to accept a len argument instead of iov_iter to make it easier to call from other places. Signed-off-by: Ojaswin Mujoo --- block/fops.c | 18 ++++++++++-------- include/linux/blkdev.h | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/block/fops.c b/block/fops.c index 516669ad69e5..5dae95c49720 100644 --- a/block/fops.c +++ b/block/fops.c @@ -41,8 +41,7 @@ static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, !bdev_iter_is_aligned(bdev, iter); } -static bool blkdev_atomic_write_valid(struct block_device *bdev, loff_t pos, - struct iov_iter *iter) +bool blkdev_atomic_write_valid(struct block_device *bdev, loff_t pos, size_t len) { unsigned int atomic_write_unit_min_bytes = queue_atomic_write_unit_min_bytes(bdev_get_queue(bdev)); @@ -53,16 +52,17 @@ static bool blkdev_atomic_write_valid(struct block_device *bdev, loff_t pos, return false; if (pos % atomic_write_unit_min_bytes) return false; - if (iov_iter_count(iter) % atomic_write_unit_min_bytes) + if (len % atomic_write_unit_min_bytes) return false; - if (!is_power_of_2(iov_iter_count(iter))) + if (!is_power_of_2(len)) return false; - if (iov_iter_count(iter) > atomic_write_unit_max_bytes) + if (len > atomic_write_unit_max_bytes) return false; - if (pos % iov_iter_count(iter)) + if (pos % len) return false; return true; } +EXPORT_SYMBOL_GPL(blkdev_atomic_write_valid); #define DIO_INLINE_BIO_VECS 4 @@ -81,7 +81,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; - if (atomic_write && !blkdev_atomic_write_valid(bdev, pos, iter)) + if (atomic_write && + !blkdev_atomic_write_valid(bdev, pos, iov_iter_count(iter))) return -EINVAL; if (nr_pages <= DIO_INLINE_BIO_VECS) @@ -348,7 +349,8 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; - if (atomic_write && !blkdev_atomic_write_valid(bdev, pos, iter)) + if (atomic_write && + !blkdev_atomic_write_valid(bdev, pos, iov_iter_count(iter))) return -EINVAL; if (iocb->ki_flags & IOCB_ALLOC_CACHE) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index f70988083734..5a3124fc191f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1566,6 +1566,8 @@ static inline int early_lookup_bdev(const char *pathname, dev_t *dev) int freeze_bdev(struct block_device *bdev); int thaw_bdev(struct block_device *bdev); +bool blkdev_atomic_write_valid(struct block_device *bdev, loff_t pos, size_t len); + struct io_comp_batch { struct request *req_list; bool need_ts; -- 2.39.3