From patchwork Fri Aug 23 20:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13775932 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 D88F1C531DC for ; Fri, 23 Aug 2024 20:08:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C5F16B0275; Fri, 23 Aug 2024 16:08:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 674CF6B0276; Fri, 23 Aug 2024 16:08:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53C646B0277; Fri, 23 Aug 2024 16:08:52 -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 338416B0275 for ; Fri, 23 Aug 2024 16:08:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id ED5D6C0D5E for ; Fri, 23 Aug 2024 20:08:51 +0000 (UTC) X-FDA: 82484598462.01.758C907 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 32F0212000A for ; Fri, 23 Aug 2024 20:08:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N440LJsG; spf=pass (imf29.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443665; 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=LLNXobqu9Lr51n4CzgcItZvbbRppxWdYVF89daxGYJk=; b=2k2S7hY8Ais5IOOFuTd2zvOueGvrX7F4ttO81UBUiH24Ubccvtu18VOg9Lb1nOB0rFmXB+ eeW9aABtcl4o/dGWx2xdDrASA0qCXbTLGRtDRCNkTGJ8ocCf5OmPL2mIm7SwvcgRDJ+Vus 1u+Z7EnGPoy8KjaUWEMUD/yGR1wHiKw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N440LJsG; spf=pass (imf29.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724443665; a=rsa-sha256; cv=none; b=vO9Og51SlSaIuW01u0H2bNkG9UJomociZrEK9VBbUCOyUm+pzVwbNrygVVxbJ+c9pyWwum cwcGCdhHkSstJw0HVRygnNiii9SqWN69IYDTO8+rywV95GruURYvL2QD0BduJ+AQ6iajJz umKoYNIk6h+gIVa+xxdGFamp+YQyZic= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724443729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LLNXobqu9Lr51n4CzgcItZvbbRppxWdYVF89daxGYJk=; b=N440LJsGGOY/B2U51BAAmYfpFknVsyB5eK+wBVN0rwORqx3SLRefS4Cpvl173FcwPTElHG nZdW5Chy5M74mxR9XOVQXOYYFPxwGC4w2ucpgg8b98wCJl6n87dFPUou9Rk6c6+oU1nZuI xTtfVSTK7vTmk1IOAhbNldZy49KwHp8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-xMba_EeYPL-FTD2gDob40w-1; Fri, 23 Aug 2024 16:08:44 -0400 X-MC-Unique: xMba_EeYPL-FTD2gDob40w-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 96CB019560AD; Fri, 23 Aug 2024 20:08:40 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DE7901955E8C; Fri, 23 Aug 2024 20:08:35 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Pankaj Raghav , Paulo Alcantara , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marc Dionne Subject: [PATCH 2/9] afs: Fix post-setattr file edit to do truncation correctly Date: Fri, 23 Aug 2024 21:08:10 +0100 Message-ID: <20240823200819.532106-3-dhowells@redhat.com> In-Reply-To: <20240823200819.532106-1-dhowells@redhat.com> References: <20240823200819.532106-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Stat-Signature: 8kdoc9wzp9j5o4wczyg6goone3un9fot X-Rspam-User: X-Rspamd-Queue-Id: 32F0212000A X-Rspamd-Server: rspam02 X-HE-Tag: 1724443730-17683 X-HE-Meta: U2FsdGVkX18jpEsUFGw4TgtCgd6l4CNQC3NREFmNKb+DqbCI4AEypOpFyJ4ZQclyzR/8bMY6ihZOBlI88KIIsZGsHcY/0x1tIPqSxDi/TOv/gwa6OLKEtNHxbi6g4vNGo4mRWoEryq/mgxlp8a9L6rrCTuP7rwnjirZeKVI6c5h1xwOYghJJBBjwjHoqnKcMw8bSOqvvJRc4MS51P65ITjEkAFGneofIos2dMretVH1zY2qKgsefvVO+ADUdG+/fU83CROVwjo3jV6QzVFieSj4nUTE4mYbEBaD/50hnAhWUHj8/KovBYo221TDYn+Evkj72ciJnGrMkpizeA7tRWEhUHuc/dj1p9AQbjsfJieRNSTnWJV0XC/PTqpcQ2cWWi83o89Zx6CFr5nEX30utvKYeYbaTMyiExAwpznqn02xgVW2yyeSDQnmFuzmd9czGKpyA8+CMV3ldcFA+r/6w9SZ71GO3fIRQziYkn8YC6c/Z73oS5fUhQI8hanMqCcEIPOJRFLBFRZxeZleTW13ULR/BeteBNelH9vKtu3X2nHndEwM+bD47COOVJCQiFKcthTo8pJqtUeexqVa4H04XLDHGSmXfLvx7PtvFSiuytGhX1prcLVPfhuqhoIru3058/315YXiqm+KmAbTxYMIPYWxQOzAURuCiek8WMnT6IDWOLK5raQlqx10wc8Q0q1JvQYlTpqlJO4AFl2VvkSd4YgEXf3VX1NLwR+M1m6H3c+IbfOhQfMae0vutinFHvTEkwCzSGJuci8b/83Fuo1MPS4q6KQsfHGpFzqgTJdxn+lEPc8f9Wl8lR6GvjwvfAV8aXKtqt3rRxEuzASc5rwhhdJVFI+3W/Uu9rdrFfX+Qp7TpapZwsN5nBmizbsnBR3T1v/YE+2gooImlWYPIHUM3AhUPtCqM0z9V4JNWx/fSHR9Qou01TyFgJzHkxrdkDtLzwcXqA/Ob7cd0iv17Wbi INPBUSou o6NUivW+2CvAVHxlDf1diyzRPGOaSUfRHNmmSHytNolrN1kyW2vQls9grDnv14shwvu85DAVyqN9nyKVnntz8hpVBd2OsqOKDE2QjagJMp1UNpIYuXpRzll+ApdE4gq3/FfQKDMD1oSRqpnocd4ggb6JRD4S3ZUTbCaoGl1/eoMiMiip3hcrPxf3wH8+CDOMY4MAaAaTP3niGLQQxBdsq9SZ2nykRIeGymaLCFQNYm32RcTBil8gqGZcOCGVEE98Wf07JMuaMgJd60P8wUtsMyoa6PR/aHD2HcsgAOntHLgVFnun87VPyeR/ejrBZe3V1jzqsqu0YROayQp0bZ+Ae8TbNLZMJK+n4E1t1IdEO10hkHedd7reqrVkCYePHJcqxZ5VEZYue5MHFUS/KNfluNwGU3mzCwZ1KxQ+CZmt/euXjLyVf19V4QRAAOJkRF5+nsbUSy1GJYSdRQOJv2ULcYQqS/7X8kOCDOWbVcYDe4dNY+rXFPDo570nA/wViUGxoa+YSdJUoo7SIE9eJNCVYKgGky5sTI1mnRV/H+TPj3g0jATedgjgPUUClHA== 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: List-Subscribe: List-Unsubscribe: At the end of an kAFS RPC operation, there is an "edit" phase (originally intended for post-directory modification ops to edit the local image) that the setattr VFS op uses to fix up the pagecache if the RPC that requested truncation of a file was successful. afs_setattr_edit_file() calls truncate_setsize() which sets i_size, expands the pagecache if needed and truncates the pagecache. The first two of those, however, are redundant as they've already been done by afs_setattr_success() under the io_lock and the first is also done under the callback lock (cb_lock). Fix afs_setattr_edit_file() to call truncate_pagecache() instead (which is called by truncate_setsize(), thereby skipping the redundant parts. Fixes: 100ccd18bb41 ("netfs: Optimise away reads above the point at which there can be no data") Signed-off-by: David Howells cc: Matthew Wilcox (Oracle) cc: Pankaj Raghav cc: Jeff Layton cc: Marc Dionne cc: linux-afs@lists.infradead.org cc: netfs@lists.linux.dev cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- fs/afs/inode.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 3acf5e050072..a95e77670b49 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -695,13 +695,18 @@ static void afs_setattr_edit_file(struct afs_operation *op) { struct afs_vnode_param *vp = &op->file[0]; struct afs_vnode *vnode = vp->vnode; + struct inode *inode = &vnode->netfs.inode; if (op->setattr.attr->ia_valid & ATTR_SIZE) { loff_t size = op->setattr.attr->ia_size; - loff_t i_size = op->setattr.old_i_size; + loff_t old = op->setattr.old_i_size; + + /* Note: inode->i_size was updated by afs_apply_status() inside + * the I/O and callback locks. + */ - if (size != i_size) { - truncate_setsize(&vnode->netfs.inode, size); + if (size != old) { + truncate_pagecache(inode, size); netfs_resize_file(&vnode->netfs, size, true); fscache_resize_cookie(afs_vnode_cache(vnode), size); }