Received: by 2002:ac8:678b:0:b0:405:464a:c27a with SMTP id b11csp12719qtp; Tue, 1 Aug 2023 12:10:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlFY+RnBokiGasxJiZ18odCYJHRY/IWwGX6i3PYwuQgQmbK5oxrs4znwj0rAWR/sf9O/VgUe X-Received: by 2002:a2e:b70e:0:b0:2b6:df71:cff1 with SMTP id j14-20020a2eb70e000000b002b6df71cff1mr3108824ljo.52.1690917017158; Tue, 01 Aug 2023 12:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690917016; cv=none; d=google.com; s=arc-20160816; b=aqtqFg5UyfyyzmJldllgf6S2l+kLDiiANmQsChpfTACQDhjVwEiv9DD7G8tUzZe8uO Ssg0SnQVjG3IGsD2asSh/lGkgknlUlNhE0/rjrm3uV0g3v8nZLtSgy7LNOKwCQizzi7+ cMqwA5vwr/QUNYXEBTlvZNvnfR0IrFVEU3Z9WuWCVRjz9HUNNaxN3WW0vnJnxUFkd56Y r7Y8CllctsLz5RXZ9vTRdj7nWx2fz+ynEUIshWtWxXvjpioHRiRc480DOyrTWZ109qkZ +r4e0+zs8VqnZILU7pWxdKHM8xYZlwkueQkEtqFDGr199E3Jy1qEGG1t89sl0dmYCZW5 8kWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LPZ36zC6GvqbTCnZCGcWZ7da5/qiX/GMMmjuuQZZ1fs=; fh=Z8ki5Y40HW1Cj4LTSUUzezOiTJ0KadqB9ku6XsqDfAM=; b=bKW8SLGDk9RotHprVBCCEPXYlp0sJKz2gJU9Cc64xmTr/pvLc998tNf2TzU35nZY+x GvHcfp9sq4ZHg94/KHa9rUqC5MRES64SsT/X2fwKiyTCpwlXd6ApszQQpzqCJssBA6/Q LKpSWpLVUxpPMSHioN70oni8wEAXsrN10NOaj3CNfKbua8bzazEOFflEuAmTqARR80XI RICfS46rl88/mmIBjY5Ts5XWxBSEj6mfdaNaceTnZ0ionv3xrGeNMpjhVeJO/fr8FD/s 6krJHzJDkjQ03CgJ8ZgaHn63obTQA/B2r01SUhHLDXDW6OEnLgFWPja+2M2L5wdAuV/n FqVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=n6MaSNhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a05640206cd00b00521820ef027si9024980edy.210.2023.08.01.12.09.51; Tue, 01 Aug 2023 12:10:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=n6MaSNhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234529AbjHARWf (ORCPT + 99 others); Tue, 1 Aug 2023 13:22:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234705AbjHARW2 (ORCPT ); Tue, 1 Aug 2023 13:22:28 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EED5F26A4; Tue, 1 Aug 2023 10:22:18 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 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); -- 2.39.2