Lines Matching refs:thp

95 set_open_errno(topo_hdl_t *thp, int *errp, int err)
97 if (thp != NULL) {
98 topo_close(thp);
106 topo_set_product(topo_hdl_t *thp)
117 shp = topo_hdl_smbios(thp);
127 if ((product == NULL) && thp->th_pi && thp->th_di &&
128 (di_prom_prop_lookup_bytes(thp->th_pi, thp->th_di, "name",
133 product = thp->th_platform;
143 thp->th_product = topo_cleanup_auth_str(thp, product);
151 topo_hdl_t *thp = NULL;
160 return (set_open_errno(thp, errp, ETOPO_HDL_ABIVER));
163 return (set_open_errno(thp, errp, ETOPO_HDL_INVAL));
165 if ((thp = topo_zalloc(sizeof (topo_hdl_t), 0)) == NULL)
166 return (set_open_errno(thp, errp, ETOPO_NOMEM));
168 (void) pthread_mutex_init(&thp->th_lock, NULL);
173 topo_debug_set(thp, dbflags, dbout);
176 return (set_open_errno(thp, errp, ETOPO_NOMEM));
188 thp->th_alloc = tap;
190 if ((thp->th_modhash = topo_modhash_create(thp)) == NULL)
191 return (set_open_errno(thp, errp, ETOPO_NOMEM));
198 rootdir = topo_hdl_strdup(thp, "/");
199 thp->th_rootdir = (char *)rootdir;
206 return (set_open_errno(thp, errp, EINVAL));
214 thp->th_rootdir = topo_hdl_strdup(thp, rpath);
225 thp->th_platform = topo_hdl_strdup(thp, platform);
226 thp->th_isa = topo_hdl_strdup(thp, isa);
227 thp->th_machine = topo_hdl_strdup(thp, uts.machine);
228 thp->th_server = topo_cleanup_auth_str(thp, uts.nodename);
230 if (thp->th_rootdir == NULL || thp->th_platform == NULL ||
231 thp->th_machine == NULL)
232 return (set_open_errno(thp, errp, ETOPO_NOMEM));
234 if (topo_builtin_create(thp, thp->th_rootdir) != 0) {
235 topo_dprintf(thp, TOPO_DBG_ERR,
237 __func__, topo_hdl_errmsg(thp));
238 return (set_open_errno(thp, errp, topo_hdl_errno(thp)));
241 return (thp);
245 topo_close(topo_hdl_t *thp)
249 topo_hdl_lock(thp);
251 if (thp->th_rootdir != NULL)
252 topo_hdl_strfree(thp, thp->th_rootdir);
253 if (thp->th_platform != NULL)
254 topo_hdl_strfree(thp, thp->th_platform);
255 if (thp->th_isa != NULL)
256 topo_hdl_strfree(thp, thp->th_isa);
257 if (thp->th_machine != NULL)
258 topo_hdl_strfree(thp, thp->th_machine);
259 if (thp->th_server != NULL)
260 topo_hdl_strfree(thp, thp->th_server);
261 if (thp->th_product != NULL)
262 topo_hdl_strfree(thp, thp->th_product);
263 if (thp->th_ipmi != NULL)
264 ipmi_close(thp->th_ipmi);
265 if (thp->th_auth != NULL)
266 nvlist_free(thp->th_auth);
271 topo_snap_destroy(thp);
276 while ((tp = topo_list_next(&thp->th_trees)) != NULL) {
277 topo_list_delete(&thp->th_trees, tp);
284 topo_modhash_unload_all(thp);
286 if (thp->th_modhash != NULL)
287 topo_modhash_destroy(thp);
288 if (thp->th_alloc != NULL)
289 topo_free(thp->th_alloc, sizeof (topo_alloc_t));
291 topo_hdl_unlock(thp);
293 topo_free(thp, sizeof (topo_hdl_t));
297 topo_snap_create(topo_hdl_t *thp, int *errp, boolean_t need_force)
303 topo_hdl_lock(thp);
304 if (thp->th_uuid != NULL) {
306 topo_dprintf(thp, TOPO_DBG_ERR,
308 topo_hdl_unlock(thp);
314 * a new one from scratch, then thp->th_snap_dir will be
318 load_snapshot = ((thp->th_snap_dir == NULL) ? B_FALSE : B_TRUE);
320 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: thp=0x%p, load_snapshot=%s\n",
321 __func__, (void *)thp,
333 thp->th_timestamp = time(NULL);
335 if ((thp->th_uuid = topo_hdl_zalloc(thp, TOPO_UUID_SIZE))
338 topo_dprintf(thp, TOPO_DBG_ERR, "%s: unable to "
340 topo_hdl_unlock(thp);
347 if (thp->th_debug & TOPO_DBG_UUID) {
353 topo_dprintf(thp, TOPO_DBG_SNAP,
360 uuid_unparse(uuid, thp->th_uuid);
362 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: new snapshot uuid=%s, "
363 "timestamp=0x%lx(%s)\n", __func__, thp->th_uuid,
364 (ulong_t)thp->th_timestamp, ctime(&(thp->th_timestamp)));
367 topo_dprintf(thp, TOPO_DBG_FORCE,
369 thp->th_di = di_init("/", DINFOFORCE |
372 thp->th_di = di_init("/", DINFOCACHE);
392 thp->th_dli = di_devlink_init(NULL, DI_MAKE_LINK);
393 thp->th_pi = di_prom_init();
394 thp->th_smbios = smbios_open(NULL, SMB_VERSION, 0, NULL);
396 topo_set_product(thp);
398 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: th_snap_dir=%s\n",
399 __func__, thp->th_snap_dir);
402 if (topo_tree_enum_all(thp) < 0) {
406 if (topo_hdl_errno(thp) == ETOPO_ENUM_FATAL) {
407 topo_dprintf(thp, TOPO_DBG_ERR, "%s: fatal "
410 topo_hdl_unlock(thp);
413 topo_dprintf(thp, TOPO_DBG_ERR, "%s: non-fatal "
418 if (thp->th_ipmi != NULL &&
419 ipmi_sdr_changed(thp->th_ipmi) &&
420 ipmi_sdr_refresh(thp->th_ipmi) != 0) {
421 topo_dprintf(thp, TOPO_DBG_ERR,
423 __func__, ipmi_errmsg(thp->th_ipmi));
426 if (thp->th_uuid == NULL) {
427 topo_dprintf(thp, TOPO_DBG_ERR,
429 *errp = thp->th_errno;
430 topo_hdl_unlock(thp);
434 if ((ustr = topo_hdl_strdup(thp, thp->th_uuid)) == NULL) {
435 topo_dprintf(thp, TOPO_DBG_ERR,
437 (void) topo_hdl_seterrno(thp, ETOPO_NOMEM);
439 topo_hdl_unlock(thp);
446 if (thp->th_auth == NULL) {
447 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: create authority\n",
449 topo_auth_create(thp);
452 topo_hdl_unlock(thp);
453 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: returning ustr=%s\n",
460 topo_snap_log_create(topo_hdl_t *thp, const char *uuid, int *errp)
467 fac_walker(topo_hdl_t *thp, tnode_t *node, void *arg)
479 topo_dprintf(thp, TOPO_DBG_ERR,
492 topo_snap_hold(topo_hdl_t *thp, const char *uuid, int *errp)
496 if ((ret = topo_snap_hold_flag(thp, uuid, errp, 0)) == NULL)
497 topo_snap_release(thp);
503 topo_snap_hold_flag(topo_hdl_t *thp, const char *uuid, int *errp, int flag)
508 if (thp == NULL)
512 return (topo_snap_log_create(thp, uuid, errp));
516 thp->th_cromk_hdl = di_cromk_begin(0);
518 ret = topo_snap_create(thp, errp,
519 (thp->th_debug & TOPO_DBG_FORCE) ? B_TRUE : B_FALSE);
522 if (thp->th_cromk_hdl) {
523 di_cromk_end(thp->th_cromk_hdl, DI_CROMK_END_ABANDON,
525 thp->th_cromk_hdl = NULL;
534 twp = topo_walk_init(thp,
541 if (thp->th_cromk_hdl) {
543 (void) nvlist_lookup_string(thp->th_auth,
545 di_cromk_end(thp->th_cromk_hdl, DI_CROMK_END_COMMIT,
546 thp->th_server, thp->th_product, csn,
547 thp->th_di ? di_cna_dev(thp->th_di) : 0);
548 thp->th_cromk_hdl = NULL;
555 topo_walk_destroy(topo_hdl_t *thp, tnode_t *node, void *notused)
570 topo_snap_destroy(topo_hdl_t *thp)
579 for (tp = topo_list_next(&thp->th_trees); tp != NULL;
616 if (thp->th_di != DI_NODE_NIL) {
617 di_fini(thp->th_di);
618 thp->th_di = DI_NODE_NIL;
620 if (thp->th_dli != NULL) {
621 (void) di_devlink_fini(&thp->th_dli);
622 thp->th_dli = NULL;
624 if (thp->th_pi != DI_PROM_HANDLE_NIL) {
625 di_prom_fini(thp->th_pi);
626 thp->th_pi = DI_PROM_HANDLE_NIL;
628 if (thp->th_smbios != NULL) {
629 smbios_close(thp->th_smbios);
630 thp->th_smbios = NULL;
633 if (thp->th_uuid != NULL) {
634 topo_hdl_free(thp, thp->th_uuid, TOPO_UUID_SIZE);
635 thp->th_uuid = NULL;
638 topo_hdl_strfree(thp, thp->th_snap_dir);
639 thp->th_snap_dir = NULL;
643 topo_snap_release(topo_hdl_t *thp)
645 if (thp == NULL)
648 topo_hdl_lock(thp);
649 topo_snap_destroy(thp);
650 topo_hdl_unlock(thp);
654 topo_walk_init(topo_hdl_t *thp, const char *scheme, topo_walk_cb_t cb_f,
660 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: thp=0x%p, uuid=%s, "
661 "scheme=%s\n", __func__, (void *)thp, thp->th_uuid, scheme);
663 for (tp = topo_list_next(&thp->th_trees); tp != NULL;
673 if ((wp = topo_node_walk_init(thp, NULL, tp->tt_root,
915 topo_hdl_devinfo(topo_hdl_t *thp)
917 return (thp == NULL ? DI_NODE_NIL : thp->th_di);
921 topo_hdl_devlink(topo_hdl_t *thp)
923 return (thp == NULL ? NULL : thp->th_dli);
927 topo_hdl_prominfo(topo_hdl_t *thp)
929 return (thp == NULL ? DI_PROM_HANDLE_NIL : thp->th_pi);
933 topo_hdl_smbios(topo_hdl_t *thp)
935 return (thp == NULL ? NULL : thp->th_smbios);
942 topo_snap_load(topo_hdl_t *thp, const char *snap_dir, int *errp)
946 if (thp == NULL) {
947 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: NULL handle\n",
954 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: NULL directory\n",
956 (void) topo_hdl_seterrno(thp, ETOPO_HDL_INVAL);
961 topo_dprintf(thp, TOPO_DBG_SNAP, "%s: thp=0x%p, snap_dir=%s\n",
962 __func__, (void *)thp, snap_dir);
964 thp->th_snap_dir = topo_hdl_strdup(thp, snap_dir);
965 ustr = topo_snap_create(thp, errp, B_FALSE);
971 topo_hdl_cromk_hdl(topo_hdl_t *thp)
973 return (thp == NULL ? NULL : thp->th_cromk_hdl);