linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: dai.ngo@oracle.com
To: Chuck Lever III <chuck.lever@oracle.com>
Cc: Bruce Fields <bfields@fieldses.org>,
	Jeff Layton <jlayton@redhat.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH RFC v17 10/11] NFSD: Update laundromat to handle courtesy clients
Date: Thu, 17 Mar 2022 10:51:25 -0700	[thread overview]
Message-ID: <902e8785-e5ed-ed72-28b3-1b9bf6866540@oracle.com> (raw)
In-Reply-To: <3414885F-7F08-4005-860D-16EC94B106A5@oracle.com>


On 3/17/22 8:03 AM, Chuck Lever III wrote:
>
>> On Mar 17, 2022, at 3:43 AM, Dai Ngo <dai.ngo@oracle.com> wrote:
>>
>> Add 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 courtesy client in CLIENT_EXPIRED state to reaplist.
>> . detect if expired client still has state and no blockers then
>>    transit it to courtesy client by setting CLIENT_COURTESY state
>>    and removing the client record.
>>
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>> fs/nfsd/nfs4state.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 91 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index b4b976e00ce6..d5758c7101dc 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -5755,24 +5755,106 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
>> }
>> #endif
>>
>> +/* Check if any lock belonging 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;
>> +
>> +	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;
>> +		if (locks_owner_has_blockers(ctx, lo))
>> +			return true;
>> +	}
>> +	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 (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED)
>> +			goto exp_client;
>> +		cour = (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY);
> I've forgotten: why don't you need to hold clp->cl_cs_lock while
> checking cs_client_state here?

The CLIENT_EXPIRED can be set when either the client is reconnecting
or when a thread tries to resolve the conflict with the courtesy
client. The reconnecting client and the laundromat are synced by
nn->client_lock. For thread that tries to resolve conflict and set
CLIENT_EXPIRED, if the laundromat misses detecting CLIENT_EXPIRED
then it will get it the next time it runs.

The CLIENT_COURTESY state is only set by the laundromat so there is
no need for any lock when checking it here.

-Dai

>
>
>> +		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);
>> +			clp->cl_cs_client_state = NFSD4_CLIENT_COURTESY;
>> +			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 (clp->cl_cs_client_state != NFSD4_CLIENT_COURTESY) {
>> +			spin_unlock(&clp->cl_cs_lock);
>> +			continue;
>> +		}
>> +		spin_unlock(&clp->cl_cs_lock);
>> +		nfsd4_client_record_remove(clp);
>> +	}
>> }
>>
>> static time64_t
>> @@ -5818,6 +5900,13 @@ nfs4_laundromat(struct nfsd_net *nn)
>> 		dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
>> 		if (!state_expired(&lt, dp->dl_time))
>> 			break;
>> +		spin_lock(&clp->cl_cs_lock);
>> +		if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY) {
>> +			clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED;
>> +			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);
>> 	}
>> -- 
>> 2.9.5
>>
> --
> Chuck Lever
>
>
>

  reply	other threads:[~2022-03-17 17:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17  7:43 [PATCH RFC v17 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-03-17  7:43 ` [PATCH RFC v17 01/11] fs/lock: add helper locks_owner_has_blockers to check for blockers Dai Ngo
2022-03-17 15:04   ` Chuck Lever III
2022-03-17 17:39   ` Jeff Layton
2022-03-17 17:46     ` Chuck Lever III
2022-03-17  7:43 ` [PATCH RFC v17 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server Dai Ngo
2022-03-17  7:43 ` [PATCH RFC v17 03/11] NFSD: Add lm_lock_expired call out Dai Ngo
2022-03-17  7:43 ` [PATCH RFC v17 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients Dai Ngo
2022-03-17  7:43 ` [PATCH RFC v17 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client Dai Ngo
2022-03-21 21:44   ` J. Bruce Fields
2022-03-23  0:42     ` dai.ngo
2022-03-17  7:43 ` [PATCH RFC v17 06/11] NFSD: Update find_clp_in_name_tree() " Dai Ngo
2022-03-22 21:50   ` J. Bruce Fields
2022-03-23  1:14     ` dai.ngo
2022-03-17  7:43 ` [PATCH RFC v17 07/11] NFSD: Update find_in_sessionid_hashtbl() " Dai Ngo
2022-03-17  7:43 ` [PATCH RFC v17 08/11] NFSD: Update find_client_in_id_table() " Dai Ngo
2022-03-17  7:43 ` [PATCH RFC v17 09/11] NFSD: Refactor nfsd4_laundromat() Dai Ngo
2022-03-17  7:43 ` [PATCH RFC v17 10/11] NFSD: Update laundromat to handle courtesy clients Dai Ngo
2022-03-17 15:03   ` Chuck Lever III
2022-03-17 17:51     ` dai.ngo [this message]
2022-03-17  7:43 ` [PATCH RFC v17 11/11] NFSD: Show state of courtesy clients in client info Dai Ngo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=902e8785-e5ed-ed72-28b3-1b9bf6866540@oracle.com \
    --to=dai.ngo@oracle.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).