From nobody Fri Dec 19 04:17:21 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE7B3C77B7E for ; Tue, 2 May 2023 16:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234201AbjEBQhj (ORCPT ); Tue, 2 May 2023 12:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234231AbjEBQhR (ORCPT ); Tue, 2 May 2023 12:37:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B774497 for ; Tue, 2 May 2023 09:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683045343; 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=tdpnpp8De4O6UqKSmXkRgYIUfjEwCgwR0f9RkM3GpmI=; b=Y+fxyRJ5hrPzWdCfgpYgqp3Aci0YEFpK+zrKWK126oyDsU7lMu0dIUU0PhXLP5aXK1ytlS Y7/UNqLfNlDf8P6jfrtZAUJnTfV2GuxqxNl8TH7RFCAKixhgyUrwcmDDHtNuz5p+N3dRS5 S51CJoSQtKBRBB+45XOslbLR2xEs2Bk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-438-YcB8fFMlMq-oG1sBydpvZg-1; Tue, 02 May 2023 12:35:38 -0400 X-MC-Unique: YcB8fFMlMq-oG1sBydpvZg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B510B85C6E7; Tue, 2 May 2023 16:35:37 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB5634020960; Tue, 2 May 2023 16:35:34 +0000 (UTC) From: David Howells To: Linus Torvalds Cc: David Howells , Marc Dionne , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] afs: Fix updating of i_size with dv jump from server Date: Tue, 2 May 2023 17:35:26 +0100 Message-Id: <20230502163528.1564398-2-dhowells@redhat.com> In-Reply-To: <20230502163528.1564398-1-dhowells@redhat.com> References: <20230502163528.1564398-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Dionne If the data version returned from the server is larger than expected, the local data is invalidated, but we may still want to note the remote file size. Since we're setting change_size, we have to also set data_changed for the i_size to get updated. Fixes: 3f4aa9818163 ("afs: Fix EOF corruption") Signed-off-by: Marc Dionne Signed-off-by: David Howells cc: linux-afs@lists.infradead.org --- fs/afs/inode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index b1bdffd5e888..82edd3351734 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -230,6 +230,7 @@ static void afs_apply_status(struct afs_operation *op, set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags); } change_size =3D true; + data_changed =3D true; } else if (vnode->status.type =3D=3D AFS_FTYPE_DIR) { /* Expected directory change is handled elsewhere so * that we can locally edit the directory and save on a From nobody Fri Dec 19 04:17:21 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F926C77B73 for ; Tue, 2 May 2023 16:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233631AbjEBQhv (ORCPT ); Tue, 2 May 2023 12:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233869AbjEBQhV (ORCPT ); Tue, 2 May 2023 12:37:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73FDB448F for ; Tue, 2 May 2023 09:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683045343; 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=wV8lRfszHcQUBFiJ03SQYtrFihBDDfl7rukuI3tTTP0=; b=fDwS8hTQ4/cMdI8fLtr4yHNWl5sr8nHJxH22GAL0KGZU3FYo9AnbgX09v85II+XGso9pHM NUyGBjiDMsuSkWFGs+vn1YF02r816PQv0ma2Uv/FFEI0EOU3Qjq+BqU0/xpFknb4hFTgWF 61c2GgPZsIfhjeg4Qdr+zIfbpXODvus= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-T2kRHgaYOKieljbTt65cPA-1; Tue, 02 May 2023 12:35:40 -0400 X-MC-Unique: T2kRHgaYOKieljbTt65cPA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 92C48101A550; Tue, 2 May 2023 16:35:39 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id C17D52166B26; Tue, 2 May 2023 16:35:38 +0000 (UTC) From: David Howells To: Linus Torvalds Cc: David Howells , Marc Dionne , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] afs: Fix getattr to report server i_size on dirs, not local size Date: Tue, 2 May 2023 17:35:27 +0100 Message-Id: <20230502163528.1564398-3-dhowells@redhat.com> In-Reply-To: <20230502163528.1564398-1-dhowells@redhat.com> References: <20230502163528.1564398-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix afs_getattr() to report the server's idea of the file size of a directory rather than the local size. The local size may differ as we edit the local copy to avoid having to redownload it and we may end up with a differently structured blob of a different size. However, if the directory is discarded from the pagecache we then download it again and the user may see the directory file size apparently change. Fixes: 63a4681ff39c ("afs: Locally edit directory data for mkdir/create/unl= ink/...") Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- fs/afs/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 82edd3351734..866bab860a88 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -450,7 +450,7 @@ static void afs_get_inode_cache(struct afs_vnode *vnode) 0 : FSCACHE_ADV_SINGLE_CHUNK, &key, sizeof(key), &aux, sizeof(aux), - vnode->status.size)); + i_size_read(&vnode->netfs.inode))); #endif } =20 @@ -777,6 +777,13 @@ int afs_getattr(struct mnt_idmap *idmap, const struct = path *path, if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) && stat->nlink > 0) stat->nlink -=3D 1; + + /* Lie about the size of directories. We maintain a locally + * edited copy and may make different allocation decisions on + * it, but we need to give userspace the server's size. + */ + if (S_ISDIR(inode->i_mode)) + stat->size =3D vnode->netfs.remote_i_size; } while (need_seqretry(&vnode->cb_lock, seq)); =20 done_seqretry(&vnode->cb_lock, seq); From nobody Fri Dec 19 04:17:21 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BBE0C77B73 for ; Tue, 2 May 2023 16:37:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234296AbjEBQhq (ORCPT ); Tue, 2 May 2023 12:37:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234364AbjEBQhS (ORCPT ); Tue, 2 May 2023 12:37:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C20484222 for ; Tue, 2 May 2023 09:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683045343; 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=CZoekTna0zWXws8EaTSEoCtu55gwMy5uNJXIGmQIy0w=; b=dAAh1kWhrDuanGZJQvwD1dIbOP18YmGjEU54b//kMloX73Rx65z0iQxdtFyXAXrotmo5yO GdcxHXO6E0llMjie/GyfHlgsFR01uAqlz+/rLy8SiJ40arOtcsnY6C4JLEirDe/ZXGxnBB kwKs40k3ptn65XRdNiFDb959NEZZFeY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-665-NezWOwQXMZa1ygaArBVR1g-1; Tue, 02 May 2023 12:35:41 -0400 X-MC-Unique: NezWOwQXMZa1ygaArBVR1g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 429371C0432C; Tue, 2 May 2023 16:35:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 346DA2166B26; Tue, 2 May 2023 16:35:40 +0000 (UTC) From: David Howells To: Linus Torvalds Cc: David Howells , Marc Dionne , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] afs: Avoid endless loop if file is larger than expected Date: Tue, 2 May 2023 17:35:28 +0100 Message-Id: <20230502163528.1564398-4-dhowells@redhat.com> In-Reply-To: <20230502163528.1564398-1-dhowells@redhat.com> References: <20230502163528.1564398-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Dionne afs_read_dir fetches an amount of data that's based on what the inode size is thought to be. If the file on the server is larger than what was fetched, the code rechecks i_size and retries. If the local i_size was not properly updated, this can lead to an endless loop of fetching i_size from the server and noticing each time that the size is larger on the server. If it is known that the remote size is larger than i_size, bump up the fetch size to that size. Fixes: f3ddee8dc4e2 ("afs: Fix directory handling") Signed-off-by: Marc Dionne Signed-off-by: David Howells cc: linux-afs@lists.infradead.org --- fs/afs/dir.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index f92b9e62d567..4dd97afa536c 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -275,6 +275,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *= dvnode, struct key *key) loff_t i_size; int nr_pages, i; int ret; + loff_t remote_size =3D 0; =20 _enter(""); =20 @@ -289,6 +290,8 @@ static struct afs_read *afs_read_dir(struct afs_vnode *= dvnode, struct key *key) =20 expand: i_size =3D i_size_read(&dvnode->netfs.inode); + if (i_size < remote_size) + i_size =3D remote_size; if (i_size < 2048) { ret =3D afs_bad(dvnode, afs_file_error_dir_small); goto error; @@ -364,6 +367,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *= dvnode, struct key *key) * buffer. */ up_write(&dvnode->validate_lock); + remote_size =3D req->file_size; goto expand; }