From f1303a1f4fc710af286e12dae50ff44c93b7cb0b 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. 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 (cherry picked from commit 9630c075409a262424805411ed473178814b412c) Change-Id: I7746ee69f7fde8760c066458ecfe44da46edbf81 Reviewed-on: http://gerrit.openafs.org/11338 Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Andrew Deason Reviewed-by: Benjamin Kaduk Tested-by: BuildBot Reviewed-by: Stephan Wiesand --- 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 74b3bbb27..2eb228fdf 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 * */ @@ -645,3 +647,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 70e4832fa..9e9f65b19 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -1132,6 +1132,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 -- 2.39.5