xref: /illumos-gate/usr/src/cmd/fs.d/nfs/nfslog/nfslogd.h (revision ea259b73)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*ea259b73SMarcel Telka  * Common Development and Distribution License (the "License").
6*ea259b73SMarcel Telka  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ea259b73SMarcel Telka  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2311606941Sjwahlig  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _NFSLOGD_H
277c478bd9Sstevel@tonic-gate #define	_NFSLOGD_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <tzfile.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <nfs/nfs_log.h>
367c478bd9Sstevel@tonic-gate #include "../lib/nfslog_config.h"
377c478bd9Sstevel@tonic-gate #include "buffer_list.h"
387c478bd9Sstevel@tonic-gate 
39*ea259b73SMarcel Telka #define	NFSLOGD_PIDFILE		"/var/run/nfslogd.pid"
407c478bd9Sstevel@tonic-gate #define	NFSLOG_OPTIONS_FILE	"/etc/default/nfslogd"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	MIN_PROCESSING_SIZE	512*1024	/* Minimum size buffer */
437c478bd9Sstevel@tonic-gate 						/* should reach before */
447c478bd9Sstevel@tonic-gate 						/* processing */
457c478bd9Sstevel@tonic-gate #define	IDLE_TIME		300	/* Max time to wait w/o processing */
467c478bd9Sstevel@tonic-gate 					/* in seconds */
477c478bd9Sstevel@tonic-gate #define	MAX_LOGS_PRESERVE	10	/* Number of log files to keep for */
487c478bd9Sstevel@tonic-gate 					/* cycling */
497c478bd9Sstevel@tonic-gate #define	MAPPING_UPDATE_INTERVAL	(SECSPERDAY)	/* frequency of updates to */
507c478bd9Sstevel@tonic-gate 						/* dbm records in seconds  */
517c478bd9Sstevel@tonic-gate #define	CYCLE_FREQUENCY		24	/* in hours */
527c478bd9Sstevel@tonic-gate #define	PRUNE_TIMEOUT		(SECSPERHOUR * 168)
537c478bd9Sstevel@tonic-gate #define	NFSLOG_UMASK		0137	/* for creating tables and logs */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * RPC dispatch table for logging. Indexed by program, version, proc.
577c478bd9Sstevel@tonic-gate  * Based on NFS dispatch table, but differs in that it does not xdr
587c478bd9Sstevel@tonic-gate  * encode/decode arguments and results.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate struct nfsl_proc_disp {
617c478bd9Sstevel@tonic-gate 	void	(*nfsl_dis_args)();	/* prt elf nl args from rpc args */
627c478bd9Sstevel@tonic-gate 	void	(*nfsl_dis_res)();	/* prt elf nl res from rpc res */
637c478bd9Sstevel@tonic-gate 	char	*procname;		/* string describing the proc */
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate struct nfsl_vers_disp {
677c478bd9Sstevel@tonic-gate 	int	nfsl_dis_nprocs;			/* number of procs */
687c478bd9Sstevel@tonic-gate 	struct nfsl_proc_disp	*nfsl_dis_proc_table;	/* proc array */
697c478bd9Sstevel@tonic-gate };
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate struct nfsl_prog_disp {
727c478bd9Sstevel@tonic-gate 	rpcprog_t	nfsl_dis_prog;		/* program number */
737c478bd9Sstevel@tonic-gate 	rpcvers_t	nfsl_dis_versmin;	/* minimum version number */
747c478bd9Sstevel@tonic-gate 	int		nfsl_dis_nvers;		/* number of version values */
757c478bd9Sstevel@tonic-gate 	struct nfsl_vers_disp	*nfsl_dis_vers_table;	/* versions array */
767c478bd9Sstevel@tonic-gate 	char	*progname;		/* string describing the program */
777c478bd9Sstevel@tonic-gate };
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate struct nfsl_log_file {
807c478bd9Sstevel@tonic-gate 	char	*path;		/* pathname of file */
817c478bd9Sstevel@tonic-gate 	FILE	*fp;		/* file pointer */
827c478bd9Sstevel@tonic-gate 	char	*buf;		/* buffer where output queued before print */
837c478bd9Sstevel@tonic-gate 	int	bufoffset;	/* current offset in (memory) buffer */
847c478bd9Sstevel@tonic-gate 	struct nfsl_log_file	*next;	/* next file in list */
857c478bd9Sstevel@tonic-gate 	struct nfsl_log_file	*prev;	/* next file in list */
867c478bd9Sstevel@tonic-gate };
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * The following four structures are used for processing the buffer file.
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate struct valid_rpcs {
927c478bd9Sstevel@tonic-gate 	rpcprog_t	prog;
937c478bd9Sstevel@tonic-gate 	rpcvers_t	versmin;
947c478bd9Sstevel@tonic-gate 	rpcvers_t	versmax;
957c478bd9Sstevel@tonic-gate };
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Simple struct for keeping track of the offset and length of
997c478bd9Sstevel@tonic-gate  * records processed from the buffer file.  This is used for the logic
1007c478bd9Sstevel@tonic-gate  * of rewriting the buffer header of that last record processed.
1017c478bd9Sstevel@tonic-gate  * Since records within the buffer file can be 'out of order' and nfslogd
1027c478bd9Sstevel@tonic-gate  * sorts those records, we need to keep track of what has been processed
1037c478bd9Sstevel@tonic-gate  * and where.  This record keeping is then used to decide when to rewrite
1047c478bd9Sstevel@tonic-gate  * the buffer header and to decide the correct offset for that rewrite.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate struct processed_records {
1077c478bd9Sstevel@tonic-gate 	struct processed_records *next;
1087c478bd9Sstevel@tonic-gate 	struct processed_records *prev;
1097c478bd9Sstevel@tonic-gate 	u_offset_t start_offset;
1107c478bd9Sstevel@tonic-gate 	unsigned int len;
1117c478bd9Sstevel@tonic-gate 	unsigned int num_recs;
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate struct nfslog_buf {
1157c478bd9Sstevel@tonic-gate 	struct nfslog_buf	*next;
1167c478bd9Sstevel@tonic-gate 	struct nfslog_buf	*prev;
1177c478bd9Sstevel@tonic-gate 	char	*bufpath;			/* buffer file name */
1187c478bd9Sstevel@tonic-gate 	int	fd;				/* buffer file fd */
1197c478bd9Sstevel@tonic-gate 	flock_t fl;				/* buffer file lock */
1207c478bd9Sstevel@tonic-gate 	u_offset_t	filesize;		/* file size */
1217c478bd9Sstevel@tonic-gate 	intptr_t mmap_addr;			/* address of mmap */
1227c478bd9Sstevel@tonic-gate 	u_offset_t next_rec;			/* address of next record */
1237c478bd9Sstevel@tonic-gate 	unsigned int last_rec_id;		/* last record id processed */
1247c478bd9Sstevel@tonic-gate 	nfslog_buffer_header	bh;		/* file buffer header */
1257c478bd9Sstevel@tonic-gate 	struct nfslog_lr *bh_lrp;
1267c478bd9Sstevel@tonic-gate 	int num_lrps;
1277c478bd9Sstevel@tonic-gate 	struct nfslog_lr *lrps;			/* raw records - not cooked */
1287c478bd9Sstevel@tonic-gate 	/* Next fields used for tracking processed records from buf file */
1297c478bd9Sstevel@tonic-gate 	u_offset_t last_record_offset;		/* value last written to hdr */
1307c478bd9Sstevel@tonic-gate 	struct processed_records *prp;		/* list of processed chunks */
1317c478bd9Sstevel@tonic-gate 	int num_pr_queued;			/* # of processed records */
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate struct nfslog_lr {
1357c478bd9Sstevel@tonic-gate 	struct	nfslog_lr *next;
1367c478bd9Sstevel@tonic-gate 	struct	nfslog_lr *prev;
1377c478bd9Sstevel@tonic-gate 	u_offset_t f_offset;			/* offset for ondisk file */
1387c478bd9Sstevel@tonic-gate 	intptr_t record;			/* mmap address of record */
1397c478bd9Sstevel@tonic-gate 	unsigned int recsize;			/* size of this record */
1407c478bd9Sstevel@tonic-gate 	caddr_t buffer;				/* used if mmap fails */
1417c478bd9Sstevel@tonic-gate 	XDR	xdrs;
1427c478bd9Sstevel@tonic-gate 	nfslog_request_record	log_record;	/* decoded record */
1437c478bd9Sstevel@tonic-gate 	bool_t			(*xdrargs)();	/* xdr function for FREE */
1447c478bd9Sstevel@tonic-gate 	bool_t			(*xdrres)();	/* xdr function for FREE */
1457c478bd9Sstevel@tonic-gate 	struct nfslog_buf *lbp;
1467c478bd9Sstevel@tonic-gate };
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * Following defines are used as a parameter to nfslog_open_trans()
1507c478bd9Sstevel@tonic-gate  * The bit mask passed to this function will determine which operations
1517c478bd9Sstevel@tonic-gate  * are placed in the log.
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_READ	0x00000001
1547c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_WRITE	0x00000002
1557c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_SETATTR	0x00000004
1567c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_REMOVE	0x00000008
1577c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_MKDIR	0x00000010
1587c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_CREATE	0x00000020
1597c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_RMDIR	0x00000040
1607c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_RENAME	0x00000080
1617c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_MKNOD	0x00000100
1627c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_LINK	0x00000200
1637c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_SYMLINK	0x00000400
1647c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_OPER_READWRITE \
1657c478bd9Sstevel@tonic-gate 	(TRANSTOLOG_OPER_READ | TRANSTOLOG_OPER_WRITE)
1667c478bd9Sstevel@tonic-gate #define	TRANSTOLOG_ALL ((uint32_t)~0)
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate extern int debug;
1697c478bd9Sstevel@tonic-gate extern boolean_t test;
1707c478bd9Sstevel@tonic-gate extern int max_logs_preserve;
1717c478bd9Sstevel@tonic-gate extern uint_t idle_time;
1727c478bd9Sstevel@tonic-gate extern boolean_t keep_running;
1737c478bd9Sstevel@tonic-gate extern boolean_t quick_cleaning;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate extern int cycle_log(char *, int);
1767c478bd9Sstevel@tonic-gate extern int prune_dbs(char *);
1777c478bd9Sstevel@tonic-gate extern int process_buffer(
1787c478bd9Sstevel@tonic-gate 	struct buffer_ent *, nfsl_config_t **, int, int, int *);
1797c478bd9Sstevel@tonic-gate extern struct nfslog_buf *nfslog_open_buf(char *, int *);
1807c478bd9Sstevel@tonic-gate extern void nfslog_close_buf(struct nfslog_buf *, int);
1817c478bd9Sstevel@tonic-gate extern struct nfslog_lr	*nfslog_get_logrecord(struct nfslog_buf *);
1827c478bd9Sstevel@tonic-gate extern void nfslog_free_logrecord(struct nfslog_lr *, bool_t);
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate extern int nfslog_process_fh_rec(struct nfslog_lr *,
1857c478bd9Sstevel@tonic-gate 		char *, char **, char **, bool_t);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate extern void *nfslog_open_elf_file(char *, nfslog_buffer_header *, int *);
1887c478bd9Sstevel@tonic-gate extern void nfslog_close_elf_file(void **);
1897c478bd9Sstevel@tonic-gate extern int nfslog_process_elf_rec(void *, nfslog_request_record *,
1907c478bd9Sstevel@tonic-gate 		char *, char *);
1917c478bd9Sstevel@tonic-gate 
19211606941Sjwahlig struct nfslog_trans_file;
1937c478bd9Sstevel@tonic-gate extern void *nfslog_open_trans_file(char *, uint32_t, uint32_t, int *);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate extern void nfslog_process_trans_timeout(struct nfslog_trans_file *,
1967c478bd9Sstevel@tonic-gate 		uint32_t);
1977c478bd9Sstevel@tonic-gate extern int nfslog_process_trans_rec(void *,
1987c478bd9Sstevel@tonic-gate 		nfslog_request_record *, char *, char *, char *);
1997c478bd9Sstevel@tonic-gate extern void nfslog_close_transactions(void **);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate extern void nfslog_opaque_print_buf(void *, int, char *, int *, int);
2027c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate #endif
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate #endif /* _NFSLOGD_H */
207