2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015 by Delphix. All rights reserved.
9 * Copyright (c) 2007, The Storage Networking Industry Association.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
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
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
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.
39 /* Copyright (c) 2007, The Storage Networking Industry Association. */
40 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
41 /* Copyright 2014 Nexenta Systems, Inc. All rights reserved. */
46 #include <sys/types.h>
48 #include <ndmpd_door.h>
50 #include "ndmpd_common.h"
51 #include "tlm_buffers.h"
53 #include "ndmpd_prop.h"
59 #define MAX_RECORD_SIZE (126*512)
60 #define REMOTE_RECORD_SIZE (60*KILOBYTE)
61 #define SCSI_MAX_NAME 32
62 #define MD5_CHALLENGE_SIZE 64
63 #define MD5_PASS_LIMIT 32
66 #define TUR_WAIT 3000000
70 /* File handler classes */
74 #define HC_ALL 0xffffffff
77 (*(struct in_addr *)&x)
79 #define FS_READONLY(fs) (hasmntopt(fs, "ro") ? 1 : 0)
81 typedef void *(*funct_t
)(void *); /* function pointer */
83 #define HOSTNAMELEN 256
85 #define VENDOR_NAME "Sun Microsystems"
86 #define PRODUCT_NAME "Solaris 5.11"
89 * Calculate array length based on its size and size of
92 #define ARRAY_LEN(a, t) (sizeof (a) / sizeof (t))
94 * Default maximum permitted sequence number for the token-based backup.
96 #define NDMP_MAX_TOKSEQ 9
99 * Hard-limit for the sequence number in the token-based backup.
100 * It's one less than the ASCII value of 'A'. The 'A' letter
101 * can be used as level in the lbr-type backups.
103 #define NDMP_TOKSEQ_HLIMIT ('A' - 1)
107 * Soft-limit for the sequence number in the token-based backup.
109 #define NDMP_TOKSEQ_SLIMIT (NDMP_TOKSEQ_HLIMIT - 5)
113 * Root inode number of dump format in V2.
118 * NDMP backup image signature
120 #define NDMPUTF8MAGIC "NDMPUTF8MAGIC"
125 #define NDMP_TAR_TYPE "tar"
126 #define NDMP_DUMP_TYPE "dump"
127 #define NDMP_ZFS_TYPE "zfs"
129 /* All 1's binary maximum mover window */
130 #define MAX_WINDOW_SIZE 0xffffffffffffffffULL
132 #define NDMP_FREE(cp) { free((char *)(cp)); (cp) = NULL; }
134 #define NDMP_YORN(f) ((f) ? 'Y' : 'N')
135 #define NDMP_TORF(f) ((f) ? "TRUE" : "FALSE")
136 #define NDMP_SVAL(cp) ((cp) ? (cp) : "NULL")
138 #define NDMP_SETENV(env, nm, val) \
145 #define NDMP_CL_ADDR_LEN 24
146 #define NDMP_TCP_ADDR_SIZE 32
147 #define NDMP_TAPE_DEV_NAME 256
151 int bk_llevel
; /* last backup level */
152 time_t bk_ldate
; /* last backup date */
153 int bk_clevel
; /* current backup level */
154 time_t bk_cdate
; /* current backup date */
158 char **bk_exl
; /* exlude list */
159 char **bk_inc
; /* include list */
160 } ndmp_backup_params_t
;
164 ulong_t rs_nf
; /* number of files to restore */
170 } ndmp_restore_params_t
;
173 * Tar format archiving ops table
175 extern tm_ops_t tm_tar_ops
;
178 * IS_LBR_BKTYPE shows if the backup type is one of these
179 * 'F' of 'f': 'Full' backup type.
180 * 'A' of 'a': 'Archive' backup type.
181 * 'I' of 'i': 'Incremental' backup type.
182 * 'D' of 'd': 'Differntial' backup type.
184 #define IS_LBR_BKTYPE(t) (((t) && strchr("FAID", toupper(t))) ? 1 : 0)
190 #define NLPF_CHKPNTED_PATH (1 << 0)
191 #define NLPF_FH (1 << 1)
192 #define NLPF_DIRECT (1 << 2)
193 #define NLPF_UPDATE (1 << 3)
194 #define NLPF_DUMP (1 << 4)
195 #define NLPF_TAR (1 << 5)
196 #define NLPF_ABORTED (1 << 6)
197 #define NLPF_TOKENBK (1 << 8)
198 #define NLPF_LBRBK (1 << 9)
199 #define NLPF_LEVELBK (1 << 10)
200 #define NLPF_IGNCTIME (1 << 11)
201 #define NLPF_INCLMTIME (1 << 12)
202 #define NLPF_RECURSIVE (1 << 13)
205 * Macros on NLP flags.
207 #define NLP_ISSET(n, f) (((n)->nlp_flags & (f)) != 0)
208 #define NLP_SET(n, f) (n)->nlp_flags |= (f)
209 #define NLP_UNSET(n, f) (n)->nlp_flags &= ~(f)
212 #define NLP_ISCHKPNTED(n) NLP_ISSET(n, NLPF_CHKPNTED_PATH)
213 #define NLP_SHOULD_UPDATE(n) NLP_ISSET(n, NLPF_UPDATE)
214 #define NLP_ISDUMP(n) NLP_ISSET(n, NLPF_DUMP)
215 #define NLP_ISTAR(n) NLP_ISSET(n, NLPF_TAR)
216 #define NLP_IGNCTIME(n) NLP_ISSET(n, NLPF_IGNCTIME)
217 #define NLP_INCLMTIME(n) NLP_ISSET(n, NLPF_INCLMTIME)
222 #define NS_INC(s) (atomic_inc_32((volatile uint32_t *)&ndstat.ns_##s))
223 #define NS_DEC(s) (atomic_dec_32((volatile uint32_t *)&ndstat.ns_##s))
224 #define NS_ADD(s, d) (atomic_add_64((volatile uint64_t *)&ndstat.ns_##s, \
226 #define NS_UPD(s, t) { \
227 atomic_inc_32((volatile uint32_t *)&ndstat.ns_##s); \
228 atomic_dec_32((volatile uint32_t *)&ndstat.ns_##t); \
233 typedef struct ndmp_lbr_params
{
234 struct ndmpd_session
*nlp_session
;
237 ndmp_backup_params_t bk_params
;
238 ndmp_restore_params_t rs_params
;
239 #define nlp_backup_path bk_params.bk_path
240 #define nlp_llevel bk_params.bk_llevel
241 #define nlp_ldate bk_params.bk_ldate
242 #define nlp_clevel bk_params.bk_clevel
243 #define nlp_tokseq nlp_clevel
244 #define nlp_tokdate nlp_ldate
245 #define nlp_cdate bk_params.bk_cdate
246 #define nlp_bkmap bk_params.bk_map
247 #define nlp_bkdirino bk_params.bk_dirino
248 #define nlp_dmpnm bk_params.bk_dmpnm
249 #define nlp_exl bk_params.bk_exl
250 #define nlp_inc bk_params.bk_inc
252 #define nlp_nfiles rs_params.rs_nf
253 #define nlp_restore_path rs_params.rs_path
254 #define nlp_restore_bk_path rs_params.rs_bkpath
255 #define nlp_restored rs_params.rs_restored
256 #define nlp_rsbm rs_params.rs_bm
257 #define nlp_lastidx rs_params.rs_lastidx
259 ndmpd_module_params_t
*nlp_params
;
260 tlm_job_stats_t
*nlp_jstat
;
261 lbr_fhlog_call_backs_t
*nlp_logcallbacks
;
262 tlm_commands_t nlp_cmds
;
264 cond_t nlp_cv
; /* for signaling a processed request */
265 mutex_t nlp_mtx
; /* mutex to synchronize access to nlp_cv */
266 u_longlong_t nlp_bytes_total
;
270 typedef struct mem_ndmp_name_v3
{
274 u_longlong_t nm3_node
;
275 u_longlong_t nm3_fh_info
;
277 } mem_ndmp_name_v3_t
;
279 typedef struct ndmpd_file_handler
{
284 ndmpd_file_handler_func_t
*fh_func
;
285 struct ndmpd_file_handler
*fh_next
;
286 } ndmpd_file_handler_t
;
288 typedef struct ndmpd_session_scsi_desc
{
291 boolean_t sd_valid_target_set
;
294 char sd_adapter_name
[SCSI_MAX_NAME
];
295 } ndmpd_session_scsi_desc_t
;
297 typedef struct ndmpd_session_tape_desc
{
298 int td_fd
; /* tape device file descriptor */
299 ulong_t td_record_count
; /* number of records written */
300 ndmp_tape_open_mode td_mode
; /* tape device open mode */
301 u_longlong_t td_pos
; /* current position on the current tape */
304 char td_adapter_name
[SCSI_MAX_NAME
];
305 } ndmpd_session_tape_desc_t
;
307 typedef struct ndmpd_session_mover_desc
{
308 ndmp_mover_state md_state
; /* current state */
309 ndmp_mover_mode md_mode
; /* current mode */
310 ndmp_mover_pause_reason md_pause_reason
; /* current reason */
311 ndmp_mover_halt_reason md_halt_reason
; /* current reason */
312 u_longlong_t md_data_written
; /* total written to tape */
313 u_longlong_t md_seek_position
; /* current seek position */
314 u_longlong_t md_bytes_left_to_read
; /* #bytes to end of seek window */
315 u_longlong_t md_window_offset
; /* valid data window begin */
316 u_longlong_t md_window_length
; /* valid data window length */
317 u_longlong_t md_position
; /* current data stream pos */
318 boolean_t md_pre_cond
; /* used for precondition checks */
319 ulong_t md_record_size
; /* tape I/O record size */
320 ulong_t md_record_num
; /* current record num */
321 int md_listen_sock
; /* data conn listen socket */
322 int md_sock
; /* data conn socket */
323 ulong_t md_r_index
; /* buffer read index */
324 ulong_t md_w_index
; /* buffer write index */
325 char *md_buf
; /* data buffer */
329 ulong_t md_discard_length
; /* bytes to discard */
334 ndmp_addr_v3 md_data_addr
;
338 ndmp_addr_v4 md_data_addr_v4
;
339 } ndmpd_session_mover_desc_t
;
342 typedef struct ndmpd_session_data_module
{
343 void *dm_module_cookie
; /* sent as abort_func param */
344 module_start_func_t
*dm_start_func
; /* start function */
345 module_abort_func_t
*dm_abort_func
; /* abort function */
346 ndmpd_module_stats dm_stats
; /* statistics buffer */
347 } ndmpd_session_data_module_t
;
349 typedef struct ndmpd_session_data_desc
{
353 ndmp_data_operation dd_operation
; /* current operation */
354 boolean_t dd_abort
; /* abort operation flag */
355 boolean_t dd_io_ready
; /* mover sock read for I/O */
356 ndmp_pval
*dd_env
; /* environment from backup or recover request */
357 ulong_t dd_env_len
; /* environment length */
358 ulong_t dd_nlist_len
; /* recover file list length */
359 int dd_sock
; /* listen and data socket */
360 u_longlong_t dd_read_offset
; /* data read seek offset */
361 u_longlong_t dd_read_length
; /* data read length */
362 u_longlong_t dd_data_size
; /* data size to be backed up */
363 ndmpd_session_data_module_t dd_module
;
365 ndmp_data_state dd_state
; /* current state */
366 ndmp_data_halt_reason dd_halt_reason
; /* current reason */
370 ndmp_name
*dd_nlist
; /* recover file list */
371 ndmp_mover_addr dd_mover
; /* mover address */
375 mem_ndmp_name_v3_t
*dd_nlist_v3
;
376 ndmp_addr_v3 dd_data_addr
;
377 int dd_listen_sock
; /* socket for listening for remote */
378 /* mover connections */
379 u_longlong_t dd_bytes_left_to_read
;
380 u_longlong_t dd_position
;
381 u_longlong_t dd_discard_length
;
385 ndmp_addr_v4 dd_data_addr_v4
;
386 } ndmpd_session_data_desc_t
;
388 typedef struct ndmpd_session_file_history
{
389 ndmp_fh_unix_path
*fh_path_entries
;
390 ndmp_fh_unix_dir
*fh_dir_entries
;
391 ndmp_fh_unix_node
*fh_node_entries
;
392 char *fh_path_name_buf
;
393 char *fh_dir_name_buf
;
394 ulong_t fh_path_index
;
395 ulong_t fh_dir_index
;
396 ulong_t fh_node_index
;
397 ulong_t fh_path_name_buf_index
;
398 ulong_t fh_dir_name_buf_index
;
399 } ndmpd_session_file_history_t
;
401 typedef struct ndmpd_session_file_history_v3
{
402 ndmp_file_v3
*fh_files
;
403 ndmp_dir_v3
*fh_dirs
;
404 ndmp_node_v3
*fh_nodes
;
405 ndmp_file_name_v3
*fh_file_names
;
406 ndmp_file_name_v3
*fh_dir_names
;
407 ndmp_file_stat_v3
*fh_file_stats
;
408 ndmp_file_stat_v3
*fh_node_stats
;
409 char *fh_file_name_buf
;
410 char *fh_dir_name_buf
;
411 ulong_t fh_file_index
;
412 ulong_t fh_dir_index
;
413 ulong_t fh_node_index
;
414 ulong_t fh_file_name_buf_index
;
415 ulong_t fh_dir_name_buf_index
;
416 } ndmpd_session_file_history_v3_t
;
419 * zfs-based backup (zfs send/recv)
431 NDMPD_ZFS_PROP_MAJOR_0
,
432 } ndmpd_zfs_prop_major_t
;
435 NDMPD_ZFS_PROP_MINOR_0
,
436 } ndmpd_zfs_prop_minor_t
;
438 #define NDMPD_ZFS_MAJOR_VERSION NDMPD_ZFS_MAJOR_0
439 #define NDMPD_ZFS_MINOR_VERSION NDMPD_ZFS_MINOR_0
440 #define NDMPD_ZFS_PROP_MAJOR_VERSION NDMPD_ZFS_PROP_MAJOR_0
441 #define NDMPD_ZFS_PROP_MINOR_VERSION NDMPD_ZFS_PROP_MINOR_0
445 char nzh_magic
[14]; /* NDMPUTF8MAGIC\0 */
446 uint32_t nzh_major
; /* major version */
447 uint32_t nzh_minor
; /* minor version */
448 uint32_t nzh_hdrlen
; /* length of hdr in bytes including magic */
449 /* future extensions */
450 } ndmpd_zfs_header_t
;
456 #define NDMPD_ZFS_DMP_NAME_MAX 32
458 typedef struct ndmpd_zfs_args
{
459 zfs_type_t nz_type
; /* type of ZFS dataset */
460 char nz_dataset
[ZFS_MAX_DATASET_NAME_LEN
]; /* dataset name */
461 char nz_snapname
[ZFS_MAX_DATASET_NAME_LEN
]; /* snapname (following @) */
462 char nz_fromsnap
[ZFS_MAX_DATASET_NAME_LEN
]; /* snap of L-1 bkup */
463 char nz_snapprop
[ZFS_MAXPROPLEN
]; /* contents of snap incr prop */
464 boolean_t nz_ndmpd_snap
; /* ndmpd-generated snap? */
466 pthread_t nz_sendrecv_thread
; /* thread for send/recv */
467 pthread_t nz_tape_thread
; /* thread for tape r/w */
468 int32_t nz_pipe_fd
[2]; /* pipe for above 2 threads */
469 int32_t nz_bufsize
; /* tape r/w buf size */
470 int64_t nz_window_len
; /* DMA window length */
472 int nz_level
; /* val of LEVEL env var */
473 char nz_zfs_mode
; /* val of ZFS_MODE env var */
474 boolean_t nz_zfs_force
; /* val of ZFS_FORCE env var */
475 boolean_t nz_update
; /* val of UPDATE env var */
476 char nz_dmp_name
[NDMPD_ZFS_DMP_NAME_MAX
]; /* val of DMP_NAME env var */
477 u_longlong_t nz_zfs_backup_size
; /* used for restore only */
479 ndmpd_module_params_t nz_params
;
480 ndmp_lbr_params_t
*nz_nlp
;
481 libzfs_handle_t
*nz_zlibh
; /* session-specific lzfs hdl */
482 ndmp_context_t nz_nctx
; /* used by plugin */
484 ndmpd_zfs_header_t nz_tape_header
; /* tape hdr for "zfs" backup */
487 #define ndmpd_zfs_params (&(ndmpd_zfs_args)->nz_params)
489 typedef struct ndmpd_session
{
490 ndmp_connection_t
*ns_connection
; /* NDMP connection to client */
491 boolean_t ns_eof
; /* connection EOF flag */
492 ushort_t ns_protocol_version
; /* connection protocol version */
493 ndmpd_session_scsi_desc_t ns_scsi
;
494 ndmpd_session_tape_desc_t ns_tape
;
495 ndmpd_session_mover_desc_t ns_mover
;
496 ndmpd_session_data_desc_t ns_data
;
497 ndmpd_session_file_history_t ns_fh
;
498 ndmpd_file_handler_t
*ns_file_handler_list
; /* for I/O multiplexing */
500 ndmp_lbr_params_t
*ns_ndmp_lbr_params
;
501 struct ndmpd_zfs_args ns_ndmpd_zfs_args
;
502 ndmpd_backup_type_t ns_butype
;
507 * Tape, SCSI, mover, data and file handlers will
508 * be shared between V2 and V3.
510 ndmpd_session_file_history_v3_t ns_fh_v3
;
511 unsigned char ns_challenge
[MD5_CHALLENGE_SIZE
]; /* For MD5 */
514 * NDMP V4 related data
516 boolean_t ns_get_ext_list
;
517 boolean_t ns_set_ext_list
;
519 /* handling of hardlink, hardlink queue head */
520 struct hardlink_q
*hardlink_q
;
525 * NDMP request handler functions.
529 ndmp_msg_handler_func_t ndmpd_config_get_host_info_v2
;
530 ndmp_msg_handler_func_t ndmpd_config_get_butype_attr_v2
;
531 ndmp_msg_handler_func_t ndmpd_config_get_mover_type_v2
;
532 ndmp_msg_handler_func_t ndmpd_config_get_auth_attr_v2
;
534 ndmp_msg_handler_func_t ndmpd_config_get_host_info_v3
;
535 ndmp_msg_handler_func_t ndmpd_config_get_butype_info_v3
;
536 ndmp_msg_handler_func_t ndmpd_config_get_connection_type_v3
;
537 ndmp_msg_handler_func_t ndmpd_config_get_auth_attr_v3
;
538 ndmp_msg_handler_func_t ndmpd_config_get_fs_info_v3
;
539 ndmp_msg_handler_func_t ndmpd_config_get_tape_info_v3
;
540 ndmp_msg_handler_func_t ndmpd_config_get_scsi_info_v3
;
541 ndmp_msg_handler_func_t ndmpd_config_get_server_info_v3
;
543 ndmp_msg_handler_func_t ndmpd_config_get_butype_info_v4
;
544 ndmp_msg_handler_func_t ndmpd_config_get_ext_list_v4
;
545 ndmp_msg_handler_func_t ndmpd_config_set_ext_list_v4
;
549 ndmp_msg_handler_func_t ndmpd_scsi_open_v2
;
550 ndmp_msg_handler_func_t ndmpd_scsi_close_v2
;
551 ndmp_msg_handler_func_t ndmpd_scsi_get_state_v2
;
552 ndmp_msg_handler_func_t ndmpd_scsi_set_target_v2
;
553 ndmp_msg_handler_func_t ndmpd_scsi_reset_device_v2
;
554 ndmp_msg_handler_func_t ndmpd_scsi_reset_bus_v2
;
555 ndmp_msg_handler_func_t ndmpd_scsi_execute_cdb_v2
;
557 ndmp_msg_handler_func_t ndmpd_scsi_open_v3
;
558 ndmp_msg_handler_func_t ndmpd_scsi_set_target_v3
;
562 ndmp_msg_handler_func_t ndmpd_tape_open_v2
;
563 ndmp_msg_handler_func_t ndmpd_tape_close_v2
;
564 ndmp_msg_handler_func_t ndmpd_tape_get_state_v2
;
565 ndmp_msg_handler_func_t ndmpd_tape_mtio_v2
;
566 ndmp_msg_handler_func_t ndmpd_tape_write_v2
;
567 ndmp_msg_handler_func_t ndmpd_tape_read_v2
;
568 ndmp_msg_handler_func_t ndmpd_tape_execute_cdb_v2
;
570 ndmp_msg_handler_func_t ndmpd_tape_open_v3
;
571 ndmp_msg_handler_func_t ndmpd_tape_get_state_v3
;
572 ndmp_msg_handler_func_t ndmpd_tape_write_v3
;
573 ndmp_msg_handler_func_t ndmpd_tape_read_v3
;
576 ndmp_msg_handler_func_t ndmpd_tape_close_v4
;
578 ndmp_msg_handler_func_t ndmpd_data_get_state_v2
;
579 ndmp_msg_handler_func_t ndmpd_data_start_backup_v2
;
580 ndmp_msg_handler_func_t ndmpd_data_start_recover_v2
;
581 ndmp_msg_handler_func_t ndmpd_data_get_env_v2
;
582 ndmp_msg_handler_func_t ndmpd_data_stop_v2
;
583 ndmp_msg_handler_func_t ndmpd_data_abort_v2
;
585 ndmp_msg_handler_func_t ndmpd_data_get_state_v3
;
586 ndmp_msg_handler_func_t ndmpd_data_connect_v3
;
587 ndmp_msg_handler_func_t ndmpd_data_listen_v3
;
588 ndmp_msg_handler_func_t ndmpd_data_stop_v3
;
589 ndmp_msg_handler_func_t ndmpd_data_abort_v3
;
590 ndmp_msg_handler_func_t ndmpd_data_start_recover_v3
;
591 ndmp_msg_handler_func_t ndmpd_data_start_backup_v3
;
593 ndmp_msg_handler_func_t ndmpd_data_get_env_v4
;
594 ndmp_msg_handler_func_t ndmpd_data_get_state_v4
;
595 ndmp_msg_handler_func_t ndmpd_data_connect_v4
;
596 ndmp_msg_handler_func_t ndmpd_data_listen_v4
;
597 ndmp_msg_handler_func_t ndmpd_data_start_recover_filehist_v4
;
601 ndmp_msg_handler_func_t ndmpd_connect_open_v2
;
602 ndmp_msg_handler_func_t ndmpd_connect_client_auth_v2
;
603 ndmp_msg_handler_func_t ndmpd_connect_server_auth_v2
;
604 ndmp_msg_handler_func_t ndmpd_connect_close_v2
;
606 ndmp_msg_handler_func_t ndmpd_connect_client_auth_v3
;
607 ndmp_msg_handler_func_t ndmpd_connect_close_v3
;
611 ndmp_msg_handler_func_t ndmpd_mover_get_state_v2
;
612 ndmp_msg_handler_func_t ndmpd_mover_listen_v2
;
613 ndmp_msg_handler_func_t ndmpd_mover_continue_v2
;
614 ndmp_msg_handler_func_t ndmpd_mover_abort_v2
;
615 ndmp_msg_handler_func_t ndmpd_mover_stop_v2
;
616 ndmp_msg_handler_func_t ndmpd_mover_set_window_v2
;
617 ndmp_msg_handler_func_t ndmpd_mover_read_v2
;
618 ndmp_msg_handler_func_t ndmpd_mover_close_v2
;
619 ndmp_msg_handler_func_t ndmpd_mover_set_record_size_v2
;
621 ndmp_msg_handler_func_t ndmpd_mover_get_state_v3
;
622 ndmp_msg_handler_func_t ndmpd_mover_listen_v3
;
623 ndmp_msg_handler_func_t ndmpd_mover_continue_v3
;
624 ndmp_msg_handler_func_t ndmpd_mover_abort_v3
;
625 ndmp_msg_handler_func_t ndmpd_mover_set_window_v3
;
626 ndmp_msg_handler_func_t ndmpd_mover_read_v3
;
627 ndmp_msg_handler_func_t ndmpd_mover_set_record_size_v3
;
628 ndmp_msg_handler_func_t ndmpd_mover_connect_v3
;
631 ndmp_msg_handler_func_t ndmpd_mover_get_state_v4
;
632 ndmp_msg_handler_func_t ndmpd_mover_listen_v4
;
633 ndmp_msg_handler_func_t ndmpd_mover_connect_v4
;
637 * Backup/recover module API functions.
639 ndmpd_get_env_func_t ndmpd_api_get_env
;
640 ndmpd_add_env_func_t ndmpd_api_add_env
;
641 ndmpd_add_env_func_t ndmpd_api_set_env
;
642 ndmpd_get_name_func_t ndmpd_api_get_name
;
643 ndmpd_dispatch_func_t ndmpd_api_dispatch
;
644 ndmpd_done_func_t ndmpd_api_done_v2
;
647 ndmpd_write_func_t ndmpd_api_write_v2
;
648 ndmpd_file_history_path_func_t ndmpd_api_file_history_path_v2
;
649 ndmpd_file_history_dir_func_t ndmpd_api_file_history_dir_v2
;
650 ndmpd_file_history_node_func_t ndmpd_api_file_history_node_v2
;
651 ndmpd_read_func_t ndmpd_api_read_v2
;
652 ndmpd_seek_func_t ndmpd_api_seek_v2
;
653 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v2
;
654 ndmpd_add_file_handler_func_t ndmpd_api_add_file_handler
;
655 ndmpd_remove_file_handler_func_t ndmpd_api_remove_file_handler
;
661 ndmpd_done_func_t ndmpd_api_done_v3
;
662 ndmpd_write_func_t ndmpd_api_write_v3
;
663 ndmpd_read_func_t ndmpd_api_read_v3
;
664 ndmpd_seek_func_t ndmpd_api_seek_v3
;
665 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v3
;
666 ndmpd_get_name_func_t ndmpd_api_get_name_v3
;
667 ndmpd_file_history_path_func_t ndmpd_api_file_history_file_v3
;
668 ndmpd_file_history_dir_func_t ndmpd_api_file_history_dir_v3
;
669 ndmpd_file_history_node_func_t ndmpd_api_file_history_node_v3
;
674 ndmpd_log_func_v3_t ndmpd_api_log_v4
;
675 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v4
;
677 #ifndef NO_NDMP_API_LOG_PROTOTYPES
678 ndmpd_log_func_t ndmpd_api_log_v2
;
679 ndmpd_log_func_v3_t ndmpd_api_log_v3
;
680 #endif /* NO_NDMP_API_LOG_PROTOTYPES */
682 typedef void ndmpd_func_t(ndmp_connection_t
*, void *);
685 * pthread call arg parameters
690 ndmp_con_handler_func_t nw_con_handler_func
;
691 } ndmpd_worker_arg_t
;
695 ndmp_lbr_params_t
*br_nlp
;
696 tlm_commands_t
*br_cmds
;
697 pthread_barrier_t br_barrier
;
698 } backup_reader_arg_t
;
701 ndmpd_session_t
*tr_session
;
702 ndmpd_module_params_t
*tr_mod_params
;
703 tlm_commands_t
*tr_cmds
;
704 } ndmp_tar_reader_arg_t
;
707 ndmpd_session_t
*bs_session
;
710 } ndmp_bkup_size_arg_t
;
713 * Variables from ndmpd_comm.c
716 extern int ndmp_full_restore_path
;
717 extern int ndmp_dar_support
;
718 extern int ndmp_port
;
719 extern ndmp_stat_t ndstat
;
721 extern void ndmpd_main(void);
722 extern void connection_handler(ndmp_connection_t
*);
723 extern void ndmpd_audit_backup(ndmp_connection_t
*conn
, char *path
,
724 int dest
, char *local_path
, int result
);
725 extern void ndmpd_audit_restore(ndmp_connection_t
*conn
,
726 char *path
, int dest
, char *local_path
, int result
);
727 extern void ndmpd_audit_connect(ndmp_connection_t
*conn
,
729 extern void ndmpd_audit_disconnect(ndmp_connection_t
*conn
);
731 /* Variables from ndmpd_main.c */
732 extern libzfs_handle_t
*zlibh
;
733 extern mutex_t zlib_mtx
;
736 * Utility from ndmpd_connect.c.
738 extern int ndmp_connect_list_add(ndmp_connection_t
*, int *);
739 extern int ndmp_connect_list_del(ndmp_connection_t
*);
740 extern int ndmpd_connect_kill_id(int);
741 extern void ndmp_connect_list_get(ndmp_door_ctx_t
*);
742 extern void ndmpd_get_devs(ndmp_door_ctx_t
*);
745 * Utility functions form ndmpd_data.c.
747 extern void ndmpd_data_cleanup(ndmpd_session_t
*);
748 extern int ndmpd_data_init(ndmpd_session_t
*);
749 extern char *ndmp_data_get_mover_mode(ndmpd_session_t
*);
750 extern void ndmpd_data_error(ndmpd_session_t
*, ndmp_data_halt_reason
);
754 * Utility functions from ndmpd_mover.c.
756 extern int ndmpd_mover_init(ndmpd_session_t
*);
757 extern void ndmpd_mover_cleanup(ndmpd_session_t
*);
758 extern ndmp_error
ndmpd_mover_connect(ndmpd_session_t
*,
760 extern void ndmpd_mover_error(ndmpd_session_t
*,
761 ndmp_mover_halt_reason
);
762 extern int ndmpd_mover_seek(ndmpd_session_t
*,
765 extern int ndmpd_local_write(ndmpd_session_t
*,
768 extern int ndmpd_remote_write(ndmpd_session_t
*,
771 extern int ndmpd_local_read(ndmpd_session_t
*,
774 extern int ndmpd_remote_read(ndmpd_session_t
*,
778 extern void ndmpd_mover_shut_down(ndmpd_session_t
*);
779 extern void ndmpd_mover_error(ndmpd_session_t
*,
780 ndmp_mover_halt_reason
);
781 extern int ndmpd_local_write_v3(ndmpd_session_t
*,
784 extern int ndmpd_local_read_v3(ndmpd_session_t
*,
787 extern int ndmpd_remote_read_v3(ndmpd_session_t
*,
793 * Utility functions from ndmpd_file_history.c
795 extern void ndmpd_file_history_init(ndmpd_session_t
*);
796 extern void ndmpd_file_history_cleanup(ndmpd_session_t
*,
798 extern int ndmpd_file_history_path(lbr_fhlog_call_backs_t
*,
802 extern int ndmpd_file_history_dir(lbr_fhlog_call_backs_t
*,
805 extern int ndmpd_file_history_node(lbr_fhlog_call_backs_t
*,
811 ndmpd_path_restored(lbr_fhlog_call_backs_t
*,
815 extern int ndmpd_fhpath_v3_cb(lbr_fhlog_call_backs_t
*,
819 extern int ndmpd_fhdir_v3_cb(lbr_fhlog_call_backs_t
*,
822 extern int ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t
*,
827 extern int ndmpd_path_restored_v3(lbr_fhlog_call_backs_t
*,
832 extern int ndmp_send_recovery_stat_v3(ndmpd_module_params_t
*,
839 * Utility functions from ndmpd_dtime.c
841 extern int ndmpd_put_dumptime(char *, int, time_t);
842 extern int ndmpd_get_dumptime(char *, int *, time_t *);
843 extern int ndmpd_append_dumptime(char *, char *, int, time_t);
847 * Global variables from ndmpd_tar3.c
849 extern char **ndmp_excl_list
;
853 * Global variables from ndmpd_util.c
855 extern int ndmp_force_bk_dirs
;
858 extern boolean_t ndmp_dump_path_node
;
859 extern boolean_t ndmp_tar_path_node
;
860 extern boolean_t ndmp_ignore_ctime
;
861 extern boolean_t ndmp_include_lmtime
;
865 * Utility functions from ndmpd_util.c.
867 extern int ndmpd_select(ndmpd_session_t
*,
871 extern ndmp_error
ndmpd_save_env(ndmpd_session_t
*,
875 extern void ndmpd_free_env(ndmpd_session_t
*);
876 extern ndmp_error
ndmpd_save_nlist_v2(ndmpd_session_t
*,
880 extern void ndmpd_free_nlist(ndmpd_session_t
*);
881 extern int ndmpd_add_file_handler(ndmpd_session_t
*,
886 ndmpd_file_handler_func_t
*);
888 extern int ndmpd_remove_file_handler(ndmpd_session_t
*,
891 extern void ndmp_send_reply(ndmp_connection_t
*,
895 extern int ndmp_mtioctl(int, int, int);
897 extern u_longlong_t
quad_to_long_long(ndmp_u_quad
);
898 extern ndmp_u_quad
long_long_to_quad(u_longlong_t
);
900 extern void set_socket_options(int sock
);
902 extern long ndmp_buffer_get_size(ndmpd_session_t
*);
903 extern int ndmp_lbr_init(ndmpd_session_t
*);
904 extern void ndmp_lbr_cleanup(ndmpd_session_t
*);
906 extern int ndmp_wait_for_mover(ndmpd_session_t
*);
907 extern boolean_t
is_buffer_erroneous(tlm_buffer_t
*);
908 extern void ndmp_execute_cdb(ndmpd_session_t
*,
912 ndmp_execute_cdb_request
*);
914 extern scsi_adapter_t
*scsi_get_adapter(int);
915 extern boolean_t
is_tape_unit_ready(char *, int);
917 extern int ndmp_open_list_add(ndmp_connection_t
*, char *, int, int, int);
918 extern int ndmp_open_list_del(char *, int, int);
919 extern void ndmp_open_list_release(ndmp_connection_t
*);
921 extern void ndmp_stop_buffer_worker(ndmpd_session_t
*);
922 extern void ndmp_stop_reader_thread(ndmpd_session_t
*);
923 extern void ndmp_stop_writer_thread(ndmpd_session_t
*);
924 extern void ndmp_free_reader_writer_ipc(ndmpd_session_t
*);
925 extern void ndmp_waitfor_op(ndmpd_session_t
*);
927 extern char *cctime(time_t *);
928 extern char *ndmp_new_job_name(char *);
929 extern char *ndmpd_mk_temp(char *);
930 extern char *ndmpd_make_bk_dir_path(char *, char *);
931 extern boolean_t
ndmp_is_chkpnt_root(char *);
932 extern char **ndmpd_make_exc_list(void);
933 extern void ndmp_sort_nlist_v3(ndmpd_session_t
*);
934 extern int ndmp_get_bk_dir_ino(ndmp_lbr_params_t
*);
935 extern int ndmp_write_utf8magic(tlm_cmd_t
*);
936 extern int ndmp_tar_writer(ndmpd_session_t
*,
937 ndmpd_module_params_t
*,
939 extern void ndmp_wait_for_reader(tlm_commands_t
*);
940 extern ndmp_error
ndmpd_save_nlist_v3(ndmpd_session_t
*,
943 extern void ndmpd_free_nlist_v3(ndmpd_session_t
*);
944 extern int ndmp_create_socket(ulong_t
*, ushort_t
*);
945 extern int ndmp_connect_sock_v3(ulong_t
, ushort_t
);
946 extern void ndmp_copy_addr_v3(ndmp_addr_v3
*, ndmp_addr_v3
*);
947 extern void ndmp_copy_addr_v4(ndmp_addr_v4
*, ndmp_addr_v4
*);
948 extern char *ndmp_addr2str_v3(ndmp_addr_type
);
949 extern boolean_t
ndmp_valid_v3addr_type(ndmp_addr_type
);
950 extern boolean_t
ndmp_check_utf8magic(tlm_cmd_t
*);
951 extern int ndmp_get_cur_bk_time(ndmp_lbr_params_t
*,
953 extern char *ndmp_get_relative_path(char *, char *);
955 extern boolean_t ndmp_fhinode
;
956 extern void ndmp_load_params(void);
957 extern void randomize(unsigned char *, int);
961 * Utility functions from ndmpd_tar3.c.
963 extern ndmp_error
ndmp_restore_get_params_v3(ndmpd_session_t
*,
964 ndmpd_module_params_t
*);
965 extern ndmp_error
ndmp_backup_get_params_v3(ndmpd_session_t
*,
966 ndmpd_module_params_t
*);
969 * door init and fini function from ndmpd_door_serv.c
971 extern int ndmp_door_init(void);
972 extern void ndmp_door_fini(void);
973 extern boolean_t
ndmp_door_check(void);
975 extern int ndmp_get_max_tok_seq(void);
977 extern int get_zfsvolname(char *, int, char *);
978 extern int ndmp_create_snapshot(char *, char *);
979 extern int ndmp_remove_snapshot(char *, char *);
980 extern int ndmpd_mark_inodes_v2(ndmpd_session_t
*, ndmp_lbr_params_t
*);
981 extern void ndmpd_abort_marking_v2(ndmpd_session_t
*);
982 extern int ndmpd_mark_inodes_v3(ndmpd_session_t
*, ndmp_lbr_params_t
*);
983 extern ndmp_lbr_params_t
*ndmp_get_nlp(void *);
985 module_start_func_t ndmpd_tar_backup_starter
;
986 module_abort_func_t ndmpd_tar_backup_abort
;
988 module_start_func_t ndmpd_tar_restore_starter
;
989 module_abort_func_t ndmpd_tar_restore_abort
;
991 module_start_func_t ndmpd_tar_backup_starter_v3
;
992 module_abort_func_t ndmpd_tar_backup_abort_v3
;
994 module_start_func_t ndmpd_tar_restore_starter_v3
;
995 module_abort_func_t ndmpd_tar_restore_abort_v3
;
997 extern int ndmp_backup_extract_params(ndmpd_session_t
*,
998 ndmpd_module_params_t
*);
999 extern int ndmp_restore_extract_params(ndmpd_session_t
*,
1000 ndmpd_module_params_t
*);
1001 extern int ndmp_tar_reader(ndmp_tar_reader_arg_t
*);
1003 extern int tape_open(char *, int);
1004 extern int tape_is_at_bot(ndmpd_session_t
*);
1005 extern int tape_is_at_bof(ndmpd_session_t
*);
1006 extern void fm_dance(ndmpd_session_t
*);
1008 extern void ndmp_session_ref(ndmpd_session_t
*);
1009 extern void ndmp_session_unref(ndmpd_session_t
*);
1011 void ndmpd_get_file_entry_type(int, ndmp_file_type
*);
1013 extern int tcp_accept(int, unsigned int *);
1014 extern int tcp_get_peer(int, unsigned int *, int *);
1016 extern char *gethostaddr(void);
1017 extern char *get_default_nic_addr(void);
1018 extern int tlm_init(void);
1020 extern int snapshot_create(char *, char *, boolean_t
, boolean_t
);
1021 extern int snapshot_destroy(char *, char *, boolean_t
, boolean_t
, int *);
1023 extern boolean_t
fs_is_chkpntvol(char *);
1024 extern boolean_t
fs_is_chkpnt_enabled(char *);
1025 extern boolean_t
fs_is_rdonly(char *);
1026 extern boolean_t
fs_volexist(char *);
1027 extern boolean_t
fs_is_valid_logvol(char *);
1028 extern boolean_t
rootfs_dot_or_dotdot(char *);
1029 extern int dp_readdir(DIR *, unsigned long *, char *,
1030 int *, unsigned long *);
1032 extern void scsi_find_sid_lun();
1033 extern char *sasd_slink_name();
1034 extern int scsi_dev_exists(char *, int, int);
1035 extern int scsi_get_devtype(char *, int, int);
1036 extern struct open_list
*ndmp_open_list_find(char *, int, int);
1037 extern int filecopy(char *, char *);
1039 extern void ndmp_stop_local_reader();
1040 extern void ndmp_stop_remote_reader();
1042 extern boolean_t
match(char *, char *);
1043 extern char *trim_whitespace(char *);
1044 extern int fs_getstat(char *, struct fs_fhandle
*, struct stat64
*);
1045 extern int fs_readdir(struct fs_fhandle
*, char *, long *,
1046 char *, int *, struct fs_fhandle
*, struct stat64
*);
1047 extern int iscreated(ndmp_lbr_params_t
*nlp
, char *name
, tlm_acls_t
*tacl
,
1050 extern int sasd_dev_count(void);
1051 extern struct scsi_link
*sasd_dev_slink(int);
1052 extern struct sasd_drive
*sasd_drive(int);
1053 extern void *ndmp_malloc(size_t size
);
1055 extern ndmp_plugin_t
*ndmp_pl
;
1057 #define NDMP_APILOG(s, t, m, ...) \
1059 if (((ndmpd_session_t *)(s))->ns_protocol_version == NDMPV4) \
1060 (void) ndmpd_api_log_v4(s, t, m, __VA_ARGS__); \
1061 else if (((ndmpd_session_t *)(s))->ns_protocol_version == NDMPV3) \
1062 (void) ndmpd_api_log_v3(s, t, m, __VA_ARGS__); \
1064 (void) ndmpd_api_log_v2(s, __VA_ARGS__); \
1068 * Backup path utility functions
1070 extern char *get_backup_path_v3(ndmpd_module_params_t
*);
1071 extern char *get_backup_path_v2(ndmpd_module_params_t
*);
1074 * Functions for zfs-based backup
1077 module_start_func_t ndmpd_zfs_backup_starter
;
1078 module_start_func_t ndmpd_zfs_restore_starter
;
1079 module_abort_func_t ndmpd_zfs_abort
;
1081 int ndmpd_zfs_init(ndmpd_session_t
*);
1082 void ndmpd_zfs_fini(ndmpd_zfs_args_t
*);
1084 boolean_t
ndmpd_zfs_backup_parms_valid(ndmpd_zfs_args_t
*);
1085 boolean_t
ndmpd_zfs_restore_parms_valid(ndmpd_zfs_args_t
*);
1087 int ndmpd_zfs_pre_backup(ndmpd_zfs_args_t
*);
1088 int ndmpd_zfs_pre_restore(ndmpd_zfs_args_t
*);
1089 int ndmpd_zfs_post_backup(ndmpd_zfs_args_t
*);
1090 int ndmpd_zfs_post_restore(ndmpd_zfs_args_t
*);
1092 void ndmpd_zfs_dma_log(ndmpd_zfs_args_t
*, ndmp_log_type
, char *, ...);
1094 #endif /* _NDMPD_H */