2022-03-25 18:38:01

by Dai Ngo

[permalink] [raw]
Subject: [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server

Hi Chuck, Bruce

This series of patches implement the NFSv4 Courteous Server.

A server which does not immediately expunge the state on lease expiration
is known as a Courteous Server. A Courteous Server continues to recognize
previously generated state tokens as valid until conflict arises between
the expired state and the requests from another client, or the server
reboots.

v2 patch includes:

. add new callback, lm_expire_lock, to lock_manager_operations to
allow the lock manager to take appropriate action with conflict lock.

. handle conflicts of NFSv4 locks with NFSv3/NLM and local locks.

. expire courtesy client after 24hr if client has not reconnected.

. do not allow expired client to become courtesy client if there are
waiters for client's locks.

. modify client_info_show to show courtesy client and seconds from
last renew.

. fix a problem with NFSv4.1 server where the it keeps returning
SEQ4_STATUS_CB_PATH_DOWN in the successful SEQUENCE reply, after
the courtesy client reconnects, causing the client to keep sending
BCTS requests to server.

v3 patch includes:

. modified posix_test_lock to check and resolve conflict locks
to handle NLM TEST and NFSv4 LOCKT requests.

. separate out fix for back channel stuck in SEQ4_STATUS_CB_PATH_DOWN.

v4 patch includes:

. rework nfsd_check_courtesy to avoid dead lock of fl_lock and client_lock
by asking the laudromat thread to destroy the courtesy client.

. handle NFSv4 share reservation conflicts with courtesy client. This
includes conflicts between access mode and deny mode and vice versa.

. drop the patch for back channel stuck in SEQ4_STATUS_CB_PATH_DOWN.

v5 patch includes:

. fix recursive locking of file_rwsem from posix_lock_file.

. retest with LOCKDEP enabled.

v6 patch includes:

. merge witn 5.15-rc7

. fix a bug in nfs4_check_deny_bmap that did not check for matched
nfs4_file before checking for access/deny conflict. This bug causes
pynfs OPEN18 to fail since the server taking too long to release
lots of un-conflict clients' state.

. enhance share reservation conflict handler to handle case where
a large number of conflict courtesy clients need to be expired.
The 1st 100 clients are expired synchronously and the rest are
expired in the background by the laundromat and NFS4ERR_DELAY
is returned to the NFS client. This is needed to prevent the
NFS client from timing out waiting got the reply.

v7 patch includes:

. Fix race condition in posix_test_lock and posix_lock_inode after
dropping spinlock.

. Enhance nfsd4_fl_expire_lock to work with with new lm_expire_lock
callback

. Always resolve share reservation conflicts asynchrously.

. Fix bug in nfs4_laundromat where spinlock is not used when
scanning cl_ownerstr_hashtbl.

. Fix bug in nfs4_laundromat where idr_get_next was called
with incorrect 'id'.

. Merge nfs4_destroy_courtesy_client into nfsd4_fl_expire_lock.

v8 patch includes:

. Fix warning in nfsd4_fl_expire_lock reported by test robot.

v9 patch includes:

. Simplify lm_expire_lock API by (1) remove the 'testonly' flag
and (2) specifying return value as true/false to indicate
whether conflict was succesfully resolved.

. Rework nfsd4_fl_expire_lock to mark client with
NFSD4_DESTROY_COURTESY_CLIENT then tell the laundromat to expire
the client in the background.

. Add a spinlock in nfs4_client to synchronize access to the
NFSD4_COURTESY_CLIENT and NFSD4_DESTROY_COURTESY_CLIENT flag to
handle race conditions when resolving lock and share reservation
conflict.

. Courtesy client that was marked as NFSD4_DESTROY_COURTESY_CLIENT
are now consisdered 'dead', waiting for the laundromat to expire
it. This client is no longer allowed to use its states if it
reconnects before the laundromat finishes expiring the client.

For v4.1 client, the detection is done in the processing of the
SEQUENCE op and returns NFS4ERR_BAD_SESSION to force the client
to re-establish new clientid and session.
For v4.0 client, the detection is done in the processing of the
RENEW and state-related ops and return NFS4ERR_EXPIRE to force
the client to re-establish new clientid.

v10 patch includes:

Resolve deadlock in v9 by avoiding getting cl_client and
cl_cs_lock together. The laundromat needs to determine whether
the expired client has any state and also has no blockers on
its locks. Both of these conditions are allowed to change after
the laundromat transits an expired client to courtesy client.
When this happens, the laundromat will detect it on the next
run and and expire the courtesy client.

Remove client persistent record before marking it as COURTESY_CLIENT
and add client persistent record before clearing the COURTESY_CLIENT
flag to allow the courtesy client to transist to normal client to
continue to use its state.

Lock/delegation/share reversation conflict with courtesy client is
resolved by marking the courtesy client as DESTROY_COURTESY_CLIENT,
effectively disable it, then allow the current request to proceed
immediately.

Courtesy client marked as DESTROY_COURTESY_CLIENT is not allowed
to reconnect to reuse itsstate. It is expired by the laundromat
asynchronously in the background.

Move processing of expired clients from nfs4_laudromat to a
separate function, nfs4_get_client_reaplist, that creates the
reaplist and also to process courtesy clients.

Update Documentation/filesystems/locking.rst to include new
lm_lock_conflict call.

Modify leases_conflict to call lm_breaker_owns_lease only if
there is real conflict. This is to allow the lock manager to
resolve the delegation conflict if possible.

v11 patch includes:

Add comment for lm_lock_conflict callback.

Replace static const courtesy_client_expiry with macro.

Remove courtesy_clnt argument from find_in_sessionid_hashtbl.
Callers use nfs4_client->cl_cs_client boolean to determined if
it's the courtesy client and take appropriate actions.

Rename NFSD4_COURTESY_CLIENT and NFSD4_DESTROY_COURTESY_CLIENT
with NFSD4_CLIENT_COURTESY and NFSD4_CLIENT_DESTROY_COURTESY.

v12 patch includes:

Remove unnecessary comment in nfs4_get_client_reaplist.

Replace nfs4_client->cl_cs_client boolean with
NFSD4_CLIENT_COURTESY_CLNT flag.

Remove courtesy_clnt argument from find_client_in_id_table and
find_clp_in_name_tree. Callers use NFSD4_CLIENT_COURTESY_CLNT to
determined if it's the courtesy client and take appropriate actions.

v13 patch includes:

Merge with 5.17-rc3.

Cleanup Documentation/filesystems/locking.rst: replace i_lock
with flc_lock, update API's that use flc_lock.

Rename lm_lock_conflict to lm_lock_expired().

Remove comment of lm_lock_expired API in lock_manager_operations.
Same information is in patch description.

Update commit messages of 4/4.

Add some comment for NFSD4_CLIENT_COURTESY_CLNT.

Add nfsd4_discard_courtesy_clnt() to eliminate duplicate code of
discarding courtesy client; setting NFSD4_DESTROY_COURTESY_CLIENT.

v14 patch includes:

. merge with Chuck's public for-next branch.

. remove courtesy_client_expiry, use client's last renew time.

. simplify comment of nfs4_check_access_deny_bmap.

. add comment about race condition in nfs4_get_client_reaplist.

. add list_del when walking cslist in nfs4_get_client_reaplist.

. remove duplicate INIT_LIST_HEAD(&reaplist) from nfs4_laundromat

. Modify find_confirmed_client and find_confirmed_client_by_name
to detect courtesy client and destroy it.

. refactor lookup_clientid to use find_client_in_id_table
directly instead of find_confirmed_client.

. refactor nfsd4_setclientid to call find_clp_in_name_tree
directly instead of find_confirmed_client_by_name.

. remove comment of NFSD4_CLIENT_COURTESY.

. replace NFSD4_CLIENT_DESTROY_COURTESY with NFSD4_CLIENT_EXPIRED.

. replace NFSD4_CLIENT_COURTESY_CLNT with NFSD4_CLIENT_RECONNECTED.

v15 patch includes:

. add helper locks_has_blockers_locked in fs.h to check for
lock blockers

. rename nfs4_conflict_clients to nfs4_resolve_deny_conflicts_locked

. update nfs4_upgrade_open() to handle courtesy clients.

. add helper nfs4_check_and_expire_courtesy_client and
nfs4_is_courtesy_client_expired to deduplicate some code.

. update nfs4_anylock_blocker:
. replace list_for_each_entry_safe with list_for_each_entry
. break nfs4_anylock_blocker into 2 smaller functions.

. update nfs4_get_client_reaplist:
. remove unnecessary commets
. acquire cl_cs_lock before setting NFSD4_CLIENT_COURTESY flag

. update client_info_show to show 'time since last renew: 00:00:38'
instead of 'seconds from last renew: 38'.

v16 patch includes:

. update client_info_show to display 'status' as
'confirmed/unconfirmed/courtesy'

. replace helper locks_has_blockers_locked in fs.h in v15 with new
locks_owner_has_blockers call in fs/locks.c

. update nfs4_lockowner_has_blockers to use locks_owner_has_blockers

. move nfs4_check_and_expire_courtesy_client from 5/11 to 4/11

. remove unnecessary check for NULL clp in find_in_sessionid_hashtb

. fix typo in commit messages

v17 patch includes:

. replace flags used for courtesy client with enum courtesy_client_state

. add state table in nfsd/state.h

. make nfsd4_expire_courtesy_clnt, nfsd4_discard_courtesy_clnt and
nfsd4_courtesy_clnt_expired as static inline.

. update nfsd_breaker_owns_lease to use dl->dl_stid.sc_client directly

. fix kernel test robot warning when CONFIG_FILE_LOCKING not defined.

v18 patch includes:

. modify 0005-NFSD-Update-nfs4_get_vfs_file-to-handle-courtesy-cli.patch to:

. remove nfs4_check_access_deny_bmap, fold this functionality
into nfs4_resolve_deny_conflicts_locked by making use of
bmap_to_share_mode.

. move nfs4_resolve_deny_conflicts_locked into nfs4_file_get_access
and nfs4_file_check_deny.


2022-03-25 19:21:20

by Dai Ngo

[permalink] [raw]
Subject: [PATCH RFC v18 06/11] NFSD: Update find_clp_in_name_tree() to handle courtesy client

Update find_clp_in_name_tree to check and expire courtesy client.

Update find_confirmed_client_by_name to discard the courtesy
client by setting CLIENT_EXPIRED.

Update nfsd4_setclientid to expire client with CLIENT_EXPIRED
state to prevent multiple confirmed clients with the same name
on the conf_name_tree.

Signed-off-by: Dai Ngo <[email protected]>
---
fs/nfsd/nfs4state.c | 27 ++++++++++++++++++++++++---
fs/nfsd/state.h | 22 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index fe8969ba94b3..eadce5d19473 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2893,8 +2893,11 @@ find_clp_in_name_tree(struct xdr_netobj *name, struct rb_root *root)
node = node->rb_left;
else if (cmp < 0)
node = node->rb_right;
- else
+ else {
+ if (nfsd4_courtesy_clnt_expired(clp))
+ return NULL;
return clp;
+ }
}
return NULL;
}
@@ -2973,8 +2976,15 @@ static bool clp_used_exchangeid(struct nfs4_client *clp)
static struct nfs4_client *
find_confirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn)
{
+ struct nfs4_client *clp;
+
lockdep_assert_held(&nn->client_lock);
- return find_clp_in_name_tree(name, &nn->conf_name_tree);
+ clp = find_clp_in_name_tree(name, &nn->conf_name_tree);
+ if (clp && clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ nfsd4_discard_courtesy_clnt(clp);
+ clp = NULL;
+ }
+ return clp;
}

