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 2003 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /*
32  *
33  * MODULE: dapl_cno_free.c
34  *
35  * PURPOSE: Consumer Notification Object destruction
36  * Description: Interfaces in this file are completely described in
37  *		the DAPL 1.1 API, Chapter 6, section 3.2.2
38  *
39  * $Id: dapl_cno_free.c,v 1.5 2003/06/16 17:53:32 sjs2 Exp $
40  */
41 
42 #include "dapl.h"
43 #include "dapl_ia_util.h"
44 #include "dapl_cno_util.h"
45 #include "dapl_adapter_util.h"
46 
47 /*
48  * dapl_cno_free
49  *
50  * DAPL Requirements Version xxx, 6.3.2.2
51  *
52  * Destroy a consumer notification object instance
53  *
54  * Input:
55  *	cno_handle
56  *
57  * Output:
58  *	none
59  *
60  * Returns:
61  *	DAT_SUCCESS
62  *	DAT_INVALID_HANDLE
63  *	DAT_INVALID_STATE
64  */
65 DAT_RETURN
dapl_cno_free(IN DAT_CNO_HANDLE cno_handle)66 dapl_cno_free(
67 	IN	DAT_CNO_HANDLE		cno_handle)	/* cno_handle */
68 {
69 	DAPL_CNO    *cno_ptr;
70 	DAT_RETURN  dat_status;
71 
72 	dat_status = DAT_SUCCESS;
73 	cno_ptr = (DAPL_CNO *)cno_handle;
74 
75 	if (DAPL_BAD_HANDLE(cno_handle, DAPL_MAGIC_CNO)) {
76 		dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
77 		    DAT_INVALID_HANDLE_CNO);
78 		goto bail;
79 	}
80 
81 	if (cno_ptr->cno_ref_count != 0 || cno_ptr->cno_waiters != 0) {
82 		dat_status = DAT_ERROR(DAT_INVALID_STATE,
83 		    DAT_INVALID_STATE_CNO_IN_USE);
84 		goto bail;
85 	}
86 
87 	dapl_os_lock(&cno_ptr->header.lock);
88 	if (!dapl_llist_is_empty(&cno_ptr->evd_list_head)) {
89 		dapl_dbg_log(DAPL_DBG_TYPE_UTIL,
90 		    "cno_free: evd list not empty!\n");
91 		dapl_os_unlock(&cno_ptr->header.lock);
92 		dat_status =  DAT_ERROR(DAT_INVALID_STATE,
93 		    DAT_INVALID_STATE_CNO_IN_USE);
94 		goto bail;
95 	}
96 	dapl_os_unlock(&cno_ptr->header.lock);
97 
98 	dat_status = dapls_ib_cno_free(cno_ptr);
99 	if (dat_status != DAT_SUCCESS) {
100 		goto bail;
101 	}
102 
103 	dapl_ia_unlink_cno(cno_ptr->header.owner_ia, cno_ptr);
104 	dapl_cno_dealloc(cno_ptr);
105 
106 bail:
107 	return (dat_status);
108 }
109