From patchwork Wed May 24 06:38:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253310 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 032A1C7EE31 for ; Wed, 24 May 2023 06:38:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AF3E280007; Wed, 24 May 2023 02:38:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86103280001; Wed, 24 May 2023 02:38:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DB20280007; Wed, 24 May 2023 02:38:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5B26E280001 for ; Wed, 24 May 2023 02:38:52 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 099811208CD for ; Wed, 24 May 2023 06:38:52 +0000 (UTC) X-FDA: 80824195704.23.CAF977B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 3D53CC0003 for ; Wed, 24 May 2023 06:38:49 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qGygllY5; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+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=1684910330; 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=UGcays7SHtJ30c2YB72Xoeq2mxU68x0UDEkjnGlewMo=; b=ZleCo/lFUoLlJdlYL9LzZJ616p2I7EaNoZ9XJb3Ym6Iqrg09dw08X40GiX4P6eMryPYU6N 800GNXePkxkQF3efGDgNzX3OcdaBTpUf041ZzUPCa/himSa8hfmQtX+mLKR+Rka125XJrx TEsqJ9uRYVt3hy2lHEtiNBqslBywpd0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qGygllY5; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910330; a=rsa-sha256; cv=none; b=Tz7j62P1P6gOCCP7BSiSNQAtFJTc9SkFm+kOtv++zgG55onX7hHVjra5VGFJOj3S0UkIyX /Bgi1fDmy7zZZHK+XPX2jO4AOpMZSmCNqnu0WtTnMGcOSyG+TWW+c4JGKkeiedaGyR0zWp mcgeL8RrTf+z4aPTmhKVsq/PXA1msc4= 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=UGcays7SHtJ30c2YB72Xoeq2mxU68x0UDEkjnGlewMo=; b=qGygllY5nnLJOFYyd0IBWQFSLQ EZRHhM8vXPJRpF7uMOuG8ZcWfWL49uI8P24Xjrd3+TBG2ba06CYT1Tki5Tc+pxSgIqvYZ8NcjEohR 57ll/L5ERXco+rn8oNDpkolxK8nebCYh8CBEV843AEYixyxCv7TYDxS1qGAORZVqrKw8bWV1FbS0y NsHl2Ecyndoz0kXEJACW+wX5KzE5uQuK6zIUFsTmXcDQu0yTIm5olLObpfTWlPt1gD8tBwmwFxHzS rkzCUHnWktCU/Iqvy5KBUEACLMonmTd3FskyrdBZZ+17oEQwG/YhB1b4cZb5+fKS94wcg1c2w18RG cdczDtgQ==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8q-00CVhQ-1A; Wed, 24 May 2023 06:38:36 +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 Subject: [PATCH 08/11] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Wed, 24 May 2023 08:38:07 +0200 Message-Id: <20230524063810.1595778-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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-Rspamd-Queue-Id: 3D53CC0003 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: b7iyf3jtj19dz8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wSXu7x1uvSppOQK+4sRn2X2GKQ++d3m7rtEtoSSHn25/eQfg/OkDSAtagSKJMV0V+lnvmjZU54+v6j/fsiHKuQ87g7d2OWHn4aRj0m9uIEilwqpC62HI5cE2rA6T3iR91r2oavJiW2ZgvlR6ELV9i/2p4s7H2AAft4p9gdB/qc4OkNYKxhcbka6DbylcZFAAFYER2cg04qDBQ4ite99b17/qa2yirf7RbcwnfkOv75MA9/Jx94NSklgVrztqJviDHARUVZmI4YaiQbHY1ifR/8LM1tZ1EqxeyeyywItcA8XVBqJVsfblv071gpcv51vg67SFDEza1leBL0Hmpm3OKkSODonKd0LZ+yUOlblvNiwbdI5OUAREGkT3Y2DimW1RwJZVq5qj9fFxQbne0c0c33sCIqH88oxZbDsaXjrsAsY5FNUe5rd5cRpaShUBXvTW7hjSMGDPXvzQh3ILkKCYrE= 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: Darrick J. Wong Reviewed-by: Hannes Reinecke --- 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; }