From 9630c075409a262424805411ed473178814b412c Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Sun, 18 May 2014 17:17:38 -0400 Subject: [PATCH] libafs: api to create and free vattrs Add a pair of functions to allocate and free struct vattrs, to avoid having struct vattrs on the stack. Change-Id: Ia5a148ebcdf8a2f1e3a2aa9d8fd3c0e0cd0e25e9 Reviewed-on: http://gerrit.openafs.org/11169 Tested-by: BuildBot Reviewed-by: Perry Ruiter Reviewed-by: Benjamin Kaduk Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: D Brashear --- src/afs/VNOPS/afs_vnop_attrs.c | 48 ++++++++++++++++++++++++++++++++++++++++++ src/afs/afs_prototypes.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/src/afs/VNOPS/afs_vnop_attrs.c b/src/afs/VNOPS/afs_vnop_attrs.c index 64797c2..798e2c1 100644 --- a/src/afs/VNOPS/afs_vnop_attrs.c +++ b/src/afs/VNOPS/afs_vnop_attrs.c @@ -17,6 +17,8 @@ * afs_getattr * afs_VAttrToAS * afs_setattr + * afs_CreateAttr + * afs_DestroyAttr * */ @@ -654,3 +656,49 @@ afs_setattr(OSI_VC_DECL(avc), struct vattr *attrs, afs_DestroyReq(treq); return code; } + +/*! + * Allocate a vattr. + * + * \note The caller must free the allocated vattr with + * afs_DestroyAttr() 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] out address of the vattr pointer + * \return 0 on success + */ +int +afs_CreateAttr(struct vattr **out) +{ + struct vattr *vattr = NULL; + + if (!out) { + return EINVAL; + } + vattr = osi_AllocSmallSpace(sizeof(struct vattr)); + if (!vattr) { + return ENOMEM; + } + memset(vattr, 0, sizeof(struct vattr)); + *out = vattr; + return 0; +} + +/*! + * Deallocate a vattr. + * + * \note The GLOCK must be held on platforms which require the GLOCK + * for osi_FreeSmallSpace(). + * + * \param[in] vattr pointer to the vattr to free; may be NULL + */ +void +afs_DestroyAttr(struct vattr *vattr) +{ + if (vattr) { + osi_FreeSmallSpace(vattr); + } +} + diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index df056b0..6a1db16 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -1171,6 +1171,8 @@ extern int afs_setattr(OSI_VC_DECL(avc), struct vattr *attrs, extern int afs_setattr(OSI_VC_DECL(avc), struct vattr *attrs, afs_ucred_t *acred); #endif +extern int afs_CreateAttr(struct vattr **out); +extern void afs_DestroyAttr(struct vattr *vattr); /* VNOPS/afs_vnop_create.c */ #ifdef AFS_SGI64_ENV -- 1.9.4