* [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
@ 2022-04-23 18:44 ` Dai Ngo
2022-04-25 18:51 ` J. Bruce Fields
2022-04-23 18:44 ` [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server Dai Ngo
` (6 subsequent siblings)
7 siblings, 1 reply; 25+ messages in thread
From: Dai Ngo @ 2022-04-23 18:44 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
This patch provides courteous server support for delegation only.
Only expired client with delegation but no conflict and no open
or lock state is allowed to be in COURTESY state.
Delegation conflict with COURTESY client is resolved by setting it
to EXPIRABLE, queue work for the laundromat and return delay to
caller. Conflict is resolved when the laudromat runs and expires
the EXIRABLE client while the NFS client retries the OPEN request.
Local thread request that gets conflict is doing the retry in
__break_lease.
Client in COURTESY state is allowed to reconnect and continues to
have access to its state while client in EXPIRABLE state is not.
To prevent 2 clients with the same name are on the conf_name_tree,
nfsd4_setclientid is modified to expire confirmed client in EXPIRABLE
state.
The spinlock cl_cs_lock is used to handle race conditions between
conflict resolver, nfsd_break_deleg_cb, and the COURTESY client
doing reconnect.
find_in_sessionid_hashtbl, find_confirmed_client_by_name and
find_confirmed_client are modified to activate COURTESY client by
setting it to ACTIVE state and skip client in EXPIRABLE state.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 129 +++++++++++++++++++++++++++++++++++++++++++++-------
fs/nfsd/nfsd.h | 1 +
fs/nfsd/state.h | 63 +++++++++++++++++++++++++
3 files changed, 177 insertions(+), 16 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 234e852fcdfa..fea5e24e7d94 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -125,6 +125,8 @@ static void free_session(struct nfsd4_session *);
static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
+static struct workqueue_struct *laundry_wq;
+
static bool is_session_dead(struct nfsd4_session *ses)
{
return ses->se_flags & NFS4_SESSION_DEAD;
@@ -690,6 +692,14 @@ static unsigned int file_hashval(struct svc_fh *fh)
static struct hlist_head file_hashtbl[FILE_HASH_SIZE];
+static inline void
+run_laundromat(struct nfsd_net *nn, bool wait)
+{
+ mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
+ if (wait)
+ flush_workqueue(laundry_wq);
+}
+
static void
__nfs4_file_get_access(struct nfs4_file *fp, u32 access)
{
@@ -1939,6 +1949,11 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net,
session = __find_in_sessionid_hashtbl(sessionid, net);
if (!session)
goto out;
+ if (!try_to_activate_client(session->se_client)) {
+ /* client is EXPIRABLE */
+ session = NULL;
+ goto out;
+ }
status = nfsd4_get_session_locked(session);
if (status)
session = NULL;
@@ -2004,6 +2019,7 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
idr_init(&clp->cl_stateids);
atomic_set(&clp->cl_rpc_users, 0);
clp->cl_cb_state = NFSD4_CB_UNKNOWN;
+ clp->cl_state = NFSD4_ACTIVE;
INIT_LIST_HEAD(&clp->cl_idhash);
INIT_LIST_HEAD(&clp->cl_openowners);
INIT_LIST_HEAD(&clp->cl_delegations);
@@ -2015,6 +2031,7 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
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:
@@ -2890,9 +2907,13 @@ 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 && !try_to_activate_client(clp))
+ clp = NULL;
+ return clp;
}
static struct nfs4_client *
@@ -2912,8 +2933,13 @@ 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 && !try_to_activate_client(clp))
+ clp = NULL;
+ return clp;
}
static struct nfs4_client *
@@ -4030,12 +4056,25 @@ 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 *expired = 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);
+ conf = find_clp_in_name_tree(&clname, &nn->conf_name_tree);
+ if (conf) {
+ if (!try_to_activate_client(conf)) {
+ /*
+ * remove EXPIRABLE client from conf_name_tree so
+ * when the new client is confirmed there won't be
+ * 2 clients with the same name on the conf_name_tree.
+ */
+ if (!mark_client_expired_locked(conf))
+ expired = conf;
+ conf = NULL;
+ }
+ }
if (conf && client_has_state(conf)) {
status = nfserr_clid_inuse;
if (clp_used_exchangeid(conf))
@@ -4073,6 +4112,8 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
trace_nfsd_clid_expire_unconf(&unconf->cl_clientid);
expire_client(unconf);
}
+ if (expired)
+ expire_client(expired);
return status;
}
@@ -4694,9 +4735,16 @@ nfsd_break_deleg_cb(struct file_lock *fl)
bool ret = false;
struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner;
struct nfs4_file *fp = dp->dl_stid.sc_file;
+ struct nfs4_client *clp = dp->dl_stid.sc_client;
+ struct nfsd_net *nn;
trace_nfsd_cb_recall(&dp->dl_stid);
+ if (try_to_expire_client(clp)) {
+ nn = net_generic(clp->net, nfsd_net_id);
+ run_laundromat(nn, false);
+ }
+
/*
* We don't want the locks code to timeout the lease for us;
* we'll remove it ourself if a delegation isn't returned
@@ -5605,6 +5653,64 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
}
#endif
+/*
+ * place holder for now, no check for lock blockers yet
+ */
+static bool
+nfs4_anylock_blockers(struct nfs4_client *clp)
+{
+ /*
+ * 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)
+{
+ struct list_head *pos, *next;
+ struct nfs4_client *clp;
+ bool cour;
+
+ 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 (clp->cl_state == NFSD4_EXPIRABLE)
+ goto exp_client;
+ if (!state_expired(lt, clp->cl_time))
+ break;
+ if (!client_has_state_tmp(clp))
+ goto exp_client;
+ cour = (clp->cl_state == NFSD4_COURTESY);
+ 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;
+ }
+ if (!cour)
+ cmpxchg(&clp->cl_state, NFSD4_ACTIVE, NFSD4_COURTESY);
+ }
+ spin_unlock(&nn->client_lock);
+}
+
static time64_t
nfs4_laundromat(struct nfsd_net *nn)
{
@@ -5627,7 +5733,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) {
@@ -5637,17 +5742,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);
@@ -5657,6 +5752,9 @@ nfs4_laundromat(struct nfsd_net *nn)
spin_lock(&state_lock);
list_for_each_safe(pos, next, &nn->del_recall_lru) {
dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
+
+ clp = dp->dl_stid.sc_client;
+ try_to_expire_client(dp->dl_stid.sc_client);
if (!state_expired(<, dp->dl_time))
break;
WARN_ON(!unhash_delegation_locked(dp));
@@ -5722,7 +5820,6 @@ nfs4_laundromat(struct nfsd_net *nn)
return max_t(time64_t, lt.new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
}
-static struct workqueue_struct *laundry_wq;
static void laundromat_main(struct work_struct *);
static void
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 4fc1fd639527..23996c6ca75e 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);
#define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
#define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
+#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */
/*
* The following attributes are currently not supported by the NFSv4 server:
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 95457cfd37fc..b7d243073c58 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -283,6 +283,28 @@ struct nfsd4_sessionid {
#define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
/*
+ * State Meaning Where set
+ * --------------------------------------------------------------------------
+ * | NFSD4_ACTIVE | Confirmed, active | Default |
+ * |------------------- ----------------------------------------------------|
+ * | NFSD4_COURTESY | Courtesy state. | nfs4_get_client_reaplist |
+ * | | Lease/lock/share | |
+ * | | reservation conflict | |
+ * | | can cause Courtesy | |
+ * | | client to be expired | |
+ * |------------------------------------------------------------------------|
+ * | NFSD4_EXPIRABLE | Courtesy client to be| nfs4_laundromat |
+ * | | expired by Laundromat| try_to_expire_client |
+ * | | due to conflict | |
+ * |------------------------------------------------------------------------|
+ */
+enum {
+ NFSD4_ACTIVE = 0,
+ NFSD4_COURTESY,
+ NFSD4_EXPIRABLE,
+};
+
+/*
* struct nfs4_client - one per client. Clientids live here.
*
* The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
@@ -385,6 +407,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;
+ unsigned int cl_state;
};
/* struct nfs4_client_reset
@@ -702,4 +727,42 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);
extern int nfsd4_client_record_check(struct nfs4_client *clp);
extern void nfsd4_record_grace_done(struct nfsd_net *nn);
+static inline bool try_to_expire_client(struct nfs4_client *clp)
+{
+ bool ret;
+
+ spin_lock(&clp->cl_cs_lock);
+ if (clp->cl_state == NFSD4_EXPIRABLE) {
+ spin_unlock(&clp->cl_cs_lock);
+ return true;
+ }
+ ret = NFSD4_COURTESY ==
+ cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
+ spin_unlock(&clp->cl_cs_lock);
+ return ret;
+}
+
+static inline bool try_to_activate_client(struct nfs4_client *clp)
+{
+ bool ret;
+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
+ /* sync with laundromat */
+ lockdep_assert_held(&nn->client_lock);
+
+ /* sync with try_to_expire_client */
+ spin_lock(&clp->cl_cs_lock);
+ if (clp->cl_state == NFSD4_ACTIVE) {
+ spin_unlock(&clp->cl_cs_lock);
+ return true;
+ }
+ if (clp->cl_state == NFSD4_EXPIRABLE) {
+ spin_unlock(&clp->cl_cs_lock);
+ return false;
+ }
+ ret = NFSD4_COURTESY ==
+ cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_ACTIVE);
+ spin_unlock(&clp->cl_cs_lock);
+ return ret;
+}
#endif /* NFSD4_STATE_H */
--
2.9.5
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-23 18:44 ` [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation Dai Ngo
@ 2022-04-25 18:51 ` J. Bruce Fields
2022-04-25 19:42 ` dai.ngo
0 siblings, 1 reply; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 18:51 UTC (permalink / raw)
To: Dai Ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Sat, Apr 23, 2022 at 11:44:09AM -0700, Dai Ngo wrote:
> This patch provides courteous server support for delegation only.
> Only expired client with delegation but no conflict and no open
> or lock state is allowed to be in COURTESY state.
>
> Delegation conflict with COURTESY client is resolved by setting it
> to EXPIRABLE, queue work for the laundromat and return delay to
> caller. Conflict is resolved when the laudromat runs and expires
> the EXIRABLE client while the NFS client retries the OPEN request.
> Local thread request that gets conflict is doing the retry in
> __break_lease.
>
> Client in COURTESY state is allowed to reconnect and continues to
> have access to its state while client in EXPIRABLE state is not.
> To prevent 2 clients with the same name are on the conf_name_tree,
> nfsd4_setclientid is modified to expire confirmed client in EXPIRABLE
> state.
>
> The spinlock cl_cs_lock is used to handle race conditions between
> conflict resolver, nfsd_break_deleg_cb, and the COURTESY client
> doing reconnect.
>
> find_in_sessionid_hashtbl, find_confirmed_client_by_name and
> find_confirmed_client are modified to activate COURTESY client by
> setting it to ACTIVE state and skip client in EXPIRABLE state.
>
> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> ---
> fs/nfsd/nfs4state.c | 129 +++++++++++++++++++++++++++++++++++++++++++++-------
> fs/nfsd/nfsd.h | 1 +
> fs/nfsd/state.h | 63 +++++++++++++++++++++++++
> 3 files changed, 177 insertions(+), 16 deletions(-)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 234e852fcdfa..fea5e24e7d94 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -125,6 +125,8 @@ static void free_session(struct nfsd4_session *);
> static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
> static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
>
> +static struct workqueue_struct *laundry_wq;
> +
> static bool is_session_dead(struct nfsd4_session *ses)
> {
> return ses->se_flags & NFS4_SESSION_DEAD;
> @@ -690,6 +692,14 @@ static unsigned int file_hashval(struct svc_fh *fh)
>
> static struct hlist_head file_hashtbl[FILE_HASH_SIZE];
>
> +static inline void
> +run_laundromat(struct nfsd_net *nn, bool wait)
> +{
> + mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
> + if (wait)
> + flush_workqueue(laundry_wq);
> +}
Let's keep those two things separate. The "wait" argument isn't
self-documenting when reading the calling code. And the
mod_delayed_work call isn't always needed before flush_workqueue.
> +
> static void
> __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
> {
> @@ -1939,6 +1949,11 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net,
> session = __find_in_sessionid_hashtbl(sessionid, net);
> if (!session)
> goto out;
> + if (!try_to_activate_client(session->se_client)) {
> + /* client is EXPIRABLE */
> + session = NULL;
> + goto out;
No, we definitely don't want to do this. As I said before, an
"expirable client" should be treated in every way exactly like any
regular active client. Literally the only difference is that the
laundromat can try to expire it.
And then all this code becomes unnecessary:
> @@ -702,4 +727,42 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);
> extern int nfsd4_client_record_check(struct nfs4_client *clp);
> extern void nfsd4_record_grace_done(struct nfsd_net *nn);
>
> +static inline bool try_to_expire_client(struct nfs4_client *clp)
> +{
> + bool ret;
> +
> + spin_lock(&clp->cl_cs_lock);
> + if (clp->cl_state == NFSD4_EXPIRABLE) {
> + spin_unlock(&clp->cl_cs_lock);
> + return true;
> + }
> + ret = NFSD4_COURTESY ==
> + cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
> + spin_unlock(&clp->cl_cs_lock);
> + return ret;
> +}
> +
> +static inline bool try_to_activate_client(struct nfs4_client *clp)
> +{
> + bool ret;
> + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
> +
> + /* sync with laundromat */
> + lockdep_assert_held(&nn->client_lock);
> +
> + /* sync with try_to_expire_client */
> + spin_lock(&clp->cl_cs_lock);
> + if (clp->cl_state == NFSD4_ACTIVE) {
> + spin_unlock(&clp->cl_cs_lock);
> + return true;
> + }
> + if (clp->cl_state == NFSD4_EXPIRABLE) {
> + spin_unlock(&clp->cl_cs_lock);
> + return false;
> + }
> + ret = NFSD4_COURTESY ==
> + cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_ACTIVE);
> + spin_unlock(&clp->cl_cs_lock);
> + return ret;
> +}
--b.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-25 18:51 ` J. Bruce Fields
@ 2022-04-25 19:42 ` dai.ngo
2022-04-25 20:40 ` J. Bruce Fields
0 siblings, 1 reply; 25+ messages in thread
From: dai.ngo @ 2022-04-25 19:42 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 4/25/22 11:51 AM, J. Bruce Fields wrote:
> On Sat, Apr 23, 2022 at 11:44:09AM -0700, Dai Ngo wrote:
>> This patch provides courteous server support for delegation only.
>> Only expired client with delegation but no conflict and no open
>> or lock state is allowed to be in COURTESY state.
>>
>> Delegation conflict with COURTESY client is resolved by setting it
>> to EXPIRABLE, queue work for the laundromat and return delay to
>> caller. Conflict is resolved when the laudromat runs and expires
>> the EXIRABLE client while the NFS client retries the OPEN request.
>> Local thread request that gets conflict is doing the retry in
>> __break_lease.
>>
>> Client in COURTESY state is allowed to reconnect and continues to
>> have access to its state while client in EXPIRABLE state is not.
>> To prevent 2 clients with the same name are on the conf_name_tree,
>> nfsd4_setclientid is modified to expire confirmed client in EXPIRABLE
>> state.
>>
>> The spinlock cl_cs_lock is used to handle race conditions between
>> conflict resolver, nfsd_break_deleg_cb, and the COURTESY client
>> doing reconnect.
>>
>> find_in_sessionid_hashtbl, find_confirmed_client_by_name and
>> find_confirmed_client are modified to activate COURTESY client by
>> setting it to ACTIVE state and skip client in EXPIRABLE state.
>>
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>> fs/nfsd/nfs4state.c | 129 +++++++++++++++++++++++++++++++++++++++++++++-------
>> fs/nfsd/nfsd.h | 1 +
>> fs/nfsd/state.h | 63 +++++++++++++++++++++++++
>> 3 files changed, 177 insertions(+), 16 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index 234e852fcdfa..fea5e24e7d94 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -125,6 +125,8 @@ static void free_session(struct nfsd4_session *);
>> static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
>> static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
>>
>> +static struct workqueue_struct *laundry_wq;
>> +
>> static bool is_session_dead(struct nfsd4_session *ses)
>> {
>> return ses->se_flags & NFS4_SESSION_DEAD;
>> @@ -690,6 +692,14 @@ static unsigned int file_hashval(struct svc_fh *fh)
>>
>> static struct hlist_head file_hashtbl[FILE_HASH_SIZE];
>>
>> +static inline void
>> +run_laundromat(struct nfsd_net *nn, bool wait)
>> +{
>> + mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
>> + if (wait)
>> + flush_workqueue(laundry_wq);
>> +}
> Let's keep those two things separate. The "wait" argument isn't
> self-documenting when reading the calling code.
we can use enum to spell out the intention.
> And the
> mod_delayed_work call isn't always needed before flush_workqueue.
ok. I'll keep them separate.
>
>> +
>> static void
>> __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
>> {
>> @@ -1939,6 +1949,11 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net,
>> session = __find_in_sessionid_hashtbl(sessionid, net);
>> if (!session)
>> goto out;
>> + if (!try_to_activate_client(session->se_client)) {
>> + /* client is EXPIRABLE */
>> + session = NULL;
>> + goto out;
> No, we definitely don't want to do this. As I said before, an
> "expirable client" should be treated in every way exactly like any
> regular active client. Literally the only difference is that the
> laundromat can try to expire it.
Do you mean leave the state as EXPIRABLE but allow the callers
to use the client as an ACTIVE client:
static inline bool try_to_expire_client(struct nfs4_client *clp)
{
bool ret;
spin_lock(&clp->cl_cs_lock);
if (clp->cl_state == NFSD4_EXPIRABLE) {
spin_unlock(&clp->cl_cs_lock);
return false; <<<====== was true
}
ret = NFSD4_COURTESY ==
cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
spin_unlock(&clp->cl_cs_lock);
return ret;
}
-Dai
>
> And then all this code becomes unnecessary:
>
>> @@ -702,4 +727,42 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);
>> extern int nfsd4_client_record_check(struct nfs4_client *clp);
>> extern void nfsd4_record_grace_done(struct nfsd_net *nn);
>>
>> +static inline bool try_to_expire_client(struct nfs4_client *clp)
>> +{
>> + bool ret;
>> +
>> + spin_lock(&clp->cl_cs_lock);
>> + if (clp->cl_state == NFSD4_EXPIRABLE) {
>> + spin_unlock(&clp->cl_cs_lock);
>> + return true;
>> + }
>> + ret = NFSD4_COURTESY ==
>> + cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
>> + spin_unlock(&clp->cl_cs_lock);
>> + return ret;
>> +}
>> +
>> +static inline bool try_to_activate_client(struct nfs4_client *clp)
>> +{
>> + bool ret;
>> + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
>> +
>> + /* sync with laundromat */
>> + lockdep_assert_held(&nn->client_lock);
>> +
>> + /* sync with try_to_expire_client */
>> + spin_lock(&clp->cl_cs_lock);
>> + if (clp->cl_state == NFSD4_ACTIVE) {
>> + spin_unlock(&clp->cl_cs_lock);
>> + return true;
>> + }
>> + if (clp->cl_state == NFSD4_EXPIRABLE) {
>> + spin_unlock(&clp->cl_cs_lock);
>> + return false;
>> + }
>> + ret = NFSD4_COURTESY ==
>> + cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_ACTIVE);
>> + spin_unlock(&clp->cl_cs_lock);
>> + return ret;
>> +}
> --b.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-25 19:42 ` dai.ngo
@ 2022-04-25 20:40 ` J. Bruce Fields
2022-04-25 21:35 ` dai.ngo
0 siblings, 1 reply; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 20:40 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Mon, Apr 25, 2022 at 12:42:58PM -0700, dai.ngo@oracle.com wrote:
>
> On 4/25/22 11:51 AM, J. Bruce Fields wrote:
> >On Sat, Apr 23, 2022 at 11:44:09AM -0700, Dai Ngo wrote:
> >>This patch provides courteous server support for delegation only.
> >>Only expired client with delegation but no conflict and no open
> >>or lock state is allowed to be in COURTESY state.
> >>
> >>Delegation conflict with COURTESY client is resolved by setting it
> >>to EXPIRABLE, queue work for the laundromat and return delay to
> >>caller. Conflict is resolved when the laudromat runs and expires
> >>the EXIRABLE client while the NFS client retries the OPEN request.
> >>Local thread request that gets conflict is doing the retry in
> >>__break_lease.
> >>
> >>Client in COURTESY state is allowed to reconnect and continues to
> >>have access to its state while client in EXPIRABLE state is not.
> >>To prevent 2 clients with the same name are on the conf_name_tree,
> >>nfsd4_setclientid is modified to expire confirmed client in EXPIRABLE
> >>state.
> >>
> >>The spinlock cl_cs_lock is used to handle race conditions between
> >>conflict resolver, nfsd_break_deleg_cb, and the COURTESY client
> >>doing reconnect.
> >>
> >>find_in_sessionid_hashtbl, find_confirmed_client_by_name and
> >>find_confirmed_client are modified to activate COURTESY client by
> >>setting it to ACTIVE state and skip client in EXPIRABLE state.
> >>
> >>Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> >>---
> >> fs/nfsd/nfs4state.c | 129 +++++++++++++++++++++++++++++++++++++++++++++-------
> >> fs/nfsd/nfsd.h | 1 +
> >> fs/nfsd/state.h | 63 +++++++++++++++++++++++++
> >> 3 files changed, 177 insertions(+), 16 deletions(-)
> >>
> >>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>index 234e852fcdfa..fea5e24e7d94 100644
> >>--- a/fs/nfsd/nfs4state.c
> >>+++ b/fs/nfsd/nfs4state.c
> >>@@ -125,6 +125,8 @@ static void free_session(struct nfsd4_session *);
> >> static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
> >> static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
> >>+static struct workqueue_struct *laundry_wq;
> >>+
> >> static bool is_session_dead(struct nfsd4_session *ses)
> >> {
> >> return ses->se_flags & NFS4_SESSION_DEAD;
> >>@@ -690,6 +692,14 @@ static unsigned int file_hashval(struct svc_fh *fh)
> >> static struct hlist_head file_hashtbl[FILE_HASH_SIZE];
> >>+static inline void
> >>+run_laundromat(struct nfsd_net *nn, bool wait)
> >>+{
> >>+ mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
> >>+ if (wait)
> >>+ flush_workqueue(laundry_wq);
> >>+}
> >Let's keep those two things separate. The "wait" argument isn't
> >self-documenting when reading the calling code.
>
> we can use enum to spell out the intention.
>
> > And the
> >mod_delayed_work call isn't always needed before flush_workqueue.
>
> ok. I'll keep them separate.
>
> >
> >>+
> >> static void
> >> __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
> >> {
> >>@@ -1939,6 +1949,11 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net,
> >> session = __find_in_sessionid_hashtbl(sessionid, net);
> >> if (!session)
> >> goto out;
> >>+ if (!try_to_activate_client(session->se_client)) {
> >>+ /* client is EXPIRABLE */
> >>+ session = NULL;
> >>+ goto out;
> >No, we definitely don't want to do this. As I said before, an
> >"expirable client" should be treated in every way exactly like any
> >regular active client. Literally the only difference is that the
> >laundromat can try to expire it.
>
> Do you mean leave the state as EXPIRABLE but allow the callers
> to use the client as an ACTIVE client:
The only place we should even be checking whether a client is EXPIRABLE
is in the laundromat thread, in the loop over the client_lru. Even
there, EXPIRABLE being set doesn't mean the client *has* to be expired,
the real decision is left to mark_client_expired_locked(), as it
currently is.
> static inline bool try_to_expire_client(struct nfs4_client *clp)
> {
> bool ret;
>
> spin_lock(&clp->cl_cs_lock);
> if (clp->cl_state == NFSD4_EXPIRABLE) {
> spin_unlock(&clp->cl_cs_lock);
> return false; <<<====== was true
> }
> ret = NFSD4_COURTESY ==
> cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
> spin_unlock(&clp->cl_cs_lock);
> return ret;
> }
So, try_to_expire_client(), as I said, should be just
static bool try_to_expire_client(struct nfs4_client *clp)
{
return COURTESY == cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
}
Except, OK, I did forget that somebody else could have already set
EXPIRABLE, and we still want to tell the caller to retry in that case,
so, oops, let's make it:
return ACTIVE != cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
In other words: set EXPIRABLE if and only if the state is COURTESY, and
then tell the caller to retry the operation if and only if the state was
previously COURTESY or EXPIRABLE.
But we shouldn't need the cl_cs_lock, and certainly shouldn't be failing
lookups of EXPIRABLE clients.
--b.
>
> -Dai
>
> >
> >And then all this code becomes unnecessary:
> >
> >>@@ -702,4 +727,42 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);
> >> extern int nfsd4_client_record_check(struct nfs4_client *clp);
> >> extern void nfsd4_record_grace_done(struct nfsd_net *nn);
> >>+static inline bool try_to_expire_client(struct nfs4_client *clp)
> >>+{
> >>+ bool ret;
> >>+
> >>+ spin_lock(&clp->cl_cs_lock);
> >>+ if (clp->cl_state == NFSD4_EXPIRABLE) {
> >>+ spin_unlock(&clp->cl_cs_lock);
> >>+ return true;
> >>+ }
> >>+ ret = NFSD4_COURTESY ==
> >>+ cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
> >>+ spin_unlock(&clp->cl_cs_lock);
> >>+ return ret;
> >>+}
> >>+
> >>+static inline bool try_to_activate_client(struct nfs4_client *clp)
> >>+{
> >>+ bool ret;
> >>+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
> >>+
> >>+ /* sync with laundromat */
> >>+ lockdep_assert_held(&nn->client_lock);
> >>+
> >>+ /* sync with try_to_expire_client */
> >>+ spin_lock(&clp->cl_cs_lock);
> >>+ if (clp->cl_state == NFSD4_ACTIVE) {
> >>+ spin_unlock(&clp->cl_cs_lock);
> >>+ return true;
> >>+ }
> >>+ if (clp->cl_state == NFSD4_EXPIRABLE) {
> >>+ spin_unlock(&clp->cl_cs_lock);
> >>+ return false;
> >>+ }
> >>+ ret = NFSD4_COURTESY ==
> >>+ cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_ACTIVE);
> >>+ spin_unlock(&clp->cl_cs_lock);
> >>+ return ret;
> >>+}
> >--b.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-25 20:40 ` J. Bruce Fields
@ 2022-04-25 21:35 ` dai.ngo
2022-04-25 21:48 ` J. Bruce Fields
0 siblings, 1 reply; 25+ messages in thread
From: dai.ngo @ 2022-04-25 21:35 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 4/25/22 1:40 PM, J. Bruce Fields wrote:
> On Mon, Apr 25, 2022 at 12:42:58PM -0700, dai.ngo@oracle.com wrote:
>> On 4/25/22 11:51 AM, J. Bruce Fields wrote:
>>> On Sat, Apr 23, 2022 at 11:44:09AM -0700, Dai Ngo wrote:
>>>> This patch provides courteous server support for delegation only.
>>>> Only expired client with delegation but no conflict and no open
>>>> or lock state is allowed to be in COURTESY state.
>>>>
>>>> Delegation conflict with COURTESY client is resolved by setting it
>>>> to EXPIRABLE, queue work for the laundromat and return delay to
>>>> caller. Conflict is resolved when the laudromat runs and expires
>>>> the EXIRABLE client while the NFS client retries the OPEN request.
>>>> Local thread request that gets conflict is doing the retry in
>>>> __break_lease.
>>>>
>>>> Client in COURTESY state is allowed to reconnect and continues to
>>>> have access to its state while client in EXPIRABLE state is not.
>>>> To prevent 2 clients with the same name are on the conf_name_tree,
>>>> nfsd4_setclientid is modified to expire confirmed client in EXPIRABLE
>>>> state.
>>>>
>>>> The spinlock cl_cs_lock is used to handle race conditions between
>>>> conflict resolver, nfsd_break_deleg_cb, and the COURTESY client
>>>> doing reconnect.
>>>>
>>>> find_in_sessionid_hashtbl, find_confirmed_client_by_name and
>>>> find_confirmed_client are modified to activate COURTESY client by
>>>> setting it to ACTIVE state and skip client in EXPIRABLE state.
>>>>
>>>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>>>> ---
>>>> fs/nfsd/nfs4state.c | 129 +++++++++++++++++++++++++++++++++++++++++++++-------
>>>> fs/nfsd/nfsd.h | 1 +
>>>> fs/nfsd/state.h | 63 +++++++++++++++++++++++++
>>>> 3 files changed, 177 insertions(+), 16 deletions(-)
>>>>
>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>> index 234e852fcdfa..fea5e24e7d94 100644
>>>> --- a/fs/nfsd/nfs4state.c
>>>> +++ b/fs/nfsd/nfs4state.c
>>>> @@ -125,6 +125,8 @@ static void free_session(struct nfsd4_session *);
>>>> static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
>>>> static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
>>>> +static struct workqueue_struct *laundry_wq;
>>>> +
>>>> static bool is_session_dead(struct nfsd4_session *ses)
>>>> {
>>>> return ses->se_flags & NFS4_SESSION_DEAD;
>>>> @@ -690,6 +692,14 @@ static unsigned int file_hashval(struct svc_fh *fh)
>>>> static struct hlist_head file_hashtbl[FILE_HASH_SIZE];
>>>> +static inline void
>>>> +run_laundromat(struct nfsd_net *nn, bool wait)
>>>> +{
>>>> + mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
>>>> + if (wait)
>>>> + flush_workqueue(laundry_wq);
>>>> +}
>>> Let's keep those two things separate. The "wait" argument isn't
>>> self-documenting when reading the calling code.
>> we can use enum to spell out the intention.
>>
>>> And the
>>> mod_delayed_work call isn't always needed before flush_workqueue.
>> ok. I'll keep them separate.
>>
>>>> +
>>>> static void
>>>> __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
>>>> {
>>>> @@ -1939,6 +1949,11 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net,
>>>> session = __find_in_sessionid_hashtbl(sessionid, net);
>>>> if (!session)
>>>> goto out;
>>>> + if (!try_to_activate_client(session->se_client)) {
>>>> + /* client is EXPIRABLE */
>>>> + session = NULL;
>>>> + goto out;
>>> No, we definitely don't want to do this. As I said before, an
>>> "expirable client" should be treated in every way exactly like any
>>> regular active client. Literally the only difference is that the
>>> laundromat can try to expire it.
>> Do you mean leave the state as EXPIRABLE but allow the callers
>> to use the client as an ACTIVE client:
> The only place we should even be checking whether a client is EXPIRABLE
> is in the laundromat thread, in the loop over the client_lru. Even
> there, EXPIRABLE being set doesn't mean the client *has* to be expired,
> the real decision is left to mark_client_expired_locked(), as it
> currently is.
>
>> static inline bool try_to_expire_client(struct nfs4_client *clp)
>> {
>> bool ret;
>>
>> spin_lock(&clp->cl_cs_lock);
>> if (clp->cl_state == NFSD4_EXPIRABLE) {
>> spin_unlock(&clp->cl_cs_lock);
>> return false; <<<====== was true
>> }
>> ret = NFSD4_COURTESY ==
>> cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
>> spin_unlock(&clp->cl_cs_lock);
>> return ret;
>> }
> So, try_to_expire_client(), as I said, should be just
>
> static bool try_to_expire_client(struct nfs4_client *clp)
> {
> return COURTESY == cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
> }
>
> Except, OK, I did forget that somebody else could have already set
> EXPIRABLE, and we still want to tell the caller to retry in that case,
> so, oops, let's make it:
>
> return ACTIVE != cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
So functionally this is the same as what i have in the patch, except this
makes it simpler?
Do we need to make any change in try_to_activate_client to work with
this change in try_to_expire_client?
>
> In other words: set EXPIRABLE if and only if the state is COURTESY, and
> then tell the caller to retry the operation if and only if the state was
> previously COURTESY or EXPIRABLE.
>
> But we shouldn't need the cl_cs_lock,
The cl_cs_lock is to synchronize between COURTESY client trying to
reconnect (try_to_activate_client) and another thread is trying to
resolve a delegation/share/lock conflict (try_to_expire_client).
So you don't think this is necessary?
-Dai
> and certainly shouldn't be failing
> lookups of EXPIRABLE clients.
>
>
>
> --b.
>
>
>> -Dai
>>
>>> And then all this code becomes unnecessary:
>>>
>>>> @@ -702,4 +727,42 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);
>>>> extern int nfsd4_client_record_check(struct nfs4_client *clp);
>>>> extern void nfsd4_record_grace_done(struct nfsd_net *nn);
>>>> +static inline bool try_to_expire_client(struct nfs4_client *clp)
>>>> +{
>>>> + bool ret;
>>>> +
>>>> + spin_lock(&clp->cl_cs_lock);
>>>> + if (clp->cl_state == NFSD4_EXPIRABLE) {
>>>> + spin_unlock(&clp->cl_cs_lock);
>>>> + return true;
>>>> + }
>>>> + ret = NFSD4_COURTESY ==
>>>> + cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
>>>> + spin_unlock(&clp->cl_cs_lock);
>>>> + return ret;
>>>> +}
>>>> +
>>>> +static inline bool try_to_activate_client(struct nfs4_client *clp)
>>>> +{
>>>> + bool ret;
>>>> + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
>>>> +
>>>> + /* sync with laundromat */
>>>> + lockdep_assert_held(&nn->client_lock);
>>>> +
>>>> + /* sync with try_to_expire_client */
>>>> + spin_lock(&clp->cl_cs_lock);
>>>> + if (clp->cl_state == NFSD4_ACTIVE) {
>>>> + spin_unlock(&clp->cl_cs_lock);
>>>> + return true;
>>>> + }
>>>> + if (clp->cl_state == NFSD4_EXPIRABLE) {
>>>> + spin_unlock(&clp->cl_cs_lock);
>>>> + return false;
>>>> + }
>>>> + ret = NFSD4_COURTESY ==
>>>> + cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_ACTIVE);
>>>> + spin_unlock(&clp->cl_cs_lock);
>>>> + return ret;
>>>> +}
>>> --b.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-25 21:35 ` dai.ngo
@ 2022-04-25 21:48 ` J. Bruce Fields
2022-04-25 22:24 ` dai.ngo
0 siblings, 1 reply; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 21:48 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Mon, Apr 25, 2022 at 02:35:27PM -0700, dai.ngo@oracle.com wrote:
> On 4/25/22 1:40 PM, J. Bruce Fields wrote:
> >On Mon, Apr 25, 2022 at 12:42:58PM -0700, dai.ngo@oracle.com wrote:
> >>static inline bool try_to_expire_client(struct nfs4_client *clp)
> >>{
> >> bool ret;
> >>
> >> spin_lock(&clp->cl_cs_lock);
> >> if (clp->cl_state == NFSD4_EXPIRABLE) {
> >> spin_unlock(&clp->cl_cs_lock);
> >> return false; <<<====== was true
> >> }
> >> ret = NFSD4_COURTESY ==
> >> cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
> >> spin_unlock(&clp->cl_cs_lock);
> >> return ret;
> >>}
> >So, try_to_expire_client(), as I said, should be just
> >
> > static bool try_to_expire_client(struct nfs4_client *clp)
> > {
> > return COURTESY == cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
> > }
> >
> >Except, OK, I did forget that somebody else could have already set
> >EXPIRABLE, and we still want to tell the caller to retry in that case,
> >so, oops, let's make it:
> >
> > return ACTIVE != cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
>
> So functionally this is the same as what i have in the patch, except this
> makes it simpler?
Right.
And my main complaint is still about the code that fails lookups of
EXPIRABLE clients. We shouldn't need to modify find_in_sessionid_hastbl
or other client lookups.
> Do we need to make any change in try_to_activate_client to work with
> this change in try_to_expire_client?
>
> >
> >In other words: set EXPIRABLE if and only if the state is COURTESY, and
> >then tell the caller to retry the operation if and only if the state was
> >previously COURTESY or EXPIRABLE.
> >
> >But we shouldn't need the cl_cs_lock,
>
> The cl_cs_lock is to synchronize between COURTESY client trying to
> reconnect (try_to_activate_client) and another thread is trying to
> resolve a delegation/share/lock conflict (try_to_expire_client).
> So you don't think this is necessary?
Correct, it's not necessary.
The only synchronization is provided by mark_client_expired_locked and
get_client_locked.
We don't need try_to_activate_client. Just set cl_state to ACTIVE in
get_client_locked.
--b.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-25 21:48 ` J. Bruce Fields
@ 2022-04-25 22:24 ` dai.ngo
2022-04-25 23:17 ` J. Bruce Fields
0 siblings, 1 reply; 25+ messages in thread
From: dai.ngo @ 2022-04-25 22:24 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 4/25/22 2:48 PM, J. Bruce Fields wrote:
> On Mon, Apr 25, 2022 at 02:35:27PM -0700, dai.ngo@oracle.com wrote:
>> On 4/25/22 1:40 PM, J. Bruce Fields wrote:
>>> On Mon, Apr 25, 2022 at 12:42:58PM -0700, dai.ngo@oracle.com wrote:
>>>> static inline bool try_to_expire_client(struct nfs4_client *clp)
>>>> {
>>>> bool ret;
>>>>
>>>> spin_lock(&clp->cl_cs_lock);
>>>> if (clp->cl_state == NFSD4_EXPIRABLE) {
>>>> spin_unlock(&clp->cl_cs_lock);
>>>> return false; <<<====== was true
>>>> }
>>>> ret = NFSD4_COURTESY ==
>>>> cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
>>>> spin_unlock(&clp->cl_cs_lock);
>>>> return ret;
>>>> }
>>> So, try_to_expire_client(), as I said, should be just
>>>
>>> static bool try_to_expire_client(struct nfs4_client *clp)
>>> {
>>> return COURTESY == cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
>>> }
>>>
>>> Except, OK, I did forget that somebody else could have already set
>>> EXPIRABLE, and we still want to tell the caller to retry in that case,
>>> so, oops, let's make it:
>>>
>>> return ACTIVE != cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
>> So functionally this is the same as what i have in the patch, except this
>> makes it simpler?
> Right.
>
> And my main complaint is still about the code that fails lookups of
> EXPIRABLE clients. We shouldn't need to modify find_in_sessionid_hastbl
> or other client lookups.
>
>> Do we need to make any change in try_to_activate_client to work with
>> this change in try_to_expire_client?
>>
>>> In other words: set EXPIRABLE if and only if the state is COURTESY, and
>>> then tell the caller to retry the operation if and only if the state was
>>> previously COURTESY or EXPIRABLE.
>>>
>>> But we shouldn't need the cl_cs_lock,
>> The cl_cs_lock is to synchronize between COURTESY client trying to
>> reconnect (try_to_activate_client) and another thread is trying to
>> resolve a delegation/share/lock conflict (try_to_expire_client).
>> So you don't think this is necessary?
> Correct, it's not necessary.
>
> The only synchronization is provided by mark_client_expired_locked and
> get_client_locked.
>
> We don't need try_to_activate_client. Just set cl_state to ACTIVE in
> get_client_locked.
ok, what you suggested seems to work. I will remove try_to_activate_client
and just set cl_state to ACTIVE and test it to see if there is any problems
that we haven't thought of with this scheme.
-Dai
>
> --b.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation
2022-04-25 22:24 ` dai.ngo
@ 2022-04-25 23:17 ` J. Bruce Fields
0 siblings, 0 replies; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 23:17 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Mon, Apr 25, 2022 at 03:24:49PM -0700, dai.ngo@oracle.com wrote:
>
> On 4/25/22 2:48 PM, J. Bruce Fields wrote:
> >On Mon, Apr 25, 2022 at 02:35:27PM -0700, dai.ngo@oracle.com wrote:
> >>On 4/25/22 1:40 PM, J. Bruce Fields wrote:
> >>>On Mon, Apr 25, 2022 at 12:42:58PM -0700, dai.ngo@oracle.com wrote:
> >>>>static inline bool try_to_expire_client(struct nfs4_client *clp)
> >>>>{
> >>>> bool ret;
> >>>>
> >>>> spin_lock(&clp->cl_cs_lock);
> >>>> if (clp->cl_state == NFSD4_EXPIRABLE) {
> >>>> spin_unlock(&clp->cl_cs_lock);
> >>>> return false; <<<====== was true
> >>>> }
> >>>> ret = NFSD4_COURTESY ==
> >>>> cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
> >>>> spin_unlock(&clp->cl_cs_lock);
> >>>> return ret;
> >>>>}
> >>>So, try_to_expire_client(), as I said, should be just
> >>>
> >>> static bool try_to_expire_client(struct nfs4_client *clp)
> >>> {
> >>> return COURTESY == cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
> >>> }
> >>>
> >>>Except, OK, I did forget that somebody else could have already set
> >>>EXPIRABLE, and we still want to tell the caller to retry in that case,
> >>>so, oops, let's make it:
> >>>
> >>> return ACTIVE != cmpxchg(clp->cl_state, COURTESY, EXPIRABLE);
> >>So functionally this is the same as what i have in the patch, except this
> >>makes it simpler?
> >Right.
> >
> >And my main complaint is still about the code that fails lookups of
> >EXPIRABLE clients. We shouldn't need to modify find_in_sessionid_hastbl
> >or other client lookups.
> >
> >>Do we need to make any change in try_to_activate_client to work with
> >>this change in try_to_expire_client?
> >>
> >>>In other words: set EXPIRABLE if and only if the state is COURTESY, and
> >>>then tell the caller to retry the operation if and only if the state was
> >>>previously COURTESY or EXPIRABLE.
> >>>
> >>>But we shouldn't need the cl_cs_lock,
> >>The cl_cs_lock is to synchronize between COURTESY client trying to
> >>reconnect (try_to_activate_client) and another thread is trying to
> >>resolve a delegation/share/lock conflict (try_to_expire_client).
> >>So you don't think this is necessary?
> >Correct, it's not necessary.
> >
> >The only synchronization is provided by mark_client_expired_locked and
> >get_client_locked.
> >
> >We don't need try_to_activate_client. Just set cl_state to ACTIVE in
> >get_client_locked.
>
> ok, what you suggested seems to work. I will remove try_to_activate_client
> and just set cl_state to ACTIVE and test it to see if there is any problems
> that we haven't thought of with this scheme.
Thanks!
--b.
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-04-23 18:44 ` [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation Dai Ngo
@ 2022-04-23 18:44 ` Dai Ngo
2022-04-24 12:18 ` kernel test robot
2022-04-25 13:15 ` Chuck Lever III
2022-04-23 18:44 ` [PATCH RFC v21 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd Dai Ngo
` (5 subsequent siblings)
7 siblings, 2 replies; 25+ messages in thread
From: Dai Ngo @ 2022-04-23 18:44 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
This patch allows expired client with open state to be in COURTESY
state. Share/access conflict with COURTESY client is resolved by
setting COURTESY client to EXPIRABLE state, schedule laundromat
to run and returning nfserr_jukebox to the request client.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 105 insertions(+), 6 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index fea5e24e7d94..b08c132648b9 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -700,6 +700,57 @@ run_laundromat(struct nfsd_net *nn, bool wait)
flush_workqueue(laundry_wq);
}
+/*
+ * Check if courtesy clients have conflicting access and resolve it if possible
+ *
+ * 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:
+ * false - access/deny mode conflict with normal client.
+ * true - 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;
+ bool conflict = true;
+ unsigned char bmap;
+ struct nfsd_net *nn;
+ struct nfs4_client *clp;
+
+ lockdep_assert_held(&fp->fi_lock);
+ list_for_each_entry(st, &fp->fi_stateids, st_perfile) {
+ /* ignore lock stateid */
+ if (st->st_openstp)
+ continue;
+ if (st == stp && new_stp)
+ continue;
+ /* check file access against deny mode or vice versa */
+ bmap = share_access ? st->st_deny_bmap : st->st_access_bmap;
+ if (!(access & bmap_to_share_mode(bmap)))
+ continue;
+ clp = st->st_stid.sc_client;
+ if (try_to_expire_client(clp))
+ continue;
+ conflict = false;
+ break;
+ }
+ if (conflict) {
+ clp = stp->st_stid.sc_client;
+ nn = net_generic(clp->net, nfsd_net_id);
+ run_laundromat(nn, false);
+ }
+ return conflict;
+}
+
static void
__nfs4_file_get_access(struct nfs4_file *fp, u32 access)
{
@@ -4995,13 +5046,14 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,
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;
int oflag = nfs4_access_to_omode(open->op_share_access);
int access = nfs4_access_to_access(open->op_share_access);
unsigned char old_access_bmap, old_deny_bmap;
+ struct nfs4_client *clp;
spin_lock(&fp->fi_lock);
@@ -5011,6 +5063,14 @@ 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) {
+ if (status != nfserr_share_denied) {
+ spin_unlock(&fp->fi_lock);
+ goto out;
+ }
+ clp = stp->st_stid.sc_client;
+ if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
+ stp, open->op_share_deny, false))
+ status = nfserr_jukebox;
spin_unlock(&fp->fi_lock);
goto out;
}
@@ -5018,6 +5078,14 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
/* set access to the file */
status = nfs4_file_get_access(fp, open->op_share_access);
if (status != nfs_ok) {
+ if (status != nfserr_share_denied) {
+ spin_unlock(&fp->fi_lock);
+ goto out;
+ }
+ clp = stp->st_stid.sc_client;
+ if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
+ stp, open->op_share_access, true))
+ status = nfserr_jukebox;
spin_unlock(&fp->fi_lock);
goto out;
}
@@ -5064,21 +5132,29 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
}
static __be32
-nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp, struct nfsd4_open *open)
+nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,
+ struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp,
+ struct nfsd4_open *open)
{
__be32 status;
unsigned 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);
status = nfs4_file_check_deny(fp, open->op_share_deny);
if (status == nfs_ok) {
- set_deny(open->op_share_deny, stp);
- fp->fi_share_deny |=
+ if (status != nfserr_share_denied) {
+ set_deny(open->op_share_deny, stp);
+ fp->fi_share_deny |=
(open->op_share_deny & NFS4_SHARE_DENY_BOTH);
+ } else {
+ if (nfs4_resolve_deny_conflicts_locked(fp, false,
+ stp, open->op_share_deny, false))
+ status = nfserr_jukebox;
+ }
}
spin_unlock(&fp->fi_lock);
@@ -5419,7 +5495,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);
@@ -5653,12 +5729,35 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
}
#endif
+static bool
+nfs4_has_any_locks(struct nfs4_client *clp)
+{
+ int i;
+ struct nfs4_stateowner *so;
+
+ 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;
+ 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
--
2.9.5
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server
2022-04-23 18:44 ` [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server Dai Ngo
@ 2022-04-24 12:18 ` kernel test robot
2022-04-25 13:15 ` Chuck Lever III
1 sibling, 0 replies; 25+ messages in thread
From: kernel test robot @ 2022-04-24 12:18 UTC (permalink / raw)
To: Dai Ngo; +Cc: llvm, kbuild-all
Hi Dai,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on v5.18-rc3 next-20220422]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Dai-Ngo/NFSD-Initial-implementation-of-NFSv4-Courteous-Server/20220424-024653
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 45ab9400e73f34103e73c18a73280c9aa1650e98
config: s390-randconfig-c005-20220424 (https://download.01.org/0day-ci/archive/20220424/202204242040.x20oF5fR-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 1cddcfdc3c683b393df1a5c9063252eb60e52818)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/1d73d8e1a14e5e742fe00605d515a338af7af59b
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Dai-Ngo/NFSD-Initial-implementation-of-NFSv4-Courteous-Server/20220424-024653
git checkout 1d73d8e1a14e5e742fe00605d515a338af7af59b
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash fs/nfsd/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from fs/nfsd/nfs4state.c:42:
In file included from include/linux/sunrpc/svcauth_gss.h:14:
In file included from include/linux/sunrpc/xdr.h:17:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
^
include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
^
In file included from fs/nfsd/nfs4state.c:42:
In file included from include/linux/sunrpc/svcauth_gss.h:14:
In file included from include/linux/sunrpc/xdr.h:17:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
^
In file included from fs/nfsd/nfs4state.c:42:
In file included from include/linux/sunrpc/svcauth_gss.h:14:
In file included from include/linux/sunrpc/xdr.h:17:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
In file included from fs/nfsd/nfs4state.c:42:
In file included from include/linux/sunrpc/svcauth_gss.h:14:
include/linux/sunrpc/xdr.h:734:10: warning: result of comparison of constant 4611686018427387903 with expression of type '__u32' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
if (len > SIZE_MAX / sizeof(*p))
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
~~~~~~~~~~~~~~~~~^~~~~
include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value'
(cond) ? \
^~~~
In file included from fs/nfsd/nfs4state.c:42:
In file included from include/linux/sunrpc/svcauth_gss.h:14:
include/linux/sunrpc/xdr.h:734:10: warning: result of comparison of constant 4611686018427387903 with expression of type '__u32' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
if (len > SIZE_MAX / sizeof(*p))
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
In file included from fs/nfsd/nfs4state.c:42:
In file included from include/linux/sunrpc/svcauth_gss.h:14:
include/linux/sunrpc/xdr.h:734:10: warning: result of comparison of constant 4611686018427387903 with expression of type '__u32' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
if (len > SIZE_MAX / sizeof(*p))
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:58:61: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> fs/nfsd/nfs4state.c:5056:22: warning: variable 'clp' set but not used [-Wunused-but-set-variable]
struct nfs4_client *clp;
^
16 warnings generated.
vim +/clp +5056 fs/nfsd/nfs4state.c
5046
5047 static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
5048 struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp,
5049 struct nfsd4_open *open, bool new_stp)
5050 {
5051 struct nfsd_file *nf = NULL;
5052 __be32 status;
5053 int oflag = nfs4_access_to_omode(open->op_share_access);
5054 int access = nfs4_access_to_access(open->op_share_access);
5055 unsigned char old_access_bmap, old_deny_bmap;
> 5056 struct nfs4_client *clp;
5057
5058 spin_lock(&fp->fi_lock);
5059
5060 /*
5061 * Are we trying to set a deny mode that would conflict with
5062 * current access?
5063 */
5064 status = nfs4_file_check_deny(fp, open->op_share_deny);
5065 if (status != nfs_ok) {
5066 if (status != nfserr_share_denied) {
5067 spin_unlock(&fp->fi_lock);
5068 goto out;
5069 }
5070 clp = stp->st_stid.sc_client;
5071 if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
5072 stp, open->op_share_deny, false))
5073 status = nfserr_jukebox;
5074 spin_unlock(&fp->fi_lock);
5075 goto out;
5076 }
5077
5078 /* set access to the file */
5079 status = nfs4_file_get_access(fp, open->op_share_access);
5080 if (status != nfs_ok) {
5081 if (status != nfserr_share_denied) {
5082 spin_unlock(&fp->fi_lock);
5083 goto out;
5084 }
5085 clp = stp->st_stid.sc_client;
5086 if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
5087 stp, open->op_share_access, true))
5088 status = nfserr_jukebox;
5089 spin_unlock(&fp->fi_lock);
5090 goto out;
5091 }
5092
5093 /* Set access bits in stateid */
5094 old_access_bmap = stp->st_access_bmap;
5095 set_access(open->op_share_access, stp);
5096
5097 /* Set new deny mask */
5098 old_deny_bmap = stp->st_deny_bmap;
5099 set_deny(open->op_share_deny, stp);
5100 fp->fi_share_deny |= (open->op_share_deny & NFS4_SHARE_DENY_BOTH);
5101
5102 if (!fp->fi_fds[oflag]) {
5103 spin_unlock(&fp->fi_lock);
5104 status = nfsd_file_acquire(rqstp, cur_fh, access, &nf);
5105 if (status)
5106 goto out_put_access;
5107 spin_lock(&fp->fi_lock);
5108 if (!fp->fi_fds[oflag]) {
5109 fp->fi_fds[oflag] = nf;
5110 nf = NULL;
5111 }
5112 }
5113 spin_unlock(&fp->fi_lock);
5114 if (nf)
5115 nfsd_file_put(nf);
5116
5117 status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode,
5118 access));
5119 if (status)
5120 goto out_put_access;
5121
5122 status = nfsd4_truncate(rqstp, cur_fh, open);
5123 if (status)
5124 goto out_put_access;
5125 out:
5126 return status;
5127 out_put_access:
5128 stp->st_access_bmap = old_access_bmap;
5129 nfs4_file_put_access(fp, open->op_share_access);
5130 reset_union_bmap_deny(bmap_to_share_mode(old_deny_bmap), stp);
5131 goto out;
5132 }
5133
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server
2022-04-23 18:44 ` [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server Dai Ngo
2022-04-24 12:18 ` kernel test robot
@ 2022-04-25 13:15 ` Chuck Lever III
2022-04-25 15:08 ` dai.ngo
1 sibling, 1 reply; 25+ messages in thread
From: Chuck Lever III @ 2022-04-25 13:15 UTC (permalink / raw)
To: Dai Ngo
Cc: Bruce Fields, Jeff Layton, Al Viro, Linux NFS Mailing List,
linux-fsdevel
> On Apr 23, 2022, at 2:44 PM, Dai Ngo <dai.ngo@oracle.com> wrote:
>
> This patch allows expired client with open state to be in COURTESY
> state. Share/access conflict with COURTESY client is resolved by
> setting COURTESY client to EXPIRABLE state, schedule laundromat
> to run and returning nfserr_jukebox to the request client.
>
> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> ---
> fs/nfsd/nfs4state.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 105 insertions(+), 6 deletions(-)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index fea5e24e7d94..b08c132648b9 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -700,6 +700,57 @@ run_laundromat(struct nfsd_net *nn, bool wait)
> flush_workqueue(laundry_wq);
> }
>
> +/*
> + * Check if courtesy clients have conflicting access and resolve it if possible
> + *
> + * 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:
> + * false - access/deny mode conflict with normal client.
> + * true - 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;
> + bool conflict = true;
> + unsigned char bmap;
> + struct nfsd_net *nn;
> + struct nfs4_client *clp;
> +
> + lockdep_assert_held(&fp->fi_lock);
> + list_for_each_entry(st, &fp->fi_stateids, st_perfile) {
> + /* ignore lock stateid */
> + if (st->st_openstp)
> + continue;
> + if (st == stp && new_stp)
> + continue;
> + /* check file access against deny mode or vice versa */
> + bmap = share_access ? st->st_deny_bmap : st->st_access_bmap;
> + if (!(access & bmap_to_share_mode(bmap)))
> + continue;
> + clp = st->st_stid.sc_client;
> + if (try_to_expire_client(clp))
> + continue;
> + conflict = false;
> + break;
> + }
> + if (conflict) {
> + clp = stp->st_stid.sc_client;
> + nn = net_generic(clp->net, nfsd_net_id);
> + run_laundromat(nn, false);
> + }
> + return conflict;
> +}
> +
> static void
> __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
> {
> @@ -4995,13 +5046,14 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,
>
> 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;
> int oflag = nfs4_access_to_omode(open->op_share_access);
> int access = nfs4_access_to_access(open->op_share_access);
> unsigned char old_access_bmap, old_deny_bmap;
> + struct nfs4_client *clp;
>
> spin_lock(&fp->fi_lock);
>
> @@ -5011,6 +5063,14 @@ 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) {
> + if (status != nfserr_share_denied) {
> + spin_unlock(&fp->fi_lock);
> + goto out;
> + }
> + clp = stp->st_stid.sc_client;
@clp is set here, but the value is never used in this function,
even in later patches. Possibly left over from the previous
revision of this series?
> + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
> + stp, open->op_share_deny, false))
> + status = nfserr_jukebox;
> spin_unlock(&fp->fi_lock);
> goto out;
> }
> @@ -5018,6 +5078,14 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
> /* set access to the file */
> status = nfs4_file_get_access(fp, open->op_share_access);
> if (status != nfs_ok) {
> + if (status != nfserr_share_denied) {
> + spin_unlock(&fp->fi_lock);
> + goto out;
> + }
> + clp = stp->st_stid.sc_client;
Ditto.
> + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
> + stp, open->op_share_access, true))
> + status = nfserr_jukebox;
> spin_unlock(&fp->fi_lock);
> goto out;
> }
> @@ -5064,21 +5132,29 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
> }
>
> static __be32
> -nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp, struct nfsd4_open *open)
> +nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,
> + struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp,
> + struct nfsd4_open *open)
> {
> __be32 status;
> unsigned 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);
> status = nfs4_file_check_deny(fp, open->op_share_deny);
> if (status == nfs_ok) {
> - set_deny(open->op_share_deny, stp);
> - fp->fi_share_deny |=
> + if (status != nfserr_share_denied) {
> + set_deny(open->op_share_deny, stp);
> + fp->fi_share_deny |=
> (open->op_share_deny & NFS4_SHARE_DENY_BOTH);
> + } else {
> + if (nfs4_resolve_deny_conflicts_locked(fp, false,
> + stp, open->op_share_deny, false))
> + status = nfserr_jukebox;
> + }
> }
> spin_unlock(&fp->fi_lock);
>
> @@ -5419,7 +5495,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);
> @@ -5653,12 +5729,35 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
> }
> #endif
>
> +static bool
> +nfs4_has_any_locks(struct nfs4_client *clp)
> +{
> + int i;
> + struct nfs4_stateowner *so;
> +
> + 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;
> + 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
> --
> 2.9.5
>
--
Chuck Lever
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server
2022-04-25 13:15 ` Chuck Lever III
@ 2022-04-25 15:08 ` dai.ngo
0 siblings, 0 replies; 25+ messages in thread
From: dai.ngo @ 2022-04-25 15:08 UTC (permalink / raw)
To: Chuck Lever III
Cc: Bruce Fields, Jeff Layton, Al Viro, Linux NFS Mailing List,
linux-fsdevel
On 4/25/22 6:15 AM, Chuck Lever III wrote:
>
>> On Apr 23, 2022, at 2:44 PM, Dai Ngo <dai.ngo@oracle.com> wrote:
>>
>> This patch allows expired client with open state to be in COURTESY
>> state. Share/access conflict with COURTESY client is resolved by
>> setting COURTESY client to EXPIRABLE state, schedule laundromat
>> to run and returning nfserr_jukebox to the request client.
>>
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>> fs/nfsd/nfs4state.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++---
>> 1 file changed, 105 insertions(+), 6 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index fea5e24e7d94..b08c132648b9 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -700,6 +700,57 @@ run_laundromat(struct nfsd_net *nn, bool wait)
>> flush_workqueue(laundry_wq);
>> }
>>
>> +/*
>> + * Check if courtesy clients have conflicting access and resolve it if possible
>> + *
>> + * 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:
>> + * false - access/deny mode conflict with normal client.
>> + * true - 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;
>> + bool conflict = true;
>> + unsigned char bmap;
>> + struct nfsd_net *nn;
>> + struct nfs4_client *clp;
>> +
>> + lockdep_assert_held(&fp->fi_lock);
>> + list_for_each_entry(st, &fp->fi_stateids, st_perfile) {
>> + /* ignore lock stateid */
>> + if (st->st_openstp)
>> + continue;
>> + if (st == stp && new_stp)
>> + continue;
>> + /* check file access against deny mode or vice versa */
>> + bmap = share_access ? st->st_deny_bmap : st->st_access_bmap;
>> + if (!(access & bmap_to_share_mode(bmap)))
>> + continue;
>> + clp = st->st_stid.sc_client;
>> + if (try_to_expire_client(clp))
>> + continue;
>> + conflict = false;
>> + break;
>> + }
>> + if (conflict) {
>> + clp = stp->st_stid.sc_client;
>> + nn = net_generic(clp->net, nfsd_net_id);
>> + run_laundromat(nn, false);
>> + }
>> + return conflict;
>> +}
>> +
>> static void
>> __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
>> {
>> @@ -4995,13 +5046,14 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,
>>
>> 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;
>> int oflag = nfs4_access_to_omode(open->op_share_access);
>> int access = nfs4_access_to_access(open->op_share_access);
>> unsigned char old_access_bmap, old_deny_bmap;
>> + struct nfs4_client *clp;
>>
>> spin_lock(&fp->fi_lock);
>>
>> @@ -5011,6 +5063,14 @@ 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) {
>> + if (status != nfserr_share_denied) {
>> + spin_unlock(&fp->fi_lock);
>> + goto out;
>> + }
>> + clp = stp->st_stid.sc_client;
> @clp is set here, but the value is never used in this function,
> even in later patches. Possibly left over from the previous
> revision of this series?
Thanks Chuck, will fix in v22.
Kernel test robot also reported the problem.
-Dai
>
>
>> + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
>> + stp, open->op_share_deny, false))
>> + status = nfserr_jukebox;
>> spin_unlock(&fp->fi_lock);
>> goto out;
>> }
>> @@ -5018,6 +5078,14 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
>> /* set access to the file */
>> status = nfs4_file_get_access(fp, open->op_share_access);
>> if (status != nfs_ok) {
>> + if (status != nfserr_share_denied) {
>> + spin_unlock(&fp->fi_lock);
>> + goto out;
>> + }
>> + clp = stp->st_stid.sc_client;
> Ditto.
>
>
>> + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
>> + stp, open->op_share_access, true))
>> + status = nfserr_jukebox;
>> spin_unlock(&fp->fi_lock);
>> goto out;
>> }
>> @@ -5064,21 +5132,29 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
>> }
>>
>> static __be32
>> -nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp, struct nfsd4_open *open)
>> +nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,
>> + struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp,
>> + struct nfsd4_open *open)
>> {
>> __be32 status;
>> unsigned 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);
>> status = nfs4_file_check_deny(fp, open->op_share_deny);
>> if (status == nfs_ok) {
>> - set_deny(open->op_share_deny, stp);
>> - fp->fi_share_deny |=
>> + if (status != nfserr_share_denied) {
>> + set_deny(open->op_share_deny, stp);
>> + fp->fi_share_deny |=
>> (open->op_share_deny & NFS4_SHARE_DENY_BOTH);
>> + } else {
>> + if (nfs4_resolve_deny_conflicts_locked(fp, false,
>> + stp, open->op_share_deny, false))
>> + status = nfserr_jukebox;
>> + }
>> }
>> spin_unlock(&fp->fi_lock);
>>
>> @@ -5419,7 +5495,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);
>> @@ -5653,12 +5729,35 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
>> }
>> #endif
>>
>> +static bool
>> +nfs4_has_any_locks(struct nfs4_client *clp)
>> +{
>> + int i;
>> + struct nfs4_stateowner *so;
>> +
>> + 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;
>> + 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
>> --
>> 2.9.5
>>
> --
> Chuck Lever
>
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH RFC v21 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-04-23 18:44 ` [PATCH RFC v21 1/7] NFSD: add courteous server support for thread with only delegation Dai Ngo
2022-04-23 18:44 ` [PATCH RFC v21 2/7] NFSD: add support for share reservation conflict to courteous server Dai Ngo
@ 2022-04-23 18:44 ` Dai Ngo
2022-04-25 15:27 ` dai.ngo
2022-04-23 18:44 ` [PATCH RFC v21 4/7] fs/lock: add helper locks_owner_has_blockers to check for blockers Dai Ngo
` (4 subsequent siblings)
7 siblings, 1 reply; 25+ messages in thread
From: Dai Ngo @ 2022-04-23 18:44 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
This patch moves create/destroy of laundry_wq from nfs4_state_start
and nfs4_state_shutdown_net to init_nfsd and exit_nfsd to prevent
the laundromat from being freed while a thread is processing a
conflicting lock.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 15 ++-------------
fs/nfsd/nfsctl.c | 6 ++++++
fs/nfsd/nfsd.h | 1 +
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index b08c132648b9..b70ba2eb5665 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -125,7 +125,7 @@ static void free_session(struct nfsd4_session *);
static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
-static struct workqueue_struct *laundry_wq;
+struct workqueue_struct *laundry_wq;
static bool is_session_dead(struct nfsd4_session *ses)
{
@@ -7798,22 +7798,12 @@ nfs4_state_start(void)
{
int ret;
- laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
- if (laundry_wq == NULL) {
- ret = -ENOMEM;
- goto out;
- }
ret = nfsd4_create_callback_queue();
if (ret)
- goto out_free_laundry;
+ return ret;
set_max_delegations();
return 0;
-
-out_free_laundry:
- destroy_workqueue(laundry_wq);
-out:
- return ret;
}
void
@@ -7850,7 +7840,6 @@ nfs4_state_shutdown_net(struct net *net)
void
nfs4_state_shutdown(void)
{
- destroy_workqueue(laundry_wq);
nfsd4_destroy_callback_queue();
}
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 16920e4512bd..884e873b46ad 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -1544,6 +1544,11 @@ static int __init init_nfsd(void)
retval = register_cld_notifier();
if (retval)
goto out_free_all;
+ laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
+ if (laundry_wq == NULL) {
+ retval = -ENOMEM;
+ goto out_free_all;
+ }
return 0;
out_free_all:
unregister_pernet_subsys(&nfsd_net_ops);
@@ -1566,6 +1571,7 @@ static int __init init_nfsd(void)
static void __exit exit_nfsd(void)
{
+ destroy_workqueue(laundry_wq);
unregister_cld_notifier();
unregister_pernet_subsys(&nfsd_net_ops);
nfsd_drc_slab_free();
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 23996c6ca75e..d41dcf1c4312 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -72,6 +72,7 @@ extern unsigned long nfsd_drc_max_mem;
extern unsigned long nfsd_drc_mem_used;
extern const struct seq_operations nfs_exports_op;
+extern struct workqueue_struct *laundry_wq;
/*
* Common void argument and result helpers
--
2.9.5
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd
2022-04-23 18:44 ` [PATCH RFC v21 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd Dai Ngo
@ 2022-04-25 15:27 ` dai.ngo
2022-04-25 19:35 ` J. Bruce Fields
0 siblings, 1 reply; 25+ messages in thread
From: dai.ngo @ 2022-04-25 15:27 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
This patch has problem to build with this error:
>> nfsctl.c:(.exit.text+0x0): undefined reference to `laundry_wq'
>> mipsel-linux-ld: nfsctl.c:(.exit.text+0x4): undefined reference to `laundry_wq'
This happens when CONFIG_NFSD is defined but CONFIG_NFSD_V4
is not. I think to fix this we need to also move the declaration
of laundry_wq from nfs4state.c to nfsctl.c. However this seems
odd since the laundry_wq is only used for v4, unless you have
any other suggestion.
-Dai
On 4/23/22 11:44 AM, Dai Ngo wrote:
> This patch moves create/destroy of laundry_wq from nfs4_state_start
> and nfs4_state_shutdown_net to init_nfsd and exit_nfsd to prevent
> the laundromat from being freed while a thread is processing a
> conflicting lock.
>
> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> ---
> fs/nfsd/nfs4state.c | 15 ++-------------
> fs/nfsd/nfsctl.c | 6 ++++++
> fs/nfsd/nfsd.h | 1 +
> 3 files changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index b08c132648b9..b70ba2eb5665 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -125,7 +125,7 @@ static void free_session(struct nfsd4_session *);
> static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
> static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
>
> -static struct workqueue_struct *laundry_wq;
> +struct workqueue_struct *laundry_wq;
>
> static bool is_session_dead(struct nfsd4_session *ses)
> {
> @@ -7798,22 +7798,12 @@ nfs4_state_start(void)
> {
> int ret;
>
> - laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
> - if (laundry_wq == NULL) {
> - ret = -ENOMEM;
> - goto out;
> - }
> ret = nfsd4_create_callback_queue();
> if (ret)
> - goto out_free_laundry;
> + return ret;
>
> set_max_delegations();
> return 0;
> -
> -out_free_laundry:
> - destroy_workqueue(laundry_wq);
> -out:
> - return ret;
> }
>
> void
> @@ -7850,7 +7840,6 @@ nfs4_state_shutdown_net(struct net *net)
> void
> nfs4_state_shutdown(void)
> {
> - destroy_workqueue(laundry_wq);
> nfsd4_destroy_callback_queue();
> }
>
> diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
> index 16920e4512bd..884e873b46ad 100644
> --- a/fs/nfsd/nfsctl.c
> +++ b/fs/nfsd/nfsctl.c
> @@ -1544,6 +1544,11 @@ static int __init init_nfsd(void)
> retval = register_cld_notifier();
> if (retval)
> goto out_free_all;
> + laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
> + if (laundry_wq == NULL) {
> + retval = -ENOMEM;
> + goto out_free_all;
> + }
> return 0;
> out_free_all:
> unregister_pernet_subsys(&nfsd_net_ops);
> @@ -1566,6 +1571,7 @@ static int __init init_nfsd(void)
>
> static void __exit exit_nfsd(void)
> {
> + destroy_workqueue(laundry_wq);
> unregister_cld_notifier();
> unregister_pernet_subsys(&nfsd_net_ops);
> nfsd_drc_slab_free();
> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> index 23996c6ca75e..d41dcf1c4312 100644
> --- a/fs/nfsd/nfsd.h
> +++ b/fs/nfsd/nfsd.h
> @@ -72,6 +72,7 @@ extern unsigned long nfsd_drc_max_mem;
> extern unsigned long nfsd_drc_mem_used;
>
> extern const struct seq_operations nfs_exports_op;
> +extern struct workqueue_struct *laundry_wq;
>
> /*
> * Common void argument and result helpers
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd
2022-04-25 15:27 ` dai.ngo
@ 2022-04-25 19:35 ` J. Bruce Fields
2022-04-25 19:46 ` dai.ngo
0 siblings, 1 reply; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 19:35 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Mon, Apr 25, 2022 at 08:27:22AM -0700, dai.ngo@oracle.com wrote:
> This patch has problem to build with this error:
>
> >>nfsctl.c:(.exit.text+0x0): undefined reference to `laundry_wq'
> >>mipsel-linux-ld: nfsctl.c:(.exit.text+0x4): undefined reference to `laundry_wq'
>
> This happens when CONFIG_NFSD is defined but CONFIG_NFSD_V4
> is not. I think to fix this we need to also move the declaration
> of laundry_wq from nfs4state.c to nfsctl.c. However this seems
> odd since the laundry_wq is only used for v4, unless you have
> any other suggestion.
I'd just leave laundry_wq private to nfs4state.c. Define
create_laundromat() and destroy_laundromat() in nfs4state.c too. And in
nfsd.h, do the usual trick of defining no-op versions of those functions
in the non-v4 case. (See e.g. what we do with nfsd4_init/free_slabs().)
--b.
>
> -Dai
>
> On 4/23/22 11:44 AM, Dai Ngo wrote:
> >This patch moves create/destroy of laundry_wq from nfs4_state_start
> >and nfs4_state_shutdown_net to init_nfsd and exit_nfsd to prevent
> >the laundromat from being freed while a thread is processing a
> >conflicting lock.
> >
> >Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> >---
> > fs/nfsd/nfs4state.c | 15 ++-------------
> > fs/nfsd/nfsctl.c | 6 ++++++
> > fs/nfsd/nfsd.h | 1 +
> > 3 files changed, 9 insertions(+), 13 deletions(-)
> >
> >diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >index b08c132648b9..b70ba2eb5665 100644
> >--- a/fs/nfsd/nfs4state.c
> >+++ b/fs/nfsd/nfs4state.c
> >@@ -125,7 +125,7 @@ static void free_session(struct nfsd4_session *);
> > static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
> > static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
> >-static struct workqueue_struct *laundry_wq;
> >+struct workqueue_struct *laundry_wq;
> > static bool is_session_dead(struct nfsd4_session *ses)
> > {
> >@@ -7798,22 +7798,12 @@ nfs4_state_start(void)
> > {
> > int ret;
> >- laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
> >- if (laundry_wq == NULL) {
> >- ret = -ENOMEM;
> >- goto out;
> >- }
> > ret = nfsd4_create_callback_queue();
> > if (ret)
> >- goto out_free_laundry;
> >+ return ret;
> > set_max_delegations();
> > return 0;
> >-
> >-out_free_laundry:
> >- destroy_workqueue(laundry_wq);
> >-out:
> >- return ret;
> > }
> > void
> >@@ -7850,7 +7840,6 @@ nfs4_state_shutdown_net(struct net *net)
> > void
> > nfs4_state_shutdown(void)
> > {
> >- destroy_workqueue(laundry_wq);
> > nfsd4_destroy_callback_queue();
> > }
> >diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
> >index 16920e4512bd..884e873b46ad 100644
> >--- a/fs/nfsd/nfsctl.c
> >+++ b/fs/nfsd/nfsctl.c
> >@@ -1544,6 +1544,11 @@ static int __init init_nfsd(void)
> > retval = register_cld_notifier();
> > if (retval)
> > goto out_free_all;
> >+ laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
> >+ if (laundry_wq == NULL) {
> >+ retval = -ENOMEM;
> >+ goto out_free_all;
> >+ }
> > return 0;
> > out_free_all:
> > unregister_pernet_subsys(&nfsd_net_ops);
> >@@ -1566,6 +1571,7 @@ static int __init init_nfsd(void)
> > static void __exit exit_nfsd(void)
> > {
> >+ destroy_workqueue(laundry_wq);
> > unregister_cld_notifier();
> > unregister_pernet_subsys(&nfsd_net_ops);
> > nfsd_drc_slab_free();
> >diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> >index 23996c6ca75e..d41dcf1c4312 100644
> >--- a/fs/nfsd/nfsd.h
> >+++ b/fs/nfsd/nfsd.h
> >@@ -72,6 +72,7 @@ extern unsigned long nfsd_drc_max_mem;
> > extern unsigned long nfsd_drc_mem_used;
> > extern const struct seq_operations nfs_exports_op;
> >+extern struct workqueue_struct *laundry_wq;
> > /*
> > * Common void argument and result helpers
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd
2022-04-25 19:35 ` J. Bruce Fields
@ 2022-04-25 19:46 ` dai.ngo
0 siblings, 0 replies; 25+ messages in thread
From: dai.ngo @ 2022-04-25 19:46 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 4/25/22 12:35 PM, J. Bruce Fields wrote:
> On Mon, Apr 25, 2022 at 08:27:22AM -0700, dai.ngo@oracle.com wrote:
>> This patch has problem to build with this error:
>>
>>>> nfsctl.c:(.exit.text+0x0): undefined reference to `laundry_wq'
>>>> mipsel-linux-ld: nfsctl.c:(.exit.text+0x4): undefined reference to `laundry_wq'
>> This happens when CONFIG_NFSD is defined but CONFIG_NFSD_V4
>> is not. I think to fix this we need to also move the declaration
>> of laundry_wq from nfs4state.c to nfsctl.c. However this seems
>> odd since the laundry_wq is only used for v4, unless you have
>> any other suggestion.
> I'd just leave laundry_wq private to nfs4state.c. Define
> create_laundromat() and destroy_laundromat() in nfs4state.c too. And in
> nfsd.h, do the usual trick of defining no-op versions of those functions
> in the non-v4 case. (See e.g. what we do with nfsd4_init/free_slabs().)
ok, thanks.
-Dai
>
> --b.
>
>> -Dai
>>
>> On 4/23/22 11:44 AM, Dai Ngo wrote:
>>> This patch moves create/destroy of laundry_wq from nfs4_state_start
>>> and nfs4_state_shutdown_net to init_nfsd and exit_nfsd to prevent
>>> the laundromat from being freed while a thread is processing a
>>> conflicting lock.
>>>
>>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>>> ---
>>> fs/nfsd/nfs4state.c | 15 ++-------------
>>> fs/nfsd/nfsctl.c | 6 ++++++
>>> fs/nfsd/nfsd.h | 1 +
>>> 3 files changed, 9 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>> index b08c132648b9..b70ba2eb5665 100644
>>> --- a/fs/nfsd/nfs4state.c
>>> +++ b/fs/nfsd/nfs4state.c
>>> @@ -125,7 +125,7 @@ static void free_session(struct nfsd4_session *);
>>> static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
>>> static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
>>> -static struct workqueue_struct *laundry_wq;
>>> +struct workqueue_struct *laundry_wq;
>>> static bool is_session_dead(struct nfsd4_session *ses)
>>> {
>>> @@ -7798,22 +7798,12 @@ nfs4_state_start(void)
>>> {
>>> int ret;
>>> - laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
>>> - if (laundry_wq == NULL) {
>>> - ret = -ENOMEM;
>>> - goto out;
>>> - }
>>> ret = nfsd4_create_callback_queue();
>>> if (ret)
>>> - goto out_free_laundry;
>>> + return ret;
>>> set_max_delegations();
>>> return 0;
>>> -
>>> -out_free_laundry:
>>> - destroy_workqueue(laundry_wq);
>>> -out:
>>> - return ret;
>>> }
>>> void
>>> @@ -7850,7 +7840,6 @@ nfs4_state_shutdown_net(struct net *net)
>>> void
>>> nfs4_state_shutdown(void)
>>> {
>>> - destroy_workqueue(laundry_wq);
>>> nfsd4_destroy_callback_queue();
>>> }
>>> diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
>>> index 16920e4512bd..884e873b46ad 100644
>>> --- a/fs/nfsd/nfsctl.c
>>> +++ b/fs/nfsd/nfsctl.c
>>> @@ -1544,6 +1544,11 @@ static int __init init_nfsd(void)
>>> retval = register_cld_notifier();
>>> if (retval)
>>> goto out_free_all;
>>> + laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
>>> + if (laundry_wq == NULL) {
>>> + retval = -ENOMEM;
>>> + goto out_free_all;
>>> + }
>>> return 0;
>>> out_free_all:
>>> unregister_pernet_subsys(&nfsd_net_ops);
>>> @@ -1566,6 +1571,7 @@ static int __init init_nfsd(void)
>>> static void __exit exit_nfsd(void)
>>> {
>>> + destroy_workqueue(laundry_wq);
>>> unregister_cld_notifier();
>>> unregister_pernet_subsys(&nfsd_net_ops);
>>> nfsd_drc_slab_free();
>>> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
>>> index 23996c6ca75e..d41dcf1c4312 100644
>>> --- a/fs/nfsd/nfsd.h
>>> +++ b/fs/nfsd/nfsd.h
>>> @@ -72,6 +72,7 @@ extern unsigned long nfsd_drc_max_mem;
>>> extern unsigned long nfsd_drc_mem_used;
>>> extern const struct seq_operations nfs_exports_op;
>>> +extern struct workqueue_struct *laundry_wq;
>>> /*
>>> * Common void argument and result helpers
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH RFC v21 4/7] fs/lock: add helper locks_owner_has_blockers to check for blockers
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (2 preceding siblings ...)
2022-04-23 18:44 ` [PATCH RFC v21 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd Dai Ngo
@ 2022-04-23 18:44 ` Dai Ngo
2022-04-23 18:44 ` [PATCH RFC v21 5/7] fs/lock: add 2 callbacks to lock_manager_operations to resolve conflict Dai Ngo
` (3 subsequent siblings)
7 siblings, 0 replies; 25+ messages in thread
From: Dai Ngo @ 2022-04-23 18:44 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Add helper locks_owner_has_blockers to check if there is any blockers
for a given lockowner.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/locks.c | 28 ++++++++++++++++++++++++++++
include/linux/fs.h | 7 +++++++
2 files changed, 35 insertions(+)
diff --git a/fs/locks.c b/fs/locks.c
index 8c6df10cd9ed..c369841ef7d1 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -300,6 +300,34 @@ void locks_release_private(struct file_lock *fl)
}
EXPORT_SYMBOL_GPL(locks_release_private);
+/**
+ * locks_owner_has_blockers - Check for blocking lock requests
+ * @flctx: file lock context
+ * @owner: lock owner
+ *
+ * Return values:
+ * %true: @owner has at least one blocker
+ * %false: @owner 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_GPL(locks_owner_has_blockers);
+
/* Free a lock which is not in use. */
void locks_free_lock(struct file_lock *fl)
{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index bbde95387a23..b8ed7f974fb4 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1174,6 +1174,8 @@ 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);
+extern bool locks_owner_has_blockers(struct file_lock_context *flctx,
+ fl_owner_t owner);
#else /* !CONFIG_FILE_LOCKING */
static inline int fcntl_getlk(struct file *file, unsigned int cmd,
struct flock __user *user)
@@ -1309,6 +1311,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_owner_has_blockers(struct file_lock_context *flctx,
+ fl_owner_t owner)
+{
+ return false;
+}
#endif /* !CONFIG_FILE_LOCKING */
static inline struct inode *file_inode(const struct file *f)
--
2.9.5
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH RFC v21 5/7] fs/lock: add 2 callbacks to lock_manager_operations to resolve conflict
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (3 preceding siblings ...)
2022-04-23 18:44 ` [PATCH RFC v21 4/7] fs/lock: add helper locks_owner_has_blockers to check for blockers Dai Ngo
@ 2022-04-23 18:44 ` Dai Ngo
2022-04-23 18:44 ` [PATCH RFC v21 6/7] NFSD: add support for lock conflict to courteous server Dai Ngo
` (2 subsequent siblings)
7 siblings, 0 replies; 25+ messages in thread
From: Dai Ngo @ 2022-04-23 18:44 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Add 2 new callbacks, lm_lock_expirable and lm_expire_lock, to
lock_manager_operations to allow the lock manager to take appropriate
action to resolve the lock conflict if possible.
A new field, lm_mod_owner, is also added to lock_manager_operations.
The lm_mod_owner is used by the fs/lock code to make sure the lock
manager module such as nfsd, is not freed while lock conflict is being
resolved.
lm_lock_expirable checks and returns a pointer to an opaque data if
the lock conflict can be resolved otherwise returns NULL. This callback
must be called with the flc_lock held so it can not block.
lm_expire_lock is called with the returned value from lm_lock_expirable
to resolve the conflict. This callback is called without the flc_lock
held since it's allowed to block. Upon returning from this callback, the
lock conflict should be resolved and the caller is expected to restart
the conflict check from the beginnning of the list.
Lock manager, such as NFSv4 courteous server, uses this callback to
resolve conflict by destroying lock owner, or the NFSv4 courtesy client
(client that has expired but allowed to maintains its states) that owns
the lock.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
Documentation/filesystems/locking.rst | 2 ++
fs/locks.c | 44 +++++++++++++++++++++++++++++++----
include/linux/fs.h | 3 +++
3 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst
index c26d854275a0..fdf3cd82b611 100644
--- a/Documentation/filesystems/locking.rst
+++ b/Documentation/filesystems/locking.rst
@@ -439,6 +439,8 @@ lm_grant: no no no
lm_break: yes no no
lm_change yes no no
lm_breaker_owns_lease: yes no no
+lm_lock_expirable yes no no
+lm_expire_lock no no yes
====================== ============= ================= =========
buffer_head
diff --git a/fs/locks.c b/fs/locks.c
index c369841ef7d1..283645f52c2e 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -896,6 +896,36 @@ static bool flock_locks_conflict(struct file_lock *caller_fl,
return locks_conflict(caller_fl, sys_fl);
}
+static bool
+resolve_lock_conflict_locked(struct file_lock_context *ctx,
+ struct file_lock *cfl, bool rwsem)
+{
+ void *ret, *owner;
+ void (*func)(void *priv);
+
+ if (cfl->fl_lmops && cfl->fl_lmops->lm_lock_expirable &&
+ cfl->fl_lmops->lm_expire_lock) {
+ ret = (*cfl->fl_lmops->lm_lock_expirable)(cfl);
+ if (!ret)
+ return false;
+ owner = cfl->fl_lmops->lm_mod_owner;
+ if (!owner)
+ return false;
+ func = cfl->fl_lmops->lm_expire_lock;
+ __module_get(owner);
+ if (rwsem)
+ percpu_up_read(&file_rwsem);
+ spin_unlock(&ctx->flc_lock);
+ (*func)(ret);
+ module_put(owner);
+ if (rwsem)
+ percpu_down_read(&file_rwsem);
+ spin_lock(&ctx->flc_lock);
+ return true;
+ }
+ return false;
+}
+
void
posix_test_lock(struct file *filp, struct file_lock *fl)
{
@@ -910,11 +940,14 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
}
spin_lock(&ctx->flc_lock);
+retry:
list_for_each_entry(cfl, &ctx->flc_posix, fl_list) {
- if (posix_locks_conflict(fl, cfl)) {
- locks_copy_conflock(fl, cfl);
- goto out;
- }
+ if (!posix_locks_conflict(fl, cfl))
+ continue;
+ if (resolve_lock_conflict_locked(ctx, cfl, false))
+ goto retry;
+ locks_copy_conflock(fl, cfl);
+ goto out;
}
fl->fl_type = F_UNLCK;
out:
@@ -1108,6 +1141,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
percpu_down_read(&file_rwsem);
spin_lock(&ctx->flc_lock);
+retry:
/*
* New lock request. Walk all POSIX locks and look for conflicts. If
* there are any, either return error or put the request on the
@@ -1117,6 +1151,8 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
list_for_each_entry(fl, &ctx->flc_posix, fl_list) {
if (!posix_locks_conflict(request, fl))
continue;
+ if (resolve_lock_conflict_locked(ctx, fl, true))
+ goto retry;
if (conflock)
locks_copy_conflock(conflock, fl);
error = -EAGAIN;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b8ed7f974fb4..0830176a1aa8 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1029,6 +1029,7 @@ struct file_lock_operations {
};
struct lock_manager_operations {
+ void *lm_mod_owner;
fl_owner_t (*lm_get_owner)(fl_owner_t);
void (*lm_put_owner)(fl_owner_t);
void (*lm_notify)(struct file_lock *); /* unblock callback */
@@ -1037,6 +1038,8 @@ struct lock_manager_operations {
int (*lm_change)(struct file_lock *, int, struct list_head *);
void (*lm_setup)(struct file_lock *, void **);
bool (*lm_breaker_owns_lease)(struct file_lock *);
+ void *(*lm_lock_expirable)(struct file_lock *cfl);
+ void (*lm_expire_lock)(void *data);
};
struct lock_manager {
--
2.9.5
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH RFC v21 6/7] NFSD: add support for lock conflict to courteous server
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (4 preceding siblings ...)
2022-04-23 18:44 ` [PATCH RFC v21 5/7] fs/lock: add 2 callbacks to lock_manager_operations to resolve conflict Dai Ngo
@ 2022-04-23 18:44 ` Dai Ngo
2022-04-23 18:44 ` [PATCH RFC v21 7/7] NFSD: Show state of courtesy client in client info Dai Ngo
2022-04-25 16:17 ` [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server J. Bruce Fields
7 siblings, 0 replies; 25+ messages in thread
From: Dai Ngo @ 2022-04-23 18:44 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
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 b70ba2eb5665..f6aef1a7cc02 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -5729,11 +5729,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++) {
@@ -5741,40 +5761,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)
@@ -5791,7 +5788,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() >=
@@ -6747,6 +6744,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);
+
+ run_laundromat(nn, true);
+}
+
static void
nfsd4_lm_notify(struct file_lock *fl)
{
@@ -6773,9 +6792,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
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH RFC v21 7/7] NFSD: Show state of courtesy client in client info
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (5 preceding siblings ...)
2022-04-23 18:44 ` [PATCH RFC v21 6/7] NFSD: add support for lock conflict to courteous server Dai Ngo
@ 2022-04-23 18:44 ` Dai Ngo
2022-04-25 16:17 ` [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server J. Bruce Fields
7 siblings, 0 replies; 25+ messages in thread
From: Dai Ngo @ 2022-04-23 18:44 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Update client_info_show to show state of courtesy client
and time since last renew.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index f6aef1a7cc02..5810bf8d9b2d 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2468,7 +2468,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)
@@ -2476,10 +2477,19 @@ static int client_info_show(struct seq_file *m, void *v)
memcpy(&clid, &clp->cl_clientid, sizeof(clid));
seq_printf(m, "clientid: 0x%llx\n", clid);
seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr);
- if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags))
+
+ if (clp->cl_state == NFSD4_COURTESY)
+ seq_puts(m, "status: courtesy\n");
+ else if (clp->cl_state == NFSD4_EXPIRABLE)
+ seq_puts(m, "status: expired\n");
+ else if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags))
seq_puts(m, "status: confirmed\n");
else
seq_puts(m, "status: unconfirmed\n");
+ 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: %llu:%02u:%02u\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);
--
2.9.5
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server
2022-04-23 18:44 [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (6 preceding siblings ...)
2022-04-23 18:44 ` [PATCH RFC v21 7/7] NFSD: Show state of courtesy client in client info Dai Ngo
@ 2022-04-25 16:17 ` J. Bruce Fields
2022-04-25 17:53 ` J. Bruce Fields
7 siblings, 1 reply; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 16:17 UTC (permalink / raw)
To: Dai Ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Sat, Apr 23, 2022 at 11:44:08AM -0700, Dai Ngo wrote:
> . Redo based on Bruce's suggestion by breaking the patches into functionality
> and also don't remove client record of courtesy client until the client is
> actually expired.
>
> 0001: courteous server framework with support for client with delegation only.
> This patch also handles COURTESY and EXPIRABLE reconnect.
> Conflict is resolved by set the courtesy client to EXPIRABLE, let the
> laundromat expires the client on next run and return NFS4ERR_DELAY
> OPEN request.
>
> 0002: add support for opens/share reservation to courteous server
> Conflict is resolved by set the courtesy client to EXPIRABLE, let the
> laundromat expires the client on next run and return NFS4ERR_DELAY
> OPEN request.
>
> 0003: mv creation/destroying laundromat workqueue from nfs4_state_start and
> and nfs4_state_shutdown_net to init_nfsd and exit_nfsd.
>
> 0004: fs/lock: add locks_owner_has_blockers helper
>
> 0005: add 2 callbacks to lock_manager_operations for resolving lock conflict
>
> 0006: add support for locks to courteous server, making use of 0004 and 0005
> Conflict is resolved by set the courtesy client to EXPIRABLE, run the
> laundromat immediately and wait for it to complete before returning to
> fs/lock code to recheck the lock list from the beginning.
>
> NOTE: I could not get queue_work/queue_delay_work and flush_workqueue
> to work as expected, I have to use mod_delayed_work and flush_workqueue
> to get the laundromat to run immediately.
Whoops, yes, my bad.
> When we check for blockers in nfs4_anylock_blockers, we do not check
> for client with delegation conflict. This is because we already hold
> the client_lock and to check for delegation conflict we need the state_lock
> and scanning the del_recall_lru list each time. So to avoid this overhead
> and potential deadlock (not sure about lock of ordering of these locks)
> we check and set the COURTESY client with delegation being recalled to
> EXPIRABLE later in nfs4_laundromat.
Hm, OK, I'll think about that, but sounds like it should work.
--b.
>
> 0007: show state of courtesy client in client info.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server
2022-04-25 16:17 ` [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server J. Bruce Fields
@ 2022-04-25 17:53 ` J. Bruce Fields
2022-04-25 18:16 ` dai.ngo
0 siblings, 1 reply; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 17:53 UTC (permalink / raw)
To: Dai Ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
I'm getting a few new pynfs failures after applying these. I haven't
tried to investigage what's happening.
--b.
**************************************************
RENEW3 st_renew.testExpired : FAILURE
nfs4lib.BadCompoundRes: Opening file b'RENEW3-1':
operation OP_OPEN should return NFS4_OK, instead got
NFS4ERR_DELAY
LKU10 st_locku.testTimedoutUnlock : FAILURE
nfs4lib.BadCompoundRes: Opening file b'LKU10-1':
operation OP_OPEN should return NFS4_OK, instead got
NFS4ERR_DELAY
CLOSE9 st_close.testTimedoutClose2 : FAILURE
nfs4lib.BadCompoundRes: Opening file b'CLOSE9-1':
operation OP_OPEN should return NFS4_OK, instead got
NFS4ERR_DELAY
CLOSE8 st_close.testTimedoutClose1 : FAILURE
nfs4lib.BadCompoundRes: Opening file b'CLOSE8-1':
operation OP_OPEN should return NFS4_OK, instead got
NFS4ERR_DELAY
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server
2022-04-25 17:53 ` J. Bruce Fields
@ 2022-04-25 18:16 ` dai.ngo
2022-04-25 19:19 ` J. Bruce Fields
0 siblings, 1 reply; 25+ messages in thread
From: dai.ngo @ 2022-04-25 18:16 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 4/25/22 10:53 AM, J. Bruce Fields wrote:
> I'm getting a few new pynfs failures after applying these. I haven't
> tried to investigage what's happening.
>
> --b.
>
> **************************************************
> RENEW3 st_renew.testExpired : FAILURE
> nfs4lib.BadCompoundRes: Opening file b'RENEW3-1':
> operation OP_OPEN should return NFS4_OK, instead got
> NFS4ERR_DELAY
> LKU10 st_locku.testTimedoutUnlock : FAILURE
> nfs4lib.BadCompoundRes: Opening file b'LKU10-1':
> operation OP_OPEN should return NFS4_OK, instead got
> NFS4ERR_DELAY
> CLOSE9 st_close.testTimedoutClose2 : FAILURE
> nfs4lib.BadCompoundRes: Opening file b'CLOSE9-1':
> operation OP_OPEN should return NFS4_OK, instead got
> NFS4ERR_DELAY
> CLOSE8 st_close.testTimedoutClose1 : FAILURE
> nfs4lib.BadCompoundRes: Opening file b'CLOSE8-1':
> operation OP_OPEN should return NFS4_OK, instead got
> NFS4ERR_DELAY
with this patches, OPEN (v4.0 and v4.1) might have to handle NFS4ERR_DELAY
if there is a reservation conflict. I had to modify open_confirm (v4.0) and
open_create_file (v4.1) to handle the NFS4ERR_DELAY error.
-Dai
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH RFC v21 0/7] NFSD: Initial implementation of NFSv4 Courteous Server
2022-04-25 18:16 ` dai.ngo
@ 2022-04-25 19:19 ` J. Bruce Fields
0 siblings, 0 replies; 25+ messages in thread
From: J. Bruce Fields @ 2022-04-25 19:19 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Mon, Apr 25, 2022 at 11:16:54AM -0700, dai.ngo@oracle.com wrote:
>
> On 4/25/22 10:53 AM, J. Bruce Fields wrote:
> >I'm getting a few new pynfs failures after applying these. I haven't
> >tried to investigage what's happening.
> >
> >--b.
> >
> >**************************************************
> >RENEW3 st_renew.testExpired : FAILURE
> > nfs4lib.BadCompoundRes: Opening file b'RENEW3-1':
> > operation OP_OPEN should return NFS4_OK, instead got
> > NFS4ERR_DELAY
> >LKU10 st_locku.testTimedoutUnlock : FAILURE
> > nfs4lib.BadCompoundRes: Opening file b'LKU10-1':
> > operation OP_OPEN should return NFS4_OK, instead got
> > NFS4ERR_DELAY
> >CLOSE9 st_close.testTimedoutClose2 : FAILURE
> > nfs4lib.BadCompoundRes: Opening file b'CLOSE9-1':
> > operation OP_OPEN should return NFS4_OK, instead got
> > NFS4ERR_DELAY
> >CLOSE8 st_close.testTimedoutClose1 : FAILURE
> > nfs4lib.BadCompoundRes: Opening file b'CLOSE8-1':
> > operation OP_OPEN should return NFS4_OK, instead got
> > NFS4ERR_DELAY
>
> with this patches, OPEN (v4.0 and v4.1) might have to handle NFS4ERR_DELAY
> if there is a reservation conflict. I had to modify open_confirm (v4.0) and
> open_create_file (v4.1) to handle the NFS4ERR_DELAY error.
Looking at your patch 2....
OK, my suggestion was: "in the case of a conflict, call
try_to_expire_client and queue_work(), then modify e.g.
nfs4_get_vfs_file to flush_workqueue() and then retry after unlocking
fi_lock." You're returning DELAY instead of waiting for the workqueue.
After thinking on it a minute.... I like your way better. It's simpler.
Any client has to handle DELAY on OPEN, for the delegation-conflict
case. Maybe it's a little suboptimal, but so what, this is a very rare
case.
So, good thinking, let's stick with that idea. We'll just need to fix
up pynfs some time.
--b.
^ permalink raw reply [flat|nested] 25+ messages in thread