1.\" 2.\" Copyright (c) 2003 Hiten M. Pandya <hmp@FreeBSD.org> 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions, and the following disclaimer, 10.\" without modification, immediately at the beginning of the file. 11.\" 2. The name of the author may not be used to endorse or promote products 12.\" derived from this software without specific prior written permission. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18.\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd May 16, 2003 29.Dt ALQ 9 30.Os 31.Sh NAME 32.Nm alq , 33.Nm alq_open , 34.Nm alq_write , 35.Nm alq_flush , 36.Nm alq_close , 37.Nm alq_get , 38.Nm alq_post 39.Nd Asynchronous Logging Queues 40.Sh SYNOPSIS 41.In sys/alq.h 42.Ft int 43.Fn alq_open "struct alq **app" "const char *file" "int size" "int count" 44.Ft int 45.Fn alq_write "struct alq *alq" "void *data" "int waitok" 46.Ft void 47.Fn alq_flush "struct alq *alq" 48.Ft void 49.Fn alq_close "struct alq *alq" 50.Ft struct ale * 51.Fn alq_get "struct alq *alq" "int waitok" 52.Ft void 53.Fn alq_post "struct alq *alq" "struct ale *ale" 54.Sh DESCRIPTION 55The 56.Nm 57facility provides an asynchronous fixed length recording 58mechanism, known as Asynchronous Logging Queues. 59It can record to any 60.Xr vnode 9 , 61thus providing the ability to journal logs to character 62devices as well as regular files. 63All functions accept a 64.Vt "struct alq" 65argument, which is an opaque type that maintains state information 66for an Asynchronous Logging Queue. 67The logging facility runs in a separate kernel thread, which services 68all log entry requests. 69.Pp 70An 71.Dq asynchronous log entry 72is defined as 73.Vt "struct ale" , 74which has the following members: 75.Bd -literal -offset indent 76struct ale { 77 struct ale *ae_next; /* Next Entry */ 78 char *ae_data; /* Entry buffer */ 79 int ae_flags; /* Entry flags */ 80}; 81.Ed 82.Pp 83The 84.Va ae_flags 85field is for internal use, clients of the 86.Nm 87interface should not modify this field. 88Behaviour is undefined if this field is modified. 89.Sh FUNCTIONS 90The 91.Fn alq_open 92function creates a new logging queue. 93.Pp 94The 95.Fa file 96argument is the name of the file to open for logging. 97The size of each entry in the queue is determined by 98.Fa size . 99The 100.Fa count 101argument determines the number of items to be stored in the 102asynchronous queue over an approximate period of a disk 103write operation. 104.Pp 105The 106.Fn alq_write 107function writes 108.Fa data 109to the designated queue, 110.Fa alq . 111In the event that 112.Fn alq_write 113could not write the entry immediately, and 114.Dv ALQ_WAITOK 115is passed to 116.Fa waitok , 117then 118.Fn alq_write 119will be allowed to 120.Xr tsleep 9 . 121.Pp 122The 123.Fn alq_flush 124function is used for flushing 125.Fa alq 126to the log medium that was passed to 127.Fn alq_open . 128.Pp 129The 130.Fn alq_close 131function will close the asynchronous logging queue, 132.Fa alq , 133and flush all pending write requests to the log medium. 134It will free all resources that were previously allocated. 135.Pp 136The 137.Fn alq_get 138function returns the next available asynchronous logging entry 139from the queue, 140.Fa alq . 141This function leaves the queue in a locked state, until a subsequent 142.Fn alq_post 143call is made. 144In the event that 145.Fn alq_get 146could not retrieve an entry immediately, it will 147.Xr tsleep 9 148with the 149.Dq Li alqget 150wait message. 151.Pp 152The 153.Fn alq_post 154function schedules the asynchronous logging entry, 155.Fa ale , 156which is retrieved using the 157.Fn alq_get 158function, 159for writing to the asynchronous logging queue, 160.Fa alq . 161This function leaves the queue, 162.Fa alq , 163in an unlocked state. 164.Sh IMPLEMENTATION NOTES 165The 166.Fn alq_open 167function uses the credentials of the invoking thread 168for opening files. 169The 170.Fn alq_write 171function is a wrapper around the 172.Fn alq_get 173and 174.Fn alq_post 175functions; by using these functions separately, a call 176to 177.Fn bcopy 178can be avoided for performance critical code paths. 179.Sh RETURN VALUES 180The 181.Fn alq_open 182function returns one of the error codes listed in 183.Xr open 2 , 184if it fails to open 185.Fa file , 186or else it returns 0. 187.Pp 188The 189.Fn alq_write 190function returns 191.Er EWOULDBLOCK 192if 193.Dv ALQ_NOWAIT 194was provided as a value to 195.Fa waitok 196and either the queue is full, or when the system is shutting down. 197.Pp 198The 199.Fn alq_get 200function returns 201.Dv NULL , 202if 203.Dv ALQ_NOWAIT 204was provided as a value to 205.Fa waitok 206and either the queue is full, or when the system is shutting down. 207.Pp 208NOTE: invalid arguments to non-void functions will result in 209undefined behaviour. 210.Sh SEE ALSO 211.Xr syslog 3 , 212.Xr kthread 9 , 213.Xr ktr 9 , 214.Xr tsleep 9 , 215.Xr vnode 9 216.Sh HISTORY 217The 218Asynchronous Logging Queues (ALQ) facility first appeared in 219.Fx 5.0 . 220.Sh AUTHORS 221.An -nosplit 222The 223.Nm 224facility was written by 225.An Jeffrey Roberson Aq jeff@FreeBSD.org . 226.Pp 227This manual page was written by 228.An Hiten M. Pandya Aq hmp@FreeBSD.org . 229