/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* This provides the basic mechanisms (str2nvl and nvl2str) for dealing with
* the service schema. The official version of a svc FMRI has the form:
*
* svc://[scope@][system-fqn]/service[:instance][@contract-id]
*
* Where 'service' is a slash-delimited list of names. Of these fields, the
* scope, constract-id, and system-fqn are rarely used, leaving the much more
* common form such as:
*
*
* Note that the SMF software typically uses a shorthard form, where the
* FMA FMRIs, we only support fully specified FMRIs.
*
* This module does not support enumeration, but implements methods for FMRI
* state (present, unusable, service state, and replaced).
*/
#include <fm/topo_mod.h>
#include <fm/fmd_fmri.h>
#include <topo_method.h>
#include <topo_subr.h>
#include <topo_prop.h>
#include <alloca.h>
#include <assert.h>
#include <svc.h>
#include <strings.h>
#include <libscf.h>
{ NULL }
};
topo_instance_t, void *, void *);
{ svc_enum, svc_release };
static int
{
switch (scf_error()) {
case SCF_ERROR_NO_MEMORY:
default:
}
}
static scf_handle_t *
{
return (hdl);
return (NULL);
}
if (scf_handle_bind(hdl) != 0) {
return (NULL);
}
return (hdl);
}
int
{
if (getenv("TOPOSVCDEBUG"))
if (version != SVC_VERSION)
return (-1);
}
return (0);
}
void
{
}
static tnode_t *
{
char *fixed;
int i, j, err;
/*
* the scf_{x}_to_fmri interfaces return short-hand svc-scheme FMRI's
* that look like:
*
* svc:/service[:instance]
*
* But all our other code assumes a proper svc-scheme FMRI, so we
* correct the fmri string before we try to convert it to an nvlist.
*
* The short-hand version is kept as the label and can be used when
* dealing with the SMF libraries and CLI's.
*/
return (NULL);
}
for (i = 0, j = 0; i < len; i++)
if (i == 5)
fixed[i] = '/';
else
fixed[i] = '\0';
return (NULL);
}
return (NULL);
}
return (NULL);
}
topo_strerror(err));
return (NULL);
}
return (tn);
}
/*ARGSUSED*/
static int
{
goto out;
goto out;
goto out;
goto out;
continue;
continue;
goto out;
}
goto out;
/* topo mod errno set */
goto out;
}
continue;
== NULL) {
goto out;
}
goto out;
== NULL) {
/* topo mod errno set */
goto out;
}
}
}
ret = 0;
out:
return (ret);
}
static void
{
}
static boolean_t
{
return (B_TRUE);
if (*str == '\0')
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
}
static int
{
char *search;
int err;
if (err != 0)
/*
* Private args to prop method are optional
*/
else
}
/*
* Lookup a topo node named svc:/svc_name[:svc_inst]
*/
}
}
}
err = 0;
return (err);
}
/*ARGSUSED*/
static int
{
char *service;
int err;
if (version > TOPO_METH_NVL2STR_VERSION)
/*
* Check for optional members.
*/
/*
* Get the service name.
*/
/*
* We make two passes through this code. The first time through we
* calculate the size of buffer that we'll need, and the second time
* through we fill it in.
*/
/*
* svc://[scope@][system-fqn]
*/
NULL, "://");
/* svc path */
if (*service == '\0')
/* [:instance][@contract-id] */
size = 0;
goto again;
}
/*
* Construct the nvlist to return as the result.
*/
}
}
return (0);
}
/*ARGSUSED*/
static int
{
if (version > TOPO_METH_STR2NVL_VERSION)
str += 6;
goto malformed;
if (*loc == '@') {
/* scope */
*loc = '\0';
if (!svc_component_valid(str)) {
*loc = '@';
goto malformed;
}
*loc = '@';
goto nomem;
}
*loc = '@';
goto malformed;
}
/* system-fqn */
*loc = '\0';
if (!svc_component_valid(str)) {
*loc = '/';
goto malformed;
}
str) != 0) {
*loc = '/';
goto nomem;
}
*loc = '/';
}
goto malformed;
*loc = '\0';
}
/* service name */
goto nomem;
}
/* instance */
goto malformed;
*loc = '\0';
str) != 0) {
*loc = '@';
goto nomem;
}
*loc = '@';
}
/* contract-id */
if (str[0] == '\0')
goto malformed;
str) != 0) {
goto nomem;
}
}
goto nomem;
return (0);
}
/*
* This common function is shared by all consumers (present, replaced,
* service state and unusable).
*
* svc_get_state succeeds
* Case with FMD_SERVICE_STATE_*
* ---------------------------- ------------------------
* svc name deleted UNKNOWN
* svc name not found UNKNOWN
* no fmri instance OK
* instance deleted UNKNOWN
* instance not found UNKNOWN
*
* If none of the above apply and this is a call from the "present"
* or "replaced" method (presence_only == B_TRUE) then
* svc_get_state returns FMD_SERVICE_STATE_OK.
*
* The "present" method maps a svc_get_state return of UNKNOWN to
* "not present" and a svc_get_state return of OK to "present".
*
* The "replaced" methods maps a return of UNKNOWN to FMD_OBJ_STATE_NOT_PRESENT
* and OK to FMD_OBJ_STATE_UNKNOWN.
*
* For the "service state" and "unusable" methods svc_get_state goes on
* to return the instance state as below, and the two methods map that
* result as in the last two columns of the following table:
*
* svc_get_state succeeds Service
* Instance state with FMD_SERVICE_STATE_* State Unusable
* -------------- ------------------------------- --------------- --------
* none OK OK
* uninitialized OK OK
* maintenance UNUSABLE UNUSABLE Yes
* offline OK OK
* disabled OK OK
* online OK OK
* degraded DEGRADED DEGRADED
* legacy_run OK (XXX can we see this?) OK
*
* Note that *only* "maintenance" state should map to an unusable service state
* or unusable status. That's because a service entering maintenance state
* is modelled as a defect fault diagnosis in FMA, but there is no
* corresponding isolation action from a response agent since the the service
* is already isolated by virtue of being in maintenance state. Any transition
* from maintenance state, even to offline, is considered a repair. If on
* repair fmd does not see the service usable again then the case hangs
* around in the "resolved but not all resources back online" state and
* further maintenance events for this service will not show up in fmd state
* because case duplicate checking code will find the old case.
*/
static int
int *ret)
{
char *state;
return (-1);
goto error;
goto error;
/*
* If we fail to get the service due to _DELETED or _NOT_FOUND, then we
* treat this as not present.
*/
goto out;
} else {
goto error;
}
}
goto out;
}
/*
* Again, check for _DELETED or _NOT_FOUND.
*/
goto out;
} else {
goto error;
}
}
/*
* For presence, we are done. Otherwise, we need to get the current
* state of the instance.
*/
if (presence_only) {
goto out;
}
goto error;
goto error;
goto error;
} else {
}
goto out;
retval = -1;
out:
return (retval);
}
/*ARGSUSED*/
static int
{
int state;
if (version > TOPO_METH_PRESENT_VERSION)
return (-1);
state != FMD_SERVICE_STATE_UNKNOWN) != 0) {
nvlist_free(*out);
}
return (0);
}
/*ARGSUSED*/
static int
{
int state;
return (-1);
FMD_OBJ_STATE_NOT_PRESENT : FMD_OBJ_STATE_UNKNOWN) != 0) {
nvlist_free(*out);
}
return (0);
}
/*ARGSUSED*/
static int
{
int state;
return (-1);
state) != 0) {
nvlist_free(*out);
}
return (0);
}
/*ARGSUSED*/
static int
{
int state;
return (-1);
(state == FMD_SERVICE_STATE_UNKNOWN ||
state == FMD_SERVICE_STATE_UNUSABLE)) != 0) {
nvlist_free(*out);
}
return (0);
}