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 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _LOWLEVEL_IMPL_H 27 #define _LOWLEVEL_IMPL_H 28 29 #include "libscf_impl.h" 30 31 #include <door.h> 32 #include <libuutil.h> 33 #include <limits.h> 34 #include <pthread.h> 35 #include <stddef.h> 36 37 #include "repcache_protocol.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 typedef struct scf_datael { 44 scf_handle_t *rd_handle; 45 uint32_t rd_entity; 46 uint32_t rd_type; 47 uint32_t rd_reset; 48 uu_list_node_t rd_node; 49 } scf_datael_t; 50 #define DATAEL_VALID 0x0001 51 52 /* 53 * Handle structure. 54 * 55 * Access to handles is serialized -- access to and modification of a handle 56 * and all of its children is protected by rh_lock. 57 * 58 * Different handles don't interfere with each other. 59 */ 60 struct scf_handle { 61 pthread_mutex_t rh_lock; 62 pthread_cond_t rh_cv; 63 64 uint32_t rh_nextiter; 65 uint32_t rh_nextentity; 66 uint32_t rh_nextchangeid; 67 68 int rh_doorfd; 69 int rh_doorfd_old; /* fd to close once rh_fd_users == 0 */ 70 door_id_t rh_doorid; 71 pid_t rh_doorpid; /* pid at bind time */ 72 73 uid_t rh_uid; 74 uint32_t rh_debug; 75 uint32_t rh_flags; /* HANDLE_*, below */ 76 uint32_t rh_fd_users; /* non-locked users of rh_doorfd */ 77 78 uu_list_t *rh_dataels; 79 uu_list_t *rh_iters; 80 long rh_entries; 81 long rh_values; 82 83 long rh_extrefs; /* user-created subhandle count */ 84 long rh_intrefs; /* handle-internal subhandle count */ 85 86 char rh_doorpath[PATH_MAX + 1]; 87 88 pthread_t rh_holder; /* thread using subhandles */ 89 uint32_t rh_hold_flags; /* which are in use */ 90 91 scf_iter_t *rh_iter; 92 scf_scope_t *rh_scope; 93 scf_service_t *rh_service; 94 scf_instance_t *rh_instance; 95 scf_snapshot_t *rh_snapshot; 96 scf_snaplevel_t *rh_snaplvl; 97 scf_propertygroup_t *rh_pg; 98 scf_property_t *rh_property; 99 scf_value_t *rh_value; 100 }; 101 #define HANDLE_DEAD 0x0001 102 #define HANDLE_UNREFED 0x0002 103 #define HANDLE_WRAPPED_ENTITY 0x0004 104 #define HANDLE_WRAPPED_ITER 0x0008 105 106 #define RH_HOLD_ITER 0x0001 107 #define RH_HOLD_SCOPE 0x0002 108 #define RH_HOLD_SERVICE 0x0004 109 #define RH_HOLD_INSTANCE 0x0008 110 #define RH_HOLD_SNAPSHOT 0x0010 111 #define RH_HOLD_SNAPLVL 0x0020 112 #define RH_HOLD_PG 0x0040 113 #define RH_HOLD_PROPERTY 0x0080 114 #define RH_HOLD_VALUE 0x0100 115 116 #define RH_HOLD_ALL 0x01ff 117 118 struct scf_scope { 119 scf_datael_t rd_d; 120 }; 121 122 struct scf_service { 123 scf_datael_t rd_d; 124 }; 125 126 struct scf_instance { 127 scf_datael_t rd_d; 128 }; 129 130 struct scf_snapshot { 131 scf_datael_t rd_d; 132 }; 133 134 /* 135 * note: be careful of adding more state here -- snaplevel_next() relies on 136 * the fact that the entityid is the only library-level state. 137 */ 138 struct scf_snaplevel { 139 scf_datael_t rd_d; 140 }; 141 142 struct scf_propertygroup { 143 scf_datael_t rd_d; 144 }; 145 146 struct scf_property { 147 scf_datael_t rd_d; 148 }; 149 150 struct scf_value { 151 scf_handle_t *value_handle; 152 scf_value_t *value_next; 153 scf_transaction_entry_t *value_tx; 154 155 rep_protocol_value_type_t value_type; 156 size_t value_size; /* only for opaque values */ 157 char value_value[REP_PROTOCOL_VALUE_LEN]; 158 }; 159 160 enum scf_entry_state { 161 ENTRY_STATE_INVALID, 162 ENTRY_STATE_IN_TX_ACTION 163 }; 164 struct scf_transaction_entry { 165 const char *entry_property; 166 scf_handle_t *entry_handle; 167 scf_transaction_t *entry_tx; 168 enum scf_entry_state entry_state; 169 uu_list_node_t entry_link; /* for property name list */ 170 171 scf_value_t *entry_head; 172 scf_value_t *entry_tail; /* for linked values */ 173 174 enum rep_protocol_transaction_action entry_action; 175 rep_protocol_value_type_t entry_type; 176 char entry_namebuf[REP_PROTOCOL_NAME_LEN]; 177 }; 178 179 enum scf_tx_state { 180 TRAN_STATE_NEW, 181 TRAN_STATE_SETUP, 182 TRAN_STATE_COMMITTED 183 }; 184 185 struct scf_transaction { 186 enum scf_tx_state tran_state; 187 scf_propertygroup_t tran_pg; 188 int tran_invalid; 189 uu_list_t *tran_props; 190 }; 191 192 struct scf_iter { 193 scf_handle_t *iter_handle; 194 int iter_type; 195 uint32_t iter_id; 196 uint32_t iter_sequence; 197 uu_list_node_t iter_node; 198 }; 199 200 #ifdef __cplusplus 201 } 202 #endif 203 204 #endif /* _LOWLEVEL_IMPL_H */ 205