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