From patchwork Wed May 31 07:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2273C7EE24 for ; Wed, 31 May 2023 07:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EB476B0074; Wed, 31 May 2023 03:51:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89BBC6B0081; Wed, 31 May 2023 03:51:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EDE4900002; Wed, 31 May 2023 03:51:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 60B3D6B0074 for ; Wed, 31 May 2023 03:51:03 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2FFFBC0273 for ; Wed, 31 May 2023 07:51:03 +0000 (UTC) X-FDA: 80849779206.29.D32FADF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id 7ADF740012 for ; Wed, 31 May 2023 07:51:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DjkGSNhf; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685519461; a=rsa-sha256; cv=none; b=QP/VkcuwDi2Khqzg79j5EpPYR9T0+NKbAeM4UBGuKZwRyTBcsT7ohOCwlun5wDf+tbwEcm 4do5nk1qKCfg95cPrkqtlIQyW6LgKEFY50S3a8DJ33H2fsyrhgpiYqhGinIHXnofznEBc5 BwDnVB3mHzm6l2CNXq4kpFN7LAyYuG0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DjkGSNhf; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685519461; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+TlwHQVmCcfSC9sL9si103D1qv7dfudCnmtDuQc976U=; b=IMlAWTlSsR9JSuXl16n/bX4DVX+YSmOzqfrf2H4oFbG0IX5sQPUFL6iQEPNt8aY7NldB2m Zs4lV/xkTgHRzGBVNgEzxx1PxUGD5pSC0/iuolSaXaN7U4QdJCzSy2vFoCGccMnxIdlxM5 qBxy4DXK5Py1sdVDdi62ur+PvbJk6TQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=+TlwHQVmCcfSC9sL9si103D1qv7dfudCnmtDuQc976U=; b=DjkGSNhfxlyHdHmZ+aBPLm0AmK 3nSTrCN5Pwh8HDmmbRXnhMRvz+JIT6h6F6yA35TYrD1FIj5qGsM8GHWl+ZAvE08Pvcxni0zcnTB7E 9jeKuRIiiVPJSBVoabk1ohE4Idh4SVB4aeVHVnQFVpZfMWvueT+wTI8vn65XazJ8ocFrbD5Hky125 TK6Bcl1zzEUcXiyd6sCm1IdkM43w3fN8zhNYZ117MvX5gdTQcqIBpA+WBivtnVlskMyMktya6Icr6 /4xWKrsWFA3/X27UuR2AvcifM2q4neWhR4fdC9tT555gl4NlHZ9UXxvTDSisBM+I0AyMC17ZdOsGI Cs7By28Q==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4Gba-00GVsM-19; Wed, 31 May 2023 07:50:50 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Hannes Reinecke Subject: [PATCH 08/12] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Wed, 31 May 2023 09:50:22 +0200 Message-Id: <20230531075026.480237-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam06 X-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xtMoxdUU2wdKH+cjJxtknhhBTl9qDdO1XnWjP6vnf42kiCfX6NneZagaz4GJaAO5cSHaAQlWl03o4bs3su7aAXmcOFhadyNDee5fN4OwC6i+WPR+YNtH0NJ932J4b7Ra22+eSxkSL727qj4LRNjwz8ns8xqwTia4XqQZeKCaKOxrSp/4O+c6PL9jgTEl9fCjRppBF21AlCy8t9A3SAPD31rV9nbiEd2UTQHcSpcN1CLpNnRPqWdPFzylghZ/awWYJnLY4IjQxhT2VMtIHc/AJND+dGT/MLkmq+Nh9OuLmrdABpBqjVavzGLwHYB8wrfO6vjT8VeSSZVMrJeVjgTDc/hSR61b0Xm7Q01NQ5ZvAOOYEk255gpdk2GmcV6hMkFGRZjwzTJcA/1LqkFuEvee/DyDZNKrW/EJVKi0In6cjAatDcupAtbXP0FTujJzzqQmpUiwCZstGPLoh3nlUISCfytqz74XK8lau+QCNUsg7VeQHd7L4zP+ltSAiTUhcqVoXy5eq4RpH4XK34+103dKfa2xPneV4e2Oa1w9CWv+/ZxDr10xjBpeWbXm8Qxa+Rf6c/GcSH2a20TvwNXoVYPkLbAy99DSlwsdug X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the common helpers for direct I/O page invalidation instead of open coding the logic. This leads to a slight reordering of checks in __iomap_dio_rw to keep the logic straight. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Darrick J. Wong --- fs/iomap/direct-io.c | 55 ++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 0795c54a745bca..6bd14691f96e07 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -472,7 +472,6 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before) { - struct address_space *mapping = iocb->ki_filp->f_mapping; struct inode *inode = file_inode(iocb->ki_filp); struct iomap_iter iomi = { .inode = inode, @@ -481,11 +480,11 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, .flags = IOMAP_DIRECT, .private = private, }; - loff_t end = iomi.pos + iomi.len - 1, ret = 0; bool wait_for_completion = is_sync_kiocb(iocb) || (dio_flags & IOMAP_DIO_FORCE_WAIT); struct blk_plug plug; struct iomap_dio *dio; + loff_t ret = 0; trace_iomap_dio_rw_begin(iocb, iter, dio_flags, done_before); @@ -509,31 +508,29 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio = NULL; + if (iocb->ki_flags & IOCB_NOWAIT) + iomi.flags |= IOMAP_NOWAIT; + if (iov_iter_rw(iter) == READ) { if (iomi.pos >= dio->i_size) goto out_free_dio; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_needs_writeback(mapping, iomi.pos, - end)) { - ret = -EAGAIN; - goto out_free_dio; - } - iomi.flags |= IOMAP_NOWAIT; - } - if (user_backed_iter(iter)) dio->flags |= IOMAP_DIO_DIRTY; + + ret = kiocb_write_and_wait(iocb, iomi.len); + if (ret) + goto out_free_dio; } else { iomi.flags |= IOMAP_WRITE; dio->flags |= IOMAP_DIO_WRITE; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_has_page(mapping, iomi.pos, end)) { - ret = -EAGAIN; + if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) { + ret = -EAGAIN; + if (iomi.pos >= dio->i_size || + iomi.pos + iomi.len > dio->i_size) goto out_free_dio; - } - iomi.flags |= IOMAP_NOWAIT; + iomi.flags |= IOMAP_OVERWRITE_ONLY; } /* for data sync or sync, we need sync completion processing */ @@ -549,31 +546,19 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (!(iocb->ki_flags & IOCB_SYNC)) dio->flags |= IOMAP_DIO_WRITE_FUA; } - } - - if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) { - ret = -EAGAIN; - if (iomi.pos >= dio->i_size || - iomi.pos + iomi.len > dio->i_size) - goto out_free_dio; - iomi.flags |= IOMAP_OVERWRITE_ONLY; - } - ret = filemap_write_and_wait_range(mapping, iomi.pos, end); - if (ret) - goto out_free_dio; - - if (iov_iter_rw(iter) == WRITE) { /* * Try to invalidate cache pages for the range we are writing. * If this invalidation fails, let the caller fall back to * buffered I/O. */ - if (invalidate_inode_pages2_range(mapping, - iomi.pos >> PAGE_SHIFT, end >> PAGE_SHIFT)) { - trace_iomap_dio_invalidate_fail(inode, iomi.pos, - iomi.len); - ret = -ENOTBLK; + ret = kiocb_invalidate_pages(iocb, iomi.len); + if (ret) { + if (ret != -EAGAIN) { + trace_iomap_dio_invalidate_fail(inode, iomi.pos, + iomi.len); + ret = -ENOTBLK; + } goto out_free_dio; }