xref: /titanic_51/usr/src/cmd/ndmpd/include/tlm_buffers.h (revision 2654012f83cec5dc15b61dfe3e4a4915f186e7a6)
1*2654012fSReza Sabdar /*
2*2654012fSReza Sabdar  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3*2654012fSReza Sabdar  * Use is subject to license terms.
4*2654012fSReza Sabdar  */
5*2654012fSReza Sabdar 
6*2654012fSReza Sabdar /*
7*2654012fSReza Sabdar  * BSD 3 Clause License
8*2654012fSReza Sabdar  *
9*2654012fSReza Sabdar  * Copyright (c) 2007, The Storage Networking Industry Association.
10*2654012fSReza Sabdar  *
11*2654012fSReza Sabdar  * Redistribution and use in source and binary forms, with or without
12*2654012fSReza Sabdar  * modification, are permitted provided that the following conditions
13*2654012fSReza Sabdar  * are met:
14*2654012fSReza Sabdar  * 	- Redistributions of source code must retain the above copyright
15*2654012fSReza Sabdar  *	  notice, this list of conditions and the following disclaimer.
16*2654012fSReza Sabdar  *
17*2654012fSReza Sabdar  * 	- Redistributions in binary form must reproduce the above copyright
18*2654012fSReza Sabdar  *	  notice, this list of conditions and the following disclaimer in
19*2654012fSReza Sabdar  *	  the documentation and/or other materials provided with the
20*2654012fSReza Sabdar  *	  distribution.
21*2654012fSReza Sabdar  *
22*2654012fSReza Sabdar  *	- Neither the name of The Storage Networking Industry Association (SNIA)
23*2654012fSReza Sabdar  *	  nor the names of its contributors may be used to endorse or promote
24*2654012fSReza Sabdar  *	  products derived from this software without specific prior written
25*2654012fSReza Sabdar  *	  permission.
26*2654012fSReza Sabdar  *
27*2654012fSReza Sabdar  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28*2654012fSReza Sabdar  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29*2654012fSReza Sabdar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30*2654012fSReza Sabdar  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31*2654012fSReza Sabdar  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32*2654012fSReza Sabdar  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33*2654012fSReza Sabdar  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34*2654012fSReza Sabdar  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35*2654012fSReza Sabdar  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36*2654012fSReza Sabdar  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37*2654012fSReza Sabdar  * POSSIBILITY OF SUCH DAMAGE.
38*2654012fSReza Sabdar  */
39*2654012fSReza Sabdar /*
40*2654012fSReza Sabdar  * This defines structures used to pass information between threads
41*2654012fSReza Sabdar  * for both local-backup and NDMP.
42*2654012fSReza Sabdar  *
43*2654012fSReza Sabdar  */
44*2654012fSReza Sabdar 
45*2654012fSReza Sabdar #ifndef	_TLM_BUFFERS_H_
46*2654012fSReza Sabdar #define	_TLM_BUFFERS_H_
47*2654012fSReza Sabdar 
48*2654012fSReza Sabdar #include <sys/types.h>
49*2654012fSReza Sabdar #include <stdlib.h>
50*2654012fSReza Sabdar #include <limits.h>
51*2654012fSReza Sabdar #include <sys/stat.h>
52*2654012fSReza Sabdar #include <thread.h>
53*2654012fSReza Sabdar #include "tlm.h"
54*2654012fSReza Sabdar 
55*2654012fSReza Sabdar #ifndef RECORDSIZE
56*2654012fSReza Sabdar #define	RECORDSIZE	512
57*2654012fSReza Sabdar #endif /* !RECORDSIZE */
58*2654012fSReza Sabdar 
59*2654012fSReza Sabdar #define	DOTDOT_DIR	".."
60*2654012fSReza Sabdar #define	IS_DOTDOT(s)	(strcmp(s, DOTDOT_DIR) == 0)
61*2654012fSReza Sabdar #define	SLASH	'/'
62*2654012fSReza Sabdar 
63*2654012fSReza Sabdar #define	NDMP_MAX_SELECTIONS	64
64*2654012fSReza Sabdar 
65*2654012fSReza Sabdar /*
66*2654012fSReza Sabdar  * List of files/directories to be excluded from backup list.
67*2654012fSReza Sabdar  */
68*2654012fSReza Sabdar #define	EXCL_PROC	"/proc"
69*2654012fSReza Sabdar #define	EXCL_TMP	"/tmp"
70*2654012fSReza Sabdar 
71*2654012fSReza Sabdar 
72*2654012fSReza Sabdar typedef struct	tlm_buffer {
73*2654012fSReza Sabdar 	char	*tb_buffer_data;	/* area to be used for I/O */
74*2654012fSReza Sabdar 	long	tb_buffer_size;	/* number of valid bytes in the buffer */
75*2654012fSReza Sabdar 	long	tb_buffer_spot;	/* current location in the I/O buffer */
76*2654012fSReza Sabdar 	longlong_t tb_seek_spot;	/* for BACKUP */
77*2654012fSReza Sabdar 				/* where in the file this buffer stops. */
78*2654012fSReza Sabdar 				/* this is used for the Multi Volume */
79*2654012fSReza Sabdar 				/* Header record. */
80*2654012fSReza Sabdar 	longlong_t tb_file_size;	/* for BACKUP */
81*2654012fSReza Sabdar 					/* how much of the file is left. */
82*2654012fSReza Sabdar 	long	tb_full	: 1,
83*2654012fSReza Sabdar 		tb_eot	: 1,
84*2654012fSReza Sabdar 		tb_eof	: 1;
85*2654012fSReza Sabdar 	int	tb_errno;	/* I/O error values */
86*2654012fSReza Sabdar } tlm_buffer_t;
87*2654012fSReza Sabdar 
88*2654012fSReza Sabdar 
89*2654012fSReza Sabdar /*
90*2654012fSReza Sabdar  * Flags for tlm_buffers.
91*2654012fSReza Sabdar  */
92*2654012fSReza Sabdar #define	TLM_BUF_IN_READY	0x00000001
93*2654012fSReza Sabdar #define	TLM_BUF_OUT_READY	0x00000002
94*2654012fSReza Sabdar 
95*2654012fSReza Sabdar typedef struct	tlm_buffers {
96*2654012fSReza Sabdar 	int	tbs_ref;	/* number of threads using this */
97*2654012fSReza Sabdar 	short	tbs_buffer_in;	/* buffer to be filled */
98*2654012fSReza Sabdar 	short	tbs_buffer_out;	/* buffer to be emptied */
99*2654012fSReza Sabdar 				/* these are indexes into tlm_buffers */
100*2654012fSReza Sabdar 	mutex_t	tbs_mtx;
101*2654012fSReza Sabdar 	cond_t	tbs_in_cv;
102*2654012fSReza Sabdar 	cond_t	tbs_out_cv;
103*2654012fSReza Sabdar 	uint32_t	tbs_flags;
104*2654012fSReza Sabdar 	long	tbs_data_transfer_size;	/* max size of read/write buffer */
105*2654012fSReza Sabdar 	longlong_t tbs_offset;
106*2654012fSReza Sabdar 	tlm_buffer_t tbs_buffer[TLM_TAPE_BUFFERS];
107*2654012fSReza Sabdar } tlm_buffers_t;
108*2654012fSReza Sabdar 
109*2654012fSReza Sabdar typedef struct	tlm_cmd {
110*2654012fSReza Sabdar 	int	tc_ref;			/* number of threads using this */
111*2654012fSReza Sabdar 	mutex_t	tc_mtx;
112*2654012fSReza Sabdar 	cond_t	tc_cv;
113*2654012fSReza Sabdar 	uint32_t	tc_flags;
114*2654012fSReza Sabdar 	int	tc_reader;		/* writer to reader */
115*2654012fSReza Sabdar 	int	tc_writer;		/* reader to writer */
116*2654012fSReza Sabdar 	char	tc_file_name[TLM_MAX_PATH_NAME]; /* name of last file */
117*2654012fSReza Sabdar 						/* for restore */
118*2654012fSReza Sabdar 	tlm_buffers_t *tc_buffers; /* reader-writer speedup buffers */
119*2654012fSReza Sabdar } tlm_cmd_t;
120*2654012fSReza Sabdar 
121*2654012fSReza Sabdar typedef struct	tlm_commands {
122*2654012fSReza Sabdar 	int	tcs_reader;	/* commands to all readers */
123*2654012fSReza Sabdar 	int	tcs_writer;	/* commands to all writers */
124*2654012fSReza Sabdar 	int	tcs_reader_count;	/* number of active readers */
125*2654012fSReza Sabdar 	int	tcs_writer_count;	/* number of active writers */
126*2654012fSReza Sabdar 	int	tcs_error;	/* worker errors */
127*2654012fSReza Sabdar 	char	tcs_message[TLM_LINE_SIZE]; /* worker message back to user */
128*2654012fSReza Sabdar 	tlm_cmd_t *tcs_command;	/* IPC area between read-write */
129*2654012fSReza Sabdar } tlm_commands_t;
130*2654012fSReza Sabdar 
131*2654012fSReza Sabdar 
132*2654012fSReza Sabdar typedef struct	tlm_job_stats {
133*2654012fSReza Sabdar 	char	js_job_name[TLM_MAX_BACKUP_JOB_NAME];
134*2654012fSReza Sabdar 	longlong_t js_bytes_total;	/* tape bytes in or out so far */
135*2654012fSReza Sabdar 	longlong_t js_bytes_in_file;	/* remaining data in a file */
136*2654012fSReza Sabdar 	longlong_t js_files_so_far;	/* files backed up so far */
137*2654012fSReza Sabdar 	longlong_t js_files_total;	/* number of files to be backed up */
138*2654012fSReza Sabdar 	int	js_errors;
139*2654012fSReza Sabdar 	time_t	js_start_time;		/* start time (GMT time) */
140*2654012fSReza Sabdar 	time_t	js_start_ltime;		/* start time (local time) */
141*2654012fSReza Sabdar 	time_t	js_stop_time;		/* stop time (local time) */
142*2654012fSReza Sabdar 	time_t	js_chkpnt_time;		/* checkpoint creation (GMT time) */
143*2654012fSReza Sabdar 	void	*js_callbacks;
144*2654012fSReza Sabdar } tlm_job_stats_t;
145*2654012fSReza Sabdar 
146*2654012fSReza Sabdar 
147*2654012fSReza Sabdar struct full_dir_info {
148*2654012fSReza Sabdar 	fs_fhandle_t fd_dir_fh;
149*2654012fSReza Sabdar 	char fd_dir_name[TLM_MAX_PATH_NAME];
150*2654012fSReza Sabdar };
151*2654012fSReza Sabdar 
152*2654012fSReza Sabdar /*
153*2654012fSReza Sabdar  * For more info please refer to
154*2654012fSReza Sabdar  * "Functional Specification Document: Usgin new LBR engine in NDMP",
155*2654012fSReza Sabdar  * Revision: 0.2
156*2654012fSReza Sabdar  * Document No.: 101438.
157*2654012fSReza Sabdar  * the "File history of backup" section
158*2654012fSReza Sabdar  */
159*2654012fSReza Sabdar typedef struct lbr_fhlog_call_backs {
160*2654012fSReza Sabdar 	void *fh_cookie;
161*2654012fSReza Sabdar 	int (*fh_logpname)();
162*2654012fSReza Sabdar 	int (*fh_log_dir)();
163*2654012fSReza Sabdar 	int (*fh_log_node)();
164*2654012fSReza Sabdar } lbr_fhlog_call_backs_t;
165*2654012fSReza Sabdar 
166*2654012fSReza Sabdar 
167*2654012fSReza Sabdar typedef struct bk_selector {
168*2654012fSReza Sabdar 	void *bs_cookie;
169*2654012fSReza Sabdar 	int bs_level;
170*2654012fSReza Sabdar 	int bs_ldate;
171*2654012fSReza Sabdar 	boolean_t (*bs_fn)(struct bk_selector *bks, struct stat64 *s);
172*2654012fSReza Sabdar } bk_selector_t;
173*2654012fSReza Sabdar 
174*2654012fSReza Sabdar 
175*2654012fSReza Sabdar /*
176*2654012fSReza Sabdar  * Call back structure to create new name for objects at restore time.
177*2654012fSReza Sabdar  */
178*2654012fSReza Sabdar struct rs_name_maker;
179*2654012fSReza Sabdar typedef char *(*rsm_fp_t)(struct rs_name_maker *,
180*2654012fSReza Sabdar 	char *buf,
181*2654012fSReza Sabdar 	int pos,
182*2654012fSReza Sabdar 	char *path);
183*2654012fSReza Sabdar 
184*2654012fSReza Sabdar struct rs_name_maker {
185*2654012fSReza Sabdar 	rsm_fp_t rn_fp;
186*2654012fSReza Sabdar 	void *rn_nlp;
187*2654012fSReza Sabdar };
188*2654012fSReza Sabdar 
189*2654012fSReza Sabdar 
190*2654012fSReza Sabdar /*
191*2654012fSReza Sabdar  *  RSFLG_OVR_*: overwriting policies.  Refer to LBR FSD for more info.
192*2654012fSReza Sabdar  *  RSFLG_MATCH_WCARD: should wildcards be supported in the selection list.
193*2654012fSReza Sabdar  *  RSFLG_IGNORE_CASE: should the compare be case-insensetive.  NDMP needs
194*2654012fSReza Sabdar  *  	case-sensetive name comparison.
195*2654012fSReza Sabdar  */
196*2654012fSReza Sabdar #define	RSFLG_OVR_ALWAYS	0x00000001
197*2654012fSReza Sabdar #define	RSFLG_OVR_NEVER		0x00000002
198*2654012fSReza Sabdar #define	RSFLG_OVR_UPDATE	0x00000004
199*2654012fSReza Sabdar #define	RSFLG_MATCH_WCARD	0x00000008
200*2654012fSReza Sabdar #define	RSFLG_IGNORE_CASE	0x00000010
201*2654012fSReza Sabdar 
202*2654012fSReza Sabdar 
203*2654012fSReza Sabdar /*
204*2654012fSReza Sabdar  * Different cases where two paths can match with each other.
205*2654012fSReza Sabdar  * Parent means that the current path, is parent of an entry in
206*2654012fSReza Sabdar  * the selection list.
207*2654012fSReza Sabdar  * Child means that the current path, is child of an entry in the
208*2654012fSReza Sabdar  * selection list.
209*2654012fSReza Sabdar  */
210*2654012fSReza Sabdar #define	PM_NONE		0
211*2654012fSReza Sabdar #define	PM_EXACT	1
212*2654012fSReza Sabdar #define	PM_PARENT	2
213*2654012fSReza Sabdar #define	PM_CHILD	3
214*2654012fSReza Sabdar 
215*2654012fSReza Sabdar extern tlm_job_stats_t *tlm_new_job_stats(char *);
216*2654012fSReza Sabdar extern tlm_job_stats_t *tlm_ref_job_stats(char *);
217*2654012fSReza Sabdar extern void tlm_un_ref_job_stats(char *);
218*2654012fSReza Sabdar extern boolean_t tlm_is_excluded(char *, char *, char **);
219*2654012fSReza Sabdar extern char *tlm_build_snapshot_name(char *, char *, char *);
220*2654012fSReza Sabdar extern char *tlm_remove_checkpoint(char *, char *);
221*2654012fSReza Sabdar extern tlm_buffers_t *tlm_allocate_buffers(boolean_t, long);
222*2654012fSReza Sabdar extern tlm_buffer_t *tlm_buffer_advance_in_idx(tlm_buffers_t *);
223*2654012fSReza Sabdar extern tlm_buffer_t *tlm_buffer_advance_out_idx(tlm_buffers_t *);
224*2654012fSReza Sabdar extern tlm_buffer_t *tlm_buffer_in_buf(tlm_buffers_t *, int *);
225*2654012fSReza Sabdar extern tlm_buffer_t *tlm_buffer_out_buf(tlm_buffers_t *, int *);
226*2654012fSReza Sabdar extern void tlm_buffer_mark_empty(tlm_buffer_t *);
227*2654012fSReza Sabdar extern void tlm_buffer_release_in_buf(tlm_buffers_t *);
228*2654012fSReza Sabdar extern void tlm_buffer_release_out_buf(tlm_buffers_t *);
229*2654012fSReza Sabdar extern void tlm_buffer_in_buf_wait(tlm_buffers_t *);
230*2654012fSReza Sabdar extern void tlm_buffer_out_buf_wait(tlm_buffers_t *);
231*2654012fSReza Sabdar extern void tlm_buffer_in_buf_timed_wait(tlm_buffers_t *, unsigned);
232*2654012fSReza Sabdar extern void tlm_buffer_out_buf_timed_wait(tlm_buffers_t *, unsigned);
233*2654012fSReza Sabdar extern char *tlm_get_write_buffer(long, long *, tlm_buffers_t *, int);
234*2654012fSReza Sabdar extern char *tlm_get_read_buffer(int, int *, tlm_buffers_t *, int *);
235*2654012fSReza Sabdar extern void tlm_unget_read_buffer(tlm_buffers_t *, int);
236*2654012fSReza Sabdar extern void tlm_unget_write_buffer(tlm_buffers_t *, int);
237*2654012fSReza Sabdar extern void tlm_release_buffers(tlm_buffers_t *);
238*2654012fSReza Sabdar extern tlm_cmd_t *tlm_create_reader_writer_ipc(boolean_t, long);
239*2654012fSReza Sabdar extern void tlm_release_reader_writer_ipc(tlm_cmd_t *);
240*2654012fSReza Sabdar 
241*2654012fSReza Sabdar extern void tlm_cmd_wait(tlm_cmd_t *, uint32_t);
242*2654012fSReza Sabdar extern void tlm_cmd_signal(tlm_cmd_t *, uint32_t);
243*2654012fSReza Sabdar 
244*2654012fSReza Sabdar typedef int (*path_hist_func_t)(lbr_fhlog_call_backs_t *,
245*2654012fSReza Sabdar     char *,
246*2654012fSReza Sabdar     struct stat64 *,
247*2654012fSReza Sabdar     u_longlong_t);
248*2654012fSReza Sabdar 
249*2654012fSReza Sabdar typedef int (*dir_hist_func_t)(lbr_fhlog_call_backs_t *,
250*2654012fSReza Sabdar     char *,
251*2654012fSReza Sabdar     struct stat64 *);
252*2654012fSReza Sabdar 
253*2654012fSReza Sabdar typedef int (*node_hist_func_t)(lbr_fhlog_call_backs_t *,
254*2654012fSReza Sabdar     char *,
255*2654012fSReza Sabdar     char *,
256*2654012fSReza Sabdar     struct stat64 *,
257*2654012fSReza Sabdar     u_longlong_t);
258*2654012fSReza Sabdar 
259*2654012fSReza Sabdar lbr_fhlog_call_backs_t *lbrlog_callbacks_init(void *,
260*2654012fSReza Sabdar     path_hist_func_t,
261*2654012fSReza Sabdar     dir_hist_func_t,
262*2654012fSReza Sabdar     node_hist_func_t);
263*2654012fSReza Sabdar 
264*2654012fSReza Sabdar typedef struct {
265*2654012fSReza Sabdar 	tlm_commands_t *ba_commands;
266*2654012fSReza Sabdar 	tlm_cmd_t *ba_cmd;
267*2654012fSReza Sabdar 	char *ba_job;
268*2654012fSReza Sabdar 	char *ba_dir;
269*2654012fSReza Sabdar 	char *ba_sels[NDMP_MAX_SELECTIONS];
270*2654012fSReza Sabdar 	pthread_barrier_t ba_barrier;
271*2654012fSReza Sabdar } tlm_backup_restore_arg_t;
272*2654012fSReza Sabdar 
273*2654012fSReza Sabdar extern void lbrlog_callbacks_done(lbr_fhlog_call_backs_t *);
274*2654012fSReza Sabdar 
275*2654012fSReza Sabdar extern boolean_t tlm_cat_path(char *, char *, char *);
276*2654012fSReza Sabdar 
277*2654012fSReza Sabdar extern char *trim_name(char *);
278*2654012fSReza Sabdar 
279*2654012fSReza Sabdar extern struct full_dir_info *dup_dir_info(struct full_dir_info *);
280*2654012fSReza Sabdar extern void write_tar_eof(tlm_cmd_t *);
281*2654012fSReza Sabdar extern int tlm_get_chkpnt_time(char *, int, time_t *, char *);
282*2654012fSReza Sabdar extern struct full_dir_info *tlm_new_dir_info(fs_fhandle_t *,
283*2654012fSReza Sabdar     char *,
284*2654012fSReza Sabdar     char *);
285*2654012fSReza Sabdar extern void tlm_release_list(char **);
286*2654012fSReza Sabdar extern longlong_t tlm_get_data_offset(tlm_cmd_t *);
287*2654012fSReza Sabdar extern int tlm_tarhdr_size(void);
288*2654012fSReza Sabdar 
289*2654012fSReza Sabdar #endif	/* _TLM_BUFFERS_H_ */
290