Commit 263453d9 authored by Chuck Lever's avatar Chuck Lever

NFSD: Add nfsd4_encode_fattr4_change()

Refactor the encoder for FATTR4_CHANGE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

The code is restructured a bit to use the modern xdr_stream flow,
and the encoded cinfo value is made const so that callers of the
encoders can be passed a const cinfo.
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 36ed7e64
...@@ -2530,17 +2530,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp) ...@@ -2530,17 +2530,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
return true; return true;
} }
static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
struct svc_export *exp)
{
if (exp->ex_flags & NFSEXP_V4ROOT) {
*p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time));
*p++ = 0;
} else
p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode));
return p;
}
static __be32 nfsd4_encode_nfstime4(struct xdr_stream *xdr, static __be32 nfsd4_encode_nfstime4(struct xdr_stream *xdr,
struct timespec64 *tv) struct timespec64 *tv)
{ {
...@@ -2581,15 +2570,17 @@ static __be32 *encode_time_delta(__be32 *p, struct inode *inode) ...@@ -2581,15 +2570,17 @@ static __be32 *encode_time_delta(__be32 *p, struct inode *inode)
} }
static __be32 static __be32
nfsd4_encode_change_info4(struct xdr_stream *xdr, struct nfsd4_change_info *c) nfsd4_encode_change_info4(struct xdr_stream *xdr, const struct nfsd4_change_info *c)
{ {
if (xdr_stream_encode_bool(xdr, c->atomic) < 0) __be32 status;
return nfserr_resource;
if (xdr_stream_encode_u64(xdr, c->before_change) < 0) status = nfsd4_encode_bool(xdr, c->atomic);
return nfserr_resource; if (status != nfs_ok)
if (xdr_stream_encode_u64(xdr, c->after_change) < 0) return status;
return nfserr_resource; status = nfsd4_encode_changeid4(xdr, c->before_change);
return nfs_ok; if (status != nfs_ok)
return status;
return nfsd4_encode_changeid4(xdr, c->after_change);
} }
/* Encode as an array of strings the string given with components /* Encode as an array of strings the string given with components
...@@ -3014,6 +3005,26 @@ static __be32 nfsd4_encode_fattr4_fh_expire_type(struct xdr_stream *xdr, ...@@ -3014,6 +3005,26 @@ static __be32 nfsd4_encode_fattr4_fh_expire_type(struct xdr_stream *xdr,
return nfsd4_encode_uint32_t(xdr, mask); return nfsd4_encode_uint32_t(xdr, mask);
} }
static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr,
const struct nfsd4_fattr_args *args)
{
const struct svc_export *exp = args->exp;
u64 c;
if (unlikely(exp->ex_flags & NFSEXP_V4ROOT)) {
u32 flush_time = convert_to_wallclock(exp->cd->flush_time);
if (xdr_stream_encode_u32(xdr, flush_time) != XDR_UNIT)
return nfserr_resource;
if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
return nfserr_resource;
return nfs_ok;
}
c = nfsd4_change_attribute(&args->stat, d_inode(args->dentry));
return nfsd4_encode_changeid4(xdr, c);
}
/* /*
* Note: @fhp can be NULL; in this case, we might have to compose the filehandle * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
* ourselves. * ourselves.
...@@ -3159,10 +3170,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, ...@@ -3159,10 +3170,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
goto out; goto out;
} }
if (bmval0 & FATTR4_WORD0_CHANGE) { if (bmval0 & FATTR4_WORD0_CHANGE) {
p = xdr_reserve_space(xdr, 8); status = nfsd4_encode_fattr4_change(xdr, &args);
if (!p) if (status != nfs_ok)
goto out_resource; goto out;
p = encode_change(p, &args.stat, d_inode(dentry), exp);
} }
if (bmval0 & FATTR4_WORD0_SIZE) { if (bmval0 & FATTR4_WORD0_SIZE) {
p = xdr_reserve_space(xdr, 8); p = xdr_reserve_space(xdr, 8);
......
...@@ -771,7 +771,7 @@ enum fsid_source fsid_source(const struct svc_fh *fhp) ...@@ -771,7 +771,7 @@ enum fsid_source fsid_source(const struct svc_fh *fhp)
* assume that the new change attr is always logged to stable storage in some * assume that the new change attr is always logged to stable storage in some
* fashion before the results can be seen. * fashion before the results can be seen.
*/ */
u64 nfsd4_change_attribute(struct kstat *stat, struct inode *inode) u64 nfsd4_change_attribute(const struct kstat *stat, const struct inode *inode)
{ {
u64 chattr; u64 chattr;
......
...@@ -293,7 +293,8 @@ static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp) ...@@ -293,7 +293,8 @@ static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
fhp->fh_pre_saved = false; fhp->fh_pre_saved = false;
} }
u64 nfsd4_change_attribute(struct kstat *stat, struct inode *inode); u64 nfsd4_change_attribute(const struct kstat *stat,
const struct inode *inode);
__be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp); __be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp);
__be32 fh_fill_post_attrs(struct svc_fh *fhp); __be32 fh_fill_post_attrs(struct svc_fh *fhp);
__be32 __must_check fh_fill_both_attrs(struct svc_fh *fhp); __be32 __must_check fh_fill_both_attrs(struct svc_fh *fhp);
......
...@@ -110,6 +110,8 @@ nfsd4_encode_uint64_t(struct xdr_stream *xdr, u64 val) ...@@ -110,6 +110,8 @@ nfsd4_encode_uint64_t(struct xdr_stream *xdr, u64 val)
return nfs_ok; return nfs_ok;
} }
#define nfsd4_encode_changeid4(x, v) nfsd4_encode_uint64_t(x, v)
/** /**
* nfsd4_encode_opaque_fixed - Encode a fixed-length XDR opaque type result * nfsd4_encode_opaque_fixed - Encode a fixed-length XDR opaque type result
* @xdr: target XDR stream * @xdr: target XDR stream
......
...@@ -256,7 +256,7 @@ inode_peek_iversion(const struct inode *inode) ...@@ -256,7 +256,7 @@ inode_peek_iversion(const struct inode *inode)
* For filesystems without any sort of change attribute, the best we can * For filesystems without any sort of change attribute, the best we can
* do is fake one up from the ctime: * do is fake one up from the ctime:
*/ */
static inline u64 time_to_chattr(struct timespec64 *t) static inline u64 time_to_chattr(const struct timespec64 *t)
{ {
u64 chattr = t->tv_sec; u64 chattr = t->tv_sec;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment