2023-06-29 02:39:56

by Dai Ngo

[permalink] [raw]
Subject: [PATCH v6 0/5] NFSD: add support for NFSv4.1+ write delegation

The NFSv4 server currently supports read delegation using VFS lease
which is implemented using file_lock.

This patch series add write delegation support for NFSv4.1+ client by:

. remove the check for F_WRLCK in generic_add_lease to allow
file_lock to be used for write delegation.

. grant write delegation for OPEN with NFS4_SHARE_ACCESS_WRITE
if there is no conflict with other OPENs.

Write delegation conflict with another OPEN, REMOVE, RENAME and SETATTR
are handled the same as read delegation using notify_change, try_break_deleg.

The write delegation support is for NFSv4.1+ client only since the NFSv4.0
Linux client behavior is not compliant with RFC 7530 Section 16.7.5. It
expects the server to look ahead in the compound to find a stateid in order
to determine whether the client that sends the GETATTR is the same client
that holds the write delegation. RFC 7530 spec does not call for the server
to look ahead in order to service the GETATTR op.

Changes since v1:

[PATCH 3/4] NFSD: add supports for CB_GETATTR callback
- remove WARN_ON_ONCE from encode_bitmap4
- replace decode_bitmap4 with xdr_stream_decode_uint32_array
- replace xdr_inline_decode and xdr_decode_hyper in decode_cb_getattr
with xdr_stream_decode_u64. Also remove the un-needed likely().
- modify signature of encode_cb_getattr4args to take pointer to
nfs4_cb_fattr
- replace decode_attr_length with xdr_stream_decode_u32
- rename decode_cb_getattr to decode_cb_fattr4
- fold the initialization of cb_cinfo and cb_fsize into decode_cb_fattr4
- rename ncf_cb_cinfo to ncf_cb_change to avoid confusion of cindo usage
in fs/nfsd/nfs4xdr.c
- correct NFS4_dec_cb_getattr_sz and update size description

[PATCH 4/4] NFSD: handle GETATTR conflict with write delegation
- change nfs4_handle_wrdeleg_conflict returns __be32 to fix test robot
- change ncf_cb_cinfo to ncf_cb_change to avoid confusion of cindo usage
in fs/nfsd/nfs4xdr.c

Changes since v2:

[PATCH 2/4] NFSD: enable support for write delegation
- rename 'deleg' to 'dl_type' in nfs4_set_delegation
- remove 'wdeleg' in nfs4_open_delegation

- drop [PATCH 3/4] NFSD: add supports for CB_GETATTR callback
and [PATCH 4/4] NFSD: handle GETATTR conflict with write delegation
for futher clarification of the benefits of these patches

Changes since v3:

- recall write delegation when there is GETATTR from 2nd client
- add trace point to track when write delegation is granted

Changes since v4:
- squash 4/4 into 2/4
- apply 1/4 last instead of first
- combine nfs4_wrdeleg_filelock and nfs4_handle_wrdeleg_conflict to
nfsd4_deleg_getattr_conflict and move it to fs/nfsd/nfs4state.c
- check for lock belongs to delegation before proceed and do it
under the fl_lock
- check and skip FL_LAYOUT file_locks

Changes since v5:
- [patch 2/5] disable write delegation for NFSv4.0 client

- [patch 4/5] allow client to use write delegation stateid for READ (same
behavior as Solaris server)

When the server receives a READ request with write delegation stateid
the server may returns the NFS4ERR_OPENMODE or allows the READ to proceed
to accommodate clients whose WRITE implementation may unavoidably do reads
(e.g., due to buffer cache constraints). Per RFC 8881 section 9.1.2. Use
of the Stateid and Locking

Returning NFS4ERR_OPENMODE causes the client and server to enter an infinite
loop of READ, NFS4ERR_OPENMODE, TEST_STATEID, READs, NFS4ERR_OPENMODEs,
TEST_STATEID, READs, NFS4ERR_OPENMODEs. The Linux NFS client can not recover
from NFS4ERR_OPENMODE for READ request if the file was opened with
OPEN4_SHARE_ACCESS_WRITE. This READ was initiated internally from the NFS
client and not from the read(2) system call.

