From patchwork Tue Aug 1 17:22:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13337068 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 2C74CC00528 for ; Tue, 1 Aug 2023 17:23:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90EB7940034; Tue, 1 Aug 2023 13:23:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BE70940010; Tue, 1 Aug 2023 13:23:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 786A4940034; Tue, 1 Aug 2023 13:23:17 -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 66A8D940010 for ; Tue, 1 Aug 2023 13:23:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2F03D160626 for ; Tue, 1 Aug 2023 17:23:17 +0000 (UTC) X-FDA: 81076206834.10.F7DFDE9 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 26ECA180076 for ; Tue, 1 Aug 2023 17:22:27 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nRUkF8mf; spf=none (imf16.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; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690910548; a=rsa-sha256; cv=none; b=cNF7K7Yfs65RaU0lKIQyo2flfV5zzl8fsePhomQBUAQQPZseIl4C9aK+skgJ1YKdFnpZ2U HYaYlpNuDds79zcLRzoR4oax7t5oeXf2c+3bMd5ew+TWcEOubeIaYkD4dKAoIhL9bMN0K/ fIkSDfOO9VcSGejjbllA7FvjG5mMnV8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nRUkF8mf; spf=none (imf16.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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690910548; 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=JTr82y7UepXdHwELYFWesdOCibavx/BJhsA/0AIsVvc=; b=Vh+gPSw9/0kdYgPUODqEcJQi8XpqTM2vKFjlTxkGMr3vMsaXoYd7XS4KTcTA8yHpkTSM9n TCMeXakZHO84Waaea8LjzFGyLV6Ov3zK8sGJ61cWQZNqUJQiqhJMkfz2wre6oZEdSP8g1k 7aNXdOB9eX+LogPxolywvmYHAwBP1kk= 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=JTr82y7UepXdHwELYFWesdOCibavx/BJhsA/0AIsVvc=; b=nRUkF8mfVPyzwn/m0kchVzdKLm 5v0iKM5U7Yxj1ykRYnyMTzxlNAyhVEMt5WKJyKGDO1xPVHDPVm0cN6UL9wSrv+Nq6nS9baElkX9Og PkWAGXgjXgMe9lsPDINkwlLDwpbQ+zrLfZ/cYC8RARePfqE5vFG2AEdi6ssi8M/scyuey/S7j5IG6 Sqcd5IhmhBMS6LcLKhiDoEjlx9V0MJtU020zEAQxnJN/uwL44fU2n+BXqdzLPLHOdx2BU2nKgfEsd O/COL+ltBjb+S4DHd4cTMhmEesg1Iy80MbD8S5E26vTY8nvboIZiZk1RZNb7QCFgx/BCVWlriJflY ggon/cpw==; 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 1qQt4h-002uYq-0B; Tue, 01 Aug 2023 17:22:23 +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, Luis Chamberlain , Pankaj Raghav , Hannes Reinecke Subject: [PATCH 5/6] block: use iomap for writes to block devices Date: Tue, 1 Aug 2023 19:22:00 +0200 Message-Id: <20230801172201.1923299-6-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-Server: rspam08 X-Rspamd-Queue-Id: 26ECA180076 X-Stat-Signature: njmc3uaim45iffioon3h6hmaqyug93ny X-Rspam-User: X-HE-Tag: 1690910547-950268 X-HE-Meta: U2FsdGVkX18aDj31qifQ7+0DqTbtWSloafXeHm86exO6K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p9mZMdf6q3/19Qq6mrUEs0/26fc9cLV5w6k79JPYowC37bn0kP6e/MuOJjNlSeFc4TT5igrUJOrckzwY7Cb3QPssTOgcvEgVzTpe2v5Bq49r/bBSpZga2XoKMx22iIq06mRfLxmYP0gscUfK88vXL0SmfUIDGJXy4Y6WuPaux7XKB6GHFLPPM0x1EaFExNFhHFh2xntuQf8gUbt/oUsQVmF9s/LoMfOTQT/q/1s4dtmFUBYMxJV9UnIdhymK+vONgHe6Pk+8xu2+Gu3qyMt6DBKv1zmUFkmXlGnkZpEQqHfnYAS+twbIhC0LZKaDbinXHuhgA9NxBCltImrbtMxJ8TVqE1IskOKfNhFzCmmA7w== 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 iomap in buffer_head compat mode to write to block devices. Signed-off-by: Christoph Hellwig Reviewed-by: Luis Chamberlain Reviewed-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Christian Brauner Reviewed-by: Johannes Thumshirn --- block/Kconfig | 1 + block/fops.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/block/Kconfig b/block/Kconfig index 86122e459fe046..1a13ef0b1ca10c 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -5,6 +5,7 @@ menuconfig BLOCK bool "Enable the block layer" if EXPERT default y + select FS_IOMAP select SBITMAP help Provide block layer support for the kernel. diff --git a/block/fops.c b/block/fops.c index f0b822c28ddfe2..063ece37d44e44 100644 --- a/block/fops.c +++ b/block/fops.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "blk.h" @@ -386,6 +387,27 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) return __blkdev_direct_IO(iocb, iter, bio_max_segs(nr_pages)); } +static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, + unsigned int flags, struct iomap *iomap, struct iomap *srcmap) +{ + struct block_device *bdev = I_BDEV(inode); + loff_t isize = i_size_read(inode); + + iomap->bdev = bdev; + iomap->offset = ALIGN_DOWN(offset, bdev_logical_block_size(bdev)); + if (iomap->offset >= isize) + return -EIO; + iomap->type = IOMAP_MAPPED; + iomap->addr = iomap->offset; + iomap->length = isize - iomap->offset; + iomap->flags |= IOMAP_F_BUFFER_HEAD; + return 0; +} + +static const struct iomap_ops blkdev_iomap_ops = { + .iomap_begin = blkdev_iomap_begin, +}; + static int blkdev_writepage(struct page *page, struct writeback_control *wbc) { return block_write_full_page(page, blkdev_get_block, wbc); @@ -556,6 +578,11 @@ blkdev_direct_write(struct kiocb *iocb, struct iov_iter *from) return written; } +static ssize_t blkdev_buffered_write(struct kiocb *iocb, struct iov_iter *from) +{ + return iomap_file_buffered_write(iocb, from, &blkdev_iomap_ops); +} + /* * Write data to the block device. Only intended for the block device itself * and the raw driver which basically is a fake block device. @@ -605,9 +632,9 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) 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)); + blkdev_buffered_write(iocb, from)); } else { - ret = generic_perform_write(iocb, from); + ret = blkdev_buffered_write(iocb, from); } if (ret > 0)