From nobody Sat Jul 9 21:47:01 2022 X-Original-To: dev-commits-src-all@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 508E71CFC7BC; Sat, 9 Jul 2022 21:47:01 +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 4LgNys1nZ7z3Kbd; Sat, 9 Jul 2022 21:47:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657403221; 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=jrurATyAUFThjUBUhnw156SyloPytdxQ+mOJrIOrndI=; b=TAI8NYA1FPTHMsCZ2qpIMkiVxi4+Vf4NAKn/393YI1E6E/Oy9V/fa4CETDzZrXXiKUR2o5 sLphZ7ZAXkqjWyleJDC6j4I+vY2lTZKjyVqNkoIxlIQlLJx+yw+T3Ku3ntOlLFHr7dw+3Y yx+fgzCPPmmEJgD1ShcNoG6CMtbBv/g0HgbKQ7r+FMXfkc9A1U4T2qu+H1Zn9Pdl2sQDbC R1HSTj+zH5zFzR2Ncz4tJ3P4QKaQ6KHwwzRAWqzXXhPuBqRxKxTYy+Ifz2FVZ9ESuyQ1gB JFHgaKU9UGc44Ze4WYwjAb+FJg30ACA7kkYNLFQuIuf+LeWJpCSeHBSY4hzm1Q== 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 4LgNys0sbjz117W; Sat, 9 Jul 2022 21:47:01 +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 269Ll1IP053419; Sat, 9 Jul 2022 21:47:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 269Ll1eo053418; Sat, 9 Jul 2022 21:47:01 GMT (envelope-from git) Date: Sat, 9 Jul 2022 21:47:01 GMT Message-Id: <202207092147.269Ll1eo053418@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: 40ada74ee1da - main - nfscl: Add optional support for slots marked bad List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 40ada74ee1dade637675cc22d50da8254046a197 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657403221; 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=jrurATyAUFThjUBUhnw156SyloPytdxQ+mOJrIOrndI=; b=kDgnT6fw6Xyawu3N8kGFPLqsepOXmOmL2pqjubEhWFHjsQejfK7CUmmPGvWVJfpqJlin8G c+LWRCKN7mGUIjAu9PVE/WrOigYIKc7c+Yc+r5gIYWHDsAingNHr1Mj1xTatwYzMsved3v LOiT8DHtnlmL8/2/5YscNeX35J4fNc46Pb/wiF0/peDjaUKKsAPWZDzBLdXPEekbYb5GX0 2h/+MhHy3WYx1doBfLRFo4jqCExeA0QB3x05/D6+eyVmQeXbH5yGAdcxjC80MNEaMtA8/d V5P1IxMocYRNl9dBCK7HtgUuHV9GiXMG97SKyDAjAK2w3QNm/XhndssmevZYLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657403221; a=rsa-sha256; cv=none; b=tRgfL1W3C/u94t+nAicDyDTCb3KGoiriH9hrjoVFusWZnvyi8ZCkIjatkFUPS+PLj0cKEl URiVh7kouSBDV7s6GoE5NqkZTa6Apt4pN+kBFbwfV1hYP0qitH8vpq0LrpAVVXKlGYf1+2 LYGE+Nk2sFtnMC4m7ECHwtdr8Y9CULJAmg3afH5Sk9/+dFRv78MB6/CdMxECtTXM35gbIG tY+e1X9nHmxb1BQB1qWGFipKmPyCLJTmqRHol998Di301QIVrVn9HqmotGZCKk8HQfiA+p VBpVpDTqO+UdAoV/IUhV+KktBNKOe6lxlCZpa+7DTMMD+lMMJ9rT/3AydPSSaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=40ada74ee1dade637675cc22d50da8254046a197 commit 40ada74ee1dade637675cc22d50da8254046a197 Author: Rick Macklem AuthorDate: 2022-07-09 21:43:16 +0000 Commit: Rick Macklem CommitDate: 2022-07-09 21:43:16 +0000 nfscl: Add optional support for slots marked bad This patch adds support for session slots marked bad to nfsv4_sequencelookup(). An additional boolean argument indicates if the check for slots marked bad should be done. The "cred" argument added to nfscl_reqstart() by commit 326bcf9394c7 is now passed into nfsv4_setquence() so that it can optionally set the boolean argument for nfsv4_sequencelookup(). When optionally enabled, nfsv4_setsequence() will do a DestroySession when all slots are marked bad. Since the code that marks slots bad is not yet committed, this patch should not result in a semantics change. PR: 260011 MFC after: 2 weeks --- sys/fs/nfs/nfs_commonkrpc.c | 2 +- sys/fs/nfs/nfs_commonsubs.c | 69 ++++++++++++++++++++++++++++++---------- sys/fs/nfs/nfs_var.h | 4 +-- sys/fs/nfs/nfsclstate.h | 1 + sys/fs/nfsserver/nfs_nfsdstate.c | 4 +-- 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/sys/fs/nfs/nfs_commonkrpc.c b/sys/fs/nfs/nfs_commonkrpc.c index 4d8db64f419f..20b12767d29d 100644 --- a/sys/fs/nfs/nfs_commonkrpc.c +++ b/sys/fs/nfs/nfs_commonkrpc.c @@ -1121,7 +1121,7 @@ tryagain: if ((nd->nd_flag & ND_LOOPBADSESS) != 0) { reterr = nfsv4_sequencelookup(nmp, sep, &slotpos, &maxslot, &slotseq, - sessionid); + sessionid, true); if (reterr == 0) { /* Fill in new session info. */ NFSCL_DEBUG(1, diff --git a/sys/fs/nfs/nfs_commonsubs.c b/sys/fs/nfs/nfs_commonsubs.c index 4c38d29ed281..6dd1a3e4c579 100644 --- a/sys/fs/nfs/nfs_commonsubs.c +++ b/sys/fs/nfs/nfs_commonsubs.c @@ -323,7 +323,7 @@ static int nfs_bigrequest[NFSV42_NPROCS] = { void nfscl_reqstart(struct nfsrv_descript *nd, int procnum, struct nfsmount *nmp, u_int8_t *nfhp, int fhlen, u_int32_t **opcntpp, struct nfsclsession *sep, - int vers, int minorvers, __unused struct ucred *cred) + int vers, int minorvers, struct ucred *cred) { struct mbuf *mb; u_int32_t *tl; @@ -416,11 +416,17 @@ nfscl_reqstart(struct nfsrv_descript *nd, int procnum, struct nfsmount *nmp, *tl = txdr_unsigned(NFSV4OP_SEQUENCE); if (sep == NULL) { sep = nfsmnt_mdssession(nmp); + /* + * For MDS mount sessions, check for bad + * slots. If the caller does not want this + * check to be done, the "cred" argument can + * be passed in as NULL. + */ nfsv4_setsequence(nmp, nd, sep, - nfs_bigreply[procnum]); + nfs_bigreply[procnum], cred); } else nfsv4_setsequence(nmp, nd, sep, - nfs_bigreply[procnum]); + nfs_bigreply[procnum], NULL); } if (nfsv4_opflag[nfsv4_opmap[procnum].op].needscfh > 0) { NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED); @@ -4769,14 +4775,23 @@ nfsv4_seqsess_cacherep(uint32_t slotid, struct nfsslot *slots, int repstat, */ void nfsv4_setsequence(struct nfsmount *nmp, struct nfsrv_descript *nd, - struct nfsclsession *sep, int dont_replycache) + struct nfsclsession *sep, int dont_replycache, struct ucred *cred) { uint32_t *tl, slotseq = 0; int error, maxslot, slotpos; uint8_t sessionid[NFSX_V4SESSIONID]; - error = nfsv4_sequencelookup(nmp, sep, &slotpos, &maxslot, &slotseq, - sessionid); + if (cred != NULL) { + error = nfsv4_sequencelookup(nmp, sep, &slotpos, &maxslot, + &slotseq, sessionid, false); + if (error == NFSERR_SEQMISORDERED) { + /* If all slots are bad, Destroy the session. */ + nfsrpc_destroysession(nmp, sep, cred, curthread); + error = 0; + } + } else + error = nfsv4_sequencelookup(nmp, sep, &slotpos, &maxslot, + &slotseq, sessionid, true); nd->nd_maxreq = sep->nfsess_maxreq; nd->nd_maxresp = sep->nfsess_maxresp; @@ -4813,12 +4828,18 @@ nfsv4_setsequence(struct nfsmount *nmp, struct nfsrv_descript *nd, nd->nd_flag |= ND_HASSEQUENCE; } +/* + * If fnd_init is true, ignore the badslots. + * If fnd_init is false, return NFSERR_SEQMISORDERED if all slots are bad. + */ int nfsv4_sequencelookup(struct nfsmount *nmp, struct nfsclsession *sep, - int *slotposp, int *maxslotp, uint32_t *slotseqp, uint8_t *sessionid) + int *slotposp, int *maxslotp, uint32_t *slotseqp, uint8_t *sessionid, + bool fnd_init) { int i, maxslot, slotpos; uint64_t bitval; + bool fnd_ok; /* Find an unused slot. */ slotpos = -1; @@ -4832,14 +4853,18 @@ nfsv4_sequencelookup(struct nfsmount *nmp, struct nfsclsession *sep, mtx_unlock(&sep->nfsess_mtx); return (NFSERR_BADSESSION); } + fnd_ok = fnd_init; bitval = 1; for (i = 0; i < sep->nfsess_foreslots; i++) { - if ((bitval & sep->nfsess_slots) == 0) { - slotpos = i; - sep->nfsess_slots |= bitval; - sep->nfsess_slotseq[i]++; - *slotseqp = sep->nfsess_slotseq[i]; - break; + if ((bitval & sep->nfsess_badslots) == 0 || fnd_init) { + fnd_ok = true; + if ((bitval & sep->nfsess_slots) == 0) { + slotpos = i; + sep->nfsess_slots |= bitval; + sep->nfsess_slotseq[i]++; + *slotseqp = sep->nfsess_slotseq[i]; + break; + } } bitval <<= 1; } @@ -4854,10 +4879,19 @@ nfsv4_sequencelookup(struct nfsmount *nmp, struct nfsclsession *sep, return (ESTALE); } /* Wake up once/sec, to check for a forced dismount. */ - (void)mtx_sleep(&sep->nfsess_slots, &sep->nfsess_mtx, - PZERO, "nfsclseq", hz); + if (fnd_ok) + mtx_sleep(&sep->nfsess_slots, &sep->nfsess_mtx, + PZERO, "nfsclseq", hz); } - } while (slotpos == -1); + } while (slotpos == -1 && fnd_ok); + /* + * If all slots are bad, just return slot 0 and NFSERR_SEQMISORDERED. + * The caller will do a DestroySession, so that the session's use + * will get a NFSERR_BADSESSION reply from the server. + */ + if (!fnd_ok) + slotpos = 0; + /* Now, find the highest slot in use. (nfsc_slots is 64bits) */ bitval = 1; for (i = 0; i < 64; i++) { @@ -4869,6 +4903,9 @@ nfsv4_sequencelookup(struct nfsmount *nmp, struct nfsclsession *sep, mtx_unlock(&sep->nfsess_mtx); *slotposp = slotpos; *maxslotp = maxslot; + + if (!fnd_ok) + return (NFSERR_SEQMISORDERED); return (0); } diff --git a/sys/fs/nfs/nfs_var.h b/sys/fs/nfs/nfs_var.h index a9648de6b028..6692bc19a725 100644 --- a/sys/fs/nfs/nfs_var.h +++ b/sys/fs/nfs/nfs_var.h @@ -358,9 +358,9 @@ int nfsv4_seqsession(uint32_t, uint32_t, uint32_t, struct nfsslot *, struct mbuf **, uint16_t); void nfsv4_seqsess_cacherep(uint32_t, struct nfsslot *, int, struct mbuf **); void nfsv4_setsequence(struct nfsmount *, struct nfsrv_descript *, - struct nfsclsession *, int); + struct nfsclsession *, int, struct ucred *); int nfsv4_sequencelookup(struct nfsmount *, struct nfsclsession *, int *, - int *, uint32_t *, uint8_t *); + int *, uint32_t *, uint8_t *, bool); void nfsv4_freeslot(struct nfsclsession *, int, bool); struct ucred *nfsrv_getgrpscred(struct ucred *); struct nfsdevice *nfsv4_findmirror(struct nfsmount *); diff --git a/sys/fs/nfs/nfsclstate.h b/sys/fs/nfs/nfsclstate.h index 03400a2cdea5..2b9b804a08dd 100644 --- a/sys/fs/nfs/nfsclstate.h +++ b/sys/fs/nfs/nfsclstate.h @@ -67,6 +67,7 @@ struct nfsclsession { SVCXPRT *nfsess_xprt; /* For backchannel callback */ uint32_t nfsess_slotseq[64]; /* Max for 64bit nm_slots */ uint64_t nfsess_slots; + uint64_t nfsess_badslots; /* Slots possibly broken */ uint32_t nfsess_sequenceid; uint32_t nfsess_maxcache; /* Max size for cached reply. */ uint32_t nfsess_maxreq; /* Max request size. */ diff --git a/sys/fs/nfsserver/nfs_nfsdstate.c b/sys/fs/nfsserver/nfs_nfsdstate.c index 419851895c7a..eafb7c958396 100644 --- a/sys/fs/nfsserver/nfs_nfsdstate.c +++ b/sys/fs/nfsserver/nfs_nfsdstate.c @@ -6637,8 +6637,8 @@ nfsv4_setcbsequence(struct nfsrv_descript *nd, struct nfsclient *clp, if (error != 0) return (error); sep = *sepp; - (void)nfsv4_sequencelookup(NULL, &sep->sess_cbsess, slotposp, &maxslot, - &slotseq, sessionid); + nfsv4_sequencelookup(NULL, &sep->sess_cbsess, slotposp, &maxslot, + &slotseq, sessionid, true); KASSERT(maxslot >= 0, ("nfsv4_setcbsequence neg maxslot")); /* Build the Sequence arguments. */