static struct nfs4_client *
@@ -4091,12 +4101,19 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfs4_client *unconf = NULL;
__be32 status;
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+ struct nfs4_client *cclient = NULL;

new = create_client(clname, rqstp, &clverifier);
if (new == NULL)
return nfserr_jukebox;
spin_lock(&nn->client_lock);
- conf = find_confirmed_client_by_name(&clname, nn);
+ /* find confirmed client by name */
+ conf = find_clp_in_name_tree(&clname, &nn->conf_name_tree);
+ if (conf && conf->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ cclient = conf;
+ conf = NULL;
+ }
+
if (conf && client_has_state(conf)) {
status = nfserr_clid_inuse;
if (clp_used_exchangeid(conf))
@@ -4127,7 +4144,11 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
new = NULL;
status = nfs_ok;
out:
+ if (cclient)
+ unhash_client_locked(cclient);
spin_unlock(&nn->client_lock);
+ if (cclient)
+ expire_client(cclient);
if (new)
free_client(new);
if (unconf) {
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index d156ae3ab46c..14b2c158ccca 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -735,6 +735,7 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);
extern int nfsd4_client_record_check(struct nfs4_client *clp);
extern void nfsd4_record_grace_done(struct nfsd_net *nn);

+/* courteous server */
static inline bool
nfsd4_expire_courtesy_clnt(struct nfs4_client *clp)
{
@@ -749,4 +750,25 @@ nfsd4_expire_courtesy_clnt(struct nfs4_client *clp)
return rc;
}

+static inline void
+nfsd4_discard_courtesy_clnt(struct nfs4_client *clp)
+{
+ spin_lock(&clp->cl_cs_lock);
+ clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED;
+ spin_unlock(&clp->cl_cs_lock);
+}
+
+static inline bool
+nfsd4_courtesy_clnt_expired(struct nfs4_client *clp)
+{
+ bool rc = false;
+
+ spin_lock(&clp->cl_cs_lock);
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED)
+ rc = true;
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY)
+ clp->cl_cs_client_state = NFSD4_CLIENT_RECONNECTED;
+ spin_unlock(&clp->cl_cs_lock);
+ return rc;
+}
#endif /* NFSD4_STATE_H */
--
2.9.5

2022-03-25 19:29:50

by Dai Ngo

[permalink] [raw]
Subject: [PATCH RFC v18 08/11] NFSD: Update find_client_in_id_table() to handle courtesy client

Update find_client_in_id_table to:
. skip client with CLIENT_EXPIRED; discarded courtesy client
. if courtesy client was found then set CLIENT_RECONNECTED
state so caller can take appropriate action.

Update find_confirmed_client to discard courtesy client.
Update lookup_clientid to call find_client_in_id_table directly.
Update set_client to create client record for courtesy client.
Update find_cpntf_state to discard courtesy client.

Signed-off-by: Dai Ngo <[email protected]>
---
fs/nfsd/nfs4state.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 3e9cdc4a4a47..fe34d6780713 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2952,6 +2952,8 @@ find_client_in_id_table(struct list_head *tbl, clientid_t *clid, bool sessions)
if (same_clid(&clp->cl_clientid, clid)) {
if ((bool)clp->cl_minorversion != sessions)
return NULL;
+ if (nfsd4_courtesy_clnt_expired(clp))
+ continue;
renew_client_locked(clp);
return clp;
}
@@ -2963,9 +2965,15 @@ static struct nfs4_client *
find_confirmed_client(clientid_t *clid, bool sessions, struct nfsd_net *nn)
{
struct list_head *tbl = nn->conf_id_hashtbl;
+ struct nfs4_client *clp;

lockdep_assert_held(&nn->client_lock);
- return find_client_in_id_table(tbl, clid, sessions);
+ clp = find_client_in_id_table(tbl, clid, sessions);
+ if (clp && clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ nfsd4_discard_courtesy_clnt(clp);
+ clp = NULL;
+ }
+ return clp;
}

static struct nfs4_client *
@@ -4881,9 +4889,10 @@ static struct nfs4_client *lookup_clientid(clientid_t *clid, bool sessions,
struct nfsd_net *nn)
{
struct nfs4_client *found;
+ struct list_head *tbl = nn->conf_id_hashtbl;

spin_lock(&nn->client_lock);
- found = find_confirmed_client(clid, sessions, nn);
+ found = find_client_in_id_table(tbl, clid, sessions);
if (found)
atomic_inc(&found->cl_rpc_users);
spin_unlock(&nn->client_lock);
@@ -4908,6 +4917,8 @@ static __be32 set_client(clientid_t *clid,
cstate->clp = lookup_clientid(clid, false, nn);
if (!cstate->clp)
return nfserr_expired;
+ if (cstate->clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)
+ nfsd4_client_record_create(cstate->clp);
return nfs_ok;
}

@@ -6144,6 +6155,13 @@ static __be32 find_cpntf_state(struct nfsd_net *nn, stateid_t *st,
found = lookup_clientid(&cps->cp_p_clid, true, nn);
if (!found)
goto out;
+ if (found->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ nfsd4_discard_courtesy_clnt(found);
+ if (atomic_dec_and_lock(&found->cl_rpc_users,
+ &nn->client_lock))
+ spin_unlock(&nn->client_lock);
+ goto out;
+ }

*stid = find_stateid_by_type(found, &cps->cp_p_stateid,
NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID);
--
2.9.5

2022-03-25 19:41:55

by Dai Ngo

[permalink] [raw]
Subject: [PATCH RFC v18 03/11] NFSD: Add lm_lock_expired call out

Add callout function nfsd4_lm_lock_expired for lm_lock_expired.
If lock request has conflict with courtesy client then expire the
courtesy client and return no conflict to caller.

Signed-off-by: Dai Ngo <[email protected]>
---
fs/nfsd/nfs4state.c | 22 ++++++++++++++++++++++
fs/nfsd/state.h | 14 ++++++++++++++
2 files changed, 36 insertions(+)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a65d59510681..80772662236b 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6578,10 +6578,32 @@ nfsd4_lm_notify(struct file_lock *fl)
}
}

+/**
+ * nfsd4_lm_lock_expired - check if lock conflict can be resolved.
+ *
+ * @fl: pointer to file_lock with a potential conflict
+ * Return values:
+ * %false: real conflict, lock conflict can not be resolved.
+ * %true: no conflict, lock conflict was resolved.
+ *
+ * Note that this function is called while the flc_lock is held.
+ */
+static bool
+nfsd4_lm_lock_expired(struct file_lock *fl)
+{
+ struct nfs4_lockowner *lo;
+
+ if (!fl)
+ return false;
+ lo = (struct nfs4_lockowner *)fl->fl_owner;
+ return nfsd4_expire_courtesy_clnt(lo->lo_owner.so_client);
+}
+
static const struct lock_manager_operations nfsd_posix_mng_ops = {
.lm_notify = nfsd4_lm_notify,
.lm_get_owner = nfsd4_lm_get_owner,
.lm_put_owner = nfsd4_lm_put_owner,
+ .lm_lock_expired = nfsd4_lm_lock_expired,
};

