rctlops.c revision 1219:f89f56c2d9ac
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, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23/*
24 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25 * Use is subject to license terms.
26 */
27
28#pragma ident	"%Z%%M%	%I%	%E% SMI"
29
30#include "synonyms.h"
31#include <sys/rctl_impl.h>
32#include <stdlib.h>
33#include <string.h>
34#include <rctl.h>
35
36/*
37 * Resource control routines
38 *
39 * rctl_walk(3C)
40 *
41 * Resource control block manipulation routines
42 *   The setrctl(2) and getrctl(2) interfaces are accessed via opaque resource
43 *   control blocks, the characteristics of which are in turn set and fetched
44 *   using the following functions.  Applications using the following interfaces
45 *   will be binary compatible across enhancements to the resource control
46 *   subsystem that involve modification of the control block.
47 */
48int
49rctl_walk(int (*callback)(const char *rctlname, void *walk_data),
50    void *init_data)
51{
52	int ret = 0;
53	char *ctl_names, *curr_name;
54	size_t sz = rctllist(NULL, 0);
55
56	if ((ctl_names = malloc(sz)) == NULL)
57		return (-1);
58
59	(void) rctllist(ctl_names, sz);
60
61	for (curr_name = ctl_names;
62	    curr_name < ctl_names + sz;
63	    curr_name += strlen(curr_name) + 1) {
64		if (ret = callback(curr_name, init_data)) {
65			free(ctl_names);
66			return (ret);
67		}
68	}
69
70	free(ctl_names);
71	return (ret);
72}
73
74uint_t
75rctlblk_get_global_action(rctlblk_t *rblk)
76{
77	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
78
79	return (ropaque->rcq_global_flagaction & (~RCTL_GLOBAL_ACTION_MASK));
80}
81
82uint_t
83rctlblk_get_local_action(rctlblk_t *rblk, int *signal)
84{
85	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
86
87	if (signal != NULL)
88		*signal = ropaque->rcq_local_signal;
89	return (ropaque->rcq_local_flagaction & (~RCTL_LOCAL_ACTION_MASK));
90}
91
92uint_t
93rctlblk_get_global_flags(rctlblk_t *rblk)
94{
95	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
96
97	return (ropaque->rcq_global_flagaction & RCTL_GLOBAL_ACTION_MASK);
98}
99
100uint_t
101rctlblk_get_local_flags(rctlblk_t *rblk)
102{
103	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
104
105	return (ropaque->rcq_local_flagaction & RCTL_LOCAL_ACTION_MASK);
106}
107
108hrtime_t
109rctlblk_get_firing_time(rctlblk_t *rblk)
110{
111	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
112
113	return (ropaque->rcq_firing_time);
114}
115
116id_t
117rctlblk_get_recipient_pid(rctlblk_t *rblk)
118{
119	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
120
121	return (ropaque->rcq_local_recipient_pid);
122}
123
124rctl_priv_t
125rctlblk_get_privilege(rctlblk_t *rblk)
126{
127	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
128	return (ropaque->rcq_privilege);
129}
130
131rctl_qty_t
132rctlblk_get_value(rctlblk_t *rblk)
133{
134	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
135	return (ropaque->rcq_value);
136}
137
138rctl_qty_t
139rctlblk_get_enforced_value(rctlblk_t *rblk)
140{
141	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
142	return (ropaque->rcq_enforced_value);
143}
144
145void
146rctlblk_set_local_action(rctlblk_t *rblk, uint_t action, int signal)
147{
148	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
149	ropaque->rcq_local_signal = signal;
150	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
151	    RCTL_LOCAL_ACTION_MASK) | (action & ~RCTL_LOCAL_ACTION_MASK);
152}
153
154void
155rctlblk_set_local_flags(rctlblk_t *rblk, uint_t flags)
156{
157	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
158	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
159	    ~RCTL_LOCAL_ACTION_MASK) | (flags & RCTL_LOCAL_ACTION_MASK);
160}
161
162void
163rctlblk_set_recipient_pid(rctlblk_t *rblk, id_t pid)
164{
165	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
166	ropaque->rcq_local_recipient_pid = pid;
167}
168
169void
170rctlblk_set_privilege(rctlblk_t *rblk, rctl_priv_t privilege)
171{
172	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
173	ropaque->rcq_privilege = privilege;
174}
175
176void
177rctlblk_set_value(rctlblk_t *rblk, rctl_qty_t value)
178{
179	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
180	ropaque->rcq_value = value;
181}
182
183size_t
184rctlblk_size(void)
185{
186	return (sizeof (rctl_opaque_t));
187}
188