2020-11-30 23:12:31

by J. Bruce Fields

[permalink] [raw]
Subject: [PATCH 1/5] nfsd: only call inode_query_iversion in the I_VERSION case

From: "J. Bruce Fields" <[email protected]>

inode_query_iversion() can modify i_version. Depending on the exported
filesystem, that may not be safe. For example, if you're re-exporting
NFS, NFS stores the server's change attribute in i_version and does not
expect it to be modified locally. This has been observed causing
unnecessary cache invalidations.

The way a filesystem indicates that it's OK to call
inode_query_iverson() is by setting SB_I_VERSION.

So, move the I_VERSION check out of encode_change(), where it's used
only in FATTR responses, to nfsd4_changeattr(), which is also called for
pre- and post- operation attributes.

(Note we could also pull the NFSEXP_V4ROOT case into
nfsd4_change_attribute as well. That would actually be a no-op, since
pre/post attrs are only used for metadata-modifying operations, and
V4ROOT exports are read-only. But we might make the change in the
future just for simplicity.)

Reported-by: Daire Byrne <[email protected]>
Signed-off-by: J. Bruce Fields <[email protected]>
---
fs/nfsd/nfs3xdr.c | 5 ++---
fs/nfsd/nfs4xdr.c | 6 +-----
fs/nfsd/nfsfh.h | 14 ++++++++++----
3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 2277f83da250..dfbf390ff40c 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -291,14 +291,13 @@ void fill_post_wcc(struct svc_fh *fhp)
printk("nfsd: inode locked twice during operation.\n");

err = fh_getattr(fhp, &fhp->fh_post_attr);
- fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
- d_inode(fhp->fh_dentry));
if (err) {
fhp->fh_post_saved = false;
- /* Grab the ctime anyway - set_change_info might use it */
fhp->fh_post_attr.ctime = d_inode(fhp->fh_dentry)->i_ctime;
} else
fhp->fh_post_saved = true;
+ fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
+ d_inode(fhp->fh_dentry));
}

