17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 238918dff3Sjwadams * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _CONFIGD_H 287c478bd9Sstevel@tonic-gate #define _CONFIGD_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <door.h> 337c478bd9Sstevel@tonic-gate #include <pthread.h> 347c478bd9Sstevel@tonic-gate #include <string.h> 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include <libscf.h> 387c478bd9Sstevel@tonic-gate #include <repcache_protocol.h> 397c478bd9Sstevel@tonic-gate #include <libuutil.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include <configd_exit.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifdef __cplusplus 447c478bd9Sstevel@tonic-gate extern "C" { 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * Lock order: 497c478bd9Sstevel@tonic-gate * 507c478bd9Sstevel@tonic-gate * client lock 517c478bd9Sstevel@tonic-gate * iter locks, in ID order 527c478bd9Sstevel@tonic-gate * entity locks, in ID order 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * (any iter/entity locks) 557c478bd9Sstevel@tonic-gate * backend locks (NORMAL, then NONPERSIST) 567c478bd9Sstevel@tonic-gate * rc_node lock 577c478bd9Sstevel@tonic-gate * children's rc_node lock 587c478bd9Sstevel@tonic-gate * cache bucket lock 597c478bd9Sstevel@tonic-gate * rc_node lock[*] 607c478bd9Sstevel@tonic-gate * 617c478bd9Sstevel@tonic-gate * * only one node may be grabbed while holding a bucket lock 627c478bd9Sstevel@tonic-gate * 637c478bd9Sstevel@tonic-gate * leaf locks: (no other locks may be aquired while holding one) 647c478bd9Sstevel@tonic-gate * rc_pg_notify_lock 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * Returns the minimum size for a structure of type 't' such 697c478bd9Sstevel@tonic-gate * that it is safe to access field 'f'. 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate #define offsetofend(t, f) (offsetof(t, f) + sizeof (((t *)0)->f)) 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * We want MUTEX_HELD, but we also want pthreads. So we're stuck with this. 757c478bd9Sstevel@tonic-gate */ 767c478bd9Sstevel@tonic-gate struct _lwp_mutex_t; 777c478bd9Sstevel@tonic-gate extern int _mutex_held(struct _lwp_mutex_t *); 787c478bd9Sstevel@tonic-gate #define MUTEX_HELD(m) _mutex_held((struct _lwp_mutex_t *)(m)) 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Maximum levels of composition. 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate #define COMPOSITION_DEPTH 2 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate * The default locations of the repository dbs 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate #define REPOSITORY_DB "/etc/svc/repository.db" 897c478bd9Sstevel@tonic-gate #define NONPERSIST_DB "/etc/svc/volatile/svc_nonpersist.db" 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #define CONFIGD_CORE "core.%f.%t.%p" 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #ifndef NDEBUG 947c478bd9Sstevel@tonic-gate #define bad_error(f, e) \ 957c478bd9Sstevel@tonic-gate uu_warn("%s:%d: %s() returned bad error %d. Aborting.\n", \ 967c478bd9Sstevel@tonic-gate __FILE__, __LINE__, f, e); \ 977c478bd9Sstevel@tonic-gate abort() 987c478bd9Sstevel@tonic-gate #else 997c478bd9Sstevel@tonic-gate #define bad_error(f, e) abort() 1007c478bd9Sstevel@tonic-gate #endif 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate typedef enum backend_type { 1037c478bd9Sstevel@tonic-gate BACKEND_TYPE_NORMAL = 0, 1047c478bd9Sstevel@tonic-gate BACKEND_TYPE_NONPERSIST, 1057c478bd9Sstevel@tonic-gate BACKEND_TYPE_TOTAL /* backend use only */ 1067c478bd9Sstevel@tonic-gate } backend_type_t; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* 1097c478bd9Sstevel@tonic-gate * pre-declare rc_* types 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate typedef struct rc_node rc_node_t; 1127c478bd9Sstevel@tonic-gate typedef struct rc_snapshot rc_snapshot_t; 1137c478bd9Sstevel@tonic-gate typedef struct rc_snaplevel rc_snaplevel_t; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * notification layer -- protected by rc_pg_notify_lock 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate typedef struct rc_notify_info rc_notify_info_t; 1197c478bd9Sstevel@tonic-gate typedef struct rc_notify_delete rc_notify_delete_t; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #define RC_NOTIFY_MAX_NAMES 4 /* enough for now */ 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate typedef struct rc_notify { 1247c478bd9Sstevel@tonic-gate uu_list_node_t rcn_list_node; 1257c478bd9Sstevel@tonic-gate rc_node_t *rcn_node; 1267c478bd9Sstevel@tonic-gate rc_notify_info_t *rcn_info; 1277c478bd9Sstevel@tonic-gate rc_notify_delete_t *rcn_delete; 1287c478bd9Sstevel@tonic-gate } rc_notify_t; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate struct rc_notify_delete { 1317c478bd9Sstevel@tonic-gate rc_notify_t rnd_notify; 1327c478bd9Sstevel@tonic-gate char rnd_fmri[REP_PROTOCOL_FMRI_LEN]; 1337c478bd9Sstevel@tonic-gate }; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate struct rc_notify_info { 1367c478bd9Sstevel@tonic-gate uu_list_node_t rni_list_node; 1377c478bd9Sstevel@tonic-gate rc_notify_t rni_notify; 1387c478bd9Sstevel@tonic-gate const char *rni_namelist[RC_NOTIFY_MAX_NAMES]; 1397c478bd9Sstevel@tonic-gate const char *rni_typelist[RC_NOTIFY_MAX_NAMES]; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate int rni_flags; 1427c478bd9Sstevel@tonic-gate int rni_waiters; 1437c478bd9Sstevel@tonic-gate pthread_cond_t rni_cv; 1447c478bd9Sstevel@tonic-gate }; 1457c478bd9Sstevel@tonic-gate #define RC_NOTIFY_ACTIVE 0x00000001 1467c478bd9Sstevel@tonic-gate #define RC_NOTIFY_DRAIN 0x00000002 1477c478bd9Sstevel@tonic-gate #define RC_NOTIFY_EMPTYING 0x00000004 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate typedef struct rc_node_pg_notify { 1507c478bd9Sstevel@tonic-gate uu_list_node_t rnpn_node; 1517c478bd9Sstevel@tonic-gate int rnpn_fd; 1527c478bd9Sstevel@tonic-gate rc_node_t *rnpn_pg; 1537c478bd9Sstevel@tonic-gate } rc_node_pg_notify_t; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* 1567c478bd9Sstevel@tonic-gate * cache layer 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * The 'key' for the main object hash. main_id is the main object 1617c478bd9Sstevel@tonic-gate * identifier. The rl_ids array contains: 1627c478bd9Sstevel@tonic-gate * 1637c478bd9Sstevel@tonic-gate * TYPE RL_IDS 1647c478bd9Sstevel@tonic-gate * scope unused 1657c478bd9Sstevel@tonic-gate * service unused 1667c478bd9Sstevel@tonic-gate * instance {service_id} 1677c478bd9Sstevel@tonic-gate * snapshot {service_id, instance_id} 1687c478bd9Sstevel@tonic-gate * snaplevel {service_id, instance_id, name_id, snapshot_id} 1697c478bd9Sstevel@tonic-gate * propertygroup {service_id, (instance_id or 0), (name_id or 0), 1707c478bd9Sstevel@tonic-gate * (snapshot_id or 0), (l_id or 0)} 1717c478bd9Sstevel@tonic-gate * property {service_id, (instance_id or 0), (name_id or 0), 1727c478bd9Sstevel@tonic-gate * (snapshot_id or 0), (l_id or 0), pg_id, gen_id} 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate #define ID_SERVICE 0 1757c478bd9Sstevel@tonic-gate #define ID_INSTANCE 1 1767c478bd9Sstevel@tonic-gate #define ID_NAME 2 1777c478bd9Sstevel@tonic-gate #define ID_SNAPSHOT 3 1787c478bd9Sstevel@tonic-gate #define ID_LEVEL 4 1797c478bd9Sstevel@tonic-gate #define ID_PG 5 1807c478bd9Sstevel@tonic-gate #define ID_GEN 6 1817c478bd9Sstevel@tonic-gate #define MAX_IDS 7 1827c478bd9Sstevel@tonic-gate typedef struct rc_node_lookup { 1837c478bd9Sstevel@tonic-gate uint16_t rl_type; /* REP_PROTOCOL_ENTITY_* */ 1847c478bd9Sstevel@tonic-gate uint16_t rl_backend; /* BACKEND_TYPE_* */ 1857c478bd9Sstevel@tonic-gate uint32_t rl_main_id; /* primary identifier */ 1867c478bd9Sstevel@tonic-gate uint32_t rl_ids[MAX_IDS]; /* context */ 1877c478bd9Sstevel@tonic-gate } rc_node_lookup_t; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate struct rc_node { 1907c478bd9Sstevel@tonic-gate /* 1917c478bd9Sstevel@tonic-gate * read-only data 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate rc_node_lookup_t rn_id; /* must be first */ 1947c478bd9Sstevel@tonic-gate uint32_t rn_hash; 1957c478bd9Sstevel@tonic-gate const char *rn_name; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /* 1987c478bd9Sstevel@tonic-gate * type-specific state 1997c478bd9Sstevel@tonic-gate * (if space becomes an issue, these can become a union) 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * Used by instances, snapshots, and "composed property groups" only. 2047c478bd9Sstevel@tonic-gate * These are the entities whose properties should appear composed when 2057c478bd9Sstevel@tonic-gate * this entity is traversed by a composed iterator. 0 is the top-most 2067c478bd9Sstevel@tonic-gate * entity, down to COMPOSITION_DEPTH - 1. 2077c478bd9Sstevel@tonic-gate */ 2087c478bd9Sstevel@tonic-gate rc_node_t *rn_cchain[COMPOSITION_DEPTH]; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * used by property groups only 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate const char *rn_type; 2147c478bd9Sstevel@tonic-gate uint32_t rn_pgflags; 2157c478bd9Sstevel@tonic-gate uint32_t rn_gen_id; 2167c478bd9Sstevel@tonic-gate uu_list_t *rn_pg_notify_list; /* prot by rc_pg_notify_lock */ 2177c478bd9Sstevel@tonic-gate rc_notify_t rn_notify; /* prot by rc_pg_notify_lock */ 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate /* 2207c478bd9Sstevel@tonic-gate * used by properties only 2217c478bd9Sstevel@tonic-gate */ 2227c478bd9Sstevel@tonic-gate rep_protocol_value_type_t rn_valtype; 2237c478bd9Sstevel@tonic-gate const char *rn_values; /* protected by rn_lock */ 2247c478bd9Sstevel@tonic-gate size_t rn_values_count; /* protected by rn_lock */ 2257c478bd9Sstevel@tonic-gate size_t rn_values_size; /* protected by rn_lock */ 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * used by snapshots only 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate uint32_t rn_snapshot_id; 2317c478bd9Sstevel@tonic-gate rc_snapshot_t *rn_snapshot; /* protected by rn_lock */ 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate /* 2347c478bd9Sstevel@tonic-gate * used by snaplevels only 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate rc_snaplevel_t *rn_snaplevel; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * mutable state 2407c478bd9Sstevel@tonic-gate */ 2417c478bd9Sstevel@tonic-gate pthread_mutex_t rn_lock; 2427c478bd9Sstevel@tonic-gate pthread_cond_t rn_cv; 2437c478bd9Sstevel@tonic-gate uint32_t rn_flags; 2447c478bd9Sstevel@tonic-gate uint32_t rn_refs; /* reference count */ 2457c478bd9Sstevel@tonic-gate uint32_t rn_other_refs; /* atomic refcount */ 2467c478bd9Sstevel@tonic-gate uint32_t rn_other_refs_held; /* for 1->0 transitions */ 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate uu_list_t *rn_children; 2497c478bd9Sstevel@tonic-gate uu_list_node_t rn_sibling_node; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate rc_node_t *rn_parent; /* set if on child list */ 2527c478bd9Sstevel@tonic-gate rc_node_t *rn_former; /* next former node */ 2537c478bd9Sstevel@tonic-gate rc_node_t *rn_parent_ref; /* reference count target */ 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * external state (protected by hash chain lock) 2577c478bd9Sstevel@tonic-gate */ 2587c478bd9Sstevel@tonic-gate rc_node_t *rn_hash_next; 2597c478bd9Sstevel@tonic-gate }; 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* 2627c478bd9Sstevel@tonic-gate * flag ordering: 2637c478bd9Sstevel@tonic-gate * RC_DYING 2647c478bd9Sstevel@tonic-gate * RC_NODE_CHILDREN_CHANGING 2657c478bd9Sstevel@tonic-gate * RC_NODE_CREATING_CHILD 2667c478bd9Sstevel@tonic-gate * RC_NODE_USING_PARENT 2677c478bd9Sstevel@tonic-gate * RC_NODE_IN_TX 2687c478bd9Sstevel@tonic-gate * 2697c478bd9Sstevel@tonic-gate * RC_NODE_USING_PARENT is special, because it lets you proceed up the tree, 2707c478bd9Sstevel@tonic-gate * in the reverse of the usual locking order. Because of this, there are 2717c478bd9Sstevel@tonic-gate * limitations on what you can do while holding it. While holding 2727c478bd9Sstevel@tonic-gate * RC_NODE_USING_PARENT, you may: 2737c478bd9Sstevel@tonic-gate * bump or release your parent's reference count 2747c478bd9Sstevel@tonic-gate * access fields in your parent 2757c478bd9Sstevel@tonic-gate * hold RC_NODE_USING_PARENT in the parent, proceeding recursively. 2767c478bd9Sstevel@tonic-gate * 2777c478bd9Sstevel@tonic-gate * If you are only holding *one* node's RC_NODE_USING_PARENT, and: 2787c478bd9Sstevel@tonic-gate * you are *not* proceeding recursively, you can hold your 2797c478bd9Sstevel@tonic-gate * immediate parent's RC_NODE_CHILDREN_CHANGING flag. 2807c478bd9Sstevel@tonic-gate * you hold your parent's RC_NODE_CHILDREN_CHANGING flag, you can add 2817c478bd9Sstevel@tonic-gate * RC_NODE_IN_TX to your flags. 2827c478bd9Sstevel@tonic-gate * you want to grab a flag in your parent, you must lock your parent, 2837c478bd9Sstevel@tonic-gate * lock yourself, drop RC_NODE_USING_PARENT, unlock yourself, 2847c478bd9Sstevel@tonic-gate * then proceed to manipulate the parent. 2857c478bd9Sstevel@tonic-gate */ 2867c478bd9Sstevel@tonic-gate #define RC_NODE_CHILDREN_CHANGING 0x00000001 /* child list in flux */ 2877c478bd9Sstevel@tonic-gate #define RC_NODE_HAS_CHILDREN 0x00000002 /* child list is accurate */ 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate #define RC_NODE_IN_PARENT 0x00000004 /* I'm in my parent's list */ 2907c478bd9Sstevel@tonic-gate #define RC_NODE_USING_PARENT 0x00000008 /* parent ptr in use */ 2917c478bd9Sstevel@tonic-gate #define RC_NODE_CREATING_CHILD 0x00000010 /* a create is in progress */ 2927c478bd9Sstevel@tonic-gate #define RC_NODE_IN_TX 0x00000020 /* a tx is in progess */ 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate #define RC_NODE_OLD 0x00000400 /* out-of-date object */ 2957c478bd9Sstevel@tonic-gate #define RC_NODE_ON_FORMER 0x00000800 /* on an rn_former list */ 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate #define RC_NODE_PARENT_REF 0x00001000 /* parent_ref in use */ 2987c478bd9Sstevel@tonic-gate #define RC_NODE_UNREFED 0x00002000 /* unref processing active */ 2997c478bd9Sstevel@tonic-gate #define RC_NODE_DYING 0x00004000 /* node is being deleted */ 3007c478bd9Sstevel@tonic-gate #define RC_NODE_DEAD 0x00008000 /* node has been deleted */ 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate #define RC_NODE_DYING_FLAGS \ 3037c478bd9Sstevel@tonic-gate (RC_NODE_CHILDREN_CHANGING | RC_NODE_IN_TX | RC_NODE_DYING | \ 3047c478bd9Sstevel@tonic-gate RC_NODE_CREATING_CHILD) 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate #define RC_NODE_WAITING_FLAGS \ 3077c478bd9Sstevel@tonic-gate (RC_NODE_DYING_FLAGS | RC_NODE_USING_PARENT) 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate typedef struct rc_node_ptr { 3117c478bd9Sstevel@tonic-gate rc_node_t *rnp_node; 3127c478bd9Sstevel@tonic-gate char rnp_authorized; /* transaction pre-authed */ 3137c478bd9Sstevel@tonic-gate char rnp_deleted; /* object was deleted */ 3147c478bd9Sstevel@tonic-gate } rc_node_ptr_t; 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate #define NODE_PTR_NOT_HELD(npp) \ 3177c478bd9Sstevel@tonic-gate ((npp)->rnp_node == NULL || !MUTEX_HELD(&(npp)->rnp_node->rn_lock)) 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate typedef int rc_iter_filter_func(rc_node_t *, void *); 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate typedef struct rc_node_iter { 3227c478bd9Sstevel@tonic-gate rc_node_t *rni_parent; 3237c478bd9Sstevel@tonic-gate int rni_clevel; /* index into rni_parent->rn_cchain[] */ 3247c478bd9Sstevel@tonic-gate rc_node_t *rni_iter_node; 3257c478bd9Sstevel@tonic-gate uu_list_walk_t *rni_iter; 3267c478bd9Sstevel@tonic-gate uint32_t rni_type; 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate /* 3297c478bd9Sstevel@tonic-gate * for normal walks 3307c478bd9Sstevel@tonic-gate */ 3317c478bd9Sstevel@tonic-gate rc_iter_filter_func *rni_filter; 3327c478bd9Sstevel@tonic-gate void *rni_filter_arg; 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate /* 3357c478bd9Sstevel@tonic-gate * for value walks 3367c478bd9Sstevel@tonic-gate */ 3377c478bd9Sstevel@tonic-gate uint32_t rni_offset; /* next value offset */ 3387c478bd9Sstevel@tonic-gate uint32_t rni_last_offset; /* previous value offset */ 3397c478bd9Sstevel@tonic-gate } rc_node_iter_t; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate typedef struct rc_node_tx { 3427c478bd9Sstevel@tonic-gate rc_node_ptr_t rnt_ptr; 3437c478bd9Sstevel@tonic-gate int rnt_authorized; /* No need to check anymore. */ 3447c478bd9Sstevel@tonic-gate } rc_node_tx_t; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate typedef struct cache_bucket { 3487c478bd9Sstevel@tonic-gate pthread_mutex_t cb_lock; 3497c478bd9Sstevel@tonic-gate rc_node_t *cb_head; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate char cb_pad[64 - sizeof (pthread_mutex_t) - 3527c478bd9Sstevel@tonic-gate 2 * sizeof (rc_node_t *)]; 3537c478bd9Sstevel@tonic-gate } cache_bucket_t; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate /* 3567c478bd9Sstevel@tonic-gate * Snapshots 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate struct rc_snapshot { 3597c478bd9Sstevel@tonic-gate uint32_t rs_snap_id; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate pthread_mutex_t rs_lock; 3627c478bd9Sstevel@tonic-gate pthread_cond_t rs_cv; 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate uint32_t rs_flags; 3657c478bd9Sstevel@tonic-gate uint32_t rs_refcnt; /* references from rc_nodes */ 3667c478bd9Sstevel@tonic-gate uint32_t rs_childref; /* references to children */ 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate rc_snaplevel_t *rs_levels; /* list of levels */ 3697c478bd9Sstevel@tonic-gate rc_snapshot_t *rs_hash_next; 3707c478bd9Sstevel@tonic-gate }; 3717c478bd9Sstevel@tonic-gate #define RC_SNAPSHOT_FILLING 0x00000001 /* rs_levels changing */ 3727c478bd9Sstevel@tonic-gate #define RC_SNAPSHOT_READY 0x00000002 3737c478bd9Sstevel@tonic-gate #define RC_SNAPSHOT_DEAD 0x00000004 /* no resources */ 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate typedef struct rc_snaplevel_pgs { 3767c478bd9Sstevel@tonic-gate uint32_t rsp_pg_id; 3777c478bd9Sstevel@tonic-gate uint32_t rsp_gen_id; 3787c478bd9Sstevel@tonic-gate } rc_snaplevel_pgs_t; 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate struct rc_snaplevel { 3817c478bd9Sstevel@tonic-gate rc_snapshot_t *rsl_parent; 3827c478bd9Sstevel@tonic-gate uint32_t rsl_level_num; 3837c478bd9Sstevel@tonic-gate uint32_t rsl_level_id; 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate uint32_t rsl_service_id; 3867c478bd9Sstevel@tonic-gate uint32_t rsl_instance_id; 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate const char *rsl_scope; 3897c478bd9Sstevel@tonic-gate const char *rsl_service; 3907c478bd9Sstevel@tonic-gate const char *rsl_instance; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate rc_snaplevel_t *rsl_next; 3937c478bd9Sstevel@tonic-gate }; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* 3967c478bd9Sstevel@tonic-gate * Client layer -- the IDs fields must be first, in order for the search 3977c478bd9Sstevel@tonic-gate * routines to work correctly. 3987c478bd9Sstevel@tonic-gate */ 3997c478bd9Sstevel@tonic-gate enum repcache_txstate { 4007c478bd9Sstevel@tonic-gate REPCACHE_TX_INIT, 4017c478bd9Sstevel@tonic-gate REPCACHE_TX_SETUP, 4027c478bd9Sstevel@tonic-gate REPCACHE_TX_COMMITTED 4037c478bd9Sstevel@tonic-gate }; 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate typedef struct repcache_entity { 4067c478bd9Sstevel@tonic-gate uint32_t re_id; 4078918dff3Sjwadams uu_avl_node_t re_link; 4087c478bd9Sstevel@tonic-gate uint32_t re_changeid; 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate pthread_mutex_t re_lock; 4117c478bd9Sstevel@tonic-gate uint32_t re_type; 4127c478bd9Sstevel@tonic-gate rc_node_ptr_t re_node; 4137c478bd9Sstevel@tonic-gate enum repcache_txstate re_txstate; /* property groups only */ 4147c478bd9Sstevel@tonic-gate } repcache_entity_t; 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate typedef struct repcache_iter { 4177c478bd9Sstevel@tonic-gate uint32_t ri_id; 4188918dff3Sjwadams uu_avl_node_t ri_link; 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate uint32_t ri_type; /* result type */ 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate pthread_mutex_t ri_lock; 4237c478bd9Sstevel@tonic-gate uint32_t ri_sequence; 4247c478bd9Sstevel@tonic-gate rc_node_iter_t *ri_iter; 4257c478bd9Sstevel@tonic-gate } repcache_iter_t; 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate typedef struct repcache_client { 4287c478bd9Sstevel@tonic-gate /* 4297c478bd9Sstevel@tonic-gate * constants 4307c478bd9Sstevel@tonic-gate */ 4317c478bd9Sstevel@tonic-gate uint32_t rc_id; /* must be first */ 4327c478bd9Sstevel@tonic-gate int rc_all_auths; /* bypass auth checks */ 4337c478bd9Sstevel@tonic-gate uint32_t rc_debug; /* debug flags */ 4347c478bd9Sstevel@tonic-gate pid_t rc_pid; /* pid of opening process */ 4357c478bd9Sstevel@tonic-gate door_id_t rc_doorid; /* a globally unique identifier */ 4367c478bd9Sstevel@tonic-gate int rc_doorfd; /* our door's FD */ 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /* 4397c478bd9Sstevel@tonic-gate * client list linkage, protected by hash chain lock 4407c478bd9Sstevel@tonic-gate */ 4417c478bd9Sstevel@tonic-gate uu_list_node_t rc_link; 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate /* 4447c478bd9Sstevel@tonic-gate * notification information, protected by rc_node layer 4457c478bd9Sstevel@tonic-gate */ 4467c478bd9Sstevel@tonic-gate rc_node_pg_notify_t rc_pg_notify; 4477c478bd9Sstevel@tonic-gate rc_notify_info_t rc_notify_info; 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate /* 4507c478bd9Sstevel@tonic-gate * client_wait output, only usable by rc_notify_thr 4517c478bd9Sstevel@tonic-gate */ 4527c478bd9Sstevel@tonic-gate rc_node_ptr_t rc_notify_ptr; 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate /* 4558918dff3Sjwadams * register sets, protected by rc_lock 4567c478bd9Sstevel@tonic-gate */ 4578918dff3Sjwadams uu_avl_t *rc_entities; 4588918dff3Sjwadams uu_avl_t *rc_iters; 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate /* 4617c478bd9Sstevel@tonic-gate * Variables, protected by rc_lock 4627c478bd9Sstevel@tonic-gate */ 4637c478bd9Sstevel@tonic-gate int rc_refcnt; /* in-progress door calls */ 4647c478bd9Sstevel@tonic-gate int rc_flags; /* state */ 4657c478bd9Sstevel@tonic-gate uint32_t rc_changeid; /* used to make backups idempotent */ 4667c478bd9Sstevel@tonic-gate pthread_t rc_insert_thr; /* single thread trying to insert */ 4677c478bd9Sstevel@tonic-gate pthread_t rc_notify_thr; /* single thread waiting for notify */ 4687c478bd9Sstevel@tonic-gate pthread_cond_t rc_cv; 4697c478bd9Sstevel@tonic-gate pthread_mutex_t rc_lock; 4707c478bd9Sstevel@tonic-gate } repcache_client_t; 4717c478bd9Sstevel@tonic-gate #define RC_CLIENT_DEAD 0x00000001 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate typedef struct client_bucket { 4747c478bd9Sstevel@tonic-gate pthread_mutex_t cb_lock; 4757c478bd9Sstevel@tonic-gate uu_list_t *cb_list; 4767c478bd9Sstevel@tonic-gate char ch_pad[64 - sizeof (pthread_mutex_t) - sizeof (uu_list_t *)]; 4777c478bd9Sstevel@tonic-gate } client_bucket_t; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate enum rc_ptr_type { 4807c478bd9Sstevel@tonic-gate RC_PTR_TYPE_ENTITY = 1, 4817c478bd9Sstevel@tonic-gate RC_PTR_TYPE_ITER 4827c478bd9Sstevel@tonic-gate }; 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate typedef struct request_log_ptr { 4857c478bd9Sstevel@tonic-gate enum rc_ptr_type rlp_type; 4867c478bd9Sstevel@tonic-gate uint32_t rlp_id; 4877c478bd9Sstevel@tonic-gate void *rlp_ptr; /* repcache_{entity,iter}_t */ 4887c478bd9Sstevel@tonic-gate void *rlp_data; /* rc_node, for ENTITY only */ 4897c478bd9Sstevel@tonic-gate } request_log_ptr_t; 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate #define MAX_PTRS 3 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate /* 4947c478bd9Sstevel@tonic-gate * rl_start through rl_client cannot move without changing start_log() 4957c478bd9Sstevel@tonic-gate */ 4967c478bd9Sstevel@tonic-gate typedef struct request_log_entry { 4977c478bd9Sstevel@tonic-gate hrtime_t rl_start; 4987c478bd9Sstevel@tonic-gate hrtime_t rl_end; 4997c478bd9Sstevel@tonic-gate pthread_t rl_tid; 5007c478bd9Sstevel@tonic-gate uint32_t rl_clientid; 5017c478bd9Sstevel@tonic-gate repcache_client_t *rl_client; 5027c478bd9Sstevel@tonic-gate enum rep_protocol_requestid rl_request; 5037c478bd9Sstevel@tonic-gate rep_protocol_responseid_t rl_response; 5047c478bd9Sstevel@tonic-gate int rl_num_ptrs; 5057c478bd9Sstevel@tonic-gate request_log_ptr_t rl_ptrs[MAX_PTRS]; 5067c478bd9Sstevel@tonic-gate } request_log_entry_t; 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate /* 5097c478bd9Sstevel@tonic-gate * thread information 5107c478bd9Sstevel@tonic-gate */ 5117c478bd9Sstevel@tonic-gate typedef enum thread_state { 5127c478bd9Sstevel@tonic-gate TI_CREATED, 5137c478bd9Sstevel@tonic-gate TI_DOOR_RETURN, 5147c478bd9Sstevel@tonic-gate TI_SIGNAL_WAIT, 5157c478bd9Sstevel@tonic-gate TI_MAIN_DOOR_CALL, 5167c478bd9Sstevel@tonic-gate TI_CLIENT_CALL 5177c478bd9Sstevel@tonic-gate } thread_state_t; 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate typedef struct thread_info { 5207c478bd9Sstevel@tonic-gate pthread_t ti_thread; 5217c478bd9Sstevel@tonic-gate uu_list_node_t ti_node; /* for list of all thread */ 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate /* 5247c478bd9Sstevel@tonic-gate * per-thread globals 5257c478bd9Sstevel@tonic-gate */ 5267c478bd9Sstevel@tonic-gate ucred_t *ti_ucred; /* for credential lookups */ 5277c478bd9Sstevel@tonic-gate int ti_ucred_read; /* ucred holds current creds */ 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate /* 5307c478bd9Sstevel@tonic-gate * per-thread state information, for debuggers 5317c478bd9Sstevel@tonic-gate */ 5327c478bd9Sstevel@tonic-gate hrtime_t ti_lastchange; 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate thread_state_t ti_state; 5357c478bd9Sstevel@tonic-gate thread_state_t ti_prev_state; 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate repcache_client_t *ti_active_client; 5387c478bd9Sstevel@tonic-gate request_log_entry_t ti_log; 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate struct rep_protocol_request *ti_client_request; 5417c478bd9Sstevel@tonic-gate repository_door_request_t *ti_main_door_request; 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate } thread_info_t; 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate /* 5467c478bd9Sstevel@tonic-gate * Backend layer 5477c478bd9Sstevel@tonic-gate */ 5487c478bd9Sstevel@tonic-gate typedef struct backend_query backend_query_t; 5497c478bd9Sstevel@tonic-gate typedef struct backend_tx backend_tx_t; 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate /* 5527c478bd9Sstevel@tonic-gate * configd.c 5537c478bd9Sstevel@tonic-gate */ 5547c478bd9Sstevel@tonic-gate int create_connection(ucred_t *cred, repository_door_request_t *rp, 5557c478bd9Sstevel@tonic-gate size_t rp_size, int *out_fd); 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate thread_info_t *thread_self(void); 5587c478bd9Sstevel@tonic-gate void thread_newstate(thread_info_t *, thread_state_t); 5597c478bd9Sstevel@tonic-gate ucred_t *get_ucred(void); 5607c478bd9Sstevel@tonic-gate int ucred_is_privileged(ucred_t *); 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate void configd_critical(const char *, ...); 5637c478bd9Sstevel@tonic-gate void configd_vcritical(const char *, va_list); 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate extern int is_main_repository; 5667c478bd9Sstevel@tonic-gate extern int max_repository_backups; 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * maindoor.c 5707c478bd9Sstevel@tonic-gate */ 5717c478bd9Sstevel@tonic-gate int setup_main_door(const char *); 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate /* 5747c478bd9Sstevel@tonic-gate * client.c 5757c478bd9Sstevel@tonic-gate */ 5767c478bd9Sstevel@tonic-gate int create_client(pid_t, uint32_t, int, int *); 5777c478bd9Sstevel@tonic-gate int client_init(void); 5787c478bd9Sstevel@tonic-gate int client_is_privileged(void); 5797c478bd9Sstevel@tonic-gate void log_enter(request_log_entry_t *); 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * rc_node.c, backend/cache interfaces (rc_node_t) 5837c478bd9Sstevel@tonic-gate */ 5847c478bd9Sstevel@tonic-gate int rc_node_init(); 5857c478bd9Sstevel@tonic-gate int rc_check_type_name(uint32_t, const char *); 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate void rc_node_rele(rc_node_t *); 5887c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup(rc_node_t *, rc_node_lookup_t *, 5897c478bd9Sstevel@tonic-gate const char *, rc_node_t *); 5907c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_pg(rc_node_t *, rc_node_lookup_t *, const char *, 5917c478bd9Sstevel@tonic-gate const char *, uint32_t, uint32_t, rc_node_t *); 5927c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_snapshot(rc_node_t *, rc_node_lookup_t *, const char *, 5937c478bd9Sstevel@tonic-gate uint32_t, rc_node_t *); 5947c478bd9Sstevel@tonic-gate rc_node_t *rc_node_setup_snaplevel(rc_node_t *, rc_node_lookup_t *, 5957c478bd9Sstevel@tonic-gate rc_snaplevel_t *, rc_node_t *); 5967c478bd9Sstevel@tonic-gate int rc_node_create_property(rc_node_t *, rc_node_lookup_t *, 5977c478bd9Sstevel@tonic-gate const char *, rep_protocol_value_type_t, const char *, size_t, size_t); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate rc_node_t *rc_node_alloc(void); 6007c478bd9Sstevel@tonic-gate void rc_node_destroy(rc_node_t *); 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate /* 6037c478bd9Sstevel@tonic-gate * rc_node.c, client interface (rc_node_ptr_t, rc_node_iter_t) 6047c478bd9Sstevel@tonic-gate */ 6057c478bd9Sstevel@tonic-gate void rc_node_ptr_init(rc_node_ptr_t *); 6067c478bd9Sstevel@tonic-gate int rc_local_scope(uint32_t, rc_node_ptr_t *); 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate void rc_node_clear(rc_node_ptr_t *, int); 6097c478bd9Sstevel@tonic-gate void rc_node_ptr_assign(rc_node_ptr_t *, const rc_node_ptr_t *); 6107c478bd9Sstevel@tonic-gate int rc_node_name(rc_node_ptr_t *, char *, size_t, uint32_t, size_t *); 6117c478bd9Sstevel@tonic-gate int rc_node_fmri(rc_node_ptr_t *, char *, size_t, size_t *); 6127c478bd9Sstevel@tonic-gate int rc_node_parent_type(rc_node_ptr_t *, uint32_t *); 6137c478bd9Sstevel@tonic-gate int rc_node_get_child(rc_node_ptr_t *, const char *, uint32_t, rc_node_ptr_t *); 6147c478bd9Sstevel@tonic-gate int rc_node_get_parent(rc_node_ptr_t *, uint32_t, rc_node_ptr_t *); 6157c478bd9Sstevel@tonic-gate int rc_node_get_property_type(rc_node_ptr_t *, rep_protocol_value_type_t *); 6167c478bd9Sstevel@tonic-gate int rc_node_get_property_value(rc_node_ptr_t *, 6177c478bd9Sstevel@tonic-gate struct rep_protocol_value_response *, size_t *); 6187c478bd9Sstevel@tonic-gate int rc_node_create_child(rc_node_ptr_t *, uint32_t, const char *, 6197c478bd9Sstevel@tonic-gate rc_node_ptr_t *); 6207c478bd9Sstevel@tonic-gate int rc_node_create_child_pg(rc_node_ptr_t *, uint32_t, const char *, 6217c478bd9Sstevel@tonic-gate const char *, uint32_t, rc_node_ptr_t *); 6227c478bd9Sstevel@tonic-gate int rc_node_update(rc_node_ptr_t *); 6237c478bd9Sstevel@tonic-gate int rc_node_delete(rc_node_ptr_t *); 6247c478bd9Sstevel@tonic-gate int rc_node_next_snaplevel(rc_node_ptr_t *, rc_node_ptr_t *); 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate int rc_node_setup_iter(rc_node_ptr_t *, rc_node_iter_t **, uint32_t, 6277c478bd9Sstevel@tonic-gate size_t, const char *); 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate int rc_iter_next(rc_node_iter_t *, rc_node_ptr_t *, uint32_t); 6307c478bd9Sstevel@tonic-gate int rc_iter_next_value(rc_node_iter_t *, struct rep_protocol_value_response *, 6317c478bd9Sstevel@tonic-gate size_t *, int); 6327c478bd9Sstevel@tonic-gate void rc_iter_destroy(rc_node_iter_t **); 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate int rc_node_setup_tx(rc_node_ptr_t *, rc_node_ptr_t *); 6357c478bd9Sstevel@tonic-gate int rc_tx_commit(rc_node_ptr_t *, const void *, size_t); 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate void rc_pg_notify_init(rc_node_pg_notify_t *); 6387c478bd9Sstevel@tonic-gate int rc_pg_notify_setup(rc_node_pg_notify_t *, rc_node_ptr_t *, int); 6397c478bd9Sstevel@tonic-gate void rc_pg_notify_fini(rc_node_pg_notify_t *); 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate void rc_notify_info_init(rc_notify_info_t *); 6427c478bd9Sstevel@tonic-gate int rc_notify_info_add_name(rc_notify_info_t *, const char *); 6437c478bd9Sstevel@tonic-gate int rc_notify_info_add_type(rc_notify_info_t *, const char *); 6447c478bd9Sstevel@tonic-gate int rc_notify_info_wait(rc_notify_info_t *, rc_node_ptr_t *, char *, size_t); 6457c478bd9Sstevel@tonic-gate void rc_notify_info_fini(rc_notify_info_t *); 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate int rc_snapshot_take_new(rc_node_ptr_t *, const char *, 6487c478bd9Sstevel@tonic-gate const char *, const char *, rc_node_ptr_t *); 6497c478bd9Sstevel@tonic-gate int rc_snapshot_take_attach(rc_node_ptr_t *, rc_node_ptr_t *); 6507c478bd9Sstevel@tonic-gate int rc_snapshot_attach(rc_node_ptr_t *, rc_node_ptr_t *); 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * file_object.c 6547c478bd9Sstevel@tonic-gate */ 6557c478bd9Sstevel@tonic-gate int object_fill_children(rc_node_t *); 6567c478bd9Sstevel@tonic-gate int object_create(rc_node_t *, uint32_t, const char *, rc_node_t **); 6577c478bd9Sstevel@tonic-gate int object_create_pg(rc_node_t *, uint32_t, const char *, const char *, 6587c478bd9Sstevel@tonic-gate uint32_t, rc_node_t **); 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate int object_delete(rc_node_t *); 6617c478bd9Sstevel@tonic-gate void object_free_values(const char *, uint32_t, size_t, size_t); 6627c478bd9Sstevel@tonic-gate 6638918dff3Sjwadams int object_fill_snapshot(rc_snapshot_t *); 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate int object_snapshot_take_new(rc_node_t *, const char *, const char *, 6667c478bd9Sstevel@tonic-gate const char *, rc_node_t **); 6677c478bd9Sstevel@tonic-gate int object_snapshot_attach(rc_node_lookup_t *, uint32_t *, int); 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate /* 6707c478bd9Sstevel@tonic-gate * object.c 6717c478bd9Sstevel@tonic-gate */ 6727c478bd9Sstevel@tonic-gate int object_tx_commit(rc_node_lookup_t *, const void *, size_t, uint32_t *); 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate /* 6757c478bd9Sstevel@tonic-gate * snapshot.c 6767c478bd9Sstevel@tonic-gate */ 6777c478bd9Sstevel@tonic-gate int rc_snapshot_get(uint32_t, rc_snapshot_t **); 6787c478bd9Sstevel@tonic-gate void rc_snapshot_rele(rc_snapshot_t *); 6797c478bd9Sstevel@tonic-gate void rc_snaplevel_hold(rc_snaplevel_t *); 6807c478bd9Sstevel@tonic-gate void rc_snaplevel_rele(rc_snaplevel_t *); 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate /* 6837c478bd9Sstevel@tonic-gate * backend.c 6847c478bd9Sstevel@tonic-gate */ 6857c478bd9Sstevel@tonic-gate int backend_init(const char *, const char *, int); 6867c478bd9Sstevel@tonic-gate void backend_fini(void); 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate rep_protocol_responseid_t backend_create_backup(const char *); 6897c478bd9Sstevel@tonic-gate 6907c478bd9Sstevel@tonic-gate /* 6917c478bd9Sstevel@tonic-gate * call on any database inconsistency -- cleans up state as best it can, 6927c478bd9Sstevel@tonic-gate * and exits with a "Database Bad" error code. 6937c478bd9Sstevel@tonic-gate */ 694*0b5c9250Shg115875 void backend_panic(const char *, ...) __NORETURN; 6957c478bd9Sstevel@tonic-gate #pragma rarely_called(backend_panic) 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate backend_query_t *backend_query_alloc(void); 6987c478bd9Sstevel@tonic-gate void backend_query_append(backend_query_t *, const char *); 6997c478bd9Sstevel@tonic-gate void backend_query_add(backend_query_t *, const char *, ...); 7007c478bd9Sstevel@tonic-gate void backend_query_free(backend_query_t *); 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate typedef int backend_run_callback_f(void *data, int columns, char **vals, 7037c478bd9Sstevel@tonic-gate char **names); 7047c478bd9Sstevel@tonic-gate #define BACKEND_CALLBACK_CONTINUE 0 7057c478bd9Sstevel@tonic-gate #define BACKEND_CALLBACK_ABORT 1 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate backend_run_callback_f backend_fail_if_seen; /* aborts TX if called */ 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate int backend_run(backend_type_t, backend_query_t *, 7107c478bd9Sstevel@tonic-gate backend_run_callback_f *, void *); 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate int backend_tx_begin(backend_type_t, backend_tx_t **); 7137c478bd9Sstevel@tonic-gate int backend_tx_begin_ro(backend_type_t, backend_tx_t **); 7147c478bd9Sstevel@tonic-gate void backend_tx_end_ro(backend_tx_t *); 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate enum id_space { 7177c478bd9Sstevel@tonic-gate BACKEND_ID_SERVICE_INSTANCE, 7187c478bd9Sstevel@tonic-gate BACKEND_ID_PROPERTYGRP, 7197c478bd9Sstevel@tonic-gate BACKEND_ID_GENERATION, 7207c478bd9Sstevel@tonic-gate BACKEND_ID_PROPERTY, 7217c478bd9Sstevel@tonic-gate BACKEND_ID_VALUE, 7227c478bd9Sstevel@tonic-gate BACKEND_ID_SNAPNAME, 7237c478bd9Sstevel@tonic-gate BACKEND_ID_SNAPSHOT, 7247c478bd9Sstevel@tonic-gate BACKEND_ID_SNAPLEVEL, 7257c478bd9Sstevel@tonic-gate BACKEND_ID_INVALID /* always illegal */ 7267c478bd9Sstevel@tonic-gate }; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate uint32_t backend_new_id(backend_tx_t *, enum id_space); 7297c478bd9Sstevel@tonic-gate int backend_tx_run_update(backend_tx_t *, const char *, ...); 7307c478bd9Sstevel@tonic-gate int backend_tx_run_update_changed(backend_tx_t *, const char *, ...); 7317c478bd9Sstevel@tonic-gate int backend_tx_run_single_int(backend_tx_t *tx, backend_query_t *q, 7327c478bd9Sstevel@tonic-gate uint32_t *buf); 7337c478bd9Sstevel@tonic-gate int backend_tx_run(backend_tx_t *, backend_query_t *, 7347c478bd9Sstevel@tonic-gate backend_run_callback_f *, void *); 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate int backend_tx_commit(backend_tx_t *); 7377c478bd9Sstevel@tonic-gate void backend_tx_rollback(backend_tx_t *); 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate #ifdef __cplusplus 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate #endif 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate #endif /* _CONFIGD_H */ 744