ses_impl.h revision 6316:40d5384cc8b2
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * 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.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef	_SES_IMPL_H
28#define	_SES_IMPL_H
29
30#pragma ident	"%Z%%M%	%I%	%E% SMI"
31
32#ifdef	__cplusplus
33extern "C" {
34#endif
35
36#include <alloca.h>
37#include <errno.h>
38#include <assert.h>
39#include <dirent.h>
40#include <dlfcn.h>
41#include <limits.h>
42#include <pthread.h>
43#include <stdarg.h>
44#include <stddef.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <strings.h>
49#include <libnvpair.h>
50#include <unistd.h>
51#include <sys/mman.h>
52#include <sys/types.h>
53#include <sys/sysmacros.h>
54#include <sys/systeminfo.h>
55
56#include <scsi/libscsi.h>
57#include <scsi/libses_plugin.h>
58#include <scsi/plugins/ses/framework/ses2_impl.h>
59
60#define	LIBSES_ERRMSGLEN	512
61
62#define	LIBSES_DEFAULT_PLUGINDIR 	"/usr/lib/scsi/plugins/ses"
63#define	LIBSES_PLUGIN_FRAMEWORK		"framework"
64#define	LIBSES_PLUGIN_VENDOR		"vendor"
65
66#define	LIBSES_PLUGIN_EXT	".so"
67
68struct ses_plugin {
69	struct ses_plugin *sp_next;	/* next plugin in list */
70	struct ses_plugin *sp_prev;	/* previous plugin in list */
71	uint64_t sp_priority;		/* plugin priority */
72	struct ses_target *sp_target;	/* corresponding target */
73	void *sp_object;		/* shared object */
74	void *sp_data;			/* module-specific data */
75	boolean_t sp_initialized;	/* successfully initialized */
76	ses_pagedesc_t *sp_pages;	/* pages */
77	int (*sp_init)(ses_plugin_t *);	/* plugin init */
78	void (*sp_fini)(ses_plugin_t *); /* plugin fini */
79	int (*sp_node_parse)(ses_plugin_t *, ses_node_t *); /* parse node */
80	int (*sp_node_ctl)(ses_plugin_t *, ses_node_t *, const char *,
81	    nvlist_t *);		/* node control */
82};
83
84struct ses_target {
85	libscsi_hdl_t *st_scsi_hdl;
86	libscsi_target_t *st_target;
87	struct ses_plugin *st_plugin_first;
88	struct ses_plugin *st_plugin_last;
89	struct ses_snap *st_snapshots;
90	boolean_t st_closescsi;
91	boolean_t st_truncate;
92	pthread_mutex_t st_lock;
93};
94
95/*
96 * Maximum number of snapshot retries triggered by generation count changes
97 */
98#define	LIBSES_MAX_GC_RETRIES	10
99
100/*
101 * Maximum number of Enclosure Busy retries
102 */
103#define	LIBSES_MAX_BUSY_RETRIES	3
104
105typedef struct ses_snap_page {
106	ses2_diag_page_t ssp_num;
107	boolean_t ssp_control;
108	boolean_t ssp_initialized;
109	size_t ssp_alloc;
110	size_t ssp_len;
111	void *ssp_page;
112	char *ssp_mmap_base;
113	size_t ssp_mmap_len;
114	struct ses_snap_page *ssp_next;
115	struct ses_snap_page *ssp_unique;
116} ses_snap_page_t;
117
118struct ses_snap {
119	struct ses_target *ss_target;
120	uint32_t ss_generation;
121	hrtime_t ss_time;
122	struct ses_node *ss_root;
123	size_t ss_n_elem;
124	ses_snap_page_t *ss_pages;
125	size_t ss_n_nodes;
126	struct ses_node **ss_nodes;
127	struct ses_snap *ss_next;
128	struct ses_snap *ss_prev;
129	uint32_t ss_refcnt;
130};
131
132struct ses_node {
133	ses_node_type_t sn_type;
134	uint64_t sn_rootidx;	/* Relative index for enclosure/aggregate */
135	size_t sn_id;		/* Unique global ID */
136	uint64_t sn_enc_num;
137	struct ses_snap *sn_snapshot;
138	struct ses_node *sn_parent;
139	struct ses_node *sn_next_sibling;
140	struct ses_node *sn_prev_sibling;
141	struct ses_node *sn_first_child;
142	struct ses_node *sn_last_child;
143	nvlist_t *sn_props;
144};
145
146extern int ses_fill_snap(ses_snap_t *);
147extern void ses_node_teardown(ses_node_t *);
148extern ses_snap_page_t *ses_snap_find_page(ses_snap_t *, ses2_diag_page_t,
149    boolean_t);
150extern ses_snap_page_t *ses_snap_ctl_page(ses_snap_t *,
151    ses2_diag_page_t, size_t, boolean_t);
152extern int ses_snap_do_ctl(ses_snap_t *);
153
154extern int ses_libscsi_error(libscsi_hdl_t *, const char *, ...);
155extern int ses_scsi_error(libscsi_action_t *, const char *, ...);
156
157extern int ses_plugin_load(ses_target_t *);
158extern void ses_plugin_unload(ses_target_t *);
159
160extern ses_pagedesc_t *ses_get_pagedesc(ses_target_t *, int, ses_pagetype_t);
161extern int ses_fill_node(ses_node_t *);
162
163extern int enc_parse_ed(ses2_ed_impl_t *, nvlist_t *);
164extern int enc_parse_td(ses2_td_hdr_impl_t *, const char *, nvlist_t *);
165
166#ifdef	__cplusplus
167}
168#endif
169
170#endif	/* _SES_IMPL_H */
171