From patchwork Thu Jul 20 14:04:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13320583 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 ABA9AEB64DD for ; Thu, 20 Jul 2023 14:06:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FF5828010F; Thu, 20 Jul 2023 10:06:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AEF328004C; Thu, 20 Jul 2023 10:06:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 103DC28010F; Thu, 20 Jul 2023 10:06:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0276828004C for ; Thu, 20 Jul 2023 10:06:48 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C2601140167 for ; Thu, 20 Jul 2023 14:06:47 +0000 (UTC) X-FDA: 81032166054.03.830DBA9 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf03.hostedemail.com (Postfix) with ESMTP id 2C5322044F for ; Thu, 20 Jul 2023 14:05:06 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d4IXxaa5; spf=none (imf03.hostedemail.com: domain of BATV+ae7cc45e83adbe90d207+7270+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+ae7cc45e83adbe90d207+7270+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689861907; a=rsa-sha256; cv=none; b=UPHndSBTrFYVVCd5KAnLECiHxm8Hhgfhx7H/Izbgd82EcYCCTTiYPuoKB1VO46jMuXT9Sd 4XRpxUPW2M+qrXuTWV0h44B9F4aj9KLo/R5Q1neF6XaQuqnPXgeJBdf6IIyPHgyqGeajsH OF1UeWlJvLKWjA29YuMLkdUOk2N1ulI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d4IXxaa5; spf=none (imf03.hostedemail.com: domain of BATV+ae7cc45e83adbe90d207+7270+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+ae7cc45e83adbe90d207+7270+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=1689861907; 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=yaOs2VrbaTQ5mw1fhRctemzRO8G1izk4pie8fEUG7Pg=; b=diExclkXUz0AWj9jepWqU//BY3UOKN2Is71hftzVasUEB3tuCuUuLuH+Ro9iU7IpqrS9Dk pY5ZO/Ko6kCfjuMzLDIxByuB+HdzYTL948Iye79CAGp2PArDNXniYEEXG6E3FQKNwtqeyj kPh4BTD7vaHfnKQaNc6O/droGw5tick= 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=yaOs2VrbaTQ5mw1fhRctemzRO8G1izk4pie8fEUG7Pg=; b=d4IXxaa5wwC5+QTPqwZACF6baC JRSFT/yUddFQ4e0UY/3unt4en7V/gUFgWW3XehEy7vbuPyeS1o5h6ibusSemRJ9GF6zjuH7dy3KS5 cUxDGvI9gRPpNA/LcUNteFDRq7AWl8O6tBbyq6UHpoKIoKKAWeU5FU1J6tK1QmZ3nLpHhj9EbKUta Si1NSYxlGTurFNu21XyAt5SbSzAa8rAXLvO854DUMthK8kWTNgK8tS6tCm44djlZm8Va+f5g9nMHF KJzeetajdRSWRG1iMdLh6awhN9EeRwIUTzrv+YB+RkP13LWl919K7HA+2sCYpxjFlqyAL+zYtTXnp l3ISmLyA==; Received: from [2001:4bb8:19a:298e:a587:c3ea:b692:5b8d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qMUH8-00BKq4-2T; Thu, 20 Jul 2023 14:05:03 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Darrick J. Wong" , Andrew Morton , Matthew Wilcox , Christian Brauner , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] block: open code __generic_file_write_iter for blkdev writes Date: Thu, 20 Jul 2023 16:04:49 +0200 Message-Id: <20230720140452.63817-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720140452.63817-1-hch@lst.de> References: <20230720140452.63817-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-Server: rspam08 X-Rspamd-Queue-Id: 2C5322044F X-Stat-Signature: sbrungi1nncs6a1a356ficmmpmtdd118 X-Rspam-User: X-HE-Tag: 1689861906-417469 X-HE-Meta: U2FsdGVkX1+022TWu+N/idcMsbYzS117+8mUK23Pzm3aqUv8cDWLauZ4fd4K2qy9w7+Qle4qnLq8ABRYl1Iop6T4TP/FYE032Py6n4XGELKvPqxmWUPadXWkRtuYpEhy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UhmI7PwrvQYQp/skzFNLdBXaPyRP5HkaXyUOAGY+e+KU4HPOxdtotBq2iNDAM4gzJA6s7gikCj3pXk87J1qfnHIjZqqBizhGqxIY7z2dvf1G982hJgwjHEJ6YivoZL6hAnlVF0Gq8vRrQ1TEwWcmhYokHnlznMJs3FaBHjBduLCA5XksWxgGq1Y62MV80irFQ7kSHabr2sHCARDjpwOSpv6WUMC1czCIlVZG8RerOQYcetx0LzVLCZ5gCLDNUXPyflwWB+nDkaT1IZYVs7UD5WPXOWs= 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 Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Reviewed-by: Luis Chamberlain --- block/fops.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/block/fops.c b/block/fops.c index a286bf3325c5d8..eb599a173ef02d 100644 --- a/block/fops.c +++ b/block/fops.c @@ -533,6 +533,29 @@ static int blkdev_release(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_direct_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. @@ -542,7 +565,8 @@ static int blkdev_release(struct inode *inode, struct file *filp) */ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) { - struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); + struct file *file = iocb->ki_filp; + struct block_device *bdev = I_BDEV(file->f_mapping->host); struct inode *bd_inode = bdev->bd_inode; loff_t size = bdev_nr_bytes(bdev); size_t shorted = 0; @@ -569,7 +593,23 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) iov_iter_truncate(from, size); } - ret = __generic_file_write_iter(iocb, from); + ret = file_remove_privs(file); + if (ret) + return ret; + + ret = file_update_time(file); + if (ret) + return ret; + + 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); + } + if (ret > 0) ret = generic_write_sync(iocb, ret); iov_iter_reexpand(from, iov_iter_count(from) + shorted);