int fmd_fmri_contains(nvlist_t *er, nvlist_t *ee) { int ret1, ret2; char *erserstr, *eeserstr; uint8_t erversion, eeversion; uint64_t erserint, eeserint; uint32_t erval, eeval; if (nvlist_lookup_uint32(er, FM_FMRI_CPU_ID, &erval) != 0) return (0); if (nvlist_lookup_uint32(ee, FM_FMRI_CPU_ID, &eeval) != 0) return (0); if (erval != eeval) return (0); if (nvlist_lookup_uint8(er, FM_VERSION, &erversion) != 0) return (0); if (nvlist_lookup_uint8(ee, FM_VERSION, &eeversion) != 0) return (0); if (erversion != eeversion) return (0); if (erversion == CPU_SCHEME_VERSION0) { if (nvlist_lookup_uint64(er, FM_FMRI_CPU_SERIAL_ID, &erserint) != 0) return (0); if (nvlist_lookup_uint64(ee, FM_FMRI_CPU_SERIAL_ID, &eeserint) != 0) return (0); if (erserint != eeserint) return (0); } else if (erversion == CPU_SCHEME_VERSION1) { /* Serial ID is an optional element */ ret1 = nvlist_lookup_string(er, FM_FMRI_CPU_SERIAL_ID, &erserstr); ret2 = nvlist_lookup_string(ee, FM_FMRI_CPU_SERIAL_ID, &eeserstr); if (ret1 != ret2) return (0); if (ret1 == ENOENT) /* * Serial IDs not found in both container, containee */ return (1); if (ret1 != 0) return (0); /* * Found Serial Ids in both container and containee. * Check if they are same. */ if (strlen(erserstr) != strlen(eeserstr)) return (0); if (strcmp(erserstr, eeserstr) != 0) return (0); } return (1); }
void cma_cpu_start_retry(fmd_hdl_t *hdl, nvlist_t *fmri, const char *uuid, boolean_t repair) { cma_cpu_t *cpu; char *scheme; uint_t cpuid; nvlist_t *asru = NULL; topo_hdl_t *thp; int err; if (repair || nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0) return; if (strcmp(scheme, FM_FMRI_SCHEME_CPU) == 0) { if (nvlist_lookup_uint32(fmri, FM_FMRI_CPU_ID, &cpuid) != 0) return; } else if (strcmp(scheme, FM_FMRI_SCHEME_HC) != 0) { return; } else { /* lookup cpuid from ASRU */ thp = fmd_fmri_topo_hold(TOPO_VERSION); if (thp != NULL) { (void) topo_fmri_asru(thp, fmri, &asru, &err); fmd_fmri_topo_rele(thp); } if (nvlist_lookup_uint32(asru, FM_FMRI_CPU_ID, &cpuid) != 0) { nvlist_free(asru); return; } } /* * check to see if the cpu has been offline. */ fmd_hdl_debug(hdl, "cpu %u is not offline yet - sleeping\n", cpuid); /* * Create a cpu node and add to the head of the cpu list */ cpu = fmd_hdl_zalloc(hdl, sizeof (cma_cpu_t), FMD_SLEEP); (void) nvlist_dup(fmri, &cpu->cpu_fmri, 0); if (uuid != NULL) cpu->cpu_uuid = fmd_hdl_strdup(hdl, uuid, FMD_SLEEP); cpu->cpuid = cpuid; cpu->cpu_next = cma.cma_cpus; cma.cma_cpus = cpu; if (cma.cma_cpu_timerid != 0) fmd_timer_remove(hdl, cma.cma_cpu_timerid); cma.cma_cpu_curdelay = cma.cma_cpu_mindelay; cma.cma_cpu_timerid = fmd_timer_install(hdl, NULL, NULL, cma.cma_cpu_curdelay); }
int topo_fmri_service_state(topo_hdl_t *thp, nvlist_t *fmri, int *err) { char *scheme; uint32_t service_state = FMD_SERVICE_STATE_UNKNOWN; nvlist_t *out = NULL; tnode_t *rnode; if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_SERVICE_STATE, out)); if ((rnode = topo_hdl_root(thp, scheme)) == NULL) return (set_error(thp, ETOPO_METHOD_NOTSUP, err, TOPO_METH_SERVICE_STATE, out)); if (topo_method_invoke(rnode, TOPO_METH_SERVICE_STATE, TOPO_METH_SERVICE_STATE_VERSION, fmri, &out, err) < 0) return (set_error(thp, *err, err, TOPO_METH_SERVICE_STATE, out)); (void) nvlist_lookup_uint32(out, TOPO_METH_SERVICE_STATE_RET, &service_state); nvlist_free(out); return (service_state); }
int topo_fmri_unretire(topo_hdl_t *thp, nvlist_t *fmri, int *err) { char *scheme; uint32_t status; nvlist_t *out = NULL; tnode_t *rnode; if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_UNRETIRE, out)); if ((rnode = topo_hdl_root(thp, scheme)) == NULL) return (set_error(thp, ETOPO_METHOD_NOTSUP, err, TOPO_METH_UNRETIRE, out)); if (topo_method_invoke(rnode, TOPO_METH_UNRETIRE, TOPO_METH_UNRETIRE_VERSION, fmri, &out, err) < 0) return (set_error(thp, *err, err, TOPO_METH_UNRETIRE, out)); if (nvlist_lookup_uint32(out, TOPO_METH_UNRETIRE_RET, &status) != 0) { nvlist_free(out); return (set_error(thp, ETOPO_METHOD_FAIL, err, TOPO_METH_UNRETIRE, out)); } nvlist_free(out); return (status); }
int topo_fmri_unusable(topo_hdl_t *thp, nvlist_t *fmri, int *err) { char *scheme; uint32_t unusable = 0; nvlist_t *out = NULL; tnode_t *rnode; if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_UNUSABLE, out)); if ((rnode = topo_hdl_root(thp, scheme)) == NULL) return (set_error(thp, ETOPO_METHOD_NOTSUP, err, TOPO_METH_UNUSABLE, out)); if (topo_method_invoke(rnode, TOPO_METH_UNUSABLE, TOPO_METH_UNUSABLE_VERSION, fmri, &out, err) < 0) return (set_error(thp, *err, err, TOPO_METH_UNUSABLE, out)); (void) nvlist_lookup_uint32(out, TOPO_METH_UNUSABLE_RET, &unusable); nvlist_free(out); return (unusable); }
int topo_fmri_contains(topo_hdl_t *thp, nvlist_t *fmri, nvlist_t *subfmri, int *err) { uint32_t contains; char *scheme; nvlist_t *in = NULL, *out = NULL; tnode_t *rnode; if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_CONTAINS, NULL)); if ((rnode = topo_hdl_root(thp, scheme)) == NULL) return (set_error(thp, ETOPO_METHOD_NOTSUP, err, TOPO_METH_CONTAINS, NULL)); if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0) return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_CONTAINS, NULL)); if (nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_FMRI, fmri) != 0 || nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_SUBFMRI, subfmri) != 0) return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_CONTAINS, in)); if (topo_method_invoke(rnode, TOPO_METH_CONTAINS, TOPO_METH_CONTAINS_VERSION, in, &out, err) < 0) return (set_error(thp, *err, err, TOPO_METH_CONTAINS, in)); (void) nvlist_lookup_uint32(out, TOPO_METH_CONTAINS_RET, &contains); nvlist_free(in); nvlist_free(out); return (contains); }
int topo_fmri_replaced(topo_hdl_t *thp, nvlist_t *fmri, int *err) { uint32_t replaced = FMD_OBJ_STATE_NOT_PRESENT; char *scheme; nvlist_t *out = NULL; tnode_t *rnode; if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_REPLACED, out)); if ((rnode = topo_hdl_root(thp, scheme)) == NULL) return (set_error(thp, ETOPO_METHOD_NOTSUP, err, TOPO_METH_REPLACED, out)); if (topo_method_invoke(rnode, TOPO_METH_REPLACED, TOPO_METH_REPLACED_VERSION, fmri, &out, err) < 0) { (void) set_error(thp, *err, err, TOPO_METH_REPLACED, out); return (FMD_OBJ_STATE_UNKNOWN); } (void) nvlist_lookup_uint32(out, TOPO_METH_REPLACED_RET, &replaced); nvlist_free(out); return (replaced); }
int topo_fmri_present(topo_hdl_t *thp, nvlist_t *fmri, int *err) { uint32_t present = 0; char *scheme; nvlist_t *out = NULL; tnode_t *rnode; if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_PRESENT, out)); if ((rnode = topo_hdl_root(thp, scheme)) == NULL) return (set_error(thp, ETOPO_METHOD_NOTSUP, err, TOPO_METH_PRESENT, out)); if (topo_method_invoke(rnode, TOPO_METH_PRESENT, TOPO_METH_PRESENT_VERSION, fmri, &out, err) < 0) { (void) set_error(thp, *err, err, TOPO_METH_PRESENT, out); return (present); } (void) nvlist_lookup_uint32(out, TOPO_METH_PRESENT_RET, &present); nvlist_free(out); return (present); }
static int add_fdisk_props(ulong_t *ret_array, int part_num, dm_descriptor_t d) { int error; nvlist_t *attrs; int i; int result = 1; int offset; static char *attr_names[] = { DM_PTYPE, DM_BOOTID, DM_RELSECT, DM_NSECTORS, NULL}; attrs = dm_get_attributes(d, &error); if (error != 0) { return (0); } /* figure out where in the array to put the values */ offset = part_num * 4; for (i = 0; attr_names[i]; i++) { uint32_t val32; if (nvlist_lookup_uint32(attrs, attr_names[i], &val32) != 0) { result = 0; break; } ret_array[offset++] = val32; } nvlist_free(attrs); return (result); }
uint32_t fnvlist_lookup_uint32(nvlist_t *nvl, const char *name) { uint32_t rv; VERIFY0(nvlist_lookup_uint32(nvl, name, &rv)); return (rv); }
int fmd_fmri_unusable(nvlist_t *nvl) { int rc, err = 0; uint8_t version; uint32_t cpuid; topo_hdl_t *thp; if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || version > FM_CPU_SCHEME_VERSION || nvlist_lookup_uint32(nvl, FM_FMRI_CPU_ID, &cpuid) != 0) return (fmd_fmri_set_errno(EINVAL)); /* * If the cpu-scheme topology exports this method unusable(), invoke it. */ if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) return (fmd_fmri_set_errno(EINVAL)); rc = topo_fmri_unusable(thp, nvl, &err); fmd_fmri_topo_rele(thp); if (err != ETOPO_METHOD_NOTSUP) return (rc); return (p_online(cpuid, P_STATUS) == P_FAULTED); }
int fmd_fmri_replaced(nvlist_t *nvl) { int rc, err = 0; uint8_t version; uint32_t cpuid; uint64_t nvlserid, curserid; char *nvlserstr, curserbuf[21]; /* sizeof (UINT64_MAX) + '\0' */ topo_hdl_t *thp; if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || nvlist_lookup_uint32(nvl, FM_FMRI_CPU_ID, &cpuid) != 0) return (fmd_fmri_set_errno(EINVAL)); /* * If the cpu-scheme topology exports this method replaced(), invoke it. */ if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) return (fmd_fmri_set_errno(EINVAL)); rc = topo_fmri_replaced(thp, nvl, &err); fmd_fmri_topo_rele(thp); if (err != ETOPO_METHOD_NOTSUP) return (rc); if (version == CPU_SCHEME_VERSION0) { if (nvlist_lookup_uint64(nvl, FM_FMRI_CPU_SERIAL_ID, &nvlserid) != 0) return (fmd_fmri_set_errno(EINVAL)); if (cpu_get_serialid_V0(cpuid, &curserid) != 0) return (errno == ENOENT ? FMD_OBJ_STATE_NOT_PRESENT : -1); return (curserid == nvlserid ? FMD_OBJ_STATE_STILL_PRESENT : FMD_OBJ_STATE_REPLACED); } else if (version == CPU_SCHEME_VERSION1) { if ((rc = nvlist_lookup_string(nvl, FM_FMRI_CPU_SERIAL_ID, &nvlserstr)) != 0) if (rc != ENOENT) return (fmd_fmri_set_errno(EINVAL)); /* * If serial id is not available, just check if the cpuid * is present. */ if (cpu_get_serialid_V1(cpuid, curserbuf, 21) != 0) if (cpu_cpuid_present(cpuid)) return (FMD_OBJ_STATE_UNKNOWN); else return (FMD_OBJ_STATE_NOT_PRESENT); return (strcmp(curserbuf, nvlserstr) == 0 ? FMD_OBJ_STATE_STILL_PRESENT : FMD_OBJ_STATE_REPLACED); } else { return (fmd_fmri_set_errno(EINVAL)); } }
ssize_t fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) { int err; uint8_t version; uint32_t cpuid; uint64_t serint; char *serstr; if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0) return (fmd_fmri_set_errno(EINVAL)); if (version == CPU_SCHEME_VERSION0) { if (nvlist_lookup_uint32(nvl, FM_FMRI_CPU_ID, &cpuid) != 0 || nvlist_lookup_uint64(nvl, FM_FMRI_CPU_SERIAL_ID, &serint) != 0) return (fmd_fmri_set_errno(EINVAL)); return (snprintf(buf, buflen, "cpu:///%s=%u/%s=%llX", FM_FMRI_CPU_ID, cpuid, FM_FMRI_CPU_SERIAL_ID, (u_longlong_t)serint)); } else if (version == CPU_SCHEME_VERSION1) { if (nvlist_lookup_uint32(nvl, FM_FMRI_CPU_ID, &cpuid) != 0) return (fmd_fmri_set_errno(EINVAL)); /* * Serial number is an optional element */ if ((err = nvlist_lookup_string(nvl, FM_FMRI_CPU_SERIAL_ID, &serstr)) != 0) if (err == ENOENT) return (snprintf(buf, buflen, "cpu:///%s=%u", FM_FMRI_CPU_ID, cpuid)); else return (fmd_fmri_set_errno(EINVAL)); else return (snprintf(buf, buflen, "cpu:///%s=%u/%s=%s", FM_FMRI_CPU_ID, cpuid, FM_FMRI_CPU_SERIAL_ID, serstr)); } else { return (fmd_fmri_set_errno(EINVAL)); } }
int fmd_fmri_expand(nvlist_t *nvl) { uint8_t version; uint32_t cpuid; uint64_t serialid; char *serstr, serbuf[21]; /* sizeof (UINT64_MAX) + '\0' */ int rc, err; topo_hdl_t *thp; if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || nvlist_lookup_uint32(nvl, FM_FMRI_CPU_ID, &cpuid) != 0) return (fmd_fmri_set_errno(EINVAL)); /* * If the cpu-scheme topology exports this method expand(), invoke it. */ if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) return (fmd_fmri_set_errno(EINVAL)); rc = topo_fmri_expand(thp, nvl, &err); fmd_fmri_topo_rele(thp); if (err != ETOPO_METHOD_NOTSUP) return (rc); if (version == CPU_SCHEME_VERSION0) { if ((rc = nvlist_lookup_uint64(nvl, FM_FMRI_CPU_SERIAL_ID, &serialid)) != 0) { if (rc != ENOENT) return (fmd_fmri_set_errno(rc)); if (cpu_get_serialid_V0(cpuid, &serialid) != 0) return (-1); /* errno is set for us */ if ((rc = nvlist_add_uint64(nvl, FM_FMRI_CPU_SERIAL_ID, serialid)) != 0) return (fmd_fmri_set_errno(rc)); } } else if (version == CPU_SCHEME_VERSION1) { if ((rc = nvlist_lookup_string(nvl, FM_FMRI_CPU_SERIAL_ID, &serstr)) != 0) { if (rc != ENOENT) return (fmd_fmri_set_errno(rc)); if (cpu_get_serialid_V1(cpuid, serbuf, 21) != 0) return (0); /* Serial number is optional */ if ((rc = nvlist_add_string(nvl, FM_FMRI_CPU_SERIAL_ID, serbuf)) != 0) return (fmd_fmri_set_errno(rc)); } } else { return (fmd_fmri_set_errno(EINVAL)); } return (0); }
int cpu_offline(fmd_hdl_t *hdl, nvlist_t *asru, const char *uuid, int cpustate) { int i; uint_t cpuid; cma_cpu_t *cpu; if (nvlist_lookup_uint32(asru, FM_FMRI_CPU_ID, &cpuid) != 0) { fmd_hdl_debug(hdl, "missing '%s'\n", FM_FMRI_CPU_ID); cma_stats.bad_flts.fmds_value.ui64++; return (CMA_RA_FAILURE); } /* * cpu offlining using ldom_fmri_retire() may be asynchronous, so we * have to set the timer and check the cpu status later. */ for (i = 0; i < cma.cma_cpu_tries; i++, (void) nanosleep(&cma.cma_cpu_delay, NULL)) { if (cpu_cmd(hdl, asru, cpustate) != -1) { cma_stats.cpu_flts.fmds_value.ui64++; break; } } if (i >= cma.cma_cpu_tries) { cma_stats.cpu_fails.fmds_value.ui64++; } /* * check to see if the cpu has been offline. */ fmd_hdl_debug(hdl, "cpu is not offline yet - sleeping\n"); /* * Create a cpu node and add to the head of the cpu list */ cpu = fmd_hdl_zalloc(hdl, sizeof (cma_cpu_t), FMD_SLEEP); (void) nvlist_dup(asru, &cpu->cpu_fmri, 0); if (uuid != NULL) cpu->cpu_uuid = fmd_hdl_strdup(hdl, uuid, FMD_SLEEP); cpu->cpuid = cpuid; cpu->cpu_next = cma.cma_cpus; cma.cma_cpus = cpu; if (cma.cma_cpu_timerid != 0) fmd_timer_remove(hdl, cma.cma_cpu_timerid); cma.cma_cpu_curdelay = cma.cma_cpu_mindelay; cma.cma_cpu_timerid = fmd_timer_install(hdl, NULL, NULL, cma.cma_cpu_curdelay); return (CMA_RA_FAILURE); }
int ct_pr_status_get_param(ct_stathdl_t stathdl, uint_t *param) { struct ctlib_status_info *info = stathdl; if (info->status.ctst_type != CTT_PROCESS) return (EINVAL); if (info->nvl == NULL) return (ENOENT); return (nvlist_lookup_uint32(info->nvl, CTPS_PARAMS, param)); }
int ct_pr_event_get_pid(ct_evthdl_t evthdl, pid_t *pid) { struct ctlib_event_info *info = evthdl; if (info->event.ctev_cttype != CTT_PROCESS) return (EINVAL); if (info->nvl == NULL) return (ENOENT); return (nvlist_lookup_uint32(info->nvl, CTPE_PID, (uint_t *)pid)); }
int ct_pr_status_get_fatal(ct_stathdl_t stathdl, uint_t *fatal) { struct ctlib_status_info *info = stathdl; if (info->status.ctst_type != CTT_PROCESS) return (EINVAL); if (info->nvl == NULL) return (ENOENT); return (nvlist_lookup_uint32(info->nvl, CTPS_EV_FATAL, fatal)); }
static int prop_method_get(tnode_t *node, topo_propval_t *pv, topo_propmethod_t *pm, nvlist_t *pargs, int *err) { int ret; nvlist_t *args, *nvl; char *name; topo_type_t type; if (topo_hdl_nvalloc(pv->tp_hdl, &args, NV_UNIQUE_NAME) < 0 || nvlist_add_nvlist(args, TOPO_PROP_ARGS, pm->tpm_args) != 0) return (method_geterror(NULL, ETOPO_PROP_NVL, err)); if (pargs != NULL) if (nvlist_add_nvlist(args, TOPO_PROP_PARGS, pargs) != 0) return (method_geterror(args, ETOPO_PROP_NVL, err)); /* * Now, get the latest value * * Grab a reference to the property and then unlock the node. This will * allow property methods to safely re-enter the prop_get codepath, * making it possible for property methods to access other property * values on the same node w\o causing a deadlock. */ topo_prop_hold(pv); topo_node_unlock(node); if (topo_method_call(node, pm->tpm_name, pm->tpm_version, args, &nvl, err) < 0) { topo_node_lock(node); topo_prop_rele(pv); return (method_geterror(args, *err, err)); } topo_node_lock(node); topo_prop_rele(pv); nvlist_free(args); /* Verify the property contents */ ret = nvlist_lookup_string(nvl, TOPO_PROP_VAL_NAME, &name); if (ret != 0 || strcmp(name, pv->tp_name) != 0) return (method_geterror(nvl, ETOPO_PROP_NAME, err)); ret = nvlist_lookup_uint32(nvl, TOPO_PROP_VAL_TYPE, (uint32_t *)&type); if (ret != 0 || type != pv->tp_type) return (method_geterror(nvl, ETOPO_PROP_TYPE, err)); /* Release the last value and re-assign to the new value */ if (pv->tp_val != NULL) nvlist_free(pv->tp_val); pv->tp_val = nvl; return (0); }
int ct_pr_event_get_signal(ct_evthdl_t evthdl, int *signal) { struct ctlib_event_info *info = evthdl; if (info->event.ctev_cttype != CTT_PROCESS) return (EINVAL); if (info->event.ctev_type != CT_PR_EV_SIGNAL) return (EINVAL); if (info->nvl == NULL) return (ENOENT); return (nvlist_lookup_uint32(info->nvl, CTPE_SIGNAL, (uint_t *)signal)); }
int ct_pr_event_get_senderct(ct_evthdl_t evthdl, ctid_t *sendct) { struct ctlib_event_info *info = evthdl; if (info->event.ctev_cttype != CTT_PROCESS) return (EINVAL); if (info->event.ctev_type != CT_PR_EV_SIGNAL) return (EINVAL); if (info->nvl == NULL) return (ENOENT); return (nvlist_lookup_uint32(info->nvl, CTPE_SENDCT, (uint_t *)sendct)); }
/* * Return: 1 if fails, 0 if ok. geometry array contains: * 0. SectorsPerCylinder * 1. HeadsPerCylinder * 2. BytesPerCylinder * 3. PhysicalCylinders * 4. DataCylinders * 5. AlternateCylinders * 6. ActualCylinders */ static int disk_geometry(char *media_name, ulong_t *geometry) { int error; dm_descriptor_t d; nvlist_t *attrs; uint32_t val32; d = dm_get_descriptor_by_name(DM_MEDIA, media_name, &error); if (error != 0) { return (1); } attrs = dm_get_attributes(d, &error); dm_free_descriptor(d); if (error != 0) { return (1); } /* * If nsect is not in the attr list then we have media that does * not have geometry info on it (e.g. EFI label). So return a failure * in this case. Otherwise, just get the attrs we can and return * their values. */ if (nvlist_lookup_uint32(attrs, DM_NSECTORS, &val32) != 0) { nvlist_free(attrs); return (1); } geometry[0] = val32; val32 = 0; nvlist_lookup_uint32(attrs, DM_NHEADS, &val32); geometry[1] = val32; val32 = 0; nvlist_lookup_uint32(attrs, DM_BLOCKSIZE, &val32); geometry[2] = (geometry[1] * geometry[0]) * val32; val32 = 0; nvlist_lookup_uint32(attrs, DM_NPHYSCYLINDERS, &val32); geometry[3] = val32; val32 = 0; nvlist_lookup_uint32(attrs, DM_NCYLINDERS, &val32); geometry[4] = val32; val32 = 0; nvlist_lookup_uint32(attrs, DM_NALTCYLINDERS, &val32); geometry[5] = val32; val32 = 0; /* This one is probably there only in x86 machines. */ nvlist_lookup_uint32(attrs, DM_NACTUALCYLINDERS, &val32); geometry[6] = val32; nvlist_free(attrs); return (0); }
static boolean_t sfunc_probe_id(ofmt_arg_t *ofmtarg, char *buf, uint_t bufsize) { ipmpstat_sfunc_arg_t *arg = ofmtarg->ofmt_cbarg; uint32_t probe_id; nvlist_t *nvl = arg->sa_data; if (nvlist_lookup_uint32(nvl, IPMP_PROBE_ID, &probe_id) != 0) return (sfunc_nvwarn("IPMP_PROBE_ID")); (void) snprintf(buf, bufsize, "%u", probe_id); return (B_TRUE); }
static int probe_event(sysevent_t *ev, void *arg) { nvlist_t *nvl; uint32_t state; uint32_t version; ipmpstat_probe_state_t *psp = arg; if (strcmp(sysevent_get_subclass_name(ev), ESC_IPMP_PROBE_STATE) != 0) return (0); if (sysevent_get_attr_list(ev, &nvl) != 0) { warn("sysevent_get_attr_list failed; dropping event"); return (0); } if (nvlist_lookup_uint32(nvl, IPMP_EVENT_VERSION, &version) != 0) { warn("dropped event with no IPMP_EVENT_VERSION\n"); goto out; } if (version != IPMP_EVENT_CUR_VERSION) { warn("dropped event with unsupported IPMP_EVENT_VERSION %d\n", version); goto out; } if (nvlist_lookup_uint32(nvl, IPMP_PROBE_STATE, &state) != 0) { warn("dropped event with no IPMP_PROBE_STATE\n"); goto out; } if (state == IPMP_PROBE_ACKED || state == IPMP_PROBE_LOST) ofmt_output(psp->ps_ofmt, psp->ps_ih, nvl); out: nvlist_free(nvl); return (0); }
/* * Given a interface name, return the kernel interface version. */ int fmd_agent_version(fmd_agent_hdl_t *hdl, const char *op, uint32_t *verp) { int err; err = nvlist_lookup_uint32(hdl->agent_ioc_versions, op, verp); if (err != 0) { errno = err; return (-1); } return (0); }
/*ARGSUSED*/ static int disk_temp_reading(topo_mod_t *mod, tnode_t *node, topo_version_t vers, nvlist_t *in, nvlist_t **out) { char *devid; uint32_t temp; dm_descriptor_t drive_descr = NULL; nvlist_t *drive_stats, *pargs, *nvl; int err; if (vers > TOPO_METH_DISK_TEMP_VERSION) return (topo_mod_seterrno(mod, ETOPO_METHOD_VERNEW)); if (nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &pargs) != 0 || nvlist_lookup_string(pargs, TOPO_IO_DEVID, &devid) != 0) { topo_mod_dprintf(mod, "Failed to lookup %s arg", TOPO_IO_DEVID); return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); } if ((drive_descr = dm_get_descriptor_by_name(DM_DRIVE, devid, &err)) == NULL) { topo_mod_dprintf(mod, "failed to get drive decriptor for %s", devid); return (topo_mod_seterrno(mod, EMOD_UNKNOWN)); } if ((drive_stats = dm_get_stats(drive_descr, DM_DRV_STAT_TEMPERATURE, &err)) == NULL || nvlist_lookup_uint32(drive_stats, DM_TEMPERATURE, &temp) != 0) { topo_mod_dprintf(mod, "failed to read disk temp for %s", devid); dm_free_descriptor(drive_descr); return (topo_mod_seterrno(mod, EMOD_UNKNOWN)); } dm_free_descriptor(drive_descr); if (topo_mod_nvalloc(mod, &nvl, NV_UNIQUE_NAME) != 0 || nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, TOPO_SENSOR_READING) != 0 || nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, TOPO_TYPE_DOUBLE) != 0 || nvlist_add_double(nvl, TOPO_PROP_VAL_VAL, (double)temp) != 0) { topo_mod_dprintf(mod, "Failed to allocate 'out' nvlist\n"); nvlist_free(nvl); return (topo_mod_seterrno(mod, EMOD_NOMEM)); } *out = nvl; return (0); }
uint32_t gmem_get_serd_filter_ratio(nvlist_t *nvl) { uint32_t filter_ratio = 0; uint32_t erpt_ratio; if (gmem.gm_filter_ratio == 0) { if (nvlist_lookup_uint32(nvl, GMEM_ERPT_PAYLOAD_FILTER_RATIO, &erpt_ratio) == 0) filter_ratio = erpt_ratio; } else filter_ratio = gmem.gm_filter_ratio; return (filter_ratio); }
/* ARGSUSED */ static int ipgpc_create_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags) { int rc; uint32_t stat; nvlist_t *nvlp; nvlp = *nvlpp; *nvlpp = NULL; /* nvlist should be NULL when this returns */ /* only one ipgpc action instance can be loaded at once */ if (ipgpc_action_exist) { nvlist_free(nvlp); return (EBUSY); } else { mutex_enter(&ipgpc_config_lock); if (ipgpc_action_exist) { nvlist_free(nvlp); mutex_exit(&ipgpc_config_lock); return (EBUSY); } /* check for action param IPP_ACTION_STATS_ENABLE */ if ((rc = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &stat)) != 0) { ipgpc_gather_stats = B_FALSE; /* disabled by default */ } else { ipgpc_gather_stats = (boolean_t)stat; } if ((rc = ipgpc_initialize(aid)) != 0) { ipgpc0dbg(("ipgpc_create_action: ipgpc_intialize " \ "error %d", rc)); ipgpc_destroy(IPP_DESTROY_REF); ipgpc_action_exist = B_FALSE; nvlist_free(nvlp); mutex_exit(&ipgpc_config_lock); return (rc); } ipgpc_action_exist = B_TRUE; nvlist_free(nvlp); mutex_exit(&ipgpc_config_lock); return (0); } }
static int ippctl_extract_flags( nvlist_t *nvlp, ipp_flags_t *valp) { int rc; /* * Look-up and remove the flags passed from libipp from the * nvlist. */ if ((rc = nvlist_lookup_uint32(nvlp, IPPCTL_FLAGS, (uint32_t *)valp)) != 0) return (rc); (void) nvlist_remove_all(nvlp, IPPCTL_FLAGS); return (0); }
int topo_fmri_compare(topo_hdl_t *thp, nvlist_t *f1, nvlist_t *f2, int *err) { uint32_t compare; char *scheme1, *scheme2; nvlist_t *in; nvlist_t *out = NULL; tnode_t *rnode; if (nvlist_lookup_string(f1, FM_FMRI_SCHEME, &scheme1) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_COMPARE, NULL)); if (nvlist_lookup_string(f2, FM_FMRI_SCHEME, &scheme2) != 0) return (set_error(thp, ETOPO_FMRI_MALFORM, err, TOPO_METH_COMPARE, NULL)); if (strcmp(scheme1, scheme2) != 0) return (0); if ((rnode = topo_hdl_root(thp, scheme1)) == NULL) return (set_error(thp, ETOPO_METHOD_NOTSUP, err, TOPO_METH_COMPARE, NULL)); if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0) return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_COMPARE, NULL)); if (nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_NV1, f1) != 0 || nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_NV2, f2) != 0) return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_COMPARE, in)); if (topo_method_invoke(rnode, TOPO_METH_COMPARE, TOPO_METH_COMPARE_VERSION, in, &out, err) < 0) return (set_error(thp, *err, err, TOPO_METH_COMPARE, in)); (void) nvlist_lookup_uint32(out, TOPO_METH_COMPARE_RET, &compare); nvlist_free(out); nvlist_free(in); return (compare); }