xref: /illumos-gate/usr/src/cmd/fs.d/nfs/nfslog/nfslogd.h (revision e067707b65c63939ade45e268f2b0dff6f65f75d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _NFSLOGD_H
28 #define	_NFSLOGD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <tzfile.h>
37 #include <sys/types.h>
38 #include <nfs/nfs_log.h>
39 #include "../lib/nfslog_config.h"
40 #include "buffer_list.h"
41 
42 #define	NFSLOGD_PIDFILE		"/tmp/.nfslogd.pid"
43 #define	NFSLOG_OPTIONS_FILE	"/etc/default/nfslogd"
44 
45 #define	MIN_PROCESSING_SIZE	512*1024	/* Minimum size buffer */
46 						/* should reach before */
47 						/* processing */
48 #define	IDLE_TIME		300	/* Max time to wait w/o processing */
49 					/* in seconds */
50 #define	MAX_LOGS_PRESERVE	10	/* Number of log files to keep for */
51 					/* cycling */
52 #define	MAPPING_UPDATE_INTERVAL	(SECSPERDAY)	/* frequency of updates to */
53 						/* dbm records in seconds  */
54 #define	CYCLE_FREQUENCY		24	/* in hours */
55 #define	PRUNE_TIMEOUT		(SECSPERHOUR * 168)
56 #define	NFSLOG_UMASK		0137	/* for creating tables and logs */
57 
58 /*
59  * RPC dispatch table for logging. Indexed by program, version, proc.
60  * Based on NFS dispatch table, but differs in that it does not xdr
61  * encode/decode arguments and results.
62  */
63 struct nfsl_proc_disp {
64 	void	(*nfsl_dis_args)();	/* prt elf nl args from rpc args */
65 	void	(*nfsl_dis_res)();	/* prt elf nl res from rpc res */
66 	char	*procname;		/* string describing the proc */
67 };
68 
69 struct nfsl_vers_disp {
70 	int	nfsl_dis_nprocs;			/* number of procs */
71 	struct nfsl_proc_disp	*nfsl_dis_proc_table;	/* proc array */
72 };
73 
74 struct nfsl_prog_disp {
75 	rpcprog_t	nfsl_dis_prog;		/* program number */
76 	rpcvers_t	nfsl_dis_versmin;	/* minimum version number */
77 	int		nfsl_dis_nvers;		/* number of version values */
78 	struct nfsl_vers_disp	*nfsl_dis_vers_table;	/* versions array */
79 	char	*progname;		/* string describing the program */
80 };
81 
82 struct nfsl_log_file {
83 	char	*path;		/* pathname of file */
84 	FILE	*fp;		/* file pointer */
85 	char	*buf;		/* buffer where output queued before print */
86 	int	bufoffset;	/* current offset in (memory) buffer */
87 	struct nfsl_log_file	*next;	/* next file in list */
88 	struct nfsl_log_file	*prev;	/* next file in list */
89 };
90 
91 /*
92  * The following four structures are used for processing the buffer file.
93  */
94 struct valid_rpcs {
95 	rpcprog_t	prog;
96 	rpcvers_t	versmin;
97 	rpcvers_t	versmax;
98 };
99 
100 /*
101  * Simple struct for keeping track of the offset and length of
102  * records processed from the buffer file.  This is used for the logic
103  * of rewriting the buffer header of that last record processed.
104  * Since records within the buffer file can be 'out of order' and nfslogd
105  * sorts those records, we need to keep track of what has been processed
106  * and where.  This record keeping is then used to decide when to rewrite
107  * the buffer header and to decide the correct offset for that rewrite.
108  */
109 struct processed_records {
110 	struct processed_records *next;
111 	struct processed_records *prev;
112 	u_offset_t start_offset;
113 	unsigned int len;
114 	unsigned int num_recs;
115 };
116 
117 struct nfslog_buf {
118 	struct nfslog_buf	*next;
119 	struct nfslog_buf	*prev;
120 	char	*bufpath;			/* buffer file name */
121 	int	fd;				/* buffer file fd */
122 	flock_t fl;				/* buffer file lock */
123 	u_offset_t	filesize;		/* file size */
124 	intptr_t mmap_addr;			/* address of mmap */
125 	u_offset_t next_rec;			/* address of next record */
126 	unsigned int last_rec_id;		/* last record id processed */
127 	nfslog_buffer_header	bh;		/* file buffer header */
128 	struct nfslog_lr *bh_lrp;
129 	int num_lrps;
130 	struct nfslog_lr *lrps;			/* raw records - not cooked */
131 	/* Next fields used for tracking processed records from buf file */
132 	u_offset_t last_record_offset;		/* value last written to hdr */
133 	struct processed_records *prp;		/* list of processed chunks */
134 	int num_pr_queued;			/* # of processed records */
135 };
136 
137 struct nfslog_lr {
138 	struct	nfslog_lr *next;
139 	struct	nfslog_lr *prev;
140 	u_offset_t f_offset;			/* offset for ondisk file */
141 	intptr_t record;			/* mmap address of record */
142 	unsigned int recsize;			/* size of this record */
143 	caddr_t buffer;				/* used if mmap fails */
144 	XDR	xdrs;
145 	nfslog_request_record	log_record;	/* decoded record */
146 	bool_t			(*xdrargs)();	/* xdr function for FREE */
147 	bool_t			(*xdrres)();	/* xdr function for FREE */
148 	struct nfslog_buf *lbp;
149 };
150 
151 /*
152  * Following defines are used as a parameter to nfslog_open_trans()
153  * The bit mask passed to this function will determine which operations
154  * are placed in the log.
155  */
156 #define	TRANSTOLOG_OPER_READ	0x00000001
157 #define	TRANSTOLOG_OPER_WRITE	0x00000002
158 #define	TRANSTOLOG_OPER_SETATTR	0x00000004
159 #define	TRANSTOLOG_OPER_REMOVE	0x00000008
160 #define	TRANSTOLOG_OPER_MKDIR	0x00000010
161 #define	TRANSTOLOG_OPER_CREATE	0x00000020
162 #define	TRANSTOLOG_OPER_RMDIR	0x00000040
163 #define	TRANSTOLOG_OPER_RENAME	0x00000080
164 #define	TRANSTOLOG_OPER_MKNOD	0x00000100
165 #define	TRANSTOLOG_OPER_LINK	0x00000200
166 #define	TRANSTOLOG_OPER_SYMLINK	0x00000400
167 #define	TRANSTOLOG_OPER_READWRITE \
168 	(TRANSTOLOG_OPER_READ | TRANSTOLOG_OPER_WRITE)
169 #define	TRANSTOLOG_ALL ((uint32_t)~0)
170 
171 extern int debug;
172 extern boolean_t test;
173 extern int max_logs_preserve;
174 extern uint_t idle_time;
175 extern boolean_t keep_running;
176 extern boolean_t quick_cleaning;
177 
178 extern int cycle_log(char *, int);
179 extern int prune_dbs(char *);
180 extern int process_buffer(
181 	struct buffer_ent *, nfsl_config_t **, int, int, int *);
182 extern struct nfslog_buf *nfslog_open_buf(char *, int *);
183 extern void nfslog_close_buf(struct nfslog_buf *, int);
184 extern struct nfslog_lr	*nfslog_get_logrecord(struct nfslog_buf *);
185 extern void nfslog_free_logrecord(struct nfslog_lr *, bool_t);
186 
187 extern int nfslog_process_fh_rec(struct nfslog_lr *,
188 		char *, char **, char **, bool_t);
189 
190 extern void *nfslog_open_elf_file(char *, nfslog_buffer_header *, int *);
191 extern void nfslog_close_elf_file(void **);
192 extern int nfslog_process_elf_rec(void *, nfslog_request_record *,
193 		char *, char *);
194 
195 struct nfslog_trans_file;
196 extern void *nfslog_open_trans_file(char *, uint32_t, uint32_t, int *);
197 
198 extern void nfslog_process_trans_timeout(struct nfslog_trans_file *,
199 		uint32_t);
200 extern int nfslog_process_trans_rec(void *,
201 		nfslog_request_record *, char *, char *, char *);
202 extern void nfslog_close_transactions(void **);
203 
204 extern void nfslog_opaque_print_buf(void *, int, char *, int *, int);
205 #ifdef	__cplusplus
206 }
207 #endif
208 
209 #endif /* _NFSLOGD_H */
210