Skip to content

Commit 23e50fe

Browse files
fllindenchucklever
authored andcommitted
nfsd: implement the xattr functions and en/decode logic
Implement the main entry points for the *XATTR operations. Add functions to calculate the reply size for the user extended attribute operations, and implement the XDR encode / decode logic for these operations. Add the user extended attributes operations to nfsd4_ops. Signed-off-by: Frank van der Linden <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 6178713 commit 23e50fe

File tree

3 files changed

+571
-1
lines changed

3 files changed

+571
-1
lines changed

fs/nfsd/nfs4proc.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,68 @@ nfsd4_layoutreturn(struct svc_rqst *rqstp,
20972097
}
20982098
#endif /* CONFIG_NFSD_PNFS */
20992099

2100+
static __be32
2101+
nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2102+
union nfsd4_op_u *u)
2103+
{
2104+
struct nfsd4_getxattr *getxattr = &u->getxattr;
2105+
2106+
return nfsd_getxattr(rqstp, &cstate->current_fh,
2107+
getxattr->getxa_name, &getxattr->getxa_buf,
2108+
&getxattr->getxa_len);
2109+
}
2110+
2111+
static __be32
2112+
nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2113+
union nfsd4_op_u *u)
2114+
{
2115+
struct nfsd4_setxattr *setxattr = &u->setxattr;
2116+
__be32 ret;
2117+
2118+
if (opens_in_grace(SVC_NET(rqstp)))
2119+
return nfserr_grace;
2120+
2121+
ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name,
2122+
setxattr->setxa_buf, setxattr->setxa_len,
2123+
setxattr->setxa_flags);
2124+
2125+
if (!ret)
2126+
set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh);
2127+
2128+
return ret;
2129+
}
2130+
2131+
static __be32
2132+
nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2133+
union nfsd4_op_u *u)
2134+
{
2135+
/*
2136+
* Get the entire list, then copy out only the user attributes
2137+
* in the encode function.
2138+
*/
2139+
return nfsd_listxattr(rqstp, &cstate->current_fh,
2140+
&u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len);
2141+
}
2142+
2143+
static __be32
2144+
nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2145+
union nfsd4_op_u *u)
2146+
{
2147+
struct nfsd4_removexattr *removexattr = &u->removexattr;
2148+
__be32 ret;
2149+
2150+
if (opens_in_grace(SVC_NET(rqstp)))
2151+
return nfserr_grace;
2152+
2153+
ret = nfsd_removexattr(rqstp, &cstate->current_fh,
2154+
removexattr->rmxa_name);
2155+
2156+
if (!ret)
2157+
set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh);
2158+
2159+
return ret;
2160+
}
2161+
21002162
/*
21012163
* NULL call.
21022164
*/
@@ -2706,6 +2768,42 @@ static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
27062768
return (op_encode_hdr_size + 3) * sizeof(__be32);
27072769
}
27082770

2771+
static inline u32 nfsd4_getxattr_rsize(struct svc_rqst *rqstp,
2772+
struct nfsd4_op *op)
2773+
{
2774+
u32 maxcount, rlen;
2775+
2776+
maxcount = svc_max_payload(rqstp);
2777+
rlen = min_t(u32, XATTR_SIZE_MAX, maxcount);
2778+
2779+
return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
2780+
}
2781+
2782+
static inline u32 nfsd4_setxattr_rsize(struct svc_rqst *rqstp,
2783+
struct nfsd4_op *op)
2784+
{
2785+
return (op_encode_hdr_size + op_encode_change_info_maxsz)
2786+
* sizeof(__be32);
2787+
}
2788+
static inline u32 nfsd4_listxattrs_rsize(struct svc_rqst *rqstp,
2789+
struct nfsd4_op *op)
2790+
{
2791+
u32 maxcount, rlen;
2792+
2793+
maxcount = svc_max_payload(rqstp);
2794+
rlen = min(op->u.listxattrs.lsxa_maxcount, maxcount);
2795+
2796+
return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
2797+
}
2798+
2799+
static inline u32 nfsd4_removexattr_rsize(struct svc_rqst *rqstp,
2800+
struct nfsd4_op *op)
2801+
{
2802+
return (op_encode_hdr_size + op_encode_change_info_maxsz)
2803+
* sizeof(__be32);
2804+
}
2805+
2806+
27092807
static const struct nfsd4_operation nfsd4_ops[] = {
27102808
[OP_ACCESS] = {
27112809
.op_func = nfsd4_access,
@@ -3087,6 +3185,28 @@ static const struct nfsd4_operation nfsd4_ops[] = {
30873185
.op_name = "OP_COPY_NOTIFY",
30883186
.op_rsize_bop = nfsd4_copy_notify_rsize,
30893187
},
3188+
[OP_GETXATTR] = {
3189+
.op_func = nfsd4_getxattr,
3190+
.op_name = "OP_GETXATTR",
3191+
.op_rsize_bop = nfsd4_getxattr_rsize,
3192+
},
3193+
[OP_SETXATTR] = {
3194+
.op_func = nfsd4_setxattr,
3195+
.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3196+
.op_name = "OP_SETXATTR",
3197+
.op_rsize_bop = nfsd4_setxattr_rsize,
3198+
},
3199+
[OP_LISTXATTRS] = {
3200+
.op_func = nfsd4_listxattrs,
3201+
.op_name = "OP_LISTXATTRS",
3202+
.op_rsize_bop = nfsd4_listxattrs_rsize,
3203+
},
3204+
[OP_REMOVEXATTR] = {
3205+
.op_func = nfsd4_removexattr,
3206+
.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
3207+
.op_name = "OP_REMOVEXATTR",
3208+
.op_rsize_bop = nfsd4_removexattr_rsize,
3209+
},
30903210
};
30913211

30923212
/**

0 commit comments

Comments
 (0)