From patchwork Fri Jan 27 16:18:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 13118934 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 D8385C61D97 for ; Fri, 27 Jan 2023 16:19:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234510AbjA0QT5 (ORCPT ); Fri, 27 Jan 2023 11:19:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234519AbjA0QTt (ORCPT ); Fri, 27 Jan 2023 11:19:49 -0500 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 8365945228 for ; Fri, 27 Jan 2023 08:19:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674836340; 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=oBD82ET37hayPo7F26/s85pvG/4hY3FyJGCUmHt9Ieo=; b=CWcYoOEf9uxFZ5j10zIZfFQAT1XG4Ku3OYTuHyerZzbnJeaKhW/hj6o0BnKTVVZPxO7hGM lFNhPJSNFLG+svTSPcCoh8I7i8T9RDalA6FYgYBelVJDE3RaOd5arUG2ic9vKoHE24Amdz tDk4gW5DKQ1KSOT1rno0ZrxRgwbnzWs= 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-611-UqvVfd-rPFep_I0r2CWfvA-1; Fri, 27 Jan 2023 11:18:57 -0500 X-MC-Unique: UqvVfd-rPFep_I0r2CWfvA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5FEBD1991C42; Fri, 27 Jan 2023 16:18:57 +0000 (UTC) Received: from bcodding.csb (unknown [10.22.50.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C8C87AD4; Fri, 27 Jan 2023 16:18:57 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id 83BF310C30E1; Fri, 27 Jan 2023 11:18:56 -0500 (EST) From: Benjamin Coddington To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH] nfsd: fix race to check ls_layouts Date: Fri, 27 Jan 2023 11:18:56 -0500 Message-Id: <979eebe94ef380af6a5fdb831e78fd4c0946a59e.1674836262.git.bcodding@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Its possible for __break_lease to find the layout's lease before we've added the layout to the owner's ls_layouts list. In that case, setting ls_recalled = true without actually recalling the layout will cause the server to never send a recall callback. Move the check for ls_layouts before setting ls_recalled. Signed-off-by: Benjamin Coddington Reviewed-by: Jeff Layton --- fs/nfsd/nfs4layouts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4layouts.c b/fs/nfsd/nfs4layouts.c index 3564d1c6f610..e8a80052cb1b 100644 --- a/fs/nfsd/nfs4layouts.c +++ b/fs/nfsd/nfs4layouts.c @@ -323,11 +323,11 @@ nfsd4_recall_file_layout(struct nfs4_layout_stateid *ls) if (ls->ls_recalled) goto out_unlock; - ls->ls_recalled = true; - atomic_inc(&ls->ls_stid.sc_file->fi_lo_recalls); if (list_empty(&ls->ls_layouts)) goto out_unlock; + ls->ls_recalled = true; + atomic_inc(&ls->ls_stid.sc_file->fi_lo_recalls); trace_nfsd_layout_recall(&ls->ls_stid.sc_stateid); refcount_inc(&ls->ls_stid.sc_count);