1 /* 2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * BSD 3 Clause License 8 * 9 * Copyright (c) 2007, The Storage Networking Industry Association. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * - Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 17 * - Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * 22 * - Neither the name of The Storage Networking Industry Association (SNIA) 23 * nor the names of its contributors may be used to endorse or promote 24 * products derived from this software without specific prior written 25 * permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 #ifndef _LIBNDMP_H 40 #define _LIBNDMP_H 41 42 #include <rpc/types.h> 43 #include <libscf.h> 44 #include <libnvpair.h> 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /* NDMP supported versions */ 51 #define NDMP_V2 2 52 #define NDMP_V3 3 53 #define NDMP_V4 4 54 55 /* Device type */ 56 #define NDMP_SINQ_SEQ_ACCESS_DEVICE 0x01 57 #define NDMP_SINQ_TAPE_ROBOT 0x08 58 59 extern int ndmp_errno; 60 61 /* NDMP plugin module API */ 62 #define NDMP_PLUGIN_VERSION 1 63 64 typedef struct ndmp_context { 65 char *nc_plname; 66 uint_t nc_plversion; 67 void *nc_pldata; 68 void *nc_cmds; 69 } ndmp_context_t; 70 71 typedef struct ndmp_plugin { 72 const char *np_plid; /* plugin identifier */ 73 uint_t np_plversion; /* plugin version */ 74 void *np_pldata; /* for private use by the plugin */ 75 76 /* Plugin entry points */ 77 int (*np_pre_backup)(struct ndmp_plugin *, ndmp_context_t *, 78 const char *); 79 int (*np_post_backup)(struct ndmp_plugin *, ndmp_context_t *, 80 int); 81 int (*np_pre_restore)(struct ndmp_plugin *, ndmp_context_t *, 82 const char *, const char *); 83 int (*np_post_restore)(struct ndmp_plugin *, ndmp_context_t *, 84 int); 85 } ndmp_plugin_t; 86 87 /* libndmp error codes */ 88 #define ENDMP_BASE 2000 89 enum { 90 ENDMP_DOOR_SRV_TIMEOUT = ENDMP_BASE, 91 ENDMP_INVALID_ARG, 92 ENDMP_DOOR_SRV_OPERATION, 93 ENDMP_DOOR_OPEN, 94 ENDMP_MEM_ALLOC, 95 ENDMP_DOOR_ENCODE_START, 96 ENDMP_DOOR_ENCODE_FINISH, 97 ENDMP_DOOR_DECODE_FINISH, 98 ENDMP_SMF_PERM, 99 ENDMP_SMF_INTERNAL, 100 ENDMP_SMF_PROP, 101 ENDMP_SMF_PROP_GRP 102 }; 103 104 /* Tape device open mode */ 105 typedef enum ndmp_tp_open_mode { 106 NDMP_TP_READ_MODE, 107 NDMP_TP_WRITE_MODE, 108 NDMP_TP_RAW_MODE, 109 NDMP_TP_RAW1_MODE = 0x7fffffff, 110 NDMP_TP_RAW2_MODE = NDMP_TP_RAW_MODE 111 } ndmp_tp_open_mode_t; 112 113 /* Mover state */ 114 typedef enum ndmp_mv_state { 115 NDMP_MV_STATE_IDLE, 116 NDMP_MV_STATE_LISTEN, 117 NDMP_MV_STATE_ACTIVE, 118 NDMP_MV_STATE_PAUSED, 119 NDMP_MV_STATE_HALTED 120 } ndmp_mv_state_t; 121 122 /* Mover mode */ 123 typedef enum ndmp_mv_mode { 124 NDMP_MV_MODE_READ, 125 NDMP_MV_MODE_WRITE, 126 NDMP_MV_MODE_NOACTION 127 } ndmp_mv_mode_t; 128 129 /* Mover pause reson */ 130 typedef enum ndmp_mv_pause_reason { 131 NDMP_MV_PAUSE_NA, 132 NDMP_MV_PAUSE_EOM, 133 NDMP_MV_PAUSE_EOF, 134 NDMP_MV_PAUSE_SEEK, 135 NDMP_MV_PAUSE_MEDIA_ERROR, 136 NDMP_MV_PAUSE_EOW 137 } ndmp_mv_pause_reason_t; 138 139 /* Mover halt reason */ 140 typedef enum ndmp_mv_halt_reason { 141 NDMP_MV_HALT_NA, 142 NDMP_MV_HALT_CONNECT_CLOSED, 143 NDMP_MV_HALT_ABORTED, 144 NDMP_MV_HALT_INTERNAL_ERROR, 145 NDMP_MV_HALT_CONNECT_ERROR, 146 NDMP_MV_HALT_MEDIA_ERROR 147 } ndmp_mv_halt_reason_t; 148 149 /* Address type */ 150 typedef enum ndmp_ad_type { 151 NDMP_AD_LOCAL, 152 NDMP_AD_TCP, 153 NDMP_AD_FC, 154 NDMP_AD_IPC 155 } ndmp_ad_type_t; 156 157 /* NDMP data operation */ 158 typedef enum ndmp_dt_operation { 159 NDMP_DT_OP_NOACTION, 160 NDMP_DT_OP_BACKUP, 161 NDMP_DT_OP_RECOVER, 162 NDMP_DT_OP_RECOVER_FILEHIST 163 } ndmp_dt_operation_t; 164 165 /* NDMP data state */ 166 typedef enum ndmp_dt_state { 167 NDMP_DT_STATE_IDLE, 168 NDMP_DT_STATE_ACTIVE, 169 NDMP_DT_STATE_HALTED, 170 NDMP_DT_STATE_LISTEN, 171 NDMP_DT_STATE_CONNECTED 172 } ndmp_dt_state_t; 173 174 /* NDMP data halt reason */ 175 typedef enum ndmp_dt_halt_reason { 176 NDMP_DT_HALT_NA, 177 NDMP_DT_HALT_SUCCESSFUL, 178 NDMP_DT_HALT_ABORTED, 179 NDMP_DT_HALT_INTERNAL_ERROR, 180 NDMP_DT_HALT_CONNECT_ERROR 181 } ndmp_dt_halt_reason_t; 182 183 /* Device information structure */ 184 typedef struct ndmp_devinfo { 185 uint_t nd_dev_type; /* SCSI device type */ 186 char *nd_name; /* Device name */ 187 uint_t nd_lun; /* Lun number */ 188 uint_t nd_sid; /* Scsi id */ 189 char *nd_vendor; /* Vendor name */ 190 char *nd_product; /* Product name */ 191 char *nd_revision; /* Revision */ 192 char *nd_serial; /* Serial */ 193 char *nd_wwn; /* World wide name */ 194 } ndmp_devinfo_t; 195 196 /* Scsi device info sturcture */ 197 typedef struct ndmp_scsi { 198 int ns_scsi_open; /* Scsi device open */ 199 /* -1 if not open */ 200 char *ns_adapter_name; /* Scsi adapter name */ 201 int ns_valid_target_set; /* Scsi valid target */ 202 /* scsi_id and lun are set only if valid_target_set is set */ 203 int ns_scsi_id; /* Scsi id */ 204 int ns_lun; /* Scsi lun */ 205 } ndmp_scsi_t; 206 207 typedef struct ndmp_tape { 208 int nt_fd; /* Tape device file descriptor */ 209 /* The data below is set only if "fd" is not -1 */ 210 ulong_t nt_rec_count; /* Number of records written */ 211 ndmp_tp_open_mode_t nt_mode; /* Tape device open mode */ 212 char *nt_dev_name; /* Device name */ 213 char *nt_adapter_name; /* Adapter name */ 214 int nt_sid; /* Scsi id */ 215 int nt_lun; /* Lun number */ 216 } ndmp_tape_t; 217 218 /* NDMP mover info structure */ 219 typedef struct ndmp_mover { 220 ndmp_mv_state_t nm_state; /* Current state */ 221 ndmp_mv_mode_t nm_mode; /* Current mode */ 222 ndmp_mv_pause_reason_t nm_pause_reason; /* Current reason */ 223 ndmp_mv_halt_reason_t nm_halt_reason; /* Current reason */ 224 ulong_t nm_rec_size; /* Tape I/O record size */ 225 ulong_t nm_rec_num; /* Current record num */ 226 u_longlong_t nm_mov_pos; /* Current data stream pos */ 227 u_longlong_t nm_window_offset; /* Valid data window begin */ 228 u_longlong_t nm_window_length; /* Valid data window length */ 229 int nm_sock; /* Data conn socket */ 230 231 /* Filled in V3 and V4 only */ 232 int nm_listen_sock; /* Data conn listen socket */ 233 ndmp_ad_type_t nm_addr_type; /* Current address type */ 234 char *nm_tcp_addr; /* Only if addr_type is tcp */ 235 } ndmp_mover_t; 236 237 typedef struct ndmp_dt_name { 238 char *nn_name; 239 char *nn_dest; 240 } ndmp_dt_name_t; 241 242 /* NDMP name/value pair structure */ 243 typedef struct ndmp_dt_pval { 244 char *np_name; 245 char *np_value; 246 } ndmp_dt_pval_t; 247 248 typedef struct ndmp_dt_name_v3 { 249 char *nn3_opath; 250 char *nn3_dpath; 251 u_longlong_t nn3_node; 252 u_longlong_t nn3_fh_info; 253 } ndmp_dt_name_v3_t; 254 255 typedef struct ndmp_dt_v3 { 256 int dv3_listen_sock; 257 u_longlong_t dv3_bytes_processed; 258 ndmp_dt_name_v3_t *dv3_nlist; /* V3 recover file list */ 259 } ndmp_dt_v3_t; 260 261 /* NDMP data structure */ 262 typedef struct ndmp_data { 263 ndmp_dt_operation_t nd_oper; /* Current operation */ 264 ndmp_dt_state_t nd_state; /* Current state */ 265 ndmp_dt_halt_reason_t nd_halt_reason; /* Current reason */ 266 int nd_sock; /* Listen and data socket */ 267 ndmp_ad_type_t nd_addr_type; /* Current address type */ 268 char *nd_tcp_addr; /* Only if addr_type is tcp */ 269 int nd_abort; /* Abort operation flag */ 270 /* 0 = No, otherwise Yes */ 271 u_longlong_t nd_read_offset; /* Data read seek offset */ 272 u_longlong_t nd_read_length; /* Data read length */ 273 u_longlong_t nd_total_size; /* Backup data size */ 274 ulong_t nd_env_len; /* Environment length */ 275 ndmp_dt_pval_t *nd_env; /* Environment from backup */ 276 /* or recover request */ 277 ulong_t nld_nlist_len; /* Recover file list length */ 278 union { 279 /* Filled in V2 */ 280 ndmp_dt_name_t *nld_nlist; /* Recover file list */ 281 /* Filled in V3 */ 282 ndmp_dt_v3_t nld_dt_v3; /* V3 data */ 283 } nd_nlist; 284 } ndmp_data_t; 285 286 /* NDMP session information */ 287 typedef struct ndmp_session_info { 288 int nsi_sid; /* Session id */ 289 int nsi_pver; /* NDMP protocol version */ 290 int nsi_auth; /* Authorized ? 0="no", else "yes" */ 291 int nsi_eof; /* Connection EOF flag */ 292 /* 0="no", else "yes" */ 293 char *nsi_cl_addr; /* Client address */ 294 ndmp_scsi_t nsi_scsi; /* Scsi device information */ 295 ndmp_tape_t nsi_tape; /* Tape device information */ 296 ndmp_mover_t nsi_mover; /* Mover information */ 297 ndmp_data_t nsi_data; /* Data information */ 298 } ndmp_session_info_t; 299 300 /* Stats data */ 301 typedef struct ndmp_stat { 302 int ns_trun; /* Number of worker threads running */ 303 int ns_twait; /* Number of blocked worker threads */ 304 int ns_nbk; /* Number of backups operations running */ 305 int ns_nrs; /* Number of restores operations running */ 306 int ns_rfile; /* Number of files being read */ 307 int ns_wfile; /* Number of files being written */ 308 uint64_t ns_rdisk; /* Number of disk blocks being read */ 309 uint64_t ns_wdisk; /* Number of disk blocks being written */ 310 uint64_t ns_rtape; /* Number of tape blocks being read */ 311 uint64_t ns_wtape; /* Number of tape blocks being written */ 312 } ndmp_stat_t; 313 314 /* Common encode/decode functions used by door clients/servers. */ 315 typedef struct ndmp_door_ctx { 316 char *ptr; 317 char *start_ptr; 318 char *end_ptr; 319 int status; 320 } ndmp_door_ctx_t; 321 322 extern int ndmp_get_devinfo(ndmp_devinfo_t **, size_t *); 323 extern void ndmp_get_devinfo_free(ndmp_devinfo_t *, size_t); 324 extern int ndmp_get_dbglevel(void); 325 extern int ndmp_get_session_info(ndmp_session_info_t **, size_t *); 326 extern void ndmp_get_session_info_free(ndmp_session_info_t *, size_t); 327 extern int ndmp_get_stats(ndmp_stat_t *); 328 extern int ndmp_terminate_session(int); 329 extern int ndmp_set_dbglevel(int); 330 extern const char *ndmp_strerror(int); 331 extern int ndmp_door_status(void); 332 extern int ndmp_get_prop(char *, char **); 333 extern int ndmp_set_prop(char *, char *); 334 extern int ndmp_service_refresh(void); 335 extern char *ndmp_base64_encode(char *); 336 extern char *ndmp_base64_decode(char *); 337 extern ndmp_door_ctx_t *ndmp_door_decode_start(char *, int); 338 extern int ndmp_door_decode_finish(ndmp_door_ctx_t *); 339 extern ndmp_door_ctx_t *ndmp_door_encode_start(char *, int); 340 extern int ndmp_door_encode_finish(ndmp_door_ctx_t *, unsigned int *); 341 extern int32_t ndmp_door_get_int32(ndmp_door_ctx_t *); 342 extern uint32_t ndmp_door_get_uint32(ndmp_door_ctx_t *); 343 extern char *ndmp_door_get_string(ndmp_door_ctx_t *); 344 extern void ndmp_door_put_int32(ndmp_door_ctx_t *, int32_t); 345 extern void ndmp_door_put_uint32(ndmp_door_ctx_t *, uint32_t); 346 extern void ndmp_door_put_string(ndmp_door_ctx_t *, char *); 347 extern void ndmp_door_free_string(char *); 348 extern int64_t ndmp_door_get_int64(ndmp_door_ctx_t *); 349 extern uint64_t ndmp_door_get_uint64(ndmp_door_ctx_t *); 350 extern void ndmp_door_put_uint64(ndmp_door_ctx_t *, uint64_t); 351 extern void ndmp_door_put_short(ndmp_door_ctx_t *, short); 352 extern short ndmp_door_get_short(ndmp_door_ctx_t *); 353 extern void ndmp_door_put_ushort(ndmp_door_ctx_t *, unsigned short); 354 extern unsigned short ndmp_door_get_ushort(ndmp_door_ctx_t *); 355 extern void ndmp_door_put_buf(ndmp_door_ctx_t *, unsigned char *, int); 356 extern int ndmp_door_get_buf(ndmp_door_ctx_t *, unsigned char *, int); 357 358 extern int ndmp_include_zfs(ndmp_context_t *, const char *); 359 extern int ndmp_iter_zfs(ndmp_context_t *, int (*)(nvlist_t *, void *), void *); 360 extern uint_t ndmp_context_get_version(ndmp_context_t *); 361 extern void ndmp_context_set_specific(ndmp_context_t *, void *); 362 extern void *ndmp_context_get_specific(ndmp_context_t *); 363 364 #ifdef __cplusplus 365 } 366 #endif 367 368 #endif /* _LIBNDMP_H */ 369