@@ -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);
}
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 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. Signed-off-by: Dai Ngo <dai.ngo@oracle.com> --- fs/nfsd/nfs4state.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-)