libafs: api to create and free vrequests
authorMichael Meffie <mmeffie@sinenomine.net>
Mon, 14 Apr 2014 20:07:53 +0000 (16:07 -0400)
committerD Brashear <shadow@your-file-system.com>
Wed, 21 May 2014 14:31:17 +0000 (10:31 -0400)
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 <shadow@your-file-system.com>
Tested-by: D Brashear <shadow@your-file-system.com>

src/afs/afs_osi_pag.c
src/afs/afs_prototypes.h

index 08ceb9d..ec85e23 100644 (file)
@@ -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)
index f9d1cf0..df056b0 100644 (file)
@@ -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);