From patchwork Thu Jul 20 14:04:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13320586 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 D1524EB64DC for ; Thu, 20 Jul 2023 14:08:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 547A6280113; Thu, 20 Jul 2023 10:08:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D13128004C; Thu, 20 Jul 2023 10:08:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3722F280113; Thu, 20 Jul 2023 10:08:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 240D528004C for ; Thu, 20 Jul 2023 10:08:30 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DEE6D140125 for ; Thu, 20 Jul 2023 14:08:29 +0000 (UTC) X-FDA: 81032170338.08.BB4D6DF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf03.hostedemail.com (Postfix) with ESMTP id 567162051D for ; Thu, 20 Jul 2023 14:05:11 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qfgHEX10; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689861913; 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=FviJ2yeCGqBqXQbTzRBmfPSUTBs1/XNV2kCvgMLKD4c=; b=wZ2wuaf0yui6eU8JweEOBkDEikaQaR9PDQu6TyAGj3y4q3scyhmrfrh9hlPDuMSmJqfZW7 Jpul/N+grxrBs8PNPsmcWBSdk1X5A6e/vjLyFHHgKUtyIchCxaa+jQqwZxQWE5aDi7JC53 hN3XAfPw9v+vteEeMoA9boSd90j70+0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qfgHEX10; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689861913; a=rsa-sha256; cv=none; b=e2fvxYfhgauTz7hGBMgGYsSh5dRo0nsb9U1+tA1kqnGb4umwm07OS8mAdr6lBLYKdWN+eN 02RofLDczXFTqtbKhnkyv3sAOcPEZglmQHwNCTXnKO8GcY1uYejvQhvrcXT8b7MZ5IOSS9 f79Vy/+T6gzE0nVqlWdgKN5iJCECCWU= 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=FviJ2yeCGqBqXQbTzRBmfPSUTBs1/XNV2kCvgMLKD4c=; b=qfgHEX10lEj4flWctKOvhcyM0M cNFGZnU1gk4ET3nG6rquI9Tpm3hN+yb//YIrG8r1fEhPAwbMqW6LP6snaOtTo/PRc0jluPzT0O5ER hXHfYA1w/l2zF5BquPeGQsthe8FOQSfH8+blJHEQw/6Pc8KYpOY6eAwDm4b4JGyQl2cN0ivmFTl6M 0yBTKNhEK+akJ92/gXbUCDB/PU/GepysHzFcaL3q9vyJarhfjKwcqC+Sn//OJkf4oSNm0jr7cSBmr fMAWGfE0GT6ET76ehq7mLgkuf0FeEEwA1C1k11lSvMgRX94FkvQpfD6jIoDPtIOm8ALLlj5djIHrJ eM5euuXA==; 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 1qMUHE-00BKuF-0C; Thu, 20 Jul 2023 14:05:08 +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 5/6] block: use iomap for writes to block devices Date: Thu, 20 Jul 2023 16:04:51 +0200 Message-Id: <20230720140452.63817-6-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-Queue-Id: 567162051D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: inni14gzyj4jxogfmx9km1dtc9qjsqj8 X-HE-Tag: 1689861911-680825 X-HE-Meta: U2FsdGVkX1/6x5gcBveC9nu9r9ewMmtC2CrZfhnNeh/Ca9Drnhkwi0hFQ7UF8fHgGsgN08hsuDOfetLhxWY0yfHSmtY9eECQKhYCADTED/M68DeHVrZLoLhXVA1jZp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arfVutD2h8F1RkTqrewyKiFFPTRa/3LVnWhb49tJkOYF0ZApn0+xz0nJFEdt/QvjTCQiL2kx06F+6bH73Nd3/vGwalJvl293FAvsk40gPASWo0njuew+UZTy9GzHo6lxq72Dvyl/C0aV/NRk4o8aTY6uqTxr5wKE3iDYmLUAOecLhawocnWv1PX7LKY7JXKiQ0ro 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: Hannes Reinecke Reviewed-by: Luis Chamberlain Reviewed-by: Pankaj Raghav --- 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 0c37c35003c3b7..31d356c83f27a3 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 (WARN_ON_ONCE(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); @@ -555,6 +577,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. @@ -604,9 +631,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)