/*
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 833a2c64dfe8..56fd5f6d5c44 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2298,12 +2298,8 @@ static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
if (exp->ex_flags & NFSEXP_V4ROOT) {
*p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time));
*p++ = 0;
- } else if (IS_I_VERSION(inode)) {
+ } else
p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode));
- } else {
- *p++ = cpu_to_be32(stat->ctime.tv_sec);
- *p++ = cpu_to_be32(stat->ctime.tv_nsec);
- }
return p;
}

diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
index 56cfbc361561..39d764b129fa 100644
--- a/fs/nfsd/nfsfh.h
+++ b/fs/nfsd/nfsfh.h
@@ -261,10 +261,16 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat,
{
u64 chattr;

- chattr = stat->ctime.tv_sec;
- chattr <<= 30;
- chattr += stat->ctime.tv_nsec;
- chattr += inode_query_iversion(inode);
+ if (IS_I_VERSION(inode)) {
+ chattr = stat->ctime.tv_sec;
+ chattr <<= 30;
+ chattr += stat->ctime.tv_nsec;
+ chattr += inode_query_iversion(inode);
+ } else {
+ chattr = stat->ctime.tv_sec;
+ chattr <<= 32;
+ chattr += stat->ctime.tv_nsec;
+ }
return chattr;
}

--
2.28.0


2020-11-30 23:12:31

by J. Bruce Fields

[permalink] [raw]
Subject: [PATCH 2/5] nfsd: simplify nfsd4_change_info

From: "J. Bruce Fields" <[email protected]>

It doesn't make sense to carry all these extra fields around. Just
make everything into change attribute from the start.

This is just cleanup, there should be no change in behavior.

Signed-off-by: J. Bruce Fields <[email protected]>
---
fs/nfsd/nfs4xdr.c | 11 ++---------
fs/nfsd/xdr4.h | 11 -----------
2 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 56fd5f6d5c44..18c912930947 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2331,15 +2331,8 @@ static __be32 *encode_time_delta(__be32 *p, struct inode *inode)
static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c)
{
*p++ = cpu_to_be32(c->atomic);
- if (c->change_supported) {
- p = xdr_encode_hyper(p, c->before_change);
- p = xdr_encode_hyper(p, c->after_change);
- } else {
- *p++ = cpu_to_be32(c->before_ctime_sec);
- *p++ = cpu_to_be32(c->before_ctime_nsec);
- *p++ = cpu_to_be32(c->after_ctime_sec);
- *p++ = cpu_to_be32(c->after_ctime_nsec);
- }
+ p = xdr_encode_hyper(p, c->before_change);
+ p = xdr_encode_hyper(p, c->after_change);
return p;
}

diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 679d40af1bbb..3a59053084e6 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -76,12 +76,7 @@ static inline bool nfsd4_has_session(struct nfsd4_compound_state *cs)

struct nfsd4_change_info {
u32 atomic;
- bool change_supported;
- u32 before_ctime_sec;
- u32 before_ctime_nsec;
u64 before_change;
- u32 after_ctime_sec;
- u32 after_ctime_nsec;
u64 after_change;
};

@@ -768,15 +763,9 @@ set_change_info(struct nfsd4_change_info *cinfo, struct svc_fh *fhp)
{
BUG_ON(!fhp->fh_pre_saved);
cinfo->atomic = (u32)fhp->fh_post_saved;
- cinfo->change_supported = IS_I_VERSION(d_inode(fhp->fh_dentry));

cinfo->before_change = fhp->fh_pre_change;
cinfo->after_change = fhp->fh_post_change;
- cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec;
- cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec;
- cinfo->after_ctime_sec = fhp->fh_post_attr.ctime.tv_sec;
- cinfo->after_ctime_nsec = fhp->fh_post_attr.ctime.tv_nsec;
-
}


--
2.28.0

2020-11-30 23:12:55

by J. Bruce Fields

[permalink] [raw]
Subject: [PATCH 4/5] nfsd4: don't query change attribute in v2/v3 case

From: "J. Bruce Fields" <[email protected]>

inode_query_iversion() has side effects, and there's no point calling it
when we're not even going to use it.

We check whether we're currently processing a v4 request by checking
fh_maxsize, which is arguably a little hacky; we could add a flag to
svc_fh instead.

Signed-off-by: J. Bruce Fields <[email protected]>
---
fs/nfsd/nfs3xdr.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index dfbf390ff40c..f4fd54dc6965 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -259,11 +259,11 @@ void fill_pre_wcc(struct svc_fh *fhp)
{
struct inode *inode;
struct kstat stat;
+ bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
__be32 err;

if (fhp->fh_pre_saved)
return;
-
inode = d_inode(fhp->fh_dentry);
err = fh_getattr(fhp, &stat);
if (err) {
@@ -272,11 +272,12 @@ void fill_pre_wcc(struct svc_fh *fhp)
stat.ctime = inode->i_ctime;
stat.size = inode->i_size;
}
+ if (v4)
+ fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);

fhp->fh_pre_mtime = stat.mtime;
fhp->fh_pre_ctime = stat.ctime;
fhp->fh_pre_size = stat.size;
- fhp->fh_pre_change = nfsd4_change_attribute(&stat, inode);
fhp->fh_pre_saved = true;
}

@@ -285,6 +286,8 @@ void fill_pre_wcc(struct svc_fh *fhp)
*/
void fill_post_wcc(struct svc_fh *fhp)
{
+ bool v4 = (fhp->fh_maxsize == NFS4_FHSIZE);
+ struct inode *inode = d_inode(fhp->fh_dentry);
__be32 err;

if (fhp->fh_post_saved)
@@ -293,11 +296,12 @@ void fill_post_wcc(struct svc_fh *fhp)
err = fh_getattr(fhp, &fhp->fh_post_attr);
if (err) {
fhp->fh_post_saved = false;
- fhp->fh_post_attr.ctime = d_inode(fhp->fh_dentry)->i_ctime;
+ fhp->fh_post_attr.ctime = inode->i_ctime;
} else
fhp->fh_post_saved = true;
- fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
- d_inode(fhp->fh_dentry));
+ if (v4)
+ fhp->fh_post_change =
+ nfsd4_change_attribute(&fhp->fh_post_attr, inode);
}

