]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/alq.h
Merge llvm-project main llvmorg-14-init-11187-g222442ec2d71
[FreeBSD/FreeBSD.git] / sys / sys / alq.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
5  * Copyright (c) 2008-2009, Lawrence Stewart <lstewart@freebsd.org>
6  * Copyright (c) 2010, The FreeBSD Foundation
7  * All rights reserved.
8  *
9  * Portions of this software were developed at the Centre for Advanced
10  * Internet Architectures, Swinburne University of Technology, Melbourne,
11  * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice unmodified, this list of conditions, and the following
18  *    disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  *
36  */
37 #ifndef _SYS_ALQ_H_
38 #define _SYS_ALQ_H_
39
40 #ifdef _KERNEL
41 /*
42  * Opaque type for the Async. Logging Queue
43  */
44 struct alq;
45
46 /* The thread for the logging daemon */
47 extern struct thread *ald_thread;
48
49 /*
50  * Async. Logging Entry
51  */
52 struct ale {
53         intptr_t        ae_bytesused;   /* # bytes written to ALE. */
54         char            *ae_data;       /* Write ptr. */
55         int             ae_pad;         /* Unused, compat. */
56 };
57
58 /* Flag options. */
59 #define ALQ_NOWAIT      0x0001  /* ALQ may not sleep. */
60 #define ALQ_WAITOK      0x0002  /* ALQ may sleep. */
61 #define ALQ_NOACTIVATE  0x0004  /* Don't activate ALQ after write. */
62 #define ALQ_ORDERED     0x0010  /* Maintain write ordering between threads. */
63
64 /* Suggested mode for file creation. */
65 #define ALQ_DEFAULT_CMODE       0600
66
67 /*
68  * alq_open_flags:  Creates a new queue
69  *
70  * Arguments:
71  *      alq     Storage for a pointer to the newly created queue.
72  *      file    The filename to open for logging.
73  *      cred    Credential to authorize open and I/O with.
74  *      cmode   Creation mode for file, if new.
75  *      size    The size of the queue in bytes.
76  *      flags   ALQ_ORDERED
77  * Returns:
78  *      error from open or 0 on success
79  */
80 struct ucred;
81 int alq_open_flags(struct alq **alqp, const char *file, struct ucred *cred, int cmode,
82             int size, int flags);
83 int alq_open(struct alq **alqp, const char *file, struct ucred *cred, int cmode,
84             int size, int count);
85
86 /*
87  * alq_writen:  Write data into the queue
88  *
89  * Arguments:
90  *      alq     The queue we're writing to
91  *      data    The entry to be recorded
92  *      len     The number of bytes to write from *data
93  *      flags   (ALQ_NOWAIT || ALQ_WAITOK), ALQ_NOACTIVATE
94  *
95  * Returns:
96  *      EWOULDBLOCK if:
97  *              Waitok is ALQ_NOWAIT and the queue is full.
98  *              The system is shutting down.
99  *      0 on success.
100  */
101 int alq_writen(struct alq *alq, void *data, int len, int flags);
102 int alq_write(struct alq *alq, void *data, int flags);
103
104 /*
105  * alq_flush:  Flush the queue out to disk
106  */
107 void alq_flush(struct alq *alq);
108
109 /*
110  * alq_close:  Flush the queue and free all resources.
111  */
112 void alq_close(struct alq *alq);
113
114 /*
115  * alq_getn:  Return an entry for direct access
116  *
117  * Arguments:
118  *      alq     The queue to retrieve an entry from
119  *      len     Max number of bytes required
120  *      flags   (ALQ_NOWAIT || ALQ_WAITOK)
121  *
122  * Returns:
123  *      The next available ale on success.
124  *      NULL if:
125  *              flags is ALQ_NOWAIT and the queue is full.
126  *              The system is shutting down.
127  *
128  * This leaves the queue locked until a subsequent alq_post.
129  */
130 struct ale *alq_getn(struct alq *alq, int len, int flags);
131 struct ale *alq_get(struct alq *alq, int flags);
132
133 /*
134  * alq_post_flags:  Schedule the ale retrieved by alq_get/alq_getn for writing.
135  *      alq     The queue to post the entry to.
136  *      ale     An asynch logging entry returned by alq_get.
137  *      flags   ALQ_NOACTIVATE
138  */
139 void alq_post_flags(struct alq *alq, struct ale *ale, int flags);
140
141 static __inline void
142 alq_post(struct alq *alq, struct ale *ale)
143 {
144         alq_post_flags(alq, ale, 0);
145 }
146
147 #endif  /* _KERNEL */
148 #endif  /* _SYS_ALQ_H_ */