* [PATCH RFC v18 01/11] fs/lock: add helper locks_owner_has_blockers to check for blockers
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server Dai Ngo
` (9 subsequent siblings)
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 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 050acf8b5110..53864eb99dc5 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 831b20430d6e..2057a9df790f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1200,6 +1200,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)
@@ -1335,6 +1337,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] 31+ messages in thread
* [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 01/11] fs/lock: add helper locks_owner_has_blockers to check for blockers Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-29 15:47 ` J. Bruce Fields
2022-03-25 4:34 ` [PATCH RFC v18 03/11] NFSD: Add lm_lock_expired call out Dai Ngo
` (8 subsequent siblings)
10 siblings, 1 reply; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Update nfs4_client to add:
. cl_cs_client_state: courtesy client state
. cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
. cl_cs_list: list used by laundromat to process courtesy clients
Modify alloc_client to initialize these fields.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 2 ++
fs/nfsd/nfsd.h | 1 +
fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
3 files changed, 36 insertions(+)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 234e852fcdfa..a65d59510681 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
INIT_LIST_HEAD(&clp->cl_delegations);
INIT_LIST_HEAD(&clp->cl_lru);
INIT_LIST_HEAD(&clp->cl_revoked);
+ INIT_LIST_HEAD(&clp->cl_cs_list);
#ifdef CONFIG_NFSD_PNFS
INIT_LIST_HEAD(&clp->cl_lo_states);
#endif
INIT_LIST_HEAD(&clp->async_copies);
spin_lock_init(&clp->async_lock);
spin_lock_init(&clp->cl_lock);
+ spin_lock_init(&clp->cl_cs_lock);
rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
return clp;
err_no_hashtbl:
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..40e390abc842 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
#define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
/*
+ * CLIENT_ CLIENT_ CLIENT_
+ * COURTESY EXPIRED RECONNECTED Meaning Where set
+ * -----------------------------------------------------------------------------
+ * | false | false | false | Confirmed, active | Default |
+ * |---------------------------------------------------------------------------|
+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
+ * | | | | Lease/lock/share | |
+ * | | | | reservation conflict | |
+ * | | | | can cause Courtesy | |
+ * | | | | client to be expired | |
+ * |---------------------------------------------------------------------------|
+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
+ * | | | | | nfsd4_expire_courtesy_clnt |
+ * |---------------------------------------------------------------------------|
+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
+ * | | | | reconnected, | |
+ * | | | | becoming active | |
+ * -----------------------------------------------------------------------------
+ */
+
+enum courtesy_client_state {
+ NFSD4_CLIENT_COURTESY = 1,
+ NFSD4_CLIENT_EXPIRED,
+ NFSD4_CLIENT_RECONNECTED,
+};
+
+/*
* struct nfs4_client - one per client. Clientids live here.
*
* The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
@@ -385,6 +414,10 @@ 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 */
+
+ enum courtesy_client_state cl_cs_client_state;
+ spinlock_t cl_cs_lock;
+ struct list_head cl_cs_list;
};
/* struct nfs4_client_reset
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-25 4:34 ` [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server Dai Ngo
@ 2022-03-29 15:47 ` J. Bruce Fields
2022-03-29 16:20 ` dai.ngo
0 siblings, 1 reply; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-29 15:47 UTC (permalink / raw)
To: Dai Ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> Update nfs4_client to add:
> . cl_cs_client_state: courtesy client state
> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> . cl_cs_list: list used by laundromat to process courtesy clients
>
> Modify alloc_client to initialize these fields.
>
> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> ---
> fs/nfsd/nfs4state.c | 2 ++
> fs/nfsd/nfsd.h | 1 +
> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> 3 files changed, 36 insertions(+)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 234e852fcdfa..a65d59510681 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> INIT_LIST_HEAD(&clp->cl_delegations);
> INIT_LIST_HEAD(&clp->cl_lru);
> INIT_LIST_HEAD(&clp->cl_revoked);
> + INIT_LIST_HEAD(&clp->cl_cs_list);
> #ifdef CONFIG_NFSD_PNFS
> INIT_LIST_HEAD(&clp->cl_lo_states);
> #endif
> INIT_LIST_HEAD(&clp->async_copies);
> spin_lock_init(&clp->async_lock);
> spin_lock_init(&clp->cl_lock);
> + spin_lock_init(&clp->cl_cs_lock);
> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> return clp;
> err_no_hashtbl:
> 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..40e390abc842 100644
> --- a/fs/nfsd/state.h
> +++ b/fs/nfsd/state.h
> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>
> /*
> + * CLIENT_ CLIENT_ CLIENT_
> + * COURTESY EXPIRED RECONNECTED Meaning Where set
> + * -----------------------------------------------------------------------------
> + * | false | false | false | Confirmed, active | Default |
> + * |---------------------------------------------------------------------------|
> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> + * | | | | Lease/lock/share | |
> + * | | | | reservation conflict | |
> + * | | | | can cause Courtesy | |
> + * | | | | client to be expired | |
> + * |---------------------------------------------------------------------------|
> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> + * | | | | | nfsd4_expire_courtesy_clnt |
> + * |---------------------------------------------------------------------------|
> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> + * | | | | reconnected, | |
> + * | | | | becoming active | |
> + * -----------------------------------------------------------------------------
These are mutually exclusive values, not bits that may set to 0 or 1, so
the three boolean columns are confusing. I'd just structure the table
like:
client state meaning where set
0 Confirmed, active Default
CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
etc.
--b.
> + */
> +
> +enum courtesy_client_state {
> + NFSD4_CLIENT_COURTESY = 1,
> + NFSD4_CLIENT_EXPIRED,
> + NFSD4_CLIENT_RECONNECTED,
> +};
> +
> +/*
> * struct nfs4_client - one per client. Clientids live here.
> *
> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
> @@ -385,6 +414,10 @@ 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 */
> +
> + enum courtesy_client_state cl_cs_client_state;
> + spinlock_t cl_cs_lock;
> + struct list_head cl_cs_list;
> };
>
> /* struct nfs4_client_reset
> --
> 2.9.5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 15:47 ` J. Bruce Fields
@ 2022-03-29 16:20 ` dai.ngo
2022-03-29 16:30 ` J. Bruce Fields
0 siblings, 1 reply; 31+ messages in thread
From: dai.ngo @ 2022-03-29 16:20 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>> Update nfs4_client to add:
>> . cl_cs_client_state: courtesy client state
>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>> . cl_cs_list: list used by laundromat to process courtesy clients
>>
>> Modify alloc_client to initialize these fields.
>>
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>> fs/nfsd/nfs4state.c | 2 ++
>> fs/nfsd/nfsd.h | 1 +
>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>> 3 files changed, 36 insertions(+)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index 234e852fcdfa..a65d59510681 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>> INIT_LIST_HEAD(&clp->cl_delegations);
>> INIT_LIST_HEAD(&clp->cl_lru);
>> INIT_LIST_HEAD(&clp->cl_revoked);
>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>> #ifdef CONFIG_NFSD_PNFS
>> INIT_LIST_HEAD(&clp->cl_lo_states);
>> #endif
>> INIT_LIST_HEAD(&clp->async_copies);
>> spin_lock_init(&clp->async_lock);
>> spin_lock_init(&clp->cl_lock);
>> + spin_lock_init(&clp->cl_cs_lock);
>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>> return clp;
>> err_no_hashtbl:
>> 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..40e390abc842 100644
>> --- a/fs/nfsd/state.h
>> +++ b/fs/nfsd/state.h
>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>
>> /*
>> + * CLIENT_ CLIENT_ CLIENT_
>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>> + * -----------------------------------------------------------------------------
>> + * | false | false | false | Confirmed, active | Default |
>> + * |---------------------------------------------------------------------------|
>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>> + * | | | | Lease/lock/share | |
>> + * | | | | reservation conflict | |
>> + * | | | | can cause Courtesy | |
>> + * | | | | client to be expired | |
>> + * |---------------------------------------------------------------------------|
>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>> + * | | | | | nfsd4_expire_courtesy_clnt |
>> + * |---------------------------------------------------------------------------|
>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>> + * | | | | reconnected, | |
>> + * | | | | becoming active | |
>> + * -----------------------------------------------------------------------------
> These are mutually exclusive values, not bits that may set to 0 or 1, so
> the three boolean columns are confusing. I'd just structure the table
> like:
>
> client state meaning where set
> 0 Confirmed, active Default
> CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
> CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
>
> etc.
will fix in v19.
Thanks,
-Dai
>
> --b.
>
>> + */
>> +
>> +enum courtesy_client_state {
>> + NFSD4_CLIENT_COURTESY = 1,
>> + NFSD4_CLIENT_EXPIRED,
>> + NFSD4_CLIENT_RECONNECTED,
>> +};
>> +
>> +/*
>> * struct nfs4_client - one per client. Clientids live here.
>> *
>> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
>> @@ -385,6 +414,10 @@ 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 */
>> +
>> + enum courtesy_client_state cl_cs_client_state;
>> + spinlock_t cl_cs_lock;
>> + struct list_head cl_cs_list;
>> };
>>
>> /* struct nfs4_client_reset
>> --
>> 2.9.5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 16:20 ` dai.ngo
@ 2022-03-29 16:30 ` J. Bruce Fields
2022-03-29 16:42 ` J. Bruce Fields
2022-03-29 18:19 ` dai.ngo
0 siblings, 2 replies; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-29 16:30 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
>
> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> >On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> >>Update nfs4_client to add:
> >> . cl_cs_client_state: courtesy client state
> >> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> >> . cl_cs_list: list used by laundromat to process courtesy clients
> >>
> >>Modify alloc_client to initialize these fields.
> >>
> >>Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> >>---
> >> fs/nfsd/nfs4state.c | 2 ++
> >> fs/nfsd/nfsd.h | 1 +
> >> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> >> 3 files changed, 36 insertions(+)
> >>
> >>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>index 234e852fcdfa..a65d59510681 100644
> >>--- a/fs/nfsd/nfs4state.c
> >>+++ b/fs/nfsd/nfs4state.c
> >>@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> >> INIT_LIST_HEAD(&clp->cl_delegations);
> >> INIT_LIST_HEAD(&clp->cl_lru);
> >> INIT_LIST_HEAD(&clp->cl_revoked);
> >>+ INIT_LIST_HEAD(&clp->cl_cs_list);
> >> #ifdef CONFIG_NFSD_PNFS
> >> INIT_LIST_HEAD(&clp->cl_lo_states);
> >> #endif
> >> INIT_LIST_HEAD(&clp->async_copies);
> >> spin_lock_init(&clp->async_lock);
> >> spin_lock_init(&clp->cl_lock);
> >>+ spin_lock_init(&clp->cl_cs_lock);
> >> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> >> return clp;
> >> err_no_hashtbl:
> >>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..40e390abc842 100644
> >>--- a/fs/nfsd/state.h
> >>+++ b/fs/nfsd/state.h
> >>@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> >> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> >> /*
> >>+ * CLIENT_ CLIENT_ CLIENT_
> >>+ * COURTESY EXPIRED RECONNECTED Meaning Where set
> >>+ * -----------------------------------------------------------------------------
> >>+ * | false | false | false | Confirmed, active | Default |
> >>+ * |---------------------------------------------------------------------------|
> >>+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> >>+ * | | | | Lease/lock/share | |
> >>+ * | | | | reservation conflict | |
> >>+ * | | | | can cause Courtesy | |
> >>+ * | | | | client to be expired | |
> >>+ * |---------------------------------------------------------------------------|
> >>+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
> >>+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> >>+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> >>+ * | | | | | nfsd4_expire_courtesy_clnt |
> >>+ * |---------------------------------------------------------------------------|
> >>+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> >>+ * | | | | reconnected, | |
> >>+ * | | | | becoming active | |
> >>+ * -----------------------------------------------------------------------------
By the way, where is a client returned to the normal (0) state? That
has to happen at some point.
How is CLIENT_EXPIRED treated differently from cl_time == 0, and why?
Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
a bind_conn_to_session fails).
--b.
> >These are mutually exclusive values, not bits that may set to 0 or 1, so
> >the three boolean columns are confusing. I'd just structure the table
> >like:
> >
> > client state meaning where set
> > 0 Confirmed, active Default
> > CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
> > CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
> >
> >etc.
>
> will fix in v19.
>
> Thanks,
> -Dai
>
> >
> >--b.
> >
> >>+ */
> >>+
> >>+enum courtesy_client_state {
> >>+ NFSD4_CLIENT_COURTESY = 1,
> >>+ NFSD4_CLIENT_EXPIRED,
> >>+ NFSD4_CLIENT_RECONNECTED,
> >>+};
> >>+
> >>+/*
> >> * struct nfs4_client - one per client. Clientids live here.
> >> *
> >> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
> >>@@ -385,6 +414,10 @@ 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 */
> >>+
> >>+ enum courtesy_client_state cl_cs_client_state;
> >>+ spinlock_t cl_cs_lock;
> >>+ struct list_head cl_cs_list;
> >> };
> >> /* struct nfs4_client_reset
> >>--
> >>2.9.5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 16:30 ` J. Bruce Fields
@ 2022-03-29 16:42 ` J. Bruce Fields
2022-03-29 18:19 ` dai.ngo
1 sibling, 0 replies; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-29 16:42 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Tue, Mar 29, 2022 at 12:30:11PM -0400, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
> >
> > On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> > >On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> > >>Update nfs4_client to add:
> > >> . cl_cs_client_state: courtesy client state
> > >> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> > >> . cl_cs_list: list used by laundromat to process courtesy clients
> > >>
> > >>Modify alloc_client to initialize these fields.
> > >>
> > >>Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> > >>---
> > >> fs/nfsd/nfs4state.c | 2 ++
> > >> fs/nfsd/nfsd.h | 1 +
> > >> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> > >> 3 files changed, 36 insertions(+)
> > >>
> > >>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> > >>index 234e852fcdfa..a65d59510681 100644
> > >>--- a/fs/nfsd/nfs4state.c
> > >>+++ b/fs/nfsd/nfs4state.c
> > >>@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> > >> INIT_LIST_HEAD(&clp->cl_delegations);
> > >> INIT_LIST_HEAD(&clp->cl_lru);
> > >> INIT_LIST_HEAD(&clp->cl_revoked);
> > >>+ INIT_LIST_HEAD(&clp->cl_cs_list);
> > >> #ifdef CONFIG_NFSD_PNFS
> > >> INIT_LIST_HEAD(&clp->cl_lo_states);
> > >> #endif
> > >> INIT_LIST_HEAD(&clp->async_copies);
> > >> spin_lock_init(&clp->async_lock);
> > >> spin_lock_init(&clp->cl_lock);
> > >>+ spin_lock_init(&clp->cl_cs_lock);
> > >> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> > >> return clp;
> > >> err_no_hashtbl:
> > >>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..40e390abc842 100644
> > >>--- a/fs/nfsd/state.h
> > >>+++ b/fs/nfsd/state.h
> > >>@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> > >> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> > >> /*
> > >>+ * CLIENT_ CLIENT_ CLIENT_
> > >>+ * COURTESY EXPIRED RECONNECTED Meaning Where set
> > >>+ * -----------------------------------------------------------------------------
> > >>+ * | false | false | false | Confirmed, active | Default |
> > >>+ * |---------------------------------------------------------------------------|
> > >>+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> > >>+ * | | | | Lease/lock/share | |
> > >>+ * | | | | reservation conflict | |
> > >>+ * | | | | can cause Courtesy | |
> > >>+ * | | | | client to be expired | |
> > >>+ * |---------------------------------------------------------------------------|
> > >>+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
> > >>+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> > >>+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> > >>+ * | | | | | nfsd4_expire_courtesy_clnt |
> > >>+ * |---------------------------------------------------------------------------|
> > >>+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> > >>+ * | | | | reconnected, | |
> > >>+ * | | | | becoming active | |
> > >>+ * -----------------------------------------------------------------------------
>
> By the way, where is a client returned to the normal (0) state? That
> has to happen at some point.
>
> How is CLIENT_EXPIRED treated differently from cl_time == 0, and why?
>
> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> a bind_conn_to_session fails).
A priori I just don't see how it can be right to treat a reconnected
client in any way differently from an normal confirmed client.
Once we've told the client that its lease is still good, we have to
treat it like any other client, don't we?
--b.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 16:30 ` J. Bruce Fields
2022-03-29 16:42 ` J. Bruce Fields
@ 2022-03-29 18:19 ` dai.ngo
2022-03-29 18:39 ` J. Bruce Fields
1 sibling, 1 reply; 31+ messages in thread
From: dai.ngo @ 2022-03-29 18:19 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 3/29/22 9:30 AM, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>> Update nfs4_client to add:
>>>> . cl_cs_client_state: courtesy client state
>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>
>>>> Modify alloc_client to initialize these fields.
>>>>
>>>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>>>> ---
>>>> fs/nfsd/nfs4state.c | 2 ++
>>>> fs/nfsd/nfsd.h | 1 +
>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>> 3 files changed, 36 insertions(+)
>>>>
>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>> index 234e852fcdfa..a65d59510681 100644
>>>> --- a/fs/nfsd/nfs4state.c
>>>> +++ b/fs/nfsd/nfs4state.c
>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>> #ifdef CONFIG_NFSD_PNFS
>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>> #endif
>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>> spin_lock_init(&clp->async_lock);
>>>> spin_lock_init(&clp->cl_lock);
>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>> return clp;
>>>> err_no_hashtbl:
>>>> 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..40e390abc842 100644
>>>> --- a/fs/nfsd/state.h
>>>> +++ b/fs/nfsd/state.h
>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>> /*
>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>> + * -----------------------------------------------------------------------------
>>>> + * | false | false | false | Confirmed, active | Default |
>>>> + * |---------------------------------------------------------------------------|
>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>> + * | | | | Lease/lock/share | |
>>>> + * | | | | reservation conflict | |
>>>> + * | | | | can cause Courtesy | |
>>>> + * | | | | client to be expired | |
>>>> + * |---------------------------------------------------------------------------|
>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>> + * |---------------------------------------------------------------------------|
>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>> + * | | | | reconnected, | |
>>>> + * | | | | becoming active | |
>>>> + * -----------------------------------------------------------------------------
> By the way, where is a client returned to the normal (0) state? That
> has to happen at some point.
For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
nfsd4_bind_conn_to_session. For 4.0 courtesy client reconnects is
detected in set_client.
>
> How is CLIENT_EXPIRED treated differently from cl_time == 0, and why?
cl_time == 0 means the client is being destroyed (almost) immediately
either by the laundromat or force_expire_client.
CLIENT_EXPIRED means the client will be destroyed by the laundromat
and this depends on when the laundromat runs. When we set CLIENT_COURTESY
we don't clear cl_time since the client is not really expired yet.
We could replace CLIENT_EXPIRED with (cl_time == 0). However,
to set cl_time = 0 we need to acquire the nn->client_lock which
causes deadlock when we try to resolve lock conflicts
from nfs4_resolve_deny_conflicts_locked (fp->fi_lock -> nn_clientlock).
We use the cl_cs_lock to set CLIENT_EXPIRED.
>
> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> a bind_conn_to_session fails).
find_in_sessionid_hashtbl: we discard the courtesy client when it
reconnects and there is error from nfsd4_get_session_locked. This
should be a rare condition so rather than reverting the client
state back to courtesy, it is simpler just to discard it.
nfsd4_create_session/find_confirmed_client: I think the only time
the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
to reconnect after missing its leases, is when it wants to do clientid
trunking. This should be a rare condition so instead of dealing
with it we just do not allow it and discard the client for now.
nfsd4_destroy_clientid/find_confirmed_client: instead of destroy
the courtesy client here we just let the laundromat destroy it
as if the client already expired.
nfsd4_setclientid_confirm/find_confirmed_client: there should not
be any courtesy client found from nfsd4_setclientid_confirm, it
should be detected and discarded in nfsd4_setclientid.
-Dai
>>> These are mutually exclusive values, not bits that may set to 0 or 1, so
>>> the three boolean columns are confusing. I'd just structure the table
>>> like:
>>>
>>> client state meaning where set
>>> 0 Confirmed, active Default
>>> CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
>>> CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
>>>
>>> etc.
>> will fix in v19.
>>
>> Thanks,
>> -Dai
>>
>>> --b.
>>>
>>>> + */
>>>> +
>>>> +enum courtesy_client_state {
>>>> + NFSD4_CLIENT_COURTESY = 1,
>>>> + NFSD4_CLIENT_EXPIRED,
>>>> + NFSD4_CLIENT_RECONNECTED,
>>>> +};
>>>> +
>>>> +/*
>>>> * struct nfs4_client - one per client. Clientids live here.
>>>> *
>>>> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
>>>> @@ -385,6 +414,10 @@ 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 */
>>>> +
>>>> + enum courtesy_client_state cl_cs_client_state;
>>>> + spinlock_t cl_cs_lock;
>>>> + struct list_head cl_cs_list;
>>>> };
>>>> /* struct nfs4_client_reset
>>>> --
>>>> 2.9.5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 18:19 ` dai.ngo
@ 2022-03-29 18:39 ` J. Bruce Fields
2022-03-29 19:32 ` Chuck Lever III
2022-03-29 21:45 ` dai.ngo
0 siblings, 2 replies; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-29 18:39 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Tue, Mar 29, 2022 at 11:19:51AM -0700, dai.ngo@oracle.com wrote:
>
> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
> >On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
> >>On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> >>>On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> >>>>Update nfs4_client to add:
> >>>> . cl_cs_client_state: courtesy client state
> >>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> >>>> . cl_cs_list: list used by laundromat to process courtesy clients
> >>>>
> >>>>Modify alloc_client to initialize these fields.
> >>>>
> >>>>Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> >>>>---
> >>>> fs/nfsd/nfs4state.c | 2 ++
> >>>> fs/nfsd/nfsd.h | 1 +
> >>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> >>>> 3 files changed, 36 insertions(+)
> >>>>
> >>>>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>>>index 234e852fcdfa..a65d59510681 100644
> >>>>--- a/fs/nfsd/nfs4state.c
> >>>>+++ b/fs/nfsd/nfs4state.c
> >>>>@@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> >>>> INIT_LIST_HEAD(&clp->cl_delegations);
> >>>> INIT_LIST_HEAD(&clp->cl_lru);
> >>>> INIT_LIST_HEAD(&clp->cl_revoked);
> >>>>+ INIT_LIST_HEAD(&clp->cl_cs_list);
> >>>> #ifdef CONFIG_NFSD_PNFS
> >>>> INIT_LIST_HEAD(&clp->cl_lo_states);
> >>>> #endif
> >>>> INIT_LIST_HEAD(&clp->async_copies);
> >>>> spin_lock_init(&clp->async_lock);
> >>>> spin_lock_init(&clp->cl_lock);
> >>>>+ spin_lock_init(&clp->cl_cs_lock);
> >>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> >>>> return clp;
> >>>> err_no_hashtbl:
> >>>>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..40e390abc842 100644
> >>>>--- a/fs/nfsd/state.h
> >>>>+++ b/fs/nfsd/state.h
> >>>>@@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> >>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> >>>> /*
> >>>>+ * CLIENT_ CLIENT_ CLIENT_
> >>>>+ * COURTESY EXPIRED RECONNECTED Meaning Where set
> >>>>+ * -----------------------------------------------------------------------------
> >>>>+ * | false | false | false | Confirmed, active | Default |
> >>>>+ * |---------------------------------------------------------------------------|
> >>>>+ * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> >>>>+ * | | | | Lease/lock/share | |
> >>>>+ * | | | | reservation conflict | |
> >>>>+ * | | | | can cause Courtesy | |
> >>>>+ * | | | | client to be expired | |
> >>>>+ * |---------------------------------------------------------------------------|
> >>>>+ * | false | true | false | Courtesy client to be| nfs4_laundromat |
> >>>>+ * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> >>>>+ * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> >>>>+ * | | | | | nfsd4_expire_courtesy_clnt |
> >>>>+ * |---------------------------------------------------------------------------|
> >>>>+ * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> >>>>+ * | | | | reconnected, | |
> >>>>+ * | | | | becoming active | |
> >>>>+ * -----------------------------------------------------------------------------
> >By the way, where is a client returned to the normal (0) state? That
> >has to happen at some point.
>
> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
> nfsd4_bind_conn_to_session.
Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
the question I asked.
> >Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> >a bind_conn_to_session fails).
>
> find_in_sessionid_hashtbl: we discard the courtesy client when it
> reconnects and there is error from nfsd4_get_session_locked. This
> should be a rare condition so rather than reverting the client
> state back to courtesy, it is simpler just to discard it.
That may be a rare situation, but I don't believe the behavior of
discarding the client in this case is correct.
> nfsd4_create_session/find_confirmed_client: I think the only time
> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
> to reconnect after missing its leases, is when it wants to do clientid
> trunking. This should be a rare condition so instead of dealing
> with it we just do not allow it and discard the client for now.
We can't wave away incorrect behavior with "but it's rare". Users with
heavy and/or unusual workloads hit rare conditions. Clients may change
their behavior over time. (E.g., trunking may become more common.)
--b.
> nfsd4_destroy_clientid/find_confirmed_client: instead of destroy
> the courtesy client here we just let the laundromat destroy it
> as if the client already expired.
>
> nfsd4_setclientid_confirm/find_confirmed_client: there should not
> be any courtesy client found from nfsd4_setclientid_confirm, it
> should be detected and discarded in nfsd4_setclientid.
>
> -Dai
>
> >>>These are mutually exclusive values, not bits that may set to 0 or 1, so
> >>>the three boolean columns are confusing. I'd just structure the table
> >>>like:
> >>>
> >>> client state meaning where set
> >>> 0 Confirmed, active Default
> >>> CLIENT_COURTESY Courtesy state.... nfs4_get_client_reaplist
> >>> CLIENT_EXPIRED Courtesy client to be.. nfs4_laundromat
> >>>
> >>>etc.
> >>will fix in v19.
> >>
> >>Thanks,
> >>-Dai
> >>
> >>>--b.
> >>>
> >>>>+ */
> >>>>+
> >>>>+enum courtesy_client_state {
> >>>>+ NFSD4_CLIENT_COURTESY = 1,
> >>>>+ NFSD4_CLIENT_EXPIRED,
> >>>>+ NFSD4_CLIENT_RECONNECTED,
> >>>>+};
> >>>>+
> >>>>+/*
> >>>> * struct nfs4_client - one per client. Clientids live here.
> >>>> *
> >>>> * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
> >>>>@@ -385,6 +414,10 @@ 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 */
> >>>>+
> >>>>+ enum courtesy_client_state cl_cs_client_state;
> >>>>+ spinlock_t cl_cs_lock;
> >>>>+ struct list_head cl_cs_list;
> >>>> };
> >>>> /* struct nfs4_client_reset
> >>>>--
> >>>>2.9.5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 18:39 ` J. Bruce Fields
@ 2022-03-29 19:32 ` Chuck Lever III
2022-03-29 19:49 ` Bruce Fields
2022-03-29 21:45 ` dai.ngo
1 sibling, 1 reply; 31+ messages in thread
From: Chuck Lever III @ 2022-03-29 19:32 UTC (permalink / raw)
To: Bruce Fields
Cc: Dai Ngo, Jeff Layton, Al Viro, Linux NFS Mailing List, linux-fsdevel
> On Mar 29, 2022, at 2:39 PM, J. Bruce Fields <bfields@fieldses.org> wrote:
>
> On Tue, Mar 29, 2022 at 11:19:51AM -0700, dai.ngo@oracle.com wrote:
>>
>> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
>>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
>>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>>>> Update nfs4_client to add:
>>>>>> . cl_cs_client_state: courtesy client state
>>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>>>
>>>>>> Modify alloc_client to initialize these fields.
>>>>>>
>>>>>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>>>>>> ---
>>>>>> fs/nfsd/nfs4state.c | 2 ++
>>>>>> fs/nfsd/nfsd.h | 1 +
>>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>>>> 3 files changed, 36 insertions(+)
>>>>>>
>>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>>>> index 234e852fcdfa..a65d59510681 100644
>>>>>> --- a/fs/nfsd/nfs4state.c
>>>>>> +++ b/fs/nfsd/nfs4state.c
>>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>>>> #ifdef CONFIG_NFSD_PNFS
>>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>>>> #endif
>>>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>>>> spin_lock_init(&clp->async_lock);
>>>>>> spin_lock_init(&clp->cl_lock);
>>>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>>>> return clp;
>>>>>> err_no_hashtbl:
>>>>>> 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..40e390abc842 100644
>>>>>> --- a/fs/nfsd/state.h
>>>>>> +++ b/fs/nfsd/state.h
>>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>>>> /*
>>>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>>>> + * -----------------------------------------------------------------------------
>>>>>> + * | false | false | false | Confirmed, active | Default |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>>>> + * | | | | Lease/lock/share | |
>>>>>> + * | | | | reservation conflict | |
>>>>>> + * | | | | can cause Courtesy | |
>>>>>> + * | | | | client to be expired | |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>>>> + * | | | | reconnected, | |
>>>>>> + * | | | | becoming active | |
>>>>>> + * -----------------------------------------------------------------------------
>>> By the way, where is a client returned to the normal (0) state? That
>>> has to happen at some point.
>>
>> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
>> nfsd4_bind_conn_to_session.
>
> Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
> the question I asked.
"reconnected" simply means the client has gotten back in touch.
The server then has to decide whether to allow the client to
become active again or it needs to purge it. That decision
is different for each operation and minor version. Look for
"if (cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)" for how
those choices are made.
>>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
>>> a bind_conn_to_session fails).
>>
>> find_in_sessionid_hashtbl: we discard the courtesy client when it
>> reconnects and there is error from nfsd4_get_session_locked. This
>> should be a rare condition so rather than reverting the client
>> state back to courtesy, it is simpler just to discard it.
>
> That may be a rare situation, but I don't believe the behavior of
> discarding the client in this case is correct.
Can you explain this? It's a courtesy client... the server can
decide it's expired at that point, can't it? IOW what breaks?
>> nfsd4_create_session/find_confirmed_client: I think the only time
>> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
>> to reconnect after missing its leases, is when it wants to do clientid
>> trunking. This should be a rare condition so instead of dealing
>> with it we just do not allow it and discard the client for now.
>
> We can't wave away incorrect behavior with "but it's rare". Users with
> heavy and/or unusual workloads hit rare conditions. Clients may change
> their behavior over time. (E.g., trunking may become more common.)
--
Chuck Lever
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 19:32 ` Chuck Lever III
@ 2022-03-29 19:49 ` Bruce Fields
2022-03-29 19:58 ` Chuck Lever III
0 siblings, 1 reply; 31+ messages in thread
From: Bruce Fields @ 2022-03-29 19:49 UTC (permalink / raw)
To: Chuck Lever III
Cc: Dai Ngo, Jeff Layton, Al Viro, Linux NFS Mailing List, linux-fsdevel
On Tue, Mar 29, 2022 at 07:32:57PM +0000, Chuck Lever III wrote:
>
>
> > On Mar 29, 2022, at 2:39 PM, J. Bruce Fields <bfields@fieldses.org> wrote:
> >
> > On Tue, Mar 29, 2022 at 11:19:51AM -0700, dai.ngo@oracle.com wrote:
> >>
> >> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
> >>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
> >>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
> >>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
> >>>>>> Update nfs4_client to add:
> >>>>>> . cl_cs_client_state: courtesy client state
> >>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
> >>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
> >>>>>>
> >>>>>> Modify alloc_client to initialize these fields.
> >>>>>>
> >>>>>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> >>>>>> ---
> >>>>>> fs/nfsd/nfs4state.c | 2 ++
> >>>>>> fs/nfsd/nfsd.h | 1 +
> >>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
> >>>>>> 3 files changed, 36 insertions(+)
> >>>>>>
> >>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>>>>> index 234e852fcdfa..a65d59510681 100644
> >>>>>> --- a/fs/nfsd/nfs4state.c
> >>>>>> +++ b/fs/nfsd/nfs4state.c
> >>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
> >>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
> >>>>>> INIT_LIST_HEAD(&clp->cl_lru);
> >>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
> >>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
> >>>>>> #ifdef CONFIG_NFSD_PNFS
> >>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
> >>>>>> #endif
> >>>>>> INIT_LIST_HEAD(&clp->async_copies);
> >>>>>> spin_lock_init(&clp->async_lock);
> >>>>>> spin_lock_init(&clp->cl_lock);
> >>>>>> + spin_lock_init(&clp->cl_cs_lock);
> >>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
> >>>>>> return clp;
> >>>>>> err_no_hashtbl:
> >>>>>> 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..40e390abc842 100644
> >>>>>> --- a/fs/nfsd/state.h
> >>>>>> +++ b/fs/nfsd/state.h
> >>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
> >>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
> >>>>>> /*
> >>>>>> + * CLIENT_ CLIENT_ CLIENT_
> >>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
> >>>>>> + * -----------------------------------------------------------------------------
> >>>>>> + * | false | false | false | Confirmed, active | Default |
> >>>>>> + * |---------------------------------------------------------------------------|
> >>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
> >>>>>> + * | | | | Lease/lock/share | |
> >>>>>> + * | | | | reservation conflict | |
> >>>>>> + * | | | | can cause Courtesy | |
> >>>>>> + * | | | | client to be expired | |
> >>>>>> + * |---------------------------------------------------------------------------|
> >>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
> >>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
> >>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
> >>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
> >>>>>> + * |---------------------------------------------------------------------------|
> >>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
> >>>>>> + * | | | | reconnected, | |
> >>>>>> + * | | | | becoming active | |
> >>>>>> + * -----------------------------------------------------------------------------
> >>> By the way, where is a client returned to the normal (0) state? That
> >>> has to happen at some point.
> >>
> >> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
> >> nfsd4_bind_conn_to_session.
> >
> > Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
> > the question I asked.
>
> "reconnected" simply means the client has gotten back in touch.
Again, my question was: when is cl_cs_client_state set back to 0? As
far as I can tell, the answer is never. That means, even long after the
client has reconnected, it's left in a weird state where it can be
suddenly expired for all sorts of reasons.
> The server then has to decide whether to allow the client to
> become active again or it needs to purge it. That decision
> is different for each operation and minor version. Look for
> "if (cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)" for how
> those choices are made.
>
>
> >>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
> >>> a bind_conn_to_session fails).
> >>
> >> find_in_sessionid_hashtbl: we discard the courtesy client when it
> >> reconnects and there is error from nfsd4_get_session_locked. This
> >> should be a rare condition so rather than reverting the client
> >> state back to courtesy, it is simpler just to discard it.
> >
> > That may be a rare situation, but I don't believe the behavior of
> > discarding the client in this case is correct.
>
> Can you explain this? It's a courtesy client... the server can
> decide it's expired at that point, can't it? IOW what breaks?
I'm not worried about courtesy clients, I'm worried about clients that
were courtesy clients but have since succesfully renewed their state.
Expiring them for a failed bind_conn_to_session isn't right.
--b.
>
>
> >> nfsd4_create_session/find_confirmed_client: I think the only time
> >> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
> >> to reconnect after missing its leases, is when it wants to do clientid
> >> trunking. This should be a rare condition so instead of dealing
> >> with it we just do not allow it and discard the client for now.
> >
> > We can't wave away incorrect behavior with "but it's rare". Users with
> > heavy and/or unusual workloads hit rare conditions. Clients may change
> > their behavior over time. (E.g., trunking may become more common.)
>
>
> --
> Chuck Lever
>
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 19:49 ` Bruce Fields
@ 2022-03-29 19:58 ` Chuck Lever III
2022-03-29 20:01 ` Bruce Fields
0 siblings, 1 reply; 31+ messages in thread
From: Chuck Lever III @ 2022-03-29 19:58 UTC (permalink / raw)
To: Bruce Fields, Dai Ngo
Cc: Jeff Layton, Al Viro, Linux NFS Mailing List, linux-fsdevel
> On Mar 29, 2022, at 3:49 PM, Bruce Fields <bfields@fieldses.org> wrote:
>
> On Tue, Mar 29, 2022 at 07:32:57PM +0000, Chuck Lever III wrote:
>>
>>
>>> On Mar 29, 2022, at 2:39 PM, J. Bruce Fields <bfields@fieldses.org> wrote:
>>>
>>> On Tue, Mar 29, 2022 at 11:19:51AM -0700, dai.ngo@oracle.com wrote:
>>>>
>>>> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
>>>>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
>>>>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>>>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>>>>>> Update nfs4_client to add:
>>>>>>>> . cl_cs_client_state: courtesy client state
>>>>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>>>>>
>>>>>>>> Modify alloc_client to initialize these fields.
>>>>>>>>
>>>>>>>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>>>>>>>> ---
>>>>>>>> fs/nfsd/nfs4state.c | 2 ++
>>>>>>>> fs/nfsd/nfsd.h | 1 +
>>>>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>>>>>> 3 files changed, 36 insertions(+)
>>>>>>>>
>>>>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>>>>>> index 234e852fcdfa..a65d59510681 100644
>>>>>>>> --- a/fs/nfsd/nfs4state.c
>>>>>>>> +++ b/fs/nfsd/nfs4state.c
>>>>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>>>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>>>>>> #ifdef CONFIG_NFSD_PNFS
>>>>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>>>>>> #endif
>>>>>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>>>>>> spin_lock_init(&clp->async_lock);
>>>>>>>> spin_lock_init(&clp->cl_lock);
>>>>>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>>>>>> return clp;
>>>>>>>> err_no_hashtbl:
>>>>>>>> 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..40e390abc842 100644
>>>>>>>> --- a/fs/nfsd/state.h
>>>>>>>> +++ b/fs/nfsd/state.h
>>>>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>>>>>> /*
>>>>>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>>>>>> + * -----------------------------------------------------------------------------
>>>>>>>> + * | false | false | false | Confirmed, active | Default |
>>>>>>>> + * |---------------------------------------------------------------------------|
>>>>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>>>>>> + * | | | | Lease/lock/share | |
>>>>>>>> + * | | | | reservation conflict | |
>>>>>>>> + * | | | | can cause Courtesy | |
>>>>>>>> + * | | | | client to be expired | |
>>>>>>>> + * |---------------------------------------------------------------------------|
>>>>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>>>>>> + * |---------------------------------------------------------------------------|
>>>>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>>>>>> + * | | | | reconnected, | |
>>>>>>>> + * | | | | becoming active | |
>>>>>>>> + * -----------------------------------------------------------------------------
>>>>> By the way, where is a client returned to the normal (0) state? That
>>>>> has to happen at some point.
>>>>
>>>> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
>>>> nfsd4_bind_conn_to_session.
>>>
>>> Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
>>> the question I asked.
>>
>> "reconnected" simply means the client has gotten back in touch.
>
> Again, my question was: when is cl_cs_client_state set back to 0? As
> far as I can tell, the answer is never. That means, even long after the
> client has reconnected, it's left in a weird state where it can be
> suddenly expired for all sorts of reasons.
Got it. Agreed, cl_cs_client_state should be reinitialized if
a courtesy client is transitioned back to "active".
Dai, would you add
+enum courtesy_client_state {
>>> NFSD4_CLIENT_ACTIVE = 0,
+ NFSD4_CLIENT_COURTESY,
+ NFSD4_CLIENT_EXPIRED,
+ NFSD4_CLIENT_RECONNECTED,
+};
And set cl_cs_client_state to ACTIVE where the client is
allowed to transition back to being active?
>> The server then has to decide whether to allow the client to
>> become active again or it needs to purge it. That decision
>> is different for each operation and minor version. Look for
>> "if (cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)" for how
>> those choices are made.
>>
>>
>>>>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
>>>>> a bind_conn_to_session fails).
>>>>
>>>> find_in_sessionid_hashtbl: we discard the courtesy client when it
>>>> reconnects and there is error from nfsd4_get_session_locked. This
>>>> should be a rare condition so rather than reverting the client
>>>> state back to courtesy, it is simpler just to discard it.
>>>
>>> That may be a rare situation, but I don't believe the behavior of
>>> discarding the client in this case is correct.
>>
>> Can you explain this? It's a courtesy client... the server can
>> decide it's expired at that point, can't it? IOW what breaks?
>
> I'm not worried about courtesy clients, I'm worried about clients that
> were courtesy clients but have since succesfully renewed their state.
> Expiring them for a failed bind_conn_to_session isn't right.
--
Chuck Lever
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 19:58 ` Chuck Lever III
@ 2022-03-29 20:01 ` Bruce Fields
2022-03-29 20:20 ` Chuck Lever III
2022-03-29 20:50 ` dai.ngo
0 siblings, 2 replies; 31+ messages in thread
From: Bruce Fields @ 2022-03-29 20:01 UTC (permalink / raw)
To: Chuck Lever III
Cc: Dai Ngo, Jeff Layton, Al Viro, Linux NFS Mailing List, linux-fsdevel
On Tue, Mar 29, 2022 at 07:58:46PM +0000, Chuck Lever III wrote:
> Got it. Agreed, cl_cs_client_state should be reinitialized if
> a courtesy client is transitioned back to "active".
>
> Dai, would you add
>
> +enum courtesy_client_state {
> >>> NFSD4_CLIENT_ACTIVE = 0,
> + NFSD4_CLIENT_COURTESY,
> + NFSD4_CLIENT_EXPIRED,
> + NFSD4_CLIENT_RECONNECTED,
> +};
>
> And set cl_cs_client_state to ACTIVE where the client is
> allowed to transition back to being active?
I'm not clear then what the RECONNECTED->ACTIVE transition would be.
My feeling is that the RECONNECTED state shouldn't exist, and that there
should only be a transition of EXPIRED back to ACTIVE.
--b.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 20:01 ` Bruce Fields
@ 2022-03-29 20:20 ` Chuck Lever III
2022-03-29 20:50 ` dai.ngo
1 sibling, 0 replies; 31+ messages in thread
From: Chuck Lever III @ 2022-03-29 20:20 UTC (permalink / raw)
To: Bruce Fields
Cc: Dai Ngo, Jeff Layton, Al Viro, Linux NFS Mailing List, linux-fsdevel
> On Mar 29, 2022, at 4:01 PM, Bruce Fields <bfields@fieldses.org> wrote:
>
> On Tue, Mar 29, 2022 at 07:58:46PM +0000, Chuck Lever III wrote:
>> Got it. Agreed, cl_cs_client_state should be reinitialized if
>> a courtesy client is transitioned back to "active".
>>
>> Dai, would you add
>>
>> +enum courtesy_client_state {
>>>>> NFSD4_CLIENT_ACTIVE = 0,
>> + NFSD4_CLIENT_COURTESY,
>> + NFSD4_CLIENT_EXPIRED,
>> + NFSD4_CLIENT_RECONNECTED,
>> +};
>>
>> And set cl_cs_client_state to ACTIVE where the client is
>> allowed to transition back to being active?
>
> I'm not clear then what the RECONNECTED->ACTIVE transition would be.
>
> My feeling is that the RECONNECTED state shouldn't exist, and that there
> should only be a transition of EXPIRED back to ACTIVE.
Audit the places that check for NFSD4_CLIENT_RECONNECTED.
Some of them will expire a reconnected client, some will
let it transition back to active. My impression from Dai
was that the server cannot transition a courtesy client
back to active in _every_ case.
If you can demonstrate that in every case where RECONNECTED
is found that a client should be transitioned to ACTIVE
rather than discarded, then yes, we should get rid of
RECONNECTED in favor of going from COURTESY -> ACTIVE.
--
Chuck Lever
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 20:01 ` Bruce Fields
2022-03-29 20:20 ` Chuck Lever III
@ 2022-03-29 20:50 ` dai.ngo
1 sibling, 0 replies; 31+ messages in thread
From: dai.ngo @ 2022-03-29 20:50 UTC (permalink / raw)
To: Bruce Fields, Chuck Lever III
Cc: Jeff Layton, Al Viro, Linux NFS Mailing List, linux-fsdevel
On 3/29/22 1:01 PM, Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 07:58:46PM +0000, Chuck Lever III wrote:
>> Got it. Agreed, cl_cs_client_state should be reinitialized if
>> a courtesy client is transitioned back to "active".
>>
>> Dai, would you add
>>
>> +enum courtesy_client_state {
>>>>> NFSD4_CLIENT_ACTIVE = 0,
>> + NFSD4_CLIENT_COURTESY,
>> + NFSD4_CLIENT_EXPIRED,
>> + NFSD4_CLIENT_RECONNECTED,
>> +};
>>
>> And set cl_cs_client_state to ACTIVE where the client is
>> allowed to transition back to being active?
fix in v19.
> I'm not clear then what the RECONNECTED->ACTIVE transition would be.
>
> My feeling is that the RECONNECTED state shouldn't exist, and that there
> should only be a transition of EXPIRED back to ACTIVE.
For the client to be truly active we need to create the client record.
We do not want to create the client record when we just detect that
the client reconnects because not all the callers want the client to
be active, we leave it for the callers to decide. Also some callers of
nfsd4_courtesy_clnt_expired hold the nn->client_lock so we can create
the client record there.
Leaving the NFSD4_CLIENT_RECONNECTED state set does not really
cause any functional problem since the RECONNECT state is meant
to used temporary within the context of the same request. But
I will reset the state back to NFSD4_CLIENT_ACTIVE for clarity.
-Dai
>
> --b.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 18:39 ` J. Bruce Fields
2022-03-29 19:32 ` Chuck Lever III
@ 2022-03-29 21:45 ` dai.ngo
2022-03-30 0:12 ` J. Bruce Fields
1 sibling, 1 reply; 31+ messages in thread
From: dai.ngo @ 2022-03-29 21:45 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 3/29/22 11:39 AM, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 11:19:51AM -0700, dai.ngo@oracle.com wrote:
>> On 3/29/22 9:30 AM, J. Bruce Fields wrote:
>>> On Tue, Mar 29, 2022 at 09:20:02AM -0700, dai.ngo@oracle.com wrote:
>>>> On 3/29/22 8:47 AM, J. Bruce Fields wrote:
>>>>> On Thu, Mar 24, 2022 at 09:34:42PM -0700, Dai Ngo wrote:
>>>>>> Update nfs4_client to add:
>>>>>> . cl_cs_client_state: courtesy client state
>>>>>> . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state
>>>>>> . cl_cs_list: list used by laundromat to process courtesy clients
>>>>>>
>>>>>> Modify alloc_client to initialize these fields.
>>>>>>
>>>>>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>>>>>> ---
>>>>>> fs/nfsd/nfs4state.c | 2 ++
>>>>>> fs/nfsd/nfsd.h | 1 +
>>>>>> fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++
>>>>>> 3 files changed, 36 insertions(+)
>>>>>>
>>>>>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>>>>>> index 234e852fcdfa..a65d59510681 100644
>>>>>> --- a/fs/nfsd/nfs4state.c
>>>>>> +++ b/fs/nfsd/nfs4state.c
>>>>>> @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
>>>>>> INIT_LIST_HEAD(&clp->cl_delegations);
>>>>>> INIT_LIST_HEAD(&clp->cl_lru);
>>>>>> INIT_LIST_HEAD(&clp->cl_revoked);
>>>>>> + INIT_LIST_HEAD(&clp->cl_cs_list);
>>>>>> #ifdef CONFIG_NFSD_PNFS
>>>>>> INIT_LIST_HEAD(&clp->cl_lo_states);
>>>>>> #endif
>>>>>> INIT_LIST_HEAD(&clp->async_copies);
>>>>>> spin_lock_init(&clp->async_lock);
>>>>>> spin_lock_init(&clp->cl_lock);
>>>>>> + spin_lock_init(&clp->cl_cs_lock);
>>>>>> rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
>>>>>> return clp;
>>>>>> err_no_hashtbl:
>>>>>> 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..40e390abc842 100644
>>>>>> --- a/fs/nfsd/state.h
>>>>>> +++ b/fs/nfsd/state.h
>>>>>> @@ -283,6 +283,35 @@ struct nfsd4_sessionid {
>>>>>> #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
>>>>>> /*
>>>>>> + * CLIENT_ CLIENT_ CLIENT_
>>>>>> + * COURTESY EXPIRED RECONNECTED Meaning Where set
>>>>>> + * -----------------------------------------------------------------------------
>>>>>> + * | false | false | false | Confirmed, active | Default |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | true | false | false | Courtesy state. | nfs4_get_client_reaplist |
>>>>>> + * | | | | Lease/lock/share | |
>>>>>> + * | | | | reservation conflict | |
>>>>>> + * | | | | can cause Courtesy | |
>>>>>> + * | | | | client to be expired | |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | true | false | Courtesy client to be| nfs4_laundromat |
>>>>>> + * | | | | expired by Laundromat| nfsd4_lm_lock_expired |
>>>>>> + * | | | | due to conflict | nfsd4_discard_courtesy_clnt |
>>>>>> + * | | | | | nfsd4_expire_courtesy_clnt |
>>>>>> + * |---------------------------------------------------------------------------|
>>>>>> + * | false | false | true | Courtesy client | nfsd4_courtesy_clnt_expired|
>>>>>> + * | | | | reconnected, | |
>>>>>> + * | | | | becoming active | |
>>>>>> + * -----------------------------------------------------------------------------
>>> By the way, where is a client returned to the normal (0) state? That
>>> has to happen at some point.
>> For 4.1 courtesy client reconnects is detected in nfsd4_sequence,
>> nfsd4_bind_conn_to_session.
> Those are the places where NFSD54_CLIENT_RECONNECTED is set, which isn't
> the question I asked.
>>> Why are RECONNECTED clients discarded in so many cases? (E.g. whenever
>>> a bind_conn_to_session fails).
>> find_in_sessionid_hashtbl: we discard the courtesy client when it
>> reconnects and there is error from nfsd4_get_session_locked. This
>> should be a rare condition so rather than reverting the client
>> state back to courtesy, it is simpler just to discard it.
> That may be a rare situation, but I don't believe the behavior of
> discarding the client in this case is correct.
>
>> nfsd4_create_session/find_confirmed_client: I think the only time
>> the courtesy client sends CREATE_SESSION, before sending the SEQUENCE
>> to reconnect after missing its leases, is when it wants to do clientid
>> trunking. This should be a rare condition so instead of dealing
>> with it we just do not allow it and discard the client for now.
> We can't wave away incorrect behavior with "but it's rare". Users with
> heavy and/or unusual workloads hit rare conditions. Clients may change
> their behavior over time. (E.g., trunking may become more common.)
This does not prevent the courtesy client from doing trunking in all
cases. It is only prevent the courtesy client from doing trunking without
first reconnect to the server.
I think this behavior is the same as if the server does not support courtesy
client; the server can expire the courtesy anytime it wants. If the
courtesy client reconnected successfully then by the time nfsd4_create_session/
find_confirmed_client is called the client already becomes active
so the server will process the request normally.
Also to handle cases when the courtesy client reconnects after it was in
EXPIRED state, we want to force the client to recover its state starting
with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.
-Dai
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-29 21:45 ` dai.ngo
@ 2022-03-30 0:12 ` J. Bruce Fields
2022-03-30 1:17 ` dai.ngo
0 siblings, 1 reply; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-30 0:12 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Tue, Mar 29, 2022 at 02:45:28PM -0700, dai.ngo@oracle.com wrote:
> This does not prevent the courtesy client from doing trunking in all
> cases. It is only prevent the courtesy client from doing trunking without
> first reconnect to the server.
>
> I think this behavior is the same as if the server does not support courtesy
> client; the server can expire the courtesy anytime it wants. If the
> courtesy client reconnected successfully then by the time nfsd4_create_session/
> find_confirmed_client is called the client already becomes active
> so the server will process the request normally.
I'm not sure what you mean here. All a client has to do to reconnect is
succesfully renew its lease. That doesn't necessarily require calling
CREATE_SESSION again.
> Also to handle cases when the courtesy client reconnects after it was in
> EXPIRED state, we want to force the client to recover its state starting
> with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.
The client should not have to send EXCHANGE_ID.
--b.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-30 0:12 ` J. Bruce Fields
@ 2022-03-30 1:17 ` dai.ngo
2022-03-30 1:48 ` J. Bruce Fields
0 siblings, 1 reply; 31+ messages in thread
From: dai.ngo @ 2022-03-30 1:17 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
[-- Attachment #1: Type: text/plain, Size: 1742 bytes --]
On 3/29/22 5:12 PM, J. Bruce Fields wrote:
> On Tue, Mar 29, 2022 at 02:45:28PM -0700, dai.ngo@oracle.com wrote:
>> This does not prevent the courtesy client from doing trunking in all
>> cases. It is only prevent the courtesy client from doing trunking without
>> first reconnect to the server.
>>
>> I think this behavior is the same as if the server does not support courtesy
>> client; the server can expire the courtesy anytime it wants. If the
>> courtesy client reconnected successfully then by the time nfsd4_create_session/
>> find_confirmed_client is called the client already becomes active
>> so the server will process the request normally.
> I'm not sure what you mean here. All a client has to do to reconnect is
> succesfully renew its lease.
For 4.1 the client renews its lease via the SEQUENCE, either stand-alone
or in a compound. Once the SEQUENCE completes successfully then the
subsequent CREATE_SESSION is processed normally. However, if the client
did not send the SEQUENCE first then server returns BAD_SESSION for the
CREATE_SESSION request.
> That doesn't necessarily require calling
> CREATE_SESSION again.
>
>> Also to handle cases when the courtesy client reconnects after it was in
>> EXPIRED state, we want to force the client to recover its state starting
>> with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.
> The client should not have to send EXCHANGE_ID.
For 4.1 the expired courtesy client must send EXCHANGE_ID to reconnect
to start new session. I don't see how the *expired* courtesy client can
access the export again without sending the EXCHANGE_ID. Attached is the
pcap that shows how the courtesy client recovers once it's in
CLIENT_EXPIRED state.
-Dai
>
> --b.
[-- Attachment #2: netpart-reconnect.pcap --]
[-- Type: application/octet-stream, Size: 66396 bytes --]
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server
2022-03-30 1:17 ` dai.ngo
@ 2022-03-30 1:48 ` J. Bruce Fields
0 siblings, 0 replies; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-30 1:48 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Tue, Mar 29, 2022 at 06:17:29PM -0700, dai.ngo@oracle.com wrote:
>
> On 3/29/22 5:12 PM, J. Bruce Fields wrote:
> >On Tue, Mar 29, 2022 at 02:45:28PM -0700, dai.ngo@oracle.com wrote:
> >>This does not prevent the courtesy client from doing trunking in all
> >>cases. It is only prevent the courtesy client from doing trunking without
> >>first reconnect to the server.
> >>
> >>I think this behavior is the same as if the server does not support courtesy
> >>client; the server can expire the courtesy anytime it wants. If the
> >>courtesy client reconnected successfully then by the time nfsd4_create_session/
> >>find_confirmed_client is called the client already becomes active
> >>so the server will process the request normally.
> >I'm not sure what you mean here. All a client has to do to reconnect is
> >succesfully renew its lease.
>
> For 4.1 the client renews its lease via the SEQUENCE, either stand-alone
> or in a compound. Once the SEQUENCE completes successfully then the
> subsequent CREATE_SESSION is processed normally. However, if the client
> did not send the SEQUENCE first then server returns BAD_SESSION for the
> CREATE_SESSION request.
>
> > That doesn't necessarily require calling
> >CREATE_SESSION again.
> >
> >>Also to handle cases when the courtesy client reconnects after it was in
> >>EXPIRED state, we want to force the client to recover its state starting
> >>with EXCHANGE_ID so we have to return BAD_SESSION on CREATE_SESSION request.
> >The client should not have to send EXCHANGE_ID.
>
> For 4.1 the expired courtesy client must send EXCHANGE_ID to reconnect
> to start new session. I don't see how the *expired* courtesy client can
> access the export again without sending the EXCHANGE_ID. Attached is the
> pcap that shows how the courtesy client recovers once it's in
> CLIENT_EXPIRED state.
Oh, sorry, sure, we're talking about an actual expired client. That's
fine.
--b.
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH RFC v18 03/11] NFSD: Add lm_lock_expired call out
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 01/11] fs/lock: add helper locks_owner_has_blockers to check for blockers Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 02/11] NFSD: Add courtesy client state, macro and spinlock to support courteous server Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients Dai Ngo
` (7 subsequent siblings)
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Add callout function nfsd4_lm_lock_expired for lm_lock_expired.
If lock request has conflict with courtesy client then expire the
courtesy client and return no conflict to caller.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 22 ++++++++++++++++++++++
fs/nfsd/state.h | 14 ++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a65d59510681..80772662236b 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6578,10 +6578,32 @@ nfsd4_lm_notify(struct file_lock *fl)
}
}
+/**
+ * nfsd4_lm_lock_expired - check if lock conflict can be resolved.
+ *
+ * @fl: pointer to file_lock with a potential conflict
+ * Return values:
+ * %false: real conflict, lock conflict can not be resolved.
+ * %true: no conflict, lock conflict was resolved.
+ *
+ * Note that this function is called while the flc_lock is held.
+ */
+static bool
+nfsd4_lm_lock_expired(struct file_lock *fl)
+{
+ struct nfs4_lockowner *lo;
+
+ if (!fl)
+ return false;
+ lo = (struct nfs4_lockowner *)fl->fl_owner;
+ return nfsd4_expire_courtesy_clnt(lo->lo_owner.so_client);
+}
+
static const struct lock_manager_operations nfsd_posix_mng_ops = {
.lm_notify = nfsd4_lm_notify,
.lm_get_owner = nfsd4_lm_get_owner,
.lm_put_owner = nfsd4_lm_put_owner,
+ .lm_lock_expired = nfsd4_lm_lock_expired,
};
static inline void
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 40e390abc842..d156ae3ab46c 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -735,4 +735,18 @@ 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
+nfsd4_expire_courtesy_clnt(struct nfs4_client *clp)
+{
+ bool rc = false;
+
+ spin_lock(&clp->cl_cs_lock);
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY)
+ clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED;
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED)
+ rc = true;
+ spin_unlock(&clp->cl_cs_lock);
+ return rc;
+}
+
#endif /* NFSD4_STATE_H */
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH RFC v18 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (2 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 03/11] NFSD: Add lm_lock_expired call out Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client Dai Ngo
` (6 subsequent siblings)
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Update nfsd_breaker_owns_lease() to handle delegation conflict with
courtesy clients by calling nfsd4_expire_courtesy_clnt.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 80772662236b..f20c75890594 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4727,6 +4727,9 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl)
struct svc_rqst *rqst;
struct nfs4_client *clp;
+ if (nfsd4_expire_courtesy_clnt(dl->dl_stid.sc_client))
+ return true;
+
if (!i_am_nfsd())
return false;
rqst = kthread_data(current);
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH RFC v18 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (3 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-29 15:24 ` J. Bruce Fields
2022-03-25 4:34 ` [PATCH RFC v18 06/11] NFSD: Update find_clp_in_name_tree() " Dai Ngo
` (5 subsequent siblings)
10 siblings, 1 reply; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
reservation conflict with courtesy client.
Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
reservation conflict with courtesy client.
When we have deny/access conflict we walk the fi_stateids of the
file in question, looking for open stateid and check the deny/access
of that stateid against the one from the open request. If there is
a conflict then we check if the client that owns that stateid is
a courtesy client. If it is then we set the client state to
CLIENT_EXPIRED and allow the open request to continue. We have
to scan all the stateid's of the file since the conflict can be
caused by multiple open stateid's.
Client with CLIENT_EXPIRED is expired by the laundromat.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 85 +++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 72 insertions(+), 13 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index f20c75890594..fe8969ba94b3 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -701,9 +701,56 @@ __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
atomic_inc(&fp->fi_access[O_RDONLY]);
}
+/*
+ * 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;
+ struct nfs4_client *clp;
+ bool conflict = true;
+ unsigned char bmap;
+
+ 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 (nfsd4_expire_courtesy_clnt(clp))
+ continue;
+ conflict = false;
+ break;
+ }
+ return conflict;
+}
+
static __be32
-nfs4_file_get_access(struct nfs4_file *fp, u32 access)
+nfs4_file_get_access(struct nfs4_file *fp, u32 access,
+ struct nfs4_ol_stateid *stp, bool new_stp)
{
+
lockdep_assert_held(&fp->fi_lock);
/* Does this access mode make sense? */
@@ -711,15 +758,21 @@ nfs4_file_get_access(struct nfs4_file *fp, u32 access)
return nfserr_inval;
/* Does it conflict with a deny mode already set? */
- if ((access & fp->fi_share_deny) != 0)
- return nfserr_share_denied;
+ if ((access & fp->fi_share_deny) != 0) {
+ if (!nfs4_resolve_deny_conflicts_locked(fp, new_stp,
+ stp, access, true))
+ return nfserr_share_denied;
+ }
__nfs4_file_get_access(fp, access);
return nfs_ok;
}
-static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny)
+static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny,
+ struct nfs4_ol_stateid *stp, bool new_stp)
{
+ __be32 rc = nfs_ok;
+
/* Common case is that there is no deny mode. */
if (deny) {
/* Does this deny mode make sense? */
@@ -728,13 +781,19 @@ static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny)
if ((deny & NFS4_SHARE_DENY_READ) &&
atomic_read(&fp->fi_access[O_RDONLY]))
- return nfserr_share_denied;
+ rc = nfserr_share_denied;
if ((deny & NFS4_SHARE_DENY_WRITE) &&
atomic_read(&fp->fi_access[O_WRONLY]))
- return nfserr_share_denied;
+ rc = nfserr_share_denied;
+
+ if (rc == nfserr_share_denied) {
+ if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
+ stp, deny, false))
+ rc = nfs_ok;
+ }
}
- return nfs_ok;
+ return rc;
}
static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag)
@@ -4952,7 +5011,7 @@ 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;
@@ -4966,14 +5025,14 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
* Are we trying to set a deny mode that would conflict with
* current access?
*/
- status = nfs4_file_check_deny(fp, open->op_share_deny);
+ status = nfs4_file_check_deny(fp, open->op_share_deny, stp, new_stp);
if (status != nfs_ok) {
spin_unlock(&fp->fi_lock);
goto out;
}
/* set access to the file */
- status = nfs4_file_get_access(fp, open->op_share_access);
+ status = nfs4_file_get_access(fp, open->op_share_access, stp, new_stp);
if (status != nfs_ok) {
spin_unlock(&fp->fi_lock);
goto out;
@@ -5027,11 +5086,11 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c
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);
+ status = nfs4_file_check_deny(fp, open->op_share_deny, stp, false);
if (status == nfs_ok) {
set_deny(open->op_share_deny, stp);
fp->fi_share_deny |=
@@ -5376,7 +5435,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);
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client
2022-03-25 4:34 ` [PATCH RFC v18 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client Dai Ngo
@ 2022-03-29 15:24 ` J. Bruce Fields
2022-03-29 16:06 ` dai.ngo
0 siblings, 1 reply; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-29 15:24 UTC (permalink / raw)
To: Dai Ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Thu, Mar 24, 2022 at 09:34:45PM -0700, Dai Ngo wrote:
> Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
> reservation conflict with courtesy client.
>
> Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
> reservation conflict with courtesy client.
>
> When we have deny/access conflict we walk the fi_stateids of the
> file in question, looking for open stateid and check the deny/access
> of that stateid against the one from the open request. If there is
> a conflict then we check if the client that owns that stateid is
> a courtesy client. If it is then we set the client state to
> CLIENT_EXPIRED and allow the open request to continue. We have
> to scan all the stateid's of the file since the conflict can be
> caused by multiple open stateid's.
>
> Client with CLIENT_EXPIRED is expired by the laundromat.
>
> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> ---
> fs/nfsd/nfs4state.c | 85 +++++++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 72 insertions(+), 13 deletions(-)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index f20c75890594..fe8969ba94b3 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -701,9 +701,56 @@ __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
> atomic_inc(&fp->fi_access[O_RDONLY]);
> }
>
> +/*
> + * 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;
> + struct nfs4_client *clp;
> + bool conflict = true;
> + unsigned char bmap;
> +
> + 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;
As I said before, I recommend just doing *both* checks here. Then you
can remove the "bool share_access" argument. I think that'll make the
code easier to read.
Otherwise, this version looks OK to me, thanks for the revisions.
--b.
> + clp = st->st_stid.sc_client;
> + if (nfsd4_expire_courtesy_clnt(clp))
> + continue;
> + conflict = false;
> + break;
> + }
> + return conflict;
> +}
> +
> static __be32
> -nfs4_file_get_access(struct nfs4_file *fp, u32 access)
> +nfs4_file_get_access(struct nfs4_file *fp, u32 access,
> + struct nfs4_ol_stateid *stp, bool new_stp)
> {
> +
> lockdep_assert_held(&fp->fi_lock);
>
> /* Does this access mode make sense? */
> @@ -711,15 +758,21 @@ nfs4_file_get_access(struct nfs4_file *fp, u32 access)
> return nfserr_inval;
>
> /* Does it conflict with a deny mode already set? */
> - if ((access & fp->fi_share_deny) != 0)
> - return nfserr_share_denied;
> + if ((access & fp->fi_share_deny) != 0) {
> + if (!nfs4_resolve_deny_conflicts_locked(fp, new_stp,
> + stp, access, true))
> + return nfserr_share_denied;
> + }
>
> __nfs4_file_get_access(fp, access);
> return nfs_ok;
> }
>
> -static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny)
> +static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny,
> + struct nfs4_ol_stateid *stp, bool new_stp)
> {
> + __be32 rc = nfs_ok;
> +
> /* Common case is that there is no deny mode. */
> if (deny) {
> /* Does this deny mode make sense? */
> @@ -728,13 +781,19 @@ static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny)
>
> if ((deny & NFS4_SHARE_DENY_READ) &&
> atomic_read(&fp->fi_access[O_RDONLY]))
> - return nfserr_share_denied;
> + rc = nfserr_share_denied;
>
> if ((deny & NFS4_SHARE_DENY_WRITE) &&
> atomic_read(&fp->fi_access[O_WRONLY]))
> - return nfserr_share_denied;
> + rc = nfserr_share_denied;
> +
> + if (rc == nfserr_share_denied) {
> + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
> + stp, deny, false))
> + rc = nfs_ok;
> + }
> }
> - return nfs_ok;
> + return rc;
> }
>
> static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag)
> @@ -4952,7 +5011,7 @@ 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;
> @@ -4966,14 +5025,14 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
> * Are we trying to set a deny mode that would conflict with
> * current access?
> */
> - status = nfs4_file_check_deny(fp, open->op_share_deny);
> + status = nfs4_file_check_deny(fp, open->op_share_deny, stp, new_stp);
> if (status != nfs_ok) {
> spin_unlock(&fp->fi_lock);
> goto out;
> }
>
> /* set access to the file */
> - status = nfs4_file_get_access(fp, open->op_share_access);
> + status = nfs4_file_get_access(fp, open->op_share_access, stp, new_stp);
> if (status != nfs_ok) {
> spin_unlock(&fp->fi_lock);
> goto out;
> @@ -5027,11 +5086,11 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c
> 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);
> + status = nfs4_file_check_deny(fp, open->op_share_deny, stp, false);
> if (status == nfs_ok) {
> set_deny(open->op_share_deny, stp);
> fp->fi_share_deny |=
> @@ -5376,7 +5435,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);
> --
> 2.9.5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client
2022-03-29 15:24 ` J. Bruce Fields
@ 2022-03-29 16:06 ` dai.ngo
2022-03-29 16:11 ` J. Bruce Fields
0 siblings, 1 reply; 31+ messages in thread
From: dai.ngo @ 2022-03-29 16:06 UTC (permalink / raw)
To: J. Bruce Fields; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On 3/29/22 8:24 AM, J. Bruce Fields wrote:
> On Thu, Mar 24, 2022 at 09:34:45PM -0700, Dai Ngo wrote:
>> Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
>> reservation conflict with courtesy client.
>>
>> Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
>> reservation conflict with courtesy client.
>>
>> When we have deny/access conflict we walk the fi_stateids of the
>> file in question, looking for open stateid and check the deny/access
>> of that stateid against the one from the open request. If there is
>> a conflict then we check if the client that owns that stateid is
>> a courtesy client. If it is then we set the client state to
>> CLIENT_EXPIRED and allow the open request to continue. We have
>> to scan all the stateid's of the file since the conflict can be
>> caused by multiple open stateid's.
>>
>> Client with CLIENT_EXPIRED is expired by the laundromat.
>>
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>> fs/nfsd/nfs4state.c | 85 +++++++++++++++++++++++++++++++++++++++++++++--------
>> 1 file changed, 72 insertions(+), 13 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index f20c75890594..fe8969ba94b3 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -701,9 +701,56 @@ __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
>> atomic_inc(&fp->fi_access[O_RDONLY]);
>> }
>>
>> +/*
>> + * 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;
>> + struct nfs4_client *clp;
>> + bool conflict = true;
>> + unsigned char bmap;
>> +
>> + 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;
> As I said before, I recommend just doing *both* checks here. Then you
> can remove the "bool share_access" argument. I think that'll make the
> code easier to read.
Bruce, I'm not clear how to check both here as I mentioned in my previous
email.
nfs4_resolve_deny_conflicts_locked is called from nfs4_file_get_access
and nfs4_file_check_deny to check either access or deny mode separately
so how do we check both access and deny in nfs4_resolve_deny_conflicts_locked?
Thanks,
-Dai
>
> Otherwise, this version looks OK to me, thanks for the revisions.
>
> --b.
>
>> + clp = st->st_stid.sc_client;
>> + if (nfsd4_expire_courtesy_clnt(clp))
>> + continue;
>> + conflict = false;
>> + break;
>> + }
>> + return conflict;
>> +}
>> +
>> static __be32
>> -nfs4_file_get_access(struct nfs4_file *fp, u32 access)
>> +nfs4_file_get_access(struct nfs4_file *fp, u32 access,
>> + struct nfs4_ol_stateid *stp, bool new_stp)
>> {
>> +
>> lockdep_assert_held(&fp->fi_lock);
>>
>> /* Does this access mode make sense? */
>> @@ -711,15 +758,21 @@ nfs4_file_get_access(struct nfs4_file *fp, u32 access)
>> return nfserr_inval;
>>
>> /* Does it conflict with a deny mode already set? */
>> - if ((access & fp->fi_share_deny) != 0)
>> - return nfserr_share_denied;
>> + if ((access & fp->fi_share_deny) != 0) {
>> + if (!nfs4_resolve_deny_conflicts_locked(fp, new_stp,
>> + stp, access, true))
>> + return nfserr_share_denied;
>> + }
>>
>> __nfs4_file_get_access(fp, access);
>> return nfs_ok;
>> }
>>
>> -static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny)
>> +static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny,
>> + struct nfs4_ol_stateid *stp, bool new_stp)
>> {
>> + __be32 rc = nfs_ok;
>> +
>> /* Common case is that there is no deny mode. */
>> if (deny) {
>> /* Does this deny mode make sense? */
>> @@ -728,13 +781,19 @@ static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny)
>>
>> if ((deny & NFS4_SHARE_DENY_READ) &&
>> atomic_read(&fp->fi_access[O_RDONLY]))
>> - return nfserr_share_denied;
>> + rc = nfserr_share_denied;
>>
>> if ((deny & NFS4_SHARE_DENY_WRITE) &&
>> atomic_read(&fp->fi_access[O_WRONLY]))
>> - return nfserr_share_denied;
>> + rc = nfserr_share_denied;
>> +
>> + if (rc == nfserr_share_denied) {
>> + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp,
>> + stp, deny, false))
>> + rc = nfs_ok;
>> + }
>> }
>> - return nfs_ok;
>> + return rc;
>> }
>>
>> static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag)
>> @@ -4952,7 +5011,7 @@ 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;
>> @@ -4966,14 +5025,14 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
>> * Are we trying to set a deny mode that would conflict with
>> * current access?
>> */
>> - status = nfs4_file_check_deny(fp, open->op_share_deny);
>> + status = nfs4_file_check_deny(fp, open->op_share_deny, stp, new_stp);
>> if (status != nfs_ok) {
>> spin_unlock(&fp->fi_lock);
>> goto out;
>> }
>>
>> /* set access to the file */
>> - status = nfs4_file_get_access(fp, open->op_share_access);
>> + status = nfs4_file_get_access(fp, open->op_share_access, stp, new_stp);
>> if (status != nfs_ok) {
>> spin_unlock(&fp->fi_lock);
>> goto out;
>> @@ -5027,11 +5086,11 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c
>> 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);
>> + status = nfs4_file_check_deny(fp, open->op_share_deny, stp, false);
>> if (status == nfs_ok) {
>> set_deny(open->op_share_deny, stp);
>> fp->fi_share_deny |=
>> @@ -5376,7 +5435,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);
>> --
>> 2.9.5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH RFC v18 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client
2022-03-29 16:06 ` dai.ngo
@ 2022-03-29 16:11 ` J. Bruce Fields
0 siblings, 0 replies; 31+ messages in thread
From: J. Bruce Fields @ 2022-03-29 16:11 UTC (permalink / raw)
To: dai.ngo; +Cc: chuck.lever, jlayton, viro, linux-nfs, linux-fsdevel
On Tue, Mar 29, 2022 at 09:06:23AM -0700, dai.ngo@oracle.com wrote:
>
> On 3/29/22 8:24 AM, J. Bruce Fields wrote:
> >On Thu, Mar 24, 2022 at 09:34:45PM -0700, Dai Ngo wrote:
> >>Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
> >>reservation conflict with courtesy client.
> >>
> >>Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share
> >>reservation conflict with courtesy client.
> >>
> >>When we have deny/access conflict we walk the fi_stateids of the
> >>file in question, looking for open stateid and check the deny/access
> >>of that stateid against the one from the open request. If there is
> >>a conflict then we check if the client that owns that stateid is
> >>a courtesy client. If it is then we set the client state to
> >>CLIENT_EXPIRED and allow the open request to continue. We have
> >>to scan all the stateid's of the file since the conflict can be
> >>caused by multiple open stateid's.
> >>
> >>Client with CLIENT_EXPIRED is expired by the laundromat.
> >>
> >>Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> >>---
> >> fs/nfsd/nfs4state.c | 85 +++++++++++++++++++++++++++++++++++++++++++++--------
> >> 1 file changed, 72 insertions(+), 13 deletions(-)
> >>
> >>diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>index f20c75890594..fe8969ba94b3 100644
> >>--- a/fs/nfsd/nfs4state.c
> >>+++ b/fs/nfsd/nfs4state.c
> >>@@ -701,9 +701,56 @@ __nfs4_file_get_access(struct nfs4_file *fp, u32 access)
> >> atomic_inc(&fp->fi_access[O_RDONLY]);
> >> }
> >>+/*
> >>+ * 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;
> >>+ struct nfs4_client *clp;
> >>+ bool conflict = true;
> >>+ unsigned char bmap;
> >>+
> >>+ 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;
> >As I said before, I recommend just doing *both* checks here. Then you
> >can remove the "bool share_access" argument. I think that'll make the
> >code easier to read.
>
> Bruce, I'm not clear how to check both here as I mentioned in my previous
> email.
>
> nfs4_resolve_deny_conflicts_locked is called from nfs4_file_get_access
> and nfs4_file_check_deny to check either access or deny mode separately
> so how do we check both access and deny in nfs4_resolve_deny_conflicts_locked?
Sorry, I forgot.
Uh, I guess on a quick skim I don't see a way to do that nicely, so,
fine, I'm OK with it as is.
--b.
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH RFC v18 06/11] NFSD: Update find_clp_in_name_tree() to handle courtesy client
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (4 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy client Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 07/11] NFSD: Update find_in_sessionid_hashtbl() " Dai Ngo
` (4 subsequent siblings)
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Update find_clp_in_name_tree to check and expire courtesy client.
Update find_confirmed_client_by_name to discard the courtesy
client by setting CLIENT_EXPIRED.
Update nfsd4_setclientid to expire client with CLIENT_EXPIRED
state to prevent multiple confirmed clients with the same name
on the conf_name_tree.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 27 ++++++++++++++++++++++++---
fs/nfsd/state.h | 22 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index fe8969ba94b3..eadce5d19473 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2893,8 +2893,11 @@ find_clp_in_name_tree(struct xdr_netobj *name, struct rb_root *root)
node = node->rb_left;
else if (cmp < 0)
node = node->rb_right;
- else
+ else {
+ if (nfsd4_courtesy_clnt_expired(clp))
+ return NULL;
return clp;
+ }
}
return NULL;
}
@@ -2973,8 +2976,15 @@ static bool clp_used_exchangeid(struct nfs4_client *clp)
static struct nfs4_client *
find_confirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn)
{
+ struct nfs4_client *clp;
+
lockdep_assert_held(&nn->client_lock);
- return find_clp_in_name_tree(name, &nn->conf_name_tree);
+ clp = find_clp_in_name_tree(name, &nn->conf_name_tree);
+ if (clp && clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ nfsd4_discard_courtesy_clnt(clp);
+ clp = NULL;
+ }
+ return clp;
}
static struct nfs4_client *
@@ -4091,12 +4101,19 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfs4_client *unconf = NULL;
__be32 status;
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+ struct nfs4_client *cclient = NULL;
new = create_client(clname, rqstp, &clverifier);
if (new == NULL)
return nfserr_jukebox;
spin_lock(&nn->client_lock);
- conf = find_confirmed_client_by_name(&clname, nn);
+ /* find confirmed client by name */
+ conf = find_clp_in_name_tree(&clname, &nn->conf_name_tree);
+ if (conf && conf->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ cclient = conf;
+ conf = NULL;
+ }
+
if (conf && client_has_state(conf)) {
status = nfserr_clid_inuse;
if (clp_used_exchangeid(conf))
@@ -4127,7 +4144,11 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
new = NULL;
status = nfs_ok;
out:
+ if (cclient)
+ unhash_client_locked(cclient);
spin_unlock(&nn->client_lock);
+ if (cclient)
+ expire_client(cclient);
if (new)
free_client(new);
if (unconf) {
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index d156ae3ab46c..14b2c158ccca 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -735,6 +735,7 @@ 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);
+/* courteous server */
static inline bool
nfsd4_expire_courtesy_clnt(struct nfs4_client *clp)
{
@@ -749,4 +750,25 @@ nfsd4_expire_courtesy_clnt(struct nfs4_client *clp)
return rc;
}
+static inline void
+nfsd4_discard_courtesy_clnt(struct nfs4_client *clp)
+{
+ spin_lock(&clp->cl_cs_lock);
+ clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED;
+ spin_unlock(&clp->cl_cs_lock);
+}
+
+static inline bool
+nfsd4_courtesy_clnt_expired(struct nfs4_client *clp)
+{
+ bool rc = false;
+
+ spin_lock(&clp->cl_cs_lock);
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED)
+ rc = true;
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY)
+ clp->cl_cs_client_state = NFSD4_CLIENT_RECONNECTED;
+ spin_unlock(&clp->cl_cs_lock);
+ return rc;
+}
#endif /* NFSD4_STATE_H */
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH RFC v18 07/11] NFSD: Update find_in_sessionid_hashtbl() to handle courtesy client
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (5 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 06/11] NFSD: Update find_clp_in_name_tree() " Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 08/11] NFSD: Update find_client_in_id_table() " Dai Ngo
` (3 subsequent siblings)
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Update find_in_sessionid_hashtbl to:
. skip client with CLIENT_EXPIRED state; discarded courtesy client.
. if courtesy client was found then set CLIENT_RECONNECTED so caller
can take appropriate action.
Update nfsd4_sequence and nfsd4_bind_conn_to_session to create client
record for courtesy client with CLIENT_RECONNECTED state.
Update nfsd4_destroy_session to discard courtesy client with
CLIENT_RECONNECTED state.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index eadce5d19473..3e9cdc4a4a47 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1994,13 +1994,22 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net,
{
struct nfsd4_session *session;
__be32 status = nfserr_badsession;
+ struct nfs4_client *clp;
session = __find_in_sessionid_hashtbl(sessionid, net);
if (!session)
goto out;
+ clp = session->se_client;
+ if (nfsd4_courtesy_clnt_expired(clp)) {
+ session = NULL;
+ goto out;
+ }
status = nfsd4_get_session_locked(session);
- if (status)
+ if (status) {
session = NULL;
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)
+ nfsd4_discard_courtesy_clnt(clp);
+ }
out:
*ret = status;
return session;
@@ -3702,6 +3711,7 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp,
struct nfsd4_session *session;
struct net *net = SVC_NET(rqstp);
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+ struct nfs4_client *clp;
if (!nfsd4_last_compound_op(rqstp))
return nfserr_not_only_op;
@@ -3734,6 +3744,13 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp,
nfsd4_init_conn(rqstp, conn, session);
status = nfs_ok;
out:
+ clp = session->se_client;
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ if (status == nfs_ok)
+ nfsd4_client_record_create(clp);
+ else
+ nfsd4_discard_courtesy_clnt(clp);
+ }
nfsd4_put_session(session);
out_no_session:
return status;
@@ -3756,6 +3773,7 @@ nfsd4_destroy_session(struct svc_rqst *r, struct nfsd4_compound_state *cstate,
int ref_held_by_me = 0;
struct net *net = SVC_NET(r);
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+ struct nfs4_client *clp;
status = nfserr_not_only_op;
if (nfsd4_compound_in_session(cstate, sessionid)) {
@@ -3768,6 +3786,12 @@ nfsd4_destroy_session(struct svc_rqst *r, struct nfsd4_compound_state *cstate,
ses = find_in_sessionid_hashtbl(sessionid, net, &status);
if (!ses)
goto out_client_lock;
+ clp = ses->se_client;
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ status = nfserr_badsession;
+ nfsd4_discard_courtesy_clnt(clp);
+ goto out_put_session;
+ }
status = nfserr_wrong_cred;
if (!nfsd4_mach_creds_match(ses->se_client, r))
goto out_put_session;
@@ -3872,7 +3896,7 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_compoundres *resp = rqstp->rq_resp;
struct xdr_stream *xdr = resp->xdr;
struct nfsd4_session *session;
- struct nfs4_client *clp;
+ struct nfs4_client *clp = NULL;
struct nfsd4_slot *slot;
struct nfsd4_conn *conn;
__be32 status;
@@ -3982,6 +4006,12 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
if (conn)
free_conn(conn);
spin_unlock(&nn->client_lock);
+ if (clp && clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ if (status == nfs_ok)
+ nfsd4_client_record_create(clp);
+ else
+ nfsd4_discard_courtesy_clnt(clp);
+ }
return status;
out_put_session:
nfsd4_put_session_locked(session);
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH RFC v18 08/11] NFSD: Update find_client_in_id_table() to handle courtesy client
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (6 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 07/11] NFSD: Update find_in_sessionid_hashtbl() " Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 09/11] NFSD: Refactor nfsd4_laundromat() Dai Ngo
` (2 subsequent siblings)
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Update find_client_in_id_table to:
. skip client with CLIENT_EXPIRED; discarded courtesy client
. if courtesy client was found then set CLIENT_RECONNECTED
state so caller can take appropriate action.
Update find_confirmed_client to discard courtesy client.
Update lookup_clientid to call find_client_in_id_table directly.
Update set_client to create client record for courtesy client.
Update find_cpntf_state to discard courtesy client.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 3e9cdc4a4a47..fe34d6780713 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2952,6 +2952,8 @@ find_client_in_id_table(struct list_head *tbl, clientid_t *clid, bool sessions)
if (same_clid(&clp->cl_clientid, clid)) {
if ((bool)clp->cl_minorversion != sessions)
return NULL;
+ if (nfsd4_courtesy_clnt_expired(clp))
+ continue;
renew_client_locked(clp);
return clp;
}
@@ -2963,9 +2965,15 @@ static struct nfs4_client *
find_confirmed_client(clientid_t *clid, bool sessions, struct nfsd_net *nn)
{
struct list_head *tbl = nn->conf_id_hashtbl;
+ struct nfs4_client *clp;
lockdep_assert_held(&nn->client_lock);
- return find_client_in_id_table(tbl, clid, sessions);
+ clp = find_client_in_id_table(tbl, clid, sessions);
+ if (clp && clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ nfsd4_discard_courtesy_clnt(clp);
+ clp = NULL;
+ }
+ return clp;
}
static struct nfs4_client *
@@ -4881,9 +4889,10 @@ static struct nfs4_client *lookup_clientid(clientid_t *clid, bool sessions,
struct nfsd_net *nn)
{
struct nfs4_client *found;
+ struct list_head *tbl = nn->conf_id_hashtbl;
spin_lock(&nn->client_lock);
- found = find_confirmed_client(clid, sessions, nn);
+ found = find_client_in_id_table(tbl, clid, sessions);
if (found)
atomic_inc(&found->cl_rpc_users);
spin_unlock(&nn->client_lock);
@@ -4908,6 +4917,8 @@ static __be32 set_client(clientid_t *clid,
cstate->clp = lookup_clientid(clid, false, nn);
if (!cstate->clp)
return nfserr_expired;
+ if (cstate->clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED)
+ nfsd4_client_record_create(cstate->clp);
return nfs_ok;
}
@@ -6144,6 +6155,13 @@ static __be32 find_cpntf_state(struct nfsd_net *nn, stateid_t *st,
found = lookup_clientid(&cps->cp_p_clid, true, nn);
if (!found)
goto out;
+ if (found->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) {
+ nfsd4_discard_courtesy_clnt(found);
+ if (atomic_dec_and_lock(&found->cl_rpc_users,
+ &nn->client_lock))
+ spin_unlock(&nn->client_lock);
+ goto out;
+ }
*stid = find_stateid_by_type(found, &cps->cp_p_stateid,
NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID);
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH RFC v18 09/11] NFSD: Refactor nfsd4_laundromat()
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (7 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 08/11] NFSD: Update find_client_in_id_table() " Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 10/11] NFSD: Update laundromat to handle courtesy clients Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 11/11] NFSD: Show state of courtesy clients in client info Dai Ngo
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Extract a bit of logic that is about to be expanded to handle
courtesy clients.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index fe34d6780713..4c3f14afb69a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -5731,6 +5731,26 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
}
#endif
+static void
+nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist,
+ struct laundry_time *lt)
+{
+ struct list_head *pos, *next;
+ struct nfs4_client *clp;
+
+ INIT_LIST_HEAD(reaplist);
+ spin_lock(&nn->client_lock);
+ list_for_each_safe(pos, next, &nn->client_lru) {
+ clp = list_entry(pos, struct nfs4_client, cl_lru);
+ if (!state_expired(lt, clp->cl_time))
+ break;
+ if (mark_client_expired_locked(clp))
+ continue;
+ list_add(&clp->cl_lru, reaplist);
+ }
+ spin_unlock(&nn->client_lock);
+}
+
static time64_t
nfs4_laundromat(struct nfsd_net *nn)
{
@@ -5753,7 +5773,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) {
@@ -5763,17 +5782,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);
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH RFC v18 10/11] NFSD: Update laundromat to handle courtesy clients
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (8 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 09/11] NFSD: Refactor nfsd4_laundromat() Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
2022-03-25 4:34 ` [PATCH RFC v18 11/11] NFSD: Show state of courtesy clients in client info Dai Ngo
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 UTC (permalink / raw)
To: chuck.lever, bfields; +Cc: jlayton, viro, linux-nfs, linux-fsdevel
Add nfs4_anylock_blocker and nfs4_lockowner_has_blockers to check
if an expired client has any lock blockers
Update nfs4_get_client_reaplist to:
. add courtesy client in CLIENT_EXPIRED state to reaplist.
. detect if expired client still has state and no blockers then
transit it to courtesy client by setting CLIENT_COURTESY state
and removing the client record.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
fs/nfsd/nfs4state.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 91 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 4c3f14afb69a..6169cbb74d31 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -5731,24 +5731,106 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
}
#endif
+/* Check if any lock belonging to this lockowner has any blockers */
+static bool
+nfs4_lockowner_has_blockers(struct nfs4_lockowner *lo)
+{
+ struct file_lock_context *ctx;
+ struct nfs4_ol_stateid *stp;
+ struct nfs4_file *nf;
+
+ list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) {
+ nf = stp->st_stid.sc_file;
+ ctx = nf->fi_inode->i_flctx;
+ if (!ctx)
+ continue;
+ if (locks_owner_has_blockers(ctx, lo))
+ return true;
+ }
+ return false;
+}
+
+static bool
+nfs4_anylock_blockers(struct nfs4_client *clp)
+{
+ int i;
+ struct nfs4_stateowner *so;
+ struct nfs4_lockowner *lo;
+
+ spin_lock(&clp->cl_lock);
+ for (i = 0; i < OWNER_HASH_SIZE; i++) {
+ list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[i],
+ so_strhash) {
+ if (so->so_is_open_owner)
+ continue;
+ lo = lockowner(so);
+ if (nfs4_lockowner_has_blockers(lo)) {
+ spin_unlock(&clp->cl_lock);
+ return true;
+ }
+ }
+ }
+ spin_unlock(&clp->cl_lock);
+ return false;
+}
+
static void
nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist,
struct laundry_time *lt)
{
struct list_head *pos, *next;
struct nfs4_client *clp;
+ bool cour;
+ struct list_head cslist;
INIT_LIST_HEAD(reaplist);
+ INIT_LIST_HEAD(&cslist);
spin_lock(&nn->client_lock);
list_for_each_safe(pos, next, &nn->client_lru) {
clp = list_entry(pos, struct nfs4_client, cl_lru);
if (!state_expired(lt, clp->cl_time))
break;
- if (mark_client_expired_locked(clp))
+
+ if (!client_has_state(clp))
+ goto exp_client;
+
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED)
+ goto exp_client;
+ cour = (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY);
+ if (cour && ktime_get_boottime_seconds() >=
+ (clp->cl_time + NFSD_COURTESY_CLIENT_TIMEOUT))
+ goto exp_client;
+ if (nfs4_anylock_blockers(clp)) {
+exp_client:
+ if (mark_client_expired_locked(clp))
+ continue;
+ list_add(&clp->cl_lru, reaplist);
continue;
- list_add(&clp->cl_lru, reaplist);
+ }
+ if (!cour) {
+ spin_lock(&clp->cl_cs_lock);
+ clp->cl_cs_client_state = NFSD4_CLIENT_COURTESY;
+ spin_unlock(&clp->cl_cs_lock);
+ list_add(&clp->cl_cs_list, &cslist);
+ }
}
spin_unlock(&nn->client_lock);
+
+ while (!list_empty(&cslist)) {
+ clp = list_first_entry(&cslist, struct nfs4_client, cl_cs_list);
+ list_del_init(&clp->cl_cs_list);
+ spin_lock(&clp->cl_cs_lock);
+ /*
+ * Client might have re-connected. Make sure it's
+ * still in courtesy state before removing its record.
+ */
+ if (clp->cl_cs_client_state != NFSD4_CLIENT_COURTESY) {
+ spin_unlock(&clp->cl_cs_lock);
+ continue;
+ }
+ spin_unlock(&clp->cl_cs_lock);
+ nfsd4_client_record_remove(clp);
+ }
}
static time64_t
@@ -5794,6 +5876,13 @@ nfs4_laundromat(struct nfsd_net *nn)
dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
if (!state_expired(<, dp->dl_time))
break;
+ spin_lock(&clp->cl_cs_lock);
+ if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY) {
+ clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED;
+ spin_unlock(&clp->cl_cs_lock);
+ continue;
+ }
+ spin_unlock(&clp->cl_cs_lock);
WARN_ON(!unhash_delegation_locked(dp));
list_add(&dp->dl_recall_lru, &reaplist);
}
--
2.9.5
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH RFC v18 11/11] NFSD: Show state of courtesy clients in client info
2022-03-25 4:34 [PATCH RFC v18 0/11] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
` (9 preceding siblings ...)
2022-03-25 4:34 ` [PATCH RFC v18 10/11] NFSD: Update laundromat to handle courtesy clients Dai Ngo
@ 2022-03-25 4:34 ` Dai Ngo
10 siblings, 0 replies; 31+ messages in thread
From: Dai Ngo @ 2022-03-25 4:34 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 | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 6169cbb74d31..5f003271004c 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2470,7 +2470,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)
@@ -2478,10 +2479,17 @@ 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_cs_client_state == NFSD4_CLIENT_COURTESY)
+ seq_puts(m, "status: courtesy\n");
+ else if (clp->cl_cs_client_state == NFSD4_CLIENT_CONFIRMED)
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] 31+ messages in thread