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