xref: /illumos-gate/usr/src/lib/udapl/udapl_tavor/common/dapl_pz_util.c (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24  */
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /*
32  *
33  * MODULE: dapl_pz_util.c
34  *
35  * PURPOSE: Manage PZ structure
36  *
37  * $Id: dapl_pz_util.c,v 1.7 2003/06/13 12:21:11 sjs2 Exp $
38  */
39 
40 #include "dapl_pz_util.h"
41 #include "dapl_ia_util.h"
42 
43 /*
44  * dapl_pz_alloc
45  *
46  * alloc and initialize an PZ struct
47  *
48  * Input:
49  * 	none
50  *
51  * Output:
52  * 	pz_ptr
53  *
54  * Returns:
55  * 	none
56  *
57  */
58 DAPL_PZ *
dapl_pz_alloc(IN DAPL_IA * ia)59 dapl_pz_alloc(
60     IN DAPL_IA 		*ia)
61 {
62 	DAPL_PZ *pz;
63 
64 	/* Allocate PZ */
65 	pz = (DAPL_PZ *) dapl_os_alloc(sizeof (DAPL_PZ));
66 	if (NULL == pz) {
67 		return (NULL);
68 	}
69 
70 	/* zero the structure */
71 	(void) dapl_os_memzero(pz, sizeof (DAPL_PZ));
72 
73 	/*
74 	 * initialize the header
75 	 */
76 	pz->header.provider	   = ia->header.provider;
77 	pz->header.magic	   = DAPL_MAGIC_PZ;
78 	pz->header.handle_type	   = DAT_HANDLE_TYPE_PZ;
79 	pz->header.owner_ia	   = ia;
80 	pz->header.user_context.as_64  = 0;
81 	pz->header.user_context.as_ptr = NULL;
82 	dapl_llist_init_entry(&pz->header.ia_list_entry);
83 	dapl_ia_link_pz(ia, pz);
84 	dapl_os_lock_init(&pz->header.lock);
85 
86 	/*
87 	 * initialize the body
88 	 */
89 	pz->pz_ref_count = 0;
90 
91 	return (pz);
92 }
93 
94 /*
95  * dapl_pz_dealloc
96  *
97  * free an PZ struct
98  *
99  * Input:
100  * 	pz_ptr
101  *
102  * Output:
103  * 	none
104  *
105  * Returns:
106  * 	none
107  *
108  */
109 void
dapl_pz_dealloc(IN DAPL_PZ * pz)110 dapl_pz_dealloc(
111 	IN DAPL_PZ *pz)
112 {
113 	/* reset magic to prevent reuse */
114 	pz->header.magic = DAPL_MAGIC_INVALID;
115 	dapl_ia_unlink_pz(pz->header.owner_ia, pz);
116 	dapl_os_lock_destroy(&pz->header.lock);
117 
118 	dapl_os_free(pz, sizeof (DAPL_PZ));
119 }
120