1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #ifdef _FILE_OFFSET_BITS 30*7c478bd9Sstevel@tonic-gate #undef _FILE_OFFSET_BITS 31*7c478bd9Sstevel@tonic-gate #endif /* _FILE_OFFSET_BITS */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <sys/contract/process.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/ctfs.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 36*7c478bd9Sstevel@tonic-gate #include <assert.h> 37*7c478bd9Sstevel@tonic-gate #include <errno.h> 38*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 39*7c478bd9Sstevel@tonic-gate #include <libcontract.h> 40*7c478bd9Sstevel@tonic-gate #include <libcontract_priv.h> 41*7c478bd9Sstevel@tonic-gate #include <libuutil.h> 42*7c478bd9Sstevel@tonic-gate #include <limits.h> 43*7c478bd9Sstevel@tonic-gate #include <procfs.h> 44*7c478bd9Sstevel@tonic-gate #include <signal.h> 45*7c478bd9Sstevel@tonic-gate #include <string.h> 46*7c478bd9Sstevel@tonic-gate #include <unistd.h> 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #include "startd.h" 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate void 51*7c478bd9Sstevel@tonic-gate contract_abandon(ctid_t ctid) 52*7c478bd9Sstevel@tonic-gate { 53*7c478bd9Sstevel@tonic-gate int err; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate assert(ctid != 0); 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate err = contract_abandon_id(ctid); 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate if (err) 60*7c478bd9Sstevel@tonic-gate log_framework(LOG_NOTICE, 61*7c478bd9Sstevel@tonic-gate "failed to abandon contract %ld: %s\n", ctid, 62*7c478bd9Sstevel@tonic-gate strerror(err)); 63*7c478bd9Sstevel@tonic-gate } 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate int 66*7c478bd9Sstevel@tonic-gate contract_kill(ctid_t ctid, int sig, const char *fmri) 67*7c478bd9Sstevel@tonic-gate { 68*7c478bd9Sstevel@tonic-gate if (sigsend(P_CTID, ctid, sig) == -1 && errno != ESRCH) { 69*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, 70*7c478bd9Sstevel@tonic-gate "%s: Could not signal all contract members: %s\n", fmri, 71*7c478bd9Sstevel@tonic-gate strerror(errno)); 72*7c478bd9Sstevel@tonic-gate return (-1); 73*7c478bd9Sstevel@tonic-gate } 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate return (0); 76*7c478bd9Sstevel@tonic-gate } 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate ctid_t 79*7c478bd9Sstevel@tonic-gate contract_init() 80*7c478bd9Sstevel@tonic-gate { 81*7c478bd9Sstevel@tonic-gate int psfd, csfd; 82*7c478bd9Sstevel@tonic-gate ctid_t ctid, configd_ctid = -1; 83*7c478bd9Sstevel@tonic-gate psinfo_t psi; 84*7c478bd9Sstevel@tonic-gate ct_stathdl_t s; 85*7c478bd9Sstevel@tonic-gate ctid_t *ctids; 86*7c478bd9Sstevel@tonic-gate uint_t nctids; 87*7c478bd9Sstevel@tonic-gate uint_t n; 88*7c478bd9Sstevel@tonic-gate int err; 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate /* 91*7c478bd9Sstevel@tonic-gate * 2. Acquire any contracts we should have inherited. First, find the 92*7c478bd9Sstevel@tonic-gate * contract we belong to, then get its status. 93*7c478bd9Sstevel@tonic-gate */ 94*7c478bd9Sstevel@tonic-gate if ((psfd = open("/proc/self/psinfo", O_RDONLY)) < 0) { 95*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not open /proc/self/psinfo; unable " 96*7c478bd9Sstevel@tonic-gate "to check to adopt contracts: %s\n", strerror(errno)); 97*7c478bd9Sstevel@tonic-gate return (-1); 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate if (read(psfd, &psi, sizeof (psinfo_t)) != sizeof (psinfo_t)) { 101*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not read from /proc/self/psinfo; " 102*7c478bd9Sstevel@tonic-gate "unable to adopt contracts: %s\n", 103*7c478bd9Sstevel@tonic-gate strerror(errno)); 104*7c478bd9Sstevel@tonic-gate startd_close(psfd); 105*7c478bd9Sstevel@tonic-gate return (-1); 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate ctid = psi.pr_contract; 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate startd_close(psfd); 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate if ((csfd = contract_open(ctid, "process", "status", O_RDONLY)) < 0) { 113*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not open containing contract " 114*7c478bd9Sstevel@tonic-gate "status; unable to adopt contracts: %s\n", strerror(errno)); 115*7c478bd9Sstevel@tonic-gate return (-1); 116*7c478bd9Sstevel@tonic-gate } 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /* 3. Go about adopting our member list. */ 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate err = ct_status_read(csfd, CTD_ALL, &s); 121*7c478bd9Sstevel@tonic-gate startd_close(csfd); 122*7c478bd9Sstevel@tonic-gate if (err) { 123*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not read containing contract " 124*7c478bd9Sstevel@tonic-gate "status; unable to adopt: %s\n", strerror(err)); 125*7c478bd9Sstevel@tonic-gate return (-1); 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate if (err = ct_pr_status_get_contracts(s, &ctids, &nctids)) { 129*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not get my inherited contracts; " 130*7c478bd9Sstevel@tonic-gate "unable to adopt: %s\n", strerror(err)); 131*7c478bd9Sstevel@tonic-gate ct_status_free(s); 132*7c478bd9Sstevel@tonic-gate return (-1); 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate if (nctids == 0) { 136*7c478bd9Sstevel@tonic-gate /* 137*7c478bd9Sstevel@tonic-gate * We're booting, as a svc.startd which managed to fork a 138*7c478bd9Sstevel@tonic-gate * child will always have a svc.configd contract to adopt. 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate st->st_initial = 1; 141*7c478bd9Sstevel@tonic-gate ct_status_free(s); 142*7c478bd9Sstevel@tonic-gate return (-1); 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * We're restarting after an interruption of some kind. 147*7c478bd9Sstevel@tonic-gate */ 148*7c478bd9Sstevel@tonic-gate log_framework(LOG_NOTICE, "restarting after interruption\n"); 149*7c478bd9Sstevel@tonic-gate st->st_initial = 0; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate /* 152*7c478bd9Sstevel@tonic-gate * 3'. Loop through the array, adopting them all where possible, and 153*7c478bd9Sstevel@tonic-gate * noting which one contains svc.configd (via a cookie vlaue of 154*7c478bd9Sstevel@tonic-gate * CONFIGD_COOKIE). 155*7c478bd9Sstevel@tonic-gate */ 156*7c478bd9Sstevel@tonic-gate for (n = 0; n < nctids; n++) { 157*7c478bd9Sstevel@tonic-gate int ccfd; 158*7c478bd9Sstevel@tonic-gate ct_stathdl_t cs; 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate if ((ccfd = contract_open(ctids[n], "process", "ctl", 161*7c478bd9Sstevel@tonic-gate O_WRONLY)) < 0) { 162*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not open contract %ld ctl " 163*7c478bd9Sstevel@tonic-gate "for adoption: %s\n", ctids[n], strerror(err)); 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate continue; 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate if ((csfd = contract_open(ctids[n], "process", "status", 169*7c478bd9Sstevel@tonic-gate O_RDONLY)) < 0) { 170*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not open contract %ld " 171*7c478bd9Sstevel@tonic-gate "status for cookie: %s\n", ctids[n], strerror(err)); 172*7c478bd9Sstevel@tonic-gate startd_close(ccfd); 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate continue; 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate if (err = ct_ctl_adopt(ccfd)) { 178*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not adopt contract %ld: " 179*7c478bd9Sstevel@tonic-gate "%s\n", ctids[n], strerror(err)); 180*7c478bd9Sstevel@tonic-gate startd_close(ccfd); 181*7c478bd9Sstevel@tonic-gate startd_close(csfd); 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate continue; 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate startd_close(ccfd); 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate if (err = ct_status_read(csfd, CTD_COMMON, &cs)) { 189*7c478bd9Sstevel@tonic-gate log_error(LOG_WARNING, "Can not read contract %ld" 190*7c478bd9Sstevel@tonic-gate "status; unable to fetch cookie: %s\n", ctids[n], 191*7c478bd9Sstevel@tonic-gate strerror(err)); 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate ct_status_free(cs); 194*7c478bd9Sstevel@tonic-gate startd_close(csfd); 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate continue; 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate if (ct_status_get_cookie(cs) == CONFIGD_COOKIE) 200*7c478bd9Sstevel@tonic-gate configd_ctid = ctids[n]; 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate ct_status_free(cs); 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate startd_close(csfd); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate ct_status_free(s); 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate return (configd_ctid); 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate int 213*7c478bd9Sstevel@tonic-gate contract_is_empty(ctid_t ctid) 214*7c478bd9Sstevel@tonic-gate { 215*7c478bd9Sstevel@tonic-gate int fd; 216*7c478bd9Sstevel@tonic-gate ct_stathdl_t ctstat; 217*7c478bd9Sstevel@tonic-gate pid_t *members; 218*7c478bd9Sstevel@tonic-gate uint_t num; 219*7c478bd9Sstevel@tonic-gate int ret; 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate fd = contract_open(ctid, "process", "status", O_RDONLY); 222*7c478bd9Sstevel@tonic-gate if (fd < 0) 223*7c478bd9Sstevel@tonic-gate return (1); 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate ret = ct_status_read(fd, CTD_ALL, &ctstat); 226*7c478bd9Sstevel@tonic-gate (void) close(fd); 227*7c478bd9Sstevel@tonic-gate if (ret != 0) 228*7c478bd9Sstevel@tonic-gate return (1); 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate ret = ct_pr_status_get_members(ctstat, &members, &num); 231*7c478bd9Sstevel@tonic-gate ct_status_free(ctstat); 232*7c478bd9Sstevel@tonic-gate if (ret != 0) 233*7c478bd9Sstevel@tonic-gate return (1); 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate if (num == 0) 236*7c478bd9Sstevel@tonic-gate return (1); 237*7c478bd9Sstevel@tonic-gate else 238*7c478bd9Sstevel@tonic-gate return (0); 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate typedef struct contract_bucket { 242*7c478bd9Sstevel@tonic-gate pthread_mutex_t cb_lock; 243*7c478bd9Sstevel@tonic-gate uu_list_t *cb_list; 244*7c478bd9Sstevel@tonic-gate } contract_bucket_t; 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate #define CI_HASH_SIZE 64 247*7c478bd9Sstevel@tonic-gate #define CI_HASH_MASK (CI_HASH_SIZE - 1); 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate /* 250*7c478bd9Sstevel@tonic-gate * contract_hash is a hash table of contract ids to restarter instance 251*7c478bd9Sstevel@tonic-gate * IDs. It can be used for quick lookups when processing contract events, 252*7c478bd9Sstevel@tonic-gate * because the restarter instance lock doesn't need to be held to access 253*7c478bd9Sstevel@tonic-gate * its entries. 254*7c478bd9Sstevel@tonic-gate */ 255*7c478bd9Sstevel@tonic-gate static contract_bucket_t contract_hash[CI_HASH_SIZE]; 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate static contract_bucket_t * 258*7c478bd9Sstevel@tonic-gate contract_hold_bucket(ctid_t ctid) 259*7c478bd9Sstevel@tonic-gate { 260*7c478bd9Sstevel@tonic-gate contract_bucket_t *bp; 261*7c478bd9Sstevel@tonic-gate int hash; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate hash = ctid & CI_HASH_MASK; 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate bp = &contract_hash[hash]; 266*7c478bd9Sstevel@tonic-gate MUTEX_LOCK(&bp->cb_lock); 267*7c478bd9Sstevel@tonic-gate return (bp); 268*7c478bd9Sstevel@tonic-gate } 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate static void 271*7c478bd9Sstevel@tonic-gate contract_release_bucket(contract_bucket_t *bp) 272*7c478bd9Sstevel@tonic-gate { 273*7c478bd9Sstevel@tonic-gate assert(PTHREAD_MUTEX_HELD(&bp->cb_lock)); 274*7c478bd9Sstevel@tonic-gate MUTEX_UNLOCK(&bp->cb_lock); 275*7c478bd9Sstevel@tonic-gate } 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate static contract_entry_t * 278*7c478bd9Sstevel@tonic-gate contract_lookup(contract_bucket_t *bp, ctid_t ctid) 279*7c478bd9Sstevel@tonic-gate { 280*7c478bd9Sstevel@tonic-gate contract_entry_t *ce; 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate assert(PTHREAD_MUTEX_HELD(&bp->cb_lock)); 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate if (bp->cb_list == NULL) 285*7c478bd9Sstevel@tonic-gate return (NULL); 286*7c478bd9Sstevel@tonic-gate 287*7c478bd9Sstevel@tonic-gate for (ce = uu_list_first(bp->cb_list); ce != NULL; 288*7c478bd9Sstevel@tonic-gate ce = uu_list_next(bp->cb_list, ce)) { 289*7c478bd9Sstevel@tonic-gate if (ce->ce_ctid == ctid) 290*7c478bd9Sstevel@tonic-gate return (ce); 291*7c478bd9Sstevel@tonic-gate } 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate return (NULL); 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate static void 297*7c478bd9Sstevel@tonic-gate contract_insert(contract_bucket_t *bp, contract_entry_t *ce) 298*7c478bd9Sstevel@tonic-gate { 299*7c478bd9Sstevel@tonic-gate int r; 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gate if (bp->cb_list == NULL) 302*7c478bd9Sstevel@tonic-gate bp->cb_list = startd_list_create(contract_list_pool, bp, 0); 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate uu_list_node_init(ce, &ce->ce_link, contract_list_pool); 305*7c478bd9Sstevel@tonic-gate r = uu_list_insert_before(bp->cb_list, NULL, ce); 306*7c478bd9Sstevel@tonic-gate assert(r == 0); 307*7c478bd9Sstevel@tonic-gate } 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate void 310*7c478bd9Sstevel@tonic-gate contract_hash_init() 311*7c478bd9Sstevel@tonic-gate { 312*7c478bd9Sstevel@tonic-gate int i; 313*7c478bd9Sstevel@tonic-gate 314*7c478bd9Sstevel@tonic-gate for (i = 0; i < CI_HASH_SIZE; i++) 315*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_init(&contract_hash[i].cb_lock, 316*7c478bd9Sstevel@tonic-gate &mutex_attrs); 317*7c478bd9Sstevel@tonic-gate } 318*7c478bd9Sstevel@tonic-gate 319*7c478bd9Sstevel@tonic-gate void 320*7c478bd9Sstevel@tonic-gate contract_hash_store(ctid_t ctid, int instid) 321*7c478bd9Sstevel@tonic-gate { 322*7c478bd9Sstevel@tonic-gate contract_bucket_t *bp; 323*7c478bd9Sstevel@tonic-gate contract_entry_t *ce; 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate bp = contract_hold_bucket(ctid); 326*7c478bd9Sstevel@tonic-gate assert(contract_lookup(bp, ctid) == NULL); 327*7c478bd9Sstevel@tonic-gate ce = startd_alloc(sizeof (contract_entry_t)); 328*7c478bd9Sstevel@tonic-gate ce->ce_ctid = ctid; 329*7c478bd9Sstevel@tonic-gate ce->ce_instid = instid; 330*7c478bd9Sstevel@tonic-gate 331*7c478bd9Sstevel@tonic-gate contract_insert(bp, ce); 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate contract_release_bucket(bp); 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate void 337*7c478bd9Sstevel@tonic-gate contract_hash_remove(ctid_t ctid) 338*7c478bd9Sstevel@tonic-gate { 339*7c478bd9Sstevel@tonic-gate contract_bucket_t *bp; 340*7c478bd9Sstevel@tonic-gate contract_entry_t *ce; 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate bp = contract_hold_bucket(ctid); 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate ce = contract_lookup(bp, ctid); 345*7c478bd9Sstevel@tonic-gate if (ce != NULL) { 346*7c478bd9Sstevel@tonic-gate uu_list_remove(bp->cb_list, ce); 347*7c478bd9Sstevel@tonic-gate startd_free(ce, sizeof (contract_entry_t)); 348*7c478bd9Sstevel@tonic-gate } 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate contract_release_bucket(bp); 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate 353*7c478bd9Sstevel@tonic-gate /* 354*7c478bd9Sstevel@tonic-gate * int lookup_inst_by_contract() 355*7c478bd9Sstevel@tonic-gate * Lookup the instance id in the hash table by the contract id. 356*7c478bd9Sstevel@tonic-gate * Returns instid if found, -1 if not. Doesn't do a hold on the 357*7c478bd9Sstevel@tonic-gate * instance, so a check for continued existence is required. 358*7c478bd9Sstevel@tonic-gate */ 359*7c478bd9Sstevel@tonic-gate int 360*7c478bd9Sstevel@tonic-gate lookup_inst_by_contract(ctid_t ctid) 361*7c478bd9Sstevel@tonic-gate { 362*7c478bd9Sstevel@tonic-gate contract_bucket_t *bp; 363*7c478bd9Sstevel@tonic-gate contract_entry_t *ce; 364*7c478bd9Sstevel@tonic-gate int id = -1; 365*7c478bd9Sstevel@tonic-gate 366*7c478bd9Sstevel@tonic-gate bp = contract_hold_bucket(ctid); 367*7c478bd9Sstevel@tonic-gate ce = contract_lookup(bp, ctid); 368*7c478bd9Sstevel@tonic-gate if (ce != NULL) 369*7c478bd9Sstevel@tonic-gate id = ce->ce_instid; 370*7c478bd9Sstevel@tonic-gate contract_release_bucket(bp); 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate return (id); 373*7c478bd9Sstevel@tonic-gate } 374