xref: /titanic_51/usr/src/cmd/ndmpd/ndmp/ndmpd.h (revision 8d8453de6847166cd4079123d746fa7e23023bca)
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 /* 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 /*
645  * Variables from ndmpd_comm.c
646  */
647 extern int ndmp_ver;
648 extern int ndmp_full_restore_path;
649 extern int ndmp_dar_support;
650 extern int ndmp_port;
651 extern ndmp_stat_t ndstat;
652 extern char *ndmp_log_path;
653 
654 extern void ndmpd_main(void);
655 extern void connection_handler(ndmp_connection_t *);
656 extern void ndmpd_audit_backup(ndmp_connection_t *conn, char *path,
657     int dest, char *local_path, int result);
658 extern void ndmpd_audit_restore(ndmp_connection_t *conn,
659     char *path, int dest, char *local_path, int result);
660 extern void ndmpd_audit_connect(ndmp_connection_t *conn,
661     int result);
662 extern void ndmpd_audit_disconnect(ndmp_connection_t *conn);
663 
664 /* Variables from ndmpd_main.c */
665 extern	libzfs_handle_t	*zlibh;
666 extern	mutex_t	zlib_mtx;
667 
668 /*
669  * Utility from ndmpd_connect.c.
670  */
671 extern int ndmp_connect_list_add(ndmp_connection_t *, int *);
672 extern int ndmp_connect_list_del(ndmp_connection_t *);
673 extern int ndmpd_connect_kill_id(int);
674 extern void ndmp_connect_list_get(ndmp_door_ctx_t *);
675 extern void ndmpd_get_devs(ndmp_door_ctx_t *);
676 
677 /*
678  * Utility functions form ndmpd_data.c.
679  */
680 extern void ndmpd_data_cleanup(ndmpd_session_t *);
681 extern int ndmpd_data_init(ndmpd_session_t *);
682 extern char *ndmp_data_get_mover_mode(ndmpd_session_t *);
683 extern void ndmpd_data_error(ndmpd_session_t *, ndmp_data_halt_reason);
684 
685 
686 /*
687  * Utility functions from ndmpd_mover.c.
688  */
689 extern int ndmpd_mover_init(ndmpd_session_t *);
690 extern void ndmpd_mover_cleanup(ndmpd_session_t *);
691 extern ndmp_error ndmpd_mover_connect(ndmpd_session_t *,
692     ndmp_mover_mode);
693 extern void ndmpd_mover_error(ndmpd_session_t *,
694     ndmp_mover_halt_reason);
695 extern int ndmpd_mover_seek(ndmpd_session_t *,
696     u_longlong_t,
697     u_longlong_t);
698 extern int ndmpd_local_write(ndmpd_session_t *,
699     char *,
700     ulong_t);
701 extern int ndmpd_remote_write(ndmpd_session_t *,
702     char *,
703     ulong_t);
704 extern int ndmpd_local_read(ndmpd_session_t *,
705     char *,
706     ulong_t);
707 extern int ndmpd_remote_read(ndmpd_session_t *,
708     char *,
709     ulong_t);
710 
711 extern void ndmpd_mover_shut_down(ndmpd_session_t *);
712 extern void ndmpd_mover_error(ndmpd_session_t *,
713     ndmp_mover_halt_reason);
714 extern int ndmpd_local_write_v3(ndmpd_session_t *,
715     char *,
716     ulong_t);
717 extern int ndmpd_local_read_v3(ndmpd_session_t *,
718     char *,
719     ulong_t);
720 extern int ndmpd_remote_read_v3(ndmpd_session_t *,
721     char *,
722     ulong_t);
723 extern int ndmpd_mover_wait_v3(ndmpd_session_t *);
724 extern void ndmpd_write_eom(int);
725 
726 
727 /*
728  * Utility functions from ndmpd_file_history.c
729  */
730 extern void ndmpd_file_history_init(ndmpd_session_t *);
731 extern void ndmpd_file_history_cleanup(ndmpd_session_t *,
732     boolean_t);
733 extern int ndmpd_file_history_path(lbr_fhlog_call_backs_t *,
734     char *,
735     struct stat64 *,
736     u_longlong_t);
737 extern int ndmpd_file_history_dir(lbr_fhlog_call_backs_t *,
738     char *,
739     struct stat64 *);
740 extern int ndmpd_file_history_node(lbr_fhlog_call_backs_t *,
741     char *,
742     char *,
743     struct stat64 *,
744     u_longlong_t);
745 extern int
746 ndmpd_path_restored(lbr_fhlog_call_backs_t *,
747     char *,
748     struct stat64 *,
749     u_longlong_t);
750 extern int ndmpd_fhpath_v3_cb(lbr_fhlog_call_backs_t *,
751     char *,
752     struct stat64 *,
753     u_longlong_t);
754 extern int ndmpd_fhdir_v3_cb(lbr_fhlog_call_backs_t *,
755     char *,
756     struct stat64 *);
757 extern int ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t *,
758     char *,
759     char *,
760     struct stat64 *,
761     u_longlong_t);
762 extern int ndmpd_path_restored_v3(lbr_fhlog_call_backs_t *,
763     char *,
764     struct stat64 *,
765     u_longlong_t);
766 
767 extern int ndmp_send_recovery_stat_v3(ndmpd_module_params_t *,
768     ndmp_lbr_params_t *,
769     int,
770     int);
771 
772 
773 /*
774  * Utility functions from ndmpd_dtime.c
775  */
776 extern int ndmpd_put_dumptime(char *, int, time_t);
777 extern int ndmpd_get_dumptime(char *, int *, time_t *);
778 extern int ndmpd_append_dumptime(char *, char *, int, time_t);
779 
780 
781 /*
782  * Global variables from ndmpd_tar3.c
783  */
784 extern char **ndmp_excl_list;
785 
786 
787 /*
788  * Global variables from ndmpd_util.c
789  */
790 extern int ndmp_force_bk_dirs;
791 extern int ndmp_rbs;
792 extern int ndmp_sbs;
793 extern boolean_t ndmp_dump_path_node;
794 extern boolean_t ndmp_tar_path_node;
795 extern boolean_t ndmp_ignore_ctime;
796 extern boolean_t ndmp_include_lmtime;
797 
798 
799 /*
800  * Utility functions from ndmpd_util.c.
801  */
802 extern int ndmpd_select(ndmpd_session_t *,
803     boolean_t,
804     ulong_t);
805 
806 extern ndmp_error ndmpd_save_env(ndmpd_session_t *,
807     ndmp_pval *,
808     ulong_t);
809 
810 extern void ndmpd_free_env(ndmpd_session_t *);
811 extern ndmp_error ndmpd_save_nlist_v2(ndmpd_session_t *,
812     ndmp_name *,
813     ulong_t);
814 
815 extern void ndmpd_free_nlist(ndmpd_session_t *);
816 extern int ndmpd_add_file_handler(ndmpd_session_t *,
817     void *,
818     int,
819     ulong_t,
820     ulong_t,
821     ndmpd_file_handler_func_t *);
822 
823 extern int ndmpd_remove_file_handler(ndmpd_session_t *,
824     int);
825 
826 extern void ndmp_send_reply(ndmp_connection_t *,
827     void *,
828     char *);
829 
830 extern int ndmp_mtioctl(int, int, int);
831 
832 extern u_longlong_t quad_to_long_long(ndmp_u_quad);
833 extern ndmp_u_quad long_long_to_quad(u_longlong_t);
834 
835 extern void ndmp_set_socket_nodelay(int);
836 extern void ndmp_set_socket_snd_buf(int, int);
837 extern void ndmp_set_socket_rcv_buf(int, int);
838 
839 extern long ndmp_buffer_get_size(ndmpd_session_t *);
840 extern int ndmp_lbr_init(ndmpd_session_t *);
841 extern void ndmp_lbr_cleanup(ndmpd_session_t *);
842 
843 extern void nlp_ref_nw(ndmpd_session_t *);
844 extern void nlp_unref_nw(ndmpd_session_t *);
845 extern void nlp_wait_nw(ndmpd_session_t *);
846 extern void nlp_event_nw(ndmpd_session_t *);
847 extern int nlp_event_rv_get(ndmpd_session_t *);
848 extern void nlp_event_rv_set(ndmpd_session_t *, int);
849 extern boolean_t is_buffer_erroneous(tlm_buffer_t *);
850 extern void ndmp_execute_cdb(ndmpd_session_t *,
851     char *,
852     int,
853     int,
854     ndmp_execute_cdb_request *);
855 
856 extern scsi_adapter_t *scsi_get_adapter(int);
857 extern boolean_t is_tape_unit_ready(char *, int);
858 
859 extern int ndmp_open_list_add(ndmp_connection_t *, char *, int, int, int);
860 extern int ndmp_open_list_del(char *, int, int);
861 extern void ndmp_open_list_release(ndmp_connection_t *);
862 
863 extern void ndmp_stop_buffer_worker(ndmpd_session_t *);
864 extern void ndmp_stop_reader_thread(ndmpd_session_t *);
865 extern void ndmp_stop_writer_thread(ndmpd_session_t *);
866 extern void ndmp_free_reader_writer_ipc(ndmpd_session_t *);
867 extern void ndmp_waitfor_op(ndmpd_session_t *);
868 
869 extern char *cctime(time_t *);
870 extern char *ndmp_new_job_name(char *);
871 extern char *ndmpd_mk_temp(char *);
872 extern char *ndmpd_make_bk_dir_path(char *, char *);
873 extern boolean_t ndmp_is_chkpnt_root(char *);
874 extern char **ndmpd_make_exc_list(void);
875 extern void ndmp_sort_nlist_v3(ndmpd_session_t *);
876 extern int ndmp_get_bk_dir_ino(ndmp_lbr_params_t *);
877 extern int ndmp_write_utf8magic(tlm_cmd_t *);
878 extern int ndmp_tar_writer(ndmpd_session_t *,
879     ndmpd_module_params_t *,
880     tlm_commands_t *);
881 extern void ndmp_wait_for_reader(tlm_commands_t *);
882 extern ndmp_error ndmpd_save_nlist_v3(ndmpd_session_t *,
883     ndmp_name_v3 *,
884     ulong_t);
885 extern void ndmpd_free_nlist_v3(ndmpd_session_t *);
886 extern int ndmp_create_socket(ulong_t *, ushort_t *);
887 extern int ndmp_connect_sock_v3(ulong_t, ushort_t);
888 extern void ndmp_copy_addr_v3(ndmp_addr_v3 *, ndmp_addr_v3 *);
889 extern void ndmp_copy_addr_v4(ndmp_addr_v4 *, ndmp_addr_v4 *);
890 extern char *ndmp_addr2str_v3(ndmp_addr_type);
891 extern boolean_t ndmp_valid_v3addr_type(ndmp_addr_type);
892 extern boolean_t ndmp_check_utf8magic(tlm_cmd_t *);
893 extern int ndmp_get_cur_bk_time(ndmp_lbr_params_t *,
894     time_t *, char *);
895 extern char *ndmp_get_relative_path(char *, char *);
896 
897 extern boolean_t ndmp_fhinode;
898 extern void ndmp_load_params(void);
899 extern void randomize(unsigned char *, int);
900 
901 
902 /*
903  * Utility functions from ndmpd_tar3.c.
904  */
905 extern ndmp_error ndmp_restore_get_params_v3(ndmpd_session_t *,
906     ndmpd_module_params_t *);
907 extern ndmp_error ndmp_backup_get_params_v3(ndmpd_session_t *,
908     ndmpd_module_params_t *);
909 extern char *get_bk_path_v3(ndmpd_module_params_t *);
910 
911 /*
912  * door init and fini function from ndmpd_door_serv.c
913  */
914 extern int ndmp_door_init(void);
915 extern void ndmp_door_fini(void);
916 extern boolean_t ndmp_door_check(void);
917 
918 extern int ndmp_get_max_tok_seq(void);
919 extern boolean_t set_debug_level(boolean_t);
920 extern boolean_t get_debug_level(void);
921 
922 typedef struct ndmp_chkpnt_vol {
923 	char cv_vol_name[64];
924 	unsigned int cv_count;
925 	void *cv_next;
926 } ndmp_chkpnt_vol_t;
927 
928 extern int get_zfsvolname(char *, int, char *);
929 extern int ndmp_start_check_point(char *, char *);
930 extern int ndmp_release_check_point(char *, char *);
931 extern int ndmpd_mark_inodes_v2(ndmpd_session_t *, ndmp_lbr_params_t *);
932 extern void ndmpd_abort_marking_v2(ndmpd_session_t *);
933 extern int ndmpd_mark_inodes_v3(ndmpd_session_t *, ndmp_lbr_params_t *);
934 extern ndmp_lbr_params_t *ndmp_get_nlp(void *);
935 
936 module_start_func_t	ndmpd_tar_backup_starter;
937 module_abort_func_t	ndmpd_tar_backup_abort;
938 
939 module_start_func_t	ndmpd_tar_restore_starter;
940 module_abort_func_t	ndmpd_tar_restore_abort;
941 
942 module_start_func_t ndmpd_tar_backup_starter_v3;
943 module_abort_func_t ndmpd_tar_backup_abort_v3;
944 
945 module_start_func_t ndmpd_tar_restore_starter_v3;
946 module_abort_func_t ndmpd_tar_restore_abort_v3;
947 
948 extern int ndmp_backup_extract_params(ndmpd_session_t *,
949     ndmpd_module_params_t *);
950 extern int ndmp_restore_extract_params(ndmpd_session_t *,
951     ndmpd_module_params_t *);
952 extern int ndmp_tar_reader(ndmp_tar_reader_arg_t *);
953 
954 extern int tape_open(char *, int);
955 
956 extern void ndmp_session_ref(ndmpd_session_t *);
957 extern void ndmp_session_unref(ndmpd_session_t *);
958 
959 void ndmpd_get_file_entry_type(int, ndmp_file_type *);
960 
961 extern int tcp_accept(int, unsigned int *);
962 extern int tcp_get_peer(int, unsigned int *, int *);
963 
964 extern char *gethostaddr(void);
965 extern int tlm_init(void);
966 
967 extern int chkpnt_backup_successful(char *, char *);
968 extern int chkpnt_backup_prepare(char *, char *);
969 
970 extern boolean_t fs_is_chkpntvol(char *);
971 extern boolean_t fs_is_chkpnt_enabled(char *);
972 extern boolean_t fs_is_rdonly(char *);
973 extern boolean_t fs_volexist(char *);
974 extern boolean_t fs_is_valid_logvol(char *);
975 extern boolean_t rootfs_dot_or_dotdot(char *);
976 extern int dp_readdir(DIR *, unsigned long *, char *,
977     int *, unsigned long *);
978 
979 extern void scsi_find_sid_lun();
980 extern char *sasd_slink_name();
981 extern int scsi_dev_exists(char *, int, int);
982 extern int scsi_get_devtype(char *, int, int);
983 extern struct open_list *ndmp_open_list_find(char *, int, int);
984 extern int filecopy(char *, char *);
985 
986 extern void ndmp_stop_local_reader();
987 extern void ndmp_stop_remote_reader();
988 
989 extern boolean_t match(char *, char *);
990 extern char *trim_whitespace(char *);
991 extern int fs_getstat(char *, struct fs_fhandle *, struct stat64 *,
992     path_list_t *);
993 extern int fs_readdir(struct fs_fhandle *, char *, long *,
994     char *, int *, struct fs_fhandle *, struct stat64 *,
995     path_list_t *);
996 extern int iscreated(ndmp_lbr_params_t *nlp, char *name, tlm_acls_t *tacl,
997     time_t t);
998 
999 extern int sasd_dev_count(void);
1000 extern struct scsi_link *sasd_dev_slink(int);
1001 extern struct sasd_drive *sasd_drive(int);
1002 extern void *ndmp_malloc(size_t size);
1003 
1004 extern ndmp_plugin_t *ndmp_pl;
1005 #endif /* _NDMPD_H */
1006