From nobody Thu Jul 28 20:26:36 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Lv2HJ4Xfjz4XpdH; Thu, 28 Jul 2022 20:26:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Lv2HJ43KPz3mgK; Thu, 28 Jul 2022 20:26:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659039996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vwaGUU4++fCcLYNHh2l1e6RCI5Sr2/Yx/NgwXMQbPrc=; b=e3uwNAtlWK7D4YVXMxGiGJfAUojSrQjPFz6nTefiWfO0dlnIO5drza1vOc9h1N3DN8fD4C sjUgR+OfyThztnuGQVINlezAGcaOjWX3QiF+6d+lej03LcNtpFE9lcKP3TnbBZ3oJcjdxk vGxkTUJ8Q+SIrZ+SpVWuD+alAY6HVHkyJ98HNQ1rheJ0jZmvSRi84xQ39o1VCyrnWZ0+OO YzZRqwbI/D1lhrbSBz2OVhUOV6achNTDIyNj+x0KiWCi/dKH4DJ4Tqabrt0U1m4ybgfAsJ ZEKdMeobgjV+1DLviWa6ucgT4HhtAzyyqYhL8Jho5bX5EQMl7yzXxLciBJz/Lg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Lv2HJ2dGjz181p; Thu, 28 Jul 2022 20:26:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26SKQaJS006958; Thu, 28 Jul 2022 20:26:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26SKQah9006957; Thu, 28 Jul 2022 20:26:36 GMT (envelope-from git) Date: Thu, 28 Jul 2022 20:26:36 GMT Message-Id: <202207282026.26SKQah9006957@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: db2eff1cff8c - stable/13 - nfsd: Fix CreateSession for an established ClientID List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: db2eff1cff8c374f04030bb116c07e3112ecc516 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659039996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vwaGUU4++fCcLYNHh2l1e6RCI5Sr2/Yx/NgwXMQbPrc=; b=Xj4zd0CV7zxnZI0+7t1BWFj2X41/OwzNQb30hjPNUCeWy4S5QvowP1Gv7DF/t/lSeExy1t e7SWzGUuzFhWVNIwgHlqgxS6a2hRPE5pPfWToJZJhQQKvCKldZY9PZpE6vCnxyFZ607489 8AzBTmPWV4rN/961s8g95wzkBoUTOMAce8w7uROZlyRo2qhkRFVgwduUMgQhK14onWGLgJ C1BqDanc771Z+GF0QvZmNpsA+9rD4L0F7lEgTdC5WmipkKrRvcuQMy8vDfL0YWbm9smfY1 Ml7I5Pv6lVP1P9w5qYFJkO5BxO7F/H272cGklPGtf5XbsVutC00p/9mHyfs5kg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659039996; a=rsa-sha256; cv=none; b=q7kBettyc3aWDbOfYxZpdfcMkZl/NY7Aa7HkVZZEGRzfxgCFTyfM/0TA7Mh/sfMV36hzd5 AKCgDhHPKnA4bYWGN1cjb3eOLMiwj/Tm0VMeHPAts8RjjO4MZg5spQM1n8FISndYWgqD+1 eXv4iN+qvEfYVti75eF8xD/K1yUp6vjqBRU3KacecPqFWwwT1aaGRLkAa13OlGekIBpNM+ 25LxNHaj6ioI01LUYx6vnQNuivXNQdMPa20LKETWyBKuhTl76D9HORetoaNCuUWw3TX4av NwQcYoXbSFPb5ix+20zUCZ5w+CkHmAZ78G/OZEwX4kd81TLH0aZrUxAMUwulXQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=db2eff1cff8c374f04030bb116c07e3112ecc516 commit db2eff1cff8c374f04030bb116c07e3112ecc516 Author: Rick Macklem AuthorDate: 2022-07-13 23:28:56 +0000 Commit: Rick Macklem CommitDate: 2022-07-28 20:20:33 +0000 nfsd: Fix CreateSession for an established ClientID I mis-read the RFC w.r.t. handling of the sequenceid when a CreateSession is done after the initial one that confirms the ClientID. Fortunately this does not affect most extant NFSv4.1/4.2 clients, since they only acquire a single session for TCP for a ClientID (Solaris might be an exception?). This patch fixes the server to handle this case, where the RFC requires the sequenceid be incremented for each CreateSession and is required to reply to a retried CreateSession with a cached reply. It adds a field to nfsclient called lc_prevsess, which caches the sessionid, which is the only field in a CreateSession reply that will change for a retry, to implement this reply cache. The recent commits up to d4a11b3e3bdd that mark session slots bad when "intr" and/or "soft" mounts are used by the client needs this server patch. Without this patch, the client will do a full recovery, including a new ClientID, losing all byte range locks. However, prior to the recent client commits, the client would hang when all session slots were bad, so even without this patch it is not a regression. PR: 260011 (cherry picked from commit 088ba4356a114416b1d68bf5ae3b3e0accf6d0df) --- sys/fs/nfs/nfsrvstate.h | 1 + sys/fs/nfsserver/nfs_nfsdstate.c | 63 ++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/sys/fs/nfs/nfsrvstate.h b/sys/fs/nfs/nfsrvstate.h index 9eebeece9727..4c171e8b3f50 100644 --- a/sys/fs/nfs/nfsrvstate.h +++ b/sys/fs/nfs/nfsrvstate.h @@ -99,6 +99,7 @@ struct nfsclient { struct nfsstatehead lc_deleg; /* Delegations */ struct nfsstatehead lc_olddeleg; /* and old delegations */ struct nfssessionhead lc_session; /* List of NFSv4.1 sessions */ + uint64_t lc_prevsess; /* CreateSession cache */ time_t lc_expiry; /* Expiry time (sec) */ time_t lc_delegtime; /* Old deleg expiry (sec) */ nfsquad_t lc_clientid; /* 64 bit clientid */ diff --git a/sys/fs/nfsserver/nfs_nfsdstate.c b/sys/fs/nfsserver/nfs_nfsdstate.c index 842d3c75f678..6b2a6e56795d 100644 --- a/sys/fs/nfsserver/nfs_nfsdstate.c +++ b/sys/fs/nfsserver/nfs_nfsdstate.c @@ -336,10 +336,10 @@ nfsrv_setclient(struct nfsrv_descript *nd, struct nfsclient **new_clpp, * Add it after assigning a client id to it. */ new_clp->lc_flags |= LCL_NEEDSCONFIRM; - if ((nd->nd_flag & ND_NFSV41) != 0) - new_clp->lc_confirm.lval[0] = confirmp->lval[0] = - ++confirm_index; - else + if ((nd->nd_flag & ND_NFSV41) != 0) { + confirmp->lval[0] = ++confirm_index; + new_clp->lc_confirm.lval[0] = confirmp->lval[0] - 1; + } else confirmp->qval = new_clp->lc_confirm.qval = ++confirm_index; clientidp->lval[0] = new_clp->lc_clientid.lval[0] = @@ -348,6 +348,7 @@ nfsrv_setclient(struct nfsrv_descript *nd, struct nfsclient **new_clpp, nfsrv_nextclientindex(); new_clp->lc_stateindex = 0; new_clp->lc_statemaxindex = 0; + new_clp->lc_prevsess = 0; new_clp->lc_cbref = 0; new_clp->lc_expiry = nfsrv_leaseexpiry(); LIST_INIT(&new_clp->lc_open); @@ -449,10 +450,10 @@ nfsrv_setclient(struct nfsrv_descript *nd, struct nfsclient **new_clpp, } new_clp->lc_flags |= LCL_NEEDSCONFIRM; - if ((nd->nd_flag & ND_NFSV41) != 0) - new_clp->lc_confirm.lval[0] = confirmp->lval[0] = - ++confirm_index; - else + if ((nd->nd_flag & ND_NFSV41) != 0) { + confirmp->lval[0] = ++confirm_index; + new_clp->lc_confirm.lval[0] = confirmp->lval[0] - 1; + } else confirmp->qval = new_clp->lc_confirm.qval = ++confirm_index; clientidp->lval[0] = new_clp->lc_clientid.lval[0] = @@ -461,6 +462,7 @@ nfsrv_setclient(struct nfsrv_descript *nd, struct nfsclient **new_clpp, nfsrv_nextclientindex(); new_clp->lc_stateindex = 0; new_clp->lc_statemaxindex = 0; + new_clp->lc_prevsess = 0; new_clp->lc_cbref = 0; new_clp->lc_expiry = nfsrv_leaseexpiry(); @@ -596,6 +598,7 @@ nfsrv_getclient(nfsquad_t clientid, int opflags, struct nfsclient **clpp, struct nfssessionhash *shp; struct nfsdsession *sep; uint64_t sessid[2]; + bool sess_replay; static uint64_t next_sess = 0; if (clpp) @@ -676,13 +679,29 @@ nfsrv_getclient(nfsquad_t clientid, int opflags, struct nfsclient **clpp, * Perform any operations specified by the opflags. */ if (opflags & CLOPS_CONFIRM) { - if ((nd->nd_flag & ND_NFSV41) != 0 && - clp->lc_confirm.lval[0] != confirm.lval[0]) + sess_replay = false; + if ((nd->nd_flag & ND_NFSV41) != 0) { + /* + * For the case where lc_confirm.lval[0] == confirm.lval[0], + * use the new session, but with the previous sessionid. + * This is not exactly what the RFC describes, but should + * result in the same reply as the previous CreateSession. + */ + if (clp->lc_confirm.lval[0] + 1 == confirm.lval[0]) { + clp->lc_confirm.lval[0] = confirm.lval[0]; + clp->lc_prevsess = sessid[0]; + } else if (clp->lc_confirm.lval[0] == confirm.lval[0]) { + if (clp->lc_prevsess == 0) + error = NFSERR_SEQMISORDERED; + else + sessid[0] = clp->lc_prevsess; + sess_replay = true; + } else error = NFSERR_SEQMISORDERED; - else if ((nd->nd_flag & ND_NFSV41) == 0 && + } else if ((nd->nd_flag & ND_NFSV41) == 0 && clp->lc_confirm.qval != confirm.qval) error = NFSERR_STALECLIENTID; - else if (nfsrv_notsamecredname(nd, clp)) + if (error == 0 && nfsrv_notsamecredname(nd, clp)) error = NFSERR_CLIDINUSE; if (!error) { @@ -716,7 +735,7 @@ nfsrv_getclient(nfsquad_t clientid, int opflags, struct nfsclient **clpp, if (nsep != NULL) { /* Hold a reference on the xprt for a backchannel. */ if ((nsep->sess_crflags & NFSV4CRSESS_CONNBACKCHAN) - != 0) { + != 0 && !sess_replay) { if (clp->lc_req.nr_client == NULL) clp->lc_req.nr_client = (struct __rpc_client *) clnt_bck_create(nd->nd_xprt->xp_socket, @@ -735,14 +754,16 @@ nfsrv_getclient(nfsquad_t clientid, int opflags, struct nfsclient **clpp, NFSX_V4SESSIONID); NFSBCOPY(sessid, nsep->sess_cbsess.nfsess_sessionid, NFSX_V4SESSIONID); - shp = NFSSESSIONHASH(nsep->sess_sessionid); - NFSLOCKSTATE(); - NFSLOCKSESSION(shp); - LIST_INSERT_HEAD(&shp->list, nsep, sess_hash); - LIST_INSERT_HEAD(&clp->lc_session, nsep, sess_list); - nsep->sess_clp = clp; - NFSUNLOCKSESSION(shp); - NFSUNLOCKSTATE(); + if (!sess_replay) { + shp = NFSSESSIONHASH(nsep->sess_sessionid); + NFSLOCKSTATE(); + NFSLOCKSESSION(shp); + LIST_INSERT_HEAD(&shp->list, nsep, sess_hash); + LIST_INSERT_HEAD(&clp->lc_session, nsep, sess_list); + nsep->sess_clp = clp; + NFSUNLOCKSESSION(shp); + NFSUNLOCKSTATE(); + } } } } else if (clp->lc_flags & LCL_NEEDSCONFIRM) {