From patchwork Mon Apr 24 05:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221667 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 5651AC7618E for ; Mon, 24 Apr 2023 05:50:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAA9B280002; Mon, 24 Apr 2023 01:50:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5A266B0087; Mon, 24 Apr 2023 01:50:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2299280002; Mon, 24 Apr 2023 01:50:31 -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 C1CDD6B0085 for ; Mon, 24 Apr 2023 01:50:31 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9B829C0178 for ; Mon, 24 Apr 2023 05:50:31 +0000 (UTC) X-FDA: 80715209862.19.4449B7C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id F20DC20005 for ; Mon, 24 Apr 2023 05:50:29 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UoeSfGuo; spf=none (imf13.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=1682315430; 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=sTswUsG7V37q4lilbMJoCzI78FMLYPHsnKSU4tW14rI=; b=rt4JaKjEipT9pkNQ8TP4y1LdDN58zkBtd50a3FKpWxt0GjeC1vWcqteLyiw3VNcFSkTkcn 4CL3J63NJXFN0TTlCNPsWje3K0K2p5Cm5g1swRJvT5a43BfK1cnBDnvAjCbprYsZFbIVR6 wolCc1w6PH7g8WR45gNrqCLv8tZpY9E= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UoeSfGuo; spf=none (imf13.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=1682315430; a=rsa-sha256; cv=none; b=2a5lCVIjHNu4yWYMyx/V02ng0PxInQpaF6963FgWFdS7qGOlblmaCJVdIpGLUHGzFEtjPT viBMIK8C7SQ1lLvJCAsrl88/3NJNG3Fri4Ku9e7RSk75EIUelKu30ZMA/yiFTAKSPXwKcz 7+KaJ8eRNB/sckiOWuV9BALdu2gOkSo= 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=sTswUsG7V37q4lilbMJoCzI78FMLYPHsnKSU4tW14rI=; b=UoeSfGuoni8M8v/l7vB42i2THY zMcmd34OOElv7F+mrbgD/ShZRx4itRpkQwFSxTkpmii613jhNw9WyxCQjGj7MQShQbt7WqJjepuL4 LBmWnG81igFVQQjFpE39ugSY4dTF5078Y+qk64oapXEUft128WQk3P7Es40nmDd7R0F2d0XieesAO j5XAkEb++llO3yox0Qy5icXKSxnxY5rP++XJ6RqFTM31wvcDtrVuuPtN/xpgA7bZCD3wVcAXdYXYo jxEebVm9CoZwe3Xf0PTdYWQayQAZxQ3W9FEGkn51muLlMnnlGjCx9TQHWQLhKUkUJmMWkZDYDkloT v7jNugbA==; 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 1pqp5X-00FP9P-1d; Mon, 24 Apr 2023 05:50:12 +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 14/17] block: open code __generic_file_write_iter for blkdev writes Date: Mon, 24 Apr 2023 07:49:23 +0200 Message-Id: <20230424054926.26927-15-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F20DC20005 X-Stat-Signature: in1net9ik31efagqoq5ggumg5bnkxxyf X-HE-Tag: 1682315429-953115 X-HE-Meta: U2FsdGVkX1+niMSNIaj1nVBqLbxt6Q5N9AnnQL6LZyJMxS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sPRoA02TPDmem18y20yZICzhwlbDSKHnXjhgHlwFhHYRrv1sbuRDtTeTJDEst2VmRI0jOzqFfQiF4GXJOh8PJaTf7zrLf5k9G1kTS/xivlEpwSiSJNOGcVA5OdWfHU/EVZ3IJjk0pvAcnYdxmx9B3UDTAx19iMngI6Y08DLbQsmDoaEy/tD84RLHHfFra9QO5BxDLsYfILZgtWceVDSNbzoT6cSSxyhgKwycUVmIwgNPYGXMxWnTfdg3R2uHbRzL8DNQmxUzu0C9YQqBYCLAe//g1/eUoLd3b0C7Bvp2UKJo1iO2awK71M4OFaqPVBG2tmNJ1W3FENVoHvkUKX1LnK4msTIjzYtBqUcE= 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: Open code __generic_file_write_iter to remove the indirect call into ->direct_IO and to prepare using the iomap based write code. Signed-off-by: Christoph Hellwig --- block/fops.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/block/fops.c b/block/fops.c index b670aa7c5bb745..fd510b6142bd57 100644 --- a/block/fops.c +++ b/block/fops.c @@ -508,6 +508,29 @@ static int blkdev_close(struct inode *inode, struct file *filp) return 0; } +static ssize_t +blkdev_direct_write(struct kiocb *iocb, struct iov_iter *from) +{ + size_t count = iov_iter_count(from); + ssize_t written; + + written = kiocb_invalidate_pages(iocb, count); + if (written) { + if (written == -EBUSY) + return 0; + return written; + } + + written = blkdev_direct_IO(iocb, from); + if (written > 0) { + kiocb_invalidate_post_write(iocb, count); + iocb->ki_pos += written; + } + if (written != -EIOCBQUEUED) + iov_iter_revert(from, count - written - iov_iter_count(from)); + return written; +} + /* * Write data to the block device. Only intended for the block device itself * and the raw driver which basically is a fake block device. @@ -517,7 +540,8 @@ static int blkdev_close(struct inode *inode, struct file *filp) */ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) { - struct block_device *bdev = iocb->ki_filp->private_data; + struct file *file = iocb->ki_filp; + struct block_device *bdev = file->private_data; struct inode *bd_inode = bdev->bd_inode; loff_t size = bdev_nr_bytes(bdev); size_t shorted = 0; @@ -538,13 +562,31 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) if ((iocb->ki_flags & (IOCB_NOWAIT | IOCB_DIRECT)) == IOCB_NOWAIT) return -EOPNOTSUPP; + ret = file_remove_privs(file); + if (ret) + return ret; + + ret = file_update_time(file); + if (ret) + return ret; + size -= iocb->ki_pos; if (iov_iter_count(from) > size) { shorted = iov_iter_count(from) - size; iov_iter_truncate(from, size); } - ret = __generic_file_write_iter(iocb, from); + current->backing_dev_info = bdev->bd_disk->bdi; + if (iocb->ki_flags & IOCB_DIRECT) { + ret = blkdev_direct_write(iocb, from); + if (ret >= 0 && iov_iter_count(from)) + ret = direct_write_fallback(iocb, from, ret, + generic_perform_write(iocb, from)); + } else { + ret = generic_perform_write(iocb, from); + } + current->backing_dev_info = NULL; + if (ret > 0) ret = generic_write_sync(iocb, ret); iov_iter_reexpand(from, iov_iter_count(from) + shorted);