4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <fm/fmd_fmri.h>
28 #include <fm/libtopo.h>
29 #include <fm/topo_mod.h>
31 #include <sys/fm/protocol.h>
45 fmd_fmri_nvl2str(nvlist_t
*nvl
, char *buf
, size_t buflen
)
52 if ((thp
= fmd_fmri_topo_hold(TOPO_VERSION
)) == NULL
)
53 return (fmd_fmri_set_errno(EINVAL
));
55 if (topo_fmri_nvl2str(thp
, nvl
, &str
, &err
) != 0) {
56 fmd_fmri_topo_rele(thp
);
57 return (fmd_fmri_set_errno(EINVAL
));
61 len
= snprintf(buf
, buflen
, "%s", str
);
65 topo_hdl_strfree(thp
, str
);
66 fmd_fmri_topo_rele(thp
);
73 fmd_fmri_present(nvlist_t
*nvl
)
79 if (nvlist_lookup_uint8(nvl
, FM_VERSION
, &version
) != 0 ||
80 version
> FM_SVC_SCHEME_VERSION
)
81 return (fmd_fmri_set_errno(EINVAL
));
83 if ((thp
= fmd_fmri_topo_hold(TOPO_VERSION
)) == NULL
)
84 return (fmd_fmri_set_errno(EINVAL
));
85 present
= topo_fmri_present(thp
, nvl
, &err
);
86 fmd_fmri_topo_rele(thp
);
92 fmd_fmri_replaced(nvlist_t
*nvl
)
98 if (nvlist_lookup_uint8(nvl
, FM_VERSION
, &version
) != 0 ||
99 version
> FM_SVC_SCHEME_VERSION
)
100 return (fmd_fmri_set_errno(EINVAL
));
102 if ((thp
= fmd_fmri_topo_hold(TOPO_VERSION
)) == NULL
)
103 return (fmd_fmri_set_errno(EINVAL
));
104 replaced
= topo_fmri_replaced(thp
, nvl
, &err
);
105 fmd_fmri_topo_rele(thp
);
111 fmd_fmri_service_state(nvlist_t
*nvl
)
114 int err
, service_state
;
117 if (nvlist_lookup_uint8(nvl
, FM_VERSION
, &version
) != 0 ||
118 version
> FM_DEV_SCHEME_VERSION
)
119 return (fmd_fmri_set_errno(EINVAL
));
121 if ((thp
= fmd_fmri_topo_hold(TOPO_VERSION
)) == NULL
)
122 return (fmd_fmri_set_errno(EINVAL
));
124 service_state
= topo_fmri_service_state(thp
, nvl
, &err
);
125 fmd_fmri_topo_rele(thp
);
128 return (FMD_SERVICE_STATE_UNKNOWN
);
130 return (service_state
);
135 fmd_fmri_unusable(nvlist_t
*nvl
)
141 if (nvlist_lookup_uint8(nvl
, FM_VERSION
, &version
) != 0 ||
142 version
> FM_SVC_SCHEME_VERSION
)
143 return (fmd_fmri_set_errno(EINVAL
));
145 if ((thp
= fmd_fmri_topo_hold(TOPO_VERSION
)) == NULL
)
146 return (fmd_fmri_set_errno(EINVAL
));
147 unusable
= topo_fmri_unusable(thp
, nvl
, &err
);
148 fmd_fmri_topo_rele(thp
);
150 return (unusable
== 1 ? 1 : 0);