xref: /titanic_50/usr/src/cmd/ndmpd/ndmp/ndmpd.h (revision 6c258465bad88e154b792fa29bed32dfd376ced0)
1 /*
2  * Copyright 2009 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 /* Copyright (c) 2007, The Storage Networking Industry Association. */
40 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
41 
42 #ifndef _NDMPD_H
43 #define	_NDMPD_H
44 
45 #include <sys/types.h>
46 #include <libzfs.h>
47 #include <ndmpd_door.h>
48 #include <libndmp.h>
49 #include "ndmpd_common.h"
50 #include "tlm_buffers.h"
51 #include <dirent.h>
52 #include "ndmpd_prop.h"
53 #include "traverse.h"
54 #include <pthread.h>
55 #include <libndmp.h>
56 #include <atomic.h>
57 
58 #define	MAX_RECORD_SIZE (126*512)
59 #define	REMOTE_RECORD_SIZE    (60*KILOBYTE)
60 #define	SCSI_MAX_NAME 32
61 #define	MD5_CHALLENGE_SIZE	64
62 #define	MD5_PASS_LIMIT		32
63 
64 /* Test unit ready */
65 #define	TUR_WAIT	3000000
66 #define	TUR_MAX_TRY	3
67 
68 
69 /* File handler classes */
70 #define	HC_CLIENT	1
71 #define	HC_MOVER	2
72 #define	HC_MODULE	4
73 #define	HC_ALL		0xffffffff
74 
75 #define	IN_ADDR(x) \
76 	(*(struct in_addr *)&x)
77 
78 #define	FS_READONLY(fs)		(hasmntopt(fs, "ro")  ? 1 :  0)
79 
80 typedef void *(*funct_t)(void *);	/* function pointer */
81 
82 #define	HOSTNAMELEN	256
83 
84 #define	VENDOR_NAME	"Sun Microsystems"
85 #define	PRODUCT_NAME	"Solaris 5.11"
86 
87 /*
88  * Calculate array length based on its size and size of
89  * its elements.
90  */
91 #define	ARRAY_LEN(a, t)	(sizeof (a) / sizeof (t))
92 /*
93  * Default maximum permitted sequence number for the token-based backup.
94  */
95 #define	NDMP_MAX_TOKSEQ	9
96 
97 /*
98  * Hard-limit for the sequence number in the token-based backup.
99  * It's one less than the ASCII value of 'A'.  The 'A' letter
100  * can be used as level in the lbr-type backups.
101  */
102 #define	NDMP_TOKSEQ_HLIMIT	('A' - 1)
103 
104 
105 /*
106  * Soft-limit for the sequence number in the token-based backup.
107  */
108 #define	NDMP_TOKSEQ_SLIMIT	(NDMP_TOKSEQ_HLIMIT - 5)
109 
110 
111 /*
112  * Root inode number of dump format in V2.
113  */
114 #define	ROOT_INODE	2
115 
116 /*
117  * NDMP backup image signature.
118  */
119 #define	NDMPUTF8MAGIC "NDMPUTF8MAGIC"
120 
121 /*
122  * Supported BU types
123  */
124 #define	NDMP_DUMP_TYPE	"dump"
125 #define	NDMP_TAR_TYPE	"tar"
126 
127 /* All 1's binary maximum mover window */
128 #define	MAX_WINDOW_SIZE	0xffffffffffffffffULL
129 
130 #define	NDMP_FREE(cp)	{ free((char *)(cp)); (cp) = NULL; }
131 
132 #define	NDMP_YORN(f)	((f) ? 'Y' : 'N')
133 #define	NDMP_TORF(f)	((f) ? "TRUE" : "FALSE")
134 #define	NDMP_SVAL(cp)	((cp) ? (cp) : "NULL")
135 
136 #define	NDMP_SETENV(env, nm, val) \
137 	{ \
138 		env->name = nm; \
139 		env->value = val; \
140 		env++; \
141 	}
142 
143 #define	NDMP_CL_ADDR_LEN	24
144 #define	NDMP_TCP_ADDR_SIZE	32
145 #define	NDMP_TAPE_DEV_NAME	256
146 
147 typedef struct {
148 	char *bk_path;
149 	int bk_llevel; /* last backup level */
150 	time_t bk_ldate; /* last backup date */
151 	int bk_clevel;	/* current backup level */
152 	time_t bk_cdate; /* current backup date */
153 	int bk_map;
154 	int bk_dirino;
155 	char *bk_dmpnm;
156 	char **bk_exl; /* exlude list */
157 	char **bk_inc; /* include list */
158 } ndmp_backup_params_t;
159 
160 
161 typedef struct {
162 	ulong_t rs_nf;	/* number of files to restore */
163 	char *rs_path;
164 	char *rs_bkpath;
165 	int *rs_restored;
166 	int rs_bm;
167 	int rs_lastidx;
168 } ndmp_restore_params_t;
169 
170 /*
171  * Tar format archiving ops table
172  */
173 extern tm_ops_t tm_tar_ops;
174 
175 /*
176  * IS_LBR_BKTYPE shows if the backup type is one of these
177  * 'F' of 'f': 'Full' backup type.
178  * 'A' of 'a': 'Archive' backup type.
179  * 'I' of 'i': 'Incremental' backup type.
180  * 'D' of 'd': 'Differntial' backup type.
181  */
182 #define	IS_LBR_BKTYPE(t)	(((t) && strchr("FAID", toupper(t))) ? 1 : 0)
183 
184 
185 /*
186  * NLP flags.
187  */
188 #define	NLPF_CHKPNTED_PATH	(1 << 0)
189 #define	NLPF_FH			(1 << 1)
190 #define	NLPF_DIRECT		(1 << 2)
191 #define	NLPF_UPDATE		(1 << 3)
192 #define	NLPF_DUMP		(1 << 4)
193 #define	NLPF_TAR		(1 << 5)
194 #define	NLPF_ABORTED		(1 << 6)
195 #define	NLPF_TOKENBK		(1 << 8)
196 #define	NLPF_LBRBK		(1 << 9)
197 #define	NLPF_LEVELBK		(1 << 10)
198 #define	NLPF_IGNCTIME		(1 << 11)
199 #define	NLPF_INCLMTIME		(1 << 12)
200 #define	NLPF_RECURSIVE		(1 << 13)
201 
202 /*
203  * Macros on NLP flags.
204  */
205 #define	NLP_ISSET(n, f)	(((n)->nlp_flags & (f)) != 0)
206 #define	NLP_SET(n, f)	(n)->nlp_flags |= (f)
207 #define	NLP_UNSET(n, f)	(n)->nlp_flags &= ~(f)
208 
209 
210 #define	NLP_ISCHKPNTED(n)	NLP_ISSET(n, NLPF_CHKPNTED_PATH)
211 #define	NLP_SHOULD_UPDATE(n)	NLP_ISSET(n, NLPF_UPDATE)
212 #define	NLP_ISDUMP(n)		NLP_ISSET(n, NLPF_DUMP)
213 #define	NLP_ISTAR(n)		NLP_ISSET(n, NLPF_TAR)
214 #define	NLP_IGNCTIME(n)		NLP_ISSET(n, NLPF_IGNCTIME)
215 #define	NLP_INCLMTIME(n)	NLP_ISSET(n, NLPF_INCLMTIME)
216 
217 /*
218  * NDMP statistics
219  */
220 #define	NS_INC(s)	(atomic_inc_32((volatile uint32_t *)&ndstat.ns_##s))
221 #define	NS_DEC(s)	(atomic_dec_32((volatile uint32_t *)&ndstat.ns_##s))
222 #define	NS_ADD(s, d)	(atomic_add_64((volatile uint64_t *)&ndstat.ns_##s, \
223 	(uint64_t)d))
224 #define	NS_UPD(s, t)	{ \
225 	atomic_inc_32((volatile uint32_t *)&ndstat.ns_##s); \
226 	atomic_dec_32((volatile uint32_t *)&ndstat.ns_##t); \
227 	}
228 
229 #define	NLP_READY	1
230 
231 typedef struct ndmp_lbr_params {
232 	struct ndmpd_session *nlp_session;
233 	int nlp_flags;
234 
235 	ndmp_backup_params_t bk_params;
236 	ndmp_restore_params_t rs_params;
237 #define	nlp_backup_path	bk_params.bk_path
238 #define	nlp_llevel	bk_params.bk_llevel
239 #define	nlp_ldate	bk_params.bk_ldate
240 #define	nlp_clevel	bk_params.bk_clevel
241 #define	nlp_tokseq	nlp_clevel
242 #define	nlp_tokdate	nlp_ldate
243 #define	nlp_cdate	bk_params.bk_cdate
244 #define	nlp_bkmap	bk_params.bk_map
245 #define	nlp_bkdirino	bk_params.bk_dirino
246 #define	nlp_dmpnm	bk_params.bk_dmpnm
247 #define	nlp_exl		bk_params.bk_exl
248 #define	nlp_inc		bk_params.bk_inc
249 
250 #define	nlp_nfiles	rs_params.rs_nf
251 #define	nlp_restore_path	rs_params.rs_path
252 #define	nlp_restore_bk_path	rs_params.rs_bkpath
253 #define	nlp_restored	rs_params.rs_restored
254 #define	nlp_rsbm	rs_params.rs_bm
255 #define	nlp_lastidx	rs_params.rs_lastidx
256 
257 	ndmpd_module_params_t *nlp_params;
258 	tlm_job_stats_t *nlp_jstat;
259 	lbr_fhlog_call_backs_t *nlp_logcallbacks;
260 	tlm_commands_t nlp_cmds;
261 	struct {
262 		/*
263 		 * nw: shows the number of threads waiting for a request
264 		 * to be processed.
265 		 * rv: if error occurred when processing a request.
266 		 */
267 		int ev_nw;
268 		int ev_rv;
269 	} nlp_event;
270 	cond_t	nlp_cv;
271 	int	nlp_flag;
272 #define	nlp_nw	nlp_event.ev_nw
273 #define	nlp_rv	nlp_event.ev_rv
274 	u_longlong_t nlp_bytes_total;
275 } ndmp_lbr_params_t;
276 
277 
278 typedef struct mem_ndmp_name_v3 {
279 	char *nm3_opath;
280 	char *nm3_dpath;
281 	char *nm3_newnm;
282 	u_longlong_t nm3_node;
283 	u_longlong_t nm3_fh_info;
284 	ndmp_error nm3_err;
285 } mem_ndmp_name_v3_t;
286 
287 
288 typedef struct ndmpd_file_handler {
289 	int fh_fd;
290 	ulong_t fh_mode;
291 	ulong_t fh_class;
292 	void *fh_cookie;
293 	ndmpd_file_handler_func_t *fh_func;
294 	struct ndmpd_file_handler *fh_next;
295 } ndmpd_file_handler_t;
296 
297 typedef struct ndmpd_session_scsi_desc {
298 	int sd_is_open;
299 	int sd_devid;
300 	boolean_t sd_valid_target_set;
301 	int sd_sid;
302 	int sd_lun;
303 	char sd_adapter_name[SCSI_MAX_NAME];
304 } ndmpd_session_scsi_desc_t;
305 
306 typedef struct ndmpd_session_tape_desc {
307 	int td_fd;			/* tape device file descriptor */
308 	ulong_t td_record_count;	/* number of records written */
309 	ndmp_tape_open_mode td_mode;	/* tape device open mode */
310 	u_longlong_t td_pos;	/* current position on the current tape */
311 	int td_sid;
312 	int td_lun;
313 	char td_adapter_name[SCSI_MAX_NAME];
314 	ulong_t td_eom_seen:1,
315 		td_io_err:1,
316 		td_write:1;
317 } ndmpd_session_tape_desc_t;
318 
319 typedef struct ndmpd_session_mover_desc {
320 	ndmp_mover_state md_state;	/* current state */
321 	ndmp_mover_mode md_mode;	/* current mode */
322 	ndmp_mover_pause_reason md_pause_reason;	/* current reason */
323 	ndmp_mover_halt_reason md_halt_reason;	/* current reason */
324 	u_longlong_t md_data_written;	/* total written to tape */
325 	u_longlong_t md_seek_position;	/* current seek position */
326 	u_longlong_t md_bytes_left_to_read; /* #bytes to end of seek window */
327 	u_longlong_t md_window_offset;	/* valid data window begin */
328 	u_longlong_t md_window_length;	/* valid data window length */
329 	u_longlong_t md_position;	/* current data stream pos */
330 	boolean_t md_pre_cond;		/* used for precondition checks */
331 	ulong_t md_record_size;	/* tape I/O record size */
332 	ulong_t md_record_num;	/* current record num */
333 	int md_listen_sock;		/* data conn listen socket */
334 	int md_sock;		/* data conn socket */
335 	ulong_t md_r_index;		/* buffer read  index */
336 	ulong_t md_w_index;		/* buffer write index */
337 	char *md_buf;		/* data buffer */
338 	/*
339 	 * V2 fields.
340 	 */
341 	ulong_t md_discard_length;	/* bytes to discard */
342 
343 	/*
344 	 * V3 fields.
345 	 */
346 	ndmp_addr_v3 md_data_addr;
347 	/*
348 	 * V4 fields.
349 	 */
350 	ndmp_addr_v4 md_data_addr_v4;
351 } ndmpd_session_mover_desc_t;
352 
353 
354 typedef struct ndmpd_session_data_module {
355 	void *dm_module_cookie;	/* sent as abort_func param */
356 	module_start_func_t *dm_start_func;	/* start function */
357 	module_abort_func_t *dm_abort_func;	/* abort function */
358 	ndmpd_module_stats dm_stats;	/* statistics buffer */
359 } ndmpd_session_data_module_t;
360 
361 typedef struct ndmpd_session_data_desc {
362 	/*
363 	 * Common fields.
364 	 */
365 	ndmp_data_operation dd_operation;	/* current operation */
366 	boolean_t dd_abort;		/* abort operation flag */
367 	boolean_t dd_io_ready;		/* mover sock read for I/O */
368 	ndmp_pval *dd_env;	/* environment from backup or recover request */
369 	ulong_t dd_env_len;		/* environment length */
370 	ulong_t dd_nlist_len;	/* recover file list length */
371 	int dd_sock;		/* listen and data socket */
372 	u_longlong_t dd_read_offset;	/* data read seek offset */
373 	u_longlong_t dd_read_length;	/* data read length */
374 	u_longlong_t dd_data_size;	/* data size to be backed up */
375 	ndmpd_session_data_module_t dd_module;
376 
377 	ndmp_data_state dd_state;	/* current state */
378 	ndmp_data_halt_reason dd_halt_reason;		/* current reason */
379 	/*
380 	 * V2 fields.
381 	 */
382 	ndmp_name *dd_nlist;	/* recover file list */
383 	ndmp_mover_addr dd_mover;	/* mover address */
384 	/*
385 	 * V3 fields.
386 	 */
387 	mem_ndmp_name_v3_t *dd_nlist_v3;
388 	ndmp_addr_v3 dd_data_addr;
389 	int dd_listen_sock;	/* socket for listening for remote */
390 				/* mover connections */
391 	u_longlong_t dd_bytes_left_to_read;
392 	u_longlong_t dd_position;
393 	u_longlong_t dd_discard_length;
394 	/*
395 	 * V4 fields.
396 	 */
397 	ndmp_addr_v4 dd_data_addr_v4;
398 } ndmpd_session_data_desc_t;
399 
400 typedef struct ndmpd_session_file_history {
401 	ndmp_fh_unix_path *fh_path_entries;
402 	ndmp_fh_unix_dir *fh_dir_entries;
403 	ndmp_fh_unix_node *fh_node_entries;
404 	char *fh_path_name_buf;
405 	char *fh_dir_name_buf;
406 	ulong_t fh_path_index;
407 	ulong_t fh_dir_index;
408 	ulong_t fh_node_index;
409 	ulong_t fh_path_name_buf_index;
410 	ulong_t fh_dir_name_buf_index;
411 } ndmpd_session_file_history_t;
412 
413 typedef struct ndmpd_session_file_history_v3 {
414 	ndmp_file_v3 *fh_files;
415 	ndmp_dir_v3 *fh_dirs;
416 	ndmp_node_v3 *fh_nodes;
417 	ndmp_file_name_v3 *fh_file_names;
418 	ndmp_file_name_v3 *fh_dir_names;
419 	ndmp_file_stat_v3 *fh_file_stats;
420 	ndmp_file_stat_v3 *fh_node_stats;
421 	char *fh_file_name_buf;
422 	char *fh_dir_name_buf;
423 	ulong_t fh_file_index;
424 	ulong_t fh_dir_index;
425 	ulong_t fh_node_index;
426 	ulong_t fh_file_name_buf_index;
427 	ulong_t fh_dir_name_buf_index;
428 } ndmpd_session_file_history_v3_t;
429 
430 typedef struct ndmpd_session {
431 	ndmp_connection_t *ns_connection;	/* NDMP connection to client */
432 	boolean_t ns_eof;		/* connection EOF flag */
433 	ushort_t ns_protocol_version;	/* connection protocol version */
434 	ndmpd_session_scsi_desc_t ns_scsi;
435 	ndmpd_session_tape_desc_t ns_tape;
436 	ndmpd_session_mover_desc_t ns_mover;
437 	ndmpd_session_data_desc_t ns_data;
438 	ndmpd_session_file_history_t ns_fh;
439 	ndmpd_file_handler_t *ns_file_handler_list; /* for I/O multiplexing */
440 	int ns_nref;
441 	ndmp_lbr_params_t *ns_ndmp_lbr_params;
442 	mutex_t ns_lock;
443 
444 	/*
445 	 * NDMP V3
446 	 * Tape, SCSI, mover, data and file handlers will
447 	 * be shared between V2 and V3.
448 	 */
449 	ndmpd_session_file_history_v3_t ns_fh_v3;
450 	unsigned char ns_challenge[MD5_CHALLENGE_SIZE];  /* For MD5 */
451 
452 	/*
453 	 * NDMP V4 related data
454 	 */
455 	boolean_t ns_set_ext_list;
456 
457 	/* handling of hardlink, hardlink queue head */
458 	struct hardlink_q *hardlink_q;
459 } ndmpd_session_t;
460 
461 
462 /*
463  * NDMP request handler functions.
464  */
465 
466 /* Config */
467 ndmp_msg_handler_func_t ndmpd_config_get_host_info_v2;
468 ndmp_msg_handler_func_t ndmpd_config_get_butype_attr_v2;
469 ndmp_msg_handler_func_t ndmpd_config_get_mover_type_v2;
470 ndmp_msg_handler_func_t ndmpd_config_get_auth_attr_v2;
471 
472 ndmp_msg_handler_func_t ndmpd_config_get_host_info_v3;
473 ndmp_msg_handler_func_t ndmpd_config_get_butype_info_v3;
474 ndmp_msg_handler_func_t ndmpd_config_get_connection_type_v3;
475 ndmp_msg_handler_func_t ndmpd_config_get_auth_attr_v3;
476 ndmp_msg_handler_func_t ndmpd_config_get_fs_info_v3;
477 ndmp_msg_handler_func_t ndmpd_config_get_tape_info_v3;
478 ndmp_msg_handler_func_t ndmpd_config_get_scsi_info_v3;
479 ndmp_msg_handler_func_t ndmpd_config_get_server_info_v3;
480 
481 ndmp_msg_handler_func_t ndmpd_config_get_butype_info_v4;
482 ndmp_msg_handler_func_t ndmpd_config_get_ext_list_v4;
483 ndmp_msg_handler_func_t ndmpd_config_set_ext_list_v4;
484 
485 
486 /* Scsi */
487 ndmp_msg_handler_func_t ndmpd_scsi_open_v2;
488 ndmp_msg_handler_func_t ndmpd_scsi_close_v2;
489 ndmp_msg_handler_func_t ndmpd_scsi_get_state_v2;
490 ndmp_msg_handler_func_t ndmpd_scsi_set_target_v2;
491 ndmp_msg_handler_func_t ndmpd_scsi_reset_device_v2;
492 ndmp_msg_handler_func_t ndmpd_scsi_reset_bus_v2;
493 ndmp_msg_handler_func_t ndmpd_scsi_execute_cdb_v2;
494 
495 ndmp_msg_handler_func_t ndmpd_scsi_open_v3;
496 ndmp_msg_handler_func_t ndmpd_scsi_set_target_v3;
497 
498 
499 /* Tape */
500 ndmp_msg_handler_func_t ndmpd_tape_open_v2;
501 ndmp_msg_handler_func_t ndmpd_tape_close_v2;
502 ndmp_msg_handler_func_t ndmpd_tape_get_state_v2;
503 ndmp_msg_handler_func_t ndmpd_tape_mtio_v2;
504 ndmp_msg_handler_func_t ndmpd_tape_write_v2;
505 ndmp_msg_handler_func_t ndmpd_tape_read_v2;
506 ndmp_msg_handler_func_t ndmpd_tape_execute_cdb_v2;
507 
508 ndmp_msg_handler_func_t ndmpd_tape_open_v3;
509 ndmp_msg_handler_func_t ndmpd_tape_get_state_v3;
510 ndmp_msg_handler_func_t ndmpd_tape_write_v3;
511 ndmp_msg_handler_func_t ndmpd_tape_read_v3;
512 
513 
514 ndmp_msg_handler_func_t ndmpd_tape_close_v4;
515 /* Data */
516 ndmp_msg_handler_func_t ndmpd_data_get_state_v2;
517 ndmp_msg_handler_func_t ndmpd_data_start_backup_v2;
518 ndmp_msg_handler_func_t ndmpd_data_start_recover_v2;
519 ndmp_msg_handler_func_t ndmpd_data_get_env_v2;
520 ndmp_msg_handler_func_t ndmpd_data_stop_v2;
521 ndmp_msg_handler_func_t ndmpd_data_abort_v2;
522 
523 ndmp_msg_handler_func_t ndmpd_data_get_state_v3;
524 ndmp_msg_handler_func_t ndmpd_data_connect_v3;
525 ndmp_msg_handler_func_t ndmpd_data_listen_v3;
526 ndmp_msg_handler_func_t ndmpd_data_stop_v3;
527 ndmp_msg_handler_func_t ndmpd_data_abort_v3;
528 ndmp_msg_handler_func_t ndmpd_data_start_recover_v3;
529 ndmp_msg_handler_func_t ndmpd_data_start_backup_v3;
530 
531 ndmp_msg_handler_func_t ndmpd_data_get_env_v4;
532 ndmp_msg_handler_func_t ndmpd_data_get_state_v4;
533 ndmp_msg_handler_func_t ndmpd_data_connect_v4;
534 ndmp_msg_handler_func_t ndmpd_data_listen_v4;
535 ndmp_msg_handler_func_t ndmpd_data_start_recover_filehist_v4;
536 
537 
538 /* Connect */
539 ndmp_msg_handler_func_t ndmpd_connect_open_v2;
540 ndmp_msg_handler_func_t ndmpd_connect_client_auth_v2;
541 ndmp_msg_handler_func_t ndmpd_connect_server_auth_v2;
542 ndmp_msg_handler_func_t ndmpd_connect_close_v2;
543 
544 ndmp_msg_handler_func_t ndmpd_connect_client_auth_v3;
545 ndmp_msg_handler_func_t ndmpd_connect_close_v3;
546 
547 
548 /* Mover */
549 ndmp_msg_handler_func_t ndmpd_mover_get_state_v2;
550 ndmp_msg_handler_func_t ndmpd_mover_listen_v2;
551 ndmp_msg_handler_func_t ndmpd_mover_continue_v2;
552 ndmp_msg_handler_func_t ndmpd_mover_abort_v2;
553 ndmp_msg_handler_func_t ndmpd_mover_stop_v2;
554 ndmp_msg_handler_func_t ndmpd_mover_set_window_v2;
555 ndmp_msg_handler_func_t ndmpd_mover_read_v2;
556 ndmp_msg_handler_func_t ndmpd_mover_close_v2;
557 ndmp_msg_handler_func_t ndmpd_mover_set_record_size_v2;
558 
559 ndmp_msg_handler_func_t ndmpd_mover_get_state_v3;
560 ndmp_msg_handler_func_t ndmpd_mover_listen_v3;
561 ndmp_msg_handler_func_t ndmpd_mover_continue_v3;
562 ndmp_msg_handler_func_t ndmpd_mover_abort_v3;
563 ndmp_msg_handler_func_t ndmpd_mover_set_window_v3;
564 ndmp_msg_handler_func_t ndmpd_mover_read_v3;
565 ndmp_msg_handler_func_t ndmpd_mover_set_record_size_v3;
566 ndmp_msg_handler_func_t ndmpd_mover_connect_v3;
567 
568 
569 ndmp_msg_handler_func_t ndmpd_mover_get_state_v4;
570 ndmp_msg_handler_func_t ndmpd_mover_listen_v4;
571 ndmp_msg_handler_func_t ndmpd_mover_connect_v4;
572 
573 
574 /*
575  * Backup/recover module API functions.
576  */
577 ndmpd_get_env_func_t ndmpd_api_get_env;
578 ndmpd_add_env_func_t ndmpd_api_add_env;
579 ndmpd_add_env_func_t ndmpd_api_set_env;
580 ndmpd_get_name_func_t ndmpd_api_get_name;
581 ndmpd_dispatch_func_t ndmpd_api_dispatch;
582 ndmpd_done_func_t ndmpd_api_done_v2;
583 
584 
585 ndmpd_write_func_t ndmpd_api_write_v2;
586 ndmpd_file_history_path_func_t ndmpd_api_file_history_path_v2;
587 ndmpd_file_history_dir_func_t ndmpd_api_file_history_dir_v2;
588 ndmpd_file_history_node_func_t ndmpd_api_file_history_node_v2;
589 ndmpd_read_func_t ndmpd_api_read_v2;
590 ndmpd_seek_func_t ndmpd_api_seek_v2;
591 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v2;
592 ndmpd_add_file_handler_func_t ndmpd_api_add_file_handler;
593 ndmpd_remove_file_handler_func_t ndmpd_api_remove_file_handler;
594 
595 
596 /*
597  * NDMP V3
598  */
599 ndmpd_done_func_t ndmpd_api_done_v3;
600 ndmpd_write_func_t ndmpd_api_write_v3;
601 ndmpd_read_func_t ndmpd_api_read_v3;
602 ndmpd_seek_func_t ndmpd_api_seek_v3;
603 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v3;
604 ndmpd_get_name_func_t ndmpd_api_get_name_v3;
605 ndmpd_file_history_path_func_t ndmpd_api_file_history_file_v3;
606 ndmpd_file_history_dir_func_t ndmpd_api_file_history_dir_v3;
607 ndmpd_file_history_node_func_t ndmpd_api_file_history_node_v3;
608 
609 /*
610  * NDMP V4
611  */
612 ndmpd_log_func_v3_t ndmpd_api_log_v4;
613 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v4;
614 
615 #ifndef NO_NDMP_API_LOG_PROTOTYPES
616 ndmpd_log_func_t ndmpd_api_log_v2;
617 ndmpd_log_func_v3_t ndmpd_api_log_v3;
618 #endif /* NO_NDMP_API_LOG_PROTOTYPES */
619 
620 typedef void ndmpd_func_t(ndmp_connection_t *, void *);
621 
622 /*
623  * pthread call arg parameters
624  */
625 typedef struct {
626 	int nw_sock;
627 	long nw_ipaddr;
628 	ndmp_con_handler_func_t nw_con_handler_func;
629 } ndmpd_worker_arg_t;
630 
631 typedef struct {
632 	char *br_jname;
633 	ndmp_lbr_params_t *br_nlp;
634 	tlm_commands_t *br_cmds;
635 	pthread_barrier_t br_barrier;
636 } backup_reader_arg_t;
637 
638 typedef struct {
639 	ndmpd_session_t *tr_session;
640 	ndmpd_module_params_t *tr_mod_params;
641 	tlm_commands_t *tr_cmds;
642 } ndmp_tar_reader_arg_t;
643 
644 typedef struct {
645 	ndmpd_session_t *bs_session;
646 	char *bs_jname;
647 	char *bs_path;
648 } ndmp_bkup_size_arg_t;
649 
650 /*
651  * Variables from ndmpd_comm.c
652  */
653 extern int ndmp_ver;
654 extern int ndmp_full_restore_path;
655 extern int ndmp_dar_support;
656 extern int ndmp_port;
657 extern ndmp_stat_t ndstat;
658 
659 extern void ndmpd_main(void);
660 extern void connection_handler(ndmp_connection_t *);
661 extern void ndmpd_audit_backup(ndmp_connection_t *conn, char *path,
662     int dest, char *local_path, int result);
663 extern void ndmpd_audit_restore(ndmp_connection_t *conn,
664     char *path, int dest, char *local_path, int result);
665 extern void ndmpd_audit_connect(ndmp_connection_t *conn,
666     int result);
667 extern void ndmpd_audit_disconnect(ndmp_connection_t *conn);
668 
669 /* Variables from ndmpd_main.c */
670 extern	libzfs_handle_t	*zlibh;
671 extern	mutex_t	zlib_mtx;
672 
673 /*
674  * Utility from ndmpd_connect.c.
675  */
676 extern int ndmp_connect_list_add(ndmp_connection_t *, int *);
677 extern int ndmp_connect_list_del(ndmp_connection_t *);
678 extern int ndmpd_connect_kill_id(int);
679 extern void ndmp_connect_list_get(ndmp_door_ctx_t *);
680 extern void ndmpd_get_devs(ndmp_door_ctx_t *);
681 
682 /*
683  * Utility functions form ndmpd_data.c.
684  */
685 extern void ndmpd_data_cleanup(ndmpd_session_t *);
686 extern int ndmpd_data_init(ndmpd_session_t *);
687 extern char *ndmp_data_get_mover_mode(ndmpd_session_t *);
688 extern void ndmpd_data_error(ndmpd_session_t *, ndmp_data_halt_reason);
689 
690 
691 /*
692  * Utility functions from ndmpd_mover.c.
693  */
694 extern int ndmpd_mover_init(ndmpd_session_t *);
695 extern void ndmpd_mover_cleanup(ndmpd_session_t *);
696 extern ndmp_error ndmpd_mover_connect(ndmpd_session_t *,
697     ndmp_mover_mode);
698 extern void ndmpd_mover_error(ndmpd_session_t *,
699     ndmp_mover_halt_reason);
700 extern int ndmpd_mover_seek(ndmpd_session_t *,
701     u_longlong_t,
702     u_longlong_t);
703 extern int ndmpd_local_write(ndmpd_session_t *,
704     char *,
705     ulong_t);
706 extern int ndmpd_remote_write(ndmpd_session_t *,
707     char *,
708     ulong_t);
709 extern int ndmpd_local_read(ndmpd_session_t *,
710     char *,
711     ulong_t);
712 extern int ndmpd_remote_read(ndmpd_session_t *,
713     char *,
714     ulong_t);
715 
716 extern void ndmpd_mover_shut_down(ndmpd_session_t *);
717 extern void ndmpd_mover_error(ndmpd_session_t *,
718     ndmp_mover_halt_reason);
719 extern int ndmpd_local_write_v3(ndmpd_session_t *,
720     char *,
721     ulong_t);
722 extern int ndmpd_local_read_v3(ndmpd_session_t *,
723     char *,
724     ulong_t);
725 extern int ndmpd_remote_read_v3(ndmpd_session_t *,
726     char *,
727     ulong_t);
728 extern int ndmpd_mover_wait_v3(ndmpd_session_t *);
729 extern void ndmpd_write_eom(int);
730 
731 
732 /*
733  * Utility functions from ndmpd_file_history.c
734  */
735 extern void ndmpd_file_history_init(ndmpd_session_t *);
736 extern void ndmpd_file_history_cleanup(ndmpd_session_t *,
737     boolean_t);
738 extern int ndmpd_file_history_path(lbr_fhlog_call_backs_t *,
739     char *,
740     struct stat64 *,
741     u_longlong_t);
742 extern int ndmpd_file_history_dir(lbr_fhlog_call_backs_t *,
743     char *,
744     struct stat64 *);
745 extern int ndmpd_file_history_node(lbr_fhlog_call_backs_t *,
746     char *,
747     char *,
748     struct stat64 *,
749     u_longlong_t);
750 extern int
751 ndmpd_path_restored(lbr_fhlog_call_backs_t *,
752     char *,
753     struct stat64 *,
754     u_longlong_t);
755 extern int ndmpd_fhpath_v3_cb(lbr_fhlog_call_backs_t *,
756     char *,
757     struct stat64 *,
758     u_longlong_t);
759 extern int ndmpd_fhdir_v3_cb(lbr_fhlog_call_backs_t *,
760     char *,
761     struct stat64 *);
762 extern int ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t *,
763     char *,
764     char *,
765     struct stat64 *,
766     u_longlong_t);
767 extern int ndmpd_path_restored_v3(lbr_fhlog_call_backs_t *,
768     char *,
769     struct stat64 *,
770     u_longlong_t);
771 
772 extern int ndmp_send_recovery_stat_v3(ndmpd_module_params_t *,
773     ndmp_lbr_params_t *,
774     int,
775     int);
776 
777 
778 /*
779  * Utility functions from ndmpd_dtime.c
780  */
781 extern int ndmpd_put_dumptime(char *, int, time_t);
782 extern int ndmpd_get_dumptime(char *, int *, time_t *);
783 extern int ndmpd_append_dumptime(char *, char *, int, time_t);
784 
785 
786 /*
787  * Global variables from ndmpd_tar3.c
788  */
789 extern char **ndmp_excl_list;
790 
791 
792 /*
793  * Global variables from ndmpd_util.c
794  */
795 extern int ndmp_force_bk_dirs;
796 extern int ndmp_rbs;
797 extern int ndmp_sbs;
798 extern boolean_t ndmp_dump_path_node;
799 extern boolean_t ndmp_tar_path_node;
800 extern boolean_t ndmp_ignore_ctime;
801 extern boolean_t ndmp_include_lmtime;
802 
803 
804 /*
805  * Utility functions from ndmpd_util.c.
806  */
807 extern int ndmpd_select(ndmpd_session_t *,
808     boolean_t,
809     ulong_t);
810 
811 extern ndmp_error ndmpd_save_env(ndmpd_session_t *,
812     ndmp_pval *,
813     ulong_t);
814 
815 extern void ndmpd_free_env(ndmpd_session_t *);
816 extern ndmp_error ndmpd_save_nlist_v2(ndmpd_session_t *,
817     ndmp_name *,
818     ulong_t);
819 
820 extern void ndmpd_free_nlist(ndmpd_session_t *);
821 extern int ndmpd_add_file_handler(ndmpd_session_t *,
822     void *,
823     int,
824     ulong_t,
825     ulong_t,
826     ndmpd_file_handler_func_t *);
827 
828 extern int ndmpd_remove_file_handler(ndmpd_session_t *,
829     int);
830 
831 extern void ndmp_send_reply(ndmp_connection_t *,
832     void *,
833     char *);
834 
835 extern int ndmp_mtioctl(int, int, int);
836 
837 extern u_longlong_t quad_to_long_long(ndmp_u_quad);
838 extern ndmp_u_quad long_long_to_quad(u_longlong_t);
839 
840 extern void ndmp_set_socket_nodelay(int);
841 extern void ndmp_set_socket_snd_buf(int, int);
842 extern void ndmp_set_socket_rcv_buf(int, int);
843 
844 extern long ndmp_buffer_get_size(ndmpd_session_t *);
845 extern int ndmp_lbr_init(ndmpd_session_t *);
846 extern void ndmp_lbr_cleanup(ndmpd_session_t *);
847 
848 extern void nlp_ref_nw(ndmpd_session_t *);
849 extern void nlp_unref_nw(ndmpd_session_t *);
850 extern void nlp_wait_nw(ndmpd_session_t *);
851 extern void nlp_event_nw(ndmpd_session_t *);
852 extern int nlp_event_rv_get(ndmpd_session_t *);
853 extern void nlp_event_rv_set(ndmpd_session_t *, int);
854 extern boolean_t is_buffer_erroneous(tlm_buffer_t *);
855 extern void ndmp_execute_cdb(ndmpd_session_t *,
856     char *,
857     int,
858     int,
859     ndmp_execute_cdb_request *);
860 
861 extern scsi_adapter_t *scsi_get_adapter(int);
862 extern boolean_t is_tape_unit_ready(char *, int);
863 
864 extern int ndmp_open_list_add(ndmp_connection_t *, char *, int, int, int);
865 extern int ndmp_open_list_del(char *, int, int);
866 extern void ndmp_open_list_release(ndmp_connection_t *);
867 
868 extern void ndmp_stop_buffer_worker(ndmpd_session_t *);
869 extern void ndmp_stop_reader_thread(ndmpd_session_t *);
870 extern void ndmp_stop_writer_thread(ndmpd_session_t *);
871 extern void ndmp_free_reader_writer_ipc(ndmpd_session_t *);
872 extern void ndmp_waitfor_op(ndmpd_session_t *);
873 
874 extern char *cctime(time_t *);
875 extern char *ndmp_new_job_name(char *);
876 extern char *ndmpd_mk_temp(char *);
877 extern char *ndmpd_make_bk_dir_path(char *, char *);
878 extern boolean_t ndmp_is_chkpnt_root(char *);
879 extern char **ndmpd_make_exc_list(void);
880 extern void ndmp_sort_nlist_v3(ndmpd_session_t *);
881 extern int ndmp_get_bk_dir_ino(ndmp_lbr_params_t *);
882 extern int ndmp_write_utf8magic(tlm_cmd_t *);
883 extern int ndmp_tar_writer(ndmpd_session_t *,
884     ndmpd_module_params_t *,
885     tlm_commands_t *);
886 extern void ndmp_wait_for_reader(tlm_commands_t *);
887 extern ndmp_error ndmpd_save_nlist_v3(ndmpd_session_t *,
888     ndmp_name_v3 *,
889     ulong_t);
890 extern void ndmpd_free_nlist_v3(ndmpd_session_t *);
891 extern int ndmp_create_socket(ulong_t *, ushort_t *);
892 extern int ndmp_connect_sock_v3(ulong_t, ushort_t);
893 extern void ndmp_copy_addr_v3(ndmp_addr_v3 *, ndmp_addr_v3 *);
894 extern void ndmp_copy_addr_v4(ndmp_addr_v4 *, ndmp_addr_v4 *);
895 extern char *ndmp_addr2str_v3(ndmp_addr_type);
896 extern boolean_t ndmp_valid_v3addr_type(ndmp_addr_type);
897 extern boolean_t ndmp_check_utf8magic(tlm_cmd_t *);
898 extern int ndmp_get_cur_bk_time(ndmp_lbr_params_t *,
899     time_t *, char *);
900 extern char *ndmp_get_relative_path(char *, char *);
901 
902 extern boolean_t ndmp_fhinode;
903 extern void ndmp_load_params(void);
904 extern void randomize(unsigned char *, int);
905 
906 
907 /*
908  * Utility functions from ndmpd_tar3.c.
909  */
910 extern ndmp_error ndmp_restore_get_params_v3(ndmpd_session_t *,
911     ndmpd_module_params_t *);
912 extern ndmp_error ndmp_backup_get_params_v3(ndmpd_session_t *,
913     ndmpd_module_params_t *);
914 extern char *get_bk_path_v3(ndmpd_module_params_t *);
915 
916 /*
917  * door init and fini function from ndmpd_door_serv.c
918  */
919 extern int ndmp_door_init(void);
920 extern void ndmp_door_fini(void);
921 extern boolean_t ndmp_door_check(void);
922 
923 extern int ndmp_get_max_tok_seq(void);
924 extern boolean_t set_debug_level(boolean_t);
925 extern boolean_t get_debug_level(void);
926 
927 typedef struct ndmp_chkpnt_vol {
928 	char cv_vol_name[64];
929 	unsigned int cv_count;
930 	void *cv_next;
931 } ndmp_chkpnt_vol_t;
932 
933 extern int get_zfsvolname(char *, int, char *);
934 extern int ndmp_start_check_point(char *, char *);
935 extern int ndmp_release_check_point(char *, char *);
936 extern int ndmpd_mark_inodes_v2(ndmpd_session_t *, ndmp_lbr_params_t *);
937 extern void ndmpd_abort_marking_v2(ndmpd_session_t *);
938 extern int ndmpd_mark_inodes_v3(ndmpd_session_t *, ndmp_lbr_params_t *);
939 extern ndmp_lbr_params_t *ndmp_get_nlp(void *);
940 
941 module_start_func_t	ndmpd_tar_backup_starter;
942 module_abort_func_t	ndmpd_tar_backup_abort;
943 
944 module_start_func_t	ndmpd_tar_restore_starter;
945 module_abort_func_t	ndmpd_tar_restore_abort;
946 
947 module_start_func_t ndmpd_tar_backup_starter_v3;
948 module_abort_func_t ndmpd_tar_backup_abort_v3;
949 
950 module_start_func_t ndmpd_tar_restore_starter_v3;
951 module_abort_func_t ndmpd_tar_restore_abort_v3;
952 
953 extern int ndmp_backup_extract_params(ndmpd_session_t *,
954     ndmpd_module_params_t *);
955 extern int ndmp_restore_extract_params(ndmpd_session_t *,
956     ndmpd_module_params_t *);
957 extern int ndmp_tar_reader(ndmp_tar_reader_arg_t *);
958 
959 extern int tape_open(char *, int);
960 
961 extern void ndmp_session_ref(ndmpd_session_t *);
962 extern void ndmp_session_unref(ndmpd_session_t *);
963 
964 void ndmpd_get_file_entry_type(int, ndmp_file_type *);
965 
966 extern int tcp_accept(int, unsigned int *);
967 extern int tcp_get_peer(int, unsigned int *, int *);
968 
969 extern char *gethostaddr(void);
970 extern int tlm_init(void);
971 
972 extern int chkpnt_backup_successful(char *, char *);
973 extern int chkpnt_backup_prepare(char *, char *);
974 
975 extern boolean_t fs_is_chkpntvol(char *);
976 extern boolean_t fs_is_chkpnt_enabled(char *);
977 extern boolean_t fs_is_rdonly(char *);
978 extern boolean_t fs_volexist(char *);
979 extern boolean_t fs_is_valid_logvol(char *);
980 extern boolean_t rootfs_dot_or_dotdot(char *);
981 extern int dp_readdir(DIR *, unsigned long *, char *,
982     int *, unsigned long *);
983 
984 extern void scsi_find_sid_lun();
985 extern char *sasd_slink_name();
986 extern int scsi_dev_exists(char *, int, int);
987 extern int scsi_get_devtype(char *, int, int);
988 extern struct open_list *ndmp_open_list_find(char *, int, int);
989 extern int filecopy(char *, char *);
990 
991 extern void ndmp_stop_local_reader();
992 extern void ndmp_stop_remote_reader();
993 
994 extern boolean_t match(char *, char *);
995 extern char *trim_whitespace(char *);
996 extern int fs_getstat(char *, struct fs_fhandle *, struct stat64 *);
997 extern int fs_readdir(struct fs_fhandle *, char *, long *,
998     char *, int *, struct fs_fhandle *, struct stat64 *);
999 extern int iscreated(ndmp_lbr_params_t *nlp, char *name, tlm_acls_t *tacl,
1000     time_t t);
1001 
1002 extern int sasd_dev_count(void);
1003 extern struct scsi_link *sasd_dev_slink(int);
1004 extern struct sasd_drive *sasd_drive(int);
1005 extern void *ndmp_malloc(size_t size);
1006 
1007 extern ndmp_plugin_t *ndmp_pl;
1008 #endif /* _NDMPD_H */
1009