static unsigned encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, uint32_t **savep) { uint32_t bm[2]; uint32_t *p; bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0); bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1); if (bm[1] != 0) { p = xdr_reserve_space(xdr, 16); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); *p++ = htonl(2); *p++ = bm[0]; *p++ = bm[1]; } else if (bm[0] != 0) { p = xdr_reserve_space(xdr, 12); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); *p++ = htonl(1); *p++ = bm[0]; } else { p = xdr_reserve_space(xdr, 8); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); *p++ = htonl(0); } *savep = p; return 0; }
static int gssx_enc_cb(struct xdr_stream *xdr, struct gssx_cb *cb) { __be32 *p; int err; /* cb->initiator_addrtype */ p = xdr_reserve_space(xdr, 8); if (!p) return -ENOSPC; p = xdr_encode_hyper(p, cb->initiator_addrtype); /* cb->initiator_address */ err = gssx_enc_buffer(xdr, &cb->initiator_address); if (err) return err; /* cb->acceptor_addrtype */ p = xdr_reserve_space(xdr, 8); if (!p) return -ENOSPC; p = xdr_encode_hyper(p, cb->acceptor_addrtype); /* cb->acceptor_address */ err = gssx_enc_buffer(xdr, &cb->acceptor_address); if (err) return err; /* cb->application_data */ err = gssx_enc_buffer(xdr, &cb->application_data); return err; }
static void encode_sattrguard3(struct xdr_stream *xdr, const struct nfs3_sattrargs *args) { __be32 *p; if (args->guard) { p = xdr_reserve_space(xdr, 4 + 8); *p++ = xdr_one; xdr_encode_nfstime3(p, &args->guardtime); } else { p = xdr_reserve_space(xdr, 4); *p = xdr_zero; } }
/* * Marshal credentials. * Maybe we should keep a cached credential for performance reasons. */ static int unx_marshal(struct rpc_task *task, struct xdr_stream *xdr) { struct rpc_clnt *clnt = task->tk_client; struct rpc_cred *cred = task->tk_rqstp->rq_cred; __be32 *p, *cred_len, *gidarr_len; int i; struct group_info *gi = cred->cr_cred->group_info; /* Credential */ p = xdr_reserve_space(xdr, 3 * sizeof(*p)); if (!p) goto marshal_failed; *p++ = rpc_auth_unix; cred_len = p++; *p++ = xdr_zero; /* stamp */ if (xdr_stream_encode_opaque(xdr, clnt->cl_nodename, clnt->cl_nodelen) < 0) goto marshal_failed; p = xdr_reserve_space(xdr, 3 * sizeof(*p)); if (!p) goto marshal_failed; *p++ = cpu_to_be32(from_kuid(&init_user_ns, cred->cr_cred->fsuid)); *p++ = cpu_to_be32(from_kgid(&init_user_ns, cred->cr_cred->fsgid)); gidarr_len = p++; if (gi) for (i = 0; i < UNX_NGROUPS && i < gi->ngroups; i++) *p++ = cpu_to_be32(from_kgid(&init_user_ns, gi->gid[i])); *gidarr_len = cpu_to_be32(p - gidarr_len - 1); *cred_len = cpu_to_be32((p - cred_len - 1) << 2); p = xdr_reserve_space(xdr, (p - gidarr_len - 1) << 2); if (!p) goto marshal_failed; /* Verifier */ p = xdr_reserve_space(xdr, 2 * sizeof(*p)); if (!p) goto marshal_failed; *p++ = rpc_auth_null; *p = xdr_zero; return 0; marshal_failed: return -EMSGSIZE; }
static unsigned encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr) { unsigned status; hdr->status = xdr_reserve_space(xdr, 4); if (unlikely(hdr->status == NULL)) return htonl(NFS4ERR_RESOURCE); status = encode_string(xdr, hdr->taglen, hdr->tag); if (unlikely(status != 0)) return status; hdr->nops = xdr_reserve_space(xdr, 4); if (unlikely(hdr->nops == NULL)) return htonl(NFS4ERR_RESOURCE); return 0; }
static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req, struct xdr_stream *xdr, const struct nfs3_setaclargs *args) { unsigned int base; int error; encode_nfs_fh3(xdr, NFS_FH(args->inode)); encode_uint32(xdr, args->mask); base = req->rq_slen; if (args->npages != 0) xdr_write_pages(xdr, args->pages, 0, args->len); else xdr_reserve_space(xdr, NFS_ACL_INLINE_BUFSIZE); error = nfsacl_encode(xdr->buf, base, args->inode, (args->mask & NFS_ACL) ? args->acl_access : NULL, 1, 0); BUG_ON(error < 0); error = nfsacl_encode(xdr->buf, base + error, args->inode, (args->mask & NFS_DFACL) ? args->acl_default : NULL, 1, NFS_ACL_DEFAULT); BUG_ON(error < 0); }
static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr) { u32 nbytes; __be32 *p; nbytes = 6 * 4; if (attr->ia_valid & ATTR_MODE) nbytes += 4; if (attr->ia_valid & ATTR_UID) nbytes += 4; if (attr->ia_valid & ATTR_GID) nbytes += 4; if (attr->ia_valid & ATTR_SIZE) nbytes += 8; if (attr->ia_valid & ATTR_ATIME_SET) nbytes += 8; if (attr->ia_valid & ATTR_MTIME_SET) nbytes += 8; p = xdr_reserve_space(xdr, nbytes); if (attr->ia_valid & ATTR_MODE) { *p++ = xdr_one; *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO); } else *p++ = xdr_zero; if (attr->ia_valid & ATTR_UID) { *p++ = xdr_one; *p++ = cpu_to_be32(attr->ia_uid); } else *p++ = xdr_zero; if (attr->ia_valid & ATTR_GID) { *p++ = xdr_one; *p++ = cpu_to_be32(attr->ia_gid); } else *p++ = xdr_zero; if (attr->ia_valid & ATTR_SIZE) { *p++ = xdr_one; p = xdr_encode_hyper(p, (u64)attr->ia_size); } else *p++ = xdr_zero; if (attr->ia_valid & ATTR_ATIME_SET) { *p++ = xdr_two; p = xdr_encode_nfstime3(p, &attr->ia_atime); } else if (attr->ia_valid & ATTR_ATIME) { *p++ = xdr_one; } else *p++ = xdr_zero; if (attr->ia_valid & ATTR_MTIME_SET) { *p++ = xdr_two; xdr_encode_nfstime3(p, &attr->ia_mtime); } else if (attr->ia_valid & ATTR_MTIME) { *p = xdr_one; } else *p = xdr_zero; }
static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier) { __be32 *p; p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE); memcpy(p, verifier, NFS3_CREATEVERFSIZE); }
static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_sequenceres *res) { __be32 *p; __be32 status = res->csr_status; if (unlikely(status != 0)) goto out; status = encode_sessionid(xdr, &res->csr_sessionid); if (status) goto out; p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t)); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); *p++ = htonl(res->csr_sequenceid); *p++ = htonl(res->csr_slotid); *p++ = htonl(res->csr_highestslotid); *p++ = htonl(res->csr_target_highestslotid); out: dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); return status; }
static void encode_bool(struct xdr_stream *xdr, const int value) { __be32 *p; p = xdr_reserve_space(xdr, 4); *p = value ? xdr_one : xdr_zero; }
static void encode_nfs_cb_opnum4(struct xdr_stream *xdr, enum nfs_cb_opnum4 op) { __be32 *p; p = xdr_reserve_space(xdr, 4); *p = cpu_to_be32(op); }
static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const void *resp) { const struct cb_sequenceres *res = resp; __be32 *p; __be32 status = res->csr_status; if (unlikely(status != 0)) return status; status = encode_sessionid(xdr, &res->csr_sessionid); if (status) return status; p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t)); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); *p++ = htonl(res->csr_sequenceid); *p++ = htonl(res->csr_slotid); *p++ = htonl(res->csr_highestslotid); *p++ = htonl(res->csr_target_highestslotid); return 0; }
/* * 2.3.3. fhandle * * typedef opaque fhandle[FHSIZE]; */ static void encode_fhandle(struct xdr_stream *xdr, const struct nfs_fh *fh) { __be32 *p; p = xdr_reserve_space(xdr, NFS2_FHSIZE); memcpy(p, fh->data, NFS2_FHSIZE); }
static void encode_int32(struct xdr_stream *xdr, const s32 value) { __be32 *p; p = xdr_reserve_space(xdr, 4); *p = cpu_to_be32(value); }
/* * stateid4 * * struct stateid4 { * uint32_t seqid; * opaque other[12]; * }; */ static void encode_stateid4(struct xdr_stream *xdr, const stateid_t *sid) { __be32 *p; p = xdr_reserve_space(xdr, NFS4_STATEID_SIZE); *p++ = cpu_to_be32(sid->si_generation); xdr_encode_opaque_fixed(p, &sid->si_opaque, NFS4_STATEID_OTHER_SIZE); }
/* * 2.3.8. path * * typedef string path<MAXPATHLEN>; */ static void encode_path(struct xdr_stream *xdr, struct page **pages, u32 length) { __be32 *p; p = xdr_reserve_space(xdr, 4); *p = cpu_to_be32(length); xdr_write_pages(xdr, pages, 0, length); }
static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev) { __be32 *p; p = xdr_reserve_space(xdr, 8); *p++ = cpu_to_be32(MAJOR(rdev)); *p = cpu_to_be32(MINOR(rdev)); }
static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh) { __be32 *p; BUG_ON(fh->size > NFS3_FHSIZE); p = xdr_reserve_space(xdr, 4 + fh->size); xdr_encode_opaque(p, fh->data, fh->size); }
static void encode_nlm_stat(struct xdr_stream *xdr, const __be32 stat) { __be32 *p; BUG_ON(be32_to_cpu(stat) > NLM_LCK_DENIED_GRACE_PERIOD); p = xdr_reserve_space(xdr, 4); *p = stat; }
/* * typedef opaque netobj<MAXNETOBJ_SZ> */ static void encode_netobj(struct xdr_stream *xdr, const u8 *data, const unsigned int length) { __be32 *p; BUG_ON(length > XDR_MAX_NETOBJ); p = xdr_reserve_space(xdr, 4 + length); xdr_encode_opaque(p, data, length); }
/* * 2.3.7. filename * * typedef string filename<MAXNAMLEN>; */ static void encode_filename(struct xdr_stream *xdr, const char *name, u32 length) { __be32 *p; BUG_ON(length > NFS2_MAXNAMLEN); p = xdr_reserve_space(xdr, 4 + length); xdr_encode_opaque(p, name, length); }
/* * enum nlm4_stats { * NLM4_GRANTED = 0, * NLM4_DENIED = 1, * NLM4_DENIED_NOLOCKS = 2, * NLM4_BLOCKED = 3, * NLM4_DENIED_GRACE_PERIOD = 4, * NLM4_DEADLCK = 5, * NLM4_ROFS = 6, * NLM4_STALE_FH = 7, * NLM4_FBIG = 8, * NLM4_FAILED = 9 * }; * * struct nlm4_stat { * nlm4_stats stat; * }; * * NB: we don't swap bytes for the NLM status values. The upper * layers deal directly with the status value in network byte * order. */ static void encode_nlm4_stat(struct xdr_stream *xdr, const __be32 stat) { __be32 *p; BUG_ON(be32_to_cpu(stat) > NLM_FAILED); p = xdr_reserve_space(xdr, 4); *p = stat; }
/* * sessionid4 * * typedef opaque sessionid4[NFS4_SESSIONID_SIZE]; */ static void encode_sessionid4(struct xdr_stream *xdr, const struct nfsd4_session *session) { __be32 *p; p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN); xdr_encode_opaque_fixed(p, session->se_sessionid.data, NFS4_MAX_SESSIONID_LEN); }
/* * nfs_fh4 * * typedef opaque nfs_fh4<NFS4_FHSIZE>; */ static void encode_nfs_fh4(struct xdr_stream *xdr, const struct knfsd_fh *fh) { u32 length = fh->fh_size; __be32 *p; BUG_ON(length > NFS4_FHSIZE); p = xdr_reserve_space(xdr, 4 + length); xdr_encode_opaque(p, &fh->fh_base, length); }
static void encode_caller_name(struct xdr_stream *xdr, const char *name) { u32 length = strlen(name); __be32 *p; BUG_ON(length > NLM_MAXSTRLEN); p = xdr_reserve_space(xdr, 4 + length); xdr_encode_opaque(p, name, length); }
static int gssx_enc_bool(struct xdr_stream *xdr, int v) { __be32 *p; p = xdr_reserve_space(xdr, 4); if (unlikely(p == NULL)) return -ENOSPC; *p = v ? xdr_one : xdr_zero; return 0; }
static unsigned encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) { uint32_t *p; p = xdr_reserve_space(xdr, 4 + len); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); xdr_encode_opaque(p, str, len); return 0; }
__be32 *pnfs_osd_xdr_ioerr_reserve_space(struct xdr_stream *xdr) { __be32 *p; p = xdr_reserve_space(xdr, 32 + 24); if (unlikely(!p)) dprintk("%s: out of xdr space\n", __func__); return p; }
/* * string caller_name<LM_MAXSTRLEN>; */ static void encode_caller_name(struct xdr_stream *xdr, const char *name) { /* NB: client-side does not set lock->len */ u32 length = strlen(name); __be32 *p; BUG_ON(length > NLM_MAXSTRLEN); p = xdr_reserve_space(xdr, 4 + length); xdr_encode_opaque(p, name, length); }
static unsigned encode_op_hdr(struct xdr_stream *xdr, uint32_t op, uint32_t res) { uint32_t *p; p = xdr_reserve_space(xdr, 8); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); *p++ = htonl(op); *p = res; return 0; }