- pass git regression test with 40 threads



2023-06-29 02:40:50

by Dai Ngo

[permalink] [raw]
Subject: [PATCH v6 5/5] NFSD: add counter for write delegation recall due to conflict GETATTR

Add counter to keep track of how many times write delegations are
recalled due to conflict with GETATTR.

Signed-off-by: Dai Ngo <[email protected]>
---
fs/nfsd/nfs4state.c | 1 +
fs/nfsd/stats.c | 2 ++
fs/nfsd/stats.h | 7 +++++++
3 files changed, 10 insertions(+)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 2d2656c41ffb..6ce95e738359 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -8410,6 +8410,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode)
}
break_lease:
spin_unlock(&ctx->flc_lock);
+ nfsd_stats_wdeleg_getattr_inc();
status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
if (status != nfserr_jukebox ||
!nfsd_wait_for_delegreturn(rqstp, inode))
diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c
index 777e24e5da33..63797635e1c3 100644
--- a/fs/nfsd/stats.c
+++ b/fs/nfsd/stats.c
@@ -65,6 +65,8 @@ static int nfsd_show(struct seq_file *seq, void *v)
seq_printf(seq, " %lld",
percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_NFS4_OP(i)]));
}
+ seq_printf(seq, "\nwdeleg_getattr %lld",
+ percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_WDELEG_GETATTR]));

seq_putc(seq, '\n');
#endif
diff --git a/fs/nfsd/stats.h b/fs/nfsd/stats.h
index 9b43dc3d9991..cf5524e7ca06 100644
--- a/fs/nfsd/stats.h
+++ b/fs/nfsd/stats.h
@@ -22,6 +22,7 @@ enum {
NFSD_STATS_FIRST_NFS4_OP, /* count of individual nfsv4 operations */
NFSD_STATS_LAST_NFS4_OP = NFSD_STATS_FIRST_NFS4_OP + LAST_NFS4_OP,
#define NFSD_STATS_NFS4_OP(op) (NFSD_STATS_FIRST_NFS4_OP + (op))
+ NFSD_STATS_WDELEG_GETATTR, /* count of getattr conflict with wdeleg */
#endif
NFSD_STATS_COUNTERS_NUM
};
@@ -93,4 +94,10 @@ static inline void nfsd_stats_drc_mem_usage_sub(struct nfsd_net *nn, s64 amount)
percpu_counter_sub(&nn->counter[NFSD_NET_DRC_MEM_USAGE], amount);
}

+#ifdef CONFIG_NFSD_V4
+static inline void nfsd_stats_wdeleg_getattr_inc(void)
+{
+ percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_WDELEG_GETATTR]);
+}
+#endif
#endif /* _NFSD_STATS_H */
--
2.39.3


2023-06-29 03:05:20

by Dai Ngo

[permalink] [raw]
Subject: [PATCH v6 4/5] NFSD: allow client to use write delegation stateid for READ

Allow NFSv4 client to use write delegation stateid for READ operation.
Per RFC 8881 section 9.1.2. Use of the Stateid and Locking.

