From patchwork Mon Apr 24 05:49:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221654 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 5F5D7C7EE24 for ; Mon, 24 Apr 2023 05:49:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BACC6B0074; Mon, 24 Apr 2023 01:49:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66B886B0075; Mon, 24 Apr 2023 01:49:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50CD76B0078; Mon, 24 Apr 2023 01:49:50 -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 424BF6B0074 for ; Mon, 24 Apr 2023 01:49:50 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 056BBAC016 for ; Mon, 24 Apr 2023 05:49:49 +0000 (UTC) X-FDA: 80715208140.24.8655C7D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id 605A82000D for ; Mon, 24 Apr 2023 05:49:47 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=MLLALFsG; spf=none (imf13.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315387; 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=EScWBpUly43XmjjjdD4wwdvXMFWqSgBIztZj7g+ZMe8=; b=smDBt+D/CDqfngBgP/C2VcC1UtFM0l6DsU215ANdRawy3vtcQUOgMrr1v6TavH0Qse432H 2ZwEX2159vkCeiGFoFXZnhXAK6T/miuRW33Qxzh2GROftLT2DO/TIZLXPitCVTTd7ftYzy kf4aV9kjPOrE/WEwufHWoWxnej+JOTs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=MLLALFsG; spf=none (imf13.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315387; a=rsa-sha256; cv=none; b=XJ1UPKbRzcRrAdCOLhSgvjmjWAKJ6SYv0IsMpHO57czxZITfPl628c8qHAsO53IcnDDddz 3Bb23xjPI7HpOgflURwrq4jXZ27LU1k7ohL7yacly0BHKbvzqY12rQnB15moIMQTXZjpYb MvFagiGVS5ZPcBrTxZgsmL4fZhd++Jc= 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=EScWBpUly43XmjjjdD4wwdvXMFWqSgBIztZj7g+ZMe8=; b=MLLALFsGBXb0yEP6gMC+osLHIV LxXX9DY2kTS2XEw2wLe6CXDUGRoxAMHBwXzobLE9Y9zji+azCMLR5NU8y8TLrvKuOMasdYzfEdAbx YS0O7LEmtvCsE+U0cmWHT4J2ADCxI6QWaoyVaWpQVUefmWLPSuNZO42MVhHQwB3WxcfClsmoL0JNN tN4fQtJUEXSg3i8MJ/wAy3B6Z6igVb8BVPomdBmnhj9Z4ZWBCDswm59W3TtI08owaBDS0Vnv8Jt+Y NyKD0hmhBS+Tx5z7HnU1WPDVW85bTSHltv+c4f8A4YPMvyYVqQ6G4LsKmHiql/CpLvwdMS1O4lk1U I4zba1cA==; 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 1pqp4v-00FOuH-2z; Mon, 24 Apr 2023 05:49:34 +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 01/17] fs: unexport buffer_check_dirty_writeback Date: Mon, 24 Apr 2023 07:49:10 +0200 Message-Id: <20230424054926.26927-2-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 605A82000D X-Stat-Signature: ijyzaqoezgu1tfs696sjs13q5a6pkhsh X-HE-Tag: 1682315387-201951 X-HE-Meta: U2FsdGVkX18E0E6K8NfruLGxa3AhNSEloY2em4gXrr/QtNJ0e/tRCp8VWwWHgqkMphtHtOWm/ktJYDtU/ZCK7MLRbJ/SUlwXIsudNLtcfQ6IQU4N/rYGaFQWS9bpAnn+XjvqYfjRGhRle9rPQqyg8nl9n13+/usHr187J9DT0x3fO1UFa/w/H0D/qsuOwRHXZo6OsCs95dl5UVNxxMGn7Xwx7xlAGIFSyex2m4rI8woytij9B+ezuL3qT5T07PgcWJLa+4OwOntYDv9BHWH7KBuG4ZPhZXm2kUrUb9vO0U8tclKUFNAaTmQrvZh3GO4snpi31uOsBexS2ePkqn1S5FIdsp088AjjbPpwP9csxR2yBOoeA2yztRlDPWjoXp/3zKjdj4zHJXq+FktZUBBP1SIlPbXx1/HrbKHEGpkKxxggOs33uLPYCpOZV1fggXwew9mr10bd+h6OnKdxTtKQkDJw24l0epNQ4i3qT+fAY97UdwoXsR17g19EIeKqWsin/B5NOWHdnl2nFklInLz8DLygkudK6Y3k29/TJdFlYGhFfDwEb7qsXf2hfvxnicaiFn/mWjEyGGUZpnRxRgUYPl/gnhGtvkqd0vqxNOdBETy4oYDjOFxDjB4H0ghpi5RMxltvJd6v6eNWoah3vN2Jg6hOHAgEh+BkvgWQ6Cnz4967Kpdc2olyXqFoMZd1ywmTMEQbeTOdeXQta5/zA5NcnMORvNFyQze+n1wdR8S4uTe3EOK5sscfS8fAjGt5CV6In1c+yJxMKxteek7Ct2lIoSAbwyncv/HsUFRgyd7tksi9YC/POZfFiV5LBGPD1p8Bw3wh9wv0wJQvMGqUYcfui2jTeXdzbAlKro4zWhuyY0nxVW1cf8zKKbk0MZmYXMiL2TYGI7fbkAn3ZzteBdxu+edPcM9Eh5Aktz0P38hhKfLDRlP/5pZKOUQcAAVYSG6xbEm61cxEfPRFJwZz++R u+g9Ahyc HMcepoM4TSu+VuCetqf6ca2FWfeLCv691JXDO+Q5C+bRRYS6x6NFDWbyfkJnlDWKu74ALNtWg7MAroySV2PoVGnKLOyU037EtiUkWKQP/aSMKyNVMLV2w59zayN1n5h8lTcU0y3Rx/bjFOc0VZ8STpZXnE7GzgHn/ndw+VOuK8tk5y7CNuOMRtnhZzzB2oYF9HU17/+s8vKxUamqlMIBJzbSGoboWG316B8klOmbVrMduLh22rJTeqWkuS+QT6S+ImYCBfdjoYjdAkk7HMu2cKj3VhBQvSiEJZj2tWY+z0z4yKFf3E5XOfguafEQELpI3PntMNP21ogacwwvjgtzUAkZc+OvaGIrd9hwQZNJ6/CE/MWEDDyl9F6HevbAlp6jrk9XRl1BuKLI67YXaQJqd+bDJhvDPxavx40NkOJC4FVkqm7GAIZGkJMraGfvDukCp203uKSkd1n8m3wF4s2lK8YZT9ilDQIbqmgebrZiMiA/cWac= 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: buffer_check_dirty_writeback is only used by the block device aops, remove the export. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- fs/buffer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/buffer.c b/fs/buffer.c index 9e1e2add541e07..eb14fbaa7d35f7 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -111,7 +111,6 @@ void buffer_check_dirty_writeback(struct folio *folio, bh = bh->b_this_page; } while (bh != head); } -EXPORT_SYMBOL(buffer_check_dirty_writeback); /* * Block until a buffer comes unlocked. This doesn't stop it From patchwork Mon Apr 24 05:49:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221655 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 59796C7618E for ; Mon, 24 Apr 2023 05:49:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33A406B0075; Mon, 24 Apr 2023 01:49:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 227576B0078; Mon, 24 Apr 2023 01:49:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0027C6B007B; Mon, 24 Apr 2023 01:49:50 -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 E5D036B0075 for ; Mon, 24 Apr 2023 01:49:50 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B45351A010F for ; Mon, 24 Apr 2023 05:49:50 +0000 (UTC) X-FDA: 80715208140.13.05CC4C7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 1F1661C000C for ; Mon, 24 Apr 2023 05:49:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=BVLdIyeC; spf=none (imf20.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315389; 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=V5nklQoA9f4p457fAmSLCbWYVHcQ95Tr9Yi93vZ1hXQ=; b=kY9W+CC8DsHYJlL1ylmuLx0PUjvqJXxo2Pi4obF+P3t/Xb1mwQVPuy567pwj6Ou+0X32Fx KEVbBgezYBrdURnxBxB7PkMlhCZniDfHNeY0ZF3wjhM34R1XM4wQyU+x8dVDnX1GQDEC9D RIWUjpt64R/QnK8o+FCcQoNSRdwmW+g= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=BVLdIyeC; spf=none (imf20.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315389; a=rsa-sha256; cv=none; b=cjwk3/WLs5rkU1nPPJ0Q+RRCVOC8Gs124UlMudbcstubDSqlwMn2nNnvapfyL42loakn4Q QfBHZ+Gm0TJgRIAFC+7x8speOWoonsqPCyK54Mi3zn8bS+n88e1sqRHMsH52WlTxEtQdQR 7LHvVgn+ehygspzf5OsTCLO82/t8ZQg= 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=V5nklQoA9f4p457fAmSLCbWYVHcQ95Tr9Yi93vZ1hXQ=; b=BVLdIyeC9XyB883rbVnHnnshYb v9MBAr9Kui06l3iqsHsxD6wr7hDLJughW5sYL6bLE4MMi2NT4MojE/Kqi+QP5twRZ+EZc4+pHQm3S kcN/fEcPtZ2XKOf2kEcveCPw4THCw9R3Vp3FTaYaHC5Q6XyN/KDa1LZrslZMBHL8ouAUMCh+sbtnt jGhkPdK1bf1+RRVNAAo7uctMzy3iud0d3e4hNElvjoV0xaEA7vu/iU7cwGxhgjr4qByRCVU5CGTNI M7ydlMTMwaIbWoe21seFAlCC/o0TZc5ZPNp4ELlK9gRxqfYBpHM10qTh06+1CPkGzgFFFvJGUiBet OQvgwjkg==; 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 1pqp4y-00FOuS-1q; Mon, 24 Apr 2023 05:49:37 +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 02/17] fs: remove the special !CONFIG_BLOCK def_blk_fops Date: Mon, 24 Apr 2023 07:49:11 +0200 Message-Id: <20230424054926.26927-3-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1F1661C000C X-Rspam-User: X-Stat-Signature: yu641rm3cu3zarz9xcr5uqmmg8wmyt4n X-HE-Tag: 1682315388-54766 X-HE-Meta: U2FsdGVkX184tHViseSaucareo13NihETOO/Z0k/daJEI4xLzU2elJ3zYifDO6ODa0cc/gxoCUpuL1h4OxmXd5b5KlspEaUP6lTH0IBZrCAaV6ValYVtokydj+w2M5KNfiSd6Ab31D637hVFwN782yHQqojE9mjtnOIG+AK8VsSW1qzy5/YQCrEiShYdySv69EZNNfc9NGILucJMlQEGELAev7njjJhpMYy6tUndPE6v1i3NrJdfzpZOJVS3b7Vqwf34SkqVDrC2qjoVwSWxbd/edtijqoFEVh6HTSQHf/JliXGKt4dg51V3xa+YgldzoZhyydanVate5j1uji5FcV2dvt7OzTvI46ZUzloIP22kYXo2xRQebV58YggTpcD+Df2d4b57jnzbktw9tgV7Q0mSTevKHP591uZn0A+IBZoknAnRkEn5G1oUIMGcvFhCjPeqgAIJWFPLfllcwWCYbaDoFMGxNdL6z+XUUYGeHdHpZjMvDTrZ4JULLAgQL+d8ASSNFQLEHybjGUj1CUjsPpO4R4RgN6guP6tWMOhhGtIdb4qhdVV9M6Si3mflmyEXVBm6+PQD0dDpbgS2LxD2u1hxkv2EujIW+kgenbcjFSdwt6U4SbLzSg6veU5HOk9Yr/OfhJWoLcEN+OepGYDbxyYQt50yK5p3V4W0Njau7ab6t2cQcZpGtBHGWj0pnanOJM1/DpCQT9KD/9AM1TvKqY/ChOaVr14a9Q94W0E+TOyMqKLG0yTIxO/zULE0bgZ12W5c2KgSW5VxxLYq2U0WRf6BiC9bfZTWXkKrZGAVbVmoOkd0Z5JjOaa3EVguedUxKABxuCbMaydv2MsvTfEq6lqRpQnao7JqlPTnslyJJ2jAVxWbpUX8PVu72NpUUeQzKcGPuc++69Ac+ZJXjhTlKhzVMyFYTG08FI1kCX9D3KgS8C14LlJUcDVMuMSPpK4PWb5HQZ10QVzfZq1ELkb +xk+cTpF rUcT7VI+mHx1kUzeZzdvR1APltmY8WwdQqco93t1VpWSZhACIS1ZynuK4FrEloF7mekjlcqaJVtEqqaJSRZB7NhD6rUpWWro9/Dx15wG+7gyK/FB/39cjLkjAtHjCKo3HAGI7XvRV67E4OcghuuAgd4o43TJrOOhb6CPBrcfVDx5wn18qTj0nDOLuybM9n/V+YzkBkJU0efD8J7ge0SnpYLYR3vOsKyU5MkNkRGq2cSy+FhwysCXVFKNwwHpujpE8hEOgOJldpIV1PG6Pk+J8uQqVbnQVdwrZ7NI4FkoGsirGGFMI+W/k250ZtCXehlgM+rvpbAMkOJzsU0/PBh+wI9+uuTjPKzpI+xWmV54VqihLH5l3XftErS6moUvrzlC3Muk5Flk4cpdB/As0vxl3B9/g0P7TtmVV2KaKRtTyNR5iwDyt4kfEy2TMCAzSEFjLrTw0Xuz7Z2HJ1S7vxX7WcUPU2iNbAlbSWLUCKTny7Wbxo0dRdkhm1mxnW1g6zbGpasBCxMNgNFujVoFrsk3HH2hG4g== 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: def_blk_fops always returns -ENODEV, which dosn't match the return value of a non-existing block device with CONFIG_BLOCK, which is -ENXIO. Just remove the extra implementation and fall back to the default no_open_fops that always returns -ENXIO. Signed-off-by: Christoph Hellwig --- fs/Makefile | 10 ++-------- fs/inode.c | 3 ++- fs/no-block.c | 19 ------------------- 3 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 fs/no-block.c diff --git a/fs/Makefile b/fs/Makefile index 05f89b5c962f88..da21e7d0a1cf37 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -18,14 +18,8 @@ obj-y := open.o read_write.o file_table.o super.o \ fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ kernel_read_file.o mnt_idmapping.o remap_range.o -ifeq ($(CONFIG_BLOCK),y) -obj-y += buffer.o mpage.o -else -obj-y += no-block.o -endif - -obj-$(CONFIG_PROC_FS) += proc_namespace.o - +obj-$(CONFIG_BLOCK) += buffer.o mpage.o +obj-$(CONFIG_PROC_FS) += proc_namespace.o obj-$(CONFIG_LEGACY_DIRECT_IO) += direct-io.o obj-y += notify/ obj-$(CONFIG_EPOLL) += eventpoll.o diff --git a/fs/inode.c b/fs/inode.c index 4558dc2f135573..d43f07f146eb73 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2265,7 +2265,8 @@ void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev) inode->i_fop = &def_chr_fops; inode->i_rdev = rdev; } else if (S_ISBLK(mode)) { - inode->i_fop = &def_blk_fops; + if (IS_ENABLED(CONFIG_BLOCK)) + inode->i_fop = &def_blk_fops; inode->i_rdev = rdev; } else if (S_ISFIFO(mode)) inode->i_fop = &pipefifo_fops; diff --git a/fs/no-block.c b/fs/no-block.c deleted file mode 100644 index 481c0f0ab4bd2c..00000000000000 --- a/fs/no-block.c +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* no-block.c: implementation of routines required for non-BLOCK configuration - * - * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. - * Written by David Howells (dhowells@redhat.com) - */ - -#include -#include - -static int no_blkdev_open(struct inode * inode, struct file * filp) -{ - return -ENODEV; -} - -const struct file_operations def_blk_fops = { - .open = no_blkdev_open, - .llseek = noop_llseek, -}; From patchwork Mon Apr 24 05:49:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221657 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 77DF5C77B73 for ; Mon, 24 Apr 2023 05:49:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C3DF6B007B; Mon, 24 Apr 2023 01:49:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 29B966B007D; Mon, 24 Apr 2023 01:49:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13B786B007E; Mon, 24 Apr 2023 01:49:54 -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 028BA6B007B for ; Mon, 24 Apr 2023 01:49:54 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CAE68160129 for ; Mon, 24 Apr 2023 05:49:53 +0000 (UTC) X-FDA: 80715208266.02.4FF9A24 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 12E5D8000D for ; Mon, 24 Apr 2023 05:49:51 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=IisOQjT9; spf=none (imf30.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315392; 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=TRgCZMat6SwmbUJc5nYBP6IbIwCnK37cme83Pl+2pA8=; b=YqJ7l5Lc5R0YggY1QSYRBB5RblDKBPvRjgCiR5IZYrZLsq5TB+S8goNxMHYkd4t2lkiB5n Vi0UCUT4cJTp9joRsbQMGn9GIy9586pxDnu8ugWXe9tkcq7BX7V+20efjq7zSVV6+13n4i +PJIp2B11/nwydWyUlZkgg1bDFGOsFA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=IisOQjT9; spf=none (imf30.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315392; a=rsa-sha256; cv=none; b=Og88mdcnwotJNfY9ZDst9FmkEVwaCBiqoYAoahz9AU1Ue2yJOsFfv6I9P6DTj/EMiPkY1T aOTAcujIPKNMvBdr1ysBP/FAGLDLy92JTv6b89QdvdvBs6TWn8Rn8Ht2qqwfNv2yvNiBF/ WGRZItD7A6SpfKqzZ+2r/Qe6itgfydA= 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=TRgCZMat6SwmbUJc5nYBP6IbIwCnK37cme83Pl+2pA8=; b=IisOQjT9f5WFKcdC3Jd5pbj8sh 4VxYG9fcjD21qV4vH246OoxCV6nph/mgCU3NIWP8P4y3dlViSSGAmZjXKbLou0yjIYZaM3cnIY2Kt mjxtvSSMGgpzOLyFt6Owfa5+glDjlrIybM/1ZBwz3b1jzQlJ1EgeUSLyfdrbYx4CDGDKxjiIrnu36 kfJfmV8CzCSfJEL70k1/Giql2X0o5GEh/voLjYWzXCdDVciAzPcCtw1ssj+JIttdkB/PCHceRsfbT 6ORot5jXqhFK8ewJjwizNl7JjjUwrZhWXmblesM672+/0ZZBeLqjjqHAXGNhN8Y39rALvBAMKA3jw wWfxZqbQ==; 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 1pqp51-00FOul-1F; Mon, 24 Apr 2023 05:49:39 +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 03/17] fs: rename and move block_page_mkwrite_return Date: Mon, 24 Apr 2023 07:49:12 +0200 Message-Id: <20230424054926.26927-4-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 12E5D8000D X-Stat-Signature: hoxgz7aedmds14m6oepre8zkrxkntwut X-HE-Tag: 1682315391-762172 X-HE-Meta: U2FsdGVkX1+jzOo1RElDjBV6QsnoMowE29wWAaBuBRdcTz/KxwabTVF+m796itf97YGnZIy1c8eNHUN1M+qKB/IR/a0OBXHXh9hZOipLWefGAA4plM3X3frNTi1XUH4CSP7ohHcVVLzkscqfycIVq+awmSibMq7ZfFyrbrj/a9IRcgeCq565M9+zbLMuJ4yy6Xgc5n08RdJeQXJKNaCDPq15cQ6AUcQ62Dnulqr4FL/8yFtpK30uDlrK6rFUA9CKdUa5BScLskYKNA3g6uTaHb917DG6POanZhgY6HZ4pi0qSPGwE6DUAfli5f8PtC2W6Q0z7K3EXR6QaGE71Imve6WldEEkYzA6d9YIJt3Rm8y7/6lOa2y69vbP1w/e7+rpGGRR1Ei6OMgJtkn9rLBzlKwj0/eJxVoaAS8BNn7qqJ/aX6OgFSdT/ewR4HZglw8dB81sthr2T2Sx8LJ3lfkbrBtWv5xSZ7B8vKlqHU/fYyHP+aKgHDwB6kV6v46MIf3jS9h4/+R9lw57MrTvsTvNBYJkJnIlvIOL6YQzWK07EWgZ0cMjwvBxiAB6EDYmsnMeOBCyBwAIC7z5KjJ5J7jT8hG9k7vxHdRbbctorM5xBpXYq2vfVsCOuniTtT0MPWMUkdvLyaixjm5pZ25Z8eYV+lvLUzbCjwWN0nCNJgDNRYvRgzqFQYuSKrW0AWyNzAaV+F0on+UcDs5nhMVUapsGG5M67wuU3DJDR2dlpUSIvWHYZiF3RKIU7UTR+8uVjqoblj4BcewpvNZovymfTpNRdRbw68VbNmhmh/xswjxDK7z1gMJzSgOt0X82rH+UZcY3MIkQ4raaiy5fitiCtkPGzuH3HMdTaRnMZQ+xKNJ862kbpi+nhQ3I4l8NoqZpc+Gfizxls1VvwzjWUhVBv4DGvdCw/moezlCY0lnGI8o0BOCbhGfHLkUObNe4uJnB9MeQFOBakedEPgE+OeTbzep KI7SlBgB WWGy5Sc4Wuwfbk21OnsV1GpQt8dbtXzBhbxlIxbXjyNmfp+AE/E6JNSYJaOfEdjbOu0RnfsvIo8G62UkHOOBhHyWHWepQIA4fzrQB5yaWwjJ75swWFaEAUW+KfM5A0+AqS6WFTceooQksJOEAH3p7/hCs4qiO6aVs8WDXUhqGJXP367lgmjU03uf8LF3UQ6fGZpuTMGviwvQZ7TYfYkoQRUhL56Ibqdq7Auz1YMVYaDJY/lJykqw/kKGSB4EUgSmtuq1RJyhJcE+NrQN1/D2T4fF9/E9iOmBFJFGA4vWhOYppcIAiK5XrW2wxMnw4X+Ken02PFCuXa0CmlHTks+Ln3VKKqIHjKEOTCCpmsKz1J86aYh9L6GDquRNuOGNT2gSnoRExjgfE2xtVuR4yTx032BE1p+U1XaMF6xNsAV+GUCL4yeWK/rhrL9taXBbabkJ4PI3GwwaF7O5wJ5WjYoEFq3S7MA== 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: block_page_mkwrite_return is neither block nor mkwrite specific, and should not be under CONFIG_BLOCK. Move it to mm.h and rename it to errno_to_vmfault. Signed-off-by: Christoph Hellwig --- fs/ext4/inode.c | 2 +- fs/f2fs/file.c | 2 +- fs/gfs2/file.c | 16 ++++++++-------- fs/iomap/buffered-io.c | 2 +- fs/nilfs2/file.c | 2 +- fs/udf/file.c | 2 +- include/linux/buffer_head.h | 12 ------------ include/linux/mm.h | 13 +++++++++++++ 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index bf0b7dea4900af..c0f41a38bd9ca4 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -6343,7 +6343,7 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) if (err == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry_alloc; out_ret: - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); out: filemap_invalidate_unlock_shared(mapping); sb_end_pagefault(inode->i_sb); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 15dabeac469050..f4ab23efcf85f8 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -161,7 +161,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) sb_end_pagefault(inode->i_sb); err: - return block_page_mkwrite_return(err); + return errno_to_vmfault(err); } static const struct vm_operations_struct f2fs_file_vm_ops = { diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 300844f50dcd28..8c4fad359ff538 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -432,7 +432,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); err = gfs2_glock_nq(&gh); if (err) { - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_uninit; } @@ -474,7 +474,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) err = gfs2_rindex_update(sdp); if (err) { - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_unlock; } @@ -482,12 +482,12 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) ap.target = data_blocks + ind_blocks; err = gfs2_quota_lock_check(ip, &ap); if (err) { - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_unlock; } err = gfs2_inplace_reserve(ip, &ap); if (err) { - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_quota_unlock; } @@ -500,7 +500,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) } err = gfs2_trans_begin(sdp, rblocks, 0); if (err) { - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_trans_fail; } @@ -508,7 +508,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) if (gfs2_is_stuffed(ip)) { err = gfs2_unstuff_dinode(ip); if (err) { - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_trans_end; } } @@ -524,7 +524,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) err = gfs2_allocate_page_backing(page, length); if (err) - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); out_page_locked: if (ret != VM_FAULT_LOCKED) @@ -558,7 +558,7 @@ static vm_fault_t gfs2_fault(struct vm_fault *vmf) gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh); err = gfs2_glock_nq(&gh); if (err) { - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_uninit; } ret = filemap_fault(vmf); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 6f4c97a6d7e9dc..2986be63d2bea6 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1290,7 +1290,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops) return VM_FAULT_LOCKED; out_unlock: folio_unlock(folio); - return block_page_mkwrite_return(ret); + return errno_to_vmfault(ret); } EXPORT_SYMBOL_GPL(iomap_page_mkwrite); diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index a265d391ffe92d..ea35294bb158a3 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c @@ -108,7 +108,7 @@ static vm_fault_t nilfs_page_mkwrite(struct vm_fault *vmf) wait_for_stable_page(page); out: sb_end_pagefault(inode->i_sb); - return block_page_mkwrite_return(ret); + return errno_to_vmfault(ret); } static const struct vm_operations_struct nilfs_file_vm_ops = { diff --git a/fs/udf/file.c b/fs/udf/file.c index 8238f742377bab..9420284d7c0455 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -71,7 +71,7 @@ static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf) err = block_commit_write(page, 0, end); if (err < 0) { unlock_page(page); - ret = block_page_mkwrite_return(err); + ret = errno_to_vmfault(err); goto out_unlock; } out_dirty: diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 8f14dca5fed756..0fcc16b7f02bb4 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -281,18 +281,6 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size); int block_commit_write(struct page *page, unsigned from, unsigned to); int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, get_block_t get_block); -/* Convert errno to return value from ->page_mkwrite() call */ -static inline vm_fault_t block_page_mkwrite_return(int err) -{ - if (err == 0) - return VM_FAULT_LOCKED; - if (err == -EFAULT || err == -EAGAIN) - return VM_FAULT_NOPAGE; - if (err == -ENOMEM) - return VM_FAULT_OOM; - /* -ENOSPC, -EDQUOT, -EIO ... */ - return VM_FAULT_SIGBUS; -} sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *); int block_truncate_page(struct address_space *, loff_t, get_block_t *); diff --git a/include/linux/mm.h b/include/linux/mm.h index 1f79667824eb60..03e645032c81ac 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3061,6 +3061,19 @@ extern vm_fault_t filemap_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff); extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf); +/* Convert errno to return value from ->page_mkwrite() call */ +static inline vm_fault_t errno_to_vmfault(int err) +{ + if (err == 0) + return VM_FAULT_LOCKED; + if (err == -EFAULT || err == -EAGAIN) + return VM_FAULT_NOPAGE; + if (err == -ENOMEM) + return VM_FAULT_OOM; + /* -ENOSPC, -EDQUOT, -EIO ... */ + return VM_FAULT_SIGBUS; +} + extern unsigned long stack_guard_gap; /* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */ extern int expand_stack(struct vm_area_struct *vma, unsigned long address); From patchwork Mon Apr 24 05:49:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221656 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 4986EC77B61 for ; Mon, 24 Apr 2023 05:49:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA0846B0078; Mon, 24 Apr 2023 01:49:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFF906B007B; Mon, 24 Apr 2023 01:49:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A0206B007D; Mon, 24 Apr 2023 01:49:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 895B26B0078 for ; Mon, 24 Apr 2023 01:49:53 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 52B7C1C5D56 for ; Mon, 24 Apr 2023 05:49:53 +0000 (UTC) X-FDA: 80715208266.04.838AA9B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id B32A640009 for ; Mon, 24 Apr 2023 05:49:51 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QAuUTMs9; spf=none (imf04.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315391; 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=bS05QMoD6j6YpGz1rHCHZCzEMuRJxwEBMPELLNqMvVM=; b=g4r4dFAxHhQ8t5c2DQdp33pKKVw0tQT5mXZVJo3OzB/EO782bIPwVyFAAzUK8EZYcLogU/ jJoCkQPK9VHISpk7iobinfoWZHLxP6u1oRTTH3mgoKsY+uxDeM172R1N3ej6XaQ/s4MhyJ 4BwDb2rmhag8TpItuKHPmCQFRsG3NN8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315391; a=rsa-sha256; cv=none; b=Uw7oGTjqHwDgi9tei/OrF16RxBSNZXxVocdGIVJnCiMrA+wkUTj7hsSrGyFchmHvhjkG6v 4bgcxm37KM+ZHoulalrSm8L+bP8enOuenVRM2KcJBX8cyNAeXYhB5GxRbR09KbBqEW0r46 ZId6FW/07dEmj+vC1dNkCUw3nOvOln8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QAuUTMs9; spf=none (imf04.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=bS05QMoD6j6YpGz1rHCHZCzEMuRJxwEBMPELLNqMvVM=; b=QAuUTMs9c0fPPuxtegrv+eZFd7 m1Lb/Zn2oEdFxGNTL6MyQ1wn8x4GTSTmoDmXSEpvoQtz2+8sgXF6o1xdmIGxAfsSLMFUF2Rdb/QCw QELH8/3nG4bNASqOdAHA35mLeydY1xzz4dUPnNEsh0dTA/um5YWXh/LZcV75W2WYGokrA0cEhf1qA KKw6r1pxS24iVwx30XkH6ewxhXLH1nN6hYHJDiHEFB82PfR4sJADmcttvzNs0seHtisbFo0Bbqa9V n3yxCEfgi9duwfR5Ke4/YsTw+fVVP3Ub8FBS1iXniGGQbGngJEVnnvGoIEv6ORCKaN3u1LbDCqCFv PHlgzFNw==; 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 1pqp54-00FOuy-17; Mon, 24 Apr 2023 05:49:42 +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 04/17] fs: remove emergency_thaw_bdev Date: Mon, 24 Apr 2023 07:49:13 +0200 Message-Id: <20230424054926.26927-5-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Queue-Id: B32A640009 X-Rspamd-Server: rspam09 X-Stat-Signature: ktnxp3pb3u5jbig9bp3kmhun7dtccbyz X-HE-Tag: 1682315391-690212 X-HE-Meta: U2FsdGVkX184KtzxArHgwsDh2WvPbFun3KAQO0kq87QVKOvX/wTjbJkRHwmnMqR8D3pYN/eLglz13j55LbB8e+RDVwjLEWpiAS0/rQzPQktf5kxNJVE6dNi4cntu5PtcNcHPnbx3NpEfJX1Dqv5a2soVRYOSEgMRdI/ouQIc3RBWrZ7xHNIerK95iQ3URB1n6WVs9lfeG0xjbZEG+8P5tB6lmFoylodKyUvNbbCsEWMtbv7mzEzX5etSwbYeAqMlfQa3drFqusqGEBZUYGsXz/g2U1R7qQr8L4PuuwFCs3YW9vEG4iecm3FFUqyO53dcnkmHJx81nYHyc/76nYqm4PhFyLIwc1gQxPzPn8SYeDcMHXe2Yh9Ns65/AUVZLzw8LOCERmckrk6G9Qd62RK7BWBHG1wFFko6GY1AwW/ll1TQRYrQ3pWXoYuKIzoO0y9I+s0ENe6UIDSFTPsXext6uqSqPkrXj3yLeUn7LeuquR2013s+X+J0cVSqrMQalOEO3vzxvz8TbCIwbdq/Pza57xD1w8fhJj1iR4MxnM3fd+pPa3nmpbEe+bwSddFngL/yNxrSFKv/w5mtorQwe6y06kb2U7qRV0b8T2JsnZpGF3Jv6L7g+QxjtvjczJvW5kvnCbaeZMnb8bJfWqyc3pqu1OsyY/o5+Uc8OcPHm0GXmdoQbQoKemOCbWPQhQLw7MptLVquGzx/YNYGCK5vvRNrnI1UdQz01OtKOFMFeiiP6xtvRO9ioKDljZgMoN/UpfaNXZXe7Z9oh0Yt2fO5348WPI5k3H1NlnK4gfY/EmXRrOKSWssRXrQXZux9kLtRNkucD1IwGuRYY83rTlx8gb9hKRHx9PWpIg9lK04QXaY00VtxbmlWXhIEjtP0RWKnaSPhvSdtLcklD6C1U9ciMrRVIKckhpuiN1sFL1E7COuW4D6cnifiLYVoy32uNZmAtzDqXVmYngVOF6U9inky8/d qcdCkp9I IwplabDo0N+72z79yi86z7DK5fl+EodYCZClCqJ0QiDAXvXMFigMZRAmlvXlCEYQ4WjGknlSAnXhEdz/niAFXnYgRD70L7UwaomTT3BprDt0PuJwfAoN3lKzONKA70kAQqOl3gAGhCOAYOvCv0YvFZgfXswdPQzzgZVfY58Aq9xKHDCrQMB6436HgeIpoNstyt7fhRL7qXtT0p3IMOW3qTurrOB3sQTkrL/xrt3rg+k4K1oGE6FXHPjnaxB/6rXTXdWIzwLW3LcN5QrO2RfTeaHsD/gSVYXoAItAvjR4BeSL2fiFM+gDJthh0sploQksk95uukcpWRee8GhRqv88TzCN16AN1k1LzmQM/FXZugdlB7a5NjjrzVsWDu7mspjNBYZGwYnPZO/AZnSfiWnbW4f5SWIZkgspVx+AA8gzRlLxSzeRgLAsrcIEiPqM9pto7Fj89+9CaBD0jMYjEqfmNqqHgZQ== 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: Fold emergency_thaw_bdev into it's only caller, to prepare for buffer.c to be built only when buffer_head support is enabled. Signed-off-by: Christoph Hellwig --- fs/buffer.c | 6 ------ fs/internal.h | 6 ------ fs/super.c | 4 +++- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index eb14fbaa7d35f7..58e0007892b1c7 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -563,12 +563,6 @@ static int osync_buffers_list(spinlock_t *lock, struct list_head *list) return err; } -void emergency_thaw_bdev(struct super_block *sb) -{ - while (sb->s_bdev && !thaw_bdev(sb->s_bdev)) - printk(KERN_WARNING "Emergency Thaw on %pg\n", sb->s_bdev); -} - /** * sync_mapping_buffers - write out & wait upon a mapping's "associated" buffers * @mapping: the mapping which wants those buffers written diff --git a/fs/internal.h b/fs/internal.h index dc4eb91a577a80..cad87784eb5e0f 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -23,16 +23,10 @@ struct mnt_idmap; */ #ifdef CONFIG_BLOCK extern void __init bdev_cache_init(void); - -void emergency_thaw_bdev(struct super_block *sb); #else static inline void bdev_cache_init(void) { } -static inline int emergency_thaw_bdev(struct super_block *sb) -{ - return 0; -} #endif /* CONFIG_BLOCK */ /* diff --git a/fs/super.c b/fs/super.c index 04bc62ab7dfea9..d8f0a28d1850b1 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1026,7 +1026,9 @@ static void do_thaw_all_callback(struct super_block *sb) { down_write(&sb->s_umount); if (sb->s_root && sb->s_flags & SB_BORN) { - emergency_thaw_bdev(sb); + if (IS_ENABLED(CONFIG_BLOCK)) + while (sb->s_bdev && !thaw_bdev(sb->s_bdev)) + pr_warn("Emergency Thaw on %pg\n", sb->s_bdev); thaw_super_locked(sb); } else { up_write(&sb->s_umount); From patchwork Mon Apr 24 05:49:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221658 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 D5900C7EE2F for ; Mon, 24 Apr 2023 05:49:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BFF26B007D; Mon, 24 Apr 2023 01:49:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 448C56B007E; Mon, 24 Apr 2023 01:49:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EC1A6B0080; Mon, 24 Apr 2023 01:49:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 218876B007D for ; Mon, 24 Apr 2023 01:49:56 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6BFFF40134 for ; Mon, 24 Apr 2023 05:49:55 +0000 (UTC) X-FDA: 80715208350.26.3AB4892 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id C8EE1C000B for ; Mon, 24 Apr 2023 05:49:53 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=cM1FMSAw; spf=none (imf22.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315393; 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=3c56lCE/WpWmApGzGmNY2gwMFr2O/06RZiXwIkvRQAA=; b=R9hlsxQ6wmnX8Qtiml01JgNpJ6JM9aRb08fln/x9j6RwQ1JKYkgqr/XbIM+F2QLkqLcpoV 4QqfVIbN6bjYkDVGBOtMFnAhEyxPrVzSkFdtEc1QwaVR3Z0rGWC5g4fxQNenW3JOy3f+tl W/vQI6iImFyrG2EujMKcza9OLD6LD0Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315393; a=rsa-sha256; cv=none; b=noTEX3C0br7XFovdfqtb9t9ROiSD0dJMp5dKFl/oiep+cg1A27YLRC2XlIFcg6bTNM5YgA 06wS+hJqjvCTUXRjd0yiX+QdNoxTUoIW+Zdbn6TRpMkKJPJ70EDfhI3Yy3W5tViIkshkUA sExrAzGDfuhBKtFe0LxtVD8Ocw3p3TE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=cM1FMSAw; spf=none (imf22.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=3c56lCE/WpWmApGzGmNY2gwMFr2O/06RZiXwIkvRQAA=; b=cM1FMSAwc/AcWY9+ks8bZeTOQS HSRE1wj1RmlIHQ8bv8JqINzDuFQyl7YsoQO9Evk1tQKaU3yYt2c2UI9Wkit37h631rokvkd0z9B2l VVR+BaKxya/38EoJ2UI+TEap1+Ose9SVw/y8UrqGFhmlrsWIquEeWKjrX32vtILQS5aSgVf0A0uaL Ujm1de5SPOrTuaN6+/YdmMaLU7F/3TLvzgdhR5BVXO6OzWn5yVlHyHDIyq0elCmeLixuuC8FOmM6S Qn7nRM49zrqQDcjoKZ3gEI5dasf5T027NjT8LyJlv76Nt62r/CuI41r9aJ9HgIGXVKNKJ2N8Fjal6 Pdgu78vg==; 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 1pqp57-00FOvQ-0r; Mon, 24 Apr 2023 05:49:45 +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 05/17] filemap: update ki_pos in generic_perform_write Date: Mon, 24 Apr 2023 07:49:14 +0200 Message-Id: <20230424054926.26927-6-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Queue-Id: C8EE1C000B X-Rspamd-Server: rspam09 X-Stat-Signature: ydutypst9zcydfc6gsg653b1jm57yyp8 X-HE-Tag: 1682315393-206191 X-HE-Meta: U2FsdGVkX1/RjidNNJNV9jb10KZ2K8wW5a4T1Tl7pWZfF4Et5VxEcSAG3w4sbG1BYNaNk07W787hYXjq1G0jwY6owO+y3vlA+VjkDvGUST853b8P5QvJFwxTVmuGAW47yCUZdmjY+cXUn5RW/5rujFwB1osVYbNewlTo5nt/3kLYHOEzW+nYjsJFYWs87OFOxYsLPYoBi2AR0VO6xt/3Rx2Axx7m5CzOL9Ur6OzjXnhNguWR8t7GvkoMI7VMpdgJ4RLWS3ACy0khVe87jFqB5Lw4APBGg4xHdbSsW/a5iW0asGbLyZqs+AEB1F8D369YrfU3THmVuzRdeHkuVnmplWyrz76GmP4b+YKs9G8YP6t/TNPFumdqoQq/USH3Hi9nRiirRmuPbVyYauokRtuSyU+T7zTIRHN8Ltf6gj4W2Q9L+SjLLpud+xH8DP+ACvy2+jXxphPys4WF8Sjtkov59o3HZsdCpUcqZ+v69HJwBEd8UYya3rI6AlxumnweRSH+8WrV9n+DUdHnat/fDXQIdTNLjTOea84+wVPUsYAwLbYgY953zzaNpiK1e70z2Df5M9d7NKRMd+jPUAPnWCmtMmJ2WK0MvurixqyaE+g9fK6oUrdiFB5FVAOt84SpFrxXn7QqIlj5dAFu7DF9FypNqTBD5JqJka4udslcEsQeDObBPUGno3FTyOTRJjSmsrY6BeynUgVH0U4CKXIImZ46XUQ0unQ08MBxTsTHVpy3oNJ3s8d7XkG3NvSkeVXBxGm5ktARTdxRGrUCazWtTVqmscHihAvDc4ljJyUzCvQ/HeIuAEahaWs513JkICpGUr44JITnZGQVu0cI47onb+YV4WQMSrgjTSTg5EOkY5oEJHJ2wuci0gGVIl5JqRQV3HCMJ1ddRlTE/beEHQuUJk/QzbMXS+DEc1UMw1RLL+JJiYj208zlR0TwtjIeDA7UEK07rj1E58I8BNyGCQoW6+k Y+zRwThs 7V/wKutEF4SXdgvEp6l/QJmqiNh92YOiKpxFkOP4i/e14Jax6azfNISXTlnhZvpbPplcNDFds4Uo2DZmwUV2CWChObgeXhmMIgH6aab7xhdCuDVUZsqy0Eann/9rTkIDbI36vtmG48jljrZGw0qnD9XMiBNK/o15YlC4fU4WIcp/OM7g1RRWc2/AIHmnXwSyjkU2noGULSYuvsBTLSFwQUQIYhnoC6bgmeu0IOG+grcTPQJSNKENHpDd1qeex1OJoiyfni0BJJ4mZDcrSGjvzLVuZU3noaHWNk75lewO/1g8QGXTkSBuG75OS1NtJvs+mrfpicMaidm3jxaT8Ddnuh4HKbkWxVeCFmZXRDUTaful8UTvYIQi2t0X0KdtO0fcQjkMSG58uAriM8rljWEt2oOb7wX3pOAwEulB1V/WTxggSQDwa4UDnpRCzbahgdvdZG5/oLVTAR96EfEU= 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: All callers of generic_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig --- fs/ceph/file.c | 2 -- fs/ext4/file.c | 9 +++------ fs/f2fs/file.c | 1 - fs/nfs/file.c | 1 - mm/filemap.c | 8 ++++---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index f4d8bf7dec88a8..feeb9882ef635a 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1894,8 +1894,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) * can not run at the same time */ written = generic_perform_write(iocb, from); - if (likely(written >= 0)) - iocb->ki_pos = pos + written; ceph_end_io_write(inode); } diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 0b8b4499e5ca18..1026acaf1235a0 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -291,12 +291,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, out: inode_unlock(inode); - if (likely(ret > 0)) { - iocb->ki_pos += ret; - ret = generic_write_sync(iocb, ret); - } - - return ret; + if (unlikely(ret <= 0)) + return ret; + return generic_write_sync(iocb, ret); } static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f4ab23efcf85f8..5a9ae054b6da7d 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4511,7 +4511,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, current->backing_dev_info = NULL; if (ret > 0) { - iocb->ki_pos += ret; f2fs_update_iostat(F2FS_I_SB(inode), inode, APP_BUFFERED_IO, ret); } diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 893625eacab9fa..abdae2b29369be 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -666,7 +666,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) goto out; written = result; - iocb->ki_pos += written; nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); if (mntflags & NFS_MOUNT_WRITE_EAGER) { diff --git a/mm/filemap.c b/mm/filemap.c index 2723104cc06a12..0110bde3708b3f 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3960,7 +3960,10 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); - return written ? written : status; + if (!written) + return status; + iocb->ki_pos += written; + return written; } EXPORT_SYMBOL(generic_perform_write); @@ -4039,7 +4042,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) endbyte = pos + status - 1; err = filemap_write_and_wait_range(mapping, pos, endbyte); if (err == 0) { - iocb->ki_pos = endbyte + 1; written += status; invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, @@ -4052,8 +4054,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) } } else { written = generic_perform_write(iocb, from); - if (likely(written > 0)) - iocb->ki_pos += written; } out: current->backing_dev_info = NULL; From patchwork Mon Apr 24 05:49:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221660 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 E9257C7EE22 for ; Mon, 24 Apr 2023 05:50:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B7696B0080; Mon, 24 Apr 2023 01:50:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 866E26B0081; Mon, 24 Apr 2023 01:50:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66C3D6B0082; Mon, 24 Apr 2023 01:50:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 586C66B0080 for ; Mon, 24 Apr 2023 01:50:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 14215A00F9 for ; Mon, 24 Apr 2023 05:50:02 +0000 (UTC) X-FDA: 80715208644.26.0950787 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id 6E88DC000F for ; Mon, 24 Apr 2023 05:50:00 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=LPBHKUTF; spf=none (imf10.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315400; 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=FZ/oX6CCuoV1bgBWAGOx8K6ORykPZ4voWywQ/l5w2pE=; b=kFNhU+exfyIjh3AcGQ7lLIAUqBd2RVcfBCaR/rLUgNR/fXXdTaT2REcSgAcHtcEs6bynVj JHNHfClo63j4DrYVuyeOBZKncgCTUlb00Ppl1+81TZybXzVa9E0BJrzDA8cjNyM7psF3Tu TRYtNXnBuZxJ3wWDJh/qfCYPHx39CfQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=LPBHKUTF; spf=none (imf10.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315400; a=rsa-sha256; cv=none; b=WqwfrGvk8XCvqXJ1fccIdEeuhNIKDaCAYKcCfV+sfjXAGb6xSi0aexznRAiwMhdmnXBRqK ZN1WZ+tUujGL6DbRB9iFwjjgfFqhgzOwCVe3aUmIax4Lwpprjrdynl5g15Ih5h+XGlGy8w X6fKUH+e/dEDp4OaDHWvjRWb4ApENiE= 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=FZ/oX6CCuoV1bgBWAGOx8K6ORykPZ4voWywQ/l5w2pE=; b=LPBHKUTFShS6lFcY9XAvrDO0zy 2lv9lSVBz58fAlT2EQi21jkueDOTS4twSStbFX5syhvx3ExuYVTYHf7Uj4O+4gRkholvUzQfsBcGM tdLNzfyJevRkb6vfEGgqTSROsy9NbDiGm1YGQ+aUl4dzdtQ7j5D4onehk+I1FYoOC/PnDCk9rdzOP Jw8L43J/TAXvVuHlvExzZqOHSCZWdqzV2HplCDpDQjup3RzBEOjFY66ho4n+n3SwT6MAzQBaWtIUq 5KlfoqP7K2wthTABWhRz6wnhfsdxVwTKphcpG74JgjuxMocweMuLa0NGt3sY0/TpYPdgIZSJTnEL8 OEkt1oog==; 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 1pqp59-00FOvi-2z; Mon, 24 Apr 2023 05:49:48 +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 06/17] filemap: add a kiocb_write_and_wait helper Date: Mon, 24 Apr 2023 07:49:15 +0200 Message-Id: <20230424054926.26927-7-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6E88DC000F X-Stat-Signature: 4rxc5qybz8admdj7bstywooz1n5mnurw X-HE-Tag: 1682315400-560161 X-HE-Meta: U2FsdGVkX18ipAUARHMUom1nf0+vRxqt1hxbRuRBv4zsYmkWiDn0jg5eSt7dAGuA9EH4UHCbdKxB9+Ta8KWjRENxOVojfmQmVBUmxgpdIuj7XG1cRbsSCeLq0rHoxC/ZFBnZ0b6W7dWfvzoa/Zpn+GmKLB0apJe/ar6I5bBKfPvq6OAi/QLTjSo6f2rQOLjyH2nQffxCQY3avXZJ9DuJi4vh5jaVcHYafQaMTgKA8hZx2psMvHn3pF9q3ybe4Ok1wtPmkFWxdHQHs3k/lb3PN8wrD+s6VbX8B1+QxZPTqOozYDt3Cy+DXgfiq/JUoGJMCZrxKtBOj3hstgq7v7IWUXUvebM6CV5aI9Gsr0KtyC5O50U0YnYXLPf7KG0DpocaKrMqVQ8jAH2uk4BhY2676kKv3yhFq/VRNXeyXeEgPBEUzU0j8qH04nz2/KgmlOkkw5odA95FurVgN+NHyGUlc5cnS52Z1xl3OD7BjUR0cQCYDXxnnMp5B+qyWtp/0BPdKdL+wd7pzXPmVRe4V3VbgSXV0FyT+l7Ru/f8XvJCNODD9GWLa9dzal8YZSVCNrsiQeK/DAMChllUDhncfO31VJ65+S5OQWtVFKLidJiG1QA+MsY6FSgVNbVcDw6Xjp/vM8/xrod5ogfpalg4T7Yn3rX2Fdp6Ccu1Ur9YCEHZRSGiqM1i2aayiYEsLVZvrChxYSBYYietLVe16n65F6T2vtZ86oMBxNMKU3Ypp5GaetcRdq2fKcVlUNQP58ddPYbjndNpvdHEScmTIS/BlDOQogF3S0lcLUc4tWfANmU/2Zs2010NBujzfFtrT7BA7dbei9zvlHKvyv5iypt1TAu19xxDtok8Q6EefXQgK4W8xsIUV/rXyVvynn5Ln1UhUTUDAAizQJ2ULcX04GyHJGzWyBC4Yo3gRezISZ1yVR2W0eUtX7yXcUSw2xK8wKZj0v31E43TPmrmUd0NXDGyyLZ qM/ZqyPk a0x8I7SU+7HPUMaNJeoOm6P+0akrpRg21dJdKiv1I5sYiPUTsd2X8sd5QzVk5kOCN8j884LtWKNq8Ye7a5hCtnXX5rZ49NE5yJq2/Ml8xO6YSTTawWHsrc0e9eg5yrhaQa1mQmhD70qHBdajWtdStpVOZRSvQPT2QSK+lEBFtZmT0sqsp3rb5n8iwhvNMjse0Xf+zKSaTzLPUyMaGTYmvA2UQ2uCu5Y2Gk1OKgEjX7+TR9iX5/xLhL78cD+Ko0qzmwuZ7Onw+mS9iHV7tq713tIBzjUIr9nrXeMA9igYx4JsIrJzeug9+xT8eavIkw10+unvgK/72G25HjT8F1sM+tlLzFIQJGdZNRp51Qak3tYaQB8CiTN0gU22r7hOlxGNxuS4DZDQ8LgO7mX/Wh9xsGAf+0wQPljxB/j5Ie61ceo3Snx8dBQNy4VBtvnPqUaaLEd7PLkbOOQjDie1SXrEpDUeoAwYcEm1OhT+gV9HPRErV5Vs= 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: Factor out a helper that does filemap_write_and_wait_range for a the range covered by a read kiocb, or returns -EAGAIN if the kiocb is marked as nowait and there would be pages to write. Signed-off-by: Christoph Hellwig --- block/fops.c | 18 +++--------------- include/linux/pagemap.h | 2 ++ mm/filemap.c | 30 ++++++++++++++++++------------ 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/block/fops.c b/block/fops.c index d2e6be4e3d1c7d..c194939b851cfb 100644 --- a/block/fops.c +++ b/block/fops.c @@ -576,21 +576,9 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) goto reexpand; /* skip atime */ if (iocb->ki_flags & IOCB_DIRECT) { - struct address_space *mapping = iocb->ki_filp->f_mapping; - - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_needs_writeback(mapping, pos, - pos + count - 1)) { - ret = -EAGAIN; - goto reexpand; - } - } else { - ret = filemap_write_and_wait_range(mapping, pos, - pos + count - 1); - if (ret < 0) - goto reexpand; - } - + ret = kiocb_write_and_wait(iocb, count); + if (ret < 0) + goto reexpand; file_accessed(iocb->ki_filp); ret = blkdev_direct_IO(iocb, to); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 0acb8e1fb7afdc..51f7aea51169c4 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -30,6 +30,7 @@ static inline void invalidate_remote_inode(struct inode *inode) int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); + int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); int filemap_flush(struct address_space *); @@ -54,6 +55,7 @@ int filemap_check_errors(struct address_space *mapping); void __filemap_set_wb_err(struct address_space *mapping, int err); int filemap_fdatawrite_wbc(struct address_space *mapping, struct writeback_control *wbc); +int kiocb_write_and_wait(struct kiocb *iocb, size_t count); static inline int filemap_write_and_wait(struct address_space *mapping) { diff --git a/mm/filemap.c b/mm/filemap.c index 0110bde3708b3f..28ea9804191d6b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2765,6 +2765,21 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, } EXPORT_SYMBOL_GPL(filemap_read); +int kiocb_write_and_wait(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos; + loff_t end = pos + count - 1; + + if (iocb->ki_flags & IOCB_NOWAIT) { + if (filemap_range_needs_writeback(mapping, pos, end)) + return -EAGAIN; + return 0; + } + + return filemap_write_and_wait_range(mapping, pos, end); +} + /** * generic_file_read_iter - generic filesystem read routine * @iocb: kernel I/O control block @@ -2800,18 +2815,9 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) struct address_space *mapping = file->f_mapping; struct inode *inode = mapping->host; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_needs_writeback(mapping, iocb->ki_pos, - iocb->ki_pos + count - 1)) - return -EAGAIN; - } else { - retval = filemap_write_and_wait_range(mapping, - iocb->ki_pos, - iocb->ki_pos + count - 1); - if (retval < 0) - return retval; - } - + retval = kiocb_write_and_wait(iocb, count); + if (retval < 0) + return retval; file_accessed(file); retval = mapping->a_ops->direct_IO(iocb, iter); From patchwork Mon Apr 24 05:49:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221659 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 F4064C77B73 for ; Mon, 24 Apr 2023 05:50:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B6CC6B007E; Mon, 24 Apr 2023 01:50:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8670D6B0080; Mon, 24 Apr 2023 01:50:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 707B2900002; Mon, 24 Apr 2023 01:50:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 640836B007E for ; Mon, 24 Apr 2023 01:50:01 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 36FB31601A2 for ; Mon, 24 Apr 2023 05:50:01 +0000 (UTC) X-FDA: 80715208602.30.561BA26 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 930D9C0008 for ; Mon, 24 Apr 2023 05:49:59 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ksnjCNaa; spf=none (imf28.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315399; 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=LInMwgmm7juakhqMJmUm/pISuBKmyhtj1h64RTxGVFE=; b=RQpuY4hq92wXgWKVec9Nq4EO7ri40OBEUyx4zlghNPzc3JnYyr2a1dU5HA8FJXalkaDFsq Zc2UdJ1MsSmLjEaId2svo9qFv++UmFUPeWN412ZxfrHJq5+L3LUbLyhyvcNfx5W3TV7qjF vgfo3KefES2jXM2OXJ/bbi8hQfJOZT8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ksnjCNaa; spf=none (imf28.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315399; a=rsa-sha256; cv=none; b=npr+Pb2dXRHR/5bK30vFXsIa/MLv664YubrgFk0WItHBS7vmTN5X3FGZu5Me6/AqSZ1lGD RZD10SX8SS5bvPhfTF/jrYXTUFOLbd8mLAUbVyUaVNCZ5+glR48Imlp0LLQrn/sthLfAit rLPWC2YvLRunnjopi+HNUKzlExiwiII= 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=LInMwgmm7juakhqMJmUm/pISuBKmyhtj1h64RTxGVFE=; b=ksnjCNaaIYILtAb94qr1FTT2Wz kZRuCMhWL9racZ9eP9X8K5p9+krm6xIvaHOewtdjyif7/XMRozz4R7mpRrFqpSzaYOYZZp+hz9j64 ccya7w488Ktn5XvstbBsAUFLV2jC6akCFOTNSUsoO0g72ip2tieVyNrcMOs/bqwhYxlcGZnjpO8P8 p+tTKt17x8IxnhUcRLwo01cYYILh46k+ybO9S5xEZSDgd33UCHppPSdPVnIHFLtlAPgyTTg0J5cIP VsGdLLnL5NPrn4LLLxCrWgG5kPHsLi0NxWZb5LKRKHJgnMP5ZYVjS6xFc2Hlea4qeMAV15N77hydj ZnQ3LaDg==; 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 1pqp5C-00FOwD-39; Mon, 24 Apr 2023 05:49:51 +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 07/17] filemap: add a kiocb_invalidate_pages helper Date: Mon, 24 Apr 2023 07:49:16 +0200 Message-Id: <20230424054926.26927-8-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 930D9C0008 X-Stat-Signature: xrurp7sgx17xoiyhht4p6fza9znig55q X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1682315399-431978 X-HE-Meta: U2FsdGVkX1/vGJH2jWOJcUcwgDYWHQOvZySEkv34cUKFrbSz4xvMK67DpZH4le+yK3HtoqI3xAIaABvruFQi0uu/Y9lT/gLOqSVLjzElkR7t4VWXJ0C6gzKWKsF+Zk4iaurK4/mme/D3ZiIrJlfvbApqn9juZmYjGg0fPk/sMCBiIQdbmwWVLcfitsu8EFY/lbRYfym3hew5u8obgUPy1DCvW8Xp3Tu76+NJNF5DiscMAD65PIX/MtJj1TFAweMs5jVi6np5FN1pOyeJWvCviMV81LmiPEdd5SUxKxNXhOiU1hx+kHw6U8u5TliEbJNHRVMGpbgKAZAUGqY7EA01ZU9dUcsaL1esDIZjaUuky57lY7ABZHFhuwvYd3cwnXKOjwkjqQSKtqwWVjtWVO7wqZW6/uwQ4JUa4XVvWlV8/u1AEMJxPIhMsgT6+KSdUlHHDSJI3Gkc5550w095URgyLDflMtr7mNbPleRXlvZeVfnXZJ5gX9yiVjnGAA9beKt0l3M/HbCEzYN4Z+fwXIRO0fkFocF6ekSWcryXlXEcYFWz9FGRX8hE/t8P5YYTW4PfxOGKk1Xh7DB4yu77KhlkrwuS8tMXTptcXd7+hF+IK6OqvatQykrGALMdtBC3BPZxyfFYRT5vgHPwh+SOiy2l05AomfjqVkkggXQ5qgCjpaX0ax0kpUUgsW4wZ3Qk8kQBNj8s416Y+qTntH2FELuwJDfBHRS/PwryVm81jv9t4S7O5Zpa7XWy1oWglooJ59FhDQ+fxWtLSaypdMVpIlFEPCOXPo5gnQEWNk8Ig0lcsOFWlfhUTBKpx2zO1aJt4Yq+5FhS0+F7ihJ4zElUvd6lGcNpETRtQg1I1ZXVPT14jZP8R2nTgCG8t2yXxLiNz9Bq7TEgVLE6JCxfudEJuti7gv3xLZY/u+nq1o1RimXBdVyHvhFiHVBHxIy3SLOGVOxH6sXCcTr+1/5GRhzEP4F OKAgxAUQ Fswi/GGHa3c096dXMXBSj5ufVy4AsmXbZxXxJK12KSWGtwEbo7uzhZANff2liSw0Q33narULQqDBq92bHgBYEm3Euk/UqA5ddp/DBcgq7Zo1TYt2/sj+8J6svfdWFhoHj+cLI0BjxkVA1fZEew/FAAhXYzoBs2lnAlmJSh2Tzm2zGuhU2erKOjNxOdszmcDjg08/xTUolB15X4Fs0nQQrAk4z93l4LtiS9ztIHnoxZkLgJDmHhX9H4PO19dykL3P6wad1vO5+AsxGNneTdvDnfoNEVzQD3ryOZIyvoFvMdzO7WGw7toNOM5HEhrfGV/G/WVq/NCANEFyrAlwhUi184KDaaj4ZTV2TicVVo3BkYLXgyZKr47b51cwIl/bW/5sQoUNzKmhyOBNkBCAcZnJ2D7sfdGu1M3Nd1EEy6sQLSm0nJPih6QLjdUtgZNN4bO8mV8x/jvSgpCDwThId1I0PiehAe1wqQPz4dy3c/i0mHWy8dbo= 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: Factor out a helper that calls filemap_write_and_wait_range and invalidate_inode_pages2_rangefor a the range covered by a write kiocb or returns -EAGAIN if the kiocb is marked as nowait and there would be pages to write or invalidate. Signed-off-by: Christoph Hellwig --- include/linux/pagemap.h | 1 + mm/filemap.c | 48 ++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 51f7aea51169c4..f6c5ef9d3d7646 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -30,6 +30,7 @@ static inline void invalidate_remote_inode(struct inode *inode) int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index 28ea9804191d6b..afb3b0169a9173 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2780,6 +2780,33 @@ int kiocb_write_and_wait(struct kiocb *iocb, size_t count) return filemap_write_and_wait_range(mapping, pos, end); } +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos; + loff_t end = pos + count - 1; + int ret; + + if (iocb->ki_flags & IOCB_NOWAIT) { + /* we could block if there are any pages in the range */ + if (filemap_range_has_page(mapping, pos, end)) + return -EAGAIN; + } else { + ret = filemap_write_and_wait_range(mapping, pos, end); + if (ret) + return ret; + } + + /* + * After a write we want buffered reads to be sure to go to disk to get + * the new data. We invalidate clean cached page from the region we're + * about to write. We do this *before* the write so that we can return + * without clobbering -EIOCBQUEUED from ->direct_IO(). + */ + return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, + end >> PAGE_SHIFT); +} + /** * generic_file_read_iter - generic filesystem read routine * @iocb: kernel I/O control block @@ -3823,30 +3850,11 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) write_len = iov_iter_count(from); end = (pos + write_len - 1) >> PAGE_SHIFT; - if (iocb->ki_flags & IOCB_NOWAIT) { - /* If there are pages to writeback, return */ - if (filemap_range_has_page(file->f_mapping, pos, - pos + write_len - 1)) - return -EAGAIN; - } else { - written = filemap_write_and_wait_range(mapping, pos, - pos + write_len - 1); - if (written) - goto out; - } - - /* - * After a write we want buffered reads to be sure to go to disk to get - * the new data. We invalidate clean cached page from the region we're - * about to write. We do this *before* the write so that we can return - * without clobbering -EIOCBQUEUED from ->direct_IO(). - */ - written = invalidate_inode_pages2_range(mapping, - pos >> PAGE_SHIFT, end); /* * If a page can not be invalidated, return 0 to fall back * to buffered write. */ + written = kiocb_invalidate_pages(iocb, write_len); if (written) { if (written == -EBUSY) return 0; From patchwork Mon Apr 24 05:49:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221661 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 3577DC7EE2A for ; Mon, 24 Apr 2023 05:50:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B6D56B0081; Mon, 24 Apr 2023 01:50:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 867996B0082; Mon, 24 Apr 2023 01:50:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 707EC6B0083; Mon, 24 Apr 2023 01:50:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6327F6B0081 for ; Mon, 24 Apr 2023 01:50:05 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 325D8ABEDF for ; Mon, 24 Apr 2023 05:50:05 +0000 (UTC) X-FDA: 80715208770.12.318F4E1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id 76A2BA0013 for ; Mon, 24 Apr 2023 05:50:03 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uebmB2Tr; spf=none (imf15.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315403; 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=i8BBYqYTYYknSfjW0NZ6ikX9GZ70UEDP1VbXwkZOOdg=; b=CbAhgscNKyielGpQ22yZN512RSuS1SO10QZQnLH8E4ezpJq8J65OSHEDoWvskWF8m0PnE+ LMtweJ6j2Lpam0+ZzuMwoWoVFqM56nmsgzO/LGbTD++OKO7rzLBaMdNJp/LVJQF7UnXzSw bJoI48xlR54yGLdkADZOeOPcaNIlPBI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uebmB2Tr; spf=none (imf15.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315403; a=rsa-sha256; cv=none; b=0aI0DCBcG8FTeWrRmrQ6Dt+r3I2fNhi0dCRUln+WoLkhKmUvU86h3LUA0KAe7Ryzj2kI0T tAcFMuGvt3f/agvq/tbz2GGcLLWk5MLTJcrnbNUt8nt2NU7QRbFj+Vu0tejVEOct/FMbFe 4x9vJZvUnPbe/j44QzXfrx98QvgIrT4= 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=i8BBYqYTYYknSfjW0NZ6ikX9GZ70UEDP1VbXwkZOOdg=; b=uebmB2TrdTF1zXHpxlQ4zmX9p7 OE6/jCrxtNpUSsm3oRanJdH9cjwZyFUIVGkLL3HYIYEywM7CWJS6u1SGHCJ+9nmF+IYsXgZypSalJ qySPa4U+nhr2t5BJFjqYAaRNRBDkR3XXH0rzwvnUK69Rxok4xokOYbpVylefv6AGEw3Xqz4XFhj93 mAJQ63xk8LERHrGP4/hp4F1dnTZ+EkYcEImpKJG/Ve4SPd0ElXFB7R7aRuKRQ8jMol/kzP9KAq1at GxurAMdHe8eQJ7AZtyAbdJg5xYLyMe1YbYIbp1uWOlFDuYVBmi1q6cEUcjG09cqN3xYIkIvgoG0z6 iOJ344gA==; 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 1pqp5F-00FOxj-2z; Mon, 24 Apr 2023 05:49:54 +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 08/17] filemap: add a kiocb_invalidate_post_write helper Date: Mon, 24 Apr 2023 07:49:17 +0200 Message-Id: <20230424054926.26927-9-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: wgqh19ejcwsqb3g1hypx6y5dqrbx17zc X-Rspamd-Queue-Id: 76A2BA0013 X-HE-Tag: 1682315403-924792 X-HE-Meta: U2FsdGVkX19bTAGO65Rq1BbovLIoGY96mkBSsH03GheD5qxfrYPbjymP2xCfh991QR7NdSc04OvQP1PKgoERDa8ROH4aUUVTP9o1KlgjfYs8B8PZlGd44xB6TzD/KUCM/28aY0zyBewLUl+pIzaqDcOOPEyq0Vj9JIcGN0wPvmf4bNgSAlTiZ66Zvgi+BzayyTq5nj5f8W6RWpoTIGp3wqJ1bnXZzFnJwutWanp1Cbn/V9DQZeV2BxVC4bElOK5A/SqPAUrCokPv44VAzidC5eyK/ktrZcNcObTPtFVMPf2paMBbD20KP9ZXLSlhAlB1qA4kwHao4H0tn2fqk54AFic72K6pZ/fNEfz63Mdyu7nG34xICU5iU9RlwuLrD8x9EZoTMP9TmMW5d2RG/orcwXezxslCnkE9o4382p+lkoyHrGAU1fBE1Vk/5f8yK8ww3C5tS1cwPD2BuxOuHzQf6QUMJlwjvYE9tRT81B5Nr0gz0YT5AQgYtWtj+Wd+fOwDF7DCfZep0R9wG9ZscFPFhI0fdhEuwf2m6tp4kF94dcjYoWlb65WNRU8wwXmUkNubiVeJSWvNZn0XNpKmax5ipOKRVPu6Lwyvx3dEGgPfc/ELoh+BTUfTXQGuVpn7wV1xMmYr+k5Tj2rillF831xZRaeIHLEKD//NwHqDgTu9ty4q0DzG+6pNwa+IiW9Ds5lVVa3KYWcRDAqra0doOZR+RRyM6xu7c62FcLNU1i4MWmhGaa6AElLp86sC2rqOZ1RPY+HPYLR9WNyABb1svb4japySgsBnCBYXlYzgxqskelZ4Nqve53556R40Mawykjj0MXVsxiwkqfL5aTH+4ahCNXyb5FvEY9tiAHb1eIT9tg6yD4p9da7vrG3ae+esMYXfcvwlToQmiDq++YFMDMwpYpD+Rn9XX6WqmLKEiU83pRCNAx1IulDluQb6yfg+HrYUF1QdZHkUDZysvjhEggk nNes0H6U w6dNVZyI5gNKkWtxCY2N9V3vj1xuJYRMjLfJl4L8ZCA7nuJhKTwTmjtPvURfQn9Xg9q6vD3DytVpSwag4CwPXfgG1QandpkzxSZ8uOVy6Og1S1okXAKnYoTKFduKIPzX3LYDNaxTsgXg1cDLC3QYJzNSLQQHGay6q+AJ92qqQxbByCEtkkyEt3bRqX8eE6nKQO6H0fdCo11a1M36Qb/t+RUbk1H5TA3Io/P0254Nvt4+flp4c+dml2Q5ACyV628vA4bn7/u+Q668CwCvkr5qZF3zrM23k4FN4eN/vGC4rK1FBvBJ4bHQs9R69mfW2K4TDi/PempvN5gqZYXIwpPxQpxIfNNBBKNV8uY/nZ1W1HZR0KrY7eXpCS89+INk20OZavCq/nOJCAyWWjmPCKUwiThXuyeFO2VvGrfrGu0RBdtH+7vmU7AsYodkIVIFXpVricF9lYg31R1g24Dmx0ukZQPc82UJzKic/iuPgJ7XOJSy0UNk= 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: Add a helper to invalidate page cache after a dio write. Signed-off-by: Christoph Hellwig --- fs/direct-io.c | 10 ++-------- fs/iomap/direct-io.c | 12 ++---------- include/linux/fs.h | 5 ----- include/linux/pagemap.h | 1 + mm/filemap.c | 37 ++++++++++++++++++++----------------- 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index ab0d7ea89813a6..f2d2e544c259dc 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -286,14 +286,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags) * zeros from unwritten extents. */ if (flags & DIO_COMPLETE_INVALIDATE && - ret > 0 && dio_op == REQ_OP_WRITE && - dio->inode->i_mapping->nrpages) { - err = invalidate_inode_pages2_range(dio->inode->i_mapping, - offset >> PAGE_SHIFT, - (offset + ret - 1) >> PAGE_SHIFT); - if (err) - dio_warn_stale_pagecache(dio->iocb->ki_filp); - } + ret > 0 && dio_op == REQ_OP_WRITE) + kiocb_invalidate_post_write(dio->iocb, ret); inode_dio_end(dio->inode); diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f771001574d008..2bf8d684675615 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -81,7 +81,6 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) { const struct iomap_dio_ops *dops = dio->dops; struct kiocb *iocb = dio->iocb; - struct inode *inode = file_inode(iocb->ki_filp); loff_t offset = iocb->ki_pos; ssize_t ret = dio->error; @@ -109,15 +108,8 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) * ->end_io() when necessary, otherwise a racing buffer read would cache * zeros from unwritten extents. */ - if (!dio->error && dio->size && - (dio->flags & IOMAP_DIO_WRITE) && inode->i_mapping->nrpages) { - int err; - err = invalidate_inode_pages2_range(inode->i_mapping, - offset >> PAGE_SHIFT, - (offset + dio->size - 1) >> PAGE_SHIFT); - if (err) - dio_warn_stale_pagecache(iocb->ki_filp); - } + if (!dio->error && dio->size && (dio->flags & IOMAP_DIO_WRITE)) + kiocb_invalidate_post_write(iocb, dio->size); inode_dio_end(file_inode(iocb->ki_filp)); /* diff --git a/include/linux/fs.h b/include/linux/fs.h index c85916e9f7db50..b8ca376e606255 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2818,11 +2818,6 @@ static inline void inode_dio_end(struct inode *inode) wake_up_bit(&inode->i_state, __I_DIO_WAKEUP); } -/* - * Warn about a page cache invalidation failure diring a direct I/O write. - */ -void dio_warn_stale_pagecache(struct file *filp); - extern void inode_set_flags(struct inode *inode, unsigned int flags, unsigned int mask); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index f6c5ef9d3d7646..38d767499daa1a 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -31,6 +31,7 @@ int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); +void kiocb_invalidate_post_write(struct kiocb *iocb, size_t count); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index afb3b0169a9173..8c5196cf93a454 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3819,7 +3819,7 @@ EXPORT_SYMBOL(read_cache_page_gfp); /* * Warn about a page cache invalidation failure during a direct I/O write. */ -void dio_warn_stale_pagecache(struct file *filp) +static void dio_warn_stale_pagecache(struct file *filp) { static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST); char pathname[128]; @@ -3836,19 +3836,23 @@ void dio_warn_stale_pagecache(struct file *filp) } } +void kiocb_invalidate_post_write(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos; + + if (mapping->nrpages && + invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, + (pos + count - 1) >> PAGE_SHIFT)) + dio_warn_stale_pagecache(iocb->ki_filp); +} + ssize_t generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) { - struct file *file = iocb->ki_filp; - struct address_space *mapping = file->f_mapping; - struct inode *inode = mapping->host; - loff_t pos = iocb->ki_pos; - ssize_t written; - size_t write_len; - pgoff_t end; - - write_len = iov_iter_count(from); - end = (pos + write_len - 1) >> PAGE_SHIFT; + struct address_space *mapping = iocb->ki_filp->f_mapping; + size_t write_len = iov_iter_count(from); + ssize_t written; /* * If a page can not be invalidated, return 0 to fall back @@ -3858,7 +3862,7 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) if (written) { if (written == -EBUSY) return 0; - goto out; + return written; } written = mapping->a_ops->direct_IO(iocb, from); @@ -3880,11 +3884,11 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) * * Skip invalidation for async writes or if mapping has no pages. */ - if (written > 0 && mapping->nrpages && - invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, end)) - dio_warn_stale_pagecache(file); - if (written > 0) { + struct inode *inode = mapping->host; + loff_t pos = iocb->ki_pos; + + kiocb_invalidate_post_write(iocb, write_len); pos += written; write_len -= written; if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { @@ -3895,7 +3899,6 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) } if (written != -EIOCBQUEUED) iov_iter_revert(from, write_len - iov_iter_count(from)); -out: return written; } EXPORT_SYMBOL(generic_file_direct_write); From patchwork Mon Apr 24 05:49:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221662 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 7E500C77B78 for ; Mon, 24 Apr 2023 05:50:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 168756B0082; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09E86900002; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E81E16B0085; Mon, 24 Apr 2023 01:50:16 -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 D7F116B0082 for ; Mon, 24 Apr 2023 01:50:16 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AF6531C5D61 for ; Mon, 24 Apr 2023 05:50:16 +0000 (UTC) X-FDA: 80715209232.18.37C8672 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 153A4C0004 for ; Mon, 24 Apr 2023 05:50:14 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YyUrIXOA; spf=none (imf28.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315415; 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=OgIbgYEwKQKejMeYOKJTDG1ASpjdjHjMo1Pk1taujZE=; b=eiua8GCGTkHdpn7lAMj4fvipUnhM4TNlD7n9QUobZNgPFI1vLOtTWXQbdDaJMELdFIkait F++pv3gClyMtnzCloXA3vxQMhZppwVbu49xo3eHK/sFpLFkjg2WJpNNKhKfIVzE3cW02J1 /VWWbp49O1c4U4I7y/KvH10QYN9qDHQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YyUrIXOA; spf=none (imf28.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315415; a=rsa-sha256; cv=none; b=8eZAwtIL0oNjoFYt6KOsjzDI7sFy/CbbTzZeemOz3tnBBWTNqZG0WBLb+BowcTG00xP8q1 MRhs4gwhbS0u4wanm14iVtYj54VxdHBeOqY63vToaur1BASdwbpjmc9sFnLWIzhFHCZeQS XmHCLaWbsh4ZaU4M8VYjGrPCJyl4JCo= 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=OgIbgYEwKQKejMeYOKJTDG1ASpjdjHjMo1Pk1taujZE=; b=YyUrIXOAsfXAxFsM0tPFGM9Qan uPkwIWFjNZRqG+oOXH7PQi1PsPlxfQZlifkTyUEDMKFh5+CU+O7VeR8qiAa6/cLTOcnziGg7FrZdN WHQ80UGCfElD1uMeRdK6iygkWMafy6tsanELOlc6CyYNZDI6bKED31apEBgrrT2rM987Itn8e43SG OMUz8tuWcsyJS+AMMKPPnMB2J6IfA8wNUtc2+Tftlwv0i3hg4/L2GodrSJjuU3MnxwrzjDt9YdQRa BIqOMz0e0+Xfnk0MI6bMMTnZ+tb0QSw5yCUbhjzc6aFqMcLNg7zx5IRNiZyuxF1hS2jGP82Mbj/5v r7PgOY5Q==; 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 1pqp5I-00FOy6-1x; Mon, 24 Apr 2023 05:49:57 +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 09/17] fs: factor out a direct_write_fallback helper Date: Mon, 24 Apr 2023 07:49:18 +0200 Message-Id: <20230424054926.26927-10-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 153A4C0004 X-Rspam-User: X-Stat-Signature: d8masu1ors63erqtyejbsi6dqcjj1tw8 X-HE-Tag: 1682315414-482830 X-HE-Meta: U2FsdGVkX18IzJu9scqtF4IIgXudtQqiTUZ1rPiCynLKqbEV2Vc092LYExkpys9cumbzzd/GUl+htweWQX+kEaM94yZVaxjyQFLzrO92zvZrwihDY78D0aBwYyo8TFBxIJrKIwaRNQzPLkzzyrgVFt1J5UvYgEO//NK9l6S/5GEZwgf+q+CBeSYja+XsjMa4inyvEylXeFbceiZBFpe4jobqC9xcipJuOAsxZNT64iTHTnPx35Rxsp+tlC9UBQ9PxtQcHo+x+yLP7TaMnRtrHHyfnQzL+ykV/3W5EbgiHyj4X36AblrSFdhmPnhcN2Zw6rqFQPVPA0o/7kHy1kRldzgYTqDBU6/WP8byogGIMpa1qTyJqhV/uW1p3p8KbLvB8glfmFAE5wodb+brHm1EYN3MxSaquBlkWxJmvpx86G77QobToGs5vRGj9/Yye6FJJ9OwdJRbS8n6mbSAhYLPmbeNQrLLltnKBomwWl+e7DJ4qoIioV88MRbbrFVfqL/19stvMyLOKtDnUTFVU6AEkGdaNRQqUpd0vf4WjRcLUmiF+Pk2ZPlLUB7k/LYOjk94qx2IT0C1VytNFnnMK74VhIRVCxPyHFewNDT6VxT+yY5hvKWqpSvHQ2sZc3QT9r4aQmV/nGdIcyJWBbYfiYzUuy+hlHLjmPmlO4p+4ThMu8QYUWwtKyRr5znZCaQHiQeMpaECHlx5jLa1bSjHl7gOSp3wHTyeGIWON4Uwx5YLIBDR+1/0QR3SjtEEanTGOQYqyHzk2ACllX1eW7ZQSh7mV6HyLJn0L3cPyZRbffWkMrtbbQjwJ9c82SnVTB7rNi3qh1jzyOu+r24rTYx/77eNe/EYo+F+GQ0+0+PEMamz0wGNltIFO/50h1DClgigZhHfTH5DCi6Xzreo6npnehh/x32h0sZiq37V7eDM9UOhpQzMi0iO7C8AMc5hSrxOLcK61HWp8FDIQ5LW+A5wnrQ vsNcgZAs kKu4St5w6R0tKEtSAF3TUsGUwWvfl75Mpsyo61dQAX6/7NeNHPEQ/ZE49vyHMPnVjcvTISehcBYzstYHdlnsV+9EHOeil+tK0XuZakevgCSVejTOZ9UfKr2kzItTrMoKs5Vk8myhU8nqRVtCvBQH+zFH1vNQZLfDDkGf/UAfbQWUvtQzYhsRZOrxNxhPZec6O3P3N0//QZnYPe2yPD8x9iePSOUy/1R2JWmrmhDJk7Lhnf9XguVd7/vPPc6A+B6lP/0ksNjydldWgHklxqzRF007Rz5P+HjD/Qm45Q+ZBuW2+WP+SFmlfmNBX+fP8qlBO7BpWEjJQ81bOdw/q2c0XgVHMj6Cl7tcFmNRxOIWQlZHs7H1QNdYJy6mftx5QJ3RP+X03FIA8WCYEhTYU3gSYBLDEtql5niztTRMX+L8pGohE35MK5QK0L1IRjnL/rXylbq8k3LvqGsEgLRodNKs6dNYYIw== 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: Add a helper dealing with handling the syncing of a buffered write fallback for direct I/O. Signed-off-by: Christoph Hellwig --- fs/libfs.c | 36 ++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/filemap.c | 59 ++++++++++------------------------------------ 3 files changed, 50 insertions(+), 47 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 4eda519c30022f..a530d36e0d1a3d 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1618,3 +1618,39 @@ u64 inode_query_iversion(struct inode *inode) return cur >> I_VERSION_QUERIED_SHIFT; } EXPORT_SYMBOL(inode_query_iversion); + +ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter, + ssize_t direct_written, ssize_t buffered_written) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos, end; + int err; + + /* + * If the buffered write fallback returned an error, we want to return + * the number of bytes which were written by direct I/O, or the error + * code if that was zero. + * + * Note that this differs from normal direct-io semantics, which will + * return -EFOO even if some bytes were written. + */ + if (unlikely(buffered_written < 0)) + return buffered_written; + + /* + * We need to ensure that the page cache pages are written to disk and + * invalidated to preserve the expected O_DIRECT semantics. + */ + end = pos + buffered_written - 1; + err = filemap_write_and_wait_range(mapping, pos, end); + if (err < 0) { + /* + * We don't know how much we wrote, so just return the number of + * bytes which were direct-written + */ + return err; + } + invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, end >> PAGE_SHIFT); + return direct_written + buffered_written; +} +EXPORT_SYMBOL_GPL(direct_write_fallback); diff --git a/include/linux/fs.h b/include/linux/fs.h index b8ca376e606255..337afdb5024dcb 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2719,6 +2719,8 @@ extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *); ssize_t generic_perform_write(struct kiocb *, struct iov_iter *); +ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter, + ssize_t direct_written, ssize_t buffered_written); ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, rwf_t flags); diff --git a/mm/filemap.c b/mm/filemap.c index 8c5196cf93a454..bb769746f78b08 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4009,25 +4009,21 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct address_space *mapping = file->f_mapping; - struct inode *inode = mapping->host; - ssize_t written = 0; - ssize_t err; - ssize_t status; + struct inode *inode = mapping->host; + ssize_t ret; /* We can write back this queue in page reclaim */ current->backing_dev_info = inode_to_bdi(inode); - err = file_remove_privs(file); - if (err) + ret = file_remove_privs(file); + if (ret) goto out; - err = file_update_time(file); - if (err) + ret = file_update_time(file); + if (ret) goto out; if (iocb->ki_flags & IOCB_DIRECT) { - loff_t pos, endbyte; - - written = generic_file_direct_write(iocb, from); + ret = generic_file_direct_write(iocb, from); /* * If the write stopped short of completing, fall back to * buffered writes. Some filesystems do this for writes to @@ -4035,46 +4031,15 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) * not succeed (even if it did, DAX does not handle dirty * page-cache pages correctly). */ - if (written < 0 || !iov_iter_count(from) || IS_DAX(inode)) - goto out; - - pos = iocb->ki_pos; - status = generic_perform_write(iocb, from); - /* - * If generic_perform_write() returned a synchronous error - * then we want to return the number of bytes which were - * direct-written, or the error code if that was zero. Note - * that this differs from normal direct-io semantics, which - * will return -EFOO even if some bytes were written. - */ - if (unlikely(status < 0)) { - err = status; - goto out; - } - /* - * We need to ensure that the page cache pages are written to - * disk and invalidated to preserve the expected O_DIRECT - * semantics. - */ - endbyte = pos + status - 1; - err = filemap_write_and_wait_range(mapping, pos, endbyte); - if (err == 0) { - written += status; - invalidate_mapping_pages(mapping, - pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - } else { - /* - * We don't know how much we wrote, so just return - * the number of bytes which were direct-written - */ - } + if (ret >= 0 && iov_iter_count(from) && !IS_DAX(inode)) + ret = direct_write_fallback(iocb, from, ret, + generic_perform_write(iocb, from)); } else { - written = generic_perform_write(iocb, from); + ret = generic_perform_write(iocb, from); } out: current->backing_dev_info = NULL; - return written ? written : err; + return ret; } EXPORT_SYMBOL(__generic_file_write_iter); From patchwork Mon Apr 24 05:49:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221663 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 83032C7EE23 for ; Mon, 24 Apr 2023 05:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C0A7900002; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 470DE6B0087; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F5946B0085; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0C7DC900003 for ; Mon, 24 Apr 2023 01:50:17 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E00D71A010E for ; Mon, 24 Apr 2023 05:50:16 +0000 (UTC) X-FDA: 80715209232.21.B089954 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id 42FA810000E for ; Mon, 24 Apr 2023 05:50:15 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3lxWVAk+; spf=none (imf14.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315415; 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=pJqF9iLDXxalAZri1sgP4ykwSrvt3ymept2aEtNRU2M=; b=nzmli5yp47OKpkMt/UlO6Ny4XuTN1VGDwrF0Jt1zPSPk6nAZSsD4Q4/KIeUwW2fqGNHh5p RMejjgLGzXqMYXjFRsajGELZnmL7DPLPhYE1Rh3ow44ho026GmwcNLc7NUPfjzPjHaP6iB 6JIm/M6XPtDmFpAGLFD3QlFo3tZ39m8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3lxWVAk+; spf=none (imf14.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315415; a=rsa-sha256; cv=none; b=aVXkjlmBUwo6pTKPStF3mcFKKmZh5JxPL+mCTxOw+2UDilEJnXolAaRsTxJLE3bVqgslOS M0OjAb0dmzw4wlsg6te1soz6cgHm/pfUJm9ilUsu2wssah5HvZ3au8XrR+/X899TpIZ6e7 A4epuSQ4tkezCUDmiub3M6riN5oGqjg= 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=pJqF9iLDXxalAZri1sgP4ykwSrvt3ymept2aEtNRU2M=; b=3lxWVAk+3jZfmQD+hx2GXifc+u 2uElWR6QJNM63DBT0CyBjHyTQty+aqsqVeci/2v+7iILU2eb3upv78/4g048VSlvmDvh2mJYlZYZ6 XOxjp6O39E62ujMQm69yzR/DnVWTniYzJvEiutGiNhDq42IO09RTn0OMm/3Bvn2K6DU3f11ZHTGj3 wO/B5SuQ7cosdpF7UlWJdzPfVB+e8gNIg9bicPczX/NjxixXpg3qMzmuu6NLAkDvHL5b74xtnSdgO ZKCt4iYFs6TuqhKmfkfCVG1sm381O08hFBNFhqmsvf5phswa19FEEeAjjvkIomMjBB57KJt2H9laH ncijNsbQ==; 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 1pqp5L-00FP1c-2M; Mon, 24 Apr 2023 05:50:00 +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 10/17] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Mon, 24 Apr 2023 07:49:19 +0200 Message-Id: <20230424054926.26927-11-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 42FA810000E X-Stat-Signature: m4q9wqsqcmr8bc5fzc7s6794w7xfho6c X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1682315415-684369 X-HE-Meta: U2FsdGVkX1/1EGyAyG4C7CVUakNduFWWm8/U/6y3pQtFUmo2+dVF0TB+WltziH4Mj+GSPDEHVpWZaELDtiwr6T+iwtWT8DlyCPPLgATivetfQIINqaGd2ttsEqdrs9LFzgJeNiCGJai/0D2Uz/8wKoSzZMeMi5F6xmBoaIqQq+icIOvFVJRacrdIy8ywN166Bm4Ui6OOzNYDPUI48yPL6QeaLSAGb+PXaoJYNDpcaY48S7RVPsF7nv0z7SLDjKK8261kj6Tkh7Vgb3oMgK8TiEpwK9AhvuGkdpWkzEmYYnwZXlUFWRGAuaw5cVWW1fMJWMo2C66TYkHrTbxlYhav0O+p16zfAq/Mas45oVethw8rhKJs3oE21d0R0cfmpDTTj+Mc2U58gJOHZSJVMkCmtpcVwwMx75N3jryqwBrW/i8CIoI1cUra5Jw0a53vzpKkUnXSsj/MXX0WNaH5o5BDCoKP4e6Z0EE3GyXyCEErbTWbl4yRxmCiLtbZ8d++drycoZmXsMJttFEP2Qk/qg4X2OB6ZYhCrmsrm1VUC1rd1nF5IJB8onUxTf+KHlPt+evvo1gJYq708q4JXtUNA1IUKVtAoM8iKRGMh/wPgl7+1GGyXGDmk0g7HzA2vXk6whmJPJjPq5DVjn5zTB/xn6xrU+t1O0/5VQ8tDxWuJNyigUOBK0xCZxHcQFJ10OHp8YMNiOpfSJpqaX4iYOvl573T4O0XBM14b1I+9FEB0+YVZW2w1oJ+rOVRGqYnw4oEsMbhrRfYJdrUYWk3zImqUb3H0HVjOt7ixG8Ba50SD2JV8kkrOQJF9vP7SGvZ/AYgR6utXpPtHqp7HH3mejiFsmgGMXBek69EHTvovlTMMG0UqFgswaufXldfzPWtNB3bWO012zCvLCucKBl4bZZOybHKI4znrR4u4d+QgIKKvsYxv11BsrSnUPD5wPU4OJWPZ8H1SVubULE6+8K3xIwHD8k Ec3a6V/L qH2YIkPMeZhEZbK6SSlRq6qu10eBQP+r1kL28u/dKvbrdc4j31+G97igznXQ9hBa7crHAD1p07iBPAGLNXJvWuB8fWLE/PHf3r+OgzKKx/q2p0dcx0WhbmUMUa+UvpbRYt60+c9KmY34oq6q9BL8YeykYJuANQ+7dT5OETLRfQoCk4EvDnViiPjQt2i/TzoeF7zQhHMo6yvvAaHEeYxw7AwZRVacBfK8bvAWEsKwrkzOQAnfmKlchHBkIBVPwXRaedr2eyR8BpIzT8tO6QLLEkF1FoGAMaqucQyKNnIG9N+FMu//4tmPtQFBrcRJHO2Bm37/4oh1HvztA2cGca66yOIf2qJOC9o/4/zS7wqEgu0we4W7ZYRhnDNOxwSC2skfXz79sl7KW/WI0Dm2/E5oZPevXo78TmagG6dZmjApvcdPVQHvGBAkCCCv/4rt3XhQ5X8Km78M/dprRpMOJBgAt9iRz1w== 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 the common helpers for direct I/O page invalidation instead of open coding the logic. This leads to a slight reordering of checks in __iomap_dio_rw to keep the logic straight. Signed-off-by: Christoph Hellwig --- fs/iomap/direct-io.c | 55 ++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 2bf8d684675615..10a790f568afca 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -470,7 +470,6 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before) { - struct address_space *mapping = iocb->ki_filp->f_mapping; struct inode *inode = file_inode(iocb->ki_filp); struct iomap_iter iomi = { .inode = inode, @@ -479,11 +478,11 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, .flags = IOMAP_DIRECT, .private = private, }; - loff_t end = iomi.pos + iomi.len - 1, ret = 0; bool wait_for_completion = is_sync_kiocb(iocb) || (dio_flags & IOMAP_DIO_FORCE_WAIT); struct blk_plug plug; struct iomap_dio *dio; + loff_t ret = 0; if (!iomi.len) return NULL; @@ -505,31 +504,29 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio = NULL; + if (iocb->ki_flags & IOCB_NOWAIT) + iomi.flags |= IOMAP_NOWAIT; + if (iov_iter_rw(iter) == READ) { if (iomi.pos >= dio->i_size) goto out_free_dio; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_needs_writeback(mapping, iomi.pos, - end)) { - ret = -EAGAIN; - goto out_free_dio; - } - iomi.flags |= IOMAP_NOWAIT; - } - if (user_backed_iter(iter)) dio->flags |= IOMAP_DIO_DIRTY; + + ret = kiocb_write_and_wait(iocb, iomi.len); + if (ret) + goto out_free_dio; } else { iomi.flags |= IOMAP_WRITE; dio->flags |= IOMAP_DIO_WRITE; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_has_page(mapping, iomi.pos, end)) { - ret = -EAGAIN; + if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) { + ret = -EAGAIN; + if (iomi.pos >= dio->i_size || + iomi.pos + iomi.len > dio->i_size) goto out_free_dio; - } - iomi.flags |= IOMAP_NOWAIT; + iomi.flags |= IOMAP_OVERWRITE_ONLY; } /* for data sync or sync, we need sync completion processing */ @@ -545,31 +542,19 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (!(iocb->ki_flags & IOCB_SYNC)) dio->flags |= IOMAP_DIO_WRITE_FUA; } - } - - if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) { - ret = -EAGAIN; - if (iomi.pos >= dio->i_size || - iomi.pos + iomi.len > dio->i_size) - goto out_free_dio; - iomi.flags |= IOMAP_OVERWRITE_ONLY; - } - ret = filemap_write_and_wait_range(mapping, iomi.pos, end); - if (ret) - goto out_free_dio; - - if (iov_iter_rw(iter) == WRITE) { /* * Try to invalidate cache pages for the range we are writing. * If this invalidation fails, let the caller fall back to * buffered I/O. */ - if (invalidate_inode_pages2_range(mapping, - iomi.pos >> PAGE_SHIFT, end >> PAGE_SHIFT)) { - trace_iomap_dio_invalidate_fail(inode, iomi.pos, - iomi.len); - ret = -ENOTBLK; + ret = kiocb_invalidate_pages(iocb, iomi.len); + if (ret) { + if (ret != -EAGAIN) { + trace_iomap_dio_invalidate_fail(inode, iomi.pos, + iomi.len); + ret = -ENOTBLK; + } goto out_free_dio; } From patchwork Mon Apr 24 05:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221664 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 CFD30C77B61 for ; Mon, 24 Apr 2023 05:50:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58286900003; Mon, 24 Apr 2023 01:50:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 533886B0085; Mon, 24 Apr 2023 01:50:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D3A16B0087; Mon, 24 Apr 2023 01:50:20 -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 25ED06B0083 for ; Mon, 24 Apr 2023 01:50:20 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E29498012D for ; Mon, 24 Apr 2023 05:50:19 +0000 (UTC) X-FDA: 80715209358.03.178070F Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 414CF1C0004 for ; Mon, 24 Apr 2023 05:50:18 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=mv0e7BU3; spf=none (imf18.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315418; 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=wb6cWzDzgbU80SKdNhmkiB4WmHIQIndA+4skiI8V8fU=; b=N//4pxpVeAqXU2fQvhbAkpT6kKVToSyzh9/GgRSUbIi/iWnruFylEyP73QrBh0OwZtjN+s upX4ul+XsE2QPcZjaVOtE6LqipAwgBmlo0nV05K2B/w2oqNsK4TpeltWQ9hiKeeu2HFov7 PRmWL/neWVg9lyeBlSBTcco/saE6WqU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=mv0e7BU3; spf=none (imf18.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315418; a=rsa-sha256; cv=none; b=gnMOX77i4SdyyNAsx3PEIoahmEuxBRVIEdjl0pSiocaKgaRY1r410wkAEKfQIwAzFNY5A6 vGe67sH/RM0ci5APyl82K4Ps17FQ3U9260V02Qkg2t70rq3llY7gsuL9rO/7xaCx1pIl6t MPzD84N2sVcWSdY2rfsS871NuB4/XvY= 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=wb6cWzDzgbU80SKdNhmkiB4WmHIQIndA+4skiI8V8fU=; b=mv0e7BU3F7SMyd8eLBhwb+Y0F7 znPgpjqXZ4HeAV1eIpqytPq1qlE2Z6ERAC05IsZSk0Xp26INJjUI7B0wTCifLQvtz95fuUly47A60 DWBGBgzkE0tv+pfytsoMZFOSHTsPvNLSWyjGi17l7Yb0x8t1sAlp/JB/Zj5Jyyvy+kUjDkJLePVzX O53Ty6SpZMoCvI5Ssudo/hWbvHKIdGyYrwRfQhwnxxHPP+bP9bKhPGJlFO0HKjlrXEq6I1qQJAGLY nLg834BQ/F7+Z8S4FjwMYtC8lma6QFFFF2rDDnUUh4ekMBmQJzlfQAYNUFafdB3JEbmYIuoTSWGtp WXUoQW8A==; 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 1pqp5O-00FP43-21; Mon, 24 Apr 2023 05:50:03 +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 11/17] iomap: assign current->backing_dev_info in iomap_file_buffered_write Date: Mon, 24 Apr 2023 07:49:20 +0200 Message-Id: <20230424054926.26927-12-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 414CF1C0004 X-Stat-Signature: kchj9ebp7izpezezd4jrq1x7pwzk8t1z X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1682315418-769966 X-HE-Meta: U2FsdGVkX189ZY/Q68a8qafx8HpY7/1b0wL16dZwWW01FxPlUKOAzqPHf9nLH1e+w+WkHdK+WqVAnmSMyMyV6e34d6PJmQUitN0pRpaht6DWDhLuyP0SLUc0kScVAQTMcI/z19oVm/srCVzRABogQ9hbuEsN1UeRMjh5ssAb0j0ZXBuhFVGlfG3Ai0aD+BNGkUxNxyboDVMCLHYT3yMzJDcpCqFKi6I6pyUqcRCPZ3fczaPgvU0Qn5LHeJg8LJsMCw9COnZ7DDM6qChiqBerWy2Ns5w2UZhrbi6+9Id/VnogdNPxiQxr0CVZIynTFuB4Pphans4GClK9raBE4FvqjiloD+6FXS/db6mr/Q2vmGuZEjbCaN0am2E2JeJO2J1LBvbi7jIolFjf+5Ebiy6fl1ZU8lrRvYJVogwKv9kxjO0y9RAF0V0xYpqfugMPFa0gU/ZipvX3IVoecW+G4ksPTS65LQP0wptLA3bhneIQ+NrtVxNoH12VLctWKCxsa4EBarOPKsNVnRMKvGuAVhegDeu1BS3k9he4/PvYnhP0/HHHZ0kOvDJlgZ7FfVzfUwkFIofWV+gZmx9dCAS+MBMl+QIcyQXF9DOhgLCwq5/8/N+LsHZb4rYKK7lAqAinZboZBcCy0DiNMZ3Qyv3uc37hKg93os2J+DWVvWS8dQpIi4NtPOeuthShh6oVZgNH5vFjcdQJgA15xRnf8muW6vyV6KSvHTBk+X3KhfJBM0fdLUf1Ys2SFHgv7TkuxwZ42V2w84yUb72QOl3cuHgXMRsRR8oMYmJ5+2Tb6QKRNErq4R/jm1D/lN/rybMil3f3ouKQCj/8c7uy42Pe1czodL7ZOvUoybuO9HsF4EqhHpoTufwpcsNK+abjll3iwAlP6Tg9FofUB4pIlCGP/ErqPu8J8tdQaQVUEQD3iN2SSSRrtuvRZ3GOmQMr2btGoCOvka6bs6O/01CoZpeKqK8pV1u R9U8hDUW H419JAF3u/iNn+6s+zpdV6grgmaEkVZMCgIeM0x9JihmcYsa04jnX5IcRi/TTeor7fhDyTsqSihnY3JcFIOW8d4j+5Ovo/pHT3UOq8z+K0BwlttPXIgq0blrL0hjY7DFRBdPs6lVHDXVtSbnLXnMSptTUmggScuN6wXB3ijxRCoTMI02lsqrWbthsvMI7HM40r+dIEg17B7SsLETtkgGS8yIAIwJNpArEHUHpGhTz4mE/SXvffNb2OKjsnUi+1gmCU0OKmRjLriYtTfm+DNppDzD+hNgE9vNQGbu3+Evyrgvz5DRF0vRTFY9ypdoKLUZmsTnJk2cVeUh4j9skaaptsjeHndeIafXPjbkYanCPaH/3o+FvKLUkjfbnnX+ycUu4ZsvW5IE+BTL46srlZ+mWfgpTF2LwLRSwJuGyg5kcDBt6EtrLwo3/13NNkSBwNmkQn3y41UKH7UkuHZfBICRCsXtn/Q== 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: Move the assignment to current->backing_dev_info from the callers into iomap_file_buffered_write. Note that zonefs was missing this assignment before. Signed-off-by: Christoph Hellwig --- fs/gfs2/file.c | 3 --- fs/iomap/buffered-io.c | 4 ++++ fs/xfs/xfs_file.c | 5 ----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 8c4fad359ff538..4d88c6080b3e30 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include "gfs2.h" @@ -1041,11 +1040,9 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, goto out_unlock; } - current->backing_dev_info = inode_to_bdi(inode); pagefault_disable(); ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops); pagefault_enable(); - current->backing_dev_info = NULL; if (ret > 0) { iocb->ki_pos += ret; written += ret; diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 2986be63d2bea6..3d5042efda202a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -3,6 +3,7 @@ * Copyright (C) 2010 Red Hat, Inc. * Copyright (C) 2016-2019 Christoph Hellwig. */ +#include #include #include #include @@ -876,8 +877,11 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; + current->backing_dev_info = inode_to_bdi(iter.inode); while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_write_iter(&iter, i); + current->backing_dev_info = NULL; + if (iter.pos == iocb->ki_pos) return ret; return iter.pos - iocb->ki_pos; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 705250f9f90a1b..f5442e689baf15 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -717,9 +716,6 @@ xfs_file_buffered_write( if (ret) goto out; - /* We can write back this queue in page reclaim */ - current->backing_dev_info = inode_to_bdi(inode); - trace_xfs_file_buffered_write(iocb, from); ret = iomap_file_buffered_write(iocb, from, &xfs_buffered_write_iomap_ops); @@ -753,7 +749,6 @@ xfs_file_buffered_write( goto write_retry; } - current->backing_dev_info = NULL; out: if (iolock) xfs_iunlock(ip, iolock); From patchwork Mon Apr 24 05:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221665 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 1A115C7EE21 for ; Mon, 24 Apr 2023 05:50:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C95F280001; Mon, 24 Apr 2023 01:50:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 979206B0085; Mon, 24 Apr 2023 01:50:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A4656B0087; Mon, 24 Apr 2023 01:50:22 -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 67D936B0083 for ; Mon, 24 Apr 2023 01:50:22 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4E45F1A0181 for ; Mon, 24 Apr 2023 05:50:22 +0000 (UTC) X-FDA: 80715209484.21.D7449F8 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id A2462180010 for ; Mon, 24 Apr 2023 05:50:20 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZQNPwJKf; spf=none (imf24.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315420; 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=Y0+yvpTOTD7M6v1Yq6rfSkRSonNSi3NR5WwAu/cW1ss=; b=Q0wl1zc8J84MaCWRVVqAm/ZseFCYaK559GEHJzy563MkI+kjX+WL+T0Nen4yZvscAJOYGr VsUVcw3wJOTaV8/+/U0JJA74QY9sd0pu4PfsrrICnPZsUNuVvSsewRurmS7FX+LkreLgCh q0ADb2wRiiBxSvRzJM/7xvzDPt1hNRg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZQNPwJKf; spf=none (imf24.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315420; a=rsa-sha256; cv=none; b=VkUrRqa/QXl8po5OEkWGMVoDYwHJAIpLlq8qUqC2Y55X/OwzwpsjlIpT3QOi3xITl2MReC eUaF7s9tkRM7iRYgIHGJMVldbWGWB5teb23ZE6drrSy2NDBi+39HwXP/n/oBF/WWpP60H7 fRouPwnZMnqCuz1njB5t81VkTVcuDtg= 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=Y0+yvpTOTD7M6v1Yq6rfSkRSonNSi3NR5WwAu/cW1ss=; b=ZQNPwJKfnD/XoJEl/XtSriZEb/ qPTxNVzmqOnJMzTZ5iTdaf9XqBSw+BBu2uTCUsDMrzAjWPNC6D9SVDVDH6rgShfNoncH7mFyV3luD sxCPuCpJEwm0G0klK3ha3UCo2LmEucN7OYhH/wziwE8/fW14ToiwebLf+FpusKtDu6RpIeIvF8maX xPF4tsipjrrtTTnYVAfuLNG5qQXZUfgRHhaC4tq5yxrW3TuZiBF7KM9G8skbrq2iBZzLJMvdl05I+ 6PwoN1Mz5APQFRqOdoUiJWha+6Ca0DLyuFLok7PIf+C183kOeH+iqnbjhsdqjiAuEjiaZ4+/sXmAv QEucEtcw==; 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 1pqp5R-00FP6k-2n; Mon, 24 Apr 2023 05:50:06 +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 12/17] fuse: use direct_write_fallback Date: Mon, 24 Apr 2023 07:49:21 +0200 Message-Id: <20230424054926.26927-13-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: s573wuhx545xfj6f1c5z4k4mkbshs4yn X-Rspamd-Queue-Id: A2462180010 X-HE-Tag: 1682315420-914077 X-HE-Meta: U2FsdGVkX1+kdNkmw9arZOaC2Re98VuAgJxaVRubmX30MCABBA2xKd+pXHoL2kMLefhyafTZy+JbOTYpVFe5mtdSEx8fmv4bAfwJePYYk8ttMeRLFknhKUDiSuDya9ElhIFBmva0nFskHbs3eTBG3KMgIfq+XOxAKALbtFJJCpKLCfAOGAw4K2X3pj1EizcMtr6ZQV0VwzmBj0FvdTFTVf2wa3pVSEFj1/wWwqSxq1xPMr7RB+3L6DpvmipnKII1i2nQVK53dGuWBcGjnpi0xBFgy/Gbpl0EDL6fq71AMyMT7VOzy+iM+lEO/tqu5Ltp3nJm0BeTXrOrHji7oqk6a9Du/J2432pPE8CMsv+qy4t28S3Fo1ZOYRVEOKcM/6MkiXUy9sCTwnCDXUoPpNPXD7UCLVgUfTHlzE97A3ePNg8Tn7zkORfWc015T6sgyXkXupsjGuHsTmg/i6fy0d2kgJLanW+6gkjIq/CY9BN0EHLDdCECzV/z83wgT5nQX0yJT2WapZGmrWYXxXbA7cpJqo8jtg7xMI1PAxKA6QQ02PXwDOMHSXXMxiGoenQZIRzz6SAsBfcrLwTXYIkhqNSJgt+z7WNUSqXC4cZs8iFPZtFq5sPFL9V4ULqHuCKcxJblSs3reem3OLCDLlxz74qbrzX748qQZe0Bqp/noVWRaxVIJ2jl4XCvaw5gpOaNdyscBEzoQSVI+SYwe/njCE5oUgiDJ6fIrHX9wT8Fvz8+EX21dIlpOTka0zWBkOIk7T3jCsya/HG/3bRO8ywXtAH0jRB0xGn5vu/xJfksjqftO0iZ5l12icN/ssNvh0E+8fLHsxQJT04nNbLEXeyo8vpDOlp77unFKvik5iDSNfNeBeBIHLeqga59GZAnqekS6OR9tBSFHdYnENlZM+w7nlOneUD4KNzL5716j185WOUlr3z0jUf5U304U/eO+o+SzwHKWV2ZoJHnHFeRN5IWSTn 1go5V+16 fKoKqjLUv7PkaqnOuCJ9XCh2bjVDXfZBZLipWshlQ3tvpTDo/y7U3oVhPi73X6XxyEOhDxw6Zj9LbAWRkzTq6xpHmlPIt8KF7vbl7hHqqRQTXIhjBvabiFePKzLVY6tRQOauhWKqpObiG729rCooaLBcJrepxy+RLSw3919ioDMgFGle5exj7sho6rb0RbbQKYGjOkNPR6VHTCdoZmYCQCqnhMP/zukDWQE0j5FR4EQokR38JZypj2zkmFmfin68FCLRrCgHQcxSRLLNxjaKcnZs17DSjIa+qyv9t9rJNe9DtvmXx/Wx1CMBARa28S5D/AWMMmFtwgpuBqourNovxkvTdBsS7L/UlDNfwTtYB+GCqDqQpspo7PiMDhNKMXkXHisJstKf0SJ6kOWJo5p4M2OcxfO+uRovjwK9TZk8B4yGfhiXJ+kJhNCc/z3NAOUFm+MCze+QCCVqUVdCYjF7U2UjPiQ== 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: Refator the fuse direct write code so that the fuse_perform_write callig convention is simplified to match generic_perform_write and it's updating ki_pos directly, and the generic direct_write_fallback helper is used to consolidate buffered I/O fallback code. Signed-off-by: Christoph Hellwig --- fs/fuse/file.c | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index de37a3a06a7169..55b64dac175d68 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1280,13 +1280,13 @@ static inline unsigned int fuse_wr_pages(loff_t pos, size_t len, max_pages); } -static ssize_t fuse_perform_write(struct kiocb *iocb, - struct address_space *mapping, - struct iov_iter *ii, loff_t pos) +static ssize_t fuse_perform_write(struct kiocb *iocb, struct iov_iter *ii) { + struct address_space *mapping = iocb->ki_filp->f_mapping; struct inode *inode = mapping->host; struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_inode *fi = get_fuse_inode(inode); + loff_t pos = iocb->ki_pos; int err = 0; ssize_t res = 0; @@ -1329,7 +1329,10 @@ static ssize_t fuse_perform_write(struct kiocb *iocb, fuse_write_update_attr(inode, pos, res); clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); - return res > 0 ? res : err; + if (!res) + return err; + iocb->ki_pos += res; + return res; } static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) @@ -1337,11 +1340,9 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) struct file *file = iocb->ki_filp; struct address_space *mapping = file->f_mapping; ssize_t written = 0; - ssize_t written_buffered = 0; struct inode *inode = mapping->host; ssize_t err; struct fuse_conn *fc = get_fuse_conn(inode); - loff_t endbyte = 0; if (fc->writeback_cache) { /* Update size (EOF optimization) and mode (SUID clearing) */ @@ -1378,35 +1379,12 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) goto out; if (iocb->ki_flags & IOCB_DIRECT) { - loff_t pos = iocb->ki_pos; written = generic_file_direct_write(iocb, from); - if (written < 0 || !iov_iter_count(from)) - goto out; - - pos += written; - - written_buffered = fuse_perform_write(iocb, mapping, from, pos); - if (written_buffered < 0) { - err = written_buffered; - goto out; - } - endbyte = pos + written_buffered - 1; - - err = filemap_write_and_wait_range(file->f_mapping, pos, - endbyte); - if (err) - goto out; - - invalidate_mapping_pages(file->f_mapping, - pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - - written += written_buffered; - iocb->ki_pos = pos + written_buffered; + if (written >= 0 && iov_iter_count(from)) + written = direct_write_fallback(iocb, from, written, + fuse_perform_write(iocb, from)); } else { - written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); - if (written >= 0) - iocb->ki_pos += written; + written = fuse_perform_write(iocb, from); } out: current->backing_dev_info = NULL; From patchwork Mon Apr 24 05:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221666 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 8F454C77B73 for ; Mon, 24 Apr 2023 05:50:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02E966B0083; Mon, 24 Apr 2023 01:50:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F22EC6B0085; Mon, 24 Apr 2023 01:50:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D98106B0087; Mon, 24 Apr 2023 01:50:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CA4CA6B0083 for ; Mon, 24 Apr 2023 01:50:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9FBB58016B for ; Mon, 24 Apr 2023 05:50:24 +0000 (UTC) X-FDA: 80715209568.12.495F2A7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id E068B40008 for ; Mon, 24 Apr 2023 05:50:22 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4lxlR6Bu; spf=none (imf11.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315422; 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=FmYSiKdP5y3EH7nBXTpf8bIFKknqbI4piiyOLlTcqUc=; b=NEuyvY/wzCC0Fdt5sQzgDq9utx/uSOoONKC3UFYlUmNYUHW50VHiMlECHQIUeLbuA6EV7p V0TsIRfd+F15x1dJkQ9btfeicrKuaVdZQfHIrdULKLb4bTGc0dQViIQtQy9h52tjRGsU7x 312Di/hxHJ8C9s22ifgO4xMSXIgthZA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4lxlR6Bu; spf=none (imf11.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315422; a=rsa-sha256; cv=none; b=5YHFnyVuuWtQm7v6c7pD2vv7GuJH+wPWpK+aDOaCM5wArV+xNhrqtMAp5x/sy4He8ipFyp ooKFFR1GHvKpHkgKSsbzSX9tKjMkpqHxuX9BKsPJStDbHKSwQljjSLJcQkbnGdnmhz4zaa kbRWpoKMvvrd3RFtaDAL03SmhazofHQ= 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=FmYSiKdP5y3EH7nBXTpf8bIFKknqbI4piiyOLlTcqUc=; b=4lxlR6BuJRIME1qgT/FLWEjLGd zZ93UA0UiVTZRciYnVz7BcBGh4qOlXvmDz+gYSX0gVpNssgkTRzVJ1F6XLACSvE58gCznare4IwV8 ONhbJNRO+Rb7AwP4E4aB6azTfv6WnFdtXg9Bd7cQuw7++D8vMUNKfCzGFlYk6+3rORK1s3nJno0oL 32gJ5Q9kRf7XT69Y0ns9Rw6WyLZWY36yGHyPSBD2vfFBjEti+pSoqjjyDRWgXT9qasHTXvq32XIhk aJhmCTOwekv9gG2uQmpUAPoElchnnj2w2DJgfRMI4gQ/+nTFeSLo60MajiM9lIGCzDORORrebRpsQ vbf3q+Zg==; 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 1pqp5U-00FP8b-21; Mon, 24 Apr 2023 05:50:09 +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 13/17] block: don't plug in blkdev_write_iter Date: Mon, 24 Apr 2023 07:49:22 +0200 Message-Id: <20230424054926.26927-14-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E068B40008 X-Stat-Signature: 3itdhnfrkgmyrzxc93zw4u6d57ttqxbw X-Rspam-User: X-HE-Tag: 1682315422-650157 X-HE-Meta: U2FsdGVkX18UIkZs/E4BbSVEFhHjZVn2ew5MJo6hw2xVtc4trz40pQA6E5kUwpuq/zgpUrBWoSq7YQHD9N2ZPWzL80lfQP5bmaS/+Kvf8HI6WGQplkhCA1oslwK9WvBAox17fDwamHn37DAWeAo0fzNuYRnnp9JIS4lkboakuoneXOmXR+1XN1W9E7n+u4ahey4XMSd+H3m0KV5ODDkrSgenMG8qal/3xJzLeuuQRzS87wpmDjBELeuR244VzJThHUpe429DqPZQjtN+5Lh0Ionc2NbTcWOktW6Lzz6c9HnrvztHWbr/hR7hrVLuQ+r/v6MiAJ4Sdsugj9ULlt2T4PetqxlVI0iBAqEF1E1Y+/VVaSnBalj2033A1kApwfDga/wFZPs/XFcP4HTLk3HUYIGShE3EJVtJ+BfieYU/meMkUgEUvvR1RfICYkHp0f3vbgNkpMqPpe2vk8zxfjYNvK9or6xc/lLpl6CSydotJDJu8kNVlNq+PZrtNdoAkQTuSD545ryn7wXeIvzSVva380n2DD5VWDrhlsNnqqQHiXEOO/PclSjGef5+S4eaTRy27me7ADcBZ/49LSSezx/KxRBNtBF9m/uAtiMTDBckczAB2RA0GjouL3WU/aNURFXYCWpSovKRXYFBVgohFJqbSngQSNZLWXnNVhOJg1UPq6rpFDGPAzxt74zjiApdFTZBaWFKL7XweTs7ZjWF/BlJkTyQ5S1DToH1CTvZFwlqaT9GdX2JQMyEC1Z7fYdl6MEkX91l+7CUV9B5JHsZrZZzLViwQWxoKC9kMw226mpbf5mT60OfqlzzZAU4oJzRt88E7CpXdJeRT5l5Ydmyf+FRmVtPoknAYU0vPOC1EZCWaUzM3BvyRgukBy12wUOxUwMV0/TT9/dNTHfaYMitAdNCqw4wva6wL6otLg6k1qKJv571hX51Gn4ZkM7jq3+pIXYSZJeKnmEniriQAAV0cdq il7YM6bJ HLuwRdc1/ZmICBOYGILagzuOhJFNEQbjnMC4DCiC6otoqLqU9NzlxREKknPtkd3N8TM+L2ZQz6eSVB2Q85rDAYfpVfHZGWguU503/z0vQzwdvB8SH3qspujggnsg93dsH2nVRqFk3cSJFpPUBqHU7ggWG2pdG3yiS+jkV40BzKadJsjGHEfqyD6Mf8Npj/m330BlPoTTpDAs6KZ1V5gz5Wq9PenIj0iWy6ECzhOLvLhHASbM5LX8xZJKYFNNzFGC3Ni0rn34j/TXssZZzB2P98fEOceealvC8X/8+oekIi6VrXDeIhHb3D5Q8BZh9qFYaScxMW61/9N55dtmH38dz2F78S8WPfRFP11WB8RUTsMy4gE7udnj33lie5r0R5sLGw6HIROIUborrWfJlIcdQi3iRNClgZxMEpPLCZQw7kPPpPkd+p51DP/6qr5C578NtEubzjam/chTNfSE= 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: Remove the no needed plug in blkdev_write_iter. For direct I/O that issues more than a single I/O, the plug is already done in __blkdev_direct_IO, and for synchronous buffered writes, the plug is done in writeback_inodes_wb / wb_writeback, while for the other cases a plug doesn't make sense. Signed-off-by: Christoph Hellwig --- block/fops.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/block/fops.c b/block/fops.c index c194939b851cfb..b670aa7c5bb745 100644 --- a/block/fops.c +++ b/block/fops.c @@ -520,7 +520,6 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) struct block_device *bdev = iocb->ki_filp->private_data; struct inode *bd_inode = bdev->bd_inode; loff_t size = bdev_nr_bytes(bdev); - struct blk_plug plug; size_t shorted = 0; ssize_t ret; @@ -545,12 +544,10 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) iov_iter_truncate(from, size); } - blk_start_plug(&plug); ret = __generic_file_write_iter(iocb, from); if (ret > 0) ret = generic_write_sync(iocb, ret); iov_iter_reexpand(from, iov_iter_count(from) + shorted); - blk_finish_plug(&plug); return ret; } From patchwork Mon Apr 24 05:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221667 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 5651AC7618E for ; Mon, 24 Apr 2023 05:50:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAA9B280002; Mon, 24 Apr 2023 01:50:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5A266B0087; Mon, 24 Apr 2023 01:50:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2299280002; Mon, 24 Apr 2023 01:50:31 -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 C1CDD6B0085 for ; Mon, 24 Apr 2023 01:50:31 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9B829C0178 for ; Mon, 24 Apr 2023 05:50:31 +0000 (UTC) X-FDA: 80715209862.19.4449B7C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id F20DC20005 for ; Mon, 24 Apr 2023 05:50:29 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UoeSfGuo; spf=none (imf13.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315430; 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=sTswUsG7V37q4lilbMJoCzI78FMLYPHsnKSU4tW14rI=; b=rt4JaKjEipT9pkNQ8TP4y1LdDN58zkBtd50a3FKpWxt0GjeC1vWcqteLyiw3VNcFSkTkcn 4CL3J63NJXFN0TTlCNPsWje3K0K2p5Cm5g1swRJvT5a43BfK1cnBDnvAjCbprYsZFbIVR6 wolCc1w6PH7g8WR45gNrqCLv8tZpY9E= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UoeSfGuo; spf=none (imf13.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315430; a=rsa-sha256; cv=none; b=2a5lCVIjHNu4yWYMyx/V02ng0PxInQpaF6963FgWFdS7qGOlblmaCJVdIpGLUHGzFEtjPT viBMIK8C7SQ1lLvJCAsrl88/3NJNG3Fri4Ku9e7RSk75EIUelKu30ZMA/yiFTAKSPXwKcz 7+KaJ8eRNB/sckiOWuV9BALdu2gOkSo= 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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F20DC20005 X-Stat-Signature: in1net9ik31efagqoq5ggumg5bnkxxyf X-HE-Tag: 1682315429-953115 X-HE-Meta: U2FsdGVkX1+niMSNIaj1nVBqLbxt6Q5N9AnnQL6LZyJMxSp3zkLrb77gGHy/8mrkwxh/61vByHG0EgYiUEDLTXCEWkeq1otndMsU2tUq0TpbCxQgbvmiq2xzS3pRATgPYeQk/SLNoe/eQ0SeYhBzGoLPgDy7PvJl4ANGbHbwbgfjRIvBMsaRxbUjf0BL0/llbxMgxIsHGtUD6ZxrDm3Axc++B9EGIYvn1jiEQ5HyK+2iyw/rP7OwHCagynJ8DUAzv1L+QU3FzIO+AN3H6ZKr+sREOUwYZqV4X1/q0L369LqQKP5QhP6i/ox5g+/V3SkMJa8nfGCLz8S9aOWe7R2W0z74gykDyjdn0VGjvegqf1ZnOVwlsPvNnErWRzGm/ZGDnz6+4iznACQ9tYla4puY1N9KSkHAhKgbT9FfPRro8de/S8eEvTlIOuNBpF3rjDrivUFx0gEfmJYHOi/GR587Us+0CwpR74kx+CJrcP98D7u2bsIx4M3m3q4uK59NMwNIMXtvycEFWyq0nXmZz2QZpCXqLlcXIZKkXnwlyCiP1haEj10RS0zpjRBQIeFePi9plsOeV/WmtnUm05OcjWio7XvOPD9d1YfZiXoPGip2Rps46nbemA5WxDvJPCyYf2N2I0Woi/yHDuxgDzRSwj8vL88KTX35auSVYKCekXWNGkKy/aIEx9SS8JkhLYjcqhVxM/N8tJqFajH4lLE58GPHrXdUUH1goKg8iKzFuEC+xN+YGm0RM3A6qN8eP65CnewMDxhfgi3+97E0KDEhtemU9OaN5IqSckz26USEy0Qhm/rYxrg8W0XwXL9JD2tDO2DJUx9e5XJc7tSXk6v+6KjO13cLfrkfyU4Fwcp95l2wGjOZ5KYS0pREwb4E3aYGgyLRViD3NndKZLIq8DbBUh4SM2ZMPJAIZe30vGmWA1fyQfilU4i6VonBpcbHyAJqfx1kQe6hO+EI15O5+G65ylj jQPLvvZS Dy4G87GrWrtL3CR89udhl6WLIGv5KDlz7T+47Rd5fUXG7/Yb5DPpBvw6uYoGooTH7Qo/5IXnxtnY3wife8LiQ92gH8ByANZv53ZlGMyCfscx0OYm3Nv3UMmPeFKSC3NCc7j1VP3edivFsPRoA02TPDmem18y20yZICzhwlbDSKHnXjhgHlwFhHYRrv1sbuRDtTeTJDEst2VmRI0jOzqFfQiF4GXJOh8PJaTf7zrLf5k9G1kTS/xivlEpwSiSJNOGcVA5OdWfHU/EVZ3IJjk0pvAcnYdxmx9B3UDTAx19iMngI6Y08DLbQsmDoaEy/tD84RLHHfFra9QO5BxDLsYfILZgtWceVDSNbzoT6cSSxyhgKwycUVmIwgNPYGXMxWnTfdg3R2uHbRzL8DNQmxUzu0C9YQqBYCLAe//g1/eUoLd3b0C7Bvp2UKJo1iO2awK71M4OFaqPVBG2tmNJ1W3FENVoHvkUKX1LnK4msTIjzYtBqUcE= 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 --- 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); From patchwork Mon Apr 24 05:49:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221669 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 75D1FC77B73 for ; Mon, 24 Apr 2023 05:50:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1156F6B0087; Mon, 24 Apr 2023 01:50:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C7376B0089; Mon, 24 Apr 2023 01:50:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA8B26B008A; Mon, 24 Apr 2023 01:50:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DB0936B0087 for ; Mon, 24 Apr 2023 01:50:35 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BAD1740135 for ; Mon, 24 Apr 2023 05:50:35 +0000 (UTC) X-FDA: 80715210030.02.AF91104 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf25.hostedemail.com (Postfix) with ESMTP id 283ACA0012 for ; Mon, 24 Apr 2023 05:50:33 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wpOqw6Fz; spf=none (imf25.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315434; 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=ygZamnLPppSKQbVI2TYtcZ1SuuieTgm7wFWt/6s68PI=; b=MBxQIcuvV5xtr+/P3JTI/iYQcMHKsMKM84grg8ChqTay29SOM0BugEwd3Ql5xANrCGQJj6 3NF3q7oBPLxDGjie3da+SIPH0hFVnauNeFrVP5kMcto3v6VXQ6qsPRSZKUZR6mKqddgAYq PhJL8VY7g6y7joo9NE0f+CXlsZklw2w= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wpOqw6Fz; spf=none (imf25.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315434; a=rsa-sha256; cv=none; b=4SW4+NnAapbDhHlmT5E0DMfpvltHTw3JjK3LeFiXMubFmRcVP48bG9/Hga8XZsfPHtbo/3 Xu6swy/uIlRY+VL/duTEcQL++R9nfAhQlHndSlZDiMx/iL83nkvBhsZw9fni0GBjhAcQLK J9/D8V9HPCyxiV583eHN768SOf6Wcxc= 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=ygZamnLPppSKQbVI2TYtcZ1SuuieTgm7wFWt/6s68PI=; b=wpOqw6FzWnc2w4juTchLC7VO9t ir9ELtuxBb0jOKnL07jIkpyJF+L1nWBSzPVGIhqVdKTgVpv8nsOhz6XqjGvbC4V9beDfWCniIGswt O9bKd9P+QqRipzQOTI8TmgW/aUC2QEQw/GLLlogXyX29WSz+zFQVPjQfpsqKsOQNqIIlcpMnx4i9l eK8Ns7AAgVVLldGZlqGnxg0NNJ4YeF6tqzIBhBzJQw7Kon0F3ruc0VhAPDYUTJO+38G7SJ6XlYNkX v0ncA0oNgduUMDrajW3dXaIsa/P7DAZvC/IznI7HvWu6OsI4XjPKJ/KK+z4OqYXElqnES62wVc7FU cqsVOn2Q==; 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 1pqp5b-00FPB8-1e; Mon, 24 Apr 2023 05:50:16 +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 15/17] block: stop setting ->direct_IO Date: Mon, 24 Apr 2023 07:49:24 +0200 Message-Id: <20230424054926.26927-16-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Stat-Signature: jhsskgm4mkrpbh4cj6zxf97ir44mnid3 X-Rspam-User: X-Rspamd-Queue-Id: 283ACA0012 X-Rspamd-Server: rspam06 X-HE-Tag: 1682315433-642574 X-HE-Meta: U2FsdGVkX1+qWRIDG+eO8rYlzDOgoxxFxXaZF54EZLi4bfx0beL/ZxV/AFQAssocLr96+3PF3VKk0DGrRih2+Kou0w3SNwNSHUdVv5s1Ic2g/Te+329sBjyjjnfiqljjFo7EDXfXbv6Bs6MVHpnabHs5GMnNoWvvM9DmGo/MT+4RAkFyWl5oRbVsJr0apfpuQw0zKSyhahuKY8Y0pDJXjwUh3Q8HO7caftUhIK3Nvi9DnAPy7SF5/1FztB1hNS2lp0kuCANHTwzsIDkUGw/rmMwI8K16JqE7FGpesLMB4WOLbYsbDbv5vHp3DtoKUvfzfr+oWC6BeYwW5Wgy7FLuFdrK0Dyne53bESV97ayj22zlxWHOzzBCpd+hxddaFK3GbfSVIqILiFtY0JGWiaaxDbDm4Mi1D+KaJXAqOsJvs4P2+uITRjls32LecmuLLWIVf8qhVdS6MVBL0SJGwz3e1ySMDp9Rk+JUFhAGurFqVlDwuO8Exa+TzaaP1/klCdIM+jkEypJn9iZpBgyj/SzfARRGNH2jQBq+VZJeUqrYAt3H+VD6Se+soZL+u28O60+OILSE6Gv5uufu7JR+4sopRJlCF8iCKhNqC5+Y90O8+g0i2vVvEEprDztbUMvorIP9Es5Ccz7my3hdWj8+QgJ4itIZcNTzWdYe7boIBBTTGD7aiQ3fyCRIf/XLe/R+mcORuJ27OTsIp3/crR5+wabbfEYrPSRcUQYdfWWa7Z6vF/XkavajLv7cjJLDo+7y5UQbkSdZIH+SzONB/yDi/dhgGoLeviBFXzRrol3u55FGyl0xSfm+mzYJ35/xdiF0O+4IkmTFzwcWimU8HfsZDFRvcN+nAkC96A56jFm10Nnm/oWKcKj6IuAO1u0D17cjAh69fZLZDrbPlXyJqFJksmTUZx0dnKeSmsXONvOmWmROVGe4kszz7OuXYBAnQf9sdWc27tMJM3VtTyCtHUzBN6M zj0RTs4B H9pzGAfhVyfHdaajmAv+MdLp96p6Xc+VgcgAVKIKc1sreJK3+mIeO3hI1tKuOamebM2B1LgwVNcSHIi2Ejboz2QvxB+Emlbd94SaHb+0VDgHEDk2DZvEDdB+GW71EJ75flp8vhW9YmEvyOwEKnZFxoGrZd7hBDjPdwkrAh4F9VFmydkdGaeTkAxslRJE0YkBFyHqakV7Ywq9GODom6lQY9GjmpN7dkpXZzRFcYdaTO8O7vaE591991MXnD29cQAnjUVw6wGo0RnrT4LsKuDzlyZf/99NkFJy/flzJUSTtdYFNt/YTo32gq0DPltnLzAL9zGPYgSegAorLpCeT5ginPq1kiBCxXPDlfOXqTYufZjJj39sdNtgdIv/Oho39LOQXQjiSpiq79x+f5KLaKLV/b2Fid/u+SjcnKDXqn3T24AQhJS+h/67LpCtNeX+BxlmTG3zrZp1YPOWaqLk= 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: Direct I/O on block devices now nevers goes through aops->direct_IO. Stop setting it and set the FMODE_CAN_ODIRECT in ->open instead. Signed-off-by: Christoph Hellwig --- block/fops.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/fops.c b/block/fops.c index fd510b6142bd57..318247832a7bcf 100644 --- a/block/fops.c +++ b/block/fops.c @@ -428,7 +428,6 @@ const struct address_space_operations def_blk_aops = { .writepage = blkdev_writepage, .write_begin = blkdev_write_begin, .write_end = blkdev_write_end, - .direct_IO = blkdev_direct_IO, .migrate_folio = buffer_migrate_folio_norefs, .is_dirty_writeback = buffer_check_dirty_writeback, }; @@ -481,7 +480,7 @@ static int blkdev_open(struct inode *inode, struct file *filp) * during an unstable branch. */ filp->f_flags |= O_LARGEFILE; - filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC; + filp->f_mode |= FMODE_CAN_ODIRECT | FMODE_NOWAIT | FMODE_BUF_RASYNC; if (filp->f_flags & O_NDELAY) filp->f_mode |= FMODE_NDELAY; From patchwork Mon Apr 24 05:49:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221668 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 27303C7618E for ; Mon, 24 Apr 2023 05:50:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B79576B0085; Mon, 24 Apr 2023 01:50:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B26226B0087; Mon, 24 Apr 2023 01:50:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EF606B0088; Mon, 24 Apr 2023 01:50:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 908876B0085 for ; Mon, 24 Apr 2023 01:50:34 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 70B1C1A010E for ; Mon, 24 Apr 2023 05:50:34 +0000 (UTC) X-FDA: 80715209988.06.42B769A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf19.hostedemail.com (Postfix) with ESMTP id D95F31A0003 for ; Mon, 24 Apr 2023 05:50:32 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=eaGzgbZa; spf=none (imf19.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315432; 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=DeEMnLNut18pjb9zsoS5o5eSPuPyLSQ1uVXA5zuWlvs=; b=Up/W80/XGBsYxYknb2n/UXRP4orMJklnfO7YoIwIbS1HbFBybkGC/5O73rF9GVCJatEBrv eGx3Jz1dC2iCPP6T6f/izk4DbjwBlSktCHsAQ2Q+mbymMkaWw6my5MLI/Iy8yB4CHoc56/ PUsmrlaMEnHoQk9iEWCbP6+HPkzg6ig= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=eaGzgbZa; spf=none (imf19.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315432; a=rsa-sha256; cv=none; b=eSY1IY8Xa4yB+02uSC2UEhNg0zSR+fWeMbciCyWyGDUfw9VQRwGM36ttjLGifH0MFTX/KC 9VKKi/0b4xHhCqbSoHrgTk18bk6FikDbgEfIETqpGUpXRAzdMb51IC6LR97KLu45qMI4Dn O3t/LgkpTbqWPB8WohXgvesCv/FeCMw= 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=DeEMnLNut18pjb9zsoS5o5eSPuPyLSQ1uVXA5zuWlvs=; b=eaGzgbZaXKx1KyoFV6zGe9nYHJ ZwankVTk2pK/HLEjyW9HXQbEvrT6olrOT1KuAt81GdNbakAo0iy44P4Damhh264EH/+JUBMVsDYUM /kugXtMO6Gv9hObKPdcxPihekCau7Ms1S+MMRj+dlBau86GBhMGLzLMEMWBDJjhuLS9zMvKps3MPN MHHySMYe2QhwxmEt9zHbO8D812jGdIzNJbIexnk/RGuGbtYWA/Htqd9xtyVpBl2gYuBEHgvrzgeQe VeoXtT8G1+qTJKrcrVDwi79thfMJRDrNOMiZDFn8W6VhlJiNx0v1TuyWCgTI6FGUeXrqgZWtaCrV4 p1Am25Kg==; 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 1pqp5e-00FPC9-1d; Mon, 24 Apr 2023 05:50:18 +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 16/17] block: use iomap for writes to block devices Date: Mon, 24 Apr 2023 07:49:25 +0200 Message-Id: <20230424054926.26927-17-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Stat-Signature: fozkmfxk4ijz13ead3q664t7dh9khux6 X-Rspam-User: X-Rspamd-Queue-Id: D95F31A0003 X-Rspamd-Server: rspam06 X-HE-Tag: 1682315432-612737 X-HE-Meta: U2FsdGVkX18a2jCNBBdB3WyoE1DiPP3Sb4KIt7p5PJIUBsl/98QlhKNbyOFVJPPlAeVuUj6/HeMXetMuVQ1YTKSxLTEZ3bD3iBFedvJTHJi8PmOX7hXQF3Wgh+ni2TwpPiiNXOOc+vdH8flJF1YzcGmvD39VpADlyR30fvFd2mFBjHUlqbOS4tE1ZADwxiCAvl8GpaCRRRrnd323Y3jcWvvqMJWXTvYcvHndQuV0fQUTL0D1GpvTEKtVHIenlJgkqr1m6ZH9JZOYtH6pIeLX9EYLP99xK1aNG5iYQnatmrIAm3VuHev7HFo3yGJU576jXFJqlUfclH1N8/hj0G/pcsAZ4ceJeWO970VNezjVLydQqyJCaPMZtxJoccCuf2QQwboKWaXNSGOgKUmEXkpIR5V3n44Wxnxlc6E3YatwpxrP1Sk4341WSD48xlFzl6UP7bOQb9qjZH7zxjfuq1Q/BkOevH7fjeJoKtzb7e/LtGTbWEf1jaTL7Eidjsiw/570GUfvc7LoGCP91zAM69XdIMH6ITqfsDovCpgWmB+2AlTeQX1ARqLmw4+69HEddCcdB0sNFA3bU4CpafRJWfgSaoq/FofAkLgG7YsErLsdUC3ZmHGTa9QjDb5zKZnbAvrlOonvM7k/uwDs0ho69cK0bZxVZHxeoTo/63G6+v2c/kDvS1sUw5KObSf5iI0d8qtJ/ljnDtCD1NfW44ZUGiCOIG2RWjtuPrLr6UP7TdcvAcMGiwrfiq4luzO8uCHPNTirJX17g7cS8I3sedM7ZGka3W+nFMns95FdEk69wB65ZyD+1Gf/IiKh2QE/LUufEryLb0aonM+tZNi85/9ara5x+M5vw8vk7adUEDz4RG3WPq/bGxCR8bJaFs07eBylXcoD/J9yEeaPWpk91zBkYe7y3V08ZvHocmzhVyVxJ8ZnP36vxrpawnf1/VyrA9UMT4xRSFqGlzAFG2BMLv6ZR2Z I8okJx14 v3FEyTzdiIU35a8KZ3XArZrctPoeRoEXLfy2Ag0iBRyL76XD/+/kcdGrCAssXWvpocsyYec52qn9sVToW/tYaiHekPnj2ffVNXUNqjsN4Sjfkb7zzB4gpwuLYViw7FQQczqZ09CVHj51OQXoqum0WTJujSs7ZdDLXcpEBbM5VEu8YEh/TG6tlnADPVxqf/8KYORBnSvBIsvPtwdats1vxv9CUFcOZqo3RiCmDmfRth2Bq23AmYPgwO/uxAKihZa/+YN+KXceb5CLZITQsERPsRx/6u77yuomXgF5XDEnFn/iouJezzpRC3eYHfS/9gag/oubX29o02EsOtoHkWt6v9RLev2S2SX17dVmz9Bc5Diuz0JrvMjJZ+Tja+V3PJabK0gksquPJFd3Ym/Fa1WnFijTinMD9zz5U79hq 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 --- block/Kconfig | 1 + block/fops.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/block/Kconfig b/block/Kconfig index 941b2dca70db73..672b08f0096ab4 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -5,6 +5,7 @@ menuconfig BLOCK bool "Enable the block layer" if EXPERT default y + select IOMAP select SBITMAP help Provide block layer support for the kernel. diff --git a/block/fops.c b/block/fops.c index 318247832a7bcf..7910636f8df33b 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); @@ -530,6 +552,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. @@ -575,16 +602,14 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) iov_iter_truncate(from, size); } - 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)); + blkdev_buffered_write(iocb, from)); } else { - ret = generic_perform_write(iocb, from); + ret = blkdev_buffered_write(iocb, from); } - current->backing_dev_info = NULL; if (ret > 0) ret = generic_write_sync(iocb, ret); From patchwork Mon Apr 24 05:49:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13221670 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 16353C7618E for ; Mon, 24 Apr 2023 05:50:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB206280003; Mon, 24 Apr 2023 01:50:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A64016B008C; Mon, 24 Apr 2023 01:50:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90321280003; Mon, 24 Apr 2023 01:50:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7B6CD6B008A for ; Mon, 24 Apr 2023 01:50:42 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5971F1A010E for ; Mon, 24 Apr 2023 05:50:42 +0000 (UTC) X-FDA: 80715210324.28.22DB7C7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id 883A1A000B for ; Mon, 24 Apr 2023 05:50:40 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=svYyaAsp; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+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=1682315440; 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=ZxrNtpoBTvtP7plF9L87gD1yTRTHFh9iF/vNVL4siZQ=; b=2gGNydzo5bjz2X+kFLDHLPLEDlOlLAtLP99zyU2HCZRbJrsCwM98N0lDvAOgddsDXzMHnJ 4h6tJWP2tJcoe1fLxfFBIGw6zAsWrh2V6dTEpH8ukh0u3ND63KeqM68pd8rtDYjgCWQuhR r4dX7eDOgUHjFsHC2uUfcr+479W2wMM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=svYyaAsp; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+e16e2fc4419b117693a1+7183+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682315440; a=rsa-sha256; cv=none; b=IniMnUJ/hBApRRO3U0dhvHo1PId1XfbZ6MDEw9ufnMqrq3LmMwFWN/cyvV6yUHvV5yUzRQ UGCTTkPlVHFaj6PECS40f0pwReWC7jZZm+nI9dChtNgz/YtVbhA/uLDZcwEUCzCdo+r985 QT1AlKsCfrhQFhTHgN9EDgNU+XPcuhw= 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=ZxrNtpoBTvtP7plF9L87gD1yTRTHFh9iF/vNVL4siZQ=; b=svYyaAsphxiqnP9jqAOpBkttbR N4Ce8N0Ipc/1VxOyM21RB2j/4GE46fi7rPsZ/z1UMNlV0FENWCFo4TFofunTPQab63OS+vC8+0r4z hNJjpAId1J1jbvucbaAE6fV27/R4fhpVu5H1IriwlKdIaxd8UWY0fze6AeJoC5Wux4wA6DOdBfJV/ 9QBAIqYsEHvTTGlu3tsn7/reirVjk9O5IcYBT4D3udLtU/4kwAjJc3xmhDgsmL5rDcCgwN2uJGzDG KQwVXSDnqxUa58BQqn6skOJxcFlaZ/v1U7wXLo1TLgUnW2kFsMlx1Z5MV0IO7GbI68rB6QW8Dmxth S+MAaziw==; 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 1pqp5h-00FPEY-0T; Mon, 24 Apr 2023 05:50:21 +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 17/17] fs: add CONFIG_BUFFER_HEAD Date: Mon, 24 Apr 2023 07:49:26 +0200 Message-Id: <20230424054926.26927-18-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 883A1A000B X-Stat-Signature: xxzowo7hs4wbk5ip66rqm7iq7ftj6rkj X-HE-Tag: 1682315440-783785 X-HE-Meta: U2FsdGVkX186WxAX2LYDVhxryMmbfqsB6KJVArXpUroUY2sE4aIGVUfn8XofN/EOSJ88LJ16+2zAMMj6c689ApIWC+jbXeIFStw7VAxZWD0pq/ZwPhqKC6k4k2v1uXYcJ7KT4QDrwOfz5+zOiPPaxPmxAgL8pjHf/Sec29tusFpIR6+OAKgtaXhYsweTkcOODoX8DTrh7Z1AroNQxNCFUxJ/yV3084q1T04J3gCMzMGutJxQSZIKAV9pyfEKAisRPyXRATnbkuUzERc9ftzmAXWczkYiUJGdOhyIuGAO/hK3gvpUwi9TFG+hSEuc02sa5d0bdvdfwjCL/W52tkqFYHag3lcmWYUTY4c+WsiwuU+F/Ufwm+C7DcMyKSFBBsm3yLwngAOw4cZIHrN/D5oMUQ7bXGegMxR6me11SGVF7qfau1G+RmY7vs2EAT6fKTC5sZocdnMyOQ+giN1gRWFACGerQfd+JnNaFsMozQbjZiT1g3tGg49dbRDEUpvUYykcBv4dY4m8vJK6V5I/XIZLPlpoP+MMs/lH05LoWdlnD1Zmc3QUp21bp91cuZfpYhp2kK3UoIRbyWYqRI43IKPd98mgKUgEzeaC7RihcTXdyi1OyR8O471gm9jivYinSTiDBzYQGKdwENJjstOBuHtL0Z/J6jUANMTUPMxZkyr/a7+WSKkEyLHlGwNen9TwbTYQQykL1OJVdY5o9D8uYaxKBtY/ELlRYNnetajzgFnUyUEYcfY3FVuoT2UWGbfHZIAeSE7uPgVruLtGILblgJ+ewtHTGGKfg9PoyAtJLQdJ0/T5yFiltuWcJf3ifK8XwnJG90ZVRZ1B0cq4ond1IC8xTl5C1t2rOqNDpQ4wARnDzRYS3EJLhN75uEtFTADQ752px2OB08QriDpAw9It0qdj35tlYeH8dBpyZnNu6BBJk8Krmnvf5q7320cLEnsBdmXOzZJ5knVJcAxqqrQIMEf NRuK8hFy AflWKxIO88uX2ekwDU3nV36c8gldK7lllDT7SXfXk4kQOOOAPGowwMWqdaka12+ST5C8an9hfbfginBfrN13AhVxVlLLuQs4kOO/K4YkKuP/HkhzDrZ+TvvribbvubaMCdPAfkqhyW5IDMG3VbG3aTyB75JZ2cxTHAra7t7qn+L/jMRNV85IMXvkBcuBrMGyAOoJapq32AEnsf3ht3UN7FwuRy5Z+3aUvIsqA660HWBBwIC0R5wonoXjrjC12UlL05ceOvmmuuI8+FMzRse/PAsa2VDm1S2aCwQp63o1HKnwNFWI6WkFeSH9pus+KEVCN0RFA3fm54qDxVuN9FEkBT2FWs9UGXbm6RIZiDpRu+A8vj9LRLDUZhjcxZM4SxPOsd2rgnqOI0Fe6m2s0ViTaBukV1K6kV+37yujq9SFMKsz8Wl/59fJyYJQYMtVmHYWqrn7bZnrromvc0xbQ3cd5MsxpF3E1xMIlS3kK02hQH5QxCZKzVHD/hO/A6A== 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: Add a new config option that controls building the buffer_head code, and select it from all file systems and stacking drivers that need it. For the block device nodes and alternative iomap based buffered I/O path is provided when buffer_head support is not enabled, and iomap needs a little tweak to be able to compile out the buffer_head based code path. Otherwise this is just Kconfig and ifdef changes. Signed-off-by: Christoph Hellwig --- block/fops.c | 71 +++++++++++++++++++++++++++++++----- drivers/md/Kconfig | 1 + fs/Kconfig | 4 ++ fs/Makefile | 2 +- fs/adfs/Kconfig | 1 + fs/affs/Kconfig | 1 + fs/befs/Kconfig | 1 + fs/bfs/Kconfig | 1 + fs/efs/Kconfig | 1 + fs/exfat/Kconfig | 1 + fs/ext2/Kconfig | 1 + fs/ext4/Kconfig | 1 + fs/f2fs/Kconfig | 1 + fs/fat/Kconfig | 1 + fs/freevxfs/Kconfig | 1 + fs/gfs2/Kconfig | 1 + fs/hfs/Kconfig | 1 + fs/hfsplus/Kconfig | 1 + fs/hpfs/Kconfig | 1 + fs/iomap/buffered-io.c | 12 ++++-- fs/isofs/Kconfig | 1 + fs/jfs/Kconfig | 1 + fs/minix/Kconfig | 1 + fs/nilfs2/Kconfig | 1 + fs/ntfs/Kconfig | 1 + fs/ntfs3/Kconfig | 1 + fs/ocfs2/Kconfig | 1 + fs/omfs/Kconfig | 1 + fs/qnx4/Kconfig | 1 + fs/qnx6/Kconfig | 1 + fs/reiserfs/Kconfig | 1 + fs/sysv/Kconfig | 1 + fs/udf/Kconfig | 1 + fs/ufs/Kconfig | 1 + include/linux/buffer_head.h | 32 ++++++++-------- include/trace/events/block.h | 2 + mm/migrate.c | 4 +- 37 files changed, 125 insertions(+), 32 deletions(-) diff --git a/block/fops.c b/block/fops.c index 7910636f8df33b..524b8a828aad3d 100644 --- a/block/fops.c +++ b/block/fops.c @@ -24,15 +24,6 @@ static inline struct inode *bdev_file_inode(struct file *file) return file->f_mapping->host; } -static int blkdev_get_block(struct inode *inode, sector_t iblock, - struct buffer_head *bh, int create) -{ - bh->b_bdev = I_BDEV(inode); - bh->b_blocknr = iblock; - set_buffer_mapped(bh); - return 0; -} - static blk_opf_t dio_bio_write_op(struct kiocb *iocb) { blk_opf_t opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE; @@ -400,7 +391,8 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->type = IOMAP_MAPPED; iomap->addr = iomap->offset; iomap->length = isize - iomap->offset; - iomap->flags |= IOMAP_F_BUFFER_HEAD; + if (IS_ENABLED(CONFIG_BUFFER_HEAD)) + iomap->flags |= IOMAP_F_BUFFER_HEAD; return 0; } @@ -408,6 +400,16 @@ static const struct iomap_ops blkdev_iomap_ops = { .iomap_begin = blkdev_iomap_begin, }; +#ifdef CONFIG_BUFFER_HEAD +static int blkdev_get_block(struct inode *inode, sector_t iblock, + struct buffer_head *bh, int create) +{ + bh->b_bdev = I_BDEV(inode); + bh->b_blocknr = iblock; + set_buffer_mapped(bh); + return 0; +} + static int blkdev_writepage(struct page *page, struct writeback_control *wbc) { return block_write_full_page(page, blkdev_get_block, wbc); @@ -453,6 +455,55 @@ const struct address_space_operations def_blk_aops = { .migrate_folio = buffer_migrate_folio_norefs, .is_dirty_writeback = buffer_check_dirty_writeback, }; +#else /* CONFIG_BUFFER_HEAD */ +static int blkdev_read_folio(struct file *file, struct folio *folio) +{ + return iomap_read_folio(folio, &blkdev_iomap_ops); +} + +static void blkdev_readahead(struct readahead_control *rac) +{ + iomap_readahead(rac, &blkdev_iomap_ops); +} + +static int blkdev_map_blocks(struct iomap_writepage_ctx *wpc, + struct inode *inode, loff_t offset) +{ + loff_t isize = i_size_read(inode); + + if (WARN_ON_ONCE(offset >= isize)) + return -EIO; + if (offset >= wpc->iomap.offset && + offset < wpc->iomap.offset + wpc->iomap.length) + return 0; + return blkdev_iomap_begin(inode, offset, isize - offset, + IOMAP_WRITE, &wpc->iomap, NULL); +} + +static const struct iomap_writeback_ops blkdev_writeback_ops = { + .map_blocks = blkdev_map_blocks, +}; + +static int blkdev_writepages(struct address_space *mapping, + struct writeback_control *wbc) +{ + struct iomap_writepage_ctx wpc = { }; + + return iomap_writepages(mapping, wbc, &wpc, &blkdev_writeback_ops); +} + +const struct address_space_operations def_blk_aops = { + .dirty_folio = filemap_dirty_folio, + .release_folio = iomap_release_folio, + .invalidate_folio = iomap_invalidate_folio, + .read_folio = blkdev_read_folio, + .readahead = blkdev_readahead, + .writepages = blkdev_writepages, + .is_partially_uptodate = iomap_is_partially_uptodate, + .error_remove_page = generic_error_remove_page, + .migrate_folio = filemap_migrate_folio, +}; +#endif /* CONFIG_BUFFER_HEAD */ /* * for a block special file file_inode(file)->i_size is zero diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index b0a22e99bade37..9ee18013b1f2ab 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig @@ -15,6 +15,7 @@ if MD config BLK_DEV_MD tristate "RAID support" select BLOCK_HOLDER_DEPRECATED if SYSFS + select BUFFER_HEAD # BLOCK_LEGACY_AUTOLOAD requirement should be removed # after relevant mdadm enhancements - to make "names=yes" # the default - are widely available. diff --git a/fs/Kconfig b/fs/Kconfig index e99830c650336a..366d5d5be2784b 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -18,8 +18,12 @@ config VALIDATE_FS_PARSER config FS_IOMAP bool +config BUFFER_HEAD + bool + # old blockdev_direct_IO implementation. Use iomap for new code instead config LEGACY_DIRECT_IO + depends on BUFFER_HEAD bool if BLOCK diff --git a/fs/Makefile b/fs/Makefile index da21e7d0a1cf37..3cd6aa1d2ce387 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -18,7 +18,7 @@ obj-y := open.o read_write.o file_table.o super.o \ fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ kernel_read_file.o mnt_idmapping.o remap_range.o -obj-$(CONFIG_BLOCK) += buffer.o mpage.o +obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o obj-$(CONFIG_PROC_FS) += proc_namespace.o obj-$(CONFIG_LEGACY_DIRECT_IO) += direct-io.o obj-y += notify/ diff --git a/fs/adfs/Kconfig b/fs/adfs/Kconfig index 44738fed66251f..1b97058f0c4a92 100644 --- a/fs/adfs/Kconfig +++ b/fs/adfs/Kconfig @@ -2,6 +2,7 @@ config ADFS_FS tristate "ADFS file system support" depends on BLOCK + select BUFFER_HEAD help The Acorn Disc Filing System is the standard file system of the RiscOS operating system which runs on Acorn's ARM-based Risc PC diff --git a/fs/affs/Kconfig b/fs/affs/Kconfig index 962b86374e1c15..1ae432d266c32f 100644 --- a/fs/affs/Kconfig +++ b/fs/affs/Kconfig @@ -2,6 +2,7 @@ config AFFS_FS tristate "Amiga FFS file system support" depends on BLOCK + select BUFFER_HEAD select LEGACY_DIRECT_IO help The Fast File System (FFS) is the common file system used on hard diff --git a/fs/befs/Kconfig b/fs/befs/Kconfig index 9550b6462b8147..5fcfc4024ffe6f 100644 --- a/fs/befs/Kconfig +++ b/fs/befs/Kconfig @@ -2,6 +2,7 @@ config BEFS_FS tristate "BeOS file system (BeFS) support (read only)" depends on BLOCK + select BUFFER_HEAD select NLS help The BeOS File System (BeFS) is the native file system of Be, Inc's diff --git a/fs/bfs/Kconfig b/fs/bfs/Kconfig index 3a757805b58568..8e7ef866b62a62 100644 --- a/fs/bfs/Kconfig +++ b/fs/bfs/Kconfig @@ -2,6 +2,7 @@ config BFS_FS tristate "BFS file system support" depends on BLOCK + select BUFFER_HEAD help Boot File System (BFS) is a file system used under SCO UnixWare to allow the bootloader access to the kernel image and other important diff --git a/fs/efs/Kconfig b/fs/efs/Kconfig index 2df1bac8b375b1..0833e533df9d53 100644 --- a/fs/efs/Kconfig +++ b/fs/efs/Kconfig @@ -2,6 +2,7 @@ config EFS_FS tristate "EFS file system support (read only)" depends on BLOCK + select BUFFER_HEAD help EFS is an older file system used for non-ISO9660 CD-ROMs and hard disk partitions by SGI's IRIX operating system (IRIX 6.0 and newer diff --git a/fs/exfat/Kconfig b/fs/exfat/Kconfig index 147edeb044691d..cbeca8e44d9b38 100644 --- a/fs/exfat/Kconfig +++ b/fs/exfat/Kconfig @@ -2,6 +2,7 @@ config EXFAT_FS tristate "exFAT filesystem support" + select BUFFER_HEAD select NLS select LEGACY_DIRECT_IO help diff --git a/fs/ext2/Kconfig b/fs/ext2/Kconfig index 77393fda99af09..74d98965902e16 100644 --- a/fs/ext2/Kconfig +++ b/fs/ext2/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config EXT2_FS tristate "Second extended fs support" + select BUFFER_HEAD select FS_IOMAP select LEGACY_DIRECT_IO help diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig index 86699c8cab281c..e20d59221fc05b 100644 --- a/fs/ext4/Kconfig +++ b/fs/ext4/Kconfig @@ -28,6 +28,7 @@ config EXT3_FS_SECURITY config EXT4_FS tristate "The Extended 4 (ext4) filesystem" + select BUFFER_HEAD select JBD2 select CRC16 select CRYPTO diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig index 03ef087537c7c4..68a1e23e1557c7 100644 --- a/fs/f2fs/Kconfig +++ b/fs/f2fs/Kconfig @@ -2,6 +2,7 @@ config F2FS_FS tristate "F2FS filesystem support" depends on BLOCK + select BUFFER_HEAD select NLS select CRYPTO select CRYPTO_CRC32 diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig index afe83b4e717280..25fae1c83725bc 100644 --- a/fs/fat/Kconfig +++ b/fs/fat/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config FAT_FS tristate + select BUFFER_HEAD select NLS select LEGACY_DIRECT_IO help diff --git a/fs/freevxfs/Kconfig b/fs/freevxfs/Kconfig index 0e2fc08f7de492..912107ebea6f40 100644 --- a/fs/freevxfs/Kconfig +++ b/fs/freevxfs/Kconfig @@ -2,6 +2,7 @@ config VXFS_FS tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)" depends on BLOCK + select BUFFER_HEAD help FreeVxFS is a file system driver that support the VERITAS VxFS(TM) file system format. VERITAS VxFS(TM) is the standard file system diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig index 03c966840422ec..be7f87a8e11ae1 100644 --- a/fs/gfs2/Kconfig +++ b/fs/gfs2/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config GFS2_FS tristate "GFS2 file system support" + select BUFFER_HEAD select FS_POSIX_ACL select CRC32 select LIBCRC32C diff --git a/fs/hfs/Kconfig b/fs/hfs/Kconfig index d985066006d588..5ea5cd8ecea9c0 100644 --- a/fs/hfs/Kconfig +++ b/fs/hfs/Kconfig @@ -2,6 +2,7 @@ config HFS_FS tristate "Apple Macintosh file system support" depends on BLOCK + select BUFFER_HEAD select NLS select LEGACY_DIRECT_IO help diff --git a/fs/hfsplus/Kconfig b/fs/hfsplus/Kconfig index 8034e7827a690b..8ce4a33a9ac788 100644 --- a/fs/hfsplus/Kconfig +++ b/fs/hfsplus/Kconfig @@ -2,6 +2,7 @@ config HFSPLUS_FS tristate "Apple Extended HFS file system support" depends on BLOCK + select BUFFER_HEAD select NLS select NLS_UTF8 select LEGACY_DIRECT_IO diff --git a/fs/hpfs/Kconfig b/fs/hpfs/Kconfig index ec975f4668775f..ac1e9318e65a4a 100644 --- a/fs/hpfs/Kconfig +++ b/fs/hpfs/Kconfig @@ -2,6 +2,7 @@ config HPFS_FS tristate "OS/2 HPFS file system support" depends on BLOCK + select BUFFER_HEAD select FS_IOMAP help OS/2 is IBM's operating system for PC's, the same as Warp, and HPFS diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 3d5042efda202a..336a9d4542c97a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -42,6 +42,12 @@ static inline struct iomap_page *to_iomap_page(struct folio *folio) return NULL; } +static inline bool iomap_use_buffer_heads(const struct iomap *iomap) +{ + return IS_ENABLED(CONFIG_BUFFER_HEAD) && + (iomap->flags & IOMAP_F_BUFFER_HEAD); +} + static struct bio_set iomap_ioend_bioset; static struct iomap_page * @@ -683,7 +689,7 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, if (srcmap->type == IOMAP_INLINE) status = iomap_write_begin_inline(iter, folio); - else if (srcmap->flags & IOMAP_F_BUFFER_HEAD) + else if (iomap_use_buffer_heads(srcmap)) status = __block_write_begin_int(folio, pos, len, NULL, srcmap); else status = __iomap_write_begin(iter, pos, len, folio); @@ -753,7 +759,7 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, if (srcmap->type == IOMAP_INLINE) { ret = iomap_write_end_inline(iter, folio, pos, copied); - } else if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { + } else if (iomap_use_buffer_heads(srcmap)) { ret = block_write_end(NULL, iter->inode->i_mapping, pos, len, copied, &folio->page, NULL); } else { @@ -1256,7 +1262,7 @@ static loff_t iomap_folio_mkwrite_iter(struct iomap_iter *iter, loff_t length = iomap_length(iter); int ret; - if (iter->iomap.flags & IOMAP_F_BUFFER_HEAD) { + if (iomap_use_buffer_heads(&iter->iomap)) { ret = __block_write_begin_int(folio, iter->pos, length, NULL, &iter->iomap); if (ret) diff --git a/fs/isofs/Kconfig b/fs/isofs/Kconfig index 08ffd37b9bb8f6..51434f2a471b0f 100644 --- a/fs/isofs/Kconfig +++ b/fs/isofs/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config ISO9660_FS tristate "ISO 9660 CDROM file system support" + select BUFFER_HEAD help This is the standard file system used on CD-ROMs. It was previously known as "High Sierra File System" and is called "hsfs" on other diff --git a/fs/jfs/Kconfig b/fs/jfs/Kconfig index 51e856f0e4b8d6..17488440eef1a9 100644 --- a/fs/jfs/Kconfig +++ b/fs/jfs/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config JFS_FS tristate "JFS filesystem support" + select BUFFER_HEAD select NLS select CRC32 select LEGACY_DIRECT_IO diff --git a/fs/minix/Kconfig b/fs/minix/Kconfig index de2003974ff0d0..90ddfad2a75e8f 100644 --- a/fs/minix/Kconfig +++ b/fs/minix/Kconfig @@ -2,6 +2,7 @@ config MINIX_FS tristate "Minix file system support" depends on BLOCK + select BUFFER_HEAD help Minix is a simple operating system used in many classes about OS's. The minix file system (method to organize files on a hard disk diff --git a/fs/nilfs2/Kconfig b/fs/nilfs2/Kconfig index 7d59567465e121..7dae168e346e30 100644 --- a/fs/nilfs2/Kconfig +++ b/fs/nilfs2/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config NILFS2_FS tristate "NILFS2 file system support" + select BUFFER_HEAD select CRC32 select LEGACY_DIRECT_IO help diff --git a/fs/ntfs/Kconfig b/fs/ntfs/Kconfig index f93e69a612833f..7b2509741735a9 100644 --- a/fs/ntfs/Kconfig +++ b/fs/ntfs/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config NTFS_FS tristate "NTFS file system support" + select BUFFER_HEAD select NLS help NTFS is the file system of Microsoft Windows NT, 2000, XP and 2003. diff --git a/fs/ntfs3/Kconfig b/fs/ntfs3/Kconfig index 96cc236f7f7bd3..cdfdf51e55d797 100644 --- a/fs/ntfs3/Kconfig +++ b/fs/ntfs3/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config NTFS3_FS tristate "NTFS Read-Write file system support" + select BUFFER_HEAD select NLS select LEGACY_DIRECT_IO help diff --git a/fs/ocfs2/Kconfig b/fs/ocfs2/Kconfig index 304d12186ccd38..4a8288f7ee8697 100644 --- a/fs/ocfs2/Kconfig +++ b/fs/ocfs2/Kconfig @@ -2,6 +2,7 @@ config OCFS2_FS tristate "OCFS2 file system support" depends on INET && SYSFS && CONFIGFS_FS + select BUFFER_HEAD select JBD2 select CRC32 select QUOTA diff --git a/fs/omfs/Kconfig b/fs/omfs/Kconfig index 42b2ec35a05bfb..8470f6c3e64e6a 100644 --- a/fs/omfs/Kconfig +++ b/fs/omfs/Kconfig @@ -2,6 +2,7 @@ config OMFS_FS tristate "SonicBlue Optimized MPEG File System support" depends on BLOCK + select BUFFER_HEAD select CRC_ITU_T help This is the proprietary file system used by the Rio Karma music diff --git a/fs/qnx4/Kconfig b/fs/qnx4/Kconfig index 45b5b98376c436..a2eb826e76c602 100644 --- a/fs/qnx4/Kconfig +++ b/fs/qnx4/Kconfig @@ -2,6 +2,7 @@ config QNX4FS_FS tristate "QNX4 file system support (read only)" depends on BLOCK + select BUFFER_HEAD help This is the file system used by the real-time operating systems QNX 4 and QNX 6 (the latter is also called QNX RTP). diff --git a/fs/qnx6/Kconfig b/fs/qnx6/Kconfig index 6a9d6bce158622..8e865d72204e75 100644 --- a/fs/qnx6/Kconfig +++ b/fs/qnx6/Kconfig @@ -2,6 +2,7 @@ config QNX6FS_FS tristate "QNX6 file system support (read only)" depends on BLOCK && CRC32 + select BUFFER_HEAD help This is the file system used by the real-time operating systems QNX 6 (also called QNX RTP). diff --git a/fs/reiserfs/Kconfig b/fs/reiserfs/Kconfig index 4d22ecfe0fab65..0e6fe26458fede 100644 --- a/fs/reiserfs/Kconfig +++ b/fs/reiserfs/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config REISERFS_FS tristate "Reiserfs support (deprecated)" + select BUFFER_HEAD select CRC32 select LEGACY_DIRECT_IO help diff --git a/fs/sysv/Kconfig b/fs/sysv/Kconfig index b4e23e03fbeba3..67b3f90afbfd67 100644 --- a/fs/sysv/Kconfig +++ b/fs/sysv/Kconfig @@ -2,6 +2,7 @@ config SYSV_FS tristate "System V/Xenix/V7/Coherent file system support" depends on BLOCK + select BUFFER_HEAD help SCO, Xenix and Coherent are commercial Unix systems for Intel machines, and Version 7 was used on the DEC PDP-11. Saying Y diff --git a/fs/udf/Kconfig b/fs/udf/Kconfig index 82e8bfa2dfd989..8f7ce30d47fdce 100644 --- a/fs/udf/Kconfig +++ b/fs/udf/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config UDF_FS tristate "UDF file system support" + select BUFFER_HEAD select CRC_ITU_T select NLS select LEGACY_DIRECT_IO diff --git a/fs/ufs/Kconfig b/fs/ufs/Kconfig index 6d30adb6b890fc..9301e7ecd09210 100644 --- a/fs/ufs/Kconfig +++ b/fs/ufs/Kconfig @@ -2,6 +2,7 @@ config UFS_FS tristate "UFS file system support (read only)" depends on BLOCK + select BUFFER_HEAD help BSD and derivate versions of Unix (such as SunOS, FreeBSD, NetBSD, OpenBSD and NeXTstep) use a file system called UFS. Some System V diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 0fcc16b7f02bb4..1ef3915cacfae2 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -16,8 +16,6 @@ #include #include -#ifdef CONFIG_BLOCK - enum bh_state_bits { BH_Uptodate, /* Contains valid data */ BH_Dirty, /* Is dirty */ @@ -196,7 +194,6 @@ void mark_buffer_write_io_error(struct buffer_head *bh); void touch_buffer(struct buffer_head *bh); void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset); -bool try_to_free_buffers(struct folio *); struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, bool retry); void create_empty_buffers(struct page *, unsigned long, @@ -207,10 +204,6 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate); /* Things to do with buffers at mapping->private_list */ void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode); -int inode_has_buffers(struct inode *); -void invalidate_inode_buffers(struct inode *); -int remove_inode_buffers(struct inode *inode); -int sync_mapping_buffers(struct address_space *mapping); void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len); static inline void clean_bdev_bh_alias(struct buffer_head *bh) @@ -230,9 +223,6 @@ void __bforget(struct buffer_head *); void __breadahead(struct block_device *, sector_t block, unsigned int size); struct buffer_head *__bread_gfp(struct block_device *, sector_t block, unsigned size, gfp_t gfp); -void invalidate_bh_lrus(void); -void invalidate_bh_lrus_cpu(void); -bool has_bh_in_lru(int cpu, void *dummy); struct buffer_head *alloc_buffer_head(gfp_t gfp_flags); void free_buffer_head(struct buffer_head * bh); void unlock_buffer(struct buffer_head *bh); @@ -248,8 +238,6 @@ int __bh_read(struct buffer_head *bh, blk_opf_t op_flags, bool wait); void __bh_read_batch(int nr, struct buffer_head *bhs[], blk_opf_t op_flags, bool force_lock); -extern int buffer_heads_over_limit; - /* * Generic address_space_operations implementations for buffer_head-backed * address_spaces. @@ -294,8 +282,6 @@ extern int buffer_migrate_folio_norefs(struct address_space *, #define buffer_migrate_folio_norefs NULL #endif -void buffer_init(void); - /* * inline definitions */ @@ -455,7 +441,20 @@ __bread(struct block_device *bdev, sector_t block, unsigned size) bool block_dirty_folio(struct address_space *mapping, struct folio *folio); -#else /* CONFIG_BLOCK */ +#ifdef CONFIG_BUFFER_HEAD + +void buffer_init(void); +bool try_to_free_buffers(struct folio *folio); +int inode_has_buffers(struct inode *inode); +void invalidate_inode_buffers(struct inode *inode); +int remove_inode_buffers(struct inode *inode); +int sync_mapping_buffers(struct address_space *mapping); +void invalidate_bh_lrus(void); +void invalidate_bh_lrus_cpu(void); +bool has_bh_in_lru(int cpu, void *dummy); +extern int buffer_heads_over_limit; + +#else /* CONFIG_BUFFER_HEAD */ static inline void buffer_init(void) {} static inline bool try_to_free_buffers(struct folio *folio) { return true; } @@ -463,9 +462,10 @@ static inline int inode_has_buffers(struct inode *inode) { return 0; } static inline void invalidate_inode_buffers(struct inode *inode) {} static inline int remove_inode_buffers(struct inode *inode) { return 1; } static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; } +static inline void invalidate_bh_lrus(void) {} static inline void invalidate_bh_lrus_cpu(void) {} static inline bool has_bh_in_lru(int cpu, void *dummy) { return false; } #define buffer_heads_over_limit 0 -#endif /* CONFIG_BLOCK */ +#endif /* CONFIG_BUFFER_HEAD */ #endif /* _LINUX_BUFFER_HEAD_H */ diff --git a/include/trace/events/block.h b/include/trace/events/block.h index 7f4dfbdf12a6f1..a0503f387104a1 100644 --- a/include/trace/events/block.h +++ b/include/trace/events/block.h @@ -12,6 +12,7 @@ #define RWBS_LEN 8 +#ifdef CONFIG_BUFFER_HEAD DECLARE_EVENT_CLASS(block_buffer, TP_PROTO(struct buffer_head *bh), @@ -61,6 +62,7 @@ DEFINE_EVENT(block_buffer, block_dirty_buffer, TP_ARGS(bh) ); +#endif /* CONFIG_BUFFER_HEAD */ /** * block_rq_requeue - place block IO request back on a queue diff --git a/mm/migrate.c b/mm/migrate.c index db3f154446af4e..9f9a81d43fc8f2 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -692,7 +692,7 @@ int migrate_folio(struct address_space *mapping, struct folio *dst, } EXPORT_SYMBOL(migrate_folio); -#ifdef CONFIG_BLOCK +#ifdef CONFIG_BUFFER_HEAD /* Returns true if all buffers are successfully locked */ static bool buffer_migrate_lock_buffers(struct buffer_head *head, enum migrate_mode mode) @@ -850,7 +850,7 @@ int buffer_migrate_folio_norefs(struct address_space *mapping, return __buffer_migrate_folio(mapping, dst, src, mode, true); } EXPORT_SYMBOL_GPL(buffer_migrate_folio_norefs); -#endif +#endif /* CONFIG_BUFFER_HEAD */ int filemap_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, enum migrate_mode mode)