/*
--
2.28.0

2020-12-01 16:33:43

by Jeffrey Layton

[permalink] [raw]
Subject: Re: [PATCH 1/5] nfsd: only call inode_query_iversion in the I_VERSION case

On Mon, 2020-11-30 at 17:46 -0500, J. Bruce Fields wrote:
> From: "J. Bruce Fields" <[email protected]>
>
> inode_query_iversion() can modify i_version. Depending on the exported
> filesystem, that may not be safe. For example, if you're re-exporting
> NFS, NFS stores the server's change attribute in i_version and does not
> expect it to be modified locally. This has been observed causing
> unnecessary cache invalidations.
>
> The way a filesystem indicates that it's OK to call
> inode_query_iverson() is by setting SB_I_VERSION.
>
> So, move the I_VERSION check out of encode_change(), where it's used
> only in FATTR responses, to nfsd4_changeattr(), which is also called for
> pre- and post- operation attributes.
>

"only in FATTR responses, to nfsd4_change_attribute(),"

> (Note we could also pull the NFSEXP_V4ROOT case into
> nfsd4_change_attribute as well. That would actually be a no-op, since
> pre/post attrs are only used for metadata-modifying operations, and
> V4ROOT exports are read-only. But we might make the change in the
> future just for simplicity.)
>
> Reported-by: Daire Byrne <[email protected]>
> Signed-off-by: J. Bruce Fields <[email protected]>
> ---
>  fs/nfsd/nfs3xdr.c | 5 ++---
>  fs/nfsd/nfs4xdr.c | 6 +-----
>  fs/nfsd/nfsfh.h | 14 ++++++++++----
>  3 files changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
> index 2277f83da250..dfbf390ff40c 100644
> --- a/fs/nfsd/nfs3xdr.c
> +++ b/fs/nfsd/nfs3xdr.c
> @@ -291,14 +291,13 @@ void fill_post_wcc(struct svc_fh *fhp)
>   printk("nfsd: inode locked twice during operation.\n");
>  
>
>
>
>   err = fh_getattr(fhp, &fhp->fh_post_attr);
> - fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
> - d_inode(fhp->fh_dentry));
>   if (err) {
>   fhp->fh_post_saved = false;
> - /* Grab the ctime anyway - set_change_info might use it */
>   fhp->fh_post_attr.ctime = d_inode(fhp->fh_dentry)->i_ctime;
>   } else
>   fhp->fh_post_saved = true;
> + fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
> + d_inode(fhp->fh_dentry));
>  }
>  
>
>
>
>  /*
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index 833a2c64dfe8..56fd5f6d5c44 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -2298,12 +2298,8 @@ static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
>   if (exp->ex_flags & NFSEXP_V4ROOT) {
>   *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time));
>   *p++ = 0;
> - } else if (IS_I_VERSION(inode)) {
> + } else
>   p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode));
> - } else {
> - *p++ = cpu_to_be32(stat->ctime.tv_sec);
> - *p++ = cpu_to_be32(stat->ctime.tv_nsec);
> - }
>   return p;
>  }
>  
>
>
>
> diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
> index 56cfbc361561..39d764b129fa 100644
> --- a/fs/nfsd/nfsfh.h
> +++ b/fs/nfsd/nfsfh.h
> @@ -261,10 +261,16 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat,
>  {
>   u64 chattr;
>  
>
>
>
> - chattr = stat->ctime.tv_sec;
> - chattr <<= 30;
> - chattr += stat->ctime.tv_nsec;
> - chattr += inode_query_iversion(inode);
> + if (IS_I_VERSION(inode)) {
> + chattr = stat->ctime.tv_sec;
> + chattr <<= 30;
> + chattr += stat->ctime.tv_nsec;
> + chattr += inode_query_iversion(inode);
> + } else {
> + chattr = stat->ctime.tv_sec;
> + chattr <<= 32;
> + chattr += stat->ctime.tv_nsec;
> + }
>   return chattr;
>  }
>  
>
>
>

--
Jeff Layton <[email protected]>

2020-12-01 16:46:14

by Jeffrey Layton

[permalink] [raw]
Subject: Re: [PATCH 1/5] nfsd: only call inode_query_iversion in the I_VERSION case

On Mon, 2020-11-30 at 17:46 -0500, J. Bruce Fields wrote:
> From: "J. Bruce Fields" <[email protected]>
>
> inode_query_iversion() can modify i_version. Depending on the exported
> filesystem, that may not be safe. For example, if you're re-exporting
> NFS, NFS stores the server's change attribute in i_version and does not
> expect it to be modified locally. This has been observed causing
> unnecessary cache invalidations.
>
> The way a filesystem indicates that it's OK to call
> inode_query_iverson() is by setting SB_I_VERSION.
>
> So, move the I_VERSION check out of encode_change(), where it's used
> only in FATTR responses, to nfsd4_changeattr(), which is also called for
> pre- and post- operation attributes.
>
> (Note we could also pull the NFSEXP_V4ROOT case into
> nfsd4_change_attribute as well. That would actually be a no-op, since
> pre/post attrs are only used for metadata-modifying operations, and
> V4ROOT exports are read-only. But we might make the change in the
> future just for simplicity.)
>
> Reported-by: Daire Byrne <[email protected]>
> Signed-off-by: J. Bruce Fields <[email protected]>
> ---
>  fs/nfsd/nfs3xdr.c | 5 ++---
>  fs/nfsd/nfs4xdr.c | 6 +-----
>  fs/nfsd/nfsfh.h | 14 ++++++++++----
>  3 files changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
> index 2277f83da250..dfbf390ff40c 100644
> --- a/fs/nfsd/nfs3xdr.c
> +++ b/fs/nfsd/nfs3xdr.c
> @@ -291,14 +291,13 @@ void fill_post_wcc(struct svc_fh *fhp)
>   printk("nfsd: inode locked twice during operation.\n");
>  
>
>
>
>   err = fh_getattr(fhp, &fhp->fh_post_attr);
> - fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
> - d_inode(fhp->fh_dentry));
>   if (err) {
>   fhp->fh_post_saved = false;
> - /* Grab the ctime anyway - set_change_info might use it */
>   fhp->fh_post_attr.ctime = d_inode(fhp->fh_dentry)->i_ctime;
>   } else
>   fhp->fh_post_saved = true;
> + fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
> + d_inode(fhp->fh_dentry));
>  }
>  
>
>
>
>  /*
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index 833a2c64dfe8..56fd5f6d5c44 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -2298,12 +2298,8 @@ static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
>   if (exp->ex_flags & NFSEXP_V4ROOT) {
>   *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time));
>   *p++ = 0;
> - } else if (IS_I_VERSION(inode)) {
> + } else
>   p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode));
> - } else {
> - *p++ = cpu_to_be32(stat->ctime.tv_sec);
> - *p++ = cpu_to_be32(stat->ctime.tv_nsec);
> - }
>   return p;
>  }
>  
>
>
>
> diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
> index 56cfbc361561..39d764b129fa 100644
> --- a/fs/nfsd/nfsfh.h
> +++ b/fs/nfsd/nfsfh.h
> @@ -261,10 +261,16 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat,
>  {
>   u64 chattr;
>  
>
>
>
> - chattr = stat->ctime.tv_sec;
> - chattr <<= 30;
> - chattr += stat->ctime.tv_nsec;
> - chattr += inode_query_iversion(inode);
> + if (IS_I_VERSION(inode)) {
> + chattr = stat->ctime.tv_sec;
> + chattr <<= 30;
> + chattr += stat->ctime.tv_nsec;
> + chattr += inode_query_iversion(inode);
> + } else {
> + chattr = stat->ctime.tv_sec;
> + chattr <<= 32;

Might be nice to annotate the shifts above and maybe make them named
constants. I'm not sure where those values come from, tbh.

> + chattr += stat->ctime.tv_nsec;
> + }
>   return chattr;
>  }
>  
>
>
>


Other than some very minor nits, the set itself looks great.

Are you planning to follow up with the series to add the fetch_iversion
op, or have you decided not to do that for now?

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

2020-12-01 20:16:24

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH 1/5] nfsd: only call inode_query_iversion in the I_VERSION case

On Tue, Dec 01, 2020 at 11:30:12AM -0500, Jeff Layton wrote:
> On Mon, 2020-11-30 at 17:46 -0500, J. Bruce Fields wrote:
> > From: "J. Bruce Fields" <[email protected]>
> >
> > inode_query_iversion() can modify i_version. Depending on the exported
> > filesystem, that may not be safe. For example, if you're re-exporting
> > NFS, NFS stores the server's change attribute in i_version and does not
> > expect it to be modified locally. This has been observed causing
> > unnecessary cache invalidations.
> >
> > The way a filesystem indicates that it's OK to call
> > inode_query_iverson() is by setting SB_I_VERSION.
> >
> > So, move the I_VERSION check out of encode_change(), where it's used
> > only in FATTR responses, to nfsd4_changeattr(), which is also called for
> > pre- and post- operation attributes.
> >
>
> "only in FATTR responses, to nfsd4_change_attribute(),"

Whoops, and also FATTR should have been GETATTR.

Fixed locally, I assume Chuck will just want to fix that up in his tree
(let me know if not).

--b.

2020-12-01 20:41:57

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH 1/5] nfsd: only call inode_query_iversion in the I_VERSION case

On Tue, Dec 01, 2020 at 11:43:31AM -0500, Jeff Layton wrote:
> On Mon, 2020-11-30 at 17:46 -0500, J. Bruce Fields wrote:
> > From: "J. Bruce Fields" <[email protected]>
> >
> > inode_query_iversion() can modify i_version. Depending on the exported
> > filesystem, that may not be safe. For example, if you're re-exporting
> > NFS, NFS stores the server's change attribute in i_version and does not
> > expect it to be modified locally. This has been observed causing
> > unnecessary cache invalidations.
> >
> > The way a filesystem indicates that it's OK to call
> > inode_query_iverson() is by setting SB_I_VERSION.
> >
> > So, move the I_VERSION check out of encode_change(), where it's used
> > only in FATTR responses, to nfsd4_changeattr(), which is also called for
> > pre- and post- operation attributes.
> >
> > (Note we could also pull the NFSEXP_V4ROOT case into
> > nfsd4_change_attribute as well. That would actually be a no-op, since
> > pre/post attrs are only used for metadata-modifying operations, and
> > V4ROOT exports are read-only. But we might make the change in the
> > future just for simplicity.)
> >
> > Reported-by: Daire Byrne <[email protected]>
> > Signed-off-by: J. Bruce Fields <[email protected]>
> > ---
> > ?fs/nfsd/nfs3xdr.c | 5 ++---
> > ?fs/nfsd/nfs4xdr.c | 6 +-----
> > ?fs/nfsd/nfsfh.h | 14 ++++++++++----
> > ?3 files changed, 13 insertions(+), 12 deletions(-)
> >
> > diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
> > index 2277f83da250..dfbf390ff40c 100644
> > --- a/fs/nfsd/nfs3xdr.c
> > +++ b/fs/nfsd/nfs3xdr.c
> > @@ -291,14 +291,13 @@ void fill_post_wcc(struct svc_fh *fhp)
> > ? printk("nfsd: inode locked twice during operation.\n");
> > ?
> >
> >
> >
> > ? err = fh_getattr(fhp, &fhp->fh_post_attr);
> > - fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
> > - d_inode(fhp->fh_dentry));
> > ? if (err) {
> > ? fhp->fh_post_saved = false;
> > - /* Grab the ctime anyway - set_change_info might use it */
> > ? fhp->fh_post_attr.ctime = d_inode(fhp->fh_dentry)->i_ctime;
> > ? } else
> > ? fhp->fh_post_saved = true;
> > + fhp->fh_post_change = nfsd4_change_attribute(&fhp->fh_post_attr,
> > + d_inode(fhp->fh_dentry));
> > ?}
> > ?
> >
> >
> >
> > ?/*
> > diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> > index 833a2c64dfe8..56fd5f6d5c44 100644
> > --- a/fs/nfsd/nfs4xdr.c
> > +++ b/fs/nfsd/nfs4xdr.c
> > @@ -2298,12 +2298,8 @@ static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
> > ? if (exp->ex_flags & NFSEXP_V4ROOT) {
> > ? *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time));
> > ? *p++ = 0;
> > - } else if (IS_I_VERSION(inode)) {
> > + } else
> > ? p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode));
> > - } else {
> > - *p++ = cpu_to_be32(stat->ctime.tv_sec);
> > - *p++ = cpu_to_be32(stat->ctime.tv_nsec);
> > - }
> > ? return p;
> > ?}
> > ?
> >
> >
> >
> > diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
> > index 56cfbc361561..39d764b129fa 100644
> > --- a/fs/nfsd/nfsfh.h
> > +++ b/fs/nfsd/nfsfh.h
> > @@ -261,10 +261,16 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat,
> > ?{
> > ? u64 chattr;
> > ?
> >
> >
> >
> > - chattr = stat->ctime.tv_sec;
> > - chattr <<= 30;
> > - chattr += stat->ctime.tv_nsec;
> > - chattr += inode_query_iversion(inode);
> > + if (IS_I_VERSION(inode)) {
> > + chattr = stat->ctime.tv_sec;
> > + chattr <<= 30;
> > + chattr += stat->ctime.tv_nsec;
> > + chattr += inode_query_iversion(inode);
> > + } else {
> > + chattr = stat->ctime.tv_sec;
> > + chattr <<= 32;
>
> Might be nice to annotate the shifts above and maybe make them named
> constants. I'm not sure where those values come from, tbh.

This shouldn't be changing the on-the-wire results at all; so
for example the latter is just doing exactly what:

> > - *p++ = cpu_to_be32(stat->ctime.tv_sec);
> > - *p++ = cpu_to_be32(stat->ctime.tv_nsec);

did (after xdr-encoding of the 64-bit chattr).

But yeah maybe it could use some explanation.

The 30-bit shift in the IS_I_VERSION case is weirder, I honestly don't
remember what I was thinking. Maybe just that nanoseconds really only
need 30 bits, and the shift would save a couple high bits in case we
wanted to change the format later without making the change attribute go
backwards. Probably overthinking it!

--b.

2020-12-01 21:37:51

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH 1/5] nfsd: only call inode_query_iversion in the I_VERSION case

On Tue, Dec 01, 2020 at 11:43:31AM -0500, Jeff Layton wrote:
> Are you planning to follow up with the series to add the fetch_iversion
> op, or have you decided not to do that for now?

I'm still interested. I just figured it's not urgent, and it'll be
easier to ask for fs-devel review after this other stuff is in, so it
may as well wait till after the merge window.

--b.