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: 13221650 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF4D2C77B61 for ; Mon, 24 Apr 2023 05:50:26 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pqp5n-0004dB-A4; Mon, 24 Apr 2023 05:50:26 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pqp5l-0004ch-BJ for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Apr 2023 05:50:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; 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:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=sTswUsG7V37q4lilbMJoCzI78FMLYPHsnKSU4tW14rI=; b=bAWV1BrZe3q2ZbaibdvjXUmijC +oDdSoD+qQsiWD+mhL1OxpoLdO1+GX3H9pezMw54fmVwwfgVBP+wjSubaMLYokRAmouFFB934m4/x XMRS/sPWgIOBB3lZQwsjC1lYU6hVQcpAboAkIjBatwHybibPumcZHoyrD0gGnrJG+XLU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; 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:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=sTswUsG7V37q4lilbMJoCzI78FMLYPHsnKSU4tW14rI=; b=jk7CTrnLjcyDjzOtu7MZkiG/g3 2kNeqdecGgug1YPv/yqMsjROv9v965qNr7ZCsdgb6vw0uYgQtnPiVApHNkkP2hDKjr+Fim18NJnJ/ Ex6kvCZ+v4lY4AxaiZ0V/81TfpdXRjO1nh+vCwggmAD4VnSx3LdVW8yDTOvSLeDK+AvI=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pqp5j-00HHu0-Sb for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Apr 2023 05:50:24 +0000 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 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-Headers-End: 1pqp5j-00HHu0-Sb Subject: [f2fs-dev] [PATCH 14/17] block: open code __generic_file_write_iter for blkdev writes X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-block@vger.kernel.org, linux-nfs@vger.kernel.org, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, Miklos Szeredi , "Darrick J. Wong" , linux-kernel@vger.kernel.org, Matthew Wilcox , linux-f2fs-devel@lists.sourceforge.net, David Howells , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Andrew Morton , linux-ext4@vger.kernel.org, ceph-devel@vger.kernel.org Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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);