diff options
author | Cheng Sean Ye <Sean.Ye@Sun.COM> | 2009-09-08 08:52:14 +0800 |
---|---|---|
committer | Cheng Sean Ye <Sean.Ye@Sun.COM> | 2009-09-08 08:52:14 +0800 |
commit | 9c94f155585ea35e938fea603bc227c685223abd (patch) | |
tree | 1d56aeabf73ef337b42b58a0ee06c5a3031fdfde | |
parent | 23294c7da48c2eb5222bccedbefb1e06cf5c4df3 (diff) | |
download | illumos-joyent-9c94f155585ea35e938fea603bc227c685223abd.tar.gz |
PSARC/2007/650 Product Serial Number for FMRI
6627041 Add a PSN nv-pair to the authority portion of the FMRI scheme
28 files changed, 462 insertions, 232 deletions
diff --git a/usr/src/cmd/fm/fmadm/common/faulty.c b/usr/src/cmd/fm/fmadm/common/faulty.c index d07e82e674..be8c98484e 100644 --- a/usr/src/cmd/fm/fmadm/common/faulty.c +++ b/usr/src/cmd/fm/fmadm/common/faulty.c @@ -195,6 +195,7 @@ typedef struct host_id { char *server; char *platform; char *domain; + char *product_sn; } hostid_t; typedef struct host_id_list { @@ -265,7 +266,8 @@ format_date(char *buf, size_t len, uint64_t sec) } static hostid_t * -find_hostid_in_list(char *platform, char *chassis, char *server, char *domain) +find_hostid_in_list(char *platform, char *chassis, char *server, char *domain, + char *product_sn) { hostid_t *rt = NULL; host_id_list_t *hostp; @@ -282,6 +284,8 @@ find_hostid_in_list(char *platform, char *chassis, char *server, char *domain) strcmp(hostp->hostid.server, server) == 0 && (chassis == NULL || hostp->hostid.chassis == NULL || strcmp(chassis, hostp->hostid.chassis) == 0) && + (product_sn == NULL || hostp->hostid.product_sn == NULL || + strcmp(product_sn, hostp->hostid.product_sn) == 0) && (domain == NULL || hostp->hostid.domain == NULL || strcmp(domain, hostp->hostid.domain) == 0)) { rt = &hostp->hostid; @@ -292,6 +296,8 @@ find_hostid_in_list(char *platform, char *chassis, char *server, char *domain) if (rt == NULL) { hostp = malloc(sizeof (host_id_list_t)); hostp->hostid.platform = strdup(platform); + hostp->hostid.product_sn = + product_sn ? strdup(product_sn) : NULL; hostp->hostid.server = strdup(server); hostp->hostid.chassis = chassis ? strdup(chassis) : NULL; hostp->hostid.domain = domain ? strdup(domain) : NULL; @@ -307,6 +313,7 @@ static hostid_t * find_hostid(nvlist_t *nvl) { char *platform = NULL, *chassis = NULL, *server = NULL, *domain = NULL; + char *product_sn = NULL; nvlist_t *auth, *fmri; hostid_t *rt = NULL; @@ -314,11 +321,14 @@ find_hostid(nvlist_t *nvl) nvlist_lookup_nvlist(fmri, FM_FMRI_AUTHORITY, &auth) == 0) { (void) nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &platform); + (void) nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, + &product_sn); (void) nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server); (void) nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &chassis); (void) nvlist_lookup_string(auth, FM_FMRI_AUTH_DOMAIN, &domain); - rt = find_hostid_in_list(platform, chassis, server, domain); + rt = find_hostid_in_list(platform, chassis, server, + domain, product_sn); } return (rt); } @@ -1441,8 +1451,10 @@ print_sup_record(status_record_t *srp, int opt_i, int full) srp->host->domain); (void) printf("\n%s %s", dgettext("FMD", "Platform :"), srp->host->platform); - (void) printf("\t%s %s\n\n", dgettext("FMD", "Chassis_id :"), + (void) printf("\t%s %s", dgettext("FMD", "Chassis_id :"), srp->host->chassis ? srp->host->chassis : ""); + (void) printf("\n%s %s\n\n", dgettext("FMD", "Product_sn :"), + srp->host->product_sn? srp->host->product_sn : ""); if (srp->class) print_name_list(srp->class, dgettext("FMD", "Fault class :"), NULL, 0, srp->class->pct, diff --git a/usr/src/cmd/fm/fmd/common/fmd.c b/usr/src/cmd/fm/fmd/common/fmd.c index ef58883699..e904c2c74d 100644 --- a/usr/src/cmd/fm/fmd/common/fmd.c +++ b/usr/src/cmd/fm/fmd/common/fmd.c @@ -72,6 +72,7 @@ const char _fmd_version[] = "1.2"; /* daemon version string */ static char _fmd_plat[MAXNAMELEN]; /* native platform string */ static char _fmd_isa[MAXNAMELEN]; /* native instruction set */ static struct utsname _fmd_uts; /* native uname(2) info */ +static char _fmd_psn[MAXNAMELEN]; /* product serial number */ static char _fmd_csn[MAXNAMELEN]; /* chassis serial number */ static char _fmd_prod[MAXNAMELEN]; /* product name string */ @@ -227,6 +228,7 @@ static const fmd_conf_formal_t _fmd_conf[] = { { "agent.path", &fmd_conf_path, _fmd_agent_path }, /* path for agents */ { "alloc_msecs", &fmd_conf_uint32, "10" }, /* msecs before alloc retry */ { "alloc_tries", &fmd_conf_uint32, "3" }, /* max # of alloc retries */ +{ "product_sn", &fmd_conf_string, _fmd_psn }, /* product serial number */ { "chassis", &fmd_conf_string, _fmd_csn }, /* chassis serial number */ { "ckpt.dir", &fmd_conf_string, "var/fm/fmd/ckpt" }, /* ckpt directory path */ { "ckpt.dirmode", &fmd_conf_int32, "0700" }, /* ckpt directory perm mode */ @@ -364,7 +366,7 @@ fmd_create(fmd_t *dp, const char *arg0, const char *root, const char *conf) { fmd_conf_path_t *pap; char file[PATH_MAX]; - const char *name; + const char *name, *psn, *csn; fmd_stat_t *sp; int i; @@ -383,10 +385,15 @@ fmd_create(fmd_t *dp, const char *arg0, const char *root, const char *conf) if ((shp = smbios_open(NULL, SMB_VERSION, 0, NULL)) != NULL) { if ((id = smbios_info_system(shp, &s1)) != SMB_ERR && - smbios_info_common(shp, id, &s2) != SMB_ERR) { + smbios_info_common(shp, id, &s2) != SMB_ERR) fmd_cleanup_auth_str(_fmd_prod, s2.smbi_product); - fmd_cleanup_auth_str(_fmd_csn, s2.smbi_serial); - } + + if ((psn = smbios_psn(shp)) != NULL) + fmd_cleanup_auth_str(_fmd_psn, psn); + + if ((csn = smbios_csn(shp)) != NULL) + fmd_cleanup_auth_str(_fmd_csn, csn); + smbios_close(shp); } else if ((rooth = di_init("/", DINFOPROP)) != DI_NODE_NIL && (promh = di_prom_init()) != DI_PROM_HANDLE_NIL) { diff --git a/usr/src/cmd/fm/fmd/common/fmd_protocol.c b/usr/src/cmd/fm/fmd/common/fmd_protocol.c index 54628816e5..0a477a35d1 100644 --- a/usr/src/cmd/fm/fmd/common/fmd_protocol.c +++ b/usr/src/cmd/fm/fmd/common/fmd_protocol.c @@ -60,6 +60,9 @@ fmd_protocol_authority(void) if (str != NULL) err |= nvlist_add_string(nvl, FM_FMRI_AUTH_PRODUCT, str); + if ((str = fmd_conf_getnzstr(fmd.d_conf, "product_sn")) != NULL) + err |= nvlist_add_string(nvl, FM_FMRI_AUTH_PRODUCT_SN, str); + if ((str = fmd_conf_getnzstr(fmd.d_conf, "chassis")) != NULL) err |= nvlist_add_string(nvl, FM_FMRI_AUTH_CHASSIS, str); diff --git a/usr/src/cmd/fm/schemes/hc/scheme.c b/usr/src/cmd/fm/schemes/hc/scheme.c index 42e1c46bfb..38f250a266 100644 --- a/usr/src/cmd/fm/schemes/hc/scheme.c +++ b/usr/src/cmd/fm/schemes/hc/scheme.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -141,6 +141,7 @@ auth_compare(nvlist_t *nvl1, nvlist_t *nvl2) { const char *names[] = { FM_FMRI_AUTH_PRODUCT, + FM_FMRI_AUTH_PRODUCT_SN, FM_FMRI_AUTH_CHASSIS, FM_FMRI_AUTH_SERVER, FM_FMRI_AUTH_DOMAIN, diff --git a/usr/src/common/smbios/smb_info.c b/usr/src/common/smbios/smb_info.c index 202c373e02..c374101a3b 100644 --- a/usr/src/common/smbios/smb_info.c +++ b/usr/src/common/smbios/smb_info.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -48,9 +48,12 @@ #include <sys/smbios_impl.h> -#ifndef _KERNEL +#ifdef _KERNEL +#include <sys/sunddi.h> +#else #include <fcntl.h> #include <unistd.h> +#include <string.h> #endif /* @@ -812,3 +815,100 @@ smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip) return (stp->smbst_hdr->smbh_hdl); } + +static boolean_t +smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr) +{ + const smb_struct_t *stp = shp->sh_structs; + smb_strtab_t s; + int i, j; + + for (i = 0; i < shp->sh_nstructs; i++, stp++) { + if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR) + continue; + + smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s)); + for (j = 0; j < s.smbtb_count; j++) + if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0) + return (B_TRUE); + } + + return (B_FALSE); +} + +static const char * +smb_serial_valid(const char *serial) +{ + char buf[MAXNAMELEN]; + int i = 0; + + if (serial == NULL) + return (NULL); + + (void) strlcpy(buf, serial, sizeof (buf)); + + while (buf[i] != '\0' && buf[i] == ' ') + i++; + + if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL || + strstr(buf, SMB_DEFAULT2) != NULL) + return (NULL); + + return (serial); +} + +/* + * Get chassis SN or product SN + */ +static int +smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp) +{ + const smb_struct_t *stp; + smbios_info_t s1, s3; + + if (psnp == NULL || csnp == NULL) + return (smb_set_errno(shp, ESMB_INVAL)); + + *psnp = *csnp = NULL; + + /* + * If SMBIOS meets Sun's PRMS requirements, retrieve product SN + * from type 1 structure, and chassis SN from type 3 structure. + * Otherwise return SN in type 1 structure as chassis SN. + */ + + /* Get type 1 SN */ + if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL || + smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR) + s1.smbi_serial = NULL; + + /* Get type 3 SN */ + if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL || + smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR) + s3.smbi_serial = NULL; + + if (smbios_has_oemstr(shp, SMB_PRMS1)) { + *psnp = smb_serial_valid(s1.smbi_serial); + *csnp = smb_serial_valid(s3.smbi_serial); + } else { + *csnp = smb_serial_valid(s1.smbi_serial); + } + + return (0); +} + +const char * +smbios_psn(smbios_hdl_t *shp) +{ + const char *psn, *csn; + + return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn); +} + +const char * +smbios_csn(smbios_hdl_t *shp) +{ + const char *psn, *csn; + + return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn); +} diff --git a/usr/src/lib/fm/libfmd_msg/common/fmd_msg.c b/usr/src/lib/fm/libfmd_msg/common/fmd_msg.c index 35ae8a4976..b41f3f1742 100644 --- a/usr/src/lib/fm/libfmd_msg/common/fmd_msg.c +++ b/usr/src/lib/fm/libfmd_msg/common/fmd_msg.c @@ -1150,7 +1150,7 @@ fmd_msg_gettext_locked(fmd_msg_hdl_t *h, char date[64]; char *uuid, *src_name, *src_vers; - char *platform, *server, *chassis; + char *platform, *server, *csn; assert(fmd_msg_lock_held(h)); bzero(items, sizeof (items)); @@ -1200,8 +1200,9 @@ fmd_msg_gettext_locked(fmd_msg_hdl_t *h, if (nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server) != 0) server = (char *)FMD_MSG_MISSING; - if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &chassis) != 0) - chassis = (char *)FMD_MSG_MISSING; + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &csn) != 0 && + nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn) != 0) + csn = (char *)FMD_MSG_MISSING; /* * Format the message once to get its length, allocate a buffer, and @@ -1209,7 +1210,7 @@ fmd_msg_gettext_locked(fmd_msg_hdl_t *h, */ len = snprintf(NULL, 0, format, code, items[FMD_MSG_ITEM_TYPE], items[FMD_MSG_ITEM_SEVERITY], - date, platform, chassis, server, src_name, src_vers, uuid, + date, platform, csn, server, src_name, src_vers, uuid, items[FMD_MSG_ITEM_DESC], items[FMD_MSG_ITEM_RESPONSE], items[FMD_MSG_ITEM_IMPACT], items[FMD_MSG_ITEM_ACTION]); @@ -1220,7 +1221,7 @@ fmd_msg_gettext_locked(fmd_msg_hdl_t *h, (void) snprintf(buf, len + 1, format, code, items[FMD_MSG_ITEM_TYPE], items[FMD_MSG_ITEM_SEVERITY], - date, platform, chassis, server, src_name, src_vers, uuid, + date, platform, csn, server, src_name, src_vers, uuid, items[FMD_MSG_ITEM_DESC], items[FMD_MSG_ITEM_RESPONSE], items[FMD_MSG_ITEM_IMPACT], items[FMD_MSG_ITEM_ACTION]); out: diff --git a/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.c b/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.c index 016c10e079..baa90276f0 100644 --- a/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.c +++ b/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.c @@ -70,6 +70,7 @@ main(int argc, char *argv[]) err |= nvlist_add_uint8(auth, FM_VERSION, FM_FMRI_AUTH_VERSION); err |= nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT, "product"); + err |= nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT_SN, "product_sn"); err |= nvlist_add_string(auth, FM_FMRI_AUTH_CHASSIS, "chassis"); err |= nvlist_add_string(auth, FM_FMRI_AUTH_DOMAIN, "domain"); err |= nvlist_add_string(auth, FM_FMRI_AUTH_SERVER, "server"); diff --git a/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.out b/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.out index fe4c4aa5ae..4ce3f79f87 100644 --- a/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.out +++ b/usr/src/lib/fm/libfmd_msg/common/fmd_msg_test.out @@ -46,7 +46,7 @@ code TEST-8000-08 item 4 = <<This entry tests variable expansion for event paylo code TEST-8000-08 item 5 = <<Variable expansion for arrays: index = 1>> code TEST-8000-08 item 6 = <<http://sun.com/msg/TEST-8000-08>> SUNW-MSG-ID: TEST-8000-08, TYPE: Defect, VER: 1, SEVERITY: Minor -PLATFORM: product, CSN: chassis, HOSTNAME: server +PLATFORM: product, CSN: product_sn, HOSTNAME: server SOURCE: fmd_msg_test, REV: 1.0 EVENT-ID: 12345678 DESC: This entry tests URL variable expansion - url = http://sun.com/msg/TEST-8000-08 @@ -55,7 +55,7 @@ IMPACT: This entry tests variable expansion for event payload members: uuid = 12 REC-ACTION: Variable expansion for arrays: index = 1 SUNW-MSG-ID: TEST-8000-08, TYPE: Defect, VER: 1, SEVERITY: Minor -PLATFORM: product, CSN: chassis, HOSTNAME: server +PLATFORM: product, CSN: product_sn, HOSTNAME: server SOURCE: fmd_msg_test, REV: 1.0 EVENT-ID: 12345678 DESC: This entry tests URL variable expansion - url = http://foo.bar.com/TEST-8000-08 @@ -87,7 +87,7 @@ code TEST-8000-08 item 4 = <<This entry tests variable expansion for event paylo code TEST-8000-08 item 5 = <<Variable expansion for arrays: index = 1>> code TEST-8000-08 item 6 = <<http://sun.com/msg/TEST-8000-08>> SUNW-MSG-ID: TEST-8000-08, TYPE: Defect, VER: 1, SEVERITY: Minor -PLATFORM: product, CSN: chassis, HOSTNAME: server +PLATFORM: product, CSN: product_sn, HOSTNAME: server SOURCE: fmd_msg_test, REV: 1.0 EVENT-ID: 12345678 DESC: This entry tests URL variable expansion - url = http://sun.com/msg/TEST-8000-08 @@ -96,7 +96,7 @@ IMPACT: This entry tests variable expansion for event payload members: uuid = 12 REC-ACTION: Variable expansion for arrays: index = 1 SUNW-MSG-ID: TEST-8000-08, TYPE: Defect, VER: 1, SEVERITY: Minor -PLATFORM: product, CSN: chassis, HOSTNAME: server +PLATFORM: product, CSN: product_sn, HOSTNAME: server SOURCE: fmd_msg_test, REV: 1.0 EVENT-ID: 12345678 DESC: This entry tests URL variable expansion - url = http://foo.bar.com/TEST-8000-08 diff --git a/usr/src/lib/fm/topo/libtopo/common/dev.c b/usr/src/lib/fm/topo/libtopo/common/dev.c index 0865b194c0..b87b287997 100644 --- a/usr/src/lib/fm/topo/libtopo/common/dev.c +++ b/usr/src/lib/fm/topo/libtopo/common/dev.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <limits.h> #include <strings.h> #include <string.h> @@ -131,16 +129,12 @@ static ssize_t fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) { nvlist_t *anvl = NULL; + nvpair_t *apair; uint8_t version; ssize_t size = 0; char *devid = NULL; char *devpath = NULL; - char *achas = NULL; - char *adom = NULL; - char *aprod = NULL; - char *asrvr = NULL; - char *ahost = NULL; - int more_auth = 0; + char *aname, *aval; int err; if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || @@ -162,54 +156,24 @@ fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) if (err != 0 || devpath == NULL) return (-1); - if (anvl != NULL) { - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_PRODUCT, &aprod); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_CHASSIS, &achas); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_DOMAIN, &adom); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_SERVER, &asrvr); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_HOST, &ahost); - if (aprod != NULL) - more_auth++; - if (achas != NULL) - more_auth++; - if (adom != NULL) - more_auth++; - if (asrvr != NULL) - more_auth++; - if (ahost != NULL) - more_auth++; - } /* dev:// */ topo_fmristr_build(&size, buf, buflen, FM_FMRI_SCHEME_DEV, NULL, "://"); /* authority, if any */ - if (aprod != NULL) - topo_fmristr_build(&size, - buf, buflen, aprod, FM_FMRI_AUTH_PRODUCT "=", - --more_auth > 0 ? "," : NULL); - if (achas != NULL) - topo_fmristr_build(&size, - buf, buflen, achas, FM_FMRI_AUTH_CHASSIS "=", - --more_auth > 0 ? "," : NULL); - if (adom != NULL) - topo_fmristr_build(&size, - buf, buflen, adom, FM_FMRI_AUTH_DOMAIN "=", - --more_auth > 0 ? "," : NULL); - if (asrvr != NULL) - topo_fmristr_build(&size, - buf, buflen, asrvr, FM_FMRI_AUTH_SERVER "=", - --more_auth > 0 ? "," : NULL); - if (ahost != NULL) - topo_fmristr_build(&size, - buf, buflen, ahost, FM_FMRI_AUTH_HOST "=", - NULL); + if (anvl != NULL) { + for (apair = nvlist_next_nvpair(anvl, NULL); + apair != NULL; apair = nvlist_next_nvpair(anvl, apair)) { + if (nvpair_type(apair) != DATA_TYPE_STRING || + nvpair_value_string(apair, &aval) != 0) + continue; + aname = nvpair_name(apair); + topo_fmristr_build(&size, buf, buflen, ":", NULL, NULL); + topo_fmristr_build(&size, buf, buflen, "=", + aname, aval); + } + } /* device-id part, topo_fmristr_build does nothing if devid is NULL */ topo_fmristr_build(&size, diff --git a/usr/src/lib/fm/topo/libtopo/common/hc.c b/usr/src/lib/fm/topo/libtopo/common/hc.c index c029084784..3d28ee9ad9 100644 --- a/usr/src/lib/fm/topo/libtopo/common/hc.c +++ b/usr/src/lib/fm/topo/libtopo/common/hc.c @@ -240,7 +240,7 @@ hc_prop_set(tnode_t *node, nvlist_t *auth) int err; char isa[MAXNAMELEN]; struct utsname uts; - char *prod, *csn, *server; + char *prod, *psn, *csn, *server; if (auth == NULL) return; @@ -261,6 +261,14 @@ hc_prop_set(tnode_t *node, nvlist_t *auth) FM_FMRI_AUTH_PRODUCT, TOPO_PROP_IMMUTABLE, prod, &err); } + if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT_SN, + &err) != 0) && (err != ETOPO_PROP_DEFD)) { + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &psn) + == 0) + (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, TOPO_PROP_IMMUTABLE, psn, + &err); + } if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err) != 0) && (err != ETOPO_PROP_DEFD)) { if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn) == 0) @@ -456,21 +464,17 @@ fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) nvlist_t **hcprs = NULL; nvlist_t *hcsp = NULL; nvlist_t *anvl = NULL; + nvpair_t *apair; nvlist_t *fnvl; uint8_t version; ssize_t size = 0; uint_t hcnprs; - char *achas = NULL; - char *adom = NULL; - char *aprod = NULL; - char *asrvr = NULL; - char *ahost = NULL; char *serial = NULL; char *part = NULL; char *root = NULL; char *rev = NULL; + char *aname, *aval; char *fname = NULL, *ftype = NULL; - int more_auth = 0; int err, i; if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || @@ -489,29 +493,6 @@ fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) if (err != 0 || hcprs == NULL) return (-1); - if (anvl != NULL) { - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_PRODUCT, &aprod); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_CHASSIS, &achas); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_DOMAIN, &adom); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_SERVER, &asrvr); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_HOST, &ahost); - if (aprod != NULL) - more_auth++; - if (achas != NULL) - more_auth++; - if (adom != NULL) - more_auth++; - if (asrvr != NULL) - more_auth++; - if (ahost != NULL) - more_auth++; - } - (void) nvlist_lookup_string(nvl, FM_FMRI_HC_SERIAL_ID, &serial); (void) nvlist_lookup_string(nvl, FM_FMRI_HC_PART, &part); (void) nvlist_lookup_string(nvl, FM_FMRI_HC_REVISION, &rev); @@ -520,21 +501,18 @@ fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) topo_fmristr_build(&size, buf, buflen, FM_FMRI_SCHEME_HC, NULL, "://"); /* authority, if any */ - if (aprod != NULL) - topo_fmristr_build(&size, - buf, buflen, aprod, ":" FM_FMRI_AUTH_PRODUCT "=", NULL); - if (achas != NULL) - topo_fmristr_build(&size, - buf, buflen, achas, ":" FM_FMRI_AUTH_CHASSIS "=", NULL); - if (adom != NULL) - topo_fmristr_build(&size, - buf, buflen, adom, ":" FM_FMRI_AUTH_DOMAIN "=", NULL); - if (asrvr != NULL) - topo_fmristr_build(&size, - buf, buflen, asrvr, ":" FM_FMRI_AUTH_SERVER "=", NULL); - if (ahost != NULL) - topo_fmristr_build(&size, - buf, buflen, ahost, ":" FM_FMRI_AUTH_HOST "=", NULL); + if (anvl != NULL) { + for (apair = nvlist_next_nvpair(anvl, NULL); + apair != NULL; apair = nvlist_next_nvpair(anvl, apair)) { + if (nvpair_type(apair) != DATA_TYPE_STRING || + nvpair_value_string(apair, &aval) != 0) + continue; + aname = nvpair_name(apair); + topo_fmristr_build(&size, buf, buflen, ":", NULL, NULL); + topo_fmristr_build(&size, buf, buflen, "=", + aname, aval); + } + } /* hardware-id part */ topo_fmristr_build(&size, diff --git a/usr/src/lib/fm/topo/libtopo/common/mod.c b/usr/src/lib/fm/topo/libtopo/common/mod.c index 4961739949..62b1232394 100644 --- a/usr/src/lib/fm/topo/libtopo/common/mod.c +++ b/usr/src/lib/fm/topo/libtopo/common/mod.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <limits.h> #include <strings.h> #include <unistd.h> @@ -262,15 +260,11 @@ static ssize_t fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) { nvlist_t *anvl = NULL; + nvpair_t *apair; uint8_t version; ssize_t size = 0; int32_t modid; - char *achas = NULL; - char *adom = NULL; - char *aprod = NULL; - char *asrvr = NULL; - char *ahost = NULL; - char *modname = NULL; + char *modname = NULL, *aname, *aval; char numbuf[MAXINTSTR]; int err; @@ -299,38 +293,22 @@ fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) if (err != 0) return (-1); - if (anvl != NULL) { - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_PRODUCT, &aprod); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_CHASSIS, &achas); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_DOMAIN, &adom); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_SERVER, &asrvr); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_HOST, &ahost); - } - /* mod:// */ topo_fmristr_build(&size, buf, buflen, FM_FMRI_SCHEME_MOD, NULL, "://"); /* authority, if any */ - if (aprod != NULL) - topo_fmristr_build(&size, buf, buflen, aprod, - ":" FM_FMRI_AUTH_PRODUCT "=", NULL); - if (achas != NULL) - topo_fmristr_build(&size, buf, buflen, achas, - ":" FM_FMRI_AUTH_CHASSIS "=", NULL); - if (adom != NULL) - topo_fmristr_build(&size, buf, buflen, adom, - ":" FM_FMRI_AUTH_DOMAIN "=", NULL); - if (asrvr != NULL) - topo_fmristr_build(&size, buf, buflen, asrvr, - ":" FM_FMRI_AUTH_SERVER "=", NULL); - if (ahost != NULL) - topo_fmristr_build(&size, buf, buflen, ahost, - ":" FM_FMRI_AUTH_HOST "=", NULL); + if (anvl != NULL) { + for (apair = nvlist_next_nvpair(anvl, NULL); + apair != NULL; apair = nvlist_next_nvpair(anvl, apair)) { + if (nvpair_type(apair) != DATA_TYPE_STRING || + nvpair_value_string(apair, &aval) != 0) + continue; + aname = nvpair_name(apair); + topo_fmristr_build(&size, buf, buflen, ":", NULL, NULL); + topo_fmristr_build(&size, buf, buflen, "=", + aname, aval); + } + } /* module parts */ topo_fmristr_build(&size, buf, buflen, modname, diff --git a/usr/src/lib/fm/topo/libtopo/common/pkg.c b/usr/src/lib/fm/topo/libtopo/common/pkg.c index e952907f59..4cf1eddda0 100644 --- a/usr/src/lib/fm/topo/libtopo/common/pkg.c +++ b/usr/src/lib/fm/topo/libtopo/common/pkg.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <limits.h> #include <strings.h> #include <string.h> @@ -248,14 +246,10 @@ static ssize_t fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) { nvlist_t *anvl = NULL; + nvpair_t *apair; uint8_t version; ssize_t size = 0; - char *pkgname = NULL; - char *achas = NULL; - char *adom = NULL; - char *aprod = NULL; - char *asrvr = NULL; - char *ahost = NULL; + char *pkgname = NULL, *aname, *aval; int err; if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || @@ -276,38 +270,22 @@ fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) if (err != 0 || pkgname == NULL) return (-1); - if (anvl != NULL) { - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_PRODUCT, &aprod); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_CHASSIS, &achas); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_DOMAIN, &adom); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_SERVER, &asrvr); - (void) nvlist_lookup_string(anvl, - FM_FMRI_AUTH_HOST, &ahost); - } - /* pkg:// */ topo_fmristr_build(&size, buf, buflen, FM_FMRI_SCHEME_PKG, NULL, "://"); /* authority, if any */ - if (aprod != NULL) - topo_fmristr_build(&size, buf, buflen, aprod, - FM_FMRI_AUTH_PRODUCT "=", NULL); - if (achas != NULL) - topo_fmristr_build(&size, buf, buflen, achas, - FM_FMRI_AUTH_CHASSIS "=", NULL); - if (adom != NULL) - topo_fmristr_build(&size, buf, buflen, adom, - FM_FMRI_AUTH_DOMAIN "=", NULL); - if (asrvr != NULL) - topo_fmristr_build(&size, buf, buflen, asrvr, - FM_FMRI_AUTH_SERVER "=", NULL); - if (ahost != NULL) - topo_fmristr_build(&size, buf, buflen, ahost, - FM_FMRI_AUTH_HOST "=", NULL); + if (anvl != NULL) { + for (apair = nvlist_next_nvpair(anvl, NULL); + apair != NULL; apair = nvlist_next_nvpair(anvl, apair)) { + if (nvpair_type(apair) != DATA_TYPE_STRING || + nvpair_value_string(apair, &aval) != 0) + continue; + aname = nvpair_name(apair); + topo_fmristr_build(&size, buf, buflen, ":", NULL, NULL); + topo_fmristr_build(&size, buf, buflen, "=", + aname, aval); + } + } /* pkg-name part */ topo_fmristr_build(&size, buf, buflen, pkgname, "/", NULL); diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_mod.c b/usr/src/lib/fm/topo/libtopo/common/topo_mod.c index b2c85ffe4d..69d11b140f 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_mod.c +++ b/usr/src/lib/fm/topo/libtopo/common/topo_mod.c @@ -90,6 +90,7 @@ #include <alloca.h> #include <unistd.h> #include <stdio.h> +#include <ctype.h> #include <sys/param.h> #include <sys/utsname.h> #include <sys/smbios.h> @@ -704,27 +705,33 @@ topo_mod_server(topo_mod_t *mod) } static char * +topo_mod_psn(topo_mod_t *mod) +{ + smbios_hdl_t *shp; + const char *psn; + + if ((shp = topo_mod_smbios(mod)) == NULL || + (psn = smbios_psn(shp)) == NULL) + return (NULL); + + return (topo_cleanup_auth_str(mod->tm_hdl, psn)); +} + +static char * topo_mod_csn(topo_mod_t *mod) { char csn[MAXNAMELEN]; + smbios_hdl_t *shp; di_prom_handle_t promh = DI_PROM_HANDLE_NIL; di_node_t rooth = DI_NODE_NIL; - char *bufp; - smbios_hdl_t *shp; - smbios_system_t s1; - smbios_info_t s2; - id_t id; + const char *bufp; if ((shp = topo_mod_smbios(mod)) != NULL) { - if ((id = smbios_info_system(shp, &s1)) != SMB_ERR && - smbios_info_common(shp, id, &s2) != SMB_ERR) { - (void) strlcpy(csn, s2.smbi_serial, MAXNAMELEN); - } - - if (strcmp(csn, SMB_DEFAULT1) == 0 || - strcmp(csn, SMB_DEFAULT2) == 0) + bufp = smbios_csn(shp); + if (bufp != NULL) + (void) strlcpy(csn, bufp, MAXNAMELEN); + else return (NULL); - } else if ((rooth = topo_mod_devinfo(mod)) != DI_NODE_NIL && (promh = topo_mod_prominfo(mod)) != DI_PROM_HANDLE_NIL) { if (di_prom_prop_lookup_bytes(promh, rooth, "chassis-sn", @@ -737,7 +744,6 @@ topo_mod_csn(topo_mod_t *mod) return (NULL); } - return (topo_cleanup_auth_str(mod->tm_hdl, csn)); } @@ -747,6 +753,7 @@ topo_mod_auth(topo_mod_t *mod, tnode_t *pnode) int err; char *prod = NULL; char *csn = NULL; + char *psn = NULL; char *server = NULL; nvlist_t *auth; @@ -758,6 +765,8 @@ topo_mod_auth(topo_mod_t *mod, tnode_t *pnode) (void) topo_prop_get_string(pnode, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &prod, &err); (void) topo_prop_get_string(pnode, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &psn, &err); + (void) topo_prop_get_string(pnode, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &csn, &err); (void) topo_prop_get_string(pnode, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &server, &err); @@ -769,6 +778,8 @@ topo_mod_auth(topo_mod_t *mod, tnode_t *pnode) prod = topo_mod_product(mod); if (csn == NULL) csn = topo_mod_csn(mod); + if (psn == NULL) + psn = topo_mod_psn(mod); if (server == NULL) { server = topo_mod_server(mod); } @@ -776,7 +787,7 @@ topo_mod_auth(topo_mod_t *mod, tnode_t *pnode) /* * No luck, return NULL */ - if (!prod && !server && !csn) { + if (!prod && !server && !csn && !psn) { nvlist_free(auth); return (NULL); } @@ -786,6 +797,10 @@ topo_mod_auth(topo_mod_t *mod, tnode_t *pnode) err |= nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT, prod); topo_mod_strfree(mod, prod); } + if (psn != NULL) { + err |= nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT_SN, psn); + topo_mod_strfree(mod, psn); + } if (server != NULL) { err |= nvlist_add_string(auth, FM_FMRI_AUTH_SERVER, server); topo_mod_strfree(mod, server); diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_node.c b/usr/src/lib/fm/topo/libtopo/common/topo_node.c index a612f66211..ab720c1755 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_node.c +++ b/usr/src/lib/fm/topo/libtopo/common/topo_node.c @@ -516,6 +516,8 @@ topo_node_bind(topo_mod_t *mod, tnode_t *pnode, const char *name, (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); @@ -648,6 +650,8 @@ topo_node_facbind(topo_mod_t *mod, tnode_t *pnode, const char *name, (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_tree.h b/usr/src/lib/fm/topo/libtopo/common/topo_tree.h index b5c6a3c00e..d43b7f0f59 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_tree.h +++ b/usr/src/lib/fm/topo/libtopo/common/topo_tree.h @@ -125,8 +125,6 @@ struct topo_hdl { }; #define TOPO_UUID_SIZE 37 /* libuuid limit + 1 */ -#define SMB_DEFAULT1 "To Be Filled By O.E.M." -#define SMB_DEFAULT2 "Not Available At This Time" extern ttree_t *topo_tree_create(topo_hdl_t *, topo_mod_t *, const char *); extern void topo_tree_destroy(ttree_t *); diff --git a/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c b/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c index 96df0fff88..12904761ee 100644 --- a/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c +++ b/usr/src/lib/fm/topo/modules/common/hostbridge/hostbridge.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <string.h> #include <fm/topo_mod.h> #include <fm/topo_hc.h> @@ -222,6 +220,8 @@ hb_tnode_create(topo_mod_t *mod, tnode_t *parent, (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/fm/topo/modules/common/xfp/xfp.c b/usr/src/lib/fm/topo/modules/common/xfp/xfp.c index af066e01ed..2ee8944476 100644 --- a/usr/src/lib/fm/topo/modules/common/xfp/xfp.c +++ b/usr/src/lib/fm/topo/modules/common/xfp/xfp.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <string.h> #include <fm/topo_mod.h> #include <fm/topo_hc.h> @@ -119,6 +117,8 @@ xfp_tnode_create(topo_mod_t *mod, tnode_t *parent, (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/fm/topo/modules/sun4v/chip/chip_sun4v.c b/usr/src/lib/fm/topo/modules/sun4v/chip/chip_sun4v.c index 63065c80e8..ffcd6071ef 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/chip/chip_sun4v.c +++ b/usr/src/lib/fm/topo/modules/sun4v/chip/chip_sun4v.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -126,7 +126,7 @@ chip_tnode_create(topo_mod_t *mod, tnode_t *parent, int err; nvlist_t *fmri; tnode_t *ntn; - char *prod = NULL, *csn = NULL, *server = NULL; + char *prod = NULL, *psn = NULL, *csn = NULL, *server = NULL; nvlist_t *auth = NULL; if (topo_mod_nvalloc(mod, &auth, NV_UNIQUE_NAME) == 0) { @@ -137,6 +137,12 @@ chip_tnode_create(topo_mod_t *mod, tnode_t *parent, topo_mod_strfree(mod, prod); } if (topo_prop_get_string(parent, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &psn, &err) == 0) { + (void) nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT_SN, + psn); + topo_mod_strfree(mod, psn); + } + if (topo_prop_get_string(parent, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &server, &err) == 0) { (void) nvlist_add_string(auth, FM_FMRI_AUTH_SERVER, server); @@ -178,6 +184,8 @@ chip_tnode_create(topo_mod_t *mod, tnode_t *parent, (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/fm/topo/modules/sun4v/cpuboard/cpuboard.c b/usr/src/lib/fm/topo/modules/sun4v/cpuboard/cpuboard.c index 0fc5ade004..fc9ab65aa6 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/cpuboard/cpuboard.c +++ b/usr/src/lib/fm/topo/modules/sun4v/cpuboard/cpuboard.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -283,6 +283,8 @@ cpuboard_tnode_create(topo_mod_t *mod, tnode_t *parent, (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/fm/topo/modules/sun4v/dimm/dimm_sun4v.c b/usr/src/lib/fm/topo/modules/sun4v/dimm/dimm_sun4v.c index c05299edd1..dfd8dbfe43 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/dimm/dimm_sun4v.c +++ b/usr/src/lib/fm/topo/modules/sun4v/dimm/dimm_sun4v.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -150,6 +150,8 @@ mem_tnode_create(topo_mod_t *mod, tnode_t *parent, (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/fm/topo/modules/sun4v/motherboard/motherboard.c b/usr/src/lib/fm/topo/modules/sun4v/motherboard/motherboard.c index d2c0cd5a35..1e505bd414 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/motherboard/motherboard.c +++ b/usr/src/lib/fm/topo/modules/sun4v/motherboard/motherboard.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -117,7 +117,8 @@ mb_topo_free(void *data, size_t size) } static int -mb_get_pri_info(topo_mod_t *mod, char **serialp, char **partp, char **csnp) +mb_get_pri_info(topo_mod_t *mod, char **serialp, char **partp, char **csnp, + char **psnp) { char isa[MAXNAMELEN]; md_t *mdp; @@ -126,7 +127,7 @@ mb_get_pri_info(topo_mod_t *mod, char **serialp, char **partp, char **csnp) ssize_t bufsize = 0; int nfrus, num_nodes, i; char *pstr = NULL; - char *sn, *pn, *dn, *csn; + char *sn, *pn, *dn, *csn, *psn; uint32_t type = 0; ldom_hdl_t *lhp; @@ -188,6 +189,9 @@ mb_get_pri_info(topo_mod_t *mod, char **serialp, char **partp, char **csnp) return (-1); } topo_mod_dprintf(mod, "nfrus=%d\n", nfrus); + + sn = pn = dn = psn = csn = NULL; + for (i = 0; i < nfrus; i++) { if (md_get_prop_str(mdp, listp[i], "type", &pstr) == 0) { /* systemboard/motherboard component */ @@ -201,6 +205,10 @@ mb_get_pri_info(topo_mod_t *mod, char **serialp, char **partp, char **csnp) if (md_get_prop_str(mdp, listp[i], "dash_number", &dn) < 0) dn = NULL; + } else if (strcmp("product", pstr) == 0) { + if (md_get_prop_str(mdp, listp[i], + "serial_number", &psn) < 0) + psn = NULL; } } /* redefined access method for chassis serial number */ @@ -222,6 +230,7 @@ mb_get_pri_info(topo_mod_t *mod, char **serialp, char **partp, char **csnp) mb_topo_free(pstr, i); *csnp = topo_mod_strdup(mod, csn); + *psnp = topo_mod_strdup(mod, psn); mb_topo_free(listp, sizeof (mde_cookie_t) * num_nodes); mb_topo_free(bufp, (size_t)bufsize); @@ -237,7 +246,7 @@ mb_prop_set(tnode_t *node, nvlist_t *auth) int err; char isa[MAXNAMELEN]; struct utsname uts; - char *prod, *csn, *server; + char *prod, *psn, *csn, *server; if ((topo_pgroup_create(node, &mb_auth_pgroup, &err) != 0) && (err != ETOPO_PROP_DEFD)) @@ -246,6 +255,9 @@ mb_prop_set(tnode_t *node, nvlist_t *auth) if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &prod) == 0) (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, TOPO_PROP_IMMUTABLE, prod, &err); + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &psn) == 0) + (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, TOPO_PROP_IMMUTABLE, psn, &err); if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn) == 0) (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, TOPO_PROP_IMMUTABLE, csn, &err); @@ -272,11 +284,14 @@ mb_tnode_create(topo_mod_t *mod, tnode_t *parent, nvlist_t *fmri; tnode_t *ntn; char *serial = NULL, *part = NULL; - char *csn = NULL, *pstr = NULL; + char *psn = NULL, *csn = NULL, *pstr = NULL; nvlist_t *auth = topo_mod_auth(mod, parent); - /* Get Chassis ID, MB Serial Number and Part Number from PRI */ - (void) mb_get_pri_info(mod, &serial, &part, &csn); + /* + * Get Product Serial Number, Chassis ID, MB Serial Number and + * Part Number from PRI. + */ + (void) mb_get_pri_info(mod, &serial, &part, &csn, &psn); if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &pstr) != 0 && csn != NULL) { @@ -288,12 +303,24 @@ mb_tnode_create(topo_mod_t *mod, tnode_t *parent, } } + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &pstr) != 0 && + psn != NULL) { + if (nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT_SN, psn) + != 0) { + topo_mod_dprintf(mod, + "failed to add product-sn to auth"); + nvlist_free(auth); + return (NULL); + } + } + fmri = topo_mod_hcfmri(mod, NULL, FM_HC_SCHEME_VERSION, name, i, NULL, auth, part, NULL, serial); topo_mod_strfree(mod, serial); topo_mod_strfree(mod, part); topo_mod_strfree(mod, csn); + topo_mod_strfree(mod, psn); if (fmri == NULL) { topo_mod_dprintf(mod, diff --git a/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_impl.h b/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_impl.h index 3ad57da28a..b42f55f6eb 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_impl.h +++ b/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_impl.h @@ -67,6 +67,7 @@ extern "C" { #define MD_STR_PART_NUMBER "part_number" /* FWARC/2008/300 */ #define MD_STR_PATH "path" #define MD_STR_PLATFORM "platform" +#define MD_STR_PRODUCT "product" /* FWARC/2009/390 */ #define MD_STR_REVISION_NUMBER "rev_number" /* FWARC/2008/300 */ #define MD_STR_SERIAL_NUMBER "serial_number" /* FWARC/2008/300 */ #define MD_STR_TOPO_HC_NAME "topo-hc-name" /* FWARC/2008/300 */ @@ -144,6 +145,7 @@ void pi_walker_fini(topo_mod_t *); int pi_find_mdenodes(topo_mod_t *, md_t *, mde_cookie_t, char *, char *, mde_cookie_t **, size_t *); int pi_skip_node(topo_mod_t *, md_t *, mde_cookie_t); +char *pi_get_productsn(topo_mod_t *, md_t *, mde_cookie_t); char *pi_get_chassisid(topo_mod_t *, md_t *, mde_cookie_t); char *pi_get_topo_hc_name(topo_mod_t *, md_t *, mde_cookie_t); int pi_get_instance(topo_mod_t *, md_t *, mde_cookie_t, topo_instance_t *); diff --git a/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_subr.c b/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_subr.c index 9c3221ba6f..eee1ad5a57 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_subr.c +++ b/usr/src/lib/fm/topo/modules/sun4v/sun4vpi/pi_subr.c @@ -143,6 +143,87 @@ pi_skip_node(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node) return (0); } +/* + * Get the product serial number (the ID as far as the topo authority is + * concerned) either from the current node, if it is of type 'product', or + * search for a product node in the PRI. + * + * The string must be freed with topo_mod_strfree() + */ +char * +pi_get_productsn(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node) +{ + int result; + int idx; + int num_nodes; + char *id = NULL; + char *type; + size_t size; + mde_cookie_t *nodes = NULL; + + topo_mod_dprintf(mod, "pi_get_productsn: enter\n"); + + result = md_get_prop_str(mdp, mde_node, MD_STR_TYPE, &type); + if (result == 0 && strcmp(type, MD_STR_PRODUCT) == 0) { + /* + * This is a product node. We need only search for the serial + * number property on this node to return the ID. + */ + result = md_get_prop_str(mdp, mde_node, MD_STR_SERIAL_NUMBER, + &id); + if (result != 0 || id == NULL || strlen(id) == 0) + return (NULL); + + topo_mod_dprintf(mod, "pi_get_productsn: product-sn = %s\n", + id); + return (topo_mod_strdup(mod, id)); + } + + /* + * Search the PRI for nodes of type MD_STR_COMPONENT and find the + * first element with type of MD_STR_PRODUCT. This node + * will contain the MD_STR_SERIAL_NUMBER property to use as the + * product-sn. + */ + num_nodes = pi_find_mdenodes(mod, mdp, MDE_INVAL_ELEM_COOKIE, + MD_STR_COMPONENT, MD_STR_FWD, &nodes, &size); + if (num_nodes <= 0 || nodes == NULL) { + /* We did not find any component nodes */ + return (NULL); + } + topo_mod_dprintf(mod, "pi_get_productsn: found %d %s nodes\n", + num_nodes, MD_STR_COMPONENT); + + idx = 0; + while (id == NULL && idx < num_nodes) { + result = md_get_prop_str(mdp, nodes[idx], MD_STR_TYPE, &type); + if (result == 0 && strcmp(type, MD_STR_PRODUCT) == 0) { + /* + * This is a product node. Get the serial number + * property from the node. + */ + result = md_get_prop_str(mdp, nodes[idx], + MD_STR_SERIAL_NUMBER, &id); + if (result != 0) + topo_mod_dprintf(mod, "pi_get_productsn: " + "failed to read %s from node_0x%llx\n", + MD_STR_SERIAL_NUMBER, + (uint64_t)nodes[idx]); + } + /* Search the next node, if necessary */ + idx++; + } + topo_mod_free(mod, nodes, size); + + /* Everything is freed up and it's time to return the product-sn */ + if (result != 0 || id == NULL || strlen(id) == 0) { + return (NULL); + } + topo_mod_dprintf(mod, "pi_get_productsn: product-sn %s\n", id); + + return (topo_mod_strdup(mod, id)); +} + /* * Get the chassis serial number (the ID as far as the topo authority is @@ -629,6 +710,7 @@ pi_set_auth(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, nvlist_t *auth; char *val = NULL; char *prod = NULL; + char *psn = NULL; char *csn = NULL; char *server = NULL; @@ -653,6 +735,8 @@ pi_set_auth(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, * Set the authority data, inheriting it if possible, but creating it * if necessary. */ + + /* product-id */ result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { @@ -699,6 +783,54 @@ pi_set_auth(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, } } + /* product-sn */ + result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + if (result != 0 && err != ETOPO_PROP_DEFD) { + val = NULL; + result = nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, + &val); + if (result != 0 || val == NULL) { + /* + * No product-sn information in the parent node or auth + * list. Find the product-sn information in the PRI. + */ + psn = pi_get_productsn(mod, mdp, mde_node); + if (psn == NULL) { + topo_mod_dprintf(mod, "pi_set_auth: psn " + "name not found for node_0x%llx\n", + (uint64_t)mde_node); + } + } else { + /* + * Dup the string. If we cannot find it in the auth + * nvlist we will need to free it, so this lets us + * have a single code path. + */ + psn = topo_mod_strdup(mod, val); + } + + /* + * We continue even if the product information is not available + * to enumerate as much as possible. + */ + if (psn != NULL) { + result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, TOPO_PROP_IMMUTABLE, psn, + &err); + if (result != 0) { + /* Preserve the error and continue */ + topo_mod_seterrno(mod, err); + topo_mod_dprintf(mod, "pi_set_auth: failed to " + "set property %s (%d) : %s\n", + FM_FMRI_AUTH_PRODUCT_SN, err, + topo_strerror(err)); + } + topo_mod_strfree(mod, psn); + } + } + + /* chassis-id */ result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { @@ -745,6 +877,7 @@ pi_set_auth(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, } } + /* server-id */ result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { diff --git a/usr/src/lib/fm/topo/modules/sun4v/xaui/xaui.c b/usr/src/lib/fm/topo/modules/sun4v/xaui/xaui.c index b54e5357d1..04e0f1b1c6 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/xaui/xaui.c +++ b/usr/src/lib/fm/topo/modules/sun4v/xaui/xaui.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <string.h> #include <fm/topo_mod.h> #include <fm/topo_hc.h> @@ -121,6 +119,8 @@ xaui_tnode_create(topo_mod_t *mod, tnode_t *parent, (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/fm/topo/modules/sun4v/zambezi/zambezi.c b/usr/src/lib/fm/topo/modules/sun4v/zambezi/zambezi.c index 73f077a4e5..3fe6ff3049 100644 --- a/usr/src/lib/fm/topo/modules/sun4v/zambezi/zambezi.c +++ b/usr/src/lib/fm/topo/modules/sun4v/zambezi/zambezi.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <string.h> #include <fm/topo_mod.h> #include <fm/topo_hc.h> @@ -125,6 +123,8 @@ zam_tnode_create(topo_mod_t *mod, tnode_t *parent, (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, &err); + (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); diff --git a/usr/src/lib/libsmbios/common/mapfile-vers b/usr/src/lib/libsmbios/common/mapfile-vers index ea6ac86f6e..a784236eb1 100644 --- a/usr/src/lib/libsmbios/common/mapfile-vers +++ b/usr/src/lib/libsmbios/common/mapfile-vers @@ -66,6 +66,7 @@ SUNWprivate_1.1 { smbios_chassis_type_desc; smbios_checksum; smbios_close; + smbios_csn; smbios_errmsg; smbios_errno; smbios_evlog_flag_desc; @@ -114,6 +115,7 @@ SUNWprivate_1.1 { smbios_processor_status_desc; smbios_processor_type_desc; smbios_processor_upgrade_desc; + smbios_psn; smbios_slot_ch1_desc; smbios_slot_ch1_name; smbios_slot_ch2_desc; diff --git a/usr/src/uts/common/sys/fm/protocol.h b/usr/src/uts/common/sys/fm/protocol.h index 767fb07d81..bcd3850816 100644 --- a/usr/src/uts/common/sys/fm/protocol.h +++ b/usr/src/uts/common/sys/fm/protocol.h @@ -170,6 +170,7 @@ extern "C" { /* FMRI authority-type member names */ #define FM_FMRI_AUTH_CHASSIS "chassis-id" +#define FM_FMRI_AUTH_PRODUCT_SN "product-sn" #define FM_FMRI_AUTH_PRODUCT "product-id" #define FM_FMRI_AUTH_DOMAIN "domain-id" #define FM_FMRI_AUTH_SERVER "server-id" diff --git a/usr/src/uts/common/sys/smbios.h b/usr/src/uts/common/sys/smbios.h index 3bb4f3eeba..187ec2c63f 100644 --- a/usr/src/uts/common/sys/smbios.h +++ b/usr/src/uts/common/sys/smbios.h @@ -20,7 +20,7 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -40,8 +40,6 @@ #ifndef _SYS_SMBIOS_H #define _SYS_SMBIOS_H -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> #ifdef __cplusplus @@ -131,6 +129,18 @@ typedef struct smbios_entry { #define SMB_TYPE_OEM_HI 256 /* end of OEM-specific type range */ /* + * OEM string indicating "Platform Resource Management Specification" + * compliance. + */ +#define SMB_PRMS1 "SUNW-PRMS-1" + +/* + * Some default values set by BIOS vendor + */ +#define SMB_DEFAULT1 "To Be Filled By O.E.M." +#define SMB_DEFAULT2 "Not Available" + +/* * SMBIOS Common Information. These structures do not correspond to anything * in the SMBIOS specification, but allow library clients to more easily read * information that is frequently encoded into the various SMBIOS structures. @@ -1137,6 +1147,9 @@ extern id_t smbios_info_hwsec(smbios_hdl_t *, smbios_hwsec_t *); extern id_t smbios_info_boot(smbios_hdl_t *, smbios_boot_t *); extern id_t smbios_info_ipmi(smbios_hdl_t *, smbios_ipmi_t *); +extern const char *smbios_psn(smbios_hdl_t *); +extern const char *smbios_csn(smbios_hdl_t *); + #ifndef _KERNEL /* * The smbios_*_desc() and smbios_*_name() interfaces can be used for utilities |