Signed-off-by: Dai Ngo <[email protected]>
---
fs/nfsd/nfs4proc.c | 16 ++++++++++++++--
fs/nfsd/nfs4xdr.c | 9 +++++++++
fs/nfsd/xdr4.h | 2 ++
3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 5ae670807449..3fa66cb38780 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -942,8 +942,18 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
/* check stateid */
status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
&read->rd_stateid, RD_STATE,
- &read->rd_nf, NULL);
-
+ &read->rd_nf, &read->rd_wd_stid);
+ /*
+ * rd_wd_stid is needed for nfsd4_encode_read to allow write
+ * delegation stateid used for read. Its refcount is decremented
+ * by nfsd4_read_release when read is done.
+ */
+ if (!status && (read->rd_wd_stid->sc_type != NFS4_DELEG_STID ||
+ delegstateid(read->rd_wd_stid)->dl_type !=
+ NFS4_OPEN_DELEGATE_WRITE)) {
+ nfs4_put_stid(read->rd_wd_stid);
+ read->rd_wd_stid = NULL;
+ }
read->rd_rqstp = rqstp;
read->rd_fhp = &cstate->current_fh;
return status;
@@ -953,6 +963,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
static void
nfsd4_read_release(union nfsd4_op_u *u)
{
+ if (u->read.rd_wd_stid)
+ nfs4_put_stid(u->read.rd_wd_stid);
if (u->read.rd_nf)
nfsd_file_put(u->read.rd_nf);
trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index b35855c8beb6..833634cdc761 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -4125,6 +4125,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
struct file *file;
int starting_len = xdr->buf->len;
__be32 *p;
+ fmode_t o_fmode = 0;

if (nfserr)
return nfserr;
@@ -4144,10 +4145,18 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
maxcount = min_t(unsigned long, read->rd_length,
(xdr->buf->buflen - xdr->buf->len));

+ if (read->rd_wd_stid) {
+ /* allow READ using write delegation stateid */
+ o_fmode = file->f_mode;
+ file->f_mode |= FMODE_READ;
+ }
if (file->f_op->splice_read && splice_ok)
nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
else
nfserr = nfsd4_encode_readv(resp, read, file, maxcount);
+ if (o_fmode)
+ file->f_mode = o_fmode;
+
if (nfserr) {
xdr_truncate_encode(xdr, starting_len);
return nfserr;
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 510978e602da..3ccc40f9274a 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -307,6 +307,8 @@ struct nfsd4_read {
struct svc_rqst *rd_rqstp; /* response */
struct svc_fh *rd_fhp; /* response */
u32 rd_eof; /* response */
+
+ struct nfs4_stid *rd_wd_stid; /* internal */
};

struct nfsd4_readdir {
--
2.39.3


2023-06-29 15:10:18

by Jeff Layton

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] NFSD: add support for NFSv4.1+ write delegation

On Wed, 2023-06-28 at 19:36 -0700, Dai Ngo wrote:
> The NFSv4 server currently supports read delegation using VFS lease
> which is implemented using file_lock.
>
> This patch series add write delegation support for NFSv4.1+ client by:
>
> . remove the check for F_WRLCK in generic_add_lease to allow
> file_lock to be used for write delegation.
>
> . grant write delegation for OPEN with NFS4_SHARE_ACCESS_WRITE
> if there is no conflict with other OPENs.
>
> Write delegation conflict with another OPEN, REMOVE, RENAME and SETATTR
> are handled the same as read delegation using notify_change, try_break_deleg.
>
> The write delegation support is for NFSv4.1+ client only since the NFSv4.0
> Linux client behavior is not compliant with RFC 7530 Section 16.7.5. It
> expects the server to look ahead in the compound to find a stateid in order
> to determine whether the client that sends the GETATTR is the same client
> that holds the write delegation. RFC 7530 spec does not call for the server
> to look ahead in order to service the GETATTR op.
>
> Changes since v1:
>
> [PATCH 3/4] NFSD: add supports for CB_GETATTR callback
> - remove WARN_ON_ONCE from encode_bitmap4
> - replace decode_bitmap4 with xdr_stream_decode_uint32_array
> - replace xdr_inline_decode and xdr_decode_hyper in decode_cb_getattr
> with xdr_stream_decode_u64. Also remove the un-needed likely().
> - modify signature of encode_cb_getattr4args to take pointer to
> nfs4_cb_fattr
> - replace decode_attr_length with xdr_stream_decode_u32
> - rename decode_cb_getattr to decode_cb_fattr4
> - fold the initialization of cb_cinfo and cb_fsize into decode_cb_fattr4
> - rename ncf_cb_cinfo to ncf_cb_change to avoid confusion of cindo usage
> in fs/nfsd/nfs4xdr.c
> - correct NFS4_dec_cb_getattr_sz and update size description
>
> [PATCH 4/4] NFSD: handle GETATTR conflict with write delegation
> - change nfs4_handle_wrdeleg_conflict returns __be32 to fix test robot
> - change ncf_cb_cinfo to ncf_cb_change to avoid confusion of cindo usage
> in fs/nfsd/nfs4xdr.c
>
> Changes since v2:
>
> [PATCH 2/4] NFSD: enable support for write delegation
> - rename 'deleg' to 'dl_type' in nfs4_set_delegation
> - remove 'wdeleg' in nfs4_open_delegation
>
> - drop [PATCH 3/4] NFSD: add supports for CB_GETATTR callback
> and [PATCH 4/4] NFSD: handle GETATTR conflict with write delegation
> for futher clarification of the benefits of these patches
>
> Changes since v3:
>
> - recall write delegation when there is GETATTR from 2nd client
> - add trace point to track when write delegation is granted
>
> Changes since v4:
> - squash 4/4 into 2/4
> - apply 1/4 last instead of first
> - combine nfs4_wrdeleg_filelock and nfs4_handle_wrdeleg_conflict to
> nfsd4_deleg_getattr_conflict and move it to fs/nfsd/nfs4state.c
> - check for lock belongs to delegation before proceed and do it
> under the fl_lock
> - check and skip FL_LAYOUT file_locks
>
> Changes since v5:
> - [patch 2/5] disable write delegation for NFSv4.0 client
>
> - [patch 4/5] allow client to use write delegation stateid for READ (same
> behavior as Solaris server)
>
> When the server receives a READ request with write delegation stateid
> the server may returns the NFS4ERR_OPENMODE or allows the READ to proceed
> to accommodate clients whose WRITE implementation may unavoidably do reads
> (e.g., due to buffer cache constraints). Per RFC 8881 section 9.1.2. Use
> of the Stateid and Locking
>
> Returning NFS4ERR_OPENMODE causes the client and server to enter an infinite
> loop of READ, NFS4ERR_OPENMODE, TEST_STATEID, READs, NFS4ERR_OPENMODEs,
> TEST_STATEID, READs, NFS4ERR_OPENMODEs. The Linux NFS client can not recover
> from NFS4ERR_OPENMODE for READ request if the file was opened with
> OPEN4_SHARE_ACCESS_WRITE. This READ was initiated internally from the NFS
> client and not from the read(2) system call.
>
> - pass git regression test with 40 threads
>

Nice work, Dai! This all looks good to me. You can add:

Reviewed-by: Jeff Layton <[email protected]>

2023-06-29 15:16:40

by Chuck Lever

[permalink] [raw]
Subject: Re: [PATCH v6 4/5] NFSD: allow client to use write delegation stateid for READ

On Wed, Jun 28, 2023 at 07:36:15PM -0700, Dai Ngo wrote:
> Allow NFSv4 client to use write delegation stateid for READ operation.
> Per RFC 8881 section 9.1.2. Use of the Stateid and Locking.

I'm wondering if this fix should precede 2/5 to prevent breakage
during a bisect. Jeff, what do you think?


> Signed-off-by: Dai Ngo <[email protected]>
> ---
> fs/nfsd/nfs4proc.c | 16 ++++++++++++++--
> fs/nfsd/nfs4xdr.c | 9 +++++++++
> fs/nfsd/xdr4.h | 2 ++
> 3 files changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index 5ae670807449..3fa66cb38780 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -942,8 +942,18 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
> /* check stateid */
> status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
> &read->rd_stateid, RD_STATE,
> - &read->rd_nf, NULL);
> -
> + &read->rd_nf, &read->rd_wd_stid);
> + /*
> + * rd_wd_stid is needed for nfsd4_encode_read to allow write
> + * delegation stateid used for read. Its refcount is decremented
> + * by nfsd4_read_release when read is done.
> + */
> + if (!status && (read->rd_wd_stid->sc_type != NFS4_DELEG_STID ||
> + delegstateid(read->rd_wd_stid)->dl_type !=
> + NFS4_OPEN_DELEGATE_WRITE)) {
> + nfs4_put_stid(read->rd_wd_stid);
> + read->rd_wd_stid = NULL;
> + }
> read->rd_rqstp = rqstp;
> read->rd_fhp = &cstate->current_fh;
> return status;
> @@ -953,6 +963,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
> static void
> nfsd4_read_release(union nfsd4_op_u *u)
> {
> + if (u->read.rd_wd_stid)
> + nfs4_put_stid(u->read.rd_wd_stid);
> if (u->read.rd_nf)
> nfsd_file_put(u->read.rd_nf);
> trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index b35855c8beb6..833634cdc761 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -4125,6 +4125,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
> struct file *file;
> int starting_len = xdr->buf->len;
> __be32 *p;
> + fmode_t o_fmode = 0;
>
> if (nfserr)
> return nfserr;
> @@ -4144,10 +4145,18 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
> maxcount = min_t(unsigned long, read->rd_length,
> (xdr->buf->buflen - xdr->buf->len));
>
> + if (read->rd_wd_stid) {
> + /* allow READ using write delegation stateid */
> + o_fmode = file->f_mode;
> + file->f_mode |= FMODE_READ;
> + }
> if (file->f_op->splice_read && splice_ok)
> nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
> else
> nfserr = nfsd4_encode_readv(resp, read, file, maxcount);
> + if (o_fmode)
> + file->f_mode = o_fmode;
> +
> if (nfserr) {
> xdr_truncate_encode(xdr, starting_len);
> return nfserr;
> diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
> index 510978e602da..3ccc40f9274a 100644
> --- a/fs/nfsd/xdr4.h
> +++ b/fs/nfsd/xdr4.h
> @@ -307,6 +307,8 @@ struct nfsd4_read {
> struct svc_rqst *rd_rqstp; /* response */
> struct svc_fh *rd_fhp; /* response */
> u32 rd_eof; /* response */
> +
> + struct nfs4_stid *rd_wd_stid; /* internal */
> };
>
> struct nfsd4_readdir {
> --
> 2.39.3
>

2023-06-29 15:17:47

by Chuck Lever

[permalink] [raw]
Subject: Re: [PATCH v6 5/5] NFSD: add counter for write delegation recall due to conflict GETATTR

On Wed, Jun 28, 2023 at 07:36:16PM -0700, Dai Ngo wrote:
> Add counter to keep track of how many times write delegations are
> recalled due to conflict with GETATTR.

Should this wee patch be squashed into 3/5 ?

The patch description ought to explain /why/ we want to track
GETATTR conflicts. (even if you squash it into 3/5). Mostly I'm
trying to get the important design choices written down so we
can remember them in a year or two.


> Signed-off-by: Dai Ngo <[email protected]>
> ---
> fs/nfsd/nfs4state.c | 1 +
> fs/nfsd/stats.c | 2 ++
> fs/nfsd/stats.h | 7 +++++++
> 3 files changed, 10 insertions(+)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 2d2656c41ffb..6ce95e738359 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -8410,6 +8410,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode)
> }
> break_lease:
> spin_unlock(&ctx->flc_lock);
> + nfsd_stats_wdeleg_getattr_inc();
> status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
> if (status != nfserr_jukebox ||
> !nfsd_wait_for_delegreturn(rqstp, inode))
> diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c
> index 777e24e5da33..63797635e1c3 100644
> --- a/fs/nfsd/stats.c
> +++ b/fs/nfsd/stats.c
> @@ -65,6 +65,8 @@ static int nfsd_show(struct seq_file *seq, void *v)
> seq_printf(seq, " %lld",
> percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_NFS4_OP(i)]));
> }
> + seq_printf(seq, "\nwdeleg_getattr %lld",
> + percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_WDELEG_GETATTR]));
>
> seq_putc(seq, '\n');
> #endif
> diff --git a/fs/nfsd/stats.h b/fs/nfsd/stats.h
> index 9b43dc3d9991..cf5524e7ca06 100644
> --- a/fs/nfsd/stats.h
> +++ b/fs/nfsd/stats.h
> @@ -22,6 +22,7 @@ enum {
> NFSD_STATS_FIRST_NFS4_OP, /* count of individual nfsv4 operations */
> NFSD_STATS_LAST_NFS4_OP = NFSD_STATS_FIRST_NFS4_OP + LAST_NFS4_OP,
> #define NFSD_STATS_NFS4_OP(op) (NFSD_STATS_FIRST_NFS4_OP + (op))
> + NFSD_STATS_WDELEG_GETATTR, /* count of getattr conflict with wdeleg */
> #endif
> NFSD_STATS_COUNTERS_NUM
> };
> @@ -93,4 +94,10 @@ static inline void nfsd_stats_drc_mem_usage_sub(struct nfsd_net *nn, s64 amount)
> percpu_counter_sub(&nn->counter[NFSD_NET_DRC_MEM_USAGE], amount);
> }
>
> +#ifdef CONFIG_NFSD_V4
> +static inline void nfsd_stats_wdeleg_getattr_inc(void)
> +{
> + percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_WDELEG_GETATTR]);
> +}
> +#endif
> #endif /* _NFSD_STATS_H */
> --
> 2.39.3
>

