From patchwork Fri May 19 09:35:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248021 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 5849EC7EE29 for ; Fri, 19 May 2023 09:36:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6645280003; Fri, 19 May 2023 05:36:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEFAE280001; Fri, 19 May 2023 05:36:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C905F280003; Fri, 19 May 2023 05:36:01 -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 B16DF280001 for ; Fri, 19 May 2023 05:36:01 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6BD6F406ED for ; Fri, 19 May 2023 09:36:01 +0000 (UTC) X-FDA: 80806498122.20.318A2AE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id B578CC0010 for ; Fri, 19 May 2023 09:35:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oyB5ENrt; spf=none (imf22.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488959; 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=C58xAMXMWyHPUrJzlledIWUNnBNJDxIHqrA6uNazQYQ=; b=LA1nBUgiqiA+0MwSYnDRy4/TIgw1tt1VKL48kW8UXOuLbEcGYO+gaWMZ3tEc8FD8JsfVCc ruky3lQWN9vOtdnaZMLT2llX9BwxvmQQlL9A5vvtO4TPtwzwg9y1Kp077hjgj6fvlueG50 1gVqVfxyoq/+gYX3r+S319I6YoEGzWU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488959; a=rsa-sha256; cv=none; b=F+p7xKv3oHYSP4C8KrNWJwc7H6pkYP5cAIr3zo3A2lWEHB2VOt1OAwvtobniSq2AgUr8aU cNIYpCXhxwVb/C2KEOgw72KDrMj7lGQQgcTyqWegEp4aAswbQnCwWfLtG2HW7lI+UBXtq+ WedxHfSeNIkrVo7RSJYmZPUxpRgTWEM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oyB5ENrt; spf=none (imf22.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=C58xAMXMWyHPUrJzlledIWUNnBNJDxIHqrA6uNazQYQ=; b=oyB5ENrtpS3oCMIV1tdQqugXkU sJw9tWTnvGCKGzKa9RpoMfHRvUYSVzT0RXiuWCYAumP4uyadSzytLs+6N80qNj9Wx28cGiAr5gPRY KzRMEKVFBYf9VfLGcLm7M27cD+XoFkxkgCSSKqQHZ2uH/AqoUIgSHz/wG2IogiCKWS/kp20FiYsw9 xyQ9CaQyFtSTLVG/mgOLVL5dwvmUwJri/zQlIjlsjwVm/9D6Z4u0xvXzVPX25fHmcOK0AEKAUd6wR 5Pyq49d9NQSlXRan5UmQ0bHDH+gbH8e7O2mZ27adQFXSM/HW3HE7/4rluA8VRqK7aYy04HDSPH9D2 6F0846Dw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWF-00Fjaj-1T; Fri, 19 May 2023 09:35:27 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 01/13] iomap: update ki_pos a little later in iomap_dio_complete Date: Fri, 19 May 2023 11:35:09 +0200 Message-Id: <20230519093521.133226-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: B578CC0010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: eusyuqt6r3xhgqohoh37uzg6ej45cmhm X-HE-Tag: 1684488959-896148 X-HE-Meta: U2FsdGVkX19Er0SuGTwpZx0utLNXWXbWnm7MApX6cYVEFPqtt8FukyHtbvn+v6DfE3sKtxS/xLev00RBoM6rmNzJwlVHaSKDHrg825lnzWlCawo8G8l4FL9CcyZSU1A7n37YAIXjoN+GNBrVCwivP6iwFdsxeJrNrjAIma92uwb4yXP4DzNY6xuBJ5IDfkLduSd3geNJ/YzjGLpBgibEb9X4+4ZHvMPHnzARreBuh8S0fdwlqqh43JXDxBRGVZ18ahzVUyesbGNXEZ+c9pn9/tWnlykziusF645pQ4KnOLJretcxyQT72Tf3HWn+XLawetCIpdMfz2CrqkfgOQz1VlVeBaTzxny3vKYmaFDVdC/v3ZuwQU/GYR4oypwwzDMl3qQslJ8UWjXkEW7UPWHao6vOb7n0mMjdDyfnq1vrHnJVixCI3i0fAfXjNtJfYo1vN0oBFz6NUf+pMVKVmnGl7teGhELgSQ9qwxailObdyK2oYorxH7roCrcZXSsn97ytv6HEvESV3Cl+8T/ry46uDkQdhe4KZRJHpkkRAVIFsqnp6qmfLhUWH4nu8wdu+iN6V/FAgkD3qTjGnA7H1T4tu0Owja7CNS4ZZwHNnAD8Hfc42WGAi0Ai70YllHK7cmcCNrLLDxdqx3eP3jVY4Om8zrW8/sctWcWHHsfbveD1+bco5A+waVGe3bBDdcLGQWZ81oYk/4wrUUliWGUwDCAYbyUGhKXPYaQLCnm2dUdvtA96KqS42wS3HVR2m8IaKO/JEe7UynfQrNI/eW8v+3ynJ26LuZzxMSGCDso3r4d5kBIjkNPfmF9LMbppVqVj7E3/E6bKZyrdo4DCkOaaAo2owbY6Y2HhCgGFd6CoY4RePtZp0/9OtRliTYp8lwzU8bhW1UgAuGqj9W35GVid7Y9yVqeIQC8/gC966tOUfBRdk8RJcwRsU3BzZxnPlEWDDDtZ0XygezrcnBR85aib0nw MMn0hTXh yVHbdqOVWNPhrSWPveuTuYfTdGUZx1OsW2QMhpGR3fuxc421edcYKktonE4gGLxwb/PnSUTbJUsM7tj+g0xXu9tXHfudQIA3HlGxie9mfstVQG8qNsHDajGn6/WoZmMHAQAGIEMW9eRlyyxSyRw5pLGcaoVjz+rJKpm/WzP/QsvVvG4UhnBKddte4kAobL6ouBxYqn7BPJ9cFZqW1DMInmkNlQTjZWPZH+uKIsZOb4hmfNELf3mYt/ZALncp+dgeDtzRsFBh3hmskyiR4HWa5Hj8EiQWTlYxzQhQFO/LAmLs2g/bM2nKSnLMuUev2CbMkVrGE4pD8Pu1w4turfHJYEWxvE9bTbLBgHiZ4vdh+TFtszJccXTxd66mNPKVqI+ROjaMTmEZ7F9e/I/8/uqIzb26rwbWNMZZ91SWLPCzIUe4c2U//ecp3Hz8uas1e4KMzTHRFeSY8tYNW6GteZSVhtUt3IA== 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 ki_pos update down a bit to prepare for a better common helper that invalidates pages based of an iocb. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/iomap/direct-io.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 019cc87d0fb339..6207a59d2162e1 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -94,7 +94,6 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) if (offset + ret > dio->i_size && !(dio->flags & IOMAP_DIO_WRITE)) ret = dio->i_size - offset; - iocb->ki_pos += ret; } /* @@ -120,19 +119,21 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) } inode_dio_end(file_inode(iocb->ki_filp)); - /* - * If this is a DSYNC write, make sure we push it to stable storage now - * that we've written data. - */ - if (ret > 0 && (dio->flags & IOMAP_DIO_NEED_SYNC)) - ret = generic_write_sync(iocb, ret); - if (ret > 0) - ret += dio->done_before; + if (ret > 0) { + iocb->ki_pos += ret; + /* + * If this is a DSYNC write, make sure we push it to stable + * storage now that we've written data. + */ + if (dio->flags & IOMAP_DIO_NEED_SYNC) + ret = generic_write_sync(iocb, ret); + if (ret > 0) + ret += dio->done_before; + } trace_iomap_dio_complete(iocb, dio->error, ret); kfree(dio); - return ret; } EXPORT_SYMBOL_GPL(iomap_dio_complete); From patchwork Fri May 19 09:35: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: 13248134 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 37953C77B75 for ; Fri, 19 May 2023 09:57:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A36F900004; Fri, 19 May 2023 05:57:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95352900003; Fri, 19 May 2023 05:57:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84372900004; Fri, 19 May 2023 05:57:08 -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 728EB900003 for ; Fri, 19 May 2023 05:57:08 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3719B40A2E for ; Fri, 19 May 2023 09:57:08 +0000 (UTC) X-FDA: 80806551336.21.EA43F93 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id D1424180011 for ; Fri, 19 May 2023 09:57:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fNcIJXSt; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684490226; 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=l1nHpSO+SfI7dJoy9Bf6sKMQrfHZhTAI7csUoY2gOqg=; b=k+LhkyzuEcFrk5VIz+yWxTfuXenD/RcrwGK6Us40VjNS8WEEjsJEL3dSv2XWMyRwzciSdT /U6UI2jhI5a2zHYG5UzUtyA1GxMRs7Z07XZ16Y7x3rRcjyMnp8GfCr65BCTdphzKxCtOm5 Y7CvQ06cpV8HHWgecjCZ0gNq0ulcXvw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fNcIJXSt; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684490226; a=rsa-sha256; cv=none; b=sgL9wKL656Eqe32o5zrFdG94f8obumv7BLM0fuJ7WZQRVN363xzz6RuZ6Tmd0RT8N4UVcu STTEPPJIwWxQwPPRHi2eISbU6c/vb6jix8qUg8LgNioqkBQDIlwzDknMZhS4kWMmuYEoWO ET7UlNauRnGOEScFR+FbIDVXKZPJYcA= 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=l1nHpSO+SfI7dJoy9Bf6sKMQrfHZhTAI7csUoY2gOqg=; b=fNcIJXStbg35Q3/kxwRadlJBkR BDEVYzDTYkGHq1nmqbayvo2Mb8RhUWRs2vpPYsKxu8f33DSVER7T9eunP8b8/p+Cm1VPG75aVtHEh rUAEhk75WkLoyrZwgVxPM/pVzSBCQHe5cSaLK2/BGJnm0EZLku21y03qF/1nrgLfo8Y/CBxH34Xpi mjIWogLEu/YGtIV81gHtLrQwwS6ZOgNx8i2yLDnmdlw9wjPJt68CN5aY4zUsNNalfAYBB5h0jwBe9 IU91VmeeMOfWsiiyMRY6eeqJxbWxpymNlF04FNOu5GcpFrlEbHeZbYXoC9JEhrJNWBeTP/bnm84Qw taYBszPA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWI-00Fjbs-0u; Fri, 19 May 2023 09:35:30 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/13] filemap: update ki_pos in generic_perform_write Date: Fri, 19 May 2023 11:35:10 +0200 Message-Id: <20230519093521.133226-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: rspam12 X-Rspamd-Queue-Id: D1424180011 X-Stat-Signature: u19zexkw5pauo7kxso5su3pdrhj16gs7 X-HE-Tag: 1684490225-193567 X-HE-Meta: U2FsdGVkX18NUY9iD8aI+qMuBlOMg4wZVLEI7dZMSu2A4e6zvUU21yZLlzWBTIcW6IsnaXPKW5Zy9uroR7SyBpkAKDczB6Vc6T9bU+Zzoedk2dciYYmjGZfSdgQLAxoCGVGTCQ3s6/W91ITU3Z9XedsTuRM7V0arwLByVV6UgaiEN0rU8rvqmON9P5CDUYQHwWa/f9IoVdOXjwF14W/0H4DFl3XoJ1Obobif49REsYZ+B1uMCOrljfFQ2WHRyE9gQi1fi0qFcFkQ4J0CZLVi/KOcvvWflOQxNtqPhyrw5521A2uScBIY0jt1jAiervshry7bYYOCWRX0GRdXWCRxg0qpGGDohByyFw1jQjp4xW2Z+rrSXhN384LS4+VbT3tWscv0cyu3UhU1OMCXvoiXAc6hrGMGERFNi/Qp0qZYtSY3IGUvLUerp40ETWDSMNdZoskLMYG9H/Wxb3csSU4ely6R2P71qSAAKP9uumD59NRNH9dzW4wOT/OAmaUk/0oZ54Ih6leH9IYr0NbZa1JdQzAJH3ifsfbEdhzRuxZVFi+QIoxvtW9VPbnFtxe4d2VrdhS+6P4ctZN1/9370aW9iSAdrRgkSFDLi+BBd9gWNzIrJ6sf1I86pF+WpA28sd0DmDZfGJrg76qRro3O2R/XkYWfMt5RLFDPC4a6H6gIj6Tx7q2tVOxuJks8EG2e625UyfUAWz3Hf84D1Kl0LqaJzlRtcutXYHNwSJN1D93OyP+6cMJtDF0R9g8LDJkeyNDQbx8wHgRdHg+1KOTl7I09h2fMrHz8qXK+fKj+DM9WEp2aaRzb6QR/9Ysor4t1tys2olf8ixrWD+BAe2vIW+Mns0J2JFMz8PSQWm4SxS3nQGcjLXAtmekeO6tFbiUL4emfgtknhHhc+abTjKBeKGxyWYNKHhmxWA1iTjI8W/C1zDZHRUaDpzilIRGW+XA4P/PjYEuCbAP8SCcINr9w5az Tm+CtWjp WhcnzHjq5ALWHjDdjuUJxinfNwCh3Ip8Ky4Jba9H8DMzDEeApXAGNlQ9o7ZhWwtzGUC2KBmCNWlFoDNV2//QL03x9RIMIOloH1or4KbePKtCMbxDLvlP/NZ9A0A+VCvky4W+A/KOCdnUnIdKAlWe+MSjjtESGPDMDjN8a3ZSLHOB1mmHEya5URQAZe1JTHeu7iNh9RGiJkcMxijySIul3JAXDpDwuuSKI6JLJJPL5XPxXP8Kpst7mLtO91SakWv92oZBW9CO4Edrv0e7BTOVMMt3xXZwWnrwuIKfVmIVAbnQ7iG7cypOOA2c156DPUPx3QkoD65L4H6eNabBT976Lz2MbZvzmMZ9eCb8kx1vg6jpK3Od4Yrs0D4ev3v6li1D+5l/oRMTPlrSDc86sc2ytqRWmSB/xB4P23Hxj2HK5+0IFgkfYNcBTHUzvsli6s+/Dxk/DJNRIUL8SiYs= 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 Reviewed-by: Damien Le Moal Reviewed-by: Xiubo Li --- 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 d101b3b0c7dad8..50824831d31def 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 5ac53d2627d20d..9e3855e43a7a63 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4522,7 +4522,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 f0edf5a36237d1..3cc87ae8473356 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -658,7 +658,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 b4c9bd368b7e58..4d0ec2fa1c7070 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3957,7 +3957,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); @@ -4036,7 +4039,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, @@ -4049,8 +4051,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 Fri May 19 09:35: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: 13248019 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 F1F34C77B75 for ; Fri, 19 May 2023 09:35:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A963A900003; Fri, 19 May 2023 05:35:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4577900004; Fri, 19 May 2023 05:35:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90D6A900003; Fri, 19 May 2023 05:35: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 63AA3900004 for ; Fri, 19 May 2023 05:35:53 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2EABD1208C2 for ; Fri, 19 May 2023 09:35:53 +0000 (UTC) X-FDA: 80806497786.23.EE05121 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 0C0C340013 for ; Fri, 19 May 2023 09:35:50 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=M6Kzmetz; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488951; 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=6ol1bWODvCYTDT1JUgKKn9Fh7sNo8e9dyRg15aWfO9s=; b=Xcogsi4X1cLJPyjJQ7J5TZkUc4b0Evvl8t08JWKdgS4AL1kDEUJrI9YD4TLR7Xw9l8JZCI cDULZQq0HD1Etw/i/o2NCxXXwtS8oEqZQBI+bzWWNgW+xzURGgmi8fMaUO+JNs/Hq7L2ZH 1ZwFRO15Yeg1aZFQmoUEcOAyctcuNrI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=M6Kzmetz; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488951; a=rsa-sha256; cv=none; b=n2SYzSvd7c45C4NAY4abtncpg0EhtI0VeQpZLJB4HbIyuNgtjE2Gskc2j9eqdWEVolPLR9 b9Nbp/bzzRANb9tgZB0o+gVaGKA76LqwXqS9iR1cg3vTQ4Dj2Psf/tAnyjoHYgli9FlpzM n1Xhw5L/N2IVP3WdzLPbLvITN/ejPo4= 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=6ol1bWODvCYTDT1JUgKKn9Fh7sNo8e9dyRg15aWfO9s=; b=M6KzmetzkAeuS/VLc0Lh9JjJju Ru7ZWS27kADd2VtwycBozYnipzuMCirIKKvprX9mPjk8FvigFdIjN4M/xtUGuo008+0WHzo3WfJO3 EWdbDmUJHxpyHqFvevzzdoF8sY4ioA/FmCmhyHPkTSVBFbLUMUzg40a4nDIY0CgVciRjpOyZAAYL6 xkhg/yyrk3LagyAARJhct/1trEUwML73oIOqKl2Q1BZS5BLz1DLbgF0IsqLaC9nklXzoY22/+vvE8 6CgJvHjCSdFdTeTp+UnCpdHK3HMDcG/2uwD5g8SjDrtquin8RrPGVFwqC+Dwf8e+kLQB4xAFRANP0 98GWXd4g==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWL-00FjdO-2V; Fri, 19 May 2023 09:35:34 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 03/13] filemap: assign current->backing_dev_info in generic_perform_write Date: Fri, 19 May 2023 11:35:11 +0200 Message-Id: <20230519093521.133226-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: rspam12 X-Rspamd-Queue-Id: 0C0C340013 X-Stat-Signature: d6hjox4jmmp3i75grpud61uqjz4co3tt X-HE-Tag: 1684488950-561942 X-HE-Meta: U2FsdGVkX1+RKRggbg4OUbWI17CJHXyrMfinAhsZajrAtWHwgLH+c6NoB2tX60MXOuNLHkMtCXpKIl88OtYH/K4hyG9gXG/LJwElDnC6Dq8HiqG+9bkw4nRxqVUyFGURxXYDm8LrNtqA5dSNG+gdVaOzOI1B2fU84GUE2szrwjocdAvmM99bolEBL0RvBNqKgkVkAz/DUV4sRD7hg6ohqjuK4yMHEmf0r6/au+Cd4CRjtu9EsdnI57E7hQvjRmeiw2MyNjbPUNB6m9kfMfPZi2smIFzSVKMZqpFN9b9gJaVGxjzwM92tXnkHgxYvE5bkP0x92mvfpEmzRhilpvhlHooUuxDcOagaLI8cGMRd6JLK3D0EEy1t2eaqeldD59hzZv8dFeyeplHg+Gqd2YEVUrnKmxaJTwS4e/ML5XwCQBOQx4qnKEdm5JSBSJYA8iOVkfiV/2o4yiMOvceBz2yCnrBs6/rKvgttxaxO9tSYfG8s/dLI1LDokmRRJOeyE5JolPHqA1Q34KWGRElReheO1Fpao1uEab4Hg3X3+Kk6uXsuKO+XSdro5bjVDr9tGZ7e5IM6Xd21MXEOoPzVBkswz6IJHw+KeJhrpCDJynWuqXU/W7W6kLQvrCk44aeB7wDtAXwQYo5fWYO72n7SZ8VSMykndqnzGJMAG2/bTUavgHh+ECQKeYj7Gbd1jgrN4Od++oWMf1xFQKlsgY1JX2eEw9XYCMyLMn0+6q/VD0nfJQtotGPdV5Xm/ZuGpAwjVJcsv7NJNrC+lVuY97pbVd1OwjKZ42Z95PQ0ry1n2Yht3WzZEohQ7dW6eWR/gY6q6y1a9rc1waUU/8zEt+MUwWQXwuPKXlSjU7JjUWoy6FGyzQAnJOvKaL0W4bC4/oOcf9yye4cqobmPaSkPgQjduAt5kCVCL0dEy9ZR1H9joaNy9F5b+MVYEiAFUmlpmOMLM7XSj9r8V8VQaITtgoOIDsv Bxb0LMBN RdhOfm+SDRj8tp50stf3+EX5qijpmEgB8WmltWH2RMBqbH9xTzBomK6c+pdqctXpNwKxqY9qFNDhEwMtr4S3OYC1gFkQzNNFr+xE3FWtNI2STYSSlRdWwdf4UDaeZjmMc0OcVU+Abr9e3rN881YU/z/9IU4VhO0EUhXG5wUMkmhC7jmko0Npbr9c8ySQKjyE+ufOrY0kPUceG3u7Jz3k4/+FuJ5Tc2utLaFhEDXPFIe7r94JVlA3h7CXayKfoX448Yh/cpuecNY/Fzau9ViWrfKqd05CTlBpb8xsTJiDu0aZ0uJ5wT+A75MfNfAI6y7LgMRDN75iW9mHjJuuzNQYvCOkha/2HcFDp/TdSVhTnu+jAb8UJrHoWPmKBzW/sFCZftjxGSqLKvHrQ6vcuFlkNk6zyKoaLKGOGkFJ3V5F4BkJrsL/w1V2OGCX0N7LjYuxjyL4lhNk3w7BD/dxCpaBFLKiZ0Q== 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 generic_perform_write to reduce boiler plate code and reduce the scope to just around the page dirtying loop. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Xiubo Li --- fs/ceph/file.c | 4 ---- fs/ext4/file.c | 3 --- fs/f2fs/file.c | 2 -- fs/nfs/file.c | 5 +---- mm/filemap.c | 2 ++ 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index feeb9882ef635a..767f4dfe7def64 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1791,9 +1791,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) else ceph_start_io_write(inode); - /* We can write back this queue in page reclaim */ - current->backing_dev_info = inode_to_bdi(inode); - if (iocb->ki_flags & IOCB_APPEND) { err = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false); if (err < 0) @@ -1938,7 +1935,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) ceph_end_io_write(inode); out_unlocked: ceph_free_cap_flush(prealloc_cf); - current->backing_dev_info = NULL; return written ? written : err; } diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 50824831d31def..3cb83a3e2e4a2a 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "ext4.h" #include "ext4_jbd2.h" #include "xattr.h" @@ -285,9 +284,7 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, if (ret <= 0) goto out; - current->backing_dev_info = inode_to_bdi(inode); ret = generic_perform_write(iocb, from); - current->backing_dev_info = NULL; out: inode_unlock(inode); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 9e3855e43a7a63..7134fe8bd008cb 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4517,9 +4517,7 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, if (iocb->ki_flags & IOCB_NOWAIT) return -EOPNOTSUPP; - current->backing_dev_info = inode_to_bdi(inode); ret = generic_perform_write(iocb, from); - current->backing_dev_info = NULL; if (ret > 0) { f2fs_update_iostat(F2FS_I_SB(inode), inode, diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 3cc87ae8473356..e8bb4c48a3210a 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -648,11 +648,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) since = filemap_sample_wb_err(file->f_mapping); nfs_start_io_write(inode); result = generic_write_checks(iocb, from); - if (result > 0) { - current->backing_dev_info = inode_to_bdi(inode); + if (result > 0) result = generic_perform_write(iocb, from); - current->backing_dev_info = NULL; - } nfs_end_io_write(inode); if (result <= 0) goto out; diff --git a/mm/filemap.c b/mm/filemap.c index 4d0ec2fa1c7070..bf693ad1da1ece 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3892,6 +3892,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) long status = 0; ssize_t written = 0; + current->backing_dev_info = inode_to_bdi(mapping->host); do { struct page *page; unsigned long offset; /* Offset into pagecache page */ @@ -3956,6 +3957,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); + current->backing_dev_info = NULL; if (!written) return status; From patchwork Fri May 19 09:35: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: 13248020 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 62417C7EE2D for ; Fri, 19 May 2023 09:35:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA349280002; Fri, 19 May 2023 05:35:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2C35280001; Fri, 19 May 2023 05:35:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7F1C280002; Fri, 19 May 2023 05:35:57 -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 A2066280001 for ; Fri, 19 May 2023 05:35:57 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 72A5F80986 for ; Fri, 19 May 2023 09:35:57 +0000 (UTC) X-FDA: 80806497954.24.94A0947 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf08.hostedemail.com (Postfix) with ESMTP id C59F8160014 for ; Fri, 19 May 2023 09:35:55 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xArZwU++; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488955; 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=tGCXuJSpKeMdDJfNmlfVF+NepybRn/cvj/Ka18QV4Tk=; b=c8wl9JCzs9llJDIwjUHrj7pTZfAT5WyOVOAIgpE8RWa7AqjAtyae09Hb4snWSscLrGDORo WNqnnRPqgvMxVokg19gz4l0IspDtYXmlvU0BEFR+Ucz51QXpaWP1zD1XvOH8hnxVaN+7cI bPTiVNMVghcpEeQK5CsHLJmPFD4RSfQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xArZwU++; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488955; a=rsa-sha256; cv=none; b=4aPx5YEsGc6lvwDt9Id8fRXkt6phSZNu/yJzDAhDa4mHEJdiSkeIM15vW3M0eyyTLSrbgm U/FvbhkQ9E4X/Dbk37rnF5RrLufwtG/44YjqRks0QvM7Zs9U+ax5Simp+3k4HTBeP1hV/L jHHMVoUL8OMqiqTXgGOz+0SXN4mmXSc= 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=tGCXuJSpKeMdDJfNmlfVF+NepybRn/cvj/Ka18QV4Tk=; b=xArZwU++0j0FGgKFO7gwbG5SAC a1/RPaFHnsRd+UOwpiKD4Hll+FQbOU/DKkcxbAcjid8e3CwS1tnTNCYZM+x+KyqcKxXicxUupis0e ZB3+K10LpIi0KqMuYdfgZL6dZTSTQbvZkH6r8F/El40AXbo89yVa1KaDyWLp3QCGRzcYOWW19+z/N 2m+4ElhodZEmxP0Tr1ON4pIvchIdcns7DtlQG0WP60hmdAH+rnDgdc0p0Ohgew+bUcpPErepKoeep u14tVprafp/sJaOi2+meSJDf/HCFZ/FFjC0EYErlFi9kYKElkKwIgcEtgjqPYwnbsZPkkX1lMh8UH EPHXXp9Q==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWO-00FjeP-1n; Fri, 19 May 2023 09:35:36 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 04/13] filemap: add a kiocb_write_and_wait helper Date: Fri, 19 May 2023 11:35:12 +0200 Message-Id: <20230519093521.133226-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: C59F8160014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: w8txaosuxosg66n36q1s4rqoxfjy9t5c X-HE-Tag: 1684488955-263894 X-HE-Meta: U2FsdGVkX197lWYZKrke8C7PdYxDfjvsfUb3nMwvWEVgoVPwVhPo2z2uADmyFyrEAsaMaKuoatkhCmfgIbScPyu5NwC05XKH9ACtYE9Dlgqf9TPQrEOqkBCq7gzRcaau5kbIqDiAgGqJfPAlJ2u7wRDjTwy8pEtvifQNyvOrtCrID77xKeAtii37txkc0ierEgZj2JAw6DpZgI0p7CFR2f0eqIlismPl3hwmzx2oNAMGmdmq03tTXQdUCFD2JvBIWOgAbTkKemSlziWKjPFiLoLdXNxMZFaD5uuSIwgPF6KiW7gTm807TnMirS97q2I8KlJanw1QapPXXEwfXYsxWDAcEKgHf1hUVFC0jFA2dS0yOtHwRvppY6rWSx9WmomLrembMHOU0lY+f0wc+c8zOOdu6lGlmqZ0O4fbbZy/7tK5k+3VH8JvL3M/Laa0TUcsE9VtttrwibpyYLzQlZyAO1bLo6P7MMniE5qofXPK+/rI97rde+VvLxCwP/iNKKX2yGgWOBO3WcPoTxOlWZf0q4MpfNrfxW0lRmRC/2M0wxbSb6PKrh3vdrYkPz8nSrN/GKoYjxyP6ZvVTl8khUZgRhhzyXX+mXLBUEna6ai+KUJyg38hDANIfemwNbZY3jzUTz2Hha3sqpB+yOVCoUlfMAOlKPGIPV0ZfcXY53GuCDbiOEyOTNF9KV8isHcSpdSiiLBmG9tDZlKFouT1DBDiVTVogGfx3UniXEc569ib9O6F7f8DAKgSE6cXVM4HBB0JhWBTXjW1zqcV+Tu6paJhDoO08IaCmIYID9X1BHtlw1nwQ0QOKU2e0AEW6tniPdtukmQ7Ddcfx5sj4tknJD2bS6XeMxYMBytu0rxWZqwEP611Qn7nARKrnt6/H77uUqnicvWt3PBSahvBqakCUvQ4zUZXloyBwpUTc0oCVgoJWWZGdQtWXgWWsDsoFdj/LJKJRxkdmdUENydmEagSLLE X/ikLXdY oEEBjf3QPh21ESJLasnOYP+5mqZmqOLr/jQXnxJ0HGOLErQhRuu07+nYb0N3jmFgO5arjW9F4YrwyunEyFEc+gMgm2RsbAFfXhR6y6WXhXlm7WwRVyCD4Uit2ricLZBo6vsSWqdibbOu/uGAdWbf3IXUpHYEp+yjriZT15gefVL6nXoU56Vtvdn6EtS/yF9mclQNH9TYCNxlgPo4+olCTrM8V18z+D46uyfBylcskF6ni0brhAds2Do4ZQTh9INyR6D7xDeRgCVYNd650UAy9Sgd5RQXIO+Sb1IeDtTw8Y9Psdv1pxY/cngWWvZah4LXpUCxm52uvTCfFJBHQFy3u0/1SQvFYUIi3Y/ohlrCkYsHF1FTiTGtWdXOQZS5HozZykL2D5gjtAtBGrDVz6MJaILDAMI8ZuvSWHrZihykhusc0ts8z6ZAIo8VgQG0ycMY6WhXuJ7TCfz0ESsXhDyuWphXkRJP7CFvk6Jm8Y4vQ5JAVsM8= 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 Reviewed-by: Damien Le Moal --- 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 a56308a9d1a450..36fc2cea13ce20 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 bf693ad1da1ece..2d7712b13b95c9 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2762,6 +2762,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 @@ -2797,18 +2812,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 Fri May 19 09:35: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: 13248022 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 95D90C7EE26 for ; Fri, 19 May 2023 09:36:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FE6B280004; Fri, 19 May 2023 05:36:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 787DB280001; Fri, 19 May 2023 05:36:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DB68280004; Fri, 19 May 2023 05:36:02 -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 498D9280001 for ; Fri, 19 May 2023 05:36:02 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 23FD98095F for ; Fri, 19 May 2023 09:36:02 +0000 (UTC) X-FDA: 80806498164.12.C210194 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf08.hostedemail.com (Postfix) with ESMTP id 6C7AC16001E for ; Fri, 19 May 2023 09:36:00 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TBnMbLul; spf=none (imf08.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488960; 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=2vGhRrsGDQG1XODk9UotEfGLA1kaizvBUpauFyMQx+4=; b=kzARZVuhLHtr7aF/sBWZVT97ETnFS8BLuU/rQZVgFjwPdtzre60GnSFA/CF3Lvn8Kitvgy hAjgqB/huF4drpTGrS1+aP349iiFHrqkCFlQP82UsMPb1U5ksnGMXwYdfls6Xi8RPVgQHX 22D8xMsXys2bkzirfeJ2xNt3F8cNAlg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488960; a=rsa-sha256; cv=none; b=ePabtY44NAMQXAOAuXH++PUz4G+TwaMj1qd7lMRe8Aoft4By7XdJYmSRmsLkM50IHMrE55 AT58qr+f3R/vu3E0duo3RP4zGiBo/1FW5ELYLUeG15O6Qz9MsLIo5Oeuf8TTsmFs9rjyZ0 5S3jXwHc28rk8Z7TI4sK1pP2v7QrymM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TBnMbLul; spf=none (imf08.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=2vGhRrsGDQG1XODk9UotEfGLA1kaizvBUpauFyMQx+4=; b=TBnMbLul9soaolAwQt3sWNxAv8 S50hIIY4562VCW+y/Cq8+3LO3VrJg96XVVX2EEiXJHKTs9YdOwSZr3vQ7xKMYQq9loacKBMo2TjQb mt2oOAqhwJYf/vwi9ZwUhGiDHZEP+OGyxljgfJPRxypkUk2aYNRd8cRBNC8WigFq4itE5QkV3u6WE k6G4AwhOJicC5M2bn3hgQkw1CEDeF7NprlLZ1rD8HkyWJakLoX2ZPgXlNNx1J6pEwSt17Z1ByP739 zN5MLhg8XrTTTkFcFtuLeIxZDkVu1Lvi1yv+CkNKAggzxH5e0OR08oQL+h60U4KPl67tkcU+vLZ53 YO6mHBPw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWR-00Fjew-1b; Fri, 19 May 2023 09:35:39 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/13] filemap: add a kiocb_invalidate_pages helper Date: Fri, 19 May 2023 11:35:13 +0200 Message-Id: <20230519093521.133226-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: 6C7AC16001E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: wnkgk68z6ujzrbbbyhfmo6b1wm9jmfdk X-HE-Tag: 1684488960-679691 X-HE-Meta: U2FsdGVkX19BK3/FGbQYmpGzXu3vwMyfNr6uJIoCU6dxd+OxgXUXvH9b5dJep8dmyBvJ2MSi2/HfZv9z1I4ik/q58PRtf4i84l4eFnBxivGK9oJZ3ID+x0D8R4iA4kNUlF2Pwr7Wd9wbJDSxVsxIeERc6XPrtA347ytDkMV2NoSsssyb5Yi5yND91S9N97qOu1T9xePSdnP1IVAoKpNwgaYFap/YvrfDKUJrdjmUkuyouIcy50kjrOwCPH4N9v4WvHJfeMHbqQYal3x45qkdN9nA62gYUJEl8qbT/fO0jnUHaB/LL+mrkp/WEXeU7QK7PdXM7CsrEGKlIlw1cfPIxIHaPTzF442c2De1Eg0BuMVPKtRO0YuXjH+SwPGCmn6HWMeW67TTmWN6L1rwkxGOU7gkkc4xDB+ooN0VhEAgFNrZZDWu1YU6pdbuoAZ7UcajtV23E6hJv2utSYHEVUEFKuU4n+IP8b4DN6yDwWa6wSDUAg2K5gPeJGUYySH9bNlZJKqIt6elu0b/tSH9kalEQvsLpKLUvadcDiiNfZxcPMriFn8pXWfO41RcX+JFmC1twfVFkV0Jd50NTle2XEyQJ79KeBqgCAFppZvFKqgEazfrMUXhTgNdbQOzES/4PgAzUvUKFaJPC3ozdTs58xgZhA1vj2UkRGI19Jb2Zo008NOwoT+eAU60nwN4Tgs4k7JVfT2O5+CTDrlb0VSJ0XwCZEPvpPyAToyyb2GFez/20uFxZn0yJeBv+mVDtg4KQL9cKtPOhUF41B8jT4ed04KeJQfwKaPbbB7DkFJVEPVx22rUdurZ5SWgPxGiLsRxcBOHq8ETFDwnVoAATdLl9AboqYe4MjgCHOEfJIMDbGkZuBTUVpRT2p9VLZqhaSDxoF4r8ds8tClDOyXbfUyd/kVbdX7lp8ZCLCkZIEQT7pQ/bameyfXo7ykdrWYf8kF8/EqHPcDpAn4wLmadmaoi9J7 2u64S5/T Q349IJ6/bV6ApTSrT1HIaeeCW5byY1ULlFvOR3AyRHHkLaDHNac5BQmKpPMHViH7Dx9R9GW0W14Q4yBYUovryH2duUb+ITUHncwCWa2zIiA9AVVH3S6O+YY9FQn4+A71lOX/JTKhIdENggGD04OwEBkZfcbNKyVodpZ4+odrTFdJFYxeNvjqCZFpSXfprWnbQDAbrGnKses58IIYZvzMH7mC/vM/f8gkQN3WWGkAiAeqh6Cs6v2bzJB9o2sHWFC2GD/5arfK9iBMrSn4QWS0yXlvxPfHfyqsP4AMlnzeTbcLk+Um8RdNU29zuYVBIokohbc2OYbb4QQGOyOdGHSIx/0yuUEhiObOCN1E9vJiD4DHDo+oiiikH11FynHP4jh8Ty2QTv/DjGpt4gprDav5EwnXX3VCOcabTRoVu/dRcL9EpkTKExm5Oz424y4GxEADV70T6kDmXVmAPvQ8+zbq6GfOzn4zui66SbVLTe6b3YkZ/oy0= 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 Reviewed-by: Damien Le Moal --- 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 36fc2cea13ce20..6e4c9ee40baa99 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 2d7712b13b95c9..8607220e20eae3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2777,6 +2777,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 @@ -3820,30 +3847,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 Fri May 19 09:35: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: 13248025 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 78A82C7EE29 for ; Fri, 19 May 2023 09:36:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CDE4280007; Fri, 19 May 2023 05:36:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 257DC280001; Fri, 19 May 2023 05:36:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03470280007; Fri, 19 May 2023 05:36:07 -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 D61B7280001 for ; Fri, 19 May 2023 05:36:07 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AEEB840A0C for ; Fri, 19 May 2023 09:36:07 +0000 (UTC) X-FDA: 80806498374.11.501BB15 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id E512B4000D for ; Fri, 19 May 2023 09:36:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DqmA7dTV; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488965; 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=GbtEVhZzh4P+WH4HZJFPMpvqDDxXPgcuIWhhv+qk6PM=; b=8Leg8kQ3SVRdQ4eKStO5rLdpVZ8+RoGgFvCcd53WnMb5wJYkcNX5xObYENT6pB/5yMKBjn +hUZbwTu3Kw12Rq7VvaTXEYZ6y+fAzvwe3QXX41EhxHI9hTldGg7q1n+Ci2T1ICu7Sai5a +YJXnxGGavEY8G0OFpU753U7yHIqtoo= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DqmA7dTV; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488965; a=rsa-sha256; cv=none; b=YGlw6vh+GlwjjdxxRcYa6nnIT1bGkXS1YdG8toGJWqZ0V5VfrpoNu7fi43HkNYeej4I56I nkHzXjC1WyZOSbasuslwRVKmRY3WYkU95nholc3qmIsu22+jDxngLAFXFyE7f9Iu5vYHha 9sOLDwOCK54m5paL/4nXnDo3ZcrWo4M= 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=GbtEVhZzh4P+WH4HZJFPMpvqDDxXPgcuIWhhv+qk6PM=; b=DqmA7dTVT68FU40NAJdsxdmoON 8s/SjmRcLhGu/lJi1M5fPke/bAE0vf9gejgATRJo1zuxUpJEhdGw3FmwR1P2R72Oe18XJcUzIJOyY 4qaiwrSWHS/9emssqkgRPz8S3h/CI0f2FzdmoTm9HnpQDQ8G4NmMwHdOVS5LmbnUUDQLMjijPyL6k KuL4nVoWfTnMbUen4VrJnRsGiEj3SYnspKxbC0Tzz4Yjb3lktJSQcHtRwxuRTaGXZ8SFw1KA1OxyS pkniwg11DAgjk+g9anhw1Lz6Vuw1/aF7J5KEsLQSp4gnwDqM+hLSnkAz39O+o0uQRe90pl4yU9eBW DZlsgkVA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWU-00FjfV-06; Fri, 19 May 2023 09:35:42 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 06/13] filemap: add a kiocb_invalidate_post_write helper Date: Fri, 19 May 2023 11:35:14 +0200 Message-Id: <20230519093521.133226-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: rspam12 X-Rspamd-Queue-Id: E512B4000D X-Stat-Signature: 4apmy1eyqi8fq7xghxfwnx64efrroaj5 X-HE-Tag: 1684488964-223449 X-HE-Meta: U2FsdGVkX19Z3jxm9HZC8bAxHxTsWEnu8iGyAss4e5xgPK5Z0ONAy6veTSPL7IOIK8Lq8sDthrT6CRFMVIvaxuPjJPvFYSn+MQcQJj3GPEUhILZCDryeSGAPXSR+Pwbhb5dsmggz7NkS3Gb/cxl1pa+I8EDxyfcRZBB0QfLnHE7jFp1p/NcrtjYVO8YaWNWfK0HLtj92qZWrtwOm3n7rX/coHuUbS1fQERvkqIyEOUPv73fDvSbBbgSnJO89p+NpKE9GvNCfXKmcjjKA+ZUoRp1LdMD0oLomPyCOOmowtAlH8zGiCasZUIJ7+040EkADARSnSzs6rCdgYUF0Rwxk7puYgHFr7kKrU33AVhfYLjwprpZlcE1IMIStyRcPL/BYTqcmzvYkWh3OYTqGZDvZ9MtcuyHc+s4y7W1Pi/09yD4JmY69ufsg5GoaAjAoOQMKCvOngikoRzHKmTFwowiAf6/XOzh+xcE4QPV10V5Uw+uE9Xoo1shk0SbkJLSQNRcEOrwJBzCFJYMrJ2I02ricRQlCP+MFKr+6LjIJsTJdZVdQFJ2k7WAIuf8yCOZiZiwLAQkFuZkbdmQzRmQ4pDt/C0lQBxsGQXZcoTRRCcDr1pcAVhjZ3UNsExU0x1JI7/ZHPLanLfT2lbmEZkFVwAKwZVHYwbR1C/Lo1PtyZG2YopBrkFZgl5oRVrmkLMiS3+DN1K0FAVwh9WgbbXJmjjpobj8dOFlW3RAMeg+QJgjjIt/Rcd2xkGF1gN0lELnUmmHOM5/pnOpLnxDeY3ZHVf+ZCBGLXV8hXgfMdUeCSKewhoSfyHPDogTs5OPj3apXxEC0VK76a7/bNN9MWt+i5Jz05j8VlbKdaxIpI7aVwtPMXz/o+o8b4LrFpK72wxiLEppvHW13SAzaoDSyybrbxlia5y2SCAsf/72NzTjZ1W1et7pq2lGt91DArS9J9T+NL6PMrQnGY3L7cJOy2ykM922 MegzDaO7 3iIMyxYnNR0iix4QcC0lsy1yX8Zn1URhdGnoI38iEacYA7TeE/7C3axnXbiN19+Uidej7jdLBBrILIMn/J6kB7rv3NxZkbTNau02seaskm+9Cp6dDt9IpR42xJ83hznI2cXSUEd/ImkeWqXKITX0RExFrJKHDkKfxtSp0TV+dutJ+izdnJnCna9zvjQwuOvWEkapFfBy0FZ6H2bNm6aYqJLdLHE5SwcGjCJWDAfMK1IKMCzjZbHp9FLzyI+HNaZlw2YN2yYtWM9NHo6EEPKrwxOOHegsjhFFTWIl3UVs/TQgUYyZBiMu+o0v58DkaHu1DVDR9wiJBNu4m58IA/gz0XWiA5DDDK7kSQOtL2nmCYqdiGOx0bx+4iJ/R7rzZnNbOUS2hgva32DNaDdOafIuWJUogs1gBkSAPOrhOJnkCGQ80GxVC6yeNRjoe5eYHDl6ZXVQhlu3V0lCBQ/JaOcZQyXX9ZWYee3COS8JZ5UdwQ5itBAM= 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 Reviewed-by: Damien Le Moal --- 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 0b380bb8a81e11..c25d68eabf4281 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -285,14 +285,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 6207a59d2162e1..45accd98344e79 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; @@ -108,15 +107,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 21a98168085641..e4efc1792a877a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2837,11 +2837,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 6e4c9ee40baa99..9695730ea86a98 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 8607220e20eae3..c1b988199aece5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3816,7 +3816,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]; @@ -3833,19 +3833,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; + + if (mapping->nrpages && + invalidate_inode_pages2_range(mapping, + iocb->ki_pos >> PAGE_SHIFT, + (iocb->ki_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 @@ -3855,7 +3859,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); @@ -3877,11 +3881,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, written); pos += written; write_len -= written; if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { @@ -3892,7 +3896,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 Fri May 19 09:35: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: 13248023 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 A79A0C77B75 for ; Fri, 19 May 2023 09:36:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 98705280005; Fri, 19 May 2023 05:36:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 910A7280001; Fri, 19 May 2023 05:36:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 787C3280005; Fri, 19 May 2023 05:36:03 -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 61898280001 for ; Fri, 19 May 2023 05:36:03 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2E6351C7961 for ; Fri, 19 May 2023 09:36:03 +0000 (UTC) X-FDA: 80806498206.07.186A1E3 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id 3DF3BC0011 for ; Fri, 19 May 2023 09:36:01 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CJ+A5Cuc; dmarc=none; spf=none (imf10.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488961; 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=jBsLbOyW4gxJfboFsPaM/jr4wcWxBT1Mri8F0Ud0gD8=; b=8UuEvZgn2E2HifO4C++rwgIKEyUeQyEwKqjvRTuGl/MB06SKVpl3L7H0AOROhRXEgA1RbH hfiDNT8QOEfZHvAJgxiTaKHX37qyfUvoMFmw9eGZ2ts9Plazo5lzNvp6jMEjlMC0lBwEFy +yUmkNyJGREHAftJaePJrrD0o3aEsiY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CJ+A5Cuc; dmarc=none; spf=none (imf10.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488961; a=rsa-sha256; cv=none; b=TgkgIsGKMwLrzVU4iVk6O0XICF9jUf9RqgmAB84wcK1v6JPz5sEqtx22TLeeyuc4jBiGyp EYCzDF057tUbanmovHlxYHiCwLey1e/H+HuaCWMIHT0AuUlY27ke4UopweyYiv2s7CCIDn gVCM0kwZwSdUZ5L+cTMZfChsXkxT5ug= 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=jBsLbOyW4gxJfboFsPaM/jr4wcWxBT1Mri8F0Ud0gD8=; b=CJ+A5CucslKF05xEph7ZTKtrZ0 2m1gkbiYfzpbtTt1XTbMs91Z6sBHAPMva3XLcVNtvCKv+5A6Yt3jZeQsnaQfDhtMWLLz7dmaTQVZ7 M09DndXYZgSi3F84aM+aUrXASh0lFIaychMModF2k0xSG4po0YGEvtMoBhLtzic+dHU8AqxyUk7nq rUT1Lz/9lG68YM/Y1UnQTYM8Xu0RsVv+sH1YXWxHCT9P5xvCDmv3wB05YjcuDoGbnPzzlAJaKcdQl rzznR1GintoXSsaocfkeJCe2ZH8w34EK+LZ0LW9n/Nu7pOWNGYOfKPfWYZVwB0Q+0Z040kY30qie4 cyio+LIA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWW-00Fjfv-2R; Fri, 19 May 2023 09:35:45 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 07/13] iomap: update ki_pos in iomap_file_buffered_write Date: Fri, 19 May 2023 11:35:15 +0200 Message-Id: <20230519093521.133226-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: rspam12 X-Rspamd-Queue-Id: 3DF3BC0011 X-Stat-Signature: 3615ecdmp5mwo44sdfifac6dypyd41ci X-HE-Tag: 1684488961-435935 X-HE-Meta: U2FsdGVkX1+eErU+WBd/sV0alIVXQs3RVsXx7Monp+1Lv9L5ZVJIQ5XxS5WEzv/U0MZWCDkSjSBzIg+bc+mkkA4Homw5zpUaFTiHQaRsJ2eNl7WWSusUpDR2E6BnXdx9DWc3QPonjRK9w8QENEpeqshre5CrKHq0i/04kDnvwMYyebWDp+ZzxyCU8byo/phzzvqhrs4qo35acBh98wXzsuGtbMnXZieLoUAhbo3RuFoHWF2hmSGRKtJDVURGeJj+8QTSrCbBJqkchbunkzN/H97QGoJ040wGIDYPiSCsGVHgxHnhW0DfPJyLuakCg1e5MtU/1udr3jFhicEOXLTX1CyosO9Co7vF4Ust3VaNgmauNT1hKEoX22dL0DnoHG841ttSlrkRaWls5zJ++d23Y0N0Qq8XhNadaSN6SLEz98Cud3ZjvoeHJXZNzMXpKd0SsYp1beaUm6HJJClSE+W6wJfPR0l+dR43WAj25H6lL/KEFGKOp//iDbeMc/I4nBU9SPqRJXCGSnY/iAXQbbSSy/cqvzgS9JVd9aYr0CCASBNMpgcH3Zv99Gnf2cEbb3z2XWM7RlGW6sjAaUpQeJIHgpK3bpnNVXtmK5BxzE/Ex1TV8kzMyNTKg4ymkobt6zLNa1CcRIW0aiZb50WyojgOCWuU8uTIKP0kr8b+Ijo9xxR9p/Zw9qKpoU9uknkL0Lc45Yvb4RMCMh3FjrIH5vnsFEL4NMAA33JLerrwnIYj5TnHh+vvrBq8K5DQDaBgVQx+kQpf/WQXClPXOhgB/wVsYvUiURXjrZxjHMofcbufIPi0+OWNkGu2u+Qzrq/fLNykAOqvirMDPwElLujaHYE4YXX2PnZ52t4NxIOeEc27ldD2FKB2su8OLgbNQfc0qEkVv4BBGwSEAIPkBnRpRKwJnQY046HwcZmgJdXRl0UxtYNTXy806ef54ipKRYP44/XbxM6zNLnEjoOCJjUnJew jGBon1el Ju+6EtXLJafA07J2DP2mnqw0XY4jbtfAtjIGTu3Iy+TQI1kBJ5pcJfRi6LHxarldq4R+Fihql2KU6wrkum1ddW4lYv+CIkMqesj5h1kRg0RF0FFageCH/LsnW9eNGOLezhxhJ0IhVbh1SxNAuNETHnUvRJTrtblnemfjiLAINZvaOEHcISeLVr2vITAx3WHE7tqVPSRlsDDIvV4TFq/RP1/SqXJk/MehguQtrE2/fGvbQ+8rAG7CyjeY/vZ0TOMcHh5+6PieXJCKZFvw+N/gMS75GO33BjEzGmUKEAyUTzAmQX8PmXBdDXEh8pmGwniSu25goiR9Y7KQdBS621RV2Qx35+SkYur6ZuG0bF+WWFdbHo7k6wsnk8wc/YZidTmSP6o1yJvaewZdNK/IDBwOgKluSbMl8pkkJD6tt6YsEL5Fvspcm/0YSEAaVpHwwNWRpnhl9nvpP420jx20xOrON5d15EA== 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 iomap_file_buffered_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Acked-by: Damien Le Moal --- fs/gfs2/file.c | 4 +--- fs/iomap/buffered-io.c | 9 ++++++--- fs/xfs/xfs_file.c | 2 -- fs/zonefs/file.c | 4 +--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 300844f50dcd28..499ef174dec138 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1046,10 +1046,8 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops); pagefault_enable(); current->backing_dev_info = NULL; - if (ret > 0) { - iocb->ki_pos += ret; + if (ret > 0) written += ret; - } if (inode == sdp->sd_rindex) gfs2_glock_dq_uninit(statfs_gh); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 063133ec77f49e..550525a525c45c 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -864,16 +864,19 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, .len = iov_iter_count(i), .flags = IOMAP_WRITE, }; - int ret; + ssize_t ret; if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_write_iter(&iter, i); - if (iter.pos == iocb->ki_pos) + + if (unlikely(ret < 0)) return ret; - return iter.pos - iocb->ki_pos; + ret = iter.pos - iocb->ki_pos; + iocb->ki_pos += ret; + return ret; } EXPORT_SYMBOL_GPL(iomap_file_buffered_write); diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index aede746541f8ae..bfba10e0b0f3c2 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -723,8 +723,6 @@ xfs_file_buffered_write( trace_xfs_file_buffered_write(iocb, from); ret = iomap_file_buffered_write(iocb, from, &xfs_buffered_write_iomap_ops); - if (likely(ret >= 0)) - iocb->ki_pos += ret; /* * If we hit a space limit, try to free up some lingering preallocated diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 132f01d3461f14..e212d0636f848e 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -643,9 +643,7 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb, goto inode_unlock; ret = iomap_file_buffered_write(iocb, from, &zonefs_write_iomap_ops); - if (ret > 0) - iocb->ki_pos += ret; - else if (ret == -EIO) + if (ret == -EIO) zonefs_io_error(inode, true); inode_unlock: From patchwork Fri May 19 09:35: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: 13248024 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 8F776C7EE26 for ; Fri, 19 May 2023 09:36:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25950280006; Fri, 19 May 2023 05:36:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E19E280001; Fri, 19 May 2023 05:36:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00DAB280006; Fri, 19 May 2023 05:36:06 -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 DED44280001 for ; Fri, 19 May 2023 05:36:06 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B6DA2C095B for ; Fri, 19 May 2023 09:36:05 +0000 (UTC) X-FDA: 80806498290.21.F7F5412 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id E37724000E for ; Fri, 19 May 2023 09:36:03 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GayNG3kz; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488964; 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=DWCBIuCWrEPUSgFUMsFJ6qSq1T5QDjJd5vFpRCChJ1w=; b=mgVNwDbO03lkKa0LBOfiTno7HC46fs18X8cDRZsvT7D24E0SZliyrjzj65huMZIymlGndp aCN/xPDeB1LqopRFliXSmDPpF+zHxT8nnO/zy3XRz+LnC6VKKLcORwKZuOuXujY9QPTLr9 BXGlmKSicIxZT8+E2TnirNNA2bNOBQE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GayNG3kz; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488964; a=rsa-sha256; cv=none; b=Uwghz/1VTgkjpPVmigw+pYLRFsDxG3PfDNTyx3WV2acpNitlqNlHRX4t1ApWlxgX6hSBwW bYzlvPUfrQyj1lQVSYWJm7WuTlCBveSeqtOIiS3VI2QsY+0mqdDL69czK3ZzrwOhE7PMvQ qf9b7t/Ld6/Wid55r8LHcQinfoPA1Xo= 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=DWCBIuCWrEPUSgFUMsFJ6qSq1T5QDjJd5vFpRCChJ1w=; b=GayNG3kzJFJ5dJ+3pyHdgpJaHg Vg+D3WJSisJRAfKh4FdM+kMULiHBkVK2JlSjPpe6AWhhM9TnhNcnVYwVNicVKsW2D6CwQtiNr4GbI ifi8oL59NNJcPyuNM4H5lL3BQg0kUH1IUPhrqcRX4x0gkGHePahAMpgU+OMoye7IWbL1i4P4N0K7d hPveIYGdIaP1exiwrksrwwox3ggk+6PoAmRpABmAJW0vLpX170W8n4+WiyOMWiWdUV0KUHViDPR2V y4iTj0Am5OrXwsAxT9LSL8UdxWNyTm0g69FXTbp/zKBR4iorevNKqz7EDBD0kG/pHeghxQmsCy7c1 7dhC9L+g==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWZ-00FjgM-1F; Fri, 19 May 2023 09:35:48 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 08/13] iomap: assign current->backing_dev_info in iomap_file_buffered_write Date: Fri, 19 May 2023 11:35:16 +0200 Message-Id: <20230519093521.133226-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: rspam09 X-Rspamd-Queue-Id: E37724000E X-Stat-Signature: ffx5cgng63kh63ep846oispbuj4jj4yj X-Rspam-User: X-HE-Tag: 1684488963-270363 X-HE-Meta: U2FsdGVkX183iR8KKW8PNVmCY0ZfvHS2waOWTjS3I3W0GKgkyo2OX+IDdRCb17YJ1+FfxuLWjoYYi8emsS48WR/mABm80he0ZmzKS6muyYRkFU21gpchJX8B+p2Cb/MorkblmqlbbbEJmQpQ8n+f2o5oXtvTNkcBLYg+HWlMcpIIIMHhcdWNU1hihvE+BXzoAv7zAYYsMy5nQ6mYC9j1mY7u1T390IoWYTVJym9mmbLfNy/foYzqdmau3Pq8H7DvkCTPhbAQ9ykhjnhM4d7xv/MoFk10+9c9Xi0oHsmcgpQqI3+E3fiZpfYtK+a/a/6Kb6mwC+LWCvgvC4SAIO1aRPhhgLgHZ3uuAhv81nj1soC1rdkkycd8xgzP9ETnP2eHxFi4TIaDCLMOPJEWGXhOCjV6IdhLGBBfmm0p1294gKS9yQI74A2SKCmiL+u2Hi3Q2AwSnOyRzxMQjv+KS692dtXxvd3+oS1YGrEe0a2vJVXUdRlBBmvLy6hYPH8qqe2P+4+4A37bNta8KxIkcaozgVbmBwWRe0g5INlYagvGvZsGhizUizExPI7ihp/3zyhAKyV2he9AxPnIOQc5+7r7DY/WjGdnhp5N8ZMkXh4L1F0q7l21AtTsCZWxvbnM1Wolx6XcnMkXYSVjsV3qMB8tPnpa8Fnln0gvi5VkGTx8rhpt0MYnTl2Gf5DBx+M2wvIP3qk3gjB75LHV5gui0tIMEs1XVp7m7U0HiJcVSu81/yDUYMv/V5DIymneC2WFOuYxTwf+NOIwPDdYlwVw9j2o6ES6cFuFYWKsgBQDqD400GWTqAQGvR2TQUfUnzo56g3ouyhkaZ91/hk8WiouQiW22G2Y6aFGj+UW9IjNn82DT0/uKcDME2KcRfxzi88N/vLbHLm1ihM40m7VzhzkXF/IJDzIPrOfEUWielaIH/fkCSBoTi8kcosIQILouPbh+if4djnSWBTM7aT7zPvT2Hb S5DzwbGu sz5xCRO5nM3j5JslrgITju5Xz393HOlCIZ1WhpegXu7TnBeUj4OfWwPuwTbmFAmjC9J9IRtx+sXbg/YoKgy+lw8SJkIZ59mKcKmxd4Tl4Y253o5bZuj+5gFhynVFtm5ILGtKYdnnnjk0fBhQn41M21ESTcyOwq3Ll2v9K9zRJSqqs0vc+Nzp7a0tSzgU0yBH+hknDr5jDuKAo/GOs3lR+I50c7GnTLg7yMsuRyPBQHd09jDDlCvczMSkyoHW1TVDaLoHIkTAnecTCtIMiKUbMQJQhDxgl9eSEgMOvoqrntYA24JXip0zeorhrX7aKb44cM8GheIoRdmcIwTENHrFbNrDkT6+ilzKIvO4ExIPAMXHoEG7ziCQl7qPXO4nnMNSx+RmH7DI5VZNXD9Cn85wb9Co9YekANZ8IctzJds9cbrjJRAMbjH5qs2IFjBppwteDHif6DEKHEPtg+JefYpwlzzWfTw== 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 to reduce boiler plate code and reduce the scope to just around the page dirtying loop. Note that zonefs was missing this assignment before. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/gfs2/file.c | 3 --- fs/iomap/buffered-io.c | 3 +++ fs/xfs/xfs_file.c | 5 ----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 499ef174dec138..261897fcfbc495 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) written += ret; diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 550525a525c45c..b2779bd1f10611 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 @@ -869,8 +870,10 @@ 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 (unlikely(ret < 0)) return ret; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index bfba10e0b0f3c2..98d763cc3b114c 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); @@ -751,7 +747,6 @@ xfs_file_buffered_write( goto write_retry; } - current->backing_dev_info = NULL; out: if (iolock) xfs_iunlock(ip, iolock); From patchwork Fri May 19 09:35: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: 13248027 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 A1780C7EE26 for ; Fri, 19 May 2023 09:36:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25943280009; Fri, 19 May 2023 05:36:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BB6B280001; Fri, 19 May 2023 05:36:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00CB5280009; Fri, 19 May 2023 05:36:11 -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 DD341280001 for ; Fri, 19 May 2023 05:36:11 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AEB0F1A0A01 for ; Fri, 19 May 2023 09:36:11 +0000 (UTC) X-FDA: 80806498542.13.8FD0C08 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 0DE601C0017 for ; Fri, 19 May 2023 09:36:09 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="pQ7KSa/8"; dmarc=none; spf=none (imf20.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488970; 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=g0XZ1SdajcGpQ1AF9r9lkRdRsXz7pcMVrMTOSW6r8Eo=; b=7Q3hlma6+6eSFASAl9ZoO7+zsxwkJ0cNXbpfeDs2cvhe/gmXHifsfeUWEbeTkQ/IqlE01W 115O288ORXKGKC9TMWNBSxMEi6qVkLoHlFSioLITSCpXO1q8QV2feTsRoVmROhCJZXlwHA PucZNim3mUtDjA+//yBwtI/psoDSGzw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="pQ7KSa/8"; dmarc=none; spf=none (imf20.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488970; a=rsa-sha256; cv=none; b=L7USJvA+1pIVRzlfFNBnhQNVch7Bb0fJLl/DyRGKqpCUxZTQuADfGCsMiKQ/jb23igxKSY 2tNWCe5SR+gceGg49yvuobcPWDzowaWx7X3p+zWnQ/epFA4B4XoBmQHEBEsUS/j6verHBe yxs8vukfpKkKiOxiYyYHkVANdZAPPkk= 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=g0XZ1SdajcGpQ1AF9r9lkRdRsXz7pcMVrMTOSW6r8Eo=; b=pQ7KSa/86Q7HW7fROWUx7jCR6O 5XFMJ9iXKvcRSF09WDb7T2Oe4gvkeIhaNzzaxy6czyIFHufAKCGsQQXKPj6V3g2+Yh3xCdmhw8Yem xgj5RovMsJ5sb9CwXmpuBgGG47h6W14hgsw8meXVfD8srvupuYd1wrBTP29pKyg4C/aN3aYMDx30V 3F+s9l05Pu0Nj8l8G8vVeSaGYZTNPRkhzs8LqCoRz22GQLqjxNh8lLcb8lcq9x99NvHbkhc0/jELZ O9XVqtERlrKY6QQYh73k45QPJOqZSIliql+BFfuGqGfwEgWEqLQweYUs7+GB+p22ORdFXz0Af4uz4 UCA5bGHA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWc-00Fjh6-1P; Fri, 19 May 2023 09:35:50 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/13] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Fri, 19 May 2023 11:35:17 +0200 Message-Id: <20230519093521.133226-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: rspam09 X-Rspamd-Queue-Id: 0DE601C0017 X-Stat-Signature: q5r5186ttctmwgd1es3jmedsx6dpgotn X-Rspam-User: X-HE-Tag: 1684488969-815320 X-HE-Meta: U2FsdGVkX19QTatAvA4e1z5Nm3cZncK1V5GMV+hEMhJpwqx9idBqYse1Vn3jdGfcmxNAB+m8iBomwmgSnNfTM/eGSrn54HR3vtaADM8mPowlxgrpEPlKRpoEMYzgANZWYhm8Eb/40vAVzmZyvXd7NonNIXKxMt2y6OwRjg8RslfjB1d7PP6YmatCoVk0vXAXUauX/3grg5q3dfFkyw7kHtBokRj9KB9dYlw0G5qS226725jf3IE/7rOMgHYYKpizgk7meyYBAd7l1t1GymbfjjUMAdiJRqztNHmMlnMO7eO44qhZn1Bh7RG9Z0jmm+x/WCcCXtvA1TMNU775urDnUjlTLjILCkvjhqqDXJlx1nL5GpqZasyxomQqDR9JSwAPDwGHPfU5htCDoKC+IQ8TTXp32SYhv5/TWttUq1/nfrsPFrnqKmm5P5X9qQ/akRruFtUfyK52iDVT903n65yn3KeD7B4WN4qyDHyzHZjHXOZmomyukWpbhTEiWD0Ml0WMuy9ZmG9M+DPgBdTGuZSu7XLbOfSMcEAFbG5EaG04NM4edfwVtfK/N7O+D5ugOvSnXo+gRtsaF3l21Hl4LSPtyAA3a1LQb+g1UVyyBL98wsaNE3CmS1xYP5qoD/2UyrJMFRozWeEahfe3FrGyjKOZ4PHmLhqnFuSR66Jyfsd1/BbSh3icUvwhjv7siQzAIthE/JB7PanjdMSwTV9P9oNtW16IBAsMRPjxjyEN7ESgF8mDpbXrg0+3Z+gHP8O6O2QwNHfiSAZRHpuZV67ML8UXPa9yNTbEVyhudcahV/xLpUQvM0p3xZf/D5furEtef9hLy7r1eopVC5i1WuISE6ECUZPCzdmfNewzqaNT9XAOAxoa5HIsWMzkuQXwjconCKvUJ6a4K0t40haLIJ7QQx7lYQevfC0wYhBqtGEREI8YXziEYInLBM35mN+6yzV9YpAuB5K4gPqB/2H5pclVfSe vCAiAScB zpy/K+/CrnWAIQn04N9pZPaW5lD2TE72QDzQ4JeXkTT9td56eQO1vPLILUJhT+grQOW4eZ5CVoDOxIe7g5h+Z4VGZCYDAoE6ErZy7X3ufA4fnDFNaF9EchM+buj/5DPiAaU0Emo4tkGnwtU3PS/YlMvLuufs0zDh6d9xk9wAfTrVEbfGbgT+SYbTOHwKxyNx9nbV9azea1x2dldQpZ8ISLrQfrY7TvAOd5jmvE+Frz1azQtgy6we746x6wVAl6LOMtbJhPIMfll+mOea4m03ZmSf7QEguLELEWReyUhCulH2g8jsXpZTLR5sYdC4jdpOOMMydqSpRooJ4JCW5dV/g7L1+rgb5eERRMIgDynz13exl5EZKhdmjCBnbDI+b7euRmSvX3HuiXv1Dmpa9YqwYjoMlTjYUpbQwwsB9ykmR+Vows3wF8uqTQ5fIHBSKCjno4ZKaDNjIvX2beTRk976A24+FXw== 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 Reviewed-by: Damien Le Moal --- 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 45accd98344e79..ccf51d57619721 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -472,7 +472,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, @@ -481,11 +480,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; trace_iomap_dio_rw_begin(iocb, iter, dio_flags, done_before); @@ -509,31 +508,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 */ @@ -549,31 +546,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 Fri May 19 09:35: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: 13248026 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 0BA15C77B75 for ; Fri, 19 May 2023 09:36:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 899B0280008; Fri, 19 May 2023 05:36:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82467280001; Fri, 19 May 2023 05:36:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65067280008; Fri, 19 May 2023 05:36:11 -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 47849280001 for ; Fri, 19 May 2023 05:36:11 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1D682AE4CE for ; Fri, 19 May 2023 09:36:11 +0000 (UTC) X-FDA: 80806498542.14.100C85D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 676E540016 for ; Fri, 19 May 2023 09:36:09 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wuR5MfjM; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488969; 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=bXtYYEEzQwvZPWpQse6yFS2DlWFyrRFvHXQe3dgGWLU=; b=qmRj2cYVd628NxxKMuXerPfrh5VJywdAzt0vHWeFNXcBvcXNYOq3ceBweTgJ+EAGPIRPiR C0358ehutd1G2od77Sti+dVp1GLjfNKmfG8Rv+74pB4ykt3XF26yvKlEelFAiX8jBWjHQS Z+xNyKsomEwI0pyoUwBu8KDOLbUWjWA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wuR5MfjM; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488969; a=rsa-sha256; cv=none; b=n3Qb78SkyV8kckGdMUjoHZ888qeTmzYyjdsts5T164zVVfCOv71iTj0Ou+9QKXIHXZ4kG8 0sl1XYs+z9IiyeuSci0fGI068BGOBc0URxcFGHCqG1dI27KRYFZsgjNTnUJWcwaHF/ojI9 kpx2cCklalWg4vdgcGibF+zvd9sUA04= 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=bXtYYEEzQwvZPWpQse6yFS2DlWFyrRFvHXQe3dgGWLU=; b=wuR5MfjM+D3bTZWoEm9c9T3FyQ Jue/kbHK6tmzfma8e+SaYSkRo0i0M95KfzwDKIl7yAZarwpeGlFg8SOccbWg+5smRc3AQ4HdXO5Wr nxv736/1Pra0TlJRc6gOvRj0yJnIoeus3Ea9ZcLZX9vsbfDhxOOcJdu2Sh3OLpn1iJaVfJZVoL+PO 6JYYrGM32hNNnf9ay0x08Yy8FXV4AEv6azjWxZA7R3S8/gudYOrARKgoCUAPoEHO6BpLCM3Eu/iHd Ze6v9o/MZ4FMpWwAoU8d5cZ1OtyW+xcKH2yx0ol+dIujh/Uz9vLoSMKaWdOFEP9SsxpBhnAOmgW1i fsiOwFhw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWe-00FjiA-3B; Fri, 19 May 2023 09:35:53 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/13] fs: factor out a direct_write_fallback helper Date: Fri, 19 May 2023 11:35:18 +0200 Message-Id: <20230519093521.133226-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: rspam09 X-Rspamd-Queue-Id: 676E540016 X-Stat-Signature: 93f1uo7zth1639z5oeyhcqibimhy5y8r X-Rspam-User: X-HE-Tag: 1684488969-273761 X-HE-Meta: U2FsdGVkX18rzn5ohzgdeS29s4ly2krHxxvX522VFBiU6pT+0PNWtGiGCAraHiMLhE8bs+bgde9e5TfdMI6BrpcZEA1e3xqNKyzWSDUA1tZ9xzRmN+ppkrE6eR5dmcASl3NVmNjawCEGGtlHD7eSpCiJI3eDE/JXZUSaSquS4RmNJXVpxolayAb/PRZUtCo9mO7RO+e5SH7cbmTkAprtrlMFyEgTCtgc/J7kWICkusfp45WheiHAXhAPKt3vp/VmXEltgrG1DZ+FuscZ9m/M1+nvJJOtGL/V+XHC8RZUDUZchhg05Peou5yx5QjuQBkuxGTq3wIrfcJwiVxtT/XMYv5+GgGWf+hTjMloEjvXG3mTRJRs3/iwjw4OK4jX9BOYoVqlsPFAr1fsgCYw44y6iYrdxhCIn2VnrB14HwDkx4urn3rzEUVhi+EMGaz6zJ0AQ9K8/hp6z7FARLZxKHT9eV2iwVc0IzkdNNtUX517lym5qs9px1UkYSSyus+TuojufTcS7BU4/MwzRHngSXjTduzIkp16OlM9/w7si4SgWWrEnOuWV2zqjDzO4yDPZR4jmRBI7utL92WF74U0wiTG6EiCBw0PQBg8kvhHAeY8AKK1go0AUbj4s7rjjwli4EQPX+dyzbskBOnMduUFEW00tcPhjiEYEFf8d6dfWOu4sAvzpch0v6HA9+YfypW6E90XxXpUnVrkg3sImvIHXbGwSIdxDq2SYgx2jj+v7jRj+dEETNM9pNOxHx+9uLpybLWTx4InsiYvZwQJ7Mxwak+PudRnLKel5e8bCKXpf4g71Rp6QHxt8nqOjfd+yreQ+5l7IGWyziXr0V7koOUvxTYMJ6FUvpvph2JIyMnYdh3HJgqz/yHYCwb9X724TpGbvo+h2fmbHxSVeynUS/93QOTcafw+KfjUJ78gf8G9EMiGBn1nrNQ44BA2rZlABWB3nJGV08S8meeVd6KTB6R3RN3 ReB9pRR9 OzOAR9qRLr4F1OPE/wGpktmoEYWsuSUpcB8ii90qR2fv6N92k2vaV6pt9j6hW4O7sy6958bP3BVcYskWJC7fZjvuB/HjvYg4Y1foHinodg6CQK8YE63XtVpPoBz2jebulBtSlE1uT/bI7LTGAd4LbHC5S2jXWUZVHMN3byfuGRReCPY/iONcXowlaLlu1OyY61Vc5NHlBIXigwI1nDMGDsQyy44gnUiHJBNsVjJOHHbPK1rjxeLRTWWXc/86RWkQBnrqsIlh3ka9KiP24d388dz6n0j8mXg3G7+HJyjhkG0KIrNL+A6eCxwF+C862gJ2SWmZpDid5TM4KuZBg9w7qDQNwEHTRcKs8jghET+Ns61W9HNKd1ItqWYuVEudv89uOtKpDEwvZZSu4/cY+CE+w8meaa2VSiuJbyYkzfpagdedjNZ7sh1/52bM792Cty454/4AN7RtDjjleitIG9wXx2POarw== 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 Reviewed-by: Damien Le Moal --- 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 89cf614a327158..9f3791fc6e0715 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1613,3 +1613,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 e4efc1792a877a..576a945db178ef 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2738,6 +2738,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 c1b988199aece5..875b2108d0a05f 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4008,25 +4008,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 @@ -4034,46 +4030,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 Fri May 19 09:35: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: 13248028 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 66897C7EE29 for ; Fri, 19 May 2023 09:36:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDD0728000A; Fri, 19 May 2023 05:36:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E64BB280001; Fri, 19 May 2023 05:36:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDE5A28000A; Fri, 19 May 2023 05:36:19 -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 BBEF9280001 for ; Fri, 19 May 2023 05:36:19 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 939C91208C2 for ; Fri, 19 May 2023 09:36:19 +0000 (UTC) X-FDA: 80806498878.10.F62896E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id DBDAD100012 for ; Fri, 19 May 2023 09:36:17 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=jBbC+jMl; spf=none (imf05.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488977; 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=TKBAB7v33dbYW3H4NRpBXoH9tha0ccQ02cfBeOuFf/4=; b=3zW7CaIN+oleqAQdkUy/4cYnPN34YPygFDsZGyiAOEPU8LdZoUWAX8B1IXrWpWAc8qWmb5 R/SEOaiVvgYmBvR0Iz7nONRu4+EMeWLK7UIC4oh2eIZQJ5bbCpx+eTqCPvUucVL+RU7yNv WKmD8oCF9fYB8GtPnyiXR6ySvulljQs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488977; a=rsa-sha256; cv=none; b=zeQT7GCkCfBDIN/cUaMDBxxMN344iOZDXL4SGMWgXI5kRB24fT54EhENf4A+XEobCVVHZp tX2wat/0yX0vWsx3b1SSYwV7r5iOvfDGwGVgTq+KdlvYkZVMRDnSJV8MKFcwQyX0AN9xtf qgLoSNGPm8B0KcRTcnKWCvlekM9oy/c= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=jBbC+jMl; spf=none (imf05.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=TKBAB7v33dbYW3H4NRpBXoH9tha0ccQ02cfBeOuFf/4=; b=jBbC+jMl9D3UjfJN7p2yKZDP/I WbBFLIN3Q/AJih3OxKSHbTD9vT/F1tJobu4KuSjWuiUGnD5rFBmeuEaeD/Iu5pzKBe+WoF0cJV/pR aHdHe3VblJTeUN80/WZVfFkLjN2xPcAqkhJGTHlmMCBAXleLOTmJaaYavT1/S9aM9V0FApxTI8BsN kq2VaEl7CyULWIrWWkY30KLE99zxPFDr6mlVbG53PUvDT0Owj+1Oafd0P6BmL8cNhjdjQCmT8ZUKw mgdHI+yL0Zy6QHpBrK9tCvQI2IS8OZd316ApM4Rm2MZrQDKXQ1/k3sGBk62SyeqnLCKYpmESn7t8M izw91Nrw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWh-00Fjj0-1m; Fri, 19 May 2023 09:35:55 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 11/13] fuse: update ki_pos in fuse_perform_write Date: Fri, 19 May 2023 11:35:19 +0200 Message-Id: <20230519093521.133226-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: fx14dp5xj1wgxjogt1o3shtrb5nx7edz X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DBDAD100012 X-Rspam-User: X-HE-Tag: 1684488977-475263 X-HE-Meta: U2FsdGVkX1/R6lB25bIhPykOnehP5a+G9LtkgiJd6t0p5ucDl9ZEvwYWAvGDoLaETtBUoUVdkYgyZ+WMuVeS4D2eKNNnn4RknYvEDqPN3fTXEWNUqk3nK70hZk7Q69w2TiL8EZYpcOW8DMveT9LgBag9ROnX3H6XAh99J091caGjuX7W8W1gl/vNeO+9NOI1hML92XarpONvQe0LPRvcolTQhm5yJzFUDhBUC8D/HPPr2H4fDBI00brQ9rLBsOUVPoFtH7UiFQMQ6ZmE+ymRE32y5mvuGETkjqVS9BoFrL/H5CW6BJapy9FnZa3Ezd8WgWaDzXIPV9v3aFCS3zvzdQp3y6WC0O/HVmLKrX2DuFUhvuWwRnAOw6MF3yrm8HwS8VmEK62KdgN90siUStlScb5/dCwy+dq+yqhoEfyqEkWRugS/WmNQoNoiUhxr6BEI1GieHE/CJ3U2LI6zOO2+8Pn9dW134TZ/CmFfyn8vK7fOTFiwgDp86Kk5Pwsf8t9rSHg8mYc/SqWqi/SnRAteSz6nS+U7SEA/zLyucGsQjiXmiiYpWgPxbjSobkYSAneUHEaNKfU7651sB4Fp/FxhT/EvLJZdHSj7EMEu7SQznSVaq+ECny3Lga0+YrF7hanklIrC0Nvzp+J+XZJtrrRxyANLvzCwdKASFw4iiXORT06EyOE+ajASKQuYBr9AfcReFE0BWBil0gZmcSUG6ReoqpMrBuBfyV3lK4O1r61McPKcI/BCtcY+IiOxrB5UlIltfyXrrd3Rq7lA38CUGfKZBdfx65CRQhUWXAMLYxTK89KvlJz6l4hG7LuqfQGYQ2dkSmzQP3Yr0pQdnwI1HELRZTf6hEZQAy4d9MamuWNHvZ58dfnXkoA6KNL8V/4j4TROlxUZeAC8Y823fXq3LeM92tkkGTjTzvfNF4hTqDU53u4fqrPWUDUHAd4wUj7lAlmjLjZk/CF0f5m24yS0i0R hWlyOkAB gE/cLuJ4SCUj+ZMAr5KQ1Hk6hKt8PyIeHyjrJW22BLVxGDm9+ab4uk5AYGXD90caXWdV6yyySR3C4SIlt34yH7YvVYYSWzQcAGReuLBldyBeF/ULC5WwDiJdYQ9Qg5x95Sfa+Vux3WZhK/WvpfHYt5wsePD+Lwygw1heuEYHsOjblYJt5zZEN1cWO4rYhhnjDaJswmidewX/B7WqbFFMcgF/1xGS9t3lw95XJzoKSMbmvETy5JZSb/bo0n9gxECuLOGtSvvs0Ww41V1PBftR9S6WAN1dgJFGeBkxbKpdGrvg9fJGvK9WM8aWbVjQ609b7BuHkgb8jmhSo4JefitBrTSOb+eQJDmXgA2oFq87z5gm25Z7xlbD2I19zd2k0mTDAjSnd4NxGXdQtXQqzjfZ/e38uPnOC6/Q53cLX0t9Ih+hNo1GWaksLeaWZc3fbweXCFyXXH2+Llg+bfXPnvwx48E4wZA== 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: Both callers of fuse_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/fuse/file.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 89d97f6188e05e..fd2f27f2144750 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -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) @@ -1378,42 +1381,36 @@ 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); + written_buffered = fuse_perform_write(iocb, mapping, from, + iocb->ki_pos); if (written_buffered < 0) { err = written_buffered; goto out; } - endbyte = pos + written_buffered - 1; + endbyte = iocb->ki_pos + written_buffered - 1; - err = filemap_write_and_wait_range(file->f_mapping, pos, + err = filemap_write_and_wait_range(file->f_mapping, + iocb->ki_pos, endbyte); if (err) goto out; invalidate_mapping_pages(file->f_mapping, - pos >> PAGE_SHIFT, + iocb->ki_pos >> PAGE_SHIFT, endbyte >> PAGE_SHIFT); written += written_buffered; - iocb->ki_pos = pos + written_buffered; + iocb->ki_pos += written_buffered; } else { written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); - if (written >= 0) - iocb->ki_pos += written; } out: current->backing_dev_info = NULL; inode_unlock(inode); - if (written > 0) - written = generic_write_sync(iocb, written); - return written ? written : err; } From patchwork Fri May 19 09:35: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: 13248029 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 6BBCEC77B75 for ; Fri, 19 May 2023 09:36:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D06AD28000B; Fri, 19 May 2023 05:36:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9438280001; Fri, 19 May 2023 05:36:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE47628000B; Fri, 19 May 2023 05:36:20 -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 925F7280001 for ; Fri, 19 May 2023 05:36:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5D2F9AE4E3 for ; Fri, 19 May 2023 09:36:20 +0000 (UTC) X-FDA: 80806498920.14.35D5043 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 9D48918001B for ; Fri, 19 May 2023 09:36:17 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=lQYT2kwa; spf=none (imf24.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488977; 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=STVg9hQSNCoHnaWP+j57/x1LHg0FYksrLdPn28xq/k4=; b=uiD8NVJJBNzv2+7DcthS+mnxZe2A6Unc0pzI3LacM+arLeo83yvQzJ2ih/IKCHdtTA7J+D u/iMRXm/TZ+ReAhnJJuS9jQMN7ZYKrpdZgSjxVJ2a8QrkF9QmsOYONTPmYwTkFGuXh0xi9 d+kjQEOO1MmcXxLHNR0vr2TSQlIFJOc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488977; a=rsa-sha256; cv=none; b=qmRsTfhR4+spinqyHqHLrsgLSBzwdAcR4y9VLjS85q5n53ta2YQ5zOlXcxt6DkYTtQEIS+ LoQFXI9iJCnjFEcwrm3IQQM/pFXXJfFIlviN+YlfjYXRbolR4PYMSiDVli94JrK2Unv3dy qCpYtjveYuIHaoJt/i8RRBhlG19Dd48= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=lQYT2kwa; spf=none (imf24.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=STVg9hQSNCoHnaWP+j57/x1LHg0FYksrLdPn28xq/k4=; b=lQYT2kwaUEtArFfEb79xA//fBJ qogp7VjnGEoqLT6bjXgEup01sK0KL/4RiA1Fe8gDUeej2m9QIQCe2S/3Jocd+N+cdKp668C9VvAeW phbQS3w1Z6z10f/6yehWWZEY+S9fYiGxT0TfhkNTWvUDWB9iDdV0uv+kx5oc3HcI/0ayvEc19i8ma zliWUfhpNpatxjBI+G08zM6lhwpCdNsKd9r0pUWyuMh5c22vx8ahQkEsYV+AjmSNW3RXuG4Ue3k+H sTtOSNleeSciqjt1JlkB9rX6zj9iM4pWW19+tNfp7ueTD0W+O2LSYhMGFcK+0P4fgPFc3EgSG2rLh YUxjFJXg==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWk-00Fjjz-1H; Fri, 19 May 2023 09:35:58 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 12/13] fuse: drop redundant arguments to fuse_perform_write Date: Fri, 19 May 2023 11:35:20 +0200 Message-Id: <20230519093521.133226-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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: mqqgyomihh3ospf6hy3kki5tzosswnga X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9D48918001B X-Rspam-User: X-HE-Tag: 1684488977-671929 X-HE-Meta: U2FsdGVkX1+sHPEnuW7W6VktgW61UYyrqf00RU0yZ0+4gW14gopNwYY/PrqJ25bNvSun0h7XHTktxtvnZbTcKjCz4hsfcfqWpXTbFyD/wfo0LkLpFBqsJMudGqFzviLMD4camZRtxwRs7mlBRCVnQ2TroPWJiLeEttmBfqLZ60hObo3eJhYYZJXkFpMJn0WWZi8OBi1muGmakj2ZuTP2XFKftFzxJVLfCi2uQr/SkwL4lFMC1Lf/KNWqzglswvBg8tphmcnuB82uBB8V/d+20wazSg+r1p5kxpmW9KAAjII5RSfWN2wCr36abZ33oCgL2bV+LWAUhos0bNJXSude/k+pf19/TdRhu2LMYT9jy6wD3n8NAF+r5PjZ6zcmBja6BBRPMM7rDl8cW81shT8pdgHhButSgARfvvWSD0lbRxbCaOnw1k1P5CoeJKglTT0ZlK3KNbSLPoVx2o1wqB9ZL7GMjwsf+pHUMq7FKMR+n0oCE2sqnSPZ1FFFa9E98nTrSi+/bxjTvJCndUFCEj9tHHDVD2310tl4khx0WWZrj+oYBNmNR61wrmMnH9VwnLUq2i7Wcu/Plspj06lo09a6Kb7Pcaq11pMi1YHQHSk8rI3MDcmBBTbUii/Asn3d5Ym4rmU/TNIfhQr+w30vFXQHr9C+NM8FYA1WiOaL4ye4LvMTlJAJRNlDKQKK0csBycRIN4vW+7464GbOs8RvWvtRcvj6JEdMeAwKTM3dWG952FTBiC85SIT/5aRzIt5wzHKbALWdGnDaujiYz1D+tg2/8NSz5IKHKcKPImLRmsL8UB2f6QzNljxIMLNRJtxHt5YIc4iMqZepvyFbwcmjFrvWztaPYUBIIuM+nuKvXF/APWkgZUNw5vAumhDE/CWBltrUZtaqnP8+vXnCIW2UuJnLQPnsKhRCCjItCiwnyr61UXImKjo2BPvsdB7IGlGdMxPlZsz9Msyq30365gJF0EI IdDe8ZED lmCkhkC8nUTCpQyBvq0mmgauptY6GqsQyD0mMlytVk9mML4AIF+JtaJW/caUIXAEzcGWC5zrd871BtssbcIKPSth9HNN228rGK+gJJmLVVTHAU0PjxZQ3lHLBqqpqRdC8cSt8OnYt1chGXFRQp2knKVjLmNJA6rC8/RqD42bh1RZQfS/f4BOoUG9c/r4QMHOcK7tlPkbbwQhVmnN7nUuW4Ft8lTPr6CwVURlOfmAZh4iSBmzGmbuYCBa6qKEZ9+wKxRI9R7SZsh/Kz7tIGFu2KHo52LnJaJv01nOuHJEN18h420qQT/iBU+FthDrUXzKDxTyXzHmiUqbApy1wtOHxvma5ePNDlT0kyHi20r6H9evry7L3pQ/n5hXZtsLPvd6m5vuUp/V4+555kcu+DFJ+bTVXoZ1rfpqtS4kGe3GZuJ5sN40Tw1x1wBMccpohowepPcRUyG8a45iQuhgr4qzYaoqUAw== 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: pos is always equal to iocb->ki_pos, and mapping is always equal to iocb->ki_filp->f_mapping. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/fuse/file.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index fd2f27f2144750..5f7b58798f99fc 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; @@ -1385,8 +1385,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) if (written < 0 || !iov_iter_count(from)) goto out; - written_buffered = fuse_perform_write(iocb, mapping, from, - iocb->ki_pos); + written_buffered = fuse_perform_write(iocb, from); if (written_buffered < 0) { err = written_buffered; goto out; @@ -1406,7 +1405,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) written += written_buffered; iocb->ki_pos += written_buffered; } else { - written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); + written = fuse_perform_write(iocb, from); } out: current->backing_dev_info = NULL; From patchwork Fri May 19 09:35: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: 13248030 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 62485C77B75 for ; Fri, 19 May 2023 09:36:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB68C28000C; Fri, 19 May 2023 05:36:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEFBF280001; Fri, 19 May 2023 05:36:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C689728000C; Fri, 19 May 2023 05:36:23 -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 AE2AD280001 for ; Fri, 19 May 2023 05:36:23 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8F9911609FC for ; Fri, 19 May 2023 09:36:23 +0000 (UTC) X-FDA: 80806499046.13.C6DD781 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id EDD371C0013 for ; Fri, 19 May 2023 09:36:21 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=cWIcWF+N; dmarc=none; spf=none (imf20.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+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=1684488982; 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=lKV8h274a8dJZYXDnZBnFaYep44iQbnn3gg/wqWXLcU=; b=BuBJmBb/gHdZR2bXykfNd2z9Oi0+gwbDaRod2vV9LqL/FKWTGB+CH5QqK+DImB91RwMOjn UfHxaYq9eqeqAPgauLP/+S+xKgSxgup30UxvM3rHsqGeOGcFKVGox3E+uPlh6UwTxRZjwx 24pOMZK6LCRItbTcbtDF2nWYUek9Gjs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=cWIcWF+N; dmarc=none; spf=none (imf20.hostedemail.com: domain of BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aecf67361b95543ec79f+7208+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684488982; a=rsa-sha256; cv=none; b=ppd4OZwWb5bHOFo/XsPR3lVQntfAeJlJz3E+GE+I7WHvKl/AJM6aTy3NeGETGcnNm7EmqZ cwzDqjP2FKge3EQY7CVUwUHJt5YIqV5YSV+5sXZEHUDM+Y5/5x4mejFGBUBfk4tEKEGtRt 5yzSnhqCeBxfHjDONL1bn3/B3ORZG+Q= 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=lKV8h274a8dJZYXDnZBnFaYep44iQbnn3gg/wqWXLcU=; b=cWIcWF+NCJsR16lt+GN3SyqYi8 20m98Sg1zXHAv7DP2DoTSsINVBJLT/jPU8582VtWjlVAlPAxQNKVTFaC0YOnpEd5FvRMnBLi4ey94 K4WsXk4K1iXMjE0WTmxaYPPuCk8QMzpH/S5exdIPqIWUyCVLjzR3cBZl2UWcus5acmbfLvwlunIjm 4ycE2BJo+CC540gWRfo2M+hpyeOMIoCToQspTNQ3U/ipx7csq77R4XMThx+m4QCcDyjZBfA7VJFoS hKoo+WYpC8HvPYhP5WamSeG2WcUggfS4/afnmf7Abg1NQrcteg0tvokFZlTlL+/0VmwC02dijjfgF XYj4OTgA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWm-00Fjl7-2x; Fri, 19 May 2023 09:36:01 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 13/13] fuse: use direct_write_fallback Date: Fri, 19 May 2023 11:35:21 +0200 Message-Id: <20230519093521.133226-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-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-Stat-Signature: dkhxc4o1rqe4qm6duyyu4m5o58guobj5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: EDD371C0013 X-HE-Tag: 1684488981-525667 X-HE-Meta: U2FsdGVkX1+RuYBueTHNIrs5MahYbUP1Nov8KJLGqPqOsN9/b7ptYT/MjgMatwRd3Muix03i9zzMxsRnWl9zJbFt2+jDZ6lVGBAPE6RzF58U+p0UXqDcHIOpMMFGYAkp0SMcm5t3fwR8QHmsh4jyY3j0v4TwodQLpinopbdBPJuAkqXQ6toApHTST9VrFKHp4rvA8hJIIPfNLiptzYHVH/A9Ddxjlm2pXn7k2XQXLhFTht4H8exIdnZrSQstf3bBErFt0IlgLztHzgdFi70PFOMYG9dNwn8pCrJgjhcwKUqg/Ff7mBX0byGhAPdkpHM7YZw0RKWAvrWvghFmUaqugafaN+nnYO02EjMlQuK+HbxmgSvCarFvEtpzCBpYN7FFY2BMfjcqnyoLfCA3yhBpm7XsrBNvB800JjsqB/rnMnek80dk97wo3ckwWo6Mx3ccBhmp6EjgWRP9vTWGnQpypiZigTJ8jwWe7Le95IpX5RCoDOgyPqKZ00JhnqdVVzeAkHS/zq/0BPDLWKFAL2Rm4F1BjTNl+WrxH/SdS5xzXOrwkfaBIMm6e9CTAHmxfzeGVYWdazAPc23upUdDXrYFliDdASB6RIr8IOa20f1Wysl53tFYCoBNkzKs0J6Ety9gCbxeUb7rK6Eyfe2oTQqB9TptmA/AhyP/eDpTGBranrzHT7Mj9mT1PUpWlslpahGwLuBf4ynYEhQF/aq0YnvXOGxFwVrty2rjL5iJeOiVC10oNMS7ooDSqLPaRDnE7gyKncL79sTiDeDCT4T4rjRIAtYuLumVqhw4JEyGLcCPjQeO+5drVWLYD6nn7fxhBzz8fsKmgbDZ1tXEtGKYsWYlFPxAs7iGAW9cExQfoVNoObaytZ2Jk4CK3FBERpcjNpWAuWpskLH3fLap/wsadx+fxB+Qqu7OY3Dba3DnyLy4Bd7wgsHqzikLg6/pTGMn4Cm0J7KM3zYwQlK++nxLv5Z nmVZ5L3L bClVWlLfXvzweObGneKs3vZgnk+vBPcyMQzZclJJTArnyGKSP+F1uefvU3FKzcycyss5boREeMZtNjRiTPaqlTMgE4/SauCgVbd8dcXWL4WnguRqtYvFowq0Z+raiwP7PBBMqJbOT52rhuGv3FBeNexlRwzEkK6Drp812llv4+HmU2j3PiAzmZ4WpowoIpDc/MzxP61uAPHKd503jfKTxFLenOhhwCShP2S75cE0i3jsu0grfGktAX0+/j+T32XIpjFHuVj7dEKn0t/e7tNpl2Vq6EgyEnggKlK3ykczBzL1V4AHVuTLaHVz5DkCc4oXrjgjARviz3CMuymsostwDsKNVTVH1B/5EA6EfBvMMnBAp5FAVTFFK69jgeHQBKBrrODT9j8RKDvsi+hj+1+wd82zpfjoHssRczZNp5FluuYgIBARGAX75m3zaDX3lzBtf+9RJatNTNOohz+O2vCHMttx4RA== 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 generic direct_write_fallback helper instead of duplicating the logic. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/fuse/file.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 5f7b58798f99fc..02ab446ab57f1f 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1340,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) */ @@ -1382,28 +1380,9 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) if (iocb->ki_flags & IOCB_DIRECT) { written = generic_file_direct_write(iocb, from); - if (written < 0 || !iov_iter_count(from)) - goto out; - - written_buffered = fuse_perform_write(iocb, from); - if (written_buffered < 0) { - err = written_buffered; - goto out; - } - endbyte = iocb->ki_pos + written_buffered - 1; - - err = filemap_write_and_wait_range(file->f_mapping, - iocb->ki_pos, - endbyte); - if (err) - goto out; - - invalidate_mapping_pages(file->f_mapping, - iocb->ki_pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - - written += written_buffered; - iocb->ki_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, from); }