Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1022349iob; Wed, 4 May 2022 12:55:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6nltf/oJ+vqszS+NY1LChhHS2+zprBdVzDkjj+9mAD/frxV/trCgw+G5j0tfiu89PZyya X-Received: by 2002:a17:90a:5b09:b0:1cd:b3d3:a3f3 with SMTP id o9-20020a17090a5b0900b001cdb3d3a3f3mr1376976pji.9.1651694105028; Wed, 04 May 2022 12:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651694105; cv=none; d=google.com; s=arc-20160816; b=XXSabLK1mrsNmFp/4aaMBFr4BDuqnjzCG232S18UG2fn98RXh0pg8qrNXpZmRRtsrK LhnyKdTtNn1kGSUdWkX4bdAQCSlqqR5MQu+Jr+st4OILRRoR65IkJSk2Kf6NxLe5GY83 9biuvL8qdY42JlpvdaVCylfKejzxSOAgNotZzXoNU5qgvepinlWTKen7Jt0fXNqACMHY IBUXXr7xTlZGtCEObP2BW7LPozkl03eHrxF4oh26FHinadyZ9aMZ2K4cQ34yaG84GfiL nezMV74xi3Jv5qdEOZN7mBoZr4CWYCy/2soaE2u6X8jzFkoIqGVvuK7UoQgXS50XRA0H Jl6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Qe4yVAvzQpTnaqUWjZUA3f+aoL1YlAlWs24T4YHjd4M=; b=ug+O5PErZUJLipmrAe8cZFOz6ap1qSin94HUhR9NVGfJSmzqSAi5K6y+az9ztWTJL+ 3NeU9tfjWnctjB2EE38d7Xf+EjHhYXkfs9K8WvCVjQA+sYX/MU6GRqkzrMteVdKdNQL/ muYoRU194TlxgX3Ydwtooj8jOnOa2ey8eO5xCu8TkdQrqmc+CpyR6tCPCilGiKeg93M9 f81d1tsVVs+AgiRhfrqpylCl1SoLFhSbZLHd+1++RhwBujuQh8hupexdmYurdmcWsRiW OtTsSCEAXPTUqTPbOIvdKIAN/5YXUSGZ9OH7d9Wl69cR44kR2OeoenyEdWewYP0P7jgw TArA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CgQ2E7Dm; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d17-20020a621d11000000b004fa687c28d4si19510333pfd.86.2022.05.04.12.54.39; Wed, 04 May 2022 12:55:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CgQ2E7Dm; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350654AbiEDN0G (ORCPT + 99 others); Wed, 4 May 2022 09:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350646AbiEDNZh (ORCPT ); Wed, 4 May 2022 09:25:37 -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 ESMTP id BF1C944769 for ; Wed, 4 May 2022 06:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651670472; 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; bh=Qe4yVAvzQpTnaqUWjZUA3f+aoL1YlAlWs24T4YHjd4M=; b=CgQ2E7Dm2zy6yXW5oxb7C4pBd3pJ4GfcSIokfxC121/ZcsNPGjofLQDLgE1m8Mm1ez8OVW FWxZaN8BGveJfMA0iGXNWdWO9qDDlNuOS9pfG5O1A1jVFL1dAgJ6Bp8otF2NhOJno+0JSq tTYfQthFt5v/9Jyrm7CgKhOKWQzCoe8= 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-218-EKKuowZ6PWWny_NHZe8fbw-1; Wed, 04 May 2022 09:21:09 -0400 X-MC-Unique: EKKuowZ6PWWny_NHZe8fbw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4440899ED3; Wed, 4 May 2022 13:21:08 +0000 (UTC) Received: from dwysocha.rdu.csb (unknown [10.22.9.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82A86155BC8B; Wed, 4 May 2022 13:21:08 +0000 (UTC) From: Dave Wysochanski To: Anna Schumaker , Trond Myklebust Cc: linux-nfs@vger.kernel.org, linux-cachefs@redhat.com, David Howells , Daire Byrne Subject: [PATCH] NFS: Pass i_size to fscache_unuse_cookie() when a file is released Date: Wed, 4 May 2022 09:21:06 -0400 Message-Id: <20220504132106.28812-1-dwysocha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Pass updated i_size in fscache_unuse_cookie() when called from nfs_fscache_release_file(), which ensures the size of an fscache object gets written to the cache storage. Failing to do so results in unnessary reads from the NFS server, even when the data is cached, due to a cachefiles object coherency check failing with a trace similar to the following: cachefiles_coherency: o=0000000e BAD osiz B=afbb3 c=0 This problem can be reproduced as follows: #!/bin/bash v=4.2; NFS_SERVER=127.0.0.1 set -e; trap cleanup EXIT; rc=1 function cleanup { umount /mnt/nfs > /dev/null 2>&1 RC_STR="TEST PASS" [ $rc -eq 1 ] && RC_STR="TEST FAIL" echo "$RC_STR on $(uname -r) with NFSv$v and server $NFS_SERVER" } mount -o vers=$v,fsc $NFS_SERVER:/export /mnt/nfs rm -f /mnt/nfs/file1.bin > /dev/null 2>&1 dd if=/dev/zero of=/mnt/nfs/file1.bin bs=4096 count=1 > /dev/null 2>&1 echo 3 > /proc/sys/vm/drop_caches echo Read file 1st time from NFS server into fscache dd if=/mnt/nfs/file1.bin of=/dev/null > /dev/null 2>&1 umount /mnt/nfs && mount -o vers=$v,fsc $NFS_SERVER:/export /mnt/nfs echo 3 > /proc/sys/vm/drop_caches echo Read file 2nd time from fscache dd if=/mnt/nfs/file1.bin of=/dev/null > /dev/null 2>&1 echo Check mountstats for NFS read grep -q "READ: 0" /proc/self/mountstats # (1st number) == 0 [ $? -eq 0 ] && rc=0 Fixes: a6b5a28eb56c "nfs: Convert to new fscache volume/cookie API" Signed-off-by: Dave Wysochanski --- fs/nfs/fscache.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c index f73c09a9cf0a..e861d7bae305 100644 --- a/fs/nfs/fscache.c +++ b/fs/nfs/fscache.c @@ -231,11 +231,10 @@ void nfs_fscache_release_file(struct inode *inode, struct file *filp) { struct nfs_fscache_inode_auxdata auxdata; struct fscache_cookie *cookie = nfs_i_fscache(inode); + loff_t i_size = i_size_read(inode); - if (fscache_cookie_valid(cookie)) { - nfs_fscache_update_auxdata(&auxdata, inode); - fscache_unuse_cookie(cookie, &auxdata, NULL); - } + nfs_fscache_update_auxdata(&auxdata, inode); + fscache_unuse_cookie(cookie, &auxdata, &i_size); } /* -- 2.27.1