Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp354748pxb; Mon, 16 Aug 2021 07:01:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdXJTtaqyPOQgV7jtqnXFFae7W/WbFpo718CWEFmrUT5tJtXJ4rOj3hPAq7GFsWgukWIaz X-Received: by 2002:a02:cc8e:: with SMTP id s14mr15384577jap.102.1629122491692; Mon, 16 Aug 2021 07:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629122491; cv=none; d=google.com; s=arc-20160816; b=G3N54psrq2jsxgX/dv8po9T1QOvWi4zEmB6wI9f+5rGq9FDBJ7HtUsJYZVbiS3JrS2 qOBEXXKDvN2gZ0emeRSL64i8kgusLB0h1M1cJzCQG/SA9iQfDBtR7lOQ/dL7emIE6oM2 f1tIKlwZ5vqc6VLa7ut9BnFTe3jgfIMFHsI/50MIarPyUyOorL5orYOe9oqhEESTToYq aYCDNAgC+r5pz3bs2UzNLWfafvVmO1HQB8s9Kh07eAqTDA4fvf6jq7pxXtRlHDrC36Nn s2Ycc+aZ18m/G5yV9GQHWUj3XR8r0NMJ6XKdKCnZB2TmMCokkdNO30GIrpMDp44LZmp9 sq/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-filter; bh=K89HIUJfZ7OSoJyVpbH8aNvEmBqqfi6BvxNNfhiS5hg=; b=d1DJM+g+N7/TClux1IvuxXjZqfylquELBsPVr5x4BTh/R4k3/4Qq60x4BX8HRt2bs3 HhjDPMYm8OFeqTSgtBLDadP4wgUM1lbdX+47KU3xJssNhksJKMsMGhHvhEveKINdPyZv F7nw5ICoVxDthkqA4xTsP7BIWF8NECsj1NA3xX/DKTVqlYAzkXNf0RVuem38h/+FkwNk U7CdY/gSrOPzW+qgqOA3r14fGQvq9JsIc4824fKeGYOLiR8IFTBMnVfQKV4+IxyUGVV2 ichZ0l9A78Q5zLPBAMHcjS1kD3CnQRGTz9m1wv+IWlRYcdOzLJQxgnsfUhrUVOdvz0oW URtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i9si11567900ilv.82.2021.08.16.07.01.18; Mon, 16 Aug 2021 07:01:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231797AbhHPOBJ (ORCPT + 99 others); Mon, 16 Aug 2021 10:01:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231820AbhHPOAX (ORCPT ); Mon, 16 Aug 2021 10:00:23 -0400 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB9E6C0612A5 for ; Mon, 16 Aug 2021 06:59:30 -0700 (PDT) Received: by fieldses.org (Postfix, from userid 2815) id 681527C62; Mon, 16 Aug 2021 09:59:28 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 681527C62 From: "J. Bruce Fields" To: Trond Myklebust , Anna Schumaker Cc: daire@dneg.com, linux-nfs@vger.kernel.org, "J. Bruce Fields" Subject: [PATCH 6/8] nfs: don't atempt blocking locks on nfs reexports Date: Mon, 16 Aug 2021 09:59:25 -0400 Message-Id: <1629122367-18541-7-git-send-email-bfields@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1629122367-18541-1-git-send-email-bfields@redhat.com> References: <1629122367-18541-1-git-send-email-bfields@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: "J. Bruce Fields" NFS implements blocking locks by blocking inside its lock method. In the reexport case, this blocks the nfs server thread, which could lead to deadlocks since an nfs server thread might be required to unlock the conflicting lock. It also causes a crash, since the nfs server thread assumes it can free the lock when its lm_notify lock callback is called. Ideal would be to make the nfs lock method return without blocking in this case, but for now it works just not to attempt blocking locks. The difference is just that the original client will have to poll (as it does in the v4.0 case) instead of getting a callback when the lock's available. Signed-off-by: J. Bruce Fields --- fs/nfs/export.c | 2 +- fs/nfsd/nfs4state.c | 8 ++++++-- include/linux/exportfs.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/nfs/export.c b/fs/nfs/export.c index 37a1a88df771..d772c20bbfd1 100644 --- a/fs/nfs/export.c +++ b/fs/nfs/export.c @@ -180,5 +180,5 @@ const struct export_operations nfs_export_ops = { .fetch_iversion = nfs_fetch_iversion, .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK| EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS| - EXPORT_OP_NOATOMIC_ATTR, + EXPORT_OP_NOATOMIC_ATTR|EXPORT_OP_SYNC_LOCKS, }; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index fa67ecd5fe63..bebe86cce7c7 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6835,6 +6835,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_blocked_lock *nbl = NULL; struct file_lock *file_lock = NULL; struct file_lock *conflock = NULL; + struct super_block *sb; __be32 status = 0; int lkflg; int err; @@ -6856,6 +6857,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, dprintk("NFSD: nfsd4_lock: permission denied!\n"); return status; } + sb = cstate->current_fh.fh_dentry->d_sb; if (lock->lk_is_new) { if (nfsd4_has_session(cstate)) @@ -6904,7 +6906,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, fp = lock_stp->st_stid.sc_file; switch (lock->lk_type) { case NFS4_READW_LT: - if (nfsd4_has_session(cstate)) + if (nfsd4_has_session(cstate) && + !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS)) fl_flags |= FL_SLEEP; fallthrough; case NFS4_READ_LT: @@ -6916,7 +6919,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, fl_type = F_RDLCK; break; case NFS4_WRITEW_LT: - if (nfsd4_has_session(cstate)) + if (nfsd4_has_session(cstate) && + !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS)) fl_flags |= FL_SLEEP; fallthrough; case NFS4_WRITE_LT: diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index fe848901fcc3..3260fe714846 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -221,6 +221,8 @@ struct export_operations { #define EXPORT_OP_NOATOMIC_ATTR (0x10) /* Filesystem cannot supply atomic attribute updates */ +#define EXPORT_OP_SYNC_LOCKS (0x20) /* Filesystem can't do + asychronous blocking locks */ unsigned long flags; }; -- 2.31.1