xref: /illumos-gate/usr/src/lib/udapl/udapl_tavor/common/dapl_evd_query.c (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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_evd_query.c
34  *
35  * PURPOSE: Event management
36  * Description: Interfaces in this file are completely described in
37  *		the DAPL 1.1 API, Chapter 6, section 3
38  *
39  * $Id: dapl_evd_query.c,v 1.8 2003/08/20 13:18:36 sjs2 Exp $
40  */
41 
42 #include "dapl.h"
43 
44 /*
45  * dapl_evd_query
46  *
47  * DAPL Requirements Version xxx, 6.3.2.3
48  *
49  * Provides the consumer with arguments of the Event Dispatcher.
50  *
51  * Input:
52  * 	evd_handle
53  * 	evd_mask
54  *
55  * Output:
56  * 	evd_param
57  *
58  * Returns:
59  * 	DAT_SUCCESS
60  * 	DAT_INVALID_PARAMETER
61  */
62 DAT_RETURN
63 dapl_evd_query(
64 	IN	DAT_EVD_HANDLE		evd_handle,
65 	IN	DAT_EVD_PARAM_MASK	evd_param_mask,
66 	OUT	DAT_EVD_PARAM		*evd_param)
67 {
68 	DAPL_EVD	    *evd_ptr;
69 	DAT_RETURN	    dat_status;
70 
71 	dat_status = DAT_SUCCESS;
72 
73 	if (evd_param_mask & ~DAT_EVD_FIELD_ALL) {
74 		dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG2);
75 		goto bail;
76 	}
77 
78 	if (NULL == evd_param) {
79 		dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG3);
80 		goto bail;
81 	}
82 
83 	/*
84 	 * Note: the spec. allows for events to be directed to a NULL EVD
85 	 * with handle of type DAT_HANDLE_NULL. See 6.3.1
86 	 */
87 	if (DAT_HANDLE_NULL == evd_handle) {
88 		(void) dapl_os_memzero(evd_param, sizeof (DAT_EVD_PARAM));
89 	} else {
90 		if (DAPL_BAD_HANDLE(evd_handle, DAPL_MAGIC_EVD)) {
91 			dat_status = DAT_ERROR(DAT_INVALID_HANDLE, 0);
92 			goto bail;
93 		}
94 
95 		evd_ptr = (DAPL_EVD *) evd_handle;
96 
97 		/*
98 		 * We may be racing against the thread safe modify
99 		 * calls here (dat_evd_{enable,disable,{set,clear}_unwaitable}).
100 		 * They are thread safe, so our reads need to be atomic with
101 		 * regard to those calls.  The below is ok (a single bit
102 		 * read counts as atomic; if it's in transition you'll get one
103 		 * of the correct values) but we'll need to be careful
104 		 * about reading the state variable atomically when we add
105 		 * in waitable/unwaitable.
106 		 */
107 		evd_param->evd_state =
108 		    (evd_ptr->evd_enabled ? DAT_EVD_STATE_ENABLED :
109 		    DAT_EVD_STATE_DISABLED);
110 		evd_param->evd_state |=
111 		    (evd_ptr->evd_waitable ? DAT_EVD_STATE_WAITABLE :
112 		    DAT_EVD_STATE_UNWAITABLE);
113 		evd_param->ia_handle = evd_ptr->header.owner_ia;
114 		evd_param->evd_qlen = evd_ptr->qlen;
115 		evd_param->cno_handle = (DAT_CNO_HANDLE) evd_ptr->cno_ptr;
116 		evd_param->evd_flags  = evd_ptr->evd_flags;
117 	}
118 
119 bail:
120 		return (dat_status);
121 }
122