From f85c21755e5de76f8f622cdd71f60b49c0751eaa Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 5 Jan 2022 16:41:34 +1000 Subject: [PATCH] nfs4: Use RELEASE_LOCKOWNER when we close a file We create a new lock_owner for every open(), to reduce pressure on the servers lock_owner cache we can tell it that this lock_owner will not be used again and it can drop it from the cache. Signed-off-by: Ronnie Sahlberg --- include/libnfs-private.h | 1 + lib/nfs_v4.c | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/libnfs-private.h b/include/libnfs-private.h index f6ccf7f..c3c4e2d 100644 --- a/include/libnfs-private.h +++ b/include/libnfs-private.h @@ -405,6 +405,7 @@ struct nfsfh { /* NFSv4 */ struct stateid stateid; + uint32_t lock_owner; /* locking */ uint32_t open_seqid; uint32_t lock_seqid; diff --git a/lib/nfs_v4.c b/lib/nfs_v4.c index c11fe6e..e1e3ca3 100644 --- a/lib/nfs_v4.c +++ b/lib/nfs_v4.c @@ -643,6 +643,21 @@ nfs4_op_commit(struct nfs_context *nfs, nfs_argop4 *op) return 1; } +static int +nfs4_op_release_lockowner(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh) +{ + RELEASE_LOCKOWNER4args *rlargs; + + op->argop = OP_RELEASE_LOCKOWNER; + rlargs = &op->nfs_argop4_u.oprelease_lockowner; + + rlargs->lock_owner.clientid = nfs->clientid; + rlargs->lock_owner.owner.owner_len = 4; + rlargs->lock_owner.owner.owner_val = (char *)&fh->lock_owner; + + return 1; +} + static int nfs4_op_close(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh) { @@ -659,6 +674,10 @@ nfs4_op_close(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh) clargs->open_stateid.seqid = fh->stateid.seqid; memcpy(clargs->open_stateid.other, fh->stateid.other, 12); +#ifdef HAVE_MULTITHREADING + i += nfs4_op_release_lockowner(nfs, &op[i], fh); +#endif + return i; } @@ -2123,7 +2142,8 @@ nfs4_open_cb(struct rpc_context *rpc, int status, void *command_data, } memcpy(fh->fh.val, gresok->object.nfs_fh4_val, fh->fh.len); fh->open_seqid = 1; - + fh->lock_owner = data->lock_owner; + if (data->filler.flags & O_SYNC) { fh->is_sync = 1; } @@ -2666,7 +2686,7 @@ nfs4_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data) { COMPOUND4args args; - nfs_argop4 op[3]; + nfs_argop4 op[4]; struct nfs4_cb_data *data; int i;