svc.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A * This provides the basic mechanisms (str2nvl and nvl2str) for dealing with 2N/A * the service schema. The official version of a svc FMRI has the form: 2N/A * svc://[scope@][system-fqn]/service[:instance][@contract-id] 2N/A * Where 'service' is a slash-delimited list of names. Of these fields, the 2N/A * scope, constract-id, and system-fqn are rarely used, leaving the much more 2N/A * common form such as: 2N/A * Note that the SMF software typically uses a shorthard form, where the 2N/A * authority is elided (svc:/network/ssh:default). As this module deals with 2N/A * FMA FMRIs, we only support fully specified FMRIs. 2N/A * This module does not support enumeration, but implements methods for FMRI 2N/A * state (service state, and presence_state). 2N/A * the scf_{x}_to_fmri interfaces return short-hand svc-scheme FMRI's 2N/A * svc:/service[:instance] 2N/A * But all our other code assumes a proper svc-scheme FMRI, so we 2N/A * correct the fmri string before we try to convert it to an nvlist. 2N/A * The short-hand version is kept as the label and can be used when 2N/A * dealing with the SMF libraries and CLI's. 2N/A for (i = 0, j = 0; i <
len; i++)
2N/A /* topo mod errno set */ 2N/A /* topo mod errno set */ 2N/A * Private args to prop method are optional 2N/A * Lookup a topo node named svc:/svc_name[:svc_inst] 2N/A * Check for optional members. 2N/A * Get the service name. 2N/A * We make two passes through this code. The first time through we 2N/A * calculate the size of buffer that we'll need, and the second time 2N/A * through we fill it in. 2N/A * svc://[scope@][system-fqn] 2N/A /* [:instance][@contract-id] */ 2N/A * Construct the nvlist to return as the result. 2N/A * This common function is shared by all consumers (presence_state 2N/A * and service state). 2N/A * svc_get_state succeeds 2N/A * Case with FMD_SERVICE_STATE_* 2N/A * ---------------------------- ------------------------ 2N/A * svc name deleted UNKNOWN 2N/A * svc name not found UNKNOWN 2N/A * no fmri instance OK 2N/A * instance deleted UNKNOWN 2N/A * instance not found UNKNOWN 2N/A * If none of the above apply and this is a call from the 2N/A * "presence_state" method (presence_only == B_TRUE) then 2N/A * svc_get_state returns FMD_SERVICE_STATE_OK. 2N/A * The "presence_state" methods maps a return of UNKNOWN to 2N/A * FMD_OBJ_STATE_NOT_PRESENT and OK to FMD_OBJ_STATE_UNKNOWN. 2N/A * For the "service state" method svc_get_state goes on 2N/A * to return the instance state as below, and the method maps that 2N/A * result as in the last column of the following table: 2N/A * svc_get_state succeeds Service 2N/A * Instance state with FMD_SERVICE_STATE_* State 2N/A * -------------- ------------------------------- --------------- 2N/A * uninitialized OK OK 2N/A * maintenance UNUSABLE UNUSABLE 2N/A * degraded DEGRADED DEGRADED 2N/A * legacy_run OK (XXX can we see this?) OK 2N/A * Note that *only* "maintenance" state should map to an unusable service state. 2N/A * That's because a service entering maintenance state 2N/A * is modelled as a defect fault diagnosis in FMA, but there is no 2N/A * corresponding isolation action from a response agent since the the service 2N/A * is already isolated by virtue of being in maintenance state. Any transition 2N/A * from maintenance state, even to offline, is considered a repair. If on 2N/A * repair fmd does not see the service usable again then the case hangs 2N/A * around in the "resolved but not all resources back online" state and 2N/A * further maintenance events for this service will not show up in fmd state 2N/A * because case duplicate checking code will find the old case. 2N/A * If we fail to get the service due to _DELETED or _NOT_FOUND, then we 2N/A * treat this as not present. 2N/A * Again, check for _DELETED or _NOT_FOUND. 2N/A * For presence, we are done. Otherwise, we need to get the current 2N/A * state of the instance.