linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: dai.ngo@oracle.com
To: "J. Bruce Fields" <bfields@fieldses.org>
Cc: chuck.lever@oracle.com, jlayton@redhat.com,
	viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH RFC v22 6/7] NFSD: add support for lock conflict to courteous server
Date: Wed, 27 Apr 2022 20:47:06 -0700	[thread overview]
Message-ID: <9fb9a58b-2790-70cb-e8db-f443566911d0@oracle.com> (raw)
In-Reply-To: <20220428020511.GK13471@fieldses.org>


On 4/27/22 7:05 PM, J. Bruce Fields wrote:
> On Wed, Apr 27, 2022 at 01:52:52AM -0700, Dai Ngo wrote:
>> This patch allows expired client with lock state to be in COURTESY
>> state. Lock conflict with COURTESY client is resolved by the fs/lock
>> code using the lm_lock_expirable and lm_expire_lock callback in the
>> struct lock_manager_operations.
>>
>> If conflict client is in COURTESY state, set it to EXPIRABLE and
>> schedule the laundromat to run immediately to expire the client. The
>> callback lm_expire_lock waits for the laundromat to flush its work
>> queue before returning to caller.
>>
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>>   fs/nfsd/nfs4state.c | 82 +++++++++++++++++++++++++++++++++--------------------
>>   1 file changed, 52 insertions(+), 30 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index 55ecf5da25fe..9b1134d823bb 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -5705,11 +5705,31 @@ 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_has_any_locks(struct nfs4_client *clp)
>> +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++) {
>> @@ -5717,40 +5737,17 @@ nfs4_has_any_locks(struct nfs4_client *clp)
>>   				so_strhash) {
>>   			if (so->so_is_open_owner)
>>   				continue;
>> -			spin_unlock(&clp->cl_lock);
>> -			return true;
>> +			lo = lockowner(so);
>> +			if (nfs4_lockowner_has_blockers(lo)) {
>> +				spin_unlock(&clp->cl_lock);
>> +				return true;
>> +			}
>>   		}
>>   	}
>>   	spin_unlock(&clp->cl_lock);
>>   	return false;
>>   }
>>   
>> -/*
>> - * place holder for now, no check for lock blockers yet
>> - */
>> -static bool
>> -nfs4_anylock_blockers(struct nfs4_client *clp)
>> -{
>> -	/* not allow locks yet */
>> -	if (nfs4_has_any_locks(clp))
>> -		return true;
>> -	/*
>> -	 * don't want to check for delegation conflict here since
>> -	 * we need the state_lock for it. The laundromat willexpire
>> -	 * COURTESY later when checking for delegation recall timeout.
>> -	 */
>> -	return false;
>> -}
>> -
>> -static bool client_has_state_tmp(struct nfs4_client *clp)
>> -{
>> -	if (((!list_empty(&clp->cl_delegations)) ||
>> -			client_has_openowners(clp)) &&
>> -			list_empty(&clp->async_copies))
>> -		return true;
>> -	return false;
>> -}
>> -
>>   static void
>>   nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist,
>>   				struct laundry_time *lt)
>> @@ -5767,7 +5764,7 @@ nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist,
>>   			goto exp_client;
>>   		if (!state_expired(lt, clp->cl_time))
>>   			break;
>> -		if (!client_has_state_tmp(clp))
>> +		if (!client_has_state(clp))
>>   			goto exp_client;
>>   		cour = (clp->cl_state == NFSD4_COURTESY);
>>   		if (cour && ktime_get_boottime_seconds() >=
>> @@ -6722,6 +6719,28 @@ nfsd4_lm_put_owner(fl_owner_t owner)
>>   		nfs4_put_stateowner(&lo->lo_owner);
>>   }
>>   
>> +/* return pointer to struct nfs4_client if client is expirable */
>> +static void *
>> +nfsd4_lm_lock_expirable(struct file_lock *cfl)
>> +{
>> +	struct nfs4_lockowner *lo = (struct nfs4_lockowner *)cfl->fl_owner;
>> +	struct nfs4_client *clp = lo->lo_owner.so_client;
>> +
>> +	if (!try_to_expire_client(clp))
>> +		return clp;
>> +	return NULL;
>> +}
>> +
>> +/* schedule laundromat to run immediately and wait for it to complete */
>> +static void
>> +nfsd4_lm_expire_lock(void *data)
>> +{
>> +	struct nfs4_client *clp = (struct nfs4_client *)data;
>> +	struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
>> +
>> +	flush_workqueue(laundry_wq);
> Note we don't actually end up using the nfsd_net, or the argument to
> lm_lock_expirable.  This was a mistake in my original sketch.  See
>
> 	https://lore.kernel.org/linux-nfs/20220417190727.GA18120@fieldses.org/
>
> 	"Correction: I forgot that the laundromat is global, not
> 	per-net.  So, we can skip the put_net/get_net.  Also,
> 	lm_lock_expirable can just return bool instead of void *, and
> 	lm_expire_lock needs no arguments."

ok. I'll make the adjustment.

-Dai

>
> --b.
>
>> +}
>> +
>>   static void
>>   nfsd4_lm_notify(struct file_lock *fl)
>>   {
>> @@ -6748,9 +6767,12 @@ nfsd4_lm_notify(struct file_lock *fl)
>>   }
>>   
>>   static const struct lock_manager_operations nfsd_posix_mng_ops  = {
>> +	.lm_mod_owner = THIS_MODULE,
>>   	.lm_notify = nfsd4_lm_notify,
>>   	.lm_get_owner = nfsd4_lm_get_owner,
>>   	.lm_put_owner = nfsd4_lm_put_owner,
>> +	.lm_lock_expirable = nfsd4_lm_lock_expirable,
>> +	.lm_expire_lock = nfsd4_lm_expire_lock,
>>   };
>>   
>>   static inline void
>> -- 
>> 2.9.5

  reply	other threads:[~2022-04-28  3:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27  8:52 [PATCH RFC v22 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-04-27  8:52 ` [PATCH RFC v22 1/7] NFSD: add courteous server support for thread with only delegation Dai Ngo
2022-04-27 16:12   ` J. Bruce Fields
2022-04-27 16:41     ` dai.ngo
2022-04-27 18:46   ` J. Bruce Fields
2022-04-27 18:53     ` dai.ngo
2022-04-27 19:09     ` dai.ngo
2022-04-27 19:13       ` J. Bruce Fields
2022-04-27 21:56   ` J. Bruce Fields
2022-04-27 22:52     ` dai.ngo
2022-04-28  1:52       ` J. Bruce Fields
2022-04-28  3:44         ` dai.ngo
2022-04-28  6:36           ` dai.ngo
2022-04-27  8:52 ` [PATCH RFC v22 2/7] NFSD: add support for share reservation conflict to courteous server Dai Ngo
2022-04-27  8:52 ` [PATCH RFC v22 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd Dai Ngo
2022-04-27  8:52 ` [PATCH RFC v22 4/7] fs/lock: add helper locks_owner_has_blockers to check for blockers Dai Ngo
2022-04-27  8:52 ` [PATCH RFC v22 5/7] fs/lock: add 2 callbacks to lock_manager_operations to resolve conflict Dai Ngo
2022-04-27  8:52 ` [PATCH RFC v22 6/7] NFSD: add support for lock conflict to courteous server Dai Ngo
2022-04-27 18:50   ` dai.ngo
2022-04-28  2:05   ` J. Bruce Fields
2022-04-28  3:47     ` dai.ngo [this message]
2022-04-27  8:52 ` [PATCH RFC v22 7/7] NFSD: Show state of courtesy client 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=9fb9a58b-2790-70cb-e8db-f443566911d0@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).