Path: blob/main/sys/contrib/openzfs/cmd/zed/agents/fmd_api.h
48529 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/2122/*23* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.24*25* Copyright (c) 2016, Intel Corporation.26*/2728#ifndef _FMD_API_H29#define _FMD_API_H3031#include <sys/types.h>32#include <sys/time.h>33#include <time.h>34#include <libnvpair.h>35#include <stdarg.h>36#include <umem.h>3738#ifdef __cplusplus39extern "C" {40#endif4142/*43* Fault Management Daemon Client Interfaces44*/4546#define FMD_API_VERSION 54748typedef struct fmd_hdl fmd_hdl_t;4950typedef struct fmd_timer {51timer_t ft_tid;52void *ft_arg;53fmd_hdl_t *ft_hdl;54} fmd_timer_t;5556#define id_t fmd_timer_t *575859typedef struct fmd_event {60hrtime_t ev_hrt; /* event time used by SERD engines */61} fmd_event_t;6263typedef struct fmd_case {64char ci_uuid[48]; /* uuid string for this case */65fmd_hdl_t *ci_mod; /* module that owns this case */66void *ci_data; /* data from fmd_case_setspecific() */67ushort_t ci_state; /* case state (see below) */68ushort_t ci_flags; /* case flags (see below) */69struct timeval ci_tv; /* time of original diagnosis */70void *ci_bufptr; /* case data serialization buffer */71size_t ci_bufsiz;72} fmd_case_t;737475#define FMD_CASE_UNSOLVED 0 /* case is not yet solved (waiting) */76#define FMD_CASE_SOLVED 1 /* case is solved (suspects added) */77#define FMD_CASE_CLOSE_WAIT 2 /* case is executing fmdo_close() */78#define FMD_CASE_CLOSED 3 /* case is closed (reconfig done) */79#define FMD_CASE_REPAIRED 4 /* case is repaired */80#define FMD_CASE_RESOLVED 5 /* case is resolved (can be freed) */8182#define FMD_CF_DIRTY 0x01 /* case is in need of checkpoint */83#define FMD_CF_SOLVED 0x02 /* case has been solved */84#define FMD_CF_ISOLATED 0x04 /* case has been isolated */85#define FMD_CF_REPAIRED 0x08 /* case has been repaired */86#define FMD_CF_RESOLVED 0x10 /* case has been resolved */878889#define FMD_TYPE_BOOL 0 /* int */90#define FMD_TYPE_INT32 1 /* int32_t */91#define FMD_TYPE_UINT32 2 /* uint32_t */92#define FMD_TYPE_INT64 3 /* int64_t */93#define FMD_TYPE_UINT64 4 /* uint64_t */94#define FMD_TYPE_TIME 5 /* uint64_t */95#define FMD_TYPE_SIZE 6 /* uint64_t */9697typedef struct fmd_prop {98const char *fmdp_name; /* property name */99uint_t fmdp_type; /* property type (see above) */100const char *fmdp_defv; /* default value */101} fmd_prop_t;102103typedef struct fmd_stat {104char fmds_name[32]; /* statistic name */105uint_t fmds_type; /* statistic type (see above) */106char fmds_desc[64]; /* statistic description */107union {108int bool; /* FMD_TYPE_BOOL */109int32_t i32; /* FMD_TYPE_INT32 */110uint32_t ui32; /* FMD_TYPE_UINT32 */111int64_t i64; /* FMD_TYPE_INT64 */112uint64_t ui64; /* FMD_TYPE_UINT64 */113} fmds_value;114} fmd_stat_t;115116typedef struct fmd_hdl_ops {117void (*fmdo_recv)(fmd_hdl_t *, fmd_event_t *, nvlist_t *, const char *);118void (*fmdo_timeout)(fmd_hdl_t *, id_t, void *);119void (*fmdo_close)(fmd_hdl_t *, fmd_case_t *);120void (*fmdo_stats)(fmd_hdl_t *);121void (*fmdo_gc)(fmd_hdl_t *);122} fmd_hdl_ops_t;123124#define FMD_SEND_SUCCESS 0 /* fmdo_send queued event */125#define FMD_SEND_FAILED 1 /* fmdo_send unrecoverable error */126#define FMD_SEND_RETRY 2 /* fmdo_send requests retry */127128typedef struct fmd_hdl_info {129const char *fmdi_desc; /* fmd client description string */130const char *fmdi_vers; /* fmd client version string */131const fmd_hdl_ops_t *fmdi_ops; /* ops vector for client */132const fmd_prop_t *fmdi_props; /* array of configuration props */133} fmd_hdl_info_t;134135extern int fmd_hdl_register(fmd_hdl_t *, int, const fmd_hdl_info_t *);136extern void fmd_hdl_unregister(fmd_hdl_t *);137138extern void fmd_hdl_setspecific(fmd_hdl_t *, void *);139extern void *fmd_hdl_getspecific(fmd_hdl_t *);140141#define FMD_SLEEP UMEM_NOFAIL142143extern void *fmd_hdl_alloc(fmd_hdl_t *, size_t, int);144extern void *fmd_hdl_zalloc(fmd_hdl_t *, size_t, int);145extern void fmd_hdl_free(fmd_hdl_t *, void *, size_t);146147extern char *fmd_hdl_strdup(fmd_hdl_t *, const char *, int);148extern void fmd_hdl_strfree(fmd_hdl_t *, char *);149150extern void fmd_hdl_vdebug(fmd_hdl_t *, const char *, va_list);151extern void fmd_hdl_debug(fmd_hdl_t *, const char *, ...);152153extern int32_t fmd_prop_get_int32(fmd_hdl_t *, const char *);154155#define FMD_STAT_NOALLOC 0x0 /* fmd should use caller's memory */156#define FMD_STAT_ALLOC 0x1 /* fmd should allocate stats memory */157158extern fmd_stat_t *fmd_stat_create(fmd_hdl_t *, uint_t, uint_t, fmd_stat_t *);159extern void fmd_stat_destroy(fmd_hdl_t *, uint_t, fmd_stat_t *);160extern void fmd_stat_setstr(fmd_hdl_t *, fmd_stat_t *, const char *);161162extern fmd_case_t *fmd_case_open(fmd_hdl_t *, void *);163extern void fmd_case_reset(fmd_hdl_t *, fmd_case_t *);164extern void fmd_case_solve(fmd_hdl_t *, fmd_case_t *);165extern void fmd_case_close(fmd_hdl_t *, fmd_case_t *);166167extern const char *fmd_case_uuid(fmd_hdl_t *, fmd_case_t *);168extern fmd_case_t *fmd_case_uulookup(fmd_hdl_t *, const char *);169extern void fmd_case_uuclose(fmd_hdl_t *, const char *);170extern int fmd_case_uuclosed(fmd_hdl_t *, const char *);171extern int fmd_case_uuisresolved(fmd_hdl_t *, const char *);172extern void fmd_case_uuresolved(fmd_hdl_t *, const char *);173174extern boolean_t fmd_case_solved(fmd_hdl_t *, fmd_case_t *);175176extern void fmd_case_add_ereport(fmd_hdl_t *, fmd_case_t *, fmd_event_t *);177extern void fmd_case_add_serd(fmd_hdl_t *, fmd_case_t *, const char *);178extern void fmd_case_add_suspect(fmd_hdl_t *, fmd_case_t *, nvlist_t *);179180extern void fmd_case_setspecific(fmd_hdl_t *, fmd_case_t *, void *);181extern void *fmd_case_getspecific(fmd_hdl_t *, fmd_case_t *);182183extern fmd_case_t *fmd_case_next(fmd_hdl_t *, fmd_case_t *);184extern fmd_case_t *fmd_case_prev(fmd_hdl_t *, fmd_case_t *);185186extern void fmd_buf_create(fmd_hdl_t *, fmd_case_t *, const char *, size_t);187extern void fmd_buf_destroy(fmd_hdl_t *, fmd_case_t *, const char *);188extern void fmd_buf_read(fmd_hdl_t *, fmd_case_t *,189const char *, void *, size_t);190extern void fmd_buf_write(fmd_hdl_t *, fmd_case_t *,191const char *, const void *, size_t);192extern size_t fmd_buf_size(fmd_hdl_t *, fmd_case_t *, const char *);193194extern void fmd_serd_create(fmd_hdl_t *, const char *, uint_t, hrtime_t);195extern void fmd_serd_destroy(fmd_hdl_t *, const char *);196extern int fmd_serd_exists(fmd_hdl_t *, const char *);197extern int fmd_serd_active(fmd_hdl_t *, const char *);198extern void fmd_serd_reset(fmd_hdl_t *, const char *);199extern int fmd_serd_record(fmd_hdl_t *, const char *, fmd_event_t *);200extern int fmd_serd_fired(fmd_hdl_t *, const char *);201extern int fmd_serd_empty(fmd_hdl_t *, const char *);202extern void fmd_serd_gc(fmd_hdl_t *);203204extern id_t fmd_timer_install(fmd_hdl_t *, void *, fmd_event_t *, hrtime_t);205extern void fmd_timer_remove(fmd_hdl_t *, id_t);206207extern nvlist_t *fmd_nvl_create_fault(fmd_hdl_t *,208const char *, uint8_t, nvlist_t *, nvlist_t *, nvlist_t *);209210extern int fmd_nvl_class_match(fmd_hdl_t *, nvlist_t *, const char *);211212#define FMD_HAS_FAULT_FRU 0213#define FMD_HAS_FAULT_ASRU 1214#define FMD_HAS_FAULT_RESOURCE 2215216extern void fmd_repair_fru(fmd_hdl_t *, const char *);217extern int fmd_repair_asru(fmd_hdl_t *, const char *);218219extern nvlist_t *fmd_nvl_alloc(fmd_hdl_t *, int);220extern nvlist_t *fmd_nvl_dup(fmd_hdl_t *, nvlist_t *, int);221222/*223* ZED Specific Interfaces224*/225226extern fmd_hdl_t *fmd_module_hdl(const char *);227extern boolean_t fmd_module_initialized(fmd_hdl_t *);228extern void fmd_module_recv(fmd_hdl_t *, nvlist_t *, const char *);229230/* ZFS FMA Retire Agent */231extern void _zfs_retire_init(fmd_hdl_t *);232extern void _zfs_retire_fini(fmd_hdl_t *);233234/* ZFS FMA Diagnosis Engine */235extern void _zfs_diagnosis_init(fmd_hdl_t *);236extern void _zfs_diagnosis_fini(fmd_hdl_t *);237238#ifdef __cplusplus239}240#endif241242#endif /* _FMD_API_H */243244245