NFSD: Initial implementation of NFSv4 Courteous Server
Subsystems (3)
Dai Ngo
reviewerv15 cover NFSD: Initial implementation of NFSv4 Courteous Server
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'.
Dai Ngo
reviewerRFC PATCH v15 1/11 fs/lock: add helper locks_any_blockers to check for blockers
Add helper locks_any_blockers to check if there is any blockers for a file_lock.
--- include/linux/fs.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/fs.h +10 -0
@@ -1200,6 +1200,11 @@ extern void lease_unregister_notifier(struct notifier_block *);struct files_struct ;extern void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files); + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return !list_empty (&lck->fl_blocked_requests); +}#else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk (struct file *file,unsigned int cmd,struct flock __user *user)
@@ -1335,6 +1340,11 @@ static inline int lease_modify(struct file_lock *fl, int arg,struct files_struct ;static inline void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files) {} + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return false; +}#endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode (const struct file *f)
Signature · 1 line
2.9.5
Re: [PATCH RFC v15 01/11] fs/lock: add helper locks_any_blockers to check for blockers
Quoted 30 lines · Dai Ngo
Add helper
locks_any_blockersto check if there is any blockers for afile_lock.Signed-off-by Dai Ngo <[email protected]>---
include/linux/fs.h| 10 ++++++++++1 file changed, 10 insertions(+)include/linux/fs.h +5
-0@@ -1200,6 +1200,11 @@ extern void lease_unregister_notifier(struct notifier_block *);struct files_struct ;extern void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files); + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return !list_empty (&lck->fl_blocked_requests); +}#else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk (struct file *file,unsigned int cmd,struct flock __user *user)@@ -1335,6 +1340,11 @@ static inline int lease_modify(struct file_lock *fl, int arg,struct files_struct ;
include/linux/fs.h static inline int lease_modify(struct file_lock *fl, int arg, · line 1350
Quoted 10 lines
include/linux/fs.h +5
-0static inline void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files) {} + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return false; +}#endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode (const struct file *f)
Hm. This is not exactly what I had in mind.
In order to be more kABI friendly, fl_blocked_requests should be dereferenced only in fs/locks.c. IMO you want to take the inner loop in nfs4_lockowner_has_blockers() and make that a function that lives in fs/locks.c. Something akin to:
fs/locks.c:
/**
* locks_owner_has_blockers - Check for blocking lock requests
* @flctx: file lock context
* @owner: lock owner
*
* Return values:
* %true: @ctx has at least one blocker
* %false: @ctx has no blockers
*/
bool locks_owner_has_blockers(struct file_lock_context *flctx,
fl_owner_t owner)
{
struct file_lock *fl;
spin_lock(&flctx->flc_lock);
list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
if (fl->fl_owner != owner)
continue;
if (!list_empty(&fl->fl_blocked_requests)) {
spin_unlock(&flctx->flc_lock);
return true;
}
}
spin_unlock(&flctx->flc_lock);
return false;
}EXPORT_SYMBOL(locks_owner_has_blockers);
As a subsequent clean up (which anyone can do at a later point), a similar change could be done to check_for_locks(). This bit of code seems to appear in several other filesystems, for example:
7643 inode = locks_inode(nf->nf_file);
7644 flctx = inode->i_flctx;
7645
7646 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
7647 spin_lock(&flctx->flc_lock);
7648 list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
7649 if (fl->fl_owner == (fl_owner_t)lowner) {
7650 status = true;
7651 break;
7652 }
7653 }
7654 spin_unlock(&flctx->flc_lock);
7655 }
--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 01/11] fs/lock: add helper locks_any_blockers to check for blockers
Quoted 74 lines · Chuck Lever III
Quoted 29 lines · Dai Ngo
Add helper
locks_any_blockersto check if there is any blockers for afile_lock.Signed-off-by Dai Ngo <[email protected]>---
include/linux/fs.h| 10 ++++++++++1 file changed, 10 insertions(+)include/linux/fs.h +5
-0@@ -1200,6 +1200,11 @@ extern void lease_unregister_notifier(struct notifier_block *);struct files_struct ;extern void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files); + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return !list_empty (&lck->fl_blocked_requests); +}#else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk (struct file *file,unsigned int cmd,struct flock __user *user)@@ -1335,6 +1340,11 @@ static inline int lease_modify(struct file_lock *fl, int arg,struct files_struct ;include/linux/fs.h static inline int lease_modify(struct file_lock *fl, int arg, · line 1350
Quoted 10 lines
include/linux/fs.h +5
-0static inline void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files) {} + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return false; +}#endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode (const struct file *f)Hm. This is not exactly what I had in mind.
In order to be more kABI friendly,
fl_blocked_requestsshould be dereferenced only infs/locks.c. IMO you want to take the inner loop innfs4_lockowner_has_blockers()and make that a function that lives infs/locks.c. Something akin to:
fs/locks.c:/**
*locks_owner_has_blockers- Check for blocking lock requests
* @flctx: file lock context
* @owner: lock owner
*
* Return values:
* %true: @ctx has at least one blocker
* %false: @ctx has no blockers
*/
bool locks_owner_has_blockers(structfile_lock_context*flctx,
fl_owner_towner){ struct file_lock *fl; spin_lock(&flctx->flc_lock); list_for_each_entry(fl, &flctx->flc_posix, fl_list) { if (fl->fl_owner != owner) continue; if (!list_empty(&fl->fl_blocked_requests)) { spin_unlock(&flctx->flc_lock); return true; } } spin_unlock(&flctx->flc_lock); return false; }
Quoted 5 lines
EXPORT_SYMBOL(locks_owner_has_blockers);As a subsequent clean up (which anyone can do at a later point), a similar change could be done to
check_for_locks(). This bit of code seems to appear in several other filesystems, for example:
I used check_for_locks as reference for locks_owner_has_blockers so both should be updated to be more kABI friendly as you suggested. Can I update both in a subsequent cleanup patch? I plan to have a number of small cleanup up patches for these and also some nits.
Thanks,
-Dai
Quoted 21 lines
7643 inode =
locks_inode(nf->nf_file);
7644 flctx =inode->i_flctx;
7645
7646 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
7647spin_lock(&flctx->flc_lock);
7648list_for_each_entry(fl, &flctx->flc_posix, fl_list){
7649 if (fl->fl_owner== (fl_owner_t)lowner) {
7650 status = true;
7651 break;
7652 }
7653 }
7654spin_unlock(&flctx->flc_lock);
7655 }--
Chuck Lever
Re: [PATCH RFC v15 01/11] fs/lock: add helper locks_any_blockers to check for blockers
Quoted 80 lines · Dai Ngo
Quoted 76 lines · Chuck Lever III
Quoted 29 lines
Quoted 2 lines · Dai Ngo
Add helper
locks_any_blockersto check if there is any blockers for afile_lock.Signed-off-by Dai Ngo <[email protected]>---
include/linux/fs.h| 10 ++++++++++1 file changed, 10 insertions(+)include/linux/fs.h +5
-0@@ -1200,6 +1200,11 @@ extern void lease_unregister_notifier(struct notifier_block *);struct files_struct ;extern void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files); + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return !list_empty (&lck->fl_blocked_requests); +}#else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk (struct file *file,unsigned int cmd,struct flock __user *user)@@ -1335,6 +1340,11 @@ static inline int lease_modify(struct file_lock *fl, int arg,struct files_struct ;include/linux/fs.h static inline int lease_modify(struct file_lock *fl, int arg, · line 1350
Quoted 10 lines
include/linux/fs.h +5
-0static inline void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files) {} + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return false; +}#endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode (const struct file *f)Hm. This is not exactly what I had in mind.
In order to be more kABI friendly,
fl_blocked_requestsshould be dereferenced only infs/locks.c. IMO you want to take the inner loop innfs4_lockowner_has_blockers()and make that a function that lives infs/locks.c. Something akin to:
fs/locks.c:/**
*locks_owner_has_blockers- Check for blocking lock requests
* @flctx: file lock context
* @owner: lock owner
*
* Return values:
* %true: @ctx has at least one blocker
* %false: @ctx has no blockers
*/
bool locks_owner_has_blockers(structfile_lock_context*flctx,
fl_owner_towner){ struct file_lock *fl; spin_lock(&flctx->flc_lock); list_for_each_entry(fl, &flctx->flc_posix, fl_list) { if (fl->fl_owner != owner) continue; if (!list_empty(&fl->fl_blocked_requests)) { spin_unlock(&flctx->flc_lock); return true; } } spin_unlock(&flctx->flc_lock); return false; }
EXPORT_SYMBOL(locks_owner_has_blockers);
Quoted 7 lines
Quoted 3 lines
As a subsequent clean up (which anyone can do at a later point), a similar change could be done to
check_for_locks(). This bit of code seems to appear in several other filesystems, for example:I used
check_for_locksas reference forlocks_owner_has_blockersso both should be updated to be more kABI friendly as you suggested. Can I update both in a subsequent cleanup patch?
No. I prefer that you don’t introduce code and then clean it up later in the same series.
You need to introduce locks_owner_has_blockers() in the same patch where you add the nfsd4_ function that will use it. I think that’s like 7 or 8/11 ? I don’t have it in front of me.
Because it deduplicates code, cleaning up check_for_locks() will need to involve at least one other site (outside of NFSD) that can make use of this new helper. Therefore I prefer that you wait and do that work after courteous server is merged.
Quoted 1 line
I plan to have a number of small cleanup up patches for these and also some nits.
Clean-ups of areas not having to do with courteous server can go in separate patches, but I would prefer to keep clean-ups of the new code in this series integrated together in the same patches with the new code.
Let’s stay focused on finishing the courteous server work and getting it merged.
Quoted 25 lines
Thanks,
-DaiQuoted 21 lines
7643 inode =
locks_inode(nf->nf_file);
7644 flctx =inode->i_flctx;
7645
7646 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
7647spin_lock(&flctx->flc_lock);
7648list_for_each_entry(fl, &flctx->flc_posix, fl_list){
7649 if (fl->fl_owner== (fl_owner_t)lowner) {
7650 status = true;
7651 break;
7652 }
7653 }
7654spin_unlock(&flctx->flc_lock);
7655 }--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 01/11] fs/lock: add helper locks_any_blockers to check for blockers
Quoted 80 lines · Chuck Lever III
Quoted 80 lines · Dai Ngo
Quoted 77 lines · Chuck Lever III
Quoted 27 lines
Quoted 1 line · Dai Ngo
Add helper
locks_any_blockersto check if there is any blockers for afile_lock.Signed-off-by Dai Ngo <[email protected]>---
include/linux/fs.h| 10 ++++++++++1 file changed, 10 insertions(+)include/linux/fs.h +5
-0@@ -1200,6 +1200,11 @@ extern void lease_unregister_notifier(struct notifier_block *);struct files_struct ;extern void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files); + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return !list_empty (&lck->fl_blocked_requests); +}#else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk (struct file *file,unsigned int cmd,struct flock __user *user)@@ -1335,6 +1340,11 @@ static inline int lease_modify(struct file_lock *fl, int arg,struct files_struct ;include/linux/fs.h static inline int lease_modify(struct file_lock *fl, int arg, · line 1350
Quoted 10 lines
include/linux/fs.h +5
-0static inline void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files) {} + +static inline bool locks_has_blockers_locked (struct file_lock *lck) +{ +return false; +}#endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode (const struct file *f)Hm. This is not exactly what I had in mind.
In order to be more kABI friendly,
fl_blocked_requestsshould be dereferenced only infs/locks.c. IMO you want to take the inner loop innfs4_lockowner_has_blockers()and make that a function that lives infs/locks.c. Something akin to:
fs/locks.c:/**
*locks_owner_has_blockers- Check for blocking lock requests
* @flctx: file lock context
* @owner: lock owner
*
* Return values:
* %true: @ctx has at least one blocker
* %false: @ctx has no blockers
*/
bool locks_owner_has_blockers(structfile_lock_context*flctx,
fl_owner_towner){ struct file_lock *fl; spin_lock(&flctx->flc_lock); list_for_each_entry(fl, &flctx->flc_posix, fl_list) { if (fl->fl_owner != owner) continue; if (!list_empty(&fl->fl_blocked_requests)) { spin_unlock(&flctx->flc_lock); return true; } } spin_unlock(&flctx->flc_lock); return false; }
EXPORT_SYMBOL(locks_owner_has_blockers);As a subsequent clean up (which anyone can do at a later point), a similar change could be done to
check_for_locks(). This bit of code seems to appear in several other filesystems, for example:
Quoted 6 lines
Quoted 3 lines
I used
check_for_locksas reference forlocks_owner_has_blockersso both should be updated to be more kABI friendly as you suggested. Can I update both in a subsequent cleanup patch?No. I prefer that you don’t introduce code and then clean it up later in the same series.
You need to introduce
locks_owner_has_blockers()in the same patch where you add thenfsd4_function that will use it. I think that’s like 7 or 8/11 ? I don’t have it in front of me.
ok, fix in v16.
Quoted 2 lines
Because it deduplicates code, cleaning up
check_for_locks()will need to involve at least one other site (outside of NFSD) that can make use of this new helper. Therefore I prefer that you wait and do that work after courteous server is merged.
ok.
Quoted 6 lines
Quoted 3 lines
I plan to have a number of small cleanup up patches for these and also some nits.
Clean-ups of areas not having to do with courteous server can go in separate patches, but I would prefer to keep clean-ups of the new code in this series integrated together in the same patches with the new code.
Let’s stay focused on finishing the courteous server work and getting it merged.
ok.
Thanks,
-Dai
Quoted 26 lines
Quoted 26 lines
Thanks,
-DaiQuoted 20 lines
7643 inode =
locks_inode(nf->nf_file);
7644 flctx =inode->i_flctx;
7645
7646 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
7647spin_lock(&flctx->flc_lock);
7648list_for_each_entry(fl, &flctx->flc_posix, fl_list){
7649 if (fl->fl_owner== (fl_owner_t)lowner) {
7650 status = true;
7651 break;
7652 }
7653 }
7654spin_unlock(&flctx->flc_lock);
7655 }--
Chuck Lever
Dai Ngo
reviewerRFC PATCH v15 2/11 NFSD: Add client flags, macro and spinlock to support courteous server
In reply to Dai NgoAdd flags to track a client's lease state after the client fails to renew its lease. Add macro for courtesy client expire time. Add spinlock to synchronize access to these flags. Modify alloc_client to initialize these fields.
--- fs/nfsd/nfs4state.c | 2 ++ fs/nfsd/nfsd.h | 1 + fs/nfsd/state.h | 6 ++++++ 3 files changed, 9 insertions(+)
fs/nfsd/nfs4state.c +2 -0
@@ -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:
fs/nfsd/nfsd.h +1 -0
@@ -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:
fs/nfsd/state.h +6 -0
@@ -343,6 +343,9 @@ struct nfs4_client {#define NFSD4_CLIENT_RECLAIM_COMPLETE (3)/* reclaim_complete done */ #define NFSD4_CLIENT_CONFIRMED (4)/* client is confirmed */ #define NFSD4_CLIENT_UPCALL_LOCK (5)/* upcall serialization */ +#define NFSD4_CLIENT_COURTESY (6) +#define NFSD4_CLIENT_EXPIRED (7) +#define NFSD4_CLIENT_RECONNECTED (8)#define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \ 1 << NFSD4_CLIENT_CB_KILL)unsigned long cl_flags;
@@ -385,6 +388,9 @@ 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 */ + +spinlock_t cl_cs_lock; +struct list_head cl_cs_list; };/* struct nfs4_client_reset
Signature · 1 line
2.9.5
Dai Ngo
reviewerRFC PATCH v15 3/11 NFSD: Add lm_lock_expired call out
In reply to Dai NgoAdd 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.
--- fs/nfsd/nfs4state.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
fs/nfsd/nfs4state.c +37 -0
@@ -6578,10 +6578,47 @@ 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; +struct nfs4_client *clp; +bool rc = false; + +if (!fl) +return false; + lo = (struct nfs4_lockowner *)fl->fl_owner; + clp = lo->lo_owner.so_client; + +/* need to sync with courtesy client trying to reconnect */ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) + rc = true; +else { +if (test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) { +set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); + rc = true; + } + } +spin_unlock (&clp->cl_cs_lock); +return rc; +} +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
Signature · 1 line
2.9.5
Dai Ngo
reviewerRFC PATCH v15 4/11 NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients
In reply to Dai NgoUpdate nfsd_breaker_owns_lease() to handle delegation conflict with courtesy clients. If conflict was caused courtesy client then discard the courtesy client by setting CLIENT_EXPIRED and return conflict resolved. Client with CLIENT_EXPIRED is expired by the laundromat.
--- fs/nfsd/nfs4state.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
fs/nfsd/nfs4state.c +18 -0
@@ -4727,6 +4727,24 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl)struct svc_rqst *rqst;struct nfs4_client *clp; + clp = dl->dl_stid.sc_client; +/* +* need to sync with courtesy client trying to reconnect using +* the cl_cs_lock, nn->client_lock can not be used since this +* function is called with the fl_lck held. +*/ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) { +spin_unlock (&clp->cl_cs_lock); +return true; + } +if (test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) { +set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +return true; + } +spin_unlock (&clp->cl_cs_lock); +if (!i_am_nfsd ())return false; rqst =kthread_data (current);
Signature · 1 line
2.9.5
Re: [PATCH RFC v15 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients
Quoted 31 lines · Dai Ngo
Update
nfsd_breaker_owns_lease()to handle delegation conflict with courtesy clients. If conflict was caused courtesy client then discard the courtesy client by settingCLIENT_EXPIREDand return conflict resolved. Client withCLIENT_EXPIREDis expired by the laundromat.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 18 ++++++++++++++++++1 file changed, 18 insertions(+)fs/nfsd/nfs4state.c +8
-0@@ -4727,6 +4727,24 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl)struct svc_rqst *rqst;struct nfs4_client *clp; + clp = dl->dl_stid.sc_client; +/* +* need to sync with courtesy client trying to reconnect using +* the cl_cs_lock, nn->client_lock can not be used since this +* function is called with the fl_lck held. +*/ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) {
fs/nfsd/nfs4state.c static bool nfsd_breaker_owns_lease(struct file_lock *fl) · line 4747
Quoted 10 lines
fs/nfsd/nfs4state.c +10
-0+spin_unlock (&clp->cl_cs_lock); +return true; + } +if (test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) { +set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +return true; + } +spin_unlock (&clp->cl_cs_lock); +
Nit: Please add nfs4_check_and_expire_courtesy_client() in this patch instead of in 05/11.
Quoted 6 lines
fs/nfsd/nfs4state.c +0
-0if (!i_am_nfsd ())return false; rqst =kthread_data (current);Signature · 1 line
2.9.5
--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients
Quoted 34 lines · Chuck Lever III
Quoted 34 lines · Dai Ngo
Update
nfsd_breaker_owns_lease()to handle delegation conflict with courtesy clients. If conflict was caused courtesy client then discard the courtesy client by settingCLIENT_EXPIREDand return conflict resolved. Client withCLIENT_EXPIREDis expired by the laundromat.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 18 ++++++++++++++++++1 file changed, 18 insertions(+)fs/nfsd/nfs4state.c +12
-0@@ -4727,6 +4727,24 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl)struct svc_rqst *rqst;struct nfs4_client *clp; + clp = dl->dl_stid.sc_client; +/* +* need to sync with courtesy client trying to reconnect using +* the cl_cs_lock, nn->client_lock can not be used since this +* function is called with the fl_lck held. +*/ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) { +spin_unlock (&clp->cl_cs_lock); +return true; + } +if (test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) {
Quoted 8 lines
fs/nfsd/nfs4state.c static bool nfsd_breaker_owns_lease(struct file_lock *fl) · line 4747
Quoted 6 lines
fs/nfsd/nfs4state.c +6
-0+set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +return true; + } +spin_unlock (&clp->cl_cs_lock); +Nit: Please add
nfs4_check_and_expire_courtesy_client()in this patch instead of in 05/11.
That means nfs4_check_and_expire_courtesy_client is being called in 05/11 but is not defined in 05/11. Is that ok?
-Dai
Quoted 13 lines
Quoted 8 lines
fs/nfsd/nfs4state.c +0
-0if (!i_am_nfsd ())return false; rqst =kthread_data (current);Signature · 1 line
2.9.5--
Chuck Lever
Re: [PATCH RFC v15 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients
Quoted 49 lines · Dai Ngo
Quoted 34 lines · Chuck Lever III
Quoted 34 lines · Dai Ngo
Update
nfsd_breaker_owns_lease()to handle delegation conflict with courtesy clients. If conflict was caused courtesy client then discard the courtesy client by settingCLIENT_EXPIREDand return conflict resolved. Client withCLIENT_EXPIREDis expired by the laundromat.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 18 ++++++++++++++++++1 file changed, 18 insertions(+)fs/nfsd/nfs4state.c +12
-0@@ -4727,6 +4727,24 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl)struct svc_rqst *rqst;struct nfs4_client *clp; + clp = dl->dl_stid.sc_client; +/* +* need to sync with courtesy client trying to reconnect using +* the cl_cs_lock, nn->client_lock can not be used since this +* function is called with the fl_lck held. +*/ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) { +spin_unlock (&clp->cl_cs_lock); +return true; + } +if (test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) {Quoted 8 lines
fs/nfsd/nfs4state.c static bool nfsd_breaker_owns_lease(struct file_lock *fl) · line 4747
Quoted 6 lines
fs/nfsd/nfs4state.c +6
-0+set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +return true; + } +spin_unlock (&clp->cl_cs_lock); +Nit: Please add
nfs4_check_and_expire_courtesy_client()in this patch instead of in 05/11.
Quoted 2 lines
That means
nfs4_check_and_expire_courtesy_clientis being called in 05/11 but is not defined in 05/11. Is that ok?
I thought I saw a hunk in 5/11 that converts nfsd_breaker_owns_lease() to use nfs4_check_and_expire_courtesy_client().
If so, I prefer if you add nfs4_check_and_expire_courtesy_client() in this patch, and call it from nfsd_breaker_owns_lease(). Then the additional clean-up in 5/11 isn't needed.
Again, this is a nit. But since you are driving a v16 soon anyway, I'd like the patches changed before they are merged.
Quoted 15 lines
-Dai
Quoted 13 lines
Quoted 8 lines
fs/nfsd/nfs4state.c +0
-0if (!i_am_nfsd ())return false; rqst =kthread_data (current);Signature · 1 line
2.9.5--
Chuck Lever
--
Chuck Lever
Dai Ngo
reviewerRFC PATCH v15 5/11 NFSD: Update nfs4_get_vfs_file() to handle courtesy clients
In reply to Dai NgoUpdate nfs4_get_vfs_file and nfs4_upgrade_open to handle share reservation conflict with courtesy client.
If share/access check fails with share denied then check if the the conflict was caused by courtesy clients. If that's the case then set CLIENT_EXPIRED flag to expire the courtesy clients and allow nfs4_get_vfs_file to continue. Client with CLIENT_EXPIRED is expired by the laundromat.
--- fs/nfsd/nfs4state.c | 135 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 22 deletions(-)
fs/nfsd/nfs4state.c +113 -22
@@ -4713,21 +4713,9 @@ nfsd_break_deleg_cb(struct file_lock *fl)return ret; } -/** -* nfsd_breaker_owns_lease - Check if lease conflict was resolved -* @fl: Lock state to check -* -* Return values: -* %true: Lease conflict was resolved -* %false: Lease conflict was not resolved. -*/ -static bool nfsd_breaker_owns_lease (struct file_lock *fl) +static bool +nfs4_check_and_expire_courtesy_client (struct nfs4_client *clp) { -struct nfs4_delegation *dl = fl->fl_owner; -struct svc_rqst *rqst; -struct nfs4_client *clp; - - clp = dl->dl_stid.sc_client;/* * need to sync with courtesy client trying to reconnect using * the cl_cs_lock, nn->client_lock can not be used since this
@@ -4744,6 +4732,26 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl)return true; }spin_unlock (&clp->cl_cs_lock); +return false; +} + +/** +* nfsd_breaker_owns_lease - Check if lease conflict was resolved +* @fl: Lock state to check +* +* Return values: +* %true: Lease conflict was resolved +* %false: Lease conflict was not resolved. +*/ +static bool nfsd_breaker_owns_lease (struct file_lock *fl) +{ +struct nfs4_delegation *dl = fl->fl_owner; +struct svc_rqst *rqst; +struct nfs4_client *clp; + + clp = dl->dl_stid.sc_client; +if (nfs4_check_and_expire_courtesy_client (clp)) +return true;if (!i_am_nfsd ())return false;
@@ -4965,9 +4973,75 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,return nfsd_setattr (rqstp, fh, &iattr,0 , (time64_t )0 ); } +static bool +nfs4_check_access_deny_bmap (struct nfs4_ol_stateid *stp,u32 access, +bool share_access) +{ +if (share_access) { +if (!stp->st_deny_bmap) +return false; + +if ((stp->st_deny_bmap & (1 <<NFS4_SHARE_DENY_BOTH )) || + (access &NFS4_SHARE_ACCESS_READ && + stp->st_deny_bmap & (1 <<NFS4_SHARE_DENY_READ )) || + (access &NFS4_SHARE_ACCESS_WRITE && + stp->st_deny_bmap & (1 <<NFS4_SHARE_DENY_WRITE ))) { +return true; + } +return false; + } +if ((access &NFS4_SHARE_DENY_BOTH ) || + (access &NFS4_SHARE_DENY_READ && + stp->st_access_bmap & (1 <<NFS4_SHARE_ACCESS_READ )) || + (access &NFS4_SHARE_DENY_WRITE && + stp->st_access_bmap & (1 <<NFS4_SHARE_ACCESS_WRITE ))) { +return true; + } +return false; +} + +/* +* Check whether courtesy clients have conflicting access +* +* access: is op_share_access if share_access is true. +* Check if access mode, op_share_access, would conflict with +* the current deny mode of the file 'fp'. +* access: is op_share_deny if share_access is false. +* Check if the deny mode, op_share_deny, would conflict with +* current access of the file 'fp'. +* stp: skip checking this entry. +* new_stp: normal open, not open upgrade. +* +* Function returns: +* true - access/deny mode conflict with normal client. +* false - no conflict or conflict with courtesy client(s) is resolved. +*/ +static bool +nfs4_resolve_deny_conflicts_locked (struct nfs4_file *fp,bool new_stp, +struct nfs4_ol_stateid *stp,u32 access,bool share_access) +{ +struct nfs4_ol_stateid *st; +struct nfs4_client *clp; +bool conflict = false; + +lockdep_assert_held (&fp->fi_lock); +list_for_each_entry (st, &fp->fi_stateids, st_perfile) { +if (st->st_openstp || (st == stp && new_stp) || + (!nfs4_check_access_deny_bmap (st, + access, share_access))) +continue ; + clp = st->st_stid.sc_client; +if (nfs4_check_and_expire_courtesy_client (clp)) +continue ; + conflict = true; +break ; + } +return conflict; +} +static __be32 nfs4_get_vfs_file (struct svc_rqst *rqstp,struct nfs4_file *fp,struct svc_fh *cur_fh,struct nfs4_ol_stateid *stp, -struct nfsd4_open *open) +struct nfsd4_open *open,bool new_stp) {struct nfsd_file *nf =NULL ;__be32 status;
@@ -4983,15 +5057,29 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,*/ status =nfs4_file_check_deny (fp, open->op_share_deny);if (status != nfs_ok) { -spin_unlock (&fp->fi_lock); - goto out; +if (status != nfserr_share_denied) { +spin_unlock (&fp->fi_lock); + goto out; + } +if (nfs4_resolve_deny_conflicts_locked (fp, new_stp, + stp, open->op_share_deny, false)) { +spin_unlock (&fp->fi_lock); + goto out; + } }/* set access to the file */ status =nfs4_file_get_access (fp, open->op_share_access);if (status != nfs_ok) { -spin_unlock (&fp->fi_lock); - goto out; +if (status != nfserr_share_denied) { +spin_unlock (&fp->fi_lock); + goto out; + } +if (nfs4_resolve_deny_conflicts_locked (fp, new_stp, + stp, open->op_share_access, true)) { +spin_unlock (&fp->fi_lock); + goto out; + } }/* Set access bits in stateid */
@@ -5042,7 +5130,7 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cunsigned char old_deny_bmap = stp->st_deny_bmap;if (!test_access (open->op_share_access, stp)) -return nfs4_get_vfs_file (rqstp, fp, cur_fh, stp, open); +return nfs4_get_vfs_file (rqstp, fp, cur_fh, stp, open, false);/* test and set deny mode */ spin_lock (&fp->fi_lock);
@@ -5051,7 +5139,10 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cset_deny (open->op_share_deny, stp); fp->fi_share_deny |= (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); - } + }else if (status == nfserr_share_denied && + !nfs4_resolve_deny_conflicts_locked (fp, false, stp, + open->op_share_deny, false)) + status = nfs_ok;spin_unlock (&fp->fi_lock);if (status != nfs_ok)
@@ -5391,7 +5482,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf goto out; } }else { - status =nfs4_get_vfs_file (rqstp, fp, current_fh, stp, open); + status =nfs4_get_vfs_file (rqstp, fp, current_fh, stp, open, true);if (status) { stp->st_stid.sc_type =NFS4_CLOSED_STID ;release_open_stateid (stp);
Signature · 1 line
2.9.5
Dai Ngo
reviewerRFC PATCH v15 6/11 NFSD: Update find_clp_in_name_tree() to handle courtesy clients
In reply to Dai NgoUpdate find_clp_in_name_tree:
. skip client with CLIENT_EXPIRED flag; discarded courtesy client. . if courtesy client was found then clear CLIENT_COURTESY and
set CLIENT_RECONNECTED so callers can take appropriate action.
Update find_confirmed_client_by_name to discard the courtesy client; set CLIENT_EXPIRED.
Update nfsd4_setclientid to expire the confirmed courtesy client to prevent multiple confirmed clients with the same name on the the conf_id_hashtbl list.
--- fs/nfsd/nfs4state.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +52 -3
@@ -1929,6 +1929,34 @@ __find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net)return NULL ; } +static void +nfsd4_discard_courtesy_clnt (struct nfs4_client *clp) +{ +spin_lock (&clp->cl_cs_lock); +set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +} + +static bool +nfs4_is_courtesy_client_expired (struct nfs4_client *clp) +{ +clear_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags); +/* need to sync with thread resolving lock/deleg conflict */ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) { +spin_unlock (&clp->cl_cs_lock); +return true; + } +/* +* clear CLIENT_COURTESY flag to prevent it from being +* destroyed by thread trying to resolve conflicts. +*/ +if (test_and_clear_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) +set_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +return false; +} +static struct nfsd4_session *find_in_sessionid_hashtbl (struct nfs4_sessionid *sessionid,struct net *net,__be32 *ret)
@@ -2834,8 +2862,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 (nfs4_is_courtesy_client_expired (clp)) +return NULL ;return clp; + } }return NULL ; }
@@ -2914,8 +2945,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 &&test_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags)) { +nfsd4_discard_courtesy_clnt (clp); + clp =NULL ; + } +return clp; } static struct nfs4_client *
@@ -4032,12 +4070,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 &&test_bit (NFSD4_CLIENT_RECONNECTED , &conf->cl_flags)) { + cclient = conf; + conf =NULL ; + } +if (conf &&client_has_state (conf)) { status = nfserr_clid_inuse;if (clp_used_exchangeid (conf))
@@ -4068,7 +4113,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) {
Signature · 1 line
2.9.5
Re: [PATCH RFC v15 06/11] NFSD: Update find_clp_in_name_tree() to handle courtesy clients
Quoted 87 lines · Dai Ngo
Update
find_clp_in_name_tree:
. skip client withCLIENT_EXPIREDflag; discarded courtesy client. . if courtesy client was found then clearCLIENT_COURTESYand
setCLIENT_RECONNECTEDso callers can take appropriate action.Update
find_confirmed_client_by_nameto discard the courtesy client; setCLIENT_EXPIRED.Update
nfsd4_setclientidto expire the confirmed courtesy client to prevent multiple confirmed clients with the same name on the theconf_id_hashtbllist.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 55 ++++++++++++++++++++++++++++++++++++++++++++++++++---1 file changed, 52 insertions(+), 3 deletions(-)fs/nfsd/nfs4state.c +28
-0@@ -1929,6 +1929,34 @@ __find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net)return NULL ; } +static void +nfsd4_discard_courtesy_clnt (struct nfs4_client *clp) +{ +spin_lock (&clp->cl_cs_lock); +set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +} + +static bool +nfs4_is_courtesy_client_expired (struct nfs4_client *clp) +{ +clear_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags); +/* need to sync with thread resolving lock/deleg conflict */ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) { +spin_unlock (&clp->cl_cs_lock); +return true; + } +/* +* clear CLIENT_COURTESY flag to prevent it from being +* destroyed by thread trying to resolve conflicts. +*/ +if (test_and_clear_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) +set_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +return false; +} +static struct
nfsd4_session*
find_in_sessionid_hashtbl(structnfs4_sessionid*sessionid, struct net *net,__be32 *ret)fs/nfsd/nfs4state.c +4
-1@@ -2834,8 +2862,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 (nfs4_is_courtesy_client_expired (clp)) +return NULL ;return clp; + } }return NULL ; }@@ -2914,8 +2945,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){fs/nfsd/nfs4state.c +2
-0+struct nfs4_client *clp; +lockdep_assert_held(&nn->client_lock);fs/nfsd/nfs4state.c +6
-1-return find_clp_in_name_tree (name, &nn->conf_name_tree); + clp =find_clp_in_name_tree (name, &nn->conf_name_tree); +if (clp &&test_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags)) { +nfsd4_discard_courtesy_clnt (clp); + clp =NULL ; + } +return clp;
Quoted 1 line
}
2983 static struct nfs4_client *
2984 find_unconfirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn) 2985 {
2986 lockdep_assert_held(&nn->client_lock);
2987 return find_clp_in_name_tree(name, &nn->unconf_name_tree);
2988 }
Notice the difference:
find_confirmed() does find_clp_in_name_tree(&nn->conf_name_tree);
^^^^find_unconfirmed() does find_clp_in_name_tree(&nn->unconf_name_tree);
^^^^^^I don't think we will ever find a client in unconf_name_tree that has CLIENT_RECONNECTED set, will we? So it seems to me that you can safely move the CLIENT_RECONNECTED test into find_clp_in_name_tree() in all cases, maybe?
Or think about it this way: is it possible for an unconfirmed client to become a courtesy client? I don't think it is.
Quoted 30 lines
fs/nfsd/nfs4state.c +8
-1@@ -4032,12 +4070,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 &&test_bit (NFSD4_CLIENT_RECONNECTED , &conf->cl_flags)) { + cclient = conf; + conf =NULL ; + } +if (conf &&client_has_state (conf)) { status = nfserr_clid_inuse;if (clp_used_exchangeid (conf))@@ -4068,7 +4113,11 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, new =NULL ; status = nfs_ok;out:
fs/nfsd/nfs4state.c +2
-0+if (cclient) +unhash_client_locked (cclient);spin_unlock(&nn->client_lock);fs/nfsd/nfs4state.c +2
-0+if (cclient) +expire_client (cclient);
Quoted 6 lines
if (new) free_client(new); if (unconf) {Signature · 1 line
2.9.5
--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 06/11] NFSD: Update find_clp_in_name_tree() to handle courtesy clients
Quoted 96 lines · Chuck Lever III
Quoted 86 lines · Dai Ngo
Update
find_clp_in_name_tree:
. skip client withCLIENT_EXPIREDflag; discarded courtesy client. . if courtesy client was found then clearCLIENT_COURTESYand
setCLIENT_RECONNECTEDso callers can take appropriate action.Update
find_confirmed_client_by_nameto discard the courtesy client; setCLIENT_EXPIRED.Update
nfsd4_setclientidto expire the confirmed courtesy client to prevent multiple confirmed clients with the same name on the theconf_id_hashtbllist.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 55 ++++++++++++++++++++++++++++++++++++++++++++++++++---1 file changed, 52 insertions(+), 3 deletions(-)fs/nfsd/nfs4state.c +28
-0@@ -1929,6 +1929,34 @@ __find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net)return NULL ; } +static void +nfsd4_discard_courtesy_clnt (struct nfs4_client *clp) +{ +spin_lock (&clp->cl_cs_lock); +set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +} + +static bool +nfs4_is_courtesy_client_expired (struct nfs4_client *clp) +{ +clear_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags); +/* need to sync with thread resolving lock/deleg conflict */ +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) { +spin_unlock (&clp->cl_cs_lock); +return true; + } +/* +* clear CLIENT_COURTESY flag to prevent it from being +* destroyed by thread trying to resolve conflicts. +*/ +if (test_and_clear_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) +set_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +return false; +} +static struct
nfsd4_session*
find_in_sessionid_hashtbl(structnfs4_sessionid*sessionid, struct net *net,__be32 *ret)fs/nfsd/nfs4state.c +4
-1@@ -2834,8 +2862,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 (nfs4_is_courtesy_client_expired (clp)) +return NULL ;return clp; + } }return NULL ; }@@ -2914,8 +2945,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){fs/nfsd/nfs4state.c +2
-0+struct nfs4_client *clp; +lockdep_assert_held(&nn->client_lock);fs/nfsd/nfs4state.c +6
-1-return find_clp_in_name_tree (name, &nn->conf_name_tree); + clp =find_clp_in_name_tree (name, &nn->conf_name_tree); +if (clp &&test_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags)) { +nfsd4_discard_courtesy_clnt (clp); + clp =NULL ; + } +return clp;Quoted 1 line
}
2983 static struct
nfs4_client*
2984find_unconfirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn)2985 {
2986lockdep_assert_held(&nn->client_lock);
2987 returnfind_clp_in_name_tree(name, &nn->unconf_name_tree);
2988 }Notice the difference:
Quoted 8 lines
find_confirmed() does find_clp_in_name_tree(&nn->conf_name_tree); ^^^^find_unconfirmed() does find_clp_in_name_tree(&nn->unconf_name_tree); ^^^^^^I don't think we will ever find a client in
unconf_name_treethat hasCLIENT_RECONNECTEDset, will we?
No.
Quoted 3 lines
So it seems to me that you
can safely move theCLIENT_RECONNECTEDtest intofind_clp_in_name_tree()in all cases, maybe?
nfsd4_setclientid needs to treat the courtesy client a little differently from find_[un]confirmed_client_by_name. It has to expire the courtesy client immediately to prevent multiple confirmed clients with the same name on the the conf_id_hashtbl list which causes problem for the subsequent setclientid_confirm.
-Dai
Quoted 46 lines
Or think about it this way: is it possible for an unconfirmed client to become a courtesy client? I don't think it is.
Quoted 30 lines
fs/nfsd/nfs4state.c +8
-1@@ -4032,12 +4070,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 &&test_bit (NFSD4_CLIENT_RECONNECTED , &conf->cl_flags)) { + cclient = conf; + conf =NULL ; + } +if (conf &&client_has_state (conf)) { status = nfserr_clid_inuse;if (clp_used_exchangeid (conf))@@ -4068,7 +4113,11 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, new =NULL ; status = nfs_ok;out:
fs/nfsd/nfs4state.c +2
-0+if (cclient) +unhash_client_locked (cclient);spin_unlock(&nn->client_lock);fs/nfsd/nfs4state.c +2
-0+if (cclient) +expire_client (cclient);Quoted 6 lines
if (new) free_client(new); if (unconf) {Signature · 1 line
2.9.5--
Chuck Lever
Dai Ngo
reviewerRFC PATCH v15 7/11 NFSD: Update find_in_sessionid_hashtbl() to handle courtesy clients
In reply to Dai NgoUpdate find_in_sessionid_hashtbl to:
. skip client with CLIENT_EXPIRED flag; discarded courtesy client. . if courtesy client was found then clear CLIENT_COURTESY and
set CLIENT_RECONNECTED so callers can take appropriate action.
Update nfsd4_sequence and nfsd4_bind_conn_to_session to create client record for client with CLIENT_RECONNECTED set.
Update nfsd4_destroy_session to discard client with CLIENT_RECONNECTED set.
--- fs/nfsd/nfs4state.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +32 -2
@@ -1963,13 +1963,22 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, {struct nfsd4_session *session;__be32 status = nfserr_badsession; +struct nfs4_client *clp; session =__find_in_sessionid_hashtbl (sessionid, net);if (!session) goto out; + clp = session->se_client; +if (clp &&nfs4_is_courtesy_client_expired (clp)) { + session =NULL ; + goto out; + } status =nfsd4_get_session_locked (session); -if (status) +if (status) { session =NULL ; +if (clp &&test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) +nfsd4_discard_courtesy_clnt (clp); + } out: *ret = status;return session;
@@ -3671,6 +3680,7 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp,struct nfsd4_session *session;struct net *net =SVC_NET (rqstp);struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct nfs4_client *clp;if (!nfsd4_last_compound_op (rqstp))return nfserr_not_only_op;
@@ -3703,6 +3713,13 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp,nfsd4_init_conn (rqstp, conn, session); status = nfs_ok; out: + clp = session->se_client; +if (test_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags)) { +if (status == nfs_ok) +nfsd4_client_record_create (clp); +else +nfsd4_discard_courtesy_clnt (clp); + }nfsd4_put_session (session); out_no_session:return status;
@@ -3725,6 +3742,7 @@ nfsd4_destroy_session(struct svc_rqst *r, struct nfsd4_compound_state *cstate,int ref_held_by_me =0 ;struct net *net =SVC_NET (r);struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct nfs4_client *clp; status = nfserr_not_only_op;if (nfsd4_compound_in_session (cstate, sessionid)) {
@@ -3737,6 +3755,12 @@ nfsd4_destroy_session(struct svc_rqst *r, struct nfsd4_compound_state *cstate, ses =find_in_sessionid_hashtbl (sessionid, net, &status);if (!ses) goto out_client_lock; + clp = ses->se_client; +if (test_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags)) { + status = nfserr_badsession; +nfsd4_discard_courtesy_clnt (clp); + goto out_put_session; + } status = nfserr_wrong_cred;if (!nfsd4_mach_creds_match (ses->se_client, r)) goto out_put_session;
@@ -3841,7 +3865,7 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_compoundres *resp = rqstp->rq_resp;struct xdr_stream *xdr = resp->xdr;struct nfsd4_session *session; -struct nfs4_client *clp; +struct nfs4_client *clp =NULL ;struct nfsd4_slot *slot;struct nfsd4_conn *conn;__be32 status;
@@ -3951,6 +3975,12 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (conn)free_conn (conn);spin_unlock (&nn->client_lock); +if (clp &&test_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags)) { +if (status == nfs_ok) +nfsd4_client_record_create (clp); +else +nfsd4_discard_courtesy_clnt (clp); + }return status; out_put_session:nfsd4_put_session_locked (session);
Signature · 1 line
2.9.5
Re: [PATCH RFC v15 07/11] NFSD: Update find_in_sessionid_hashtbl() to handle courtesy clients
Quoted 35 lines · Dai Ngo
Update
find_in_sessionid_hashtblto:
. skip client withCLIENT_EXPIREDflag; discarded courtesy client. . if courtesy client was found then clearCLIENT_COURTESYand
setCLIENT_RECONNECTEDso callers can take appropriate action.Update
nfsd4_sequenceandnfsd4_bind_conn_to_sessionto create client record for client withCLIENT_RECONNECTEDset.Update
nfsd4_destroy_sessionto discard client withCLIENT_RECONNECTEDset.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 34 ++++++++++++++++++++++++++++++++--1 file changed, 32 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +3
-0@@ -1963,13 +1963,22 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, {struct nfsd4_session *session;__be32 status = nfserr_badsession; +struct nfs4_client *clp; session =__find_in_sessionid_hashtbl (sessionid, net);if (!session) goto out; + clp = session->se_client; +if (clp &&nfs4_is_courtesy_client_expired (clp)) {
fs/nfsd/nfs4state.c find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, · line 1981
Quoted 10 lines
fs/nfsd/nfs4state.c +7
-1+ session =NULL ; + goto out; + } status =nfsd4_get_session_locked (session); -if (status) +if (status) { session =NULL ; +if (clp &&test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) +nfsd4_discard_courtesy_clnt (clp); + }
Here and above: I'm not seeing how @clp can be NULL, but I'm kind of new to fs/nfsd/nfs4state.c.
--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 07/11] NFSD: Update find_in_sessionid_hashtbl() to handle courtesy clients
Quoted 38 lines · Chuck Lever III
Quoted 38 lines · Dai Ngo
Update
find_in_sessionid_hashtblto:
. skip client withCLIENT_EXPIREDflag; discarded courtesy client. . if courtesy client was found then clearCLIENT_COURTESYand
setCLIENT_RECONNECTEDso callers can take appropriate action.Update
nfsd4_sequenceandnfsd4_bind_conn_to_sessionto create client record for client withCLIENT_RECONNECTEDset.Update
nfsd4_destroy_sessionto discard client withCLIENT_RECONNECTEDset.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 34 ++++++++++++++++++++++++++++++++--1 file changed, 32 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +6
-0@@ -1963,13 +1963,22 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, {struct nfsd4_session *session;__be32 status = nfserr_badsession; +struct nfs4_client *clp; session =__find_in_sessionid_hashtbl (sessionid, net);if (!session) goto out; + clp = session->se_client; +if (clp &&nfs4_is_courtesy_client_expired (clp)) { + session =NULL ; + goto out; + } status =nfsd4_get_session_locked (session);
Quoted 8 lines
fs/nfsd/nfs4state.c find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, · line 1981
Quoted 6 lines
fs/nfsd/nfs4state.c +4
-1-if (status) +if (status) { session =NULL ; +if (clp &&test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) +nfsd4_discard_courtesy_clnt (clp); + }Here and above: I'm not seeing how @clp can be NULL, but I'm kind of new to
fs/nfsd/nfs4state.c.
it seems like @clp can not be NULL since existing code does not check for it. I will remove it to avoid any confusion. Can this be done a a separate clean up patch?
Thanks,
-Dai
Quoted 7 lines
--
Chuck Lever
Re: [PATCH RFC v15 07/11] NFSD: Update find_in_sessionid_hashtbl() to handle courtesy clients
Quoted 34 lines · Dai Ngo
Quoted 30 lines · Chuck Lever III
Quoted 29 lines
Quoted 2 lines · Dai Ngo
Update
find_in_sessionid_hashtblto:
. skip client withCLIENT_EXPIREDflag; discarded courtesy client. . if courtesy client was found then clearCLIENT_COURTESYand
setCLIENT_RECONNECTEDso callers can take appropriate action.Update
nfsd4_sequenceandnfsd4_bind_conn_to_sessionto create client record for client withCLIENT_RECONNECTEDset.Update
nfsd4_destroy_sessionto discard client withCLIENT_RECONNECTEDset.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 34 ++++++++++++++++++++++++++++++++--1 file changed, 32 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +1
-0@@ -1963,13 +1963,22 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, {struct nfsd4_session *session;__be32 status = nfserr_badsession; +struct nfs4_client *clp;
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
fs/nfsd/nfs4state.c +2
-0session =__find_in_sessionid_hashtbl (sessionid, net);if (!session) goto out; + clp = session->se_client; +if (clp &&nfs4_is_courtesy_client_expired (clp)) {Quoted 8 lines
fs/nfsd/nfs4state.c find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, · line 1979
Quoted 8 lines
fs/nfsd/nfs4state.c +5
-1+ session =NULL ; + goto out; + } status =nfsd4_get_session_locked (session); -if (status) +if (status) { session =NULL ; +if (clp &&test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags))
By the way, I don’t understand why this checks CLIENT_COURTESY to see if the clp should be discarded. Shouldn’t it check CLIENT_RECONNECTED like the other sites?
Quoted 8 lines
Quoted 4 lines
fs/nfsd/nfs4state.c find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, · line 1981
Quoted 2 lines
fs/nfsd/nfs4state.c +2
-0+nfsd4_discard_courtesy_clnt (clp); + }Here and above: I'm not seeing how @clp can be NULL, but I'm kind of new to
fs/nfsd/nfs4state.c.it seems like @clp can not be NULL since existing code does not check for it. I will remove it to avoid any confusion. Can this be done as a separate clean up patch?
I don’t think this series is going to make v5.18. We can keep working on improving each of the patches. And I would rather ensure that the series is properly bisectable. I don’t think we’re at a point where the patches are immutable.
Quoted 10 lines
Thanks,
-DaiQuoted 7 lines
--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 07/11] NFSD: Update find_in_sessionid_hashtbl() to handle courtesy clients
Quoted 32 lines · Chuck Lever III
Quoted 32 lines · Dai Ngo
Quoted 29 lines · Chuck Lever III
Quoted 28 lines
Quoted 2 lines · Dai Ngo
Update
find_in_sessionid_hashtblto:
. skip client withCLIENT_EXPIREDflag; discarded courtesy client. . if courtesy client was found then clearCLIENT_COURTESYand
setCLIENT_RECONNECTEDso callers can take appropriate action.Update
nfsd4_sequenceandnfsd4_bind_conn_to_sessionto create client record for client withCLIENT_RECONNECTEDset.Update
nfsd4_destroy_sessionto discard client withCLIENT_RECONNECTEDset.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 34 ++++++++++++++++++++++++++++++++--1 file changed, 32 insertions(+), 2 deletions(-)fs/nfsd/nfs4state.c +1
-0@@ -1963,13 +1963,22 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, {struct nfsd4_session *session;__be32 status = nfserr_badsession; +struct nfs4_client *clp;
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
fs/nfsd/nfs4state.c +2
-0session =__find_in_sessionid_hashtbl (sessionid, net);if (!session) goto out; + clp = session->se_client; +if (clp &&nfs4_is_courtesy_client_expired (clp)) {Quoted 8 lines
Quoted 8 lines
fs/nfsd/nfs4state.c find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, · line 1979
Quoted 8 lines
fs/nfsd/nfs4state.c +5
-1+ session =NULL ; + goto out; + } status =nfsd4_get_session_locked (session); -if (status) +if (status) { session =NULL ; +if (clp &&test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags))By the way, I don’t understand why this checks
CLIENT_COURTESYto see if the clp should be discarded. Shouldn’t it checkCLIENT_RECONNECTEDlike the other sites?
Thanks, this should check for CLIENT_RECONNECTED as described in the commit message.
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
fs/nfsd/nfs4state.c find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, · line 1981
Quoted 4 lines
fs/nfsd/nfs4state.c +2
-0+nfsd4_discard_courtesy_clnt (clp); + }Here and above: I'm not seeing how @clp can be NULL, but I'm kind of new to
fs/nfsd/nfs4state.c.it seems like @clp can not be NULL since existing code does not check for it. I will remove it to avoid any confusion. Can this be done as a separate clean up patch?
I don’t think this series is going to make v5.18. We can keep working on improving each of the patches. And I would rather ensure that the series is properly bisectable. I don’t think we’re at a point where the patches are immutable.
okay, I will submit v16 to address review comments.
-Dai
Dai Ngo
reviewerRFC PATCH v15 8/11 NFSD: Update find_client_in_id_table() to handle courtesy clients
In reply to Dai NgoUpdate find_client_in_id_table to:
. skip client with CLIENT_EXPIRED; discarded courtesy client . if courtesy client was found then clear CLIENT_COURTESY and set
CLIENT_RECONNECTED flag so callers 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.
--- fs/nfsd/nfs4state.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +20 -2
@@ -2921,6 +2921,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 (nfs4_is_courtesy_client_expired (clp)) +continue ;renew_client_locked (clp);return clp; }
@@ -2932,9 +2934,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 &&test_bit (NFSD4_CLIENT_RECONNECTED , &clp->cl_flags)) { +nfsd4_discard_courtesy_clnt (clp); + clp =NULL ; + } +return clp; } static struct nfs4_client *
@@ -4873,9 +4881,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);
@@ -4900,6 +4909,8 @@ static __be32 set_client(clientid_t *clid, cstate->clp =lookup_clientid (clid, false, nn);if (!cstate->clp)return nfserr_expired; +if (test_bit (NFSD4_CLIENT_RECONNECTED , &cstate->clp->cl_flags)) +nfsd4_client_record_create (cstate->clp);return nfs_ok; }
@@ -6219,6 +6230,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 (test_bit (NFSD4_CLIENT_RECONNECTED , &found->cl_flags)) { +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 );
Signature · 1 line
2.9.5
Dai Ngo
reviewerRFC PATCH v15 9/11 NFSD: Refactor nfsd4_laundromat()
In reply to Dai NgoExtract a bit of logic that is about to be expanded to handle courtesy clients.
--- fs/nfsd/nfs4state.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
fs/nfsd/nfs4state.c +21 -12
@@ -5806,6 +5806,26 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn) }#endif +static void +nfs4_get_client_reaplist (struct nfsd_net *nn,struct list_head *reaplist, +struct laundry_time *lt) +{ +struct list_head *pos, *next; +struct nfs4_client *clp; + +INIT_LIST_HEAD (reaplist); +spin_lock (&nn->client_lock); +list_for_each_safe (pos, next, &nn->client_lru) { + clp = list_entry(pos, struct nfs4_client, cl_lru); +if (!state_expired (lt, clp->cl_time)) +break ; +if (mark_client_expired_locked (clp)) +continue ; +list_add (&clp->cl_lru, reaplist); + } +spin_unlock (&nn->client_lock); +} +static time64_t nfs4_laundromat (struct nfsd_net *nn) {
@@ -5828,7 +5848,6 @@ nfs4_laundromat(struct nfsd_net *nn) goto out; }nfsd4_end_grace (nn); -INIT_LIST_HEAD (&reaplist);spin_lock (&nn->s2s_cp_lock);idr_for_each_entry (&nn->s2s_cp_stateids, cps_t, i) {
@@ -5838,17 +5857,7 @@ nfs4_laundromat(struct nfsd_net *nn)_free_cpntf_state_locked (nn, cps); }spin_unlock (&nn->s2s_cp_lock); - -spin_lock (&nn->client_lock); -list_for_each_safe (pos, next, &nn->client_lru) { - clp = list_entry(pos, struct nfs4_client, cl_lru); -if (!state_expired (<, clp->cl_time)) -break ; -if (mark_client_expired_locked (clp)) -continue ; -list_add (&clp->cl_lru, &reaplist); - } -spin_unlock (&nn->client_lock); +nfs4_get_client_reaplist (nn, &reaplist, <);list_for_each_safe (pos, next, &reaplist) { clp = list_entry(pos, struct nfs4_client, cl_lru);trace_nfsd_clid_purged (&clp->cl_clientid);
Signature · 1 line
2.9.5
Dai Ngo
reviewerRFC PATCH v15 10/11 NFSD: Update laundromat to handle courtesy clients
In reply to Dai NgoAdd nfs4_anylock_blocker and nfs4_lockowner_has_blockers to check if an expired client has any lock blockers
Update nfs4_get_client_reaplist to:
. add discarded courtesy client; client marked with CLIENT_EXPIRED,
to reaplist.
. detect if expired client still has state and no blockers then
transit it to courtesy client by setting CLIENT_COURTESY flag and removing the client record.
--- fs/nfsd/nfs4state.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +101 -2
@@ -5806,24 +5806,116 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn) }#endif +/* Check if any lock belongs to this lockowner has any blockers */ +static bool +nfs4_lockowner_has_blockers (struct nfs4_lockowner *lo) +{ +struct file_lock_context *ctx; +struct nfs4_ol_stateid *stp; +struct nfs4_file *nf; +struct file_lock *fl; + +list_for_each_entry (stp, &lo->lo_owner.so_stateids, st_perstateowner) { + nf = stp->st_stid.sc_file; + ctx = nf->fi_inode->i_flctx; +if (!ctx) +continue ; +spin_lock (&ctx->flc_lock); +list_for_each_entry (fl, &ctx->flc_posix, fl_list) { +if (fl->fl_owner != lo) +continue ; +if (locks_has_blockers_locked (fl)) { +spin_unlock (&ctx->flc_lock); +return true; + } + } +spin_unlock (&ctx->flc_lock); + } +return false; +} + +static bool +nfs4_anylock_blockers (struct nfs4_client *clp) +{ +int i; +struct nfs4_stateowner *so; +struct nfs4_lockowner *lo; + +spin_lock (&clp->cl_lock); +for (i =0 ; i <OWNER_HASH_SIZE ; i++) { +list_for_each_entry (so, &clp->cl_ownerstr_hashtbl[i], + so_strhash) { +if (so->so_is_open_owner) +continue ; + lo =lockowner (so); +if (nfs4_lockowner_has_blockers (lo)) { +spin_unlock (&clp->cl_lock); +return true; + } + } + } +spin_unlock (&clp->cl_lock); +return false; +} +static void nfs4_get_client_reaplist (struct nfsd_net *nn,struct list_head *reaplist,struct laundry_time *lt) {struct list_head *pos, *next;struct nfs4_client *clp; +bool cour; +struct list_head cslist;INIT_LIST_HEAD (reaplist); +INIT_LIST_HEAD (&cslist);spin_lock (&nn->client_lock);list_for_each_safe (pos, next, &nn->client_lru) { clp = list_entry(pos, struct nfs4_client, cl_lru);if (!state_expired (lt, clp->cl_time))break ; -if (mark_client_expired_locked (clp)) + +if (!client_has_state (clp)) + goto exp_client; + +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags)) + goto exp_client; + cour =test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags); +if (cour &&ktime_get_boottime_seconds () >= + (clp->cl_time +NFSD_COURTESY_CLIENT_TIMEOUT )) + goto exp_client; +if (nfs4_anylock_blockers (clp)) { +exp_client: +if (mark_client_expired_locked (clp)) +continue ; +list_add (&clp->cl_lru, reaplist);continue ; -list_add (&clp->cl_lru, reaplist); + } +if (!cour) { +spin_lock (&clp->cl_cs_lock); +set_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +list_add (&clp->cl_cs_list, &cslist); + } }spin_unlock (&nn->client_lock); + +while (!list_empty (&cslist)) { + clp = list_first_entry(&cslist, struct nfs4_client, cl_cs_list); +list_del_init (&clp->cl_cs_list); +spin_lock (&clp->cl_cs_lock); +/* +* Client might have re-connected. Make sure it's +* still in courtesy state before removing its record. +*/ +if (test_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags) || + !test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) { +spin_unlock (&clp->cl_cs_lock); +continue ; + } +spin_unlock (&clp->cl_cs_lock); +nfsd4_client_record_remove (clp); + } } static time64_t
@@ -5869,6 +5961,13 @@ nfs4_laundromat(struct nfsd_net *nn) dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);if (!state_expired (<, dp->dl_time))break ; +spin_lock (&clp->cl_cs_lock); +if (test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags)) { +set_bit (NFSD4_CLIENT_EXPIRED , &clp->cl_flags); +spin_unlock (&clp->cl_cs_lock); +continue ; + } +spin_unlock (&clp->cl_cs_lock);WARN_ON (!unhash_delegation_locked (dp));list_add (&dp->dl_recall_lru, &reaplist); }
Signature · 1 line
2.9.5
Dai Ngo
reviewerRFC PATCH v15 11/11 NFSD: Show state of courtesy clients in client info
In reply to Dai NgoUpdate client_info_show to show state of courtesy client and time since last renew.
--- fs/nfsd/nfs4state.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/nfsd/nfs4state.c +8 -1
@@ -2439,7 +2439,8 @@ static int client_info_show(struct seq_file *m, void *v) {struct inode *inode = m->private;struct nfs4_client *clp; -u64 clid; +u64 clid, hrs; +u32 mins, secs; clp =get_nfsdfs_clp (inode);if (!clp)
@@ -2451,6 +2452,12 @@ static int client_info_show(struct seq_file *m, void *v)seq_puts (m,"status: confirmed\n" ); else seq_puts(m, "status: unconfirmed\n"); +seq_printf (m,"courtesy client: %s\n" , +test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags) ?"yes" :"no" ); + hrs =div_u64_rem (ktime_get_boottime_seconds () - clp->cl_time, +3600 , &secs); + mins =div_u64_rem ((u64 )secs,60 , &secs); +seq_printf (m,"time since last renew: %02ld:%02d:%02d\n" , hrs, mins, secs);seq_printf (m,"name: " );seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len);seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion);
Signature · 1 line
2.9.5
Re: [PATCH RFC v15 11/11] NFSD: Show state of courtesy clients in client info
Quoted 27 lines · Dai Ngo
Update
client_info_showto show state of courtesy client and time since last renew.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +2
-1@@ -2439,7 +2439,8 @@ static int client_info_show(struct seq_file *m, void *v) {struct inode *inode = m->private;struct nfs4_client *clp; -u64 clid; +u64 clid, hrs; +u32 mins, secs; clp =get_nfsdfs_clp (inode);if (!clp)
fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2456
Quoted 5 lines
fs/nfsd/nfs4state.c +2
-0@@ -2451,6 +2452,12 @@ static int client_info_show(struct seq_file *m, void *v)seq_puts (m,"status: confirmed\n" ); else seq_puts(m, "status: unconfirmed\n"); +seq_printf (m,"courtesy client: %s\n" , +test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags) ?"yes" :"no" );
I'm wondering if it would be more economical to combine this output with the status output just before it so we have only one of:
seq_puts(m, "status: unconfirmed\n"); seq_puts(m, "status: confirmed\n");
or
seq_puts(m, "status: courtesy\n");
fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2460
Quoted 4 lines
fs/nfsd/nfs4state.c +4
-0+ hrs =div_u64_rem (ktime_get_boottime_seconds () - clp->cl_time, +3600 , &secs); + mins =div_u64_rem ((u64 )secs,60 , &secs); +seq_printf (m,"time since last renew: %02ld:%02d:%02d\n" , hrs, mins, secs);
Thanks, this seems more friendly than what was here before.
However if we replace the fixed courtesy timeout with a shrinker, I bet some courtesy clients might lie about for many more that 99 hours. Perhaps the left-most format specifier could be just "%lu" and the rest could be "%02u".
(ie, also turn the "d" into "u" to prevent ever displaying a negative number of time units).
Quoted 6 lines
fs/nfsd/nfs4state.c +0
-0seq_printf (m,"name: " );seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len);seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion);Signature · 1 line
2.9.5
--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 11/11] NFSD: Show state of courtesy clients in client info
Quoted 35 lines · Chuck Lever III
Quoted 26 lines · Dai Ngo
Update
client_info_showto show state of courtesy client and time since last renew.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +2
-1@@ -2439,7 +2439,8 @@ static int client_info_show(struct seq_file *m, void *v) {struct inode *inode = m->private;struct nfs4_client *clp; -u64 clid; +u64 clid, hrs; +u32 mins, secs; clp =get_nfsdfs_clp (inode);if (!clp)fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2456
Quoted 5 lines
fs/nfsd/nfs4state.c +2
-0@@ -2451,6 +2452,12 @@ static int client_info_show(struct seq_file *m, void *v)seq_puts (m,"status: confirmed\n" ); else seq_puts(m, "status: unconfirmed\n"); +seq_printf (m,"courtesy client: %s\n" , +test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags) ?"yes" :"no" );I'm wondering if it would be more economical to combine this output with the status output just before it so we have only one of:
Quoted 7 lines
seq_puts(m, "status: unconfirmed\n"); seq_puts(m, "status: confirmed\n");or
seq_puts(m, "status: courtesy\n");
make sense, will fix.
Quoted 8 lines
fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2460
Quoted 6 lines
fs/nfsd/nfs4state.c +4
-0+ hrs =div_u64_rem (ktime_get_boottime_seconds () - clp->cl_time, +3600 , &secs); + mins =div_u64_rem ((u64 )secs,60 , &secs); +seq_printf (m,"time since last renew: %02ld:%02d:%02d\n" , hrs, mins, secs);Thanks, this seems more friendly than what was here before.
Quoted 7 lines
However if we replace the fixed courtesy timeout with a shrinker, I bet some courtesy clients might lie about for many more that 99 hours. Perhaps the left-most format specifier could be just "%lu" and the rest could be "%02u".
(ie, also turn the "d" into "u" to prevent ever displaying a negative number of time units).
will fix.
I will wait for your review of the rest of the patches before I submit v16.
Thanks,
-Dai
Quoted 13 lines
Quoted 8 lines
fs/nfsd/nfs4state.c +0
-0seq_printf (m,"name: " );seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len);seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion);Signature · 1 line
2.9.5--
Chuck Lever
[email protected]
reviewerRe: [PATCH RFC v15 11/11] NFSD: Show state of courtesy clients in client info
Quoted 42 lines · On 3/9/22 12:51 PM, [email protected] wrote:
Quoted 40 lines · Chuck Lever III
Quoted 29 lines · Dai Ngo
Update
client_info_showto show state of courtesy client and time since last renew.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +2
-1@@ -2439,7 +2439,8 @@ static int client_info_show(struct seq_file *m, void *v) { struct inode *inode = m->private; struct nfs4_client *clp; - u64 clid; + u64 clid, hrs; + u32 mins, secs; clp = get_nfsdfs_clp(inode);if (!clp)
fs/nfsd/nfs4state.c +0
-0@@ -2451,6 +2452,12 @@ static int client_info_show(struct seq_file *m, void *v) seq_puts(m, "status: confirmed\n");Quoted 5 lines
else
seq_puts(m, "status: unconfirmed\n");
+ seq_printf(m, "courtesy client: %s\n",
+test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)? "yes" :
"no");I'm wondering if it would be more economical to combine this output with the status output just before it so we have only one of:
seq_puts(m, "status: unconfirmed\n");
Quoted 7 lines
Quoted 5 lines
seq_puts(m, "status: confirmed\n");
or
seq_puts(m, "status: courtesy\n");
make sense, will fix.
On second thought, I think it's safer to keep this the same since there might be scripts out there that depend on it.
-Dai
Quoted 39 lines
Quoted 10 lines
Quoted 8 lines
+ hrs =
div_u64_rem(ktime_get_boottime_seconds() - clp->cl_time, + 3600, &secs);
+ mins =div_u64_rem((u64)secs, 60, &secs);
+seq_printf(m, "time since last renew: %02ld:%02d:%02d\n", hrs, mins, secs);Thanks, this seems more friendly than what was here before.
Quoted 7 lines
However if we replace the fixed courtesy timeout with a shrinker, I bet some courtesy clients might lie about for many more that 99 hours. Perhaps the left-most format specifier could be just "%lu" and the rest could be "%02u".
(ie, also turn the "d" into "u" to prevent ever displaying a negative number of time units).
will fix.
I will wait for your review of the rest of the patches before I submit v16.
Thanks,
-DaiQuoted 13 lines
Quoted 8 lines
seq_printf(m, "name: ");
seq_quote_mem(m,clp->cl_name.data,clp->cl_name.len);seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion);Signature · 1 line
2.9.5Signature · 1 line
Chuck Lever
Re: [PATCH RFC v15 11/11] NFSD: Show state of courtesy clients in client info
Quoted 46 lines · Dai Ngo
Quoted 42 lines · On 3/9/22 12:51 PM, [email protected] wrote:
Quoted 41 lines · Chuck Lever III
Quoted 26 lines · Dai Ngo
Update
client_info_showto show state of courtesy client and time since last renew.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +2
-1@@ -2439,7 +2439,8 @@ static int client_info_show(struct seq_file *m, void *v) {struct inode *inode = m->private;struct nfs4_client *clp; -u64 clid; +u64 clid, hrs; +u32 mins, secs; clp =get_nfsdfs_clp (inode);if (!clp)fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2456
Quoted 5 lines
fs/nfsd/nfs4state.c +2
-0@@ -2451,6 +2452,12 @@ static int client_info_show(struct seq_file *m, void *v)seq_puts (m,"status: confirmed\n" ); else seq_puts(m, "status: unconfirmed\n"); +seq_printf (m,"courtesy client: %s\n" , +test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags) ?"yes" :"no" );I'm wondering if it would be more economical to combine this output with the status output just before it so we have only one of:
seq_puts(m, "status: unconfirmed\n"); seq_puts(m, "status: confirmed\n");
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
or
seq_puts(m, "status: courtesy\n");make sense, will fix.
On second thought, I think it's safer to keep this the same since there might be scripts out there that depend on it.
I agree we should be sensitive to potential users of this information. However…
Without having one or two examples of such scripts in front of us, it’s hard to say whether my suggestion (a new keyword after “status:”) or your original (a new line in the file) would be more disruptive.
Also I’m not seeing exactly how the output format is versioned… so what’s the safest way to make changes to the output format of this file? Anyone?
When I get in front of a computer again, I’ll have a look at the change history of this function.
Quoted 40 lines
-Dai
Quoted 38 lines
Quoted 9 lines
fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2460
Quoted 7 lines
fs/nfsd/nfs4state.c +4
-0+ hrs =div_u64_rem (ktime_get_boottime_seconds () - clp->cl_time, +3600 , &secs); + mins =div_u64_rem ((u64 )secs,60 , &secs); +seq_printf (m,"time since last renew: %02ld:%02d:%02d\n" , hrs, mins, secs);Thanks, this seems more friendly than what was here before.
Quoted 7 lines
However if we replace the fixed courtesy timeout with a shrinker, I bet some courtesy clients might lie about for many more that 99 hours. Perhaps the left-most format specifier could be just "%lu" and the rest could be "%02u".
(ie, also turn the "d" into "u" to prevent ever displaying a negative number of time units).
will fix.
I will wait for your review of the rest of the patches before I submit v16.
Thanks,
-DaiQuoted 13 lines
Quoted 8 lines
fs/nfsd/nfs4state.c +0
-0seq_printf (m,"name: " );seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len);seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion);Signature · 1 line
2.9.5Signature · 1 line
Chuck Lever
Re: [PATCH RFC v15 11/11] NFSD: Show state of courtesy clients in client info
Quoted 50 lines · Chuck Lever III
Quoted 38 lines · Dai Ngo
Quoted 34 lines · On 3/9/22 12:51 PM, [email protected] wrote:
Quoted 33 lines · Chuck Lever III
Quoted 17 lines · Dai Ngo
Update
client_info_showto show state of courtesy client and time since last renew.Signed-off-by Dai Ngo <[email protected]> ---
fs/nfsd/nfs4state.c| 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c index renamed from fs/nfsd/nfs4state.c +0
-0
bced09014e6b..ed14e0b54537100644 ---a/fs/nfsd/nfs4state.c+++b/fs/nfsd/nfs4state.c@@ -2439,7 +2439,8 @@ static intclient_info_show(struct seq_file *m, void *v){ struct inode
*inode =m->private; structnfs4_client*clp; - u64 clid; +
u64 clid, hrs; + u32 mins, secs;Quoted 6 lines
clp =
get_nfsdfs_clp(inode); if (!clp) @@ -2451,6 +2452,12 @@ static intclient_info_show(struct seq_file *m, void *v)seq_puts(m, "status: confirmed\n"); else seq_puts(m, "status:
unconfirmed\n"); + seq_printf(m, "courtesy client: %s\n",
+test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)?
"yes" : "no");I'm wondering if it would be more economical to combine this output with the status output just before it so we have only one of:
seq_puts(m, "status: unconfirmed\n"); seq_puts(m, "status: confirmed\n");Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
or
seq_puts(m, "status: courtesy\n");make sense, will fix.
On second thought, I think it's safer to keep this the same since there might be scripts out there that depend on it.
I agree we should be sensitive to potential users of this information. However…
Quoted 7 lines
Without having one or two examples of such scripts in front of us, it’s hard to say whether my suggestion (a new keyword after “status:”) or your original (a new line in the file) would be more disruptive.
Also I’m not seeing exactly how the output format is versioned… so what’s the safest way to make changes to the output format of this file? Anyone?
It's not versioned. It'd be good to document some rules; nfsd(7) seems like the logical place to put that, though probably knows about it. Pointers to it from kernel comments and elsewhere might help?
I suppose the absolute safest option would be adding a new line, but I like the idea of adding the possibility of "courtesy" to the existing line as you suggest, and that seems very low risk.
There is one utility, see nfs-utils/tools/nfsdclnt. I'd forgotten about it untill I looked just now....
--b.
[email protected]
reviewerRe: [PATCH RFC v15 11/11] NFSD: Show state of courtesy clients in client info
Quoted 58 lines · Bruce Fields
Quoted 46 lines · Chuck Lever III
Quoted 35 lines · Dai Ngo
Quoted 32 lines · On 3/9/22 12:51 PM, [email protected] wrote:
Quoted 31 lines · Chuck Lever III
Quoted 17 lines · Dai Ngo
Update
client_info_showto show state of courtesy client and time since last renew.Signed-off-by Dai Ngo <[email protected]> ---
fs/nfsd/nfs4state.c| 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c index renamed from fs/nfsd/nfs4state.c +0
-0
bced09014e6b..ed14e0b54537100644 ---a/fs/nfsd/nfs4state.c+++b/fs/nfsd/nfs4state.c@@ -2439,7 +2439,8 @@ static intclient_info_show(struct seq_file *m, void *v){ struct inode
*inode =m->private; structnfs4_client*clp; - u64 clid; +
u64 clid, hrs; + u32 mins, secs;Quoted 6 lines
clp =
get_nfsdfs_clp(inode); if (!clp) @@ -2451,6 +2452,12 @@ static intclient_info_show(struct seq_file *m, void *v)seq_puts(m, "status: confirmed\n"); else seq_puts(m, "status:
unconfirmed\n"); + seq_printf(m, "courtesy client: %s\n",
+test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)?
"yes" : "no");I'm wondering if it would be more economical to combine this output with the status output just before it so we have only one of:
seq_puts(m, "status: unconfirmed\n");Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
seq_puts(m, "status: confirmed\n");or
seq_puts(m, "status: courtesy\n");make sense, will fix.
On second thought, I think it's safer to keep this the same since there might be scripts out there that depend on it.
I agree we should be sensitive to potential users of this information. However…
Quoted 7 lines
Without having one or two examples of such scripts in front of us, it’s hard to say whether my suggestion (a new keyword after “status:”) or your original (a new line in the file) would be more disruptive.
Also I’m not seeing exactly how the output format is versioned… so what’s the safest way to make changes to the output format of this file? Anyone?
It's not versioned. It'd be good to document some rules; nfsd(7) seems like the logical place to put that, though probably knows about it. Pointers to it from kernel comments and elsewhere might help?
Quoted 6 lines
I suppose the absolute safest option would be adding a new line, but I like the idea of adding the possibility of "courtesy" to the existing line as you suggest, and that seems very low risk.
There is one utility, see nfs-utils/tools/nfsdclnt. I'd forgotten about it untill I looked just now....
I think nfsdclnt does not parse the 'status' field so we're safe to update the status to show 'confirmed/unconfirmed/courtesy'.
-Dai
Quoted 2 lines
--b.
Re: [PATCH RFC v15 11/11] NFSD: Show state of courtesy clients in client info
In reply to [email protected]Quoted 47 lines · Dai Ngo
Quoted 41 lines · On 3/9/22 12:51 PM, [email protected] wrote:
Quoted 39 lines · Chuck Lever III
Quoted 26 lines · Dai Ngo
Update
client_info_showto show state of courtesy client and time since last renew.Signed-off-by Dai Ngo <[email protected]>---
fs/nfsd/nfs4state.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +2
-1@@ -2439,7 +2439,8 @@ static int client_info_show(struct seq_file *m, void *v) {struct inode *inode = m->private;struct nfs4_client *clp; -u64 clid; +u64 clid, hrs; +u32 mins, secs; clp =get_nfsdfs_clp (inode);if (!clp)fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2456
Quoted 5 lines
fs/nfsd/nfs4state.c +2
-0@@ -2451,6 +2452,12 @@ static int client_info_show(struct seq_file *m, void *v)seq_puts (m,"status: confirmed\n" ); else seq_puts(m, "status: unconfirmed\n"); +seq_printf (m,"courtesy client: %s\n" , +test_bit (NFSD4_CLIENT_COURTESY , &clp->cl_flags) ?"yes" :"no" );I'm wondering if it would be more economical to combine this output with the status output just before it so we have only one of:
seq_puts(m, "status: unconfirmed\n"); seq_puts(m, "status: confirmed\n");
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
or
seq_puts(m, "status: courtesy\n");make sense, will fix.
On second thought, I think it's safer to keep this the same since there might be scripts out there that depend on it.
The "status:" information was added just a year ago by 472d155a0631 ("nfsd: report client confirmation status in "info" file"). I don't see any concern in recent commit history about making the information in this file machine-readable or backwards-compatible.
Therefore IMO it should be safe and acceptable to use:
status: confirmed|unconfirmed|courtesy
Quoted 40 lines
-Dai
Quoted 38 lines
Quoted 9 lines
fs/nfsd/nfs4state.c static int client_info_show(struct seq_file *m, void *v) · line 2460
Quoted 7 lines
fs/nfsd/nfs4state.c +4
-0+ hrs =div_u64_rem (ktime_get_boottime_seconds () - clp->cl_time, +3600 , &secs); + mins =div_u64_rem ((u64 )secs,60 , &secs); +seq_printf (m,"time since last renew: %02ld:%02d:%02d\n" , hrs, mins, secs);Thanks, this seems more friendly than what was here before.
Quoted 7 lines
However if we replace the fixed courtesy timeout with a shrinker, I bet some courtesy clients might lie about for many more that 99 hours. Perhaps the left-most format specifier could be just "%lu" and the rest could be "%02u".
(ie, also turn the "d" into "u" to prevent ever displaying a negative number of time units).
will fix.
I will wait for your review of the rest of the patches before I submit v16.
Thanks,
-DaiQuoted 13 lines
Quoted 8 lines
fs/nfsd/nfs4state.c +0
-0seq_printf (m,"name: " );seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len);seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion);Signature · 1 line
2.9.5Signature · 1 line
Chuck Lever
--
Chuck Lever