Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp511534imn; Thu, 28 Jul 2022 07:30:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sTSXIneNNkbJUqtYSz/PmodzAoHboJn41tI/ixZY2zGWjhLKINM99H0NTLs5ybVfQawJoe X-Received: by 2002:a63:4c4d:0:b0:41a:a125:60c9 with SMTP id m13-20020a634c4d000000b0041aa12560c9mr22960612pgl.329.1659018633196; Thu, 28 Jul 2022 07:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659018633; cv=none; d=google.com; s=arc-20160816; b=PnlYFxV3NhTSBde3rgxx/WPV3Nx/h9Pn1OBtACRKE7D1hMW3vgeS42SJaSeP8RJH75 ThlZkfIKla9/cjA828w9A58LGjBB3jJ0pvAX/UNPquiDwyV8pEeKwg66aMWMfoCf/MSl eiG/tsahxv50TnWy8aRyqttpxjwvx1XeQ1NY6m+5VU2ue15TfDXyLcwu6ON0awlqKS5B wqbtsVquuWmfmPCr5WB1CflyyqBM9S29sinMWqlFKxAvDCTAFPj1+WQ1XkDcFQh59oNc 0FbMJxHQspl/Zkp9gQxbc0q/2P8NZsSLYGC9pr7OQ+h0YY2WYPSBzFCIqb7XCwJd0wUZ 5/Sw== 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=eGVWn45w63jDfP9jpZli1WwPY1yQDfXk1yiQcwRozVQ=; b=yPySagc6hgdHIGAyrRD55XIQZr5k+8D2oKaUZXjbvGBN+yXQAHX43WaEM+4JoVwh1X uFTZytEAuM4N/GTVX13T59pL1LB4QaRCvY40EIRumUxVyCVFop3MAYXV0CCVQvyrFa1A yJJ2apihwe8fc6cNLbfEf5rG+oktu2SHOBrVf6kzSbQ5hE361C803OByq1XXL6Gdu0s5 wv5WVT5pL6jDBTug5zlasOuzuUQZMZsVVG+LWqaVmgs/GtYf/ruOfNv8M9TP8LbWIbm/ TLa/sYGqnAJh1oTrEtOdHJmNDlzJWDdQa22fgSxte6ceGIuk0FAvvxPANqaEnqGwkUYo Vxrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E1QJ8ubq; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w5-20020a170902ca0500b0016c049f656asi1074575pld.54.2022.07.28.07.30.10; Thu, 28 Jul 2022 07:30:33 -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=@kernel.org header.s=k20201202 header.b=E1QJ8ubq; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbiG1OYN (ORCPT + 99 others); Thu, 28 Jul 2022 10:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbiG1OYM (ORCPT ); Thu, 28 Jul 2022 10:24:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 799F865679 for ; Thu, 28 Jul 2022 07:24:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 303C8B82483 for ; Thu, 28 Jul 2022 14:24:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EB31C433C1; Thu, 28 Jul 2022 14:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659018248; bh=DMqJPYyKbkY+oxzus1MnyYlhu5NqZim4Kn2OsLjfWdA=; h=From:To:Cc:Subject:Date:From; b=E1QJ8ubqBiM7msbMajba1+7EV8Oyoj2/YCQqXx/sjn3WBA6WNPzkKBkSua8Z543SC hN6rncdE2o4h4AbA4Q0z/KsRJJK69Z/MtXiOmuXlq2QXafaUWenaA1szZigDQCknEX cEY6OifV9/xEqkjYejKiqjEWyOLKUb+WOYRIhSaHHgvbbIaODFG8sL9ai62VUjYdTw htS1tEE8WB6jDMrn7zxHSH/LiIuEfJGbY7YTNUlWDXnJYDlJzwuWfn+ZOP93HPU+eH TSUdJgYNHf7fQ8x5lExgzI/6btEgzE9quROXdM0JVngnSvXxbnO3wurDUL9hTv5BJJ NNrpTg211NE3Q== From: Jeff Layton To: trond.myklebust@hammerspace.com, anna@kernel.org Cc: linux-nfs@vger.kernel.org, Scott Mayhew , Ben Coddington , Olga Kornieskaia Subject: [RFC PATCH] nfs: don't skip CTO on v2/3 mounts, regardless of order of reference puts Date: Thu, 28 Jul 2022 10:24:06 -0400 Message-Id: <20220728142406.91832-1-jlayton@kernel.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Olga reported a case of data corruption in a situation where two clients (v3 and v4) were alternately doing open/write/close the same file. Looking at captures, the v3 client failed to perform any of the GETATTR calls for CTO during one of the events, leading it to overwrite some data that had been written by the v4 client. We have two calls that work similarly: put_nfs_open_context and put_nfs_open_context_sync. The only difference is the is_sync parameter that gets passed to close_context. The only caller of the _sync variant is in the close codepath. On a v2/3 mount, if the last reference is not put by put_nfs_open_context_sync, then CTO revalidation never happens. Fix this by adding a new flag to nfs_open_context and set that in put_nfs_open_context_sync. In nfs_close_context, check for that flag when we're checking is_sync and treat them as equivalent. Cc: Scott Mayhew Cc: Ben Coddington Reported-by: Olga Kornieskaia Signed-off-by: Jeff Layton --- fs/nfs/inode.c | 3 ++- include/linux/nfs_fs.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) I'm not sure this is the right fix. Maybe we'd be better off just ignoring the is_sync parameter in nfs_close_context? It's probably functionally equivalent anyway. Thoughts? diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index b4e46b0ffa2d..58b506a0a2f2 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -1005,7 +1005,7 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync) if (!(ctx->mode & FMODE_WRITE)) return; - if (!is_sync) + if (!is_sync && !test_bit(NFS_CONTEXT_DO_CLOSE, &ctx->flags)) return; inode = d_inode(ctx->dentry); if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) @@ -1091,6 +1091,7 @@ EXPORT_SYMBOL_GPL(put_nfs_open_context); static void put_nfs_open_context_sync(struct nfs_open_context *ctx) { + set_bit(NFS_CONTEXT_DO_CLOSE, &ctx->flags); __put_nfs_open_context(ctx, 1); } diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index a17c337dbdf1..faff0d60aad2 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -85,8 +85,9 @@ struct nfs_open_context { unsigned long flags; #define NFS_CONTEXT_RESEND_WRITES (1) #define NFS_CONTEXT_BAD (2) -#define NFS_CONTEXT_UNLOCK (3) +#define NFS_CONTEXT_UNLOCK (3) #define NFS_CONTEXT_FILE_OPEN (4) +#define NFS_CONTEXT_DO_CLOSE (5) int error; struct list_head list; -- 2.37.1