10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*11981SMarcel.Telka@Sun.COM * Common Development and Distribution License (the "License"). 6*11981SMarcel.Telka@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*11981SMarcel.Telka@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23249Sjwahlig * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _NFSLOGD_H 270Sstevel@tonic-gate #define _NFSLOGD_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <tzfile.h> 340Sstevel@tonic-gate #include <sys/types.h> 350Sstevel@tonic-gate #include <nfs/nfs_log.h> 360Sstevel@tonic-gate #include "../lib/nfslog_config.h" 370Sstevel@tonic-gate #include "buffer_list.h" 380Sstevel@tonic-gate 39*11981SMarcel.Telka@Sun.COM #define NFSLOGD_PIDFILE "/var/run/nfslogd.pid" 400Sstevel@tonic-gate #define NFSLOG_OPTIONS_FILE "/etc/default/nfslogd" 410Sstevel@tonic-gate 420Sstevel@tonic-gate #define MIN_PROCESSING_SIZE 512*1024 /* Minimum size buffer */ 430Sstevel@tonic-gate /* should reach before */ 440Sstevel@tonic-gate /* processing */ 450Sstevel@tonic-gate #define IDLE_TIME 300 /* Max time to wait w/o processing */ 460Sstevel@tonic-gate /* in seconds */ 470Sstevel@tonic-gate #define MAX_LOGS_PRESERVE 10 /* Number of log files to keep for */ 480Sstevel@tonic-gate /* cycling */ 490Sstevel@tonic-gate #define MAPPING_UPDATE_INTERVAL (SECSPERDAY) /* frequency of updates to */ 500Sstevel@tonic-gate /* dbm records in seconds */ 510Sstevel@tonic-gate #define CYCLE_FREQUENCY 24 /* in hours */ 520Sstevel@tonic-gate #define PRUNE_TIMEOUT (SECSPERHOUR * 168) 530Sstevel@tonic-gate #define NFSLOG_UMASK 0137 /* for creating tables and logs */ 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * RPC dispatch table for logging. Indexed by program, version, proc. 570Sstevel@tonic-gate * Based on NFS dispatch table, but differs in that it does not xdr 580Sstevel@tonic-gate * encode/decode arguments and results. 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate struct nfsl_proc_disp { 610Sstevel@tonic-gate void (*nfsl_dis_args)(); /* prt elf nl args from rpc args */ 620Sstevel@tonic-gate void (*nfsl_dis_res)(); /* prt elf nl res from rpc res */ 630Sstevel@tonic-gate char *procname; /* string describing the proc */ 640Sstevel@tonic-gate }; 650Sstevel@tonic-gate 660Sstevel@tonic-gate struct nfsl_vers_disp { 670Sstevel@tonic-gate int nfsl_dis_nprocs; /* number of procs */ 680Sstevel@tonic-gate struct nfsl_proc_disp *nfsl_dis_proc_table; /* proc array */ 690Sstevel@tonic-gate }; 700Sstevel@tonic-gate 710Sstevel@tonic-gate struct nfsl_prog_disp { 720Sstevel@tonic-gate rpcprog_t nfsl_dis_prog; /* program number */ 730Sstevel@tonic-gate rpcvers_t nfsl_dis_versmin; /* minimum version number */ 740Sstevel@tonic-gate int nfsl_dis_nvers; /* number of version values */ 750Sstevel@tonic-gate struct nfsl_vers_disp *nfsl_dis_vers_table; /* versions array */ 760Sstevel@tonic-gate char *progname; /* string describing the program */ 770Sstevel@tonic-gate }; 780Sstevel@tonic-gate 790Sstevel@tonic-gate struct nfsl_log_file { 800Sstevel@tonic-gate char *path; /* pathname of file */ 810Sstevel@tonic-gate FILE *fp; /* file pointer */ 820Sstevel@tonic-gate char *buf; /* buffer where output queued before print */ 830Sstevel@tonic-gate int bufoffset; /* current offset in (memory) buffer */ 840Sstevel@tonic-gate struct nfsl_log_file *next; /* next file in list */ 850Sstevel@tonic-gate struct nfsl_log_file *prev; /* next file in list */ 860Sstevel@tonic-gate }; 870Sstevel@tonic-gate 880Sstevel@tonic-gate /* 890Sstevel@tonic-gate * The following four structures are used for processing the buffer file. 900Sstevel@tonic-gate */ 910Sstevel@tonic-gate struct valid_rpcs { 920Sstevel@tonic-gate rpcprog_t prog; 930Sstevel@tonic-gate rpcvers_t versmin; 940Sstevel@tonic-gate rpcvers_t versmax; 950Sstevel@tonic-gate }; 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * Simple struct for keeping track of the offset and length of 990Sstevel@tonic-gate * records processed from the buffer file. This is used for the logic 1000Sstevel@tonic-gate * of rewriting the buffer header of that last record processed. 1010Sstevel@tonic-gate * Since records within the buffer file can be 'out of order' and nfslogd 1020Sstevel@tonic-gate * sorts those records, we need to keep track of what has been processed 1030Sstevel@tonic-gate * and where. This record keeping is then used to decide when to rewrite 1040Sstevel@tonic-gate * the buffer header and to decide the correct offset for that rewrite. 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate struct processed_records { 1070Sstevel@tonic-gate struct processed_records *next; 1080Sstevel@tonic-gate struct processed_records *prev; 1090Sstevel@tonic-gate u_offset_t start_offset; 1100Sstevel@tonic-gate unsigned int len; 1110Sstevel@tonic-gate unsigned int num_recs; 1120Sstevel@tonic-gate }; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate struct nfslog_buf { 1150Sstevel@tonic-gate struct nfslog_buf *next; 1160Sstevel@tonic-gate struct nfslog_buf *prev; 1170Sstevel@tonic-gate char *bufpath; /* buffer file name */ 1180Sstevel@tonic-gate int fd; /* buffer file fd */ 1190Sstevel@tonic-gate flock_t fl; /* buffer file lock */ 1200Sstevel@tonic-gate u_offset_t filesize; /* file size */ 1210Sstevel@tonic-gate intptr_t mmap_addr; /* address of mmap */ 1220Sstevel@tonic-gate u_offset_t next_rec; /* address of next record */ 1230Sstevel@tonic-gate unsigned int last_rec_id; /* last record id processed */ 1240Sstevel@tonic-gate nfslog_buffer_header bh; /* file buffer header */ 1250Sstevel@tonic-gate struct nfslog_lr *bh_lrp; 1260Sstevel@tonic-gate int num_lrps; 1270Sstevel@tonic-gate struct nfslog_lr *lrps; /* raw records - not cooked */ 1280Sstevel@tonic-gate /* Next fields used for tracking processed records from buf file */ 1290Sstevel@tonic-gate u_offset_t last_record_offset; /* value last written to hdr */ 1300Sstevel@tonic-gate struct processed_records *prp; /* list of processed chunks */ 1310Sstevel@tonic-gate int num_pr_queued; /* # of processed records */ 1320Sstevel@tonic-gate }; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate struct nfslog_lr { 1350Sstevel@tonic-gate struct nfslog_lr *next; 1360Sstevel@tonic-gate struct nfslog_lr *prev; 1370Sstevel@tonic-gate u_offset_t f_offset; /* offset for ondisk file */ 1380Sstevel@tonic-gate intptr_t record; /* mmap address of record */ 1390Sstevel@tonic-gate unsigned int recsize; /* size of this record */ 1400Sstevel@tonic-gate caddr_t buffer; /* used if mmap fails */ 1410Sstevel@tonic-gate XDR xdrs; 1420Sstevel@tonic-gate nfslog_request_record log_record; /* decoded record */ 1430Sstevel@tonic-gate bool_t (*xdrargs)(); /* xdr function for FREE */ 1440Sstevel@tonic-gate bool_t (*xdrres)(); /* xdr function for FREE */ 1450Sstevel@tonic-gate struct nfslog_buf *lbp; 1460Sstevel@tonic-gate }; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* 1490Sstevel@tonic-gate * Following defines are used as a parameter to nfslog_open_trans() 1500Sstevel@tonic-gate * The bit mask passed to this function will determine which operations 1510Sstevel@tonic-gate * are placed in the log. 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate #define TRANSTOLOG_OPER_READ 0x00000001 1540Sstevel@tonic-gate #define TRANSTOLOG_OPER_WRITE 0x00000002 1550Sstevel@tonic-gate #define TRANSTOLOG_OPER_SETATTR 0x00000004 1560Sstevel@tonic-gate #define TRANSTOLOG_OPER_REMOVE 0x00000008 1570Sstevel@tonic-gate #define TRANSTOLOG_OPER_MKDIR 0x00000010 1580Sstevel@tonic-gate #define TRANSTOLOG_OPER_CREATE 0x00000020 1590Sstevel@tonic-gate #define TRANSTOLOG_OPER_RMDIR 0x00000040 1600Sstevel@tonic-gate #define TRANSTOLOG_OPER_RENAME 0x00000080 1610Sstevel@tonic-gate #define TRANSTOLOG_OPER_MKNOD 0x00000100 1620Sstevel@tonic-gate #define TRANSTOLOG_OPER_LINK 0x00000200 1630Sstevel@tonic-gate #define TRANSTOLOG_OPER_SYMLINK 0x00000400 1640Sstevel@tonic-gate #define TRANSTOLOG_OPER_READWRITE \ 1650Sstevel@tonic-gate (TRANSTOLOG_OPER_READ | TRANSTOLOG_OPER_WRITE) 1660Sstevel@tonic-gate #define TRANSTOLOG_ALL ((uint32_t)~0) 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate extern int debug; 1690Sstevel@tonic-gate extern boolean_t test; 1700Sstevel@tonic-gate extern int max_logs_preserve; 1710Sstevel@tonic-gate extern uint_t idle_time; 1720Sstevel@tonic-gate extern boolean_t keep_running; 1730Sstevel@tonic-gate extern boolean_t quick_cleaning; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate extern int cycle_log(char *, int); 1760Sstevel@tonic-gate extern int prune_dbs(char *); 1770Sstevel@tonic-gate extern int process_buffer( 1780Sstevel@tonic-gate struct buffer_ent *, nfsl_config_t **, int, int, int *); 1790Sstevel@tonic-gate extern struct nfslog_buf *nfslog_open_buf(char *, int *); 1800Sstevel@tonic-gate extern void nfslog_close_buf(struct nfslog_buf *, int); 1810Sstevel@tonic-gate extern struct nfslog_lr *nfslog_get_logrecord(struct nfslog_buf *); 1820Sstevel@tonic-gate extern void nfslog_free_logrecord(struct nfslog_lr *, bool_t); 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate extern int nfslog_process_fh_rec(struct nfslog_lr *, 1850Sstevel@tonic-gate char *, char **, char **, bool_t); 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate extern void *nfslog_open_elf_file(char *, nfslog_buffer_header *, int *); 1880Sstevel@tonic-gate extern void nfslog_close_elf_file(void **); 1890Sstevel@tonic-gate extern int nfslog_process_elf_rec(void *, nfslog_request_record *, 1900Sstevel@tonic-gate char *, char *); 1910Sstevel@tonic-gate 192249Sjwahlig struct nfslog_trans_file; 1930Sstevel@tonic-gate extern void *nfslog_open_trans_file(char *, uint32_t, uint32_t, int *); 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate extern void nfslog_process_trans_timeout(struct nfslog_trans_file *, 1960Sstevel@tonic-gate uint32_t); 1970Sstevel@tonic-gate extern int nfslog_process_trans_rec(void *, 1980Sstevel@tonic-gate nfslog_request_record *, char *, char *, char *); 1990Sstevel@tonic-gate extern void nfslog_close_transactions(void **); 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate extern void nfslog_opaque_print_buf(void *, int, char *, int *, int); 2020Sstevel@tonic-gate #ifdef __cplusplus 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate #endif 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate #endif /* _NFSLOGD_H */ 207