]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
libafs: api to create and free vattrs
authorMichael Meffie <mmeffie@sinenomine.net>
Sun, 18 May 2014 21:17:38 +0000 (17:17 -0400)
committerStephan Wiesand <stephan.wiesand@desy.de>
Wed, 13 Aug 2014 15:27:56 +0000 (11:27 -0400)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Perry Ruiter <pruiter@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: D Brashear <shadow@your-file-system.com>
(cherry picked from commit 9630c075409a262424805411ed473178814b412c)

Change-Id: I7746ee69f7fde8760c066458ecfe44da46edbf81
Reviewed-on: http://gerrit.openafs.org/11338
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
src/afs/VNOPS/afs_vnop_attrs.c
src/afs/afs_prototypes.h

index 74b3bbb276ee5562d4bdb317a2b7c8c3492207df..2eb228fdf459f11163d2d0cead957fc23affbe17 100644 (file)
@@ -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);
+    }
+}
+
index 70e4832fa92cba31a717b9f4047ce39cc6911cbd..9e9f65b1975c504f53affe8e887247f2d65e6c44 100644 (file)
@@ -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