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