xref: /titanic_52/usr/src/cmd/ndmpd/ndmp/ndmpd.h (revision 2e0fe3efe5f9d579d4e44b3532d8e342c68b40ca)
1 /*
2  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 
5 /*
6  * BSD 3 Clause License
7  *
8  * Copyright (c) 2007, The Storage Networking Industry Association.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 	- Redistributions of source code must retain the above copyright
14  *	  notice, this list of conditions and the following disclaimer.
15  *
16  * 	- Redistributions in binary form must reproduce the above copyright
17  *	  notice, this list of conditions and the following disclaimer in
18  *	  the documentation and/or other materials provided with the
19  *	  distribution.
20  *
21  *	- Neither the name of The Storage Networking Industry Association (SNIA)
22  *	  nor the names of its contributors may be used to endorse or promote
23  *	  products derived from this software without specific prior written
24  *	  permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 /* Copyright (c) 2007, The Storage Networking Industry Association. */
39 /* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
40 
41 #ifndef _NDMPD_H
42 #define	_NDMPD_H
43 
44 #include <sys/types.h>
45 #include <libzfs.h>
46 #include <ndmpd_door.h>
47 #include <libndmp.h>
48 #include "ndmpd_common.h"
49 #include "tlm_buffers.h"
50 #include <dirent.h>
51 #include "ndmpd_prop.h"
52 #include "traverse.h"
53 #include <pthread.h>
54 #include <libndmp.h>
55 #include <atomic.h>
56 
57 #define	MAX_RECORD_SIZE (126*512)
58 #define	REMOTE_RECORD_SIZE    (60*KILOBYTE)
59 #define	SCSI_MAX_NAME 32
60 #define	MD5_CHALLENGE_SIZE	64
61 #define	MD5_PASS_LIMIT		32
62 
63 /* Test unit ready */
64 #define	TUR_WAIT	3000000
65 #define	TUR_MAX_TRY	3
66 
67 
68 /* File handler classes */
69 #define	HC_CLIENT	1
70 #define	HC_MOVER	2
71 #define	HC_MODULE	4
72 #define	HC_ALL		0xffffffff
73 
74 #define	IN_ADDR(x) \
75 	(*(struct in_addr *)&x)
76 
77 #define	FS_READONLY(fs)		(hasmntopt(fs, "ro")  ? 1 :  0)
78 
79 typedef void *(*funct_t)(void *);	/* function pointer */
80 
81 #define	HOSTNAMELEN	256
82 
83 #define	VENDOR_NAME	"Sun Microsystems"
84 #define	PRODUCT_NAME	"Solaris 5.11"
85 
86 /*
87  * Calculate array length based on its size and size of
88  * its elements.
89  */
90 #define	ARRAY_LEN(a, t)	(sizeof (a) / sizeof (t))
91 /*
92  * Default maximum permitted sequence number for the token-based backup.
93  */
94 #define	NDMP_MAX_TOKSEQ	9
95 
96 /*
97  * Hard-limit for the sequence number in the token-based backup.
98  * It's one less than the ASCII value of 'A'.  The 'A' letter
99  * can be used as level in the lbr-type backups.
100  */
101 #define	NDMP_TOKSEQ_HLIMIT	('A' - 1)
102 
103 
104 /*
105  * Soft-limit for the sequence number in the token-based backup.
106  */
107 #define	NDMP_TOKSEQ_SLIMIT	(NDMP_TOKSEQ_HLIMIT - 5)
108 
109 
110 /*
111  * Root inode number of dump format in V2.
112  */
113 #define	ROOT_INODE	2
114 
115 /*
116  * NDMP backup image signature
117  */
118 #define	NDMPUTF8MAGIC "NDMPUTF8MAGIC"
119 
120 /*
121  * Supported BU types
122  */
123 #define	NDMP_TAR_TYPE	"tar"
124 #define	NDMP_DUMP_TYPE	"dump"
125 #define	NDMP_ZFS_TYPE	"zfs"
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 typedef struct ndmpd_file_handler {
288 	int fh_fd;
289 	ulong_t fh_mode;
290 	ulong_t fh_class;
291 	void *fh_cookie;
292 	ndmpd_file_handler_func_t *fh_func;
293 	struct ndmpd_file_handler *fh_next;
294 } ndmpd_file_handler_t;
295 
296 typedef struct ndmpd_session_scsi_desc {
297 	int sd_is_open;
298 	int sd_devid;
299 	boolean_t sd_valid_target_set;
300 	int sd_sid;
301 	int sd_lun;
302 	char sd_adapter_name[SCSI_MAX_NAME];
303 } ndmpd_session_scsi_desc_t;
304 
305 typedef struct ndmpd_session_tape_desc {
306 	int td_fd;			/* tape device file descriptor */
307 	ulong_t td_record_count;	/* number of records written */
308 	ndmp_tape_open_mode td_mode;	/* tape device open mode */
309 	u_longlong_t td_pos;	/* current position on the current tape */
310 	int td_sid;
311 	int td_lun;
312 	char td_adapter_name[SCSI_MAX_NAME];
313 	ulong_t td_eom_seen:1,
314 		td_io_err:1,
315 		td_write:1;
316 } ndmpd_session_tape_desc_t;
317 
318 typedef struct ndmpd_session_mover_desc {
319 	ndmp_mover_state md_state;	/* current state */
320 	ndmp_mover_mode md_mode;	/* current mode */
321 	ndmp_mover_pause_reason md_pause_reason;	/* current reason */
322 	ndmp_mover_halt_reason md_halt_reason;	/* current reason */
323 	u_longlong_t md_data_written;	/* total written to tape */
324 	u_longlong_t md_seek_position;	/* current seek position */
325 	u_longlong_t md_bytes_left_to_read; /* #bytes to end of seek window */
326 	u_longlong_t md_window_offset;	/* valid data window begin */
327 	u_longlong_t md_window_length;	/* valid data window length */
328 	u_longlong_t md_position;	/* current data stream pos */
329 	boolean_t md_pre_cond;		/* used for precondition checks */
330 	ulong_t md_record_size;	/* tape I/O record size */
331 	ulong_t md_record_num;	/* current record num */
332 	int md_listen_sock;		/* data conn listen socket */
333 	int md_sock;		/* data conn socket */
334 	ulong_t md_r_index;		/* buffer read  index */
335 	ulong_t md_w_index;		/* buffer write index */
336 	char *md_buf;		/* data buffer */
337 	/*
338 	 * V2 fields.
339 	 */
340 	ulong_t md_discard_length;	/* bytes to discard */
341 
342 	/*
343 	 * V3 fields.
344 	 */
345 	ndmp_addr_v3 md_data_addr;
346 	/*
347 	 * V4 fields.
348 	 */
349 	ndmp_addr_v4 md_data_addr_v4;
350 } ndmpd_session_mover_desc_t;
351 
352 
353 typedef struct ndmpd_session_data_module {
354 	void *dm_module_cookie;	/* sent as abort_func param */
355 	module_start_func_t *dm_start_func;	/* start function */
356 	module_abort_func_t *dm_abort_func;	/* abort function */
357 	ndmpd_module_stats dm_stats;	/* statistics buffer */
358 } ndmpd_session_data_module_t;
359 
360 typedef struct ndmpd_session_data_desc {
361 	/*
362 	 * Common fields.
363 	 */
364 	ndmp_data_operation dd_operation;	/* current operation */
365 	boolean_t dd_abort;		/* abort operation flag */
366 	boolean_t dd_io_ready;		/* mover sock read for I/O */
367 	ndmp_pval *dd_env;	/* environment from backup or recover request */
368 	ulong_t dd_env_len;		/* environment length */
369 	ulong_t dd_nlist_len;	/* recover file list length */
370 	int dd_sock;		/* listen and data socket */
371 	u_longlong_t dd_read_offset;	/* data read seek offset */
372 	u_longlong_t dd_read_length;	/* data read length */
373 	u_longlong_t dd_data_size;	/* data size to be backed up */
374 	ndmpd_session_data_module_t dd_module;
375 
376 	ndmp_data_state dd_state;	/* current state */
377 	ndmp_data_halt_reason dd_halt_reason;		/* current reason */
378 	/*
379 	 * V2 fields.
380 	 */
381 	ndmp_name *dd_nlist;	/* recover file list */
382 	ndmp_mover_addr dd_mover;	/* mover address */
383 	/*
384 	 * V3 fields.
385 	 */
386 	mem_ndmp_name_v3_t *dd_nlist_v3;
387 	ndmp_addr_v3 dd_data_addr;
388 	int dd_listen_sock;	/* socket for listening for remote */
389 				/* mover connections */
390 	u_longlong_t dd_bytes_left_to_read;
391 	u_longlong_t dd_position;
392 	u_longlong_t dd_discard_length;
393 	/*
394 	 * V4 fields.
395 	 */
396 	ndmp_addr_v4 dd_data_addr_v4;
397 } ndmpd_session_data_desc_t;
398 
399 typedef struct ndmpd_session_file_history {
400 	ndmp_fh_unix_path *fh_path_entries;
401 	ndmp_fh_unix_dir *fh_dir_entries;
402 	ndmp_fh_unix_node *fh_node_entries;
403 	char *fh_path_name_buf;
404 	char *fh_dir_name_buf;
405 	ulong_t fh_path_index;
406 	ulong_t fh_dir_index;
407 	ulong_t fh_node_index;
408 	ulong_t fh_path_name_buf_index;
409 	ulong_t fh_dir_name_buf_index;
410 } ndmpd_session_file_history_t;
411 
412 typedef struct ndmpd_session_file_history_v3 {
413 	ndmp_file_v3 *fh_files;
414 	ndmp_dir_v3 *fh_dirs;
415 	ndmp_node_v3 *fh_nodes;
416 	ndmp_file_name_v3 *fh_file_names;
417 	ndmp_file_name_v3 *fh_dir_names;
418 	ndmp_file_stat_v3 *fh_file_stats;
419 	ndmp_file_stat_v3 *fh_node_stats;
420 	char *fh_file_name_buf;
421 	char *fh_dir_name_buf;
422 	ulong_t fh_file_index;
423 	ulong_t fh_dir_index;
424 	ulong_t fh_node_index;
425 	ulong_t fh_file_name_buf_index;
426 	ulong_t fh_dir_name_buf_index;
427 } ndmpd_session_file_history_v3_t;
428 
429 /*
430  * zfs-based backup (zfs send/recv)
431  */
432 
433 typedef enum {
434 	NDMPD_ZFS_MAJOR_0,
435 } ndmpd_zfs_major_t;
436 
437 typedef enum {
438 	NDMPD_ZFS_MINOR_0,
439 } ndmpd_zfs_minor_t;
440 
441 typedef enum {
442 	NDMPD_ZFS_PROP_MAJOR_0,
443 } ndmpd_zfs_prop_major_t;
444 
445 typedef enum {
446 	NDMPD_ZFS_PROP_MINOR_0,
447 } ndmpd_zfs_prop_minor_t;
448 
449 #define	NDMPD_ZFS_MAJOR_VERSION NDMPD_ZFS_MAJOR_0
450 #define	NDMPD_ZFS_MINOR_VERSION NDMPD_ZFS_MINOR_0
451 #define	NDMPD_ZFS_PROP_MAJOR_VERSION NDMPD_ZFS_PROP_MAJOR_0
452 #define	NDMPD_ZFS_PROP_MINOR_VERSION NDMPD_ZFS_PROP_MINOR_0
453 
454 #pragma pack(1)
455 typedef struct {
456 	char nzh_magic[14]; /* NDMPUTF8MAGIC\0 */
457 	uint32_t nzh_major; /* major version */
458 	uint32_t nzh_minor; /* minor version */
459 	uint32_t nzh_hdrlen; /* length of hdr in bytes including magic */
460 	/* future extensions */
461 } ndmpd_zfs_header_t;
462 #pragma pack()
463 
464 #define	PIPE_TAPE 0
465 #define	PIPE_ZFS 1
466 
467 #define	NDMPD_ZFS_DMP_NAME_MAX 32
468 
469 typedef struct ndmpd_zfs_args {
470 	zfs_type_t nz_type;			/* type of ZFS dataset */
471 	char nz_dataset[ZFS_MAXNAMELEN];	/* dataset name */
472 	char nz_snapname[ZFS_MAXNAMELEN];	/* snapname (following '@') */
473 	char nz_fromsnap[ZFS_MAXNAMELEN];	/* snap of L-1 bkup */
474 	char nz_snapprop[ZFS_MAXPROPLEN];	/* contents of snap incr prop */
475 	boolean_t nz_ndmpd_snap;		/* ndmpd-generated snap? */
476 
477 	pthread_t nz_sendrecv_thread;		/* thread for send/recv */
478 	pthread_t nz_tape_thread;		/* thread for tape r/w */
479 	int32_t nz_pipe_fd[2];			/* pipe for above 2 threads */
480 	int32_t nz_bufsize;			/* tape r/w buf size */
481 	int64_t nz_window_len;			/* DMA window length */
482 
483 	int nz_level;				/* val of LEVEL env var */
484 	char nz_zfs_mode;			/* val of ZFS_MODE env var */
485 	boolean_t nz_zfs_force;			/* val of ZFS_FORCE env var */
486 	boolean_t nz_update;			/* val of UPDATE env var */
487 	char nz_dmp_name[NDMPD_ZFS_DMP_NAME_MAX]; /* val of DMP_NAME env var */
488 
489 	ndmpd_module_params_t nz_params;
490 	ndmp_lbr_params_t *nz_nlp;
491 	libzfs_handle_t *nz_zlibh;		/* session-specific lzfs hdl */
492 	ndmp_context_t nz_nctx;			/* used by plugin */
493 
494 	ndmpd_zfs_header_t nz_tape_header;	/* tape hdr for "zfs" backup */
495 } ndmpd_zfs_args_t;
496 
497 #define	ndmpd_zfs_params (&(ndmpd_zfs_args)->nz_params)
498 
499 typedef struct ndmpd_session {
500 	ndmp_connection_t *ns_connection;	/* NDMP connection to client */
501 	boolean_t ns_eof;		/* connection EOF flag */
502 	ushort_t ns_protocol_version;	/* connection protocol version */
503 	ndmpd_session_scsi_desc_t ns_scsi;
504 	ndmpd_session_tape_desc_t ns_tape;
505 	ndmpd_session_mover_desc_t ns_mover;
506 	ndmpd_session_data_desc_t ns_data;
507 	ndmpd_session_file_history_t ns_fh;
508 	ndmpd_file_handler_t *ns_file_handler_list; /* for I/O multiplexing */
509 	int ns_nref;
510 	ndmp_lbr_params_t *ns_ndmp_lbr_params;
511 	struct ndmpd_zfs_args ns_ndmpd_zfs_args;
512 	ndmpd_backup_type_t ns_butype;
513 	mutex_t ns_lock;
514 
515 	/*
516 	 * NDMP V3
517 	 * Tape, SCSI, mover, data and file handlers will
518 	 * be shared between V2 and V3.
519 	 */
520 	ndmpd_session_file_history_v3_t ns_fh_v3;
521 	unsigned char ns_challenge[MD5_CHALLENGE_SIZE];  /* For MD5 */
522 
523 	/*
524 	 * NDMP V4 related data
525 	 */
526 	boolean_t ns_set_ext_list;
527 
528 	/* handling of hardlink, hardlink queue head */
529 	struct hardlink_q *hardlink_q;
530 } ndmpd_session_t;
531 
532 
533 /*
534  * NDMP request handler functions.
535  */
536 
537 /* Config */
538 ndmp_msg_handler_func_t ndmpd_config_get_host_info_v2;
539 ndmp_msg_handler_func_t ndmpd_config_get_butype_attr_v2;
540 ndmp_msg_handler_func_t ndmpd_config_get_mover_type_v2;
541 ndmp_msg_handler_func_t ndmpd_config_get_auth_attr_v2;
542 
543 ndmp_msg_handler_func_t ndmpd_config_get_host_info_v3;
544 ndmp_msg_handler_func_t ndmpd_config_get_butype_info_v3;
545 ndmp_msg_handler_func_t ndmpd_config_get_connection_type_v3;
546 ndmp_msg_handler_func_t ndmpd_config_get_auth_attr_v3;
547 ndmp_msg_handler_func_t ndmpd_config_get_fs_info_v3;
548 ndmp_msg_handler_func_t ndmpd_config_get_tape_info_v3;
549 ndmp_msg_handler_func_t ndmpd_config_get_scsi_info_v3;
550 ndmp_msg_handler_func_t ndmpd_config_get_server_info_v3;
551 
552 ndmp_msg_handler_func_t ndmpd_config_get_butype_info_v4;
553 ndmp_msg_handler_func_t ndmpd_config_get_ext_list_v4;
554 ndmp_msg_handler_func_t ndmpd_config_set_ext_list_v4;
555 
556 
557 /* Scsi */
558 ndmp_msg_handler_func_t ndmpd_scsi_open_v2;
559 ndmp_msg_handler_func_t ndmpd_scsi_close_v2;
560 ndmp_msg_handler_func_t ndmpd_scsi_get_state_v2;
561 ndmp_msg_handler_func_t ndmpd_scsi_set_target_v2;
562 ndmp_msg_handler_func_t ndmpd_scsi_reset_device_v2;
563 ndmp_msg_handler_func_t ndmpd_scsi_reset_bus_v2;
564 ndmp_msg_handler_func_t ndmpd_scsi_execute_cdb_v2;
565 
566 ndmp_msg_handler_func_t ndmpd_scsi_open_v3;
567 ndmp_msg_handler_func_t ndmpd_scsi_set_target_v3;
568 
569 
570 /* Tape */
571 ndmp_msg_handler_func_t ndmpd_tape_open_v2;
572 ndmp_msg_handler_func_t ndmpd_tape_close_v2;
573 ndmp_msg_handler_func_t ndmpd_tape_get_state_v2;
574 ndmp_msg_handler_func_t ndmpd_tape_mtio_v2;
575 ndmp_msg_handler_func_t ndmpd_tape_write_v2;
576 ndmp_msg_handler_func_t ndmpd_tape_read_v2;
577 ndmp_msg_handler_func_t ndmpd_tape_execute_cdb_v2;
578 
579 ndmp_msg_handler_func_t ndmpd_tape_open_v3;
580 ndmp_msg_handler_func_t ndmpd_tape_get_state_v3;
581 ndmp_msg_handler_func_t ndmpd_tape_write_v3;
582 ndmp_msg_handler_func_t ndmpd_tape_read_v3;
583 
584 
585 ndmp_msg_handler_func_t ndmpd_tape_close_v4;
586 /* Data */
587 ndmp_msg_handler_func_t ndmpd_data_get_state_v2;
588 ndmp_msg_handler_func_t ndmpd_data_start_backup_v2;
589 ndmp_msg_handler_func_t ndmpd_data_start_recover_v2;
590 ndmp_msg_handler_func_t ndmpd_data_get_env_v2;
591 ndmp_msg_handler_func_t ndmpd_data_stop_v2;
592 ndmp_msg_handler_func_t ndmpd_data_abort_v2;
593 
594 ndmp_msg_handler_func_t ndmpd_data_get_state_v3;
595 ndmp_msg_handler_func_t ndmpd_data_connect_v3;
596 ndmp_msg_handler_func_t ndmpd_data_listen_v3;
597 ndmp_msg_handler_func_t ndmpd_data_stop_v3;
598 ndmp_msg_handler_func_t ndmpd_data_abort_v3;
599 ndmp_msg_handler_func_t ndmpd_data_start_recover_v3;
600 ndmp_msg_handler_func_t ndmpd_data_start_backup_v3;
601 
602 ndmp_msg_handler_func_t ndmpd_data_get_env_v4;
603 ndmp_msg_handler_func_t ndmpd_data_get_state_v4;
604 ndmp_msg_handler_func_t ndmpd_data_connect_v4;
605 ndmp_msg_handler_func_t ndmpd_data_listen_v4;
606 ndmp_msg_handler_func_t ndmpd_data_start_recover_filehist_v4;
607 
608 
609 /* Connect */
610 ndmp_msg_handler_func_t ndmpd_connect_open_v2;
611 ndmp_msg_handler_func_t ndmpd_connect_client_auth_v2;
612 ndmp_msg_handler_func_t ndmpd_connect_server_auth_v2;
613 ndmp_msg_handler_func_t ndmpd_connect_close_v2;
614 
615 ndmp_msg_handler_func_t ndmpd_connect_client_auth_v3;
616 ndmp_msg_handler_func_t ndmpd_connect_close_v3;
617 
618 
619 /* Mover */
620 ndmp_msg_handler_func_t ndmpd_mover_get_state_v2;
621 ndmp_msg_handler_func_t ndmpd_mover_listen_v2;
622 ndmp_msg_handler_func_t ndmpd_mover_continue_v2;
623 ndmp_msg_handler_func_t ndmpd_mover_abort_v2;
624 ndmp_msg_handler_func_t ndmpd_mover_stop_v2;
625 ndmp_msg_handler_func_t ndmpd_mover_set_window_v2;
626 ndmp_msg_handler_func_t ndmpd_mover_read_v2;
627 ndmp_msg_handler_func_t ndmpd_mover_close_v2;
628 ndmp_msg_handler_func_t ndmpd_mover_set_record_size_v2;
629 
630 ndmp_msg_handler_func_t ndmpd_mover_get_state_v3;
631 ndmp_msg_handler_func_t ndmpd_mover_listen_v3;
632 ndmp_msg_handler_func_t ndmpd_mover_continue_v3;
633 ndmp_msg_handler_func_t ndmpd_mover_abort_v3;
634 ndmp_msg_handler_func_t ndmpd_mover_set_window_v3;
635 ndmp_msg_handler_func_t ndmpd_mover_read_v3;
636 ndmp_msg_handler_func_t ndmpd_mover_set_record_size_v3;
637 ndmp_msg_handler_func_t ndmpd_mover_connect_v3;
638 
639 
640 ndmp_msg_handler_func_t ndmpd_mover_get_state_v4;
641 ndmp_msg_handler_func_t ndmpd_mover_listen_v4;
642 ndmp_msg_handler_func_t ndmpd_mover_connect_v4;
643 
644 
645 /*
646  * Backup/recover module API functions.
647  */
648 ndmpd_get_env_func_t ndmpd_api_get_env;
649 ndmpd_add_env_func_t ndmpd_api_add_env;
650 ndmpd_add_env_func_t ndmpd_api_set_env;
651 ndmpd_get_name_func_t ndmpd_api_get_name;
652 ndmpd_dispatch_func_t ndmpd_api_dispatch;
653 ndmpd_done_func_t ndmpd_api_done_v2;
654 
655 
656 ndmpd_write_func_t ndmpd_api_write_v2;
657 ndmpd_file_history_path_func_t ndmpd_api_file_history_path_v2;
658 ndmpd_file_history_dir_func_t ndmpd_api_file_history_dir_v2;
659 ndmpd_file_history_node_func_t ndmpd_api_file_history_node_v2;
660 ndmpd_read_func_t ndmpd_api_read_v2;
661 ndmpd_seek_func_t ndmpd_api_seek_v2;
662 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v2;
663 ndmpd_add_file_handler_func_t ndmpd_api_add_file_handler;
664 ndmpd_remove_file_handler_func_t ndmpd_api_remove_file_handler;
665 
666 
667 /*
668  * NDMP V3
669  */
670 ndmpd_done_func_t ndmpd_api_done_v3;
671 ndmpd_write_func_t ndmpd_api_write_v3;
672 ndmpd_read_func_t ndmpd_api_read_v3;
673 ndmpd_seek_func_t ndmpd_api_seek_v3;
674 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v3;
675 ndmpd_get_name_func_t ndmpd_api_get_name_v3;
676 ndmpd_file_history_path_func_t ndmpd_api_file_history_file_v3;
677 ndmpd_file_history_dir_func_t ndmpd_api_file_history_dir_v3;
678 ndmpd_file_history_node_func_t ndmpd_api_file_history_node_v3;
679 
680 /*
681  * NDMP V4
682  */
683 ndmpd_log_func_v3_t ndmpd_api_log_v4;
684 ndmpd_file_recovered_func_t ndmpd_api_file_recovered_v4;
685 
686 #ifndef NO_NDMP_API_LOG_PROTOTYPES
687 ndmpd_log_func_t ndmpd_api_log_v2;
688 ndmpd_log_func_v3_t ndmpd_api_log_v3;
689 #endif /* NO_NDMP_API_LOG_PROTOTYPES */
690 
691 typedef void ndmpd_func_t(ndmp_connection_t *, void *);
692 
693 /*
694  * pthread call arg parameters
695  */
696 typedef struct {
697 	int nw_sock;
698 	long nw_ipaddr;
699 	ndmp_con_handler_func_t nw_con_handler_func;
700 } ndmpd_worker_arg_t;
701 
702 typedef struct {
703 	char *br_jname;
704 	ndmp_lbr_params_t *br_nlp;
705 	tlm_commands_t *br_cmds;
706 	pthread_barrier_t br_barrier;
707 } backup_reader_arg_t;
708 
709 typedef struct {
710 	ndmpd_session_t *tr_session;
711 	ndmpd_module_params_t *tr_mod_params;
712 	tlm_commands_t *tr_cmds;
713 } ndmp_tar_reader_arg_t;
714 
715 typedef struct {
716 	ndmpd_session_t *bs_session;
717 	char *bs_jname;
718 	char *bs_path;
719 } ndmp_bkup_size_arg_t;
720 
721 /*
722  * Variables from ndmpd_comm.c
723  */
724 extern int ndmp_ver;
725 extern int ndmp_full_restore_path;
726 extern int ndmp_dar_support;
727 extern int ndmp_port;
728 extern ndmp_stat_t ndstat;
729 
730 extern void ndmpd_main(void);
731 extern void connection_handler(ndmp_connection_t *);
732 extern void ndmpd_audit_backup(ndmp_connection_t *conn, char *path,
733     int dest, char *local_path, int result);
734 extern void ndmpd_audit_restore(ndmp_connection_t *conn,
735     char *path, int dest, char *local_path, int result);
736 extern void ndmpd_audit_connect(ndmp_connection_t *conn,
737     int result);
738 extern void ndmpd_audit_disconnect(ndmp_connection_t *conn);
739 
740 /* Variables from ndmpd_main.c */
741 extern	libzfs_handle_t	*zlibh;
742 extern	mutex_t	zlib_mtx;
743 
744 /*
745  * Utility from ndmpd_connect.c.
746  */
747 extern int ndmp_connect_list_add(ndmp_connection_t *, int *);
748 extern int ndmp_connect_list_del(ndmp_connection_t *);
749 extern int ndmpd_connect_kill_id(int);
750 extern void ndmp_connect_list_get(ndmp_door_ctx_t *);
751 extern void ndmpd_get_devs(ndmp_door_ctx_t *);
752 
753 /*
754  * Utility functions form ndmpd_data.c.
755  */
756 extern void ndmpd_data_cleanup(ndmpd_session_t *);
757 extern int ndmpd_data_init(ndmpd_session_t *);
758 extern char *ndmp_data_get_mover_mode(ndmpd_session_t *);
759 extern void ndmpd_data_error(ndmpd_session_t *, ndmp_data_halt_reason);
760 
761 
762 /*
763  * Utility functions from ndmpd_mover.c.
764  */
765 extern int ndmpd_mover_init(ndmpd_session_t *);
766 extern void ndmpd_mover_cleanup(ndmpd_session_t *);
767 extern ndmp_error ndmpd_mover_connect(ndmpd_session_t *,
768     ndmp_mover_mode);
769 extern void ndmpd_mover_error(ndmpd_session_t *,
770     ndmp_mover_halt_reason);
771 extern int ndmpd_mover_seek(ndmpd_session_t *,
772     u_longlong_t,
773     u_longlong_t);
774 extern int ndmpd_local_write(ndmpd_session_t *,
775     char *,
776     ulong_t);
777 extern int ndmpd_remote_write(ndmpd_session_t *,
778     char *,
779     ulong_t);
780 extern int ndmpd_local_read(ndmpd_session_t *,
781     char *,
782     ulong_t);
783 extern int ndmpd_remote_read(ndmpd_session_t *,
784     char *,
785     ulong_t);
786 
787 extern void ndmpd_mover_shut_down(ndmpd_session_t *);
788 extern void ndmpd_mover_error(ndmpd_session_t *,
789     ndmp_mover_halt_reason);
790 extern int ndmpd_local_write_v3(ndmpd_session_t *,
791     char *,
792     ulong_t);
793 extern int ndmpd_local_read_v3(ndmpd_session_t *,
794     char *,
795     ulong_t);
796 extern int ndmpd_remote_read_v3(ndmpd_session_t *,
797     char *,
798     ulong_t);
799 extern int ndmpd_mover_wait_v3(ndmpd_session_t *);
800 extern void ndmpd_write_eom(int);
801 
802 
803 /*
804  * Utility functions from ndmpd_file_history.c
805  */
806 extern void ndmpd_file_history_init(ndmpd_session_t *);
807 extern void ndmpd_file_history_cleanup(ndmpd_session_t *,
808     boolean_t);
809 extern int ndmpd_file_history_path(lbr_fhlog_call_backs_t *,
810     char *,
811     struct stat64 *,
812     u_longlong_t);
813 extern int ndmpd_file_history_dir(lbr_fhlog_call_backs_t *,
814     char *,
815     struct stat64 *);
816 extern int ndmpd_file_history_node(lbr_fhlog_call_backs_t *,
817     char *,
818     char *,
819     struct stat64 *,
820     u_longlong_t);
821 extern int
822 ndmpd_path_restored(lbr_fhlog_call_backs_t *,
823     char *,
824     struct stat64 *,
825     u_longlong_t);
826 extern int ndmpd_fhpath_v3_cb(lbr_fhlog_call_backs_t *,
827     char *,
828     struct stat64 *,
829     u_longlong_t);
830 extern int ndmpd_fhdir_v3_cb(lbr_fhlog_call_backs_t *,
831     char *,
832     struct stat64 *);
833 extern int ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t *,
834     char *,
835     char *,
836     struct stat64 *,
837     u_longlong_t);
838 extern int ndmpd_path_restored_v3(lbr_fhlog_call_backs_t *,
839     char *,
840     struct stat64 *,
841     u_longlong_t);
842 
843 extern int ndmp_send_recovery_stat_v3(ndmpd_module_params_t *,
844     ndmp_lbr_params_t *,
845     int,
846     int);
847 
848 
849 /*
850  * Utility functions from ndmpd_dtime.c
851  */
852 extern int ndmpd_put_dumptime(char *, int, time_t);
853 extern int ndmpd_get_dumptime(char *, int *, time_t *);
854 extern int ndmpd_append_dumptime(char *, char *, int, time_t);
855 
856 
857 /*
858  * Global variables from ndmpd_tar3.c
859  */
860 extern char **ndmp_excl_list;
861 
862 
863 /*
864  * Global variables from ndmpd_util.c
865  */
866 extern int ndmp_force_bk_dirs;
867 extern int ndmp_rbs;
868 extern int ndmp_sbs;
869 extern boolean_t ndmp_dump_path_node;
870 extern boolean_t ndmp_tar_path_node;
871 extern boolean_t ndmp_ignore_ctime;
872 extern boolean_t ndmp_include_lmtime;
873 
874 
875 /*
876  * Utility functions from ndmpd_util.c.
877  */
878 extern int ndmpd_select(ndmpd_session_t *,
879     boolean_t,
880     ulong_t);
881 
882 extern ndmp_error ndmpd_save_env(ndmpd_session_t *,
883     ndmp_pval *,
884     ulong_t);
885 
886 extern void ndmpd_free_env(ndmpd_session_t *);
887 extern ndmp_error ndmpd_save_nlist_v2(ndmpd_session_t *,
888     ndmp_name *,
889     ulong_t);
890 
891 extern void ndmpd_free_nlist(ndmpd_session_t *);
892 extern int ndmpd_add_file_handler(ndmpd_session_t *,
893     void *,
894     int,
895     ulong_t,
896     ulong_t,
897     ndmpd_file_handler_func_t *);
898 
899 extern int ndmpd_remove_file_handler(ndmpd_session_t *,
900     int);
901 
902 extern void ndmp_send_reply(ndmp_connection_t *,
903     void *,
904     char *);
905 
906 extern int ndmp_mtioctl(int, int, int);
907 
908 extern u_longlong_t quad_to_long_long(ndmp_u_quad);
909 extern ndmp_u_quad long_long_to_quad(u_longlong_t);
910 
911 extern void ndmp_set_socket_nodelay(int);
912 extern void ndmp_set_socket_snd_buf(int, int);
913 extern void ndmp_set_socket_rcv_buf(int, int);
914 
915 extern long ndmp_buffer_get_size(ndmpd_session_t *);
916 extern int ndmp_lbr_init(ndmpd_session_t *);
917 extern void ndmp_lbr_cleanup(ndmpd_session_t *);
918 
919 extern void nlp_ref_nw(ndmpd_session_t *);
920 extern void nlp_unref_nw(ndmpd_session_t *);
921 extern void nlp_wait_nw(ndmpd_session_t *);
922 extern void nlp_event_nw(ndmpd_session_t *);
923 extern int nlp_event_rv_get(ndmpd_session_t *);
924 extern void nlp_event_rv_set(ndmpd_session_t *, int);
925 extern boolean_t is_buffer_erroneous(tlm_buffer_t *);
926 extern void ndmp_execute_cdb(ndmpd_session_t *,
927     char *,
928     int,
929     int,
930     ndmp_execute_cdb_request *);
931 
932 extern scsi_adapter_t *scsi_get_adapter(int);
933 extern boolean_t is_tape_unit_ready(char *, int);
934 
935 extern int ndmp_open_list_add(ndmp_connection_t *, char *, int, int, int);
936 extern int ndmp_open_list_del(char *, int, int);
937 extern void ndmp_open_list_release(ndmp_connection_t *);
938 
939 extern void ndmp_stop_buffer_worker(ndmpd_session_t *);
940 extern void ndmp_stop_reader_thread(ndmpd_session_t *);
941 extern void ndmp_stop_writer_thread(ndmpd_session_t *);
942 extern void ndmp_free_reader_writer_ipc(ndmpd_session_t *);
943 extern void ndmp_waitfor_op(ndmpd_session_t *);
944 
945 extern char *cctime(time_t *);
946 extern char *ndmp_new_job_name(char *);
947 extern char *ndmpd_mk_temp(char *);
948 extern char *ndmpd_make_bk_dir_path(char *, char *);
949 extern boolean_t ndmp_is_chkpnt_root(char *);
950 extern char **ndmpd_make_exc_list(void);
951 extern void ndmp_sort_nlist_v3(ndmpd_session_t *);
952 extern int ndmp_get_bk_dir_ino(ndmp_lbr_params_t *);
953 extern int ndmp_write_utf8magic(tlm_cmd_t *);
954 extern int ndmp_tar_writer(ndmpd_session_t *,
955     ndmpd_module_params_t *,
956     tlm_commands_t *);
957 extern void ndmp_wait_for_reader(tlm_commands_t *);
958 extern ndmp_error ndmpd_save_nlist_v3(ndmpd_session_t *,
959     ndmp_name_v3 *,
960     ulong_t);
961 extern void ndmpd_free_nlist_v3(ndmpd_session_t *);
962 extern int ndmp_create_socket(ulong_t *, ushort_t *);
963 extern int ndmp_connect_sock_v3(ulong_t, ushort_t);
964 extern void ndmp_copy_addr_v3(ndmp_addr_v3 *, ndmp_addr_v3 *);
965 extern void ndmp_copy_addr_v4(ndmp_addr_v4 *, ndmp_addr_v4 *);
966 extern char *ndmp_addr2str_v3(ndmp_addr_type);
967 extern boolean_t ndmp_valid_v3addr_type(ndmp_addr_type);
968 extern boolean_t ndmp_check_utf8magic(tlm_cmd_t *);
969 extern int ndmp_get_cur_bk_time(ndmp_lbr_params_t *,
970     time_t *, char *);
971 extern char *ndmp_get_relative_path(char *, char *);
972 
973 extern boolean_t ndmp_fhinode;
974 extern void ndmp_load_params(void);
975 extern void randomize(unsigned char *, int);
976 
977 
978 /*
979  * Utility functions from ndmpd_tar3.c.
980  */
981 extern ndmp_error ndmp_restore_get_params_v3(ndmpd_session_t *,
982     ndmpd_module_params_t *);
983 extern ndmp_error ndmp_backup_get_params_v3(ndmpd_session_t *,
984     ndmpd_module_params_t *);
985 
986 /*
987  * door init and fini function from ndmpd_door_serv.c
988  */
989 extern int ndmp_door_init(void);
990 extern void ndmp_door_fini(void);
991 extern boolean_t ndmp_door_check(void);
992 
993 extern int ndmp_get_max_tok_seq(void);
994 extern boolean_t set_debug_level(boolean_t);
995 extern boolean_t get_debug_level(void);
996 
997 typedef struct ndmp_chkpnt_vol {
998 	char cv_vol_name[64];
999 	unsigned int cv_count;
1000 	void *cv_next;
1001 } ndmp_chkpnt_vol_t;
1002 
1003 extern int get_zfsvolname(char *, int, char *);
1004 extern int ndmp_start_check_point(char *, char *);
1005 extern int ndmp_release_check_point(char *, char *);
1006 extern int ndmpd_mark_inodes_v2(ndmpd_session_t *, ndmp_lbr_params_t *);
1007 extern void ndmpd_abort_marking_v2(ndmpd_session_t *);
1008 extern int ndmpd_mark_inodes_v3(ndmpd_session_t *, ndmp_lbr_params_t *);
1009 extern ndmp_lbr_params_t *ndmp_get_nlp(void *);
1010 
1011 module_start_func_t ndmpd_tar_backup_starter;
1012 module_abort_func_t ndmpd_tar_backup_abort;
1013 
1014 module_start_func_t ndmpd_tar_restore_starter;
1015 module_abort_func_t ndmpd_tar_restore_abort;
1016 
1017 module_start_func_t ndmpd_tar_backup_starter_v3;
1018 module_abort_func_t ndmpd_tar_backup_abort_v3;
1019 
1020 module_start_func_t ndmpd_tar_restore_starter_v3;
1021 module_abort_func_t ndmpd_tar_restore_abort_v3;
1022 
1023 extern int ndmp_backup_extract_params(ndmpd_session_t *,
1024     ndmpd_module_params_t *);
1025 extern int ndmp_restore_extract_params(ndmpd_session_t *,
1026     ndmpd_module_params_t *);
1027 extern int ndmp_tar_reader(ndmp_tar_reader_arg_t *);
1028 
1029 extern int tape_open(char *, int);
1030 
1031 extern void ndmp_session_ref(ndmpd_session_t *);
1032 extern void ndmp_session_unref(ndmpd_session_t *);
1033 
1034 void ndmpd_get_file_entry_type(int, ndmp_file_type *);
1035 
1036 extern int tcp_accept(int, unsigned int *);
1037 extern int tcp_get_peer(int, unsigned int *, int *);
1038 
1039 extern char *gethostaddr(void);
1040 extern int tlm_init(void);
1041 
1042 extern int chkpnt_backup_successful(char *, char *, boolean_t, int *);
1043 extern int chkpnt_backup_prepare(char *, char *, boolean_t);
1044 
1045 extern boolean_t fs_is_chkpntvol(char *);
1046 extern boolean_t fs_is_chkpnt_enabled(char *);
1047 extern boolean_t fs_is_rdonly(char *);
1048 extern boolean_t fs_volexist(char *);
1049 extern boolean_t fs_is_valid_logvol(char *);
1050 extern boolean_t rootfs_dot_or_dotdot(char *);
1051 extern int dp_readdir(DIR *, unsigned long *, char *,
1052     int *, unsigned long *);
1053 
1054 extern void scsi_find_sid_lun();
1055 extern char *sasd_slink_name();
1056 extern int scsi_dev_exists(char *, int, int);
1057 extern int scsi_get_devtype(char *, int, int);
1058 extern struct open_list *ndmp_open_list_find(char *, int, int);
1059 extern int filecopy(char *, char *);
1060 
1061 extern void ndmp_stop_local_reader();
1062 extern void ndmp_stop_remote_reader();
1063 
1064 extern boolean_t match(char *, char *);
1065 extern char *trim_whitespace(char *);
1066 extern int fs_getstat(char *, struct fs_fhandle *, struct stat64 *);
1067 extern int fs_readdir(struct fs_fhandle *, char *, long *,
1068     char *, int *, struct fs_fhandle *, struct stat64 *);
1069 extern int iscreated(ndmp_lbr_params_t *nlp, char *name, tlm_acls_t *tacl,
1070     time_t t);
1071 
1072 extern int sasd_dev_count(void);
1073 extern struct scsi_link *sasd_dev_slink(int);
1074 extern struct sasd_drive *sasd_drive(int);
1075 extern void *ndmp_malloc(size_t size);
1076 
1077 extern ndmp_plugin_t *ndmp_pl;
1078 
1079 #define	NDMP_APILOG(s, t, m, ...) \
1080 { \
1081 	if (((ndmpd_session_t *)(s))->ns_protocol_version == NDMPV4) \
1082 		(void) ndmpd_api_log_v4(s, t, m, __VA_ARGS__); \
1083 	else if (((ndmpd_session_t *)(s))->ns_protocol_version == NDMPV3) \
1084 		(void) ndmpd_api_log_v3(s, t, m, __VA_ARGS__); \
1085 	else \
1086 		(void) ndmpd_api_log_v2(s, __VA_ARGS__); \
1087 }
1088 
1089 /*
1090  * Backup path utility functions
1091  */
1092 extern char *get_backup_path_v3(ndmpd_module_params_t *);
1093 extern char *get_backup_path_v2(ndmpd_module_params_t *);
1094 
1095 /*
1096  * Functions for zfs-based backup
1097  */
1098 
1099 module_start_func_t ndmpd_zfs_backup_starter;
1100 module_start_func_t ndmpd_zfs_restore_starter;
1101 module_abort_func_t ndmpd_zfs_abort;
1102 
1103 int ndmpd_zfs_init(ndmpd_session_t *);
1104 void ndmpd_zfs_fini(ndmpd_zfs_args_t *);
1105 
1106 boolean_t ndmpd_zfs_backup_parms_valid(ndmpd_zfs_args_t *);
1107 boolean_t ndmpd_zfs_restore_parms_valid(ndmpd_zfs_args_t *);
1108 
1109 int ndmpd_zfs_pre_backup(ndmpd_zfs_args_t *);
1110 int ndmpd_zfs_pre_restore(ndmpd_zfs_args_t *);
1111 int ndmpd_zfs_post_backup(ndmpd_zfs_args_t *);
1112 int ndmpd_zfs_post_restore(ndmpd_zfs_args_t *);
1113 
1114 void ndmpd_zfs_dma_log(ndmpd_zfs_args_t *, ndmp_log_type, char *, ...);
1115 
1116 #endif /* _NDMPD_H */
1117