From patchwork Mon Apr 24 05:49:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221663 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 83032C7EE23 for ; Mon, 24 Apr 2023 05:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C0A7900002; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 470DE6B0087; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F5946B0085; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0C7DC900003 for ; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E00D71A010E for ; Mon, 24 Apr 2023 05:50:16 +0000 (UTC) X-FDA: 80715209232.21.B089954 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id 42FA810000E for ; Mon, 24 Apr 2023 05:50:15 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3lxWVAk+; spf=none (imf14.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682315415; 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=pJqF9iLDXxalAZri1sgP4ykwSrvt3ymept2aEtNRU2M=; b=nzmli5yp47OKpkMt/UlO6Ny4XuTN1VGDwrF0Jt1zPSPk6nAZSsD4Q4/KIeUwW2fqGNHh5p RMejjgLGzXqMYXjFRsajGELZnmL7DPLPhYE1Rh3ow44ho026GmwcNLc7NUPfjzPjHaP6iB 6JIm/M6XPtDmFpAGLFD3QlFo3tZ39m8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3lxWVAk+; spf=none (imf14.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315415; a=rsa-sha256; cv=none; b=aVXkjlmBUwo6pTKPStF3mcFKKmZh5JxPL+mCTxOw+2UDilEJnXolAaRsTxJLE3bVqgslOS M0OjAb0dmzw4wlsg6te1soz6cgHm/pfUJm9ilUsu2wssah5HvZ3au8XrR+/X899TpIZ6e7 A4epuSQ4tkezCUDmiub3M6riN5oGqjg= 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=pJqF9iLDXxalAZri1sgP4ykwSrvt3ymept2aEtNRU2M=; b=3lxWVAk+3jZfmQD+hx2GXifc+u 2uElWR6QJNM63DBT0CyBjHyTQty+aqsqVeci/2v+7iILU2eb3upv78/4g048VSlvmDvh2mJYlZYZ6 XOxjp6O39E62ujMQm69yzR/DnVWTniYzJvEiutGiNhDq42IO09RTn0OMm/3Bvn2K6DU3f11ZHTGj3 wO/B5SuQ7cosdpF7UlWJdzPfVB+e8gNIg9bicPczX/NjxixXpg3qMzmuu6NLAkDvHL5b74xtnSdgO ZKCt4iYFs6TuqhKmfkfCVG1sm381O08hFBNFhqmsvf5phswa19FEEeAjjvkIomMjBB57KJt2H9laH ncijNsbQ==; Received: from [2001:4bb8:189:a74f:e8a5:5f73:6d2:23b8] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pqp5L-00FP1c-2M; Mon, 24 Apr 2023 05:50:00 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Miklos Szeredi , "Darrick J. Wong" , Andrew Morton , David Howells , Matthew Wilcox , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, ceph-devel@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, linux-kernel@vger.kernel.org Subject: [PATCH 10/17] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Mon, 24 Apr 2023 07:49:19 +0200 Message-Id: <20230424054926.26927-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230424054926.26927-1-hch@lst.de> References: <20230424054926.26927-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: 42FA810000E X-Stat-Signature: m4q9wqsqcmr8bc5fzc7s6794w7xfho6c X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1682315415-684369 X-HE-Meta: U2FsdGVkX1/1EGyAyG4C7CV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cx0WhbmUMUa+UvpbRYt60+c9KmY34oq6q9BL8YeykYJuANQ+7dT5OETLRfQoCk4EvDnViiPjQt2i/TzoeF7zQhHMo6yvvAaHEeYxw7AwZRVacBfK8bvAWEsKwrkzOQAnfmKlchHBkIBVPwXRaedr2eyR8BpIzT8tO6QLLEkF1FoGAMaqucQyKNnIG9N+FMu//4tmPtQFBrcRJHO2Bm37/4oh1HvztA2cGca66yOIf2qJOC9o/4/zS7wqEgu0we4W7ZYRhnDNOxwSC2skfXz79sl7KW/WI0Dm2/E5oZPevXo78TmagG6dZmjApvcdPVQHvGBAkCCCv/4rt3XhQ5X8Km78M/dprRpMOJBgAt9iRz1w== 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 --- 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 2bf8d684675615..10a790f568afca 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -470,7 +470,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, @@ -479,11 +478,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; if (!iomi.len) return NULL; @@ -505,31 +504,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 */ @@ -545,31 +542,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; }