Lines Matching refs:ct
260 contract_dtor(contract_t *ct)
262 cte_queue_destroy(&ct->ct_events);
263 list_destroy(&ct->ct_vnodes);
264 mutex_destroy(&ct->ct_reflock);
265 mutex_destroy(&ct->ct_lock);
266 mutex_destroy(&ct->ct_evtlock);
284 contract_ctor(contract_t *ct, ct_type_t *type, ct_template_t *tmpl, void *data,
292 mutex_init(&ct->ct_lock, NULL, MUTEX_DEFAULT, NULL);
293 mutex_init(&ct->ct_reflock, NULL, MUTEX_DEFAULT, NULL);
294 mutex_init(&ct->ct_evtlock, NULL, MUTEX_DEFAULT, NULL);
295 ct->ct_id = id_alloc(contract_ids);
297 cte_queue_create(&ct->ct_events, CTEL_CONTRACT, 20, 0);
298 list_create(&ct->ct_vnodes, sizeof (contract_vnode_t),
304 ct->ct_ref = 2; /* one for the holder, one for "latest" */
305 ct->ct_cuid = crgetuid(CRED());
306 ct->ct_type = type;
307 ct->ct_data = data;
308 gethrestime(&ct->ct_ctime);
309 ct->ct_state = CTS_OWNED;
310 ct->ct_flags = flags;
311 ct->ct_regent = author->p_ct_process ?
313 ct->ct_ev_info = tmpl->ctmpl_ev_info;
314 ct->ct_ev_crit = tmpl->ctmpl_ev_crit;
315 ct->ct_cookie = tmpl->ctmpl_cookie;
316 ct->ct_owner = author;
317 ct->ct_ntime.ctm_total = -1;
318 ct->ct_qtime.ctm_total = -1;
319 ct->ct_nevent = NULL;
329 id_free(contract_ids, ct->ct_id);
332 ct->ct_events.ctq_flags |= CTQ_DEAD;
333 contract_dtor(ct);
336 ct->ct_proj = author->p_task->tk_proj;
337 ct->ct_proj->kpj_data.kpd_contract++;
338 (void) project_hold(ct->ct_proj);
347 ct->ct_zoneid = author->p_zone->zone_id;
348 ct->ct_czuniqid = ct->ct_mzuniqid = author->p_zone->zone_uniqid;
349 VERIFY(avl_find(&author->p_ct_held, ct, &where) == NULL);
350 avl_insert(&author->p_ct_held, ct, where);
357 VERIFY(avl_find(&contract_avl, ct, &where) == NULL);
358 avl_insert(&contract_avl, ct, where);
365 VERIFY(avl_find(&type->ct_type_avl, ct, &where) == NULL);
366 avl_insert(&type->ct_type_avl, ct, where);
367 type->ct_type_timestruc = ct->ct_ctime;
372 curlwp->lwp_ct_latest[type->ct_type_index] = ct;
387 contract_rele(contract_t *ct)
391 mutex_enter(&ct->ct_reflock);
392 ASSERT(ct->ct_ref > 0);
393 nref = --ct->ct_ref;
394 mutex_exit(&ct->ct_reflock);
399 ASSERT(ct->ct_owner == NULL);
400 ASSERT(ct->ct_evcnt == 0);
406 avl_remove(&contract_avl, ct);
412 mutex_enter(&ct->ct_type->ct_type_lock);
413 avl_remove(&ct->ct_type->ct_type_avl, ct);
414 mutex_exit(&ct->ct_type->ct_type_lock);
419 id_free(contract_ids, ct->ct_id);
425 ct->ct_proj->kpj_data.kpd_contract--;
426 project_rele(ct->ct_proj);
432 contract_dtor(ct);
433 ct->ct_type->ct_type_ops->contop_free(ct);
443 contract_hold(contract_t *ct)
445 mutex_enter(&ct->ct_reflock);
446 ASSERT(ct->ct_ref < UINT64_MAX);
447 ct->ct_ref++;
448 mutex_exit(&ct->ct_reflock);
460 contract_getzuniqid(contract_t *ct)
464 mutex_enter(&ct->ct_reflock);
465 zuniqid = ct->ct_mzuniqid;
466 mutex_exit(&ct->ct_reflock);
477 contract_setzuniqid(contract_t *ct, uint64_t zuniqid)
479 mutex_enter(&ct->ct_reflock);
480 ct->ct_mzuniqid = zuniqid;
481 mutex_exit(&ct->ct_reflock);
494 contract_abandon(contract_t *ct, proc_t *p, int explicit)
502 mutex_enter(&ct->ct_lock);
509 if (!explicit && (ct->ct_flags & CTF_INHERIT) &&
511 mutex_exit(&ct->ct_lock);
513 mutex_enter(&ct->ct_lock);
517 if (ct->ct_owner != p) {
518 mutex_exit(&ct->ct_lock);
526 avl_remove(&p->p_ct_held, ct);
527 ct->ct_owner = NULL;
535 q = p->p_ct_equeue[ct->ct_type->ct_type_index];
546 contract_hold(ct);
549 ct->ct_state = CTS_INHERITED;
550 VERIFY(ct->ct_regent == parent);
551 contract_process_take(parent, ct);
558 mutex_exit(&ct->ct_lock);
561 ct->ct_regent = NULL;
562 ct->ct_type->ct_type_ops->contop_abandon(ct);
571 cte_trim(q, ct);
575 contract_rele(ct);
581 contract_newct(contract_t *ct)
583 return (ct->ct_type->ct_type_ops->contop_newct(ct));
595 contract_adopt(contract_t *ct, proc_t *p)
607 (void) contract_type_pbundle(ct->ct_type, p);
609 mutex_enter(&ct->ct_lock);
610 parent = ct->ct_regent;
611 if (ct->ct_state != CTS_INHERITED ||
613 p->p_zone->zone_uniqid != ct->ct_czuniqid) {
614 mutex_exit(&ct->ct_lock);
621 mutex_exit(&ct->ct_lock);
623 mutex_enter(&ct->ct_lock);
631 if (ct->ct_state != CTS_INHERITED) {
633 mutex_exit(&ct->ct_lock);
636 ASSERT(ct->ct_regent == parent);
638 ct->ct_state = CTS_OWNED;
640 contract_process_adopt(ct, p);
643 ct->ct_owner = p;
644 VERIFY(avl_find(&p->p_ct_held, ct, &where) == NULL);
645 avl_insert(&p->p_ct_held, ct, where);
648 ASSERT(ct->ct_owner->p_ct_equeue);
649 ASSERT(ct->ct_owner->p_ct_equeue[ct->ct_type->ct_type_index]);
650 q = ct->ct_owner->p_ct_equeue[ct->ct_type->ct_type_index];
651 cte_copy(&ct->ct_events, q);
652 mutex_exit(&ct->ct_lock);
663 contract_ack(contract_t *ct, uint64_t evid, int ack)
666 list_t *queue = &ct->ct_events.ctq_events;
673 mutex_enter(&ct->ct_lock);
674 mutex_enter(&ct->ct_events.ctq_lock);
686 ct->ct_evcnt--;
693 mutex_exit(&ct->ct_events.ctq_lock);
694 mutex_exit(&ct->ct_lock);
705 error = ct->ct_type->ct_type_ops->contop_ack(ct, evtype, evid);
707 error = ct->ct_type->ct_type_ops->contop_nack(ct, evtype, evid);
714 contract_ack_inval(contract_t *ct, uint_t evtype, uint64_t evid)
717 ct->ct_id);
723 contract_qack_inval(contract_t *ct, uint_t evtype, uint64_t evid)
726 ct->ct_id);
732 contract_qack_notsup(contract_t *ct, uint_t evtype, uint64_t evid)
743 contract_qack(contract_t *ct, uint64_t evid)
746 list_t *queue = &ct->ct_events.ctq_events;
750 mutex_enter(&ct->ct_lock);
751 mutex_enter(&ct->ct_events.ctq_lock);
762 mutex_exit(&ct->ct_events.ctq_lock);
763 mutex_exit(&ct->ct_lock);
773 return (ct->ct_type->ct_type_ops->contop_qack(ct, evtype, evid));
783 contract_orphan(contract_t *ct)
786 list_t *queue = &ct->ct_events.ctq_events;
788 ASSERT(MUTEX_HELD(&ct->ct_lock));
789 ASSERT(ct->ct_state != CTS_ORPHAN);
791 mutex_enter(&ct->ct_events.ctq_lock);
792 ct->ct_state = CTS_ORPHAN;
796 ct->ct_evcnt--;
799 mutex_exit(&ct->ct_events.ctq_lock);
801 ASSERT(ct->ct_evcnt == 0);
814 contract_destroy(contract_t *ct)
816 ASSERT(MUTEX_HELD(&ct->ct_lock));
817 ASSERT(ct->ct_state != CTS_DEAD);
818 ASSERT(ct->ct_owner == NULL);
820 ct->ct_state = CTS_DEAD;
821 cte_queue_drain(&ct->ct_events, 1);
822 mutex_exit(&ct->ct_lock);
823 mutex_enter(&ct->ct_type->ct_type_events.ctq_lock);
824 cte_trim(&ct->ct_type->ct_type_events, ct);
825 mutex_exit(&ct->ct_type->ct_type_events.ctq_lock);
826 mutex_enter(&ct->ct_lock);
827 ct->ct_type->ct_type_ops->contop_destroy(ct);
828 mutex_exit(&ct->ct_lock);
829 contract_rele(ct);
840 contract_vnode_get(contract_t *ct, vfs_t *vfsp)
845 mutex_enter(&ct->ct_lock);
846 for (ctv = list_head(&ct->ct_vnodes); ctv != NULL;
847 ctv = list_next(&ct->ct_vnodes, ctv))
853 mutex_exit(&ct->ct_lock);
866 contract_vnode_set(contract_t *ct, contract_vnode_t *ctv, vnode_t *vnode)
868 mutex_enter(&ct->ct_lock);
870 list_insert_head(&ct->ct_vnodes, ctv);
871 mutex_exit(&ct->ct_lock);
883 contract_vnode_clear(contract_t *ct, contract_vnode_t *ctv)
888 mutex_enter(&ct->ct_lock);
891 list_remove(&ct->ct_vnodes, ctv);
898 mutex_exit(&ct->ct_lock);
912 contract_t *ct;
926 while ((ct = avl_destroy_nodes(&p->p_ct_held, &cookie)) != NULL)
927 VERIFY(contract_abandon(ct, p, 0) == 0);
964 contract_status_common(contract_t *ct, zone_t *zone, void *status,
970 ASSERT(MUTEX_HELD(&ct->ct_lock));
972 zone->zone_uniqid == ct->ct_czuniqid) {
981 if (zone->zone_uniqid == ct->ct_czuniqid ||
982 ct->ct_czuniqid == GLOBAL_ZONEUNIQID) {
983 zoneid = ct->ct_zoneid;
984 } else if ((czone = zone_find_by_id(ct->ct_zoneid)) != NULL) {
985 if (czone->zone_uniqid == ct->ct_mzuniqid)
986 zoneid = ct->ct_zoneid;
992 (ct->ct_state == CTS_OWNED) ? ct->ct_owner->p_pid :
993 (ct->ct_state == CTS_INHERITED) ? ct->ct_regent->ct_id : 0);
994 STRUCT_FSET(lstatus, ctst_state, ct->ct_state);
1007 STRUCT_FSET(lstatus, ctst_holder, (ct->ct_state < CTS_ORPHAN) ?
1009 STRUCT_FSET(lstatus, ctst_state, (ct->ct_state < CTS_ORPHAN) ?
1010 CTS_OWNED : ct->ct_state);
1012 STRUCT_FSET(lstatus, ctst_nevents, ct->ct_evcnt);
1013 STRUCT_FSET(lstatus, ctst_ntime, get_time_left(&ct->ct_ntime));
1014 STRUCT_FSET(lstatus, ctst_qtime, get_time_left(&ct->ct_qtime));
1016 ct->ct_nevent ? ct->ct_nevent->cte_id : 0);
1017 STRUCT_FSET(lstatus, ctst_critical, ct->ct_ev_crit);
1018 STRUCT_FSET(lstatus, ctst_informative, ct->ct_ev_info);
1019 STRUCT_FSET(lstatus, ctst_cookie, ct->ct_cookie);
1020 STRUCT_FSET(lstatus, ctst_type, ct->ct_type->ct_type_index);
1021 STRUCT_FSET(lstatus, ctst_id, ct->ct_id);
1032 contract_checkcred(contract_t *ct, const cred_t *cr)
1037 mutex_enter(&ct->ct_lock);
1038 if ((p = ct->ct_owner) != NULL) {
1043 mutex_exit(&ct->ct_lock);
1057 contract_owned(contract_t *ct, const cred_t *cr, int locked)
1063 ASSERT(locked || MUTEX_NOT_HELD(&ct->ct_lock));
1066 mzuniqid = contract_getzuniqid(ct);
1077 owner = (ct->ct_owner == curproc);
1078 cmatch = (zuniqid == ct->ct_czuniqid) &&
1079 ((ct->ct_cuid == euid) || (!locked && contract_checkcred(ct, cr)));
1080 zmatch = (ct->ct_czuniqid != mzuniqid) && (zuniqid == mzuniqid) &&
1144 contract_t *ct;
1148 ct = avl_last(&type->ct_type_avl);
1149 res = ct ? ct->ct_id : -1;
1163 contract_t *ct;
1167 ct = avl_last(&contract_avl);
1168 res = ct ? ct->ct_id : -1;
1184 contract_t template, *ct;
1189 ct = avl_find(tree, &template, &where);
1190 if (ct == NULL)
1191 ct = avl_nearest(tree, where, AVL_AFTER);
1193 while (ct && (contract_getzuniqid(ct) != zuniqid))
1194 ct = AVL_NEXT(tree, ct);
1195 res = ct ? ct->ct_id : -1;
1247 contract_t template, *ct;
1256 ct = avl_find(&contract_avl, &template, &where);
1257 if (ct == NULL)
1258 ct = avl_nearest(&contract_avl, where, AVL_AFTER);
1259 while (ct && !(ct->ct_state < CTS_ORPHAN &&
1260 contract_getzuniqid(ct) == zuniqid &&
1261 ct->ct_czuniqid == GLOBAL_ZONEUNIQID))
1262 ct = AVL_NEXT(&contract_avl, ct);
1263 res = ct ? ct->ct_id : -1;
1267 ct = avl_find(&p->p_ct_held, &template, &where);
1268 if (ct == NULL)
1269 ct = avl_nearest(&p->p_ct_held, where, AVL_AFTER);
1270 res = ct ? ct->ct_id : -1;
1287 contract_t template, *ct;
1290 ct = avl_find(tree, &template, NULL);
1291 if (ct == NULL || (zuniqid != GLOBAL_ZONEUNIQID &&
1292 contract_getzuniqid(ct) != zuniqid)) {
1301 mutex_enter(&ct->ct_reflock);
1302 if (ct->ct_ref) {
1303 ct->ct_ref++;
1304 mutex_exit(&ct->ct_reflock);
1306 mutex_exit(&ct->ct_reflock);
1307 ct = NULL;
1310 return (ct);
1323 contract_t *ct;
1326 ct = contract_ptr_common(&type->ct_type_avl, id, zuniqid);
1329 return (ct);
1342 contract_t *ct;
1345 ct = contract_ptr_common(&contract_avl, id, zuniqid);
1348 return (ct);
1915 contract_t *ct = e->cte_contract;
1919 result = curproc->p_zone->zone_uniqid == ct->ct_czuniqid &&
1920 contract_checkcred(ct, cr);
1939 contract_t *ct;
1949 ct = e->cte_contract;
1957 zuniqid != contract_getzuniqid(ct))) {
1969 } else if (cr != NULL && !contract_owned(ct, cr, B_TRUE)) {
2120 cte_trim(ct_equeue_t *q, contract_t *ct)
2135 (e->cte_contract == ct)) {
2142 } else if ((e->cte_contract == ct) && !stopper) {
2145 } else if (ct && !stopper) {
2291 cte_publish_all(contract_t *ct, ct_kevent_t *e, nvlist_t *data, nvlist_t *gdata)
2299 e->cte_contract = ct;
2303 evid = e->cte_id = atomic_inc_64_nv(&ct->ct_type->ct_type_evid);
2304 contract_hold(ct);
2307 * For a negotiation event we set the ct->ct_nevent field of the
2313 ct->ct_nevent = e;
2325 mutex_enter(&ct->ct_evtlock);
2331 mutex_enter(&ct->ct_lock);
2332 mutex_enter(&ct->ct_events.ctq_lock);
2334 if (ct->ct_state >= CTS_ORPHAN)
2337 ct->ct_evcnt++;
2339 mutex_exit(&ct->ct_lock);
2340 cte_publish(&ct->ct_events, e, &ts, B_FALSE);
2346 mutex_enter(&ct->ct_type->ct_type_events.ctq_lock);
2347 cte_publish(&ct->ct_type->ct_type_events, e, &ts, B_FALSE);
2353 mutex_enter(&ct->ct_lock);
2354 if (ct->ct_owner) {
2359 ASSERT(ct->ct_owner->p_ct_equeue);
2360 ASSERT(ct->ct_owner->p_ct_equeue[ct->ct_type->ct_type_index]);
2361 q = ct->ct_owner->p_ct_equeue[ct->ct_type->ct_type_index];
2363 mutex_exit(&ct->ct_lock);
2373 mutex_exit(&ct->ct_lock);
2378 mutex_enter(&ct->ct_lock);
2379 negev = ct->ct_nevent;
2380 ct->ct_nevent = NULL;
2382 mutex_exit(&ct->ct_lock);
2385 mutex_exit(&ct->ct_evtlock);