1N/A/*
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License (the "License").
1N/A * You may not use this file except in compliance with the License.
1N/A *
1N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * When distributing Covered Code, include this CDDL HEADER in each
1N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A * If applicable, add the following below this CDDL HEADER, with the
1N/A * fields enclosed by brackets "[]" replaced with your own identifying
1N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1N/A *
1N/A * CDDL HEADER END
1N/A */
1N/A
1N/A/*
1N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
1N/A */
1N/A
1N/A#ifndef _LIBSES_PLUGIN_H
1N/A#define _LIBSES_PLUGIN_H
1N/A
1N/A#ifdef __cplusplus
1N/Aextern "C" {
1N/A#endif
1N/A
1N/A#define LIBSES_PLUGIN_VERSION 1
1N/A
1N/A/*
1N/A * These are the primary APIs for plugins to interact with libses.
1N/A */
1N/A
1N/Astruct ses_plugin;
1N/Atypedef struct ses_plugin ses_plugin_t;
1N/A
1N/Atypedef enum {
1N/A SES_PAGE_DIAG,
1N/A SES_PAGE_CTL
1N/A} ses_pagetype_t;
1N/A
1N/Atypedef enum ses_page_req {
1N/A SES_REQ_OPTIONAL,
1N/A SES_REQ_MANDATORY_ALL,
1N/A SES_REQ_MANDATORY_STANDARD,
1N/A SES_REQ_OPTIONAL_STANDARD
1N/A} ses_page_req_t;
1N/A
1N/Atypedef struct ses_pagedesc {
1N/A int spd_pagenum;
1N/A size_t (*spd_ctl_len)(uint_t, int, size_t);
1N/A void *(*spd_ctl_fill)(ses_plugin_t *, void *, size_t,
1N/A ses_node_t *);
1N/A void *(*spd_index)(ses_plugin_t *, ses_node_t *,
1N/A void *, size_t, size_t *);
1N/A int spd_gcoff;
1N/A ses_page_req_t spd_req;
1N/A} ses_pagedesc_t;
1N/A
1N/Atypedef struct ses_plugin_config {
1N/A ses_pagedesc_t *spc_pages;
1N/A int (*spc_node_parse)(ses_plugin_t *, ses_node_t *);
1N/A int (*spc_node_ctl)(ses_plugin_t *, ses_node_t *,
1N/A const char *, nvlist_t *);
1N/A int (*spc_node_type_known)(ses_plugin_t *, ses_node_t *);
1N/A /* check if the type of a node is known to the plugin. */
1N/A} ses_plugin_config_t;
1N/A
1N/Aextern int ses_plugin_register(ses_plugin_t *, int, ses_plugin_config_t *);
1N/A
1N/Aextern void *ses_plugin_page_lookup(ses_plugin_t *, ses_snap_t *, int,
1N/A ses_node_t *, size_t *);
1N/A
1N/Aextern void *ses_plugin_ctlpage_lookup(ses_plugin_t *, ses_snap_t *, int,
1N/A size_t, ses_node_t *, boolean_t);
1N/A
1N/Aextern void ses_plugin_setspecific(ses_plugin_t *, void *);
1N/Aextern void *ses_plugin_getspecific(ses_plugin_t *);
1N/A
1N/A/*
1N/A * The following are support functions provided by libses.
1N/A */
1N/A
1N/Aextern int ses_assert(const char *, const char *, int);
1N/A
1N/A#define VERIFY(x) ((void)((x) || ses_assert(#x, __FILE__, __LINE__)))
1N/A
1N/A#ifdef DEBUG
1N/A#define ASSERT(x) VERIFY(x)
1N/A#else
1N/A#define ASSERT(x)
1N/A#endif
1N/A
1N/A#define SES_NV_ADD(_t, _e, _l, _n, ...) \
1N/A if (((_e) = nvlist_add_##_t((_l), (_n), __VA_ARGS__)) != 0) \
1N/A return (ses_set_nverrno((_e), (_n)))
1N/A
1N/A#define SES_NV_ADD_OR_FREE(_t, _e, _l, _n, ...) \
1N/A if (((_e) = nvlist_add_##_t((_l), (_n), __VA_ARGS__)) != 0) { \
1N/A nvlist_free(_l); return (ses_set_nverrno((_e), (_n))); }
1N/A
1N/A#define SES_NV_ADD_FS(_e, _l, _name, _buf) \
1N/A SES_NV_ADD(fixed_string, (_e), (_l), (_name), (_buf), sizeof (_buf))
1N/A
1N/A#define SES_NV_ADD_FS_TRUNC(_e, _l, _name, _buf) \
1N/A SES_NV_ADD(fixed_string_trunc, (_e), (_l), (_name), (_buf), \
1N/A sizeof (_buf))
1N/A
1N/A#define SES_NV_CTLBOOL(_l, _n, _b) \
1N/A { \
1N/A boolean_t v = B_FALSE; \
1N/A (void) nvlist_lookup_boolean_value((_l), (_n), &v); \
1N/A (_b) = v; \
1N/A }
1N/A
1N/A#define SES_NV_CTLBOOL_INVERT(_l, _n, _b) \
1N/A { \
1N/A boolean_t v = B_FALSE; \
1N/A (void) nvlist_lookup_boolean_value((_l), (_n), &v); \
1N/A (_b) = !v; \
1N/A }
1N/A
1N/A#define SES_NV_CTL64(_l, _n, _v) \
1N/A { \
1N/A uint64_t v = 0; \
1N/A (void) nvlist_lookup_uint64((_l), (_n), &v); \
1N/A (_v) = v; \
1N/A }
1N/A
1N/A#define SES_NV_CTL16(_l, _n, _v) \
1N/A { \
1N/A uint16_t v = 0; \
1N/A (void) nvlist_lookup_uint16((_l), (_n), &v); \
1N/A SCSI_WRITE16(&(_v), v); \
1N/A }
1N/A
1N/Aextern void *ses_alloc(size_t);
1N/Aextern void *ses_zalloc(size_t);
1N/Aextern char *ses_strdup(const char *);
1N/Aextern void *ses_realloc(void *, size_t);
1N/Aextern void ses_free(void *);
1N/A
extern int ses_set_errno(ses_errno_t);
extern int ses_set_nverrno(int, const char *);
extern int ses_error(ses_errno_t, const char *, ...);
extern int ses_nverror(int, const char *, const char *, ...);
extern void ses_panic(const char *, ...) __NORETURN;
extern int nvlist_add_fixed_string(nvlist_t *, const char *,
const char *, size_t);
extern int nvlist_add_fixed_string_trunc(nvlist_t *, const char *,
const char *, size_t);
#define SES_WITHIN_PAGE(sp, size, data, len) \
((char *)(sp) <= (char *)(data) + (len) - (size))
#define SES_WITHIN_PAGE_STRUCT(sp, data, len) \
SES_WITHIN_PAGE((sp), sizeof (*(sp)), (data), (len))
#ifdef __cplusplus
}
#endif
#endif /* _LIBSES_PLUGIN_H */