From: Michael Meffie Date: Mon, 14 Apr 2014 20:07:53 +0000 (-0400) Subject: libafs: api to create and free vrequests X-Git-Tag: upstream/1.8.0_pre1^2~688 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=76ad941902c650a4a716168d3cbe68f62aef109f;p=packages%2Fo%2Fopenafs.git libafs: api to create and free vrequests Add a pair of functions to allocate and free struct vrequests, which are to be used to avoid having struct vrequests on the stack. Change-Id: I6cbfe2ed21beb1ba500975188bb76608fdee4bc7 Reviewed-on: http://gerrit.openafs.org/11074 Reviewed-by: D Brashear Tested-by: D Brashear --- diff --git a/src/afs/afs_osi_pag.c b/src/afs/afs_osi_pag.c index 08ceb9ddb..ec85e2311 100644 --- a/src/afs/afs_osi_pag.c +++ b/src/afs/afs_osi_pag.c @@ -486,6 +486,64 @@ afs_InitReq(struct vrequest *av, afs_ucred_t *acred) return 0; } +/*! + * Allocate and setup a vrequest. + * + * \note The caller must free the allocated vrequest with + * afs_DestroyReq() if this function returns successfully (zero). + * + * \note The GLOCK must be held on platforms which require the GLOCK + * for osi_AllocSmallSpace() and osi_FreeSmallSpace(). + * + * \param[out] avpp address of the vrequest pointer + * \param[in] acred user credentials to setup the vrequest; may be NULL + * \return 0 on success + */ +int +afs_CreateReq(struct vrequest **avpp, afs_ucred_t *acred) +{ + int code; + struct vrequest *treq = NULL; + + if (afs_shuttingdown) { + return EIO; + } + if (!avpp) { + return EINVAL; + } + treq = osi_AllocSmallSpace(sizeof(struct vrequest)); + if (!treq) { + return ENOMEM; + } + if (!acred) { + memset(treq, 0, sizeof(struct vrequest)); + } else { + code = afs_InitReq(treq, acred); + if (code != 0) { + osi_FreeSmallSpace(treq); + return code; + } + } + *avpp = treq; + return 0; +} + +/*! + * Deallocate a vrequest. + * + * \note The GLOCK must be held on platforms which require the GLOCK + * for osi_FreeSmallSpace(). + * + * \param[in] av pointer to the vrequest to free; may be NULL + */ +void +afs_DestroyReq(struct vrequest *av) +{ + if (av) { + osi_FreeSmallSpace(av); + } +} + #ifndef AFS_LINUX26_ONEGROUP_ENV afs_uint32 afs_get_pag_from_groups(gid_t g0a, gid_t g1a) diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index f9d1cf0b0..df056b038 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -601,6 +601,8 @@ extern int AddPag(afs_proc_t *p, afs_int32 aval, afs_ucred_t **credpp); extern int AddPag(afs_int32 aval, afs_ucred_t **credpp); #endif extern int afs_InitReq(struct vrequest *av, afs_ucred_t *acred); +extern int afs_CreateReq(struct vrequest **avpp, afs_ucred_t *acred); +extern void afs_DestroyReq(struct vrequest *av); extern afs_uint32 afs_get_pag_from_groups(gid_t g0a, gid_t g1a); extern void afs_get_groups_from_pag(afs_uint32 pag, gid_t * g0p, gid_t * g1p); extern afs_int32 PagInCred(afs_ucred_t *cred);