static inline void
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 40e390abc842..d156ae3ab46c 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -735,4 +735,18 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);
extern int nfsd4_client_record_check(struct nfs4_client *clp);
extern void nfsd4_record_grace_done(struct nfsd_net *nn);

+static inline bool
+nfsd4_expire_courtesy_clnt(struct nfs4_client *clp)
+{
+ bool rc = false;
+
+ spin_lock(&clp->cl_cs_lock);
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY)
+ clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED;
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED)
+ rc = true;
+ spin_unlock(&clp->cl_cs_lock);
+ return rc;
+}
+
#endif /* NFSD4_STATE_H */
--
2.9.5

2022-03-25 19:55:53

by Dai Ngo

[permalink] [raw]
Subject: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

Update nfs4_client to add:
. cl_cs_client_state: courtesy client state
. cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
. cl_cs_list: list used by laundromat to process courtesy clients

Modify alloc_client to initialize these fields.

Signed-off-by: Dai Ngo <[email protected]>
---
fs/nfsd/nfs4state.c | 2 ++
fs/nfsd/nfsd.h | 1 +
fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
3 files changed, 36 insertions(+)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 234e852fcdfa..a65d59510681 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
INIT_LIST_HEAD(&clp->cl_delegations);
INIT_LIST_HEAD(&clp->cl_lru);
INIT_LIST_HEAD(&clp->cl_revoked);
+ INIT_LIST_HEAD(&clp->cl_cs_list);
#ifdef CONFIG_NFSD_PNFS
INIT_LIST_HEAD(&clp->cl_lo_states);
#endif
INIT_LIST_HEAD(&clp->async_copies);
spin_lock_init(&clp->async_lock);
spin_lock_init(&clp->cl_lock);
+ spin_lock_init(&clp->cl_cs_lock);
rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
return clp;
err_no_hashtbl:
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 4fc1fd639527..23996c6ca75e 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
#define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */

#define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
+#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */

/*
* The following attributes are currently not supported by the NFSv4 server:
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 95457cfd37fc..40e390abc842 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
#define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */

/*
+ * CLIENT_ CLIENT_ CLIENT_
+ * COURTESY EXPIRED RECONNECTED Meaning Where set
+ * -----------------------------------------------------------------------------
+ * | false | false | false | Confirmed, active | Default |
+ * |---------------------------------------------------------------------------|
+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
+ * | | | | Lease/lock/share | |
+ * | | | | reservation conflict | |
+ * | | | | can cause Courtesy | |
+ * | | | | client to be expired | |
+ * |---------------------------------------------------------------------------|
+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
+ * | | | | | nfsd4_expire_courtesy_clnt |
+ * |---------------------------------------------------------------------------|
+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
+ * | | | | reconnected, | |
+ * | | | | becoming active | |
+ * -----------------------------------------------------------------------------
+ */
+
+enum courtesy_client_state {
+ NFSD4_CLIENT_COURTESY = 1,
+ NFSD4_CLIENT_EXPIRED,
+ NFSD4_CLIENT_RECONNECTED,
+};
+
+/*
* struct nfs4_client - one per client. Clientids live here.
*
* The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
@@ -385,6 +414,10 @@ struct nfs4_client {
struct list_head async_copies; /* list of async copies */
spinlock_t async_lock; /* lock for async copies */
atomic_t cl_cb_inflight; /* Outstanding callbacks */
+
+ enum courtesy_client_state cl_cs_client_state;
+ spinlock_t cl_cs_lock;
+ struct list_head cl_cs_list;
};

