mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-22 20:30:58 +02:00
NFSD: Update the NFSv2 attrstat encoder to use struct xdr_stream
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
This commit is contained in:
@@ -640,7 +640,7 @@ static const struct svc_procedure nfsd_procedures2[18] = {
|
|||||||
[NFSPROC_GETATTR] = {
|
[NFSPROC_GETATTR] = {
|
||||||
.pc_func = nfsd_proc_getattr,
|
.pc_func = nfsd_proc_getattr,
|
||||||
.pc_decode = nfssvc_decode_fhandleargs,
|
.pc_decode = nfssvc_decode_fhandleargs,
|
||||||
.pc_encode = nfssvc_encode_attrstat,
|
.pc_encode = nfssvc_encode_attrstatres,
|
||||||
.pc_release = nfssvc_release_attrstat,
|
.pc_release = nfssvc_release_attrstat,
|
||||||
.pc_argsize = sizeof(struct nfsd_fhandle),
|
.pc_argsize = sizeof(struct nfsd_fhandle),
|
||||||
.pc_ressize = sizeof(struct nfsd_attrstat),
|
.pc_ressize = sizeof(struct nfsd_attrstat),
|
||||||
@@ -651,7 +651,7 @@ static const struct svc_procedure nfsd_procedures2[18] = {
|
|||||||
[NFSPROC_SETATTR] = {
|
[NFSPROC_SETATTR] = {
|
||||||
.pc_func = nfsd_proc_setattr,
|
.pc_func = nfsd_proc_setattr,
|
||||||
.pc_decode = nfssvc_decode_sattrargs,
|
.pc_decode = nfssvc_decode_sattrargs,
|
||||||
.pc_encode = nfssvc_encode_attrstat,
|
.pc_encode = nfssvc_encode_attrstatres,
|
||||||
.pc_release = nfssvc_release_attrstat,
|
.pc_release = nfssvc_release_attrstat,
|
||||||
.pc_argsize = sizeof(struct nfsd_sattrargs),
|
.pc_argsize = sizeof(struct nfsd_sattrargs),
|
||||||
.pc_ressize = sizeof(struct nfsd_attrstat),
|
.pc_ressize = sizeof(struct nfsd_attrstat),
|
||||||
@@ -714,7 +714,7 @@ static const struct svc_procedure nfsd_procedures2[18] = {
|
|||||||
[NFSPROC_WRITE] = {
|
[NFSPROC_WRITE] = {
|
||||||
.pc_func = nfsd_proc_write,
|
.pc_func = nfsd_proc_write,
|
||||||
.pc_decode = nfssvc_decode_writeargs,
|
.pc_decode = nfssvc_decode_writeargs,
|
||||||
.pc_encode = nfssvc_encode_attrstat,
|
.pc_encode = nfssvc_encode_attrstatres,
|
||||||
.pc_release = nfssvc_release_attrstat,
|
.pc_release = nfssvc_release_attrstat,
|
||||||
.pc_argsize = sizeof(struct nfsd_writeargs),
|
.pc_argsize = sizeof(struct nfsd_writeargs),
|
||||||
.pc_ressize = sizeof(struct nfsd_attrstat),
|
.pc_ressize = sizeof(struct nfsd_attrstat),
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
/*
|
/*
|
||||||
* Mapping of S_IF* types to NFS file types
|
* Mapping of S_IF* types to NFS file types
|
||||||
*/
|
*/
|
||||||
static u32 nfs_ftypes[] = {
|
static const u32 nfs_ftypes[] = {
|
||||||
NFNON, NFCHR, NFCHR, NFBAD,
|
NFNON, NFCHR, NFCHR, NFBAD,
|
||||||
NFDIR, NFBAD, NFBLK, NFBAD,
|
NFDIR, NFBAD, NFBLK, NFBAD,
|
||||||
NFREG, NFBAD, NFLNK, NFBAD,
|
NFREG, NFBAD, NFLNK, NFBAD,
|
||||||
@@ -70,6 +70,17 @@ encode_fh(__be32 *p, struct svc_fh *fhp)
|
|||||||
return p + (NFS_FHSIZE>> 2);
|
return p + (NFS_FHSIZE>> 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __be32 *
|
||||||
|
encode_timeval(__be32 *p, const struct timespec64 *time)
|
||||||
|
{
|
||||||
|
*p++ = cpu_to_be32((u32)time->tv_sec);
|
||||||
|
if (time->tv_nsec)
|
||||||
|
*p++ = cpu_to_be32(time->tv_nsec / NSEC_PER_USEC);
|
||||||
|
else
|
||||||
|
*p++ = xdr_zero;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
svcxdr_decode_filename(struct xdr_stream *xdr, char **name, unsigned int *len)
|
svcxdr_decode_filename(struct xdr_stream *xdr, char **name, unsigned int *len)
|
||||||
{
|
{
|
||||||
@@ -233,6 +244,64 @@ encode_fattr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp,
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
svcxdr_encode_fattr(struct svc_rqst *rqstp, struct xdr_stream *xdr,
|
||||||
|
const struct svc_fh *fhp, const struct kstat *stat)
|
||||||
|
{
|
||||||
|
struct user_namespace *userns = nfsd_user_namespace(rqstp);
|
||||||
|
struct dentry *dentry = fhp->fh_dentry;
|
||||||
|
int type = stat->mode & S_IFMT;
|
||||||
|
struct timespec64 time;
|
||||||
|
__be32 *p;
|
||||||
|
u32 fsid;
|
||||||
|
|
||||||
|
p = xdr_reserve_space(xdr, XDR_UNIT * 17);
|
||||||
|
if (!p)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*p++ = cpu_to_be32(nfs_ftypes[type >> 12]);
|
||||||
|
*p++ = cpu_to_be32((u32)stat->mode);
|
||||||
|
*p++ = cpu_to_be32((u32)stat->nlink);
|
||||||
|
*p++ = cpu_to_be32((u32)from_kuid_munged(userns, stat->uid));
|
||||||
|
*p++ = cpu_to_be32((u32)from_kgid_munged(userns, stat->gid));
|
||||||
|
|
||||||
|
if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN)
|
||||||
|
*p++ = cpu_to_be32(NFS_MAXPATHLEN);
|
||||||
|
else
|
||||||
|
*p++ = cpu_to_be32((u32) stat->size);
|
||||||
|
*p++ = cpu_to_be32((u32) stat->blksize);
|
||||||
|
if (S_ISCHR(type) || S_ISBLK(type))
|
||||||
|
*p++ = cpu_to_be32(new_encode_dev(stat->rdev));
|
||||||
|
else
|
||||||
|
*p++ = cpu_to_be32(0xffffffff);
|
||||||
|
*p++ = cpu_to_be32((u32)stat->blocks);
|
||||||
|
|
||||||
|
switch (fsid_source(fhp)) {
|
||||||
|
case FSIDSOURCE_FSID:
|
||||||
|
fsid = (u32)fhp->fh_export->ex_fsid;
|
||||||
|
break;
|
||||||
|
case FSIDSOURCE_UUID:
|
||||||
|
fsid = ((u32 *)fhp->fh_export->ex_uuid)[0];
|
||||||
|
fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[1];
|
||||||
|
fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[2];
|
||||||
|
fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[3];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fsid = new_encode_dev(stat->dev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*p++ = cpu_to_be32(fsid);
|
||||||
|
|
||||||
|
*p++ = cpu_to_be32((u32)stat->ino);
|
||||||
|
p = encode_timeval(p, &stat->atime);
|
||||||
|
time = stat->mtime;
|
||||||
|
lease_get_mtime(d_inode(dentry), &time);
|
||||||
|
p = encode_timeval(p, &time);
|
||||||
|
encode_timeval(p, &stat->ctime);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Helper function for NFSv2 ACL code */
|
/* Helper function for NFSv2 ACL code */
|
||||||
__be32 *nfs2svc_encode_fattr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp, struct kstat *stat)
|
__be32 *nfs2svc_encode_fattr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp, struct kstat *stat)
|
||||||
{
|
{
|
||||||
@@ -412,16 +481,21 @@ nfssvc_encode_statres(struct svc_rqst *rqstp, __be32 *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
nfssvc_encode_attrstat(struct svc_rqst *rqstp, __be32 *p)
|
nfssvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p)
|
||||||
{
|
{
|
||||||
|
struct xdr_stream *xdr = &rqstp->rq_res_stream;
|
||||||
struct nfsd_attrstat *resp = rqstp->rq_resp;
|
struct nfsd_attrstat *resp = rqstp->rq_resp;
|
||||||
|
|
||||||
*p++ = resp->status;
|
if (!svcxdr_encode_stat(xdr, resp->status))
|
||||||
if (resp->status != nfs_ok)
|
return 0;
|
||||||
goto out;
|
switch (resp->status) {
|
||||||
p = encode_fattr(rqstp, p, &resp->fh, &resp->stat);
|
case nfs_ok:
|
||||||
out:
|
if (!svcxdr_encode_fattr(rqstp, xdr, &resp->fh, &resp->stat))
|
||||||
return xdr_ressize_check(rqstp, p);
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@@ -148,7 +148,7 @@ int nfssvc_decode_linkargs(struct svc_rqst *, __be32 *);
|
|||||||
int nfssvc_decode_symlinkargs(struct svc_rqst *, __be32 *);
|
int nfssvc_decode_symlinkargs(struct svc_rqst *, __be32 *);
|
||||||
int nfssvc_decode_readdirargs(struct svc_rqst *, __be32 *);
|
int nfssvc_decode_readdirargs(struct svc_rqst *, __be32 *);
|
||||||
int nfssvc_encode_statres(struct svc_rqst *, __be32 *);
|
int nfssvc_encode_statres(struct svc_rqst *, __be32 *);
|
||||||
int nfssvc_encode_attrstat(struct svc_rqst *, __be32 *);
|
int nfssvc_encode_attrstatres(struct svc_rqst *, __be32 *);
|
||||||
int nfssvc_encode_diropres(struct svc_rqst *, __be32 *);
|
int nfssvc_encode_diropres(struct svc_rqst *, __be32 *);
|
||||||
int nfssvc_encode_readlinkres(struct svc_rqst *, __be32 *);
|
int nfssvc_encode_readlinkres(struct svc_rqst *, __be32 *);
|
||||||
int nfssvc_encode_readres(struct svc_rqst *, __be32 *);
|
int nfssvc_encode_readres(struct svc_rqst *, __be32 *);
|
||||||
|
Reference in New Issue
Block a user