2023-06-29 15:56:53

by Jeff Layton

[permalink] [raw]
Subject: Re: [PATCH v6 4/5] NFSD: allow client to use write delegation stateid for READ

On Thu, 2023-06-29 at 11:02 -0400, Chuck Lever wrote:
> On Wed, Jun 28, 2023 at 07:36:15PM -0700, Dai Ngo wrote:
> > Allow NFSv4 client to use write delegation stateid for READ operation.
> > Per RFC 8881 section 9.1.2. Use of the Stateid and Locking.
>
> I'm wondering if this fix should precede 2/5 to prevent breakage
> during a bisect. Jeff, what do you think?
>

Good point. Probably the patch that actually makes it actually hand out
write delegations should?be the last one.

>
> > Signed-off-by: Dai Ngo <[email protected]>
> > ---
> > fs/nfsd/nfs4proc.c | 16 ++++++++++++++--
> > fs/nfsd/nfs4xdr.c | 9 +++++++++
> > fs/nfsd/xdr4.h | 2 ++
> > 3 files changed, 25 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> > index 5ae670807449..3fa66cb38780 100644
> > --- a/fs/nfsd/nfs4proc.c
> > +++ b/fs/nfsd/nfs4proc.c
> > @@ -942,8 +942,18 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
> > /* check stateid */
> > status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
> > &read->rd_stateid, RD_STATE,
> > - &read->rd_nf, NULL);
> > -
> > + &read->rd_nf, &read->rd_wd_stid);
> > + /*
> > + * rd_wd_stid is needed for nfsd4_encode_read to allow write
> > + * delegation stateid used for read. Its refcount is decremented
> > + * by nfsd4_read_release when read is done.
> > + */
> > + if (!status && (read->rd_wd_stid->sc_type != NFS4_DELEG_STID ||
> > + delegstateid(read->rd_wd_stid)->dl_type !=
> > + NFS4_OPEN_DELEGATE_WRITE)) {
> > + nfs4_put_stid(read->rd_wd_stid);
> > + read->rd_wd_stid = NULL;
> > + }
> > read->rd_rqstp = rqstp;
> > read->rd_fhp = &cstate->current_fh;
> > return status;
> > @@ -953,6 +963,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
> > static void
> > nfsd4_read_release(union nfsd4_op_u *u)
> > {
> > + if (u->read.rd_wd_stid)
> > + nfs4_put_stid(u->read.rd_wd_stid);
> > if (u->read.rd_nf)
> > nfsd_file_put(u->read.rd_nf);
> > trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
> > diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> > index b35855c8beb6..833634cdc761 100644
> > --- a/fs/nfsd/nfs4xdr.c
> > +++ b/fs/nfsd/nfs4xdr.c
> > @@ -4125,6 +4125,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
> > struct file *file;
> > int starting_len = xdr->buf->len;
> > __be32 *p;
> > + fmode_t o_fmode = 0;
> >
> > if (nfserr)
> > return nfserr;
> > @@ -4144,10 +4145,18 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
> > maxcount = min_t(unsigned long, read->rd_length,
> > (xdr->buf->buflen - xdr->buf->len));
> >
> > + if (read->rd_wd_stid) {
> > + /* allow READ using write delegation stateid */
> > + o_fmode = file->f_mode;
> > + file->f_mode |= FMODE_READ;
> > + }
> > if (file->f_op->splice_read && splice_ok)
> > nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
> > else
> > nfserr = nfsd4_encode_readv(resp, read, file, maxcount);
> > + if (o_fmode)
> > + file->f_mode = o_fmode;
> > +
> > if (nfserr) {
> > xdr_truncate_encode(xdr, starting_len);
> > return nfserr;
> > diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
> > index 510978e602da..3ccc40f9274a 100644
> > --- a/fs/nfsd/xdr4.h
> > +++ b/fs/nfsd/xdr4.h
> > @@ -307,6 +307,8 @@ struct nfsd4_read {
> > struct svc_rqst *rd_rqstp; /* response */
> > struct svc_fh *rd_fhp; /* response */
> > u32 rd_eof; /* response */
> > +
> > + struct nfs4_stid *rd_wd_stid; /* internal */
> > };
> >
> > struct nfsd4_readdir {
> > --
> > 2.39.3
> >

--
Jeff Layton <[email protected]>

2023-06-29 16:22:33

by Dai Ngo

[permalink] [raw]
Subject: Re: [PATCH v6 4/5] NFSD: allow client to use write delegation stateid for READ


On 6/29/23 8:02 AM, Chuck Lever wrote:
> On Wed, Jun 28, 2023 at 07:36:15PM -0700, Dai Ngo wrote:
>> Allow NFSv4 client to use write delegation stateid for READ operation.
>> Per RFC 8881 section 9.1.2. Use of the Stateid and Locking.
> I'm wondering if this fix should precede 2/5 to prevent breakage
> during a bisect. Jeff, what do you think?

Will make this patch preceed 2/5.

-Dai

>
>
>> Signed-off-by: Dai Ngo <[email protected]>
>> ---
>> fs/nfsd/nfs4proc.c | 16 ++++++++++++++--
>> fs/nfsd/nfs4xdr.c | 9 +++++++++
>> fs/nfsd/xdr4.h | 2 ++
>> 3 files changed, 25 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
>> index 5ae670807449..3fa66cb38780 100644
>> --- a/fs/nfsd/nfs4proc.c
>> +++ b/fs/nfsd/nfs4proc.c
>> @@ -942,8 +942,18 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>> /* check stateid */
>> status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
>> &read->rd_stateid, RD_STATE,
>> - &read->rd_nf, NULL);
>> -
>> + &read->rd_nf, &read->rd_wd_stid);
>> + /*
>> + * rd_wd_stid is needed for nfsd4_encode_read to allow write
>> + * delegation stateid used for read. Its refcount is decremented
>> + * by nfsd4_read_release when read is done.
>> + */
>> + if (!status && (read->rd_wd_stid->sc_type != NFS4_DELEG_STID ||
>> + delegstateid(read->rd_wd_stid)->dl_type !=
>> + NFS4_OPEN_DELEGATE_WRITE)) {
>> + nfs4_put_stid(read->rd_wd_stid);
>> + read->rd_wd_stid = NULL;
>> + }
>> read->rd_rqstp = rqstp;
>> read->rd_fhp = &cstate->current_fh;
>> return status;
>> @@ -953,6 +963,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>> static void
>> nfsd4_read_release(union nfsd4_op_u *u)
>> {
>> + if (u->read.rd_wd_stid)
>> + nfs4_put_stid(u->read.rd_wd_stid);
>> if (u->read.rd_nf)
>> nfsd_file_put(u->read.rd_nf);
>> trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
>> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
>> index b35855c8beb6..833634cdc761 100644
>> --- a/fs/nfsd/nfs4xdr.c
>> +++ b/fs/nfsd/nfs4xdr.c
>> @@ -4125,6 +4125,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
>> struct file *file;
>> int starting_len = xdr->buf->len;
>> __be32 *p;
>> + fmode_t o_fmode = 0;
>>
>> if (nfserr)
>> return nfserr;
>> @@ -4144,10 +4145,18 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
>> maxcount = min_t(unsigned long, read->rd_length,
>> (xdr->buf->buflen - xdr->buf->len));
>>
>> + if (read->rd_wd_stid) {
>> + /* allow READ using write delegation stateid */
>> + o_fmode = file->f_mode;
>> + file->f_mode |= FMODE_READ;
>> + }
>> if (file->f_op->splice_read && splice_ok)
>> nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
>> else
>> nfserr = nfsd4_encode_readv(resp, read, file, maxcount);
>> + if (o_fmode)
>> + file->f_mode = o_fmode;
>> +
>> if (nfserr) {
>> xdr_truncate_encode(xdr, starting_len);
>> return nfserr;
>> diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
>> index 510978e602da..3ccc40f9274a 100644
>> --- a/fs/nfsd/xdr4.h
>> +++ b/fs/nfsd/xdr4.h
>> @@ -307,6 +307,8 @@ struct nfsd4_read {
>> struct svc_rqst *rd_rqstp; /* response */
>> struct svc_fh *rd_fhp; /* response */
>> u32 rd_eof; /* response */
>> +
>> + struct nfs4_stid *rd_wd_stid; /* internal */
>> };
>>
>> struct nfsd4_readdir {
>> --
>> 2.39.3
>>

2023-06-29 16:27:08

by Dai Ngo

[permalink] [raw]
Subject: Re: [PATCH v6 5/5] NFSD: add counter for write delegation recall due to conflict GETATTR


On 6/29/23 8:07 AM, Chuck Lever wrote:
> On Wed, Jun 28, 2023 at 07:36:16PM -0700, Dai Ngo wrote:
>> Add counter to keep track of how many times write delegations are
>> recalled due to conflict with GETATTR.
> Should this wee patch be squashed into 3/5 ?

Yes, will squash this into 3/5.

>
> The patch description ought to explain /why/ we want to track
> GETATTR conflicts. (even if you squash it into 3/5). Mostly I'm
> trying to get the important design choices written down so we
> can remember them in a year or two.

will do.

-Dai

>
>
>> Signed-off-by: Dai Ngo <[email protected]>
>> ---
>> fs/nfsd/nfs4state.c | 1 +
>> fs/nfsd/stats.c | 2 ++
>> fs/nfsd/stats.h | 7 +++++++
>> 3 files changed, 10 insertions(+)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index 2d2656c41ffb..6ce95e738359 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -8410,6 +8410,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode)
>> }
>> break_lease:
>> spin_unlock(&ctx->flc_lock);
>> + nfsd_stats_wdeleg_getattr_inc();
>> status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
>> if (status != nfserr_jukebox ||
>> !nfsd_wait_for_delegreturn(rqstp, inode))
>> diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c
>> index 777e24e5da33..63797635e1c3 100644
>> --- a/fs/nfsd/stats.c
>> +++ b/fs/nfsd/stats.c
>> @@ -65,6 +65,8 @@ static int nfsd_show(struct seq_file *seq, void *v)
>> seq_printf(seq, " %lld",
>> percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_NFS4_OP(i)]));
>> }
>> + seq_printf(seq, "\nwdeleg_getattr %lld",
>> + percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_WDELEG_GETATTR]));
>>
>> seq_putc(seq, '\n');
>> #endif
>> diff --git a/fs/nfsd/stats.h b/fs/nfsd/stats.h
>> index 9b43dc3d9991..cf5524e7ca06 100644
>> --- a/fs/nfsd/stats.h
>> +++ b/fs/nfsd/stats.h
>> @@ -22,6 +22,7 @@ enum {
>> NFSD_STATS_FIRST_NFS4_OP, /* count of individual nfsv4 operations */
>> NFSD_STATS_LAST_NFS4_OP = NFSD_STATS_FIRST_NFS4_OP + LAST_NFS4_OP,
>> #define NFSD_STATS_NFS4_OP(op) (NFSD_STATS_FIRST_NFS4_OP + (op))
>> + NFSD_STATS_WDELEG_GETATTR, /* count of getattr conflict with wdeleg */
>> #endif
>> NFSD_STATS_COUNTERS_NUM
>> };
>> @@ -93,4 +94,10 @@ static inline void nfsd_stats_drc_mem_usage_sub(struct nfsd_net *nn, s64 amount)
>> percpu_counter_sub(&nn->counter[NFSD_NET_DRC_MEM_USAGE], amount);
>> }
>>
>> +#ifdef CONFIG_NFSD_V4
>> +static inline void nfsd_stats_wdeleg_getattr_inc(void)
>> +{
>> + percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_WDELEG_GETATTR]);
>> +}
>> +#endif
>> #endif /* _NFSD_STATS_H */
>> --
>> 2.39.3
>>