aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRick Macklem <rmacklem@FreeBSD.org>2021-07-28 22:48:27 +0000
committerRick Macklem <rmacklem@FreeBSD.org>2021-07-28 22:48:27 +0000
commitefea1bc1fd93831c29fa7594d67094e0c125fb88 (patch)
treedd6c6b90f7a6aedbad31e3f0d6c1ede120acbec9
parent54ff3b3986741b9cd06ce20b90c96711cbe146d0 (diff)
downloadsrc-efea1bc1fd93831c29fa7594d67094e0c125fb88.tar.gz
src-efea1bc1fd93831c29fa7594d67094e0c125fb88.zip
nfscl: Cache an open stateid for the "oneopenown" mount option
For NFSv4.1/4.2, if the "oneopenown" mount option is used, there is, at most, only one open stateid for each NFS vnode. When an open stateid for a file is acquired, set a pointer to the open structure in the NFS vnode. This pointer can be used to acquire the open stateid without searching the open linked list when the following is true: - No delegations have been issued for the file. Since delegations can outlive an NFS vnode for a file, use the global NFSMNTP_DELEGISSUED flag on the mount to determine this. - No lock stateid has been issued for the file. To determine this, a new NFS vnode flag called NMIGHTBELOCKED is set when a lock stateid is issued, which can then be tested. When this open structure pointer can be used, it avoids the need to acquire the NFSCLSTATELOCK() and searching the open structure list for an open. The NFSCLSTATELOCK() can be highly contended when there are a lot of opens issued for the NFSv4.1/4.2 mount. This patch only affects NFSv4.1/4.2 mounts when the "oneopenown" mount option is used. MFC after: 2 weeks
-rw-r--r--sys/fs/nfsclient/nfs_clnode.c11
-rw-r--r--sys/fs/nfsclient/nfs_clrpcops.c8
-rw-r--r--sys/fs/nfsclient/nfs_clstate.c36
-rw-r--r--sys/fs/nfsclient/nfs_clvnops.c17
-rw-r--r--sys/fs/nfsclient/nfsnode.h2
5 files changed, 70 insertions, 4 deletions
diff --git a/sys/fs/nfsclient/nfs_clnode.c b/sys/fs/nfsclient/nfs_clnode.c
index 1c0e855ff5a9..9718c2c36a3c 100644
--- a/sys/fs/nfsclient/nfs_clnode.c
+++ b/sys/fs/nfsclient/nfs_clnode.c
@@ -243,7 +243,11 @@ ncl_inactive(struct vop_inactive_args *ap)
boolean_t retv;
td = curthread;
+ np = VTONFS(vp);
if (NFS_ISV4(vp) && vp->v_type == VREG) {
+ NFSLOCKNODE(np);
+ np->n_openstateid = NULL;
+ NFSUNLOCKNODE(np);
/*
* Since mmap()'d files do I/O after VOP_CLOSE(), the NFSv4
* Close operations are delayed until now. Any dirty
@@ -263,7 +267,6 @@ ncl_inactive(struct vop_inactive_args *ap)
}
}
- np = VTONFS(vp);
NFSLOCKNODE(np);
ncl_releasesillyrename(vp, td);
@@ -303,9 +306,10 @@ ncl_reclaim(struct vop_reclaim_args *ap)
NFSLOCKNODE(np);
ncl_releasesillyrename(vp, td);
- NFSUNLOCKNODE(np);
if (NFS_ISV4(vp) && vp->v_type == VREG) {
+ np->n_openstateid = NULL;
+ NFSUNLOCKNODE(np);
/*
* We can now safely close any remaining NFSv4 Opens for
* this file. Most opens will have already been closed by
@@ -325,7 +329,8 @@ ncl_reclaim(struct vop_reclaim_args *ap)
nfscl_delegreturnvp(vp, td);
} else
MNT_IUNLOCK(mp);
- }
+ } else
+ NFSUNLOCKNODE(np);
vfs_hash_remove(vp);
diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c
index acc4bc7b9f88..74803e255aae 100644
--- a/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/sys/fs/nfsclient/nfs_clrpcops.c
@@ -457,8 +457,14 @@ else printf(" fhl=0\n");
* If error is non-zero, don't increment it, since the Open
* hasn't succeeded yet.
*/
- if (!error)
+ if (!error) {
op->nfso_opencnt++;
+ if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp)) {
+ NFSLOCKNODE(np);
+ np->n_openstateid = op;
+ NFSUNLOCKNODE(np);
+ }
+ }
nfscl_openrelease(nmp, op, error, newone);
if (error == NFSERR_GRACE || error == NFSERR_STALECLIENTID ||
error == NFSERR_STALEDONTRECOVER || error == NFSERR_DELAY ||
diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c
index b119f86e2267..bb2c78a72ed9 100644
--- a/sys/fs/nfsclient/nfs_clstate.c
+++ b/sys/fs/nfsclient/nfs_clstate.c
@@ -547,6 +547,34 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
return (EISDIR);
np = VTONFS(vp);
nmp = VFSTONFS(vp->v_mount);
+
+ /*
+ * For "oneopenown" mounts, first check for a cached open in the
+ * NFS vnode, that can be used as a stateid. This can only be
+ * done if no delegations have been issued to the mount and no
+ * byte range file locking has been done for the file.
+ */
+ if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp) && fords == 0) {
+ NFSLOCKMNT(nmp);
+ NFSLOCKNODE(np);
+ if ((nmp->nm_privflag & NFSMNTP_DELEGISSUED) == 0 &&
+ (np->n_flag & NMIGHTBELOCKED) == 0 &&
+ np->n_openstateid != NULL) {
+ stateidp->seqid = 0;
+ stateidp->other[0] =
+ np->n_openstateid->nfso_stateid.other[0];
+ stateidp->other[1] =
+ np->n_openstateid->nfso_stateid.other[1];
+ stateidp->other[2] =
+ np->n_openstateid->nfso_stateid.other[2];
+ NFSUNLOCKNODE(np);
+ NFSUNLOCKMNT(nmp);
+ return (0);
+ }
+ NFSUNLOCKNODE(np);
+ NFSUNLOCKMNT(nmp);
+ }
+
NFSLOCKCLSTATE();
clp = nfscl_findcl(nmp);
if (clp == NULL) {
@@ -4302,9 +4330,17 @@ nfscl_relock(vnode_t vp, struct nfsclclient *clp, struct nfsmount *nmp,
{
struct nfscllockowner *nlp;
struct nfsfh *nfhp;
+ struct nfsnode *np;
u_int64_t off, len;
int error, newone, donelocally;
+ if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp)) {
+ np = VTONFS(vp);
+ NFSLOCKNODE(np);
+ np->n_flag |= NMIGHTBELOCKED;
+ NFSUNLOCKNODE(np);
+ }
+
off = lop->nfslo_first;
len = lop->nfslo_end - lop->nfslo_first;
error = nfscl_getbytelock(vp, off, len, lop->nfslo_type, cred, p,
diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c
index 2311ea099042..72d9eac8e962 100644
--- a/sys/fs/nfsclient/nfs_clvnops.c
+++ b/sys/fs/nfsclient/nfs_clvnops.c
@@ -3166,6 +3166,7 @@ nfs_advlock(struct vop_advlock_args *ap)
struct vattr va;
int ret, error;
u_quad_t size;
+ struct nfsmount *nmp;
error = NFSVOPLOCK(vp, LK_SHARED);
if (error != 0)
@@ -3196,6 +3197,22 @@ nfs_advlock(struct vop_advlock_args *ap)
(void) ncl_flush(vp, MNT_WAIT, td, 1, 0);
/*
+ * Mark NFS node as might have acquired a lock.
+ * This is separate from NHASBEENLOCKED, because it must
+ * be done before the nfsrpc_advlock() call, which might
+ * add a nfscllock structure to the client state.
+ * It is used to check for the case where a nfscllock
+ * state structure cannot exist for the file.
+ * Only done for "oneopenown" NFSv4.1/4.2 mounts.
+ */
+ nmp = VFSTONFS(vp->v_mount);
+ if (NFSHASNFSV4N(nmp) && NFSHASONEOPENOWN(nmp)) {
+ NFSLOCKNODE(np);
+ np->n_flag |= NMIGHTBELOCKED;
+ NFSUNLOCKNODE(np);
+ }
+
+ /*
* Loop around doing the lock op, while a blocking lock
* must wait for the lock op to succeed.
*/
diff --git a/sys/fs/nfsclient/nfsnode.h b/sys/fs/nfsclient/nfsnode.h
index 66a2de31551a..b34e362a8522 100644
--- a/sys/fs/nfsclient/nfsnode.h
+++ b/sys/fs/nfsclient/nfsnode.h
@@ -128,6 +128,7 @@ struct nfsnode {
u_int64_t n_change; /* old Change attribute */
struct nfsv4node *n_v4; /* extra V4 stuff */
struct ucred *n_writecred; /* Cred. for putpages */
+ struct nfsclopen *n_openstateid; /* Cached open stateid */
};
#define n_atim n_un1.nf_atim
@@ -164,6 +165,7 @@ struct nfsnode {
#define NHASBEENLOCKED 0x00080000 /* Has been file locked. */
#define NDSCOMMIT 0x00100000 /* Commit is done via the DS. */
#define NVNSETSZSKIP 0x00200000 /* Skipped vnode_pager_setsize() */
+#define NMIGHTBELOCKED 0x00400000 /* Might be file locked. */
/*
* Convert between nfsnode pointers and vnode pointers