From patchwork Tue Aug 1 17:21:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13337086 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 94FF0C001DF for ; Tue, 1 Aug 2023 17:32:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8CC94003B; Tue, 1 Aug 2023 13:32:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08A1A940010; Tue, 1 Aug 2023 13:32:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E92FD94003B; Tue, 1 Aug 2023 13:32: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 D5578940010 for ; Tue, 1 Aug 2023 13:32:48 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8F90480987 for ; Tue, 1 Aug 2023 17:32:48 +0000 (UTC) X-FDA: 81076230816.14.8CADB70 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 345C940A23 for ; Tue, 1 Aug 2023 17:22:19 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=n6MaSNhs; dmarc=none; spf=none (imf17.hostedemail.com: domain of BATV+44153ebb3f5e3de177ba+7282+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+44153ebb3f5e3de177ba+7282+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=1690910540; 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=LPZ36zC6GvqbTCnZCGcWZ7da5/qiX/GMMmjuuQZZ1fs=; b=h6dQIYp5uKXwTHvfPZTE/9u1h2n1DbiM2I6ZIp3gjDq4a5LC7HSJAuDy5epKl35ZXh1hXX 6j6seijDfr4rNBYA95dr34yOF0TbldRcWDwmQmc8tFeHEC/LP7D2PsFa1DIH1ZpJgxbr9Z C+Z9hlBAc4E0nkIGFK/IUr9/AYn7Ghg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=n6MaSNhs; dmarc=none; spf=none (imf17.hostedemail.com: domain of BATV+44153ebb3f5e3de177ba+7282+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+44153ebb3f5e3de177ba+7282+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690910540; a=rsa-sha256; cv=none; b=qogn8BAe8PQZcMe98qWWV/aNz1UsGEVbefaUqVHPKB9Wyq/EDJRzQNJOnPI3KdQb9TlrbK QDXirLz0T8+8TEbCJC+AOMfL0HLk9ldot8qvqU5+BEco/be7TDarcRi24b6B9N5qlW0DYc 1NglOuaEebAE0tfsGKLAX/JGzGs6Pto= 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=LPZ36zC6GvqbTCnZCGcWZ7da5/qiX/GMMmjuuQZZ1fs=; b=n6MaSNhs8uVYotBzA6i/yJX+px g9LfPU499il++YjZ9AbVXnSkDQBxSIWomOOY+Mjq6Yq+hJ5WAN4tk2csRUjw/a8Cw63RlENt4IQav 79sSAP3IucnjQVn7QhONiH8ez4qiM2AYluorFx0XkLElRk42SZOWWmcQdWxJdyOR0B2Y5VeXmXIur feZmMcWLKjFyUk0VomkUVYmdacIukiXVZICpUbQ4ZpTWCgBR2kGzhCWZmTcN4jpM4ZP4RijkGtGQH n/jzw2gt8+tptTOTyEPEiOC0p2XHnxMotMu51AsgooTfgEEYVuGmVDFkODUKQBf9QUr0xriWRFrhZ tEjlhmQw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qQt4a-002uVb-0I; Tue, 01 Aug 2023 17:22:16 +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: Tue, 1 Aug 2023 19:21:58 +0200 Message-Id: <20230801172201.1923299-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230801172201.1923299-1-hch@lst.de> References: <20230801172201.1923299-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: 345C940A23 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6xkgmt61nc588qn7j8p9ki1szezs9bps X-HE-Tag: 1690910539-782746 X-HE-Meta: U2FsdGVkX1/y642gkYvctupdZOv9aggrWuJTSa83tL3eP5/tWhYpzlW10vwgG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8+9T/Um2mQpz8yIzohhVQJYs3q1NFcJqHOkbyJZlzMbgJTAH6TAq7b8DlzEODtFNmZq4cgzIAMewP5TUonrvNi1zCiAn8Fd3xfwuyiOwUkeBJWur0FCYQgCW5y2D9lOkYW+G4zYhQcPbwW5XZl/nRoKFFXLJF+sqkxSWC0eOCd4WGxjAzLppBp9ylW8wiwAZFyLjy8U16yfo1CKOLLJiN27Bo+5KFSkLWHlsiMhbAfmF3SwR4s71tciAMwelLVDaDFFqByUGT8l/5qPL4NbJaNm2F1xiM7swOO96QWEvH+tU/j6sTa6rGVC3dVYVbKXEh7DSboc/wobl4lh2PClA= 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: Hannes Reinecke Reviewed-by: Luis Chamberlain Reviewed-by: Christian Brauner Reviewed-by: Johannes Thumshirn --- block/fops.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/block/fops.c b/block/fops.c index a286bf3325c5d8..8a05d99166e3bd 100644 --- a/block/fops.c +++ b/block/fops.c @@ -533,6 +533,30 @@ 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; + count -= written; + } + if (written != -EIOCBQUEUED) + iov_iter_revert(from, count - 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 +566,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 +594,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);