/* struct nfs4_client_reset
--
2.9.5

2022-03-29 20:11:21

by Dai Ngo

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server


On 3/29/22 9:30 AM, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>> Update nfs4_client to add:
>>>> . cl_cs_client_state: courtesy client state
>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>
>>>> Modify alloc_client to initialize these fields.
>>>>
>>>> Signed-off-by: Dai Ngo <[email protected]>
>>>> ---
>>>> fs/nfsd/nfs4state.c | 2 ++
>>>> fs/nfsd/nfsd.h | 1 +
>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>> 3 files changed, 36 insertions(+)
>>>>
>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>> index 234e852fcdfa..a65d59510681 100644
>>>> --- a/fs/nfsd/nfs4state.c
>>>> +++ b/fs/nfsd/nfs4state.c
>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>> #ifdef CONFIG_NFSD_PNFS
>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>> #endif
>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>> spin_lock_init(&clp->async_lock);
>>>> spin_lock_init(&clp->cl_lock);
>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>> return clp;
>>>> err_no_hashtbl:
>>>> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
>>>> index 4fc1fd639527..23996c6ca75e 100644
>>>> --- a/fs/nfsd/nfsd.h
>>>> +++ b/fs/nfsd/nfsd.h
>>>> @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
>>>> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
>>>> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
>>>> +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
>>>> /*
>>>> * The following attributes are currently not supported by the NFSv4 server:
>>>> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
>>>> index 95457cfd37fc..40e390abc842 100644
>>>> --- a/fs/nfsd/state.h
>>>> +++ b/fs/nfsd/state.h
>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>> /*
>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>> + * -----------------------------------------------------------------------------
>>>> + * | false | false | false | Confirmed, active | Default |
>>>> + * |---------------------------------------------------------------------------|
>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>> + * | | | | Lease/lock/share | |
>>>> + * | | | | reservation conflict | |
>>>> + * | | | | can cause Courtesy | |
>>>> + * | | | | client to be expired | |
>>>> + * |---------------------------------------------------------------------------|
>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>> + * |---------------------------------------------------------------------------|
>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>> + * | | | | reconnected, | |
>>>> + * | | | | becoming active | |
>>>> + * -----------------------------------------------------------------------------
> By the way, where is a client returned to the normal (0) state? That
> has to happen at some point.

For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
nfsd4_bind_conn_to_session. For 4.0 courtesy client reconnects is
detected in set_client.

>
> How is CLIENT_EXPIRED treated differently from cl_time == 0, and why?

cl_time == 0 means the client is being destroyed (almost) immediately
either by the laundromat or force_expire_client.

CLIENT_EXPIRED means the client will be destroyed by the laundromat
and this depends on when the laundromat runs. When we set CLIENT_COURTESY
we don't clear cl_time since the client is not really expired yet.

We could replace CLIENT_EXPIRED with (cl_time == 0). However,
to set cl_time = 0 we need to acquire the nn->client_lock which
causes deadlock when we try to resolve lock conflicts
from nfs4_resolve_deny_conflicts_locked (fp->fi_lock -> nn_clientlock).
We use the cl_cs_lock to set CLIENT_EXPIRED.

>
> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> a bind_conn_to_session fails).

find_in_sessionid_hashtbl: we discard the courtesy client when it
reconnects and there is error from nfsd4_get_session_locked. This
should be a rare condition so rather than reverting the client
state back to courtesy, it is simpler just to discard it.

nfsd4_create_session/find_confirmed_client: I think the only time
the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
to reconnect after missing its leases, is when it wants to do clientid
trunking. This should be a rare condition so instead of dealing
with it we just do not allow it and discard the client for now.

nfsd4_destroy_clientid/find_confirmed_client: instead of destroy
the courtesy client here we just let the laundromat destroy it
as if the client already expired.

nfsd4_setclientid_confirm/find_confirmed_client: there should not
be any courtesy client found from nfsd4_setclientid_confirm, it
should be detected and discarded in nfsd4_setclientid.

-Dai

>>> These are mutually exclusive values, not bits that may set to 0 or 1, so
>>> the three boolean columns are confusing. I'd just structure the table
>>> like:
>>>
>>> client state meaning where set
>>> 0 Confirmed, active Default
>>> CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
>>> CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
>>>
>>> etc.
>> will fix in v19.
>>
>> Thanks,
>> -Dai
>>
>>> --b.
>>>
>>>> + */
>>>> +
>>>> +enum courtesy_client_state {
>>>> + NFSD4_CLIENT_COURTESY = 1,
>>>> + NFSD4_CLIENT_EXPIRED,
>>>> + NFSD4_CLIENT_RECONNECTED,
>>>> +};
>>>> +
>>>> +/*
>>>> * struct nfs4_client - one per client. Clientids live here.
>>>> *
>>>> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
>>>> @@ -385,6 +414,10 @@ struct nfs4_client {
>>>> struct list_head async_copies; /* list of async copies */
>>>> spinlock_t async_lock; /* lock for async copies */
>>>> atomic_t cl_cb_inflight; /* Outstanding callbacks */
>>>> +
>>>> + enum courtesy_client_state cl_cs_client_state;
>>>> + spinlock_t cl_cs_lock;
>>>> + struct list_head cl_cs_list;
>>>> };
>>>> /* struct nfs4_client_reset
>>>> --
>>>> 2.9.5

2022-03-29 20:14:38

by Dai Ngo

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server


On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>> Update nfs4_client to add:
>> . cl_cs_client_state: courtesy client state
>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>> . cl_cs_list: list used by laundromat to process courtesy clients
>>
>> Modify alloc_client to initialize these fields.
>>
>> Signed-off-by: Dai Ngo <[email protected]>
>> ---
>> fs/nfsd/nfs4state.c | 2 ++
>> fs/nfsd/nfsd.h | 1 +
>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>> 3 files changed, 36 insertions(+)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index 234e852fcdfa..a65d59510681 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>> INIT_LIST_HEAD(&clp->cl_delegations);
>> INIT_LIST_HEAD(&clp->cl_lru);
>> INIT_LIST_HEAD(&clp->cl_revoked);
>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>> #ifdef CONFIG_NFSD_PNFS
>> INIT_LIST_HEAD(&clp->cl_lo_states);
>> #endif
>> INIT_LIST_HEAD(&clp->async_copies);
>> spin_lock_init(&clp->async_lock);
>> spin_lock_init(&clp->cl_lock);
>> + spin_lock_init(&clp->cl_cs_lock);
>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>> return clp;
>> err_no_hashtbl:
>> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
>> index 4fc1fd639527..23996c6ca75e 100644
>> --- a/fs/nfsd/nfsd.h
>> +++ b/fs/nfsd/nfsd.h
>> @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
>> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
>>
>> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
>> +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
>>
>> /*
>> * The following attributes are currently not supported by the NFSv4 server:
>> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
>> index 95457cfd37fc..40e390abc842 100644
>> --- a/fs/nfsd/state.h
>> +++ b/fs/nfsd/state.h
>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>
>> /*
>> + * CLIENT_ CLIENT_ CLIENT_
>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>> + * -----------------------------------------------------------------------------
>> + * | false | false | false | Confirmed, active | Default |
>> + * |---------------------------------------------------------------------------|
>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>> + * | | | | Lease/lock/share | |
>> + * | | | | reservation conflict | |
>> + * | | | | can cause Courtesy | |
>> + * | | | | client to be expired | |
>> + * |---------------------------------------------------------------------------|
>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>> + * | | | | | nfsd4_expire_courtesy_clnt |
>> + * |---------------------------------------------------------------------------|
>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>> + * | | | | reconnected, | |
>> + * | | | | becoming active | |
>> + * -----------------------------------------------------------------------------
> These are mutually exclusive values, not bits that may set to 0 or 1, so
> the three boolean columns are confusing. I'd just structure the table
> like:
>
> client state meaning where set
> 0 Confirmed, active Default
> CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
> CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
>
> etc.

will fix in v19.

Thanks,
-Dai

>
> --b.
>
>> + */
>> +
>> +enum courtesy_client_state {
>> + NFSD4_CLIENT_COURTESY = 1,
>> + NFSD4_CLIENT_EXPIRED,
>> + NFSD4_CLIENT_RECONNECTED,
>> +};
>> +
>> +/*
>> * struct nfs4_client - one per client. Clientids live here.
>> *
>> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
>> @@ -385,6 +414,10 @@ struct nfs4_client {
>> struct list_head async_copies; /* list of async copies */
>> spinlock_t async_lock; /* lock for async copies */
>> atomic_t cl_cb_inflight; /* Outstanding callbacks */
>> +
>> + enum courtesy_client_state cl_cs_client_state;
>> + spinlock_t cl_cs_lock;
>> + struct list_head cl_cs_list;
>> };
>>
>> /* struct nfs4_client_reset
>> --
>> 2.9.5

2022-03-29 23:31:52

by Chuck Lever

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server



> On Mar 29, 2022, at 3:49 PM, Bruce Fields <[email protected]> wrote:
>
> On Tue, Mar 29, 2022 at 07:32:57PM +0000, Chuck Lever III wrote:
>>
>>
>>> On Mar 29, 2022, at 2:39 PM, J. Bruce Fields <[email protected]> wrote:
>>>
>>> On Tue, Mar 29, 2022 at 11:19:51AM -0700, [email protected] wrote:
>>>>
>>>> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
>>>>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
>>>>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>>>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>>>>>> Update nfs4_client to add:
>>>>>>>> . cl_cs_client_state: courtesy client state
>>>>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>>>>>
>>>>>>>> Modify alloc_client to initialize these fields.
>>>>>>>>
>>>>>>>> Signed-off-by: Dai Ngo <[email protected]>
>>>>>>>> ---
>>>>>>>> fs/nfsd/nfs4state.c | 2 ++
>>>>>>>> fs/nfsd/nfsd.h | 1 +
>>>>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>>>>>> 3 files changed, 36 insertions(+)
>>>>>>>>
>>>>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>>>>>> index 234e852fcdfa..a65d59510681 100644
>>>>>>>> --- a/fs/nfsd/nfs4state.c
>>>>>>>> +++ b/fs/nfsd/nfs4state.c
>>>>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>>>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>>>>>> #ifdef CONFIG_NFSD_PNFS
>>>>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>>>>>> #endif
>>>>>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>>>>>> spin_lock_init(&clp->async_lock);
>>>>>>>> spin_lock_init(&clp->cl_lock);
>>>>>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>>>>>> return clp;
>>>>>>>> err_no_hashtbl:
>>>>>>>> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
>>>>>>>> index 4fc1fd639527..23996c6ca75e 100644
>>>>>>>> --- a/fs/nfsd/nfsd.h
>>>>>>>> +++ b/fs/nfsd/nfsd.h
>>>>>>>> @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
>>>>>>>> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
>>>>>>>> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
>>>>>>>> +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
>>>>>>>> /*
>>>>>>>> * The following attributes are currently not supported by the NFSv4 server:
>>>>>>>> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
>>>>>>>> index 95457cfd37fc..40e390abc842 100644
>>>>>>>> --- a/fs/nfsd/state.h
>>>>>>>> +++ b/fs/nfsd/state.h
>>>>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>>>>>> /*
>>>>>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>>>>>> + * -----------------------------------------------------------------------------
>>>>>>>> + * | false | false | false | Confirmed, active | Default |
>>>>>>>> + * |---------------------------------------------------------------------------|
>>>>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>>>>>> + * | | | | Lease/lock/share | |
>>>>>>>> + * | | | | reservation conflict | |
>>>>>>>> + * | | | | can cause Courtesy | |
>>>>>>>> + * | | | | client to be expired | |
>>>>>>>> + * |---------------------------------------------------------------------------|
>>>>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>>>>>> + * |---------------------------------------------------------------------------|
>>>>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>>>>>> + * | | | | reconnected, | |
>>>>>>>> + * | | | | becoming active | |
>>>>>>>> + * -----------------------------------------------------------------------------
>>>>> By the way, where is a client returned to the normal (0) state? That
>>>>> has to happen at some point.
>>>>
>>>> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
>>>> nfsd4_bind_conn_to_session.
>>>
>>> Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
>>> the question I asked.
>>
>> "reconnected" simply means the client has gotten back in touch.
>
> Again, my question was: when is cl_cs_client_state set back to 0? As
> far as I can tell, the answer is never. That means, even long after the
> client has reconnected, it's left in a weird state where it can be
> suddenly expired for all sorts of reasons.

Got it. Agreed, cl_cs_client_state should be reinitialized if
a courtesy client is transitioned back to "active".

Dai, would you add

+enum courtesy_client_state {
>>> NFSD4_CLIENT_ACTIVE = 0,
+ NFSD4_CLIENT_COURTESY,
+ NFSD4_CLIENT_EXPIRED,
+ NFSD4_CLIENT_RECONNECTED,
+};

And set cl_cs_client_state to ACTIVE where the client is
allowed to transition back to being active?


>> The server then has to decide whether to allow the client to
>> become active again or it needs to purge it. That decision
>> is different for each operation and minor version. Look for
>> "if (cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)" for how
>> those choices are made.
>>
>>
>>>>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
>>>>> a bind_conn_to_session fails).
>>>>
>>>> find_in_sessionid_hashtbl: we discard the courtesy client when it
>>>> reconnects and there is error from nfsd4_get_session_locked. This
>>>> should be a rare condition so rather than reverting the client
>>>> state back to courtesy, it is simpler just to discard it.
>>>
>>> That may be a rare situation, but I don't believe the behavior of
>>> discarding the client in this case is correct.
>>
>> Can you explain this? It's a courtesy client... the server can
>> decide it's expired at that point, can't it? IOW what breaks?
>
> I'm not worried about courtesy clients, I'm worried about clients that
> were courtesy clients but have since succesfully renewed their state.
> Expiring them for a failed bind_conn_to_session isn't right.


--
Chuck Lever



2022-03-30 00:05:31

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> Update nfs4_client to add:
> . cl_cs_client_state: courtesy client state
> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> . cl_cs_list: list used by laundromat to process courtesy clients
>
> Modify alloc_client to initialize these fields.
>
> Signed-off-by: Dai Ngo <[email protected]>
> ---
> fs/nfsd/nfs4state.c | 2 ++
> fs/nfsd/nfsd.h | 1 +
> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> 3 files changed, 36 insertions(+)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 234e852fcdfa..a65d59510681 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> INIT_LIST_HEAD(&clp->cl_delegations);
> INIT_LIST_HEAD(&clp->cl_lru);
> INIT_LIST_HEAD(&clp->cl_revoked);
> + INIT_LIST_HEAD(&clp->cl_cs_list);
> #ifdef CONFIG_NFSD_PNFS
> INIT_LIST_HEAD(&clp->cl_lo_states);
> #endif
> INIT_LIST_HEAD(&clp->async_copies);
> spin_lock_init(&clp->async_lock);
> spin_lock_init(&clp->cl_lock);
> + spin_lock_init(&clp->cl_cs_lock);
> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> return clp;
> err_no_hashtbl:
> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> index 4fc1fd639527..23996c6ca75e 100644
> --- a/fs/nfsd/nfsd.h
> +++ b/fs/nfsd/nfsd.h
> @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
>
> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
> +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
>
> /*
> * The following attributes are currently not supported by the NFSv4 server:
> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
> index 95457cfd37fc..40e390abc842 100644
> --- a/fs/nfsd/state.h
> +++ b/fs/nfsd/state.h
> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>
> /*
> + * CLIENT_ CLIENT_ CLIENT_
> + * COURTESY EXPIRED RECONNECTED Meaning Where set
> + * -----------------------------------------------------------------------------
> + * | false | false | false | Confirmed, active | Default |
> + * |---------------------------------------------------------------------------|
> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> + * | | | | Lease/lock/share | |
> + * | | | | reservation conflict | |
> + * | | | | can cause Courtesy | |
> + * | | | | client to be expired | |
> + * |---------------------------------------------------------------------------|
> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> + * | | | | | nfsd4_expire_courtesy_clnt |
> + * |---------------------------------------------------------------------------|
> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> + * | | | | reconnected, | |
> + * | | | | becoming active | |
> + * -----------------------------------------------------------------------------

These are mutually exclusive values, not bits that may set to 0 or 1, so
the three boolean columns are confusing. I'd just structure the table
like:

client state meaning where set
0 Confirmed, active Default
CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat

etc.

--b.

> + */
> +
> +enum courtesy_client_state {
> + NFSD4_CLIENT_COURTESY = 1,
> + NFSD4_CLIENT_EXPIRED,
> + NFSD4_CLIENT_RECONNECTED,
> +};
> +
> +/*
> * struct nfs4_client - one per client. Clientids live here.
> *
> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
> @@ -385,6 +414,10 @@ struct nfs4_client {
> struct list_head async_copies; /* list of async copies */
> spinlock_t async_lock; /* lock for async copies */
> atomic_t cl_cb_inflight; /* Outstanding callbacks */
> +
> + enum courtesy_client_state cl_cs_client_state;
> + spinlock_t cl_cs_lock;
> + struct list_head cl_cs_list;
> };
>
> /* struct nfs4_client_reset
> --
> 2.9.5

2022-03-30 03:32:29

by Dai Ngo

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server


On 3/29/22 1:01 PM, Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 07:58:46PM +0000, Chuck Lever III wrote:
>> Got it. Agreed, cl_cs_client_state should be reinitialized if
>> a courtesy client is transitioned back to "active".
>>
>> Dai, would you add
>>
>> +enum courtesy_client_state {
>>>>> NFSD4_CLIENT_ACTIVE = 0,
>> + NFSD4_CLIENT_COURTESY,
>> + NFSD4_CLIENT_EXPIRED,
>> + NFSD4_CLIENT_RECONNECTED,
>> +};
>>
>> And set cl_cs_client_state to ACTIVE where the client is
>> allowed to transition back to being active?

fix in v19.

> I'm not clear then what the RECONNECTED->ACTIVE transition would be.
>
> My feeling is that the RECONNECTED state shouldn't exist, and that there
> should only be a transition of EXPIRED back to ACTIVE.

For the client to be truly active we need to create the client record.
We do not want to create the client record when we just detect that
the client reconnects because not all the callers want the client to
be active, we leave it for the callers to decide. Also some callers of
nfsd4_courtesy_clnt_expired hold the nn->client_lock so we can create
the client record there.

Leaving the NFSD4_CLIENT_RECONNECTED state set does not really
cause any functional problem since the RECONNECT state is meant
to used temporary within the context of the same request. But
I will reset the state back to NFSD4_CLIENT_ACTIVE for clarity.


-Dai

>
> --b.

2022-03-30 07:13:58

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Tue, Mar 29, 2022 at 02:45:28PM -0700, [email protected] wrote:
> This does not prevent the courtesy client from doing trunking in all
> cases. It is only prevent the courtesy client from doing trunking without
> first reconnect to the server.
>
> I think this behavior is the same as if the server does not support courtesy
> client; the server can expire the courtesy anytime it wants. If the
> courtesy client reconnected successfully then by the time nfsd4_create_session/
> find_confirmed_client is called the client already becomes active
> so the server will process the request normally.

I'm not sure what you mean here. All a client has to do to reconnect is
succesfully renew its lease. That doesn't necessarily require calling
CREATE_SESSION again.

> Also to handle cases when the courtesy client reconnects after it was in
> EXPIRED state, we want to force the client to recover its state starting
> with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.

The client should not have to send EXCHANGE_ID.

--b.

2022-03-30 10:44:06

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Tue, Mar 29, 2022 at 11:19:51AM -0700, [email protected] wrote:
>
> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
> >On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
> >>On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> >>>On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> >>>>Update nfs4_client to add:
> >>>> . cl_cs_client_state: courtesy client state
> >>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> >>>> . cl_cs_list: list used by laundromat to process courtesy clients
> >>>>
> >>>>Modify alloc_client to initialize these fields.
> >>>>
> >>>>Signed-off-by: Dai Ngo <[email protected]>
> >>>>---
> >>>> fs/nfsd/nfs4state.c | 2 ++
> >>>> fs/nfsd/nfsd.h | 1 +
> >>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> >>>> 3 files changed, 36 insertions(+)
> >>>>
> >>>>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>>>index 234e852fcdfa..a65d59510681 100644
> >>>>--- a/fs/nfsd/nfs4state.c
> >>>>+++ b/fs/nfsd/nfs4state.c
> >>>>@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> >>>> INIT_LIST_HEAD(&clp->cl_delegations);
> >>>> INIT_LIST_HEAD(&clp->cl_lru);
> >>>> INIT_LIST_HEAD(&clp->cl_revoked);
> >>>>+ INIT_LIST_HEAD(&clp->cl_cs_list);
> >>>> #ifdef CONFIG_NFSD_PNFS
> >>>> INIT_LIST_HEAD(&clp->cl_lo_states);
> >>>> #endif
> >>>> INIT_LIST_HEAD(&clp->async_copies);
> >>>> spin_lock_init(&clp->async_lock);
> >>>> spin_lock_init(&clp->cl_lock);
> >>>>+ spin_lock_init(&clp->cl_cs_lock);
> >>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> >>>> return clp;
> >>>> err_no_hashtbl:
> >>>>diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> >>>>index 4fc1fd639527..23996c6ca75e 100644
> >>>>--- a/fs/nfsd/nfsd.h
> >>>>+++ b/fs/nfsd/nfsd.h
> >>>>@@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
> >>>> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
> >>>> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
> >>>>+#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
> >>>> /*
> >>>> * The following attributes are currently not supported by the NFSv4 server:
> >>>>diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
> >>>>index 95457cfd37fc..40e390abc842 100644
> >>>>--- a/fs/nfsd/state.h
> >>>>+++ b/fs/nfsd/state.h
> >>>>@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> >>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> >>>> /*
> >>>>+ * CLIENT_ CLIENT_ CLIENT_
> >>>>+ * COURTESY EXPIRED RECONNECTED Meaning Where set
> >>>>+ * -----------------------------------------------------------------------------
> >>>>+ * | false | false | false | Confirmed, active | Default |
> >>>>+ * |---------------------------------------------------------------------------|
> >>>>+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> >>>>+ * | | | | Lease/lock/share | |
> >>>>+ * | | | | reservation conflict | |
> >>>>+ * | | | | can cause Courtesy | |
> >>>>+ * | | | | client to be expired | |
> >>>>+ * |---------------------------------------------------------------------------|
> >>>>+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
> >>>>+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> >>>>+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> >>>>+ * | | | | | nfsd4_expire_courtesy_clnt |
> >>>>+ * |---------------------------------------------------------------------------|
> >>>>+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> >>>>+ * | | | | reconnected, | |
> >>>>+ * | | | | becoming active | |
> >>>>+ * -----------------------------------------------------------------------------
> >By the way, where is a client returned to the normal (0) state? That
> >has to happen at some point.
>
> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
> nfsd4_bind_conn_to_session.

Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
the question I asked.

> >Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> >a bind_conn_to_session fails).
>
> find_in_sessionid_hashtbl: we discard the courtesy client when it
> reconnects and there is error from nfsd4_get_session_locked. This
> should be a rare condition so rather than reverting the client
> state back to courtesy, it is simpler just to discard it.

That may be a rare situation, but I don't believe the behavior of
discarding the client in this case is correct.

> nfsd4_create_session/find_confirmed_client: I think the only time
> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
> to reconnect after missing its leases, is when it wants to do clientid
> trunking. This should be a rare condition so instead of dealing
> with it we just do not allow it and discard the client for now.

We can't wave away incorrect behavior with "but it's rare". Users with
heavy and/or unusual workloads hit rare conditions. Clients may change
their behavior over time. (E.g., trunking may become more common.)

--b.

> nfsd4_destroy_clientid/find_confirmed_client: instead of destroy
> the courtesy client here we just let the laundromat destroy it
> as if the client already expired.
>
> nfsd4_setclientid_confirm/find_confirmed_client: there should not
> be any courtesy client found from nfsd4_setclientid_confirm, it
> should be detected and discarded in nfsd4_setclientid.
>
> -Dai
>
> >>>These are mutually exclusive values, not bits that may set to 0 or 1, so
> >>>the three boolean columns are confusing. I'd just structure the table
> >>>like:
> >>>
> >>> client state meaning where set
> >>> 0 Confirmed, active Default
> >>> CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
> >>> CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
> >>>
> >>>etc.
> >>will fix in v19.
> >>
> >>Thanks,
> >>-Dai
> >>
> >>>--b.
> >>>
> >>>>+ */
> >>>>+
> >>>>+enum courtesy_client_state {
> >>>>+ NFSD4_CLIENT_COURTESY = 1,
> >>>>+ NFSD4_CLIENT_EXPIRED,
> >>>>+ NFSD4_CLIENT_RECONNECTED,
> >>>>+};
> >>>>+
> >>>>+/*
> >>>> * struct nfs4_client - one per client. Clientids live here.
> >>>> *
> >>>> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
> >>>>@@ -385,6 +414,10 @@ struct nfs4_client {
> >>>> struct list_head async_copies; /* list of async copies */
> >>>> spinlock_t async_lock; /* lock for async copies */
> >>>> atomic_t cl_cb_inflight; /* Outstanding callbacks */
> >>>>+
> >>>>+ enum courtesy_client_state cl_cs_client_state;
> >>>>+ spinlock_t cl_cs_lock;
> >>>>+ struct list_head cl_cs_list;
> >>>> };
> >>>> /* struct nfs4_client_reset
> >>>>--
> >>>>2.9.5

2022-03-30 10:48:14

by Chuck Lever

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server



> On Mar 29, 2022, at 4:01 PM, Bruce Fields <[email protected]> wrote:
>
> On Tue, Mar 29, 2022 at 07:58:46PM +0000, Chuck Lever III wrote:
>> Got it. Agreed, cl_cs_client_state should be reinitialized if
>> a courtesy client is transitioned back to "active".
>>
>> Dai, would you add
>>
>> +enum courtesy_client_state {
>>>>> NFSD4_CLIENT_ACTIVE = 0,
>> + NFSD4_CLIENT_COURTESY,
>> + NFSD4_CLIENT_EXPIRED,
>> + NFSD4_CLIENT_RECONNECTED,
>> +};
>>
>> And set cl_cs_client_state to ACTIVE where the client is
>> allowed to transition back to being active?
>
> I'm not clear then what the RECONNECTED->ACTIVE transition would be.
>
> My feeling is that the RECONNECTED state shouldn't exist, and that there
> should only be a transition of EXPIRED back to ACTIVE.

Audit the places that check for NFSD4_CLIENT_RECONNECTED.
Some of them will expire a reconnected client, some will
let it transition back to active. My impression from Dai
was that the server cannot transition a courtesy client
back to active in _every_ case.

If you can demonstrate that in every case where RECONNECTED
is found that a client should be transitioned to ACTIVE
rather than discarded, then yes, we should get rid of
RECONNECTED in favor of going from COURTESY -> ACTIVE.


--
Chuck Lever



2022-03-30 12:08:55

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
>
> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> >On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> >>Update nfs4_client to add:
> >> . cl_cs_client_state: courtesy client state
> >> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> >> . cl_cs_list: list used by laundromat to process courtesy clients
> >>
> >>Modify alloc_client to initialize these fields.
> >>
> >>Signed-off-by: Dai Ngo <[email protected]>
> >>---
> >> fs/nfsd/nfs4state.c | 2 ++
> >> fs/nfsd/nfsd.h | 1 +
> >> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> >> 3 files changed, 36 insertions(+)
> >>
> >>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>index 234e852fcdfa..a65d59510681 100644
> >>--- a/fs/nfsd/nfs4state.c
> >>+++ b/fs/nfsd/nfs4state.c
> >>@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> >> INIT_LIST_HEAD(&clp->cl_delegations);
> >> INIT_LIST_HEAD(&clp->cl_lru);
> >> INIT_LIST_HEAD(&clp->cl_revoked);
> >>+ INIT_LIST_HEAD(&clp->cl_cs_list);
> >> #ifdef CONFIG_NFSD_PNFS
> >> INIT_LIST_HEAD(&clp->cl_lo_states);
> >> #endif
> >> INIT_LIST_HEAD(&clp->async_copies);
> >> spin_lock_init(&clp->async_lock);
> >> spin_lock_init(&clp->cl_lock);
> >>+ spin_lock_init(&clp->cl_cs_lock);
> >> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> >> return clp;
> >> err_no_hashtbl:
> >>diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> >>index 4fc1fd639527..23996c6ca75e 100644
> >>--- a/fs/nfsd/nfsd.h
> >>+++ b/fs/nfsd/nfsd.h
> >>@@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
> >> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
> >> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
> >>+#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
> >> /*
> >> * The following attributes are currently not supported by the NFSv4 server:
> >>diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
> >>index 95457cfd37fc..40e390abc842 100644
> >>--- a/fs/nfsd/state.h
> >>+++ b/fs/nfsd/state.h
> >>@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> >> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> >> /*
> >>+ * CLIENT_ CLIENT_ CLIENT_
> >>+ * COURTESY EXPIRED RECONNECTED Meaning Where set
> >>+ * -----------------------------------------------------------------------------
> >>+ * | false | false | false | Confirmed, active | Default |
> >>+ * |---------------------------------------------------------------------------|
> >>+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> >>+ * | | | | Lease/lock/share | |
> >>+ * | | | | reservation conflict | |
> >>+ * | | | | can cause Courtesy | |
> >>+ * | | | | client to be expired | |
> >>+ * |---------------------------------------------------------------------------|
> >>+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
> >>+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> >>+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> >>+ * | | | | | nfsd4_expire_courtesy_clnt |
> >>+ * |---------------------------------------------------------------------------|
> >>+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> >>+ * | | | | reconnected, | |
> >>+ * | | | | becoming active | |
> >>+ * -----------------------------------------------------------------------------

By the way, where is a client returned to the normal (0) state? That
has to happen at some point.

How is CLIENT_EXPIRED treated differently from cl_time == 0, and why?

Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
a bind_conn_to_session fails).

--b.


> >These are mutually exclusive values, not bits that may set to 0 or 1, so
> >the three boolean columns are confusing. I'd just structure the table
> >like:
> >
> > client state meaning where set
> > 0 Confirmed, active Default
> > CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
> > CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
> >
> >etc.
>
> will fix in v19.
>
> Thanks,
> -Dai
>
> >
> >--b.
> >
> >>+ */
> >>+
> >>+enum courtesy_client_state {
> >>+ NFSD4_CLIENT_COURTESY = 1,
> >>+ NFSD4_CLIENT_EXPIRED,
> >>+ NFSD4_CLIENT_RECONNECTED,
> >>+};
> >>+
> >>+/*
> >> * struct nfs4_client - one per client. Clientids live here.
> >> *
> >> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
> >>@@ -385,6 +414,10 @@ struct nfs4_client {
> >> struct list_head async_copies; /* list of async copies */
> >> spinlock_t async_lock; /* lock for async copies */
> >> atomic_t cl_cb_inflight; /* Outstanding callbacks */
> >>+
> >>+ enum courtesy_client_state cl_cs_client_state;
> >>+ spinlock_t cl_cs_lock;
> >>+ struct list_head cl_cs_list;
> >> };
> >> /* struct nfs4_client_reset
> >>--
> >>2.9.5

2022-03-30 12:09:23

by Chuck Lever

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server



> On Mar 29, 2022, at 2:39 PM, J. Bruce Fields <[email protected]> wrote:
>
> On Tue, Mar 29, 2022 at 11:19:51AM -0700, [email protected] wrote:
>>
>> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
>>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
>>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>>>> Update nfs4_client to add:
>>>>>> . cl_cs_client_state: courtesy client state
>>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>>>
>>>>>> Modify alloc_client to initialize these fields.
>>>>>>
>>>>>> Signed-off-by: Dai Ngo <[email protected]>
>>>>>> ---
>>>>>> fs/nfsd/nfs4state.c | 2 ++
>>>>>> fs/nfsd/nfsd.h | 1 +
>>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>>>> 3 files changed, 36 insertions(+)
>>>>>>
>>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>>>> index 234e852fcdfa..a65d59510681 100644
>>>>>> --- a/fs/nfsd/nfs4state.c
>>>>>> +++ b/fs/nfsd/nfs4state.c
>>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>>>> #ifdef CONFIG_NFSD_PNFS
>>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>>>> #endif
>>>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>>>> spin_lock_init(&clp->async_lock);
>>>>>> spin_lock_init(&clp->cl_lock);
>>>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>>>> return clp;
>>>>>> err_no_hashtbl:
>>>>>> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
>>>>>> index 4fc1fd639527..23996c6ca75e 100644
>>>>>> --- a/fs/nfsd/nfsd.h
>>>>>> +++ b/fs/nfsd/nfsd.h
>>>>>> @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
>>>>>> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
>>>>>> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
>>>>>> +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
>>>>>> /*
>>>>>> * The following attributes are currently not supported by the NFSv4 server:
>>>>>> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
>>>>>> index 95457cfd37fc..40e390abc842 100644
>>>>>> --- a/fs/nfsd/state.h
>>>>>> +++ b/fs/nfsd/state.h
>>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>>>> /*
>>>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>>>> + * -----------------------------------------------------------------------------
>>>>>> + * | false | false | false | Confirmed, active | Default |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>>>> + * | | | | Lease/lock/share | |
>>>>>> + * | | | | reservation conflict | |
>>>>>> + * | | | | can cause Courtesy | |
>>>>>> + * | | | | client to be expired | |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>>>> + * | | | | reconnected, | |
>>>>>> + * | | | | becoming active | |
>>>>>> + * -----------------------------------------------------------------------------
>>> By the way, where is a client returned to the normal (0) state? That
>>> has to happen at some point.
>>
>> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
>> nfsd4_bind_conn_to_session.
>
> Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
> the question I asked.

"reconnected" simply means the client has gotten back in touch.

The server then has to decide whether to allow the client to
become active again or it needs to purge it. That decision
is different for each operation and minor version. Look for
"if (cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)" for how
those choices are made.


>>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
>>> a bind_conn_to_session fails).
>>
>> find_in_sessionid_hashtbl: we discard the courtesy client when it
>> reconnects and there is error from nfsd4_get_session_locked. This
>> should be a rare condition so rather than reverting the client
>> state back to courtesy, it is simpler just to discard it.
>
> That may be a rare situation, but I don't believe the behavior of
> discarding the client in this case is correct.

Can you explain this? It's a courtesy client... the server can
decide it's expired at that point, can't it? IOW what breaks?


>> nfsd4_create_session/find_confirmed_client: I think the only time
>> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
>> to reconnect after missing its leases, is when it wants to do clientid
>> trunking. This should be a rare condition so instead of dealing
>> with it we just do not allow it and discard the client for now.
>
> We can't wave away incorrect behavior with "but it's rare". Users with
> heavy and/or unusual workloads hit rare conditions. Clients may change
> their behavior over time. (E.g., trunking may become more common.)


--
Chuck Lever



2022-03-30 12:09:28

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Tue, Mar 29, 2022 at 07:58:46PM +0000, Chuck Lever III wrote:
> Got it. Agreed, cl_cs_client_state should be reinitialized if
> a courtesy client is transitioned back to "active".
>
> Dai, would you add
>
> +enum courtesy_client_state {
> >>> NFSD4_CLIENT_ACTIVE = 0,
> + NFSD4_CLIENT_COURTESY,
> + NFSD4_CLIENT_EXPIRED,
> + NFSD4_CLIENT_RECONNECTED,
> +};
>
> And set cl_cs_client_state to ACTIVE where the client is
> allowed to transition back to being active?

I'm not clear then what the RECONNECTED->ACTIVE transition would be.

My feeling is that the RECONNECTED state shouldn't exist, and that there
should only be a transition of EXPIRED back to ACTIVE.

--b.

2022-03-30 14:44:40

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Tue, Mar 29, 2022 at 12:30:11PM -0400, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
> >
> > On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> > >On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> > >>Update nfs4_client to add:
> > >> . cl_cs_client_state: courtesy client state
> > >> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> > >> . cl_cs_list: list used by laundromat to process courtesy clients
> > >>
> > >>Modify alloc_client to initialize these fields.
> > >>
> > >>Signed-off-by: Dai Ngo <[email protected]>
> > >>---
> > >> fs/nfsd/nfs4state.c | 2 ++
> > >> fs/nfsd/nfsd.h | 1 +
> > >> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> > >> 3 files changed, 36 insertions(+)
> > >>
> > >>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> > >>index 234e852fcdfa..a65d59510681 100644
> > >>--- a/fs/nfsd/nfs4state.c
> > >>+++ b/fs/nfsd/nfs4state.c
> > >>@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> > >> INIT_LIST_HEAD(&clp->cl_delegations);
> > >> INIT_LIST_HEAD(&clp->cl_lru);
> > >> INIT_LIST_HEAD(&clp->cl_revoked);
> > >>+ INIT_LIST_HEAD(&clp->cl_cs_list);
> > >> #ifdef CONFIG_NFSD_PNFS
> > >> INIT_LIST_HEAD(&clp->cl_lo_states);
> > >> #endif
> > >> INIT_LIST_HEAD(&clp->async_copies);
> > >> spin_lock_init(&clp->async_lock);
> > >> spin_lock_init(&clp->cl_lock);
> > >>+ spin_lock_init(&clp->cl_cs_lock);
> > >> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> > >> return clp;
> > >> err_no_hashtbl:
> > >>diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> > >>index 4fc1fd639527..23996c6ca75e 100644
> > >>--- a/fs/nfsd/nfsd.h
> > >>+++ b/fs/nfsd/nfsd.h
> > >>@@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
> > >> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
> > >> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
> > >>+#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
> > >> /*
> > >> * The following attributes are currently not supported by the NFSv4 server:
> > >>diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
> > >>index 95457cfd37fc..40e390abc842 100644
> > >>--- a/fs/nfsd/state.h
> > >>+++ b/fs/nfsd/state.h
> > >>@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> > >> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> > >> /*
> > >>+ * CLIENT_ CLIENT_ CLIENT_
> > >>+ * COURTESY EXPIRED RECONNECTED Meaning Where set
> > >>+ * -----------------------------------------------------------------------------
> > >>+ * | false | false | false | Confirmed, active | Default |
> > >>+ * |---------------------------------------------------------------------------|
> > >>+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> > >>+ * | | | | Lease/lock/share | |
> > >>+ * | | | | reservation conflict | |
> > >>+ * | | | | can cause Courtesy | |
> > >>+ * | | | | client to be expired | |
> > >>+ * |---------------------------------------------------------------------------|
> > >>+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
> > >>+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> > >>+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> > >>+ * | | | | | nfsd4_expire_courtesy_clnt |
> > >>+ * |---------------------------------------------------------------------------|
> > >>+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> > >>+ * | | | | reconnected, | |
> > >>+ * | | | | becoming active | |
> > >>+ * -----------------------------------------------------------------------------
>
> By the way, where is a client returned to the normal (0) state? That
> has to happen at some point.
>
> How is CLIENT_EXPIRED treated differently from cl_time == 0, and why?
>
> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> a bind_conn_to_session fails).

A priori I just don't see how it can be right to treat a reconnected
client in any way differently from an normal confirmed client.

Once we've told the client that its lease is still good, we have to
treat it like any other client, don't we?

--b.

2022-03-30 18:24:41

by Dai Ngo

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server


On 3/29/22 11:39 AM, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 11:19:51AM -0700, [email protected] wrote:
>> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
>>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
>>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>>>> Update nfs4_client to add:
>>>>>> . cl_cs_client_state: courtesy client state
>>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>>>
>>>>>> Modify alloc_client to initialize these fields.
>>>>>>
>>>>>> Signed-off-by: Dai Ngo <[email protected]>
>>>>>> ---
>>>>>> fs/nfsd/nfs4state.c | 2 ++
>>>>>> fs/nfsd/nfsd.h | 1 +
>>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>>>> 3 files changed, 36 insertions(+)
>>>>>>
>>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>>>> index 234e852fcdfa..a65d59510681 100644
>>>>>> --- a/fs/nfsd/nfs4state.c
>>>>>> +++ b/fs/nfsd/nfs4state.c
>>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>>>> #ifdef CONFIG_NFSD_PNFS
>>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>>>> #endif
>>>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>>>> spin_lock_init(&clp->async_lock);
>>>>>> spin_lock_init(&clp->cl_lock);
>>>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>>>> return clp;
>>>>>> err_no_hashtbl:
>>>>>> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
>>>>>> index 4fc1fd639527..23996c6ca75e 100644
>>>>>> --- a/fs/nfsd/nfsd.h
>>>>>> +++ b/fs/nfsd/nfsd.h
>>>>>> @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
>>>>>> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
>>>>>> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
>>>>>> +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
>>>>>> /*
>>>>>> * The following attributes are currently not supported by the NFSv4 server:
>>>>>> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
>>>>>> index 95457cfd37fc..40e390abc842 100644
>>>>>> --- a/fs/nfsd/state.h
>>>>>> +++ b/fs/nfsd/state.h
>>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>>>> /*
>>>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>>>> + * -----------------------------------------------------------------------------
>>>>>> + * | false | false | false | Confirmed, active | Default |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>>>> + * | | | | Lease/lock/share | |
>>>>>> + * | | | | reservation conflict | |
>>>>>> + * | | | | can cause Courtesy | |
>>>>>> + * | | | | client to be expired | |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>>>> + * | | | | reconnected, | |
>>>>>> + * | | | | becoming active | |
>>>>>> + * -----------------------------------------------------------------------------
>>> By the way, where is a client returned to the normal (0) state? That
>>> has to happen at some point.
>> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
>> nfsd4_bind_conn_to_session.
> Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
> the question I asked.
>>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
>>> a bind_conn_to_session fails).
>> find_in_sessionid_hashtbl: we discard the courtesy client when it
>> reconnects and there is error from nfsd4_get_session_locked. This
>> should be a rare condition so rather than reverting the client
>> state back to courtesy, it is simpler just to discard it.
> That may be a rare situation, but I don't believe the behavior of
> discarding the client in this case is correct.
>
>> nfsd4_create_session/find_confirmed_client: I think the only time
>> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
>> to reconnect after missing its leases, is when it wants to do clientid
>> trunking. This should be a rare condition so instead of dealing
>> with it we just do not allow it and discard the client for now.
> We can't wave away incorrect behavior with "but it's rare". Users with
> heavy and/or unusual workloads hit rare conditions. Clients may change
> their behavior over time. (E.g., trunking may become more common.)

This does not prevent the courtesy client from doing trunking in all
cases. It is only prevent the courtesy client from doing trunking without
first reconnect to the server.

I think this behavior is the same as if the server does not support courtesy
client; the server can expire the courtesy anytime it wants. If the
courtesy client reconnected successfully then by the time nfsd4_create_session/
find_confirmed_client is called the client already becomes active
so the server will process the request normally.

Also to handle cases when the courtesy client reconnects after it was in
EXPIRED state, we want to force the client to recover its state starting
with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.

-Dai

2022-03-30 19:42:57

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Tue, Mar 29, 2022 at 07:32:57PM +0000, Chuck Lever III wrote:
>
>
> > On Mar 29, 2022, at 2:39 PM, J. Bruce Fields <[email protected]> wrote:
> >
> > On Tue, Mar 29, 2022 at 11:19:51AM -0700, [email protected] wrote:
> >>
> >> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
> >>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, [email protected] wrote:
> >>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> >>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> >>>>>> Update nfs4_client to add:
> >>>>>> . cl_cs_client_state: courtesy client state
> >>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> >>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
> >>>>>>
> >>>>>> Modify alloc_client to initialize these fields.
> >>>>>>
> >>>>>> Signed-off-by: Dai Ngo <[email protected]>
> >>>>>> ---
> >>>>>> fs/nfsd/nfs4state.c | 2 ++
> >>>>>> fs/nfsd/nfsd.h | 1 +
> >>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> >>>>>> 3 files changed, 36 insertions(+)
> >>>>>>
> >>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>>>>> index 234e852fcdfa..a65d59510681 100644
> >>>>>> --- a/fs/nfsd/nfs4state.c
> >>>>>> +++ b/fs/nfsd/nfs4state.c
> >>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> >>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
> >>>>>> INIT_LIST_HEAD(&clp->cl_lru);
> >>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
> >>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
> >>>>>> #ifdef CONFIG_NFSD_PNFS
> >>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
> >>>>>> #endif
> >>>>>> INIT_LIST_HEAD(&clp->async_copies);
> >>>>>> spin_lock_init(&clp->async_lock);
> >>>>>> spin_lock_init(&clp->cl_lock);
> >>>>>> + spin_lock_init(&clp->cl_cs_lock);
> >>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> >>>>>> return clp;
> >>>>>> err_no_hashtbl:
> >>>>>> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> >>>>>> index 4fc1fd639527..23996c6ca75e 100644
> >>>>>> --- a/fs/nfsd/nfsd.h
> >>>>>> +++ b/fs/nfsd/nfsd.h
> >>>>>> @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
> >>>>>> #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
> >>>>>> #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
> >>>>>> +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
> >>>>>> /*
> >>>>>> * The following attributes are currently not supported by the NFSv4 server:
> >>>>>> diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
> >>>>>> index 95457cfd37fc..40e390abc842 100644
> >>>>>> --- a/fs/nfsd/state.h
> >>>>>> +++ b/fs/nfsd/state.h
> >>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> >>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> >>>>>> /*
> >>>>>> + * CLIENT_ CLIENT_ CLIENT_
> >>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
> >>>>>> + * -----------------------------------------------------------------------------
> >>>>>> + * | false | false | false | Confirmed, active | Default |
> >>>>>> + * |---------------------------------------------------------------------------|
> >>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> >>>>>> + * | | | | Lease/lock/share | |
> >>>>>> + * | | | | reservation conflict | |
> >>>>>> + * | | | | can cause Courtesy | |
> >>>>>> + * | | | | client to be expired | |
> >>>>>> + * |---------------------------------------------------------------------------|
> >>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
> >>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> >>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> >>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
> >>>>>> + * |---------------------------------------------------------------------------|
> >>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> >>>>>> + * | | | | reconnected, | |
> >>>>>> + * | | | | becoming active | |
> >>>>>> + * -----------------------------------------------------------------------------
> >>> By the way, where is a client returned to the normal (0) state? That
> >>> has to happen at some point.
> >>
> >> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
> >> nfsd4_bind_conn_to_session.
> >
> > Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
> > the question I asked.
>
> "reconnected" simply means the client has gotten back in touch.

Again, my question was: when is cl_cs_client_state set back to 0? As
far as I can tell, the answer is never. That means, even long after the
client has reconnected, it's left in a weird state where it can be
suddenly expired for all sorts of reasons.

> The server then has to decide whether to allow the client to
> become active again or it needs to purge it. That decision
> is different for each operation and minor version. Look for
> "if (cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)" for how
> those choices are made.
>
>
> >>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> >>> a bind_conn_to_session fails).
> >>
> >> find_in_sessionid_hashtbl: we discard the courtesy client when it
> >> reconnects and there is error from nfsd4_get_session_locked. This
> >> should be a rare condition so rather than reverting the client
> >> state back to courtesy, it is simpler just to discard it.
> >
> > That may be a rare situation, but I don't believe the behavior of
> > discarding the client in this case is correct.
>
> Can you explain this? It's a courtesy client... the server can
> decide it's expired at that point, can't it? IOW what breaks?

I'm not worried about courtesy clients, I'm worried about clients that
were courtesy clients but have since succesfully renewed their state.
Expiring them for a failed bind_conn_to_session isn't right.

--b.

>
>
> >> nfsd4_create_session/find_confirmed_client: I think the only time
> >> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
> >> to reconnect after missing its leases, is when it wants to do clientid
> >> trunking. This should be a rare condition so instead of dealing
> >> with it we just do not allow it and discard the client for now.
> >
> > We can't wave away incorrect behavior with "but it's rare". Users with
> > heavy and/or unusual workloads hit rare conditions. Clients may change
> > their behavior over time. (E.g., trunking may become more common.)
>
>
> --
> Chuck Lever
>
>

2022-03-31 03:27:40

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server

On Tue, Mar 29, 2022 at 06:17:29PM -0700, [email protected] wrote:
>
> On 3/29/22 5:12 PM, J. Bruce Fields wrote:
> >On Tue, Mar 29, 2022 at 02:45:28PM -0700, [email protected] wrote:
> >>This does not prevent the courtesy client from doing trunking in all
> >>cases. It is only prevent the courtesy client from doing trunking without
> >>first reconnect to the server.
> >>
> >>I think this behavior is the same as if the server does not support courtesy
> >>client; the server can expire the courtesy anytime it wants. If the
> >>courtesy client reconnected successfully then by the time nfsd4_create_session/
> >>find_confirmed_client is called the client already becomes active
> >>so the server will process the request normally.
> >I'm not sure what you mean here. All a client has to do to reconnect is
> >succesfully renew its lease.
>
> For 4.1 the client renews its lease via the SEQUENCE, either stand-alone
> or in a compound. Once the SEQUENCE completes successfully then the
> subsequent CREATE_SESSION is processed normally. However, if the client
> did not send the SEQUENCE first then server returns BAD_SESSION for the
> CREATE_SESSION request.
>
> > That doesn't necessarily require calling
> >CREATE_SESSION again.
> >
> >>Also to handle cases when the courtesy client reconnects after it was in
> >>EXPIRED state, we want to force the client to recover its state starting
> >>with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.
> >The client should not have to send EXCHANGE_ID.
>
> For 4.1 the expired courtesy client must send EXCHANGE_ID to reconnect
> to start new session. I don't see how the *expired* courtesy client can
> access the export again without sending the EXCHANGE_ID. Attached is the
> pcap that shows how the courtesy client recovers once it's in
> CLIENT_EXPIRED state.

Oh, sorry, sure, we're talking about an actual expired client. That's
fine.

--b.

2022-03-31 05:00:00

by Dai Ngo

[permalink] [raw]
Subject: Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server


On 3/29/22 5:12 PM, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 02:45:28PM -0700, [email protected] wrote:
>> This does not prevent the courtesy client from doing trunking in all
>> cases. It is only prevent the courtesy client from doing trunking without
>> first reconnect to the server.
>>
>> I think this behavior is the same as if the server does not support courtesy
>> client; the server can expire the courtesy anytime it wants. If the
>> courtesy client reconnected successfully then by the time nfsd4_create_session/
>> find_confirmed_client is called the client already becomes active
>> so the server will process the request normally.
> I'm not sure what you mean here. All a client has to do to reconnect is
> succesfully renew its lease.

For 4.1 the client renews its lease via the SEQUENCE, either stand-alone
or in a compound. Once the SEQUENCE completes successfully then the
subsequent CREATE_SESSION is processed normally. However, if the client
did not send the SEQUENCE first then server returns BAD_SESSION for the
CREATE_SESSION request.

> That doesn't necessarily require calling
> CREATE_SESSION again.
>
>> Also to handle cases when the courtesy client reconnects after it was in
>> EXPIRED state, we want to force the client to recover its state starting
>> with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.
> The client should not have to send EXCHANGE_ID.

For 4.1 the expired courtesy client must send EXCHANGE_ID to reconnect
to start new session. I don't see how the *expired* courtesy client can
access the export again without sending the EXCHANGE_ID. Attached is the
pcap that shows how the courtesy client recovers once it's in
CLIENT_EXPIRED state.

-Dai

>
> --b.


Attachments:
netpart-reconnect.pcap (64.84 kB)