17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5567cc2e6Sstephh * Common Development and Distribution License (the "License"). 6567cc2e6Sstephh * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21d9638e54Smws 227c478bd9Sstevel@tonic-gate /* 23cbf75e67SStephen Hanson * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _FMD_ASRU_H 287c478bd9Sstevel@tonic-gate #define _FMD_ASRU_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <pthread.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include <fmd_api.h> 387c478bd9Sstevel@tonic-gate #include <fmd_log.h> 39567cc2e6Sstephh #include <fmd_list.h> 40940d71d2Seschrock #include <fmd_topo.h> 417c478bd9Sstevel@tonic-gate 42567cc2e6Sstephh /* 43567cc2e6Sstephh * The resource is represented by an fmd_asru_t structure and one or more 44567cc2e6Sstephh * fmd_asru_link_t structures. Each of the latter represents a separate 45567cc2e6Sstephh * unrepaired case (problem) involving the resource. There are separate 46567cc2e6Sstephh * reference counts for both the fmd_asru_t and fmd_asru_link_t structures, 47567cc2e6Sstephh * but only one lock is used (asru_lock) which protects both the parent 48567cc2e6Sstephh * fmd_asru_t and its associated fmd_asru_link_t structures. The FMD_ASRU_FAULTY 49567cc2e6Sstephh * flags in the fmd_asru_t represents the cumulative value of the associated 50567cc2e6Sstephh * FMD_ASRU_FAULTY flags in the fmd_asru_link_t structures (and therefore of 51567cc2e6Sstephh * all independant unrepaired problems that are affecting that resource). 52567cc2e6Sstephh */ 537c478bd9Sstevel@tonic-gate typedef struct fmd_asru { 547c478bd9Sstevel@tonic-gate struct fmd_asru *asru_next; /* next asru on hash chain */ 557c478bd9Sstevel@tonic-gate char *asru_name; /* string form of resource fmri (ro) */ 567c478bd9Sstevel@tonic-gate nvlist_t *asru_fmri; /* nvlist form of resource fmri (ro) */ 577c478bd9Sstevel@tonic-gate char *asru_root; /* directory for cache entry (ro) */ 587c478bd9Sstevel@tonic-gate char *asru_uuid; /* uuid for asru cache entry (ro) */ 597c478bd9Sstevel@tonic-gate uint_t asru_uuidlen; /* length of asru_uuid (not incl. \0) */ 607c478bd9Sstevel@tonic-gate pthread_mutex_t asru_lock; /* lock protecting remaining members */ 617c478bd9Sstevel@tonic-gate pthread_cond_t asru_cv; /* condition variable for asru_flags */ 627c478bd9Sstevel@tonic-gate uint_t asru_refs; /* reference count */ 637c478bd9Sstevel@tonic-gate uint_t asru_flags; /* flags (see below) */ 64d9638e54Smws fmd_case_t *asru_case; /* case associated with last change */ 65162ba6eaSmws nvlist_t *asru_event; /* event associated with last change */ 66567cc2e6Sstephh fmd_list_t asru_list; /* linked list next/prev pointers */ 677c478bd9Sstevel@tonic-gate } fmd_asru_t; 687c478bd9Sstevel@tonic-gate 69567cc2e6Sstephh typedef struct fmd_asru_link { 70567cc2e6Sstephh fmd_list_t al_list; /* linked list next/prev pointers */ 71567cc2e6Sstephh struct fmd_asru *al_asru; /* pointer back to parent */ 72567cc2e6Sstephh struct fmd_asru_link *al_asru_next; /* next link on hash chain */ 73567cc2e6Sstephh struct fmd_asru_link *al_case_next; /* next link on hash chain */ 74567cc2e6Sstephh struct fmd_asru_link *al_fru_next; /* next link on hash chain */ 75567cc2e6Sstephh struct fmd_asru_link *al_label_next; /* next link on hash chain */ 76567cc2e6Sstephh struct fmd_asru_link *al_rsrc_next; /* next link on hash chain */ 77567cc2e6Sstephh char *al_uuid; /* uuid for asru cache entry (ro) */ 78567cc2e6Sstephh uint_t al_uuidlen; /* length of al_uuid (not incl. \0) */ 79567cc2e6Sstephh fmd_log_t *al_log; /* persistent event log */ 80567cc2e6Sstephh char *al_asru_name; /* string form of asru fmri (ro) */ 81567cc2e6Sstephh char *al_fru_name; /* string form of fru fmri (ro) */ 82567cc2e6Sstephh char *al_rsrc_name; /* string form of resource fmri (ro) */ 83567cc2e6Sstephh char *al_label; /* label */ 84567cc2e6Sstephh char *al_case_uuid; /* case uuid */ 85567cc2e6Sstephh nvlist_t *al_asru_fmri; /* nvlist form of resource fmri (ro) */ 86567cc2e6Sstephh fmd_case_t *al_case; /* case associated with last change */ 87567cc2e6Sstephh nvlist_t *al_event; /* event associated with last change */ 88567cc2e6Sstephh uint_t al_refs; /* reference count */ 89567cc2e6Sstephh uint_t al_flags; /* flags (see below) */ 9025c6ff4bSstephh uint8_t al_reason; /* repair reason (see below) */ 91567cc2e6Sstephh } fmd_asru_link_t; 92567cc2e6Sstephh 937c478bd9Sstevel@tonic-gate #define FMD_ASRU_FAULTY 0x01 /* asru has been diagnosed as faulty */ 947c478bd9Sstevel@tonic-gate #define FMD_ASRU_UNUSABLE 0x02 /* asru can not be used at present */ 957c478bd9Sstevel@tonic-gate #define FMD_ASRU_VALID 0x04 /* asru is initialized and valid */ 967c478bd9Sstevel@tonic-gate #define FMD_ASRU_INTERNAL 0x08 /* asru is managed by fmd itself */ 977c478bd9Sstevel@tonic-gate #define FMD_ASRU_INVISIBLE 0x10 /* asru is not visibly administered */ 980b9e3e76Smws #define FMD_ASRU_RECREATED 0x20 /* asru recreated by cache replay */ 99162ba6eaSmws #define FMD_ASRU_PRESENT 0x40 /* asru present at last R$ update */ 10025c6ff4bSstephh #define FMD_ASRU_DEGRADED 0x80 /* asru service is degraded */ 101cbf75e67SStephen Hanson #define FMD_ASRU_PROXY 0x100 /* asru on proxy */ 102cbf75e67SStephen Hanson #define FMD_ASRU_PROXY_WITH_ASRU 0x200 /* asru accessible locally on proxy */ 103cbf75e67SStephen Hanson #define FMD_ASRU_PROXY_EXTERNAL 0x400 /* proxy over external transport */ 104cbf75e67SStephen Hanson #define FMD_ASRU_PROXY_RDONLY 0x800 /* proxy over readonly transport */ 10525c6ff4bSstephh 10625c6ff4bSstephh /* 10725c6ff4bSstephh * Note the following are defined in order of increasing precedence and 10825c6ff4bSstephh * this should not be changed 10925c6ff4bSstephh */ 110cbf75e67SStephen Hanson #define FMD_ASRU_REMOVED 0 /* asru removed */ 11125c6ff4bSstephh #define FMD_ASRU_ACQUITTED 1 /* asru acquitted */ 11225c6ff4bSstephh #define FMD_ASRU_REPAIRED 2 /* asru repaired */ 11325c6ff4bSstephh #define FMD_ASRU_REPLACED 3 /* asru replaced */ 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #define FMD_ASRU_STATE (FMD_ASRU_FAULTY | FMD_ASRU_UNUSABLE) 1167c478bd9Sstevel@tonic-gate 117567cc2e6Sstephh #define FMD_ASRU_AL_HASH_NAME(a, off) \ 118567cc2e6Sstephh *(char **)((uint8_t *)a + off) 119567cc2e6Sstephh #define FMD_ASRU_AL_HASH_NEXT(a, off) \ 120567cc2e6Sstephh *(fmd_asru_link_t **)((uint8_t *)a + off) 121567cc2e6Sstephh #define FMD_ASRU_AL_HASH_NEXTP(a, off) \ 122567cc2e6Sstephh (fmd_asru_link_t **)((uint8_t *)a + off) 123567cc2e6Sstephh 1247c478bd9Sstevel@tonic-gate typedef struct fmd_asru_hash { 1257c478bd9Sstevel@tonic-gate pthread_rwlock_t ah_lock; /* r/w lock protecting hash contents */ 1267c478bd9Sstevel@tonic-gate fmd_asru_t **ah_hash; /* hash bucket array for asrus */ 127567cc2e6Sstephh fmd_asru_link_t **ah_asru_hash; /* hash bucket array for asrus */ 128567cc2e6Sstephh fmd_asru_link_t **ah_case_hash; /* hash bucket array for frus */ 129567cc2e6Sstephh fmd_asru_link_t **ah_fru_hash; /* hash bucket array for cases */ 130567cc2e6Sstephh fmd_asru_link_t **ah_label_hash; /* label hash bucket array */ 131567cc2e6Sstephh fmd_asru_link_t **ah_rsrc_hash; /* hash bucket array for rsrcs */ 1327c478bd9Sstevel@tonic-gate uint_t ah_hashlen; /* length of hash bucket array */ 1337c478bd9Sstevel@tonic-gate char *ah_dirpath; /* path of hash's log file directory */ 1347c478bd9Sstevel@tonic-gate uint64_t ah_lifetime; /* max lifetime of log if not present */ 135567cc2e6Sstephh uint_t ah_al_count; /* count of number of entries in hash */ 136567cc2e6Sstephh uint_t ah_count; /* count of separate rsrcs in hash */ 1377c478bd9Sstevel@tonic-gate int ah_error; /* error from opening asru log */ 138940d71d2Seschrock fmd_topo_t *ah_topo; /* topo handle */ 1397c478bd9Sstevel@tonic-gate } fmd_asru_hash_t; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate extern fmd_asru_hash_t *fmd_asru_hash_create(const char *, const char *); 1427c478bd9Sstevel@tonic-gate extern void fmd_asru_hash_destroy(fmd_asru_hash_t *); 1437c478bd9Sstevel@tonic-gate extern void fmd_asru_hash_refresh(fmd_asru_hash_t *); 144162ba6eaSmws extern void fmd_asru_hash_replay(fmd_asru_hash_t *); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate extern void fmd_asru_hash_apply(fmd_asru_hash_t *, 1477c478bd9Sstevel@tonic-gate void (*)(fmd_asru_t *, void *), void *); 148567cc2e6Sstephh extern void fmd_asru_al_hash_apply(fmd_asru_hash_t *, 149567cc2e6Sstephh void (*)(fmd_asru_link_t *, void *), void *); 15007312882SEric Schrock extern void fmd_asru_hash_apply_by_asru(fmd_asru_hash_t *, const char *, 151567cc2e6Sstephh void (*)(fmd_asru_link_t *, void *), void *); 15207312882SEric Schrock extern void fmd_asru_hash_apply_by_label(fmd_asru_hash_t *, const char *, 153567cc2e6Sstephh void (*)(fmd_asru_link_t *, void *), void *); 15407312882SEric Schrock extern void fmd_asru_hash_apply_by_fru(fmd_asru_hash_t *, const char *, 155567cc2e6Sstephh void (*)(fmd_asru_link_t *, void *), void *); 15607312882SEric Schrock extern void fmd_asru_hash_apply_by_rsrc(fmd_asru_hash_t *, const char *, 157567cc2e6Sstephh void (*)(fmd_asru_link_t *, void *), void *); 158567cc2e6Sstephh extern void fmd_asru_hash_apply_by_case(fmd_asru_hash_t *, fmd_case_t *, 159567cc2e6Sstephh void (*)(fmd_asru_link_t *, void *), void *); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate extern fmd_asru_t *fmd_asru_hash_lookup_name(fmd_asru_hash_t *, const char *); 162567cc2e6Sstephh extern fmd_asru_link_t *fmd_asru_hash_create_entry(fmd_asru_hash_t *, 163567cc2e6Sstephh fmd_case_t *, nvlist_t *); 1647c478bd9Sstevel@tonic-gate extern void fmd_asru_hash_release(fmd_asru_hash_t *, fmd_asru_t *); 165567cc2e6Sstephh extern void fmd_asru_hash_delete_case(fmd_asru_hash_t *, fmd_case_t *); 1667c478bd9Sstevel@tonic-gate 167567cc2e6Sstephh extern void fmd_asru_clear_aged_rsrcs(); 168cbf75e67SStephen Hanson 169cbf75e67SStephen Hanson /* 170cbf75e67SStephen Hanson * flags used in fara_bywhat field in fmd_asru_rep_arg_t 171cbf75e67SStephen Hanson */ 172cbf75e67SStephen Hanson #define FARA_ALL 0 173cbf75e67SStephen Hanson #define FARA_BY_CASE 1 174cbf75e67SStephen Hanson #define FARA_BY_ASRU 2 175cbf75e67SStephen Hanson #define FARA_BY_FRU 3 176cbf75e67SStephen Hanson #define FARA_BY_RSRC 4 177cbf75e67SStephen Hanson #define FARA_BY_LABEL 5 178cbf75e67SStephen Hanson 179cbf75e67SStephen Hanson /* 1806e1fa242SStephen Hanson * Return values for fmd_asru_repaired. May return "ok" or "not replaced". 1816e1fa242SStephen Hanson * If no fault is found we will get default value of "not found". 1826e1fa242SStephen Hanson */ 1836e1fa242SStephen Hanson #define FARA_OK 0 1846e1fa242SStephen Hanson #define FARA_ERR_RSRCNOTF 1 1856e1fa242SStephen Hanson #define FARA_ERR_RSRCNOTR 2 1866e1fa242SStephen Hanson 1876e1fa242SStephen Hanson /* 188cbf75e67SStephen Hanson * The following structures are used to pass arguments to the corresponding 189cbf75e67SStephen Hanson * function when walking the resource cache by case etc. 190cbf75e67SStephen Hanson */ 191cbf75e67SStephen Hanson typedef struct { 192cbf75e67SStephen Hanson uint8_t fara_reason; /* repaired, acquit, replaced, removed */ 193cbf75e67SStephen Hanson uint8_t fara_bywhat; /* whether doing a walk by case, asru, etc */ 194cbf75e67SStephen Hanson int *fara_rval; /* for return success or failure */ 195cbf75e67SStephen Hanson char *fara_uuid; /* uuid can be passed in for comparison */ 196cbf75e67SStephen Hanson } fmd_asru_rep_arg_t; 19725c6ff4bSstephh extern void fmd_asru_repaired(fmd_asru_link_t *, void *); 198*5750ef5cSStephen Hanson extern void fmd_asru_flush(fmd_asru_link_t *, void *); 199cbf75e67SStephen Hanson 200cbf75e67SStephen Hanson typedef struct { 201cbf75e67SStephen Hanson int *faus_countp; 202cbf75e67SStephen Hanson int faus_maxcount; 203cbf75e67SStephen Hanson uint8_t *faus_ba; /* received status for each suspect */ 204cbf75e67SStephen Hanson uint8_t *faus_proxy_asru; /* asru on proxy for each suspect? */ 205cbf75e67SStephen Hanson uint8_t *faus_diag_asru; /* asru on diag for each suspect? */ 206cbf75e67SStephen Hanson boolean_t faus_is_proxy; /* are we on the proxy side? */ 207cbf75e67SStephen Hanson } fmd_asru_update_status_t; 208cbf75e67SStephen Hanson extern void fmd_asru_update_status(fmd_asru_link_t *alp, void *arg); 209cbf75e67SStephen Hanson 210cbf75e67SStephen Hanson typedef struct { 211cbf75e67SStephen Hanson int *fasp_countp; 212cbf75e67SStephen Hanson int fasp_maxcount; 213cbf75e67SStephen Hanson uint8_t *fasp_proxy_asru; /* asru on proxy for each suspect? */ 214cbf75e67SStephen Hanson int fasp_proxy_external; /* is this an external transport? */ 215cbf75e67SStephen Hanson int fasp_proxy_rdonly; /* is this a rdonly transport? */ 216cbf75e67SStephen Hanson } fmd_asru_set_on_proxy_t; 217cbf75e67SStephen Hanson extern void fmd_asru_set_on_proxy(fmd_asru_link_t *alp, void *arg); 218cbf75e67SStephen Hanson 219cbf75e67SStephen Hanson extern void fmd_asru_update_containees(fmd_asru_link_t *alp, void *arg); 220cbf75e67SStephen Hanson 221cbf75e67SStephen Hanson typedef struct { 222cbf75e67SStephen Hanson int *facs_countp; 223cbf75e67SStephen Hanson int facs_maxcount; 224cbf75e67SStephen Hanson } fmd_asru_close_status_t; 225cbf75e67SStephen Hanson extern void fmd_asru_close_status(fmd_asru_link_t *alp, void *arg); 226cbf75e67SStephen Hanson 227567cc2e6Sstephh extern int fmd_asru_setflags(fmd_asru_link_t *, uint_t); 22825c6ff4bSstephh extern int fmd_asru_clrflags(fmd_asru_link_t *, uint_t, uint8_t); 229*5750ef5cSStephen Hanson extern void fmd_asru_log_resolved(fmd_asru_link_t *, void *); 230567cc2e6Sstephh extern int fmd_asru_al_getstate(fmd_asru_link_t *); 2317c478bd9Sstevel@tonic-gate extern int fmd_asru_getstate(fmd_asru_t *); 232*5750ef5cSStephen Hanson extern void fmd_asru_check_if_aged(fmd_asru_link_t *, void *); 233*5750ef5cSStephen Hanson void fmd_asru_most_recent(fmd_asru_link_t *, void *); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate #endif 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate #endif /* _FMD_ASRU_H */ 240