Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5156015rwr; Sun, 23 Apr 2023 22:52:51 -0700 (PDT) X-Google-Smtp-Source: AKy350anoNsaMH13o0hL3hNXCl64uH9cMngDS+KAJcSqxBS5LKh4i3WCNELBiD5KX+gy2tjbUCR8 X-Received: by 2002:a05:6a20:244f:b0:d7:5f98:d2a3 with SMTP id t15-20020a056a20244f00b000d75f98d2a3mr17030857pzc.54.1682315570775; Sun, 23 Apr 2023 22:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682315570; cv=none; d=google.com; s=arc-20160816; b=SRB9pCZ1yhNpkojfc6Qg8njAvfe7+sBlN4jpjl7uWuzu29H3jv1gYi0a3Ia97vrN/i 2PWKnKZI7QVhqyGbwmX+r2bwf3iZ57cs/w52Jurbc5sRbB30uZcDYAUVImanFHLYwdmx tc+1a1sPcWpUmO8nSziG8QvQZtMp8YCN+a+tZ56BkeqwEZKj4IMf06HWncDee04l/cB4 YGu2pFrD3cB64Ce3GBozvWLfRxxw4d4mDY6MvJCBg6hV9OgyyJ2aJTUwFMgjTqvHELJk hsTNEYDhVdkRbfhLKWqzqOOVBgUoY9HA4rbciaj9ryb0YOBhcdjST1uE8OopT8MhZa3B Aw8Q== 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=sTswUsG7V37q4lilbMJoCzI78FMLYPHsnKSU4tW14rI=; b=WENqcFKmcgraKkClb8yG0QKDgIto8ykuRZIwjwm9ca02snDPS46JNIf0XR7FSpMcPI d/EPhRRN9VJuJjK/CiqCVcdX7fn+JiZkUqvl8lTixO69l0wLrOQ1P3/ZZEHHNufKwmil TAW6DWHupqXDoorcu79dKru/44t/hdFC8pQF+j5qKmsEA+zJ7ZTKYaxmT7QlD+bqvHWc 7IguEo1csE3rWHDAvL1gS6ZKlURnEnBaLHodIs4I1+qBMPbdm6N5QW9PAEm/y4Uk73iq DWANHsW8KY4GnhMW0WTohr+6p8QJF8gLnPk1TFzjG5sbM6z8LtWyq0zh4HN45lECDcNQ TWhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=UoeSfGuo; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 v62-20020a632f41000000b0051b37c000dcsi10440995pgv.81.2023.04.23.22.52.38; Sun, 23 Apr 2023 22:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=UoeSfGuo; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231249AbjDXFwR (ORCPT + 99 others); Mon, 24 Apr 2023 01:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231273AbjDXFvq (ORCPT ); Mon, 24 Apr 2023 01:51:46 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56FD044BD; Sun, 23 Apr 2023 22:50:34 -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=sTswUsG7V37q4lilbMJoCzI78FMLYPHsnKSU4tW14rI=; b=UoeSfGuoni8M8v/l7vB42i2THY zMcmd34OOElv7F+mrbgD/ShZRx4itRpkQwFSxTkpmii613jhNw9WyxCQjGj7MQShQbt7WqJjepuL4 LBmWnG81igFVQQjFpE39ugSY4dTF5078Y+qk64oapXEUft128WQk3P7Es40nmDd7R0F2d0XieesAO j5XAkEb++llO3yox0Qy5icXKSxnxY5rP++XJ6RqFTM31wvcDtrVuuPtN/xpgA7bZCD3wVcAXdYXYo jxEebVm9CoZwe3Xf0PTdYWQayQAZxQ3W9FEGkn51muLlMnnlGjCx9TQHWQLhKUkUJmMWkZDYDkloT v7jNugbA==; Received: from [2001:4bb8:189:a74f:e8a5:5f73:6d2:23b8] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pqp5X-00FP9P-1d; Mon, 24 Apr 2023 05:50:12 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Miklos Szeredi , "Darrick J. Wong" , Andrew Morton , David Howells , Matthew Wilcox , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, ceph-devel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 14/17] block: open code __generic_file_write_iter for blkdev writes Date: Mon, 24 Apr 2023 07:49:23 +0200 Message-Id: <20230424054926.26927-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230424054926.26927-1-hch@lst.de> References: <20230424054926.26927-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=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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-ext4@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 | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/block/fops.c b/block/fops.c index b670aa7c5bb745..fd510b6142bd57 100644 --- a/block/fops.c +++ b/block/fops.c @@ -508,6 +508,29 @@ static int blkdev_close(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_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. @@ -517,7 +540,8 @@ static int blkdev_close(struct inode *inode, struct file *filp) */ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) { - struct block_device *bdev = iocb->ki_filp->private_data; + struct file *file = iocb->ki_filp; + struct block_device *bdev = file->private_data; struct inode *bd_inode = bdev->bd_inode; loff_t size = bdev_nr_bytes(bdev); size_t shorted = 0; @@ -538,13 +562,31 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) if ((iocb->ki_flags & (IOCB_NOWAIT | IOCB_DIRECT)) == IOCB_NOWAIT) return -EOPNOTSUPP; + ret = file_remove_privs(file); + if (ret) + return ret; + + ret = file_update_time(file); + if (ret) + return ret; + size -= iocb->ki_pos; if (iov_iter_count(from) > size) { shorted = iov_iter_count(from) - size; iov_iter_truncate(from, size); } - ret = __generic_file_write_iter(iocb, from); + current->backing_dev_info = bdev->bd_disk->bdi; + 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); + } + current->backing_dev_info = NULL; + if (ret > 0) ret = generic_write_sync(iocb, ret); iov_iter_reexpand(from, iov_iter_count(from) + shorted); -- 2.39.2